Skip to content

Commit b49e63f

Browse files
committed
Fix compatibility with MPTCP
1 parent b42efe2 commit b49e63f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

redirect_nftables_rules.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,43 @@ func (r *autoRedirect) nftablesCreateExcludeRules(nft *nftables.Conn, table *nft
534534
nftablesCreateExcludeDestinationIPSet(nft, table, chain, 4, "inet6_route_exclude_address_set", nftables.TableFamilyIPv6, false)
535535
}
536536

537+
mptcpVerdict := expr.VerdictDrop
538+
if r.tunOptions.ExcludeMPTCP {
539+
mptcpVerdict = expr.VerdictReturn
540+
}
541+
nft.AddRule(&nftables.Rule{
542+
Table: table,
543+
Chain: chain,
544+
Exprs: []expr.Any{
545+
&expr.Meta{
546+
Key: expr.MetaKeyL4PROTO,
547+
Register: 1,
548+
},
549+
&expr.Cmp{
550+
Op: expr.CmpOpEq,
551+
Register: 1,
552+
Data: []byte{unix.IPPROTO_TCP},
553+
},
554+
&expr.Exthdr{
555+
DestRegister: 1,
556+
Type: 30,
557+
Offset: 0,
558+
Len: 1,
559+
Flags: unix.NFT_EXTHDR_F_PRESENT,
560+
Op: expr.ExthdrOpTcpopt,
561+
},
562+
&expr.Cmp{
563+
Op: expr.CmpOpEq,
564+
Register: 1,
565+
Data: []byte{1},
566+
},
567+
&expr.Counter{},
568+
&expr.Verdict{
569+
Kind: mptcpVerdict,
570+
},
571+
},
572+
})
573+
537574
return nil
538575
}
539576

tun.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type Options struct {
8383
AutoRedirectMarkMode bool
8484
AutoRedirectInputMark uint32
8585
AutoRedirectOutputMark uint32
86+
ExcludeMPTCP bool
8687
Inet4LoopbackAddress []netip.Addr
8788
Inet6LoopbackAddress []netip.Addr
8889
StrictRoute bool

0 commit comments

Comments
 (0)