]> git.ipfire.org Git - thirdparty/kernel/stable.git/blob - net/netfilter/nft_fib_netdev.c
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500
[thirdparty/kernel/stable.git] / net / netfilter / nft_fib_netdev.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2017 Pablo M. Bermudo Garay <pablombg@gmail.com>
4 *
5 * This code is based on net/netfilter/nft_fib_inet.c, written by
6 * Florian Westphal <fw@strlen.de>.
7 */
8
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>
17
18 #include <net/netfilter/nft_fib.h>
19
20 static void nft_fib_netdev_eval(const struct nft_expr *expr,
21 struct nft_regs *regs,
22 const struct nft_pktinfo *pkt)
23 {
24 const struct nft_fib *priv = nft_expr_priv(expr);
25
26 switch (ntohs(pkt->skb->protocol)) {
27 case ETH_P_IP:
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);
34 }
35 break;
36 case ETH_P_IPV6:
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);
43 }
44 break;
45 }
46
47 regs->verdict.code = NFT_BREAK;
48 }
49
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,
55 .init = nft_fib_init,
56 .dump = nft_fib_dump,
57 .validate = nft_fib_validate,
58 };
59
60 static struct nft_expr_type nft_fib_netdev_type __read_mostly = {
61 .family = NFPROTO_NETDEV,
62 .name = "fib",
63 .ops = &nft_fib_netdev_ops,
64 .policy = nft_fib_policy,
65 .maxattr = NFTA_FIB_MAX,
66 .owner = THIS_MODULE,
67 };
68
69 static int __init nft_fib_netdev_module_init(void)
70 {
71 return nft_register_expr(&nft_fib_netdev_type);
72 }
73
74 static void __exit nft_fib_netdev_module_exit(void)
75 {
76 nft_unregister_expr(&nft_fib_netdev_type);
77 }
78
79 module_init(nft_fib_netdev_module_init);
80 module_exit(nft_fib_netdev_module_exit);
81
82 MODULE_LICENSE("GPL");
83 MODULE_AUTHOR("Pablo M. Bermudo Garay <pablombg@gmail.com>");
84 MODULE_ALIAS_NFT_AF_EXPR(5, "fib");