-
Notifications
You must be signed in to change notification settings - Fork 260
Set constant mac for host veth interface in transparent vlan mode #1906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2061701
62ab3b1
7a0d8cd
3ed02ea
68a1c1d
90e4fad
b2f0a29
76606f3
dc94fc4
f003b2c
f381510
c4670fc
48e12c5
f39c515
fe952ca
0b91783
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,7 +158,7 @@ func (nw *network) newEndpointImpl( | |
| } | ||
| // set deleteHostVeth to true to cleanup host veth interface if created | ||
| //nolint:errcheck // ignore error | ||
| epClient.DeleteEndpoints(endpt, true) | ||
| epClient.DeleteEndpoints(endpt) | ||
| } | ||
| }() | ||
|
|
||
|
|
@@ -284,7 +284,7 @@ func (nw *network) deleteEndpointImpl(nl netlink.NetlinkInterface, plc platform. | |
| // deleteHostVeth set to false not to delete veth as CRI will remove network namespace and | ||
| // veth will get removed as part of that. | ||
| //nolint:errcheck // ignore error | ||
| epClient.DeleteEndpoints(ep, false) | ||
| epClient.DeleteEndpoints(ep) | ||
|
|
||
| return nil | ||
| } | ||
|
|
@@ -297,8 +297,6 @@ func addRoutes(nl netlink.NetlinkInterface, netioshim netio.NetIOInterface, inte | |
| ifIndex := 0 | ||
|
|
||
| for _, route := range routes { | ||
| log.Printf("[net] Adding IP route %+v to link %v.", route, interfaceName) | ||
|
|
||
| if route.DevName != "" { | ||
| devIf, _ := netioshim.GetNetworkInterfaceByName(route.DevName) | ||
| ifIndex = devIf.Index | ||
|
|
@@ -327,6 +325,7 @@ func addRoutes(nl netlink.NetlinkInterface, netioshim netio.NetIOInterface, inte | |
| Table: route.Table, | ||
| } | ||
|
|
||
| log.Printf("[net] Adding IP route %+v to link %v.", route, interfaceName) | ||
| if err := nl.AddIPRoute(nlRoute); err != nil { | ||
| if !strings.Contains(strings.ToLower(err.Error()), "file exists") { | ||
| return err | ||
|
|
@@ -343,8 +342,6 @@ func deleteRoutes(nl netlink.NetlinkInterface, netioshim netio.NetIOInterface, i | |
| ifIndex := 0 | ||
|
|
||
| for _, route := range routes { | ||
| log.Printf("[net] Deleting IP route %+v from link %v.", route, interfaceName) | ||
|
|
||
| if route.DevName != "" { | ||
| devIf, _ := netioshim.GetNetworkInterfaceByName(route.DevName) | ||
| if devIf == nil { | ||
|
|
@@ -353,15 +350,15 @@ func deleteRoutes(nl netlink.NetlinkInterface, netioshim netio.NetIOInterface, i | |
| } | ||
|
|
||
| ifIndex = devIf.Index | ||
| } else { | ||
| } else if interfaceName != "" { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this failing in a case where
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would not fail but skip deleting the route if interface not provided but the requirement is to delete route even if interface name not provided |
||
| interfaceIf, _ := netioshim.GetNetworkInterfaceByName(interfaceName) | ||
| if interfaceIf == nil { | ||
| log.Printf("[net] Not deleting route. Interface %v doesn't exist", interfaceName) | ||
| continue | ||
| } | ||
|
|
||
| ifIndex = interfaceIf.Index | ||
| } | ||
|
|
||
| family := netlink.GetIPAddressFamily(route.Gw) | ||
| if route.Gw == nil { | ||
| family = netlink.GetIPAddressFamily(route.Dst.IP) | ||
|
|
@@ -370,12 +367,13 @@ func deleteRoutes(nl netlink.NetlinkInterface, netioshim netio.NetIOInterface, i | |
| nlRoute := &netlink.Route{ | ||
| Family: family, | ||
| Dst: &route.Dst, | ||
| Gw: route.Gw, | ||
| LinkIndex: ifIndex, | ||
| Gw: route.Gw, | ||
| Protocol: route.Protocol, | ||
| Scope: route.Scope, | ||
| } | ||
|
|
||
| log.Printf("[net] Deleting IP route %+v from link %v.", route, interfaceName) | ||
| if err := nl.DeleteIPRoute(nlRoute); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| package network | ||
|
|
||
| import ( | ||
| "net" | ||
| "testing" | ||
|
|
||
| "github.com/Azure/azure-container-networking/netio" | ||
| "github.com/Azure/azure-container-networking/netlink" | ||
| . "github.com/onsi/ginkgo" | ||
| . "github.com/onsi/gomega" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| func TestEndpointLinux(t *testing.T) { | ||
| RegisterFailHandler(Fail) | ||
| RunSpecs(t, "Endpoint Suite") | ||
| } | ||
|
|
||
| var _ = Describe("Test TestEndpointLinux", func() { | ||
| Describe("Test deleteRoutes", func() { | ||
| _, dst, _ := net.ParseCIDR("192.168.0.0/16") | ||
|
|
||
| It("DeleteRoute with interfacename explicit", func() { | ||
| nlc := netlink.NewMockNetlink(false, "") | ||
| nlc.SetDeleteRouteValidationFn(func(r *netlink.Route) error { | ||
| Expect(r.LinkIndex).To(Equal(5)) | ||
| return nil | ||
| }) | ||
|
|
||
| netiocl := netio.NewMockNetIO(false, 0) | ||
| netiocl.SetGetInterfaceValidatonFn(func(ifName string) (*net.Interface, error) { | ||
| Expect(ifName).To(Equal("eth0")) | ||
| return &net.Interface{ | ||
| Index: 5, | ||
| }, nil | ||
| }) | ||
|
|
||
| err := deleteRoutes(nlc, netiocl, "eth0", []RouteInfo{{Dst: *dst, DevName: ""}}) | ||
| Expect(err).To(BeNil()) | ||
| }) | ||
| It("DeleteRoute with interfacename set in Route", func() { | ||
| nlc := netlink.NewMockNetlink(false, "") | ||
| nlc.SetDeleteRouteValidationFn(func(r *netlink.Route) error { | ||
| Expect(r.LinkIndex).To(Equal(6)) | ||
| return nil | ||
| }) | ||
|
|
||
| netiocl := netio.NewMockNetIO(false, 0) | ||
| netiocl.SetGetInterfaceValidatonFn(func(ifName string) (*net.Interface, error) { | ||
| Expect(ifName).To(Equal("eth1")) | ||
| return &net.Interface{ | ||
| Index: 6, | ||
| }, nil | ||
| }) | ||
|
|
||
| err := deleteRoutes(nlc, netiocl, "", []RouteInfo{{Dst: *dst, DevName: "eth1"}}) | ||
| Expect(err).To(BeNil()) | ||
| }) | ||
| It("DeleteRoute with no ifindex", func() { | ||
| nlc := netlink.NewMockNetlink(false, "") | ||
| nlc.SetDeleteRouteValidationFn(func(r *netlink.Route) error { | ||
| Expect(r.LinkIndex).To(Equal(0)) | ||
| return nil | ||
| }) | ||
|
|
||
| netiocl := netio.NewMockNetIO(false, 0) | ||
| netiocl.SetGetInterfaceValidatonFn(func(ifName string) (*net.Interface, error) { | ||
| Expect(ifName).To(Equal("eth1")) | ||
| return &net.Interface{ | ||
| Index: 6, | ||
| }, nil | ||
| }) | ||
|
|
||
| err := deleteRoutes(nlc, netiocl, "", []RouteInfo{{Dst: *dst, DevName: ""}}) | ||
| Expect(err).To(BeNil()) | ||
| }) | ||
| }) | ||
| Describe("Test addRoutes", func() { | ||
| _, dst, _ := net.ParseCIDR("192.168.0.0/16") | ||
| It("AddRoute with interfacename explicit", func() { | ||
| nlc := netlink.NewMockNetlink(false, "") | ||
| nlc.SetAddRouteValidationFn(func(r *netlink.Route) error { | ||
| Expect(r).NotTo(BeNil()) | ||
| Expect(r.LinkIndex).To(Equal(5)) | ||
| return nil | ||
| }) | ||
|
|
||
| netiocl := netio.NewMockNetIO(false, 0) | ||
| netiocl.SetGetInterfaceValidatonFn(func(ifName string) (*net.Interface, error) { | ||
| Expect(ifName).To(Equal("eth0")) | ||
| return &net.Interface{ | ||
| Index: 5, | ||
| }, nil | ||
| }) | ||
|
|
||
| err := addRoutes(nlc, netiocl, "eth0", []RouteInfo{{Dst: *dst, DevName: ""}}) | ||
| Expect(err).To(BeNil()) | ||
| }) | ||
| It("AddRoute with interfacename set in route", func() { | ||
| nlc := netlink.NewMockNetlink(false, "") | ||
| nlc.SetAddRouteValidationFn(func(r *netlink.Route) error { | ||
| Expect(r.LinkIndex).To(Equal(6)) | ||
| return nil | ||
| }) | ||
|
|
||
| netiocl := netio.NewMockNetIO(false, 0) | ||
| netiocl.SetGetInterfaceValidatonFn(func(ifName string) (*net.Interface, error) { | ||
| Expect(ifName).To(Equal("eth1")) | ||
| return &net.Interface{ | ||
| Index: 6, | ||
| }, nil | ||
| }) | ||
|
|
||
| err := addRoutes(nlc, netiocl, "", []RouteInfo{{Dst: *dst, DevName: "eth1"}}) | ||
| Expect(err).To(BeNil()) | ||
| }) | ||
| It("AddRoute with interfacename not set should return error", func() { | ||
| nlc := netlink.NewMockNetlink(false, "") | ||
| nlc.SetAddRouteValidationFn(func(r *netlink.Route) error { | ||
| Expect(r.LinkIndex).To(Equal(0)) | ||
| //nolint:goerr113 // for testing | ||
| return errors.New("Cannot add route") | ||
| }) | ||
|
|
||
| netiocl := netio.NewMockNetIO(false, 0) | ||
| netiocl.SetGetInterfaceValidatonFn(func(ifName string) (*net.Interface, error) { | ||
| Expect(ifName).To(Equal("")) | ||
| return &net.Interface{ | ||
| Index: 0, | ||
| }, errors.Wrapf(netio.ErrInterfaceNil, "Cannot get interface") | ||
| }) | ||
|
|
||
| err := addRoutes(nlc, netiocl, "", []RouteInfo{{Dst: *dst, DevName: ""}}) | ||
| Expect(err).ToNot(BeNil()) | ||
| }) | ||
| }) | ||
| }) |
Uh oh!
There was an error while loading. Please reload this page.