libxt_CHECKSUM.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Shared library add-on to xtables for CHECKSUM
  2. *
  3. * (C) 2002 by Harald Welte <laforge@gnumonks.org>
  4. * (C) 2010 by Red Hat, Inc
  5. * Author: Michael S. Tsirkin <mst@redhat.com>
  6. *
  7. * This program is distributed under the terms of GNU GPL v2, 1991
  8. *
  9. * libxt_CHECKSUM.c borrowed some bits from libipt_ECN.c
  10. */
  11. #include <stdio.h>
  12. #include <xtables.h>
  13. #include <linux/netfilter/xt_CHECKSUM.h>
  14. enum {
  15. O_CHECKSUM_FILL = 0,
  16. };
  17. static void CHECKSUM_help(void)
  18. {
  19. printf(
  20. "CHECKSUM target options\n"
  21. " --checksum-fill Fill in packet checksum.\n");
  22. }
  23. static const struct xt_option_entry CHECKSUM_opts[] = {
  24. {.name = "checksum-fill", .id = O_CHECKSUM_FILL,
  25. .flags = XTOPT_MAND, .type = XTTYPE_NONE},
  26. XTOPT_TABLEEND,
  27. };
  28. static void CHECKSUM_parse(struct xt_option_call *cb)
  29. {
  30. struct xt_CHECKSUM_info *einfo = cb->data;
  31. xtables_option_parse(cb);
  32. einfo->operation = XT_CHECKSUM_OP_FILL;
  33. }
  34. static void CHECKSUM_print(const void *ip, const struct xt_entry_target *target,
  35. int numeric)
  36. {
  37. const struct xt_CHECKSUM_info *einfo =
  38. (const struct xt_CHECKSUM_info *)target->data;
  39. printf(" CHECKSUM");
  40. if (einfo->operation & XT_CHECKSUM_OP_FILL)
  41. printf(" fill");
  42. }
  43. static void CHECKSUM_save(const void *ip, const struct xt_entry_target *target)
  44. {
  45. const struct xt_CHECKSUM_info *einfo =
  46. (const struct xt_CHECKSUM_info *)target->data;
  47. if (einfo->operation & XT_CHECKSUM_OP_FILL)
  48. printf(" --checksum-fill");
  49. }
  50. static struct xtables_target checksum_tg_reg = {
  51. .name = "CHECKSUM",
  52. .version = XTABLES_VERSION,
  53. .family = NFPROTO_UNSPEC,
  54. .size = XT_ALIGN(sizeof(struct xt_CHECKSUM_info)),
  55. .userspacesize = XT_ALIGN(sizeof(struct xt_CHECKSUM_info)),
  56. .help = CHECKSUM_help,
  57. .print = CHECKSUM_print,
  58. .save = CHECKSUM_save,
  59. .x6_parse = CHECKSUM_parse,
  60. .x6_options = CHECKSUM_opts,
  61. };
  62. void _init(void)
  63. {
  64. xtables_register_target(&checksum_tg_reg);
  65. }