cregit-Linux how code gets into the kernel

Release 4.16 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; /* 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)9254.76%213.33%
Arnaldo Carvalho de Melo2414.29%16.67%
Patrick McHardy1710.12%16.67%
Eric W. Biedermann74.17%213.33%
Herbert Xu74.17%16.67%
Thomas Graf63.57%16.67%
Simon Horman52.98%16.67%
Alexey Dobriyan42.38%213.33%
David S. Miller42.38%213.33%
Jan Engelhardt10.60%16.67%
Al Viro10.60%16.67%
Total168100.00%15100.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%
Andrew Morton15.00%125.00%
Jan Engelhardt15.00%125.00%
Total20100.00%4100.00%

module_init(iptable_mangle_init); module_exit(iptable_mangle_fini);

Overall Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)17229.55%24.88%
Florian Westphal11119.07%24.88%
Jan Engelhardt9115.64%717.07%
Alexey Dobriyan7512.89%49.76%
Arnaldo Carvalho de Melo274.64%24.88%
Patrick McHardy223.78%512.20%
Harald Welte213.61%37.32%
Eric W. Biedermann122.06%49.76%
Art Haas101.72%12.44%
David S. Miller101.72%37.32%
Herbert Xu71.20%12.44%
Thomas Graf61.03%12.44%
Simon Horman50.86%12.44%
Linus Torvalds50.86%12.44%
Andrew Morton30.52%12.44%
Tejun Heo30.52%12.44%
Jean Sacren10.17%12.44%
Al Viro10.17%12.44%
Total582100.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.