Skip to content

Commit 60adafd

Browse files
authored
Add support for Client Link-Layer Address Option (#373)
RFC6939 specifies a client option to relay the link-layer address of the original client in the relayed message. This commit adjusts the OOB plugin to first try and read the address from that option and falls back to the old EUI64 parsing when that fails. It should be noted that the EUI64 parsing does not work if the client has IPv6 privacy extensions enabled as the server can not distinguish between EUI64 and and a random IPv6 host address. See: https://www.rfc-editor.org/rfc/rfc6939
1 parent dddcf5b commit 60adafd

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

plugins/oob/plugin.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/coredhcp/coredhcp/plugins"
2424
"github.com/insomniacslk/dhcp/dhcpv4"
2525
"github.com/insomniacslk/dhcp/dhcpv6"
26+
"github.com/insomniacslk/dhcp/iana"
2627

2728
"github.com/mdlayher/netx/eui64"
2829
)
@@ -104,10 +105,9 @@ func handler6(req, resp dhcpv6.DHCPv6) (dhcpv6.DHCPv6, bool) {
104105

105106
relayMsg := req.(*dhcpv6.RelayMessage)
106107

107-
// Retrieve IPv6 prefix and MAC address from IPv6 address
108-
_, mac, err := eui64.ParseIP(relayMsg.PeerAddr)
108+
mac, err := getMAC(relayMsg)
109109
if err != nil {
110-
log.Errorf("Could not parse peer address: %s", err)
110+
log.Errorf("Failed to obtain MAC, dropping.")
111111
return nil, true
112112
}
113113

@@ -160,6 +160,22 @@ func handler6(req, resp dhcpv6.DHCPv6) (dhcpv6.DHCPv6, bool) {
160160
return resp, false
161161
}
162162

163+
func getMAC(relayMsg *dhcpv6.RelayMessage) (net.HardwareAddr, error) {
164+
hwType, mac := relayMsg.Options.ClientLinkLayerAddress()
165+
if hwType == iana.HWTypeEthernet {
166+
return mac, nil
167+
}
168+
169+
log.Infof("failed to retrieve client link layer address, falling back to EUI64 (%s)", relayMsg.PeerAddr.String())
170+
_, mac, err := eui64.ParseIP(relayMsg.PeerAddr)
171+
if err != nil {
172+
log.Errorf("Could not parse peer address: %s", err)
173+
return nil, err
174+
}
175+
176+
return mac, nil
177+
}
178+
163179
func setup4(args ...string) (handler.Handler4, error) {
164180
oobConfig, err := loadConfig(args...)
165181
if err != nil {

0 commit comments

Comments
 (0)