Skip to content

Commit

Permalink
Merge branch 'main' into pass-status-along-ipam-update
Browse files Browse the repository at this point in the history
  • Loading branch information
LionelJouin committed Aug 30, 2024
2 parents 5eaeb9d + 20f31e5 commit 044df64
Show file tree
Hide file tree
Showing 277 changed files with 9,111 additions and 13,526 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
name: test

on: ["push", "pull_request"]
on:
pull_request: {}

env:
# be sure to update the version in release.yaml too
GO_VERSION: "1.22"
LINUX_ARCHES: "amd64 386 arm arm64 s390x mips64le ppc64le riscv64"

Expand All @@ -16,7 +18,7 @@ jobs:
- name: setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
go-version: ${{ env.GO_VERSION }}
- uses: ibiqlik/action-yamllint@v3
with:
format: auto
Expand All @@ -34,7 +36,7 @@ jobs:
- name: setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
go-version: ${{ env.GO_VERSION }}
- name: Build on all supported architectures
run: |
set -e
Expand All @@ -58,7 +60,7 @@ jobs:
- name: setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
go-version: ${{ env.GO_VERSION }}
- name: Set up Go for root
run: |
sudo ln -sf `which go` `sudo which go` || true
Expand Down Expand Up @@ -89,6 +91,6 @@ jobs:
- name: setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
go-version: ${{ env.GO_VERSION }}
- name: test
run: bash ./test_windows.sh
34 changes: 17 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,46 @@ module github.com/containernetworking/plugins
go 1.21

require (
github.com/Microsoft/hcsshim v0.12.4
github.com/Microsoft/hcsshim v0.12.6
github.com/alexflint/go-filemutex v1.3.0
github.com/buger/jsonparser v1.1.1
github.com/containernetworking/cni v1.2.2
github.com/coreos/go-iptables v0.7.0
github.com/containernetworking/cni v1.2.3
github.com/coreos/go-iptables v0.8.0
github.com/coreos/go-systemd/v22 v22.5.0
github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c
github.com/d2g/dhcp4client v1.0.0
github.com/d2g/dhcp4server v0.0.0-20181031114812-7d4a0a7f59a5
github.com/godbus/dbus/v5 v5.1.0
github.com/mattn/go-shellwords v1.0.12
github.com/networkplumbing/go-nft v0.4.0
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
github.com/onsi/ginkgo/v2 v2.20.1
github.com/onsi/gomega v1.34.1
github.com/opencontainers/selinux v1.11.0
github.com/safchain/ethtool v0.4.1
github.com/vishvananda/netlink v1.2.1-beta.2
golang.org/x/sys v0.21.0
github.com/vishvananda/netlink v1.3.0
golang.org/x/sys v0.23.0
)

require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/containerd/cgroups/v3 v3.0.2 // indirect
github.com/containerd/cgroups/v3 v3.0.3 // indirect
github.com/containerd/errdefs v0.1.0 // indirect
github.com/d2g/hardwareaddr v0.0.0-20190221164911-e7d9fbe030e4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 // indirect
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/tools v0.24.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
76 changes: 36 additions & 40 deletions go.sum

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions pkg/ip/route_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ func AddDefaultRoute(gw net.IP, dev netlink.Link) error {
}
return AddRoute(defNet, gw, dev)
}

// IsIPNetZero check if the IPNet is "0.0.0.0/0" or "::/0"
// This is needed as go-netlink replaces nil Dst with a '0' IPNet since
// https://github.com/vishvananda/netlink/commit/acdc658b8613655ddb69f978e9fb4cf413e2b830
func IsIPNetZero(ipnet *net.IPNet) bool {
if ipnet == nil {
return true
}
if ones, _ := ipnet.Mask.Size(); ones != 0 {
return false
}
return ipnet.IP.Equal(net.IPv4zero) || ipnet.IP.Equal(net.IPv6zero)
}
4 changes: 2 additions & 2 deletions pkg/utils/conntrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func DeleteConntrackEntriesForDstIP(dstIP string, protocol uint8) error {
filter.AddIP(netlink.ConntrackOrigDstIP, ip)
filter.AddProtocol(protocol)

_, err := netlink.ConntrackDeleteFilter(netlink.ConntrackTable, family, filter)
_, err := netlink.ConntrackDeleteFilters(netlink.ConntrackTable, family, filter)
if err != nil {
return fmt.Errorf("error deleting connection tracking state for protocol: %d IP: %s, error: %v", protocol, ip, err)
}
Expand All @@ -65,7 +65,7 @@ func DeleteConntrackEntriesForDstPort(port uint16, protocol uint8, family netlin
filter.AddProtocol(protocol)
filter.AddPort(netlink.ConntrackOrigDstPort, port)

_, err := netlink.ConntrackDeleteFilter(netlink.ConntrackTable, family, filter)
_, err := netlink.ConntrackDeleteFilters(netlink.ConntrackTable, family, filter)
if err != nil {
return fmt.Errorf("error deleting connection tracking state for protocol: %d Port: %d, error: %v", protocol, port, err)
}
Expand Down
14 changes: 7 additions & 7 deletions plugins/ipam/dhcp/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,19 @@ func (l *DHCPLease) getAllOptions() dhcp4.Options {
}

func (l *DHCPLease) acquire() error {
c, err := newDHCPClient(l.link, l.timeout, l.broadcast)
if err != nil {
return err
}
defer c.Close()

if (l.link.Attrs().Flags & net.FlagUp) != net.FlagUp {
log.Printf("Link %q down. Attempting to set up", l.link.Attrs().Name)
if err = netlink.LinkSetUp(l.link); err != nil {
if err := netlink.LinkSetUp(l.link); err != nil {
return err
}
}

c, err := newDHCPClient(l.link, l.timeout, l.broadcast)
if err != nil {
return err
}
defer c.Close()

opts := l.getAllOptions()

pkt, err := backoffRetry(l.resendMax, func() (*dhcp4.Packet, error) {
Expand Down
2 changes: 2 additions & 0 deletions plugins/ipam/dhcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ func main() {
Add: cmdAdd,
Check: cmdCheck,
Del: cmdDel,
/* FIXME GC */
/* FIXME Status */
}, version.All, bv.BuildString("dhcp"))
}
}
Expand Down
2 changes: 2 additions & 0 deletions plugins/ipam/host-local/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func main() {
Add: cmdAdd,
Check: cmdCheck,
Del: cmdDel,
/* FIXME GC */
/* FIXME Status */
}, version.All, bv.BuildString("host-local"))
}

Expand Down
2 changes: 2 additions & 0 deletions plugins/ipam/static/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func main() {
Add: cmdAdd,
Check: cmdCheck,
Del: cmdDel,
/* FIXME GC */
/* FIXME Status */
}, version.All, bv.BuildString("static"))
}

Expand Down
1 change: 1 addition & 0 deletions plugins/main/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ func main() {
Check: cmdCheck,
Del: cmdDel,
Status: cmdStatus,
/* FIXME GC */
}, version.All, bv.BuildString("bridge"))
}

Expand Down
12 changes: 6 additions & 6 deletions plugins/main/bridge/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ func (tester *testerV10x) cmdAddTest(tc testCase, dataDir string) (types.Result,
continue
}
for _, route := range routes {
*found = (route.Dst == nil && route.Src == nil && route.Gw.Equal(gwIP))
*found = (ip.IsIPNetZero(route.Dst) && route.Src == nil && route.Gw.Equal(gwIP))
if *found {
break
}
Expand Down Expand Up @@ -814,7 +814,7 @@ func (tester *testerV10x) cmdCheckTest(tc testCase, conf *Net, _ string) {
continue
}
for _, route := range routes {
*found = (route.Dst == nil && route.Src == nil && route.Gw.Equal(gwIP))
*found = (ip.IsIPNetZero(route.Dst) && route.Src == nil && route.Gw.Equal(gwIP))
if *found {
break
}
Expand Down Expand Up @@ -1064,7 +1064,7 @@ func (tester *testerV04x) cmdAddTest(tc testCase, dataDir string) (types.Result,
continue
}
for _, route := range routes {
*found = (route.Dst == nil && route.Src == nil && route.Gw.Equal(gwIP))
*found = (ip.IsIPNetZero(route.Dst) && route.Src == nil && route.Gw.Equal(gwIP))
if *found {
break
}
Expand Down Expand Up @@ -1148,7 +1148,7 @@ func (tester *testerV04x) cmdCheckTest(tc testCase, conf *Net, _ string) {
continue
}
for _, route := range routes {
*found = (route.Dst == nil && route.Src == nil && route.Gw.Equal(gwIP))
*found = (ip.IsIPNetZero(route.Dst) && route.Src == nil && route.Gw.Equal(gwIP))
if *found {
break
}
Expand Down Expand Up @@ -1396,7 +1396,7 @@ func (tester *testerV03x) cmdAddTest(tc testCase, dataDir string) (types.Result,
continue
}
for _, route := range routes {
*found = (route.Dst == nil && route.Src == nil && route.Gw.Equal(gwIP))
*found = (ip.IsIPNetZero(route.Dst) && route.Src == nil && route.Gw.Equal(gwIP))
if *found {
break
}
Expand Down Expand Up @@ -1625,7 +1625,7 @@ func (tester *testerV01xOr02x) cmdAddTest(tc testCase, dataDir string) (types.Re
continue
}
for _, route := range routes {
*found = (route.Dst == nil && route.Src == nil && route.Gw.Equal(gwIP))
*found = (ip.IsIPNetZero(route.Dst) && route.Src == nil && route.Gw.Equal(gwIP))
if *found {
break
}
Expand Down
1 change: 1 addition & 0 deletions plugins/main/dummy/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func main() {
Check: cmdCheck,
Del: cmdDel,
Status: cmdStatus,
/* FIXME GC */
}, version.All, bv.BuildString("dummy"))
}

Expand Down
1 change: 1 addition & 0 deletions plugins/main/host-device/host-device.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ func main() {
Check: cmdCheck,
Del: cmdDel,
Status: cmdStatus,
/* FIXME GC */
}, version.All, bv.BuildString("host-device"))
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/main/ipvlan/ipvlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func getDefaultRouteInterfaceName() (string, error) {
}

for _, v := range routeToDstIP {
if v.Dst == nil {
if ip.IsIPNetZero(v.Dst) {
l, err := netlink.LinkByIndex(v.LinkIndex)
if err != nil {
return "", err
Expand Down Expand Up @@ -354,6 +354,7 @@ func main() {
Check: cmdCheck,
Del: cmdDel,
Status: cmdStatus,
/* FIXME GC */
}, version.All, bv.BuildString("ipvlan"))
}

Expand Down
13 changes: 7 additions & 6 deletions plugins/main/loopback/loopback.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@ func cmdDel(args *skel.CmdArgs) error {
}

func main() {
skel.PluginMainFuncs(
skel.CNIFuncs{
Add: cmdAdd,
Check: cmdCheck,
Del: cmdDel,
}, version.All, bv.BuildString("loopback"))
skel.PluginMainFuncs(skel.CNIFuncs{
Add: cmdAdd,
Check: cmdCheck,
Del: cmdDel,
/* FIXME GC */
/* FIXME Status */
}, version.All, bv.BuildString("loopback"))
}

func cmdCheck(args *skel.CmdArgs) error {
Expand Down
3 changes: 2 additions & 1 deletion plugins/main/loopback/loopback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ var _ = Describe("Loopback", func() {
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

Eventually(session).Should(gbytes.Say(`.+`))
// "(?s)" turns on the "s" flag, making "." match newlines too.
Eventually(session).Should(gbytes.Say(`(?s){.*}`))
Eventually(session).Should(gexec.Exit(0))

var lo *net.Interface
Expand Down
6 changes: 5 additions & 1 deletion plugins/main/macvlan/macvlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type NetConf struct {
MTU int `json:"mtu"`
Mac string `json:"mac,omitempty"`
LinkContNs bool `json:"linkInContainer,omitempty"`
BcQueueLen uint32 `json:"bcqueuelen,omitempty"`

RuntimeConfig struct {
Mac string `json:"mac,omitempty"`
Expand All @@ -67,7 +68,7 @@ func getDefaultRouteInterfaceName() (string, error) {
}

for _, v := range routeToDstIP {
if v.Dst == nil {
if ip.IsIPNetZero(v.Dst) {
l, err := netlink.LinkByIndex(v.LinkIndex)
if err != nil {
return "", err
Expand Down Expand Up @@ -245,6 +246,8 @@ func createMacvlan(conf *NetConf, ifName string, netns ns.NetNS) (*current.Inter
Mode: mode,
}

mv.BCQueueLen = conf.BcQueueLen

if conf.LinkContNs {
err = netns.Do(func(_ ns.NetNS) error {
return netlink.LinkAdd(mv)
Expand Down Expand Up @@ -431,6 +434,7 @@ func main() {
Check: cmdCheck,
Del: cmdDel,
Status: cmdStatus,
/* FIXME GC */
}, version.All, bv.BuildString("macvlan"))
}

Expand Down
1 change: 1 addition & 0 deletions plugins/main/ptp/ptp.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ func main() {
Check: cmdCheck,
Del: cmdDel,
Status: cmdStatus,
/* FIXME GC */
}, version.All, bv.BuildString("ptp"))
}

Expand Down
1 change: 1 addition & 0 deletions plugins/main/tap/tap.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ func main() {
Check: cmdCheck,
Del: cmdDel,
Status: cmdStatus,
/* FIXME GC */
}, version.All, bv.BuildString("tap"))
}

Expand Down
1 change: 1 addition & 0 deletions plugins/main/vlan/vlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func main() {
Check: cmdCheck,
Del: cmdDel,
Status: cmdStatus,
/* FIXME GC */
}, version.All, bv.BuildString("vlan"))
}

Expand Down
1 change: 1 addition & 0 deletions plugins/main/windows/win-bridge/win-bridge_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func main() {
Check: cmdCheck,
Del: cmdDel,
Status: cmdStatus,
/* FIXME GC */
}, version.All, bv.BuildString("win-bridge"))
}

Expand Down
1 change: 1 addition & 0 deletions plugins/main/windows/win-overlay/win-overlay_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ func main() {
Check: cmdCheck,
Del: cmdDel,
Status: cmdStatus,
/* FIXME GC */
}, version.All, bv.BuildString("win-overlay"))
}

Expand Down
Loading

0 comments on commit 044df64

Please sign in to comment.