Skip to content

Commit ce883dc

Browse files
authored
Merge pull request #56 from ZeehMn/master
support gratuitous_arp_request
2 parents fb298b4 + 556e879 commit ce883dc

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

cni/k8s-sriov/k8s_sriov.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func cmdAdd(args *skel.CmdArgs) error {
9292
}
9393
//send Gratuitous ARP to let switch knows IP floats onto this node
9494
//ignore errors as we can't print logs and we do this as best as we can
95-
_ = utils.SendGratuitousARP(args.IfName, result020.IP4.IP.IP.String(), args.Netns)
95+
_ = utils.SendGratuitousARP(args.IfName, result020.IP4.IP.IP.String(), args.Netns, false)
9696
result020.DNS = conf.DNS
9797
return result020.Print()
9898
}

cni/k8s-vlan/k8s_vlan.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func setupNetwork(result020s []*t020.Result, vlanIds []uint16, args *skel.CmdArg
9696
//send Gratuitous ARP to let switch knows IP floats onto this node
9797
//ignore errors as we can't print logs and we do this as best as we can
9898
if d.PureMode() {
99-
_ = utils.SendGratuitousARP(d.Device, result020s[0].IP4.IP.IP.String(), "")
99+
_ = utils.SendGratuitousARP(d.Device, result020s[0].IP4.IP.IP.String(), "", d.GratuitousArpRequest)
100100
}
101101
return nil
102102
}
@@ -108,7 +108,7 @@ func setupMacvlan(result *t020.Result, vlanId uint16, args *skel.CmdArgs) error
108108
if err := utils.MacVlanConnectsHostWithContainer(result, args, d.DeviceIndex); err != nil {
109109
return err
110110
}
111-
_ = utils.SendGratuitousARP(args.IfName, result.IP4.IP.IP.String(), args.Netns)
111+
_ = utils.SendGratuitousARP(args.IfName, result.IP4.IP.IP.String(), args.Netns, d.GratuitousArpRequest)
112112
return nil
113113
}
114114

@@ -119,7 +119,7 @@ func setupIPVlan(result *t020.Result, vlanId uint16, args *skel.CmdArgs) error {
119119
if err := utils.IPVlanConnectsHostWithContainer(result, args, d.DeviceIndex); err != nil {
120120
return err
121121
}
122-
_ = utils.SendGratuitousARP(args.IfName, result.IP4.IP.IP.String(), args.Netns)
122+
_ = utils.SendGratuitousARP(args.IfName, result.IP4.IP.IP.String(), args.Netns, d.GratuitousArpRequest)
123123
return nil
124124
}
125125

@@ -146,7 +146,7 @@ func setupVlanDevice(result020s []*t020.Result, vlanIds []uint16, args *skel.Cmd
146146
if err := utils.VethConnectsHostWithContainer(result020, args, bridgeName, suffix); err != nil {
147147
return err
148148
}
149-
_ = utils.SendGratuitousARP(args.IfName, result020s[0].IP4.IP.IP.String(), args.Netns)
149+
_ = utils.SendGratuitousARP(args.IfName, result020s[0].IP4.IP.IP.String(), args.Netns, d.GratuitousArpRequest)
150150
}
151151
return nil
152152
}

pkg/network/vlan/vlan.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ package vlan
1919
import (
2020
"encoding/json"
2121
"fmt"
22-
"github.com/vishvananda/netlink/nl"
2322
"net"
2423
"strings"
2524
"sync"
2625

2726
"github.com/containernetworking/cni/pkg/types"
2827
"github.com/vishvananda/netlink"
28+
"github.com/vishvananda/netlink/nl"
2929
"tkestack.io/galaxy/pkg/network"
3030
"tkestack.io/galaxy/pkg/utils"
3131
)
@@ -61,6 +61,8 @@ type NetConf struct {
6161
BridgeNamePrefix string `json:"bridge_name_prefix"`
6262

6363
VlanNamePrefix string `json:"vlan_name_prefix"`
64+
65+
GratuitousArpRequest bool `json:"gratuitous_arp_request"`
6466
}
6567

6668
func (d *VlanDriver) LoadConf(bytes []byte) (*NetConf, error) {

pkg/utils/utils.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,19 @@ func VethConnectsHostWithContainer(result *t020.Result, args *skel.CmdArgs, brid
302302
return nil
303303
}
304304

305-
func SendGratuitousARP(dev, ip, nns string) error {
305+
func SendGratuitousARP(dev, ip, nns string, useArpRequest bool) error {
306306
arping, err := exec.LookPath("arping")
307307
if err != nil {
308308
return fmt.Errorf("unable to locate arping")
309309
}
310-
command := exec.Command(arping, "-c", "2", "-A", "-I", dev, ip)
310+
311+
var command *exec.Cmd
312+
if useArpRequest {
313+
command = exec.Command(arping, "-c", "2", "-U", "-I", dev, ip)
314+
} else {
315+
command = exec.Command(arping, "-c", "2", "-A", "-I", dev, ip)
316+
}
317+
311318
if nns == "" {
312319
_, err = command.CombinedOutput()
313320
return err

0 commit comments

Comments
 (0)