Skip to content

Commit

Permalink
dhcpv4: add Client Identifier option; respect RFC 6842
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Koch <[email protected]>
  • Loading branch information
hugelgupf committed Dec 3, 2019
1 parent 23cb9c9 commit 3997b8a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 5 additions & 1 deletion dhcpv4/dhcpv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)...)
}

Expand Down
12 changes: 5 additions & 7 deletions dhcpv4/modifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions dhcpv4/option_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 3997b8a

Please sign in to comment.