/
flow.c
759 lines (654 loc) · 20.3 KB
/
flow.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
/*
* flow.c -- flow handling utility
*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <malloc.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdbool.h>
#include <assert.h>
#include <time.h>
#include <asm/types.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/mman.h>
#include <asm/types.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/if_ether.h>
#include <net/if.h>
#ifdef __KERNEL__
#include <netinet/ether.h>
#endif
#include "vr_types.h"
#include "vr_flow.h"
#include "vr_mirror.h"
#include "vr_genetlink.h"
#include "nl_util.h"
#define TABLE_FLAG_VALID 0x1
#define MEM_DEV "/dev/flow"
static int dvrf_set, mir_set, help_set;
static unsigned short dvrf;
static int flow_index, list, flow_cmd, mirror = -1;
static int rate;
static int stats;
struct flow_table {
struct vr_flow_entry *ft_entries;
u_int64_t ft_entries_p;
u_int64_t ft_span;
u_int64_t ft_processed;
u_int64_t ft_created;
u_int64_t ft_added;
unsigned int ft_num_entries;
unsigned int ft_flags;
unsigned int ft_cpus;
unsigned int ft_hold_oflows;
u_int32_t ft_hold_stat[64];
} main_table;
int mem_fd;
struct nl_client *cl;
vr_flow_req flow_req;
struct vr_flow_entry *
flow_get(unsigned int flow_index)
{
return &main_table.ft_entries[flow_index];
}
const char *
flow_get_drop_reason(uint8_t drop_code)
{
switch (drop_code) {
case VR_FLOW_DR_UNKNOWN:
return "Unknown";
case VR_FLOW_DR_UNAVIALABLE_INTF:
return "IntfErr";
case VR_FLOW_DR_IPv4_FWD_DIS:
return "Ipv4Dis";
case VR_FLOW_DR_UNAVAILABLE_VRF:
return "VrfErr";
case VR_FLOW_DR_NO_SRC_ROUTE:
return "NoSrcRt";
case VR_FLOW_DR_NO_DST_ROUTE:
return "NoDstRt";
case VR_FLOW_DR_AUDIT_ENTRY:
return "Audit";
case VR_FLOW_DR_VRF_CHANGE:
return "VrfChange";
case VR_FLOW_DR_NO_REVERSE_FLOW:
return "NoRevFlow";
case VR_FLOW_DR_REVERSE_FLOW_CHANGE:
return "RevFlowChng";
case VR_FLOW_DR_NAT_CHANGE:
return "NatChng";
case VR_FLOW_DR_FLOW_LIMIT:
return "FlowLim";
case VR_FLOW_DR_LINKLOCAL_SRC_NAT:
return "LinkSrcNatErr";
case VR_FLOW_DR_POLICY:
return "Policy";
case VR_FLOW_DR_OUT_POLICY:
return "OutPolicy";
case VR_FLOW_DR_SG:
return "SG";
case VR_FLOW_DR_OUT_SG:
return "OutSG";
case VR_FLOW_DR_REVERSE_SG:
return "RevSG";
case VR_FLOW_DR_REVERSE_OUT_SG:
return "RevOutSG";
default:
break;
}
return NULL;
}
static void
dump_table(struct flow_table *ft)
{
unsigned int i, j, fi, need_flag_print = 0;
struct vr_flow_entry *fe;
char action, flag_string[sizeof(fe->fe_flags) * 8 + 32];
unsigned int need_drop_reason = 0;
const char *drop_reason = NULL;
struct in_addr in_src, in_dest;
printf("Flow table(size %lu, entries %lu)\n\n", ft->ft_span,
ft->ft_num_entries);
printf("Entries: Created %lu Added %lu Processed %lu\n",
ft->ft_created, ft->ft_added, ft->ft_processed);
printf("(Created Flows/CPU: ");
for (i = 0; i < ft->ft_cpus; i++) {
printf("%u", ft->ft_hold_stat[i]);
if (i != (ft->ft_cpus - 1))
printf(" ");
}
printf(")(oflows %u)\n", ft->ft_hold_oflows);
printf(" Index Source:Port Destination:Port \tProto(V)\n");
printf("-----------------------------------------------------------------");
printf("--------\n");
for (i = 0; i < ft->ft_num_entries; i++) {
bzero(flag_string, sizeof(flag_string));
need_flag_print = 0;
need_drop_reason = 0;
fe = (struct vr_flow_entry *)((char *)ft->ft_entries + (i * sizeof(*fe)));
if (fe->fe_flags & VR_FLOW_FLAG_ACTIVE) {
in_src.s_addr = fe->fe_key.key_src_ip;
in_dest.s_addr = fe->fe_key.key_dest_ip;
printf("%6d", i);
if (fe->fe_rflow >= 0)
printf("<=>%-6d", fe->fe_rflow);
else
printf(" ");
printf(" %12s:%-5d ", inet_ntoa(in_src),
ntohs(fe->fe_key.key_src_port));
printf("%16s:%-5d %d (%d",
inet_ntoa(in_dest),
ntohs(fe->fe_key.key_dst_port),
fe->fe_key.key_proto,
fe->fe_vrf);
if (fe->fe_flags & VR_FLOW_FLAG_VRFT)
printf("->%d", fe->fe_dvrf);
printf(")\n");
switch (fe->fe_action) {
case VR_FLOW_ACTION_HOLD:
action = 'H';
break;
case VR_FLOW_ACTION_FORWARD:
action = 'F';
break;
case VR_FLOW_ACTION_DROP:
action = 'D';
need_drop_reason = 1;
drop_reason = flow_get_drop_reason(fe->fe_drop_reason);
break;
case VR_FLOW_ACTION_NAT:
action = 'N';
need_flag_print = 1;
fi = 0;
for (j = 0; (j < (sizeof(fe->fe_flags) * 8)) &&
fi < sizeof(flag_string); j++)
switch ((1 << j) & fe->fe_flags) {
case VR_FLOW_FLAG_SNAT:
flag_string[fi++] = 'S';
break;
case VR_FLOW_FLAG_DNAT:
flag_string[fi++] = 'D';
break;
case VR_FLOW_FLAG_SPAT:
flag_string[fi++] = 'P';
flag_string[fi++] = 's';
break;
case VR_FLOW_FLAG_DPAT:
flag_string[fi++] = 'P';
flag_string[fi++] = 'd';
break;
case VR_FLOW_FLAG_LINK_LOCAL:
flag_string[fi++] = 'L';
}
break;
default:
action = 'U';
}
printf("\t(");
printf("K(nh):%u, ", fe->fe_key.key_nh_id);
printf("Action:%c", action);
if (need_flag_print)
printf("(%s)", flag_string);
if (need_drop_reason) {
if (drop_reason != NULL)
printf("(%s)", drop_reason);
else
printf("(%u)", fe->fe_drop_reason);
}
printf(", ");
if (fe->fe_ecmp_nh_index >= 0)
printf("E:%d, ", fe->fe_ecmp_nh_index);
printf("S(nh):%u, ", fe->fe_src_nh_index);
printf(" Statistics:%u/%u", fe->fe_stats.flow_packets,
fe->fe_stats.flow_bytes);
if (fe->fe_flags & VR_FLOW_FLAG_MIRROR) {
printf(" Mirror Index :");
if (fe->fe_mirror_id < VR_MAX_MIRROR_INDICES)
printf(" %d", fe->fe_mirror_id);
if (fe->fe_sec_mirror_id < VR_MAX_MIRROR_INDICES)
printf(", %d", fe->fe_sec_mirror_id);
}
printf(")\n\n");
}
}
return;
}
static void
flow_list(void)
{
dump_table(&main_table);
return;
}
static void
flow_stats(void)
{
struct flow_table *ft = &main_table;
unsigned int i;
struct vr_flow_entry *fe;
struct timeval now;
struct timeval last_time;
int active_entries = 0;
int hold_entries = 0;
int prev_active_entries = 0;
int prev_hold_entries = 0;
int total_entries = 0;
int prev_total_entries = 0;
int diff_ms;
int rate;
int avg_setup_rate = 0;
int avg_teardown_rate = 0;
uint64_t setup_time = 0;
uint64_t teardown_time = 0;
int total_rate;
int flow_action_drop = 0;
int flow_action_fwd = 0;
int flow_action_nat = 0;
gettimeofday(&last_time, NULL);
while (1) {
active_entries = 0;
total_entries = 0;
hold_entries = 0;
flow_action_drop = 0;
flow_action_fwd = 0;
flow_action_nat = 0;
usleep(500000);
for (i = 0; i < ft->ft_num_entries; i++) {
fe = (struct vr_flow_entry *)((char *)ft->ft_entries +
(i * sizeof(*fe)));
if (fe->fe_flags & VR_FLOW_FLAG_ACTIVE) {
total_entries++;
if (fe->fe_action != VR_FLOW_ACTION_HOLD) {
active_entries++;
} else {
hold_entries++;
}
if (fe->fe_action == VR_FLOW_ACTION_DROP) {
flow_action_drop++;
} else if (fe->fe_action == VR_FLOW_ACTION_FORWARD) {
flow_action_fwd++;
} else if (fe->fe_action == VR_FLOW_ACTION_NAT) {
flow_action_nat++;
}
}
}
gettimeofday(&now, NULL);
/* calc time difference and rate */
diff_ms = (now.tv_sec - last_time.tv_sec) * 1000;
diff_ms += (now.tv_usec - last_time.tv_usec) / 1000;
assert(diff_ms > 0 );
rate = (active_entries - prev_active_entries) * 1000;
rate /= diff_ms;
total_rate = (total_entries - prev_total_entries) * 1000;
total_rate /= diff_ms;
if (rate != 0 || total_rate != 0) {
if (rate < -1000) {
avg_teardown_rate = avg_teardown_rate * teardown_time -
(active_entries - prev_active_entries) * 1000;
teardown_time += diff_ms;
avg_teardown_rate /= teardown_time;
}
if (rate > 1000) {
avg_setup_rate = avg_setup_rate * setup_time +
(active_entries - prev_active_entries) * 1000;
setup_time += diff_ms;
avg_setup_rate /= setup_time;
}
}
system("clear");
struct tm *tm;
char fmt[64], buf[64];
if((tm = localtime(&now.tv_sec)) != NULL)
{
strftime(fmt, sizeof fmt, "%Y-%m-%d %H:%M:%S %z", tm);
snprintf(buf, sizeof buf, fmt, now.tv_usec);
printf("%s\n", buf);
}
printf("Flow Statistics\n");
printf("---------------\n");
printf(" Total Entries --- Total = %7d, new = %7d \n",
total_entries, (total_entries - prev_total_entries));
printf(" Active Entries --- Total = %7d, new = %7d \n",
active_entries, (active_entries - prev_active_entries));
printf(" Hold Entries --- Total = %7d, new = %7d \n",
hold_entries, (hold_entries - prev_hold_entries));
printf(" Fwd flow Entries - Total = %7d\n", flow_action_fwd);
printf(" drop flow Entries - Total = %7d\n", flow_action_drop);
printf(" NAT flow Entries - Total = %7d\n\n", flow_action_nat);
printf(" Rate of change of Active Entries\n");
printf(" --------------------------------\n");
printf(" current rate = %8d\n", rate);
printf(" Avg setup rate = %8d\n", avg_setup_rate);
printf(" Avg teardown rate = %8d\n", avg_teardown_rate);
printf(" Rate of change of Flow Entries\n");
printf(" ------------------------------\n");
printf(" current rate = %8d\n", total_rate);
last_time = now;
prev_active_entries = active_entries;
prev_total_entries = total_entries;
prev_hold_entries = hold_entries;
}
}
static void
flow_rate(void)
{
struct flow_table *ft = &main_table;
unsigned int i;
struct vr_flow_entry *fe;
struct timeval now;
struct timeval last_time;
int active_entries = 0;
int prev_active_entries = 0;
int total_entries = 0;
int prev_total_entries = 0;
int diff_ms;
int rate;
int total_rate;
gettimeofday(&last_time, NULL);
while (1) {
active_entries = 0;
total_entries = 0;
usleep(500000);
for (i = 0; i < ft->ft_num_entries; i++) {
fe = (struct vr_flow_entry *)((char *)ft->ft_entries + (i * sizeof(*fe)));
if (fe->fe_flags & VR_FLOW_FLAG_ACTIVE) {
total_entries++;
if (fe->fe_action != VR_FLOW_ACTION_HOLD)
active_entries++;
}
}
gettimeofday(&now, NULL);
/* calc time difference and rate */
diff_ms = (now.tv_sec - last_time.tv_sec) * 1000;
diff_ms += (now.tv_usec - last_time.tv_usec) / 1000;
assert(diff_ms > 0 );
rate = (active_entries - prev_active_entries) * 1000;
rate /= diff_ms;
total_rate = (total_entries - prev_total_entries) * 1000;
total_rate /= diff_ms;
if (rate != 0 || total_rate != 0) {
printf("New = %4d, Flow setup rate = %4d flows/sec, ",
(active_entries - prev_active_entries), rate);
printf("Flow rate = %4d flows/sec, for last %4d ms\n", total_rate, diff_ms);
fflush(stdout);
}
last_time = now;
prev_active_entries = active_entries;
prev_total_entries = total_entries;
}
}
void
vr_response_process(void *sresp)
{
vr_response *resp = (vr_response *)sresp;
if (resp->resp_code < 0)
printf("%s\n", strerror(-resp->resp_code));
return;
}
int
flow_table_map(vr_flow_req *req)
{
int ret;
unsigned int i;
struct flow_table *ft = &main_table;
if (req->fr_ftable_dev < 0)
exit(ENODEV);
ret = mknod(MEM_DEV, S_IFCHR | O_RDWR,
makedev(req->fr_ftable_dev, req->fr_rid));
if (ret && errno != EEXIST) {
perror(MEM_DEV);
exit(errno);
}
mem_fd = open(MEM_DEV, O_RDONLY | O_SYNC);
if (mem_fd <= 0) {
perror(MEM_DEV);
exit(errno);
}
ft->ft_entries = (struct vr_flow_entry *)mmap(NULL, req->fr_ftable_size,
PROT_READ, MAP_SHARED, mem_fd, 0);
if (ft->ft_entries == MAP_FAILED) {
printf("flow table: %s\n", strerror(errno));
exit(errno);
}
ft->ft_span = req->fr_ftable_size;
ft->ft_num_entries = ft->ft_span / sizeof(struct vr_flow_entry);
ft->ft_processed = req->fr_processed;
ft->ft_created = req->fr_created;
ft->ft_hold_oflows = req->fr_hold_oflows;
ft->ft_added = req->fr_added;
ft->ft_cpus = req->fr_cpus;
if (req->fr_hold_stat && req->fr_hold_stat_size) {
for (i = 0; i < ft->ft_cpus; i++) {
ft->ft_hold_stat[i] = req->fr_hold_stat[i];
}
}
return ft->ft_num_entries;
}
void
vr_flow_req_process(void *sreq)
{
vr_flow_req *req = (vr_flow_req *)sreq;
switch (req->fr_op) {
case FLOW_OP_FLOW_TABLE_GET:
if (flow_table_map(req) <= 0)
return;
break;
default:
break;
}
return;
}
static int
make_flow_req(vr_flow_req *req)
{
int ret, attr_len, error;
struct nl_response *resp;
ret = nl_build_nlh(cl, cl->cl_genl_family_id, NLM_F_REQUEST);
if (ret)
return ret;
ret = nl_build_genlh(cl, SANDESH_REQUEST, 0);
if (ret)
return ret;
attr_len = nl_get_attr_hdr_size();
error = 0;
ret = sandesh_encode(req, "vr_flow_req", vr_find_sandesh_info,
(nl_get_buf_ptr(cl) + attr_len),
(nl_get_buf_len(cl) - attr_len), &error);
if ((ret <= 0) || error) {
return ret;
}
nl_build_attr(cl, ret, NL_ATTR_VR_MESSAGE_PROTOCOL);
nl_update_nlh(cl);
ret = nl_sendmsg(cl);
if (ret <= 0)
return ret;
while ((ret = nl_recvmsg(cl)) > 0) {
resp = nl_parse_reply(cl);
if (resp->nl_op == SANDESH_REQUEST) {
sandesh_decode(resp->nl_data, resp->nl_len, vr_find_sandesh_info, &ret);
}
}
if (errno == EAGAIN || errno == EWOULDBLOCK)
ret = 0;
return ret;
}
int
flow_table_get(void)
{
/* get the kernel's view of the flow table */
memset(&flow_req, 0, sizeof(flow_req));
flow_req.fr_op = FLOW_OP_FLOW_TABLE_GET;
return make_flow_req(&flow_req);
}
static int
flow_table_setup(void)
{
int ret;
cl = nl_register_client();
if (!cl)
return -ENOMEM;
ret = nl_socket(cl, NETLINK_GENERIC);
if (ret <= 0)
return ret;
ret = vrouter_get_family_id(cl);
if (ret <= 0)
return ret;
return ret;
}
void
flow_validate(int flow_index, char action)
{
struct vr_flow_entry *fe;
memset(&flow_req, 0, sizeof(flow_req));
fe = flow_get(flow_index);
flow_req.fr_op = FLOW_OP_FLOW_SET;
flow_req.fr_index = flow_index;
flow_req.fr_flags = VR_FLOW_FLAG_ACTIVE;
flow_req.fr_flow_sip = fe->fe_key.key_src_ip;
flow_req.fr_flow_dip = fe->fe_key.key_dest_ip;
flow_req.fr_flow_proto = fe->fe_key.key_proto;
flow_req.fr_flow_sport = fe->fe_key.key_src_port;
flow_req.fr_flow_dport = fe->fe_key.key_dst_port;
flow_req.fr_flow_nh_id = fe->fe_key.key_nh_id;
switch (action) {
case 'd':
flow_req.fr_action = VR_FLOW_ACTION_DROP;
break;
case 'f':
flow_req.fr_action = VR_FLOW_ACTION_FORWARD;
break;
case 'i':
flow_req.fr_flags = VR_FLOW_FLAG_ACTIVE ^ VR_FLOW_FLAG_ACTIVE;
flow_req.fr_action = VR_FLOW_ACTION_DROP;
break;
default:
return;
}
if (mirror >= 0) {
flow_req.fr_mir_id = mirror;
flow_req.fr_flags |= VR_FLOW_FLAG_MIRROR;
} else
flow_req.fr_flags &= ~VR_FLOW_FLAG_MIRROR;
make_flow_req(&flow_req);
return;
}
static void
Usage(void)
{
printf("Usage:flow [-f flow_index]\n");
printf(" [-d flow_index]\n");
printf(" [-i flow_index]\n");
printf(" [--mirror=mirror table index]\n");
printf(" [-l]\n");
printf(" [-r]\n");
printf(" [-s]\n");
printf("\n");
printf("-f <flow_index>\t Set forward action for flow at flow_index <flow_index>\n");
printf("-d <flow_index>\t Set drop action for flow at flow_index <flow_index>\n");
printf("-i <flow_index>\t Invalidate flow at flow_index <flow_index>\n");
printf("--mirror\t mirror index to mirror to\n");
printf("-l\t\t List all flows\n");
printf("-r\t\t Start dumping flow setup rate\n");
printf("-s\t\t Start dumping flow stats\n");
printf("--help\t\t Print this help\n");
exit(-EINVAL);
}
enum opt_flow_index {
DVRF_OPT_INDEX,
MIRROR_OPT_INDEX,
HELP_OPT_INDEX,
MAX_OPT_INDEX
};
static struct option long_options[] = {
[DVRF_OPT_INDEX] = {"dvrf", required_argument, &dvrf_set, 1},
[MIRROR_OPT_INDEX] = {"mirror", required_argument, &mir_set, 1},
[HELP_OPT_INDEX] = {"help", no_argument, &help_set, 1},
[MAX_OPT_INDEX] = { NULL, 0, 0, 0}
};
static void
validate_options(void)
{
if (!flow_index && !list && !rate && !stats)
Usage();
return;
}
static void
parse_long_opts(int opt_flow_index, char *opt_arg)
{
errno = 0;
switch (opt_flow_index) {
case DVRF_OPT_INDEX:
dvrf = strtoul(opt_arg, NULL, 0);
if (errno)
Usage();
break;
case MIRROR_OPT_INDEX:
mirror = strtoul(opt_arg, NULL, 0);
if (errno)
Usage();
break;
case HELP_OPT_INDEX:
default:
Usage();
}
return;
}
int
main(int argc, char *argv[])
{
char opt;
int ret;
int option_index;
while ((opt = getopt_long(argc, argv, "d:f:i:lrs",
long_options, &option_index)) >= 0) {
switch (opt) {
case 'f':
case 'd':
case 'i':
flow_cmd = opt;
flow_index = strtoul(optarg, NULL, 0);
break;
case 'l':
list = 1;
break;
case 'r':
rate = 1;
break;
case 's':
stats = 1;
break;
case 0:
parse_long_opts(option_index, optarg);
break;
default:
Usage();
}
}
validate_options();
ret = flow_table_setup();
if (ret < 0)
return ret;
ret = flow_table_get();
if (ret < 0)
return ret;
if (list)
flow_list();
else if (rate)
flow_rate();
else if (stats)
flow_stats();
else
flow_validate(flow_index, flow_cmd);
return 0;
}