1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/kernel.h>
4 #include <linux/init.h>
5 #include <linux/module.h>
6 #include <linux/netlink.h>
7 #include <linux/netfilter.h>
8 #include <linux/netfilter/nf_tables.h>
9 #include <net/netfilter/nf_tables_core.h>
10 #include <net/netfilter/nf_tables.h>
12 #include <net/netfilter/nft_fib.h>
14 static void nft_fib_inet_eval(const struct nft_expr
*expr
,
15 struct nft_regs
*regs
,
16 const struct nft_pktinfo
*pkt
)
18 const struct nft_fib
*priv
= nft_expr_priv(expr
);
20 switch (nft_pf(pkt
)) {
22 switch (priv
->result
) {
23 case NFT_FIB_RESULT_OIF
:
24 case NFT_FIB_RESULT_OIFNAME
:
25 return nft_fib4_eval(expr
, regs
, pkt
);
26 case NFT_FIB_RESULT_ADDRTYPE
:
27 return nft_fib4_eval_type(expr
, regs
, pkt
);
31 switch (priv
->result
) {
32 case NFT_FIB_RESULT_OIF
:
33 case NFT_FIB_RESULT_OIFNAME
:
34 return nft_fib6_eval(expr
, regs
, pkt
);
35 case NFT_FIB_RESULT_ADDRTYPE
:
36 return nft_fib6_eval_type(expr
, regs
, pkt
);
41 regs
->verdict
.code
= NF_DROP
;
44 static struct nft_expr_type nft_fib_inet_type
;
45 static const struct nft_expr_ops nft_fib_inet_ops
= {
46 .type
= &nft_fib_inet_type
,
47 .size
= NFT_EXPR_SIZE(sizeof(struct nft_fib
)),
48 .eval
= nft_fib_inet_eval
,
51 .validate
= nft_fib_validate
,
54 static struct nft_expr_type nft_fib_inet_type __read_mostly
= {
55 .family
= NFPROTO_INET
,
57 .ops
= &nft_fib_inet_ops
,
58 .policy
= nft_fib_policy
,
59 .maxattr
= NFTA_FIB_MAX
,
63 static int __init
nft_fib_inet_module_init(void)
65 return nft_register_expr(&nft_fib_inet_type
);
68 static void __exit
nft_fib_inet_module_exit(void)
70 nft_unregister_expr(&nft_fib_inet_type
);
73 module_init(nft_fib_inet_module_init
);
74 module_exit(nft_fib_inet_module_exit
);
76 MODULE_LICENSE("GPL");
77 MODULE_AUTHOR("Florian Westphal <fw@strlen.de>");
78 MODULE_ALIAS_NFT_AF_EXPR(1, "fib");