Skip to content

Commit ed2fd0d

Browse files
committed
[tunnel] Toggle cksum recalc in dev
1 parent 7f224ba commit ed2fd0d

File tree

6 files changed

+45
-11
lines changed

6 files changed

+45
-11
lines changed

cmd/tunnelproxy/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var (
4949
jwksURLs = flag.String("jwks_urls", "", "Comma-separated URLs of the JWKS endpoints.")
5050

5151
extIPv6SubnetSize = flag.Int("ext_ipv6_subnet_size", 64, "IPv6 subnet size.")
52+
cksumRecalc = flag.Bool("cksum_recalc", false, "Recalculate checksum.")
5253
)
5354

5455
func main() {
@@ -118,9 +119,11 @@ func main() {
118119

119120
log.Infof("External IPv6 prefix: %s", extIPv6Prefix.String())
120121

121-
r, err := router.NewNetlinkRouter(
122+
rOpts := []router.Option{
122123
router.WithExternalIPv6Prefix(extIPv6Prefix),
123-
)
124+
router.WithChecksumRecalculation(*cksumRecalc),
125+
}
126+
r, err := router.NewNetlinkRouter(rOpts...)
124127
if err != nil {
125128
log.Fatalf("Failed to create netlink router: %v", err)
126129
}

pkg/drivers/tunnelproxy_docker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func (d *TunnelProxyDockerDriver) Start(
117117
cmd.Args = append(cmd.Args, []string{
118118
"--apiserver_addr=" + apiserverAddr,
119119
fmt.Sprintf("--jwks_urls=http://%s:%d%s", apiserverHost, 8444, token.JWKSURI),
120+
"--cksum_recalc=true",
120121
}...)
121122
if build.IsDev() {
122123
cmd.Args = append(cmd.Args, "--dev")

pkg/tunnel/connection/splice.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func defaultSpliceConfig() *SpliceConfig {
6060
}
6161
}
6262

63+
// Splice starts the TUN <-> Connection splice operation.
6364
func Splice(tunDev tun.Device, conn Connection, opts ...SpliceOption) error {
6465
config := defaultSpliceConfig()
6566
for _, opt := range opts {

pkg/tunnel/router/netstack.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ var (
2424
// NetstackRouter implements Router using a userspace network stack.
2525
// This router can be used for both client and server sides.
2626
type NetstackRouter struct {
27-
tunDev *netstack.TunDevice
28-
mux *connection.MuxedConn
29-
proxy *socksproxy.ProxyServer
27+
tunDev *netstack.TunDevice
28+
mux *connection.MuxedConn
29+
30+
proxy *socksproxy.ProxyServer
31+
3032
localAddresses []netip.Prefix
3133
resolveConf *network.ResolveConfig
3234
socksListenAddr string
33-
closeOnce sync.Once
35+
cksumRecalc bool
36+
37+
closeOnce sync.Once
3438
}
3539

3640
// NewNetstackRouter creates a new netstack-based tunnel router.
@@ -52,12 +56,15 @@ func NewNetstackRouter(opts ...Option) (*NetstackRouter, error) {
5256
)
5357

5458
return &NetstackRouter{
55-
tunDev: tunDev,
56-
mux: connection.NewMuxedConn(),
57-
proxy: proxy,
59+
tunDev: tunDev,
60+
mux: connection.NewMuxedConn(),
61+
62+
proxy: proxy,
63+
5864
localAddresses: options.localAddresses,
5965
resolveConf: options.resolveConf,
6066
socksListenAddr: options.socksListenAddr,
67+
cksumRecalc: options.cksumRecalc,
6168
}, nil
6269
}
6370

@@ -75,7 +82,11 @@ func (r *NetstackRouter) Start(ctx context.Context) error {
7582
})
7683

7784
g.Go(func() error {
78-
return connection.Splice(r.tunDev, r.mux, connection.WithChecksumRecalculation())
85+
var opts []connection.SpliceOption
86+
if r.cksumRecalc {
87+
opts = append(opts, connection.WithChecksumRecalculation())
88+
}
89+
return connection.Splice(r.tunDev, r.mux, opts...)
7990
})
8091

8192
_, socksListenPortStr, err := net.SplitHostPort(r.socksListenAddr)

pkg/tunnel/router/options.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ type routerOptions struct {
1717
extIfaceName string
1818
tunIfaceName string
1919
socksListenAddr string
20+
cksumRecalc bool
2021
}
2122

2223
func defaultOptions() *routerOptions {
2324
return &routerOptions{
2425
extIfaceName: "eth0",
2526
tunIfaceName: "tun0",
2627
socksListenAddr: "localhost:1080",
28+
cksumRecalc: false,
2729
}
2830
}
2931

@@ -78,3 +80,11 @@ func WithSocksListenAddr(addr string) Option {
7880
o.socksListenAddr = addr
7981
}
8082
}
83+
84+
// WithChecksumRecalculation enables or disables checksum recalculation for the netstack router.
85+
// Only valid for netstack routers.
86+
func WithChecksumRecalculation(enable bool) Option {
87+
return func(o *routerOptions) {
88+
o.cksumRecalc = enable
89+
}
90+
}

pkg/tunnel/router/server_netlink_linux.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ type NetlinkRouter struct {
3333
extLink netlink.Link
3434
extIPv6Prefix netip.Prefix
3535

36+
cksumRecalc bool
37+
3638
tunDev tun.Device
3739
tunLink netlink.Link
3840

@@ -114,6 +116,8 @@ func NewNetlinkRouter(opts ...Option) (*NetlinkRouter, error) {
114116
extLink: extLink,
115117
extIPv6Prefix: options.extIPv6Prefix,
116118

119+
cksumRecalc: options.cksumRecalc,
120+
117121
tunDev: tunDev,
118122
tunLink: tunLink,
119123

@@ -200,7 +204,11 @@ func (r *NetlinkRouter) Start(ctx context.Context) error {
200204

201205
// Start the splicing operation
202206
g.Go(func() error {
203-
return connection.Splice(r.tunDev, r.mux)
207+
var opts []connection.SpliceOption
208+
if r.cksumRecalc {
209+
opts = append(opts, connection.WithChecksumRecalculation())
210+
}
211+
return connection.Splice(r.tunDev, r.mux, opts...)
204212
})
205213

206214
return g.Wait()

0 commit comments

Comments
 (0)