ip6t_eui64.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Kernel module to match EUI64 address parameters. */
  2. /* (C) 2001-2002 Andras Kis-Szabo <kisza@sch.bme.hu>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/skbuff.h>
  10. #include <linux/ipv6.h>
  11. #include <linux/if_ether.h>
  12. #include <linux/netfilter/x_tables.h>
  13. #include <linux/netfilter_ipv6/ip6_tables.h>
  14. MODULE_DESCRIPTION("Xtables: IPv6 EUI64 address match");
  15. MODULE_LICENSE("GPL");
  16. MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
  17. static bool
  18. eui64_mt6(const struct sk_buff *skb, struct xt_action_param *par)
  19. {
  20. unsigned char eui64[8];
  21. if (!(skb_mac_header(skb) >= skb->head &&
  22. skb_mac_header(skb) + ETH_HLEN <= skb->data) &&
  23. par->fragoff != 0) {
  24. par->hotdrop = true;
  25. return false;
  26. }
  27. memset(eui64, 0, sizeof(eui64));
  28. if (eth_hdr(skb)->h_proto == htons(ETH_P_IPV6)) {
  29. if (ipv6_hdr(skb)->version == 0x6) {
  30. memcpy(eui64, eth_hdr(skb)->h_source, 3);
  31. memcpy(eui64 + 5, eth_hdr(skb)->h_source + 3, 3);
  32. eui64[3] = 0xff;
  33. eui64[4] = 0xfe;
  34. eui64[0] ^= 0x02;
  35. if (!memcmp(ipv6_hdr(skb)->saddr.s6_addr + 8, eui64,
  36. sizeof(eui64)))
  37. return true;
  38. }
  39. }
  40. return false;
  41. }
  42. static struct xt_match eui64_mt6_reg __read_mostly = {
  43. .name = "eui64",
  44. .family = NFPROTO_IPV6,
  45. .match = eui64_mt6,
  46. .matchsize = sizeof(int),
  47. .hooks = (1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_IN) |
  48. (1 << NF_INET_FORWARD),
  49. .me = THIS_MODULE,
  50. };
  51. static int __init eui64_mt6_init(void)
  52. {
  53. return xt_register_match(&eui64_mt6_reg);
  54. }
  55. static void __exit eui64_mt6_exit(void)
  56. {
  57. xt_unregister_match(&eui64_mt6_reg);
  58. }
  59. module_init(eui64_mt6_init);
  60. module_exit(eui64_mt6_exit);