@@ -202,6 +202,55 @@ static struct nft_expr_type nft_redir_ipv6_type __read_mostly = {
202202};
203203#endif
204204
205+ #ifdef CONFIG_NF_TABLES_INET
206+ static void nft_redir_inet_eval (const struct nft_expr * expr ,
207+ struct nft_regs * regs ,
208+ const struct nft_pktinfo * pkt )
209+ {
210+ switch (nft_pf (pkt )) {
211+ case NFPROTO_IPV4 :
212+ return nft_redir_ipv4_eval (expr , regs , pkt );
213+ case NFPROTO_IPV6 :
214+ return nft_redir_ipv6_eval (expr , regs , pkt );
215+ }
216+
217+ WARN_ON_ONCE (1 );
218+ }
219+
220+ static void
221+ nft_redir_inet_destroy (const struct nft_ctx * ctx , const struct nft_expr * expr )
222+ {
223+ nf_ct_netns_put (ctx -> net , NFPROTO_INET );
224+ }
225+
226+ static struct nft_expr_type nft_redir_inet_type ;
227+ static const struct nft_expr_ops nft_redir_inet_ops = {
228+ .type = & nft_redir_inet_type ,
229+ .size = NFT_EXPR_SIZE (sizeof (struct nft_redir )),
230+ .eval = nft_redir_inet_eval ,
231+ .init = nft_redir_init ,
232+ .destroy = nft_redir_inet_destroy ,
233+ .dump = nft_redir_dump ,
234+ .validate = nft_redir_validate ,
235+ };
236+
237+ static struct nft_expr_type nft_redir_inet_type __read_mostly = {
238+ .family = NFPROTO_INET ,
239+ .name = "redir" ,
240+ .ops = & nft_redir_inet_ops ,
241+ .policy = nft_redir_policy ,
242+ .maxattr = NFTA_MASQ_MAX ,
243+ .owner = THIS_MODULE ,
244+ };
245+
246+ static int __init nft_redir_module_init_inet (void )
247+ {
248+ return nft_register_expr (& nft_redir_inet_type );
249+ }
250+ #else
251+ static inline int nft_redir_module_init_inet (void ) { return 0 ; }
252+ #endif
253+
205254static int __init nft_redir_module_init (void )
206255{
207256 int ret = nft_register_expr (& nft_redir_ipv4_type );
@@ -217,6 +266,15 @@ static int __init nft_redir_module_init(void)
217266 }
218267#endif
219268
269+ ret = nft_redir_module_init_inet ();
270+ if (ret < 0 ) {
271+ nft_unregister_expr (& nft_redir_ipv4_type );
272+ #ifdef CONFIG_NF_TABLES_IPV6
273+ nft_unregister_expr (& nft_redir_ipv6_type );
274+ #endif
275+ return ret ;
276+ }
277+
220278 return ret ;
221279}
222280
@@ -226,6 +284,9 @@ static void __exit nft_redir_module_exit(void)
226284#ifdef CONFIG_NF_TABLES_IPV6
227285 nft_unregister_expr (& nft_redir_ipv6_type );
228286#endif
287+ #ifdef CONFIG_NF_TABLES_INET
288+ nft_unregister_expr (& nft_redir_inet_type );
289+ #endif
229290}
230291
231292module_init (nft_redir_module_init );
0 commit comments