Skip to content

Commit

Permalink
[BPF] set MTU on bpfin/out.cali to match host
Browse files Browse the repository at this point in the history
Set the MTU to match the smallest MTU of the host devices as per the
current autodetection. That makes sure that if large MTU is used, the
extra device does not create a bottleneck with a small MTU. Also when
MTU changes, on host devices, it get adjusted automatically.

Fixes projectcalico#8918
  • Loading branch information
tomastigera committed Jun 18, 2024
1 parent 211f008 commit 622b6ff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions felix/dataplane/linux/bpf_ep_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ type bpfEndpointManager struct {

natInIdx int
natOutIdx int
hostMTU int

v4 *bpfEndpointManagerDataplane
v6 *bpfEndpointManagerDataplane
Expand Down Expand Up @@ -437,6 +438,7 @@ func NewTestEpMgr(
new(environment.FakeFeatureDetector),
nil,
nil,
1500,
)
}

Expand All @@ -456,6 +458,7 @@ func newBPFEndpointManager(
featureDetector environment.FeatureDetectorIface,
healthAggregator *health.HealthAggregator,
dataplanefeatures *environment.Features,
hostMTU int,
) (*bpfEndpointManager, error) {
if livenessCallback == nil {
livenessCallback = func() {}
Expand Down Expand Up @@ -623,6 +626,7 @@ func newBPFEndpointManager(
}
}

m.hostMTU = hostMTU
if err := m.dp.ensureBPFDevices(); err != nil {
return nil, fmt.Errorf("ensure BPF devices: %w", err)
} else {
Expand Down Expand Up @@ -3192,6 +3196,7 @@ func (m *bpfEndpointManager) ensureBPFDevices() error {
if err != nil {
la := netlink.NewLinkAttrs()
la.Name = bpfInDev
la.MTU = m.hostMTU
nat := &netlink.Veth{
LinkAttrs: la,
PeerName: bpfOutDev,
Expand All @@ -3204,6 +3209,7 @@ func (m *bpfEndpointManager) ensureBPFDevices() error {
return fmt.Errorf("missing %s after add: %w", bpfInDev, err)
}
}

if state := bpfin.Attrs().OperState; state != netlink.OperUp {
log.WithField("state", state).Info(bpfInDev)
if err := netlink.LinkSetUp(bpfin); err != nil {
Expand All @@ -3221,6 +3227,15 @@ func (m *bpfEndpointManager) ensureBPFDevices() error {
}
}

err = netlink.LinkSetMTU(bpfin, m.hostMTU)
if err != nil {
return fmt.Errorf("failed to set MTU to %d on %s: %w", m.hostMTU, bpfInDev, err)
}
err = netlink.LinkSetMTU(bpfout, m.hostMTU)
if err != nil {
return fmt.Errorf("failed to set MTU to %d on %s: %w", m.hostMTU, bpfOutDev, err)
}

m.natInIdx = bpfin.Attrs().Index
m.natOutIdx = bpfout.Attrs().Index

Expand Down
1 change: 1 addition & 0 deletions felix/dataplane/linux/bpf_ep_mgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ var _ = Describe("BPF Endpoint Manager", func() {
&environment.FakeFeatureDetector{},
nil,
environment.NewFeatureDetector(nil).GetFeatures(),
1250,
)
Expect(err).NotTo(HaveOccurred())
bpfEpMgr.v4.hostIP = net.ParseIP("1.2.3.4")
Expand Down
1 change: 1 addition & 0 deletions felix/dataplane/linux/int_dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ func NewIntDataplaneDriver(config Config) *InternalDataplane {
featureDetector,
config.HealthAggregator,
dataplaneFeatures,
hostMTU,
)

if err != nil {
Expand Down

0 comments on commit 622b6ff

Please sign in to comment.