4 * Peter Warasin <peter@endian.com>
9 * ebt_ulog.c, (C) 2004, Bart De Schuymer <bdschuym@pandora.be>
17 #include "../include/ebtables_u.h"
18 #include <linux/netfilter_bridge/ebt_nflog.h>
24 NFLOG_THRESHOLD
= 0x8,
28 static struct option nflog_opts
[] = {
29 {"nflog-group", required_argument
, NULL
, NFLOG_GROUP
},
30 {"nflog-prefix", required_argument
, NULL
, NFLOG_PREFIX
},
31 {"nflog-range", required_argument
, NULL
, NFLOG_RANGE
},
32 {"nflog-threshold", required_argument
, NULL
, NFLOG_THRESHOLD
},
33 {"nflog", no_argument
, NULL
, NFLOG_NFLOG
},
37 static void nflog_help()
39 printf("nflog options:\n"
40 "--nflog : use the default nflog parameters\n"
41 "--nflog-prefix prefix : Prefix string for log message\n"
42 "--nflog-group group : NETLINK group used for logging\n"
43 "--nflog-range range : Number of byte to copy\n"
44 "--nflog-threshold : Message threshold of"
48 static void init(struct ebt_entry_watcher
*watcher
)
50 struct ebt_nflog_info
*info
= (struct ebt_nflog_info
*)watcher
->data
;
52 info
->prefix
[0] = '\0';
53 info
->group
= EBT_NFLOG_DEFAULT_GROUP
;
54 info
->threshold
= EBT_NFLOG_DEFAULT_THRESHOLD
;
57 static int nflog_parse(int c
, char **argv
, int argc
,
58 const struct ebt_u_entry
*entry
, unsigned int *flags
,
59 struct ebt_entry_watcher
**watcher
)
61 struct ebt_nflog_info
*info
;
65 info
= (struct ebt_nflog_info
*)(*watcher
)->data
;
68 if (ebt_check_inverse2(optarg
))
70 ebt_check_option2(flags
, NFLOG_PREFIX
);
71 if (strlen(optarg
) > EBT_NFLOG_PREFIX_SIZE
- 1)
72 ebt_print_error("Prefix too long for nflog-prefix");
73 strcpy(info
->prefix
, optarg
);
77 if (ebt_check_inverse2(optarg
))
79 ebt_check_option2(flags
, NFLOG_GROUP
);
80 i
= strtoul(optarg
, &end
, 10);
82 ebt_print_error2("--nflog-group must be a number!");
87 if (ebt_check_inverse2(optarg
))
89 ebt_check_option2(flags
, NFLOG_RANGE
);
90 i
= strtoul(optarg
, &end
, 10);
92 ebt_print_error2("--nflog-range must be a number!");
97 if (ebt_check_inverse2(optarg
))
99 ebt_check_option2(flags
, NFLOG_THRESHOLD
);
100 i
= strtoul(optarg
, &end
, 10);
102 ebt_print_error2("--nflog-threshold must be a number!");
106 if (ebt_check_inverse(optarg
))
107 goto inverse_invalid
;
108 ebt_check_option2(flags
, NFLOG_NFLOG
);
117 ebt_print_error("The use of '!' makes no sense for the nflog watcher");
121 static void nflog_final_check(const struct ebt_u_entry
*entry
,
122 const struct ebt_entry_watcher
*watcher
,
123 const char *name
, unsigned int hookmask
,
128 static void nflog_print(const struct ebt_u_entry
*entry
,
129 const struct ebt_entry_watcher
*watcher
)
131 struct ebt_nflog_info
*info
= (struct ebt_nflog_info
*)watcher
->data
;
133 if (info
->prefix
[0] != '\0')
134 printf("--nflog-prefix \"%s\"", info
->prefix
);
136 printf("--nflog-group %d ", info
->group
);
138 printf("--nflog-range %d", info
->len
);
139 if (info
->threshold
!= EBT_NFLOG_DEFAULT_THRESHOLD
)
140 printf(" --nflog-threshold %d ", info
->threshold
);
143 static int nflog_compare(const struct ebt_entry_watcher
*w1
,
144 const struct ebt_entry_watcher
*w2
)
146 struct ebt_nflog_info
*info1
= (struct ebt_nflog_info
*)w1
->data
;
147 struct ebt_nflog_info
*info2
= (struct ebt_nflog_info
*)w2
->data
;
149 if (info1
->group
!= info2
->group
||
150 info1
->len
!= info2
->len
||
151 info1
->threshold
!= info2
->threshold
||
152 strcmp(info1
->prefix
, info2
->prefix
))
157 static struct ebt_u_watcher nflog_watcher
= {
159 .size
= sizeof(struct ebt_nflog_info
),
162 .parse
= nflog_parse
,
163 .final_check
= nflog_final_check
,
164 .print
= nflog_print
,
165 .compare
= nflog_compare
,
166 .extra_ops
= nflog_opts
,
171 ebt_register_watcher(&nflog_watcher
);