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

Netkit flex #9435

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
71 changes: 42 additions & 29 deletions cni-plugin/pkg/dataplane/linux/dataplane_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,25 @@ func (d *linuxDataplane) DoWorkloadNetnsSetUp(

err = ns.WithNetNSPath(netnsPath, func(hostNS ns.NetNS) error {
la := netlink.NewLinkAttrs()
la.Name = contVethName
la.Name = hostVethName
la.MTU = d.mtu
la.NumTxQueues = d.queues
la.NumRxQueues = d.queues
veth := &netlink.Veth{
LinkAttrs: la,
PeerName: hostVethName,
PeerNamespace: netlink.NsFd(int(hostNS.Fd())),
la.Namespace = netlink.NsFd(int(hostNS.Fd()))

veth := &netlink.Netkit{
LinkAttrs: la,
}

veth.Mode = netlink.NETKIT_MODE_L3
veth.Policy = netlink.NETKIT_POLICY_FORWARD

peer := netlink.NewLinkAttrs()
peer.Name = contVethName
peer.MTU = d.mtu
peer.NumTxQueues = d.queues
peer.NumRxQueues = d.queues
veth.SetPeerAttrs(&peer)
if err := netlink.LinkAdd(veth); err != nil {
d.logger.Errorf("Error adding veth %+v: %s", veth, err)
return err
Expand All @@ -145,13 +154,15 @@ func (d *linuxDataplane) DoWorkloadNetnsSetUp(
return err
}

if mac, err := net.ParseMAC("EE:EE:EE:EE:EE:EE"); err != nil {
d.logger.Infof("failed to parse MAC Address: %v. Using kernel generated MAC.", err)
} else {
// Set the MAC address on the host side interface so the kernel does not
// have to generate a persistent address which fails some times.
if err = hostNlHandle.LinkSetHardwareAddr(hostVeth, mac); err != nil {
d.logger.Warnf("failed to Set MAC of %q: %v. Using kernel generated MAC.", hostVethName, err)
if veth.Mode != netlink.NETKIT_MODE_L3 {
if mac, err := net.ParseMAC("EE:EE:EE:EE:EE:EE"); err != nil {
d.logger.Infof("failed to parse MAC Address: %v. Using kernel generated MAC.", err)
} else {
// Set the MAC address on the host side interface so the kernel does not
// have to generate a persistent address which fails some times.
if err = hostNlHandle.LinkSetHardwareAddr(hostVeth, mac); err != nil {
d.logger.Warnf("failed to Set MAC of %q: %v. Using kernel generated MAC.", hostVethName, err)
}
}
}

Expand Down Expand Up @@ -210,28 +221,30 @@ func (d *linuxDataplane) DoWorkloadNetnsSetUp(

// Check if there is an annotation requesting a specific fixed MAC address for the container Veth, otherwise
// use kernel-assigned MAC.
if requestedContVethMac, found := annotations["cni.projectcalico.org/hwAddr"]; found {
tmpContVethMAC, err := net.ParseMAC(requestedContVethMac)
if err != nil {
return fmt.Errorf("failed to parse MAC address %v provided via cni.projectcalico.org/hwAddr: %v",
requestedContVethMac, err)
}
if veth.Mode != netlink.NETKIT_MODE_L3 {
if requestedContVethMac, found := annotations["cni.projectcalico.org/hwAddr"]; found {
tmpContVethMAC, err := net.ParseMAC(requestedContVethMac)
if err != nil {
return fmt.Errorf("failed to parse MAC address %v provided via cni.projectcalico.org/hwAddr: %v",
requestedContVethMac, err)
}

err = netlink.LinkSetHardwareAddr(contVeth, tmpContVethMAC)
if err != nil {
return fmt.Errorf("failed to set container veth MAC to %v as requested via cni.projectcalico.org/hwAddr: %v",
requestedContVethMac, err)
err = netlink.LinkSetHardwareAddr(contVeth, tmpContVethMAC)
if err != nil {
return fmt.Errorf("failed to set container veth MAC to %v as requested via cni.projectcalico.org/hwAddr: %v",
requestedContVethMac, err)
}

contVethMAC = tmpContVethMAC.String()
d.logger.Infof("successfully configured container veth MAC to %v as requested via cni.projectcalico.org/hwAddr",
contVethMAC)
} else {
contVethMAC = contVeth.Attrs().HardwareAddr.String()
}

contVethMAC = tmpContVethMAC.String()
d.logger.Infof("successfully configured container veth MAC to %v as requested via cni.projectcalico.org/hwAddr",
contVethMAC)
} else {
contVethMAC = contVeth.Attrs().HardwareAddr.String()
d.logger.WithField("MAC", contVethMAC).Debug("Found MAC for container veth")
}

d.logger.WithField("MAC", contVethMAC).Debug("Found MAC for container veth")

// At this point, the virtual ethernet pair has been created, and both ends have the right names.

// Do the per-IP version set-up. Add gateway routes etc.
Expand Down
2 changes: 1 addition & 1 deletion felix/dataplane/linux/endpoint_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ func configureInterface(name string, ipVersion int, rpFilter string, writeProcSy
// means that we don't need to assign the link local address explicitly to each
// host side of the veth, which is one fewer thing to maintain and one fewer
// thing we may clash over.
err = writeProcSys(fmt.Sprintf("/proc/sys/net/ipv4/conf/%s/proxy_arp", name), "1")
err = writeProcSys(fmt.Sprintf("/proc/sys/net/ipv4/conf/%s/proxy_arp", name), "0")
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions felix/routerule/rule_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (r *Rule) markMatchesWithMask(mark, mask uint32) *Rule {
if mark&mask != mark {
logCxt.Panic("Bug: mark is not contained in mask")
}
r.nlRule.Mask = int(mask)
r.nlRule.Mark = int(mark)
r.nlRule.Mask = &mask
r.nlRule.Mark = mark

return r
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ require (
github.com/tchap/go-patricia/v2 v2.3.1
github.com/termie/go-shutil v0.0.0-20140729215957-bcacb06fecae
github.com/urfave/cli/v2 v2.27.3
github.com/vishvananda/netlink v1.2.1-beta.2.0.20240703200800-b54f85093f4a
github.com/vishvananda/netlink v1.3.1-0.20241022031324-976bd8de7d81
go.etcd.io/etcd/api/v3 v3.5.12
go.etcd.io/etcd/client/pkg/v3 v3.5.12
go.etcd.io/etcd/client/v2 v2.305.12
Expand Down
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,8 @@ github.com/urfave/cli v1.22.4 h1:u7tSpNPPswAFymm8IehJhy4uJMlUuU/GmqSkvJ1InXA=
github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.27.3 h1:/POWahRmdh7uztQ3CYnaDddk0Rm90PyOgIxgW2rr41M=
github.com/urfave/cli/v2 v2.27.3/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ=
github.com/vishvananda/netlink v1.2.1-beta.2.0.20240703200800-b54f85093f4a h1:n9iF7t9sLw43CwPLvPZkCfsFEGvoR2A63W8OEjuQqJ4=
github.com/vishvananda/netlink v1.2.1-beta.2.0.20240703200800-b54f85093f4a/go.mod h1:whJevzBpTrid75eZy99s3DqCmy05NfibNaF2Ol5Ox5A=
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/vishvananda/netlink v1.3.1-0.20241022031324-976bd8de7d81 h1:9fkQcQYvtTr9ayFXuMfDMVuDt4+BYG9FwsGLnrBde0M=
github.com/vishvananda/netlink v1.3.1-0.20241022031324-976bd8de7d81/go.mod h1:i6NetklAujEcC6fK0JPjT8qSwWyO0HLn4UKG+hGqeJs=
github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8=
github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
Expand Down Expand Up @@ -936,7 +935,6 @@ golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -976,6 +974,7 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
Expand Down