Skip to content

Commit 51ac6b3

Browse files
committed
redirect: Fix handling of local pings
1 parent 31e29f9 commit 51ac6b3

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

redirect_nftables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (r *autoRedirect) setupNFTables() error {
6464
r.nftablesCreateRedirect(nft, table, chainOutput)
6565

6666
chainOutputUDP := nft.AddChain(&nftables.Chain{
67-
Name: "output_udp",
67+
Name: "output_udp_icmp",
6868
Table: table,
6969
Hooknum: nftables.ChainHookOutput,
7070
Priority: nftables.ChainPriorityMangle,

redirect_nftables_rules.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,20 @@ func (r *autoRedirect) nftablesCreateExcludeRules(nft *nftables.Conn, table *nft
439439
if r.tunOptions.AutoRedirectMarkMode &&
440440
((chain.Hooknum == nftables.ChainHookOutput && chain.Type == nftables.ChainTypeRoute) ||
441441
(chain.Hooknum == nftables.ChainHookPrerouting && chain.Type == nftables.ChainTypeFilter)) {
442+
ipProto := &nftables.Set{
443+
Table: table,
444+
Anonymous: true,
445+
Constant: true,
446+
KeyType: nftables.TypeInetProto,
447+
}
448+
err := nft.AddSet(ipProto, []nftables.SetElement{
449+
{Key: []byte{unix.IPPROTO_UDP}},
450+
{Key: []byte{unix.IPPROTO_ICMP}},
451+
{Key: []byte{unix.IPPROTO_ICMPV6}},
452+
})
453+
if err != nil {
454+
return err
455+
}
442456
nft.AddRule(&nftables.Rule{
443457
Table: table,
444458
Chain: chain,
@@ -447,10 +461,11 @@ func (r *autoRedirect) nftablesCreateExcludeRules(nft *nftables.Conn, table *nft
447461
Key: expr.MetaKeyL4PROTO,
448462
Register: 1,
449463
},
450-
&expr.Cmp{
451-
Op: expr.CmpOpNeq,
452-
Register: 1,
453-
Data: []byte{unix.IPPROTO_UDP},
464+
&expr.Lookup{
465+
SourceRegister: 1,
466+
SetID: ipProto.ID,
467+
SetName: ipProto.Name,
468+
Invert: true,
454469
},
455470
&expr.Verdict{
456471
Kind: expr.VerdictReturn,

0 commit comments

Comments
 (0)