aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorLuigi Rizzo <luigi@FreeBSD.org>2012-04-12 08:38:56 +0000
committerLuigi Rizzo <luigi@FreeBSD.org>2012-04-12 08:38:56 +0000
commitaaca8f41f5078d07f95d17d3d79982c02c94296f (patch)
tree8d80a9866d0697bd2eabbf9652e709b638a03374 /tools
parent3ad4cbcf209fbd503ddaa0aa51895e0bdb6aabe1 (diff)
downloadsrc-aaca8f41f5078d07f95d17d3d79982c02c94296f.tar.gz
src-aaca8f41f5078d07f95d17d3d79982c02c94296f.zip
use getopt to parse options, add one option to set
the wait time for link-up events
Notes
Notes: svn path=/head/; revision=234168
Diffstat (limited to 'tools')
-rw-r--r--tools/tools/netmap/bridge.c80
1 files changed, 61 insertions, 19 deletions
diff --git a/tools/tools/netmap/bridge.c b/tools/tools/netmap/bridge.c
index 1b027d7a45fe..7d2f4f4c1461 100644
--- a/tools/tools/netmap/bridge.c
+++ b/tools/tools/netmap/bridge.c
@@ -48,7 +48,7 @@ int verbose = 0;
} while (0)
-char *version = "$Id: bridge.c 10637 2012-02-24 16:36:25Z luigi $";
+char *version = "$Id: bridge.c 10857 2012-04-06 12:18:22Z luigi $";
static int do_abort = 0;
@@ -306,6 +306,14 @@ howmany(struct my_ring *me, int tx)
return tot;
}
+static void
+usage(void)
+{
+ fprintf(stderr,
+ "usage: bridge [-v] [-i ifa] [-i ifb] [-b burst] [-w wait_time] [iface]\n");
+ exit(1);
+}
+
/*
* bridge [-v] if1 [if2]
*
@@ -317,36 +325,72 @@ int
main(int argc, char **argv)
{
struct pollfd pollfd[2];
- int i;
- u_int burst = 1024;
+ int i, ch;
+ u_int burst = 1024, wait_link = 4;
struct my_ring me[2];
+ char *ifa = NULL, *ifb = NULL;
fprintf(stderr, "%s %s built %s %s\n",
argv[0], version, __DATE__, __TIME__);
bzero(me, sizeof(me));
- while (argc > 1 && !strcmp(argv[1], "-v")) {
- verbose++;
- argv++;
- argc--;
- }
+ while ( (ch = getopt(argc, argv, "b:i:vw:")) != -1) {
+ switch (ch) {
+ D("bad option %c %s", ch, optarg);
+ usage();
+ break;
+ case 'b': /* burst */
+ burst = atoi(optarg);
+ break;
+ case 'i': /* interface */
+ if (ifa == NULL)
+ ifa = optarg;
+ else if (ifb == NULL)
+ ifb = optarg;
+ else
+ D("%s ignored, already have 2 interfaces",
+ optarg);
+ break;
+ case 'v':
+ verbose++;
+ break;
+ case 'w':
+ wait_link = atoi(optarg);
+ break;
+ }
- if (argc < 2 || argc > 4) {
- D("Usage: %s IFNAME1 [IFNAME2 [BURST]]", argv[0]);
- return (1);
}
+ if (argc > 1)
+ ifa = argv[1];
+ if (argc > 2)
+ ifb = argv[2];
+ if (argc > 3)
+ burst = atoi(argv[3]);
+ if (!ifb)
+ ifb = ifa;
+ if (!ifa) {
+ D("missing interface");
+ usage();
+ }
+ if (burst < 1 || burst > 8192) {
+ D("invalid burst %d, set to 1024", burst);
+ burst = 1024;
+ }
+ if (wait_link > 100) {
+ D("invalid wait_link %d, set to 4", wait_link);
+ wait_link = 4;
+ }
/* setup netmap interface #1. */
- me[0].ifname = argv[1];
- if (argc == 2 || !strcmp(argv[1], argv[2])) {
+ me[0].ifname = ifa;
+ me[1].ifname = ifb;
+ if (!strcmp(ifa, ifb)) {
D("same interface, endpoint 0 goes to host");
i = NETMAP_SW_RING;
- me[1].ifname = argv[1];
} else {
/* two different interfaces. Take all rings on if1 */
i = 0; // all hw rings
- me[1].ifname = argv[2];
}
if (netmap_open(me, i))
return (1);
@@ -385,8 +429,6 @@ main(int argc, char **argv)
me[1].if_reqcap = me[1].if_curcap;
me[1].if_reqcap &= ~(IFCAP_HWCSUM | IFCAP_TSO | IFCAP_TOE);
do_ioctl(me+1, SIOCSIFCAP);
- if (argc > 3)
- burst = atoi(argv[3]); /* packets burst size. */
/* setup poll(2) variables. */
memset(pollfd, 0, sizeof(pollfd));
@@ -395,8 +437,8 @@ main(int argc, char **argv)
pollfd[i].events = (POLLIN);
}
- D("Wait 2 secs for link to come up...");
- sleep(2);
+ D("Wait %d secs for link to come up...", wait_link);
+ sleep(wait_link);
D("Ready to go, %s 0x%x/%d <-> %s 0x%x/%d.",
me[0].ifname, me[0].queueid, me[0].nifp->ni_rx_queues,
me[1].ifname, me[1].queueid, me[1].nifp->ni_rx_queues);