Linux-2.6.12-rc2
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] / net / ipv6 / netfilter / ip6t_MARK.c
1 /* This is a module which is used for setting the NFMARK field of an skb. */
2
3 /* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
12 #include <linux/ip.h>
13 #include <net/checksum.h>
14
15 #include <linux/netfilter_ipv6/ip6_tables.h>
16 #include <linux/netfilter_ipv6/ip6t_MARK.h>
17
18 MODULE_LICENSE("GPL");
19 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
20
21 static unsigned int
22 target(struct sk_buff **pskb,
23 const struct net_device *in,
24 const struct net_device *out,
25 unsigned int hooknum,
26 const void *targinfo,
27 void *userinfo)
28 {
29 const struct ip6t_mark_target_info *markinfo = targinfo;
30
31 if((*pskb)->nfmark != markinfo->mark) {
32 (*pskb)->nfmark = markinfo->mark;
33 (*pskb)->nfcache |= NFC_ALTERED;
34 }
35 return IP6T_CONTINUE;
36 }
37
38 static int
39 checkentry(const char *tablename,
40 const struct ip6t_entry *e,
41 void *targinfo,
42 unsigned int targinfosize,
43 unsigned int hook_mask)
44 {
45 if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_mark_target_info))) {
46 printk(KERN_WARNING "MARK: targinfosize %u != %Zu\n",
47 targinfosize,
48 IP6T_ALIGN(sizeof(struct ip6t_mark_target_info)));
49 return 0;
50 }
51
52 if (strcmp(tablename, "mangle") != 0) {
53 printk(KERN_WARNING "MARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
54 return 0;
55 }
56
57 return 1;
58 }
59
60 static struct ip6t_target ip6t_mark_reg
61 = { { NULL, NULL }, "MARK", target, checkentry, NULL, THIS_MODULE };
62
63 static int __init init(void)
64 {
65 printk(KERN_DEBUG "registering ipv6 mark target\n");
66 if (ip6t_register_target(&ip6t_mark_reg))
67 return -EINVAL;
68
69 return 0;
70 }
71
72 static void __exit fini(void)
73 {
74 ip6t_unregister_target(&ip6t_mark_reg);
75 }
76
77 module_init(init);
78 module_exit(fini);