4 * Bart De Schuymer <bdschuym@pandora.be>
10 #define __need_suseconds_t
15 #include "../include/ebtables_u.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'
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
},
37 static void print_help()
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
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
;
73 uloginfo
= (struct ebt_ulog_info
*)(*watcher
)->data
;
76 if (ebt_check_inverse2(optarg
))
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
);
85 if (ebt_check_inverse2(optarg
))
87 ebt_check_option2(flags
, OPT_NLGROUP
);
88 i
= strtoul(optarg
, &end
, 10);
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;
97 if (ebt_check_inverse2(optarg
))
99 ebt_check_option2(flags
, OPT_CPRANGE
);
100 i
= strtoul(optarg
, &end
, 10);
102 if (strcasecmp(optarg
, CP_NO_LIMIT_S
))
103 ebt_print_error2("Problem with ulog-cprange: %s", optarg
);
106 uloginfo
->cprange
= i
;
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);
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
;
121 if (ebt_check_inverse(optarg
))
122 goto inverse_invalid
;
123 ebt_check_option2(flags
, OPT_ULOG
);
132 ebt_print_error("The use of '!' makes no sense for the ulog watcher");
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
);
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
))
170 static struct ebt_u_watcher ulog_watcher
=
173 .size
= sizeof(struct ebt_ulog_info
),
177 .final_check
= final_check
,
185 ebt_register_watcher(&ulog_watcher
);