1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2017 Pablo M. Bermudo Garay <pablombg@gmail.com>
5 * This code is based on net/netfilter/nft_fib_inet.c, written by
6 * Florian Westphal <fw@strlen.de>.
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/module.h>
12 #include <linux/netlink.h>
13 #include <linux/netfilter.h>
14 #include <linux/netfilter/nf_tables.h>
15 #include <net/netfilter/nf_tables_core.h>
16 #include <net/netfilter/nf_tables.h>
18 #include <net/netfilter/nft_fib.h>
20 static void nft_fib_netdev_eval(const struct nft_expr *expr,
21 struct nft_regs *regs,
22 const struct nft_pktinfo *pkt)
24 const struct nft_fib *priv = nft_expr_priv(expr);
26 switch (ntohs(pkt->skb->protocol)) {
28 switch (priv->result) {
29 case NFT_FIB_RESULT_OIF:
30 case NFT_FIB_RESULT_OIFNAME:
31 return nft_fib4_eval(expr, regs, pkt);
32 case NFT_FIB_RESULT_ADDRTYPE:
33 return nft_fib4_eval_type(expr, regs, pkt);
37 switch (priv->result) {
38 case NFT_FIB_RESULT_OIF:
39 case NFT_FIB_RESULT_OIFNAME:
40 return nft_fib6_eval(expr, regs, pkt);
41 case NFT_FIB_RESULT_ADDRTYPE:
42 return nft_fib6_eval_type(expr, regs, pkt);
47 regs->verdict.code = NFT_BREAK;
50 static struct nft_expr_type nft_fib_netdev_type;
51 static const struct nft_expr_ops nft_fib_netdev_ops = {
52 .type = &nft_fib_netdev_type,
53 .size = NFT_EXPR_SIZE(sizeof(struct nft_fib)),
54 .eval = nft_fib_netdev_eval,
57 .validate = nft_fib_validate,
60 static struct nft_expr_type nft_fib_netdev_type __read_mostly = {
61 .family = NFPROTO_NETDEV,
63 .ops = &nft_fib_netdev_ops,
64 .policy = nft_fib_policy,
65 .maxattr = NFTA_FIB_MAX,
69 static int __init nft_fib_netdev_module_init(void)
71 return nft_register_expr(&nft_fib_netdev_type);
74 static void __exit nft_fib_netdev_module_exit(void)
76 nft_unregister_expr(&nft_fib_netdev_type);
79 module_init(nft_fib_netdev_module_init);
80 module_exit(nft_fib_netdev_module_exit);
82 MODULE_LICENSE("GPL");
83 MODULE_AUTHOR("Pablo M. Bermudo Garay <pablombg@gmail.com>");
84 MODULE_ALIAS_NFT_AF_EXPR(5, "fib");