cregit-Linux how code gets into the kernel

Release 4.8 net/ipv4/netfilter/iptable_mangle.c

/*
 * This is the 1999 rewrite of IP Firewalling, aiming for kernel 2.3.x.
 *
 * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
 * Copyright (C) 2000-2004 Netfilter Core Team <coreteam@netfilter.org>
 *
 * 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.
 */
#include <linux/module.h>
#include <linux/netfilter_ipv4/ip_tables.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
#include <net/sock.h>
#include <net/route.h>
#include <linux/ip.h>
#include <net/ip.h>

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
MODULE_DESCRIPTION("iptables mangle table");


#define MANGLE_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | \
                            (1 << NF_INET_LOCAL_IN) | \
                            (1 << NF_INET_FORWARD) | \
                            (1 << NF_INET_LOCAL_OUT) | \
                            (1 << NF_INET_POST_ROUTING))

static int __net_init iptable_mangle_table_init(struct net *net);


static const struct xt_table packet_mangler = {
	.name		= "mangle",
	.valid_hooks	= MANGLE_VALID_HOOKS,
	.me		= THIS_MODULE,
	.af		= NFPROTO_IPV4,
	.priority	= NF_IP_PRI_MANGLE,
	.table_init	= iptable_mangle_table_init,
};


static unsigned int ipt_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state) { unsigned int ret; const struct iphdr *iph; u_int8_t tos; __be32 saddr, daddr; u_int32_t mark; int err; /* root is playing with raw sockets. */ if (skb->len < sizeof(struct iphdr) || ip_hdrlen(skb) < sizeof(struct iphdr)) return NF_ACCEPT; /* Save things which could affect route */ mark = skb->mark; iph = ip_hdr(skb); saddr = iph->saddr; daddr = iph->daddr; tos = iph->tos; ret = ipt_do_table(skb, state, state->net->ipv4.iptable_mangle); /* Reroute for ANY change. */ if (ret != NF_DROP && ret != NF_STOLEN) { iph = ip_hdr(skb); if (iph->saddr != saddr || iph->daddr != daddr || skb->mark != mark || iph->tos != tos) { err = ip_route_me_harder(state->net, skb, RTN_UNSPEC); if (err < 0) ret = NF_DROP_ERR(err); } } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git11458.46%212.50%
arnaldo carvalho de meloarnaldo carvalho de melo2713.85%212.50%
patrick mchardypatrick mchardy178.72%16.25%
herbert xuherbert xu94.62%16.25%
eric w. biedermaneric w. biederman73.59%212.50%
thomas grafthomas graf63.08%16.25%
simon hormansimon horman52.56%16.25%
alexey dobriyanalexey dobriyan42.05%212.50%
david s. millerdavid s. miller42.05%212.50%
al viroal viro10.51%16.25%
jan engelhardtjan engelhardt10.51%16.25%
Total195100.00%16100.00%

/* The work comes in here from netfilter.c. */
static unsigned int iptable_mangle_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { if (state->hook == NF_INET_LOCAL_OUT) return ipt_mangle_out(skb, state); return ipt_do_table(skb, state, state->net->ipv4.iptable_mangle); }

Contributors

PersonTokensPropCommitsCommitProp
jan engelhardtjan engelhardt4175.93%228.57%
david s. millerdavid s. miller611.11%114.29%
eric w. biedermaneric w. biederman59.26%342.86%
patrick mchardypatrick mchardy23.70%114.29%
Total54100.00%7100.00%

static struct nf_hook_ops *mangle_ops __read_mostly;
static int __net_init iptable_mangle_table_init(struct net *net) { struct ipt_replace *repl; int ret; if (net->ipv4.iptable_mangle) return 0; repl = ipt_alloc_initial_table(&packet_mangler); if (repl == NULL) return -ENOMEM; ret = ipt_register_table(net, &packet_mangler, repl, mangle_ops, &net->ipv4.iptable_mangle); kfree(repl); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
jan engelhardtjan engelhardt2835.90%114.29%
florian westphalflorian westphal2633.33%228.57%
pre-gitpre-git1114.10%114.29%
alexey dobriyanalexey dobriyan1114.10%228.57%
harald welteharald welte22.56%114.29%
Total78100.00%7100.00%


static void __net_exit iptable_mangle_net_exit(struct net *net) { if (!net->ipv4.iptable_mangle) return; ipt_unregister_table(net, net->ipv4.iptable_mangle, mangle_ops); net->ipv4.iptable_mangle = NULL; }

Contributors

PersonTokensPropCommitsCommitProp
alexey dobriyanalexey dobriyan2353.49%250.00%
florian westphalflorian westphal2046.51%250.00%
Total43100.00%4100.00%

static struct pernet_operations iptable_mangle_net_ops = { .exit = iptable_mangle_net_exit, };
static int __init iptable_mangle_init(void) { int ret; mangle_ops = xt_hook_ops_alloc(&packet_mangler, iptable_mangle_hook); if (IS_ERR(mangle_ops)) { ret = PTR_ERR(mangle_ops); return ret; } ret = register_pernet_subsys(&iptable_mangle_net_ops); if (ret < 0) { kfree(mangle_ops); return ret; } ret = iptable_mangle_table_init(&init_net); if (ret) { unregister_pernet_subsys(&iptable_mangle_net_ops); kfree(mangle_ops); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
florian westphalflorian westphal4548.39%114.29%
alexey dobriyanalexey dobriyan2425.81%228.57%
pre-gitpre-git1010.75%114.29%
jan engelhardtjan engelhardt99.68%114.29%
linus torvaldslinus torvalds44.30%114.29%
jean sacrenjean sacren11.08%114.29%
Total93100.00%7100.00%


static void __exit iptable_mangle_fini(void) { unregister_pernet_subsys(&iptable_mangle_net_ops); kfree(mangle_ops); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git1470.00%125.00%
florian westphalflorian westphal420.00%125.00%
jan engelhardtjan engelhardt15.00%125.00%
andrew mortonandrew morton15.00%125.00%
Total20100.00%4100.00%

module_init(iptable_mangle_init); module_exit(iptable_mangle_fini);

Overall Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git19431.86%24.88%
florian westphalflorian westphal11118.23%24.88%
jan engelhardtjan engelhardt9114.94%717.07%
alexey dobriyanalexey dobriyan7512.32%49.76%
arnaldo carvalho de meloarnaldo carvalho de melo304.93%24.88%
patrick mchardypatrick mchardy223.61%512.20%
harald welteharald welte213.45%37.32%
eric w. biedermaneric w. biederman121.97%49.76%
david s. millerdavid s. miller101.64%37.32%
art haasart haas101.64%12.44%
herbert xuherbert xu91.48%12.44%
thomas grafthomas graf60.99%12.44%
simon hormansimon horman50.82%12.44%
linus torvaldslinus torvalds50.82%12.44%
tejun heotejun heo30.49%12.44%
andrew mortonandrew morton30.49%12.44%
jean sacrenjean sacren10.16%12.44%
al viroal viro10.16%12.44%
Total609100.00%41100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.