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

cilium: Repoint netlink lib back to upstream. #26359

Merged
merged 2 commits into from
Jun 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/tidwall/gjson v1.14.4
github.com/tidwall/sjson v1.2.5
github.com/vishvananda/netlink v1.2.1-beta.2.0.20230420174744-55c8b9515a01
github.com/vishvananda/netlink v1.2.1-beta.2.0.20230616155239-a8a91c050431
github.com/vishvananda/netns v0.0.4
go.etcd.io/etcd/api/v3 v3.5.9
go.etcd.io/etcd/client/pkg/v3 v3.5.9
Expand Down Expand Up @@ -271,5 +271,3 @@ replace (
// as to why we are using a private fork.
sigs.k8s.io/controller-tools => github.com/cilium/controller-tools v0.6.2
)

replace github.com/vishvananda/netlink => github.com/cilium/netlink v1.0.1-0.20230616101939-19dab5b7a180
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions pkg/datapath/linux/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/vishvananda/netns"
"golang.org/x/sys/unix"

"github.com/cilium/cilium/pkg/cidr"
"github.com/cilium/cilium/pkg/datapath/linux/probes"
"github.com/cilium/cilium/pkg/defaults"
"github.com/cilium/cilium/pkg/lock"
Expand Down Expand Up @@ -257,6 +258,22 @@ type linkInfo struct {
hasDefaultRoute bool
}

func genZeroNet(family int) *net.IPNet {
switch family {
case netlink.FAMILY_V4:
return &net.IPNet{
IP: net.IPv4zero,
Mask: net.CIDRMask(0, 8*net.IPv4len),
}
case netlink.FAMILY_V6:
return &net.IPNet{
IP: net.IPv6zero,
Mask: net.CIDRMask(0, 8*net.IPv6len),
}
}
return nil
}

// updateDevicesFromRoutes processes a batch of routes and updates the set of
// devices. Returns true if devices changed.
func (dm *DeviceManager) updateDevicesFromRoutes(l3DevOK bool, routes []netlink.Route) bool {
Expand All @@ -266,11 +283,11 @@ func (dm *DeviceManager) updateDevicesFromRoutes(l3DevOK bool, routes []netlink.
for _, route := range routes {
// Only consider devices that have global unicast routes,
// e.g. skip loopback, multicast.
if route.Dst != nil && !route.Dst.IP.IsGlobalUnicast() {
if !cidr.Equal(route.Dst, genZeroNet(route.Family)) && !route.Dst.IP.IsGlobalUnicast() {
continue
}
linkInfo := linkInfos[route.LinkIndex]
linkInfo.hasDefaultRoute = linkInfo.hasDefaultRoute || route.Dst == nil
linkInfo.hasDefaultRoute = linkInfo.hasDefaultRoute || cidr.Equal(route.Dst, genZeroNet(route.Family))
linkInfos[route.LinkIndex] = linkInfo
}

Expand Down
45 changes: 45 additions & 0 deletions vendor/github.com/vishvananda/netlink/route_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ github.com/tklauser/go-sysconf
# github.com/tklauser/numcpus v0.6.0
## explicit; go 1.13
github.com/tklauser/numcpus
# github.com/vishvananda/netlink v1.2.1-beta.2.0.20230420174744-55c8b9515a01 => github.com/cilium/netlink v1.0.1-0.20230616101939-19dab5b7a180
# github.com/vishvananda/netlink v1.2.1-beta.2.0.20230616155239-a8a91c050431
## explicit; go 1.12
github.com/vishvananda/netlink
github.com/vishvananda/netlink/nl
Expand Down Expand Up @@ -1833,4 +1833,3 @@ sigs.k8s.io/yaml
# go.universe.tf/metallb => github.com/cilium/metallb v0.1.1-0.20220829170633-5d7dfb1129f7
# k8s.io/client-go => github.com/cilium/client-go v0.27.2-fix
# sigs.k8s.io/controller-tools => github.com/cilium/controller-tools v0.6.2
# github.com/vishvananda/netlink => github.com/cilium/netlink v1.0.1-0.20230616101939-19dab5b7a180