Release 4.11 net/netfilter/nf_tables_core.c
/*
* Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/list.h>
#include <linux/rculist.h>
#include <linux/skbuff.h>
#include <linux/netlink.h>
#include <linux/netfilter.h>
#include <linux/static_key.h>
#include <linux/netfilter/nfnetlink.h>
#include <linux/netfilter/nf_tables.h>
#include <net/netfilter/nf_tables_core.h>
#include <net/netfilter/nf_tables.h>
#include <net/netfilter/nf_log.h>
static const char *const comments[__NFT_TRACETYPE_MAX] = {
[NFT_TRACETYPE_POLICY] = "policy",
[NFT_TRACETYPE_RETURN] = "return",
[NFT_TRACETYPE_RULE] = "rule",
};
static struct nf_loginfo trace_loginfo = {
.type = NF_LOG_TYPE_LOG,
.u = {
.log = {
.level = LOGLEVEL_WARNING,
.logflags = NF_LOG_DEFAULT_MASK,
},
},
};
static noinline void __nft_trace_packet(struct nft_traceinfo *info,
const struct nft_chain *chain,
int rulenum, enum nft_trace_types type)
{
const struct nft_pktinfo *pkt = info->pkt;
if (!info->trace || !pkt->skb->nf_trace)
return;
info->chain = chain;
info->type = type;
nft_trace_notify(info);
nf_log_trace(nft_net(pkt), nft_pf(pkt), nft_hook(pkt), pkt->skb,
nft_in(pkt), nft_out(pkt), &trace_loginfo,
"TRACE: %s:%s:%s:%u ",
chain->table->name, chain->name, comments[type], rulenum);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Patrick McHardy | 59 | 48.76% | 1 | 16.67% |
Florian Westphal | 46 | 38.02% | 3 | 50.00% |
Pablo Neira Ayuso | 15 | 12.40% | 1 | 16.67% |
Eric W. Biedermann | 1 | 0.83% | 1 | 16.67% |
Total | 121 | 100.00% | 6 | 100.00% |
static inline void nft_trace_packet(struct nft_traceinfo *info,
const struct nft_chain *chain,
const struct nft_rule *rule,
int rulenum,
enum nft_trace_types type)
{
if (static_branch_unlikely(&nft_trace_enabled)) {
info->rule = rule;
__nft_trace_packet(info, chain, rulenum, type);
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Patrick McHardy | 37 | 63.79% | 1 | 33.33% |
Florian Westphal | 21 | 36.21% | 2 | 66.67% |
Total | 58 | 100.00% | 3 | 100.00% |
static void nft_cmp_fast_eval(const struct nft_expr *expr,
struct nft_regs *regs)
{
const struct nft_cmp_fast_expr *priv = nft_expr_priv(expr);
u32 mask = nft_cmp_fast_mask(priv->len);
if ((regs->data[priv->sreg] & mask) == priv->data)
return;
regs->verdict.code = NFT_BREAK;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Patrick McHardy | 66 | 100.00% | 3 | 100.00% |
Total | 66 | 100.00% | 3 | 100.00% |
static bool nft_payload_fast_eval(const struct nft_expr *expr,
struct nft_regs *regs,
const struct nft_pktinfo *pkt)
{
const struct nft_payload *priv = nft_expr_priv(expr);
const struct sk_buff *skb = pkt->skb;
u32 *dest = ®s->data[priv->dreg];
unsigned char *ptr;
if (priv->base == NFT_PAYLOAD_NETWORK_HEADER)
ptr = skb_network_header(skb);
else {
if (!pkt->tprot_set)
return false;
ptr = skb_network_header(skb) + pkt->xt.thoff;
}
ptr += priv->offset;
if (unlikely(ptr + priv->len > skb_tail_pointer(skb)))
return false;
*dest = 0;
if (priv->len == 2)
*(u16 *)dest = *(u16 *)ptr;
else if (priv->len == 4)
*(u32 *)dest = *(u32 *)ptr;
else
*(u8 *)dest = *(u8 *)ptr;
return true;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Patrick McHardy | 177 | 89.85% | 4 | 57.14% |
Liping Zhang | 13 | 6.60% | 2 | 28.57% |
Pablo Neira Ayuso | 7 | 3.55% | 1 | 14.29% |
Total | 197 | 100.00% | 7 | 100.00% |
struct nft_jumpstack {
const struct nft_chain *chain;
const struct nft_rule *rule;
int rulenum;
};
unsigned int
nft_do_chain(struct nft_pktinfo *pkt, void *priv)
{
const struct nft_chain *chain = priv, *basechain = chain;
const struct net *net = nft_net(pkt);
const struct nft_rule *rule;
const struct nft_expr *expr, *last;
struct nft_regs regs;
unsigned int stackptr = 0;
struct nft_jumpstack jumpstack[NFT_JUMP_STACK_SIZE];
struct nft_stats *stats;
int rulenum;
unsigned int gencursor = nft_genmask_cur(net);
struct nft_traceinfo info;
info.trace = false;
if (static_branch_unlikely(&nft_trace_enabled))
nft_trace_init(&info, pkt, ®s.verdict, basechain);
do_chain:
rulenum = 0;
rule = list_entry(&chain->rules, struct nft_rule, list);
next_rule:
regs.verdict.code = NFT_CONTINUE;
list_for_each_entry_continue_rcu(rule, &chain->rules, list) {
/* This rule is not active, skip. */
if (unlikely(rule->genmask & gencursor))
continue;
rulenum++;
nft_rule_for_each_expr(expr, last, rule) {
if (expr->ops == &nft_cmp_fast_ops)
nft_cmp_fast_eval(expr, ®s);
else if (expr->ops != &nft_payload_fast_ops ||
!nft_payload_fast_eval(expr, ®s, pkt))
expr->ops->eval(expr, ®s, pkt);
if (regs.verdict.code != NFT_CONTINUE)
break;
}
switch (regs.verdict.code) {
case NFT_BREAK:
regs.verdict.code = NFT_CONTINUE;
continue;
case NFT_CONTINUE:
nft_trace_packet(&info, chain, rule,
rulenum, NFT_TRACETYPE_RULE);
continue;
}
break;
}
switch (regs.verdict.code & NF_VERDICT_MASK) {
case NF_ACCEPT:
case NF_DROP:
case NF_QUEUE:
case NF_STOLEN:
nft_trace_packet(&info, chain, rule,
rulenum, NFT_TRACETYPE_RULE);
return regs.verdict.code;
}
switch (regs.verdict.code) {
case NFT_JUMP:
BUG_ON(stackptr >= NFT_JUMP_STACK_SIZE);
jumpstack[stackptr].chain = chain;
jumpstack[stackptr].rule = rule;
jumpstack[stackptr].rulenum = rulenum;
stackptr++;
/* fall through */
case NFT_GOTO:
nft_trace_packet(&info, chain, rule,
rulenum, NFT_TRACETYPE_RULE);
chain = regs.verdict.chain;
goto do_chain;
case NFT_CONTINUE:
rulenum++;
/* fall through */
case NFT_RETURN:
nft_trace_packet(&info, chain, rule,
rulenum, NFT_TRACETYPE_RETURN);
break;
default:
WARN_ON(1);
}
if (stackptr > 0) {
stackptr--;
chain = jumpstack[stackptr].chain;
rule = jumpstack[stackptr].rule;
rulenum = jumpstack[stackptr].rulenum;
goto next_rule;
}
nft_trace_packet(&info, basechain, NULL, -1,
NFT_TRACETYPE_POLICY);
rcu_read_lock_bh();
stats = this_cpu_ptr(rcu_dereference(nft_base_chain(basechain)->stats));
u64_stats_update_begin(&stats->syncp);
stats->pkts++;
stats->bytes += pkt->skb->len;
u64_stats_update_end(&stats->syncp);
rcu_read_unlock_bh();
return nft_base_chain(basechain)->policy;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Patrick McHardy | 294 | 52.22% | 8 | 32.00% |
Pablo Neira Ayuso | 172 | 30.55% | 10 | 40.00% |
Florian Westphal | 61 | 10.83% | 3 | 12.00% |
Eric Dumazet | 19 | 3.37% | 1 | 4.00% |
Eric Leblond | 9 | 1.60% | 1 | 4.00% |
Eric W. Biedermann | 8 | 1.42% | 2 | 8.00% |
Total | 563 | 100.00% | 25 | 100.00% |
EXPORT_SYMBOL_GPL(nft_do_chain);
static struct nft_expr_type *nft_basic_types[] = {
&nft_imm_type,
&nft_cmp_type,
&nft_lookup_type,
&nft_bitwise_type,
&nft_byteorder_type,
&nft_payload_type,
&nft_dynset_type,
&nft_range_type,
};
int __init nf_tables_core_module_init(void)
{
int err, i;
for (i = 0; i < ARRAY_SIZE(nft_basic_types); i++) {
err = nft_register_expr(nft_basic_types[i]);
if (err)
goto err;
}
return 0;
err:
while (i-- > 0)
nft_unregister_expr(nft_basic_types[i]);
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Liping Zhang | 38 | 53.52% | 1 | 25.00% |
Patrick McHardy | 29 | 40.85% | 2 | 50.00% |
Pablo Neira Ayuso | 4 | 5.63% | 1 | 25.00% |
Total | 71 | 100.00% | 4 | 100.00% |
void nf_tables_core_module_exit(void)
{
int i;
i = ARRAY_SIZE(nft_basic_types);
while (i-- > 0)
nft_unregister_expr(nft_basic_types[i]);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Liping Zhang | 23 | 71.88% | 1 | 50.00% |
Patrick McHardy | 9 | 28.12% | 1 | 50.00% |
Total | 32 | 100.00% | 2 | 100.00% |
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Patrick McHardy | 762 | 59.95% | 13 | 33.33% |
Pablo Neira Ayuso | 221 | 17.39% | 12 | 30.77% |
Florian Westphal | 139 | 10.94% | 4 | 10.26% |
Liping Zhang | 108 | 8.50% | 4 | 10.26% |
Eric Dumazet | 19 | 1.49% | 1 | 2.56% |
Eric W. Biedermann | 9 | 0.71% | 3 | 7.69% |
Eric Leblond | 9 | 0.71% | 1 | 2.56% |
Joe Perches | 4 | 0.31% | 1 | 2.56% |
Total | 1271 | 100.00% | 39 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.