xt_CHECKSUM.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* iptables module for the packet checksum mangling
  2. *
  3. * (C) 2002 by Harald Welte <laforge@netfilter.org>
  4. * (C) 2010 Red Hat, Inc.
  5. *
  6. * Author: Michael S. Tsirkin <mst@redhat.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/module.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/netfilter/x_tables.h>
  16. #include <linux/netfilter/xt_CHECKSUM.h>
  17. MODULE_LICENSE("GPL");
  18. MODULE_AUTHOR("Michael S. Tsirkin <mst@redhat.com>");
  19. MODULE_DESCRIPTION("Xtables: checksum modification");
  20. MODULE_ALIAS("ipt_CHECKSUM");
  21. MODULE_ALIAS("ip6t_CHECKSUM");
  22. static unsigned int
  23. checksum_tg(struct sk_buff *skb, const struct xt_action_param *par)
  24. {
  25. if (skb->ip_summed == CHECKSUM_PARTIAL)
  26. skb_checksum_help(skb);
  27. return XT_CONTINUE;
  28. }
  29. static int checksum_tg_check(const struct xt_tgchk_param *par)
  30. {
  31. const struct xt_CHECKSUM_info *einfo = par->targinfo;
  32. if (einfo->operation & ~XT_CHECKSUM_OP_FILL) {
  33. pr_info("unsupported CHECKSUM operation %x\n", einfo->operation);
  34. return -EINVAL;
  35. }
  36. if (!einfo->operation) {
  37. pr_info("no CHECKSUM operation enabled\n");
  38. return -EINVAL;
  39. }
  40. return 0;
  41. }
  42. static struct xt_target checksum_tg_reg __read_mostly = {
  43. .name = "CHECKSUM",
  44. .family = NFPROTO_UNSPEC,
  45. .target = checksum_tg,
  46. .targetsize = sizeof(struct xt_CHECKSUM_info),
  47. .table = "mangle",
  48. .checkentry = checksum_tg_check,
  49. .me = THIS_MODULE,
  50. };
  51. static int __init checksum_tg_init(void)
  52. {
  53. return xt_register_target(&checksum_tg_reg);
  54. }
  55. static void __exit checksum_tg_exit(void)
  56. {
  57. xt_unregister_target(&checksum_tg_reg);
  58. }
  59. module_init(checksum_tg_init);
  60. module_exit(checksum_tg_exit);