1*3f189349SFlorian Westphal // SPDX-License-Identifier: GPL-2.0
2*3f189349SFlorian Westphal
3*3f189349SFlorian Westphal #include <errno.h>
4*3f189349SFlorian Westphal #include <stdbool.h>
5*3f189349SFlorian Westphal #include <stdio.h>
6*3f189349SFlorian Westphal #include <stdint.h>
7*3f189349SFlorian Westphal #include <stdlib.h>
8*3f189349SFlorian Westphal #include <unistd.h>
9*3f189349SFlorian Westphal #include <string.h>
10*3f189349SFlorian Westphal #include <time.h>
11*3f189349SFlorian Westphal #include <arpa/inet.h>
12*3f189349SFlorian Westphal
13*3f189349SFlorian Westphal #include <libmnl/libmnl.h>
14*3f189349SFlorian Westphal #include <linux/netfilter.h>
15*3f189349SFlorian Westphal #include <linux/netfilter/nfnetlink.h>
16*3f189349SFlorian Westphal #include <linux/netfilter/nfnetlink_queue.h>
17*3f189349SFlorian Westphal
18*3f189349SFlorian Westphal struct options {
19*3f189349SFlorian Westphal bool count_packets;
20*3f189349SFlorian Westphal bool gso_enabled;
21*3f189349SFlorian Westphal int verbose;
22*3f189349SFlorian Westphal unsigned int queue_num;
23*3f189349SFlorian Westphal unsigned int timeout;
24*3f189349SFlorian Westphal uint32_t verdict;
25*3f189349SFlorian Westphal uint32_t delay_ms;
26*3f189349SFlorian Westphal };
27*3f189349SFlorian Westphal
28*3f189349SFlorian Westphal static unsigned int queue_stats[5];
29*3f189349SFlorian Westphal static struct options opts;
30*3f189349SFlorian Westphal
help(const char * p)31*3f189349SFlorian Westphal static void help(const char *p)
32*3f189349SFlorian Westphal {
33*3f189349SFlorian Westphal printf("Usage: %s [-c|-v [-vv] ] [-t timeout] [-q queue_num] [-Qdst_queue ] [ -d ms_delay ] [-G]\n", p);
34*3f189349SFlorian Westphal }
35*3f189349SFlorian Westphal
parse_attr_cb(const struct nlattr * attr,void * data)36*3f189349SFlorian Westphal static int parse_attr_cb(const struct nlattr *attr, void *data)
37*3f189349SFlorian Westphal {
38*3f189349SFlorian Westphal const struct nlattr **tb = data;
39*3f189349SFlorian Westphal int type = mnl_attr_get_type(attr);
40*3f189349SFlorian Westphal
41*3f189349SFlorian Westphal /* skip unsupported attribute in user-space */
42*3f189349SFlorian Westphal if (mnl_attr_type_valid(attr, NFQA_MAX) < 0)
43*3f189349SFlorian Westphal return MNL_CB_OK;
44*3f189349SFlorian Westphal
45*3f189349SFlorian Westphal switch (type) {
46*3f189349SFlorian Westphal case NFQA_MARK:
47*3f189349SFlorian Westphal case NFQA_IFINDEX_INDEV:
48*3f189349SFlorian Westphal case NFQA_IFINDEX_OUTDEV:
49*3f189349SFlorian Westphal case NFQA_IFINDEX_PHYSINDEV:
50*3f189349SFlorian Westphal case NFQA_IFINDEX_PHYSOUTDEV:
51*3f189349SFlorian Westphal if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) {
52*3f189349SFlorian Westphal perror("mnl_attr_validate");
53*3f189349SFlorian Westphal return MNL_CB_ERROR;
54*3f189349SFlorian Westphal }
55*3f189349SFlorian Westphal break;
56*3f189349SFlorian Westphal case NFQA_TIMESTAMP:
57*3f189349SFlorian Westphal if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC,
58*3f189349SFlorian Westphal sizeof(struct nfqnl_msg_packet_timestamp)) < 0) {
59*3f189349SFlorian Westphal perror("mnl_attr_validate2");
60*3f189349SFlorian Westphal return MNL_CB_ERROR;
61*3f189349SFlorian Westphal }
62*3f189349SFlorian Westphal break;
63*3f189349SFlorian Westphal case NFQA_HWADDR:
64*3f189349SFlorian Westphal if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC,
65*3f189349SFlorian Westphal sizeof(struct nfqnl_msg_packet_hw)) < 0) {
66*3f189349SFlorian Westphal perror("mnl_attr_validate2");
67*3f189349SFlorian Westphal return MNL_CB_ERROR;
68*3f189349SFlorian Westphal }
69*3f189349SFlorian Westphal break;
70*3f189349SFlorian Westphal case NFQA_PAYLOAD:
71*3f189349SFlorian Westphal break;
72*3f189349SFlorian Westphal }
73*3f189349SFlorian Westphal tb[type] = attr;
74*3f189349SFlorian Westphal return MNL_CB_OK;
75*3f189349SFlorian Westphal }
76*3f189349SFlorian Westphal
queue_cb(const struct nlmsghdr * nlh,void * data)77*3f189349SFlorian Westphal static int queue_cb(const struct nlmsghdr *nlh, void *data)
78*3f189349SFlorian Westphal {
79*3f189349SFlorian Westphal struct nlattr *tb[NFQA_MAX+1] = { 0 };
80*3f189349SFlorian Westphal struct nfqnl_msg_packet_hdr *ph = NULL;
81*3f189349SFlorian Westphal uint32_t id = 0;
82*3f189349SFlorian Westphal
83*3f189349SFlorian Westphal (void)data;
84*3f189349SFlorian Westphal
85*3f189349SFlorian Westphal mnl_attr_parse(nlh, sizeof(struct nfgenmsg), parse_attr_cb, tb);
86*3f189349SFlorian Westphal if (tb[NFQA_PACKET_HDR]) {
87*3f189349SFlorian Westphal ph = mnl_attr_get_payload(tb[NFQA_PACKET_HDR]);
88*3f189349SFlorian Westphal id = ntohl(ph->packet_id);
89*3f189349SFlorian Westphal
90*3f189349SFlorian Westphal if (opts.verbose > 0)
91*3f189349SFlorian Westphal printf("packet hook=%u, hwproto 0x%x",
92*3f189349SFlorian Westphal ntohs(ph->hw_protocol), ph->hook);
93*3f189349SFlorian Westphal
94*3f189349SFlorian Westphal if (ph->hook >= 5) {
95*3f189349SFlorian Westphal fprintf(stderr, "Unknown hook %d\n", ph->hook);
96*3f189349SFlorian Westphal return MNL_CB_ERROR;
97*3f189349SFlorian Westphal }
98*3f189349SFlorian Westphal
99*3f189349SFlorian Westphal if (opts.verbose > 0) {
100*3f189349SFlorian Westphal uint32_t skbinfo = 0;
101*3f189349SFlorian Westphal
102*3f189349SFlorian Westphal if (tb[NFQA_SKB_INFO])
103*3f189349SFlorian Westphal skbinfo = ntohl(mnl_attr_get_u32(tb[NFQA_SKB_INFO]));
104*3f189349SFlorian Westphal if (skbinfo & NFQA_SKB_CSUMNOTREADY)
105*3f189349SFlorian Westphal printf(" csumnotready");
106*3f189349SFlorian Westphal if (skbinfo & NFQA_SKB_GSO)
107*3f189349SFlorian Westphal printf(" gso");
108*3f189349SFlorian Westphal if (skbinfo & NFQA_SKB_CSUM_NOTVERIFIED)
109*3f189349SFlorian Westphal printf(" csumnotverified");
110*3f189349SFlorian Westphal puts("");
111*3f189349SFlorian Westphal }
112*3f189349SFlorian Westphal
113*3f189349SFlorian Westphal if (opts.count_packets)
114*3f189349SFlorian Westphal queue_stats[ph->hook]++;
115*3f189349SFlorian Westphal }
116*3f189349SFlorian Westphal
117*3f189349SFlorian Westphal return MNL_CB_OK + id;
118*3f189349SFlorian Westphal }
119*3f189349SFlorian Westphal
120*3f189349SFlorian Westphal static struct nlmsghdr *
nfq_build_cfg_request(char * buf,uint8_t command,int queue_num)121*3f189349SFlorian Westphal nfq_build_cfg_request(char *buf, uint8_t command, int queue_num)
122*3f189349SFlorian Westphal {
123*3f189349SFlorian Westphal struct nlmsghdr *nlh = mnl_nlmsg_put_header(buf);
124*3f189349SFlorian Westphal struct nfqnl_msg_config_cmd cmd = {
125*3f189349SFlorian Westphal .command = command,
126*3f189349SFlorian Westphal .pf = htons(AF_INET),
127*3f189349SFlorian Westphal };
128*3f189349SFlorian Westphal struct nfgenmsg *nfg;
129*3f189349SFlorian Westphal
130*3f189349SFlorian Westphal nlh->nlmsg_type = (NFNL_SUBSYS_QUEUE << 8) | NFQNL_MSG_CONFIG;
131*3f189349SFlorian Westphal nlh->nlmsg_flags = NLM_F_REQUEST;
132*3f189349SFlorian Westphal
133*3f189349SFlorian Westphal nfg = mnl_nlmsg_put_extra_header(nlh, sizeof(*nfg));
134*3f189349SFlorian Westphal
135*3f189349SFlorian Westphal nfg->nfgen_family = AF_UNSPEC;
136*3f189349SFlorian Westphal nfg->version = NFNETLINK_V0;
137*3f189349SFlorian Westphal nfg->res_id = htons(queue_num);
138*3f189349SFlorian Westphal
139*3f189349SFlorian Westphal mnl_attr_put(nlh, NFQA_CFG_CMD, sizeof(cmd), &cmd);
140*3f189349SFlorian Westphal
141*3f189349SFlorian Westphal return nlh;
142*3f189349SFlorian Westphal }
143*3f189349SFlorian Westphal
144*3f189349SFlorian Westphal static struct nlmsghdr *
nfq_build_cfg_params(char * buf,uint8_t mode,int range,int queue_num)145*3f189349SFlorian Westphal nfq_build_cfg_params(char *buf, uint8_t mode, int range, int queue_num)
146*3f189349SFlorian Westphal {
147*3f189349SFlorian Westphal struct nlmsghdr *nlh = mnl_nlmsg_put_header(buf);
148*3f189349SFlorian Westphal struct nfqnl_msg_config_params params = {
149*3f189349SFlorian Westphal .copy_range = htonl(range),
150*3f189349SFlorian Westphal .copy_mode = mode,
151*3f189349SFlorian Westphal };
152*3f189349SFlorian Westphal struct nfgenmsg *nfg;
153*3f189349SFlorian Westphal
154*3f189349SFlorian Westphal nlh->nlmsg_type = (NFNL_SUBSYS_QUEUE << 8) | NFQNL_MSG_CONFIG;
155*3f189349SFlorian Westphal nlh->nlmsg_flags = NLM_F_REQUEST;
156*3f189349SFlorian Westphal
157*3f189349SFlorian Westphal nfg = mnl_nlmsg_put_extra_header(nlh, sizeof(*nfg));
158*3f189349SFlorian Westphal nfg->nfgen_family = AF_UNSPEC;
159*3f189349SFlorian Westphal nfg->version = NFNETLINK_V0;
160*3f189349SFlorian Westphal nfg->res_id = htons(queue_num);
161*3f189349SFlorian Westphal
162*3f189349SFlorian Westphal mnl_attr_put(nlh, NFQA_CFG_PARAMS, sizeof(params), ¶ms);
163*3f189349SFlorian Westphal
164*3f189349SFlorian Westphal return nlh;
165*3f189349SFlorian Westphal }
166*3f189349SFlorian Westphal
167*3f189349SFlorian Westphal static struct nlmsghdr *
nfq_build_verdict(char * buf,int id,int queue_num,uint32_t verd)168*3f189349SFlorian Westphal nfq_build_verdict(char *buf, int id, int queue_num, uint32_t verd)
169*3f189349SFlorian Westphal {
170*3f189349SFlorian Westphal struct nfqnl_msg_verdict_hdr vh = {
171*3f189349SFlorian Westphal .verdict = htonl(verd),
172*3f189349SFlorian Westphal .id = htonl(id),
173*3f189349SFlorian Westphal };
174*3f189349SFlorian Westphal struct nlmsghdr *nlh;
175*3f189349SFlorian Westphal struct nfgenmsg *nfg;
176*3f189349SFlorian Westphal
177*3f189349SFlorian Westphal nlh = mnl_nlmsg_put_header(buf);
178*3f189349SFlorian Westphal nlh->nlmsg_type = (NFNL_SUBSYS_QUEUE << 8) | NFQNL_MSG_VERDICT;
179*3f189349SFlorian Westphal nlh->nlmsg_flags = NLM_F_REQUEST;
180*3f189349SFlorian Westphal nfg = mnl_nlmsg_put_extra_header(nlh, sizeof(*nfg));
181*3f189349SFlorian Westphal nfg->nfgen_family = AF_UNSPEC;
182*3f189349SFlorian Westphal nfg->version = NFNETLINK_V0;
183*3f189349SFlorian Westphal nfg->res_id = htons(queue_num);
184*3f189349SFlorian Westphal
185*3f189349SFlorian Westphal mnl_attr_put(nlh, NFQA_VERDICT_HDR, sizeof(vh), &vh);
186*3f189349SFlorian Westphal
187*3f189349SFlorian Westphal return nlh;
188*3f189349SFlorian Westphal }
189*3f189349SFlorian Westphal
print_stats(void)190*3f189349SFlorian Westphal static void print_stats(void)
191*3f189349SFlorian Westphal {
192*3f189349SFlorian Westphal unsigned int last, total;
193*3f189349SFlorian Westphal int i;
194*3f189349SFlorian Westphal
195*3f189349SFlorian Westphal total = 0;
196*3f189349SFlorian Westphal last = queue_stats[0];
197*3f189349SFlorian Westphal
198*3f189349SFlorian Westphal for (i = 0; i < 5; i++) {
199*3f189349SFlorian Westphal printf("hook %d packets %08u\n", i, queue_stats[i]);
200*3f189349SFlorian Westphal last = queue_stats[i];
201*3f189349SFlorian Westphal total += last;
202*3f189349SFlorian Westphal }
203*3f189349SFlorian Westphal
204*3f189349SFlorian Westphal printf("%u packets total\n", total);
205*3f189349SFlorian Westphal }
206*3f189349SFlorian Westphal
open_queue(void)207*3f189349SFlorian Westphal struct mnl_socket *open_queue(void)
208*3f189349SFlorian Westphal {
209*3f189349SFlorian Westphal char buf[MNL_SOCKET_BUFFER_SIZE];
210*3f189349SFlorian Westphal unsigned int queue_num;
211*3f189349SFlorian Westphal struct mnl_socket *nl;
212*3f189349SFlorian Westphal struct nlmsghdr *nlh;
213*3f189349SFlorian Westphal struct timeval tv;
214*3f189349SFlorian Westphal uint32_t flags;
215*3f189349SFlorian Westphal
216*3f189349SFlorian Westphal nl = mnl_socket_open(NETLINK_NETFILTER);
217*3f189349SFlorian Westphal if (nl == NULL) {
218*3f189349SFlorian Westphal perror("mnl_socket_open");
219*3f189349SFlorian Westphal exit(EXIT_FAILURE);
220*3f189349SFlorian Westphal }
221*3f189349SFlorian Westphal
222*3f189349SFlorian Westphal if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
223*3f189349SFlorian Westphal perror("mnl_socket_bind");
224*3f189349SFlorian Westphal exit(EXIT_FAILURE);
225*3f189349SFlorian Westphal }
226*3f189349SFlorian Westphal
227*3f189349SFlorian Westphal queue_num = opts.queue_num;
228*3f189349SFlorian Westphal nlh = nfq_build_cfg_request(buf, NFQNL_CFG_CMD_BIND, queue_num);
229*3f189349SFlorian Westphal
230*3f189349SFlorian Westphal if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
231*3f189349SFlorian Westphal perror("mnl_socket_sendto");
232*3f189349SFlorian Westphal exit(EXIT_FAILURE);
233*3f189349SFlorian Westphal }
234*3f189349SFlorian Westphal
235*3f189349SFlorian Westphal nlh = nfq_build_cfg_params(buf, NFQNL_COPY_PACKET, 0xFFFF, queue_num);
236*3f189349SFlorian Westphal
237*3f189349SFlorian Westphal flags = opts.gso_enabled ? NFQA_CFG_F_GSO : 0;
238*3f189349SFlorian Westphal flags |= NFQA_CFG_F_UID_GID;
239*3f189349SFlorian Westphal mnl_attr_put_u32(nlh, NFQA_CFG_FLAGS, htonl(flags));
240*3f189349SFlorian Westphal mnl_attr_put_u32(nlh, NFQA_CFG_MASK, htonl(flags));
241*3f189349SFlorian Westphal
242*3f189349SFlorian Westphal if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
243*3f189349SFlorian Westphal perror("mnl_socket_sendto");
244*3f189349SFlorian Westphal exit(EXIT_FAILURE);
245*3f189349SFlorian Westphal }
246*3f189349SFlorian Westphal
247*3f189349SFlorian Westphal memset(&tv, 0, sizeof(tv));
248*3f189349SFlorian Westphal tv.tv_sec = opts.timeout;
249*3f189349SFlorian Westphal if (opts.timeout && setsockopt(mnl_socket_get_fd(nl),
250*3f189349SFlorian Westphal SOL_SOCKET, SO_RCVTIMEO,
251*3f189349SFlorian Westphal &tv, sizeof(tv))) {
252*3f189349SFlorian Westphal perror("setsockopt(SO_RCVTIMEO)");
253*3f189349SFlorian Westphal exit(EXIT_FAILURE);
254*3f189349SFlorian Westphal }
255*3f189349SFlorian Westphal
256*3f189349SFlorian Westphal return nl;
257*3f189349SFlorian Westphal }
258*3f189349SFlorian Westphal
sleep_ms(uint32_t delay)259*3f189349SFlorian Westphal static void sleep_ms(uint32_t delay)
260*3f189349SFlorian Westphal {
261*3f189349SFlorian Westphal struct timespec ts = { .tv_sec = delay / 1000 };
262*3f189349SFlorian Westphal
263*3f189349SFlorian Westphal delay %= 1000;
264*3f189349SFlorian Westphal
265*3f189349SFlorian Westphal ts.tv_nsec = delay * 1000llu * 1000llu;
266*3f189349SFlorian Westphal
267*3f189349SFlorian Westphal nanosleep(&ts, NULL);
268*3f189349SFlorian Westphal }
269*3f189349SFlorian Westphal
mainloop(void)270*3f189349SFlorian Westphal static int mainloop(void)
271*3f189349SFlorian Westphal {
272*3f189349SFlorian Westphal unsigned int buflen = 64 * 1024 + MNL_SOCKET_BUFFER_SIZE;
273*3f189349SFlorian Westphal struct mnl_socket *nl;
274*3f189349SFlorian Westphal struct nlmsghdr *nlh;
275*3f189349SFlorian Westphal unsigned int portid;
276*3f189349SFlorian Westphal char *buf;
277*3f189349SFlorian Westphal int ret;
278*3f189349SFlorian Westphal
279*3f189349SFlorian Westphal buf = malloc(buflen);
280*3f189349SFlorian Westphal if (!buf) {
281*3f189349SFlorian Westphal perror("malloc");
282*3f189349SFlorian Westphal exit(EXIT_FAILURE);
283*3f189349SFlorian Westphal }
284*3f189349SFlorian Westphal
285*3f189349SFlorian Westphal nl = open_queue();
286*3f189349SFlorian Westphal portid = mnl_socket_get_portid(nl);
287*3f189349SFlorian Westphal
288*3f189349SFlorian Westphal for (;;) {
289*3f189349SFlorian Westphal uint32_t id;
290*3f189349SFlorian Westphal
291*3f189349SFlorian Westphal ret = mnl_socket_recvfrom(nl, buf, buflen);
292*3f189349SFlorian Westphal if (ret == -1) {
293*3f189349SFlorian Westphal if (errno == ENOBUFS || errno == EINTR)
294*3f189349SFlorian Westphal continue;
295*3f189349SFlorian Westphal
296*3f189349SFlorian Westphal if (errno == EAGAIN) {
297*3f189349SFlorian Westphal errno = 0;
298*3f189349SFlorian Westphal ret = 0;
299*3f189349SFlorian Westphal break;
300*3f189349SFlorian Westphal }
301*3f189349SFlorian Westphal
302*3f189349SFlorian Westphal perror("mnl_socket_recvfrom");
303*3f189349SFlorian Westphal exit(EXIT_FAILURE);
304*3f189349SFlorian Westphal }
305*3f189349SFlorian Westphal
306*3f189349SFlorian Westphal ret = mnl_cb_run(buf, ret, 0, portid, queue_cb, NULL);
307*3f189349SFlorian Westphal if (ret < 0) {
308*3f189349SFlorian Westphal perror("mnl_cb_run");
309*3f189349SFlorian Westphal exit(EXIT_FAILURE);
310*3f189349SFlorian Westphal }
311*3f189349SFlorian Westphal
312*3f189349SFlorian Westphal id = ret - MNL_CB_OK;
313*3f189349SFlorian Westphal if (opts.delay_ms)
314*3f189349SFlorian Westphal sleep_ms(opts.delay_ms);
315*3f189349SFlorian Westphal
316*3f189349SFlorian Westphal nlh = nfq_build_verdict(buf, id, opts.queue_num, opts.verdict);
317*3f189349SFlorian Westphal if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
318*3f189349SFlorian Westphal perror("mnl_socket_sendto");
319*3f189349SFlorian Westphal exit(EXIT_FAILURE);
320*3f189349SFlorian Westphal }
321*3f189349SFlorian Westphal }
322*3f189349SFlorian Westphal
323*3f189349SFlorian Westphal mnl_socket_close(nl);
324*3f189349SFlorian Westphal
325*3f189349SFlorian Westphal return ret;
326*3f189349SFlorian Westphal }
327*3f189349SFlorian Westphal
parse_opts(int argc,char ** argv)328*3f189349SFlorian Westphal static void parse_opts(int argc, char **argv)
329*3f189349SFlorian Westphal {
330*3f189349SFlorian Westphal int c;
331*3f189349SFlorian Westphal
332*3f189349SFlorian Westphal while ((c = getopt(argc, argv, "chvt:q:Q:d:G")) != -1) {
333*3f189349SFlorian Westphal switch (c) {
334*3f189349SFlorian Westphal case 'c':
335*3f189349SFlorian Westphal opts.count_packets = true;
336*3f189349SFlorian Westphal break;
337*3f189349SFlorian Westphal case 'h':
338*3f189349SFlorian Westphal help(argv[0]);
339*3f189349SFlorian Westphal exit(0);
340*3f189349SFlorian Westphal break;
341*3f189349SFlorian Westphal case 'q':
342*3f189349SFlorian Westphal opts.queue_num = atoi(optarg);
343*3f189349SFlorian Westphal if (opts.queue_num > 0xffff)
344*3f189349SFlorian Westphal opts.queue_num = 0;
345*3f189349SFlorian Westphal break;
346*3f189349SFlorian Westphal case 'Q':
347*3f189349SFlorian Westphal opts.verdict = atoi(optarg);
348*3f189349SFlorian Westphal if (opts.verdict > 0xffff) {
349*3f189349SFlorian Westphal fprintf(stderr, "Expected destination queue number\n");
350*3f189349SFlorian Westphal exit(1);
351*3f189349SFlorian Westphal }
352*3f189349SFlorian Westphal
353*3f189349SFlorian Westphal opts.verdict <<= 16;
354*3f189349SFlorian Westphal opts.verdict |= NF_QUEUE;
355*3f189349SFlorian Westphal break;
356*3f189349SFlorian Westphal case 'd':
357*3f189349SFlorian Westphal opts.delay_ms = atoi(optarg);
358*3f189349SFlorian Westphal if (opts.delay_ms == 0) {
359*3f189349SFlorian Westphal fprintf(stderr, "Expected nonzero delay (in milliseconds)\n");
360*3f189349SFlorian Westphal exit(1);
361*3f189349SFlorian Westphal }
362*3f189349SFlorian Westphal break;
363*3f189349SFlorian Westphal case 't':
364*3f189349SFlorian Westphal opts.timeout = atoi(optarg);
365*3f189349SFlorian Westphal break;
366*3f189349SFlorian Westphal case 'G':
367*3f189349SFlorian Westphal opts.gso_enabled = false;
368*3f189349SFlorian Westphal break;
369*3f189349SFlorian Westphal case 'v':
370*3f189349SFlorian Westphal opts.verbose++;
371*3f189349SFlorian Westphal break;
372*3f189349SFlorian Westphal }
373*3f189349SFlorian Westphal }
374*3f189349SFlorian Westphal
375*3f189349SFlorian Westphal if (opts.verdict != NF_ACCEPT && (opts.verdict >> 16 == opts.queue_num)) {
376*3f189349SFlorian Westphal fprintf(stderr, "Cannot use same destination and source queue\n");
377*3f189349SFlorian Westphal exit(1);
378*3f189349SFlorian Westphal }
379*3f189349SFlorian Westphal }
380*3f189349SFlorian Westphal
main(int argc,char * argv[])381*3f189349SFlorian Westphal int main(int argc, char *argv[])
382*3f189349SFlorian Westphal {
383*3f189349SFlorian Westphal int ret;
384*3f189349SFlorian Westphal
385*3f189349SFlorian Westphal opts.verdict = NF_ACCEPT;
386*3f189349SFlorian Westphal opts.gso_enabled = true;
387*3f189349SFlorian Westphal
388*3f189349SFlorian Westphal parse_opts(argc, argv);
389*3f189349SFlorian Westphal
390*3f189349SFlorian Westphal ret = mainloop();
391*3f189349SFlorian Westphal if (opts.count_packets)
392*3f189349SFlorian Westphal print_stats();
393*3f189349SFlorian Westphal
394*3f189349SFlorian Westphal return ret;
395*3f189349SFlorian Westphal }
396