netfilter: nft_payload: add optimized payload implementation for small loads
[deliverable/linux.git] / net / ipv6 / netfilter / nf_table_route_ipv6.c
1 /*
2 * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * Development of this code funded by Astaro AG (http://www.astaro.com/)
9 */
10
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/list.h>
14 #include <linux/skbuff.h>
15 #include <linux/netlink.h>
16 #include <linux/netfilter.h>
17 #include <linux/netfilter_ipv6.h>
18 #include <linux/netfilter/nfnetlink.h>
19 #include <linux/netfilter/nf_tables.h>
20 #include <net/netfilter/nf_tables.h>
21 #include <net/route.h>
22
23 static unsigned int nf_route_table_hook(const struct nf_hook_ops *ops,
24 struct sk_buff *skb,
25 const struct net_device *in,
26 const struct net_device *out,
27 int (*okfn)(struct sk_buff *))
28 {
29 unsigned int ret;
30 struct in6_addr saddr, daddr;
31 u_int8_t hop_limit;
32 u32 mark, flowlabel;
33
34 /* save source/dest address, mark, hoplimit, flowlabel, priority */
35 memcpy(&saddr, &ipv6_hdr(skb)->saddr, sizeof(saddr));
36 memcpy(&daddr, &ipv6_hdr(skb)->daddr, sizeof(daddr));
37 mark = skb->mark;
38 hop_limit = ipv6_hdr(skb)->hop_limit;
39
40 /* flowlabel and prio (includes version, which shouldn't change either */
41 flowlabel = *((u32 *)ipv6_hdr(skb));
42
43 ret = nft_do_chain(ops, skb, in, out, okfn);
44 if (ret != NF_DROP && ret != NF_QUEUE &&
45 (memcmp(&ipv6_hdr(skb)->saddr, &saddr, sizeof(saddr)) ||
46 memcmp(&ipv6_hdr(skb)->daddr, &daddr, sizeof(daddr)) ||
47 skb->mark != mark ||
48 ipv6_hdr(skb)->hop_limit != hop_limit ||
49 flowlabel != *((u_int32_t *)ipv6_hdr(skb))))
50 return ip6_route_me_harder(skb) == 0 ? ret : NF_DROP;
51
52 return ret;
53 }
54
55 static struct nft_base_chain nf_chain_route_output __read_mostly = {
56 .chain = {
57 .name = "OUTPUT",
58 .rules = LIST_HEAD_INIT(nf_chain_route_output.chain.rules),
59 .flags = NFT_BASE_CHAIN | NFT_CHAIN_BUILTIN,
60 },
61 .ops = {
62 .hook = nf_route_table_hook,
63 .owner = THIS_MODULE,
64 .pf = NFPROTO_IPV6,
65 .hooknum = NF_INET_LOCAL_OUT,
66 .priority = NF_IP6_PRI_MANGLE,
67 .priv = &nf_chain_route_output.chain,
68 },
69 };
70
71 static struct nft_table nf_table_route_ipv6 __read_mostly = {
72 .name = "route",
73 .chains = LIST_HEAD_INIT(nf_table_route_ipv6.chains),
74 };
75
76 static int __init nf_table_route_init(void)
77 {
78 list_add_tail(&nf_chain_route_output.chain.list,
79 &nf_table_route_ipv6.chains);
80 return nft_register_table(&nf_table_route_ipv6, NFPROTO_IPV6);
81 }
82
83 static void __exit nf_table_route_exit(void)
84 {
85 nft_unregister_table(&nf_table_route_ipv6, NFPROTO_IPV6);
86 }
87
88 module_init(nf_table_route_init);
89 module_exit(nf_table_route_exit);
90
91 MODULE_LICENSE("GPL");
92 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
93 MODULE_ALIAS_NFT_TABLE(AF_INET6, "route");
This page took 0.035973 seconds and 5 git commands to generate.