nft_reject_ipv6.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2008-2009 Patrick McHardy <kaber@trash.net>
  3. * Copyright (c) 2013 Eric Leblond <eric@regit.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Development of this code funded by Astaro AG (http://www.astaro.com/)
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include <linux/netlink.h>
  15. #include <linux/netfilter.h>
  16. #include <linux/netfilter/nf_tables.h>
  17. #include <net/netfilter/nf_tables.h>
  18. #include <net/netfilter/nft_reject.h>
  19. #include <net/netfilter/ipv6/nf_reject.h>
  20. static void nft_reject_ipv6_eval(const struct nft_expr *expr,
  21. struct nft_regs *regs,
  22. const struct nft_pktinfo *pkt)
  23. {
  24. struct nft_reject *priv = nft_expr_priv(expr);
  25. switch (priv->type) {
  26. case NFT_REJECT_ICMP_UNREACH:
  27. nf_send_unreach6(pkt->net, pkt->skb, priv->icmp_code,
  28. pkt->hook);
  29. break;
  30. case NFT_REJECT_TCP_RST:
  31. nf_send_reset6(pkt->net, pkt->skb, pkt->hook);
  32. break;
  33. default:
  34. break;
  35. }
  36. regs->verdict.code = NF_DROP;
  37. }
  38. static struct nft_expr_type nft_reject_ipv6_type;
  39. static const struct nft_expr_ops nft_reject_ipv6_ops = {
  40. .type = &nft_reject_ipv6_type,
  41. .size = NFT_EXPR_SIZE(sizeof(struct nft_reject)),
  42. .eval = nft_reject_ipv6_eval,
  43. .init = nft_reject_init,
  44. .dump = nft_reject_dump,
  45. };
  46. static struct nft_expr_type nft_reject_ipv6_type __read_mostly = {
  47. .family = NFPROTO_IPV6,
  48. .name = "reject",
  49. .ops = &nft_reject_ipv6_ops,
  50. .policy = nft_reject_policy,
  51. .maxattr = NFTA_REJECT_MAX,
  52. .owner = THIS_MODULE,
  53. };
  54. static int __init nft_reject_ipv6_module_init(void)
  55. {
  56. return nft_register_expr(&nft_reject_ipv6_type);
  57. }
  58. static void __exit nft_reject_ipv6_module_exit(void)
  59. {
  60. nft_unregister_expr(&nft_reject_ipv6_type);
  61. }
  62. module_init(nft_reject_ipv6_module_init);
  63. module_exit(nft_reject_ipv6_module_exit);
  64. MODULE_LICENSE("GPL");
  65. MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
  66. MODULE_ALIAS_NFT_AF_EXPR(AF_INET6, "reject");