cregit-Linux how code gets into the kernel

Release 4.9 net/netfilter/nf_queue.c

Directory: net/netfilter
/*
 * 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

PersonTokensPropCommitsCommitProp
harald welteharald welte1435.00%225.00%
eric w. biedermaneric w. biederman1332.50%112.50%
eric dumazeteric dumazet512.50%225.00%
florian westphalflorian westphal410.00%112.50%
yasuyuki kozakaiyasuyuki kozakai37.50%112.50%
patrick mchardypatrick mchardy12.50%112.50%
Total40100.00%8100.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

PersonTokensPropCommitsCommitProp
harald welteharald welte838.10%120.00%
eric w. biedermaneric w. biederman838.10%120.00%
yasuyuki kozakaiyasuyuki kozakai314.29%120.00%
florian westphalflorian westphal14.76%120.00%
stephen hemmingerstephen hemminger14.76%120.00%
Total21100.00%5100.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

PersonTokensPropCommitsCommitProp
patrick mchardypatrick mchardy6453.78%120.00%
david s. millerdavid s. miller2924.37%240.00%
florian westphalflorian westphal2117.65%120.00%
pablo neira ayusopablo neira ayuso54.20%120.00%
Total119100.00%5100.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

PersonTokensPropCommitsCommitProp
florian westphalflorian westphal8471.19%350.00%
david s. millerdavid s. miller2924.58%233.33%
pablo neira ayusopablo neira ayuso54.24%116.67%
Total118100.00%6100.00%

EXPORT_SYMBOL_GPL(nf_queue_entry_get_refs);
void nf_queue_nf_hook_drop(struct net *net, const struct nf_hook_entry *entry) { const struct nf_queue_handler *qh; rcu_read_lock(); qh = rcu_dereference(net->nf.queue_handler); if (qh) qh->nf_hook_drop(net, entry); rcu_read_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
eric w. biedermaneric w. biederman4382.69%250.00%
pablo neira ayusopablo neira ayuso59.62%125.00%
aaron conoleaaron conole47.69%125.00%
Total52100.00%4100.00%


static int __nf_queue(struct sk_buff *skb, const 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, .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

PersonTokensPropCommitsCommitProp
harald welteharald welte8437.67%29.09%
patrick mchardypatrick mchardy6227.80%731.82%
florian westphalflorian westphal3716.59%627.27%
eric w. biedermaneric w. biederman135.83%14.55%
yasuyuki kozakaiyasuyuki kozakai114.93%14.55%
david s. millerdavid s. miller73.14%29.09%
eric dumazeteric dumazet52.24%14.55%
pablo neira ayusopablo neira ayuso31.35%14.55%
lucas de marchilucas de marchi10.45%14.55%
Total223100.00%22100.00%

/* Packets leaving via this function must come back through nf_reinject(). */
int nf_queue(struct sk_buff *skb, struct nf_hook_state *state, struct nf_hook_entry **entryp, unsigned int verdict) { struct nf_hook_entry *entry = *entryp; int ret; RCU_INIT_POINTER(state->hook_entries, entry); ret = __nf_queue(skb, state, verdict >> NF_VERDICT_QBITS); if (ret < 0) { if (ret == -ESRCH && (verdict & NF_VERDICT_FLAG_QUEUE_BYPASS)) { *entryp = rcu_dereference(entry->next); return 1; } kfree_skb(skb); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pablo neira ayusopablo neira ayuso102100.00%1100.00%
Total102100.00%1100.00%


void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict) { struct nf_hook_entry *hook_entry; struct sk_buff *skb = entry->skb; const struct nf_afinfo *afinfo; struct nf_hook_ops *elem; int err; hook_entry = rcu_dereference(entry->state.hook_entries); elem = &hook_entry->ops; 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) { hook_entry = rcu_dereference(hook_entry->next); if (hook_entry) next_hook: verdict = nf_iterate(skb, &entry->state, &hook_entry); } switch (verdict & NF_VERDICT_MASK) { case NF_ACCEPT: case NF_STOP: okfn: local_bh_disable(); entry->state.okfn(entry->state.net, entry->state.sk, skb); local_bh_enable(); break; case NF_QUEUE: err = nf_queue(skb, &entry->state, &hook_entry, verdict); if (err == 1) { if (hook_entry) goto next_hook; goto okfn; } break; case NF_STOLEN: break; default: kfree_skb(skb); } kfree(entry); }

Contributors

PersonTokensPropCommitsCommitProp
harald welteharald welte9032.26%14.35%
patrick mchardypatrick mchardy6523.30%730.43%
aaron conoleaaron conole2910.39%14.35%
florian westphalflorian westphal2910.39%521.74%
pablo neira ayusopablo neira ayuso248.60%14.35%
david s. millerdavid s. miller227.89%313.04%
eric w. biedermaneric w. biederman124.30%28.70%
michael wangmichael wang41.43%14.35%
eric dumazeteric dumazet31.08%14.35%
julian anastasovjulian anastasov10.36%14.35%
Total279100.00%23100.00%

EXPORT_SYMBOL(nf_reinject);

Overall Contributors

PersonTokensPropCommitsCommitProp
harald welteharald welte24023.37%36.52%
patrick mchardypatrick mchardy19919.38%1123.91%
florian westphalflorian westphal19118.60%1021.74%
pablo neira ayusopablo neira ayuso14514.12%36.52%
eric w. biedermaneric w. biederman898.67%48.70%
david s. millerdavid s. miller878.47%48.70%
aaron conoleaaron conole333.21%12.17%
yasuyuki kozakaiyasuyuki kozakai171.66%12.17%
eric dumazeteric dumazet161.56%48.70%
michael wangmichael wang40.39%12.17%
tejun heotejun heo30.29%12.17%
julian anastasovjulian anastasov10.10%12.17%
lucas de marchilucas de marchi10.10%12.17%
stephen hemmingerstephen hemminger10.10%12.17%
Total1027100.00%46100.00%
Directory: net/netfilter