1 /* Shared library add-on to iptables to add comment match support.
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
15 #include <linux/netfilter/xt_comment.h>
17 /* Function which prints out usage message. */
18 static void comment_help(void)
21 "comment match options:\n"
22 "--comment COMMENT Attach a comment to a rule\n");
25 static const struct option comment_opts[] = {
26 { "comment", 1, NULL, '1' },
31 parse_comment(const char *s, struct xt_comment_info *info)
35 if (slen >= XT_MAX_COMMENT_LEN) {
36 exit_error(PARAMETER_PROBLEM,
37 "COMMENT must be shorter than %i characters", XT_MAX_COMMENT_LEN);
39 strcpy((char *)info->comment, s);
42 /* Function which parses command options; returns true if it
45 comment_parse(int c, char **argv, int invert, unsigned int *flags,
46 const void *entry, struct xt_entry_match **match)
48 struct xt_comment_info *commentinfo = (struct xt_comment_info *)(*match)->data;
52 check_inverse(argv[optind-1], &invert, &optind, 0);
54 exit_error(PARAMETER_PROBLEM,
55 "Sorry, you can't have an inverted comment");
57 parse_comment(argv[optind-1], commentinfo);
67 /* Final check; must have specified --comment. */
68 static void comment_check(unsigned int flags)
71 exit_error(PARAMETER_PROBLEM,
72 "COMMENT match: You must specify `--comment'");
75 /* Prints out the matchinfo. */
77 comment_print(const void *ip, const struct xt_entry_match *match, int numeric)
79 struct xt_comment_info *commentinfo = (struct xt_comment_info *)match->data;
81 commentinfo->comment[XT_MAX_COMMENT_LEN-1] = '\0';
82 printf("/* %s */ ", commentinfo->comment);
85 /* Saves the union ipt_matchinfo in parsable form to stdout. */
87 comment_save(const void *ip, const struct xt_entry_match *match)
89 struct xt_comment_info *commentinfo = (struct xt_comment_info *)match->data;
91 commentinfo->comment[XT_MAX_COMMENT_LEN-1] = '\0';
92 printf("--comment \"%s\" ", commentinfo->comment);
95 static struct xtables_match comment_match = {
98 .version = XTABLES_VERSION,
99 .size = XT_ALIGN(sizeof(struct xt_comment_info)),
100 .userspacesize = XT_ALIGN(sizeof(struct xt_comment_info)),
101 .help = comment_help,
102 .parse = comment_parse,
103 .final_check = comment_check,
104 .print = comment_print,
105 .save = comment_save,
106 .extra_opts = comment_opts,
109 static struct xtables_match comment_match6 = {
112 .version = XTABLES_VERSION,
113 .size = XT_ALIGN(sizeof(struct xt_comment_info)),
114 .userspacesize = XT_ALIGN(sizeof(struct xt_comment_info)),
115 .help = comment_help,
116 .parse = comment_parse,
117 .final_check = comment_check,
118 .print = comment_print,
119 .save = comment_save,
120 .extra_opts = comment_opts,
125 xtables_register_match(&comment_match);
126 xtables_register_match(&comment_match6);