Skip to content

Commit 4ac634f

Browse files
committed
Make disabling TX checksum for Antrea gateway
This is a supplement to PR #3832. When `disableTXChecksumOffload` is true, TX checksum offload should be also disabled, otherwise for the cases in which the datapath doesn't support TX checksum offloading, packets received on Antrea gateway could be dropped due to bad checksum. Signed-off-by: Hongliang Liu <[email protected]>
1 parent 0aad945 commit 4ac634f

File tree

5 files changed

+87
-39
lines changed

5 files changed

+87
-39
lines changed

cmd/antrea-agent/agent.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ func run(o *Options) error {
236236
stopCh,
237237
features.DefaultFeatureGate.Enabled(features.AntreaProxy),
238238
o.config.AntreaProxy.ProxyAll,
239-
connectUplinkToBridge)
239+
connectUplinkToBridge,
240+
o.config.DisableTXChecksumOffload)
240241
err = agentInitializer.Initialize()
241242
if err != nil {
242243
return fmt.Errorf("error initializing agent: %v", err)

pkg/agent/agent.go

+47-33
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"antrea.io/antrea/pkg/agent/route"
4545
"antrea.io/antrea/pkg/agent/types"
4646
"antrea.io/antrea/pkg/agent/util"
47+
"antrea.io/antrea/pkg/agent/util/ethtool"
4748
"antrea.io/antrea/pkg/agent/wireguard"
4849
"antrea.io/antrea/pkg/features"
4950
"antrea.io/antrea/pkg/ovs/ovsconfig"
@@ -81,22 +82,23 @@ var otherConfigKeysForIPsecCertificates = []string{"certificate", "private_key",
8182

8283
// Initializer knows how to setup host networking, OpenVSwitch, and Openflow.
8384
type Initializer struct {
84-
client clientset.Interface
85-
ovsBridgeClient ovsconfig.OVSBridgeClient
86-
ofClient openflow.Client
87-
routeClient route.Interface
88-
wireGuardClient wireguard.Interface
89-
ifaceStore interfacestore.InterfaceStore
90-
ovsBridge string
91-
hostGateway string // name of gateway port on the OVS bridge
92-
mtu int
93-
networkConfig *config.NetworkConfig
94-
nodeConfig *config.NodeConfig
95-
wireGuardConfig *config.WireGuardConfig
96-
egressConfig *config.EgressConfig
97-
serviceConfig *config.ServiceConfig
98-
enableProxy bool
99-
connectUplinkToBridge bool
85+
client clientset.Interface
86+
ovsBridgeClient ovsconfig.OVSBridgeClient
87+
ofClient openflow.Client
88+
routeClient route.Interface
89+
wireGuardClient wireguard.Interface
90+
ifaceStore interfacestore.InterfaceStore
91+
ovsBridge string
92+
hostGateway string // name of gateway port on the OVS bridge
93+
mtu int
94+
networkConfig *config.NetworkConfig
95+
nodeConfig *config.NodeConfig
96+
wireGuardConfig *config.WireGuardConfig
97+
egressConfig *config.EgressConfig
98+
serviceConfig *config.ServiceConfig
99+
enableProxy bool
100+
connectUplinkToBridge bool
101+
disableTXChecksumOffload bool
100102
// networkReadyCh should be closed once the Node's network is ready.
101103
// The CNI server will wait for it before handling any CNI Add requests.
102104
proxyAll bool
@@ -122,25 +124,27 @@ func NewInitializer(
122124
enableProxy bool,
123125
proxyAll bool,
124126
connectUplinkToBridge bool,
127+
disableTXChecksumOffload bool,
125128
) *Initializer {
126129
return &Initializer{
127-
ovsBridgeClient: ovsBridgeClient,
128-
client: k8sClient,
129-
ifaceStore: ifaceStore,
130-
ofClient: ofClient,
131-
routeClient: routeClient,
132-
ovsBridge: ovsBridge,
133-
hostGateway: hostGateway,
134-
mtu: mtu,
135-
networkConfig: networkConfig,
136-
wireGuardConfig: wireGuardConfig,
137-
egressConfig: egressConfig,
138-
serviceConfig: serviceConfig,
139-
networkReadyCh: networkReadyCh,
140-
stopCh: stopCh,
141-
enableProxy: enableProxy,
142-
proxyAll: proxyAll,
143-
connectUplinkToBridge: connectUplinkToBridge,
130+
ovsBridgeClient: ovsBridgeClient,
131+
client: k8sClient,
132+
ifaceStore: ifaceStore,
133+
ofClient: ofClient,
134+
routeClient: routeClient,
135+
ovsBridge: ovsBridge,
136+
hostGateway: hostGateway,
137+
mtu: mtu,
138+
networkConfig: networkConfig,
139+
wireGuardConfig: wireGuardConfig,
140+
egressConfig: egressConfig,
141+
serviceConfig: serviceConfig,
142+
networkReadyCh: networkReadyCh,
143+
stopCh: stopCh,
144+
enableProxy: enableProxy,
145+
proxyAll: proxyAll,
146+
connectUplinkToBridge: connectUplinkToBridge,
147+
disableTXChecksumOffload: disableTXChecksumOffload,
144148
}
145149
}
146150

@@ -663,6 +667,16 @@ func (i *Initializer) configureGatewayInterface(gatewayIface *interfacestore.Int
663667
return err
664668
}
665669

670+
if i.disableTXChecksumOffload {
671+
if err := ethtool.EthtoolTXHWCsumSwitch(i.hostGateway, ethtool.TXCSUM_OFF); err != nil {
672+
return fmt.Errorf("error when disabling TX checksum offload on %s: %v", i.hostGateway, err)
673+
}
674+
} else {
675+
if err := ethtool.EthtoolTXHWCsumSwitch(i.hostGateway, ethtool.TXCSUM_ON); err != nil {
676+
return fmt.Errorf("error when enabling TX checksum offload on %s: %v", i.hostGateway, err)
677+
}
678+
}
679+
666680
i.nodeConfig.GatewayConfig = &config.GatewayConfig{Name: i.hostGateway, MAC: gwMAC, OFPort: uint32(gatewayIface.OFPort)}
667681
gatewayIface.MAC = gwMAC
668682
gatewayIface.IPs = []net.IP{}

pkg/agent/cniserver/interface_configuration_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func (ic *ifConfigurator) configureContainerLinkVeth(
265265
// OVS netdev datapath doesn't support TX checksum offloading, i.e. if packet
266266
// arrives with bad/no checksum it will be sent to the output port with same bad/no checksum.
267267
if ic.disableTXChecksumOffload || ic.ovsDatapathType == ovsconfig.OVSDatapathNetdev {
268-
if err := ethtool.EthtoolTXHWCsumOff(containerVeth.Name); err != nil {
268+
if err := ethtool.EthtoolTXHWCsumSwitch(containerVeth.Name, ethtool.TXCSUM_OFF); err != nil {
269269
return fmt.Errorf("error when disabling TX checksum offload on container veth: %v", err)
270270
}
271271
}

pkg/agent/util/ethtool/ethtool_linux.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build linux
2+
// +build linux
3+
14
// Copyright 2019 Antrea Authors
25
//
36
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,6 +27,9 @@ const (
2427
IFNAMSIZ = 16 // defined in linux/if.h
2528
SIOCETHTOOL = 0x8946 // ethtool interface, defined in linux/sockios.h
2629
ETHTOOL_STXCSUM = 0x00000017 // set TX hw csum enable, defined in linux/ethtool.h
30+
31+
TXCSUM_ON = uint32(1)
32+
TXCSUM_OFF = uint32(0)
2733
)
2834

2935
// defined in linux/if.h (struct ifreq)
@@ -38,8 +44,8 @@ type ethtoolValue struct {
3844
Data uint32
3945
}
4046

41-
// EthtoolTXHWCsumOff disables TX checksum offload on the specified interface.
42-
func EthtoolTXHWCsumOff(name string) error {
47+
// EthtoolTXHWCsumSwitch enables or disables TX checksum offload on the specified interface.
48+
func EthtoolTXHWCsumSwitch(name string, op uint32) error {
4349
if len(name)+1 > IFNAMSIZ {
4450
return fmt.Errorf("name '%s' exceeds IFNAMSIZ (%d)", name, IFNAMSIZ)
4551
}
@@ -52,14 +58,14 @@ func EthtoolTXHWCsumOff(name string) error {
5258

5359
value := ethtoolValue{
5460
Cmd: ETHTOOL_STXCSUM,
55-
Data: 0,
61+
Data: op,
5662
}
5763
request := ifReq{
5864
Data: uintptr(unsafe.Pointer(&value)),
5965
}
6066
copy(request.Name[:], []byte(name))
6167

62-
// We perform the call unconditionally: if TX checksum offload is already disabled the call
68+
// We perform the call unconditionally: if TX checksum offload is already as expected the call
6369
// will be a no-op and there will be no error.
6470
if _, _, errno := syscall.RawSyscall(
6571
syscall.SYS_IOCTL,
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//go:build windows
2+
// +build windows
3+
4+
// Copyright 2022 Antrea Authors
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
package ethtool
19+
20+
var (
21+
TXCSUM_ON = uint32(1)
22+
TXCSUM_OFF = uint32(0)
23+
)
24+
25+
func EthtoolTXHWCsumSwitch(name string, op uint32) error {
26+
return nil
27+
}

0 commit comments

Comments
 (0)