Skip to content

Commit

Permalink
Merge pull request #115 from OrangeBao/main
Browse files Browse the repository at this point in the history
fix: periodic update ARP table
  • Loading branch information
kosmos-robot authored and wangyizhi1 committed Oct 18, 2023
2 parents 26c59e2 + af4913f commit db40232
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pkg/clusterlink/network/neigh.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,27 @@ var NEIGH_TYPE_MAP map[NeighType]string = map[NeighType]string{
NEIGH_FDB: "fbd",
}

func getNeighList(linkIndex, family int, neighType NeighType) ([]netlink.Neigh, error) {
func neighListForArp(linkIndex int) ([]netlink.Neigh, error) {
var err error
var neighList []netlink.Neigh
neighList4, err4 := netlink.NeighList(linkIndex, netlink.FAMILY_V4)
neighList6, err6 := netlink.NeighList(linkIndex, netlink.FAMILY_V6)
neighList = append(neighList, neighList4...)
neighList = append(neighList, neighList6...)
if err4 != nil || err6 != nil {
err = fmt.Errorf("list arp err, linkIndex: %d, err4: %s, err6: %s ", linkIndex, err4, err6)
}
return neighList, err
}

func getNeighList(linkIndex int, neighType NeighType) ([]netlink.Neigh, error) {
var err error
var neighList []netlink.Neigh
switch neighType {
case NEIGH_FDB:
neighList, err = netlink.NeighList(linkIndex, unix.AF_BRIDGE)
case NEIGH_ARP:
neighList, err = netlink.NeighList(linkIndex, netlink.FAMILY_V4)
neighList, err = neighListForArp(linkIndex)
default:
return nil, fmt.Errorf("strange neighType %v", neighType)
}
Expand Down Expand Up @@ -156,7 +169,7 @@ func DeleteNeighByDevice(dev string, neighType NeighType) error {
klog.Errorf("Find interface %s error :%v", dev, err)
return err
}
neighList, err := getNeighList(vxlanIface.Attrs().Index, unix.AF_BRIDGE, neighType)
neighList, err := getNeighList(vxlanIface.Attrs().Index, neighType)
if err != nil {
klog.Errorf("Show %s entries error: %v", NEIGH_TYPE_MAP[neighType], err)
return err
Expand Down Expand Up @@ -186,7 +199,7 @@ func ListNeigh(neighType NeighType) []FDBRecord {
if err != nil {
continue
}
neighList, err := getNeighList(vxlanIface.Attrs().Index, unix.AF_BRIDGE, neighType)
neighList, err := getNeighList(vxlanIface.Attrs().Index, neighType)
if err != nil {
klog.Errorf("List vxlan neigh %s entries, but get error : %v", NEIGH_TYPE_MAP[neighType], err)
continue
Expand Down

0 comments on commit db40232

Please sign in to comment.