2 * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
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 * Development of this code funded by Astaro AG (http://www.astaro.com/)
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/list.h>
14 #include <linux/rculist.h>
15 #include <linux/skbuff.h>
16 #include <linux/netlink.h>
17 #include <linux/netfilter.h>
18 #include <linux/netfilter/nfnetlink.h>
19 #include <linux/netfilter/nf_tables.h>
20 #include <net/netfilter/nf_tables_core.h>
21 #include <net/netfilter/nf_tables.h>
23 static void nft_cmp_fast_eval(const struct nft_expr *expr,
24 struct nft_data data[NFT_REG_MAX + 1])
26 const struct nft_cmp_fast_expr *priv = nft_expr_priv(expr);
29 mask = ~0U >> (sizeof(priv->data) * BITS_PER_BYTE - priv->len);
30 if ((data[priv->sreg].data[0] & mask) == priv->data)
32 data[NFT_REG_VERDICT].verdict = NFT_BREAK;
35 unsigned int nft_do_chain(const struct nf_hook_ops *ops,
37 const struct net_device *in,
38 const struct net_device *out,
39 int (*okfn)(struct sk_buff *))
41 const struct nft_chain *chain = ops->priv;
42 const struct nft_rule *rule;
43 const struct nft_expr *expr, *last;
44 struct nft_data data[NFT_REG_MAX + 1];
45 const struct nft_pktinfo pkt = {
49 .hooknum = ops->hooknum,
51 unsigned int stackptr = 0;
53 const struct nft_chain *chain;
54 const struct nft_rule *rule;
55 } jumpstack[NFT_JUMP_STACK_SIZE];
58 rule = list_entry(&chain->rules, struct nft_rule, list);
60 data[NFT_REG_VERDICT].verdict = NFT_CONTINUE;
61 list_for_each_entry_continue_rcu(rule, &chain->rules, list) {
62 nft_rule_for_each_expr(expr, last, rule) {
63 if (expr->ops == &nft_cmp_fast_ops)
64 nft_cmp_fast_eval(expr, data);
66 expr->ops->eval(expr, data, &pkt);
68 if (data[NFT_REG_VERDICT].verdict != NFT_CONTINUE)
72 switch (data[NFT_REG_VERDICT].verdict) {
74 data[NFT_REG_VERDICT].verdict = NFT_CONTINUE;
82 switch (data[NFT_REG_VERDICT].verdict) {
86 return data[NFT_REG_VERDICT].verdict;
88 BUG_ON(stackptr >= NFT_JUMP_STACK_SIZE);
89 jumpstack[stackptr].chain = chain;
90 jumpstack[stackptr].rule = rule;
94 chain = data[NFT_REG_VERDICT].chain;
105 chain = jumpstack[stackptr].chain;
106 rule = jumpstack[stackptr].rule;
112 EXPORT_SYMBOL_GPL(nft_do_chain);
114 int __init nf_tables_core_module_init(void)
118 err = nft_immediate_module_init();
122 err = nft_cmp_module_init();
126 err = nft_lookup_module_init();
130 err = nft_bitwise_module_init();
134 err = nft_byteorder_module_init();
138 err = nft_payload_module_init();
145 nft_byteorder_module_exit();
147 nft_bitwise_module_exit();
149 nft_lookup_module_exit();
151 nft_cmp_module_exit();
153 nft_immediate_module_exit();
158 void nf_tables_core_module_exit(void)
160 nft_payload_module_exit();
161 nft_byteorder_module_exit();
162 nft_bitwise_module_exit();
163 nft_lookup_module_exit();
164 nft_cmp_module_exit();
165 nft_immediate_module_exit();