pax_global_header00006660000000000000000000000064115442265460014523gustar00rootroot0000000000000052 comment=fd647340f15f868573a119bb38cbe8caa7c59a2c bridge-utils-1.5/000077500000000000000000000000001154422654600137625ustar00rootroot00000000000000bridge-utils-1.5/.gitignore000066400000000000000000000005671154422654600157620ustar00rootroot00000000000000# # NOTE! Don't add files that are generated in specific # subdirectories here. Add them in the ".gitignore" file # in that subdirectory instead. # # Normal rules # .* *.o *.o.* *.a *.s *.so # Generated by configure Makefile bridge-utils.spec configure config.* # # Top-level generic files # tags TAGS # quilt's files patches series # cscope files cscope.* *.orig *.rej bridge-utils-1.5/AUTHORS000066400000000000000000000001161154422654600150300ustar00rootroot00000000000000Stephen Hemminger Lennert Buytenhek bridge-utils-1.5/COPYING000066400000000000000000000430771154422654600150300ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. bridge-utils-1.5/ChangeLog000066400000000000000000000067641154422654600155510ustar00rootroot000000000000002006-05-31 Stephen Hemminger * Fixed bug where setting port priority set path cost instead 2006-01-31 Stephen Hemminger * Released bridge-utils 1.1 * Change to use libsysfs 2.0 2005-03-16 Stephen Hemminger * Released bridge-utils 1.0.6 * Fix for libsys detection (for FC) * Update autoconf usage * Allow multiple interfaces for addif,delif 2004-12-02 Stephen Hemminger * 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 * Released bridge-utils 1.0.4 - should build with out sysfs now. - report errors on foreach_port failing - more build cleanup 20040525 Stephen Hemminger * Released bridge-utils 1.0.1 - Change configure option from --with-linux= to --with-linux-headers= so options match help message. - Fix so utilities work with earlier 2.6 kernels that have sysfs but not new ioctl's or directories yet. - Build spec file from template. 20040524 Stephen Hemminger * Released bridge-utils 1.0 - Use sysfs to control bridge parameters - Add new ioctl syntax to handle mixed 32/64 bit mode (Earlier method would not work on all platforms). - Change libbbridge API to do work as needed, rather than reading all bridges/ports at startup. Old way would not scale with 1000's of entries - Minor cleanups. 20040401 Stephen Hemminger * Releases bridge-utils 0.9.7 - add -V option - support 100's of bridge ports - minor bug fixes 20021002 Lennert Buytenhek * Released bridge-utils 0.9.6. 20020403 Lennert Buytenhek * autoconfization by Andreas Hofmeister. 20020116 Lennert Buytenhek * On sparc, try to detect 32/64-bitness of the kernel at runtime. * Released bridge-utils 0.9.5. 20020106 Lennert Buytenhek * Remove 'tap'. * Added TODO list. * Added extra check for argument count to brctl * Added error message for circular bridge dev enslavement to brctl. * Get rid of some compiler warnings. * Steal Red Hat rawhide spec file. * Added 'how to use libbridge_compat.c' explanation by Serge Caron. * Try to work around sparc64 brokenness (FUCK ARGHH FUCK FUCK FUCK) * Release bridge-utils 0.9.4. 20011107 Lennert Buytenhek * Moved FAQ to the website. * Updated docs for 2.4 firewalling. * Add out-of-date notice to the THANKS file. ???????? Lennert Buytenhek * Fixed brctl timeout 42.94s wrap buglet. * Cleanup some docs. * Released bridge-utils 0.9.3. 20001002 Lennert Buytenhek * Incorporated two cleanup patches from H. J. Lu (one splits the CC define into CC and CFLAGS, the other one changes a few occurances of __close into the libc5 compatibility stub to close). * Removed all RCS tags. * Removed sample scripts dir. * Tweaked THANKS file a bit (it needs updating as well..) * Made 'show' command show an interface list. * Changed the 'showbr' command to 'showstp' * Tweaked FAQ. * Added explanation for iptables firewalling. * Released bridge-utils 0.9.2. 20000905 Lennert Buytenhek * Incorporated Roger Venning's patch to tap which will let you specify a local address to be used for the 'tunnel'. bridge-utils-1.5/Makefile.in000066400000000000000000000011501154422654600160240ustar00rootroot00000000000000 DESTDIR= KERNEL_HEADERS=-I@KERNEL_HEADERS@ INSTALL=@INSTALL@ prefix=@prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ sbindir=@sbindir@ mandir=@mandir@ distdir = $(PACKAGE)-$(VERSION) SUBDIRS=libbridge brctl doc all: for x in $(SUBDIRS); do $(MAKE) $(MFLAGS) -C $$x ; done clean: for x in $(SUBDIRS); do $(MAKE) $(MFLAGS) -C $$x clean ; done distclean: clean rm -f config.log rm -f config.cache rm -f config.status maintainer-clean: distclean rm -f Makefile rm -f brctl/Makefile rm -f libbridge/Makefile rm -f doc/Makefile install: for x in $(SUBDIRS); do $(MAKE) $(MFLAGS) -C $$x install; done bridge-utils-1.5/README000066400000000000000000000025621154422654600146470ustar00rootroot00000000000000This version of the bridge utilities is for Linux 2.4 and 2.6, it uses the sysfs interface if possible on Linux 2.6. The code repository is: git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/bridge-utils.git Advantages of the new code are: - Support for multiple bridge port groups (i.e. multiple independent bridges in one machine). - Each bridge is seen as a logical device, which allows you to do firewalling between port groups for example. - Everything is dynamic; bridges are created dynamically using the userspace configuration tool, ports are 'enslaved' dynamically, etc. - It is being actively maintained. - It uses a hash table for MAC addresses, not an AVL tree. - It's small (currently 4 pages of i386 code) and modular. - The source isn't a mess. - It works as a module. If you have any comments, questions or suggestions, please send email to the mailing list bridge@linux-foundation.org -------------------------- Files in this package: AUTHORS Authors of this package COPYING The GNU General Public License. Makefile Recursive Makefile. README This file. brctl/ The userspace bridge configuration tool. bridge-utils.spec A .spec file for Red Hat package building. "rpm -tb " ought to give you a .RPM file. doc/ Some documentation files. libbridge/ The bridge configuration interface library. misc/ Miscellaneous utilities. bridge-utils-1.5/THANKS000066400000000000000000000027151154422654600147020ustar00rootroot00000000000000Thanks go to (this list is REALLY out-of-date): F. Nicolaas Benders Lars Bohn Jim Chapman Robert Collier Steven Dewinter Arne Fitzenreiter Alejando Garcia Matthew Grant Mark Hahn Andreas Hofmeister Oskari Jaaskelainen Joshua Jensen Jason Lambert Christoph Lameter Miles Lane Janne Liimatainen Benoit Locher Daniel Lopez Stuart Lynne Andrew McRory David S. Miller Philippe Moutarlier Petr Novopashenniy Monte Ohrt Joachim Ott Kristian Rietveld Jacob Schroeder Bart de Schuymer Heikki Vatiainen Ernest Yik and everyone else I forgot. Thanks also go to Leiden University for letting me use their equipment and allowing me to work on this during work hours. I would also like to express my thanks and eternal gratitude to Margaret Suda. I hope you'll read this some day. bridge-utils-1.5/TODO000066400000000000000000000015751154422654600144620ustar00rootroot00000000000000main 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 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 managerial ---------- improve documentation.. netfilter patch --------------- sync MAC addresses DNAT/SNAT make src mac substitution configurable br_nf_pre_routing: ip_route_output -> output_key check: don't send unreachables stp state delay kernel panic on REDIRECT on bridge device w/o IP address bridge-utils-1.5/brctl/000077500000000000000000000000001154422654600150705ustar00rootroot00000000000000bridge-utils-1.5/brctl/Makefile.in000066400000000000000000000014571154422654600171440ustar00rootroot00000000000000 KERNEL_HEADERS=-I@KERNEL_HEADERS@ CC=@CC@ CFLAGS= -Wall @CFLAGS@ LDFLAGS=@LDFLAGS@ INCLUDE=-I../libbridge $(KERNEL_HEADERS) LIBS= -L ../libbridge -lbridge @LIBS@ prefix=@prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ sbindir=@sbindir@ mandir=@mandir@ INSTALL=@INSTALL@ common_SOURCES= brctl_cmd.c brctl_disp.c brctl_SOURCES= brctl.c $(common_SOURCES) common_OBJECTS= $(common_SOURCES:.c=.o) brctl_OBJECTS= $(brctl_SOURCES:.c=.o) OBJECTS= $(common_OBJECTS) $(brctl_OBJECTS) PROGRAMS= brctl all: $(PROGRAMS) install: $(PROGRAMS) mkdir -p $(DESTDIR)$(sbindir) $(INSTALL) -m 755 $(PROGRAMS) $(DESTDIR)$(sbindir) brctl: $(brctl_OBJECTS) ../libbridge/libbridge.a $(CC) $(LDFLAGS) $(brctl_OBJECTS) $(LIBS) -o brctl %.o: %.c brctl.h $(CC) $(CFLAGS) $(INCLUDE) -c $< clean: rm -f *.o brctl core bridge-utils-1.5/brctl/brctl.c000066400000000000000000000037501154422654600163470ustar00rootroot00000000000000/* * 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 #include #include #include #include #include "libbridge.h" #include "config.h" #include "brctl.h" static void help() { printf("Usage: brctl [commands]\n"); printf("commands:\n"); command_helpall(); } 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 } }; while ((f = getopt_long(argc, argv, "Vh", options, NULL)) != EOF) switch(f) { case 'h': help(); return 0; case 'V': printf("%s, %s\n", PACKAGE_NAME, PACKAGE_VERSION); return 0; default: fprintf(stderr, "Unknown option '%c'\n", f); goto help; } if (argc == optind) goto help; if (br_init()) { fprintf(stderr, "can't setup bridge control: %s\n", strerror(errno)); return 1; } 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 + 1) { printf("Incorrect number of arguments for command\n"); printf("Usage: brctl %s %s\n", cmd->name, cmd->help); return 1; } return cmd->func(argc, argv); help: help(); return 1; } bridge-utils-1.5/brctl/brctl.h000066400000000000000000000023301154422654600163450ustar00rootroot00000000000000/* * 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. */ #ifndef _BRCTL_H #define _BRCTL_H struct command { int nargs; const char *name; int (*func)(int argc, char *const* argv); const char *help; }; const struct command *command_lookup(const char *cmd); void command_help(const struct command *); void command_helpall(void); void br_dump_bridge_id(const unsigned char *x); void br_show_timer(const struct timeval *tv); void br_dump_interface_list(const char *br); void br_dump_info(const char *br, const struct bridge_info *bri); #endif bridge-utils-1.5/brctl/brctl_cmd.c000066400000000000000000000253351154422654600171750ustar00rootroot00000000000000/* * 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 #include #include #include #include #include #include "libbridge.h" #include "brctl.h" static int strtotimeval(struct timeval *tv, const char *time) { double secs; if (sscanf(time, "%lf", &secs) != 1) return -1; tv->tv_sec = secs; tv->tv_usec = 1000000 * (secs - tv->tv_sec); return 0; } static int br_cmd_addbr(int argc, char*const* argv) { int err; switch (err = br_add_bridge(argv[1])) { case 0: return 0; case EEXIST: fprintf(stderr, "device %s already exists; can't create " "bridge with the same name\n", argv[1]); return 1; default: fprintf(stderr, "add bridge failed: %s\n", strerror(err)); return 1; } } static int br_cmd_delbr(int argc, char*const* argv) { int err; switch (err = br_del_bridge(argv[1])){ case 0: return 0; case ENXIO: fprintf(stderr, "bridge %s doesn't exist; can't delete it\n", argv[1]); return 1; case EBUSY: fprintf(stderr, "bridge %s is still up; can't delete it\n", argv[1]); return 1; default: fprintf(stderr, "can't delete bridge %s: %s\n", argv[1], strerror(err)); return 1; } } static int br_cmd_addif(int argc, char *const* argv) { const char *brname; int err; argc -= 2; brname = *++argv; while (argc-- > 0) { const char *ifname = *++argv; err = br_add_interface(brname, ifname); switch(err) { case 0: continue; case ENODEV: if (if_nametoindex(ifname) == 0) fprintf(stderr, "interface %s does not exist!\n", ifname); else fprintf(stderr, "bridge %s does not exist!\n", brname); break; case EBUSY: fprintf(stderr, "device %s is already a member of a bridge; " "can't enslave it to bridge %s.\n", ifname, brname); break; case ELOOP: fprintf(stderr, "device %s is a bridge device itself; " "can't enslave a bridge device to a bridge device.\n", ifname); break; default: fprintf(stderr, "can't add %s to bridge %s: %s\n", ifname, brname, strerror(err)); } return 1; } return 0; } static int br_cmd_delif(int argc, char *const* argv) { const char *brname; int err; argc -= 2; brname = *++argv; while (argc-- > 0) { const char *ifname = *++argv; err = br_del_interface(brname, ifname); switch (err) { case 0: continue; case ENODEV: if (if_nametoindex(ifname) == 0) fprintf(stderr, "interface %s does not exist!\n", ifname); else fprintf(stderr, "bridge %s does not exist!\n", brname); break; case EINVAL: fprintf(stderr, "device %s is not a slave of %s\n", ifname, brname); break; default: fprintf(stderr, "can't delete %s from %s: %s\n", ifname, brname, strerror(err)); } return 1; } return 0; } static int br_cmd_setageing(int argc, char *const* argv) { int err; struct timeval tv; if (strtotimeval(&tv, argv[2])) { fprintf(stderr, "bad ageing time value\n"); return 1; } err = br_set_ageing_time(argv[1], &tv); if (err) fprintf(stderr, "set ageing time failed: %s\n", strerror(err)); return err != 0; } static int br_cmd_setbridgeprio(int argc, char *const* argv) { int prio; int err; if (sscanf(argv[2], "%i", &prio) != 1) { fprintf(stderr,"bad priority\n"); return 1; } err = br_set_bridge_priority(argv[1], prio); if (err) fprintf(stderr, "set bridge priority failed: %s\n", strerror(err)); return err != 0; } static int br_cmd_setfd(int argc, char *const* argv) { struct timeval tv; int err; if (strtotimeval(&tv, argv[2])) { fprintf(stderr, "bad forward delay value\n"); return 1; } err = br_set_bridge_forward_delay(argv[1], &tv); if (err) fprintf(stderr, "set forward delay failed: %s\n", strerror(err)); return err != 0; } static int br_cmd_sethello(int argc, char *const* argv) { struct timeval tv; int err; if (strtotimeval(&tv, argv[2])) { fprintf(stderr, "bad hello timer value\n"); return 1; } err = br_set_bridge_hello_time(argv[1], &tv); if (err) fprintf(stderr, "set hello timer failed: %s\n", strerror(err)); return err != 0; } static int br_cmd_setmaxage(int argc, char *const* argv) { struct timeval tv; int err; if (strtotimeval(&tv, argv[2])) { fprintf(stderr, "bad max age value\n"); return 1; } err = br_set_bridge_max_age(argv[1], &tv); if (err) fprintf(stderr, "set max age failed: %s\n", strerror(err)); return err != 0; } static int br_cmd_setpathcost(int argc, char *const* argv) { int cost, err; if (sscanf(argv[3], "%i", &cost) != 1) { fprintf(stderr, "bad path cost value\n"); return 1; } err = br_set_path_cost(argv[1], argv[2], cost); if (err) fprintf(stderr, "set path cost failed: %s\n", strerror(err)); return err != 0; } static int br_cmd_setportprio(int argc, char *const* argv) { int cost, err; if (sscanf(argv[3], "%i", &cost) != 1) { fprintf(stderr, "bad path priority value\n"); return 1; } err = br_set_port_priority(argv[1], argv[2], cost); if (err) fprintf(stderr, "set port priority failed: %s\n", strerror(errno)); return err != 0; } static int br_cmd_stp(int argc, char *const* argv) { int stp, err; if (!strcmp(argv[2], "on") || !strcmp(argv[2], "yes") || !strcmp(argv[2], "1")) stp = 1; else if (!strcmp(argv[2], "off") || !strcmp(argv[2], "no") || !strcmp(argv[2], "0")) stp = 0; else { fprintf(stderr, "expect on/off for argument\n"); return 1; } err = br_set_stp_state(argv[1], stp); if (err) fprintf(stderr, "set stp status failed: %s\n", strerror(errno)); return err != 0; } static int br_cmd_showstp(int argc, char *const* argv) { struct bridge_info info; if (br_get_bridge_info(argv[1], &info)) { fprintf(stderr, "%s: can't get info %s\n", argv[1], strerror(errno)); return 1; } br_dump_info(argv[1], &info); return 0; } static int show_bridge(const char *name, void *arg) { struct bridge_info info; printf("%s\t\t", name); fflush(stdout); if (br_get_bridge_info(name, &info)) { fprintf(stderr, "can't get info %s\n", strerror(errno)); return 1; } br_dump_bridge_id((unsigned char *)&info.bridge_id); printf("\t%s\t\t", info.stp_enabled?"yes":"no"); br_dump_interface_list(name); return 0; } static int br_cmd_show(int argc, char *const* argv) { int i; printf("bridge name\tbridge id\t\tSTP enabled\tinterfaces\n"); if (argc == 1) br_foreach_bridge(show_bridge, NULL); else for(i = 2; i <= argc; i++) show_bridge(argv[i - 1], NULL); return 0; } static int compare_fdbs(const void *_f0, const void *_f1) { const struct fdb_entry *f0 = _f0; const struct fdb_entry *f1 = _f1; return memcmp(f0->mac_addr, f1->mac_addr, 6); } static int br_cmd_showmacs(int argc, char *const* argv) { const char *brname = argv[1]; #define CHUNK 128 int i, n; struct fdb_entry *fdb = NULL; int offset = 0; for(;;) { fdb = realloc(fdb, (offset + CHUNK) * sizeof(struct fdb_entry)); if (!fdb) { fprintf(stderr, "Out of memory\n"); return 1; } n = br_read_fdb(brname, fdb+offset, offset, CHUNK); if (n == 0) break; if (n < 0) { fprintf(stderr, "read of forward table failed: %s\n", strerror(errno)); return 1; } offset += n; } qsort(fdb, offset, sizeof(struct fdb_entry), compare_fdbs); printf("port no\tmac addr\t\tis local?\tageing timer\n"); for (i = 0; i < offset; i++) { const struct fdb_entry *f = fdb + i; printf("%3i\t", f->port_no); printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\t", f->mac_addr[0], f->mac_addr[1], f->mac_addr[2], f->mac_addr[3], f->mac_addr[4], f->mac_addr[5]); printf("%s\t\t", f->is_local?"yes":"no"); br_show_timer(&f->ageing_timer_value); printf("\n"); } return 0; } static int br_cmd_hairpin(int argc, char *const* argv) { int hairpin, err; const char *brname = *++argv; const char *ifname = *++argv; const char *hpmode = *++argv; if (!strcmp(hpmode, "on") || !strcmp(hpmode, "yes") || !strcmp(hpmode, "1")) hairpin = 1; else if (!strcmp(hpmode, "off") || !strcmp(hpmode, "no") || !strcmp(hpmode, "0")) hairpin = 0; else { fprintf(stderr, "expect on/off for argument\n"); return 1; } if (if_nametoindex(ifname) == 0) { fprintf(stderr, "interface %s does not exist!\n", ifname); return 1; } else if (if_nametoindex(brname) == 0) { fprintf(stderr, "bridge %s does not exist!\n", brname); return 1; } err = br_set_hairpin_mode(brname, ifname, hairpin); if (err) { fprintf(stderr, "can't set %s to hairpin on bridge %s: %s\n", ifname, brname, strerror(err)); } return err != 0; } static const struct command commands[] = { { 1, "addbr", br_cmd_addbr, "\t\tadd bridge" }, { 1, "delbr", br_cmd_delbr, "\t\tdelete bridge" }, { 2, "addif", br_cmd_addif, " \tadd interface to bridge" }, { 2, "delif", br_cmd_delif, " \tdelete interface from bridge" }, { 3, "hairpin", br_cmd_hairpin, " {on|off}\tturn hairpin on/off" }, { 2, "setageing", br_cmd_setageing, "