diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | README | 22 | ||||
-rw-r--r-- | TODO | 14 | ||||
-rw-r--r-- | brctl/Makefile.in | 4 | ||||
-rw-r--r-- | brctl/brctl.c | 46 | ||||
-rw-r--r-- | brctl/brctl.h | 2 | ||||
-rw-r--r-- | brctl/brctl_cmd.c | 42 | ||||
-rw-r--r-- | brctl/brctld.c | 208 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | libbridge/libbridge_misc.c | 10 |
10 files changed, 84 insertions, 274 deletions
@@ -1,3 +1,11 @@ +2004-12-02 Stephen Hemminger <shemminger@osdl.org> + + * Released bridge-utils 1.0.5 + * Remove brctld out of date, buggy not used + * Cleanup command line help and error messages + * Fix segv with wrong # of args to 'brctl stp' + + 20040601 Stephen Hemminger <shemminger@osdl.org> * Released bridge-utils 1.0.4 - should build with out sysfs now. @@ -1,7 +1,9 @@ -Hi there! +This version of the bridge utilities is for Linux 2.4 and 2.6, +it uses the sysfs interface if possible on Linux 2.6 -In this package you'll find the new-and-improved linux ethernet -bridging code. I (Lennert Buytenhek) rewrote the linux bridging code + +--------------------------- +Lennert Buytenhek rewrote the linux bridging code because the old code was a big mess and nonextensible. The new code is published at: @@ -24,15 +26,8 @@ Advantages of the new code are: If you have any comments, questions or suggestions, please send email to -the mailing list. - - - -Have fun! -Lennert Buytenhek - - - +the mailing list bridge@osdl.org +-------------------------- Files in this package: @@ -44,8 +39,7 @@ Makefile Recursive Makefile. README This file. -brctl/ The new-and-improved userspace bridge configuration - tool. +brctl/ The userspace bridge configuration tool. bridge-utils.spec A .spec file for Red Hat package building. "rpm -tb @@ -1,30 +1,24 @@ main code --------- +Add netlink based API? we have a tiny deviation from IEEE 802.1d: we don't kill the awaiting-tx skb queue when a port leaves the FORWARDING state RH initscripts for setting up bridge interfaces automatically bridge ID change notifications -for 2.4: module_author and module_description -smarter fdb timeout scheme -slab cache for fdbs? -I'm not happy with the current timer tick interval -make the bridge device zerocopy/highmem transparent + move the spanning tree code to userspace to be MLT (Nortel Multi Link Trunking) compatible: send bpdu's on all interfaces in the bonding bundle + faster switch to forward mode per-port STP disabling 'fast start': listening->learning->forwarding in 2*hello instead of 2*fd -enslaved devs same MAC (like tap), then one changes +enslaved devs same MAC (like tap), then one changes managerial ---------- improve documentation.. -backup mailing list archives of openrock and math somewhere -revamp the web page -add web page mirrors - netfilter patch --------------- diff --git a/brctl/Makefile.in b/brctl/Makefile.in index 93618ec..e1956d6 100644 --- a/brctl/Makefile.in +++ b/brctl/Makefile.in @@ -18,13 +18,11 @@ INSTALL=@INSTALL@ common_SOURCES= brctl_cmd.c brctl_disp.c brctl_SOURCES= brctl.c $(common_SOURCES) -brctld_SOURCES= brctld.c $(common_SOURCES) common_OBJECTS= $(common_SOURCES:.c=.o) brctl_OBJECTS= $(brctl_SOURCES:.c=.o) -brctld_OBJECTS= $(brctld_SOURCES:.c=.o) -OBJECTS= $(common_OBJECTS) $(brctl_OBJECTS) $(brctld_OBJECTS) +OBJECTS= $(common_OBJECTS) $(brctl_OBJECTS) PROGRAMS= brctl diff --git a/brctl/brctl.c b/brctl/brctl.c index 11dc1f3..33c15fd 100644 --- a/brctl/brctl.c +++ b/brctl/brctl.c @@ -20,6 +20,8 @@ #include <stdlib.h> #include <string.h> #include <sys/errno.h> +#include <getopt.h> + #include "libbridge.h" #include "config.h" @@ -27,39 +29,57 @@ static void help() { + printf("Usage: brctl [commands]\n"); printf("commands:\n"); command_helpall(); } -int main(int argc, char *argv[]) +int main(int argc, char *const* argv) { const struct command *cmd; + int f; + static const struct option options[] = { + { .name = "help", .val = 'h' }, + { .name = "version", .val = 'V' }, + { 0 } + }; - if (argc < 2) + while ((f = getopt_long(argc, argv, "Vh", options, NULL)) != EOF) + switch(f) { + case 'h': + help(); + return 0; + case 'V': + printf("%s, %s\n", PACKAGE, VERSION); + return 0; + default: + fprintf(stderr, "Unknown option '%c'\n", f); + goto help; + } + + if (argc == optind) goto help; - - if (strcmp(argv[1], "-V") == 0) { - printf("%s, %s\n", PACKAGE, VERSION); - return 0; - } - + if (br_init()) { fprintf(stderr, "can't setup bridge control: %s\n", strerror(errno)); return 1; } - if ((cmd = command_lookup(argv[1])) == NULL) { + argc -= optind; + argv += optind; + if ((cmd = command_lookup(*argv)) == NULL) { fprintf(stderr, "never heard of command [%s]\n", argv[1]); goto help; } - if (argc < cmd->nargs + 2) { - fprintf(stderr, "incorrect number of arguments for command\n"); - goto help; + if (argc < cmd->nargs + 1) { + printf("Incorrect number of arguments for command\n"); + printf("Usage: brctl %s %s\n", cmd->name, cmd->help); + return 1; } - return cmd->func(++argv); + return cmd->func(argc, argv); help: help(); diff --git a/brctl/brctl.h b/brctl/brctl.h index 8fdd9ef..55b7897 100644 --- a/brctl/brctl.h +++ b/brctl/brctl.h @@ -23,7 +23,7 @@ struct command { int nargs; const char *name; - int (*func)(char **argv); + int (*func)(int argc, char *const* argv); const char *help; }; diff --git a/brctl/brctl_cmd.c b/brctl/brctl_cmd.c index 9ab7166..f135282 100644 --- a/brctl/brctl_cmd.c +++ b/brctl/brctl_cmd.c @@ -35,7 +35,7 @@ static int strtotimeval(struct timeval *tv, const char *time) return 0; } -static int br_cmd_addbr(char** argv) +static int br_cmd_addbr(int argc, char*const* argv) { int err; @@ -54,7 +54,7 @@ static int br_cmd_addbr(char** argv) } } -static int br_cmd_delbr(char** argv) +static int br_cmd_delbr(int argc, char*const* argv) { int err; @@ -79,7 +79,7 @@ static int br_cmd_delbr(char** argv) } } -static int br_cmd_addif(char** argv) +static int br_cmd_addif(int argc, char *const* argv) { int err; @@ -109,7 +109,7 @@ static int br_cmd_addif(char** argv) } } -static int br_cmd_delif(char** argv) +static int br_cmd_delif(int argc, char *const* argv) { int err; @@ -132,7 +132,7 @@ static int br_cmd_delif(char** argv) } } -static int br_cmd_setageing(char** argv) +static int br_cmd_setageing(int argc, char *const* argv) { int err; struct timeval tv; @@ -150,7 +150,7 @@ static int br_cmd_setageing(char** argv) return err != 0; } -static int br_cmd_setbridgeprio(char** argv) +static int br_cmd_setbridgeprio(int argc, char *const* argv) { int prio; int err; @@ -167,7 +167,7 @@ static int br_cmd_setbridgeprio(char** argv) return err != 0; } -static int br_cmd_setfd(char** argv) +static int br_cmd_setfd(int argc, char *const* argv) { struct timeval tv; int err; @@ -185,7 +185,7 @@ static int br_cmd_setfd(char** argv) return err != 0; } -static int br_cmd_sethello(char** argv) +static int br_cmd_sethello(int argc, char *const* argv) { struct timeval tv; int err; @@ -203,7 +203,7 @@ static int br_cmd_sethello(char** argv) return err != 0; } -static int br_cmd_setmaxage(char** argv) +static int br_cmd_setmaxage(int argc, char *const* argv) { struct timeval tv; int err; @@ -220,7 +220,7 @@ static int br_cmd_setmaxage(char** argv) return err != 0; } -static int br_cmd_setpathcost(char** argv) +static int br_cmd_setpathcost(int argc, char *const* argv) { int cost, err; @@ -236,7 +236,7 @@ static int br_cmd_setpathcost(char** argv) return err != 0; } -static int br_cmd_setportprio(char** argv) +static int br_cmd_setportprio(int argc, char *const* argv) { int cost, err; @@ -253,7 +253,7 @@ static int br_cmd_setportprio(char** argv) return err != 0; } -static int br_cmd_stp(char** argv) +static int br_cmd_stp(int argc, char *const* argv) { int stp, err; @@ -275,7 +275,7 @@ static int br_cmd_stp(char** argv) return err != 0; } -static int br_cmd_showstp(char** argv) +static int br_cmd_showstp(int argc, char *const* argv) { struct bridge_info info; @@ -309,7 +309,7 @@ static int show_bridge(const char *name, void *arg) return 0; } -static int br_cmd_show(char** argv) +static int br_cmd_show(int argc, char *const* argv) { printf("bridge name\tbridge id\t\tSTP enabled\tinterfaces\n"); br_foreach_bridge(show_bridge, NULL); @@ -324,7 +324,7 @@ static int compare_fdbs(const void *_f0, const void *_f1) return memcmp(f0->mac_addr, f1->mac_addr, 6); } -static int br_cmd_showmacs(char** argv) +static int br_cmd_showmacs(int argc, char *const* argv) { const char *brname = argv[1]; #define CHUNK 128 @@ -394,7 +394,7 @@ static const struct command commands[] = { "<bridge>\t\tshow a list of mac addrs"}, { 1, "showstp", br_cmd_showstp, "<bridge>\t\tshow bridge stp info"}, - { 1, "stp", br_cmd_stp, + { 2, "stp", br_cmd_stp, "<bridge> <state>\tturn stp on/off" }, }; @@ -410,15 +410,11 @@ const struct command *command_lookup(const char *cmd) return NULL; } -void command_help(const struct command *cmd) -{ - printf("\t%-10s\t%s\n", cmd->name, cmd->help); -} - void command_helpall(void) { int i; - for (i = 0; i < sizeof(commands)/sizeof(commands[0]); i++) - command_help(commands+i); + for (i = 0; i < sizeof(commands)/sizeof(commands[0]); i++) { + printf("\t%-10s\t%s\n", commands[i].name, commands[i].help); + } } diff --git a/brctl/brctld.c b/brctl/brctld.c deleted file mode 100644 index f2b4e45..0000000 --- a/brctl/brctld.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (C) 2000 Lennert Buytenhek - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <netinet/in.h> -#include <signal.h> -#include <sys/resource.h> -#include <sys/time.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <unistd.h> -#include <asm/param.h> -#include "libbridge.h" -#include "brctl.h" - -char *help_message = -"addbr\t\t\t\t\tadd bridge\n" -"addif\t\t\t<device>\tadd interface to bridge\n" -"bridge\t\t\t<bridge>\tselect bridge to work in\n" -"delbr\t\t\t\t\tdelete bridge\n" -"delif\t\t\t<device>\tdelete interface from bridge\n" -"setageing\t\t<time>\t\tset ageing time\n" -"setbridgeprio\t\t<prio>\t\tset bridge priority\n" -"setfd\t\t\t<time>\t\tset bridge forward delay\n" -"setgcint\t\t<time>\t\tset garbage collection interval\n" -"sethello\t\t<time>\t\tset hello time\n" -"setmaxage\t\t<time>\t\tset max message age\n" -"setpathcost\t\t<port> <cost>\tset path cost\n" -"setportprio\t\t<port> <prio>\tset port priority\n" -"show\t\t\t\t\tshow a list of bridges\n" -"showmacs\t\t\t\tshow a list of mac addrs\n" -"showstp\t\t\t\t\tshow bridge stp info\n" -"stp\t\t\t<state>\t\tturn stp on/off\n" -"quit\t\t\t\t\texit this session\n" -"\n"; - -void help() -{ - fprintf(stderr, help_message); -} - -struct bridge *br = NULL; - -int forkaway() -{ - int f; - - f = fork(); - if (f < 0) { - perror("fork"); - exit(-1); - } - - return f; -} - -void runchild(int sock) -{ - char hostname[128]; - - if (forkaway()) - return; - - /* Hack. */ - close(0); dup(sock); - close(1); dup(sock); - close(2); dup(sock); - - br_init(); - gethostname(hostname, 128); - - printf("\n\n\n\n"); - printf("brctld\t\tCopyright (C) 2000 Lennert Buytenhek <buytenh@gnu.org>\n"); - printf("======================================================================"); - printf("\n\n\n\n"); - - while (1) { - char arg0[128]; - char arg1[128]; - char cmd[128]; - struct command *cmdptr; - char line[1024]; - int numcmd; - - printf("<%s> ", hostname); - fflush(stdout); - line[1023] = 0; - fgets(line, 1023, stdin); - while (strlen(line) > 0 && - (line[strlen(line)-1] == '\r' || - line[strlen(line)-1] == '\n')) - line[strlen(line)-1] = 0; - - numcmd = sscanf(line, "%s %s %s", cmd, arg0, arg1); - - if (!strcmp(cmd, "help")) { - help(); - continue; - } else if (!strcmp(cmd, "bridge")) { - if (numcmd != 2) { - fprintf(stderr, "invalid number of arguments\n"); - continue; - } - - br = br_find_bridge(arg0); - if (br != NULL) - printf("now using bridge %s\n\n", arg0); - else - printf("can't find bridge %s\n\n", arg0); - continue; - } else if (!strcmp(cmd, "quit")) { - break; - } - - if ((cmdptr = br_command_lookup(cmd)) == NULL) { - printf("unknown command '%s'\n\n", line); - continue; - } - - if (cmdptr->needs_bridge_argument && br == NULL) { - printf("this command needs a bridge\n\n"); - continue; - } - - br_refresh(); - cmdptr->func(br, arg0, arg1); - printf("\n"); - } - - shutdown(sock, 2); - exit(0); -} - -void sigchild(int sig) -{ - int status; - - wait3(&status, WNOHANG, NULL); -} - -int main(int argc, char *argv[]) -{ - struct sockaddr_in addr; - int sock; - int x; - - if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - perror("socket"); - return 1; - } - - x = 1; - if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)) < 0) { - perror("setsockopt"); - return 1; - } - - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = htonl(INADDR_ANY); - addr.sin_port = htons(31338); - if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - perror("bind"); - return 1; - } - - if (listen(sock, 1) < 0) { - perror("listen"); - return 1; - } - - if (forkaway()) - return 0; - - setsid(); - signal(SIGCHLD, sigchild); - - while (1) { - int len; - int newsock; - - len = sizeof(addr); - if ((newsock = accept(sock, (struct sockaddr *)&addr, &len)) < 0) { - perror("accept"); - return 1; - } - - runchild(newsock); - } - - return 0; -} diff --git a/configure.in b/configure.in index 7eeb70f..fe2e729 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(brctl/brctl.c) AC_CONFIG_HEADER(libbridge/config.h) -AM_INIT_AUTOMAKE(bridge-utils,1.0.4) +AM_INIT_AUTOMAKE(bridge-utils,1.0.5) AC_ARG_WITH( linux-headers, [ --with-linux-headers Location of the linux headers to use], KERNEL_HEADERS=$withval, KERNEL_HEADERS="/usr/src/linux/include") diff --git a/libbridge/libbridge_misc.c b/libbridge/libbridge_misc.c index b227185..5791638 100644 --- a/libbridge/libbridge_misc.c +++ b/libbridge/libbridge_misc.c @@ -30,7 +30,7 @@ static const char *state_names[5] = { [BR_STATE_LISTENING] = "listening", [BR_STATE_LEARNING] = "learning", [BR_STATE_FORWARDING] = "forwarding", - [BR_STATE_BLOCKING] ="blocking", + [BR_STATE_BLOCKING] = "blocking", }; const char *br_get_state_name(int state) @@ -40,3 +40,11 @@ const char *br_get_state_name(int state) return "<INVALID STATE>"; } + +int __br_hz_internal; + +int __get_hz(void) +{ + const char * s = getenv("HZ"); + return s ? atoi(s) : HZ; +} |