Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v2.6.18-rc6 177 lines 4.0 kB view raw
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/x_tables.h> 16#include <linux/netfilter/xt_MARK.h> 17 18MODULE_LICENSE("GPL"); 19MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>"); 20MODULE_DESCRIPTION("ip[6]tables MARK modification module"); 21MODULE_ALIAS("ipt_MARK"); 22MODULE_ALIAS("ip6t_MARK"); 23 24static unsigned int 25target_v0(struct sk_buff **pskb, 26 const struct net_device *in, 27 const struct net_device *out, 28 unsigned int hooknum, 29 const struct xt_target *target, 30 const void *targinfo, 31 void *userinfo) 32{ 33 const struct xt_mark_target_info *markinfo = targinfo; 34 35 if((*pskb)->nfmark != markinfo->mark) 36 (*pskb)->nfmark = markinfo->mark; 37 38 return XT_CONTINUE; 39} 40 41static unsigned int 42target_v1(struct sk_buff **pskb, 43 const struct net_device *in, 44 const struct net_device *out, 45 unsigned int hooknum, 46 const struct xt_target *target, 47 const void *targinfo, 48 void *userinfo) 49{ 50 const struct xt_mark_target_info_v1 *markinfo = targinfo; 51 int mark = 0; 52 53 switch (markinfo->mode) { 54 case XT_MARK_SET: 55 mark = markinfo->mark; 56 break; 57 58 case XT_MARK_AND: 59 mark = (*pskb)->nfmark & markinfo->mark; 60 break; 61 62 case XT_MARK_OR: 63 mark = (*pskb)->nfmark | markinfo->mark; 64 break; 65 } 66 67 if((*pskb)->nfmark != mark) 68 (*pskb)->nfmark = mark; 69 70 return XT_CONTINUE; 71} 72 73 74static int 75checkentry_v0(const char *tablename, 76 const void *entry, 77 const struct xt_target *target, 78 void *targinfo, 79 unsigned int targinfosize, 80 unsigned int hook_mask) 81{ 82 struct xt_mark_target_info *markinfo = targinfo; 83 84 if (markinfo->mark > 0xffffffff) { 85 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n"); 86 return 0; 87 } 88 return 1; 89} 90 91static int 92checkentry_v1(const char *tablename, 93 const void *entry, 94 const struct xt_target *target, 95 void *targinfo, 96 unsigned int targinfosize, 97 unsigned int hook_mask) 98{ 99 struct xt_mark_target_info_v1 *markinfo = targinfo; 100 101 if (markinfo->mode != XT_MARK_SET 102 && markinfo->mode != XT_MARK_AND 103 && markinfo->mode != XT_MARK_OR) { 104 printk(KERN_WARNING "MARK: unknown mode %u\n", 105 markinfo->mode); 106 return 0; 107 } 108 if (markinfo->mark > 0xffffffff) { 109 printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n"); 110 return 0; 111 } 112 return 1; 113} 114 115static struct xt_target ipt_mark_reg_v0 = { 116 .name = "MARK", 117 .target = target_v0, 118 .targetsize = sizeof(struct xt_mark_target_info), 119 .table = "mangle", 120 .checkentry = checkentry_v0, 121 .me = THIS_MODULE, 122 .family = AF_INET, 123 .revision = 0, 124}; 125 126static struct xt_target ipt_mark_reg_v1 = { 127 .name = "MARK", 128 .target = target_v1, 129 .targetsize = sizeof(struct xt_mark_target_info_v1), 130 .table = "mangle", 131 .checkentry = checkentry_v1, 132 .me = THIS_MODULE, 133 .family = AF_INET, 134 .revision = 1, 135}; 136 137static struct xt_target ip6t_mark_reg_v0 = { 138 .name = "MARK", 139 .target = target_v0, 140 .targetsize = sizeof(struct xt_mark_target_info), 141 .table = "mangle", 142 .checkentry = checkentry_v0, 143 .me = THIS_MODULE, 144 .family = AF_INET6, 145 .revision = 0, 146}; 147 148static int __init xt_mark_init(void) 149{ 150 int err; 151 152 err = xt_register_target(&ipt_mark_reg_v0); 153 if (err) 154 return err; 155 156 err = xt_register_target(&ipt_mark_reg_v1); 157 if (err) 158 xt_unregister_target(&ipt_mark_reg_v0); 159 160 err = xt_register_target(&ip6t_mark_reg_v0); 161 if (err) { 162 xt_unregister_target(&ipt_mark_reg_v0); 163 xt_unregister_target(&ipt_mark_reg_v1); 164 } 165 166 return err; 167} 168 169static void __exit xt_mark_fini(void) 170{ 171 xt_unregister_target(&ipt_mark_reg_v0); 172 xt_unregister_target(&ipt_mark_reg_v1); 173 xt_unregister_target(&ip6t_mark_reg_v0); 174} 175 176module_init(xt_mark_init); 177module_exit(xt_mark_fini);