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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* Kernel module to match EUI64 address parameters. */
  2. #include <linux/module.h>
  3. #include <linux/skbuff.h>
  4. #include <linux/ipv6.h>
  5. #include <linux/if_ether.h>
  6. #include <linux/netfilter_ipv6/ip6_tables.h>
  7. static int
  8. match(const struct sk_buff *skb,
  9.       const struct net_device *in,
  10.       const struct net_device *out,
  11.       const void *matchinfo,
  12.       int offset,
  13.       const void *hdr,
  14.       u_int16_t datalen,
  15.       int *hotdrop)
  16. {
  17.     unsigned char eui64[8];
  18.     int i=0;
  19.      if ( !(skb->mac.raw >= skb->head
  20.                 && (skb->mac.raw + ETH_HLEN) <= skb->data)
  21.                 && offset != 0) {
  22.                         *hotdrop = 1;
  23.                         return 0;
  24.                 }
  25.     
  26.     memset(eui64, 0, sizeof(eui64));
  27.     if (skb->mac.ethernet->h_proto == ntohs(ETH_P_IPV6)) {
  28.       if (skb->nh.ipv6h->version == 0x6) { 
  29.          memcpy(eui64, skb->mac.ethernet->h_source, 3);
  30.          memcpy(eui64 + 5, skb->mac.ethernet->h_source + 3, 3);
  31.  eui64[3]=0xff;
  32.  eui64[4]=0xfe;
  33.  eui64[0] |= 0x02;
  34.  i=0;
  35.  while ((skb->nh.ipv6h->saddr.in6_u.u6_addr8[8+i] ==
  36.  eui64[i]) && (i<8)) i++;
  37.  if ( i == 8 )
  38.   return 1;
  39.       }
  40.     }
  41.     return 0;
  42. }
  43. static int
  44. ip6t_eui64_checkentry(const char *tablename,
  45.    const struct ip6t_ip6 *ip,
  46.    void *matchinfo,
  47.    unsigned int matchsize,
  48.    unsigned int hook_mask)
  49. {
  50. if (hook_mask
  51.     & ~((1 << NF_IP6_PRE_ROUTING) | (1 << NF_IP6_LOCAL_IN) |
  52. (1 << NF_IP6_PRE_ROUTING) )) {
  53. printk("ip6t_eui64: only valid for PRE_ROUTING, LOCAL_IN or FORWARD.n");
  54. return 0;
  55. }
  56. if (matchsize != IP6T_ALIGN(sizeof(int)))
  57. return 0;
  58. return 1;
  59. }
  60. static struct ip6t_match eui64_match
  61. = { { NULL, NULL }, "eui64", &match, &ip6t_eui64_checkentry, NULL, THIS_MODULE };
  62. static int __init init(void)
  63. {
  64. return ip6t_register_match(&eui64_match);
  65. }
  66. static void __exit fini(void)
  67. {
  68. ip6t_unregister_match(&eui64_match);
  69. }
  70. module_init(init);
  71. module_exit(fini);
  72. MODULE_DESCRIPTION("IPv6 EUI64 address checking match");
  73. MODULE_LICENSE("GPL");
  74. MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");