Skip to content

Commit

Permalink
dhcpd: add default options
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Sep 13, 2021
1 parent 575e9d0 commit 723f818
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions internal/dhcpd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,46 @@ func parseOpt(s string) (opt dhcpv4.Option, err error) {
func prepareOptions(conf V4ServerConf) (opts dhcpv4.Options) {
opts = make(dhcpv4.Options)

// Set default values for host configuration parameters listed in
// Appendix A of RFC-2131. Those parameters, if requested by client,
// should be returned with values defined by Host Requirements Document.
//
// See https://datatracker.ietf.org/doc/html/rfc2131#appendix-A.
//
// See also https://datatracker.ietf.org/doc/html/rfc1122,
// https://datatracker.ietf.org/doc/html/rfc1123, and
// https://datatracker.ietf.org/doc/html/rfc2132.
for _, opt := range []dhcpv4.Option{
// IP-Layer Per Host

dhcpv4.OptGeneric(dhcpv4.OptionNonLocalSourceRouting, []byte{0}),
// Set the current recommended default time to live for the
// Internet Protocol which is 64, see
// https://datatracker.ietf.org/doc/html/rfc1700.
dhcpv4.OptGeneric(dhcpv4.OptionDefaultIPTTL, []byte{64}),

// IP-Layer Per Interface

dhcpv4.OptGeneric(dhcpv4.OptionPerformMaskDiscovery, []byte{0}),
dhcpv4.OptGeneric(dhcpv4.OptionMaskSupplier, []byte{0}),
dhcpv4.OptGeneric(dhcpv4.OptionPerformRouterDiscovery, []byte{1}),
// The all-routers address is preferred wherever possible, see
// https://datatracker.ietf.org/doc/html/rfc1256#section-5.1.
dhcpv4.OptGeneric(dhcpv4.OptionRouterSolicitationAddress, net.IPv4allrouter),
dhcpv4.OptBroadcastAddress(net.IPv4bcast),

// Link-Layer Per Interface

dhcpv4.OptGeneric(dhcpv4.OptionTrailerEncapsulation, []byte{0}),
dhcpv4.OptGeneric(dhcpv4.OptionEthernetEncapsulation, []byte{0}),

// TCP Per Host
{Code: dhcpv4.OptionTCPKeepaliveInterval, Value: dhcpv4.Duration(0)},
dhcpv4.OptGeneric(dhcpv4.OptionTCPKeepaliveGarbage, []byte{0}),
} {
opts.Update(opt)
}

// Set values for options from server's configuration.
for _, opt := range []dhcpv4.Option{
dhcpv4.OptRouter(conf.subnet.IP),
Expand Down

0 comments on commit 723f818

Please sign in to comment.