xt_MARK源码请教
时间:2010-08-06
来源:互联网
内核版本2.6.22.19,iptables1.3.8
复制代码
特向高人请教不明白之处:
1.target_v0和target_v1,怎么有两个版本,其它模块都只有一个的啊?
2.#ifdef CONFIG_COMPAT
这个CONFIG_COMPAT是什么东西来的
- /* This is a module which is used for setting the NFMARK field of an skb. */
-
- /* (C) 1999-2001 Marc Boucher <[email protected]>
- *
- * 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/skbuff.h>
- #include <linux/ip.h>
- #include <net/checksum.h>
-
- #include <linux/netfilter/x_tables.h>
- #include <linux/netfilter/xt_MARK.h>
-
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR("Marc Boucher <[email protected]>");
- MODULE_DESCRIPTION("ip[6]tables MARK modification module");
- MODULE_ALIAS("ipt_MARK");
- MODULE_ALIAS("ip6t_MARK");
-
- static unsigned int
- target_v0(struct sk_buff **pskb,
- const struct net_device *in,
- const struct net_device *out,
- unsigned int hooknum,
- const struct xt_target *target,
- const void *targinfo)
- {
- const struct xt_mark_target_info *markinfo = targinfo;
-
- (*pskb)->mark = markinfo->mark;
- return XT_CONTINUE;
- }
-
- static unsigned int
- target_v1(struct sk_buff **pskb,
- const struct net_device *in,
- const struct net_device *out,
- unsigned int hooknum,
- const struct xt_target *target,
- const void *targinfo)
- {
- const struct xt_mark_target_info_v1 *markinfo = targinfo;
- int mark = 0;
-
- switch (markinfo->mode) {
- case XT_MARK_SET:
- mark = markinfo->mark;
- break;
-
- case XT_MARK_AND:
- mark = (*pskb)->mark & markinfo->mark;
- break;
-
- case XT_MARK_OR:
- mark = (*pskb)->mark | markinfo->mark;
- break;
- }
-
- (*pskb)->mark = mark;
- return XT_CONTINUE;
- }
-
-
- static int
- checkentry_v0(const char *tablename,
- const void *entry,
- const struct xt_target *target,
- void *targinfo,
- unsigned int hook_mask)
- {
- struct xt_mark_target_info *markinfo = targinfo;
-
- if (markinfo->mark > 0xffffffff) {
- printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
- return 0;
- }
- return 1;
- }
-
- static int
- checkentry_v1(const char *tablename,
- const void *entry,
- const struct xt_target *target,
- void *targinfo,
- unsigned int hook_mask)
- {
- struct xt_mark_target_info_v1 *markinfo = targinfo;
-
- if (markinfo->mode != XT_MARK_SET
- && markinfo->mode != XT_MARK_AND
- && markinfo->mode != XT_MARK_OR) {
- printk(KERN_WARNING "MARK: unknown mode %u\n",
- markinfo->mode);
- return 0;
- }
- if (markinfo->mark > 0xffffffff) {
- printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n");
- return 0;
- }
- return 1;
- }
-
- #ifdef CONFIG_COMPAT
- struct compat_xt_mark_target_info_v1 {
- compat_ulong_t mark;
- u_int8_t mode;
- u_int8_t __pad1;
- u_int16_t __pad2;
- };
-
- static void compat_from_user_v1(void *dst, void *src)
- {
- struct compat_xt_mark_target_info_v1 *cm = src;
- struct xt_mark_target_info_v1 m = {
- .mark = cm->mark,
- .mode = cm->mode,
- };
- memcpy(dst, &m, sizeof(m));
- }
-
- static int compat_to_user_v1(void __user *dst, void *src)
- {
- struct xt_mark_target_info_v1 *m = src;
- struct compat_xt_mark_target_info_v1 cm = {
- .mark = m->mark,
- .mode = m->mode,
- };
- return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
- }
- #endif /* CONFIG_COMPAT */
-
- static struct xt_target xt_mark_target[] = {
- {
- .name = "MARK",
- .family = AF_INET,
- .revision = 0,
- .checkentry = checkentry_v0,
- .target = target_v0,
- .targetsize = sizeof(struct xt_mark_target_info),
- .table = "mangle",
- .me = THIS_MODULE,
- },
- {
- .name = "MARK",
- .family = AF_INET,
- .revision = 1,
- .checkentry = checkentry_v1,
- .target = target_v1,
- .targetsize = sizeof(struct xt_mark_target_info_v1),
- #ifdef CONFIG_COMPAT
- .compatsize = sizeof(struct compat_xt_mark_target_info_v1),
- .compat_from_user = compat_from_user_v1,
- .compat_to_user = compat_to_user_v1,
- #endif
- .table = "mangle",
- .me = THIS_MODULE,
- },
- {
- .name = "MARK",
- .family = AF_INET6,
- .revision = 0,
- .checkentry = checkentry_v0,
- .target = target_v0,
- .targetsize = sizeof(struct xt_mark_target_info),
- .table = "mangle",
- .me = THIS_MODULE,
- },
- };
-
- static int __init xt_mark_init(void)
- {
- return xt_register_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
- }
-
- static void __exit xt_mark_fini(void)
- {
- xt_unregister_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target));
- }
-
- module_init(xt_mark_init);
- module_exit(xt_mark_fini);
1.target_v0和target_v1,怎么有两个版本,其它模块都只有一个的啊?
2.#ifdef CONFIG_COMPAT
这个CONFIG_COMPAT是什么东西来的
作者: zhoutao0712 发布时间: 2010-08-06
建议到程序区问问。感觉是配置时使用的一个控制参数吧。
作者: renxiao2003 发布时间: 2010-08-06
关于 COMPAT 的文章这里提到了一点点
http://blog.chinaunix.net/u1/38994/showart_2246878.html
至于为什么同时有两个版本,可能是为了照顾不同用户态程序,v1 比 v0 功能更强大些,但为了保持兼容性,保留了 v0
http://blog.chinaunix.net/u1/38994/showart_2246878.html
至于为什么同时有两个版本,可能是为了照顾不同用户态程序,v1 比 v0 功能更强大些,但为了保持兼容性,保留了 v0
作者: platinum 发布时间: 2010-08-06
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28