libxt_tcpmss.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <stdio.h>
  2. #include <xtables.h>
  3. #include <linux/netfilter/xt_tcpmss.h>
  4. enum {
  5. O_TCPMSS = 0,
  6. };
  7. static void tcpmss_help(void)
  8. {
  9. printf(
  10. "tcpmss match options:\n"
  11. "[!] --mss value[:value] Match TCP MSS range.\n"
  12. " (only valid for TCP SYN or SYN/ACK packets)\n");
  13. }
  14. static const struct xt_option_entry tcpmss_opts[] = {
  15. {.name = "mss", .id = O_TCPMSS, .type = XTTYPE_UINT16RC,
  16. .flags = XTOPT_MAND | XTOPT_INVERT},
  17. XTOPT_TABLEEND,
  18. };
  19. static void tcpmss_parse(struct xt_option_call *cb)
  20. {
  21. struct xt_tcpmss_match_info *mssinfo = cb->data;
  22. xtables_option_parse(cb);
  23. mssinfo->mss_min = cb->val.u16_range[0];
  24. mssinfo->mss_max = mssinfo->mss_min;
  25. if (cb->nvals == 2)
  26. mssinfo->mss_max = cb->val.u16_range[1];
  27. if (cb->invert)
  28. mssinfo->invert = 1;
  29. }
  30. static void
  31. tcpmss_print(const void *ip, const struct xt_entry_match *match, int numeric)
  32. {
  33. const struct xt_tcpmss_match_info *info = (void *)match->data;
  34. printf(" tcpmss match %s", info->invert ? "!" : "");
  35. if (info->mss_min == info->mss_max)
  36. printf("%u", info->mss_min);
  37. else
  38. printf("%u:%u", info->mss_min, info->mss_max);
  39. }
  40. static void tcpmss_save(const void *ip, const struct xt_entry_match *match)
  41. {
  42. const struct xt_tcpmss_match_info *info = (void *)match->data;
  43. printf("%s --mss ", info->invert ? " !" : "");
  44. if (info->mss_min == info->mss_max)
  45. printf("%u", info->mss_min);
  46. else
  47. printf("%u:%u", info->mss_min, info->mss_max);
  48. }
  49. static struct xtables_match tcpmss_match = {
  50. .family = NFPROTO_UNSPEC,
  51. .name = "tcpmss",
  52. .version = XTABLES_VERSION,
  53. .size = XT_ALIGN(sizeof(struct xt_tcpmss_match_info)),
  54. .userspacesize = XT_ALIGN(sizeof(struct xt_tcpmss_match_info)),
  55. .help = tcpmss_help,
  56. .print = tcpmss_print,
  57. .save = tcpmss_save,
  58. .x6_parse = tcpmss_parse,
  59. .x6_options = tcpmss_opts,
  60. };
  61. void _init(void)
  62. {
  63. xtables_register_match(&tcpmss_match);
  64. }