├── AUTHORS ├── COPYING ├── COPYING.LIB ├── ChangeLog ├── INSTALL ├── Makefile.am ├── Makefile.in ├── NEWS ├── README.md ├── README.zebra ├── REPORTING-BUGS ├── SERVICES ├── TODO ├── aclocal.m4 ├── config.guess ├── config.h.in ├── config.sub ├── configure ├── configure.ac ├── depcomp ├── doc ├── Makefile.am ├── Makefile.in └── vtysh.1 ├── install-sh ├── lib ├── Makefile.am ├── Makefile.in ├── buffer.c ├── buffer.h ├── command.c ├── command.h ├── daemon.c ├── filter.c ├── filter.h ├── getopt.c ├── getopt.h ├── getopt1.c ├── hash.c ├── hash.h ├── if.c ├── if.h ├── keychain.c ├── keychain.h ├── linklist.c ├── linklist.h ├── log.c ├── log.h ├── md5-gnu.h ├── md5.c ├── memory.c ├── memory.h ├── network.c ├── network.h ├── pid_output.c ├── plist.c ├── plist.h ├── pqueue.c ├── pqueue.h ├── prefix.c ├── prefix.h ├── print_version.c ├── regex-gnu.h ├── regex.c ├── routemap.c ├── routemap.h ├── smux.c ├── smux.h ├── sockopt.c ├── sockopt.h ├── sockunion.c ├── sockunion.h ├── str.c ├── str.h ├── stream.c ├── stream.h ├── table.c ├── table.h ├── thread.c ├── thread.h ├── vector.c ├── vector.h ├── version.c ├── version.h ├── vty.c ├── vty.h └── zebra.h ├── missing ├── mkinstalldirs ├── update-autotools ├── vtysh ├── Makefile.am ├── Makefile.in ├── vtysh.c ├── vtysh.conf.sample ├── vtysh.h ├── vtysh_cmd.c ├── vtysh_config.c ├── vtysh_main.c ├── vtysh_user.c └── vtysh_user.h └── zebra ├── connected.c ├── connected.h ├── rib.h ├── zserv.c └── zserv.h /AUTHORS: -------------------------------------------------------------------------------- 1 | Kunihiro Ishiguro 2 | Toshiaki Takada 3 | Yasuhiro Ohara 4 | Akihiro Mizutani 5 | Gleb Natapov 6 | Alex D. Zinin 7 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Basic Installation 2 | ================== 3 | 4 | These are generic installation instructions. 5 | 6 | The `configure' shell script attempts to guess correct values for 7 | various system-dependent variables used during compilation. It uses 8 | those values to create a `Makefile' in each directory of the package. 9 | It may also create one or more `.h' files containing system-dependent 10 | definitions. Finally, it creates a shell script `config.status' that 11 | you can run in the future to recreate the current configuration, a file 12 | `config.cache' that saves the results of its tests to speed up 13 | reconfiguring, and a file `config.log' containing compiler output 14 | (useful mainly for debugging `configure'). 15 | 16 | If you need to do unusual things to compile the package, please try 17 | to figure out how `configure' could check whether to do them, and mail 18 | diffs or instructions to the address given in the `README' so they can 19 | be considered for the next release. If at some point `config.cache' 20 | contains results you don't want to keep, you may remove or edit it. 21 | 22 | The file `configure.in' is used to create `configure' by a program 23 | called `autoconf'. You only need `configure.in' if you want to change 24 | it or regenerate `configure' using a newer version of `autoconf'. 25 | 26 | The simplest way to compile this package is: 27 | 28 | 1. `cd' to the directory containing the package's source code and type 29 | `./configure' to configure the package for your system. If you're 30 | using `csh' on an old version of System V, you might need to type 31 | `sh ./configure' instead to prevent `csh' from trying to execute 32 | `configure' itself. 33 | 34 | Running `configure' takes awhile. While running, it prints some 35 | messages telling which features it is checking for. 36 | 37 | 2. Type `make' to compile the package. 38 | 39 | 3. Optionally, type `make check' to run any self-tests that come with 40 | the package. 41 | 42 | 4. Type `make install' to install the programs and any data files and 43 | documentation. 44 | 45 | 5. You can remove the program binaries and object files from the 46 | source code directory by typing `make clean'. To also remove the 47 | files that `configure' created (so you can compile the package for 48 | a different kind of computer), type `make distclean'. There is 49 | also a `make maintainer-clean' target, but that is intended mainly 50 | for the package's developers. If you use it, you may have to get 51 | all sorts of other programs in order to regenerate files that came 52 | with the distribution. 53 | 54 | Compilers and Options 55 | ===================== 56 | 57 | Some systems require unusual options for compilation or linking that 58 | the `configure' script does not know about. You can give `configure' 59 | initial values for variables by setting them in the environment. Using 60 | a Bourne-compatible shell, you can do that on the command line like 61 | this: 62 | CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure 63 | 64 | Or on systems that have the `env' program, you can do it like this: 65 | env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure 66 | 67 | Compiling For Multiple Architectures 68 | ==================================== 69 | 70 | You can compile the package for more than one kind of computer at the 71 | same time, by placing the object files for each architecture in their 72 | own directory. To do this, you must use a version of `make' that 73 | supports the `VPATH' variable, such as GNU `make'. `cd' to the 74 | directory where you want the object files and executables to go and run 75 | the `configure' script. `configure' automatically checks for the 76 | source code in the directory that `configure' is in and in `..'. 77 | 78 | If you have to use a `make' that does not supports the `VPATH' 79 | variable, you have to compile the package for one architecture at a time 80 | in the source code directory. After you have installed the package for 81 | one architecture, use `make distclean' before reconfiguring for another 82 | architecture. 83 | 84 | Installation Names 85 | ================== 86 | 87 | By default, `make install' will install the package's files in 88 | `/usr/local/bin', `/usr/local/man', etc. You can specify an 89 | installation prefix other than `/usr/local' by giving `configure' the 90 | option `--prefix=PATH'. 91 | 92 | You can specify separate installation prefixes for 93 | architecture-specific files and architecture-independent files. If you 94 | give `configure' the option `--exec-prefix=PATH', the package will use 95 | PATH as the prefix for installing programs and libraries. 96 | Documentation and other data files will still use the regular prefix. 97 | 98 | In addition, if you use an unusual directory layout you can give 99 | options like `--bindir=PATH' to specify different values for particular 100 | kinds of files. Run `configure --help' for a list of the directories 101 | you can set and what kinds of files go in them. 102 | 103 | If the package supports it, you can cause programs to be installed 104 | with an extra prefix or suffix on their names by giving `configure' the 105 | option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. 106 | 107 | Optional Features 108 | ================= 109 | 110 | Some packages pay attention to `--enable-FEATURE' options to 111 | `configure', where FEATURE indicates an optional part of the package. 112 | They may also pay attention to `--with-PACKAGE' options, where PACKAGE 113 | is something like `gnu-as' or `x' (for the X Window System). The 114 | `README' should mention any `--enable-' and `--with-' options that the 115 | package recognizes. 116 | 117 | For packages that use the X Window System, `configure' can usually 118 | find the X include and library files automatically, but if it doesn't, 119 | you can use the `configure' options `--x-includes=DIR' and 120 | `--x-libraries=DIR' to specify their locations. 121 | 122 | Specifying the System Type 123 | ========================== 124 | 125 | There may be some features `configure' can not figure out 126 | automatically, but needs to determine by the type of host the package 127 | will run on. Usually `configure' can figure that out, but if it prints 128 | a message saying it can not guess the host type, give it the 129 | `--host=TYPE' option. TYPE can either be a short name for the system 130 | type, such as `sun4', or a canonical name with three fields: 131 | CPU-COMPANY-SYSTEM 132 | 133 | See the file `config.sub' for the possible values of each field. If 134 | `config.sub' isn't included in this package, then this package doesn't 135 | need to know the host type. 136 | 137 | If you are building compiler tools for cross-compiling, you can also 138 | use the `--target=TYPE' option to select the type of system they will 139 | produce code for and the `--build=TYPE' option to select the type of 140 | system on which you are compiling the package. 141 | 142 | Sharing Defaults 143 | ================ 144 | 145 | If you want to set default values for `configure' scripts to share, 146 | you can create a site shell script called `config.site' that gives 147 | default values for variables like `CC', `cache_file', and `prefix'. 148 | `configure' looks for `PREFIX/share/config.site' if it exists, then 149 | `PREFIX/etc/config.site' if it exists. Or, you can set the 150 | `CONFIG_SITE' environment variable to the location of the site script. 151 | A warning: not all `configure' scripts look for a site script. 152 | 153 | Operation Controls 154 | ================== 155 | 156 | `configure' recognizes the following options to control how it 157 | operates. 158 | 159 | `--cache-file=FILE' 160 | Use and save the results of the tests in FILE instead of 161 | `./config.cache'. Set FILE to `/dev/null' to disable caching, for 162 | debugging `configure'. 163 | 164 | `--help' 165 | Print a summary of the options to `configure', and exit. 166 | 167 | `--quiet' 168 | `--silent' 169 | `-q' 170 | Do not print messages saying which checks are being made. 171 | 172 | `--srcdir=DIR' 173 | Look for the package's source code in directory DIR. Usually 174 | `configure' can determine that directory automatically. 175 | 176 | `--version' 177 | Print the version of Autoconf used to generate the `configure' 178 | script, and exit. 179 | 180 | `configure' also accepts some other, not widely useful, options. 181 | 182 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in. 2 | 3 | SUBDIRS = lib vtysh doc 4 | 5 | EXTRA_DIST = aclocal.m4 SERVICES TODO REPORTING-BUGS vtysh/Makefile.in \ 6 | vtysh/Makefile.am update-autotools 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | mini-vtysh 2 | ========== 3 | 4 | A shell which is similar to Cisco IOS CLI , tailored from GNU Zebra. 5 | 6 | GNU [Zebra][0] is free software that manages various IPv4 and IPv6 routing 7 | protocols. It provides a shell which is similar to Cisco IOS CLI--VTY shell. 8 | 9 | So, I just want to tailor the source code(version is 0.95a ), to extract a 10 | small vtysh for eductaion purpose. 11 | 12 | I modified the configure.ac for removing the unuseless option,removed some 13 | source file in zebra directory. Certainly, most source file in vtysh 14 | directory were changed. 15 | 16 | I tried my best to extract a clean and simple vtysh, but the result was 17 | far from satisfactory. Some features that I want to implement, if you know 18 | how to implement them then please do them for me! 19 | 20 | Here are some notes or articles ( most of them are wrote in Chinese) for your reference. 21 | + [Evernote sharing notes][1] 22 | 23 | Please rename the README.md to README if some strange error happens!:) 24 | 25 | 26 | Basic Installation 27 | ================== 28 | The simplest way to compile this package is: 29 | 30 | 1. 'cd' to the directory containing the package's source code and type 31 | './configure' to configure the package for your system. 32 | 33 | 2. Type 'make' to compile the package. 34 | 35 | 3. Type 'make install' to install the programs and any data files and 36 | documentation. 37 | 38 | 4. You can remove the program binaries and object files from the 39 | source code directory by typing 'make clean'. 40 | 41 | More information 42 | ================ 43 | I did't change or remove the ChangeLog,TODO or other basic files in the 44 | root directory of the package's source code.See the file README.zebra for 45 | original readme and other infomation. 46 | 47 | [0]: http://www.gnu.org/software/zebra/ 48 | [1]: https://www.evernote.com/pub/mengyingchina/simshell 49 | -------------------------------------------------------------------------------- /README.zebra: -------------------------------------------------------------------------------- 1 | GNU Zebra is free software that manages various IPv4 and IPv6 routing 2 | protocols. 3 | 4 | Currently GNU Zebra supports BGP4, BGP4+, OSPFv2, OSPFv3, RIPv1, 5 | RIPv2, and RIPng. 6 | 7 | See the file INSTALL for building and installation instructions. 8 | 9 | See the file REPORTING-BUGS to report bugs. 10 | 11 | GNU Zebra is free software. See the file COPYING for copying conditions. 12 | 13 | -------------------------------------------------------------------------------- /REPORTING-BUGS: -------------------------------------------------------------------------------- 1 | This file describes the procedure for reporting Zebra bugs. 2 | You are not obliged to follow this format , but it would be 3 | great help for Zebra developers if you report a bug as described 4 | below. 5 | 6 | Send your report to bug-zebra@gnu.org mailing list. 7 | 8 | Please supply the following information: 9 | 1. Your zebra version or if it is CVS version then the date you did checkout. 10 | Always try to report the bugs on the current CVS version. 11 | 2. Zebra daemons you run e.g. bgpd or ripd, your OS full name, 12 | any specific options you compiled zebra with. 13 | 3. Problem description. Copy and paste relative zebra commands and their 14 | output to describe your network setup e.g. "zebra>show ip route". 15 | Please, also give your simple network layout and output of relative OS commands 16 | (e.g. ifconfig). 17 | 4. All zebra configuration files you use. If you don't want to publish 18 | your network numbers change 2 middle bytes in IPv4 address to be XXX e.g. 19 | 192.XXX.XXX.32/24. Similar could be done with IPv6. 20 | 5. If any zebra daemon core dumped, please, supply stack trace using 21 | the following commands: host> gdb exec_file core_file , (gdb) bt . 22 | 6. Run all zebra daemons with full debugging on (see documentation on debugging) and 23 | send _only_ part of logs which are relative to your problem. 24 | 7. If the problem is difficult to reproduce please send a shell script to 25 | reproduce it. 26 | 8. Patches, workarounds, fixes are always welcome. 27 | 28 | Thank You. 29 | -------------------------------------------------------------------------------- /SERVICES: -------------------------------------------------------------------------------- 1 | # As long as this software is in alpha testing it is not yet included 2 | # in /etc/services files. This means that you may need to add the following 3 | # lines into your /etc/services file on your hosts. 4 | # 5 | # --- Please add this to your /etc/services --- 6 | 7 | # 8 | # GNU Zebra services 9 | # 10 | 11 | zebrasrv 2600/tcp 12 | zebra 2601/tcp 13 | ripd 2602/tcp 14 | ripng 2603/tcp 15 | ospfd 2604/tcp 16 | bgpd 2605/tcp 17 | ospf6d 2606/tcp 18 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | 2 | Zebra TODO list 3 | 2004/07/20 4 | 5 | zebra: 6 | 7 | o Pointopoint address configuration. 8 | o Multiple (alias) address configuration for the interface when kernel 9 | support it [just starting]. 10 | 11 | bgpd: 12 | 13 | o HUP signal support (reload configuration file). 14 | o BGP multi-path extension 15 | 16 | ripd: 17 | 18 | o Multipath support. 19 | 20 | ospfd: 21 | 22 | o Rewrite the incremental RT update code. 23 | o Demand circuits. 24 | o Multiple instances. 25 | o OSPF MIB [SNMP get is amost finished]. 26 | o HUP signal treatment. 27 | 28 | ospf6d: 29 | 30 | o Documentation. 31 | -- 32 | Kunihiro Ishiguro 33 | -------------------------------------------------------------------------------- /config.guess: -------------------------------------------------------------------------------- 1 | /usr/share/automake-1.11/config.guess -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define if building universal (internal helper macro) */ 4 | #undef AC_APPLE_UNIVERSAL_BUILD 5 | 6 | /* BSDI */ 7 | #undef BSDI_NRL 8 | 9 | /* FreeBSD 3.2 */ 10 | #undef FREEBSD_32 11 | 12 | /* GNU Linux */ 13 | #undef GNU_LINUX 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_ASM_TYPES_H 17 | 18 | /* Define to 1 if you have the `bcopy' function. */ 19 | #undef HAVE_BCOPY 20 | 21 | /* Define to 1 if you have the `bzero' function. */ 22 | #undef HAVE_BZERO 23 | 24 | /* Define to 1 if you have the `daemon' function. */ 25 | #undef HAVE_DAEMON 26 | 27 | /* Define to 1 if you have the `getaddrinfo' function. */ 28 | #undef HAVE_GETADDRINFO 29 | 30 | /* Define to 1 if you have the `getifaddrs' function. */ 31 | #undef HAVE_GETIFADDRS 32 | 33 | /* GNU regexp library */ 34 | #undef HAVE_GNU_REGEX 35 | 36 | /* ifaliasreq */ 37 | #undef HAVE_IFALIASREQ 38 | 39 | /* Define to 1 if you have the `if_indextoname' function. */ 40 | #undef HAVE_IF_INDEXTONAME 41 | 42 | /* Define to 1 if you have the `if_nametoindex' function. */ 43 | #undef HAVE_IF_NAMETOINDEX 44 | 45 | /* in6addr global variables e.g. in6addr_loopback */ 46 | #undef HAVE_IN6ADDR_GLOBAL 47 | 48 | /* in6_aliasreq */ 49 | #undef HAVE_IN6_ALIASREQ 50 | 51 | /* Define to 1 if you have the `inet_aton' function. */ 52 | #undef HAVE_INET_ATON 53 | 54 | /* Define to 1 if you have the header file. */ 55 | #undef HAVE_INET_ND_H 56 | 57 | /* inet_ntop */ 58 | #undef HAVE_INET_NTOP 59 | 60 | /* inet_pton */ 61 | #undef HAVE_INET_PTON 62 | 63 | /* in_pktinfo */ 64 | #undef HAVE_INPKTINFO 65 | 66 | /* Define to 1 if you have the header file. */ 67 | #undef HAVE_INTTYPES_H 68 | 69 | /* IPv6 */ 70 | #undef HAVE_IPV6 71 | 72 | /* Define to 1 if you have the header file. */ 73 | #undef HAVE_KVM_H 74 | 75 | /* Define to 1 if you have the `crypt' library (-lcrypt). */ 76 | #undef HAVE_LIBCRYPT 77 | 78 | /* Define to 1 if you have the `kvm' library (-lkvm). */ 79 | #undef HAVE_LIBKVM 80 | 81 | /* Define to 1 if you have the `m' library (-lm). */ 82 | #undef HAVE_LIBM 83 | 84 | /* Define to 1 if you have the `ncurses' library (-lncurses). */ 85 | #undef HAVE_LIBNCURSES 86 | 87 | /* Define to 1 if you have the `nsl' library (-lnsl). */ 88 | #undef HAVE_LIBNSL 89 | 90 | /* Define to 1 if you have the `readline' library (-lreadline). */ 91 | #undef HAVE_LIBREADLINE 92 | 93 | /* Define to 1 if you have the `resolv' library (-lresolv). */ 94 | #undef HAVE_LIBRESOLV 95 | 96 | /* Define to 1 if you have the `socket' library (-lsocket). */ 97 | #undef HAVE_LIBSOCKET 98 | 99 | /* Define to 1 if you have the `termcap' library (-ltermcap). */ 100 | #undef HAVE_LIBTERMCAP 101 | 102 | /* Define to 1 if you have the `tinfo' library (-ltinfo). */ 103 | #undef HAVE_LIBTINFO 104 | 105 | /* Define to 1 if you have the header file. */ 106 | #undef HAVE_LIBUTIL_H 107 | 108 | /* Define to 1 if you have the `xnet' library (-lxnet). */ 109 | #undef HAVE_LIBXNET 110 | 111 | /* Define to 1 if you have the header file. */ 112 | #undef HAVE_LINUX_VERSION_H 113 | 114 | /* Define to 1 if you have the header file. */ 115 | #undef HAVE_MEMORY_H 116 | 117 | /* Define to 1 if you have the header file. */ 118 | #undef HAVE_NETDB_H 119 | 120 | /* Define to 1 if you have the header file. */ 121 | #undef HAVE_NETINET6_ND6_H 122 | 123 | /* Define to 1 if you have the header file. */ 124 | #undef HAVE_NETINET_ICMP6_H 125 | 126 | /* Define to 1 if you have the header file. */ 127 | #undef HAVE_NETINET_IN6_H 128 | 129 | /* Define to 1 if you have the header file. */ 130 | #undef HAVE_NETINET_IN6_VAR_H 131 | 132 | /* Define to 1 if you have the header file. */ 133 | #undef HAVE_NETINET_IN_H 134 | 135 | /* Define to 1 if you have the header file. */ 136 | #undef HAVE_NETINET_IN_VAR_H 137 | 138 | /* netlink */ 139 | #undef HAVE_NETLINK 140 | 141 | /* Define to 1 if you have the header file. */ 142 | #undef HAVE_NET_IF_DL_H 143 | 144 | /* Define to 1 if you have the header file. */ 145 | #undef HAVE_NET_IF_VAR_H 146 | 147 | /* Define to 1 if you have the header file. */ 148 | #undef HAVE_NET_NETOPT_H 149 | 150 | /* NET_RT_IFLIST */ 151 | #undef HAVE_NET_RT_IFLIST 152 | 153 | /* /proc/net/dev */ 154 | #undef HAVE_PROC_NET_DEV 155 | 156 | /* /proc/net/if_inet6 */ 157 | #undef HAVE_PROC_NET_IF_INET6 158 | 159 | /* rt_addrinfo */ 160 | #undef HAVE_RT_ADDRINFO 161 | 162 | /* rusage */ 163 | #undef HAVE_RUSAGE 164 | 165 | /* sa_len */ 166 | #undef HAVE_SA_LEN 167 | 168 | /* Define to 1 if you have the `setproctitle' function. */ 169 | #undef HAVE_SETPROCTITLE 170 | 171 | /* scope id */ 172 | #undef HAVE_SIN6_SCOPE_ID 173 | 174 | /* sin_len */ 175 | #undef HAVE_SIN_LEN 176 | 177 | /* Define to 1 if you have the `snprintf' function. */ 178 | #undef HAVE_SNPRINTF 179 | 180 | /* sockaddr_dl */ 181 | #undef HAVE_SOCKADDR_DL 182 | 183 | /* socklen_t */ 184 | #undef HAVE_SOCKLEN_T 185 | 186 | /* Define to 1 if you have the header file. */ 187 | #undef HAVE_STDINT_H 188 | 189 | /* Define to 1 if you have the header file. */ 190 | #undef HAVE_STDLIB_H 191 | 192 | /* Define to 1 if you have the `strerror' function. */ 193 | #undef HAVE_STRERROR 194 | 195 | /* Define to 1 if you have the header file. */ 196 | #undef HAVE_STRINGS_H 197 | 198 | /* Define to 1 if you have the header file. */ 199 | #undef HAVE_STRING_H 200 | 201 | /* Define to 1 if you have the `strlcat' function. */ 202 | #undef HAVE_STRLCAT 203 | 204 | /* Define to 1 if you have the `strlcpy' function. */ 205 | #undef HAVE_STRLCPY 206 | 207 | /* Define to 1 if you have the header file. */ 208 | #undef HAVE_STROPTS_H 209 | 210 | /* sun_len */ 211 | #undef HAVE_SUN_LEN 212 | 213 | /* Define to 1 if you have the header file. */ 214 | #undef HAVE_SYS_CONF_H 215 | 216 | /* Define to 1 if you have the header file. */ 217 | #undef HAVE_SYS_KSYM_H 218 | 219 | /* Define to 1 if you have the header file. */ 220 | #undef HAVE_SYS_SELECT_H 221 | 222 | /* Define to 1 if you have the header file. */ 223 | #undef HAVE_SYS_SOCKIO_H 224 | 225 | /* Define to 1 if you have the header file. */ 226 | #undef HAVE_SYS_STAT_H 227 | 228 | /* Define to 1 if you have the header file. */ 229 | #undef HAVE_SYS_SYSCTL_H 230 | 231 | /* Define to 1 if you have the header file. */ 232 | #undef HAVE_SYS_TIMES_H 233 | 234 | /* Define to 1 if you have the header file. */ 235 | #undef HAVE_SYS_TIME_H 236 | 237 | /* Define to 1 if you have the header file. */ 238 | #undef HAVE_SYS_TYPES_H 239 | 240 | /* Define to 1 if you have the header file. */ 241 | #undef HAVE_UNISTD_H 242 | 243 | /* Define to 1 if you have the `vsnprintf' function. */ 244 | #undef HAVE_VSNPRINTF 245 | 246 | /* Inria IPv6 */ 247 | #undef INRIA_IPV6 248 | 249 | /* KAME IPv6 */ 250 | #undef KAME 251 | 252 | /* Linux IPv6 */ 253 | #undef LINUX_IPV6 254 | 255 | /* NRL */ 256 | #undef NRL 257 | 258 | /* OpenBSD */ 259 | #undef OPEN_BSD 260 | 261 | /* Name of package */ 262 | #undef PACKAGE 263 | 264 | /* Define to the address where bug reports for this package should be sent. */ 265 | #undef PACKAGE_BUGREPORT 266 | 267 | /* Define to the full name of this package. */ 268 | #undef PACKAGE_NAME 269 | 270 | /* Define to the full name and version of this package. */ 271 | #undef PACKAGE_STRING 272 | 273 | /* Define to the one symbol short name of this package. */ 274 | #undef PACKAGE_TARNAME 275 | 276 | /* Define to the home page for this package. */ 277 | #undef PACKAGE_URL 278 | 279 | /* Define to the version of this package. */ 280 | #undef PACKAGE_VERSION 281 | 282 | /* Define as the return type of signal handlers (`int' or `void'). */ 283 | #undef RETSIGTYPE 284 | 285 | /* Define to 1 if you have the ANSI C header files. */ 286 | #undef STDC_HEADERS 287 | 288 | /* SunOS 5 */ 289 | #undef SUNOS_5 290 | 291 | /* Use PAM for authentication */ 292 | #undef USE_PAM 293 | 294 | /* Enable extensions on AIX 3, Interix. */ 295 | #ifndef _ALL_SOURCE 296 | # undef _ALL_SOURCE 297 | #endif 298 | /* Enable GNU extensions on systems that have them. */ 299 | #ifndef _GNU_SOURCE 300 | # undef _GNU_SOURCE 301 | #endif 302 | /* Enable threading extensions on Solaris. */ 303 | #ifndef _POSIX_PTHREAD_SEMANTICS 304 | # undef _POSIX_PTHREAD_SEMANTICS 305 | #endif 306 | /* Enable extensions on HP NonStop. */ 307 | #ifndef _TANDEM_SOURCE 308 | # undef _TANDEM_SOURCE 309 | #endif 310 | /* Enable general extensions on Solaris. */ 311 | #ifndef __EXTENSIONS__ 312 | # undef __EXTENSIONS__ 313 | #endif 314 | 315 | 316 | /* Version number of package */ 317 | #undef VERSION 318 | 319 | /* VTY shell */ 320 | #undef VTYSH 321 | 322 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 323 | significant byte first (like Motorola and SPARC, unlike Intel). */ 324 | #if defined AC_APPLE_UNIVERSAL_BUILD 325 | # if defined __BIG_ENDIAN__ 326 | # define WORDS_BIGENDIAN 1 327 | # endif 328 | #else 329 | # ifndef WORDS_BIGENDIAN 330 | # undef WORDS_BIGENDIAN 331 | # endif 332 | #endif 333 | 334 | /* Define to 1 if on MINIX. */ 335 | #undef _MINIX 336 | 337 | /* Define to 2 if the system does not provide POSIX.1 features except with 338 | this defined. */ 339 | #undef _POSIX_1_SOURCE 340 | 341 | /* Define to 1 if you need to in order for `stat' and other things to work. */ 342 | #undef _POSIX_SOURCE 343 | 344 | /* Define to empty if `const' does not conform to ANSI C. */ 345 | #undef const 346 | -------------------------------------------------------------------------------- /config.sub: -------------------------------------------------------------------------------- 1 | /usr/share/automake-1.11/config.sub -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in. 2 | 3 | man_MANS = vtysh.1 4 | 5 | -------------------------------------------------------------------------------- /doc/vtysh.1: -------------------------------------------------------------------------------- 1 | .TH VTYSH 1 "July 2000" "Zebra Beast - VTY shell" "Version 0.88" 2 | 3 | .SH NAME 4 | vtysh \- a integrated shell for Zebra routing software 5 | 6 | .SH SYNOPSIS 7 | .B vtysh 8 | [ 9 | .B \-e command 10 | ] 11 | 12 | .SH DESCBGPTION 13 | .B vtysh 14 | is a integrated shell for 15 | .B Zebra 16 | routing engine. 17 | 18 | 19 | .SH OPTIONS 20 | 21 | .TP 22 | \fB\-e 23 | Specify command to be executed under batch mode. 24 | 25 | 26 | .SH COMMANDS 27 | 28 | \fB Almost Zebra commands. 29 | 30 | \fB ping 31 | \fB traceroute 32 | \fB telnnet 33 | 34 | \fB start-shell 35 | \fB start-shell bash 36 | \fB start-shell zsh 37 | 38 | 39 | .SH FILES 40 | 41 | .TP 42 | .BI /usr/local/etc/Zebra.conf 43 | The default location of the 44 | .B vtysh 45 | config file. 46 | 47 | 48 | .SH WARNING 49 | This man page is intended as a quick reference for command line 50 | options, and for config file commands. The definitive document is the 51 | Info file \fBZebra\fR. 52 | 53 | 54 | .SH "SEE ALSO" 55 | References to other related man pages: 56 | 57 | bgpd(8), ripd(8), ripngd(8), ospfd(8), ospf6d(8), zebra(8) 58 | 59 | 60 | .SH BUGS 61 | .B vtysh 62 | eats bugs for breakfast. If you have food for the maintainers try 63 | .BI 64 | 65 | 66 | .SH AUTHOR[S] 67 | See <\fBwww.zebra.org\fR>, or the Info file for an accurate list of authors. 68 | 69 | -------------------------------------------------------------------------------- /install-sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # install - install a program, script, or datafile 4 | # This comes from X11R5 (mit/util/scripts/install.sh). 5 | # 6 | # Copyright 1991 by the Massachusetts Institute of Technology 7 | # 8 | # Permission to use, copy, modify, distribute, and sell this software and its 9 | # documentation for any purpose is hereby granted without fee, provided that 10 | # the above copyright notice appear in all copies and that both that 11 | # copyright notice and this permission notice appear in supporting 12 | # documentation, and that the name of M.I.T. not be used in advertising or 13 | # publicity pertaining to distribution of the software without specific, 14 | # written prior permission. M.I.T. makes no representations about the 15 | # suitability of this software for any purpose. It is provided "as is" 16 | # without express or implied warranty. 17 | # 18 | # Calling this script install-sh is preferred over install.sh, to prevent 19 | # `make' implicit rules from creating a file called install from it 20 | # when there is no Makefile. 21 | # 22 | # This script is compatible with the BSD install script, but was written 23 | # from scratch. It can only install one file at a time, a restriction 24 | # shared with many OS's install programs. 25 | 26 | 27 | # set DOITPROG to echo to test this script 28 | 29 | # Don't use :- since 4.3BSD and earlier shells don't like it. 30 | doit="${DOITPROG-}" 31 | 32 | 33 | # put in absolute paths if you don't have them in your path; or use env. vars. 34 | 35 | mvprog="${MVPROG-mv}" 36 | cpprog="${CPPROG-cp}" 37 | chmodprog="${CHMODPROG-chmod}" 38 | chownprog="${CHOWNPROG-chown}" 39 | chgrpprog="${CHGRPPROG-chgrp}" 40 | stripprog="${STRIPPROG-strip}" 41 | rmprog="${RMPROG-rm}" 42 | mkdirprog="${MKDIRPROG-mkdir}" 43 | 44 | transformbasename="" 45 | transform_arg="" 46 | instcmd="$mvprog" 47 | chmodcmd="$chmodprog 0755" 48 | chowncmd="" 49 | chgrpcmd="" 50 | stripcmd="" 51 | rmcmd="$rmprog -f" 52 | mvcmd="$mvprog" 53 | src="" 54 | dst="" 55 | dir_arg="" 56 | 57 | while [ x"$1" != x ]; do 58 | case $1 in 59 | -c) instcmd="$cpprog" 60 | shift 61 | continue;; 62 | 63 | -d) dir_arg=true 64 | shift 65 | continue;; 66 | 67 | -m) chmodcmd="$chmodprog $2" 68 | shift 69 | shift 70 | continue;; 71 | 72 | -o) chowncmd="$chownprog $2" 73 | shift 74 | shift 75 | continue;; 76 | 77 | -g) chgrpcmd="$chgrpprog $2" 78 | shift 79 | shift 80 | continue;; 81 | 82 | -s) stripcmd="$stripprog" 83 | shift 84 | continue;; 85 | 86 | -t=*) transformarg=`echo $1 | sed 's/-t=//'` 87 | shift 88 | continue;; 89 | 90 | -b=*) transformbasename=`echo $1 | sed 's/-b=//'` 91 | shift 92 | continue;; 93 | 94 | *) if [ x"$src" = x ] 95 | then 96 | src=$1 97 | else 98 | # this colon is to work around a 386BSD /bin/sh bug 99 | : 100 | dst=$1 101 | fi 102 | shift 103 | continue;; 104 | esac 105 | done 106 | 107 | if [ x"$src" = x ] 108 | then 109 | echo "install: no input file specified" 110 | exit 1 111 | else 112 | : 113 | fi 114 | 115 | if [ x"$dir_arg" != x ]; then 116 | dst=$src 117 | src="" 118 | 119 | if [ -d $dst ]; then 120 | instcmd=: 121 | chmodcmd="" 122 | else 123 | instcmd=$mkdirprog 124 | fi 125 | else 126 | 127 | # Waiting for this to be detected by the "$instcmd $src $dsttmp" command 128 | # might cause directories to be created, which would be especially bad 129 | # if $src (and thus $dsttmp) contains '*'. 130 | 131 | if [ -f $src -o -d $src ] 132 | then 133 | : 134 | else 135 | echo "install: $src does not exist" 136 | exit 1 137 | fi 138 | 139 | if [ x"$dst" = x ] 140 | then 141 | echo "install: no destination specified" 142 | exit 1 143 | else 144 | : 145 | fi 146 | 147 | # If destination is a directory, append the input filename; if your system 148 | # does not like double slashes in filenames, you may need to add some logic 149 | 150 | if [ -d $dst ] 151 | then 152 | dst="$dst"/`basename $src` 153 | else 154 | : 155 | fi 156 | fi 157 | 158 | ## this sed command emulates the dirname command 159 | dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` 160 | 161 | # Make sure that the destination directory exists. 162 | # this part is taken from Noah Friedman's mkinstalldirs script 163 | 164 | # Skip lots of stat calls in the usual case. 165 | if [ ! -d "$dstdir" ]; then 166 | defaultIFS=' 167 | ' 168 | IFS="${IFS-${defaultIFS}}" 169 | 170 | oIFS="${IFS}" 171 | # Some sh's can't handle IFS=/ for some reason. 172 | IFS='%' 173 | set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` 174 | IFS="${oIFS}" 175 | 176 | pathcomp='' 177 | 178 | while [ $# -ne 0 ] ; do 179 | pathcomp="${pathcomp}${1}" 180 | shift 181 | 182 | if [ ! -d "${pathcomp}" ] ; 183 | then 184 | $mkdirprog "${pathcomp}" 185 | else 186 | : 187 | fi 188 | 189 | pathcomp="${pathcomp}/" 190 | done 191 | fi 192 | 193 | if [ x"$dir_arg" != x ] 194 | then 195 | $doit $instcmd $dst && 196 | 197 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else : ; fi && 198 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else : ; fi && 199 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else : ; fi && 200 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else : ; fi 201 | else 202 | 203 | # If we're going to rename the final executable, determine the name now. 204 | 205 | if [ x"$transformarg" = x ] 206 | then 207 | dstfile=`basename $dst` 208 | else 209 | dstfile=`basename $dst $transformbasename | 210 | sed $transformarg`$transformbasename 211 | fi 212 | 213 | # don't allow the sed command to completely eliminate the filename 214 | 215 | if [ x"$dstfile" = x ] 216 | then 217 | dstfile=`basename $dst` 218 | else 219 | : 220 | fi 221 | 222 | # Make a temp file name in the proper directory. 223 | 224 | dsttmp=$dstdir/#inst.$$# 225 | 226 | # Move or copy the file name to the temp name 227 | 228 | $doit $instcmd $src $dsttmp && 229 | 230 | trap "rm -f ${dsttmp}" 0 && 231 | 232 | # and set any options; do chmod last to preserve setuid bits 233 | 234 | # If any of these fail, we abort the whole thing. If we want to 235 | # ignore errors from any of these, just make sure not to ignore 236 | # errors from the above "$doit $instcmd $src $dsttmp" command. 237 | 238 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else :;fi && 239 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else :;fi && 240 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else :;fi && 241 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else :;fi && 242 | 243 | # Now rename the file to the real destination. 244 | 245 | $doit $rmcmd -f $dstdir/$dstfile && 246 | $doit $mvcmd $dsttmp $dstdir/$dstfile 247 | 248 | fi && 249 | 250 | 251 | exit 0 252 | -------------------------------------------------------------------------------- /lib/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in. 2 | 3 | INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib 4 | DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" 5 | 6 | noinst_LIBRARIES = libzebra.a 7 | 8 | libzebra_a_SOURCES = \ 9 | version.c network.c pid_output.c getopt.c getopt1.c daemon.c \ 10 | print_version.c vector.c linklist.c vty.c command.c \ 11 | sockunion.c prefix.c thread.c if.c memory.c buffer.c table.c hash.c \ 12 | filter.c routemap.c stream.c str.c log.c plist.c \ 13 | sockopt.c smux.c md5.c keychain.c pqueue.c 14 | 15 | libzebra_a_DEPENDENCIES = @LIB_REGEX@ 16 | 17 | libzebra_a_LIBADD = @LIB_REGEX@ 18 | 19 | noinst_HEADERS = \ 20 | buffer.h command.h filter.h getopt.h hash.h if.h linklist.h log.h \ 21 | memory.h network.h prefix.h routemap.h sockunion.h \ 22 | str.h stream.h table.h thread.h vector.h version.h vty.h \ 23 | zebra.h plist.h sockopt.h smux.h md5-gnu.h keychain.h \ 24 | pqueue.h 25 | 26 | EXTRA_DIST = regex.c regex-gnu.h 27 | 28 | version.c: Makefile 29 | echo '' >version.c 30 | echo 'char *host_name = "$(host_alias)";' >>version.c 31 | -------------------------------------------------------------------------------- /lib/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Buffering to output and input. 3 | * Copyright (C) 1998 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published 9 | * by the Free Software Foundation; either version 2, or (at your 10 | * option) any later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | #ifndef _ZEBRA_BUFFER_H 24 | #define _ZEBRA_BUFFER_H 25 | 26 | /* Buffer master. */ 27 | struct buffer 28 | { 29 | /* Data list. */ 30 | struct buffer_data *head; 31 | struct buffer_data *tail; 32 | 33 | /* Current allocated data. */ 34 | unsigned long alloc; 35 | 36 | /* Total length of buffer. */ 37 | unsigned long size; 38 | 39 | /* For allocation. */ 40 | struct buffer_data *unused_head; 41 | struct buffer_data *unused_tail; 42 | 43 | /* Current total length of this buffer. */ 44 | unsigned long length; 45 | }; 46 | 47 | /* Data container. */ 48 | struct buffer_data 49 | { 50 | struct buffer *parent; 51 | struct buffer_data *next; 52 | struct buffer_data *prev; 53 | 54 | /* Acctual data stream. */ 55 | unsigned char *data; 56 | 57 | /* Current pointer. */ 58 | unsigned long cp; 59 | 60 | /* Start pointer. */ 61 | unsigned long sp; 62 | }; 63 | 64 | /* Buffer prototypes. */ 65 | struct buffer *buffer_new (size_t); 66 | int buffer_write (struct buffer *, u_char *, size_t); 67 | void buffer_free (struct buffer *); 68 | char *buffer_getstr (struct buffer *); 69 | int buffer_putc (struct buffer *, u_char); 70 | int buffer_putstr (struct buffer *, u_char *); 71 | void buffer_reset (struct buffer *); 72 | int buffer_flush_all (struct buffer *, int); 73 | int buffer_flush_vty_all (struct buffer *, int, int, int); 74 | int buffer_flush_window (struct buffer *, int, int, int, int, int); 75 | int buffer_empty (struct buffer *); 76 | 77 | #endif /* _ZEBRA_BUFFER_H */ 78 | -------------------------------------------------------------------------------- /lib/daemon.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Daemonize routine 3 | * Copyright (C) 1997, 1999 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published 9 | * by the Free Software Foundation; either version 2, or (at your 10 | * option) any later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | #include 24 | 25 | #ifndef HAVE_DAEMON 26 | 27 | /* Daemonize myself. */ 28 | int 29 | daemon (int nochdir, int noclose) 30 | { 31 | pid_t pid; 32 | 33 | pid = fork (); 34 | 35 | /* In case of fork is error. */ 36 | if (pid < 0) 37 | { 38 | perror ("fork"); 39 | return -1; 40 | } 41 | 42 | /* In case of this is parent process. */ 43 | if (pid != 0) 44 | exit (0); 45 | 46 | /* Become session leader and get pid. */ 47 | pid = setsid(); 48 | 49 | if (pid < -1) 50 | { 51 | perror ("setsid"); 52 | return -1; 53 | } 54 | 55 | /* Change directory to root. */ 56 | if (! nochdir) 57 | chdir ("/"); 58 | 59 | /* File descriptor close. */ 60 | if (! noclose) 61 | { 62 | int fd; 63 | 64 | fd = open ("/dev/null", O_RDWR, 0); 65 | if (fd != -1) 66 | { 67 | dup2 (fd, STDIN_FILENO); 68 | dup2 (fd, STDOUT_FILENO); 69 | dup2 (fd, STDERR_FILENO); 70 | if (fd > 2) 71 | close (fd); 72 | } 73 | } 74 | 75 | umask (0027); 76 | 77 | return 0; 78 | } 79 | 80 | #endif /* HAVE_DAEMON */ 81 | -------------------------------------------------------------------------------- /lib/filter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Route filtering function. 3 | * Copyright (C) 1998 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published 9 | * by the Free Software Foundation; either version 2, or (at your 10 | * option) any later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | #ifndef _ZEBRA_FILTER_H 24 | #define _ZEBRA_FILTER_H 25 | 26 | #include "if.h" 27 | 28 | /* Filter type is made by `permit', `deny' and `dynamic'. */ 29 | enum filter_type 30 | { 31 | FILTER_DENY, 32 | FILTER_PERMIT, 33 | FILTER_DYNAMIC 34 | }; 35 | 36 | enum access_type 37 | { 38 | ACCESS_TYPE_STRING, 39 | ACCESS_TYPE_NUMBER 40 | }; 41 | 42 | /* Access list */ 43 | struct access_list 44 | { 45 | char *name; 46 | char *remark; 47 | 48 | struct access_master *master; 49 | 50 | enum access_type type; 51 | 52 | struct access_list *next; 53 | struct access_list *prev; 54 | 55 | struct filter *head; 56 | struct filter *tail; 57 | }; 58 | 59 | /* Prototypes for access-list. */ 60 | void access_list_init (void); 61 | void access_list_reset (void); 62 | void access_list_add_hook (void (*func)(struct access_list *)); 63 | void access_list_delete_hook (void (*func)(struct access_list *)); 64 | struct access_list *access_list_lookup (afi_t, char *); 65 | enum filter_type access_list_apply (struct access_list *, void *); 66 | 67 | #endif /* _ZEBRA_FILTER_H */ 68 | -------------------------------------------------------------------------------- /lib/getopt.h: -------------------------------------------------------------------------------- 1 | /* Declarations for getopt. 2 | Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc. 3 | 4 | NOTE: The canonical source of this file is maintained with the GNU C Library. 5 | Bugs can be reported to bug-glibc@gnu.org. 6 | 7 | This program is free software; you can redistribute it and/or modify it 8 | under the terms of the GNU General Public License as published by the 9 | Free Software Foundation; either version 2, or (at your option) any 10 | later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 20 | USA. */ 21 | 22 | #ifndef _GETOPT_H 23 | #define _GETOPT_H 1 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* For communication from `getopt' to the caller. 30 | When `getopt' finds an option that takes an argument, 31 | the argument value is returned here. 32 | Also, when `ordering' is RETURN_IN_ORDER, 33 | each non-option ARGV-element is returned here. */ 34 | 35 | extern char *optarg; 36 | 37 | /* Index in ARGV of the next element to be scanned. 38 | This is used for communication to and from the caller 39 | and for communication between successive calls to `getopt'. 40 | 41 | On entry to `getopt', zero means this is the first call; initialize. 42 | 43 | When `getopt' returns -1, this is the index of the first of the 44 | non-option elements that the caller should itself scan. 45 | 46 | Otherwise, `optind' communicates from one call to the next 47 | how much of ARGV has been scanned so far. */ 48 | 49 | extern int optind; 50 | 51 | /* Callers store zero here to inhibit the error message `getopt' prints 52 | for unrecognized options. */ 53 | 54 | extern int opterr; 55 | 56 | /* Set to an option character which was unrecognized. */ 57 | 58 | extern int optopt; 59 | 60 | /* Describe the long-named options requested by the application. 61 | The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 62 | of `struct option' terminated by an element containing a name which is 63 | zero. 64 | 65 | The field `has_arg' is: 66 | no_argument (or 0) if the option does not take an argument, 67 | required_argument (or 1) if the option requires an argument, 68 | optional_argument (or 2) if the option takes an optional argument. 69 | 70 | If the field `flag' is not NULL, it points to a variable that is set 71 | to the value given in the field `val' when the option is found, but 72 | left unchanged if the option is not found. 73 | 74 | To have a long-named option do something other than set an `int' to 75 | a compiled-in constant, such as set a value from `optarg', set the 76 | option's `flag' field to zero and its `val' field to a nonzero 77 | value (the equivalent single-letter option character, if there is 78 | one). For long options that have a zero `flag' field, `getopt' 79 | returns the contents of the `val' field. */ 80 | 81 | struct option 82 | { 83 | #if defined (__STDC__) && __STDC__ 84 | const char *name; 85 | #else 86 | char *name; 87 | #endif 88 | /* has_arg can't be an enum because some compilers complain about 89 | type mismatches in all the code that assumes it is an int. */ 90 | int has_arg; 91 | int *flag; 92 | int val; 93 | }; 94 | 95 | /* Names for the values of the `has_arg' field of `struct option'. */ 96 | 97 | #define no_argument 0 98 | #define required_argument 1 99 | #define optional_argument 2 100 | 101 | #if defined (__STDC__) && __STDC__ 102 | #ifdef __GNU_LIBRARY__ 103 | /* Many other libraries have conflicting prototypes for getopt, with 104 | differences in the consts, in stdlib.h. To avoid compilation 105 | errors, only prototype getopt for the GNU C library. */ 106 | extern int getopt (int argc, char *const *argv, const char *shortopts); 107 | #else /* not __GNU_LIBRARY__ */ 108 | extern int getopt (); 109 | #endif /* __GNU_LIBRARY__ */ 110 | extern int getopt_long (int argc, char *const *argv, const char *shortopts, 111 | const struct option *longopts, int *longind); 112 | extern int getopt_long_only (int argc, char *const *argv, 113 | const char *shortopts, 114 | const struct option *longopts, int *longind); 115 | 116 | /* Internal only. Users should not call this directly. */ 117 | extern int _getopt_internal (int argc, char *const *argv, 118 | const char *shortopts, 119 | const struct option *longopts, int *longind, 120 | int long_only); 121 | #else /* not __STDC__ */ 122 | extern int getopt (); 123 | extern int getopt_long (); 124 | extern int getopt_long_only (); 125 | 126 | extern int _getopt_internal (); 127 | #endif /* __STDC__ */ 128 | 129 | #ifdef __cplusplus 130 | } 131 | #endif 132 | 133 | #endif /* getopt.h */ 134 | -------------------------------------------------------------------------------- /lib/getopt1.c: -------------------------------------------------------------------------------- 1 | /* getopt_long and getopt_long_only entry points for GNU getopt. 2 | Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 3 | Free Software Foundation, Inc. 4 | 5 | NOTE: The canonical source of this file is maintained with the GNU C Library. 6 | Bugs can be reported to bug-glibc@gnu.org. 7 | 8 | This program is free software; you can redistribute it and/or modify it 9 | under the terms of the GNU General Public License as published by the 10 | Free Software Foundation; either version 2, or (at your option) any 11 | later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 21 | USA. */ 22 | 23 | #ifdef HAVE_CONFIG_H 24 | #include 25 | #endif 26 | 27 | #include "getopt.h" 28 | 29 | #if !defined __STDC__ || !__STDC__ 30 | /* This is a separate conditional since some stdc systems 31 | reject `defined (const)'. */ 32 | #ifndef const 33 | #define const 34 | #endif 35 | #endif 36 | 37 | #include 38 | 39 | /* Comment out all this code if we are using the GNU C Library, and are not 40 | actually compiling the library itself. This code is part of the GNU C 41 | Library, but also included in many other GNU distributions. Compiling 42 | and linking in this code is a waste when using the GNU C library 43 | (especially if it is a shared library). Rather than having every GNU 44 | program understand `configure --with-gnu-libc' and omit the object files, 45 | it is simpler to just do this in the source for each such file. */ 46 | 47 | #define GETOPT_INTERFACE_VERSION 2 48 | #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 49 | #include 50 | #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION 51 | #define ELIDE_CODE 52 | #endif 53 | #endif 54 | 55 | #ifndef ELIDE_CODE 56 | 57 | 58 | /* This needs to come after some library #include 59 | to get __GNU_LIBRARY__ defined. */ 60 | #ifdef __GNU_LIBRARY__ 61 | #include 62 | #endif 63 | 64 | #ifndef NULL 65 | #define NULL 0 66 | #endif 67 | 68 | int 69 | getopt_long (argc, argv, options, long_options, opt_index) 70 | int argc; 71 | char *const *argv; 72 | const char *options; 73 | const struct option *long_options; 74 | int *opt_index; 75 | { 76 | return _getopt_internal (argc, argv, options, long_options, opt_index, 0); 77 | } 78 | 79 | /* Like getopt_long, but '-' as well as '--' can indicate a long option. 80 | If an option that starts with '-' (not '--') doesn't match a long option, 81 | but does match a short option, it is parsed as a short option 82 | instead. */ 83 | 84 | int 85 | getopt_long_only (argc, argv, options, long_options, opt_index) 86 | int argc; 87 | char *const *argv; 88 | const char *options; 89 | const struct option *long_options; 90 | int *opt_index; 91 | { 92 | return _getopt_internal (argc, argv, options, long_options, opt_index, 1); 93 | } 94 | 95 | 96 | #endif /* Not ELIDE_CODE. */ 97 | 98 | #ifdef TEST 99 | 100 | #include 101 | 102 | int 103 | main (argc, argv) 104 | int argc; 105 | char **argv; 106 | { 107 | int c; 108 | int digit_optind = 0; 109 | 110 | while (1) 111 | { 112 | int this_option_optind = optind ? optind : 1; 113 | int option_index = 0; 114 | static struct option long_options[] = 115 | { 116 | {"add", 1, 0, 0}, 117 | {"append", 0, 0, 0}, 118 | {"delete", 1, 0, 0}, 119 | {"verbose", 0, 0, 0}, 120 | {"create", 0, 0, 0}, 121 | {"file", 1, 0, 0}, 122 | {0, 0, 0, 0} 123 | }; 124 | 125 | c = getopt_long (argc, argv, "abc:d:0123456789", 126 | long_options, &option_index); 127 | if (c == -1) 128 | break; 129 | 130 | switch (c) 131 | { 132 | case 0: 133 | printf ("option %s", long_options[option_index].name); 134 | if (optarg) 135 | printf (" with arg %s", optarg); 136 | printf ("\n"); 137 | break; 138 | 139 | case '0': 140 | case '1': 141 | case '2': 142 | case '3': 143 | case '4': 144 | case '5': 145 | case '6': 146 | case '7': 147 | case '8': 148 | case '9': 149 | if (digit_optind != 0 && digit_optind != this_option_optind) 150 | printf ("digits occur in two different argv-elements.\n"); 151 | digit_optind = this_option_optind; 152 | printf ("option %c\n", c); 153 | break; 154 | 155 | case 'a': 156 | printf ("option a\n"); 157 | break; 158 | 159 | case 'b': 160 | printf ("option b\n"); 161 | break; 162 | 163 | case 'c': 164 | printf ("option c with value `%s'\n", optarg); 165 | break; 166 | 167 | case 'd': 168 | printf ("option d with value `%s'\n", optarg); 169 | break; 170 | 171 | case '?': 172 | break; 173 | 174 | default: 175 | printf ("?? getopt returned character code 0%o ??\n", c); 176 | } 177 | } 178 | 179 | if (optind < argc) 180 | { 181 | printf ("non-option ARGV-elements: "); 182 | while (optind < argc) 183 | printf ("%s ", argv[optind++]); 184 | printf ("\n"); 185 | } 186 | 187 | exit (0); 188 | } 189 | 190 | #endif /* TEST */ 191 | -------------------------------------------------------------------------------- /lib/hash.c: -------------------------------------------------------------------------------- 1 | /* Hash routine. 2 | * Copyright (C) 1998 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; either version 2, or (at your 9 | * option) any later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #include 23 | 24 | #include "hash.h" 25 | #include "memory.h" 26 | 27 | /* Allocate a new hash. */ 28 | struct hash * 29 | hash_create_size (unsigned int size, 30 | unsigned int (*hash_key) (), int (*hash_cmp) ()) 31 | { 32 | struct hash *hash; 33 | 34 | hash = XMALLOC (MTYPE_HASH, sizeof (struct hash)); 35 | hash->index = XMALLOC (MTYPE_HASH_INDEX, 36 | sizeof (struct hash_backet *) * size); 37 | memset (hash->index, 0, sizeof (struct hash_backet *) * size); 38 | hash->size = size; 39 | hash->hash_key = hash_key; 40 | hash->hash_cmp = hash_cmp; 41 | hash->count = 0; 42 | 43 | return hash; 44 | } 45 | 46 | /* Allocate a new hash with default hash size. */ 47 | struct hash * 48 | hash_create (unsigned int (*hash_key) (), int (*hash_cmp) ()) 49 | { 50 | return hash_create_size (HASHTABSIZE, hash_key, hash_cmp); 51 | } 52 | 53 | /* Utility function for hash_get(). When this function is specified 54 | as alloc_func, return arugment as it is. This function is used for 55 | intern already allocated value. */ 56 | void * 57 | hash_alloc_intern (void *arg) 58 | { 59 | return arg; 60 | } 61 | 62 | /* Lookup and return hash backet in hash. If there is no 63 | corresponding hash backet and alloc_func is specified, create new 64 | hash backet. */ 65 | void * 66 | hash_get (struct hash *hash, void *data, void * (*alloc_func) ()) 67 | { 68 | unsigned int key; 69 | unsigned int index; 70 | void *newdata; 71 | struct hash_backet *backet; 72 | 73 | key = (*hash->hash_key) (data); 74 | index = key % hash->size; 75 | 76 | for (backet = hash->index[index]; backet != NULL; backet = backet->next) 77 | if (backet->key == key && (*hash->hash_cmp) (backet->data, data)) 78 | return backet->data; 79 | 80 | if (alloc_func) 81 | { 82 | newdata = (*alloc_func) (data); 83 | if (newdata == NULL) 84 | return NULL; 85 | 86 | backet = XMALLOC (MTYPE_HASH_BACKET, sizeof (struct hash_backet)); 87 | backet->data = newdata; 88 | backet->key = key; 89 | backet->next = hash->index[index]; 90 | hash->index[index] = backet; 91 | hash->count++; 92 | return backet->data; 93 | } 94 | return NULL; 95 | } 96 | 97 | /* Hash lookup. */ 98 | void * 99 | hash_lookup (struct hash *hash, void *data) 100 | { 101 | return hash_get (hash, data, NULL); 102 | } 103 | 104 | /* This function release registered value from specified hash. When 105 | release is successfully finished, return the data pointer in the 106 | hash backet. */ 107 | void * 108 | hash_release (struct hash *hash, void *data) 109 | { 110 | void *ret; 111 | unsigned int key; 112 | unsigned int index; 113 | struct hash_backet *backet; 114 | struct hash_backet *pp; 115 | 116 | key = (*hash->hash_key) (data); 117 | index = key % hash->size; 118 | 119 | for (backet = pp = hash->index[index]; backet; backet = backet->next) 120 | { 121 | if (backet->key == key && (*hash->hash_cmp) (backet->data, data)) 122 | { 123 | if (backet == pp) 124 | hash->index[index] = backet->next; 125 | else 126 | pp->next = backet->next; 127 | 128 | ret = backet->data; 129 | XFREE (MTYPE_HASH_BACKET, backet); 130 | hash->count--; 131 | return ret; 132 | } 133 | pp = backet; 134 | } 135 | return NULL; 136 | } 137 | 138 | /* Iterator function for hash. */ 139 | void 140 | hash_iterate (struct hash *hash, 141 | void (*func) (struct hash_backet *, void *), void *arg) 142 | { 143 | int i; 144 | struct hash_backet *hb; 145 | 146 | for (i = 0; i < hash->size; i++) 147 | for (hb = hash->index[i]; hb; hb = hb->next) 148 | (*func) (hb, arg); 149 | } 150 | 151 | /* Clean up hash. */ 152 | void 153 | hash_clean (struct hash *hash, void (*free_func) (void *)) 154 | { 155 | int i; 156 | struct hash_backet *hb; 157 | struct hash_backet *next; 158 | 159 | for (i = 0; i < hash->size; i++) 160 | { 161 | for (hb = hash->index[i]; hb; hb = next) 162 | { 163 | next = hb->next; 164 | 165 | if (free_func) 166 | (*free_func) (hb->data); 167 | 168 | XFREE (MTYPE_HASH_BACKET, hb); 169 | hash->count--; 170 | } 171 | hash->index[i] = NULL; 172 | } 173 | } 174 | 175 | /* Free hash memory. You may call hash_clean before call this 176 | function. */ 177 | void 178 | hash_free (struct hash *hash) 179 | { 180 | XFREE (MTYPE_HASH_INDEX, hash->index); 181 | XFREE (MTYPE_HASH, hash); 182 | } 183 | -------------------------------------------------------------------------------- /lib/hash.h: -------------------------------------------------------------------------------- 1 | /* Hash routine. 2 | Copyright (C) 1998 Kunihiro Ishiguro 3 | 4 | This file is part of GNU Zebra. 5 | 6 | GNU Zebra is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published 8 | by the Free Software Foundation; either version 2, or (at your 9 | option) any later version. 10 | 11 | GNU Zebra is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with GNU Zebra; see the file COPYING. If not, write to the 18 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | Boston, MA 02111-1307, USA. */ 20 | 21 | #ifndef _ZEBRA_HASH_H 22 | #define _ZEBRA_HASH_H 23 | 24 | /* Default hash table size. */ 25 | #define HASHTABSIZE 1024 26 | 27 | struct hash_backet 28 | { 29 | /* Linked list. */ 30 | struct hash_backet *next; 31 | 32 | /* Hash key. */ 33 | unsigned int key; 34 | 35 | /* Data. */ 36 | void *data; 37 | }; 38 | 39 | struct hash 40 | { 41 | /* Hash backet. */ 42 | struct hash_backet **index; 43 | 44 | /* Hash table size. */ 45 | unsigned int size; 46 | 47 | /* Key make function. */ 48 | unsigned int (*hash_key) (); 49 | 50 | /* Data compare function. */ 51 | int (*hash_cmp) (); 52 | 53 | /* Backet alloc. */ 54 | unsigned long count; 55 | }; 56 | 57 | struct hash *hash_create (unsigned int (*) (), int (*) ()); 58 | struct hash *hash_create_size (unsigned int, unsigned int (*) (), int (*) ()); 59 | 60 | void *hash_get (struct hash *, void *, void * (*) ()); 61 | void *hash_alloc_intern (void *); 62 | void *hash_lookup (struct hash *, void *); 63 | void *hash_release (struct hash *, void *); 64 | 65 | void hash_iterate (struct hash *, 66 | void (*) (struct hash_backet *, void *), void *); 67 | 68 | void hash_clean (struct hash *, void (*) (void *)); 69 | void hash_free (struct hash *); 70 | 71 | #endif /* _ZEBRA_HASH_H */ 72 | -------------------------------------------------------------------------------- /lib/if.h: -------------------------------------------------------------------------------- 1 | /* Interface related header. 2 | Copyright (C) 1997, 98, 99 Kunihiro Ishiguro 3 | 4 | This file is part of GNU Zebra. 5 | 6 | GNU Zebra is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published 8 | by the Free Software Foundation; either version 2, or (at your 9 | option) any later version. 10 | 11 | GNU Zebra is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with GNU Zebra; see the file COPYING. If not, write to the 18 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | Boston, MA 02111-1307, USA. */ 20 | 21 | #ifndef _ZEBRA_IF_H 22 | #define _ZEBRA_IF_H 23 | 24 | #include "linklist.h" 25 | 26 | /* 27 | Interface name length. 28 | 29 | Linux define value in /usr/include/linux/if.h. 30 | #define IFNAMSIZ 16 31 | 32 | FreeBSD define value in /usr/include/net/if.h. 33 | #define IFNAMSIZ 16 34 | */ 35 | 36 | #define INTERFACE_NAMSIZ 20 37 | #define INTERFACE_HWADDR_MAX 20 38 | 39 | /* Internal If indexes start at 0xFFFFFFFF and go down to 1 greater 40 | than this */ 41 | #define IFINDEX_INTERNBASE 0x80000000 42 | 43 | #ifdef HAVE_PROC_NET_DEV 44 | struct if_stats 45 | { 46 | unsigned long rx_packets; /* total packets received */ 47 | unsigned long tx_packets; /* total packets transmitted */ 48 | unsigned long rx_bytes; /* total bytes received */ 49 | unsigned long tx_bytes; /* total bytes transmitted */ 50 | unsigned long rx_errors; /* bad packets received */ 51 | unsigned long tx_errors; /* packet transmit problems */ 52 | unsigned long rx_dropped; /* no space in linux buffers */ 53 | unsigned long tx_dropped; /* no space available in linux */ 54 | unsigned long rx_multicast; /* multicast packets received */ 55 | unsigned long rx_compressed; 56 | unsigned long tx_compressed; 57 | unsigned long collisions; 58 | 59 | /* detailed rx_errors: */ 60 | unsigned long rx_length_errors; 61 | unsigned long rx_over_errors; /* receiver ring buff overflow */ 62 | unsigned long rx_crc_errors; /* recved pkt with crc error */ 63 | unsigned long rx_frame_errors; /* recv'd frame alignment error */ 64 | unsigned long rx_fifo_errors; /* recv'r fifo overrun */ 65 | unsigned long rx_missed_errors; /* receiver missed packet */ 66 | /* detailed tx_errors */ 67 | unsigned long tx_aborted_errors; 68 | unsigned long tx_carrier_errors; 69 | unsigned long tx_fifo_errors; 70 | unsigned long tx_heartbeat_errors; 71 | unsigned long tx_window_errors; 72 | }; 73 | #endif /* HAVE_PROC_NET_DEV */ 74 | 75 | /* Interface structure */ 76 | struct interface 77 | { 78 | /* Interface name. */ 79 | char name[INTERFACE_NAMSIZ + 1]; 80 | 81 | /* Interface index. */ 82 | unsigned int ifindex; 83 | 84 | /* Zebra internal interface status */ 85 | u_char status; 86 | #define ZEBRA_INTERFACE_ACTIVE (1 << 0) 87 | #define ZEBRA_INTERFACE_SUB (1 << 1) 88 | 89 | /* Interface flags. */ 90 | unsigned long flags; 91 | 92 | /* Interface metric */ 93 | int metric; 94 | 95 | /* Interface MTU. */ 96 | int mtu; 97 | 98 | /* Hardware address. */ 99 | #ifdef HAVE_SOCKADDR_DL 100 | struct sockaddr_dl sdl; 101 | #else 102 | unsigned short hw_type; 103 | u_char hw_addr[INTERFACE_HWADDR_MAX]; 104 | int hw_addr_len; 105 | #endif /* HAVE_SOCKADDR_DL */ 106 | 107 | /* interface bandwidth, kbits */ 108 | unsigned int bandwidth; 109 | 110 | /* description of the interface. */ 111 | char *desc; 112 | 113 | /* Distribute list. */ 114 | void *distribute_in; 115 | void *distribute_out; 116 | 117 | /* Connected address list. */ 118 | list connected; 119 | 120 | /* Daemon specific interface data pointer. */ 121 | void *info; 122 | 123 | /* Statistics fileds. */ 124 | #ifdef HAVE_PROC_NET_DEV 125 | struct if_stats stats; 126 | #endif /* HAVE_PROC_NET_DEV */ 127 | #ifdef HAVE_NET_RT_IFLIST 128 | struct if_data stats; 129 | #endif /* HAVE_NET_RT_IFLIST */ 130 | }; 131 | 132 | /* Connected address structure. */ 133 | struct connected 134 | { 135 | /* Attached interface. */ 136 | struct interface *ifp; 137 | 138 | /* Flags for configuration. */ 139 | u_char conf; 140 | #define ZEBRA_IFC_REAL (1 << 0) 141 | #define ZEBRA_IFC_CONFIGURED (1 << 1) 142 | 143 | /* Flags for connected address. */ 144 | u_char flags; 145 | #define ZEBRA_IFA_SECONDARY (1 << 0) 146 | 147 | /* Address of connected network. */ 148 | struct prefix *address; 149 | struct prefix *destination; 150 | 151 | /* Label for Linux 2.2.X and upper. */ 152 | char *label; 153 | }; 154 | 155 | /* Interface hook sort. */ 156 | #define IF_NEW_HOOK 0 157 | #define IF_DELETE_HOOK 1 158 | 159 | /* There are some interface flags which are only supported by some 160 | operating system. */ 161 | 162 | #ifndef IFF_NOTRAILERS 163 | #define IFF_NOTRAILERS 0x0 164 | #endif /* IFF_NOTRAILERS */ 165 | #ifndef IFF_OACTIVE 166 | #define IFF_OACTIVE 0x0 167 | #endif /* IFF_OACTIVE */ 168 | #ifndef IFF_SIMPLEX 169 | #define IFF_SIMPLEX 0x0 170 | #endif /* IFF_SIMPLEX */ 171 | #ifndef IFF_LINK0 172 | #define IFF_LINK0 0x0 173 | #endif /* IFF_LINK0 */ 174 | #ifndef IFF_LINK1 175 | #define IFF_LINK1 0x0 176 | #endif /* IFF_LINK1 */ 177 | #ifndef IFF_LINK2 178 | #define IFF_LINK2 0x0 179 | #endif /* IFF_LINK2 */ 180 | 181 | /* Prototypes. */ 182 | struct interface *if_new (void); 183 | struct interface *if_create (void); 184 | struct interface *if_lookup_by_index (unsigned int); 185 | struct interface *if_lookup_by_name (char *); 186 | struct interface *if_lookup_exact_address (struct in_addr); 187 | struct interface *if_lookup_address (struct in_addr); 188 | struct interface *if_get_by_name (char *); 189 | void if_delete (struct interface *); 190 | int if_is_up (struct interface *); 191 | int if_is_loopback (struct interface *); 192 | int if_is_broadcast (struct interface *); 193 | int if_is_pointopoint (struct interface *); 194 | int if_is_multicast (struct interface *); 195 | void if_add_hook (int, int (*)(struct interface *)); 196 | void if_init (); 197 | void if_dump_all (); 198 | char *ifindex2ifname (unsigned int); 199 | 200 | /* Connected address functions. */ 201 | struct connected *connected_new (); 202 | void connected_free (struct connected *); 203 | void connected_add (struct interface *, struct connected *); 204 | struct connected *connected_delete_by_prefix (struct interface *, struct prefix *); 205 | int ifc_pointopoint (struct connected *); 206 | 207 | #ifndef HAVE_IF_NAMETOINDEX 208 | unsigned int if_nametoindex (const char *); 209 | #endif 210 | #ifndef HAVE_IF_INDEXTONAME 211 | char *if_indextoname (unsigned int, char *); 212 | #endif 213 | 214 | /* Exported variables. */ 215 | extern list iflist; 216 | extern struct cmd_element interface_desc_cmd; 217 | extern struct cmd_element no_interface_desc_cmd; 218 | extern struct cmd_element interface_cmd; 219 | extern struct cmd_element interface_pseudo_cmd; 220 | extern struct cmd_element no_interface_pseudo_cmd; 221 | 222 | #endif /* _ZEBRA_IF_H */ 223 | -------------------------------------------------------------------------------- /lib/keychain.h: -------------------------------------------------------------------------------- 1 | /* key-chain for authentication. 2 | * Copyright (C) 2000 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; either version 2, or (at your 9 | * option) any later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #ifndef _ZEBRA_KEYCHAIN_H 23 | #define _ZEBRA_KEYCHAIN_H 24 | 25 | struct keychain 26 | { 27 | char *name; 28 | 29 | struct list *key; 30 | }; 31 | 32 | struct key_range 33 | { 34 | time_t start; 35 | time_t end; 36 | 37 | u_char duration; 38 | }; 39 | 40 | struct key 41 | { 42 | u_int32_t index; 43 | 44 | char *string; 45 | 46 | struct key_range send; 47 | struct key_range accept; 48 | }; 49 | 50 | void keychain_init (); 51 | struct keychain *keychain_lookup (char *); 52 | struct key *key_lookup_for_accept (struct keychain *, u_int32_t); 53 | struct key *key_match_for_accept (struct keychain *, char *); 54 | struct key *key_lookup_for_send (struct keychain *); 55 | 56 | #endif /* _ZEBRA_KEYCHAIN_H */ 57 | -------------------------------------------------------------------------------- /lib/linklist.c: -------------------------------------------------------------------------------- 1 | /* Generic linked list routine. 2 | * Copyright (C) 1997, 2000 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #include 23 | 24 | #include "linklist.h" 25 | #include "memory.h" 26 | 27 | /* Allocate new list. */ 28 | struct list * 29 | list_new () 30 | { 31 | struct list *new; 32 | 33 | new = XMALLOC (MTYPE_LINK_LIST, sizeof (struct list)); 34 | memset (new, 0, sizeof (struct list)); 35 | return new; 36 | } 37 | 38 | /* Free list. */ 39 | void 40 | list_free (struct list *l) 41 | { 42 | XFREE (MTYPE_LINK_LIST, l); 43 | } 44 | 45 | /* Allocate new listnode. Internal use only. */ 46 | static struct listnode * 47 | listnode_new () 48 | { 49 | struct listnode *node; 50 | 51 | node = XMALLOC (MTYPE_LINK_NODE, sizeof (struct listnode)); 52 | memset (node, 0, sizeof (struct listnode)); 53 | return node; 54 | } 55 | 56 | /* Free listnode. */ 57 | static void 58 | listnode_free (struct listnode *node) 59 | { 60 | XFREE (MTYPE_LINK_NODE, node); 61 | } 62 | 63 | /* Add new data to the list. */ 64 | void 65 | listnode_add (struct list *list, void *val) 66 | { 67 | struct listnode *node; 68 | 69 | node = listnode_new (); 70 | 71 | node->prev = list->tail; 72 | node->data = val; 73 | 74 | if (list->head == NULL) 75 | list->head = node; 76 | else 77 | list->tail->next = node; 78 | list->tail = node; 79 | 80 | list->count++; 81 | } 82 | 83 | /* Add new node with sort function. */ 84 | void 85 | listnode_add_sort (struct list *list, void *val) 86 | { 87 | struct listnode *n; 88 | struct listnode *new; 89 | 90 | new = listnode_new (); 91 | new->data = val; 92 | 93 | if (list->cmp) 94 | { 95 | for (n = list->head; n; n = n->next) 96 | { 97 | if ((*list->cmp) (val, n->data) < 0) 98 | { 99 | new->next = n; 100 | new->prev = n->prev; 101 | 102 | if (n->prev) 103 | n->prev->next = new; 104 | else 105 | list->head = new; 106 | n->prev = new; 107 | list->count++; 108 | return; 109 | } 110 | } 111 | } 112 | 113 | new->prev = list->tail; 114 | 115 | if (list->tail) 116 | list->tail->next = new; 117 | else 118 | list->head = new; 119 | 120 | list->tail = new; 121 | list->count++; 122 | } 123 | 124 | void 125 | listnode_add_after (struct list *list, struct listnode *pp, void *val) 126 | { 127 | struct listnode *nn; 128 | 129 | nn = listnode_new (); 130 | nn->data = val; 131 | 132 | if (pp == NULL) 133 | { 134 | if (list->head) 135 | list->head->prev = nn; 136 | else 137 | list->tail = nn; 138 | 139 | nn->next = list->head; 140 | nn->prev = pp; 141 | 142 | list->head = nn; 143 | } 144 | else 145 | { 146 | if (pp->next) 147 | pp->next->prev = nn; 148 | else 149 | list->tail = nn; 150 | 151 | nn->next = pp->next; 152 | nn->prev = pp; 153 | 154 | pp->next = nn; 155 | } 156 | } 157 | 158 | 159 | /* Delete specific date pointer from the list. */ 160 | void 161 | listnode_delete (struct list *list, void *val) 162 | { 163 | struct listnode *node; 164 | 165 | for (node = list->head; node; node = node->next) 166 | { 167 | if (node->data == val) 168 | { 169 | if (node->prev) 170 | node->prev->next = node->next; 171 | else 172 | list->head = node->next; 173 | 174 | if (node->next) 175 | node->next->prev = node->prev; 176 | else 177 | list->tail = node->prev; 178 | 179 | list->count--; 180 | listnode_free (node); 181 | return; 182 | } 183 | } 184 | } 185 | 186 | /* Return first node's data if it is there. */ 187 | void * 188 | listnode_head (struct list *list) 189 | { 190 | struct listnode *node; 191 | 192 | node = list->head; 193 | 194 | if (node) 195 | return node->data; 196 | return NULL; 197 | } 198 | 199 | /* Delete all listnode from the list. */ 200 | void 201 | list_delete_all_node (struct list *list) 202 | { 203 | struct listnode *node; 204 | struct listnode *next; 205 | 206 | for (node = list->head; node; node = next) 207 | { 208 | next = node->next; 209 | if (list->del) 210 | (*list->del) (node->data); 211 | listnode_free (node); 212 | } 213 | list->head = list->tail = NULL; 214 | list->count = 0; 215 | } 216 | 217 | /* Delete all listnode then free list itself. */ 218 | void 219 | list_delete (struct list *list) 220 | { 221 | struct listnode *node; 222 | struct listnode *next; 223 | 224 | for (node = list->head; node; node = next) 225 | { 226 | next = node->next; 227 | if (list->del) 228 | (*list->del) (node->data); 229 | listnode_free (node); 230 | } 231 | list_free (list); 232 | } 233 | 234 | /* Lookup the node which has given data. */ 235 | struct listnode * 236 | listnode_lookup (struct list *list, void *data) 237 | { 238 | listnode node; 239 | 240 | for (node = list->head; node; nextnode (node)) 241 | if (data == getdata (node)) 242 | return node; 243 | return NULL; 244 | } 245 | 246 | /* Delete the node from list. For ospfd and ospf6d. */ 247 | void 248 | list_delete_node (list list, listnode node) 249 | { 250 | if (node->prev) 251 | node->prev->next = node->next; 252 | else 253 | list->head = node->next; 254 | if (node->next) 255 | node->next->prev = node->prev; 256 | else 257 | list->tail = node->prev; 258 | list->count--; 259 | listnode_free (node); 260 | } 261 | 262 | /* ospf_spf.c */ 263 | void 264 | list_add_node_prev (list list, listnode current, void *val) 265 | { 266 | struct listnode *node; 267 | 268 | node = listnode_new (); 269 | node->next = current; 270 | node->data = val; 271 | 272 | if (current->prev == NULL) 273 | list->head = node; 274 | else 275 | current->prev->next = node; 276 | 277 | node->prev = current->prev; 278 | current->prev = node; 279 | 280 | list->count++; 281 | } 282 | 283 | /* ospf_spf.c */ 284 | void 285 | list_add_node_next (list list, listnode current, void *val) 286 | { 287 | struct listnode *node; 288 | 289 | node = listnode_new (); 290 | node->prev = current; 291 | node->data = val; 292 | 293 | if (current->next == NULL) 294 | list->tail = node; 295 | else 296 | current->next->prev = node; 297 | 298 | node->next = current->next; 299 | current->next = node; 300 | 301 | list->count++; 302 | } 303 | 304 | /* ospf_spf.c */ 305 | void 306 | list_add_list (struct list *l, struct list *m) 307 | { 308 | struct listnode *n; 309 | 310 | for (n = listhead (m); n; nextnode (n)) 311 | listnode_add (l, n->data); 312 | } 313 | -------------------------------------------------------------------------------- /lib/linklist.h: -------------------------------------------------------------------------------- 1 | /* Generic linked list 2 | * Copyright (C) 1997, 2000 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #ifndef _ZEBRA_LINKLIST_H 23 | #define _ZEBRA_LINKLIST_H 24 | 25 | typedef struct list *list; 26 | typedef struct listnode *listnode; 27 | 28 | struct listnode 29 | { 30 | struct listnode *next; 31 | struct listnode *prev; 32 | void *data; 33 | }; 34 | 35 | struct list 36 | { 37 | struct listnode *head; 38 | struct listnode *tail; 39 | unsigned int count; 40 | int (*cmp) (void *val1, void *val2); 41 | void (*del) (void *val); 42 | }; 43 | 44 | #define nextnode(X) ((X) = (X)->next) 45 | #define listhead(X) ((X)->head) 46 | #define listcount(X) ((X)->count) 47 | #define list_isempty(X) ((X)->head == NULL && (X)->tail == NULL) 48 | #define getdata(X) ((X)->data) 49 | 50 | /* Prototypes. */ 51 | struct list *list_new(); 52 | void list_free (struct list *); 53 | 54 | void listnode_add (struct list *, void *); 55 | void listnode_add_sort (struct list *, void *); 56 | void listnode_add_after (struct list *, struct listnode *, void *); 57 | void listnode_delete (struct list *, void *); 58 | struct listnode *listnode_lookup (struct list *, void *); 59 | void *listnode_head (struct list *); 60 | 61 | void list_delete (struct list *); 62 | void list_delete_all_node (struct list *); 63 | 64 | /* For ospfd and ospf6d. */ 65 | void list_delete_node (list, listnode); 66 | 67 | /* For ospf_spf.c */ 68 | void list_add_node_prev (list, listnode, void *); 69 | void list_add_node_next (list, listnode, void *); 70 | void list_add_list (list, list); 71 | 72 | /* List iteration macro. */ 73 | #define LIST_LOOP(L,V,N) \ 74 | for ((N) = (L)->head; (N); (N) = (N)->next) \ 75 | if (((V) = (N)->data) != NULL) 76 | 77 | /* List node add macro. */ 78 | #define LISTNODE_ADD(L,N) \ 79 | do { \ 80 | (N)->prev = (L)->tail; \ 81 | if ((L)->head == NULL) \ 82 | (L)->head = (N); \ 83 | else \ 84 | (L)->tail->next = (N); \ 85 | (L)->tail = (N); \ 86 | } while (0) 87 | 88 | /* List node delete macro. */ 89 | #define LISTNODE_DELETE(L,N) \ 90 | do { \ 91 | if ((N)->prev) \ 92 | (N)->prev->next = (N)->next; \ 93 | else \ 94 | (L)->head = (N)->next; \ 95 | if ((N)->next) \ 96 | (N)->next->prev = (N)->prev; \ 97 | else \ 98 | (L)->tail = (N)->prev; \ 99 | } while (0) 100 | 101 | #endif /* _ZEBRA_LINKLIST_H */ 102 | -------------------------------------------------------------------------------- /lib/log.h: -------------------------------------------------------------------------------- 1 | /* Zebra logging funcions. 2 | * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #ifndef _ZEBRA_LOG_H 23 | #define _ZEBRA_LOG_H 24 | 25 | #include 26 | 27 | #define ZLOG_NOLOG 0x00 28 | #define ZLOG_FILE 0x01 29 | #define ZLOG_SYSLOG 0x02 30 | #define ZLOG_STDOUT 0x04 31 | #define ZLOG_STDERR 0x08 32 | 33 | #define ZLOG_NOLOG_INDEX 0 34 | #define ZLOG_FILE_INDEX 1 35 | #define ZLOG_SYSLOG_INDEX 2 36 | #define ZLOG_STDOUT_INDEX 3 37 | #define ZLOG_STDERR_INDEX 4 38 | #define ZLOG_MAX_INDEX 5 39 | 40 | typedef enum 41 | { 42 | ZLOG_NONE, 43 | ZLOG_DEFAULT, 44 | ZLOG_ZEBRA, 45 | ZLOG_RIP, 46 | ZLOG_BGP, 47 | ZLOG_OSPF, 48 | ZLOG_RIPNG, 49 | ZLOG_OSPF6, 50 | ZLOG_MASC 51 | } zlog_proto_t; 52 | 53 | struct zlog 54 | { 55 | const char *ident; 56 | zlog_proto_t protocol; 57 | int flags; 58 | FILE *fp; 59 | char *filename; 60 | int syslog; 61 | int stat; 62 | int connected; 63 | int maskpri; /* as per syslog setlogmask */ 64 | int priority; /* as per syslog priority */ 65 | int facility; /* as per syslog facility */ 66 | int record_priority; 67 | }; 68 | 69 | /* Message structure. */ 70 | struct message 71 | { 72 | int key; 73 | char *str; 74 | }; 75 | 76 | /* Default logging strucutre. */ 77 | extern struct zlog *zlog_default; 78 | 79 | /* Open zlog function */ 80 | struct zlog *openzlog (const char *, int, zlog_proto_t, int, int); 81 | 82 | /* Close zlog function. */ 83 | void closezlog (struct zlog *zl); 84 | 85 | /* GCC have printf type attribute check. */ 86 | #ifdef __GNUC__ 87 | #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) 88 | #else 89 | #define PRINTF_ATTRIBUTE(a,b) 90 | #endif /* __GNUC__ */ 91 | 92 | /* Generic function for zlog. */ 93 | void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); 94 | 95 | /* Handy zlog functions. */ 96 | void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); 97 | void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); 98 | void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); 99 | void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); 100 | void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); 101 | 102 | /* For bgpd's peer oriented log. */ 103 | void plog_err (struct zlog *, const char *format, ...); 104 | void plog_warn (struct zlog *, const char *format, ...); 105 | void plog_info (struct zlog *, const char *format, ...); 106 | void plog_notice (struct zlog *, const char *format, ...); 107 | void plog_debug (struct zlog *, const char *format, ...); 108 | 109 | /* Set zlog flags. */ 110 | void zlog_set_flag (struct zlog *zl, int flags); 111 | void zlog_reset_flag (struct zlog *zl, int flags); 112 | 113 | /* Set zlog filename. */ 114 | int zlog_set_file (struct zlog *zl, int flags, char *filename); 115 | int zlog_reset_file (struct zlog *zl); 116 | 117 | /* Rotate log. */ 118 | int zlog_rotate (); 119 | 120 | /* For hackey massage lookup and check */ 121 | #define LOOKUP(x, y) mes_lookup(x, x ## _max, y) 122 | 123 | char *lookup (struct message *, int); 124 | char *mes_lookup (struct message *meslist, int max, int index); 125 | 126 | extern const char *zlog_priority[]; 127 | 128 | #endif /* _ZEBRA_LOG_H */ 129 | -------------------------------------------------------------------------------- /lib/md5-gnu.h: -------------------------------------------------------------------------------- 1 | /* Declaration of functions and data types used for MD5 sum computing 2 | library functions. 3 | Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. 4 | This file is part of the GNU C Library. 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Library General Public License as 8 | published by the Free Software Foundation; either version 2 of the 9 | License, or (at your option) any later version. 10 | 11 | The GNU C Library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Library General Public License for more details. 15 | 16 | You should have received a copy of the GNU Library General Public 17 | License along with the GNU C Library; see the file COPYING.LIB. If not, 18 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | Boston, MA 02111-1307, USA. */ 20 | 21 | #ifndef _MD5_H 22 | #define _MD5_H 1 23 | 24 | #include 25 | 26 | #if defined HAVE_LIMITS_H || _LIBC 27 | # include 28 | #endif 29 | 30 | /* The following contortions are an attempt to use the C preprocessor 31 | to determine an unsigned integral type that is 32 bits wide. An 32 | alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but 33 | doing that would require that the configure script compile and *run* 34 | the resulting executable. Locally running cross-compiled executables 35 | is usually not possible. */ 36 | 37 | #ifdef _LIBC 38 | # include 39 | typedef u_int32_t md5_uint32; 40 | #else 41 | # if defined __STDC__ && __STDC__ 42 | # define UINT_MAX_32_BITS 4294967295U 43 | # else 44 | # define UINT_MAX_32_BITS 0xFFFFFFFF 45 | # endif 46 | 47 | /* If UINT_MAX isn't defined, assume it's a 32-bit type. 48 | This should be valid for all systems GNU cares about because 49 | that doesn't include 16-bit systems, and only modern systems 50 | (that certainly have ) have 64+-bit integral types. */ 51 | 52 | # ifndef UINT_MAX 53 | # define UINT_MAX UINT_MAX_32_BITS 54 | # endif 55 | 56 | # if UINT_MAX == UINT_MAX_32_BITS 57 | typedef unsigned int md5_uint32; 58 | # else 59 | # if USHRT_MAX == UINT_MAX_32_BITS 60 | typedef unsigned short md5_uint32; 61 | # else 62 | # if ULONG_MAX == UINT_MAX_32_BITS 63 | typedef unsigned long md5_uint32; 64 | # else 65 | /* The following line is intended to evoke an error. 66 | Using #error is not portable enough. */ 67 | "Cannot determine unsigned 32-bit data type." 68 | # endif 69 | # endif 70 | # endif 71 | #endif 72 | 73 | #undef __P 74 | #if defined (__STDC__) && __STDC__ 75 | # define __P(x) x 76 | #else 77 | # define __P(x) () 78 | #endif 79 | 80 | /* Structure to save state of computation between the single steps. */ 81 | struct md5_ctx 82 | { 83 | md5_uint32 A; 84 | md5_uint32 B; 85 | md5_uint32 C; 86 | md5_uint32 D; 87 | 88 | md5_uint32 total[2]; 89 | md5_uint32 buflen; 90 | char buffer[128]; 91 | }; 92 | 93 | /* 94 | * The following three functions are build up the low level used in 95 | * the functions `md5_stream' and `md5_buffer'. 96 | */ 97 | 98 | /* Initialize structure containing state of computation. 99 | (RFC 1321, 3.3: Step 3) */ 100 | extern void __md5_init_ctx __P ((struct md5_ctx *ctx)); 101 | extern void md5_init_ctx __P ((struct md5_ctx *ctx)); 102 | 103 | /* Starting with the result of former calls of this function (or the 104 | initialization function update the context for the next LEN bytes 105 | starting at BUFFER. 106 | It is necessary that LEN is a multiple of 64!!! */ 107 | extern void __md5_process_block __P ((const void *buffer, size_t len, 108 | struct md5_ctx *ctx)); 109 | extern void md5_process_block __P ((const void *buffer, size_t len, 110 | struct md5_ctx *ctx)); 111 | 112 | /* Starting with the result of former calls of this function (or the 113 | initialization function update the context for the next LEN bytes 114 | starting at BUFFER. 115 | It is NOT required that LEN is a multiple of 64. */ 116 | extern void __md5_process_bytes __P ((const void *buffer, size_t len, 117 | struct md5_ctx *ctx)); 118 | extern void md5_process_bytes __P ((const void *buffer, size_t len, 119 | struct md5_ctx *ctx)); 120 | 121 | /* Process the remaining bytes in the buffer and put result from CTX 122 | in first 16 bytes following RESBUF. The result is always in little 123 | endian byte order, so that a byte-wise output yields to the wanted 124 | ASCII representation of the message digest. 125 | 126 | IMPORTANT: On some systems it is required that RESBUF is correctly 127 | aligned for a 32 bits value. */ 128 | extern void *__md5_finish_ctx __P ((struct md5_ctx *ctx, void *resbuf)); 129 | extern void *md5_finish_ctx __P ((struct md5_ctx *ctx, void *resbuf)); 130 | 131 | 132 | /* Put result from CTX in first 16 bytes following RESBUF. The result is 133 | always in little endian byte order, so that a byte-wise output yields 134 | to the wanted ASCII representation of the message digest. 135 | 136 | IMPORTANT: On some systems it is required that RESBUF is correctly 137 | aligned for a 32 bits value. */ 138 | extern void *__md5_read_ctx __P ((const struct md5_ctx *ctx, void *resbuf)); 139 | extern void *md5_read_ctx __P ((const struct md5_ctx *ctx, void *resbuf)); 140 | 141 | 142 | /* Compute MD5 message digest for bytes read from STREAM. The 143 | resulting message digest number will be written into the 16 bytes 144 | beginning at RESBLOCK. */ 145 | extern int __md5_stream __P ((FILE *stream, void *resblock)); 146 | 147 | /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The 148 | result is always in little endian byte order, so that a byte-wise 149 | output yields to the wanted ASCII representation of the message 150 | digest. */ 151 | extern void *__md5_buffer __P ((const char *buffer, size_t len, 152 | void *resblock)); 153 | extern void *md5_buffer __P ((const char *buffer, size_t len, 154 | void *resblock)); 155 | 156 | #endif /* md5.h */ 157 | -------------------------------------------------------------------------------- /lib/memory.h: -------------------------------------------------------------------------------- 1 | /* Memory management routine 2 | Copyright (C) 1998 Kunihiro Ishiguro 3 | 4 | This file is part of GNU Zebra. 5 | 6 | GNU Zebra is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the 8 | Free Software Foundation; either version 2, or (at your option) any 9 | later version. 10 | 11 | GNU Zebra is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | 02111-1307, USA. */ 20 | 21 | #ifndef _ZEBRA_MEMORY_H 22 | #define _ZEBRA_MEMORY_H 23 | 24 | /* #define MEMORY_LOG */ 25 | 26 | /* For tagging memory, below is the type of the memory. */ 27 | enum 28 | { 29 | MTYPE_TMP = 1, 30 | MTYPE_STRVEC, 31 | MTYPE_VECTOR, 32 | MTYPE_VECTOR_INDEX, 33 | MTYPE_LINK_LIST, 34 | MTYPE_LINK_NODE, 35 | MTYPE_THREAD, 36 | MTYPE_THREAD_MASTER, 37 | MTYPE_VTY, 38 | MTYPE_VTY_HIST, 39 | MTYPE_VTY_OUT_BUF, 40 | MTYPE_IF, 41 | MTYPE_IF_IRDP, 42 | MTYPE_CONNECTED, 43 | MTYPE_AS_SEG, 44 | MTYPE_AS_STR, 45 | MTYPE_AS_PATH, 46 | MTYPE_CLUSTER, 47 | MTYPE_CLUSTER_VAL, 48 | MTYPE_ATTR, 49 | MTYPE_TRANSIT, 50 | MTYPE_TRANSIT_VAL, 51 | MTYPE_BUFFER, 52 | MTYPE_BUFFER_DATA, 53 | MTYPE_STREAM, 54 | MTYPE_STREAM_DATA, 55 | MTYPE_STREAM_FIFO, 56 | MTYPE_PREFIX, 57 | MTYPE_PREFIX_IPV4, 58 | MTYPE_PREFIX_IPV6, 59 | MTYPE_HASH, 60 | MTYPE_HASH_INDEX, 61 | MTYPE_HASH_BACKET, 62 | MTYPE_RIPNG_ROUTE, 63 | MTYPE_RIPNG_AGGREGATE, 64 | MTYPE_ROUTE_TABLE, 65 | MTYPE_ROUTE_NODE, 66 | MTYPE_ACCESS_LIST, 67 | MTYPE_ACCESS_LIST_STR, 68 | MTYPE_ACCESS_FILTER, 69 | MTYPE_PREFIX_LIST, 70 | MTYPE_PREFIX_LIST_STR, 71 | MTYPE_PREFIX_LIST_ENTRY, 72 | MTYPE_ROUTE_MAP, 73 | MTYPE_ROUTE_MAP_NAME, 74 | MTYPE_ROUTE_MAP_INDEX, 75 | MTYPE_ROUTE_MAP_RULE, 76 | MTYPE_ROUTE_MAP_RULE_STR, 77 | MTYPE_ROUTE_MAP_COMPILED, 78 | 79 | MTYPE_RIB, 80 | MTYPE_DISTRIBUTE, 81 | MTYPE_ZLOG, 82 | MTYPE_ZCLIENT, 83 | MTYPE_NEXTHOP, 84 | MTYPE_RTADV_PREFIX, 85 | MTYPE_IF_RMAP, 86 | MTYPE_SOCKUNION, 87 | MTYPE_STATIC_IPV4, 88 | MTYPE_STATIC_IPV6, 89 | 90 | MTYPE_DESC, 91 | MTYPE_OSPF_TOP, 92 | MTYPE_OSPF_AREA, 93 | MTYPE_OSPF_AREA_RANGE, 94 | MTYPE_OSPF_NETWORK, 95 | MTYPE_OSPF_NEIGHBOR_STATIC, 96 | MTYPE_OSPF_IF, 97 | MTYPE_OSPF_NEIGHBOR, 98 | MTYPE_OSPF_ROUTE, 99 | MTYPE_OSPF_TMP, 100 | MTYPE_OSPF_LSA, 101 | MTYPE_OSPF_LSA_DATA, 102 | MTYPE_OSPF_LSDB, 103 | MTYPE_OSPF_PACKET, 104 | MTYPE_OSPF_FIFO, 105 | MTYPE_OSPF_VERTEX, 106 | MTYPE_OSPF_NEXTHOP, 107 | MTYPE_OSPF_PATH, 108 | MTYPE_OSPF_VL_DATA, 109 | MTYPE_OSPF_CRYPT_KEY, 110 | MTYPE_OSPF_EXTERNAL_INFO, 111 | MTYPE_OSPF_MESSAGE, 112 | MTYPE_OSPF_DISTANCE, 113 | MTYPE_OSPF_IF_INFO, 114 | MTYPE_OSPF_IF_PARAMS, 115 | 116 | MTYPE_OSPF6_TOP, 117 | MTYPE_OSPF6_AREA, 118 | MTYPE_OSPF6_IF, 119 | MTYPE_OSPF6_NEIGHBOR, 120 | MTYPE_OSPF6_ROUTE, 121 | MTYPE_OSPF6_PREFIX, 122 | MTYPE_OSPF6_MESSAGE, 123 | MTYPE_OSPF6_LSA, 124 | MTYPE_OSPF6_LSA_SUMMARY, 125 | MTYPE_OSPF6_LSDB, 126 | MTYPE_OSPF6_VERTEX, 127 | MTYPE_OSPF6_SPFTREE, 128 | MTYPE_OSPF6_NEXTHOP, 129 | MTYPE_OSPF6_EXTERNAL_INFO, 130 | MTYPE_OSPF6_OTHER, 131 | 132 | MTYPE_BGP, 133 | MTYPE_BGP_PEER, 134 | MTYPE_PEER_GROUP, 135 | MTYPE_PEER_DESC, 136 | MTYPE_PEER_UPDATE_SOURCE, 137 | MTYPE_BGP_STATIC, 138 | MTYPE_BGP_AGGREGATE, 139 | MTYPE_BGP_CONFED_LIST, 140 | MTYPE_BGP_NEXTHOP_CACHE, 141 | MTYPE_BGP_DAMP_INFO, 142 | MTYPE_BGP_DAMP_ARRAY, 143 | MTYPE_BGP_ANNOUNCE, 144 | MTYPE_BGP_ATTR_QUEUE, 145 | MTYPE_BGP_ROUTE_QUEUE, 146 | MTYPE_BGP_DISTANCE, 147 | MTYPE_BGP_ROUTE, 148 | MTYPE_BGP_TABLE, 149 | MTYPE_BGP_NODE, 150 | MTYPE_BGP_ADVERTISE_ATTR, 151 | MTYPE_BGP_ADVERTISE, 152 | MTYPE_BGP_ADJ_IN, 153 | MTYPE_BGP_ADJ_OUT, 154 | MTYPE_BGP_REGEXP, 155 | MTYPE_AS_FILTER, 156 | MTYPE_AS_FILTER_STR, 157 | MTYPE_AS_LIST, 158 | 159 | MTYPE_COMMUNITY, 160 | MTYPE_COMMUNITY_VAL, 161 | MTYPE_COMMUNITY_STR, 162 | 163 | MTYPE_ECOMMUNITY, 164 | MTYPE_ECOMMUNITY_VAL, 165 | MTYPE_ECOMMUNITY_STR, 166 | 167 | /* community-list and extcommunity-list. */ 168 | MTYPE_COMMUNITY_LIST_HANDLER, 169 | MTYPE_COMMUNITY_LIST, 170 | MTYPE_COMMUNITY_LIST_NAME, 171 | MTYPE_COMMUNITY_LIST_ENTRY, 172 | MTYPE_COMMUNITY_LIST_CONFIG, 173 | 174 | MTYPE_RIP, 175 | MTYPE_RIP_INTERFACE, 176 | MTYPE_RIP_DISTANCE, 177 | MTYPE_RIP_OFFSET_LIST, 178 | MTYPE_RIP_INFO, 179 | MTYPE_RIP_PEER, 180 | MTYPE_KEYCHAIN, 181 | MTYPE_KEY, 182 | 183 | MTYPE_VTYSH_CONFIG, 184 | MTYPE_VTYSH_CONFIG_LINE, 185 | 186 | MTYPE_VRF, 187 | MTYPE_VRF_NAME, 188 | 189 | MTYPE_MAX 190 | }; 191 | 192 | #ifdef MEMORY_LOG 193 | #define XMALLOC(mtype, size) \ 194 | mtype_zmalloc (__FILE__, __LINE__, (mtype), (size)) 195 | #define XCALLOC(mtype, size) \ 196 | mtype_zcalloc (__FILE__, __LINE__, (mtype), (size)) 197 | #define XREALLOC(mtype, ptr, size) \ 198 | mtype_zrealloc (__FILE__, __LINE__, (mtype), (ptr), (size)) 199 | #define XFREE(mtype, ptr) \ 200 | mtype_zfree (__FILE__, __LINE__, (mtype), (ptr)) 201 | #define XSTRDUP(mtype, str) \ 202 | mtype_zstrdup (__FILE__, __LINE__, (mtype), (str)) 203 | #else 204 | #define XMALLOC(mtype, size) zmalloc ((mtype), (size)) 205 | #define XCALLOC(mtype, size) zcalloc ((mtype), (size)) 206 | #define XREALLOC(mtype, ptr, size) zrealloc ((mtype), (ptr), (size)) 207 | #define XFREE(mtype, ptr) zfree ((mtype), (ptr)) 208 | #define XSTRDUP(mtype, str) zstrdup ((mtype), (str)) 209 | #endif /* MEMORY_LOG */ 210 | 211 | /* Prototypes of memory function. */ 212 | void *zmalloc (int type, size_t size); 213 | void *zcalloc (int type, size_t size); 214 | void *zrealloc (int type, void *ptr, size_t size); 215 | void zfree (int type, void *ptr); 216 | char *zstrdup (int type, char *str); 217 | 218 | void *mtype_zmalloc (const char *file, 219 | int line, 220 | int type, 221 | size_t size); 222 | 223 | void *mtype_zcalloc (const char *file, 224 | int line, 225 | int type, 226 | size_t num, 227 | size_t size); 228 | 229 | void *mtype_zrealloc (const char *file, 230 | int line, 231 | int type, 232 | void *ptr, 233 | size_t size); 234 | 235 | void mtype_zfree (const char *file, 236 | int line, 237 | int type, 238 | void *ptr); 239 | 240 | char *mtype_zstrdup (const char *file, 241 | int line, 242 | int type, 243 | char *str); 244 | void memory_init (); 245 | 246 | #endif /* _ZEBRA_MEMORY_H */ 247 | -------------------------------------------------------------------------------- /lib/network.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Network library. 3 | * Copyright (C) 1997 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the 9 | * Free Software Foundation; either version 2, or (at your option) any 10 | * later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20 | * 02111-1307, USA. 21 | */ 22 | 23 | #include 24 | 25 | /* Read nbytes from fd and store into ptr. */ 26 | int 27 | readn (int fd, char *ptr, int nbytes) 28 | { 29 | int nleft; 30 | int nread; 31 | 32 | nleft = nbytes; 33 | 34 | while (nleft > 0) 35 | { 36 | nread = read (fd, ptr, nleft); 37 | 38 | if (nread < 0) 39 | return (nread); 40 | else 41 | if (nread == 0) 42 | break; 43 | 44 | nleft -= nread; 45 | ptr += nread; 46 | } 47 | 48 | return nbytes - nleft; 49 | } 50 | 51 | /* Write nbytes from ptr to fd. */ 52 | int 53 | writen(int fd, char *ptr, int nbytes) 54 | { 55 | int nleft; 56 | int nwritten; 57 | 58 | nleft = nbytes; 59 | 60 | while (nleft > 0) 61 | { 62 | nwritten = write(fd, ptr, nleft); 63 | 64 | if (nwritten <= 0) 65 | return (nwritten); 66 | 67 | nleft -= nwritten; 68 | ptr += nwritten; 69 | } 70 | return nbytes - nleft; 71 | } 72 | -------------------------------------------------------------------------------- /lib/network.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Network library header. 3 | * Copyright (C) 1998 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the 9 | * Free Software Foundation; either version 2, or (at your option) any 10 | * later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20 | * 02111-1307, USA. 21 | */ 22 | 23 | #ifndef _ZEBRA_NETWORK_H 24 | #define _ZEBRA_NETWORK_H 25 | 26 | int readn (int, char *, int); 27 | int writen (int, char *, int); 28 | 29 | #endif /* _ZEBRA_NETWORK_H */ 30 | -------------------------------------------------------------------------------- /lib/pid_output.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Process id output. 3 | * Copyright (C) 1998, 1999 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the 9 | * Free Software Foundation; either version 2, or (at your option) any 10 | * later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20 | * 02111-1307, USA. 21 | */ 22 | 23 | #include 24 | 25 | pid_t 26 | pid_output (char *path) 27 | { 28 | FILE *fp; 29 | pid_t pid; 30 | 31 | pid = getpid(); 32 | 33 | fp = fopen (path, "w"); 34 | if (fp != NULL) 35 | { 36 | fprintf (fp, "%d\n", (int) pid); 37 | fclose (fp); 38 | return -1; 39 | } 40 | return pid; 41 | } 42 | 43 | pid_t 44 | pid_output_lock (char *path) 45 | { 46 | int tmp; 47 | int fd; 48 | pid_t pid; 49 | char buf[16], *p; 50 | 51 | pid = getpid (); 52 | 53 | fd = open (path, O_RDWR | O_CREAT | O_EXCL, 0644); 54 | if (fd < 0) 55 | { 56 | fd = open (path, O_RDONLY); 57 | if (fd < 0) 58 | fprintf (stderr, "Can't creat pid lock file, exit\n"); 59 | else 60 | { 61 | read (fd, buf, sizeof (buf)); 62 | if ((p = index (buf, '\n')) != NULL) 63 | *p = 0; 64 | fprintf (stderr, "Another process(%s) running, exit\n", buf); 65 | } 66 | exit (-1); 67 | } 68 | else 69 | { 70 | sprintf (buf, "%d\n", (int) pid); 71 | tmp = write (fd, buf, strlen (buf)); 72 | close (fd); 73 | } 74 | 75 | return pid; 76 | } 77 | 78 | -------------------------------------------------------------------------------- /lib/plist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Prefix list functions. 3 | * Copyright (C) 1999 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published 9 | * by the Free Software Foundation; either version 2, or (at your 10 | * option) any later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | #define AFI_ORF_PREFIX 65535 24 | 25 | enum prefix_list_type 26 | { 27 | PREFIX_DENY, 28 | PREFIX_PERMIT, 29 | }; 30 | 31 | enum prefix_name_type 32 | { 33 | PREFIX_TYPE_STRING, 34 | PREFIX_TYPE_NUMBER 35 | }; 36 | 37 | struct prefix_list 38 | { 39 | char *name; 40 | char *desc; 41 | 42 | struct prefix_master *master; 43 | 44 | enum prefix_name_type type; 45 | 46 | int count; 47 | int rangecount; 48 | 49 | struct prefix_list_entry *head; 50 | struct prefix_list_entry *tail; 51 | 52 | struct prefix_list *next; 53 | struct prefix_list *prev; 54 | }; 55 | 56 | struct orf_prefix 57 | { 58 | u_int32_t seq; 59 | u_char ge; 60 | u_char le; 61 | struct prefix p; 62 | }; 63 | 64 | /* Prototypes. */ 65 | void prefix_list_init (void); 66 | void prefix_list_reset (void); 67 | void prefix_list_add_hook (void (*func) (struct prefix_list *)); 68 | void prefix_list_delete_hook (void (*func) (struct prefix_list *)); 69 | 70 | struct prefix_list *prefix_list_lookup (afi_t, char *); 71 | enum prefix_list_type prefix_list_apply (struct prefix_list *, void *); 72 | 73 | struct stream * 74 | prefix_bgp_orf_entry (struct stream *, struct prefix_list *, 75 | u_char, u_char, u_char); 76 | int prefix_bgp_orf_set (char *, afi_t, struct orf_prefix *, int, int); 77 | void prefix_bgp_orf_remove_all (char *); 78 | int prefix_bgp_show_prefix_list (struct vty *, afi_t, char *); 79 | -------------------------------------------------------------------------------- /lib/pqueue.c: -------------------------------------------------------------------------------- 1 | /* Priority queue functions. 2 | Copyright (C) 2003 Yasuhiro Ohara 3 | 4 | This file is part of GNU Zebra. 5 | 6 | GNU Zebra is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published 8 | by the Free Software Foundation; either version 2, or (at your 9 | option) any later version. 10 | 11 | GNU Zebra is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with GNU Zebra; see the file COPYING. If not, write to the 18 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | Boston, MA 02111-1307, USA. */ 20 | 21 | #include 22 | 23 | #include "pqueue.h" 24 | 25 | /* priority queue using heap sort */ 26 | 27 | /* pqueue->cmp() controls the order of sorting (i.e, ascending or 28 | descending). If you want the left node to move upper of the heap 29 | binary tree, make cmp() to return less than 0. for example, if cmp 30 | (10, 20) returns -1, the sorting is ascending order. if cmp (10, 31 | 20) returns 1, the sorting is descending order. if cmp (10, 20) 32 | returns 0, this library does not do sorting (which will not be what 33 | you want). To be brief, if the contents of cmp_func (left, right) 34 | is left - right, dequeue () returns the smallest node. Otherwise 35 | (if the contents is right - left), dequeue () returns the largest 36 | node. */ 37 | 38 | #define DATA_SIZE (sizeof (void *)) 39 | #define PARENT_OF(x) ((x - 1) / 2) 40 | #define LEFT_OF(x) (2 * x + 1) 41 | #define RIGHT_OF(x) (2 * x + 2) 42 | #define HAVE_CHILD(x,q) (x < (q)->size / 2) 43 | 44 | static void 45 | trickle_up (int index, struct pqueue *queue) 46 | { 47 | void *tmp; 48 | 49 | /* Save current node as tmp node. */ 50 | tmp = queue->array[index]; 51 | 52 | /* Continue until the node reaches top or the place where the parent 53 | node should be upper than the tmp node. */ 54 | while (index > 0 && 55 | (*queue->cmp) (tmp, queue->array[PARENT_OF (index)]) < 0) 56 | { 57 | /* actually trickle up */ 58 | queue->array[index] = queue->array[PARENT_OF (index)]; 59 | index = PARENT_OF (index); 60 | } 61 | 62 | /* Restore the tmp node to appropriate place. */ 63 | queue->array[index] = tmp; 64 | } 65 | 66 | static void 67 | trickle_down (int index, struct pqueue *queue) 68 | { 69 | void *tmp; 70 | int which; 71 | 72 | /* Save current node as tmp node. */ 73 | tmp = queue->array[index]; 74 | 75 | /* Continue until the node have at least one (left) child. */ 76 | while (HAVE_CHILD (index, queue)) 77 | { 78 | /* If right child exists, and if the right child is more proper 79 | to be moved upper. */ 80 | if (RIGHT_OF (index) < queue->size && 81 | (*queue->cmp) (queue->array[LEFT_OF (index)], 82 | queue->array[RIGHT_OF (index)]) > 0) 83 | which = RIGHT_OF (index); 84 | else 85 | which = LEFT_OF (index); 86 | 87 | /* If the tmp node should be upper than the child, break. */ 88 | if ((*queue->cmp) (queue->array[which], tmp) > 0) 89 | break; 90 | 91 | /* Actually trickle down the tmp node. */ 92 | queue->array[index] = queue->array[which]; 93 | index = which; 94 | } 95 | 96 | /* Restore the tmp node to appropriate place. */ 97 | queue->array[index] = tmp; 98 | } 99 | 100 | struct pqueue * 101 | pqueue_create () 102 | { 103 | struct pqueue *queue; 104 | 105 | queue = (struct pqueue *) malloc (sizeof (struct pqueue)); 106 | memset (queue, 0, sizeof (struct pqueue)); 107 | 108 | queue->array = (void **) 109 | malloc (DATA_SIZE * PQUEUE_INIT_ARRAYSIZE); 110 | memset (queue->array, 0, DATA_SIZE * PQUEUE_INIT_ARRAYSIZE); 111 | queue->array_size = PQUEUE_INIT_ARRAYSIZE; 112 | 113 | return queue; 114 | } 115 | 116 | void 117 | pqueue_delete (struct pqueue *queue) 118 | { 119 | free (queue->array); 120 | free (queue); 121 | } 122 | 123 | static int 124 | pqueue_expand (struct pqueue *queue) 125 | { 126 | void **newarray; 127 | 128 | newarray = (void **) malloc (queue->array_size * DATA_SIZE * 2); 129 | if (newarray == NULL) 130 | return 0; 131 | 132 | memset (newarray, 0, queue->array_size * DATA_SIZE * 2); 133 | memcpy (newarray, queue->array, queue->array_size * DATA_SIZE); 134 | 135 | free (queue->array); 136 | queue->array = newarray; 137 | queue->array_size *= 2; 138 | 139 | return 1; 140 | } 141 | 142 | void 143 | pqueue_enqueue (void *data, struct pqueue *queue) 144 | { 145 | if (queue->size + 2 >= queue->array_size && ! pqueue_expand (queue)) 146 | return; 147 | 148 | queue->array[queue->size] = data; 149 | trickle_up (queue->size, queue); 150 | queue->size ++; 151 | } 152 | 153 | void * 154 | pqueue_dequeue (struct pqueue *queue) 155 | { 156 | void *data = queue->array[0]; 157 | queue->array[0] = queue->array[--queue->size]; 158 | trickle_down (0, queue); 159 | return data; 160 | } 161 | -------------------------------------------------------------------------------- /lib/pqueue.h: -------------------------------------------------------------------------------- 1 | /* Priority queue functions. 2 | Copyright (C) 2003 Yasuhiro Ohara 3 | 4 | This file is part of GNU Zebra. 5 | 6 | GNU Zebra is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published 8 | by the Free Software Foundation; either version 2, or (at your 9 | option) any later version. 10 | 11 | GNU Zebra is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with GNU Zebra; see the file COPYING. If not, write to the 18 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | Boston, MA 02111-1307, USA. */ 20 | 21 | #ifndef _ZEBRA_PQUEUE_H 22 | #define _ZEBRA_PQUEUE_H 23 | 24 | struct pqueue 25 | { 26 | void **array; 27 | int array_size; 28 | int size; 29 | 30 | int (*cmp) (void *, void *); 31 | }; 32 | 33 | #define PQUEUE_INIT_ARRAYSIZE 32 34 | 35 | struct pqueue *pqueue_create (); 36 | void pqueue_delete (struct pqueue *queue); 37 | 38 | void pqueue_enqueue (void *data, struct pqueue *queue); 39 | void *pqueue_dequeue (struct pqueue *queue); 40 | 41 | #endif /* _ZEBRA_PQUEUE_H */ 42 | -------------------------------------------------------------------------------- /lib/prefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Prefix structure. 3 | * Copyright (C) 1998 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the 9 | * Free Software Foundation; either version 2, or (at your option) any 10 | * later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20 | * 02111-1307, USA. 21 | */ 22 | 23 | #ifndef _ZEBRA_PREFIX_H 24 | #define _ZEBRA_PREFIX_H 25 | 26 | /* IPv4 and IPv6 unified prefix structure. */ 27 | struct prefix 28 | { 29 | u_char family; 30 | u_char prefixlen; 31 | union 32 | { 33 | u_char prefix; 34 | struct in_addr prefix4; 35 | #ifdef HAVE_IPV6 36 | struct in6_addr prefix6; 37 | #endif /* HAVE_IPV6 */ 38 | struct 39 | { 40 | struct in_addr id; 41 | struct in_addr adv_router; 42 | } lp; 43 | u_char val[8]; 44 | } u __attribute__ ((aligned (8))); 45 | }; 46 | 47 | /* IPv4 prefix structure. */ 48 | struct prefix_ipv4 49 | { 50 | u_char family; 51 | u_char prefixlen; 52 | struct in_addr prefix __attribute__ ((aligned (8))); 53 | }; 54 | 55 | /* IPv6 prefix structure. */ 56 | #ifdef HAVE_IPV6 57 | struct prefix_ipv6 58 | { 59 | u_char family; 60 | u_char prefixlen; 61 | struct in6_addr prefix __attribute__ ((aligned (8))); 62 | }; 63 | #endif /* HAVE_IPV6 */ 64 | 65 | struct prefix_ls 66 | { 67 | u_char family; 68 | u_char prefixlen; 69 | struct in_addr id __attribute__ ((aligned (8))); 70 | struct in_addr adv_router; 71 | }; 72 | 73 | /* Prefix for routing distinguisher. */ 74 | struct prefix_rd 75 | { 76 | u_char family; 77 | u_char prefixlen; 78 | u_char val[8] __attribute__ ((aligned (8))); 79 | }; 80 | 81 | #ifndef INET_ADDRSTRLEN 82 | #define INET_ADDRSTRLEN 16 83 | #endif /* INET_ADDRSTRLEN */ 84 | 85 | #ifndef INET6_ADDRSTRLEN 86 | #define INET6_ADDRSTRLEN 46 87 | #endif /* INET6_ADDRSTRLEN */ 88 | 89 | #ifndef INET6_BUFSIZ 90 | #define INET6_BUFSIZ 51 91 | #endif /* INET6_BUFSIZ */ 92 | 93 | /* Max bit/byte length of IPv4 address. */ 94 | #define IPV4_MAX_BYTELEN 4 95 | #define IPV4_MAX_BITLEN 32 96 | #define IPV4_MAX_PREFIXLEN 32 97 | #define IPV4_ADDR_CMP(D,S) memcmp ((D), (S), IPV4_MAX_BYTELEN) 98 | #define IPV4_ADDR_SAME(D,S) (memcmp ((D), (S), IPV4_MAX_BYTELEN) == 0) 99 | #define IPV4_ADDR_COPY(D,S) memcpy ((D), (S), IPV4_MAX_BYTELEN) 100 | 101 | #define IPV4_NET0(a) ((((u_int32_t) (a)) & 0xff000000) == 0x00000000) 102 | #define IPV4_NET127(a) ((((u_int32_t) (a)) & 0xff000000) == 0x7f000000) 103 | 104 | /* Max bit/byte length of IPv6 address. */ 105 | #define IPV6_MAX_BYTELEN 16 106 | #define IPV6_MAX_BITLEN 128 107 | #define IPV6_MAX_PREFIXLEN 128 108 | #define IPV6_ADDR_CMP(D,S) memcmp ((D), (S), IPV6_MAX_BYTELEN) 109 | #define IPV6_ADDR_SAME(D,S) (memcmp ((D), (S), IPV6_MAX_BYTELEN) == 0) 110 | #define IPV6_ADDR_COPY(D,S) memcpy ((D), (S), IPV6_MAX_BYTELEN) 111 | 112 | /* Count prefix size from mask length */ 113 | #define PSIZE(a) (((a) + 7) / (8)) 114 | 115 | /* Prefix's family member. */ 116 | #define PREFIX_FAMILY(p) ((p)->family) 117 | 118 | /* Prototypes. */ 119 | int afi2family (int); 120 | int family2afi (int); 121 | 122 | int prefix2str (struct prefix *, char *, int); 123 | int str2prefix (char *, struct prefix *); 124 | struct prefix *prefix_new (); 125 | void prefix_free (struct prefix *p); 126 | 127 | struct prefix_ipv4 *prefix_ipv4_new (); 128 | void prefix_ipv4_free (); 129 | int str2prefix_ipv4 (char *, struct prefix_ipv4 *); 130 | void apply_mask_ipv4 (struct prefix_ipv4 *); 131 | int prefix_blen (struct prefix *); 132 | u_char ip_masklen (struct in_addr); 133 | int prefix_ipv4_any (struct prefix_ipv4 *); 134 | void masklen2ip (int, struct in_addr *); 135 | void apply_classful_mask_ipv4 (struct prefix_ipv4 *); 136 | 137 | char *prefix_family_str (struct prefix *p); 138 | struct prefix *sockunion2prefix (); 139 | struct prefix *sockunion2hostprefix (); 140 | 141 | #ifdef HAVE_IPV6 142 | struct prefix_ipv6 *prefix_ipv6_new (); 143 | void prefix_ipv6_free (); 144 | struct prefix *str2routev6 (char *); 145 | int str2prefix_ipv6 (char *str, struct prefix_ipv6 *p); 146 | void apply_mask_ipv6 (struct prefix_ipv6 *p); 147 | void str2in6_addr (char *str, struct in6_addr *addr); 148 | void masklen2ip6 (int masklen, struct in6_addr *netmask); 149 | int ip6_masklen (struct in6_addr netmask); 150 | #endif /* HAVE_IPV6 */ 151 | 152 | void apply_mask (struct prefix *); 153 | int prefix_match (struct prefix *n, struct prefix *p); 154 | int prefix_same (struct prefix *, struct prefix *); 155 | int prefix_cmp (struct prefix *, struct prefix *); 156 | void prefix_copy (struct prefix *, struct prefix *); 157 | 158 | int all_digit (char *); 159 | int netmask_str2prefix_str (char *, char *, char *); 160 | 161 | #endif /* _ZEBRA_PREFIX_H */ 162 | -------------------------------------------------------------------------------- /lib/print_version.c: -------------------------------------------------------------------------------- 1 | /* Print version function. 2 | * Copyright (C) 1997, 98 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #include 23 | 24 | #include "version.h" 25 | 26 | void 27 | print_version (char *progname) 28 | { 29 | printf ("%s version %s (%s)\n", progname, ZEBRA_VERSION, host_name); 30 | printf ("Copyright 1996-2001, Kunihiro Ishiguro\n"); 31 | } 32 | -------------------------------------------------------------------------------- /lib/routemap.h: -------------------------------------------------------------------------------- 1 | /* Route map function. 2 | * Copyright (C) 1998 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #ifndef _ZEBRA_ROUTEMAP_H 23 | #define _ZEBRA_ROUTEMAP_H 24 | 25 | /* Route map's type. */ 26 | enum route_map_type 27 | { 28 | RMAP_PERMIT, 29 | RMAP_DENY, 30 | RMAP_ANY 31 | }; 32 | 33 | typedef enum 34 | { 35 | RMAP_MATCH, 36 | RMAP_DENYMATCH, 37 | RMAP_NOMATCH, 38 | RMAP_ERROR, 39 | RMAP_OKAY 40 | } route_map_result_t; 41 | 42 | typedef enum 43 | { 44 | RMAP_RIP, 45 | RMAP_RIPNG, 46 | RMAP_OSPF, 47 | RMAP_OSPF6, 48 | RMAP_BGP 49 | } route_map_object_t; 50 | 51 | typedef enum 52 | { 53 | RMAP_EXIT, 54 | RMAP_GOTO, 55 | RMAP_NEXT 56 | } route_map_end_t; 57 | 58 | typedef enum 59 | { 60 | RMAP_EVENT_SET_ADDED, 61 | RMAP_EVENT_SET_DELETED, 62 | RMAP_EVENT_SET_REPLACED, 63 | RMAP_EVENT_MATCH_ADDED, 64 | RMAP_EVENT_MATCH_DELETED, 65 | RMAP_EVENT_MATCH_REPLACED, 66 | RMAP_EVENT_INDEX_ADDED, 67 | RMAP_EVENT_INDEX_DELETED 68 | } route_map_event_t; 69 | 70 | /* Route map rule structure for matching and setting. */ 71 | struct route_map_rule_cmd 72 | { 73 | /* Route map rule name (e.g. as-path, metric) */ 74 | char *str; 75 | 76 | /* Function for value set or match. */ 77 | route_map_result_t (*func_apply)(void *, struct prefix *, 78 | route_map_object_t, void *); 79 | 80 | /* Compile argument and return result as void *. */ 81 | void *(*func_compile)(char *); 82 | 83 | /* Free allocated value by func_compile (). */ 84 | void (*func_free)(void *); 85 | }; 86 | 87 | /* Route map apply error. */ 88 | enum 89 | { 90 | /* Route map rule is missing. */ 91 | RMAP_RULE_MISSING = 1, 92 | 93 | /* Route map rule can't compile */ 94 | RMAP_COMPILE_ERROR 95 | }; 96 | 97 | /* Route map rule list. */ 98 | struct route_map_rule_list 99 | { 100 | struct route_map_rule *head; 101 | struct route_map_rule *tail; 102 | }; 103 | 104 | /* Route map index structure. */ 105 | struct route_map_index 106 | { 107 | struct route_map *map; 108 | 109 | /* Preference of this route map rule. */ 110 | int pref; 111 | 112 | /* Route map type permit or deny. */ 113 | enum route_map_type type; 114 | 115 | /* Do we follow old rules, or hop forward? */ 116 | route_map_end_t exitpolicy; 117 | 118 | /* If we're using "GOTO", to where do we go? */ 119 | int nextpref; 120 | 121 | /* Matching rule list. */ 122 | struct route_map_rule_list match_list; 123 | struct route_map_rule_list set_list; 124 | 125 | /* Make linked list. */ 126 | struct route_map_index *next; 127 | struct route_map_index *prev; 128 | }; 129 | 130 | /* Route map list structure. */ 131 | struct route_map 132 | { 133 | /* Name of route map. */ 134 | char *name; 135 | 136 | /* Route map's rule. */ 137 | struct route_map_index *head; 138 | struct route_map_index *tail; 139 | 140 | /* Make linked list. */ 141 | struct route_map *next; 142 | struct route_map *prev; 143 | }; 144 | 145 | /* Prototypes. */ 146 | void route_map_init (); 147 | void route_map_init_vty (); 148 | 149 | /* Add match statement to route map. */ 150 | int 151 | route_map_add_match (struct route_map_index *index, 152 | char *match_name, 153 | char *match_arg); 154 | 155 | /* Delete specified route match rule. */ 156 | int 157 | route_map_delete_match (struct route_map_index *index, 158 | char *match_name, 159 | char *match_arg); 160 | 161 | /* Add route-map set statement to the route map. */ 162 | int 163 | route_map_add_set (struct route_map_index *index, 164 | char *set_name, 165 | char *set_arg); 166 | 167 | /* Delete route map set rule. */ 168 | int 169 | route_map_delete_set (struct route_map_index *index, char *set_name, 170 | char *set_arg); 171 | 172 | /* Install rule command to the match list. */ 173 | void 174 | route_map_install_match (struct route_map_rule_cmd *cmd); 175 | 176 | /* Install rule command to the set list. */ 177 | void 178 | route_map_install_set (struct route_map_rule_cmd *cmd); 179 | 180 | /* Lookup route map by name. */ 181 | struct route_map * 182 | route_map_lookup_by_name (char *name); 183 | 184 | /* Apply route map to the object. */ 185 | route_map_result_t 186 | route_map_apply (struct route_map *map, struct prefix *, 187 | route_map_object_t object_type, void *object); 188 | 189 | void route_map_add_hook (void (*func) (char *)); 190 | void route_map_delete_hook (void (*func) (char *)); 191 | void route_map_event_hook (void (*func) (route_map_event_t, char *)); 192 | 193 | 194 | #endif /* _ZEBRA_ROUTEMAP_H */ 195 | -------------------------------------------------------------------------------- /lib/smux.h: -------------------------------------------------------------------------------- 1 | /* SNMP support 2 | * Copyright (C) 1999 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #ifndef _ZEBRA_SNMP_H 23 | #define _ZEBRA_SNMP_H 24 | 25 | #define SMUX_PORT_DEFAULT 199 26 | 27 | #define SMUXMAXPKTSIZE 1500 28 | #define SMUXMAXSTRLEN 256 29 | 30 | #define SMUX_OPEN (ASN_APPLICATION | ASN_CONSTRUCTOR | 0) 31 | #define SMUX_CLOSE (ASN_APPLICATION | ASN_PRIMITIVE | 1) 32 | #define SMUX_RREQ (ASN_APPLICATION | ASN_CONSTRUCTOR | 2) 33 | #define SMUX_RRSP (ASN_APPLICATION | ASN_PRIMITIVE | 3) 34 | #define SMUX_SOUT (ASN_APPLICATION | ASN_PRIMITIVE | 4) 35 | 36 | #define SMUX_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0) 37 | #define SMUX_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | 1) 38 | #define SMUX_GETRSP (ASN_CONTEXT | ASN_CONSTRUCTOR | 2) 39 | #define SMUX_SET (ASN_CONTEXT | ASN_CONSTRUCTOR | 3) 40 | #define SMUX_TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 4) 41 | 42 | #define SMUX_MAX_FAILURE 3 43 | 44 | /* Structures here are mostly compatible with UCD SNMP 4.1.1 */ 45 | #define MATCH_FAILED (-1) 46 | #define MATCH_SUCCEEDED 0 47 | 48 | /* SYNTAX TruthValue from SNMPv2-TC. */ 49 | #define SNMP_TRUE 1 50 | #define SNMP_FALSE 2 51 | 52 | /* SYNTAX RowStatus from SNMPv2-TC. */ 53 | #define SNMP_VALID 1 54 | #define SNMP_INVALID 2 55 | 56 | #define IN_ADDR_SIZE sizeof(struct in_addr) 57 | 58 | struct variable; 59 | 60 | #define REGISTER_MIB(descr, var, vartype, theoid) \ 61 | smux_register_mib(descr, (struct variable *)var, sizeof(struct vartype), \ 62 | sizeof(var)/sizeof(struct vartype), \ 63 | theoid, sizeof(theoid)/sizeof(oid)) 64 | 65 | typedef int (WriteMethod)(int action, 66 | u_char *var_val, 67 | u_char var_val_type, 68 | size_t var_val_len, 69 | u_char *statP, 70 | oid *name, 71 | size_t length, 72 | struct variable *v); 73 | 74 | typedef u_char *(FindVarMethod)(struct variable *v, 75 | oid *name, 76 | size_t *length, 77 | int exact, 78 | size_t *var_len, 79 | WriteMethod **write_method); 80 | 81 | /* SNMP variable */ 82 | struct variable 83 | { 84 | /* Index of the MIB.*/ 85 | u_char magic; 86 | 87 | /* Type of variable. */ 88 | char type; 89 | 90 | /* Access control list. */ 91 | u_short acl; 92 | 93 | /* Callback function. */ 94 | FindVarMethod *findVar; 95 | 96 | /* Suffix of the MIB. */ 97 | u_char namelen; 98 | oid name[MAX_OID_LEN]; 99 | }; 100 | 101 | /* SNMP tree. */ 102 | struct subtree 103 | { 104 | /* Tree's oid. */ 105 | oid name[MAX_OID_LEN]; 106 | u_char name_len; 107 | 108 | /* List of the variables. */ 109 | struct variable *variables; 110 | 111 | /* Length of the variables list. */ 112 | int variables_num; 113 | 114 | /* Width of the variables list. */ 115 | int variables_width; 116 | 117 | /* Registered flag. */ 118 | int registered; 119 | }; 120 | 121 | struct trap_object 122 | { 123 | FindVarMethod *findVar; 124 | u_char namelen; 125 | oid name[MAX_OID_LEN]; 126 | }; 127 | 128 | /* Declare SMUX return value. */ 129 | #define SNMP_LOCAL_VARIABLES \ 130 | static int32_t snmp_int_val; \ 131 | static struct in_addr snmp_in_addr_val; 132 | 133 | #define SNMP_INTEGER(V) \ 134 | ( \ 135 | *var_len = sizeof (int32_t), \ 136 | snmp_int_val = V, \ 137 | (u_char *) &snmp_int_val \ 138 | ) 139 | 140 | #define SNMP_IPADDRESS(V) \ 141 | ( \ 142 | *var_len = sizeof (struct in_addr), \ 143 | snmp_in_addr_val = V, \ 144 | (u_char *) &snmp_in_addr_val \ 145 | ) 146 | 147 | void smux_init (oid [], size_t); 148 | void smux_start (void); 149 | void smux_register_mib(char *, struct variable *, size_t, int, oid [], size_t); 150 | int smux_header_generic (struct variable *, oid [], size_t *, int, size_t *, 151 | WriteMethod **); 152 | int smux_trap (oid *, size_t, oid *, size_t, struct trap_object *, size_t, unsigned int, u_char); 153 | 154 | int oid_compare (oid *, int, oid *, int); 155 | void oid2in_addr (oid [], int, struct in_addr *); 156 | void *oid_copy (void *, void *, size_t); 157 | void oid_copy_addr (oid [], struct in_addr *, int); 158 | 159 | #endif /* _ZEBRA_SNMP_H */ 160 | -------------------------------------------------------------------------------- /lib/sockopt.c: -------------------------------------------------------------------------------- 1 | /* setsockopt functions 2 | * Copyright (C) 1999 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #include 23 | #include "log.h" 24 | 25 | #ifdef HAVE_IPV6 26 | /* Set IPv6 packet info to the socket. */ 27 | int 28 | setsockopt_ipv6_pktinfo (int sock, int val) 29 | { 30 | int ret; 31 | 32 | #ifdef IPV6_RECVPKTINFO /*2292bis-01*/ 33 | ret = setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &val, sizeof(val)); 34 | if (ret < 0) 35 | zlog_warn ("can't setsockopt IPV6_RECVPKTINFO : %s", strerror (errno)); 36 | #else /*RFC2292*/ 37 | ret = setsockopt(sock, IPPROTO_IPV6, IPV6_PKTINFO, &val, sizeof(val)); 38 | if (ret < 0) 39 | zlog_warn ("can't setsockopt IPV6_PKTINFO : %s", strerror (errno)); 40 | #endif /* INIA_IPV6 */ 41 | return ret; 42 | } 43 | 44 | /* Set multicast hops val to the socket. */ 45 | int 46 | setsockopt_ipv6_checksum (int sock, int val) 47 | { 48 | int ret; 49 | 50 | #ifdef GNU_LINUX 51 | ret = setsockopt(sock, IPPROTO_RAW, IPV6_CHECKSUM, &val, sizeof(val)); 52 | #else 53 | ret = setsockopt(sock, IPPROTO_IPV6, IPV6_CHECKSUM, &val, sizeof(val)); 54 | #endif /* GNU_LINUX */ 55 | if (ret < 0) 56 | zlog_warn ("can't setsockopt IPV6_CHECKSUM"); 57 | return ret; 58 | } 59 | 60 | /* Set multicast hops val to the socket. */ 61 | int 62 | setsockopt_ipv6_multicast_hops (int sock, int val) 63 | { 64 | int ret; 65 | 66 | ret = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &val, sizeof(val)); 67 | if (ret < 0) 68 | zlog_warn ("can't setsockopt IPV6_MULTICAST_HOPS"); 69 | return ret; 70 | } 71 | 72 | /* Set multicast hops val to the socket. */ 73 | int 74 | setsockopt_ipv6_unicast_hops (int sock, int val) 75 | { 76 | int ret; 77 | 78 | ret = setsockopt(sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &val, sizeof(val)); 79 | if (ret < 0) 80 | zlog_warn ("can't setsockopt IPV6_UNICAST_HOPS"); 81 | return ret; 82 | } 83 | 84 | int 85 | setsockopt_ipv6_hoplimit (int sock, int val) 86 | { 87 | int ret; 88 | 89 | #ifdef IPV6_RECVHOPLIMIT /*2292bis-01*/ 90 | ret = setsockopt (sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &val, sizeof(val)); 91 | if (ret < 0) 92 | zlog_warn ("can't setsockopt IPV6_RECVHOPLIMIT"); 93 | #else /*RFC2292*/ 94 | ret = setsockopt (sock, IPPROTO_IPV6, IPV6_HOPLIMIT, &val, sizeof(val)); 95 | if (ret < 0) 96 | zlog_warn ("can't setsockopt IPV6_HOPLIMIT"); 97 | #endif 98 | return ret; 99 | } 100 | 101 | /* Set multicast loop zero to the socket. */ 102 | int 103 | setsockopt_ipv6_multicast_loop (int sock, int val) 104 | { 105 | int ret; 106 | 107 | ret = setsockopt (sock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &val, 108 | sizeof (val)); 109 | if (ret < 0) 110 | zlog_warn ("can't setsockopt IPV6_MULTICAST_LOOP"); 111 | return ret; 112 | } 113 | 114 | #endif /* HAVE_IPV6 */ 115 | 116 | 117 | /* Set up a multicast socket options for IPv4 118 | This is here so that people only have to do their OS multicast mess 119 | in one place rather than all through zebra, ospfd, and ripd 120 | NB: This is a hookpoint for specific OS functionality */ 121 | int 122 | setsockopt_multicast_ipv4(int sock, 123 | int optname, 124 | struct in_addr if_addr, 125 | unsigned int mcast_addr, 126 | unsigned int ifindex) 127 | { 128 | 129 | /* Linux 2.2.0 and up */ 130 | #if defined(GNU_LINUX) && LINUX_VERSION_CODE > 131584 131 | /* This is better because it uses ifindex directly */ 132 | struct ip_mreqn mreqn; 133 | 134 | switch (optname) 135 | { 136 | case IP_MULTICAST_IF: 137 | case IP_ADD_MEMBERSHIP: 138 | case IP_DROP_MEMBERSHIP: 139 | memset (&mreqn, 0, sizeof(mreqn)); 140 | 141 | if (mcast_addr) 142 | mreqn.imr_multiaddr.s_addr = mcast_addr; 143 | 144 | if (ifindex) 145 | mreqn.imr_ifindex = ifindex; 146 | else 147 | mreqn.imr_address = if_addr; 148 | 149 | return setsockopt(sock, IPPROTO_IP, optname, (void *)&mreqn, sizeof(mreqn)); 150 | break; 151 | 152 | default: 153 | /* Can out and give an understandable error */ 154 | errno = EINVAL; 155 | return -1; 156 | break; 157 | } 158 | 159 | /* Example defines for another OS, boilerplate off other code in this 160 | function, AND handle optname as per other sections for consistency !! */ 161 | /* #elif defined(BOGON_NIX) && EXAMPLE_VERSION_CODE > -100000 */ 162 | /* Add your favourite OS here! */ 163 | 164 | #else /* #if OS_TYPE */ 165 | /* default OS support */ 166 | 167 | struct in_addr m; 168 | struct ip_mreq mreq; 169 | 170 | switch (optname) 171 | { 172 | case IP_MULTICAST_IF: 173 | m = if_addr; 174 | 175 | return setsockopt (sock, IPPROTO_IP, optname, (void *)&m, sizeof(m)); 176 | break; 177 | 178 | case IP_ADD_MEMBERSHIP: 179 | case IP_DROP_MEMBERSHIP: 180 | memset (&mreq, 0, sizeof(mreq)); 181 | mreq.imr_multiaddr.s_addr = mcast_addr; 182 | mreq.imr_interface = if_addr; 183 | 184 | return setsockopt (sock, 185 | IPPROTO_IP, 186 | optname, 187 | (void *)&mreq, 188 | sizeof(mreq)); 189 | break; 190 | 191 | default: 192 | /* Can out and give an understandable error */ 193 | errno = EINVAL; 194 | return -1; 195 | break; 196 | } 197 | #endif /* #if OS_TYPE */ 198 | 199 | } 200 | -------------------------------------------------------------------------------- /lib/sockopt.h: -------------------------------------------------------------------------------- 1 | /* Router advertisement 2 | * Copyright (C) 1999 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #ifndef _ZEBRA_SOCKOPT_H 23 | #define _ZEBRA_SOCKOPT_H 24 | 25 | #ifdef HAVE_IPV6 26 | int setsockopt_ipv6_pktinfo (int, int); 27 | int setsockopt_ipv6_checksum (int, int); 28 | int setsockopt_ipv6_multicast_hops (int, int); 29 | int setsockopt_ipv6_unicast_hops (int, int); 30 | int setsockopt_ipv6_hoplimit (int, int); 31 | int setsockopt_ipv6_multicast_loop (int, int); 32 | #endif /* HAVE_IPV6 */ 33 | 34 | int setsockopt_multicast_ipv4(int sock, 35 | int optname, 36 | struct in_addr if_addr, 37 | unsigned int mcast_addr, 38 | unsigned int ifindex); 39 | 40 | 41 | #endif /*_ZEBRA_SOCKOPT_H */ 42 | -------------------------------------------------------------------------------- /lib/sockunion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Socket union header. 3 | * Copyright (c) 1997 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the 9 | * Free Software Foundation; either version 2, or (at your option) any 10 | * later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20 | * 02111-1307, USA. 21 | */ 22 | 23 | #ifndef _ZEBRA_SOCKUNION_H 24 | #define _ZEBRA_SOCKUNION_H 25 | 26 | #if 0 27 | union sockunion { 28 | struct sockinet { 29 | u_char si_len; 30 | u_char si_family; 31 | u_short si_port; 32 | } su_si; 33 | struct sockaddr_in su_sin; 34 | struct sockaddr_in6 su_sin6; 35 | }; 36 | #define su_len su_si.si_len 37 | #define su_family su_si.si_family 38 | #define su_port su_si.si_port 39 | #endif /* 0 */ 40 | 41 | union sockunion 42 | { 43 | struct sockaddr sa; 44 | struct sockaddr_in sin; 45 | #ifdef HAVE_IPV6 46 | struct sockaddr_in6 sin6; 47 | #endif /* HAVE_IPV6 */ 48 | }; 49 | 50 | enum connect_result 51 | { 52 | connect_error, 53 | connect_success, 54 | connect_in_progress 55 | }; 56 | 57 | /* Default address family. */ 58 | #ifdef HAVE_IPV6 59 | #define AF_INET_UNION AF_INET6 60 | #else 61 | #define AF_INET_UNION AF_INET 62 | #endif 63 | 64 | /* Sockunion address string length. Same as INET6_ADDRSTRLEN. */ 65 | #define SU_ADDRSTRLEN 46 66 | 67 | /* Macro to set link local index to the IPv6 address. For KAME IPv6 68 | stack. */ 69 | #ifdef KAME 70 | #define IN6_LINKLOCAL_IFINDEX(a) ((a).s6_addr[2] << 8 | (a).s6_addr[3]) 71 | #define SET_IN6_LINKLOCAL_IFINDEX(a, i) \ 72 | do { \ 73 | (a).s6_addr[2] = ((i) >> 8) & 0xff; \ 74 | (a).s6_addr[3] = (i) & 0xff; \ 75 | } while (0) 76 | #else 77 | #define IN6_LINKLOCAL_IFINDEX(a) 78 | #define SET_IN6_LINKLOCAL_IFINDEX(a, i) 79 | #endif /* KAME */ 80 | 81 | /* shortcut macro to specify address field of struct sockaddr */ 82 | #define sock2ip(X) (((struct sockaddr_in *)(X))->sin_addr.s_addr) 83 | #ifdef HAVE_IPV6 84 | #define sock2ip6(X) (((struct sockaddr_in6 *)(X))->sin6_addr.s6_addr) 85 | #endif /* HAVE_IPV6 */ 86 | 87 | #define sockunion_family(X) (X)->sa.sa_family 88 | 89 | /* Prototypes. */ 90 | int str2sockunion (char *, union sockunion *); 91 | const char *sockunion2str (union sockunion *, char *, size_t); 92 | int sockunion_cmp (union sockunion *, union sockunion *); 93 | int sockunion_same (union sockunion *, union sockunion *); 94 | 95 | char *sockunion_su2str (union sockunion *su); 96 | union sockunion *sockunion_str2su (char *str); 97 | struct in_addr sockunion_get_in_addr (union sockunion *su); 98 | int sockunion_accept (int sock, union sockunion *); 99 | int sockunion_stream_socket (union sockunion *); 100 | int sockopt_reuseaddr (int); 101 | int sockopt_reuseport (int); 102 | int sockunion_bind (int sock, union sockunion *, unsigned short, union sockunion *); 103 | int sockopt_ttl (int family, int sock, int ttl); 104 | int sockunion_socket (union sockunion *su); 105 | const char *inet_sutop (union sockunion *su, char *str); 106 | enum connect_result 107 | sockunion_connect (int fd, union sockunion *su, unsigned short port, unsigned int); 108 | union sockunion *sockunion_getsockname (int); 109 | union sockunion *sockunion_getpeername (int); 110 | union sockunion *sockunion_dup (union sockunion *); 111 | void sockunion_free (union sockunion *); 112 | 113 | #ifndef HAVE_INET_NTOP 114 | const char * 115 | inet_ntop (int family, const void *addrptr, char *strptr, size_t len); 116 | #endif /* HAVE_INET_NTOP */ 117 | 118 | #ifndef HAVE_INET_PTON 119 | int 120 | inet_pton (int family, const char *strptr, void *addrptr); 121 | #endif /* HAVE_INET_PTON */ 122 | 123 | #ifndef HAVE_INET_ATON 124 | int 125 | inet_aton (const char *cp, struct in_addr *inaddr); 126 | #endif 127 | 128 | #endif /* _ZEBRA_SOCKUNION_H */ 129 | -------------------------------------------------------------------------------- /lib/str.c: -------------------------------------------------------------------------------- 1 | /* 2 | * zebra string function 3 | * 4 | * these functions are just very basic wrappers around exiting ones and 5 | * do not offer the protection that might be expected against buffer 6 | * overruns etc 7 | */ 8 | 9 | #include 10 | 11 | #include "str.h" 12 | 13 | #ifndef HAVE_SNPRINTF 14 | /* 15 | * snprint() is a real basic wrapper around the standard sprintf() 16 | * without any bounds checking 17 | */ 18 | int 19 | snprintf(char *str, size_t size, const char *format, ...) 20 | { 21 | va_list args; 22 | 23 | va_start (args, format); 24 | 25 | return vsprintf (str, format, args); 26 | } 27 | #endif 28 | 29 | #ifndef HAVE_STRLCPY 30 | /* 31 | * strlcpy is a safer version of strncpy(), checking the total 32 | * size of the buffer 33 | */ 34 | size_t 35 | strlcpy(char *dst, const char *src, size_t size) 36 | { 37 | strncpy(dst, src, size); 38 | 39 | return (strlen(dst)); 40 | } 41 | #endif 42 | 43 | #ifndef HAVE_STRLCAT 44 | /* 45 | * strlcat is a safer version of strncat(), checking the total 46 | * size of the buffer 47 | */ 48 | size_t 49 | strlcat(char *dst, const char *src, size_t size) 50 | { 51 | /* strncpy(dst, src, size - strlen(dst)); */ 52 | 53 | /* I've just added below code only for workable under Linux. So 54 | need rewrite -- Kunihiro. */ 55 | if (strlen (dst) + strlen (src) >= size) 56 | return -1; 57 | 58 | strcat (dst, src); 59 | 60 | return (strlen(dst)); 61 | } 62 | #endif 63 | -------------------------------------------------------------------------------- /lib/str.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: str.h,v 1.3 1999/02/19 17:01:49 developer Exp $ 3 | */ 4 | 5 | #ifndef _ZEBRA_STR_H 6 | #define _ZEBRA_STR_H 7 | 8 | #ifndef HAVE_SNPRINTF 9 | int snprintf(char *, size_t, const char *, ...); 10 | #endif 11 | 12 | #ifndef HAVE_VSNPRINTF 13 | #define vsnprintf(buf, size, format, args) vsprintf(buf, format, args) 14 | #endif 15 | 16 | #ifndef HAVE_STRLCPY 17 | size_t strlcpy(char *, const char *, size_t); 18 | #endif 19 | 20 | #ifndef HAVE_STRLCAT 21 | size_t strlcat(char *, const char *, size_t); 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /lib/stream.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Packet interface 3 | * Copyright (C) 1999 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the 9 | * Free Software Foundation; either version 2, or (at your option) any 10 | * later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20 | * 02111-1307, USA. 21 | */ 22 | 23 | #include 24 | 25 | #include "stream.h" 26 | #include "memory.h" 27 | #include "network.h" 28 | #include "prefix.h" 29 | 30 | 31 | /*A macro to check pointers in order to not 32 | go behind the allocated mem block 33 | S -- stream reference 34 | Z -- size of data to be written 35 | */ 36 | 37 | #define CHECK_SIZE(S, Z) \ 38 | if (((S)->putp + (Z)) > (S)->size) \ 39 | (Z) = (S)->size - (S)->putp; 40 | 41 | /* Stream is fixed length buffer for network output/input. */ 42 | 43 | /* Make stream buffer. */ 44 | struct stream * 45 | stream_new (size_t size) 46 | { 47 | struct stream *s; 48 | 49 | s = XCALLOC (MTYPE_STREAM, sizeof (struct stream)); 50 | 51 | s->data = XCALLOC (MTYPE_STREAM_DATA, size); 52 | s->size = size; 53 | return s; 54 | } 55 | 56 | /* Free it now. */ 57 | void 58 | stream_free (struct stream *s) 59 | { 60 | XFREE (MTYPE_STREAM_DATA, s->data); 61 | XFREE (MTYPE_STREAM, s); 62 | } 63 | 64 | unsigned long 65 | stream_get_getp (struct stream *s) 66 | { 67 | return s->getp; 68 | } 69 | 70 | unsigned long 71 | stream_get_putp (struct stream *s) 72 | { 73 | return s->putp; 74 | } 75 | 76 | unsigned long 77 | stream_get_endp (struct stream *s) 78 | { 79 | return s->endp; 80 | } 81 | 82 | unsigned long 83 | stream_get_size (struct stream *s) 84 | { 85 | return s->size; 86 | } 87 | 88 | /* Stream structre' stream pointer related functions. */ 89 | void 90 | stream_set_getp (struct stream *s, unsigned long pos) 91 | { 92 | s->getp = pos; 93 | } 94 | 95 | void 96 | stream_set_putp (struct stream *s, unsigned long pos) 97 | { 98 | s->putp = pos; 99 | } 100 | 101 | /* Forward pointer. */ 102 | void 103 | stream_forward (struct stream *s, int size) 104 | { 105 | s->getp += size; 106 | } 107 | 108 | /* Copy from stream to destination. */ 109 | void 110 | stream_get (void *dst, struct stream *s, size_t size) 111 | { 112 | memcpy (dst, s->data + s->getp, size); 113 | s->getp += size; 114 | } 115 | 116 | /* Get next character from the stream. */ 117 | u_char 118 | stream_getc (struct stream *s) 119 | { 120 | u_char c; 121 | 122 | c = s->data[s->getp]; 123 | s->getp++; 124 | return c; 125 | } 126 | 127 | /* Get next character from the stream. */ 128 | u_char 129 | stream_getc_from (struct stream *s, unsigned long from) 130 | { 131 | u_char c; 132 | 133 | c = s->data[from]; 134 | return c; 135 | } 136 | 137 | /* Get next word from the stream. */ 138 | u_int16_t 139 | stream_getw (struct stream *s) 140 | { 141 | u_int16_t w; 142 | 143 | w = s->data[s->getp++] << 8; 144 | w |= s->data[s->getp++]; 145 | return w; 146 | } 147 | 148 | /* Get next word from the stream. */ 149 | u_int16_t 150 | stream_getw_from (struct stream *s, unsigned long from) 151 | { 152 | u_int16_t w; 153 | 154 | w = s->data[from++] << 8; 155 | w |= s->data[from]; 156 | return w; 157 | } 158 | 159 | /* Get next long word from the stream. */ 160 | u_int32_t 161 | stream_getl (struct stream *s) 162 | { 163 | u_int32_t l; 164 | 165 | l = s->data[s->getp++] << 24; 166 | l |= s->data[s->getp++] << 16; 167 | l |= s->data[s->getp++] << 8; 168 | l |= s->data[s->getp++]; 169 | return l; 170 | } 171 | 172 | /* Get next long word from the stream. */ 173 | u_int32_t 174 | stream_get_ipv4 (struct stream *s) 175 | { 176 | u_int32_t l; 177 | 178 | memcpy (&l, s->data + s->getp, 4); 179 | s->getp += 4; 180 | 181 | return l; 182 | } 183 | 184 | /* Copy to source to stream. */ 185 | void 186 | stream_put (struct stream *s, void *src, size_t size) 187 | { 188 | 189 | CHECK_SIZE(s, size); 190 | 191 | if (src) 192 | memcpy (s->data + s->putp, src, size); 193 | else 194 | memset (s->data + s->putp, 0, size); 195 | 196 | s->putp += size; 197 | if (s->putp > s->endp) 198 | s->endp = s->putp; 199 | } 200 | 201 | /* Put character to the stream. */ 202 | int 203 | stream_putc (struct stream *s, u_char c) 204 | { 205 | if (s->putp >= s->size) return 0; 206 | 207 | s->data[s->putp] = c; 208 | s->putp++; 209 | if (s->putp > s->endp) 210 | s->endp = s->putp; 211 | return 1; 212 | } 213 | 214 | /* Put word to the stream. */ 215 | int 216 | stream_putw (struct stream *s, u_int16_t w) 217 | { 218 | if ((s->size - s->putp) < 2) return 0; 219 | 220 | s->data[s->putp++] = (u_char)(w >> 8); 221 | s->data[s->putp++] = (u_char) w; 222 | 223 | if (s->putp > s->endp) 224 | s->endp = s->putp; 225 | return 2; 226 | } 227 | 228 | /* Put long word to the stream. */ 229 | int 230 | stream_putl (struct stream *s, u_int32_t l) 231 | { 232 | if ((s->size - s->putp) < 4) return 0; 233 | 234 | s->data[s->putp++] = (u_char)(l >> 24); 235 | s->data[s->putp++] = (u_char)(l >> 16); 236 | s->data[s->putp++] = (u_char)(l >> 8); 237 | s->data[s->putp++] = (u_char)l; 238 | 239 | if (s->putp > s->endp) 240 | s->endp = s->putp; 241 | return 4; 242 | } 243 | 244 | int 245 | stream_putc_at (struct stream *s, unsigned long putp, u_char c) 246 | { 247 | s->data[putp] = c; 248 | return 1; 249 | } 250 | 251 | int 252 | stream_putw_at (struct stream *s, unsigned long putp, u_int16_t w) 253 | { 254 | s->data[putp] = (u_char)(w >> 8); 255 | s->data[putp + 1] = (u_char) w; 256 | return 2; 257 | } 258 | 259 | int 260 | stream_putl_at (struct stream *s, unsigned long putp, u_int32_t l) 261 | { 262 | s->data[putp] = (u_char)(l >> 24); 263 | s->data[putp + 1] = (u_char)(l >> 16); 264 | s->data[putp + 2] = (u_char)(l >> 8); 265 | s->data[putp + 3] = (u_char)l; 266 | return 4; 267 | } 268 | 269 | /* Put long word to the stream. */ 270 | int 271 | stream_put_ipv4 (struct stream *s, u_int32_t l) 272 | { 273 | if ((s->size - s->putp) < 4) 274 | return 0; 275 | 276 | memcpy (s->data + s->putp, &l, 4); 277 | s->putp += 4; 278 | 279 | if (s->putp > s->endp) 280 | s->endp = s->putp; 281 | return 4; 282 | } 283 | 284 | /* Put long word to the stream. */ 285 | int 286 | stream_put_in_addr (struct stream *s, struct in_addr *addr) 287 | { 288 | if ((s->size - s->putp) < 4) 289 | return 0; 290 | 291 | memcpy (s->data + s->putp, addr, 4); 292 | s->putp += 4; 293 | 294 | if (s->putp > s->endp) 295 | s->endp = s->putp; 296 | return 4; 297 | } 298 | 299 | /* Put prefix by nlri type format. */ 300 | int 301 | stream_put_prefix (struct stream *s, struct prefix *p) 302 | { 303 | u_char psize; 304 | 305 | psize = PSIZE (p->prefixlen); 306 | 307 | if ((s->size - s->putp) < psize) return 0; 308 | 309 | stream_putc (s, p->prefixlen); 310 | memcpy (s->data + s->putp, &p->u.prefix, psize); 311 | s->putp += psize; 312 | 313 | if (s->putp > s->endp) 314 | s->endp = s->putp; 315 | 316 | return psize; 317 | } 318 | 319 | /* Read size from fd. */ 320 | int 321 | stream_read (struct stream *s, int fd, size_t size) 322 | { 323 | int nbytes; 324 | 325 | nbytes = readn (fd, s->data + s->putp, size); 326 | 327 | if (nbytes > 0) 328 | { 329 | s->putp += nbytes; 330 | s->endp += nbytes; 331 | } 332 | return nbytes; 333 | } 334 | 335 | /* Read size from fd. */ 336 | int 337 | stream_read_unblock (struct stream *s, int fd, size_t size) 338 | { 339 | int nbytes; 340 | int val; 341 | 342 | val = fcntl (fd, F_GETFL, 0); 343 | fcntl (fd, F_SETFL, val|O_NONBLOCK); 344 | nbytes = read (fd, s->data + s->putp, size); 345 | fcntl (fd, F_SETFL, val); 346 | 347 | if (nbytes > 0) 348 | { 349 | s->putp += nbytes; 350 | s->endp += nbytes; 351 | } 352 | return nbytes; 353 | } 354 | 355 | /* Write data to buffer. */ 356 | int 357 | stream_write (struct stream *s, u_char *ptr, size_t size) 358 | { 359 | 360 | CHECK_SIZE(s, size); 361 | 362 | memcpy (s->data + s->putp, ptr, size); 363 | s->putp += size; 364 | if (s->putp > s->endp) 365 | s->endp = s->putp; 366 | return size; 367 | } 368 | 369 | /* Return current read pointer. */ 370 | u_char * 371 | stream_pnt (struct stream *s) 372 | { 373 | return s->data + s->getp; 374 | } 375 | 376 | /* Check does this stream empty? */ 377 | int 378 | stream_empty (struct stream *s) 379 | { 380 | if (s->putp == 0 && s->endp == 0 && s->getp == 0) 381 | return 1; 382 | else 383 | return 0; 384 | } 385 | 386 | /* Reset stream. */ 387 | void 388 | stream_reset (struct stream *s) 389 | { 390 | s->putp = 0; 391 | s->endp = 0; 392 | s->getp = 0; 393 | } 394 | 395 | /* Write stream contens to the file discriptor. */ 396 | int 397 | stream_flush (struct stream *s, int fd) 398 | { 399 | int nbytes; 400 | 401 | nbytes = write (fd, s->data + s->getp, s->endp - s->getp); 402 | 403 | return nbytes; 404 | } 405 | 406 | /* Stream first in first out queue. */ 407 | 408 | struct stream_fifo * 409 | stream_fifo_new () 410 | { 411 | struct stream_fifo *new; 412 | 413 | new = XCALLOC (MTYPE_STREAM_FIFO, sizeof (struct stream_fifo)); 414 | return new; 415 | } 416 | 417 | /* Add new stream to fifo. */ 418 | void 419 | stream_fifo_push (struct stream_fifo *fifo, struct stream *s) 420 | { 421 | if (fifo->tail) 422 | fifo->tail->next = s; 423 | else 424 | fifo->head = s; 425 | 426 | fifo->tail = s; 427 | 428 | fifo->count++; 429 | } 430 | 431 | /* Delete first stream from fifo. */ 432 | struct stream * 433 | stream_fifo_pop (struct stream_fifo *fifo) 434 | { 435 | struct stream *s; 436 | 437 | s = fifo->head; 438 | 439 | if (s) 440 | { 441 | fifo->head = s->next; 442 | 443 | if (fifo->head == NULL) 444 | fifo->tail = NULL; 445 | } 446 | 447 | fifo->count--; 448 | 449 | return s; 450 | } 451 | 452 | /* Return first fifo entry. */ 453 | struct stream * 454 | stream_fifo_head (struct stream_fifo *fifo) 455 | { 456 | return fifo->head; 457 | } 458 | 459 | void 460 | stream_fifo_clean (struct stream_fifo *fifo) 461 | { 462 | struct stream *s; 463 | struct stream *next; 464 | 465 | for (s = fifo->head; s; s = next) 466 | { 467 | next = s->next; 468 | stream_free (s); 469 | } 470 | fifo->head = fifo->tail = NULL; 471 | fifo->count = 0; 472 | } 473 | 474 | void 475 | stream_fifo_free (struct stream_fifo *fifo) 476 | { 477 | stream_fifo_clean (fifo); 478 | XFREE (MTYPE_STREAM_FIFO, fifo); 479 | } 480 | -------------------------------------------------------------------------------- /lib/stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Packet interface 3 | * Copyright (C) 1999 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the 9 | * Free Software Foundation; either version 2, or (at your option) any 10 | * later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20 | * 02111-1307, USA. 21 | */ 22 | 23 | #ifndef _ZEBRA_STREAM_H 24 | #define _ZEBRA_STREAM_H 25 | 26 | /* Stream buffer. */ 27 | struct stream 28 | { 29 | struct stream *next; 30 | 31 | unsigned char *data; 32 | 33 | /* Put pointer. */ 34 | unsigned long putp; 35 | 36 | /* Get pointer. */ 37 | unsigned long getp; 38 | 39 | /* End of pointer. */ 40 | unsigned long endp; 41 | 42 | /* Data size. */ 43 | unsigned long size; 44 | }; 45 | 46 | /* First in first out queue structure. */ 47 | struct stream_fifo 48 | { 49 | unsigned long count; 50 | 51 | struct stream *head; 52 | struct stream *tail; 53 | }; 54 | 55 | /* Utility macros. */ 56 | #define STREAM_PNT(S) ((S)->data + (S)->getp) 57 | #define STREAM_SIZE(S) ((S)->size) 58 | #define STREAM_REMAIN(S) ((S)->size - (S)->putp) 59 | #define STREAM_DATA(S) ((S)->data) 60 | 61 | /* Stream prototypes. */ 62 | struct stream *stream_new (size_t); 63 | void stream_free (struct stream *); 64 | 65 | unsigned long stream_get_getp (struct stream *); 66 | unsigned long stream_get_putp (struct stream *); 67 | unsigned long stream_get_endp (struct stream *); 68 | unsigned long stream_get_size (struct stream *); 69 | u_char *stream_get_data (struct stream *); 70 | 71 | void stream_set_getp (struct stream *, unsigned long); 72 | void stream_set_putp (struct stream *, unsigned long); 73 | 74 | void stream_forward (struct stream *, int); 75 | 76 | void stream_put (struct stream *, void *, size_t); 77 | int stream_putc (struct stream *, u_char); 78 | int stream_putc_at (struct stream *, unsigned long, u_char); 79 | int stream_putw (struct stream *, u_int16_t); 80 | int stream_putw_at (struct stream *, unsigned long, u_int16_t); 81 | int stream_putl (struct stream *, u_int32_t); 82 | int stream_putl_at (struct stream *, unsigned long, u_int32_t); 83 | int stream_put_ipv4 (struct stream *, u_int32_t); 84 | int stream_put_in_addr (struct stream *, struct in_addr *); 85 | 86 | void stream_get (void *, struct stream *, size_t); 87 | u_char stream_getc (struct stream *); 88 | u_char stream_getc_from (struct stream *, unsigned long); 89 | u_int16_t stream_getw (struct stream *); 90 | u_int16_t stream_getw_from (struct stream *, unsigned long); 91 | u_int32_t stream_getl (struct stream *); 92 | u_int32_t stream_get_ipv4 (struct stream *); 93 | 94 | #undef stream_read 95 | #undef stream_write 96 | int stream_read (struct stream *, int, size_t); 97 | int stream_read_unblock (struct stream *, int, size_t); 98 | int stream_write (struct stream *, u_char *, size_t); 99 | 100 | u_char *stream_pnt (struct stream *); 101 | void stream_reset (struct stream *); 102 | int stream_flush (struct stream *, int); 103 | int stream_empty (struct stream *); 104 | 105 | /* Stream fifo. */ 106 | struct stream_fifo *stream_fifo_new (); 107 | void stream_fifo_push (struct stream_fifo *fifo, struct stream *s); 108 | struct stream *stream_fifo_pop (struct stream_fifo *fifo); 109 | struct stream *stream_fifo_head (struct stream_fifo *fifo); 110 | void stream_fifo_clean (struct stream_fifo *fifo); 111 | void stream_fifo_free (struct stream_fifo *fifo); 112 | 113 | #endif /* _ZEBRA_STREAM_H */ 114 | -------------------------------------------------------------------------------- /lib/table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Routing Table 3 | * Copyright (C) 1998 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the 9 | * Free Software Foundation; either version 2, or (at your option) any 10 | * later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20 | * 02111-1307, USA. 21 | */ 22 | 23 | #ifndef _ZEBRA_TABLE_H 24 | #define _ZEBRA_TABLE_H 25 | 26 | /* Routing table top structure. */ 27 | struct route_table 28 | { 29 | struct route_node *top; 30 | }; 31 | 32 | /* Each routing entry. */ 33 | struct route_node 34 | { 35 | /* Actual prefix of this radix. */ 36 | struct prefix p; 37 | 38 | /* Tree link. */ 39 | struct route_table *table; 40 | struct route_node *parent; 41 | struct route_node *link[2]; 42 | #define l_left link[0] 43 | #define l_right link[1] 44 | 45 | /* Lock of this radix */ 46 | unsigned int lock; 47 | 48 | /* Each node of route. */ 49 | void *info; 50 | 51 | /* Aggregation. */ 52 | void *aggregate; 53 | }; 54 | 55 | /* Prototypes. */ 56 | struct route_table *route_table_init (void); 57 | void route_table_finish (struct route_table *); 58 | void route_unlock_node (struct route_node *node); 59 | void route_node_delete (struct route_node *node); 60 | struct route_node *route_top (struct route_table *); 61 | struct route_node *route_next (struct route_node *); 62 | struct route_node *route_next_until (struct route_node *, struct route_node *); 63 | struct route_node *route_node_get (struct route_table *, struct prefix *); 64 | struct route_node *route_node_lookup (struct route_table *, struct prefix *); 65 | struct route_node *route_lock_node (struct route_node *node); 66 | struct route_node *route_node_match (struct route_table *, struct prefix *); 67 | struct route_node *route_node_match_ipv4 (struct route_table *, 68 | struct in_addr *); 69 | #ifdef HAVE_IPV6 70 | struct route_node *route_node_match_ipv6 (struct route_table *, 71 | struct in6_addr *); 72 | #endif /* HAVE_IPV6 */ 73 | 74 | #endif /* _ZEBRA_TABLE_H */ 75 | -------------------------------------------------------------------------------- /lib/thread.h: -------------------------------------------------------------------------------- 1 | /* Thread management routine header. 2 | * Copyright (C) 1998 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #ifndef _ZEBRA_THREAD_H 23 | #define _ZEBRA_THREAD_H 24 | 25 | #ifdef HAVE_RUSAGE 26 | #define RUSAGE_T struct rusage 27 | #define GETRUSAGE(X) getrusage (RUSAGE_SELF, X); 28 | #else 29 | #define RUSAGE_T struct timeval 30 | #define GETRUSAGE(X) gettimeofday (X, NULL); 31 | #endif /* HAVE_RUSAGE */ 32 | 33 | /* Linked list of thread. */ 34 | struct thread_list 35 | { 36 | struct thread *head; 37 | struct thread *tail; 38 | int count; 39 | }; 40 | 41 | /* Master of the theads. */ 42 | struct thread_master 43 | { 44 | struct thread_list read; 45 | struct thread_list write; 46 | struct thread_list timer; 47 | struct thread_list event; 48 | struct thread_list ready; 49 | struct thread_list unuse; 50 | fd_set readfd; 51 | fd_set writefd; 52 | fd_set exceptfd; 53 | unsigned long alloc; 54 | }; 55 | 56 | /* Thread itself. */ 57 | struct thread 58 | { 59 | unsigned char type; /* thread type */ 60 | struct thread *next; /* next pointer of the thread */ 61 | struct thread *prev; /* previous pointer of the thread */ 62 | struct thread_master *master; /* pointer to the struct thread_master. */ 63 | int (*func) (struct thread *); /* event function */ 64 | void *arg; /* event argument */ 65 | union { 66 | int val; /* second argument of the event. */ 67 | int fd; /* file descriptor in case of read/write. */ 68 | struct timeval sands; /* rest of time sands value. */ 69 | } u; 70 | RUSAGE_T ru; /* Indepth usage info. */ 71 | }; 72 | 73 | /* Thread types. */ 74 | #define THREAD_READ 0 75 | #define THREAD_WRITE 1 76 | #define THREAD_TIMER 2 77 | #define THREAD_EVENT 3 78 | #define THREAD_READY 4 79 | #define THREAD_UNUSED 5 80 | 81 | /* Thread yield time. */ 82 | #define THREAD_YIELD_TIME_SLOT 100 * 1000L /* 100ms */ 83 | 84 | /* Macros. */ 85 | #define THREAD_ARG(X) ((X)->arg) 86 | #define THREAD_FD(X) ((X)->u.fd) 87 | #define THREAD_VAL(X) ((X)->u.val) 88 | 89 | #define THREAD_READ_ON(master,thread,func,arg,sock) \ 90 | do { \ 91 | if (! thread) \ 92 | thread = thread_add_read (master, func, arg, sock); \ 93 | } while (0) 94 | 95 | #define THREAD_WRITE_ON(master,thread,func,arg,sock) \ 96 | do { \ 97 | if (! thread) \ 98 | thread = thread_add_write (master, func, arg, sock); \ 99 | } while (0) 100 | 101 | #define THREAD_TIMER_ON(master,thread,func,arg,time) \ 102 | do { \ 103 | if (! thread) \ 104 | thread = thread_add_timer (master, func, arg, time); \ 105 | } while (0) 106 | 107 | #define THREAD_OFF(thread) \ 108 | do { \ 109 | if (thread) \ 110 | { \ 111 | thread_cancel (thread); \ 112 | thread = NULL; \ 113 | } \ 114 | } while (0) 115 | 116 | #define THREAD_READ_OFF(thread) THREAD_OFF(thread) 117 | #define THREAD_WRITE_OFF(thread) THREAD_OFF(thread) 118 | #define THREAD_TIMER_OFF(thread) THREAD_OFF(thread) 119 | 120 | /* Prototypes. */ 121 | struct thread_master *thread_master_create (); 122 | struct thread *thread_add_read (struct thread_master *, 123 | int (*)(struct thread *), void *, int); 124 | struct thread *thread_add_write (struct thread_master *, 125 | int (*)(struct thread *), void *, int); 126 | struct thread *thread_add_timer (struct thread_master *, 127 | int (*)(struct thread *), void *, long); 128 | struct thread *thread_add_event (struct thread_master *, 129 | int (*)(struct thread *), void *, int ); 130 | void thread_cancel (struct thread *); 131 | void thread_cancel_event (struct thread_master *, void *); 132 | 133 | struct thread *thread_fetch (struct thread_master *, struct thread *); 134 | struct thread *thread_execute (struct thread_master *, 135 | int (*)(struct thread *), void *, int); 136 | void thread_call (struct thread *); 137 | char *thread_timer_remain_second (struct thread *); 138 | 139 | #endif /* _ZEBRA_THREAD_H */ 140 | -------------------------------------------------------------------------------- /lib/vector.c: -------------------------------------------------------------------------------- 1 | /* Generic vector interface routine 2 | * Copyright (C) 1997 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #include 23 | 24 | #include "vector.h" 25 | #include "memory.h" 26 | 27 | /* Initialize vector : allocate memory and return vector. */ 28 | vector 29 | vector_init (unsigned int size) 30 | { 31 | vector v = XCALLOC (MTYPE_VECTOR, sizeof (struct _vector)); 32 | 33 | /* allocate at least one slot */ 34 | if (size == 0) 35 | size = 1; 36 | 37 | v->alloced = size; 38 | v->max = 0; 39 | v->index = XCALLOC (MTYPE_VECTOR_INDEX, sizeof (void *) * size); 40 | return v; 41 | } 42 | 43 | void 44 | vector_only_wrapper_free (vector v) 45 | { 46 | XFREE (MTYPE_VECTOR, v); 47 | } 48 | 49 | void 50 | vector_only_index_free (void *index) 51 | { 52 | XFREE (MTYPE_VECTOR_INDEX, index); 53 | } 54 | 55 | void 56 | vector_free (vector v) 57 | { 58 | XFREE (MTYPE_VECTOR_INDEX, v->index); 59 | XFREE (MTYPE_VECTOR, v); 60 | } 61 | 62 | vector 63 | vector_copy (vector v) 64 | { 65 | unsigned int size; 66 | vector new = XCALLOC (MTYPE_VECTOR, sizeof (struct _vector)); 67 | 68 | new->max = v->max; 69 | new->alloced = v->alloced; 70 | 71 | size = sizeof (void *) * (v->alloced); 72 | new->index = XCALLOC (MTYPE_VECTOR_INDEX, size); 73 | memcpy (new->index, v->index, size); 74 | 75 | return new; 76 | } 77 | 78 | /* Check assigned index, and if it runs short double index pointer */ 79 | void 80 | vector_ensure (vector v, unsigned int num) 81 | { 82 | if (v->alloced > num) 83 | return; 84 | 85 | v->index = XREALLOC (MTYPE_VECTOR_INDEX, 86 | v->index, sizeof (void *) * (v->alloced * 2)); 87 | memset (&v->index[v->alloced], 0, sizeof (void *) * v->alloced); 88 | v->alloced *= 2; 89 | 90 | if (v->alloced <= num) 91 | vector_ensure (v, num); 92 | } 93 | 94 | /* This function only returns next empty slot index. It dose not mean 95 | the slot's index memory is assigned, please call vector_ensure() 96 | after calling this function. */ 97 | int 98 | vector_empty_slot (vector v) 99 | { 100 | unsigned int i; 101 | 102 | if (v->max == 0) 103 | return 0; 104 | 105 | for (i = 0; i < v->max; i++) 106 | if (v->index[i] == 0) 107 | return i; 108 | 109 | return i; 110 | } 111 | 112 | /* Set value to the smallest empty slot. */ 113 | int 114 | vector_set (vector v, void *val) 115 | { 116 | unsigned int i; 117 | 118 | i = vector_empty_slot (v); 119 | vector_ensure (v, i); 120 | 121 | v->index[i] = val; 122 | 123 | if (v->max <= i) 124 | v->max = i + 1; 125 | 126 | return i; 127 | } 128 | 129 | /* Set value to specified index slot. */ 130 | int 131 | vector_set_index (vector v, unsigned int i, void *val) 132 | { 133 | vector_ensure (v, i); 134 | 135 | v->index[i] = val; 136 | 137 | if (v->max <= i) 138 | v->max = i + 1; 139 | 140 | return i; 141 | } 142 | 143 | /* Look up vector. */ 144 | void * 145 | vector_lookup (vector v, unsigned int i) 146 | { 147 | if (i >= v->max) 148 | return NULL; 149 | return v->index[i]; 150 | } 151 | 152 | /* Lookup vector, ensure it. */ 153 | void * 154 | vector_lookup_ensure (vector v, unsigned int i) 155 | { 156 | vector_ensure (v, i); 157 | return v->index[i]; 158 | } 159 | 160 | /* Unset value at specified index slot. */ 161 | void 162 | vector_unset (vector v, unsigned int i) 163 | { 164 | if (i >= v->alloced) 165 | return; 166 | 167 | v->index[i] = NULL; 168 | 169 | if (i + 1 == v->max) 170 | { 171 | v->max--; 172 | while (i && v->index[--i] == NULL && v->max--) 173 | ; /* Is this ugly ? */ 174 | } 175 | } 176 | 177 | /* Count the number of not emplty slot. */ 178 | unsigned int 179 | vector_count (vector v) 180 | { 181 | unsigned int i; 182 | unsigned count = 0; 183 | 184 | for (i = 0; i < v->max; i++) 185 | if (v->index[i] != NULL) 186 | count++; 187 | 188 | return count; 189 | } 190 | -------------------------------------------------------------------------------- /lib/vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Generic vector interface header. 3 | * Copyright (C) 1997, 98 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the 9 | * Free Software Foundation; either version 2, or (at your option) any 10 | * later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20 | * 02111-1307, USA. 21 | */ 22 | 23 | #ifndef _ZEBRA_VECTOR_H 24 | #define _ZEBRA_VECTOR_H 25 | 26 | /* struct for vector */ 27 | struct _vector 28 | { 29 | unsigned int max; /* max number of used slot */ 30 | unsigned int alloced; /* number of allocated slot */ 31 | void **index; /* index to data */ 32 | }; 33 | typedef struct _vector *vector; 34 | 35 | #define VECTOR_MIN_SIZE 1 36 | 37 | /* (Sometimes) usefull macros. This macro convert index expression to 38 | array expression. */ 39 | #define vector_slot(V,I) ((V)->index[(I)]) 40 | #define vector_max(V) ((V)->max) 41 | 42 | /* Prototypes. */ 43 | vector vector_init (unsigned int size); 44 | void vector_ensure (vector v, unsigned int num); 45 | int vector_empty_slot (vector v); 46 | int vector_set (vector v, void *val); 47 | int vector_set_index (vector v, unsigned int i, void *val); 48 | void vector_unset (vector v, unsigned int i); 49 | unsigned int vector_count (vector v); 50 | void vector_only_wrapper_free (vector v); 51 | void vector_only_index_free (void *index); 52 | void vector_free (vector v); 53 | vector vector_copy (vector v); 54 | 55 | void *vector_lookup (vector, unsigned int); 56 | void *vector_lookup_ensure (vector, unsigned int); 57 | 58 | #endif /* _ZEBRA_VECTOR_H */ 59 | -------------------------------------------------------------------------------- /lib/version.c: -------------------------------------------------------------------------------- 1 | 2 | char *host_name = ""; 3 | -------------------------------------------------------------------------------- /lib/version.h: -------------------------------------------------------------------------------- 1 | /* Zebra version 2 | * Copyright (C) 1997, 1999 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #ifndef _ZEBRA_VERSION_H 23 | #define _ZEBRA_VERSION_H 24 | 25 | #define ZEBRA_VERSION "0.95a" 26 | 27 | #define ZEBRA_BUG_ADDRESS "bug-zebra@gnu.org" 28 | 29 | extern char *host_name; 30 | 31 | void print_version(char *); 32 | pid_t pid_output (char *); 33 | pid_t pid_output_lock (char *); 34 | 35 | #ifndef HAVE_DAEMON 36 | int daemon(int, int); 37 | #endif 38 | 39 | #endif /* _ZEBRA_VERSION_H */ 40 | -------------------------------------------------------------------------------- /lib/vty.h: -------------------------------------------------------------------------------- 1 | /* Virtual terminal [aka TeletYpe] interface routine 2 | Copyright (C) 1997 Kunihiro Ishiguro 3 | 4 | This file is part of GNU Zebra. 5 | 6 | GNU Zebra is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the 8 | Free Software Foundation; either version 2, or (at your option) any 9 | later version. 10 | 11 | GNU Zebra is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | 02111-1307, USA. */ 20 | 21 | #ifndef _ZEBRA_VTY_H 22 | #define _ZEBRA_VTY_H 23 | 24 | #define VTY_BUFSIZ 512 25 | #define VTY_MAXHIST 20 26 | 27 | /* VTY struct. */ 28 | struct vty 29 | { 30 | /* File descripter of this vty. */ 31 | int fd; 32 | 33 | /* Is this vty connect to file or not */ 34 | enum {VTY_TERM, VTY_FILE, VTY_SHELL, VTY_SHELL_SERV} type; 35 | 36 | /* Node status of this vty */ 37 | int node; 38 | 39 | /* What address is this vty comming from. */ 40 | char *address; 41 | 42 | /* Privilege level of this vty. */ 43 | int privilege; 44 | 45 | /* Failure count */ 46 | int fail; 47 | 48 | /* Output buffer. */ 49 | struct buffer *obuf; 50 | 51 | /* Command input buffer */ 52 | char *buf; 53 | 54 | /* Command cursor point */ 55 | int cp; 56 | 57 | /* Command length */ 58 | int length; 59 | 60 | /* Command max length. */ 61 | int max; 62 | 63 | /* Histry of command */ 64 | char *hist[VTY_MAXHIST]; 65 | 66 | /* History lookup current point */ 67 | int hp; 68 | 69 | /* History insert end point */ 70 | int hindex; 71 | 72 | /* For current referencing point of interface, route-map, 73 | access-list etc... */ 74 | void *index; 75 | 76 | /* For multiple level index treatment such as key chain and key. */ 77 | void *index_sub; 78 | 79 | /* For escape character. */ 80 | unsigned char escape; 81 | 82 | /* Current vty status. */ 83 | enum {VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE, 84 | VTY_START, VTY_CONTINUE} status; 85 | 86 | /* IAC handling */ 87 | unsigned char iac; 88 | 89 | /* IAC SB handling */ 90 | unsigned char iac_sb_in_progress; 91 | struct buffer *sb_buffer; 92 | 93 | /* Window width/height. */ 94 | int width; 95 | int height; 96 | 97 | int scroll_one; 98 | 99 | /* Configure lines. */ 100 | int lines; 101 | 102 | /* Current executing function pointer. */ 103 | int (*func) (struct vty *, void *arg); 104 | 105 | /* Terminal monitor. */ 106 | int monitor; 107 | 108 | /* In configure mode. */ 109 | int config; 110 | 111 | /* Read and write thread. */ 112 | struct thread *t_read; 113 | struct thread *t_write; 114 | 115 | /* Timeout seconds and thread. */ 116 | unsigned long v_timeout; 117 | struct thread *t_timeout; 118 | 119 | /* Thread output function. */ 120 | struct thread *t_output; 121 | 122 | /* Output data pointer. */ 123 | int (*output_func) (struct vty *, int); 124 | void (*output_clean) (struct vty *); 125 | void *output_rn; 126 | unsigned long output_count; 127 | int output_type; 128 | void *output_arg; 129 | }; 130 | 131 | /* Integrated configuration file. */ 132 | #define INTEGRATE_DEFAULT_CONFIG "Zebra.conf" 133 | 134 | /* Small macro to determine newline is newline only or linefeed needed. */ 135 | #define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n") 136 | 137 | /* Default time out value */ 138 | #define VTY_TIMEOUT_DEFAULT 600 139 | 140 | /* Vty read buffer size. */ 141 | #define VTY_READ_BUFSIZ 512 142 | 143 | /* Directory separator. */ 144 | #ifndef DIRECTORY_SEP 145 | #define DIRECTORY_SEP '/' 146 | #endif /* DIRECTORY_SEP */ 147 | 148 | #ifndef IS_DIRECTORY_SEP 149 | #define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP) 150 | #endif 151 | 152 | /* GCC have printf type attribute check. */ 153 | #ifdef __GNUC__ 154 | #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) 155 | #else 156 | #define PRINTF_ATTRIBUTE(a,b) 157 | #endif /* __GNUC__ */ 158 | 159 | /* Utility macro to convert VTY argument to unsigned integer. */ 160 | #define VTY_GET_INTEGER(NAME,V,STR) \ 161 | { \ 162 | char *endptr = NULL; \ 163 | (V) = strtoul ((STR), &endptr, 10); \ 164 | if ((V) == ULONG_MAX || *endptr != '\0') \ 165 | { \ 166 | vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \ 167 | return CMD_WARNING; \ 168 | } \ 169 | } 170 | 171 | #define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \ 172 | { \ 173 | char *endptr = NULL; \ 174 | (V) = strtoul ((STR), &endptr, 10); \ 175 | if ((V) == ULONG_MAX || *endptr != '\0' \ 176 | || (V) < (MIN) || (V) > (MAX)) \ 177 | { \ 178 | vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \ 179 | return CMD_WARNING; \ 180 | } \ 181 | } 182 | 183 | /* Exported variables */ 184 | extern char integrate_default[]; 185 | 186 | /* Prototypes. */ 187 | void vty_init (void);// 188 | void vty_init_vtysh (void); 189 | void vty_reset (void);// 190 | void vty_finish (void);// 191 | struct vty *vty_new (void); 192 | int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3); 193 | void vty_read_config (char *, char *, char *);// 194 | void vty_time_print (struct vty *, int);// 195 | void vty_serv_sock (const char *, unsigned short, char *);// 196 | void vty_close (struct vty *);// 197 | char *vty_get_cwd (void);// 198 | void vty_log (const char *, const char *, va_list); 199 | int vty_config_lock (struct vty *);// 200 | int vty_config_unlock (struct vty *);// 201 | int vty_shell (struct vty *); 202 | int vty_shell_serv (struct vty *); 203 | void vty_hello (struct vty *); 204 | 205 | #endif /* _ZEBRA_VTY_H */ 206 | -------------------------------------------------------------------------------- /mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | # Author: Noah Friedman 4 | # Created: 1993-05-16 5 | # Public domain 6 | 7 | # $Id: mkinstalldirs,v 1.3 2002/03/08 12:44:47 akim Exp $ 8 | 9 | errstatus=0 10 | dirmode="" 11 | 12 | usage="\ 13 | Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..." 14 | 15 | # process command line arguments 16 | while test $# -gt 0 ; do 17 | case "${1}" in 18 | -h | --help | --h* ) # -h for help 19 | echo "${usage}" 1>&2; exit 0 ;; 20 | -m ) # -m PERM arg 21 | shift 22 | test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; } 23 | dirmode="${1}" 24 | shift ;; 25 | -- ) shift; break ;; # stop option processing 26 | -* ) echo "${usage}" 1>&2; exit 1 ;; # unknown option 27 | * ) break ;; # first non-opt arg 28 | esac 29 | done 30 | 31 | for file 32 | do 33 | if test -d "$file"; then 34 | shift 35 | else 36 | break 37 | fi 38 | done 39 | 40 | case $# in 41 | 0) exit 0 ;; 42 | esac 43 | 44 | case $dirmode in 45 | '') 46 | if mkdir -p -- . 2>/dev/null; then 47 | echo "mkdir -p -- $*" 48 | exec mkdir -p -- "$@" 49 | fi ;; 50 | *) 51 | if mkdir -m "$dirmode" -p -- . 2>/dev/null; then 52 | echo "mkdir -m $dirmode -p -- $*" 53 | exec mkdir -m "$dirmode" -p -- "$@" 54 | fi ;; 55 | esac 56 | 57 | for file 58 | do 59 | set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 60 | shift 61 | 62 | pathcomp= 63 | for d 64 | do 65 | pathcomp="$pathcomp$d" 66 | case "$pathcomp" in 67 | -* ) pathcomp=./$pathcomp ;; 68 | esac 69 | 70 | if test ! -d "$pathcomp"; then 71 | echo "mkdir $pathcomp" 72 | 73 | mkdir "$pathcomp" || lasterr=$? 74 | 75 | if test ! -d "$pathcomp"; then 76 | errstatus=$lasterr 77 | else 78 | if test ! -z "$dirmode"; then 79 | echo "chmod $dirmode $pathcomp" 80 | 81 | lasterr="" 82 | chmod "$dirmode" "$pathcomp" || lasterr=$? 83 | 84 | if test ! -z "$lasterr"; then 85 | errstatus=$lasterr 86 | fi 87 | fi 88 | fi 89 | fi 90 | 91 | pathcomp="$pathcomp/" 92 | done 93 | done 94 | 95 | exit $errstatus 96 | 97 | # Local Variables: 98 | # mode: shell-script 99 | # sh-indentation: 3 100 | # End: 101 | # mkinstalldirs ends here 102 | -------------------------------------------------------------------------------- /update-autotools: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # When local system does not have the latest autoconf/automake 4 | # -- Kunihiro Ishiguro 5 | # 6 | rm -f config.cache 7 | rm -f Makefile.in 8 | rm -f aclocal.m4 9 | rm -f config.h.in 10 | rm -f configure 11 | aclocal 12 | autoheader 13 | autoconf 14 | automake --foreign 15 | -------------------------------------------------------------------------------- /vtysh/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with Automake to create Makefile.in 2 | 3 | INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib 4 | DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" 5 | 6 | LIBS = @LIBS@ @CURSES@ @LIBPAM@ 7 | 8 | bin_PROGRAMS = vtysh 9 | 10 | vtysh_SOURCES = vtysh_main.c vtysh.c vtysh_cmd.c vtysh_user.c vtysh_config.c 11 | noinst_HEADERS = vtysh.h vtysh_user.h 12 | vtysh_LDADD = ../lib/libzebra.a 13 | 14 | sysconf_DATA = vtysh.conf.sample 15 | 16 | EXTRA_DIST = vtysh.conf.sample 17 | 18 | rebuild4: 19 | ../lib/keychain.c ../lib/routemap.c ../lib/filter.c ../lib/plist.c ../lib/distribute.c > vtysh_cmd.c 20 | 21 | rebuild: 22 | ../lib/keychain.c ../lib/routemap.c ../lib/filter.c ../lib/plist.c ../lib/distribute.c > vtysh_cmd.c 23 | -------------------------------------------------------------------------------- /vtysh/vtysh.conf.sample: -------------------------------------------------------------------------------- 1 | ! 2 | ! vtysh sample configuratin file 3 | ! 4 | !username kunihiro nopassword 5 | -------------------------------------------------------------------------------- /vtysh/vtysh.h: -------------------------------------------------------------------------------- 1 | /* Virtual terminal interface shell. 2 | * Copyright (C) 2000 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #ifndef VTYSH_H 23 | #define VTYSH_H 24 | 25 | #define VTYSH_ZEBRA 0x01 26 | #define VTYSH_ALL VTYSH_ZEBRA 27 | 28 | #define VTYSH_INDEX_ZEBRA 0 29 | #define VTYSH_INDEX_MAX 1 30 | 31 | /* UNIX domain socket path. */ 32 | #define ZEBRA_PATH "/tmp/.zebra" 33 | 34 | /* vtysh local configuration file. */ 35 | #define VTYSH_DEFAULT_CONFIG "vtysh.conf" 36 | 37 | void vtysh_init_vty (); 38 | void vtysh_init_cmd (); 39 | void vtysh_connect_all (); 40 | void vtysh_readline_init (); 41 | void vtysh_user_init (); 42 | 43 | void vtysh_execute (char *); 44 | void vtysh_execute_no_pager (char *); 45 | 46 | char *vtysh_prompt (); 47 | 48 | void vtysh_config_write (); 49 | 50 | int vtysh_config_from_file (struct vty *, FILE *); 51 | 52 | void vtysh_read_config (char *, char *, char *); 53 | 54 | void vtysh_config_parse (char *); 55 | 56 | void vtysh_config_dump (FILE *); 57 | 58 | void vtysh_config_init (); 59 | 60 | void vtysh_pager_init (); 61 | 62 | /* Child process execution flag. */ 63 | extern int execute_flag; 64 | 65 | extern struct vty *vty; 66 | 67 | #endif /* VTYSH_H */ 68 | -------------------------------------------------------------------------------- /vtysh/vtysh_cmd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "command.h" 3 | #include "vtysh.h" 4 | 5 | void 6 | vtysh_init_cmd () 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /vtysh/vtysh_config.c: -------------------------------------------------------------------------------- 1 | /* Configuration generator. 2 | Copyright (C) 2000 Kunihiro Ishiguro 3 | 4 | This file is part of GNU Zebra. 5 | 6 | GNU Zebra is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the 8 | Free Software Foundation; either version 2, or (at your option) any 9 | later version. 10 | 11 | GNU Zebra is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | 02111-1307, USA. */ 20 | 21 | #include 22 | 23 | #include "command.h" 24 | #include "linklist.h" 25 | #include "memory.h" 26 | 27 | #include "vtysh/vtysh.h" 28 | 29 | vector configvec; 30 | 31 | struct config 32 | { 33 | /* Configuration node name. */ 34 | char *name; 35 | 36 | /* Configuration string line. */ 37 | struct list *line; 38 | 39 | /* Configuration can be nest. */ 40 | struct config *config; 41 | 42 | /* Index of this config. */ 43 | u_int32_t index; 44 | }; 45 | 46 | struct list *config_top; 47 | 48 | int 49 | line_cmp (char *c1, char *c2) 50 | { 51 | return strcmp (c1, c2); 52 | } 53 | 54 | void 55 | line_del (char *line) 56 | { 57 | XFREE (MTYPE_VTYSH_CONFIG_LINE, line); 58 | } 59 | 60 | struct config * 61 | config_new () 62 | { 63 | struct config *config; 64 | config = XCALLOC (MTYPE_VTYSH_CONFIG, sizeof (struct config)); 65 | return config; 66 | } 67 | 68 | int 69 | config_cmp (struct config *c1, struct config *c2) 70 | { 71 | return strcmp (c1->name, c2->name); 72 | } 73 | 74 | void 75 | config_del (struct config* config) 76 | { 77 | list_delete (config->line); 78 | if (config->name) 79 | XFREE (MTYPE_VTYSH_CONFIG_LINE, config->name); 80 | XFREE (MTYPE_VTYSH_CONFIG, config); 81 | } 82 | 83 | struct config * 84 | config_get (int index, char *line) 85 | { 86 | struct config *config; 87 | struct config *config_loop; 88 | struct list *master; 89 | struct listnode *nn; 90 | 91 | config = config_loop = NULL; 92 | 93 | master = vector_lookup_ensure (configvec, index); 94 | 95 | if (! master) 96 | { 97 | master = list_new (); 98 | master->del = (void (*) (void *))config_del; 99 | master->cmp = (int (*)(void *, void *)) config_cmp; 100 | vector_set_index (configvec, index, master); 101 | } 102 | 103 | LIST_LOOP (master, config_loop, nn) 104 | { 105 | if (strcmp (config_loop->name, line) == 0) 106 | config = config_loop; 107 | } 108 | 109 | if (! config) 110 | { 111 | config = config_new (); 112 | config->line = list_new (); 113 | config->line->del = (void (*) (void *))line_del; 114 | config->line->cmp = (int (*)(void *, void *)) line_cmp; 115 | config->name = XSTRDUP (MTYPE_VTYSH_CONFIG_LINE, line); 116 | config->index = index; 117 | listnode_add (master, config); 118 | } 119 | return config; 120 | } 121 | 122 | void 123 | config_add_line (struct list *config, char *line) 124 | { 125 | listnode_add (config, XSTRDUP (MTYPE_VTYSH_CONFIG_LINE, line)); 126 | } 127 | 128 | void 129 | config_add_line_uniq (struct list *config, char *line) 130 | { 131 | struct listnode *nn; 132 | char *pnt; 133 | 134 | LIST_LOOP (config, pnt, nn) 135 | { 136 | if (strcmp (pnt, line) == 0) 137 | return; 138 | } 139 | listnode_add_sort (config, XSTRDUP (MTYPE_VTYSH_CONFIG_LINE, line)); 140 | } 141 | 142 | void 143 | vtysh_config_parse_line (char *line) 144 | { 145 | char c; 146 | static struct config *config = NULL; 147 | 148 | if (! line) 149 | return; 150 | 151 | c = line[0]; 152 | 153 | if (c == '\0') 154 | return; 155 | 156 | /* printf ("[%s]\n", line); */ 157 | 158 | switch (c) 159 | { 160 | case '!': 161 | case '#': 162 | break; 163 | case ' ': 164 | /* Store line to current configuration. */ 165 | if (config) 166 | { 167 | config_add_line (config->line, line); 168 | } 169 | else 170 | config_add_line (config_top, line); 171 | break; 172 | default: 173 | if (strncmp (line, "interface", strlen ("interface")) == 0) 174 | config = config_get (INTERFACE_NODE, line); 175 | else if (strncmp (line, "key", strlen ("key")) == 0) 176 | config = config_get (KEYCHAIN_NODE, line); 177 | else 178 | { 179 | if (strncmp (line, "log", strlen ("log")) == 0 180 | || strncmp (line, "hostname", strlen ("hostname")) == 0 181 | || strncmp (line, "password", strlen ("hostname")) == 0) 182 | config_add_line_uniq (config_top, line); 183 | else 184 | config_add_line (config_top, line); 185 | config = NULL; 186 | } 187 | break; 188 | } 189 | } 190 | 191 | void 192 | vtysh_config_parse (char *line) 193 | { 194 | char *begin; 195 | char *pnt; 196 | 197 | begin = pnt = line; 198 | 199 | while (*pnt != '\0') 200 | { 201 | if (*pnt == '\n') 202 | { 203 | *pnt++ = '\0'; 204 | vtysh_config_parse_line (begin); 205 | begin = pnt; 206 | } 207 | else 208 | { 209 | pnt++; 210 | } 211 | } 212 | } 213 | 214 | /* Macro to check delimiter is needed between each configuration line 215 | or not. */ 216 | #define NO_DELIMITER(I) \ 217 | ((I) == ACCESS_NODE || (I) == PREFIX_NODE || (I) == IP_NODE \ 218 | || (I) == AS_LIST_NODE || (I) == COMMUNITY_LIST_NODE || \ 219 | (I) == ACCESS_IPV6_NODE || (I) == PREFIX_IPV6_NODE) 220 | 221 | /* Display configuration to file pointer. */ 222 | void 223 | vtysh_config_dump (FILE *fp) 224 | { 225 | struct listnode *nn; 226 | struct listnode *nm; 227 | struct config *config; 228 | struct list *master; 229 | char *line; 230 | int i; 231 | 232 | LIST_LOOP (config_top, line, nn) 233 | { 234 | fprintf (fp, "%s\n", line); 235 | fflush (fp); 236 | } 237 | fprintf (fp, "!\n"); 238 | fflush (fp); 239 | 240 | for (i = 0; i < vector_max (configvec); i++) 241 | if ((master = vector_slot (configvec, i)) != NULL) 242 | { 243 | LIST_LOOP (master, config, nn) 244 | { 245 | fprintf (fp, "%s\n", config->name); 246 | fflush (fp); 247 | 248 | LIST_LOOP (config->line, line, nm) 249 | { 250 | fprintf (fp, "%s\n", line); 251 | fflush (fp); 252 | } 253 | if (! NO_DELIMITER (i)) 254 | { 255 | fprintf (fp, "!\n"); 256 | fflush (fp); 257 | } 258 | } 259 | if (NO_DELIMITER (i)) 260 | { 261 | fprintf (fp, "!\n"); 262 | fflush (fp); 263 | } 264 | } 265 | 266 | for (i = 0; i < vector_max (configvec); i++) 267 | if ((master = vector_slot (configvec, i)) != NULL) 268 | { 269 | list_delete (master); 270 | vector_slot (configvec, i) = NULL; 271 | } 272 | list_delete_all_node (config_top); 273 | } 274 | 275 | /* Read up configuration file from file_name. */ 276 | static void 277 | vtysh_read_file (FILE *confp) 278 | { 279 | int ret; 280 | struct vty *vty; 281 | 282 | vty = vty_new (); 283 | vty->fd = 0; /* stdout */ 284 | vty->type = VTY_TERM; 285 | vty->node = CONFIG_NODE; 286 | 287 | vtysh_execute_no_pager ("enable"); 288 | vtysh_execute_no_pager ("configure terminal"); 289 | 290 | /* Execute configuration file */ 291 | ret = vtysh_config_from_file (vty, confp); 292 | 293 | vtysh_execute_no_pager ("end"); 294 | vtysh_execute_no_pager ("disable"); 295 | 296 | vty_close (vty); 297 | 298 | if (ret != CMD_SUCCESS) 299 | { 300 | switch (ret) 301 | { 302 | case CMD_ERR_AMBIGUOUS: 303 | fprintf (stderr, "Ambiguous command.\n"); 304 | break; 305 | case CMD_ERR_NO_MATCH: 306 | fprintf (stderr, "There is no such command.\n"); 307 | break; 308 | } 309 | fprintf (stderr, "Error occured during reading below line.\n%s\n", 310 | vty->buf); 311 | exit (1); 312 | } 313 | } 314 | 315 | /* Read up configuration file from file_name. */ 316 | void 317 | vtysh_read_config (char *config_file, 318 | char *config_current_dir, 319 | char *config_default_dir) 320 | { 321 | char *cwd; 322 | FILE *confp = NULL; 323 | char *fullpath; 324 | 325 | /* If -f flag specified. */ 326 | if (config_file != NULL) 327 | { 328 | if (! IS_DIRECTORY_SEP (config_file[0])) 329 | { 330 | cwd = getcwd (NULL, MAXPATHLEN); 331 | fullpath = XMALLOC (MTYPE_TMP, 332 | strlen (cwd) + strlen (config_file) + 2); 333 | sprintf (fullpath, "%s/%s", cwd, config_file); 334 | } 335 | else 336 | fullpath = config_file; 337 | 338 | confp = fopen (fullpath, "r"); 339 | 340 | if (confp == NULL) 341 | { 342 | fprintf (stderr, "can't open configuration file [%s]\n", 343 | config_file); 344 | exit(1); 345 | } 346 | } 347 | else 348 | { 349 | /* Relative path configuration file open. */ 350 | if (config_current_dir) 351 | confp = fopen (config_current_dir, "r"); 352 | 353 | /* If there is no relative path exists, open system default file. */ 354 | if (confp == NULL) 355 | { 356 | confp = fopen (config_default_dir, "r"); 357 | if (confp == NULL) 358 | { 359 | fprintf (stderr, "can't open configuration file [%s]\n", 360 | config_default_dir); 361 | exit (1); 362 | } 363 | else 364 | fullpath = config_default_dir; 365 | } 366 | else 367 | { 368 | /* Rleative path configuration file. */ 369 | cwd = getcwd (NULL, MAXPATHLEN); 370 | fullpath = XMALLOC (MTYPE_TMP, 371 | strlen (cwd) + strlen (config_current_dir) + 2); 372 | sprintf (fullpath, "%s/%s", cwd, config_current_dir); 373 | } 374 | } 375 | vtysh_read_file (confp); 376 | 377 | fclose (confp); 378 | 379 | host_config_set (fullpath); 380 | } 381 | 382 | void 383 | vtysh_config_write (FILE *fp) 384 | { 385 | extern struct host host; 386 | 387 | if (host.name) 388 | fprintf (fp, "hostname %s\n", host.name); 389 | fprintf (fp, "!\n"); 390 | } 391 | 392 | void 393 | vtysh_config_init () 394 | { 395 | config_top = list_new (); 396 | config_top->del = (void (*) (void *))line_del; 397 | configvec = vector_init (1); 398 | } 399 | -------------------------------------------------------------------------------- /vtysh/vtysh_main.c: -------------------------------------------------------------------------------- 1 | /* Virtual terminal interface shell. 2 | * Copyright (C) 2000 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #include "version.h" 33 | #include "getopt.h" 34 | #include "command.h" 35 | 36 | #include "vtysh/vtysh.h" 37 | #include "vtysh/vtysh_user.h" 38 | 39 | /* VTY shell program name. */ 40 | char *progname; 41 | 42 | /* Configuration file name. Usually this is configurable, but vtysh 43 | has static configuration file only. */ 44 | char *config_file = NULL; 45 | 46 | /* Configuration file and directory. */ 47 | char *config_current = NULL; 48 | char config_default[] = SYSCONFDIR VTYSH_DEFAULT_CONFIG; 49 | 50 | /* Integrated configuration file. */ 51 | char *integrate_file = NULL; 52 | char *integrate_current = NULL; 53 | #if 0 54 | char integrate_default[] = SYSCONFDIR INTEGRATE_DEFAULT_CONFIG; 55 | #endif 56 | 57 | /* Flag for indicate executing child command. */ 58 | int execute_flag = 0; 59 | 60 | /* For sigsetjmp() & siglongjmp(). */ 61 | static sigjmp_buf jmpbuf; 62 | 63 | /* Flag for avoid recursive siglongjmp() call. */ 64 | static int jmpflag = 0; 65 | 66 | /* A static variable for holding the line. */ 67 | static char *line_read; 68 | 69 | /* Master of threads. */ 70 | struct thread_master *master; 71 | 72 | /* SIGTSTP handler. This function care user's ^Z input. */ 73 | void 74 | sigtstp (int sig) 75 | { 76 | /* Execute "end" command. */ 77 | vtysh_execute ("end"); 78 | 79 | /* Initialize readline. */ 80 | rl_initialize (); 81 | printf ("\n"); 82 | 83 | /* Check jmpflag for duplicate siglongjmp(). */ 84 | if (! jmpflag) 85 | return; 86 | 87 | jmpflag = 0; 88 | 89 | /* Back to main command loop. */ 90 | siglongjmp (jmpbuf, 1); 91 | } 92 | 93 | /* SIGINT handler. This function care user's ^Z input. */ 94 | void 95 | sigint (int sig) 96 | { 97 | /* Check this process is not child process. */ 98 | if (! execute_flag) 99 | { 100 | rl_initialize (); 101 | printf ("\n"); 102 | rl_forced_update_display (); 103 | } 104 | } 105 | 106 | /* Signale wrapper. */ 107 | RETSIGTYPE * 108 | signal_set (int signo, void (*func)(int)) 109 | { 110 | int ret; 111 | struct sigaction sig; 112 | struct sigaction osig; 113 | 114 | sig.sa_handler = func; 115 | sigemptyset (&sig.sa_mask); 116 | sig.sa_flags = 0; 117 | #ifdef SA_RESTART 118 | sig.sa_flags |= SA_RESTART; 119 | #endif /* SA_RESTART */ 120 | 121 | ret = sigaction (signo, &sig, &osig); 122 | 123 | if (ret < 0) 124 | return (SIG_ERR); 125 | else 126 | return (osig.sa_handler); 127 | } 128 | 129 | /* Initialization of signal handles. */ 130 | void 131 | signal_init () 132 | { 133 | signal_set (SIGINT, sigint); 134 | signal_set (SIGTSTP, sigtstp); 135 | signal_set (SIGPIPE, SIG_IGN); 136 | } 137 | 138 | /* Help information display. */ 139 | static void 140 | usage (int status) 141 | { 142 | if (status != 0) 143 | fprintf (stderr, "Try `%s --help' for more information.\n", progname); 144 | else 145 | { 146 | printf ("Usage : %s [OPTION...]\n\n\ 147 | Daemon which manages kernel routing table management and \ 148 | redistribution between different routing protocols.\n\n\ 149 | -b, --boot Execute boot startup configuration\n\ 150 | -e, --eval Execute argument as command\n\ 151 | -h, --help Display this help and exit\n\ 152 | \n\ 153 | Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS); 154 | } 155 | exit (status); 156 | } 157 | 158 | /* VTY shell options, we use GNU getopt library. */ 159 | struct option longopts[] = 160 | { 161 | { "boot", no_argument, NULL, 'b'}, 162 | { "eval", required_argument, NULL, 'e'}, 163 | { "help", no_argument, NULL, 'h'}, 164 | { 0 } 165 | }; 166 | 167 | /* Read a string, and return a pointer to it. Returns NULL on EOF. */ 168 | char * 169 | vtysh_rl_gets () 170 | { 171 | /* If the buffer has already been allocated, return the memory 172 | to the free pool. */ 173 | if (line_read) 174 | { 175 | free (line_read); 176 | line_read = NULL; 177 | } 178 | 179 | /* Get a line from the user. Change prompt according to node. XXX. */ 180 | line_read = readline (vtysh_prompt ()); 181 | 182 | /* If the line has any text in it, save it on the history. */ 183 | if (line_read && *line_read) 184 | add_history (line_read); 185 | 186 | return (line_read); 187 | } 188 | 189 | /* VTY shell main routine. */ 190 | int 191 | main (int argc, char **argv, char **env) 192 | { 193 | char *p; 194 | int opt; 195 | int eval_flag = 0; 196 | int boot_flag = 0; 197 | char *eval_line = NULL; 198 | char *integrated_file = NULL; 199 | 200 | /* Preserve name of myself. */ 201 | progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); 202 | 203 | /* Option handling. */ 204 | while (1) 205 | { 206 | opt = getopt_long (argc, argv, "be:h", longopts, 0); 207 | 208 | if (opt == EOF) 209 | break; 210 | 211 | switch (opt) 212 | { 213 | case 0: 214 | break; 215 | case 'b': 216 | boot_flag = 1; 217 | break; 218 | case 'e': 219 | eval_flag = 1; 220 | eval_line = optarg; 221 | break; 222 | case 'h': 223 | usage (0); 224 | break; 225 | case 'i': 226 | integrated_file = strdup (optarg); 227 | default: 228 | usage (1); 229 | break; 230 | } 231 | } 232 | 233 | /* Initialize user input buffer. */ 234 | line_read = NULL; 235 | 236 | /* Signal and others. */ 237 | signal_init (); 238 | 239 | /* Make vty structure and register commands. */ 240 | vtysh_init_vty (); 241 | vtysh_init_cmd (); 242 | vtysh_user_init (); 243 | vtysh_config_init (); 244 | 245 | vty_init_vtysh (); 246 | 247 | sort_node (); 248 | 249 | vtysh_connect_all (); 250 | 251 | /* Read vtysh configuration file. */ 252 | vtysh_read_config (config_file, config_current, config_default); 253 | 254 | /* If eval mode */ 255 | if (eval_flag) 256 | { 257 | vtysh_execute_no_pager (eval_line); 258 | exit (0); 259 | } 260 | 261 | /* Boot startup configuration file. */ 262 | if (boot_flag) 263 | { 264 | vtysh_read_config (integrate_file, integrate_current, integrate_default); 265 | exit (0); 266 | } 267 | 268 | vtysh_pager_init (); 269 | 270 | vtysh_readline_init (); 271 | 272 | vty_hello (vty); 273 | 274 | vtysh_auth (); 275 | 276 | /* Preparation for longjmp() in sigtstp(). */ 277 | sigsetjmp (jmpbuf, 1); 278 | jmpflag = 1; 279 | 280 | /* Main command loop. */ 281 | while (vtysh_rl_gets ()) 282 | vtysh_execute (line_read); 283 | 284 | printf ("\n"); 285 | 286 | /* Rest in peace. */ 287 | exit (0); 288 | } 289 | -------------------------------------------------------------------------------- /vtysh/vtysh_user.c: -------------------------------------------------------------------------------- 1 | /* User authentication for vtysh. 2 | * Copyright (C) 2000 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #include 23 | 24 | #include 25 | 26 | #ifdef USE_PAM 27 | #include 28 | #include 29 | #endif /* USE_PAM */ 30 | 31 | #include "memory.h" 32 | #include "linklist.h" 33 | #include "command.h" 34 | 35 | #ifdef USE_PAM 36 | static struct pam_conv conv = 37 | { 38 | misc_conv, 39 | NULL 40 | }; 41 | 42 | int 43 | vtysh_pam (char *user) 44 | { 45 | int ret; 46 | pam_handle_t *pamh = NULL; 47 | 48 | /* Start PAM. */ 49 | ret = pam_start("zebra", user, &conv, &pamh); 50 | /* printf ("ret %d\n", ret); */ 51 | 52 | /* Is user really user? */ 53 | if (ret == PAM_SUCCESS) 54 | ret = pam_authenticate (pamh, 0); 55 | /* printf ("ret %d\n", ret); */ 56 | 57 | #if 0 58 | /* Permitted access? */ 59 | if (ret == PAM_SUCCESS) 60 | ret = pam_acct_mgmt (pamh, 0); 61 | printf ("ret %d\n", ret); 62 | 63 | if (ret == PAM_AUTHINFO_UNAVAIL) 64 | ret = PAM_SUCCESS; 65 | #endif /* 0 */ 66 | 67 | /* This is where we have been authorized or not. */ 68 | #ifdef DEBUG 69 | if (ret == PAM_SUCCESS) 70 | printf("Authenticated\n"); 71 | else 72 | printf("Not Authenticated\n"); 73 | #endif /* DEBUG */ 74 | 75 | /* close Linux-PAM */ 76 | if (pam_end (pamh, ret) != PAM_SUCCESS) 77 | { 78 | pamh = NULL; 79 | fprintf(stderr, "vtysh_pam: failed to release authenticator\n"); 80 | exit(1); 81 | } 82 | 83 | return ret == PAM_SUCCESS ? 0 : 1; 84 | } 85 | #endif /* USE_PAM */ 86 | 87 | struct user 88 | { 89 | char *name; 90 | u_char nopassword; 91 | }; 92 | 93 | struct list *userlist; 94 | 95 | struct user * 96 | user_new () 97 | { 98 | struct user *user; 99 | user = XMALLOC (0, sizeof (struct user)); 100 | memset (user, 0, sizeof (struct user)); 101 | return user; 102 | } 103 | 104 | void 105 | user_free (struct user *user) 106 | { 107 | XFREE (0, user); 108 | } 109 | 110 | struct user * 111 | user_lookup (char *name) 112 | { 113 | struct listnode *nn; 114 | struct user *user; 115 | 116 | LIST_LOOP (userlist, user, nn) 117 | { 118 | if (strcmp (user->name, name) == 0) 119 | return user; 120 | } 121 | return NULL; 122 | } 123 | 124 | void 125 | user_config_write () 126 | { 127 | struct listnode *nn; 128 | struct user *user; 129 | 130 | LIST_LOOP (userlist, user, nn) 131 | { 132 | if (user->nopassword) 133 | printf (" username %s nopassword\n", user->name); 134 | } 135 | } 136 | 137 | struct user * 138 | user_get (char *name) 139 | { 140 | struct user *user; 141 | user = user_lookup (name); 142 | if (user) 143 | return user; 144 | 145 | user = user_new (); 146 | user->name = strdup (name); 147 | listnode_add (userlist, user); 148 | 149 | return user; 150 | } 151 | 152 | DEFUN (username_nopassword, 153 | username_nopassword_cmd, 154 | "username WORD nopassword", 155 | "\n" 156 | "\n" 157 | "\n") 158 | { 159 | struct user *user; 160 | user = user_get (argv[0]); 161 | user->nopassword = 1; 162 | return CMD_SUCCESS; 163 | } 164 | 165 | int 166 | vtysh_auth () 167 | { 168 | struct user *user; 169 | struct passwd *passwd; 170 | 171 | passwd = getpwuid (geteuid ()); 172 | 173 | user = user_lookup (passwd->pw_name); 174 | if (user && user->nopassword) 175 | /* Pass through */; 176 | else 177 | { 178 | #ifdef USE_PAM 179 | if (vtysh_pam (passwd->pw_name)) 180 | exit (0); 181 | #endif /* USE_PAM */ 182 | } 183 | return 0; 184 | } 185 | 186 | void 187 | vtysh_user_init () 188 | { 189 | userlist = list_new (); 190 | install_element (CONFIG_NODE, &username_nopassword_cmd); 191 | } 192 | -------------------------------------------------------------------------------- /vtysh/vtysh_user.h: -------------------------------------------------------------------------------- 1 | /* User authentication for vtysh. 2 | * Copyright (C) 2000 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #ifndef _VTYSH_USER_H 23 | #define _VTYSH_USER_H 24 | 25 | int vtysh_auth (); 26 | 27 | #endif /* _VTYSH_USER_H */ 28 | -------------------------------------------------------------------------------- /zebra/connected.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface's address and mask. 3 | * Copyright (C) 1997 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the 9 | * Free Software Foundation; either version 2, or (at your option) any 10 | * later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20 | * 02111-1307, USA. 21 | */ 22 | 23 | #ifndef _ZEBRA_CONNECTED_H 24 | #define _ZEBRA_CONNECTED_H 25 | 26 | struct connected * 27 | connected_check_ipv4 (struct interface *ifp, struct prefix *p); 28 | 29 | void 30 | connected_add_ipv4 (struct interface *ifp, int flags, struct in_addr *addr, 31 | int prefixlen, struct in_addr *broad, char *label); 32 | 33 | void 34 | connected_delete_ipv4 (struct interface *ifp, int flags, struct in_addr *addr, 35 | int prefixlen, struct in_addr *broad, char *label); 36 | 37 | void 38 | connected_up_ipv4 (struct interface *, struct connected *); 39 | void 40 | connected_down_ipv4 (struct interface *, struct connected *); 41 | 42 | #ifdef HAVE_IPV6 43 | struct connected * 44 | connected_check_ipv6 (struct interface *ifp, struct prefix *p); 45 | 46 | void 47 | connected_add_ipv6 (struct interface *ifp, struct in6_addr *address, 48 | int prefixlen, struct in6_addr *broad); 49 | void 50 | connected_delete_ipv6 (struct interface *ifp, struct in6_addr *address, 51 | int prefixlen, struct in6_addr *broad); 52 | void 53 | connected_up_ipv6 (struct interface *, struct connected *); 54 | 55 | void 56 | connected_down_ipv6 (struct interface *ifp, struct connected *); 57 | 58 | #endif /* HAVE_IPV6 */ 59 | 60 | #endif /*_ZEBRA_CONNECTED_H */ 61 | -------------------------------------------------------------------------------- /zebra/rib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Routing Information Base header 3 | * Copyright (C) 1997 Kunihiro Ishiguro 4 | * 5 | * This file is part of GNU Zebra. 6 | * 7 | * GNU Zebra is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the 9 | * Free Software Foundation; either version 2, or (at your option) any 10 | * later version. 11 | * 12 | * GNU Zebra is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20 | * 02111-1307, USA. 21 | */ 22 | 23 | #ifndef _ZEBRA_RIB_H 24 | #define _ZEBRA_RIB_H 25 | 26 | #define DISTANCE_INFINITY 255 27 | 28 | /* Routing information base. */ 29 | struct rib 30 | { 31 | /* Link list. */ 32 | struct rib *next; 33 | struct rib *prev; 34 | 35 | /* Type fo this route. */ 36 | int type; 37 | 38 | /* Which routing table */ 39 | int table; 40 | 41 | /* Distance. */ 42 | u_char distance; 43 | 44 | /* Flags of this route. This flag's definition is in lib/zebra.h 45 | ZEBRA_FLAG_* */ 46 | u_char flags; 47 | 48 | /* Metric */ 49 | u_int32_t metric; 50 | 51 | /* Uptime. */ 52 | time_t uptime; 53 | 54 | /* Refrence count. */ 55 | unsigned long refcnt; 56 | 57 | /* Nexthop information. */ 58 | u_char nexthop_num; 59 | u_char nexthop_active_num; 60 | u_char nexthop_fib_num; 61 | 62 | struct nexthop *nexthop; 63 | }; 64 | 65 | /* Static route information. */ 66 | struct static_ipv4 67 | { 68 | /* For linked list. */ 69 | struct static_ipv4 *prev; 70 | struct static_ipv4 *next; 71 | 72 | /* Administrative distance. */ 73 | u_char distance; 74 | 75 | /* Flag for this static route's type. */ 76 | u_char type; 77 | #define STATIC_IPV4_GATEWAY 1 78 | #define STATIC_IPV4_IFNAME 2 79 | #define STATIC_IPV4_BLACKHOLE 3 80 | 81 | /* Nexthop value. */ 82 | union 83 | { 84 | struct in_addr ipv4; 85 | char *ifname; 86 | } gate; 87 | }; 88 | 89 | #ifdef HAVE_IPV6 90 | /* Static route information. */ 91 | struct static_ipv6 92 | { 93 | /* For linked list. */ 94 | struct static_ipv6 *prev; 95 | struct static_ipv6 *next; 96 | 97 | /* Administrative distance. */ 98 | u_char distance; 99 | 100 | /* Flag for this static route's type. */ 101 | u_char type; 102 | #define STATIC_IPV6_GATEWAY 1 103 | #define STATIC_IPV6_GATEWAY_IFNAME 2 104 | #define STATIC_IPV6_IFNAME 3 105 | #define STATIC_IPV6_BLACKHOLE 4 106 | 107 | /* Nexthop value. */ 108 | struct in6_addr ipv6; 109 | char *ifname; 110 | }; 111 | #endif /* HAVE_IPV6 */ 112 | 113 | /* Nexthop structure. */ 114 | struct nexthop 115 | { 116 | struct nexthop *next; 117 | struct nexthop *prev; 118 | 119 | u_char type; 120 | #define NEXTHOP_TYPE_IFINDEX 1 /* Directly connected. */ 121 | #define NEXTHOP_TYPE_IFNAME 2 /* Interface route. */ 122 | #define NEXTHOP_TYPE_IPV4 3 /* IPv4 nexthop. */ 123 | #define NEXTHOP_TYPE_IPV4_IFINDEX 4 /* IPv4 nexthop with ifindex. */ 124 | #define NEXTHOP_TYPE_IPV4_IFNAME 5 /* IPv4 nexthop with ifname. */ 125 | #define NEXTHOP_TYPE_IPV6 6 /* IPv6 nexthop. */ 126 | #define NEXTHOP_TYPE_IPV6_IFINDEX 7 /* IPv6 nexthop with ifindex. */ 127 | #define NEXTHOP_TYPE_IPV6_IFNAME 8 /* IPv6 nexthop with ifname. */ 128 | #define NEXTHOP_TYPE_BLACKHOLE 9 /* Null0 nexthop. */ 129 | 130 | u_char flags; 131 | #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */ 132 | #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */ 133 | #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */ 134 | 135 | /* Interface index. */ 136 | unsigned int ifindex; 137 | char *ifname; 138 | 139 | /* Nexthop address or interface name. */ 140 | union 141 | { 142 | struct in_addr ipv4; 143 | #ifdef HAVE_IPV6 144 | struct in6_addr ipv6; 145 | #endif /* HAVE_IPV6*/ 146 | } gate; 147 | 148 | /* Recursive lookup nexthop. */ 149 | u_char rtype; 150 | unsigned int rifindex; 151 | union 152 | { 153 | struct in_addr ipv4; 154 | #ifdef HAVE_IPV6 155 | struct in6_addr ipv6; 156 | #endif /* HAVE_IPV6 */ 157 | } rgate; 158 | 159 | struct nexthop *indirect; 160 | }; 161 | 162 | /* Routing table instance. */ 163 | struct vrf 164 | { 165 | /* Identifier. This is same as routing table vector index. */ 166 | u_int32_t id; 167 | 168 | /* Routing table name. */ 169 | char *name; 170 | 171 | /* Description. */ 172 | char *desc; 173 | 174 | /* FIB identifier. */ 175 | u_char fib_id; 176 | 177 | /* Routing table. */ 178 | struct route_table *table[AFI_MAX][SAFI_MAX]; 179 | 180 | /* Static route configuration. */ 181 | struct route_table *stable[AFI_MAX][SAFI_MAX]; 182 | }; 183 | 184 | struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int); 185 | struct nexthop *nexthop_ifname_add (struct rib *, char *); 186 | struct nexthop *nexthop_blackhole_add (struct rib *); 187 | struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *); 188 | #ifdef HAVE_IPV6 189 | struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *); 190 | #endif /* HAVE_IPV6 */ 191 | 192 | struct vrf *vrf_lookup (u_int32_t); 193 | struct route_table *vrf_table (afi_t afi, safi_t safi, u_int32_t id); 194 | struct route_table *vrf_static_table (afi_t afi, safi_t safi, u_int32_t id); 195 | 196 | int 197 | rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p, 198 | struct in_addr *gate, unsigned int ifindex, u_int32_t vrf_id, 199 | u_int32_t, u_char); 200 | 201 | int 202 | rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *); 203 | 204 | int 205 | rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p, 206 | struct in_addr *gate, unsigned int ifindex, u_int32_t); 207 | 208 | struct rib * 209 | rib_match_ipv4 (struct in_addr); 210 | 211 | struct rib * 212 | rib_lookup_ipv4 (struct prefix_ipv4 *); 213 | 214 | void rib_update (); 215 | void rib_sweep_route (); 216 | void rib_close (); 217 | void rib_init (); 218 | 219 | int 220 | static_add_ipv4 (struct prefix *p, struct in_addr *gate, char *ifname, 221 | u_char distance, u_int32_t vrf_id); 222 | 223 | int 224 | static_delete_ipv4 (struct prefix *p, struct in_addr *gate, char *ifname, 225 | u_char distance, u_int32_t vrf_id); 226 | 227 | #ifdef HAVE_IPV6 228 | int 229 | rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p, 230 | struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id); 231 | 232 | int 233 | rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p, 234 | struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id); 235 | 236 | struct rib *rib_lookup_ipv6 (struct in6_addr *); 237 | 238 | struct rib *rib_match_ipv6 (struct in6_addr *); 239 | 240 | extern struct route_table *rib_table_ipv6; 241 | 242 | int 243 | static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, 244 | char *ifname, u_char distance, u_int32_t vrf_id); 245 | 246 | int 247 | static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, 248 | char *ifname, u_char distance, u_int32_t vrf_id); 249 | 250 | #endif /* HAVE_IPV6 */ 251 | 252 | #endif /*_ZEBRA_RIB_H */ 253 | -------------------------------------------------------------------------------- /zebra/zserv.h: -------------------------------------------------------------------------------- 1 | /* Zebra daemon server header. 2 | * Copyright (C) 1997, 98 Kunihiro Ishiguro 3 | * 4 | * This file is part of GNU Zebra. 5 | * 6 | * GNU Zebra is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2, or (at your option) any 9 | * later version. 10 | * 11 | * GNU Zebra is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | * 02111-1307, USA. 20 | */ 21 | 22 | #ifndef _ZEBRA_ZSERV_H 23 | #define _ZEBRA_ZSERV_H 24 | 25 | /* Default port information. */ 26 | #define ZEBRA_PORT 2600 27 | #define ZEBRA_VTY_PORT 2601 28 | #define ZEBRA_VTYSH_PATH "/tmp/.zebra" 29 | #define ZEBRA_SERV_PATH "/tmp/.zserv" 30 | 31 | /* Default configuration filename. */ 32 | #define DEFAULT_CONFIG_FILE "zebra.conf" 33 | 34 | /* Client structure. */ 35 | struct zserv 36 | { 37 | /* Client file descriptor. */ 38 | int sock; 39 | 40 | /* Input/output buffer to the client. */ 41 | struct stream *ibuf; 42 | struct stream *obuf; 43 | 44 | /* Threads for read/write. */ 45 | struct thread *t_read; 46 | struct thread *t_write; 47 | 48 | /* default routing table this client munges */ 49 | int rtm_table; 50 | 51 | /* This client's redistribute flag. */ 52 | u_char redist[ZEBRA_ROUTE_MAX]; 53 | 54 | /* Redistribute default route flag. */ 55 | u_char redist_default; 56 | 57 | /* Interface information. */ 58 | u_char ifinfo; 59 | }; 60 | 61 | /* Count prefix size from mask length */ 62 | #define PSIZE(a) (((a) + 7) / (8)) 63 | 64 | /* Prototypes. */ 65 | void zebra_init (); 66 | void zebra_if_init (); 67 | void hostinfo_get (); 68 | void rib_init (); 69 | void interface_list (); 70 | void kernel_init (); 71 | void route_read (); 72 | void rtadv_init (); 73 | void zebra_snmp_init (); 74 | 75 | int 76 | zsend_interface_add (struct zserv *, struct interface *); 77 | int 78 | zsend_interface_delete (struct zserv *, struct interface *); 79 | 80 | int 81 | zsend_interface_address_add (struct zserv *, struct interface *, 82 | struct connected *); 83 | 84 | int 85 | zsend_interface_address_delete (struct zserv *, struct interface *, 86 | struct connected *); 87 | 88 | int 89 | zsend_interface_up (struct zserv *, struct interface *); 90 | 91 | int 92 | zsend_interface_down (struct zserv *, struct interface *); 93 | 94 | int 95 | zsend_ipv4_add (struct zserv *client, int type, int flags, 96 | struct prefix_ipv4 *p, struct in_addr *nexthop, 97 | unsigned int ifindex); 98 | 99 | int 100 | zsend_ipv4_delete (struct zserv *client, int type, int flags, 101 | struct prefix_ipv4 *p, struct in_addr *nexthop, 102 | unsigned int ifindex); 103 | 104 | int 105 | zsend_ipv4_add_multipath (struct zserv *, struct prefix *, struct rib *); 106 | 107 | int 108 | zsend_ipv4_delete_multipath (struct zserv *, struct prefix *, struct rib *); 109 | 110 | #ifdef HAVE_IPV6 111 | int 112 | zsend_ipv6_add (struct zserv *client, int type, int flags, 113 | struct prefix_ipv6 *p, struct in6_addr *nexthop, 114 | unsigned int ifindex); 115 | 116 | int 117 | zsend_ipv6_delete (struct zserv *client, int type, int flags, 118 | struct prefix_ipv6 *p, struct in6_addr *nexthop, 119 | unsigned int ifindex); 120 | 121 | int 122 | zsend_ipv6_add_multipath (struct zserv *, struct prefix *, struct rib *); 123 | 124 | int 125 | zsend_ipv6_delete_multipath (struct zserv *, struct prefix *, struct rib *); 126 | 127 | #endif /* HAVE_IPV6 */ 128 | 129 | extern pid_t pid; 130 | extern pid_t old_pid; 131 | 132 | #endif /* _ZEBRA_ZEBRA_H */ 133 | --------------------------------------------------------------------------------