diff options
author | Jason Wright <jason@cvs.openbsd.org> | 1999-02-27 18:29:55 +0000 |
---|---|---|
committer | Jason Wright <jason@cvs.openbsd.org> | 1999-02-27 18:29:55 +0000 |
commit | 78d7e1843d2489a6696dd134094ee311d22b7d5e (patch) | |
tree | d7bd4eb935ec066731e5d434f4cd3991762bfccb /usr.sbin/brconfig | |
parent | f86f3ce35998c674ae28cee4ee47701f303f6b49 (diff) |
changes in command syntax; suggested by deraadt.
Diffstat (limited to 'usr.sbin/brconfig')
-rw-r--r-- | usr.sbin/brconfig/brconfig.8 | 41 | ||||
-rw-r--r-- | usr.sbin/brconfig/brconfig.c | 77 |
2 files changed, 77 insertions, 41 deletions
diff --git a/usr.sbin/brconfig/brconfig.8 b/usr.sbin/brconfig/brconfig.8 index 990d8cff4fa..dc44eeeefba 100644 --- a/usr.sbin/brconfig/brconfig.8 +++ b/usr.sbin/brconfig/brconfig.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: brconfig.8,v 1.2 1999/02/26 19:17:41 jason Exp $ +.\" $OpenBSD: brconfig.8,v 1.3 1999/02/27 18:29:54 jason Exp $ .\" .\" Copyright (c) 1999 Jason L. Wright (jason@thought.net) .\" All rights reserved. @@ -34,15 +34,15 @@ .Os .Sh NAME .Nm brconfig -.Nd manipulate Ethernet bridges +.Nd manipulate bridge interfaces .Sh SYNOPSIS .Nm brconfig +.Ar -a +.Nm brconfig .Ar bridge-name .Op Ar up .Op Ar down -.Op Ar list -.Op Ar routes -.Op Ar status +.Op Ar addr .Op Ar add interface-name .Op Ar delete interface-name .Op Ar link0 @@ -53,11 +53,16 @@ .Sh DESCRIPTION The .Nm brconfig -utility retrieves kernel state of Ethernet bridges and allows -user control of these bridges. Its command line consists +utility retrieves kernel state of bridge interfaces and allows +user control of these bridges. In the first synopsis, the command +will list the status of all bridges in the system. +In the second, its command line consists of the name of a bridge and a set of operations to be performed on that bridge. The commands are executed in -the order they were specified. +the order they were specified. If no command is specified in +the second synopsis, the +.Nm brconfig +will display status information about the bridge. .Pp The available commands are: .Bl -tag -width Ds @@ -65,13 +70,8 @@ The available commands are: Start the bridge forwarding packets. .It Ar down Stop the bridge from forwarding packets. -.It Ar list -Retrieve a list of interface members of the bridge. -.It Ar routes -Display the routes that have been learned by the bridge. -.It Ar status -Print the status of the bridge, including member interfaces and -routes learned by the bridge. +.It Ar addr +Display the addresses that have been learned by the bridge. .It Ar add interface-name Add the interface named by .Ar interface-name @@ -90,6 +90,8 @@ Remove the interface named by from the bridge. Promiscuous mode is turned off for the interface when it is removed from the bridge. +.It Ar del +Alias for `delete'. .It Ar link0 Setting this flag stops all non-IP multicast packets from being forwarded by the bridge. @@ -110,8 +112,9 @@ flag on the bridge interface. .It Cm brconfig bridge0 add pn0 add mx0 up Add the Ethernet interfaces pn0 and mx0 to the bridge bridge0, and start the bridge forwarding packets. -.It Cm brconfig bridge0 list -Retrieve a list of interfaces that are members of bridge0. +.It Cm brconfig bridge0 +Retrieve a list of interfaces that are members of bridge0, and the addresses +learned by the bridge. .It Cm brconfig bridge0 down Stop bridge0 from forwarding packets. .It Cm brconfig bridge0 delete pn0 @@ -133,7 +136,7 @@ kernel interface were written by Jason L. Wright <jason@thought.net> as part of an undergraduate indenpendent study at the University of North Carolina at Greensboro. .Sh BUGS -There are some Ethernet chipsets which will not work in a bridge +There are some network interface chipsets which will not work in a bridge configuration. Some, like the Lite-On PNIC, have serious flaws when running in promiscuous mode, and others, like the TI ThunderLAN, receive -their own transmissions, which makes the route learning code ineffective. +their own transmissions, which makes the address learning code ineffective. diff --git a/usr.sbin/brconfig/brconfig.c b/usr.sbin/brconfig/brconfig.c index 947eb4eef1f..3071d2541c4 100644 --- a/usr.sbin/brconfig/brconfig.c +++ b/usr.sbin/brconfig/brconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: brconfig.c,v 1.1 1999/02/26 17:52:12 jason Exp $ */ +/* $OpenBSD: brconfig.c,v 1.2 1999/02/27 18:29:54 jason Exp $ */ /* * Copyright (c) 1999 Jason L. Wright (jason@thought.net) @@ -33,6 +33,7 @@ #include <stdio.h> #include <unistd.h> +#include <stdlib.h> #include <sys/param.h> #include <sys/socket.h> #include <sys/ioctl.h> @@ -51,11 +52,12 @@ int main(int, char **); int bridge_setflag(int, char *, short); int bridge_clrflag(int, char *, short); int bridge_list(int, char *, char *); -int bridge_routes(int, char *, char *); +int bridge_addrs(int, char *, char *); int bridge_add(int, char *, char *); int bridge_delete(int, char *, char *); int bridge_status(int, char *); int is_bridge(int, char *); +int bridge_show_all(int); void printb(char *, unsigned short, char *); /* if_flags bits: borrowed from ifconfig.c */ @@ -65,9 +67,9 @@ void printb(char *, unsigned short, char *); void usage() { + fprintf(stderr, "brconfig -a\n"); fprintf(stderr, - "brconfig bridge_name [up] [down] [add interface_name]\n"); - fprintf(stderr, "\t[delete interface_name] ...\n"); + "brconfig interface [up] [down] [add interface] [delete interface] ...\n"); } int @@ -90,8 +92,13 @@ main(argc, argv) argc--; argv++; brdg = argv[0]; - if (!is_bridge(sock, brdg)) + if (strcmp(brdg, "-a") == 0) + return bridge_show_all(sock); + + if (!is_bridge(sock, brdg)) { + warnx("%s is not a bridge", brdg); return (EX_USAGE); + } if (argc == 1) { error = bridge_status(sock, brdg); @@ -109,7 +116,8 @@ main(argc, argv) if (error) return (error); } - else if (strcmp("delete", argv[0]) == 0) { + else if (strcmp("delete", argv[0]) == 0 || + strcmp("del", argv[0]) == 0) { argc--; argv++; if (argc == 0) { warnx("delete requires an argument"); @@ -119,11 +127,6 @@ main(argc, argv) if (error) return (error); } - else if (strcmp("list", argv[0]) == 0) { - error = bridge_list(sock, brdg, ""); - if (error) - return (error); - } else if (strcmp("up", argv[0]) == 0) { error = bridge_setflag(sock, brdg, IFF_UP); if (error) @@ -154,13 +157,8 @@ main(argc, argv) if (error) return (error); } - else if (strcmp("routes", argv[0]) == 0) { - error = bridge_routes(sock, brdg, ""); - if (error) - return (error); - } - else if (strcmp("status", argv[0]) == 0) { - error = bridge_status(sock, brdg); + else if (strcmp("addr", argv[0]) == 0) { + error = bridge_addrs(sock, brdg, ""); if (error) return (error); } @@ -174,6 +172,42 @@ main(argc, argv) } int +bridge_show_all(s) + int s; +{ + char *inbuf = NULL; + struct ifconf ifc; + struct ifreq *ifrp, ifreq; + int len = 8192, i; + + while (1) { + ifc.ifc_len = len; + ifc.ifc_buf = inbuf = realloc(inbuf, len); + if (inbuf == NULL) + err(1, "malloc"); + if (ioctl(s, SIOCGIFCONF, &ifc) < 0) + err(1, "ioctl(SIOCGIFCONF)"); + if (ifc.ifc_len + sizeof(struct ifreq) < len) + break; + len *= 2; + } + ifrp = ifc.ifc_req; + ifreq.ifr_name[0] = '\0'; + for (i = 0; i < ifc.ifc_len; ) { + ifrp = (struct ifreq *)((caddr_t)ifc.ifc_req + i); + i += sizeof(ifrp->ifr_name) + + (ifrp->ifr_addr.sa_len > sizeof(struct sockaddr) ? + ifrp->ifr_addr.sa_len : sizeof(struct sockaddr)); + if (ifrp->ifr_addr.sa_family != AF_LINK) + continue; + if (!is_bridge(s, ifrp->ifr_name)) + continue; + bridge_status(s, ifrp->ifr_name); + } + return (0); +} + +int bridge_setflag(s, brdg, f) int s; char *brdg; @@ -296,7 +330,7 @@ bridge_delete(s, brdg, ifn) } int -bridge_routes(s, brdg, delim) +bridge_addrs(s, brdg, delim) int s; char *brdg, *delim; { @@ -346,7 +380,6 @@ is_bridge(s, brdg) if (ioctl(s, SIOCBRDGRT, (caddr_t)&req) < 0) { if (errno == ENOENT || errno == ENETDOWN) return (1); - warn("ioctl(SIOCBRDGRT)"); return (0); } return (1); @@ -378,8 +411,8 @@ bridge_status(s, brdg) if (err) return (err); - printf("\tRoutes:\n"); - err = bridge_routes(s, brdg, "\t\t"); + printf("\tAddresses:\n"); + err = bridge_addrs(s, brdg, "\t\t"); return (err); } |