dhcp ipam: truncate client id to 254 bytes

Signed-off-by: SilverBut <SilverBut@users.noreply.github.com>
This commit is contained in:
SilverBut 2021-10-01 19:44:26 +08:00
parent 6d1f71e55a
commit be383cf30d

View File

@ -33,8 +33,6 @@ import (
"github.com/coreos/go-systemd/v22/activation"
)
const listenFdsStart = 3
var errNoMoreTries = errors.New("no more tries")
type DHCP struct {
@ -54,8 +52,15 @@ func newDHCP(clientTimeout, clientResendMax time.Duration) *DHCP {
}
}
// TODO: current client ID is too long. At least the container ID should not be used directly.
// A seperate issue is necessary to ensure no breaking change is affecting other users.
func generateClientID(containerID string, netName string, ifName string) string {
return containerID + "/" + netName + "/" + ifName
clientID := containerID + "/" + netName + "/" + ifName
// defined in RFC 2132, length size can not be larger than 1 octet. So we truncate 254 to make everyone happy.
if len(clientID) > 254 {
clientID = clientID[0:254]
}
return clientID
}
// Allocate acquires an IP from a DHCP server for a specified container.