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_ipv4/ipt_comment.h>
17 /* Function which prints out usage message. */
22 "COMMENT match options:\n"
23 "--comment COMMENT Attach a comment to a rule\n\n"
27 static struct option opts
[] = {
28 { "comment", 1, 0, '1' },
33 parse_comment(const char *s
, struct ipt_comment_info
*info
)
37 if (slen
>= IPT_MAX_COMMENT_LEN
) {
38 exit_error(PARAMETER_PROBLEM
,
39 "COMMENT must be shorter than %i characters", IPT_MAX_COMMENT_LEN
);
41 strcpy((char *)info
->comment
, s
);
44 /* Function which parses command options; returns true if it
47 parse(int c
, char **argv
, int invert
, unsigned int *flags
,
48 const struct ipt_entry
*entry
,
49 unsigned int *nfcache
,
50 struct ipt_entry_match
**match
)
52 struct ipt_comment_info
*commentinfo
= (struct ipt_comment_info
*)(*match
)->data
;
56 check_inverse(argv
[optind
-1], &invert
, &optind
, 0);
58 exit_error(PARAMETER_PROBLEM
,
59 "Sorry, you can't have an inverted comment");
61 parse_comment(argv
[optind
-1], commentinfo
);
71 /* Final check; must have specified --comment. */
73 final_check(unsigned int flags
)
76 exit_error(PARAMETER_PROBLEM
,
77 "COMMENT match: You must specify `--comment'");
80 /* Prints out the matchinfo. */
82 print(const struct ipt_ip
*ip
,
83 const struct ipt_entry_match
*match
,
86 struct ipt_comment_info
*commentinfo
= (struct ipt_comment_info
*)match
->data
;
88 commentinfo
->comment
[IPT_MAX_COMMENT_LEN
-1] = '\0';
89 printf("/* %s */ ", commentinfo
->comment
);
92 /* Saves the union ipt_matchinfo in parsable form to stdout. */
94 save(const struct ipt_ip
*ip
, const struct ipt_entry_match
*match
)
96 struct ipt_comment_info
*commentinfo
= (struct ipt_comment_info
*)match
->data
;
98 commentinfo
->comment
[IPT_MAX_COMMENT_LEN
-1] = '\0';
99 printf("--comment \"%s\" ", commentinfo
->comment
);
102 static struct iptables_match comment
= {
105 .version
= IPTABLES_VERSION
,
106 .size
= IPT_ALIGN(sizeof(struct ipt_comment_info
)),
107 .userspacesize
= IPT_ALIGN(sizeof(struct ipt_comment_info
)),
110 .final_check
= &final_check
,
118 register_match(&comment
);