
The dhcp server is systemd-networkd, and the dhcp plugin can request an ip but can not renew it. The systemd-networkd just ignore the renew request. ``` 2024/09/14 21:46:00 no DHCP packet received within 10s 2024/09/14 21:46:00 retrying in 31.529038 seconds 2024/09/14 21:46:42 no DHCP packet received within 10s 2024/09/14 21:46:42 retrying in 63.150490 seconds 2024/09/14 21:47:45 98184616c91f15419f5cacd012697f85afaa2daeb5d3233e28b0ec21589fb45a/iot/eth1: no more tries 2024/09/14 21:47:45 98184616c91f15419f5cacd012697f85afaa2daeb5d3233e28b0ec21589fb45a/iot/eth1: renewal time expired, rebinding 2024/09/14 21:47:45 Link "eth1" down. Attempting to set up 2024/09/14 21:47:45 98184616c91f15419f5cacd012697f85afaa2daeb5d3233e28b0ec21589fb45a/iot/eth1: lease rebound, expiration is 2024-09-14 22:47:45.309270751 +0800 CST m=+11730.048516519 ``` Follow the https://datatracker.ietf.org/doc/html/rfc2131#section-4.3.6, following options must not be sent in renew - Requested IP Address - Server Identifier Since the upstream code has been inactive for 6 years, we should switch to another dhcpv4 library. The new selected one is https://github.com/insomniacslk/dhcp. Signed-off-by: Songmin Li <lisongmin@protonmail.com>
85 lines
2.5 KiB
Go
85 lines
2.5 KiB
Go
package dhcpv4
|
|
|
|
// String represents an option encapsulating a string in IPv4 DHCP.
|
|
//
|
|
// This representation is shared by multiple options specified by RFC 2132,
|
|
// Sections 3.14, 3.16, 3.17, 3.19, and 3.20.
|
|
type String string
|
|
|
|
// ToBytes returns a serialized stream of bytes for this option.
|
|
func (o String) ToBytes() []byte {
|
|
return []byte(o)
|
|
}
|
|
|
|
// String returns a human-readable string.
|
|
func (o String) String() string {
|
|
return string(o)
|
|
}
|
|
|
|
// FromBytes parses a serialized stream of bytes into o.
|
|
func (o *String) FromBytes(data []byte) error {
|
|
*o = String(string(data))
|
|
return nil
|
|
}
|
|
|
|
// GetString parses an RFC 2132 string from o[code].
|
|
func GetString(code OptionCode, o Options) string {
|
|
v := o.Get(code)
|
|
if v == nil {
|
|
return ""
|
|
}
|
|
return string(v)
|
|
}
|
|
|
|
// OptDomainName returns a new DHCPv4 Domain Name option.
|
|
//
|
|
// The Domain Name option is described by RFC 2132, Section 3.17.
|
|
func OptDomainName(name string) Option {
|
|
return Option{Code: OptionDomainName, Value: String(name)}
|
|
}
|
|
|
|
// OptHostName returns a new DHCPv4 Host Name option.
|
|
//
|
|
// The Host Name option is described by RFC 2132, Section 3.14.
|
|
func OptHostName(name string) Option {
|
|
return Option{Code: OptionHostName, Value: String(name)}
|
|
}
|
|
|
|
// OptRootPath returns a new DHCPv4 Root Path option.
|
|
//
|
|
// The Root Path option is described by RFC 2132, Section 3.19.
|
|
func OptRootPath(name string) Option {
|
|
return Option{Code: OptionRootPath, Value: String(name)}
|
|
}
|
|
|
|
// OptBootFileName returns a new DHCPv4 Boot File Name option.
|
|
//
|
|
// The Bootfile Name option is described by RFC 2132, Section 9.5.
|
|
func OptBootFileName(name string) Option {
|
|
return Option{Code: OptionBootfileName, Value: String(name)}
|
|
}
|
|
|
|
// OptTFTPServerName returns a new DHCPv4 TFTP Server Name option.
|
|
//
|
|
// The TFTP Server Name option is described by RFC 2132, Section 9.4.
|
|
func OptTFTPServerName(name string) Option {
|
|
return Option{Code: OptionTFTPServerName, Value: String(name)}
|
|
}
|
|
|
|
// OptClassIdentifier returns a new DHCPv4 Class Identifier option.
|
|
//
|
|
// The Vendor Class Identifier option is described by RFC 2132, Section 9.13.
|
|
func OptClassIdentifier(name string) Option {
|
|
return Option{Code: OptionClassIdentifier, Value: String(name)}
|
|
}
|
|
|
|
// OptUserClass returns a new DHCPv4 User Class option.
|
|
func OptUserClass(name string) Option {
|
|
return Option{Code: OptionUserClassInformation, Value: String(name)}
|
|
}
|
|
|
|
// OptMessage returns a new DHCPv4 (Error) Message option.
|
|
func OptMessage(msg string) Option {
|
|
return Option{Code: OptionMessage, Value: String(msg)}
|
|
}
|