ip6table_raw.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * IPv6 raw table, a port of the IPv4 raw table to IPv6
  3. *
  4. * Copyright (C) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
  5. */
  6. #include <linux/module.h>
  7. #include <linux/netfilter_ipv6/ip6_tables.h>
  8. #include <linux/slab.h>
  9. #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
  10. static const struct xt_table packet_raw = {
  11. .name = "raw",
  12. .valid_hooks = RAW_VALID_HOOKS,
  13. .me = THIS_MODULE,
  14. .af = NFPROTO_IPV6,
  15. .priority = NF_IP6_PRI_RAW,
  16. };
  17. /* The work comes in here from netfilter.c. */
  18. static unsigned int
  19. ip6table_raw_hook(void *priv, struct sk_buff *skb,
  20. const struct nf_hook_state *state)
  21. {
  22. return ip6t_do_table(skb, state, state->net->ipv6.ip6table_raw);
  23. }
  24. static struct nf_hook_ops *rawtable_ops __read_mostly;
  25. static int __net_init ip6table_raw_net_init(struct net *net)
  26. {
  27. struct ip6t_replace *repl;
  28. repl = ip6t_alloc_initial_table(&packet_raw);
  29. if (repl == NULL)
  30. return -ENOMEM;
  31. net->ipv6.ip6table_raw =
  32. ip6t_register_table(net, &packet_raw, repl);
  33. kfree(repl);
  34. return PTR_ERR_OR_ZERO(net->ipv6.ip6table_raw);
  35. }
  36. static void __net_exit ip6table_raw_net_exit(struct net *net)
  37. {
  38. ip6t_unregister_table(net, net->ipv6.ip6table_raw);
  39. }
  40. static struct pernet_operations ip6table_raw_net_ops = {
  41. .init = ip6table_raw_net_init,
  42. .exit = ip6table_raw_net_exit,
  43. };
  44. static int __init ip6table_raw_init(void)
  45. {
  46. int ret;
  47. ret = register_pernet_subsys(&ip6table_raw_net_ops);
  48. if (ret < 0)
  49. return ret;
  50. /* Register hooks */
  51. rawtable_ops = xt_hook_link(&packet_raw, ip6table_raw_hook);
  52. if (IS_ERR(rawtable_ops)) {
  53. ret = PTR_ERR(rawtable_ops);
  54. goto cleanup_table;
  55. }
  56. return ret;
  57. cleanup_table:
  58. unregister_pernet_subsys(&ip6table_raw_net_ops);
  59. return ret;
  60. }
  61. static void __exit ip6table_raw_fini(void)
  62. {
  63. xt_hook_unlink(&packet_raw, rawtable_ops);
  64. unregister_pernet_subsys(&ip6table_raw_net_ops);
  65. }
  66. module_init(ip6table_raw_init);
  67. module_exit(ip6table_raw_fini);
  68. MODULE_LICENSE("GPL");