redirect: Fix UDP rules
This commit is contained in:
parent
a8ce3838bc
commit
219c612399
2 changed files with 74 additions and 7 deletions
|
|
@ -113,12 +113,6 @@ func (r *autoRedirect) setupNFTables() error {
|
||||||
Priority: nftables.ChainPriorityRef(*nftables.ChainPriorityNATDest + 2),
|
Priority: nftables.ChainPriorityRef(*nftables.ChainPriorityNATDest + 2),
|
||||||
Type: nftables.ChainTypeFilter,
|
Type: nftables.ChainTypeFilter,
|
||||||
})
|
})
|
||||||
if r.enableIPv4 {
|
|
||||||
nftablesCreateExcludeDestinationIPSet(nft, table, chainPreRoutingUDP, 5, "inet4_local_address_set", nftables.TableFamilyIPv4, false)
|
|
||||||
}
|
|
||||||
if r.enableIPv6 {
|
|
||||||
nftablesCreateExcludeDestinationIPSet(nft, table, chainPreRoutingUDP, 6, "inet6_local_address_set", nftables.TableFamilyIPv6, false)
|
|
||||||
}
|
|
||||||
nft.AddRule(&nftables.Rule{
|
nft.AddRule(&nftables.Rule{
|
||||||
Table: table,
|
Table: table,
|
||||||
Chain: chainPreRoutingUDP,
|
Chain: chainPreRoutingUDP,
|
||||||
|
|
@ -128,10 +122,28 @@ func (r *autoRedirect) setupNFTables() error {
|
||||||
Register: 1,
|
Register: 1,
|
||||||
},
|
},
|
||||||
&expr.Cmp{
|
&expr.Cmp{
|
||||||
Op: expr.CmpOpEq,
|
Op: expr.CmpOpNeq,
|
||||||
Register: 1,
|
Register: 1,
|
||||||
Data: []byte{unix.IPPROTO_UDP},
|
Data: []byte{unix.IPPROTO_UDP},
|
||||||
},
|
},
|
||||||
|
&expr.Verdict{
|
||||||
|
Kind: expr.VerdictReturn,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
nft.AddRule(&nftables.Rule{
|
||||||
|
Table: table,
|
||||||
|
Chain: chainPreRoutingUDP,
|
||||||
|
Exprs: []expr.Any{
|
||||||
|
&expr.Meta{
|
||||||
|
Key: expr.MetaKeyIIFNAME,
|
||||||
|
Register: 1,
|
||||||
|
},
|
||||||
|
&expr.Cmp{
|
||||||
|
Op: expr.CmpOpNeq,
|
||||||
|
Register: 1,
|
||||||
|
Data: nftablesIfname(r.tunOptions.Name),
|
||||||
|
},
|
||||||
&expr.Ct{
|
&expr.Ct{
|
||||||
Key: expr.CtKeyMARK,
|
Key: expr.CtKeyMARK,
|
||||||
Register: 1,
|
Register: 1,
|
||||||
|
|
@ -149,6 +161,40 @@ func (r *autoRedirect) setupNFTables() error {
|
||||||
&expr.Counter{},
|
&expr.Counter{},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
nft.AddRule(&nftables.Rule{
|
||||||
|
Table: table,
|
||||||
|
Chain: chainPreRoutingUDP,
|
||||||
|
Exprs: []expr.Any{
|
||||||
|
&expr.Ct{
|
||||||
|
Key: expr.CtKeyMARK,
|
||||||
|
Register: 1,
|
||||||
|
},
|
||||||
|
&expr.Cmp{
|
||||||
|
Op: expr.CmpOpNeq,
|
||||||
|
Register: 1,
|
||||||
|
Data: binaryutil.NativeEndian.PutUint32(r.tunOptions.AutoRedirectInputMark),
|
||||||
|
},
|
||||||
|
&expr.Immediate{
|
||||||
|
Register: 1,
|
||||||
|
Data: binaryutil.NativeEndian.PutUint32(r.tunOptions.AutoRedirectOutputMark),
|
||||||
|
},
|
||||||
|
&expr.Meta{
|
||||||
|
Key: expr.MetaKeyMARK,
|
||||||
|
Register: 1,
|
||||||
|
SourceRegister: true,
|
||||||
|
},
|
||||||
|
&expr.Meta{
|
||||||
|
Key: expr.MetaKeyMARK,
|
||||||
|
Register: 1,
|
||||||
|
},
|
||||||
|
&expr.Ct{
|
||||||
|
Key: expr.CtKeyMARK,
|
||||||
|
Register: 1,
|
||||||
|
SourceRegister: true,
|
||||||
|
},
|
||||||
|
&expr.Counter{},
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
err = r.configureOpenWRTFirewall4(nft, false)
|
err = r.configureOpenWRTFirewall4(nft, false)
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,27 @@ func (r *autoRedirect) nftablesCreateExcludeRules(nft *nftables.Conn, table *nft
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
if chain.Type == nftables.ChainTypeRoute {
|
||||||
|
nft.AddRule(&nftables.Rule{
|
||||||
|
Table: table,
|
||||||
|
Chain: chain,
|
||||||
|
Exprs: []expr.Any{
|
||||||
|
&expr.Ct{
|
||||||
|
Key: expr.CtKeyMARK,
|
||||||
|
Register: 1,
|
||||||
|
},
|
||||||
|
&expr.Cmp{
|
||||||
|
Op: expr.CmpOpEq,
|
||||||
|
Register: 1,
|
||||||
|
Data: binaryutil.NativeEndian.PutUint32(r.tunOptions.AutoRedirectOutputMark),
|
||||||
|
},
|
||||||
|
&expr.Counter{},
|
||||||
|
&expr.Verdict{
|
||||||
|
Kind: expr.VerdictReturn,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if chain.Hooknum == nftables.ChainHookPrerouting {
|
if chain.Hooknum == nftables.ChainHookPrerouting {
|
||||||
if len(r.tunOptions.IncludeInterface) > 0 {
|
if len(r.tunOptions.IncludeInterface) > 0 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue