libxt_comment.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Shared library add-on to iptables to add comment match support.
  2. *
  3. * ChangeLog
  4. * 2003-05-13: Brad Fisher <brad@info-link.net>
  5. * Initial comment match
  6. * 2004-05-12: Brad Fisher <brad@info-link.net>
  7. * Port to patch-o-matic-ng
  8. */
  9. #include <stdio.h>
  10. #include <xtables.h>
  11. #include <linux/netfilter/xt_comment.h>
  12. enum {
  13. O_COMMENT = 0,
  14. };
  15. static void comment_help(void)
  16. {
  17. printf(
  18. "comment match options:\n"
  19. "--comment COMMENT Attach a comment to a rule\n");
  20. }
  21. static const struct xt_option_entry comment_opts[] = {
  22. {.name = "comment", .id = O_COMMENT, .type = XTTYPE_STRING,
  23. .flags = XTOPT_MAND | XTOPT_PUT,
  24. XTOPT_POINTER(struct xt_comment_info, comment)},
  25. XTOPT_TABLEEND,
  26. };
  27. static void
  28. comment_print(const void *ip, const struct xt_entry_match *match, int numeric)
  29. {
  30. struct xt_comment_info *commentinfo = (void *)match->data;
  31. commentinfo->comment[XT_MAX_COMMENT_LEN-1] = '\0';
  32. printf(" /* %s */", commentinfo->comment);
  33. }
  34. /* Saves the union ipt_matchinfo in parsable form to stdout. */
  35. static void
  36. comment_save(const void *ip, const struct xt_entry_match *match)
  37. {
  38. struct xt_comment_info *commentinfo = (void *)match->data;
  39. commentinfo->comment[XT_MAX_COMMENT_LEN-1] = '\0';
  40. printf(" --comment");
  41. xtables_save_string(commentinfo->comment);
  42. }
  43. static struct xtables_match comment_match = {
  44. .family = NFPROTO_UNSPEC,
  45. .name = "comment",
  46. .version = XTABLES_VERSION,
  47. .size = XT_ALIGN(sizeof(struct xt_comment_info)),
  48. .userspacesize = XT_ALIGN(sizeof(struct xt_comment_info)),
  49. .help = comment_help,
  50. .print = comment_print,
  51. .save = comment_save,
  52. .x6_parse = xtables_option_parse,
  53. .x6_options = comment_opts,
  54. };
  55. void _init(void)
  56. {
  57. xtables_register_match(&comment_match);
  58. }