Skip to content
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

Replace arping package with arp_notify #687

Merged
merged 2 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/d2g/dhcp4client v1.0.0
github.com/d2g/dhcp4server v0.0.0-20181031114812-7d4a0a7f59a5
github.com/godbus/dbus/v5 v5.0.4
github.com/j-keck/arping v1.0.2
github.com/mattn/go-shellwords v1.0.12
github.com/networkplumbing/go-nft v0.2.0
github.com/onsi/ginkgo v1.16.4
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ github.com/containerd/zfs v1.0.0/go.mod h1:m+m51S1DvAP6r3FcmYCp54bQ34pyOwTieQDNR
github.com/containernetworking/cni v0.7.1/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
github.com/containernetworking/cni v0.8.0/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
github.com/containernetworking/cni v0.8.1/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
github.com/containernetworking/cni v1.0.0 h1:9VJe1a5uKtdeJIHC/UvbTweracOh6GafT0nfbEGVcQ0=
github.com/containernetworking/cni v1.0.0/go.mod h1:AKuhXbN5EzmD4yTNtfSsX3tPcmtrBI6QcRV0NiNt15Y=
github.com/containernetworking/cni v1.0.1 h1:9OIL/sZmMYDBe+G8svzILAlulUpaDTUjeAbtH/JNLBo=
github.com/containernetworking/cni v1.0.1/go.mod h1:AKuhXbN5EzmD4yTNtfSsX3tPcmtrBI6QcRV0NiNt15Y=
github.com/containernetworking/plugins v0.8.6/go.mod h1:qnw5mN19D8fIwkqW7oHHYDHVlzhJpcY6TQxn/fUyDDM=
Expand Down Expand Up @@ -375,8 +373,6 @@ github.com/imdario/mergo v0.3.10/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA=
github.com/j-keck/arping v1.0.2 h1:hlLhuXgQkzIJTZuhMigvG/CuSkaspeaD9hRDk2zuiMI=
github.com/j-keck/arping v1.0.2/go.mod h1:aJbELhR92bSk7tp79AWM/ftfc90EfEi2bQJrbBFOsPw=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
Expand Down
9 changes: 2 additions & 7 deletions pkg/ip/link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ var (
func makeVethPair(name, peer string, mtu int, mac string, hostNS ns.NetNS) (netlink.Link, error) {
veth := &netlink.Veth{
LinkAttrs: netlink.LinkAttrs{
Name: name,
Flags: net.FlagUp,
MTU: mtu,
Name: name,
MTU: mtu,
},
PeerName: peer,
PeerNamespace: netlink.NsFd(int(hostNS.Fd())),
Expand Down Expand Up @@ -146,10 +145,6 @@ func SetupVethWithName(contVethName, hostVethName string, mtu int, contVethMac s
return net.Interface{}, net.Interface{}, err
}

if err = netlink.LinkSetUp(contVeth); err != nil {
return net.Interface{}, net.Interface{}, fmt.Errorf("failed to set %q up: %v", contVethName, err)
}

var hostVeth netlink.Link
err = hostNS.Do(func(_ ns.NetNS) error {
hostVeth, err = netlink.LinkByName(hostVethName)
Expand Down
8 changes: 4 additions & 4 deletions pkg/ipam/ipam_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ func ConfigureIface(ifName string, res *current.Result) error {
return fmt.Errorf("failed to lookup %q: %v", ifName, err)
}

if err := netlink.LinkSetUp(link); err != nil {
return fmt.Errorf("failed to set %q UP: %v", ifName, err)
}

var v4gw, v6gw net.IP
var has_enabled_ipv6 bool = false
for _, ipc := range res.IPs {
Expand Down Expand Up @@ -99,6 +95,10 @@ func ConfigureIface(ifName string, res *current.Result) error {
}
}

if err := netlink.LinkSetUp(link); err != nil {
return fmt.Errorf("failed to set %q UP: %v", ifName, err)
}

if v6gw != nil {
ip.SettleAddresses(ifName, 10)
}
Expand Down
39 changes: 21 additions & 18 deletions plugins/main/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"syscall"
"time"

"github.com/j-keck/arping"
"github.com/vishvananda/netlink"

"github.com/containernetworking/cni/pkg/skel"
Expand Down Expand Up @@ -324,6 +323,11 @@ func ensureVlanInterface(br *netlink.Bridge, vlanId int) (netlink.Link, error) {
if err != nil {
return nil, fmt.Errorf("failed to lookup %q: %v", brGatewayIface.Name, err)
}

err = netlink.LinkSetUp(brGatewayVeth)
if err != nil {
return nil, fmt.Errorf("failed to up %q: %v", brGatewayIface.Name, err)
}
}

return brGatewayVeth, nil
Expand Down Expand Up @@ -524,6 +528,8 @@ func cmdAdd(args *skel.CmdArgs) error {
}
}

_, _ = sysctl.Sysctl(fmt.Sprintf("net/ipv4/conf/%s/arp_notify", args.IfName), "1")

// Add the IP to the interface
if err := ipam.ConfigureIface(args.IfName, result); err != nil {
return err
Expand Down Expand Up @@ -551,23 +557,6 @@ func cmdAdd(args *skel.CmdArgs) error {
}
}

// Send a gratuitous arp
if err := netns.Do(func(_ ns.NetNS) error {
contVeth, err := net.InterfaceByName(args.IfName)
if err != nil {
return err
}

for _, ipc := range result.IPs {
if ipc.Address.IP.To4() != nil {
_ = arping.GratuitousArpOverIface(ipc.Address.IP, *contVeth)
}
}
return nil
}); err != nil {
return err
}

if n.IsGW {
var firstV4Addr net.IP
var vlanInterface *current.Interface
Expand Down Expand Up @@ -618,6 +607,20 @@ func cmdAdd(args *skel.CmdArgs) error {
}
}
}
} else {
if err := netns.Do(func(_ ns.NetNS) error {
link, err := netlink.LinkByName(args.IfName)
if err != nil {
return fmt.Errorf("failed to retrieve link: %v", err)
}
// If layer 2 we still need to set the container veth to up
if err = netlink.LinkSetUp(link); err != nil {
return fmt.Errorf("failed to set %q up: %v", args.IfName, err)
}
return nil
}); err != nil {
return err
}
}

// Refetch the bridge since its MAC address may change when the first
Expand Down
4 changes: 2 additions & 2 deletions plugins/main/bridge/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (

"github.com/containernetworking/cni/pkg/skel"
"github.com/containernetworking/cni/pkg/types"
"github.com/containernetworking/cni/pkg/types/040"
"github.com/containernetworking/cni/pkg/types/100"
types040 "github.com/containernetworking/cni/pkg/types/040"
types100 "github.com/containernetworking/cni/pkg/types/100"
"github.com/containernetworking/plugins/pkg/ip"
"github.com/containernetworking/plugins/pkg/ns"
"github.com/containernetworking/plugins/pkg/testutils"
Expand Down
16 changes: 3 additions & 13 deletions plugins/main/ipvlan/ipvlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"runtime"

"github.com/j-keck/arping"
"github.com/vishvananda/netlink"

"github.com/containernetworking/cni/pkg/skel"
Expand All @@ -33,6 +31,7 @@ import (
"github.com/containernetworking/plugins/pkg/ipam"
"github.com/containernetworking/plugins/pkg/ns"
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
"github.com/containernetworking/plugins/pkg/utils/sysctl"
)

type NetConf struct {
Expand Down Expand Up @@ -256,20 +255,11 @@ func cmdAdd(args *skel.CmdArgs) error {
result.Interfaces = []*current.Interface{ipvlanInterface}

err = netns.Do(func(_ ns.NetNS) error {
_, _ = sysctl.Sysctl(fmt.Sprintf("net/ipv4/conf/%s/arp_notify", args.IfName), "1")

if err := ipam.ConfigureIface(args.IfName, result); err != nil {
return err
}

contVeth, err := net.InterfaceByName(args.IfName)
if err != nil {
return fmt.Errorf("failed to look up %q: %v", args.IfName, err)
}

for _, ipc := range result.IPs {
if ipc.Address.IP.To4() != nil {
_ = arping.GratuitousArpOverIface(ipc.Address.IP, *contVeth)
}
}
return nil
})
if err != nil {
Expand Down
15 changes: 3 additions & 12 deletions plugins/main/macvlan/macvlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"net"
"runtime"

"github.com/j-keck/arping"
"github.com/vishvananda/netlink"

"github.com/containernetworking/cni/pkg/skel"
Expand All @@ -33,6 +32,7 @@ import (
"github.com/containernetworking/plugins/pkg/ipam"
"github.com/containernetworking/plugins/pkg/ns"
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
"github.com/containernetworking/plugins/pkg/utils/sysctl"
)

type NetConf struct {
Expand Down Expand Up @@ -294,20 +294,11 @@ func cmdAdd(args *skel.CmdArgs) error {
}

err = netns.Do(func(_ ns.NetNS) error {
_, _ = sysctl.Sysctl(fmt.Sprintf("net/ipv4/conf/%s/arp_notify", args.IfName), "1")

if err := ipam.ConfigureIface(args.IfName, result); err != nil {
return err
}

contVeth, err := net.InterfaceByName(args.IfName)
if err != nil {
return fmt.Errorf("failed to look up %q: %v", args.IfName, err)
}

for _, ipc := range result.IPs {
if ipc.Address.IP.To4() != nil {
_ = arping.GratuitousArpOverIface(ipc.Address.IP, *contVeth)
}
}
return nil
})
if err != nil {
Expand Down
16 changes: 4 additions & 12 deletions plugins/main/ptp/ptp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os"
"runtime"

"github.com/j-keck/arping"
"github.com/vishvananda/netlink"

"github.com/containernetworking/cni/pkg/skel"
Expand Down Expand Up @@ -83,15 +82,15 @@ func setupContainerVeth(netns ns.NetNS, ifName string, mtu int, pr *current.Resu

pr.Interfaces = []*current.Interface{hostInterface, containerInterface}

if err = ipam.ConfigureIface(ifName, pr); err != nil {
return err
}

contVeth, err := net.InterfaceByName(ifName)
if err != nil {
return fmt.Errorf("failed to look up %q: %v", ifName, err)
}

if err = ipam.ConfigureIface(ifName, pr); err != nil {
return err
}

for _, ipc := range pr.IPs {
// Delete the route that was automatically added
route := netlink.Route{
Expand Down Expand Up @@ -139,13 +138,6 @@ func setupContainerVeth(netns ns.NetNS, ifName string, mtu int, pr *current.Resu
}
}

// Send a gratuitous arp for all v4 addresses
for _, ipc := range pr.IPs {
if ipc.Address.IP.To4() != nil {
_ = arping.GratuitousArpOverIface(ipc.Address.IP, *contVeth)
}
}

return nil
})
if err != nil {
Expand Down
12 changes: 0 additions & 12 deletions plugins/meta/tuning/tuning.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"path/filepath"
"strings"

"github.com/j-keck/arping"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"

Expand Down Expand Up @@ -315,11 +314,6 @@ func cmdAdd(args *skel.CmdArgs) error {
return err
}

result, err := current.NewResultFromResult(tuningConf.PrevResult)
if err != nil {
return err
}

// The directory /proc/sys/net is per network namespace. Enter in the
// network namespace before writing on it.

Expand Down Expand Up @@ -355,12 +349,6 @@ func cmdAdd(args *skel.CmdArgs) error {
return err
}

for _, ipc := range result.IPs {
if ipc.Address.IP.To4() != nil {
_ = arping.GratuitousArpOverIfaceByName(ipc.Address.IP, args.IfName)
}
}

updateResultsMacAddr(tuningConf, args.IfName, tuningConf.Mac)
}

Expand Down
1 change: 0 additions & 1 deletion vendor/github.com/j-keck/arping/.gitignore

This file was deleted.

22 changes: 0 additions & 22 deletions vendor/github.com/j-keck/arping/LICENSE

This file was deleted.

31 changes: 0 additions & 31 deletions vendor/github.com/j-keck/arping/README.md

This file was deleted.

Loading