diff options
author | Chris Koch <chrisko@google.com> | 2019-11-20 15:41:45 -0800 |
---|---|---|
committer | Chris K <c@chrisko.ch> | 2019-12-03 16:02:05 -0700 |
commit | 3997b8a58c66233275ad9b26612ef733a63bd9d3 (patch) | |
tree | eb6e50a7cdb43b7a638be799dea969ded1a9ca6e | |
parent | 23cb9c9804a6fcab99e1843729a1f561e424716e (diff) |
dhcpv4: add Client Identifier option; respect RFC 6842
Signed-off-by: Chris Koch <chrisko@google.com>
-rw-r--r-- | dhcpv4/dhcpv4.go | 6 | ||||
-rw-r--r-- | dhcpv4/modifiers.go | 12 | ||||
-rw-r--r-- | dhcpv4/option_misc.go | 5 |
3 files changed, 15 insertions, 8 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go index 1d8ddef..0bfea48 100644 --- a/dhcpv4/dhcpv4.go +++ b/dhcpv4/dhcpv4.go @@ -262,7 +262,11 @@ func NewReplyFromRequest(request *DHCPv4, modifiers ...Modifier) (*DHCPv4, error return New(PrependModifiers(modifiers, WithReply(request), WithGatewayIP(request.GatewayIPAddr), - WithRelayAgentInfo(request), + WithOptionCopied(request, OptionRelayAgentInformation), + + // RFC 6842 states the Client Identifier option must be copied + // from the request if a client specified it. + WithOptionCopied(request, OptionClientIdentifier), )...) } diff --git a/dhcpv4/modifiers.go b/dhcpv4/modifiers.go index 2bf79b8..0ab35bc 100644 --- a/dhcpv4/modifiers.go +++ b/dhcpv4/modifiers.go @@ -43,18 +43,16 @@ func WithGatewayIP(ip net.IP) Modifier { } } -// WithRelayAgentInfo copies the relay options from the request to the reply. -func WithRelayAgentInfo(request *DHCPv4) Modifier { +// WithOptionCopied copies the value of option opt from request. +func WithOptionCopied(request *DHCPv4, opt OptionCode) Modifier { return func(d *DHCPv4) { - // If request has Relay Agent Info copy it to the reply - if relayOpt := request.RelayAgentInfo(); relayOpt != nil { - d.UpdateOption(Option{Code: OptionRelayAgentInformation, Value: relayOpt}) + if val := request.Options.Get(opt); val != nil { + d.UpdateOption(OptGeneric(opt, val)) } } } -// WithReply fills in opcode, hwtype, xid, clienthwaddr, flags, and gateway ip -// addr from the given packet. +// WithReply fills in opcode, hwtype, xid, clienthwaddr, and flags from the given packet. func WithReply(request *DHCPv4) Modifier { return func(d *DHCPv4) { if request.OpCode == OpcodeBootRequest { diff --git a/dhcpv4/option_misc.go b/dhcpv4/option_misc.go index 01de95f..e91b34d 100644 --- a/dhcpv4/option_misc.go +++ b/dhcpv4/option_misc.go @@ -16,3 +16,8 @@ func OptDomainSearch(labels *rfc1035label.Labels) Option { func OptClientArch(archs ...iana.Arch) Option { return Option{Code: OptionClientSystemArchitectureType, Value: iana.Archs(archs)} } + +// OptClientIdentifier returns a new Client Identifier option. +func OptClientIdentifier(ident []byte) Option { + return OptGeneric(OptionClientIdentifier, ident) +} |