Release 4.7 net/netfilter/nf_queue.c
/*
* Rusty Russell (C)2000 -- This code is GPL.
* Patrick McHardy (c) 2006-2012
*/
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/skbuff.h>
#include <linux/netfilter.h>
#include <linux/netfilter_bridge.h>
#include <linux/seq_file.h>
#include <linux/rcupdate.h>
#include <net/protocol.h>
#include <net/netfilter/nf_queue.h>
#include <net/dst.h>
#include "nf_internals.h"
/*
* Hook for nfnetlink_queue to register its queue handler.
* We do this so that most of the NFQUEUE code can be modular.
*
* Once the queue is registered it must reinject all packets it
* receives, no matter what.
*/
/* return EBUSY when somebody else is registered, return EEXIST if the
* same handler is registered, return 0 in case of success. */
void nf_register_queue_handler(struct net *net, const struct nf_queue_handler *qh)
{
/* should never happen, we only have one queueing backend in kernel */
WARN_ON(rcu_access_pointer(net->nf.queue_handler));
rcu_assign_pointer(net->nf.queue_handler, qh);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
harald welte | harald welte | 14 | 35.00% | 2 | 25.00% |
eric w. biederman | eric w. biederman | 13 | 32.50% | 1 | 12.50% |
eric dumazet | eric dumazet | 5 | 12.50% | 2 | 25.00% |
florian westphal | florian westphal | 4 | 10.00% | 1 | 12.50% |
yasuyuki kozakai | yasuyuki kozakai | 3 | 7.50% | 1 | 12.50% |
patrick mchardy | patrick mchardy | 1 | 2.50% | 1 | 12.50% |
| Total | 40 | 100.00% | 8 | 100.00% |
EXPORT_SYMBOL(nf_register_queue_handler);
/* The caller must flush their queue before this */
void nf_unregister_queue_handler(struct net *net)
{
RCU_INIT_POINTER(net->nf.queue_handler, NULL);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
eric w. biederman | eric w. biederman | 8 | 38.10% | 1 | 20.00% |
harald welte | harald welte | 8 | 38.10% | 1 | 20.00% |
yasuyuki kozakai | yasuyuki kozakai | 3 | 14.29% | 1 | 20.00% |
florian westphal | florian westphal | 1 | 4.76% | 1 | 20.00% |
stephen hemminger | stephen hemminger | 1 | 4.76% | 1 | 20.00% |
| Total | 21 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL(nf_unregister_queue_handler);
void nf_queue_entry_release_refs(struct nf_queue_entry *entry)
{
struct nf_hook_state *state = &entry->state;
/* Release those devices we held, or Alexey will kill me. */
if (state->in)
dev_put(state->in);
if (state->out)
dev_put(state->out);
if (state->sk)
sock_put(state->sk);
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
if (entry->skb->nf_bridge) {
struct net_device *physdev;
physdev = nf_bridge_get_physindev(entry->skb);
if (physdev)
dev_put(physdev);
physdev = nf_bridge_get_physoutdev(entry->skb);
if (physdev)
dev_put(physdev);
}
#endif
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
patrick mchardy | patrick mchardy | 64 | 53.78% | 1 | 20.00% |
david s. miller | david s. miller | 29 | 24.37% | 2 | 40.00% |
florian westphal | florian westphal | 21 | 17.65% | 1 | 20.00% |
pablo neira ayuso | pablo neira ayuso | 5 | 4.20% | 1 | 20.00% |
| Total | 119 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL_GPL(nf_queue_entry_release_refs);
/* Bump dev refs so they don't vanish while packet is out */
void nf_queue_entry_get_refs(struct nf_queue_entry *entry)
{
struct nf_hook_state *state = &entry->state;
if (state->in)
dev_hold(state->in);
if (state->out)
dev_hold(state->out);
if (state->sk)
sock_hold(state->sk);
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
if (entry->skb->nf_bridge) {
struct net_device *physdev;
physdev = nf_bridge_get_physindev(entry->skb);
if (physdev)
dev_hold(physdev);
physdev = nf_bridge_get_physoutdev(entry->skb);
if (physdev)
dev_hold(physdev);
}
#endif
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
florian westphal | florian westphal | 84 | 71.19% | 3 | 50.00% |
david s. miller | david s. miller | 29 | 24.58% | 2 | 33.33% |
pablo neira ayuso | pablo neira ayuso | 5 | 4.24% | 1 | 16.67% |
| Total | 118 | 100.00% | 6 | 100.00% |
EXPORT_SYMBOL_GPL(nf_queue_entry_get_refs);
void nf_queue_nf_hook_drop(struct net *net, struct nf_hook_ops *ops)
{
const struct nf_queue_handler *qh;
rcu_read_lock();
qh = rcu_dereference(net->nf.queue_handler);
if (qh)
qh->nf_hook_drop(net, ops);
rcu_read_unlock();
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
eric w. biederman | eric w. biederman | 46 | 90.20% | 2 | 66.67% |
pablo neira ayuso | pablo neira ayuso | 5 | 9.80% | 1 | 33.33% |
| Total | 51 | 100.00% | 3 | 100.00% |
/*
* Any packet that leaves via this function must come back
* through nf_reinject().
*/
int nf_queue(struct sk_buff *skb,
struct nf_hook_ops *elem,
struct nf_hook_state *state,
unsigned int queuenum)
{
int status = -ENOENT;
struct nf_queue_entry *entry = NULL;
const struct nf_afinfo *afinfo;
const struct nf_queue_handler *qh;
struct net *net = state->net;
/* QUEUE == DROP if no one is waiting, to be safe. */
qh = rcu_dereference(net->nf.queue_handler);
if (!qh) {
status = -ESRCH;
goto err;
}
afinfo = nf_get_afinfo(state->pf);
if (!afinfo)
goto err;
entry = kmalloc(sizeof(*entry) + afinfo->route_key_size, GFP_ATOMIC);
if (!entry) {
status = -ENOMEM;
goto err;
}
*entry = (struct nf_queue_entry) {
.skb = skb,
.elem = elem,
.state = *state,
.size = sizeof(*entry) + afinfo->route_key_size,
};
nf_queue_entry_get_refs(entry);
skb_dst_force(skb);
afinfo->saveroute(skb, entry);
status = qh->outfn(entry, queuenum);
if (status < 0) {
nf_queue_entry_release_refs(entry);
goto err;
}
return 0;
err:
kfree(entry);
return status;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
harald welte | harald welte | 89 | 38.53% | 2 | 9.09% |
patrick mchardy | patrick mchardy | 66 | 28.57% | 7 | 31.82% |
florian westphal | florian westphal | 38 | 16.45% | 6 | 27.27% |
eric w. biederman | eric w. biederman | 13 | 5.63% | 1 | 4.55% |
yasuyuki kozakai | yasuyuki kozakai | 11 | 4.76% | 1 | 4.55% |
david s. miller | david s. miller | 7 | 3.03% | 2 | 9.09% |
eric dumazet | eric dumazet | 5 | 2.16% | 1 | 4.55% |
lucas de marchi | lucas de marchi | 1 | 0.43% | 1 | 4.55% |
michael wang | michael wang | 1 | 0.43% | 1 | 4.55% |
| Total | 231 | 100.00% | 22 | 100.00% |
void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
{
struct sk_buff *skb = entry->skb;
struct nf_hook_ops *elem = entry->elem;
const struct nf_afinfo *afinfo;
int err;
nf_queue_entry_release_refs(entry);
/* Continue traversal iff userspace said ok... */
if (verdict == NF_REPEAT)
verdict = elem->hook(elem->priv, skb, &entry->state);
if (verdict == NF_ACCEPT) {
afinfo = nf_get_afinfo(entry->state.pf);
if (!afinfo || afinfo->reroute(entry->state.net, skb, entry) < 0)
verdict = NF_DROP;
}
entry->state.thresh = INT_MIN;
if (verdict == NF_ACCEPT) {
next_hook:
verdict = nf_iterate(entry->state.hook_list,
skb, &entry->state, &elem);
}
switch (verdict & NF_VERDICT_MASK) {
case NF_ACCEPT:
case NF_STOP:
local_bh_disable();
entry->state.okfn(entry->state.net, entry->state.sk, skb);
local_bh_enable();
break;
case NF_QUEUE:
err = nf_queue(skb, elem, &entry->state,
verdict >> NF_VERDICT_QBITS);
if (err < 0) {
if (err == -ESRCH &&
(verdict & NF_VERDICT_FLAG_QUEUE_BYPASS))
goto next_hook;
kfree_skb(skb);
}
break;
case NF_STOLEN:
break;
default:
kfree_skb(skb);
}
kfree(entry);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
harald welte | harald welte | 98 | 37.26% | 1 | 4.35% |
patrick mchardy | patrick mchardy | 72 | 27.38% | 7 | 30.43% |
florian westphal | florian westphal | 47 | 17.87% | 6 | 26.09% |
david s. miller | david s. miller | 24 | 9.13% | 3 | 13.04% |
eric w. biederman | eric w. biederman | 13 | 4.94% | 3 | 13.04% |
michael wang | michael wang | 5 | 1.90% | 1 | 4.35% |
eric dumazet | eric dumazet | 3 | 1.14% | 1 | 4.35% |
julian anastasov | julian anastasov | 1 | 0.38% | 1 | 4.35% |
| Total | 263 | 100.00% | 23 | 100.00% |
EXPORT_SYMBOL(nf_reinject);
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
harald welte | harald welte | 253 | 27.62% | 3 | 6.25% |
patrick mchardy | patrick mchardy | 210 | 22.93% | 11 | 22.92% |
florian westphal | florian westphal | 210 | 22.93% | 11 | 22.92% |
eric w. biederman | eric w. biederman | 93 | 10.15% | 5 | 10.42% |
david s. miller | david s. miller | 89 | 9.72% | 4 | 8.33% |
yasuyuki kozakai | yasuyuki kozakai | 17 | 1.86% | 1 | 2.08% |
eric dumazet | eric dumazet | 16 | 1.75% | 4 | 8.33% |
pablo neira ayuso | pablo neira ayuso | 15 | 1.64% | 2 | 4.17% |
michael wang | michael wang | 6 | 0.66% | 2 | 4.17% |
tejun heo | tejun heo | 3 | 0.33% | 1 | 2.08% |
hideaki yoshifuji | hideaki yoshifuji | 1 | 0.11% | 1 | 2.08% |
stephen hemminger | stephen hemminger | 1 | 0.11% | 1 | 2.08% |
lucas de marchi | lucas de marchi | 1 | 0.11% | 1 | 2.08% |
julian anastasov | julian anastasov | 1 | 0.11% | 1 | 2.08% |
| Total | 916 | 100.00% | 48 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.