Route to SDN irrespective if macvlan mode is used or not
Fixes
@@ -137,6 +137,10 @@ func (p *cniPlugin) CmdAdd(args *skel.CmdArgs) error {
if err != nil {
return err
}
+ _, serviceIPNet, err := net.ParseCIDR(config.ServiceNetworkCIDR)
+ if err != nil {
+ return fmt.Errorf("failed to parse ServiceNetworkCIDR: %v", err)
+ }
var hostVeth, contVeth net.Interface
err = ns.WithNetNSPath(args.Netns, func(hostNS ns.NetNS) error {
@@ -194,6 +198,7 @@ func (p *cniPlugin) CmdAdd(args *skel.CmdArgs) error {
return fmt.Errorf("failed to configure container loopback: %v", err)
}
+ var dsts []*net.IPNet
// Set up macvlan0 (if it exists)
link, err = netlink.LinkByName("macvlan0")
if err == nil {
@@ -222,18 +227,12 @@ func (p *cniPlugin) CmdAdd(args *skel.CmdArgs) error {
if err != nil {
return fmt.Errorf("failed to configure macvlan device: %v", err)
}
-
- var dsts []*net.IPNet
for _, addr := range addrs {
dsts = append(dsts, &net.IPNet{IP: addr.IP, Mask: net.CIDRMask(32, 32)})
}
-
- _, serviceIPNet, err := net.ParseCIDR(config.ServiceNetworkCIDR)
- if err != nil {
- return fmt.Errorf("failed to parse ServiceNetworkCIDR: %v", err)
}
- dsts = append(dsts, serviceIPNet)
+ dsts = append(dsts, serviceIPNet)
for _, dst := range dsts {
route := &netlink.Route{
Dst: dst,
@@ -243,7 +242,6 @@ func (p *cniPlugin) CmdAdd(args *skel.CmdArgs) error {
return fmt.Errorf("failed to add route to dst: %v via SDN: %v", dst, err)
}
}
- }
// Block access to certain things
for _, args := range iptablesCommands {
