cregit-Linux how code gets into the kernel

Release 4.7 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%
david s. millerdavid s. miller42.05%212.50%
alexey dobriyanalexey dobriyan42.05%212.50%
jan engelhardtjan engelhardt10.51%16.25%
al viroal viro10.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); if (state->hook == NF_INET_POST_ROUTING) return ipt_do_table(skb, state, state->net->ipv4.iptable_mangle); /* PREROUTING/INPUT/FORWARD: */ return ipt_do_table(skb, state, state->net->ipv4.iptable_mangle); }

Contributors

PersonTokensPropCommitsCommitProp
jan engelhardtjan engelhardt4253.16%225.00%
alexey dobriyanalexey dobriyan1721.52%112.50%
david s. millerdavid s. miller911.39%112.50%
eric w. biedermaneric w. biederman810.13%337.50%
patrick mchardypatrick mchardy33.80%112.50%
Total79100.00%8100.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%
alexey dobriyanalexey dobriyan1114.10%228.57%
pre-gitpre-git1114.10%114.29%
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-git19430.60%24.76%
florian westphalflorian westphal11117.51%24.76%
jan engelhardtjan engelhardt9214.51%716.67%
alexey dobriyanalexey dobriyan9214.51%511.90%
arnaldo carvalho de meloarnaldo carvalho de melo304.73%24.76%
patrick mchardypatrick mchardy233.63%511.90%
harald welteharald welte213.31%37.14%
eric w. biedermaneric w. biederman152.37%49.52%
david s. millerdavid s. miller132.05%37.14%
art haasart haas101.58%12.38%
herbert xuherbert xu91.42%12.38%
thomas grafthomas graf60.95%12.38%
simon hormansimon horman50.79%12.38%
linus torvaldslinus torvalds50.79%12.38%
andrew mortonandrew morton30.47%12.38%
tejun heotejun heo30.47%12.38%
al viroal viro10.16%12.38%
jean sacrenjean sacren10.16%12.38%
Total634100.00%42100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}