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