@@ -113,12 +113,6 @@ func (r *autoRedirect) setupNFTables() error {
113113 Priority : nftables .ChainPriorityRef (* nftables .ChainPriorityNATDest + 2 ),
114114 Type : nftables .ChainTypeFilter ,
115115 })
116- if r .enableIPv4 {
117- nftablesCreateExcludeDestinationIPSet (nft , table , chainPreRoutingUDP , 5 , "inet4_local_address_set" , nftables .TableFamilyIPv4 , false )
118- }
119- if r .enableIPv6 {
120- nftablesCreateExcludeDestinationIPSet (nft , table , chainPreRoutingUDP , 6 , "inet6_local_address_set" , nftables .TableFamilyIPv6 , false )
121- }
122116 nft .AddRule (& nftables.Rule {
123117 Table : table ,
124118 Chain : chainPreRoutingUDP ,
@@ -128,10 +122,28 @@ func (r *autoRedirect) setupNFTables() error {
128122 Register : 1 ,
129123 },
130124 & expr.Cmp {
131- Op : expr .CmpOpEq ,
125+ Op : expr .CmpOpNeq ,
132126 Register : 1 ,
133127 Data : []byte {unix .IPPROTO_UDP },
134128 },
129+ & expr.Verdict {
130+ Kind : expr .VerdictReturn ,
131+ },
132+ },
133+ })
134+ nft .AddRule (& nftables.Rule {
135+ Table : table ,
136+ Chain : chainPreRoutingUDP ,
137+ Exprs : []expr.Any {
138+ & expr.Meta {
139+ Key : expr .MetaKeyIIFNAME ,
140+ Register : 1 ,
141+ },
142+ & expr.Cmp {
143+ Op : expr .CmpOpNeq ,
144+ Register : 1 ,
145+ Data : nftablesIfname (r .tunOptions .Name ),
146+ },
135147 & expr.Ct {
136148 Key : expr .CtKeyMARK ,
137149 Register : 1 ,
@@ -149,6 +161,40 @@ func (r *autoRedirect) setupNFTables() error {
149161 & expr.Counter {},
150162 },
151163 })
164+ nft .AddRule (& nftables.Rule {
165+ Table : table ,
166+ Chain : chainPreRoutingUDP ,
167+ Exprs : []expr.Any {
168+ & expr.Ct {
169+ Key : expr .CtKeyMARK ,
170+ Register : 1 ,
171+ },
172+ & expr.Cmp {
173+ Op : expr .CmpOpNeq ,
174+ Register : 1 ,
175+ Data : binaryutil .NativeEndian .PutUint32 (r .tunOptions .AutoRedirectInputMark ),
176+ },
177+ & expr.Immediate {
178+ Register : 1 ,
179+ Data : binaryutil .NativeEndian .PutUint32 (r .tunOptions .AutoRedirectOutputMark ),
180+ },
181+ & expr.Meta {
182+ Key : expr .MetaKeyMARK ,
183+ Register : 1 ,
184+ SourceRegister : true ,
185+ },
186+ & expr.Meta {
187+ Key : expr .MetaKeyMARK ,
188+ Register : 1 ,
189+ },
190+ & expr.Ct {
191+ Key : expr .CtKeyMARK ,
192+ Register : 1 ,
193+ SourceRegister : true ,
194+ },
195+ & expr.Counter {},
196+ },
197+ })
152198 }
153199
154200 err = r .configureOpenWRTFirewall4 (nft , false )
0 commit comments