Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / ebtables / extensions / ebt_ulog.c
blob162586d7a4c3545f505f1b12e88bf4b0fa07a541
1 /* ebt_ulog
3 * Authors:
4 * Bart De Schuymer <bdschuym@pandora.be>
6 * November, 2004
7 */
9 #define __need_time_t
10 #define __need_suseconds_t
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <getopt.h>
15 #include "../include/ebtables_u.h"
16 #include <sys/time.h>
17 #include <linux/netfilter_bridge/ebt_ulog.h>
19 #define CP_NO_LIMIT_S "default_cprange"
20 #define CP_NO_LIMIT_N 0
22 #define ULOG_PREFIX '1'
23 #define ULOG_NLGROUP '2'
24 #define ULOG_CPRANGE '3'
25 #define ULOG_QTHRESHOLD '4'
26 #define ULOG_ULOG '5'
27 static struct option opts[] =
29 { "ulog-prefix" , required_argument, 0, ULOG_PREFIX },
30 { "ulog-nlgroup" , required_argument, 0, ULOG_NLGROUP },
31 { "ulog-cprange" , required_argument, 0, ULOG_CPRANGE },
32 { "ulog-qthreshold", required_argument, 0, ULOG_QTHRESHOLD },
33 { "ulog" , no_argument , 0, ULOG_ULOG },
34 { 0 }
37 static void print_help()
39 printf(
40 "ulog options:\n"
41 "--ulog : use the default ulog parameters\n"
42 "--ulog-prefix prefix : max %d characters (default is no prefix)\n"
43 "--ulog-nlgroup group : 0 < group number < %d (default = %d)\n"
44 "--ulog-cprange range : max copy range (default is " CP_NO_LIMIT_S ")\n"
45 "--ulog-qthreshold : 0 < queueing threshold < %d (default = %d)\n",
46 EBT_ULOG_PREFIX_LEN - 1, EBT_ULOG_MAXNLGROUPS + 1,
47 EBT_ULOG_DEFAULT_NLGROUP + 1, EBT_ULOG_MAX_QLEN + 1,
48 EBT_ULOG_DEFAULT_QTHRESHOLD);
51 static void init(struct ebt_entry_watcher *watcher)
53 struct ebt_ulog_info *uloginfo = (struct ebt_ulog_info *)watcher->data;
55 uloginfo->prefix[0] = '\0';
56 uloginfo->nlgroup = EBT_ULOG_DEFAULT_NLGROUP;
57 uloginfo->cprange = CP_NO_LIMIT_N; /* Use default netlink buffer size */
58 uloginfo->qthreshold = EBT_ULOG_DEFAULT_QTHRESHOLD;
61 #define OPT_PREFIX 0x01
62 #define OPT_NLGROUP 0x02
63 #define OPT_CPRANGE 0x04
64 #define OPT_QTHRESHOLD 0x08
65 #define OPT_ULOG 0x10
66 static int parse(int c, char **argv, int argc, const struct ebt_u_entry *entry,
67 unsigned int *flags, struct ebt_entry_watcher **watcher)
69 struct ebt_ulog_info *uloginfo;
70 unsigned int i;
71 char *end;
73 uloginfo = (struct ebt_ulog_info *)(*watcher)->data;
74 switch (c) {
75 case ULOG_PREFIX:
76 if (ebt_check_inverse2(optarg))
77 goto inverse_invalid;
78 ebt_check_option2(flags, OPT_PREFIX);
79 if (strlen(optarg) > EBT_ULOG_PREFIX_LEN - 1)
80 ebt_print_error("Prefix too long for ulog-prefix");
81 strcpy(uloginfo->prefix, optarg);
82 break;
84 case ULOG_NLGROUP:
85 if (ebt_check_inverse2(optarg))
86 goto inverse_invalid;
87 ebt_check_option2(flags, OPT_NLGROUP);
88 i = strtoul(optarg, &end, 10);
89 if (*end != '\0')
90 ebt_print_error2("Problem with ulog-nlgroup: %s", optarg);
91 if (i < 1 || i > EBT_ULOG_MAXNLGROUPS)
92 ebt_print_error2("the ulog-nlgroup number must be between 1 and 32");
93 uloginfo->nlgroup = i - 1;
94 break;
96 case ULOG_CPRANGE:
97 if (ebt_check_inverse2(optarg))
98 goto inverse_invalid;
99 ebt_check_option2(flags, OPT_CPRANGE);
100 i = strtoul(optarg, &end, 10);
101 if (*end != '\0') {
102 if (strcasecmp(optarg, CP_NO_LIMIT_S))
103 ebt_print_error2("Problem with ulog-cprange: %s", optarg);
104 i = CP_NO_LIMIT_N;
106 uloginfo->cprange = i;
107 break;
109 case ULOG_QTHRESHOLD:
110 if (ebt_check_inverse2(optarg))
111 goto inverse_invalid;
112 ebt_check_option2(flags, OPT_QTHRESHOLD);
113 i = strtoul(optarg, &end, 10);
114 if (*end != '\0')
115 ebt_print_error2("Problem with ulog-qthreshold: %s", optarg);
116 if (i > EBT_ULOG_MAX_QLEN)
117 ebt_print_error2("ulog-qthreshold argument %d exceeds the maximum of %d", i, EBT_ULOG_MAX_QLEN);
118 uloginfo->qthreshold = i;
119 break;
120 case ULOG_ULOG:
121 if (ebt_check_inverse(optarg))
122 goto inverse_invalid;
123 ebt_check_option2(flags, OPT_ULOG);
124 break;
126 default:
127 return 0;
129 return 1;
131 inverse_invalid:
132 ebt_print_error("The use of '!' makes no sense for the ulog watcher");
133 return 1;
136 static void final_check(const struct ebt_u_entry *entry,
137 const struct ebt_entry_watcher *watcher, const char *name,
138 unsigned int hookmask, unsigned int time)
142 static void print(const struct ebt_u_entry *entry,
143 const struct ebt_entry_watcher *watcher)
145 struct ebt_ulog_info *uloginfo = (struct ebt_ulog_info *)watcher->data;
147 printf("--ulog-prefix \"%s\" --ulog-nlgroup %d --ulog-cprange ",
148 uloginfo->prefix, uloginfo->nlgroup + 1);
149 if (uloginfo->cprange == CP_NO_LIMIT_N)
150 printf(CP_NO_LIMIT_S);
151 else
152 printf("%d", uloginfo->cprange);
153 printf(" --ulog-qthreshold %d ", uloginfo->qthreshold);
156 static int compare(const struct ebt_entry_watcher *w1,
157 const struct ebt_entry_watcher *w2)
159 struct ebt_ulog_info *uloginfo1 = (struct ebt_ulog_info *)w1->data;
160 struct ebt_ulog_info *uloginfo2 = (struct ebt_ulog_info *)w2->data;
162 if (uloginfo1->nlgroup != uloginfo2->nlgroup ||
163 uloginfo1->cprange != uloginfo2->cprange ||
164 uloginfo1->qthreshold != uloginfo2->qthreshold ||
165 strcmp(uloginfo1->prefix, uloginfo2->prefix))
166 return 0;
167 return 1;
170 static struct ebt_u_watcher ulog_watcher =
172 .name = "ulog",
173 .size = sizeof(struct ebt_ulog_info),
174 .help = print_help,
175 .init = init,
176 .parse = parse,
177 .final_check = final_check,
178 .print = print,
179 .compare = compare,
180 .extra_ops = opts,
183 void _init(void)
185 ebt_register_watcher(&ulog_watcher);