Compare commits

...

3 Commits

Author SHA1 Message Date
Matt Dupre
4744ec27b8
Merge pull request #716 from squeed/cp-bugfixes
[release-1.1] Cherry-pick some bugfixes
2022-03-09 09:06:40 -08:00
Fabian Wiesel
b1782e50d7 ipam/dhcp: Fix client id in renew/release
The client id was constructed differently in the acquire
function compared to the release and renew functions,
which caused the dhcp-server to consider it a different client.
This is now encapsulated in a common function.

Signed-off-by: Fabian Wiesel <fabian.wiesel@sap.com>
2022-03-09 17:47:10 +01:00
gojoy
b03deb63a9 call ipam.ExceDel after clean up device in netns
fix #666

Signed-off-by: gojoy <729324352@qq.com>
2022-03-09 17:46:59 +01:00
2 changed files with 40 additions and 23 deletions

View File

@ -200,6 +200,30 @@ func (l *DHCPLease) Stop() {
l.wg.Wait() l.wg.Wait()
} }
func (l *DHCPLease) getOptionsWithClientId() dhcp4.Options {
opts := make(dhcp4.Options)
opts[dhcp4.OptionClientIdentifier] = []byte(l.clientID)
// client identifier's first byte is "type"
newClientID := []byte{0}
newClientID = append(newClientID, opts[dhcp4.OptionClientIdentifier]...)
opts[dhcp4.OptionClientIdentifier] = newClientID
return opts
}
func (l *DHCPLease) getAllOptions() dhcp4.Options {
opts := l.getOptionsWithClientId()
for k, v := range l.optsProviding {
opts[k] = v
}
opts[dhcp4.OptionParameterRequestList] = []byte{}
for k := range l.optsRequesting {
opts[dhcp4.OptionParameterRequestList] = append(opts[dhcp4.OptionParameterRequestList], byte(k))
}
return opts
}
func (l *DHCPLease) acquire() error { func (l *DHCPLease) acquire() error {
c, err := newDHCPClient(l.link, l.clientID, l.timeout, l.broadcast) c, err := newDHCPClient(l.link, l.clientID, l.timeout, l.broadcast)
if err != nil { if err != nil {
@ -214,19 +238,7 @@ func (l *DHCPLease) acquire() error {
} }
} }
opts := make(dhcp4.Options) opts := l.getAllOptions()
opts[dhcp4.OptionClientIdentifier] = []byte(l.clientID)
opts[dhcp4.OptionParameterRequestList] = []byte{}
for k := range l.optsRequesting {
opts[dhcp4.OptionParameterRequestList] = append(opts[dhcp4.OptionParameterRequestList], byte(k))
}
for k, v := range l.optsProviding {
opts[k] = v
}
// client identifier's first byte is "type"
newClientID := []byte{0}
newClientID = append(newClientID, opts[dhcp4.OptionClientIdentifier]...)
opts[dhcp4.OptionClientIdentifier] = newClientID
pkt, err := backoffRetry(l.resendMax, func() (*dhcp4.Packet, error) { pkt, err := backoffRetry(l.resendMax, func() (*dhcp4.Packet, error) {
ok, ack, err := DhcpRequest(c, opts) ok, ack, err := DhcpRequest(c, opts)
@ -344,9 +356,7 @@ func (l *DHCPLease) renew() error {
} }
defer c.Close() defer c.Close()
opts := make(dhcp4.Options) opts := l.getOptionsWithClientId()
opts[dhcp4.OptionClientIdentifier] = []byte(l.clientID)
pkt, err := backoffRetry(l.resendMax, func() (*dhcp4.Packet, error) { pkt, err := backoffRetry(l.resendMax, func() (*dhcp4.Packet, error) {
ok, ack, err := DhcpRenew(c, *l.ack, opts) ok, ack, err := DhcpRenew(c, *l.ack, opts)
switch { switch {
@ -375,8 +385,7 @@ func (l *DHCPLease) release() error {
} }
defer c.Close() defer c.Close()
opts := make(dhcp4.Options) opts := l.getOptionsWithClientId()
opts[dhcp4.OptionClientIdentifier] = []byte(l.clientID)
if err = DhcpRelease(c, *l.ack, opts); err != nil { if err = DhcpRelease(c, *l.ack, opts); err != nil {
return fmt.Errorf("failed to send DHCPRELEASE") return fmt.Errorf("failed to send DHCPRELEASE")

View File

@ -631,14 +631,17 @@ func cmdDel(args *skel.CmdArgs) error {
isLayer3 := n.IPAM.Type != "" isLayer3 := n.IPAM.Type != ""
ipamDel := func() error {
if isLayer3 { if isLayer3 {
if err := ipam.ExecDel(n.IPAM.Type, args.StdinData); err != nil { if err := ipam.ExecDel(n.IPAM.Type, args.StdinData); err != nil {
return err return err
} }
} }
return nil
}
if args.Netns == "" { if args.Netns == "" {
return nil return ipamDel()
} }
// There is a netns so try to clean up. Delete can be called multiple times // There is a netns so try to clean up. Delete can be called multiple times
@ -660,11 +663,16 @@ func cmdDel(args *skel.CmdArgs) error {
// https://github.com/kubernetes/kubernetes/issues/43014#issuecomment-287164444 // https://github.com/kubernetes/kubernetes/issues/43014#issuecomment-287164444
_, ok := err.(ns.NSPathNotExistErr) _, ok := err.(ns.NSPathNotExistErr)
if ok { if ok {
return nil return ipamDel()
} }
return err return err
} }
// call ipam.ExecDel after clean up device in netns
if err := ipamDel(); err != nil {
return err
}
if n.MacSpoofChk { if n.MacSpoofChk {
sc := link.NewSpoofChecker("", "", uniqueID(args.ContainerID, args.IfName)) sc := link.NewSpoofChecker("", "", uniqueID(args.ContainerID, args.IfName))
if err := sc.Teardown(); err != nil { if err := sc.Teardown(); err != nil {