@@ -113,12 +113,6 @@ func (r *autoRedirect) setupNFTables() error {
113
113
Priority : nftables .ChainPriorityRef (* nftables .ChainPriorityNATDest + 2 ),
114
114
Type : nftables .ChainTypeFilter ,
115
115
})
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
- }
122
116
nft .AddRule (& nftables.Rule {
123
117
Table : table ,
124
118
Chain : chainPreRoutingUDP ,
@@ -128,10 +122,28 @@ func (r *autoRedirect) setupNFTables() error {
128
122
Register : 1 ,
129
123
},
130
124
& expr.Cmp {
131
- Op : expr .CmpOpEq ,
125
+ Op : expr .CmpOpNeq ,
132
126
Register : 1 ,
133
127
Data : []byte {unix .IPPROTO_UDP },
134
128
},
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
+ },
135
147
& expr.Ct {
136
148
Key : expr .CtKeyMARK ,
137
149
Register : 1 ,
@@ -149,6 +161,40 @@ func (r *autoRedirect) setupNFTables() error {
149
161
& expr.Counter {},
150
162
},
151
163
})
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
+ })
152
198
}
153
199
154
200
err = r .configureOpenWRTFirewall4 (nft , false )
0 commit comments