ip6t_length.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:1k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* Length Match - IPv6 Port */
  2. #include <linux/module.h>
  3. #include <linux/skbuff.h>
  4. #include <linux/netfilter_ipv6/ip6t_length.h>
  5. #include <linux/netfilter_ipv6/ip6_tables.h>
  6. static int
  7. match(const struct sk_buff *skb,
  8.       const struct net_device *in,
  9.       const struct net_device *out,
  10.       const void *matchinfo,
  11.       int offset,
  12.       const void *hdr,
  13.       u_int16_t datalen,
  14.       int *hotdrop)
  15. {
  16. const struct ip6t_length_info *info = matchinfo;
  17. u_int16_t pktlen = ntohs(skb->nh.ipv6h->payload_len) + sizeof(struct ipv6hdr);
  18. return (pktlen >= info->min && pktlen <= info->max) ^ info->invert;
  19. }
  20. static int
  21. checkentry(const char *tablename,
  22.            const struct ip6t_ip6 *ip,
  23.            void *matchinfo,
  24.            unsigned int matchsize,
  25.            unsigned int hook_mask)
  26. {
  27. if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_length_info)))
  28. return 0;
  29. return 1;
  30. }
  31. static struct ip6t_match length_match
  32. = { { NULL, NULL }, "length", &match, &checkentry, NULL, THIS_MODULE };
  33. static int __init init(void)
  34. {
  35. return ip6t_register_match(&length_match);
  36. }
  37. static void __exit fini(void)
  38. {
  39. ip6t_unregister_match(&length_match);
  40. }
  41. module_init(init);
  42. module_exit(fini);