免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: springwind426
打印 上一主题 下一主题

[网络管理] 发布一个速度匹配的内核模块(hashspeed) [复制链接]

论坛徽章:
0
51 [报告]
发表于 2008-01-07 09:20 |只看该作者
原帖由 springwind426 于 2008-1-4 13:40 发表


我用这个:
iptables -t mangle -A POSTROUTING -o 内网网卡 -m hashspeed --hashspeed-name squid --hashspeed-mode dstip \! --hashspeed-bytes 64K -j DROP

能够把通过代理访问的内网主机的下载速度 ...


在mangle上做规则确实可以了。
但如果将下载限制到100K的话,那对浏览网页有没有影响呢,这个咋测试,用感观还是其他什么软件?

论坛徽章:
0
52 [报告]
发表于 2008-01-07 13:48 |只看该作者
至于有没有影响,你需要自己去测试

如果客户端开了下载上传的软件,可能会对自己有一些影响。

论坛徽章:
0
53 [报告]
发表于 2008-01-11 13:22 |只看该作者
执行iptables -m hashspeed --help 可以看到hashspeed,
但是执行iptables -A FORWARD -o eth0 -m iprange ! --dst-range 192.168.1.81-192.168.1.90 -m hashspeed  ! --hashspeed-bytes 60K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP
提示iptables: No chain/target/match by that name

论坛徽章:
0
54 [报告]
发表于 2008-01-14 10:04 |只看该作者
不错,限制成下载64K,好用

论坛徽章:
0
55 [报告]
发表于 2008-03-05 20:51 |只看该作者
老大,你的主页我这里打不开啊。。。

对了,可以的话,能传输份最新的上来么?反正文件不大的~~~ 不是不支持您主页,确实是访问不能啊。。。

论坛徽章:
0
56 [报告]
发表于 2008-03-06 19:01 |只看该作者
真是抱歉,前两天重启了电脑,忘记开web服务了

现在已经更新了第一个帖子上的附件

论坛徽章:
0
57 [报告]
发表于 2008-03-06 19:32 |只看该作者
原帖由 springwind426 于 2008-3-6 19:01 发表
真是抱歉,前两天重启了电脑,忘记开web服务了

现在已经更新了第一个帖子上的附件


呵呵,下载了,但是结果好像大概是由于我用的 iptables 1.4.0 和 gcc 4.1.2 所有有些不尽如人意


  1. make
  2. make -C /lib/modules/2.6.24.3skylove/build M=/data/hashspeed-0.1 modules
  3. make[1]: Entering directory `/data/linux-2.6.24.3'
  4.   CC [M]  /data/hashspeed-0.1/ipt_hashspeed.o
  5. /data/hashspeed-0.1/ipt_hashspeed.c: 在函数 ‘ipt_hashspeed_init’ 中:
  6. /data/hashspeed-0.1/ipt_hashspeed.c:751: 错误:‘proc_net’ 未声明 (在此函数内第一次使用)
  7. /data/hashspeed-0.1/ipt_hashspeed.c:751: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
  8. /data/hashspeed-0.1/ipt_hashspeed.c:751: 错误:所在的函数内只报告一次。)
  9. /data/hashspeed-0.1/ipt_hashspeed.c: 在函数 ‘ipt_hashspeed_fini’ 中:
  10. /data/hashspeed-0.1/ipt_hashspeed.c:773: 错误:‘proc_net’ 未声明 (在此函数内第一次使用)
  11. make[2]: *** [/data/hashspeed-0.1/ipt_hashspeed.o] 错误 1
  12. make[1]: *** [_module_/data/hashspeed-0.1] 错误 2
  13. make[1]: Leaving directory `/data/linux-2.6.24.3'
  14. make: *** [ipt_hashspeed.ko] 错误 2
复制代码


我尝试着处理,但是没辙。。。盼助

论坛徽章:
0
58 [报告]
发表于 2008-03-07 13:45 |只看该作者
你查看查看

proc_net 是在 include/linux/proc_fs.h中定义的

我没有用过2.6.24,是不是定义有变化?
在include/linux/proc_fs.h中有proc_mkdir的定义

论坛徽章:
0
59 [报告]
发表于 2008-03-07 17:44 |只看该作者
原帖由 springwind426 于 2008-3-7 13:45 发表
你查看查看

proc_net 是在 include/linux/proc_fs.h中定义的

我没有用过2.6.24,是不是定义有变化?
在include/linux/proc_fs.h中有proc_mkdir的定义


我现在在外面,今天单位女同志过节,我搭着吃饭。。。 回去了试一下,感谢哦

论坛徽章:
0
60 [报告]
发表于 2008-03-08 08:30 |只看该作者
原帖由 springwind426 于 2008-3-7 13:45 发表
你查看查看

proc_net 是在 include/linux/proc_fs.h中定义的

我没有用过2.6.24,是不是定义有变化?
在include/linux/proc_fs.h中有proc_mkdir的定义


我将这个版本的 proc_fs.h 贴出,麻烦您参考看看,给点意见?


  1. cat proc_fs.h   
  2. #ifndef _LINUX_PROC_FS_H
  3. #define _LINUX_PROC_FS_H

  4. #include <linux/slab.h>
  5. #include <linux/fs.h>
  6. #include <linux/spinlock.h>
  7. #include <linux/magic.h>
  8. #include <asm/atomic.h>

  9. struct net;
  10. struct completion;

  11. /*
  12. * The proc filesystem constants/structures
  13. */

  14. /*
  15. * Offset of the first process in the /proc root directory..
  16. */
  17. #define FIRST_PROCESS_ENTRY 256


  18. /*
  19. * We always define these enumerators
  20. */

  21. enum {
  22.         PROC_ROOT_INO = 1,
  23. };

  24. /*
  25. * This is not completely implemented yet. The idea is to
  26. * create an in-memory tree (like the actual /proc filesystem
  27. * tree) of these proc_dir_entries, so that we can dynamically
  28. * add new files to /proc.
  29. *
  30. * The "next" pointer creates a linked list of one /proc directory,
  31. * while parent/subdir create the directory structure (every
  32. * /proc file has a parent, but "subdir" is NULL for all
  33. * non-directory entries).
  34. *
  35. * "get_info" is called at "read", while "owner" is used to protect module
  36. * from unloading while proc_dir_entry is in use
  37. */

  38. typedef int (read_proc_t)(char *page, char **start, off_t off,
  39.                           int count, int *eof, void *data);
  40. typedef int (write_proc_t)(struct file *file, const char __user *buffer,
  41.                            unsigned long count, void *data);
  42. typedef int (get_info_t)(char *, char **, off_t, int);
  43. typedef struct proc_dir_entry *(shadow_proc_t)(struct task_struct *task,
  44.                                                 struct proc_dir_entry *pde);

  45. struct proc_dir_entry {
  46.         unsigned int low_ino;
  47.         unsigned short namelen;
  48.         const char *name;
  49.         mode_t mode;
  50.         nlink_t nlink;
  51.         uid_t uid;
  52.         gid_t gid;
  53.         loff_t size;
  54.         const struct inode_operations *proc_iops;
  55.         /*
  56.          * NULL ->proc_fops means "PDE is going away RSN" or
  57.          * "PDE is just created". In either case, e.g. ->read_proc won't be
  58.          * called because it's too late or too early, respectively.
  59.          *
  60.          * If you're allocating ->proc_fops dynamically, save a pointer
  61.          * somewhere.
  62.          */
  63.         const struct file_operations *proc_fops;
  64.         get_info_t *get_info;
  65.         struct module *owner;
  66.         struct proc_dir_entry *next, *parent, *subdir;
  67.         void *data;
  68.         read_proc_t *read_proc;
  69.         write_proc_t *write_proc;
  70.         atomic_t count;         /* use count */
  71.         int pde_users;  /* number of callers into module in progress */
  72.         spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
  73.         struct completion *pde_unload_completion;
  74.         shadow_proc_t *shadow_proc;
  75. };

  76. struct kcore_list {
  77.         struct kcore_list *next;
  78.         unsigned long addr;
  79.         size_t size;
  80. };

  81. struct vmcore {
  82.         struct list_head list;
  83.         unsigned long long paddr;
  84.         unsigned long long size;
  85.         loff_t offset;
  86. };

  87. #ifdef CONFIG_PROC_FS

  88. extern struct proc_dir_entry proc_root;
  89. extern struct proc_dir_entry *proc_root_fs;
  90. extern struct proc_dir_entry *proc_bus;
  91. extern struct proc_dir_entry *proc_root_driver;
  92. extern struct proc_dir_entry *proc_root_kcore;

  93. extern spinlock_t proc_subdir_lock;

  94. extern void proc_root_init(void);
  95. extern void proc_misc_init(void);

  96. struct mm_struct;

  97. void proc_flush_task(struct task_struct *task);
  98. struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *);
  99. int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
  100. unsigned long task_vsize(struct mm_struct *);
  101. int task_statm(struct mm_struct *, int *, int *, int *, int *);
  102. char *task_mem(struct mm_struct *, char *);
  103. void clear_refs_smap(struct mm_struct *mm);

  104. struct proc_dir_entry *de_get(struct proc_dir_entry *de);
  105. void de_put(struct proc_dir_entry *de);

  106. extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
  107.                                                 struct proc_dir_entry *parent);
  108. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);

  109. extern struct vfsmount *proc_mnt;
  110. struct pid_namespace;
  111. extern int proc_fill_super(struct super_block *);
  112. extern struct inode *proc_get_inode(struct super_block *, unsigned int, struct proc_dir_entry *);

  113. /*
  114. * These are generic /proc routines that use the internal
  115. * "struct proc_dir_entry" tree to traverse the filesystem.
  116. *
  117. * The /proc root directory has extended versions to take care
  118. * of the /proc/<pid> subdirectories.
  119. */
  120. extern int proc_readdir(struct file *, void *, filldir_t);
  121. extern struct dentry *proc_lookup(struct inode *, struct dentry *, struct nameidata *);

  122. extern const struct file_operations proc_kcore_operations;
  123. extern const struct file_operations proc_kmsg_operations;
  124. extern const struct file_operations ppc_htab_operations;

  125. extern int pid_ns_prepare_proc(struct pid_namespace *ns);
  126. extern void pid_ns_release_proc(struct pid_namespace *ns);

  127. /*
  128. * proc_tty.c
  129. */
  130. struct tty_driver;
  131. extern void proc_tty_init(void);
  132. extern void proc_tty_register_driver(struct tty_driver *driver);
  133. extern void proc_tty_unregister_driver(struct tty_driver *driver);

  134. /*
  135. * proc_devtree.c
  136. */
  137. #ifdef CONFIG_PROC_DEVICETREE
  138. struct device_node;
  139. struct property;
  140. extern void proc_device_tree_init(void);
  141. extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
  142. extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
  143. extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
  144.                                          struct property *prop);
  145. extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
  146.                                          struct property *newprop,
  147.                                          struct property *oldprop);
  148. #endif /* CONFIG_PROC_DEVICETREE */

  149. extern struct proc_dir_entry *proc_symlink(const char *,
  150.                 struct proc_dir_entry *, const char *);
  151. extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
  152. extern struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
  153.                         struct proc_dir_entry *parent);

  154. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  155.         mode_t mode, struct proc_dir_entry *base,
  156.         read_proc_t *read_proc, void * data)
  157. {
  158.         struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  159.         if (res) {
  160.                 res->read_proc=read_proc;
  161.                 res->data=data;
  162.         }
  163.         return res;
  164. }

  165. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  166.         mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  167. {
  168.         struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  169.         if (res) res->get_info=get_info;
  170.         return res;
  171. }

  172. extern struct proc_dir_entry *proc_net_fops_create(struct net *net,
  173.         const char *name, mode_t mode, const struct file_operations *fops);
  174. extern void proc_net_remove(struct net *net, const char *name);

  175. #else

  176. #define proc_root_driver NULL
  177. #define proc_bus NULL

  178. #define proc_net_fops_create(net, name, mode, fops)  ({ (void)(mode), NULL; })
  179. static inline void proc_net_remove(struct net *net, const char *name) {}

  180. static inline void proc_flush_task(struct task_struct *task)
  181. {
  182. }

  183. static inline struct proc_dir_entry *create_proc_entry(const char *name,
  184.         mode_t mode, struct proc_dir_entry *parent) { return NULL; }

  185. #define remove_proc_entry(name, parent) do {} while (0)

  186. static inline struct proc_dir_entry *proc_symlink(const char *name,
  187.                 struct proc_dir_entry *parent,const char *dest) {return NULL;}
  188. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  189.         struct proc_dir_entry *parent) {return NULL;}

  190. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  191.         mode_t mode, struct proc_dir_entry *base,
  192.         read_proc_t *read_proc, void * data) { return NULL; }
  193. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  194.         mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  195.         { return NULL; }

  196. struct tty_driver;
  197. static inline void proc_tty_register_driver(struct tty_driver *driver) {};
  198. static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};

  199. extern struct proc_dir_entry proc_root;

  200. static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
  201. {
  202.         return 0;
  203. }

  204. static inline void pid_ns_release_proc(struct pid_namespace *ns)
  205. {
  206. }

  207. #endif /* CONFIG_PROC_FS */

  208. #if !defined(CONFIG_PROC_KCORE)
  209. static inline void kclist_add(struct kcore_list *new, void *addr, size_t size)
  210. {
  211. }
  212. #else
  213. extern void kclist_add(struct kcore_list *, void *, size_t);
  214. #endif

  215. union proc_op {
  216.         int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
  217.         int (*proc_read)(struct task_struct *task, char *page);
  218. };

  219. struct proc_inode {
  220.         struct pid *pid;
  221.         int fd;
  222.         union proc_op op;
  223.         struct proc_dir_entry *pde;
  224.         struct inode vfs_inode;
  225. };

  226. static inline struct proc_inode *PROC_I(const struct inode *inode)
  227. {
  228.         return container_of(inode, struct proc_inode, vfs_inode);
  229. }

  230. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  231. {
  232.         return PROC_I(inode)->pde;
  233. }

  234. static inline struct net *PDE_NET(struct proc_dir_entry *pde)
  235. {
  236.         return pde->parent->data;
  237. }

  238. struct net *get_proc_net(const struct inode *inode);

  239. struct proc_maps_private {
  240.         struct pid *pid;
  241.         struct task_struct *task;
  242. #ifdef CONFIG_MMU
  243.         struct vm_area_struct *tail_vma;
  244. #endif
  245. };

  246. #endif /* _LINUX_PROC_FS_H */
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP