2 * Copyright (c) 2017 Pablo M. Bermudo Garay <pablombg@gmail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This code is based on net/netfilter/nft_fib_inet.c, written by
9 * Florian Westphal <fw@strlen.de>.
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/netlink.h>
16 #include <linux/netfilter.h>
17 #include <linux/netfilter/nf_tables.h>
18 #include <net/netfilter/nf_tables_core.h>
19 #include <net/netfilter/nf_tables.h>
21 #include <net/netfilter/nft_fib.h>
23 static void nft_fib_netdev_eval(const struct nft_expr
*expr
,
24 struct nft_regs
*regs
,
25 const struct nft_pktinfo
*pkt
)
27 const struct nft_fib
*priv
= nft_expr_priv(expr
);
29 switch (ntohs(pkt
->skb
->protocol
)) {
31 switch (priv
->result
) {
32 case NFT_FIB_RESULT_OIF
:
33 case NFT_FIB_RESULT_OIFNAME
:
34 return nft_fib4_eval(expr
, regs
, pkt
);
35 case NFT_FIB_RESULT_ADDRTYPE
:
36 return nft_fib4_eval_type(expr
, regs
, pkt
);
40 switch (priv
->result
) {
41 case NFT_FIB_RESULT_OIF
:
42 case NFT_FIB_RESULT_OIFNAME
:
43 return nft_fib6_eval(expr
, regs
, pkt
);
44 case NFT_FIB_RESULT_ADDRTYPE
:
45 return nft_fib6_eval_type(expr
, regs
, pkt
);
50 regs
->verdict
.code
= NFT_BREAK
;
53 static struct nft_expr_type nft_fib_netdev_type
;
54 static const struct nft_expr_ops nft_fib_netdev_ops
= {
55 .type
= &nft_fib_netdev_type
,
56 .size
= NFT_EXPR_SIZE(sizeof(struct nft_fib
)),
57 .eval
= nft_fib_netdev_eval
,
60 .validate
= nft_fib_validate
,
63 static struct nft_expr_type nft_fib_netdev_type __read_mostly
= {
64 .family
= NFPROTO_NETDEV
,
66 .ops
= &nft_fib_netdev_ops
,
67 .policy
= nft_fib_policy
,
68 .maxattr
= NFTA_FIB_MAX
,
72 static int __init
nft_fib_netdev_module_init(void)
74 return nft_register_expr(&nft_fib_netdev_type
);
77 static void __exit
nft_fib_netdev_module_exit(void)
79 nft_unregister_expr(&nft_fib_netdev_type
);
82 module_init(nft_fib_netdev_module_init
);
83 module_exit(nft_fib_netdev_module_exit
);
85 MODULE_LICENSE("GPL");
86 MODULE_AUTHOR("Pablo M. Bermudo Garay <pablombg@gmail.com>");
87 MODULE_ALIAS_NFT_AF_EXPR(5, "fib");