Skip to content

Commit

Permalink
datapath: Only make ETH_HLEN as static data if L3 dev exist
Browse files Browse the repository at this point in the history
This should eliminate a datapath perf penalty introduced by the L2-less
changes when running on systems which all involved devices have L2
addrs.

Signed-off-by: Martynas Pumputis <m@lambda.lt>
  • Loading branch information
brb committed Mar 3, 2021
1 parent 76cd0f2 commit 678db1b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
16 changes: 2 additions & 14 deletions daemon/cmd/kube_proxy_replacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/cilium/cilium/pkg/datapath/loader"
datapathOption "github.com/cilium/cilium/pkg/datapath/option"
"github.com/cilium/cilium/pkg/logging/logfields"
"github.com/cilium/cilium/pkg/mac"
"github.com/cilium/cilium/pkg/maglev"
"github.com/cilium/cilium/pkg/node"
"github.com/cilium/cilium/pkg/option"
Expand Down Expand Up @@ -434,7 +435,7 @@ func finishKubeProxyReplacementInit(isKubeProxyReplacementStrict bool) {
case (option.Config.EnableIPv4Masquerade || option.Config.EnableIPv6Masquerade) &&
!option.Config.EnableBPFMasquerade:
msg = fmt.Sprintf("BPF host routing requires %s.", option.EnableBPFMasquerade)
case !hasHardwareAddress():
case !mac.HaveMACAddr(option.Config.Devices):
msg = fmt.Sprintf("BPF host routing is currently not supported with devices without L2 addr.")
default:
probesManager := probes.NewProbeManager()
Expand Down Expand Up @@ -728,16 +729,3 @@ func hasFullHostReachableServices() bool {
option.Config.EnableHostServicesTCP &&
option.Config.EnableHostServicesUDP
}

func hasHardwareAddress() bool {
for _, iface := range option.Config.Devices {
iface, err := netlink.LinkByName(iface)
if err != nil {
return false
}
if len(iface.Attrs().HardwareAddr) == 0 {
return false
}
}
return true
}
7 changes: 5 additions & 2 deletions pkg/datapath/linux/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,11 @@ func (h *HeaderfileWriter) writeStaticData(fw io.Writer, e datapath.EndpointConf
fmt.Fprint(fw, defineUint32("SECCTX_FROM_IPCACHE", 1))
fmt.Fprint(fw, defineUint32("HOST_EP_ID", uint32(e.GetID())))

// L2 hdr len (for L2-less devices it will be replaced with "0")
fmt.Fprint(fw, defineUint32("ETH_HLEN", mac.EthHdrLen))
// Use templating for ETH_HLEN only if there is any L2-less device
if !mac.HaveMACAddr(option.Config.Devices) {
// L2 hdr len (for L2-less devices it will be replaced with "0")
fmt.Fprint(fw, defineUint32("ETH_HLEN", mac.EthHdrLen))
}
} else {
// We want to ensure that the template BPF program always has "LXC_IP"
// defined and present as a symbol in the resulting object file after
Expand Down
16 changes: 16 additions & 0 deletions pkg/mac/mac.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"encoding/hex"
"fmt"
"net"

"github.com/vishvananda/netlink"
)

// Untagged ethernet (IEEE 802.3) frame header len
Expand Down Expand Up @@ -109,3 +111,17 @@ func GenerateRandMAC() (MAC, error) {

return MAC(buf), nil
}

// HaveMACAddr return true if all given network interfaces have L2 addr.
func HaveMACAddr(ifaces []string) bool {
for _, iface := range ifaces {
iface, err := netlink.LinkByName(iface)
if err != nil {
return false
}
if len(iface.Attrs().HardwareAddr) == 0 {
return false
}
}
return true
}

0 comments on commit 678db1b

Please sign in to comment.