cregit-Linux how code gets into the kernel

Release 4.11 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
Linus Torvalds (pre-git)11458.46%212.50%
Arnaldo Carvalho de Melo2713.85%212.50%
Patrick McHardy178.72%16.25%
Herbert Xu94.62%16.25%
Eric W. Biedermann73.59%212.50%
Thomas Graf63.08%16.25%
Simon Horman52.56%16.25%
Alexey Dobriyan42.05%212.50%
David S. Miller42.05%212.50%
Al Viro10.51%16.25%
Jan 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 Engelhardt4175.93%228.57%
David S. Miller611.11%114.29%
Eric W. Biedermann59.26%342.86%
Patrick 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 Engelhardt2835.90%114.29%
Florian Westphal2633.33%228.57%
Alexey Dobriyan1114.10%228.57%
Linus Torvalds (pre-git)1114.10%114.29%
Harald 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 Dobriyan2353.49%250.00%
Florian 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 Westphal4548.39%114.29%
Alexey Dobriyan2425.81%228.57%
Linus Torvalds (pre-git)1010.75%114.29%
Jan Engelhardt99.68%114.29%
Linus Torvalds44.30%114.29%
Jean 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
Linus Torvalds (pre-git)1470.00%125.00%
Florian Westphal420.00%125.00%
Jan Engelhardt15.00%125.00%
Andrew Morton15.00%125.00%
Total20100.00%4100.00%

module_init(iptable_mangle_init); module_exit(iptable_mangle_fini);

Overall Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)19431.86%24.88%
Florian Westphal11118.23%24.88%
Jan Engelhardt9114.94%717.07%
Alexey Dobriyan7512.32%49.76%
Arnaldo Carvalho de Melo304.93%24.88%
Patrick McHardy223.61%512.20%
Harald Welte213.45%37.32%
Eric W. Biedermann121.97%49.76%
David S. Miller101.64%37.32%
Art Haas101.64%12.44%
Herbert Xu91.48%12.44%
Thomas Graf60.99%12.44%
Linus Torvalds50.82%12.44%
Simon Horman50.82%12.44%
Andrew Morton30.49%12.44%
Tejun Heo30.49%12.44%
Jean Sacren10.16%12.44%
Al 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.
Created with cregit.