├── .cvsignore ├── Doc ├── INSTALL ├── NEWS ├── README ├── TODO ├── aclocal.m4 ├── bird.conf ├── client ├── Doc ├── Makefile ├── birdc.c ├── birdcl.c ├── client.c ├── client.h ├── cmds.m4 ├── commands.c └── util.c ├── conf ├── Doc ├── Makefile ├── cf-lex.l ├── conf.c ├── conf.h ├── confbase.Y ├── gen_commands.m4 ├── gen_keywords.m4 └── gen_parser.m4 ├── configure ├── configure.in ├── doc ├── Doc ├── LinuxDocTools.pm ├── Makefile ├── bird.conf.example ├── bird.sgml ├── kernel-doc ├── old │ ├── banner.tex │ └── status.tex ├── prog-foot.sgml ├── prog-head.sgml ├── prog-intro.sgml ├── prog-spell.sed ├── reply_codes ├── sbase │ ├── VERSION │ ├── dist │ │ ├── birddoc │ │ │ ├── groff │ │ │ │ └── mapping │ │ │ ├── html │ │ │ │ └── mapping │ │ │ └── latex2e │ │ │ │ └── mapping │ │ ├── fmt_html.pl │ │ ├── fmt_latex2e.pl │ │ └── fmt_txt.pl │ └── dtd │ │ ├── birddoc.dtd │ │ ├── catalog │ │ ├── common │ │ └── isoent ├── sgml2html ├── sgml2latex ├── sgml2txt ├── slides │ ├── Makefile │ ├── logo.eps │ ├── obr1.eps │ ├── obr2.eps │ ├── obr5.eps │ └── slides.tex ├── slt2001 │ ├── Makefile │ └── slt.tex └── tex │ ├── birddoc.sty │ ├── null.sty │ ├── qwertz.sty │ └── url.sty ├── filter ├── Doc ├── Makefile ├── config.Y ├── f-util.c ├── filter.c ├── filter.h ├── test.conf ├── test.conf.inc ├── test.conf2 ├── test6.conf ├── tree.c └── trie.c ├── lib ├── Doc ├── Modules ├── alloca.h ├── birdlib.h ├── bitops.c ├── bitops.h ├── buffer.h ├── checksum.c ├── checksum.h ├── event.c ├── event.h ├── fletcher16.h ├── hash.h ├── heap.h ├── ip.c ├── ip.h ├── lists.c ├── lists.h ├── md5.c ├── md5.h ├── mempool.c ├── patmatch.c ├── printf.c ├── resource.c ├── resource.h ├── resource.sgml ├── slab.c ├── slists.c ├── slists.h ├── socket.h ├── string.h ├── tbf.c ├── unaligned.h └── xmalloc.c ├── misc ├── Makefile ├── bird.init ├── bird.spec ├── cisco2list ├── ips.c └── stats ├── nest ├── Doc ├── Makefile ├── a-path.c ├── a-set.c ├── attrs.h ├── bfd.h ├── bird.h ├── cli.c ├── cli.h ├── cmds.c ├── cmds.h ├── config.Y ├── iface.c ├── iface.h ├── locks.c ├── locks.h ├── mrtdump.h ├── neighbor.c ├── password.c ├── password.h ├── proto-hooks.c ├── proto.c ├── proto.sgml ├── protocol.h ├── route.h ├── rt-attr.c ├── rt-dev.c ├── rt-dev.h ├── rt-fib.c ├── rt-roa.c └── rt-table.c ├── proto ├── Doc ├── bfd │ ├── Doc │ ├── Makefile │ ├── bfd.c │ ├── bfd.h │ ├── config.Y │ ├── io.c │ ├── io.h │ └── packets.c ├── bgp │ ├── Doc │ ├── Makefile │ ├── attrs.c │ ├── bgp.c │ ├── bgp.h │ ├── config.Y │ └── packets.c ├── ospf │ ├── Doc │ ├── Makefile │ ├── config.Y │ ├── dbdes.c │ ├── hello.c │ ├── iface.c │ ├── lsack.c │ ├── lsalib.c │ ├── lsalib.h │ ├── lsreq.c │ ├── lsupd.c │ ├── neighbor.c │ ├── ospf.c │ ├── ospf.h │ ├── packet.c │ ├── rt.c │ ├── rt.h │ ├── topology.c │ └── topology.h ├── pipe │ ├── Doc │ ├── Makefile │ ├── config.Y │ ├── pipe.c │ └── pipe.h ├── radv │ ├── Doc │ ├── Makefile │ ├── config.Y │ ├── packets.c │ ├── radv.c │ └── radv.h ├── rip │ ├── Doc │ ├── Makefile │ ├── auth.c │ ├── config.Y │ ├── rip.c │ └── rip.h └── static │ ├── Doc │ ├── Makefile │ ├── config.Y │ ├── static.c │ └── static.h ├── sysdep ├── Doc ├── autoconf.h.in ├── bsd │ ├── Modules │ ├── krt-sock.Y │ ├── krt-sock.c │ ├── krt-sys.h │ └── sysio.h ├── cf │ ├── README │ ├── bsd-v6.h │ ├── bsd.h │ ├── linux-v6.h │ └── linux.h ├── config.h ├── linux │ ├── Modules │ ├── krt-sys.h │ ├── netlink.Y │ ├── netlink.c │ ├── sysio.h │ └── syspriv.h ├── sysdep.sgml └── unix │ ├── Doc │ ├── Modules │ ├── config.Y │ ├── endian.h │ ├── io.c │ ├── krt.Y │ ├── krt.c │ ├── krt.h │ ├── log.c │ ├── main.c │ ├── random.c │ ├── timer.h │ └── unix.h └── tools ├── Makefile-top.in ├── Makefile.in ├── Rules.in ├── config.guess ├── config.sub ├── cvslog ├── gendist ├── install-sh ├── mergedirs └── progdoc /.cvsignore: -------------------------------------------------------------------------------- 1 | bird.conf 2 | -------------------------------------------------------------------------------- /Doc: -------------------------------------------------------------------------------- 1 | C doc 2 | C nest 3 | C conf 4 | C filter 5 | C proto 6 | C sysdep 7 | C lib 8 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | How to install BIRD 2 | =================== 3 | 4 | $ ./configure 5 | $ make 6 | # make install 7 | 8 | Default location for configuration file is /usr/local/etc/bird.conf and 9 | for control socket is /usr/local/var/run/bird.ctl . You can change that 10 | by --sysconfdir and --localstatedir configure options. 11 | 12 | 13 | Requirements 14 | ============ 15 | 16 | For compiling BIRD you need these programs and libraries: 17 | 18 | - GNU C Compiler 19 | - GNU Make 20 | - GNU Bison 21 | - GNU M4 22 | - Flex 23 | 24 | - ncurses library 25 | - GNU Readline library (2.1 or newer) 26 | 27 | For compiling BIRD documentation you also need: 28 | 29 | - Linuxdoc-Tools 30 | - LaTeX 31 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 |  BIRD Internet Routing Daemon with built in Route Leak protection 2 | 3 | 4 | 5 | 6 | This is a fork of BIRD Routing daemon (v1.5.0) with built in protection against 7 | BGP route leaks. Route leak is a network anomaly, when route learned from 8 | provider or peer is announced to another provider or peer. The effect of such 9 | issues could vary from increased network delays for victim (originator of prefix) 10 | to DoS for both victim and leaker. 11 | This BGP implementation supports full compatibility with other BGP implementations 12 | except the case where strict_mode is set by user. 13 | 14 | Currently, this branch supports mechanism for route leak prevention and 15 | procedure for mutual verification of peering relations, which are described in 16 | draft-ymbk-idr-bgp-open-policy. Also in branch eOTC_support was added mechanism 17 | for route leak detection, described in draft-ymbk-idr-bgp-eotr-policy. Finally, 18 | in branch ISP_border in addition you can find some mechanism for supporting new 19 | definition of border between two ISP, which is described in draft-ymbk-idr-isp-border. 20 | 21 | 22 | Change in BGP Configuration: 23 | In each BGP protocol section you must set a role option. Currently, there 24 | are 5 possible values for this option: 25 | 1) "provider" - sender is transit provider to neigbor; 26 | 2) "customer" - sender is customer of neigbor; 27 | 3) "peer" - sender and neighbor are peers; 28 | 4) "internal" - sender is part of an internal AS of an organsation which has multiple ASs; 29 | 5) "complex" - sender want to use per prefix role policies. 30 | Without setting a role in BGP protocol section you will receive error message 31 | from config parser. 32 | Also you could set strict_mode option in BGP protocol section. In this scenario 33 | BGP session with your neighbor will be established only if your neighbor also 34 | support Roles and corresponding Role is correct. 35 | 36 | 37 | BGP Protocol modification: 38 | There are two main changes in BGP protocol behaviour: 39 | 40 | 1. BGP Update modification: add mechanisms for route leak prevention using 41 | new nontransitive optional BGP PATH attribute iOTC (code 19 in this 42 | realization), which is following next set of rules: 43 | "a. The iOTC attribute MUST be added to all incoming routes if the 44 | receiver’s Role is Customer or Peer; 45 | b. The iOTC attribute MUST be added to all incoming routes if the 46 | receiver’s Role is Complex and prefix Role is Customer or Peer; 47 | c. Routes with the iOTC attribute set MUST NOT be announced if the 48 | sender’s Role is Customer or Peer; 49 | d. Routes with the iOTC attribute set MUST NOT be announced if the 50 | sender’s Role is Complex and prefix Role is Customer or Peer." 51 | 52 | 2. BGP Open modification: to OPEN messages add new capability option "Role" 53 | (Capability code 38 in current realization), in which broadcast value of Role configuration option. 54 | Establish connection only if speaker and its neighbor have appropriate pair of 55 | Roles: (provider, customer), (customer, provider), (peer, peer), (internal, internal), (complex, complex). 56 | 57 | 58 | How to install BIRD: 59 | 60 | 61 | ./configure 62 | make 63 | make install 64 | 65 | 66 | Example of configuration with new options can be seen in doc/bird.conf.example 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | Contact: mail@qrator.net 78 | Qrator Team. 79 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Core 2 | ~~~~ 3 | - socket open failure should not be fatal 4 | - &&,||: priorities 5 | - static: allow specifying a per-route filter program for setting route attributes? 6 | 7 | Globals 8 | ~~~~~~~ 9 | - right usage of DBG vs. debug 10 | - logging and tracing; use appropriate log levels 11 | - check incoming packets and log errors!! 12 | - check log calls for trailing newlines and log levels followed by comma 13 | - check if all protocols set proper packet priorities and TTL's. 14 | - try compiling with -Wunused 15 | - does everybody test return value of sk_open? 16 | - protocols: implement CLI hooks and per-procotol CLI commands 17 | - protocols: implement reconfigure hook 18 | - protocols: use locking 19 | - check use of system includes and sprintf() 20 | 21 | Various ideas 22 | ~~~~~~~~~~~~~ 23 | - client: Ctrl-R eats one more enter 24 | - bgp: timing of updates? 25 | - netlink: import Linux route attributes to our rta's, so that they can be filtered? 26 | - config: executable config files 27 | - filters: user defined attributes? 28 | - io: use poll if available 29 | - route recalculation timing and flap dampening [see RFC2439 for algorithms] 30 | - aggregate engine: standard route aggregation and summarization [RFC2519] 31 | - aggregate engine: injection of manually configured pseudo-static routes 32 | - generate default route if any working BGP connection exists (aggregate engine again?) 33 | - generate default route to IGP's (aggregate engine yet another time?) 34 | - look at RFC 2386 (QoS-based routing) 35 | - cli: show tables? 36 | 37 | OSPF 38 | ~~~~ 39 | - check incoming packets using neighbor cache 40 | - RFC2328 appendix E: Use a better algorithm 41 | - automatic generation of external route tags (RFC1403) 42 | - RFC2370 opaque LSA's 43 | - Limit export rate of external LSAs (like Gated does) 44 | - Bugfix in link state retransmission list (aging) 45 | - Graceful OSPF restart - RFC3623 46 | -------------------------------------------------------------------------------- /bird.conf: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an example configuration file. 3 | */ 4 | 5 | # Yet another comment 6 | 7 | router id 62.168.0.1; 8 | 9 | define xyzzy = (120+10); 10 | 11 | protocol device { 12 | disabled; 13 | # interface "eth*", "ppp*"; 14 | } 15 | 16 | protocol direct { 17 | } 18 | 19 | protocol kernel { 20 | disabled; 21 | # learn; # Learn all routes from the kernel 22 | # scan time 10; # Scan kernel tables every 10 seconds 23 | } 24 | 25 | protocol static { 26 | # disabled; 27 | 28 | route fec0:2::/64 blackhole; 29 | route fec0:3::/64 unreachable; 30 | route fec0:4::/64 prohibit; 31 | 32 | # route 0.0.0.0/0 via 195.113.31.113; 33 | # route 62.168.0.0/25 unreachable; 34 | # route 1.2.3.4/32 via 195.113.31.124; 35 | # route 10.0.0.0/8 unreachable; 36 | # route 10.1.1.0:255.255.255.0 via 62.168.0.3; 37 | # route 10.1.2.0:255.255.255.0 via 62.168.0.3; 38 | # route 10.1.3.0:255.255.255.0 via 62.168.0.4; 39 | # route 10.2.0.0/24 via "arc0"; 40 | export all; 41 | } 42 | 43 | protocol rip { 44 | } 45 | -------------------------------------------------------------------------------- /client/Doc: -------------------------------------------------------------------------------- 1 | H Client 2 | S client.c commands.c 3 | -------------------------------------------------------------------------------- /client/Makefile: -------------------------------------------------------------------------------- 1 | source=commands.c util.c client.c 2 | root-rel=../ 3 | dir-name=client 4 | 5 | clients := $(client) birdcl 6 | 7 | source-dep := $(source) $(addsuffix .c,$(clients)) 8 | 9 | subdir: $(addsuffix .o,$(clients)) 10 | 11 | include ../Rules 12 | -------------------------------------------------------------------------------- /client/birdc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Client - Readline variant I/O 3 | * 4 | * (c) 1999--2004 Martin Mares 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "nest/bird.h" 19 | #include "lib/resource.h" 20 | #include "lib/string.h" 21 | #include "client/client.h" 22 | 23 | static int input_hidden_end; 24 | static int prompt_active; 25 | 26 | /*** Input ***/ 27 | 28 | /* HACK: libreadline internals we need to access */ 29 | extern int _rl_vis_botlin; 30 | extern void _rl_move_vert(int); 31 | 32 | static void 33 | add_history_dedup(char *cmd) 34 | { 35 | /* Add history line if it differs from the last one */ 36 | HIST_ENTRY *he = history_get(history_length); 37 | if (!he || strcmp(he->line, cmd)) 38 | add_history(cmd); 39 | } 40 | 41 | static void 42 | input_got_line(char *cmd_buffer) 43 | { 44 | if (!cmd_buffer) 45 | { 46 | cleanup(); 47 | exit(0); 48 | } 49 | 50 | if (cmd_buffer[0]) 51 | { 52 | add_history_dedup(cmd_buffer); 53 | submit_command(cmd_buffer); 54 | } 55 | 56 | free(cmd_buffer); 57 | } 58 | 59 | void 60 | input_start_list(void) 61 | { 62 | /* Leave the currently edited line and make space for listing */ 63 | _rl_move_vert(_rl_vis_botlin); 64 | #ifdef HAVE_RL_CRLF 65 | rl_crlf(); 66 | #endif 67 | } 68 | 69 | void 70 | input_stop_list(void) 71 | { 72 | /* Reprint the currently edited line after listing */ 73 | rl_on_new_line(); 74 | rl_redisplay(); 75 | } 76 | 77 | static int 78 | input_complete(int arg UNUSED, int key UNUSED) 79 | { 80 | static int complete_flag; 81 | char buf[256]; 82 | 83 | if (rl_last_func != input_complete) 84 | complete_flag = 0; 85 | switch (cmd_complete(rl_line_buffer, rl_point, buf, complete_flag)) 86 | { 87 | case 0: 88 | complete_flag = 1; 89 | break; 90 | case 1: 91 | rl_insert_text(buf); 92 | break; 93 | default: 94 | complete_flag = 1; 95 | #ifdef HAVE_RL_DING 96 | rl_ding(); 97 | #endif 98 | } 99 | return 0; 100 | } 101 | 102 | static int 103 | input_help(int arg, int key UNUSED) 104 | { 105 | int i, in_string, in_bracket; 106 | 107 | if (arg != 1) 108 | return rl_insert(arg, '?'); 109 | 110 | in_string = in_bracket = 0; 111 | for (i = 0; i < rl_point; i++) 112 | { 113 | 114 | if (rl_line_buffer[i] == '"') 115 | in_string = ! in_string; 116 | else if (! in_string) 117 | { 118 | if (rl_line_buffer[i] == '[') 119 | in_bracket++; 120 | else if (rl_line_buffer[i] == ']') 121 | in_bracket--; 122 | } 123 | } 124 | 125 | /* `?' inside string or path -> insert */ 126 | if (in_string || in_bracket) 127 | return rl_insert(1, '?'); 128 | 129 | rl_begin_undo_group(); /* HACK: We want to display `?' at point position */ 130 | rl_insert_text("?"); 131 | rl_redisplay(); 132 | rl_end_undo_group(); 133 | input_start_list(); 134 | cmd_help(rl_line_buffer, rl_point); 135 | rl_undo_command(1, 0); 136 | input_stop_list(); 137 | return 0; 138 | } 139 | 140 | void 141 | input_init(void) 142 | { 143 | rl_readline_name = "birdc"; 144 | rl_add_defun("bird-complete", input_complete, '\t'); 145 | rl_add_defun("bird-help", input_help, '?'); 146 | rl_callback_handler_install("bird> ", input_got_line); 147 | 148 | // rl_get_screen_size(); 149 | term_lns = LINES; 150 | term_cls = COLS; 151 | 152 | prompt_active = 1; 153 | 154 | // readline library does strange things when stdin is nonblocking. 155 | // if (fcntl(0, F_SETFL, O_NONBLOCK) < 0) 156 | // die("fcntl: %m"); 157 | } 158 | 159 | static void 160 | input_reveal(void) 161 | { 162 | /* need this, otherwise some lib seems to eat pending output when 163 | the prompt is displayed */ 164 | fflush(stdout); 165 | tcdrain(STDOUT_FILENO); 166 | 167 | rl_end = input_hidden_end; 168 | rl_expand_prompt("bird> "); 169 | rl_forced_update_display(); 170 | 171 | prompt_active = 1; 172 | } 173 | 174 | static void 175 | input_hide(void) 176 | { 177 | input_hidden_end = rl_end; 178 | rl_end = 0; 179 | rl_expand_prompt(""); 180 | rl_redisplay(); 181 | 182 | prompt_active = 0; 183 | } 184 | 185 | void 186 | input_notify(int prompt) 187 | { 188 | if (prompt == prompt_active) 189 | return; 190 | 191 | if (prompt) 192 | input_reveal(); 193 | else 194 | input_hide(); 195 | } 196 | 197 | void 198 | input_read(void) 199 | { 200 | rl_callback_read_char(); 201 | } 202 | 203 | void 204 | more_begin(void) 205 | { 206 | } 207 | 208 | void 209 | more_end(void) 210 | { 211 | } 212 | 213 | void 214 | cleanup(void) 215 | { 216 | if (init) 217 | return; 218 | 219 | input_hide(); 220 | rl_callback_handler_remove(); 221 | } 222 | -------------------------------------------------------------------------------- /client/birdcl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Client - Light variant I/O 3 | * 4 | * (c) 1999--2004 Martin Mares 5 | * (c) 2013 Tomas Hlavacek 6 | * 7 | * Can be freely distributed and used under the terms of the GNU GPL. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | #include "nest/bird.h" 19 | #include "lib/resource.h" 20 | #include "lib/string.h" 21 | #include "client/client.h" 22 | #include "sysdep/unix/unix.h" 23 | 24 | #define INPUT_BUF_LEN 2048 25 | 26 | struct termios tty_save; 27 | 28 | void 29 | input_start_list(void) 30 | { 31 | /* Empty in non-ncurses version. */ 32 | } 33 | 34 | void 35 | input_stop_list(void) 36 | { 37 | /* Empty in non-ncurses version. */ 38 | } 39 | 40 | void 41 | input_notify(int prompt) 42 | { 43 | /* No ncurses -> no status to reveal/hide, print prompt manually. */ 44 | if (!prompt) 45 | return; 46 | 47 | printf("bird> "); 48 | fflush(stdout); 49 | } 50 | 51 | 52 | static int 53 | lastnb(char *str, int i) 54 | { 55 | while (i--) 56 | if ((str[i] != ' ') && (str[i] != '\t')) 57 | return str[i]; 58 | 59 | return 0; 60 | } 61 | 62 | void 63 | input_read(void) 64 | { 65 | char buf[INPUT_BUF_LEN]; 66 | 67 | if ((fgets(buf, INPUT_BUF_LEN, stdin) == NULL) || (buf[0] == 0)) 68 | { 69 | putchar('\n'); 70 | cleanup(); 71 | exit(0); 72 | } 73 | 74 | int l = strlen(buf); 75 | if ((l+1) == INPUT_BUF_LEN) 76 | { 77 | printf("Input too long.\n"); 78 | return; 79 | } 80 | 81 | if (buf[l-1] == '\n') 82 | buf[--l] = '\0'; 83 | 84 | if (!interactive) 85 | printf("%s\n", buf); 86 | 87 | if (l == 0) 88 | return; 89 | 90 | if (lastnb(buf, l) == '?') 91 | { 92 | cmd_help(buf, strlen(buf)); 93 | return; 94 | } 95 | 96 | submit_command(buf); 97 | } 98 | 99 | static struct termios stored_tty; 100 | static int more_active = 0; 101 | 102 | void 103 | more_begin(void) 104 | { 105 | static struct termios tty; 106 | 107 | tty = stored_tty; 108 | tty.c_lflag &= (~ECHO); 109 | tty.c_lflag &= (~ICANON); 110 | 111 | if (tcsetattr (0, TCSANOW, &tty) < 0) 112 | die("tcsetattr: %m"); 113 | 114 | more_active = 1; 115 | } 116 | 117 | void 118 | more_end(void) 119 | { 120 | more_active = 0; 121 | 122 | if (tcsetattr (0, TCSANOW, &stored_tty) < 0) 123 | die("tcsetattr: %m"); 124 | } 125 | 126 | static void 127 | sig_handler(int signal) 128 | { 129 | cleanup(); 130 | exit(0); 131 | } 132 | 133 | void 134 | input_init(void) 135 | { 136 | if (!interactive) 137 | return; 138 | 139 | if (tcgetattr(0, &stored_tty) < 0) 140 | die("tcgetattr: %m"); 141 | 142 | if (signal(SIGINT, sig_handler) == SIG_IGN) 143 | signal(SIGINT, SIG_IGN); 144 | if (signal(SIGTERM, sig_handler) == SIG_IGN) 145 | signal(SIGTERM, SIG_IGN); 146 | 147 | struct winsize tws; 148 | if (ioctl(0, TIOCGWINSZ, &tws) == 0) 149 | { 150 | term_lns = tws.ws_row; 151 | term_cls = tws.ws_col; 152 | } 153 | } 154 | 155 | void 156 | cleanup(void) 157 | { 158 | if (more_active) 159 | more_end(); 160 | } 161 | -------------------------------------------------------------------------------- /client/client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Client 3 | * 4 | * (c) 1999--2000 Martin Mares 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | 10 | extern int init, busy, interactive; 11 | extern int term_lns, term_cls; 12 | 13 | /* birdc.c / birdcl.c */ 14 | 15 | void input_start_list(void); 16 | void input_stop_list(void); 17 | 18 | void input_init(void); 19 | void input_notify(int prompt); 20 | void input_read(void); 21 | 22 | void more_begin(void); 23 | void more_end(void); 24 | 25 | void cleanup(void); 26 | 27 | /* commands.c */ 28 | 29 | void cmd_build_tree(void); 30 | void cmd_help(char *cmd, int len); 31 | int cmd_complete(char *cmd, int len, char *buf, int again); 32 | char *cmd_expand(char *cmd); 33 | 34 | /* client.c */ 35 | 36 | void submit_command(char *cmd_raw); 37 | -------------------------------------------------------------------------------- /client/cmds.m4: -------------------------------------------------------------------------------- 1 | # 2 | # BIRD -- Internal Commands Of The Client 3 | # 4 | # (c) 2000 Martin Mares 5 | # 6 | # Can be freely distributed and used under the terms of the GNU GPL. 7 | # 8 | 9 | CF_CLI(QUIT,,, [[Quit the client]]) 10 | CF_CLI(EXIT,,, [[Exit the client]]) 11 | CF_CLI(HELP,,, [[Description of the help system]]) 12 | -------------------------------------------------------------------------------- /client/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Client -- Utility Functions 3 | * 4 | * (c) 1999--2000 Martin Mares 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "nest/bird.h" 14 | #include "lib/string.h" 15 | #include "client/client.h" 16 | 17 | /* Client versions of logging functions */ 18 | 19 | static void 20 | vlog(const char *msg, va_list args) 21 | { 22 | char buf[1024]; 23 | 24 | if (bvsnprintf(buf, sizeof(buf)-1, msg, args) < 0) 25 | bsprintf(buf + sizeof(buf) - 100, " ... "); 26 | fputs(buf, stderr); 27 | fputc('\n', stderr); 28 | } 29 | 30 | void 31 | bug(const char *msg, ...) 32 | { 33 | va_list args; 34 | 35 | va_start(args, msg); 36 | cleanup(); 37 | fputs("Internal error: ", stderr); 38 | vlog(msg, args); 39 | vfprintf(stderr, msg, args); 40 | exit(1); 41 | } 42 | 43 | void 44 | die(const char *msg, ...) 45 | { 46 | va_list args; 47 | 48 | va_start(args, msg); 49 | cleanup(); 50 | vlog(msg, args); 51 | exit(1); 52 | } 53 | -------------------------------------------------------------------------------- /conf/Doc: -------------------------------------------------------------------------------- 1 | H Configuration 2 | S conf.c 3 | S cf-lex.l 4 | -------------------------------------------------------------------------------- /conf/Makefile: -------------------------------------------------------------------------------- 1 | source=cf-parse.tab.c cf-lex.c conf.c 2 | root-rel=../ 3 | 4 | include ../Rules 5 | 6 | conf-src=$(srcdir)/conf 7 | conf-fragments=$(conf-src)/confbase.Y @CONFS@ $(addsuffix /config.Y,$(static-dir-paths)) 8 | 9 | ifdef DEBUG 10 | BISON_DEBUG=-t 11 | #FLEX_DEBUG=-d 12 | endif 13 | 14 | cf-parse.tab.h: cf-parse.tab.c 15 | 16 | cf-parse.tab.c: cf-parse.y 17 | $(BISON) -bcf-parse -dv -pcf_ $(BISON_DEBUG) cf-parse.y 18 | 19 | cf-parse.y: $(conf-fragments) $(conf-src)/gen_parser.m4 20 | $(M4) -P $(conf-src)/gen_parser.m4 $(conf-fragments) >cf-parse.y 21 | 22 | keywords.h: $(conf-fragments) $(conf-src)/gen_keywords.m4 23 | $(M4) -P $(conf-src)/gen_keywords.m4 $(conf-fragments) >keywords.h 24 | 25 | commands.h: $(conf-fragments) $(conf-src)/gen_commands.m4 $(srcdir)/client/cmds.m4 26 | $(M4) -P $(conf-src)/gen_commands.m4 $(srcdir)/client/cmds.m4 $(conf-fragments) | sort >commands.h 27 | 28 | cf-lex.c: cf-lex.l 29 | $(FLEX) $(FLEX_DEBUG) -s -B -8 -ocf-lex.c -Pcf_ cf-lex.l 30 | 31 | depend: keywords.h commands.h cf-parse.tab.c cf-lex.c 32 | -------------------------------------------------------------------------------- /conf/confbase.Y: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Configuration Parser Top 3 | * 4 | * (c) 1998--2000 Martin Mares 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | CF_HDR 10 | 11 | #define PARSER 1 12 | 13 | #include "nest/bird.h" 14 | #include "conf/conf.h" 15 | #include "lib/resource.h" 16 | #include "lib/socket.h" 17 | #include "lib/timer.h" 18 | #include "lib/string.h" 19 | #include "nest/protocol.h" 20 | #include "nest/iface.h" 21 | #include "nest/route.h" 22 | #include "nest/cli.h" 23 | #include "filter/filter.h" 24 | 25 | /* FIXME: Turn on YYERROR_VERBOSE and work around lots of bison bugs? */ 26 | 27 | CF_DEFINES 28 | 29 | static void 30 | check_u16(unsigned val) 31 | { 32 | if (val > 0xFFFF) 33 | cf_error("Value %d out of range (0-65535)", val); 34 | } 35 | 36 | CF_DECLS 37 | 38 | %union { 39 | int i; 40 | u32 i32; 41 | ip_addr a; 42 | struct symbol *s; 43 | char *t; 44 | struct rtable_config *r; 45 | struct f_inst *x; 46 | struct role_map *rm; 47 | struct filter *f; 48 | struct f_tree *e; 49 | struct f_trie *trie; 50 | struct f_val v; 51 | struct f_path_mask *h; 52 | struct password_item *p; 53 | struct rt_show_data *ra; 54 | struct roa_show_data *ro; 55 | struct sym_show_data *sd; 56 | struct lsadb_show_data *ld; 57 | struct iface *iface; 58 | struct roa_table *rot; 59 | void *g; 60 | bird_clock_t time; 61 | struct prefix px; 62 | struct proto_spec ps; 63 | struct timeformat *tf; 64 | } 65 | 66 | %token END CLI_MARKER INVALID_TOKEN ELSECOL DDOT 67 | %token GEQ LEQ NEQ AND OR 68 | %token PO PC 69 | %token NUM ENUM 70 | %token RTRID 71 | %token IPA 72 | %token SYM 73 | %token TEXT 74 | %type ipa_scope 75 | 76 | %type expr bool pxlen 77 | %type expr_us 78 | %type ipa 80 | %type prefix prefix_or_ipa 81 | %type text 82 | %type text_or_none 83 | 84 | %nonassoc PREFIX_DUMMY 85 | %left AND OR 86 | %nonassoc '=' '<' '>' '~' GEQ LEQ NEQ PO PC 87 | %left '+' '-' 88 | %left '*' '/' '%' 89 | %left '!' 90 | %nonassoc '.' 91 | 92 | CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT) 93 | 94 | CF_GRAMMAR 95 | 96 | /* Basic config file structure */ 97 | 98 | config: conf_entries END { return 0; } 99 | | CLI_MARKER cli_cmd { return 0; } 100 | ; 101 | 102 | conf_entries: 103 | /* EMPTY */ 104 | | conf_entries conf 105 | ; 106 | 107 | CF_ADDTO(conf, ';') 108 | 109 | 110 | /* Constant expressions */ 111 | 112 | CF_ADDTO(conf, definition) 113 | definition: 114 | DEFINE SYM '=' term ';' { 115 | struct f_val *val = cfg_alloc(sizeof(struct f_val)); 116 | *val = f_eval($4, cfg_mem); 117 | if (val->type == T_RETURN) cf_error("Runtime error"); 118 | cf_define_symbol($2, SYM_CONSTANT | val->type, val); 119 | } 120 | ; 121 | 122 | expr: 123 | NUM 124 | | '(' term ')' { $$ = f_eval_int($2); } 125 | | SYM { 126 | if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number expected"); 127 | $$ = SYM_VAL($1).i; } 128 | ; 129 | 130 | 131 | expr_us: 132 | expr S { $$ = (u32) $1 * 1000000; } 133 | | expr MS { $$ = (u32) $1 * 1000; } 134 | | expr US { $$ = (u32) $1 * 1; } 135 | ; 136 | 137 | /* expr_u16: expr { check_u16($1); $$ = $1; }; */ 138 | 139 | /* Switches */ 140 | 141 | bool: 142 | expr {$$ = !!$1; } 143 | | ON { $$ = 1; } 144 | | YES { $$ = 1; } 145 | | OFF { $$ = 0; } 146 | | NO { $$ = 0; } 147 | | /* Silence means agreement */ { $$ = 1; } 148 | ; 149 | 150 | /* Addresses, prefixes and netmasks */ 151 | 152 | ipa: 153 | IPA 154 | | SYM { 155 | if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected"); 156 | $$ = SYM_VAL($1).px.ip; 157 | } 158 | ; 159 | 160 | ipa_scope: 161 | /* empty */ { $$ = NULL; } 162 | | '%' SYM { $$ = if_get_by_name($2->name); } 163 | ; 164 | 165 | prefix: 166 | ipa pxlen { 167 | if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix"); 168 | $$.addr = $1; $$.len = $2; 169 | } 170 | ; 171 | 172 | prefix_or_ipa: 173 | prefix 174 | | ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; } 175 | ; 176 | 177 | pxlen: 178 | '/' expr { 179 | if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2); 180 | $$ = $2; 181 | } 182 | | ':' ipa { 183 | $$ = ipa_masklen($2); 184 | if ($$ < 0) cf_error("Invalid netmask %I", $2); 185 | } 186 | ; 187 | 188 | datetime: 189 | TEXT { 190 | $$ = tm_parse_datetime($1); 191 | if (!$$) 192 | cf_error("Invalid date and time"); 193 | } 194 | ; 195 | 196 | text: 197 | TEXT 198 | | SYM { 199 | if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String expected"); 200 | $$ = SYM_VAL($1).s; 201 | } 202 | ; 203 | 204 | text_or_none: 205 | TEXT { $$ = $1; } 206 | | { $$ = NULL; } 207 | ; 208 | 209 | CF_CODE 210 | 211 | CF_END 212 | -------------------------------------------------------------------------------- /conf/gen_commands.m4: -------------------------------------------------------------------------------- 1 | m4_divert(-1)m4_dnl 2 | # 3 | # BIRD -- Generator of CLI Command List 4 | # 5 | # (c) 2000 Martin Mares 6 | # 7 | # Can be freely distributed and used under the terms of the GNU GPL. 8 | # 9 | 10 | m4_define(CF_CLI, `m4_divert(0){ "m4_translit($1,A-Z,a-z)", "$3", "$4", 1 }, 11 | m4_divert(-1)') 12 | 13 | m4_define(CF_CLI_CMD, `m4_divert(0){ "m4_translit($1,A-Z,a-z)", "$2", "$3", 1 }, 14 | m4_divert(-1)') 15 | 16 | m4_define(CF_CLI_HELP, `m4_divert(0){ "m4_translit($1,A-Z,a-z)", "$2", "$3", 0 }, 17 | m4_divert(-1)') 18 | 19 | # As we are processing C source, we must access all M4 primitives via 20 | # m4_* and also set different quoting convention: `[[' and ']]' 21 | m4_changequote([[,]]) 22 | -------------------------------------------------------------------------------- /conf/gen_keywords.m4: -------------------------------------------------------------------------------- 1 | m4_divert(-1)m4_dnl 2 | # 3 | # BIRD -- Generator of Configuration Keyword List 4 | # 5 | # (c) 1998--2000 Martin Mares 6 | # 7 | # Can be freely distributed and used under the terms of the GNU GPL. 8 | # 9 | 10 | # Common aliases 11 | m4_define(DNL, `m4_dnl') 12 | 13 | # Diversions used: 14 | # 1 keywords 15 | 16 | # Simple iterator 17 | m4_define(CF_itera, `m4_ifelse($#, 1, [[CF_iter($1)]], [[CF_iter($1)[[]]CF_itera(m4_shift($@))]])') 18 | m4_define(CF_iterate, `m4_define([[CF_iter]], m4_defn([[$1]]))CF_itera($2)') 19 | 20 | # We include all the headers 21 | m4_define(CF_HDR, `m4_divert(0)') 22 | m4_define(CF_DECLS, `m4_divert(-1)') 23 | m4_define(CF_DEFINES, `m4_divert(-1)') 24 | 25 | # Keywords are translated to C initializers 26 | m4_define(CF_handle_kw, `m4_divert(1){ "m4_translit($1,[[A-Z]],[[a-z]])", $1, NULL }, 27 | m4_divert(-1)') 28 | m4_define(CF_keywd, `m4_ifdef([[CF_tok_$1]],,[[m4_define([[CF_tok_$1]],1)CF_handle_kw($1)]])') 29 | m4_define(CF_KEYWORDS, `m4_define([[CF_toks]],[[]])CF_iterate([[CF_keywd]], [[$@]])m4_ifelse(CF_toks,,,%token[[]]CF_toks 30 | )DNL') 31 | 32 | # CLI commands generate keywords as well 33 | m4_define(CF_CLI, `CF_KEYWORDS(m4_translit($1, [[ ]], [[,]])) 34 | ') 35 | 36 | # Enums are translated to C initializers: use CF_ENUM(typename, prefix, values) 37 | m4_define(CF_enum, `m4_divert(1){ "CF_enum_prefix[[]]$1", -((CF_enum_type<<16) | CF_enum_prefix[[]]$1), NULL }, 38 | m4_divert(-1)') 39 | m4_define(CF_ENUM, `m4_define([[CF_enum_type]],$1)m4_define([[CF_enum_prefix]],$2)CF_iterate([[CF_enum]], [[m4_shift(m4_shift($@))]])DNL') 40 | 41 | # After all configuration templates end, we generate the 42 | m4_m4wrap(` 43 | m4_divert(0) 44 | static struct keyword keyword_list[] = { 45 | m4_undivert(1){ NULL, -1, NULL } }; 46 | ') 47 | 48 | # As we are processing C source, we must access all M4 primitives via 49 | # m4_* and also set different quoting convention: `[[' and ']]' 50 | m4_changequote([[,]]) 51 | -------------------------------------------------------------------------------- /conf/gen_parser.m4: -------------------------------------------------------------------------------- 1 | m4_divert(-1)m4_dnl 2 | # 3 | # BIRD -- Generator of Configuration Grammar 4 | # 5 | # (c) 1998--1999 Martin Mares 6 | # 7 | # Can be freely distributed and used under the terms of the GNU GPL. 8 | # 9 | 10 | # Diversions used: 11 | # 1 includes 12 | # 2 types etc. 13 | # 3 rules 14 | # 4 C code 15 | 16 | # Common aliases 17 | m4_define(DNL, `m4_dnl') 18 | 19 | # Define macros for defining sections 20 | m4_define(CF_ZONE, `m4_divert($1)/* $2 from m4___file__ */') 21 | m4_define(CF_HDR, `CF_ZONE(1, Headers)') 22 | m4_define(CF_DEFINES, `CF_ZONE(1, Defines)') 23 | m4_define(CF_DECLS, `CF_ZONE(2, Declarations)') 24 | m4_define(CF_GRAMMAR, `CF_ZONE(3, Grammar)') 25 | m4_define(CF_CODE, `CF_ZONE(4, C Code)') 26 | m4_define(CF_END, `m4_divert(-1)') 27 | 28 | # Simple iterator 29 | m4_define(CF_itera, `m4_ifelse($#, 1, [[CF_iter($1)]], [[CF_iter($1)[[]]CF_itera(m4_shift($@))]])') 30 | m4_define(CF_iterate, `m4_define([[CF_iter]], m4_defn([[$1]]))CF_itera($2)') 31 | 32 | # Keywords act as untyped %token 33 | m4_define(CF_keywd, `m4_ifdef([[CF_tok_$1]],,[[m4_define([[CF_tok_$1]],1)m4_define([[CF_toks]],CF_toks $1)]])') 34 | m4_define(CF_KEYWORDS, `m4_define([[CF_toks]],[[]])CF_iterate([[CF_keywd]], [[$@]])m4_ifelse(CF_toks,,,%token[[]]CF_toks 35 | )DNL') 36 | 37 | # Dynamic syntax rules 38 | m4_define(CF_dyn_rules,) 39 | m4_define(CF_ADDTO, `m4_define([[CF_rule_$1]],m4_ifdef([[CF_rule_$1]],CF_rule_$1 | ,[[m4_define([[CF_dyn_rules]],CF_dyn_rules[[CF_RULE($1) 40 | ]])]])$2)DNL') 41 | 42 | # CLI commands 43 | m4_define(CF_CLI, `m4_define([[CF_cmd]], cmd_[[]]m4_translit($1, [[ ]], _))DNL 44 | m4_divert(2)CF_KEYWORDS(m4_translit($1, [[ ]], [[,]])) 45 | m4_divert(3)CF_ADDTO(cli_cmd, CF_cmd) 46 | CF_cmd: $1 $2 END') 47 | m4_define(CF_CLI_CMD, `') 48 | m4_define(CF_CLI_HELP, `') 49 | 50 | # ENUM declarations are ignored 51 | m4_define(CF_ENUM, `') 52 | 53 | # After all configuration templates end, we finally generate the grammar file. 54 | m4_m4wrap(` 55 | m4_divert(0)DNL 56 | %{ 57 | m4_undivert(1)DNL 58 | %} 59 | 60 | m4_undivert(2)DNL 61 | 62 | %% 63 | m4_undivert(3)DNL 64 | 65 | /* Dynamic rules */ 66 | 67 | m4_define(CF_RULE, [[$1: CF_rule_$1 ;]]) 68 | CF_dyn_rules 69 | %% 70 | m4_undivert(4)DNL 71 | ') 72 | 73 | # As we are processing C source, we must access all M4 primitives via 74 | # m4_* and also set different quoting convention: `[[' and ']]' 75 | m4_changequote([[,]]) 76 | -------------------------------------------------------------------------------- /doc/Doc: -------------------------------------------------------------------------------- 1 | D prog-intro.sgml 2 | -------------------------------------------------------------------------------- /doc/LinuxDocTools.pm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QratorLabs/bird/85019fbc1eea830b5ccec71f76b41778aa6dafdb/doc/LinuxDocTools.pm -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | root-rel=../ 2 | dir-name=doc 3 | 4 | ifneq ($(wildcard ../Rules),) 5 | include ../Rules 6 | else 7 | srcdir=$(shell cd $(root-rel) ; pwd) 8 | srcdir_abs=$(srcdir) 9 | endif 10 | 11 | # Force rebuilds 12 | .PHONY: prog.sgml bird.sgml 13 | 14 | docs: progdocs userdocs 15 | progdocs: prog.html prog.ps 16 | userdocs: bird.html bird.ps 17 | 18 | prog.sgml: 19 | $(srcdir)/tools/progdoc $(srcdir_abs) 20 | 21 | %.html: %.sgml 22 | ./sgml2html $< 23 | 24 | %.dvi: %.tex 25 | latex $< 26 | latex $< 27 | 28 | %.ps: %.dvi 29 | dvips -D600 -ta4 -o $@ $< 30 | 31 | %.tex: %.sgml 32 | ./sgml2latex --output=tex $< 33 | 34 | %.txt: %.sgml 35 | ./sgml2txt $< 36 | 37 | progspell: prog.sgml 38 | sed -f prog-spell.sed prog.spell 39 | ispell prog.spell 40 | 41 | clean: 42 | rm -f *.tex *.dvi *.log *.txt *.aux *.toc *.spell 43 | rm -f prog.sgml 44 | 45 | distclean: clean 46 | rm -f *.html *.ps 47 | -------------------------------------------------------------------------------- /doc/old/banner.tex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QratorLabs/bird/85019fbc1eea830b5ccec71f76b41778aa6dafdb/doc/old/banner.tex -------------------------------------------------------------------------------- /doc/old/status.tex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QratorLabs/bird/85019fbc1eea830b5ccec71f76b41778aa6dafdb/doc/old/status.tex -------------------------------------------------------------------------------- /doc/prog-foot.sgml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /doc/prog-head.sgml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | BIRD Programmer's Documentation 13 | <author> 14 | Ondrej Filip <it/<feela@network.cz>/, 15 | Pavel Machek <it/<pavel@ucw.cz>/, 16 | Martin Mares <it/<mj@ucw.cz>/, 17 | Ondrej Zajicek <it/<santiago@crfreenet.org>/ 18 | </author> 19 | 20 | <abstract> 21 | This document contains programmer's documentation for the BIRD Internet Routing Daemon project. 22 | </abstract> 23 | 24 | <!-- Table of contents --> 25 | <toc> 26 | 27 | <!-- Begin the document --> 28 | -------------------------------------------------------------------------------- /doc/prog-spell.sed: -------------------------------------------------------------------------------- 1 | s%<type>[^<]*</type>%%g 2 | s%<param>[^<]*</param>%%g 3 | s%<func>[^<]*</func>%%g 4 | s%<funcdef>[^<]*</funcdef>%%g 5 | s%<type/[^</]*/%%g 6 | s%<param/[^</]*/%%g 7 | s%<func/[^</]*/%%g 8 | s%<funcdef/[^</]*/%%g 9 | s%<struct/[^</]*/%%g 10 | s%<const/[^</]*/%%g 11 | s%<[^<>/ ]\+/%%g 12 | s%</\?[^<>/ ]*>%%g 13 | s%&[^;]*;%%g 14 | -------------------------------------------------------------------------------- /doc/reply_codes: -------------------------------------------------------------------------------- 1 | Reply codes of BIRD command-line interface 2 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | 0xxx Action suceessfully completed 4 | 1xxx Table entry 5 | 2xxx Table heading 6 | 8xxx Run-time error 7 | 9xxx Parse-time error 8 | <space> Continuation 9 | + Spontaneous printout 10 | 11 | 0000 OK 12 | 0001 Welcome 13 | 0002 Reading configuration 14 | 0003 Reconfigured 15 | 0004 Reconfiguration in progress 16 | 0005 Reconfiguration already in progress, queueing 17 | 0006 Reconfiguration ignored, shutting down 18 | 0007 Shutdown ordered 19 | 0008 Already disabled 20 | 0009 Disabled 21 | 0010 Already enabled 22 | 0011 Enabled 23 | 0012 Restarted 24 | 0013 Status report 25 | 0014 Route count 26 | 0015 Reloading 27 | 0016 Access restricted 28 | 0017 Reconfiguration already in progress, removing queued config 29 | 0018 Reconfiguration confirmed 30 | 0019 Nothing to do (configure undo/confirm) 31 | 0020 Configuration OK 32 | 0021 Undo requested 33 | 0022 Undo scheduled 34 | 0023 Evaluation of expression 35 | 0024 Graceful restart status report 36 | 37 | 1000 BIRD version 38 | 1001 Interface list 39 | 1002 Protocol list 40 | 1003 Interface address 41 | 1004 Interface flags 42 | 1005 Interface summary 43 | 1006 Protocol details 44 | 1007 Route list 45 | 1008 Route details 46 | 1009 Static route list 47 | 1010 Symbol list 48 | 1011 Uptime 49 | 1012 Route extended attribute list 50 | 1013 Show ospf neighbors 51 | 1014 Show ospf 52 | 1015 Show ospf interface 53 | 1016 Show ospf state/topology 54 | 1017 Show ospf lsadb 55 | 1018 Show memory 56 | 1019 Show ROA list 57 | 1020 Show BFD sessions 58 | 59 | 8000 Reply too long 60 | 8001 Route not found 61 | 8002 Configuration file error 62 | 8003 No protocols match 63 | 8004 Stopped due to reconfiguration 64 | 8005 Protocol is down => cannot dump 65 | 8006 Reload failed 66 | 8007 Access denied 67 | 8008 Evaluation runtime error 68 | 69 | 9000 Command too long 70 | 9001 Parse error 71 | 9002 Invalid symbol type 72 | -------------------------------------------------------------------------------- /doc/sbase/VERSION: -------------------------------------------------------------------------------- 1 | 1.0.9 2 | -------------------------------------------------------------------------------- /doc/sbase/dist/fmt_html.pl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QratorLabs/bird/85019fbc1eea830b5ccec71f76b41778aa6dafdb/doc/sbase/dist/fmt_html.pl -------------------------------------------------------------------------------- /doc/sbase/dist/fmt_latex2e.pl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QratorLabs/bird/85019fbc1eea830b5ccec71f76b41778aa6dafdb/doc/sbase/dist/fmt_latex2e.pl -------------------------------------------------------------------------------- /doc/sbase/dist/fmt_txt.pl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QratorLabs/bird/85019fbc1eea830b5ccec71f76b41778aa6dafdb/doc/sbase/dist/fmt_txt.pl -------------------------------------------------------------------------------- /doc/sbase/dtd/catalog: -------------------------------------------------------------------------------- 1 | -- This is a DTD, but will be read as -*- sgml -*- -- 2 | -- ================================================= -- 3 | -- $Id$ 4 | 5 | This is dtd/catalog for SGML-Tools. 6 | 7 | Initial revision June 23st, 1997, by B. Kreimeier 8 | 9 | $Log$ 10 | Revision 1.1 2000-05-29 12:05:22 mj 11 | Renamed the DTD from linuxdoc to birddoc. 12 | 13 | Pavel, please check whether it builds in your environment as well. 14 | 15 | Revision 1.7 1998/10/13 12:12:09 cg 16 | * Clean up catalog file. (CdG) 17 | 18 | Revision 1.6 1998/03/09 21:10:14 cg 19 | * Removed sgmltool.dtd. (CdG) 20 | 21 | Revision 1.5 1998/01/08 19:59:54 cg 22 | * Add empty line, it gave problems. (CdG) 23 | 24 | Revision 1.4 1997/12/09 20:56:15 cg 25 | * Added html32.dtd (with a modified reference to ISOent) and updated 26 | catalog accordingly. You can now do sgmlcheck on HTML files. (CdG) 27 | 28 | Revision 1.3 1997/07/09 13:27:12 cg 29 | * Completely new DTD setup by Bernd (BK). 30 | 31 | 32 | -- 33 | -- ================================================= -- 34 | -- Revision Comments -- 35 | 36 | -- BK/97/06/23: added a header, changed for 0.99.12 -- 37 | -- ================================================= -- 38 | 39 | DOCTYPE "BIRDDOC" "birddoc.dtd" 40 | 41 | -- Linuxdoc96.dtd, frozen orignal Linuxdoc DTD -- 42 | DOCTYPE "LINUXDOC" "linuxdoc.dtd" 43 | PUBLIC "-//LinuxDoc//DTD LinuxDoc 96//EN" linuxdoc96.dtd 44 | 45 | -- Linuxdoc97 Strict DTD -- 46 | PUBLIC "-//LinuxDoc//DTD LinuxDoc 97//EN" linuxdoc97.dtd 47 | 48 | -- outdated and shared entities -- 49 | ENTITY %common "common" 50 | ENTITY %isoent "isoent" 51 | 52 | ENTITY %deprec96 "deprec96" 53 | 54 | 55 | -- for development and debug, internal use only -- 56 | DOCTYPE "QWERTZ" "qwertz.dtd" 57 | DOCTYPE "TEST" "test.dtd" 58 | 59 | -- for SGML validation -- 60 | DOCTYPE "HTML" "html32.dtd" 61 | PUBLIC "-//W3C//DTD HTML 3.2 Final//EN" html32.dtd 62 | 63 | -- obsolete -- 64 | ENTITY %general "general" 65 | 66 | 67 | -- ================================================= -- 68 | -- end of dtd/catalog -- 69 | -- 70 | Local Variables: 71 | mode: sgml 72 | End: -- 73 | -- ================================================= -- 74 | 75 | -------------------------------------------------------------------------------- /doc/sbase/dtd/common: -------------------------------------------------------------------------------- 1 | <!-- This is a DTD, but will be read as -*- sgml -*- --> 2 | <!-- ================================================= --> 3 | <!-- $Id$ 4 | 5 | This is COMMON ENTITY for SGML-Tools. 6 | 7 | The definitions herein are used by both 8 | LINUXDOC97 Strict DTD and SGMLTOOL DTD. 9 | 10 | Initial revision May 16, 1997, by B. Kreimeier 11 | 12 | &Log:$ 13 | 14 | --> 15 | <!-- ================================================= --> 16 | <!-- Revision Comments --> 17 | 18 | <!-- BK/97/05/16: created from linuxdoc97.dtd --> 19 | <!-- BK/97/07/17: Moved <descrip> to linuxdoc97.dtd. --> 20 | <!-- BK/97/05/18: removed quote and code back from 21 | "common", as I want to modify them (caption) --> 22 | <!-- ================================================= --> 23 | 24 | 25 | 26 | 27 | 28 | <!-- ================================================= --> 29 | <!-- TITLE, TITLEPAGE --> 30 | <!-- MDW: hacked, abstract now part of titlepag --> 31 | <!-- ================================================= --> 32 | 33 | <!element titlepag o o (title, author, date?, abstract?)> 34 | <!element title - o (%inline) > 35 | 36 | <!usemap oneline titlepag> 37 | 38 | <!element author - o 39 | (name, (and, name )*)> 40 | 41 | <!element name o o (%inline) > 42 | <!element and - o empty> 43 | <!element date - o (#pcdata) > 44 | 45 | 46 | <!element abstract - o (%inline)> 47 | <!usemap oneline abstract> 48 | 49 | <!element toc - o empty> 50 | 51 | <!-- ================================================= --> 52 | <!-- SECTion - section hierarchy --> 53 | <!-- ================================================= --> 54 | 55 | <!element header - - (lhead, rhead) > 56 | <!element lhead - o (%inline)> 57 | <!element rhead - o (%inline)> 58 | 59 | <!entity % sect "heading, header?, p* " > 60 | 61 | <!element heading o o (%inline)> 62 | <!element sect - o (%sect, sect1*)> 63 | <!element sect1 - o (%sect, sect2*)> 64 | <!element sect2 - o (%sect, sect3*)> 65 | <!element sect3 - o (%sect, sect4*)> 66 | <!element sect4 - o (%sect)> 67 | 68 | <!usemap oneline (sect,sect1,sect2,sect3,sect4)> 69 | 70 | <!-- ================================================= --> 71 | <!-- LIST elements --> 72 | <!-- Group of all list elements, except descrip --> 73 | <!-- ================================================= --> 74 | 75 | <!element itemize - - (item+)> 76 | <!element enum - - (item+)> 77 | <!element item o o ((%inline; | %sectpar;)*, p*) > 78 | 79 | <!usemap global (itemize,enum)> 80 | 81 | 82 | 83 | <!-- ================================================= --> 84 | <!-- P - paragraph, smallest block of text --> 85 | <!-- ================================================= --> 86 | 87 | <!element p o o (( %inline | %sectpar )+) > 88 | <!usemap pmap p> 89 | 90 | 91 | 92 | <!-- ================================================= --> 93 | <!-- end of COMMON ENTITY --> 94 | <!-- 95 | Local Variables: 96 | mode: sgml 97 | End: --> 98 | <!-- ================================================= --> -------------------------------------------------------------------------------- /doc/sbase/dtd/isoent: -------------------------------------------------------------------------------- 1 | <!-- This is a DTD, but will be read as -*- sgml -*- --> 2 | <!-- ================================================= --> 3 | <!-- $Id$ 4 | 5 | This is dtd/isoent for SGML-Tools. 6 | 7 | Initial revision June 23st, 1997, by B. Kreimeier 8 | 9 | $Log$ 10 | Revision 1.1 2000-05-31 14:27:50 mj 11 | This should be enough from the SGMLtools distribution to make the 12 | SGMLtools happy. 13 | 14 | The only symlink you need now is dist/birddoc -> dist/sgmltool. I'm 15 | convinced it could be avoided by renaming the directory instead, but I'd 16 | rather avoid it due to CVS pecularities. 17 | 18 | Revision 1.1 1997/07/09 13:27:16 cg 19 | * Completely new DTD setup by Bernd (BK). 20 | 21 | 22 | --> 23 | <!-- ================================================= --> 24 | <!-- Revision Comments --> 25 | <!-- BK/97/06/22: installed 0.99.12, applied changes 26 | made for new entity mapping. --> 27 | <!-- ================================================= --> 28 | 29 | 30 | <!-- ================================================= --> 31 | <!-- ISO entities --> 32 | <!-- ================================================= --> 33 | 34 | 35 | <!ENTITY % ISOdia PUBLIC 36 | "ISO 8879:1986//ENTITIES Diacritical Marks//EN"> 37 | %ISOdia; 38 | 39 | <!ENTITY % ISOgrk3 PUBLIC 40 | "ISO 8879:1986//ENTITIES Greek Symbols//EN"> 41 | %ISOgrk3; 42 | 43 | <!ENTITY % ISOlat1 PUBLIC 44 | "ISO 8879:1986//ENTITIES Added Latin 1//EN"> 45 | %ISOlat1; 46 | 47 | <!ENTITY % ISOnum PUBLIC 48 | "ISO 8879:1986//ENTITIES Numeric and Special Graphic//EN"> 49 | %ISOnum; 50 | 51 | <!ENTITY % ISOpub PUBLIC 52 | "ISO 8879:1986//ENTITIES Publishing//EN"> 53 | %ISOpub; 54 | 55 | 56 | 57 | <!-- ================================================= --> 58 | <!-- end of dtd/isoent --> 59 | <!-- 60 | Local Variables: 61 | mode: sgml 62 | End: --> 63 | <!-- ================================================= --> -------------------------------------------------------------------------------- /doc/sgml2html: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # sgmltools.in 4 | # 5 | # $Id$ 6 | # 7 | # SGML-Tools driver. Calls all other SGML-Tools components, contains 8 | # configuration information, etcetera. 9 | # 10 | package main; 11 | 12 | sub BEGIN 13 | { 14 | require 5.004; 15 | } 16 | use strict; 17 | 18 | use vars qw($prefix $DataDir $BinDir $progs); 19 | 20 | $prefix = "/usr"; 21 | $DataDir = "sbase"; 22 | $BinDir = "/usr/bin"; 23 | 24 | use lib "/usr/share/linuxdoc-tools"; 25 | use lib "/usr/perl5"; 26 | use lib "/usr/lib/perl5"; 27 | use lib "/usr/share/perl5"; 28 | $progs = { 29 | "NSGMLS" => "/usr/bin/nsgmls", 30 | "SGMLSASP" => "/usr/bin/sgmlsasp", 31 | "GROFF" => "/usr/bin/groff", 32 | "GROFFMACRO" => "-ms", 33 | "AWK" => "/usr/share/linuxdoc-tools/awkwhich" 34 | }; 35 | $ENV{"SGML_CATALOG_FILES"} = "sbase/dtd/catalog"; 36 | 37 | require "./LinuxDocTools.pm"; 38 | &LinuxDocTools::init; 39 | 40 | my @FileList = LinuxDocTools::process_options ("html", @ARGV); 41 | for my $curfile (@FileList) 42 | { 43 | LinuxDocTools::process_file ($curfile); 44 | } 45 | 46 | exit 0; 47 | -------------------------------------------------------------------------------- /doc/sgml2latex: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # sgmltools.in 4 | # 5 | # $Id$ 6 | # 7 | # SGML-Tools driver. Calls all other SGML-Tools components, contains 8 | # configuration information, etcetera. 9 | # 10 | package main; 11 | 12 | sub BEGIN 13 | { 14 | require 5.004; 15 | } 16 | use strict; 17 | 18 | use vars qw($prefix $DataDir $BinDir $progs); 19 | 20 | $prefix = "/usr"; 21 | $DataDir = "sbase"; 22 | $BinDir = "/usr/bin"; 23 | 24 | use lib "/usr/share/linuxdoc-tools"; 25 | use lib "/usr/perl5"; 26 | use lib "/usr/lib/perl5"; 27 | use lib "/usr/share/perl5"; 28 | $progs = { 29 | "NSGMLS" => "/usr/bin/nsgmls", 30 | "SGMLSASP" => "/usr/bin/sgmlsasp", 31 | "GROFF" => "/usr/bin/groff", 32 | "GROFFMACRO" => "-ms", 33 | "AWK" => "/usr/share/linuxdoc-tools/awkwhich" 34 | }; 35 | $ENV{"SGML_CATALOG_FILES"} = "sbase/dtd/catalog"; 36 | 37 | require "./LinuxDocTools.pm"; 38 | &LinuxDocTools::init; 39 | 40 | my @FileList = LinuxDocTools::process_options ("latex", @ARGV); 41 | for my $curfile (@FileList) 42 | { 43 | LinuxDocTools::process_file ($curfile); 44 | } 45 | 46 | exit 0; 47 | -------------------------------------------------------------------------------- /doc/sgml2txt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # sgmltools.in 4 | # 5 | # $Id$ 6 | # 7 | # SGML-Tools driver. Calls all other SGML-Tools components, contains 8 | # configuration information, etcetera. 9 | # 10 | package main; 11 | 12 | sub BEGIN 13 | { 14 | require 5.004; 15 | } 16 | use strict; 17 | 18 | use vars qw($prefix $DataDir $BinDir $progs); 19 | 20 | $prefix = "/usr"; 21 | $DataDir = "sbase"; 22 | $BinDir = "/usr/bin"; 23 | 24 | use lib "/usr/share/linuxdoc-tools"; 25 | use lib "/usr/perl5"; 26 | use lib "/usr/lib/perl5"; 27 | use lib "/usr/share/perl5"; 28 | $progs = { 29 | "NSGMLS" => "/usr/bin/nsgmls", 30 | "SGMLSASP" => "/usr/bin/sgmlsasp", 31 | "GROFF" => "/usr/bin/groff", 32 | "GROFFMACRO" => "-ms", 33 | "AWK" => "/usr/share/linuxdoc-tools/awkwhich" 34 | }; 35 | $ENV{"SGML_CATALOG_FILES"} = "sbase/dtd/catalog"; 36 | 37 | require "./LinuxDocTools.pm"; 38 | &LinuxDocTools::init; 39 | 40 | my @FileList = LinuxDocTools::process_options ("txt", @ARGV); 41 | for my $curfile (@FileList) 42 | { 43 | LinuxDocTools::process_file ($curfile); 44 | } 45 | 46 | exit 0; 47 | -------------------------------------------------------------------------------- /doc/slides/Makefile: -------------------------------------------------------------------------------- 1 | all: slides.dvi 2 | 3 | slides.dvi: slides.tex 4 | csplain slides.tex 5 | 6 | slides.ps: slides.dvi 7 | dvips -o slides.ps -D600 -ta4 slides.dvi 8 | 9 | view: slides.dvi 10 | xdvi -expert -geometry 1100x700 -l -s 4 -paper a4 -margins 1in slides.dvi 11 | 12 | viewlarge: slides.dvi 13 | xdvi -expert -geometry 1024x700 -l -s 1 -paper a4 -margins 1in slides.dvi 14 | 15 | viewreal: slides.dvi 16 | xdvi -expert -geometry 1024x700 -l -s 6 -paper a4 -margins 1in slides.dvi 17 | 18 | clean: 19 | rm -f *~ *.log *.tfm *.*pk *.*gf *.ps *.dvi 20 | -------------------------------------------------------------------------------- /doc/slides/logo.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QratorLabs/bird/85019fbc1eea830b5ccec71f76b41778aa6dafdb/doc/slides/logo.eps -------------------------------------------------------------------------------- /doc/slides/slides.tex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QratorLabs/bird/85019fbc1eea830b5ccec71f76b41778aa6dafdb/doc/slides/slides.tex -------------------------------------------------------------------------------- /doc/slt2001/Makefile: -------------------------------------------------------------------------------- 1 | all: slt.dvi 2 | 3 | slt.dvi: slt.tex 4 | csplain slt.tex 5 | 6 | slt.ps: slt.dvi 7 | dvips -o slt.ps -D600 -ta4 slt.dvi 8 | 9 | clean: 10 | rm -f *~ *.log *.tfm *.*pk *.*gf *.ps *.dvi 11 | -------------------------------------------------------------------------------- /doc/slt2001/slt.tex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QratorLabs/bird/85019fbc1eea830b5ccec71f76b41778aa6dafdb/doc/slt2001/slt.tex -------------------------------------------------------------------------------- /doc/tex/birddoc.sty: -------------------------------------------------------------------------------- 1 | %% This is a LaTeX style file for typesetting BIRD documentation. 2 | %% Hacked up by Martin Mares <mj@ucw.cz> 3 | %% 4 | %% This is a modified version of linuxdoc-qwertz.sty, for use with SGML-generated LaTeX 5 | %% by Matt Welsh (mdw@sunsite.unc.edu) 6 | %% 7 | %% Based on linuxdoc.sty by Michael K. Johnson, and latex.tex by 8 | %% Leslie Lamport. 9 | 10 | \NeedsTeXFormat{LaTeX2e} 11 | \ProvidesClass{birddoc} 12 | 13 | %%% GLOBAL LAYOUT THINGS 14 | 15 | \marginparwidth 0.0 in 16 | \parindent=0 in 17 | \parskip=0.5ex 18 | %\parindent=0.5in 19 | %\parskip=0pt 20 | \topmargin -0.5 in 21 | \setlength{\textheight}{\paperheight} 22 | \addtolength{\textheight}{-2 in} 23 | %\advance\headsep 2 ex 24 | \advance\textheight -2 ex 25 | %\renewcommand{\baselinestretch}{1.14} 26 | \setcounter{tocdepth}{1} 27 | \oddsidemargin 0.15 in 28 | \evensidemargin -0.35 in 29 | \textwidth 6.5in 30 | 31 | \def\ps@headings{\let\@mkboth\markboth 32 | \def\@oddfoot{}\def\@evenfoot{}% No feet. 33 | \def\@evenhead{\protect\rule[-4pt]{\textwidth}{.5pt}\kern-\textwidth 34 | \rm \thepage\hfil \bf \leftmark} % Left heading. 35 | \def\@oddhead{\protect\rule[-4pt]{\textwidth}{.5pt}\kern-\textwidth 36 | {\bf \rightmark}\hfil \rm\thepage} % Right heading. 37 | \def\chaptermark##1{\markboth {{\ifnum \c@secnumdepth >\m@ne 38 | \@chapapp\ \thechapter. \ \fi ##1}}{}}% 39 | \def\sectionmark##1{\markright {{\ifnum \c@secnumdepth >\z@ 40 | \thesection. \ \fi ##1}}}} 41 | 42 | \def\@makechapterhead#1{% 43 | {\parindent \z@ \raggedright \normalfont 44 | \huge \bfseries \@chapapp\space\thechapter: #1\par\nobreak 45 | \vskip 20\p@ 46 | }} 47 | \def\@makeschapterhead#1{% 48 | {\parindent \z@ \raggedright \normalfont 49 | \huge \bfseries #1\par\nobreak 50 | \vskip 20\p@ 51 | }} 52 | 53 | %% Titlepage stuff 54 | 55 | \gdef\@title{} 56 | \gdef\title#1{\gdef\@title{#1}} 57 | \gdef\@date{} 58 | \gdef\date#1{\gdef\@date{#1}} 59 | \gdef\@author{} 60 | \gdef\author#1{\gdef\@author{#1}} 61 | \gdef\@abstract{} 62 | \gdef\abstract#1{\gdef\@abstract{#1}} 63 | 64 | \def\maketitle{\thispagestyle{empty}\let\footnotesize\small% 65 | \let\footnoterule\relax 66 | %\setcounter{page}{0}% 67 | %\null 68 | %\vskip 3 in 69 | \noindent 70 | {\huge\sf \@title}\\ 71 | \rule{\textwidth}{1mm}\\ 72 | \mbox{}\@author\ \hfill \@date\ \\ 73 | \vskip 1 ex 74 | \noindent{\sf \@abstract} 75 | \setcounter{footnote}{0}% 76 | \gdef\@author{}\gdef\@title{}\gdef\@years{}\gdef\@abstract{} 77 | \let\maketitle\relax} 78 | 79 | \def\birdnarrow{\advance\@totalleftmargin by 0.5in} 80 | 81 | %% Needs to be here for the previous ps@headings defs to work. 82 | \pagestyle{headings} 83 | 84 | \def\progdoc{ 85 | \raggedbottom 86 | } 87 | 88 | %%% USEFUL MACROS 89 | 90 | \newcommand{\linux}{Linux} % Always use this when 91 | % refering to the \linux\ 92 | % operating system, like that. 93 | \newcommand{\key}[1]{{\fbox{\small\tt #1}}} % Use this to mark keys, like 94 | % \key{del} for the delete key. 95 | \newcommand{\ret}{\fbox{\sf return}} % Special case for the return key. 96 | \newcommand{\st}{\small\tt} % Small typewriter -- comes in handy. 97 | %\newcommand{\lb}{{\tt\char '173}} % Left Brace '{' 98 | %\newcommand{\rb}{{\tt\char '175}} % Right Brace '}' 99 | \newcommand{\lbr}{$\langle$} % Left Bracket '<' 100 | \newcommand{\rbr}{$\rangle$} % Right Bracket '>' 101 | \newcommand{\bs}{{\tt\char '134}} % BackSlash '\' 102 | \newcommand{\tm}{${}^{\mbox{\tiny\sf TM}}$} 103 | \newcommand{\TM}{\tm} % TM trademark symbol in 104 | % either case 105 | \newcommand{\cparam}[1]{{\rm \lbr{\sl #1}\rbr}} 106 | % Metavariables. 107 | 108 | %% Define NAMEURL macro to handle the optional name argument 109 | %% This calls on the \url macro from the url.sty package so the 110 | %% URL will be hyphenated correctly. 111 | \def\nameurl#1#2{{\em #2} {\tt <\url{#1}>}} 112 | \def\onlynameurl#1{{\em #1}} 113 | 114 | %% the tscreen environment automatically goes into typewriter type, 115 | %% but is otherwise like the screen environment 116 | 117 | \newenvironment{tscreen}% 118 | {\begin{quote}\bgroup\small\tt}% 119 | {\egroup\end{quote}} 120 | 121 | %% Typesetting of function descriptions 122 | 123 | \def\function{\bigbreak\hrule\nobreak\bigskip\nobreak\leftline{\bf Function}\nobreak\smallskip\nobreak\parskip=0pt\relax} 124 | \def\funcsect#1{\medbreak\leftline{\bf #1}\nobreak} 125 | -------------------------------------------------------------------------------- /doc/tex/null.sty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QratorLabs/bird/85019fbc1eea830b5ccec71f76b41778aa6dafdb/doc/tex/null.sty -------------------------------------------------------------------------------- /doc/tex/qwertz.sty: -------------------------------------------------------------------------------- 1 | 2 | % qwertz TeX macros 3 | 4 | \catcode`\"=12 5 | \sloppy 6 | \newtheorem{definition}{Definition} 7 | \newtheorem{proposition}{Proposition} 8 | \newtheorem{lemma}{Lemma} 9 | \newtheorem{corollary}{Corollary} 10 | \newtheorem{theorem}{Theorem} 11 | \newcommand{\mch}[1]{{\ifmmode#1 \else\(#1\)\fi}} 12 | \newcommand{\lt}{{\ifmmode{<}\else{\verb+<+}\fi}} 13 | \newcommand{\gt}{{\ifmmode{>}\else{\verb+>+}\fi}} 14 | \newcommand{\verbar}{{\ifmmode{|}\else{\tt|}\fi}} 15 | \newcommand{\idx}[1]{#1\index{#1}} 16 | \newcommand{\cdx}[1]{#1\index{#1@{\tt #1}}} 17 | \newcommand{\nidx}[1]{\index{#1}} 18 | \newcommand{\ncdx}[1]{\index{#1@{\tt #1}}} 19 | 20 | -------------------------------------------------------------------------------- /filter/Doc: -------------------------------------------------------------------------------- 1 | H Filters 2 | S filter.c 3 | S tree.c 4 | S trie.c -------------------------------------------------------------------------------- /filter/Makefile: -------------------------------------------------------------------------------- 1 | source=f-util.c filter.c tree.c trie.c 2 | root-rel=../ 3 | dir-name=filter 4 | 5 | include ../Rules 6 | -------------------------------------------------------------------------------- /filter/f-util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Filters: utility functions 3 | * 4 | * Copyright 1998 Pavel Machek <pavel@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #include "nest/bird.h" 10 | #include "conf/conf.h" 11 | #include "filter/filter.h" 12 | 13 | #define P(a,b) ((a<<8) | b) 14 | 15 | struct f_inst * 16 | f_new_inst(void) 17 | { 18 | struct f_inst * ret; 19 | ret = cfg_alloc(sizeof(struct f_inst)); 20 | ret->code = ret->aux = 0; 21 | ret->arg1 = ret->arg2 = ret->next = NULL; 22 | ret->lineno = ifs->lino; 23 | return ret; 24 | } 25 | 26 | struct f_inst * 27 | f_new_dynamic_attr(int type, int f_type UNUSED, int code) 28 | { 29 | /* FIXME: Remove the f_type parameter? */ 30 | struct f_inst *f = f_new_inst(); 31 | f->aux = type; 32 | f->a2.i = code; 33 | return f; 34 | } 35 | 36 | /* 37 | * Generate set_dynamic( operation( get_dynamic(), argument ) ) 38 | */ 39 | struct f_inst * 40 | f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument) 41 | { 42 | struct f_inst *set_dyn = f_new_inst(), 43 | *oper = f_new_inst(), 44 | *get_dyn = dyn; 45 | 46 | *set_dyn = *get_dyn; 47 | get_dyn->code = P('e','a'); 48 | oper->code = operation; 49 | oper->aux = operation_aux; 50 | oper->a1.p = get_dyn; 51 | oper->a2.p = argument; 52 | set_dyn->code = P('e','S'); 53 | set_dyn->a1.p = oper; 54 | return set_dyn; 55 | } 56 | 57 | 58 | struct f_inst * 59 | f_generate_roa_check(struct symbol *sym, struct f_inst *prefix, struct f_inst *asn) 60 | { 61 | struct f_inst_roa_check *ret = cfg_allocz(sizeof(struct f_inst_roa_check)); 62 | ret->i.code = P('R','C'); 63 | ret->i.lineno = ifs->lino; 64 | ret->i.arg1 = prefix; 65 | ret->i.arg2 = asn; 66 | /* prefix == NULL <-> asn == NULL */ 67 | 68 | if ((sym->class != SYM_ROA) || ! sym->def) 69 | cf_error("%s is not a ROA table", sym->name); 70 | ret->rtc = sym->def; 71 | 72 | return &ret->i; 73 | } 74 | 75 | char * 76 | filter_name(struct filter *filter) 77 | { 78 | if (!filter) 79 | return "ACCEPT"; 80 | else if (filter == FILTER_REJECT) 81 | return "REJECT"; 82 | else if (!filter->name) 83 | return "(unnamed)"; 84 | else 85 | return filter->name; 86 | } 87 | -------------------------------------------------------------------------------- /filter/test.conf.inc: -------------------------------------------------------------------------------- 1 | 2 | print "Entering include"; 3 | print "Should be 2: ", 1+1; 4 | print "Leaving include"; 5 | 6 | -------------------------------------------------------------------------------- /filter/test.conf2: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an example configuration file. 3 | */ 4 | 5 | # Yet another comment 6 | 7 | router id 62.168.0.1; 8 | 9 | define xyzzy = (120+10); 10 | 11 | protocol device { 12 | # disabled; 13 | # interface "eth*", "ppp*"; 14 | } 15 | 16 | protocol direct { 17 | } 18 | 19 | protocol kernel { 20 | disabled; 21 | # learn; # Learn all routes from the kernel 22 | # scan time 10; # Scan kernel tables every 10 seconds 23 | } 24 | 25 | protocol static { 26 | # disabled; 27 | 28 | import filter { print "ahoj"; 29 | print source; 30 | if source = RTS_STATIC then { 31 | print "It is from static"; 32 | } 33 | print from; 34 | from = 1.2.3.4; 35 | print from; 36 | print scope; 37 | scope = SCOPE_HOST; 38 | print scope; 39 | if !(scope ~ [ SCOPE_HOST, SCOPE_SITE ]) then { 40 | print "Failed in test"; 41 | quitbird; 42 | } 43 | 44 | preference = 15; 45 | print preference; 46 | preference = 29; 47 | print preference; 48 | rip_metric = 1; 49 | print rip_metric; 50 | rip_metric = rip_metric + 5; 51 | print rip_metric; 52 | bgp_community = - empty - ; 53 | print "nazdar"; 54 | bgp_community = add(bgp_community, (1,2)); 55 | print "cau"; 56 | bgp_community = add(bgp_community, (2,3)); 57 | bgp_community.add((4,5)); 58 | print "community = ", bgp_community; 59 | bgp_community.delete((2,3)); 60 | print "community = ", bgp_community; 61 | bgp_community.empty; 62 | print "community = ", bgp_community; 63 | print "done"; 64 | }; 65 | 66 | route 0.0.0.0/0 via 195.113.31.113; 67 | route 62.168.0.0/25 reject; 68 | route 1.2.3.4/32 via 195.113.31.124; 69 | # route 10.0.0.0/8 reject; 70 | # route 10.1.1.0:255.255.255.0 via 62.168.0.3; 71 | # route 10.1.2.0:255.255.255.0 via 62.168.0.3; 72 | # route 10.1.3.0:255.255.255.0 via 62.168.0.4; 73 | # route 10.2.0.0/24 via "arc0"; 74 | export all; 75 | } 76 | -------------------------------------------------------------------------------- /filter/tree.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Filters: utility functions 3 | * 4 | * Copyright 1998 Pavel Machek <pavel@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #include "lib/alloca.h" 10 | #include "nest/bird.h" 11 | #include "conf/conf.h" 12 | #include "filter/filter.h" 13 | 14 | /** 15 | * find_tree 16 | * @t: tree to search in 17 | * @val: value to find 18 | * 19 | * Search for given value in the tree. I relies on fact that sorted tree is populated 20 | * by &f_val structures (that can be compared by val_compare()). In each node of tree, 21 | * either single value (then t->from==t->to) or range is present. 22 | * 23 | * Both set matching and |switch() { }| construction is implemented using this function, 24 | * thus both are as fast as they can be. 25 | */ 26 | struct f_tree * 27 | find_tree(struct f_tree *t, struct f_val val) 28 | { 29 | if (!t) 30 | return NULL; 31 | if ((val_compare(t->from, val) != 1) && 32 | (val_compare(t->to, val) != -1)) 33 | return t; 34 | if (val_compare(t->from, val) == -1) 35 | return find_tree(t->right, val); 36 | else 37 | return find_tree(t->left, val); 38 | } 39 | 40 | static struct f_tree * 41 | build_tree_rec(struct f_tree **buf, int l, int h) 42 | { 43 | struct f_tree *n; 44 | int pos; 45 | 46 | if (l >= h) 47 | return NULL; 48 | 49 | pos = (l+h)/2; 50 | n = buf[pos]; 51 | n->left = build_tree_rec(buf, l, pos); 52 | n->right = build_tree_rec(buf, pos+1, h); 53 | return n; 54 | } 55 | 56 | static int 57 | tree_compare(const void *p1, const void *p2) 58 | { 59 | return val_compare((* (struct f_tree **) p1)->from, (* (struct f_tree **) p2)->from); 60 | } 61 | 62 | /** 63 | * build_tree 64 | * @from: degenerated tree (linked by @tree->left) to be transformed into form suitable for find_tree() 65 | * 66 | * Transforms denerated tree into balanced tree. 67 | */ 68 | struct f_tree * 69 | build_tree(struct f_tree *from) 70 | { 71 | struct f_tree *tmp, *root; 72 | struct f_tree **buf; 73 | int len, i; 74 | 75 | if (from == NULL) 76 | return NULL; 77 | 78 | len = 0; 79 | for (tmp = from; tmp != NULL; tmp = tmp->left) 80 | len++; 81 | 82 | if (len <= 1024) 83 | buf = alloca(len * sizeof(struct f_tree *)); 84 | else 85 | buf = malloc(len * sizeof(struct f_tree *)); 86 | 87 | /* Convert a degenerated tree into an sorted array */ 88 | i = 0; 89 | for (tmp = from; tmp != NULL; tmp = tmp->left) 90 | buf[i++] = tmp; 91 | 92 | qsort(buf, len, sizeof(struct f_tree *), tree_compare); 93 | 94 | root = build_tree_rec(buf, 0, len); 95 | 96 | if (len > 1024) 97 | free(buf); 98 | 99 | return root; 100 | } 101 | 102 | struct f_tree * 103 | f_new_tree(void) 104 | { 105 | struct f_tree * ret; 106 | ret = cfg_alloc(sizeof(struct f_tree)); 107 | ret->left = ret->right = NULL; 108 | ret->from.type = ret->to.type = T_VOID; 109 | ret->from.val.i = ret->to.val.i = 0; 110 | ret->data = NULL; 111 | return ret; 112 | } 113 | 114 | /** 115 | * same_tree 116 | * @t1: first tree to be compared 117 | * @t2: second one 118 | * 119 | * Compares two trees and returns 1 if they are same 120 | */ 121 | int 122 | same_tree(struct f_tree *t1, struct f_tree *t2) 123 | { 124 | if ((!!t1) != (!!t2)) 125 | return 0; 126 | if (!t1) 127 | return 1; 128 | if (val_compare(t1->from, t2->from)) 129 | return 0; 130 | if (val_compare(t1->to, t2->to)) 131 | return 0; 132 | if (!same_tree(t1->left, t2->left)) 133 | return 0; 134 | if (!same_tree(t1->right, t2->right)) 135 | return 0; 136 | if (!i_same(t1->data, t2->data)) 137 | return 0; 138 | return 1; 139 | } 140 | 141 | 142 | static void 143 | tree_node_format(struct f_tree *t, buffer *buf) 144 | { 145 | if (t == NULL) 146 | return; 147 | 148 | tree_node_format(t->left, buf); 149 | 150 | val_format(t->from, buf); 151 | if (val_compare(t->from, t->to) != 0) 152 | { 153 | buffer_puts(buf, ".."); 154 | val_format(t->to, buf); 155 | } 156 | buffer_puts(buf, ", "); 157 | 158 | tree_node_format(t->right, buf); 159 | } 160 | 161 | void 162 | tree_format(struct f_tree *t, buffer *buf) 163 | { 164 | buffer_puts(buf, "["); 165 | 166 | tree_node_format(t, buf); 167 | 168 | /* Undo last separator */ 169 | if (buf->pos[-1] != '[') 170 | buf->pos -= 2; 171 | 172 | buffer_puts(buf, "]"); 173 | } 174 | -------------------------------------------------------------------------------- /lib/Doc: -------------------------------------------------------------------------------- 1 | H Library functions 2 | S ip.c ipv4.c ipv6.c 3 | S lists.c 4 | S checksum.c bitops.c patmatch.c printf.c xmalloc.c tbf.c 5 | D resource.sgml 6 | S resource.c 7 | S mempool.c 8 | S slab.c 9 | S event.c 10 | S ../sysdep/unix/io.c 11 | -------------------------------------------------------------------------------- /lib/Modules: -------------------------------------------------------------------------------- 1 | birdlib.h 2 | bitops.c 3 | bitops.h 4 | ip.h 5 | ip.c 6 | lists.c 7 | lists.h 8 | md5.c 9 | md5.h 10 | mempool.c 11 | resource.c 12 | resource.h 13 | slab.c 14 | socket.h 15 | tbf.c 16 | unaligned.h 17 | xmalloc.c 18 | printf.c 19 | string.h 20 | patmatch.c 21 | slists.c 22 | slists.h 23 | event.c 24 | event.h 25 | checksum.c 26 | checksum.h 27 | alloca.h 28 | -------------------------------------------------------------------------------- /lib/alloca.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- Alloca.h 3 | * 4 | * (c) 2004 Ondrej Filip <feela@network.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_ALLOCA_H_ 10 | #define _BIRD_ALLOCA_H_ 11 | 12 | #ifdef HAVE_ALLOCA_H 13 | #include <alloca.h> 14 | #else 15 | #include <stdlib.h> 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /lib/birdlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library 3 | * 4 | * (c) 1998--2004 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_BIRDLIB_H_ 10 | #define _BIRD_BIRDLIB_H_ 11 | 12 | #include "timer.h" 13 | #include "alloca.h" 14 | 15 | /* Ugly structure offset handling macros */ 16 | 17 | #define OFFSETOF(s, i) ((size_t) &((s *)0)->i) 18 | #define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i))) 19 | #define BIRD_ALIGN(s, a) (((s)+a-1)&~(a-1)) 20 | 21 | /* Utility macros */ 22 | 23 | #define MIN_(a,b) (((a)<(b))?(a):(b)) 24 | #define MAX_(a,b) (((a)>(b))?(a):(b)) 25 | 26 | #ifndef PARSER 27 | #undef MIN 28 | #undef MAX 29 | #define MIN(a,b) MIN_(a,b) 30 | #define MAX(a,b) MAX_(a,b) 31 | #endif 32 | 33 | #define ABS(a) ((a)>=0 ? (a) : -(a)) 34 | #define DELTA(a,b) (((a)>=(b))?(a)-(b):(b)-(a)) 35 | #define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a))) 36 | 37 | 38 | /* Bitfield macros */ 39 | 40 | /* b is u32 array (or ptr), l is size of it in bits (multiple of 32), p is 0..(l-1) */ 41 | #define BIT32_VAL(p) (((u32) 1) << ((p) % 32)) 42 | #define BIT32_TEST(b,p) ((b)[(p)/32] & BIT32_VAL(p)) 43 | #define BIT32_SET(b,p) ((b)[(p)/32] |= BIT32_VAL(p)) 44 | #define BIT32_CLR(b,p) ((b)[(p)/32] &= ~BIT32_VAL(p)) 45 | #define BIT32_ZERO(b,l) memset((b), 0, (l)/8) 46 | 47 | #ifndef NULL 48 | #define NULL ((void *) 0) 49 | #endif 50 | 51 | #ifndef IPV6 52 | #define IP_VERSION 4 53 | #else 54 | #define IP_VERSION 6 55 | #endif 56 | 57 | 58 | /* Macros for gcc attributes */ 59 | 60 | #define NORET __attribute__((noreturn)) 61 | #define UNUSED __attribute__((unused)) 62 | 63 | 64 | /* Microsecond time */ 65 | 66 | typedef s64 btime; 67 | 68 | #define S_ *1000000 69 | #define MS_ *1000 70 | #define US_ *1 71 | #define TO_S /1000000 72 | #define TO_MS /1000 73 | #define TO_US /1 74 | 75 | #ifndef PARSER 76 | #define S S_ 77 | #define MS MS_ 78 | #define US US_ 79 | #endif 80 | 81 | 82 | /* Rate limiting */ 83 | 84 | struct tbf { 85 | bird_clock_t timestamp; /* Last update */ 86 | u16 count; /* Available tokens */ 87 | u16 burst; /* Max number of tokens */ 88 | u16 rate; /* Rate of replenishment */ 89 | u16 mark; /* Whether last op was limited */ 90 | }; 91 | 92 | /* Default TBF values for rate limiting log messages */ 93 | #define TBF_DEFAULT_LOG_LIMITS { .rate = 1, .burst = 5 } 94 | 95 | void tbf_update(struct tbf *f); 96 | 97 | static inline int 98 | tbf_limit(struct tbf *f) 99 | { 100 | tbf_update(f); 101 | 102 | if (!f->count) 103 | { 104 | f->mark = 1; 105 | return 1; 106 | } 107 | 108 | f->count--; 109 | f->mark = 0; 110 | return 0; 111 | } 112 | 113 | 114 | /* Logging and dying */ 115 | 116 | typedef struct buffer { 117 | byte *start; 118 | byte *pos; 119 | byte *end; 120 | } buffer; 121 | 122 | #define STACK_BUFFER_INIT(buf,size) \ 123 | do { \ 124 | buf.start = alloca(size); \ 125 | buf.pos = buf.start; \ 126 | buf.end = buf.start + size; \ 127 | } while(0) 128 | 129 | #define LOG_BUFFER_INIT(buf) \ 130 | STACK_BUFFER_INIT(buf, LOG_BUFFER_SIZE) 131 | 132 | #define LOG_BUFFER_SIZE 1024 133 | 134 | #define log log_msg 135 | void log_commit(int class, buffer *buf); 136 | void log_msg(const char *msg, ...); 137 | void log_rl(struct tbf *rl, const char *msg, ...); 138 | void die(const char *msg, ...) NORET; 139 | void bug(const char *msg, ...) NORET; 140 | 141 | #define L_DEBUG "\001" /* Debugging messages */ 142 | #define L_TRACE "\002" /* Protocol tracing */ 143 | #define L_INFO "\003" /* Informational messages */ 144 | #define L_REMOTE "\004" /* Remote protocol errors */ 145 | #define L_WARN "\005" /* Local warnings */ 146 | #define L_ERR "\006" /* Local errors */ 147 | #define L_AUTH "\007" /* Authorization failed etc. */ 148 | #define L_FATAL "\010" /* Fatal errors */ 149 | #define L_BUG "\011" /* BIRD bugs */ 150 | 151 | void debug(const char *msg, ...); /* Printf to debug output */ 152 | 153 | /* Debugging */ 154 | 155 | #if defined(LOCAL_DEBUG) || defined(GLOBAL_DEBUG) 156 | #define DBG(x, y...) debug(x, ##y) 157 | #else 158 | #define DBG(x, y...) do { } while(0) 159 | #endif 160 | 161 | #ifdef DEBUGGING 162 | #define ASSERT(x) do { if (!(x)) bug("Assertion `%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0) 163 | #else 164 | #define ASSERT(x) do { } while(0) 165 | #endif 166 | 167 | /* Pseudorandom numbers */ 168 | 169 | u32 random_u32(void); 170 | 171 | #endif 172 | -------------------------------------------------------------------------------- /lib/bitops.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- Generic Bit Operations 3 | * 4 | * (c) 1998 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #include "nest/bird.h" 10 | #include "bitops.h" 11 | 12 | /** 13 | * u32_mkmask - create a bit mask 14 | * @n: number of bits 15 | * 16 | * u32_mkmask() returns an unsigned 32-bit integer which binary 17 | * representation consists of @n ones followed by zeroes. 18 | */ 19 | u32 20 | u32_mkmask(uint n) 21 | { 22 | return n ? ~((1 << (32 - n)) - 1) : 0; 23 | } 24 | 25 | /** 26 | * u32_masklen - calculate length of a bit mask 27 | * @x: bit mask 28 | * 29 | * This function checks whether the given integer @x represents 30 | * a valid bit mask (binary representation contains first ones, then 31 | * zeroes) and returns the number of ones or -1 if the mask is invalid. 32 | */ 33 | int 34 | u32_masklen(u32 x) 35 | { 36 | int l = 0; 37 | u32 n = ~x; 38 | 39 | if (n & (n+1)) return -1; 40 | if (x & 0x0000ffff) { x &= 0x0000ffff; l += 16; } 41 | if (x & 0x00ff00ff) { x &= 0x00ff00ff; l += 8; } 42 | if (x & 0x0f0f0f0f) { x &= 0x0f0f0f0f; l += 4; } 43 | if (x & 0x33333333) { x &= 0x33333333; l += 2; } 44 | if (x & 0x55555555) l++; 45 | if (x & 0xaaaaaaaa) l++; 46 | return l; 47 | } 48 | 49 | /** 50 | * u32_log2 - compute a binary logarithm. 51 | * @v: number 52 | * 53 | * This function computes a integral part of binary logarithm of given 54 | * integer @v and returns it. The computed value is also an index of the 55 | * most significant non-zero bit position. 56 | */ 57 | 58 | u32 59 | u32_log2(u32 v) 60 | { 61 | /* The code from http://www-graphics.stanford.edu/~seander/bithacks.html */ 62 | u32 r, shift; 63 | r = (v > 0xFFFF) << 4; v >>= r; 64 | shift = (v > 0xFF ) << 3; v >>= shift; r |= shift; 65 | shift = (v > 0xF ) << 2; v >>= shift; r |= shift; 66 | shift = (v > 0x3 ) << 1; v >>= shift; r |= shift; 67 | r |= (v >> 1); 68 | return r; 69 | } 70 | 71 | -------------------------------------------------------------------------------- /lib/bitops.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- Generic Bit Operations 3 | * 4 | * (c) 1998 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_BITOPTS_H_ 10 | #define _BIRD_BITOPTS_H_ 11 | 12 | /* 13 | * Bit mask operations: 14 | * 15 | * u32_mkmask Make bit mask consisting of <n> consecutive ones 16 | * from the left and the rest filled with zeroes. 17 | * E.g., u32_mkmask(5) = 0xf8000000. 18 | * u32_masklen Inverse operation to u32_mkmask, -1 if not a bitmask. 19 | */ 20 | 21 | u32 u32_mkmask(uint n); 22 | int u32_masklen(u32 x); 23 | 24 | u32 u32_log2(u32 v); 25 | 26 | static inline u32 u32_hash(u32 v) { return v * 2902958171u; } 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /lib/buffer.h: -------------------------------------------------------------------------------- 1 | 2 | #define BUFFER(type) struct { type *data; uint used, size; } 3 | 4 | #define BUFFER_SIZE(v) ((v).size * sizeof(* (v).data)) 5 | 6 | #define BUFFER_INIT(v,pool,isize) \ 7 | ({ \ 8 | (v).used = 0; \ 9 | (v).size = (isize); \ 10 | (v).data = mb_alloc(pool, BUFFER_SIZE(v)); \ 11 | }) 12 | 13 | #define BUFFER_SET(v,nsize) \ 14 | ({ \ 15 | (v).used = (nsize); \ 16 | if ((v).used > (v).size) \ 17 | buffer_realloc((void **) &((v).data), &((v).size), (v).used, sizeof(* (v).data)); \ 18 | }) 19 | 20 | #define BUFFER_INC(v,step) \ 21 | ({ \ 22 | uint _o = (v).used; \ 23 | BUFFER_SET(v, (v).used + (step)); \ 24 | (v).data + _o; \ 25 | }) 26 | 27 | #define BUFFER_DEC(v,step) ({ (v).used -= (step); }) 28 | 29 | #define BUFFER_PUSH(v) (*BUFFER_INC(v,1)) 30 | 31 | #define BUFFER_POP(v) BUFFER_DEC(v,1) 32 | 33 | #define BUFFER_FLUSH(v) ({ (v).used = 0; }) 34 | 35 | 36 | -------------------------------------------------------------------------------- /lib/checksum.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- IP One-Complement Checksum 3 | * 4 | * (c) 1999--2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | /** 10 | * DOC: Miscellaneous functions. 11 | */ 12 | 13 | #include <stdarg.h> 14 | 15 | #include "nest/bird.h" 16 | #include "checksum.h" 17 | 18 | static inline u32 19 | add32(u32 sum, u32 x) 20 | { 21 | u32 z = sum + x; 22 | // return z + (z < sum); 23 | 24 | /* add carry */ 25 | if (z < x) 26 | z++; 27 | return z; 28 | } 29 | 30 | static u16 31 | ipsum_calc_block(u32 *buf, uint len, u16 isum) 32 | { 33 | /* 34 | * A few simple facts about the IP checksum (see RFC 1071 for detailed 35 | * discussion): 36 | * 37 | * o It's associative and commutative. 38 | * o It's byte order independent. 39 | * o It's word size independent. 40 | * 41 | * This gives us a neat 32-bits-at-a-time algorithm which respects 42 | * usual alignment requirements and is reasonably fast. 43 | */ 44 | 45 | ASSERT(!(len % 4)); 46 | if (!len) 47 | return isum; 48 | 49 | u32 *end = buf + (len >> 2); 50 | u32 sum = isum; 51 | while (buf < end) 52 | sum = add32(sum, *buf++); 53 | 54 | sum = (sum >> 16) + (sum & 0xffff); /* add high-16 to low-16 */ 55 | sum += (sum >> 16); /* add carry */ 56 | return sum; 57 | } 58 | 59 | static u16 60 | ipsum_calc(void *frag, uint len, va_list args) 61 | { 62 | u16 sum = 0; 63 | 64 | for(;;) 65 | { 66 | sum = ipsum_calc_block(frag, len, sum); 67 | frag = va_arg(args, void *); 68 | if (!frag) 69 | break; 70 | len = va_arg(args, uint); 71 | } 72 | return sum; 73 | } 74 | 75 | /** 76 | * ipsum_verify - verify an IP checksum 77 | * @frag: first packet fragment 78 | * @len: length in bytes 79 | * 80 | * This function verifies whether a given fragmented packet 81 | * has correct one's complement checksum as used by the IP 82 | * protocol. 83 | * 84 | * It uses all the clever tricks described in RFC 1071 to speed 85 | * up checksum calculation as much as possible. 86 | * 87 | * Result: 1 if the checksum is correct, 0 else. 88 | */ 89 | int 90 | ipsum_verify(void *frag, uint len, ...) 91 | { 92 | va_list args; 93 | u16 sum; 94 | 95 | va_start(args, len); 96 | sum = ipsum_calc(frag, len, args); 97 | va_end(args); 98 | return sum == 0xffff; 99 | } 100 | 101 | /** 102 | * ipsum_calculate - compute an IP checksum 103 | * @frag: first packet fragment 104 | * @len: length in bytes 105 | * 106 | * This function calculates a one's complement checksum of a given fragmented 107 | * packet. 108 | * 109 | * It uses all the clever tricks described in RFC 1071 to speed 110 | * up checksum calculation as much as possible. 111 | */ 112 | u16 113 | ipsum_calculate(void *frag, uint len, ...) 114 | { 115 | va_list args; 116 | u16 sum; 117 | 118 | va_start(args, len); 119 | sum = ipsum_calc(frag, len, args); 120 | va_end(args); 121 | return 0xffff - sum; 122 | } 123 | -------------------------------------------------------------------------------- /lib/checksum.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- IP One-Complement Checksum 3 | * 4 | * (c) 1999 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_CHECKSUM_H_ 10 | #define _BIRD_CHECKSUM_H_ 11 | 12 | /* 13 | * Both checksumming functions accept a vararg list of packet 14 | * fragments finished by NULL pointer. 15 | */ 16 | 17 | int ipsum_verify(void *frag, uint len, ...); 18 | u16 ipsum_calculate(void *frag, uint len, ...); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /lib/event.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- Event Processing 3 | * 4 | * (c) 1999 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | /** 10 | * DOC: Events 11 | * 12 | * Events are there to keep track of deferred execution. 13 | * Since BIRD is single-threaded, it requires long lasting tasks to be split to smaller 14 | * parts, so that no module can monopolize the CPU. To split such a task, just create 15 | * an &event resource, point it to the function you want to have called and call ev_schedule() 16 | * to ask the core to run the event when nothing more important requires attention. 17 | * 18 | * You can also define your own event lists (the &event_list structure), enqueue your 19 | * events in them and explicitly ask to run them. 20 | */ 21 | 22 | #include "nest/bird.h" 23 | #include "lib/event.h" 24 | 25 | event_list global_event_list; 26 | 27 | inline void 28 | ev_postpone(event *e) 29 | { 30 | if (ev_active(e)) 31 | { 32 | rem_node(&e->n); 33 | e->n.next = NULL; 34 | } 35 | } 36 | 37 | static void 38 | ev_dump(resource *r) 39 | { 40 | event *e = (event *) r; 41 | 42 | debug("(code %p, data %p, %s)\n", 43 | e->hook, 44 | e->data, 45 | e->n.next ? "scheduled" : "inactive"); 46 | } 47 | 48 | static struct resclass ev_class = { 49 | "Event", 50 | sizeof(event), 51 | (void (*)(resource *)) ev_postpone, 52 | ev_dump, 53 | NULL, 54 | NULL 55 | }; 56 | 57 | /** 58 | * ev_new - create a new event 59 | * @p: resource pool 60 | * 61 | * This function creates a new event resource. To use it, 62 | * you need to fill the structure fields and call ev_schedule(). 63 | */ 64 | event * 65 | ev_new(pool *p) 66 | { 67 | event *e = ralloc(p, &ev_class); 68 | return e; 69 | } 70 | 71 | /** 72 | * ev_run - run an event 73 | * @e: an event 74 | * 75 | * This function explicitly runs the event @e (calls its hook 76 | * function) and removes it from an event list if it's linked to any. 77 | * 78 | * From the hook function, you can call ev_enqueue() or ev_schedule() 79 | * to re-add the event. 80 | */ 81 | inline void 82 | ev_run(event *e) 83 | { 84 | ev_postpone(e); 85 | e->hook(e->data); 86 | } 87 | 88 | /** 89 | * ev_enqueue - enqueue an event 90 | * @l: an event list 91 | * @e: an event 92 | * 93 | * ev_enqueue() stores the event @e to the specified event 94 | * list @l which can be run by calling ev_run_list(). 95 | */ 96 | inline void 97 | ev_enqueue(event_list *l, event *e) 98 | { 99 | ev_postpone(e); 100 | add_tail(l, &e->n); 101 | } 102 | 103 | /** 104 | * ev_schedule - schedule an event 105 | * @e: an event 106 | * 107 | * This function schedules an event by enqueueing it to a system-wide 108 | * event list which is run by the platform dependent code whenever 109 | * appropriate. 110 | */ 111 | void 112 | ev_schedule(event *e) 113 | { 114 | ev_enqueue(&global_event_list, e); 115 | } 116 | 117 | void io_log_event(void *hook, void *data); 118 | 119 | /** 120 | * ev_run_list - run an event list 121 | * @l: an event list 122 | * 123 | * This function calls ev_run() for all events enqueued in the list @l. 124 | */ 125 | int 126 | ev_run_list(event_list *l) 127 | { 128 | node *n; 129 | list tmp_list; 130 | 131 | init_list(&tmp_list); 132 | add_tail_list(&tmp_list, l); 133 | init_list(l); 134 | WALK_LIST_FIRST(n, tmp_list) 135 | { 136 | event *e = SKIP_BACK(event, n, n); 137 | 138 | /* This is ugly hack, we want to log just events executed from the main I/O loop */ 139 | if (l == &global_event_list) 140 | io_log_event(e->hook, e->data); 141 | 142 | ev_run(e); 143 | } 144 | return !EMPTY_LIST(*l); 145 | } 146 | -------------------------------------------------------------------------------- /lib/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- Event Processing 3 | * 4 | * (c) 1999 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_EVENT_H_ 10 | #define _BIRD_EVENT_H_ 11 | 12 | #include "lib/resource.h" 13 | 14 | typedef struct event { 15 | resource r; 16 | void (*hook)(void *); 17 | void *data; 18 | node n; /* Internal link */ 19 | } event; 20 | 21 | typedef list event_list; 22 | 23 | extern event_list global_event_list; 24 | 25 | event *ev_new(pool *); 26 | void ev_run(event *); 27 | #define ev_init_list(el) init_list(el) 28 | void ev_enqueue(event_list *, event *); 29 | void ev_schedule(event *); 30 | void ev_postpone(event *); 31 | int ev_run_list(event_list *); 32 | 33 | static inline int 34 | ev_active(event *e) 35 | { 36 | return e->n.next != NULL; 37 | } 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /lib/lists.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- Linked Lists 3 | * 4 | * (c) 1998 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | /** 10 | * DOC: Linked lists 11 | * 12 | * The BIRD library provides a set of functions for operating on linked 13 | * lists. The lists are internally represented as standard doubly linked 14 | * lists with synthetic head and tail which makes all the basic operations 15 | * run in constant time and contain no extra end-of-list checks. Each list 16 | * is described by a &list structure, nodes can have any format as long 17 | * as they start with a &node structure. If you want your nodes to belong 18 | * to multiple lists at once, you can embed multiple &node structures in them 19 | * and use the SKIP_BACK() macro to calculate a pointer to the start of the 20 | * structure from a &node pointer, but beware of obscurity. 21 | * 22 | * There also exist safe linked lists (&slist, &snode and all functions 23 | * being prefixed with |s_|) which support asynchronous walking very 24 | * similar to that used in the &fib structure. 25 | */ 26 | 27 | #define _BIRD_LISTS_C_ 28 | 29 | #include "nest/bird.h" 30 | #include "lib/lists.h" 31 | 32 | /** 33 | * add_tail - append a node to a list 34 | * @l: linked list 35 | * @n: list node 36 | * 37 | * add_tail() takes a node @n and appends it at the end of the list @l. 38 | */ 39 | LIST_INLINE void 40 | add_tail(list *l, node *n) 41 | { 42 | node *z = l->tail; 43 | 44 | n->next = (node *) &l->null; 45 | n->prev = z; 46 | z->next = n; 47 | l->tail = n; 48 | } 49 | 50 | /** 51 | * add_head - prepend a node to a list 52 | * @l: linked list 53 | * @n: list node 54 | * 55 | * add_head() takes a node @n and prepends it at the start of the list @l. 56 | */ 57 | LIST_INLINE void 58 | add_head(list *l, node *n) 59 | { 60 | node *z = l->head; 61 | 62 | n->next = z; 63 | n->prev = (node *) &l->head; 64 | z->prev = n; 65 | l->head = n; 66 | } 67 | 68 | /** 69 | * insert_node - insert a node to a list 70 | * @n: a new list node 71 | * @after: a node of a list 72 | * 73 | * Inserts a node @n to a linked list after an already inserted 74 | * node @after. 75 | */ 76 | LIST_INLINE void 77 | insert_node(node *n, node *after) 78 | { 79 | node *z = after->next; 80 | 81 | n->next = z; 82 | n->prev = after; 83 | after->next = n; 84 | z->prev = n; 85 | } 86 | 87 | /** 88 | * rem_node - remove a node from a list 89 | * @n: node to be removed 90 | * 91 | * Removes a node @n from the list it's linked in. 92 | */ 93 | LIST_INLINE void 94 | rem_node(node *n) 95 | { 96 | node *z = n->prev; 97 | node *x = n->next; 98 | 99 | z->next = x; 100 | x->prev = z; 101 | } 102 | 103 | /** 104 | * rem2_node - remove a node from a list, with cleanup 105 | * @n: node to be removed 106 | * 107 | * Removes a node @n from the list it's linked in and resets its pointers to NULL. 108 | * Useful if you want to distinguish between linked and unlinked nodes. 109 | */ 110 | LIST_INLINE void 111 | rem2_node(node *n) 112 | { 113 | node *z = n->prev; 114 | node *x = n->next; 115 | 116 | z->next = x; 117 | x->prev = z; 118 | n->next = NULL; 119 | n->prev = NULL; 120 | } 121 | 122 | /** 123 | * replace_node - replace a node in a list with another one 124 | * @old: node to be removed 125 | * @new: node to be inserted 126 | * 127 | * Replaces node @old in the list it's linked in with node @new. Node 128 | * @old may be a copy of the original node, which is not accessed 129 | * through the list. The function could be called with @old == @new, 130 | * which just fixes neighbors' pointers in the case that the node 131 | * was reallocated. 132 | */ 133 | LIST_INLINE void 134 | replace_node(node *old, node *new) 135 | { 136 | old->next->prev = new; 137 | old->prev->next = new; 138 | 139 | new->prev = old->prev; 140 | new->next = old->next; 141 | } 142 | 143 | /** 144 | * init_list - create an empty list 145 | * @l: list 146 | * 147 | * init_list() takes a &list structure and initializes its 148 | * fields, so that it represents an empty list. 149 | */ 150 | LIST_INLINE void 151 | init_list(list *l) 152 | { 153 | l->head = (node *) &l->null; 154 | l->null = NULL; 155 | l->tail = (node *) &l->head; 156 | } 157 | 158 | /** 159 | * add_tail_list - concatenate two lists 160 | * @to: destination list 161 | * @l: source list 162 | * 163 | * This function appends all elements of the list @l to 164 | * the list @to in constant time. 165 | */ 166 | LIST_INLINE void 167 | add_tail_list(list *to, list *l) 168 | { 169 | node *p = to->tail; 170 | node *q = l->head; 171 | 172 | p->next = q; 173 | q->prev = p; 174 | q = l->tail; 175 | q->next = (node *) &to->null; 176 | to->tail = q; 177 | } 178 | -------------------------------------------------------------------------------- /lib/lists.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- Linked Lists 3 | * 4 | * (c) 1998 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_LISTS_H_ 10 | #define _BIRD_LISTS_H_ 11 | 12 | /* 13 | * I admit the list structure is very tricky and also somewhat awkward, 14 | * but it's both efficient and easy to manipulate once one understands the 15 | * basic trick: The list head always contains two synthetic nodes which are 16 | * always present in the list: the head and the tail. But as the `next' 17 | * entry of the tail and the `prev' entry of the head are both NULL, the 18 | * nodes can overlap each other: 19 | * 20 | * head head_node.next 21 | * null head_node.prev tail_node.next 22 | * tail tail_node.prev 23 | */ 24 | 25 | typedef struct node { 26 | struct node *next, *prev; 27 | } node; 28 | 29 | typedef struct list { /* In fact two overlayed nodes */ 30 | struct node *head, *null, *tail; 31 | } list; 32 | 33 | #define NODE (node *) 34 | #define HEAD(list) ((void *)((list).head)) 35 | #define TAIL(list) ((void *)((list).tail)) 36 | #define NODE_NEXT(n) ((void *)((NODE (n))->next)) 37 | #define NODE_VALID(n) ((NODE (n))->next) 38 | #define WALK_LIST(n,list) for(n=HEAD(list); NODE_VALID(n); n=NODE_NEXT(n)) 39 | #define WALK_LIST2(n,nn,list,pos) \ 40 | for(nn=(list).head; NODE_VALID(nn) && (n=SKIP_BACK(typeof(*n),pos,nn)); nn=nn->next) 41 | #define WALK_LIST_DELSAFE(n,nxt,list) \ 42 | for(n=HEAD(list); nxt=NODE_NEXT(n); n=(void *) nxt) 43 | /* WALK_LIST_FIRST supposes that called code removes each processed node */ 44 | #define WALK_LIST_FIRST(n,list) \ 45 | while(n=HEAD(list), (NODE (n))->next) 46 | #define WALK_LIST_BACKWARDS(n,list) for(n=TAIL(list);(NODE (n))->prev; \ 47 | n=(void *)((NODE (n))->prev)) 48 | #define WALK_LIST_BACKWARDS_DELSAFE(n,prv,list) \ 49 | for(n=TAIL(list); prv=(void *)((NODE (n))->prev); n=(void *) prv) 50 | 51 | #define EMPTY_LIST(list) (!(list).head->next) 52 | 53 | 54 | #ifndef _BIRD_LISTS_C_ 55 | #define LIST_INLINE static inline 56 | #include "lib/lists.c" 57 | #undef LIST_INLINE 58 | 59 | #else /* _BIRD_LISTS_C_ */ 60 | #define LIST_INLINE 61 | void add_tail(list *, node *); 62 | void add_head(list *, node *); 63 | void rem_node(node *); 64 | void rem2_node(node *); 65 | void add_tail_list(list *, list *); 66 | void init_list(list *); 67 | void insert_node(node *, node *); 68 | #endif 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /lib/md5.h: -------------------------------------------------------------------------------- 1 | #ifndef MD5_H 2 | #define MD5_H 3 | 4 | struct MD5Context { 5 | u32 buf[4]; 6 | u32 bits[2]; 7 | unsigned char in[64]; 8 | }; 9 | 10 | void MD5Init(struct MD5Context *context); 11 | void MD5Update(struct MD5Context *context, unsigned char const *buf, 12 | unsigned len); 13 | void MD5Final(unsigned char digest[16], struct MD5Context *context); 14 | void MD5Transform(u32 buf[4], u32 const in[16]); 15 | 16 | #endif /* !MD5_H */ 17 | -------------------------------------------------------------------------------- /lib/patmatch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- Generic Shell-Like Pattern Matching (currently only '?' and '*') 3 | * 4 | * (c) 1998--2000 Martin Mares <mj@ucw.cz> 5 | */ 6 | 7 | #include "nest/bird.h" 8 | #include "lib/string.h" 9 | 10 | #ifndef MATCH_FUNC_NAME 11 | #define MATCH_FUNC_NAME patmatch 12 | #endif 13 | 14 | #ifndef Convert 15 | #define Convert(x) x 16 | #endif 17 | 18 | int 19 | MATCH_FUNC_NAME(byte *p, byte *s) 20 | { 21 | while (*p) 22 | { 23 | if (*p == '?' && *s) 24 | p++, s++; 25 | else if (*p == '*') 26 | { 27 | int z = p[1]; 28 | 29 | if (!z) 30 | return 1; 31 | if (z == '\\' && p[2]) 32 | z = p[2]; 33 | z = Convert(z); 34 | for(;;) 35 | { 36 | while (*s && Convert(*s) != z) 37 | s++; 38 | if (!*s) 39 | return 0; 40 | if (MATCH_FUNC_NAME(p+1, s)) 41 | return 1; 42 | s++; 43 | } 44 | } 45 | else 46 | { 47 | if (*p == '\\' && p[1]) 48 | p++; 49 | if (Convert(*p++) != Convert(*s++)) 50 | return 0; 51 | } 52 | } 53 | return !*s; 54 | } 55 | 56 | #if 0 57 | /** 58 | * patmatch - match shell-like patterns 59 | * @p: pattern 60 | * @s: string 61 | * 62 | * patmatch() returns whether given string @s matches the given shell-like 63 | * pattern @p. The patterns consist of characters (which are matched literally), 64 | * question marks which match any single character, asterisks which match any 65 | * (possibly empty) string of characters and backslashes which are used to 66 | * escape any special characters and force them to be treated literally. 67 | * 68 | * The matching process is not optimized with respect to time, so please 69 | * avoid using this function for complex patterns. 70 | */ 71 | int 72 | patmatch(byte *p, byte *s) 73 | { DUMMY; } 74 | #endif 75 | -------------------------------------------------------------------------------- /lib/resource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Resource Manager 3 | * 4 | * (c) 1998--1999 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_RESOURCE_H_ 10 | #define _BIRD_RESOURCE_H_ 11 | 12 | #include "lib/lists.h" 13 | 14 | /* Resource */ 15 | 16 | typedef struct resource { 17 | node n; /* Inside resource pool */ 18 | struct resclass *class; /* Resource class */ 19 | } resource; 20 | 21 | /* Resource class */ 22 | 23 | struct resclass { 24 | char *name; /* Resource class name */ 25 | unsigned size; /* Standard size of single resource */ 26 | void (*free)(resource *); /* Freeing function */ 27 | void (*dump)(resource *); /* Dump to debug output */ 28 | resource *(*lookup)(resource *, unsigned long); /* Look up address (only for debugging) */ 29 | size_t (*memsize)(resource *); /* Return size of memory used by the resource, may be NULL */ 30 | }; 31 | 32 | /* Estimate of system allocator overhead per item, for memory consumtion stats */ 33 | #define ALLOC_OVERHEAD 8 34 | 35 | /* Generic resource manipulation */ 36 | 37 | typedef struct pool pool; 38 | 39 | void resource_init(void); 40 | pool *rp_new(pool *, char *); /* Create new pool */ 41 | void rfree(void *); /* Free single resource */ 42 | void rdump(void *); /* Dump to debug output */ 43 | size_t rmemsize(void *res); /* Return size of memory used by the resource */ 44 | void rlookup(unsigned long); /* Look up address (only for debugging) */ 45 | void rmove(void *, pool *); /* Move to a different pool */ 46 | 47 | void *ralloc(pool *, struct resclass *); 48 | 49 | extern pool root_pool; 50 | 51 | /* Normal memory blocks */ 52 | 53 | void *mb_alloc(pool *, unsigned size); 54 | void *mb_allocz(pool *, unsigned size); 55 | void *mb_realloc(void *m, unsigned size); 56 | void mb_free(void *); 57 | 58 | /* Memory pools with linear allocation */ 59 | 60 | typedef struct linpool linpool; 61 | 62 | linpool *lp_new(pool *, unsigned blk); 63 | void *lp_alloc(linpool *, unsigned size); /* Aligned */ 64 | void *lp_allocu(linpool *, unsigned size); /* Unaligned */ 65 | void *lp_allocz(linpool *, unsigned size); /* With clear */ 66 | void lp_flush(linpool *); /* Free everything, but leave linpool */ 67 | 68 | /* Slabs */ 69 | 70 | typedef struct slab slab; 71 | 72 | slab *sl_new(pool *, unsigned size); 73 | void *sl_alloc(slab *); 74 | void sl_free(slab *, void *); 75 | 76 | /* 77 | * Low-level memory allocation functions, please don't use 78 | * outside resource manager and possibly sysdep code. 79 | */ 80 | 81 | void buffer_realloc(void **buf, unsigned *size, unsigned need, unsigned item_size); 82 | 83 | 84 | #ifdef HAVE_LIBDMALLOC 85 | /* 86 | * The standard dmalloc macros tend to produce lots of namespace 87 | * conflicts and we use only xmalloc, xrealloc and xfree, so we 88 | * can define the stubs ourselves. 89 | */ 90 | #define DMALLOC_DISABLE 91 | #include <dmalloc.h> 92 | #define xmalloc(size) _xmalloc_leap(__FILE__, __LINE__, size) 93 | #define xrealloc(size) _xrealloc_leap(__FILE__, __LINE__, size) 94 | #define xfree(ptr) _xfree_leap(__FILE__, __LINE__, ptr) 95 | #else 96 | /* 97 | * Unfortunately, several libraries we might want to link to define 98 | * their own xmalloc and we don't want to interfere with them, hence 99 | * the renaming. 100 | */ 101 | #define xmalloc bird_xmalloc 102 | #define xrealloc bird_xrealloc 103 | void *xmalloc(unsigned); 104 | void *xrealloc(void *, unsigned); 105 | #define xfree(x) free(x) 106 | #endif 107 | 108 | #endif 109 | 110 | -------------------------------------------------------------------------------- /lib/resource.sgml: -------------------------------------------------------------------------------- 1 | <!-- 2 | BIRD Programmer's Guide: Resources 3 | 4 | (c) 2000 Martin Mares <mj@ucw.cz> 5 | --> 6 | 7 | <chapt>Resources 8 | 9 | <sect>Introduction 10 | 11 | <p>Most large software projects implemented in classical procedural 12 | programming languages usually end up with lots of code taking care 13 | of resource allocation and deallocation. Bugs in such code are often 14 | very difficult to find, because they cause only `resource leakage', 15 | that is keeping a lot of memory and other resources which nobody 16 | references to. 17 | 18 | <p>We've tried to solve this problem by employing a resource tracking 19 | system which keeps track of all the resources allocated by all the 20 | modules of BIRD, deallocates everything automatically when a module 21 | shuts down and it is able to print out the list of resources and 22 | the corresponding modules they are allocated by. 23 | 24 | <p>Each allocated resource (from now we'll speak about allocated 25 | resources only) is represented by a structure starting with a standard 26 | header (struct <struct/resource/) consisting of a list node (resources are 27 | often linked to various lists) and a pointer to <struct/resclass/ -- a resource 28 | class structure pointing to functions implementing generic resource 29 | operations (such as freeing of the resource) for the particular resource 30 | type. 31 | 32 | <p>There exist the following types of resources: 33 | 34 | <itemize> 35 | <item><it/Resource pools/ (<struct/pool/) 36 | <item><it/Memory blocks/ 37 | <item><it/Linear memory pools/ (<struct/linpool/) 38 | <item><it/Slabs/ (<struct/slab/) 39 | <item><it/Events/ (<struct/event/) 40 | <item><it/Timers/ (<struct/timer/) 41 | <item><it/Sockets/ (<struct/socket/) 42 | </itemize> 43 | -------------------------------------------------------------------------------- /lib/slists.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- Safe Linked Lists 3 | * 4 | * (c) 1998 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #define _BIRD_SLISTS_C_ 10 | 11 | #include "nest/bird.h" 12 | #include "lib/slists.h" 13 | 14 | static inline void 15 | s_merge(snode *from, snode *to) 16 | { 17 | siterator *f, *g; 18 | 19 | if (!(f = from->readers)) 20 | return; 21 | if (!(g = to->readers)) 22 | { 23 | /* Fast path */ 24 | to->readers = f; 25 | f->prev = (siterator *) to; 26 | fixup: 27 | while (f && f->node) 28 | { 29 | f->node = NULL; 30 | f = f->next; 31 | } 32 | return; 33 | } 34 | /* Really merging */ 35 | while (g->next) 36 | g = g->next; 37 | g->next = f; 38 | f->prev = g; 39 | goto fixup; 40 | } 41 | 42 | snode * 43 | s_get(siterator *i) 44 | { 45 | siterator *f, *g; 46 | snode *n; 47 | 48 | if (!(n = i->node)) 49 | { 50 | /* 51 | * No node found. We have to walk the iterator list backwards 52 | * to find where are we linked. 53 | */ 54 | f = i; 55 | while (!f->null) 56 | f = f->prev; 57 | n = (snode *) f; 58 | } 59 | f = i->prev; /* Maybe the snode itself */ 60 | g = i->next; 61 | f->next = g; 62 | if (g) 63 | g->prev = f; 64 | 65 | i->prev = NULL; 66 | i->next = NULL; 67 | return n; 68 | } 69 | 70 | void 71 | s_put(siterator *i, snode *n) 72 | { 73 | siterator *f; 74 | 75 | i->node = n; 76 | if (f = n->readers) 77 | f->prev = i; 78 | i->next = f; 79 | n->readers = i; 80 | i->prev = (siterator *) n; 81 | i->null = NULL; 82 | } 83 | 84 | void 85 | s_add_tail(slist *l, snode *n) 86 | { 87 | snode *z = l->tail; 88 | 89 | n->next = (snode *) &l->null; 90 | n->prev = z; 91 | z->next = n; 92 | l->tail = n; 93 | n->readers = NULL; 94 | } 95 | 96 | void 97 | s_add_head(slist *l, snode *n) 98 | { 99 | snode *z = l->head; 100 | 101 | n->next = z; 102 | n->prev = (snode *) &l->head; 103 | z->prev = n; 104 | l->head = n; 105 | n->readers = NULL; 106 | } 107 | 108 | void 109 | s_insert_node(snode *n, snode *after) 110 | { 111 | snode *z = after->next; 112 | 113 | n->next = z; 114 | n->prev = after; 115 | after->next = n; 116 | z->prev = n; 117 | n->readers = NULL; 118 | } 119 | 120 | void 121 | s_rem_node(snode *n) 122 | { 123 | snode *z = n->prev; 124 | snode *x = n->next; 125 | 126 | z->next = x; 127 | x->prev = z; 128 | s_merge(n, x); 129 | } 130 | 131 | void 132 | s_init_list(slist *l) 133 | { 134 | l->head = (snode *) &l->null; 135 | l->null = NULL; 136 | l->tail = (snode *) &l->head; 137 | l->tail_readers = NULL; 138 | } 139 | 140 | void 141 | s_add_tail_list(slist *to, slist *l) 142 | { 143 | snode *p = to->tail; 144 | snode *q = l->head; 145 | 146 | p->next = q; 147 | q->prev = p; 148 | q = l->tail; 149 | q->next = (snode *) &to->null; 150 | to->tail = q; 151 | s_merge((snode *) &l->null, (snode *) &to->null); 152 | } 153 | 154 | #ifdef TEST 155 | 156 | #include "lib/resource.h" 157 | #include <stdio.h> 158 | 159 | void dump(char *c, slist *a) 160 | { 161 | snode *x; 162 | 163 | puts(c); 164 | for(x=SHEAD(*a); x; x=x->next) 165 | { 166 | siterator *i, *j; 167 | printf("%p", x); 168 | j = (siterator *) x; 169 | for(i=x->readers; i; i=i->next) 170 | { 171 | if (i->prev != j) 172 | printf(" ???"); 173 | j = i; 174 | printf(" [%p:%p]", i, i->node); 175 | } 176 | putchar('\n'); 177 | } 178 | puts("---"); 179 | } 180 | 181 | int main(void) 182 | { 183 | slist a, b; 184 | snode *x, *y; 185 | siterator i, j; 186 | 187 | s_init_list(&a); 188 | s_init_list(&b); 189 | x = xmalloc(sizeof(*x)); 190 | s_add_tail(&a, x); 191 | x = xmalloc(sizeof(*x)); 192 | s_add_tail(&a, x); 193 | x = xmalloc(sizeof(*x)); 194 | s_add_tail(&a, x); 195 | dump("1", &a); 196 | 197 | s_init(&i, &a); 198 | s_init(&j, &a); 199 | dump("2", &a); 200 | 201 | x = s_get(&i); 202 | printf("Got %p\n", x); 203 | dump("3", &a); 204 | 205 | s_put(&i, x->next); 206 | dump("4", &a); 207 | 208 | y = s_get(&j); 209 | while (y) 210 | { 211 | s_put(&j, y); 212 | dump("5*", &a); 213 | y = s_get(&j)->next; 214 | } 215 | 216 | dump("5 done", &a); 217 | 218 | s_rem_node(a.head->next); 219 | dump("6 (deletion)", &a); 220 | 221 | s_put(&i, s_get(&i)->next); 222 | dump("6 (relink)", &a); 223 | 224 | x = xmalloc(sizeof(*x)); 225 | s_add_tail(&b, x); 226 | dump("7 (second list)", &b); 227 | 228 | s_add_tail_list(&b, &a); 229 | dump("8 (after merge)", &b); 230 | 231 | return 0; 232 | } 233 | 234 | #endif 235 | -------------------------------------------------------------------------------- /lib/slists.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- Safe Linked Lists 3 | * 4 | * (c) 1998 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_SLISTS_H_ 10 | #define _BIRD_SLISTS_H_ 11 | 12 | /* 13 | * These linked lists work in a way similar to standard lists defined 14 | * in lib/lists.h, but in addition to all usual list functions they 15 | * provide fast deletion/insertion/everything-safe asynchronous 16 | * walking. 17 | * 18 | * Example: 19 | * slist l; 20 | * siterator i; 21 | * snode *n; 22 | * 23 | * s_init(&i, &l); // Initialize iteration 24 | * ... 25 | * n = s_get(&i); // Some time later, fetch present 26 | * // value of the iterator and unlink it 27 | * // from the list. 28 | * while (n->next) { 29 | * ... 30 | * if (decided_to_stop) { 31 | * s_put(&i, n); // Store current position (maybe even 32 | * // that we stay at list end) 33 | * return; // and return 34 | * } 35 | * ... 36 | * } 37 | * // After finishing, don't link the iterator back 38 | */ 39 | 40 | typedef struct snode { 41 | struct snode *next, *prev; 42 | struct siterator *readers; 43 | } snode; 44 | 45 | typedef struct slist { /* In fact two overlayed snodes */ 46 | struct snode *head, *null, *tail; 47 | struct siterator *tail_readers; 48 | } slist; 49 | 50 | typedef struct siterator { 51 | /* 52 | * Caution: Layout of this structure depends hard on layout of the 53 | * snode. Our `next' must be at position of snode `readers' 54 | * field, our `null' must be at position of `prev' and it must 55 | * contain NULL in order to distinguish between siterator 56 | * and snode (snodes with NULL `prev' field never carry 57 | * iterators). You are not expected to understand this. 58 | */ 59 | struct siterator *prev, *null, *next; 60 | /* 61 | * For recently merged nodes this can be NULL, but then it's NULL 62 | * for all successors as well. This is done to speed up iterator 63 | * merging when there are lots of deletions. 64 | */ 65 | snode *node; 66 | } siterator; 67 | 68 | #define SNODE (snode *) 69 | #define SHEAD(list) ((void *)((list).head)) 70 | #define STAIL(list) ((void *)((list).tail)) 71 | #define SNODE_NEXT(n) ((void *)((SNODE (n))->next)) 72 | #define SNODE_VALID(n) ((SNODE (n))->next) 73 | 74 | #define WALK_SLIST(n,list) for(n=SHEAD(list); SNODE_VALID(n); n=SNODE_NEXT(n)) 75 | #define WALK_SLIST_DELSAFE(n,nxt,list) \ 76 | for(n=SHEAD(list); nxt=SNODE_NEXT(n); n=(void *) nxt) 77 | #define EMPTY_SLIST(list) (!(list).head->next) 78 | 79 | void s_add_tail(slist *, snode *); 80 | void s_add_head(slist *, snode *); 81 | void s_rem_node(snode *); 82 | void s_add_tail_list(slist *, slist *); 83 | void s_init_list(slist *); 84 | void s_insert_node(snode *, snode *); 85 | 86 | snode *s_get(siterator *); 87 | void s_put(siterator *, snode *n); 88 | static inline void s_init(siterator *i, slist *l) { s_put(i, SHEAD(*l)); } 89 | static inline int s_is_used(siterator *i) { return (i->prev != NULL); } 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /lib/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- String Functions 3 | * 4 | * (c) 1998 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_STRING_H_ 10 | #define _BIRD_STRING_H_ 11 | 12 | #include <stdarg.h> 13 | #include <string.h> 14 | #include <strings.h> 15 | 16 | int bsprintf(char *str, const char *fmt, ...); 17 | int bvsprintf(char *str, const char *fmt, va_list args); 18 | int bsnprintf(char *str, int size, const char *fmt, ...); 19 | int bvsnprintf(char *str, int size, const char *fmt, va_list args); 20 | 21 | int buffer_vprint(buffer *buf, const char *fmt, va_list args); 22 | int buffer_print(buffer *buf, const char *fmt, ...); 23 | void buffer_puts(buffer *buf, const char *str); 24 | 25 | int patmatch(byte *pat, byte *str); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /lib/tbf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- Token Bucket Filter 3 | * 4 | * (c) 2014 Ondrej Zajicek <santiago@crfreenet.org> 5 | * (c) 2014 CZ.NIC z.s.p.o. 6 | * 7 | * Can be freely distributed and used under the terms of the GNU GPL. 8 | */ 9 | 10 | #include "nest/bird.h" 11 | 12 | void 13 | tbf_update(struct tbf *f) 14 | { 15 | bird_clock_t delta = now - f->timestamp; 16 | 17 | if (delta == 0) 18 | return; 19 | 20 | f->timestamp = now; 21 | 22 | if ((0 < delta) && (delta < f->burst)) 23 | { 24 | u32 next = f->count + delta * f->rate; 25 | f->count = MIN(next, f->burst); 26 | } 27 | else 28 | f->count = f->burst; 29 | } 30 | -------------------------------------------------------------------------------- /lib/unaligned.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Unaligned Data Accesses -- Generic Version, Network Order 3 | * 4 | * (c) 2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_UNALIGNED_H_ 10 | #define _BIRD_UNALIGNED_H_ 11 | 12 | /* 13 | * We don't do any clever tricks with unaligned accesses since it's 14 | * virtually impossible to figure out what alignment does the CPU want 15 | * (unaligned accesses can be emulated by the OS which makes them work, 16 | * but unusably slow). We use memcpy and hope GCC will optimize it out 17 | * if possible. 18 | */ 19 | 20 | #include "lib/string.h" 21 | 22 | static inline u16 23 | get_u16(void *p) 24 | { 25 | u16 x; 26 | memcpy(&x, p, 2); 27 | return ntohs(x); 28 | } 29 | 30 | static inline u32 31 | get_u32(void *p) 32 | { 33 | u32 x; 34 | memcpy(&x, p, 4); 35 | return ntohl(x); 36 | } 37 | 38 | static inline void 39 | put_u16(void *p, u16 x) 40 | { 41 | x = htons(x); 42 | memcpy(p, &x, 2); 43 | } 44 | 45 | static inline void 46 | put_u32(void *p, u32 x) 47 | { 48 | x = htonl(x); 49 | memcpy(p, &x, 4); 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /lib/xmalloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Library -- malloc() With Checking 3 | * 4 | * (c) 1998--2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #include <stdlib.h> 10 | 11 | #include "nest/bird.h" 12 | #include "lib/resource.h" 13 | 14 | #ifndef HAVE_LIBDMALLOC 15 | 16 | /** 17 | * xmalloc - malloc with checking 18 | * @size: block size 19 | * 20 | * This function is equivalent to malloc() except that in case of 21 | * failure it calls die() to quit the program instead of returning 22 | * a %NULL pointer. 23 | * 24 | * Wherever possible, please use the memory resources instead. 25 | */ 26 | void * 27 | xmalloc(uint size) 28 | { 29 | void *p = malloc(size); 30 | if (p) 31 | return p; 32 | die("Unable to allocate %d bytes of memory", size); 33 | } 34 | 35 | /** 36 | * xrealloc - realloc with checking 37 | * @ptr: original memory block 38 | * @size: block size 39 | * 40 | * This function is equivalent to realloc() except that in case of 41 | * failure it calls die() to quit the program instead of returning 42 | * a %NULL pointer. 43 | * 44 | * Wherever possible, please use the memory resources instead. 45 | */ 46 | void * 47 | xrealloc(void *ptr, uint size) 48 | { 49 | void *p = realloc(ptr, size); 50 | if (p) 51 | return p; 52 | die("Unable to allocate %d bytes of memory", size); 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /misc/Makefile: -------------------------------------------------------------------------------- 1 | all: ips 2 | 3 | ips: ips.c 4 | gcc ips.c -o ips -lm -O2 -Wall 5 | 6 | clean: 7 | rm -f ips 8 | -------------------------------------------------------------------------------- /misc/bird.init: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # bird Starts the Internet Routing Daemon. 4 | # 5 | # Author: Ondrej Feela Filip, <feela@network.cz> 6 | # 7 | # chkconfig: - 32 75 8 | # description: Internet routing daemon supporting IPv4 routing protocols: 9 | # BGP4, RIPv2 and OSPFv2. 10 | # 11 | # processname: bird 12 | # config: /etc/bird.conf 13 | 14 | 15 | # Source function library. 16 | . /etc/rc.d/init.d/functions 17 | 18 | [ -f /etc/sysconfig/network ] || exit 0 19 | 20 | . /etc/sysconfig/network 21 | 22 | BIRD4="yes" 23 | BIRD6="yes" 24 | 25 | BIRD4ARGS= 26 | BIRD6ARGS= 27 | 28 | [ -f /etc/bird.conf ] || BIRD4="no" 29 | [ -f /usr/sbin/bird ] || BIRD4="no" 30 | [ "${NETWORKING}" = "yes" ] || BIRD4="no" 31 | 32 | [ -f /etc/bird6.conf ] || BIRD6="no" 33 | [ -f /usr/sbin/bird6 ] || BIRD6="no" 34 | [ "${NETWORKING_IPV6}" = "yes" ] || BIRD6="no" 35 | 36 | [ -e /etc/sysconfig/bird ] && . /etc/sysconfig/bird 37 | 38 | RETVAL=0 39 | 40 | # See how we were called. 41 | case "$1" in 42 | start) 43 | if [ "$BIRD4" = "yes" ] 44 | then 45 | echo -n "Starting BIRD for IPv4: " 46 | daemon bird ${BIRD4ARGS} 47 | RETVAL=$? 48 | echo 49 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/bird 50 | fi 51 | if [ "$BIRD6" = "yes" ] 52 | then 53 | echo -n "Starting BIRD for IPv6: " 54 | daemon bird6 ${BIRD6ARGS} 55 | RETVAL=$? 56 | echo 57 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/bird6 58 | fi 59 | ;; 60 | stop) 61 | echo -n "Stopping BIRD for IPv4: " 62 | killproc bird 63 | RETVAL=$? 64 | echo 65 | [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/bird 66 | 67 | echo -n "Stopping BIRD for IPv6: " 68 | killproc bird6 69 | RETVAL=$? 70 | echo 71 | [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/bird6 72 | ;; 73 | status) 74 | status bird 75 | status bird6 76 | RETVAL=$? 77 | ;; 78 | restart) 79 | $0 stop 80 | $0 start 81 | RETVAL=$? 82 | ;; 83 | reload) 84 | killproc bird -HUP 85 | RETVAL=$? 86 | echo 87 | echo -n "Reloading BIRD for IPv6: " 88 | killproc bird6 -HUP 89 | RETVAL=$? 90 | echo 91 | ;; 92 | *) 93 | echo "Usage: bird.init {start|stop|status|restart|reload}" 94 | exit 1 95 | esac 96 | 97 | exit $RETVAL 98 | -------------------------------------------------------------------------------- /misc/bird.spec: -------------------------------------------------------------------------------- 1 | Summary: BIRD Internet Routing Daemon 2 | Name: bird 3 | Version: 1.5.0 4 | Release: 1 5 | Copyright: GPL 6 | Group: Networking/Daemons 7 | Source: ftp://bird.network.cz/pub/bird/bird-%{version}.tar.gz 8 | Source1: bird.init 9 | Source2: birdc6 10 | Buildroot: /var/tmp/bird-root 11 | Url: http://bird.network.cz 12 | Prereq: /sbin/chkconfig 13 | BuildRequires: flex bison readline-devel ncurses-devel 14 | 15 | %description 16 | BIRD is dynamic routing daemon supporting IPv4 and IPv6 versions of routing 17 | protocols BGP, RIP and OSPF. 18 | 19 | %prep 20 | %setup -n bird-%{version} 21 | 22 | %build 23 | ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-ipv6 24 | make 25 | mv bird bird6 26 | make clean 27 | ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var 28 | make 29 | 30 | 31 | %install 32 | rm -rf $RPM_BUILD_ROOT/* 33 | make install prefix=$RPM_BUILD_ROOT/usr sysconfdir=$RPM_BUILD_ROOT/etc localstatedir=$RPM_BUILD_ROOT/var 34 | install bird6 $RPM_BUILD_ROOT/usr/sbin 35 | 36 | cd $RPM_BUILD_ROOT 37 | install -d etc/rc.d/init.d 38 | install $RPM_SOURCE_DIR/bird.init etc/rc.d/init.d/bird 39 | install $RPM_SOURCE_DIR/birdc6 usr/sbin/birdc6 40 | 41 | %post 42 | /sbin/ldconfig 43 | /sbin/chkconfig --add bird 44 | 45 | %preun 46 | if [ $1 = 0 ] ; then 47 | /sbin/chkconfig --del bird 48 | fi 49 | 50 | %files 51 | %attr(755,root,root) /usr/sbin/bird 52 | %attr(755,root,root) /usr/sbin/bird6 53 | %attr(755,root,root) /usr/sbin/birdc 54 | %attr(755,root,root) /usr/sbin/birdc6 55 | %attr(755,root,root) /etc/rc.d/init.d/bird 56 | -------------------------------------------------------------------------------- /misc/cisco2list: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # Convert Cisco routing table listing to list of prefixes 4 | # 5 | 6 | $loc = ($ARGV[0] eq "-l"); # Print only local prefixes 7 | 8 | while (<STDIN>) { 9 | ($loc ? /^[OR]\s/ : /^B\s/) || next; 10 | /^[ORB]( E[12])?\s+(\d+\.\d+\.\d+\.\d+)(\s|\/\d+\s)/ || die "Cannot parse $_"; 11 | $net = $2; 12 | $len = $3; 13 | if ($len =~ /^\s*$/) { 14 | # Magic rule :) 15 | $len = ($net =~ /\.0$/) ? 24 : 32; 16 | } 17 | $len =~ s/^\///; 18 | $net =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/; 19 | printf "%02x%02x%02x%02x/%d\n", $1, $2, $3, $4, $len; 20 | } 21 | -------------------------------------------------------------------------------- /misc/ips.c: -------------------------------------------------------------------------------- 1 | #include <stdio.h> 2 | #include <math.h> 3 | #include <unistd.h> 4 | #include <stdlib.h> 5 | 6 | int h[65536]; 7 | 8 | /* 9 | * Probability analysis of hashing function: 10 | * 11 | * Let n be number of items and k number of boxes. For uniform distribution 12 | * we get: 13 | * 14 | * Expected value of "item i is in given box": Xi = 1/k 15 | * Expected number of items in given box: a = EX = E(sum Xi) = sum E(Xi) = n/k 16 | * Expected square value: E(X^2) = E((sum Xi)^2) = E((sum_i Xi^2) + (sum_i,j i<>j XiXj)) = 17 | * = sum_i E(Xi^2) + sum_i,j i<>j E(XiXj) = 18 | * = sum_i E(Xi) [Xi is binary] + sum_i,j i<>j E(XiXj) [those are independent] = 19 | * = n/k + n*(n-1)/k^2 20 | * Variance: var X = E(X^2) - (EX)^2 = n/k + n*(n-1)/k^2 - n^2/k^2 = 21 | * = n/k - n/k^2 = a * (1-1/k) 22 | * Probability of fixed box being zero: Pz = ((k-1)/k)^n = (1-1/k)^n = (1-1/k)^(ak) = 23 | * = ((1-1/k)^k)^a which we can approximate by e^-a. 24 | */ 25 | 26 | uint hf(uint n) 27 | { 28 | #if 0 29 | n = (n ^ (n >> 16)) & 0xffff; 30 | n = (n ^ (n << 8)) & 0xffff; 31 | #elif 1 32 | n = (n >> 16) ^ n; 33 | n = (n ^ (n << 10)) & 0xffff; 34 | #elif 0 35 | n = (n >> 16) ^ n; 36 | n *= 259309; 37 | #elif 0 38 | n ^= (n >> 20); 39 | n ^= (n >> 10); 40 | n ^= (n >> 5); 41 | #elif 0 42 | n = (n * 259309) + ((n >> 16) * 123479); 43 | #else 44 | return random(); 45 | #endif 46 | return n; 47 | } 48 | 49 | int 50 | main(int argc, char **argv) 51 | { 52 | int cnt=0; 53 | int i; 54 | 55 | int bits = atol(argv[1]); 56 | int z = 1 << bits; 57 | int max = atol(argv[2]); 58 | 59 | while (max--) 60 | { 61 | uint i, e; 62 | if (scanf("%x/%d", &i, &e) != 2) 63 | if (feof(stdin)) 64 | break; 65 | else 66 | fprintf(stderr, "BUGGG\n"); 67 | // i >>= (32-e); 68 | // i |= (i >> e); 69 | cnt++; 70 | h[(hf(i) >> 1*(16 - bits)) & (z-1)]++; 71 | } 72 | // printf(">>> %d addresses\n", cnt); 73 | #if 0 74 | for(i=0; i<z; i++) 75 | printf("%d\t%d\n", i, h[i]); 76 | #else 77 | { 78 | int min=cnt, max=0, zer=0; 79 | double delta=0; 80 | double avg = (double) cnt / z; 81 | double exdelta = avg*(1-1/(double)z); 82 | double exzer = exp(-avg); 83 | for(i=0; i<z; i++) { 84 | if (h[i] < min) min=h[i]; 85 | if (h[i] > max) max=h[i]; 86 | delta += (h[i] - avg) * (h[i] - avg); 87 | if (!h[i]) zer++; 88 | } 89 | printf("size=%5d, min=%d, max=%2d, delta=%-7.6g (%-7.6g), avg=%-5.3g, zero=%g%% (%g%%)\n", z, min, max, delta/z, exdelta, avg, zer/(double)z*100, exzer*100); 90 | } 91 | #endif 92 | 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /misc/stats: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | make ips 4 | echo "Global tables:" 5 | for a in 4 5 6 7 8 9 10 11 12 13 14 15 ; do 6 | ./ips <global $a $((1<<($a+2))) 7 | done 8 | echo "Local tables:" 9 | ./ips <local 6 1000 10 | -------------------------------------------------------------------------------- /nest/Doc: -------------------------------------------------------------------------------- 1 | H Core 2 | S rt-fib.c 3 | S rt-table.c 4 | S rt-attr.c 5 | D proto.sgml 6 | S proto.c 7 | S proto-hooks.c 8 | S iface.c 9 | S neighbor.c 10 | S cli.c 11 | S locks.c 12 | # rt-dev.c documented in Protocols chapter 13 | -------------------------------------------------------------------------------- /nest/Makefile: -------------------------------------------------------------------------------- 1 | source=rt-table.c rt-fib.c rt-attr.c rt-roa.c proto.c iface.c rt-dev.c password.c cli.c locks.c cmds.c neighbor.c \ 2 | a-path.c a-set.c 3 | root-rel=../ 4 | dir-name=nest 5 | 6 | include ../Rules 7 | -------------------------------------------------------------------------------- /nest/attrs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Internet Routing Daemon -- Attribute Operations 3 | * 4 | * (c) 2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_ATTRS_H_ 10 | #define _BIRD_ATTRS_H_ 11 | 12 | #include <stdint.h> 13 | 14 | /* a-path.c */ 15 | 16 | #define AS_PATH_SET 1 /* Types of path segments */ 17 | #define AS_PATH_SEQUENCE 2 18 | #define AS_PATH_CONFED_SEQUENCE 3 19 | #define AS_PATH_CONFED_SET 4 20 | 21 | #define AS_PATH_MAXLEN 10000 22 | 23 | #define AS_TRANS 23456 24 | /* AS_TRANS is used when we need to store 32bit ASN larger than 0xFFFF 25 | * to 16bit slot (like in 16bit AS_PATH). See RFC 4893 for details 26 | */ 27 | 28 | struct f_tree; 29 | 30 | struct adata *as_path_prepend(struct linpool *pool, struct adata *olda, u32 as); 31 | int as_path_convert_to_old(struct adata *path, byte *dst, int *new_used); 32 | int as_path_convert_to_new(struct adata *path, byte *dst, int req_as); 33 | void as_path_format(struct adata *path, byte *buf, uint size); 34 | int as_path_getlen(struct adata *path); 35 | int as_path_getlen_int(struct adata *path, int bs); 36 | int as_path_get_first(struct adata *path, u32 *orig_as); 37 | int as_path_get_last(struct adata *path, u32 *last_as); 38 | int as_path_contains(struct adata *path, u32 as, int min); 39 | int as_path_match_set(struct adata *path, struct f_tree *set); 40 | struct adata *as_path_filter(struct linpool *pool, struct adata *path, struct f_tree *set, u32 key, int pos); 41 | 42 | 43 | #define PM_ASN 0 44 | #define PM_QUESTION 1 45 | #define PM_ASTERISK 2 46 | #define PM_ASN_EXPR 3 47 | 48 | struct f_path_mask { 49 | struct f_path_mask *next; 50 | int kind; 51 | uintptr_t val; 52 | }; 53 | 54 | int as_path_match(struct adata *path, struct f_path_mask *mask); 55 | 56 | /* a-set.c */ 57 | 58 | 59 | /* Extended Community subtypes (kinds) */ 60 | #define EC_RT 0x0002 61 | #define EC_RO 0x0003 62 | 63 | #define EC_GENERIC 0xFFFF 64 | 65 | /* Transitive bit (for first u32 half of EC) */ 66 | #define EC_TBIT 0x40000000 67 | 68 | 69 | static inline int int_set_get_size(struct adata *list) 70 | { return list->length / 4; } 71 | 72 | static inline int ec_set_get_size(struct adata *list) 73 | { return list->length / 8; } 74 | 75 | static inline u32 *int_set_get_data(struct adata *list) 76 | { return (u32 *) list->data; } 77 | 78 | static inline u32 ec_hi(u64 ec) { return ec >> 32; } 79 | static inline u32 ec_lo(u64 ec) { return ec; } 80 | static inline u64 ec_get(const u32 *l, int i) 81 | { return (((u64) l[i]) << 32) | l[i+1]; } 82 | 83 | /* RFC 4360 3.1. Two-Octet AS Specific Extended Community */ 84 | static inline u64 ec_as2(u64 kind, u64 key, u64 val) 85 | { return ((kind | 0x0000) << 48) | (key << 32) | val; } 86 | 87 | /* RFC 5668 4-Octet AS Specific BGP Extended Community */ 88 | static inline u64 ec_as4(u64 kind, u64 key, u64 val) 89 | { return ((kind | 0x0200) << 48) | (key << 16) | val; } 90 | 91 | /* RFC 4360 3.2. IPv4 Address Specific Extended Community */ 92 | static inline u64 ec_ip4(u64 kind, u64 key, u64 val) 93 | { return ((kind | 0x0100) << 48) | (key << 16) | val; } 94 | 95 | static inline u64 ec_generic(u64 key, u64 val) 96 | { return (key << 32) | val; } 97 | 98 | int int_set_format(struct adata *set, int way, int from, byte *buf, uint size); 99 | int ec_format(byte *buf, u64 ec); 100 | int ec_set_format(struct adata *set, int from, byte *buf, uint size); 101 | int int_set_contains(struct adata *list, u32 val); 102 | int ec_set_contains(struct adata *list, u64 val); 103 | struct adata *int_set_add(struct linpool *pool, struct adata *list, u32 val); 104 | struct adata *ec_set_add(struct linpool *pool, struct adata *list, u64 val); 105 | struct adata *int_set_del(struct linpool *pool, struct adata *list, u32 val); 106 | struct adata *ec_set_del(struct linpool *pool, struct adata *list, u64 val); 107 | struct adata *int_set_union(struct linpool *pool, struct adata *l1, struct adata *l2); 108 | struct adata *ec_set_union(struct linpool *pool, struct adata *l1, struct adata *l2); 109 | 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /nest/bfd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Bidirectional Forwarding Detection (BFD) 3 | * 4 | * Can be freely distributed and used under the terms of the GNU GPL. 5 | */ 6 | 7 | #ifndef _BIRD_NBFD_H_ 8 | #define _BIRD_NBFD_H_ 9 | 10 | #include "lib/lists.h" 11 | #include "lib/resource.h" 12 | 13 | struct bfd_session; 14 | 15 | struct bfd_request { 16 | resource r; 17 | node n; 18 | 19 | ip_addr addr; 20 | ip_addr local; 21 | struct iface *iface; 22 | 23 | void (*hook)(struct bfd_request *); 24 | void *data; 25 | 26 | struct bfd_session *session; 27 | 28 | u8 state; 29 | u8 diag; 30 | u8 old_state; 31 | u8 down; 32 | }; 33 | 34 | 35 | #define BFD_STATE_ADMIN_DOWN 0 36 | #define BFD_STATE_DOWN 1 37 | #define BFD_STATE_INIT 2 38 | #define BFD_STATE_UP 3 39 | 40 | 41 | #ifdef CONFIG_BFD 42 | 43 | struct bfd_request * bfd_request_session(pool *p, ip_addr addr, ip_addr local, struct iface *iface, void (*hook)(struct bfd_request *), void *data); 44 | 45 | static inline void cf_check_bfd(int use) { } 46 | 47 | #else 48 | 49 | static inline struct bfd_request * bfd_request_session(pool *p, ip_addr addr, ip_addr local, struct iface *iface, void (*hook)(struct bfd_request *), void *data) { return NULL; } 50 | 51 | static inline void cf_check_bfd(int use) { if (use) cf_error("BFD not available"); } 52 | 53 | #endif /* CONFIG_BFD */ 54 | 55 | 56 | 57 | #endif /* _BIRD_NBFD_H_ */ 58 | -------------------------------------------------------------------------------- /nest/bird.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Internet Routing Daemon -- Basic Declarations 3 | * 4 | * (c) 1998--2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_BIRD_H_ 10 | #define _BIRD_BIRD_H_ 11 | 12 | #include "sysdep/config.h" 13 | #include "lib/birdlib.h" 14 | #include "lib/ip.h" 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /nest/cli.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Internet Routing Daemon -- Command-Line Interface 3 | * 4 | * (c) 1999--2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_CLI_H_ 10 | #define _BIRD_CLI_H_ 11 | 12 | #include "lib/resource.h" 13 | #include "lib/event.h" 14 | 15 | #define CLI_RX_BUF_SIZE 4096 16 | #define CLI_TX_BUF_SIZE 4096 17 | #define CLI_MAX_ASYNC_QUEUE 4096 18 | 19 | #define CLI_MSG_SIZE 500 20 | #define CLI_LINE_SIZE 512 21 | 22 | struct cli_out { 23 | struct cli_out *next; 24 | byte *wpos, *outpos, *end; 25 | byte buf[0]; 26 | }; 27 | 28 | typedef struct cli { 29 | node n; /* Node in list of all log hooks */ 30 | pool *pool; 31 | void *priv; /* Private to sysdep layer */ 32 | byte *rx_buf, *rx_pos, *rx_aux; /* sysdep */ 33 | struct cli_out *tx_buf, *tx_pos, *tx_write; 34 | event *event; 35 | void (*cont)(struct cli *c); 36 | void (*cleanup)(struct cli *c); 37 | void *rover; /* Private to continuation routine */ 38 | int last_reply; 39 | int restricted; /* CLI is restricted to read-only commands */ 40 | struct linpool *parser_pool; /* Pool used during parsing */ 41 | byte *ring_buf; /* Ring buffer for asynchronous messages */ 42 | byte *ring_end, *ring_read, *ring_write; /* Pointers to the ring buffer */ 43 | uint ring_overflow; /* Counter of ring overflows */ 44 | uint log_mask; /* Mask of allowed message levels */ 45 | uint log_threshold; /* When free < log_threshold, store only important messages */ 46 | uint async_msg_size; /* Total size of async messages queued in tx_buf */ 47 | } cli; 48 | 49 | extern pool *cli_pool; 50 | extern struct cli *this_cli; /* Used during parsing */ 51 | 52 | #define CLI_ASYNC_CODE 10000 53 | 54 | /* Functions to be called by command handlers */ 55 | 56 | void cli_printf(cli *, int, char *, ...); 57 | #define cli_msg(x...) cli_printf(this_cli, x) 58 | void cli_set_log_echo(cli *, uint mask, uint size); 59 | 60 | /* Functions provided to sysdep layer */ 61 | 62 | cli *cli_new(void *); 63 | void cli_init(void); 64 | void cli_free(cli *); 65 | void cli_kick(cli *); 66 | void cli_written(cli *); 67 | void cli_echo(uint class, byte *msg); 68 | 69 | static inline int cli_access_restricted(void) 70 | { 71 | if (this_cli && this_cli->restricted) 72 | return (cli_printf(this_cli, 8007, "Access denied"), 1); 73 | else 74 | return 0; 75 | } 76 | 77 | /* Functions provided by sysdep layer */ 78 | 79 | void cli_write_trigger(cli *); 80 | int cli_get_command(cli *); 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /nest/cmds.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Internet Routing Daemon -- CLI Commands Which Don't Fit Anywhere Else 3 | * 4 | * (c) 2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #include "nest/bird.h" 10 | #include "nest/protocol.h" 11 | #include "nest/route.h" 12 | #include "nest/cli.h" 13 | #include "conf/conf.h" 14 | #include "nest/cmds.h" 15 | #include "lib/string.h" 16 | #include "lib/resource.h" 17 | #include "filter/filter.h" 18 | 19 | extern int shutting_down; 20 | extern int configuring; 21 | 22 | void 23 | cmd_show_status(void) 24 | { 25 | byte tim[TM_DATETIME_BUFFER_SIZE]; 26 | 27 | cli_msg(-1000, "BIRD " BIRD_VERSION); 28 | tm_format_datetime(tim, &config->tf_base, now); 29 | cli_msg(-1011, "Router ID is %R", config->router_id); 30 | cli_msg(-1011, "Current server time is %s", tim); 31 | tm_format_datetime(tim, &config->tf_base, boot_time); 32 | cli_msg(-1011, "Last reboot on %s", tim); 33 | tm_format_datetime(tim, &config->tf_base, config->load_time); 34 | cli_msg(-1011, "Last reconfiguration on %s", tim); 35 | 36 | graceful_restart_show_status(); 37 | 38 | if (shutting_down) 39 | cli_msg(13, "Shutdown in progress"); 40 | else if (configuring) 41 | cli_msg(13, "Reconfiguration in progress"); 42 | else 43 | cli_msg(13, "Daemon is up and running"); 44 | } 45 | 46 | void 47 | cmd_show_symbols(struct sym_show_data *sd) 48 | { 49 | int pos = 0; 50 | struct symbol *sym = sd->sym; 51 | 52 | if (sym) 53 | cli_msg(1010, "%-8s\t%s", sym->name, cf_symbol_class_name(sym)); 54 | else 55 | { 56 | while (sym = cf_walk_symbols(config, sym, &pos)) 57 | { 58 | if (sd->type && (sym->class != sd->type)) 59 | continue; 60 | 61 | cli_msg(-1010, "%-8s\t%s", sym->name, cf_symbol_class_name(sym)); 62 | } 63 | cli_msg(0, ""); 64 | } 65 | } 66 | 67 | static void 68 | print_size(char *dsc, size_t val) 69 | { 70 | char *px = " kMG"; 71 | int i = 0; 72 | while ((val >= 10000) && (i < 3)) 73 | { 74 | val = (val + 512) / 1024; 75 | i++; 76 | } 77 | 78 | cli_msg(-1018, "%-17s %4u %cB", dsc, (unsigned) val, px[i]); 79 | } 80 | 81 | extern pool *rt_table_pool; 82 | extern pool *rta_pool; 83 | extern pool *roa_pool; 84 | extern pool *proto_pool; 85 | 86 | void 87 | cmd_show_memory(void) 88 | { 89 | cli_msg(-1018, "BIRD memory usage"); 90 | print_size("Routing tables:", rmemsize(rt_table_pool)); 91 | print_size("Route attributes:", rmemsize(rta_pool)); 92 | print_size("ROA tables:", rmemsize(roa_pool)); 93 | print_size("Protocols:", rmemsize(proto_pool)); 94 | print_size("Total:", rmemsize(&root_pool)); 95 | cli_msg(0, ""); 96 | } 97 | 98 | void 99 | cmd_eval(struct f_inst *expr) 100 | { 101 | struct f_val v = f_eval(expr, this_cli->parser_pool); 102 | 103 | if (v.type == T_RETURN) 104 | { 105 | cli_msg(8008, "runtime error"); 106 | return; 107 | } 108 | 109 | buffer buf; 110 | LOG_BUFFER_INIT(buf); 111 | val_format(v, &buf); 112 | cli_msg(23, "%s", buf.start); 113 | } 114 | -------------------------------------------------------------------------------- /nest/cmds.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Internet Routing Daemon -- CLI Commands Which Don't Fit Anywhere Else 3 | * 4 | * (c) 2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | struct sym_show_data { 10 | int type; /* Symbols type to show */ 11 | struct symbol *sym; 12 | }; 13 | 14 | struct f_inst; 15 | 16 | void cmd_show_status(void); 17 | void cmd_show_symbols(struct sym_show_data *sym); 18 | void cmd_show_memory(void); 19 | void cmd_eval(struct f_inst *expr); 20 | -------------------------------------------------------------------------------- /nest/locks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Object Locks 3 | * 4 | * (c) 1999 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_LOCKS_H_ 10 | #define _BIRD_LOCKS_H_ 11 | 12 | #include "lib/resource.h" 13 | #include "lib/event.h" 14 | 15 | /* 16 | * The object locks are used for controlling exclusive access 17 | * to various physical resources like UDP ports on specific devices. 18 | * When you want to access such resource, you ask for a object lock 19 | * structure, fill in specification of the object and your function 20 | * you want to have called when the object is available and invoke 21 | * olock_acquire() afterwards. When the object becomes free, the lock 22 | * manager calls your function. To free the object lock, just call rfree 23 | * on its resource. 24 | */ 25 | 26 | struct object_lock { 27 | resource r; 28 | ip_addr addr; /* Identification of a object: IP address */ 29 | uint type; /* ... object type (OBJLOCK_xxx) */ 30 | uint port; /* ... port number */ 31 | uint inst; /* ... instance ID */ 32 | struct iface *iface; /* ... interface */ 33 | void (*hook)(struct object_lock *); /* Called when the lock succeeds */ 34 | void *data; /* User data */ 35 | /* ... internal to lock manager, don't touch ... */ 36 | node n; /* Node in list of olocks */ 37 | int state; /* OLOCK_STATE_xxx */ 38 | list waiters; /* Locks waiting for the same resource */ 39 | }; 40 | 41 | struct object_lock *olock_new(pool *); 42 | void olock_acquire(struct object_lock *); 43 | void olock_init(void); 44 | 45 | #define OBJLOCK_UDP 1 /* UDP port */ 46 | #define OBJLOCK_TCP 2 /* TCP port */ 47 | #define OBJLOCK_IP 3 /* IP protocol */ 48 | 49 | #define OLOCK_STATE_FREE 0 50 | #define OLOCK_STATE_LOCKED 1 51 | #define OLOCK_STATE_WAITING 2 52 | #define OLOCK_STATE_EVENT 3 /* waiting for unlock processing */ 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /nest/mrtdump.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- MRTdump handling 3 | * 4 | * 5 | * Can be freely distributed and used under the terms of the GNU GPL. 6 | */ 7 | 8 | #ifndef MRTDUMP_H 9 | #define MRTDUMP_H 10 | #include "nest/protocol.h" 11 | 12 | /* MRTDump values */ 13 | 14 | #define MRTDUMP_HDR_LENGTH 12 15 | 16 | /* MRTdump types */ 17 | 18 | #define BGP4MP 16 19 | 20 | /* MRTdump subtypes */ 21 | 22 | #define BGP4MP_MESSAGE 1 23 | #define BGP4MP_MESSAGE_AS4 4 24 | #define BGP4MP_STATE_CHANGE_AS4 5 25 | 26 | 27 | /* implemented in sysdep */ 28 | void mrt_dump_message(struct proto *p, u16 type, u16 subtype, byte *buf, u32 len); 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /nest/password.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Password handling 3 | * 4 | * (c) 1999 Pavel Machek <pavel@ucw.cz> 5 | * (c) 2004 Ondrej Filip <feela@network.cz> 6 | * 7 | * Can be freely distributed and used under the terms of the GNU GPL. 8 | */ 9 | 10 | #include "nest/bird.h" 11 | #include "nest/password.h" 12 | #include "lib/string.h" 13 | 14 | struct password_item *last_password_item = NULL; 15 | 16 | struct password_item * 17 | password_find(list *l, int first_fit) 18 | { 19 | struct password_item *pi; 20 | struct password_item *pf = NULL; 21 | 22 | if (l) 23 | { 24 | WALK_LIST(pi, *l) 25 | { 26 | if ((pi->genfrom < now_real) && (pi->gento > now_real)) 27 | { 28 | if (first_fit) 29 | return pi; 30 | 31 | if (!pf || pf->genfrom < pi->genfrom) 32 | pf = pi; 33 | } 34 | } 35 | } 36 | return pf; 37 | } 38 | 39 | struct password_item * 40 | password_find_by_id(list *l, int id) 41 | { 42 | struct password_item *pi; 43 | 44 | if (!l) 45 | return NULL; 46 | 47 | WALK_LIST(pi, *l) 48 | if ((pi->id == id) && (pi->accfrom <= now_real) && (now_real < pi->accto)) 49 | return pi; 50 | 51 | return NULL; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /nest/password.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Password handling 3 | * 4 | * (c) 1999 Pavel Machek <pavel@ucw.cz> 5 | * (c) 2004 Ondrej Filip <feela@network.cz> 6 | * 7 | * Can be freely distributed and used under the terms of the GNU GPL. 8 | */ 9 | 10 | #ifndef PASSWORD_H 11 | #define PASSWORD_H 12 | #include "lib/timer.h" 13 | 14 | #define MD5_AUTH_SIZE 16 15 | 16 | struct password_item { 17 | node n; 18 | char *password; 19 | int id; 20 | bird_clock_t accfrom, accto, genfrom, gento; 21 | }; 22 | 23 | extern struct password_item *last_password_item; 24 | 25 | struct password_item *password_find(list *l, int first_fit); 26 | struct password_item *password_find_by_id(list *l, int id); 27 | 28 | static inline int password_verify(struct password_item *p1, char *p2, uint size) 29 | { 30 | char buf[size]; 31 | strncpy(buf, p1->password, size); 32 | return !memcmp(buf, p2, size); 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /nest/proto.sgml: -------------------------------------------------------------------------------- 1 | <!-- 2 | BIRD Programmer's Guide: Protocols 3 | 4 | (c) 2000 Martin Mares <mj@ucw.cz> 5 | --> 6 | 7 | <sect>Routing protocols 8 | 9 | <sect1>Introduction 10 | 11 | <p>The routing protocols are the bird's heart and a fine amount of code 12 | is dedicated to their management and for providing support functions to them. 13 | (-: Actually, this is the reason why the directory with sources of the core 14 | code is called <tt/nest/ :-). 15 | 16 | <p>When talking about protocols, one need to distinguish between <em/protocols/ 17 | and protocol <em/instances/. A protocol exists exactly once, not depending on whether 18 | it's configured or not and it can have an arbitrary number of instances corresponding 19 | to its "incarnations" requested by the configuration file. Each instance is completely 20 | autonomous, has its own configuration, its own status, its own set of routes and its 21 | own set of interfaces it works on. 22 | 23 | <p>A protocol is represented by a <struct/protocol/ structure containing all the basic 24 | information (protocol name, default settings and pointers to most of the protocol 25 | hooks). All these structures are linked in the <param/protocol_list/ list. 26 | 27 | <p>Each instance has its own <struct/proto/ structure describing all its properties: protocol 28 | type, configuration, a resource pool where all resources belonging to the instance 29 | live, various protocol attributes (take a look at the declaration of <struct/proto/ in 30 | <tt/protocol.h/), protocol states (see below for what do they mean), connections 31 | to routing tables, filters attached to the protocol 32 | and finally a set of pointers to the rest of protocol hooks (they 33 | are the same for all instances of the protocol, but in order to avoid extra 34 | indirections when calling the hooks from the fast path, they are stored directly 35 | in <struct/proto/). The instance is always linked in both the global instance list 36 | (<param/proto_list/) and a per-status list (either <param/active_proto_list/ for 37 | running protocols, <param/initial_proto_list/ for protocols being initialized or 38 | <param/flush_proto_list/ when the protocol is being shut down). 39 | 40 | <p>The protocol hooks are described in the next chapter, for more information about 41 | configuration of protocols, please refer to the configuration chapter and also 42 | to the description of the <func/proto_commit/ function. 43 | 44 | <sect1>Protocol states 45 | 46 | <p>As startup and shutdown of each protocol are complex processes which can be affected 47 | by lots of external events (user's actions, reconfigurations, behavior of neighboring routers etc.), 48 | we have decided to supervise them by a pair of simple state machines -- the protocol 49 | state machine and a core state machine. 50 | 51 | <p>The <em/protocol state machine/ corresponds to internal state of the protocol 52 | and the protocol can alter its state whenever it wants to. There are 53 | the following states: 54 | 55 | <descrip> 56 | <tag/PS_DOWN/ The protocol is down and waits for being woken up by calling its 57 | start() hook. 58 | <tag/PS_START/ The protocol is waiting for connection with the rest of the 59 | network. It's active, it has resources allocated, but it still doesn't want 60 | any routes since it doesn't know what to do with them. 61 | <tag/PS_UP/ The protocol is up and running. It communicates with the core, 62 | delivers routes to tables and wants to hear announcement about route changes. 63 | <tag/PS_STOP/ The protocol has been shut down (either by being asked by the 64 | core code to do so or due to having encountered a protocol error). 65 | </descrip> 66 | 67 | <p>Unless the protocol is in the <tt/PS_DOWN/ state, it can decide to change 68 | its state by calling the <func/proto_notify_state/ function. 69 | 70 | <p>At any time, the core code can ask the protocol to shut itself down by calling its stop() hook. 71 | 72 | <p>The <em/core state machine/ takes care of the core view of protocol state. 73 | The states are traversed according to changes of the protocol state machine, but 74 | sometimes the transitions are delayed if the core needs to finish some actions 75 | (for example sending of new routes to the protocol) before proceeding to the 76 | new state. There are the following core states: 77 | 78 | <descrip> 79 | <tag/FS_HUNGRY/ The protocol is down, it doesn't have any routes and 80 | doesn't want them. 81 | <tag/FS_FEEDING/ The protocol has reached the <tt/PS_UP/ state, but 82 | we are still busy sending the initial set of routes to it. 83 | <tag/FS_HAPPY/ The protocol is up and has complete routing information. 84 | <tag/FS_FLUSHING/ The protocol is shutting down (it's in either <tt/PS_STOP/ 85 | or <tt/PS_DOWN/ state) and we're flushing all of its routes from the 86 | routing tables. 87 | </descrip> 88 | 89 | <sect1>Functions of the protocol module 90 | 91 | <p>The protocol module provides the following functions: 92 | -------------------------------------------------------------------------------- /nest/rt-dev.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Direct Device Routes 3 | * 4 | * (c) 1998--2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | /** 10 | * DOC: Direct 11 | * 12 | * The Direct protocol works by converting all ifa_notify() events it receives 13 | * to rte_update() calls for the corresponding network. 14 | */ 15 | 16 | #undef LOCAL_DEBUG 17 | 18 | #include "nest/bird.h" 19 | #include "nest/iface.h" 20 | #include "nest/protocol.h" 21 | #include "nest/route.h" 22 | #include "nest/rt-dev.h" 23 | #include "conf/conf.h" 24 | #include "lib/resource.h" 25 | #include "lib/string.h" 26 | 27 | static void 28 | dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad) 29 | { 30 | struct rt_dev_config *P = (void *) p->cf; 31 | 32 | if (!EMPTY_LIST(P->iface_list) && 33 | !iface_patt_find(&P->iface_list, ad->iface, ad->iface->addr)) 34 | /* Empty list is automagically treated as "*" */ 35 | return; 36 | 37 | if (ad->flags & IA_SECONDARY) 38 | return; 39 | 40 | if (ad->scope <= SCOPE_LINK) 41 | return; 42 | 43 | if (c & IF_CHANGE_DOWN) 44 | { 45 | net *n; 46 | 47 | DBG("dev_if_notify: %s:%I going down\n", ad->iface->name, ad->ip); 48 | n = net_find(p->table, ad->prefix, ad->pxlen); 49 | if (!n) 50 | { 51 | DBG("dev_if_notify: device shutdown: prefix not found\n"); 52 | return; 53 | } 54 | 55 | /* Use iface ID as local source ID */ 56 | struct rte_src *src = rt_get_source(p, ad->iface->index); 57 | rte_update2(p->main_ahook, n, NULL, src); 58 | } 59 | else if (c & IF_CHANGE_UP) 60 | { 61 | rta *a; 62 | net *n; 63 | rte *e; 64 | 65 | DBG("dev_if_notify: %s:%I going up\n", ad->iface->name, ad->ip); 66 | 67 | /* Use iface ID as local source ID */ 68 | struct rte_src *src = rt_get_source(p, ad->iface->index); 69 | 70 | rta a0 = { 71 | .src = src, 72 | .source = RTS_DEVICE, 73 | .scope = SCOPE_UNIVERSE, 74 | .cast = RTC_UNICAST, 75 | .dest = RTD_DEVICE, 76 | .iface = ad->iface 77 | }; 78 | 79 | a = rta_lookup(&a0); 80 | n = net_get(p->table, ad->prefix, ad->pxlen); 81 | e = rte_get_temp(a); 82 | e->net = n; 83 | e->pflags = 0; 84 | rte_update2(p->main_ahook, n, e, src); 85 | } 86 | } 87 | 88 | static struct proto * 89 | dev_init(struct proto_config *c) 90 | { 91 | struct proto *p = proto_new(c, sizeof(struct proto)); 92 | 93 | p->ifa_notify = dev_ifa_notify; 94 | return p; 95 | } 96 | 97 | static int 98 | dev_reconfigure(struct proto *p, struct proto_config *new) 99 | { 100 | struct rt_dev_config *o = (struct rt_dev_config *) p->cf; 101 | struct rt_dev_config *n = (struct rt_dev_config *) new; 102 | 103 | return iface_patts_equal(&o->iface_list, &n->iface_list, NULL); 104 | } 105 | 106 | static void 107 | dev_copy_config(struct proto_config *dest, struct proto_config *src) 108 | { 109 | struct rt_dev_config *d = (struct rt_dev_config *) dest; 110 | struct rt_dev_config *s = (struct rt_dev_config *) src; 111 | 112 | /* 113 | * We copy iface_list as ifaces can be shared by more direct protocols. 114 | * Copy suffices to be is shallow, because new nodes can be added, but 115 | * old nodes cannot be modified (although they contain internal lists). 116 | */ 117 | cfg_copy_list(&d->iface_list, &s->iface_list, sizeof(struct iface_patt)); 118 | } 119 | 120 | struct protocol proto_device = { 121 | .name = "Direct", 122 | .template = "direct%d", 123 | .preference = DEF_PREF_DIRECT, 124 | .config_size = sizeof(struct rt_dev_config), 125 | .init = dev_init, 126 | .reconfigure = dev_reconfigure, 127 | .copy_config = dev_copy_config 128 | }; 129 | -------------------------------------------------------------------------------- /nest/rt-dev.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Direct Device Routes 3 | * 4 | * (c) 1998--1999 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_RT_DEV_H_ 10 | #define _BIRD_RT_DEV_H_ 11 | 12 | struct rt_dev_config { 13 | struct proto_config c; 14 | list iface_list; /* list of struct iface_patt */ 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /proto/Doc: -------------------------------------------------------------------------------- 1 | H Protocols 2 | C bfd 3 | C bgp 4 | C ospf 5 | C pipe 6 | C rip 7 | C radv 8 | C static 9 | S ../nest/rt-dev.c 10 | -------------------------------------------------------------------------------- /proto/bfd/Doc: -------------------------------------------------------------------------------- 1 | S bfd.c 2 | -------------------------------------------------------------------------------- /proto/bfd/Makefile: -------------------------------------------------------------------------------- 1 | source=bfd.c packets.c io.c 2 | root-rel=../../ 3 | dir-name=proto/bfd 4 | 5 | include ../../Rules 6 | -------------------------------------------------------------------------------- /proto/bfd/config.Y: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Router Advertisement Configuration 3 | * 4 | * 5 | * Can be freely distributed and used under the terms of the GNU GPL. 6 | */ 7 | 8 | CF_HDR 9 | 10 | #include "proto/bfd/bfd.h" 11 | 12 | CF_DEFINES 13 | 14 | #define BFD_CFG ((struct bfd_config *) this_proto) 15 | #define BFD_IFACE ((struct bfd_iface_config *) this_ipatt) 16 | #define BFD_NEIGHBOR this_bfd_neighbor 17 | 18 | static struct bfd_neighbor *this_bfd_neighbor; 19 | 20 | extern struct bfd_config *bfd_cf; 21 | 22 | CF_DECLS 23 | 24 | CF_KEYWORDS(BFD, MIN, IDLE, RX, TX, INTERVAL, MULTIPLIER, PASSIVE, 25 | INTERFACE, MULTIHOP, NEIGHBOR, DEV, LOCAL) 26 | 27 | %type <iface> bfd_neigh_iface 28 | %type <a> bfd_neigh_local 29 | %type <i> bfd_neigh_multihop 30 | 31 | CF_GRAMMAR 32 | 33 | CF_ADDTO(proto, bfd_proto) 34 | 35 | bfd_proto_start: proto_start BFD 36 | { 37 | this_proto = proto_config_new(&proto_bfd, $1); 38 | init_list(&BFD_CFG->patt_list); 39 | init_list(&BFD_CFG->neigh_list); 40 | 41 | if (bfd_cf) 42 | cf_error("Only one BFD instance allowed"); 43 | bfd_cf = BFD_CFG; 44 | }; 45 | 46 | bfd_proto_item: 47 | proto_item 48 | | INTERFACE bfd_iface 49 | | MULTIHOP bfd_multihop 50 | | NEIGHBOR bfd_neighbor 51 | ; 52 | 53 | bfd_proto_opts: 54 | /* empty */ 55 | | bfd_proto_opts bfd_proto_item ';' 56 | ; 57 | 58 | bfd_proto: 59 | bfd_proto_start proto_name '{' bfd_proto_opts '}'; 60 | 61 | 62 | bfd_iface_start: 63 | { 64 | this_ipatt = cfg_allocz(sizeof(struct bfd_iface_config)); 65 | init_list(&this_ipatt->ipn_list); 66 | 67 | BFD_IFACE->min_rx_int = BFD_DEFAULT_MIN_RX_INT; 68 | BFD_IFACE->min_tx_int = BFD_DEFAULT_MIN_TX_INT; 69 | BFD_IFACE->idle_tx_int = BFD_DEFAULT_IDLE_TX_INT; 70 | BFD_IFACE->multiplier = BFD_DEFAULT_MULTIPLIER; 71 | }; 72 | 73 | bfd_iface_item: 74 | INTERVAL expr_us { BFD_IFACE->min_rx_int = BFD_IFACE->min_tx_int = $2; } 75 | | MIN RX INTERVAL expr_us { BFD_IFACE->min_rx_int = $4; } 76 | | MIN TX INTERVAL expr_us { BFD_IFACE->min_tx_int = $4; } 77 | | IDLE TX INTERVAL expr_us { BFD_IFACE->idle_tx_int = $4; } 78 | | MULTIPLIER expr { BFD_IFACE->multiplier = $2; } 79 | | PASSIVE bool { BFD_IFACE->passive = $2; } 80 | ; 81 | 82 | bfd_iface_opts: 83 | /* empty */ 84 | | bfd_iface_opts bfd_iface_item ';' 85 | ; 86 | 87 | bfd_iface_opt_list: 88 | /* empty */ 89 | | '{' bfd_iface_opts '}' 90 | ; 91 | 92 | bfd_iface: bfd_iface_start iface_patt_list_nopx bfd_iface_opt_list 93 | { add_tail(&BFD_CFG->patt_list, NODE this_ipatt); }; 94 | 95 | bfd_multihop: bfd_iface_start bfd_iface_opt_list 96 | { BFD_CFG->multihop = BFD_IFACE; }; 97 | 98 | 99 | bfd_neigh_iface: 100 | /* empty */ { $$ = NULL; } 101 | | '%' SYM { $$ = if_get_by_name($2->name); } 102 | | DEV text { $$ = if_get_by_name($2); } 103 | ; 104 | 105 | bfd_neigh_local: 106 | /* empty */ { $$ = IPA_NONE; } 107 | | LOCAL ipa { $$ = $2; } 108 | ; 109 | 110 | bfd_neigh_multihop: 111 | /* empty */ { $$ = 0; } 112 | | MULTIHOP bool { $$ = $2; } 113 | ; 114 | 115 | bfd_neighbor: ipa bfd_neigh_iface bfd_neigh_local bfd_neigh_multihop 116 | { 117 | this_bfd_neighbor = cfg_allocz(sizeof(struct bfd_neighbor)); 118 | add_tail(&BFD_CFG->neigh_list, NODE this_bfd_neighbor); 119 | 120 | BFD_NEIGHBOR->addr = $1; 121 | BFD_NEIGHBOR->local = $3; 122 | BFD_NEIGHBOR->iface = $2; 123 | BFD_NEIGHBOR->multihop = $4; 124 | 125 | if ($4 && $2) 126 | cf_error("Neighbor cannot set both interface and multihop"); 127 | 128 | if ($4 && ipa_zero($3)) 129 | cf_error("Multihop neighbor requires specified local address"); 130 | }; 131 | 132 | 133 | CF_CLI_HELP(SHOW BFD, ..., [[Show information about BFD protocol]]); 134 | CF_CLI(SHOW BFD SESSIONS, optsym, [<name>], [[Show information about BFD sessions]]) 135 | { bfd_show_sessions(proto_get_named($4, &proto_bfd)); }; 136 | 137 | CF_CODE 138 | 139 | CF_END 140 | -------------------------------------------------------------------------------- /proto/bfd/io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- I/O and event loop 3 | * 4 | * Can be freely distributed and used under the terms of the GNU GPL. 5 | */ 6 | 7 | #ifndef _BIRD_BFD_IO_H_ 8 | #define _BIRD_BFD_IO_H_ 9 | 10 | #include "nest/bird.h" 11 | #include "lib/lists.h" 12 | #include "lib/resource.h" 13 | #include "lib/event.h" 14 | #include "lib/socket.h" 15 | // #include "lib/timer.h" 16 | 17 | 18 | typedef struct timer2 19 | { 20 | resource r; 21 | void (*hook)(struct timer2 *); 22 | void *data; 23 | 24 | btime expires; /* 0=inactive */ 25 | uint randomize; /* Amount of randomization */ 26 | uint recurrent; /* Timer recurrence */ 27 | 28 | int index; 29 | } timer2; 30 | 31 | 32 | btime current_time(void); 33 | 34 | void ev2_schedule(event *e); 35 | 36 | 37 | timer2 *tm2_new(pool *p); 38 | void tm2_set(timer2 *t, btime when); 39 | void tm2_start(timer2 *t, btime after); 40 | void tm2_stop(timer2 *t); 41 | 42 | static inline int 43 | tm2_active(timer2 *t) 44 | { 45 | return t->expires != 0; 46 | } 47 | 48 | static inline btime 49 | tm2_remains(timer2 *t) 50 | { 51 | btime now = current_time(); 52 | return (t->expires > now) ? (t->expires - now) : 0; 53 | } 54 | 55 | static inline timer2 * 56 | tm2_new_init(pool *p, void (*hook)(struct timer2 *), void *data, uint rec, uint rand) 57 | { 58 | timer2 *t = tm2_new(p); 59 | t->hook = hook; 60 | t->data = data; 61 | t->recurrent = rec; 62 | t->randomize = rand; 63 | return t; 64 | } 65 | 66 | static inline void 67 | tm2_set_max(timer2 *t, btime when) 68 | { 69 | if (when > t->expires) 70 | tm2_set(t, when); 71 | } 72 | 73 | /* 74 | static inline void 75 | tm2_start_max(timer2 *t, btime after) 76 | { 77 | btime rem = tm2_remains(t); 78 | tm2_start(t, MAX_(rem, after)); 79 | } 80 | */ 81 | 82 | 83 | void sk_start(sock *s); 84 | void sk_stop(sock *s); 85 | 86 | 87 | 88 | struct birdloop *birdloop_new(void); 89 | void birdloop_start(struct birdloop *loop); 90 | void birdloop_stop(struct birdloop *loop); 91 | void birdloop_free(struct birdloop *loop); 92 | 93 | void birdloop_enter(struct birdloop *loop); 94 | void birdloop_leave(struct birdloop *loop); 95 | void birdloop_mask_wakeups(struct birdloop *loop); 96 | void birdloop_unmask_wakeups(struct birdloop *loop); 97 | 98 | 99 | #endif /* _BIRD_BFD_IO_H_ */ 100 | -------------------------------------------------------------------------------- /proto/bgp/Doc: -------------------------------------------------------------------------------- 1 | S bgp.c 2 | S packets.c 3 | S attrs.c 4 | -------------------------------------------------------------------------------- /proto/bgp/Makefile: -------------------------------------------------------------------------------- 1 | source=bgp.c attrs.c packets.c 2 | root-rel=../../ 3 | dir-name=proto/bgp 4 | 5 | include ../../Rules 6 | -------------------------------------------------------------------------------- /proto/ospf/Doc: -------------------------------------------------------------------------------- 1 | S ospf.c 2 | S topology.c 3 | S neighbor.c 4 | S iface.c 5 | S packet.c 6 | S lsalib.c 7 | S dbdes.c 8 | S rt.c 9 | -------------------------------------------------------------------------------- /proto/ospf/Makefile: -------------------------------------------------------------------------------- 1 | source=ospf.c topology.c packet.c hello.c neighbor.c iface.c dbdes.c lsreq.c lsupd.c lsack.c lsalib.c rt.c 2 | root-rel=../../ 3 | dir-name=proto/ospf 4 | 5 | include ../../Rules 6 | -------------------------------------------------------------------------------- /proto/ospf/lsalib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- OSPF 3 | * 4 | * (c) 1999--2000 Ondrej Filip <feela@network.cz> 5 | * (c) 2009--2014 Ondrej Zajicek <santiago@crfreenet.org> 6 | * (c) 2009--2014 CZ.NIC z.s.p.o. 7 | * 8 | * Can be freely distributed and used under the terms of the GNU GPL. 9 | */ 10 | 11 | #ifndef _BIRD_OSPF_LSALIB_H_ 12 | #define _BIRD_OSPF_LSALIB_H_ 13 | 14 | #ifdef CPU_BIG_ENDIAN 15 | static inline void lsa_hton_hdr(struct ospf_lsa_header *h, struct ospf_lsa_header *n) { *n = *h; }; 16 | static inline void lsa_ntoh_hdr(struct ospf_lsa_header *n, struct ospf_lsa_header *h) { *h = *n; }; 17 | static inline void lsa_hton_body(void *h, void *n, u16 len) { ASSERT(h != n); memcpy(n, h, len); }; 18 | static inline void lsa_ntoh_body(void *n, void *h, u16 len) { ASSERT(n != h); memcpy(h, n, len); }; 19 | static inline void lsa_hton_body1(void *h, u16 len) { }; 20 | static inline void lsa_ntoh_body1(void *n, u16 len) { }; 21 | #else 22 | void lsa_hton_hdr(struct ospf_lsa_header *h, struct ospf_lsa_header *n); 23 | void lsa_ntoh_hdr(struct ospf_lsa_header *n, struct ospf_lsa_header *h); 24 | void lsa_hton_body(void *h, void *n, u16 len); 25 | void lsa_ntoh_body(void *n, void *h, u16 len); 26 | static inline void lsa_hton_body1(void *h, u16 len) { lsa_hton_body(h, h, len); }; 27 | static inline void lsa_ntoh_body1(void *n, u16 len) { lsa_ntoh_body(n, n, len); }; 28 | #endif 29 | 30 | struct ospf_lsa_rt_walk { 31 | struct top_hash_entry *en; 32 | void *buf, *bufend; 33 | int ospf2; 34 | u16 type, metric; 35 | u32 id, data, lif, nif; 36 | }; 37 | 38 | 39 | void lsa_get_type_domain_(u32 itype, struct ospf_iface *ifa, u32 *otype, u32 *domain); 40 | 41 | static inline void lsa_get_type_domain(struct ospf_lsa_header *lsa, struct ospf_iface *ifa, u32 *otype, u32 *domain) 42 | { lsa_get_type_domain_(lsa->type_raw, ifa, otype, domain); } 43 | 44 | static inline u32 lsa_get_etype(struct ospf_lsa_header *h, struct ospf_proto *p) 45 | { return ospf_is_v2(p) ? (h->type_raw & LSA_T_V2_MASK) : h->type_raw; } 46 | 47 | 48 | int lsa_flooding_allowed(u32 type, u32 domain, struct ospf_iface *ifa); 49 | void lsa_generate_checksum(struct ospf_lsa_header *lsa, const u8 *body); 50 | u16 lsa_verify_checksum(const void *lsa_n, int lsa_len); 51 | 52 | #define CMP_NEWER 1 53 | #define CMP_SAME 0 54 | #define CMP_OLDER -1 55 | int lsa_comp(struct ospf_lsa_header *l1, struct ospf_lsa_header *l2); 56 | void lsa_walk_rt_init(struct ospf_proto *po, struct top_hash_entry *act, struct ospf_lsa_rt_walk *rt); 57 | int lsa_walk_rt(struct ospf_lsa_rt_walk *rt); 58 | void lsa_parse_sum_net(struct top_hash_entry *en, int ospf2, ip_addr *ip, int *pxlen, u8 *pxopts, u32 *metric); 59 | void lsa_parse_sum_rt(struct top_hash_entry *en, int ospf2, u32 *drid, u32 *metric, u32 *options); 60 | void lsa_parse_ext(struct top_hash_entry *en, int ospf2, struct ospf_lsa_ext_local *rt); 61 | int lsa_validate(struct ospf_lsa_header *lsa, u32 lsa_type, int ospf2, void *body); 62 | 63 | #endif /* _BIRD_OSPF_LSALIB_H_ */ 64 | -------------------------------------------------------------------------------- /proto/ospf/lsreq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- OSPF 3 | * 4 | * (c) 2000--2004 Ondrej Filip <feela@network.cz> 5 | * (c) 2009--2014 Ondrej Zajicek <santiago@crfreenet.org> 6 | * (c) 2009--2014 CZ.NIC z.s.p.o. 7 | * 8 | * Can be freely distributed and used under the terms of the GNU GPL. 9 | */ 10 | 11 | #include "ospf.h" 12 | 13 | 14 | /* 15 | struct ospf_lsreq_packet 16 | { 17 | struct ospf_packet hdr; 18 | // union ospf_auth auth; 19 | 20 | struct ospf_lsreq_header lsrs[]; 21 | }; 22 | */ 23 | 24 | 25 | static inline void 26 | ospf_lsreq_body(struct ospf_proto *p, struct ospf_packet *pkt, 27 | struct ospf_lsreq_header **body, uint *count) 28 | { 29 | uint plen = ntohs(pkt->length); 30 | uint hlen = ospf_pkt_hdrlen(p); 31 | 32 | *body = ((void *) pkt) + hlen; 33 | *count = (plen - hlen) / sizeof(struct ospf_lsreq_header); 34 | } 35 | 36 | static void 37 | ospf_dump_lsreq(struct ospf_proto *p, struct ospf_packet *pkt) 38 | { 39 | struct ospf_lsreq_header *lsrs; 40 | uint i, lsr_count; 41 | 42 | ASSERT(pkt->type == LSREQ_P); 43 | ospf_dump_common(p, pkt); 44 | 45 | ospf_lsreq_body(p, pkt, &lsrs, &lsr_count); 46 | for (i = 0; i < lsr_count; i++) 47 | log(L_TRACE "%s: LSR Type: %04x, Id: %R, Rt: %R", p->p.name, 48 | ntohl(lsrs[i].type), ntohl(lsrs[i].id), ntohl(lsrs[i].rt)); 49 | } 50 | 51 | 52 | void 53 | ospf_send_lsreq(struct ospf_proto *p, struct ospf_neighbor *n) 54 | { 55 | struct ospf_iface *ifa = n->ifa; 56 | struct ospf_lsreq_header *lsrs; 57 | struct top_hash_entry *req; 58 | struct ospf_packet *pkt; 59 | uint i, lsr_max, length; 60 | 61 | /* RFC 2328 10.9 */ 62 | 63 | /* ASSERT((n->state >= NEIGHBOR_EXCHANGE) && !EMPTY_SLIST(n->lsrql)); */ 64 | 65 | pkt = ospf_tx_buffer(ifa); 66 | ospf_pkt_fill_hdr(ifa, pkt, LSREQ_P); 67 | ospf_lsreq_body(p, pkt, &lsrs, &lsr_max); 68 | 69 | i = 0; 70 | WALK_SLIST(req, n->lsrql) 71 | { 72 | if (i == lsr_max) 73 | break; 74 | 75 | DBG("Requesting %uth LSA: Type: %04u, ID: %R, RT: %R, SN: 0x%x, Age %u\n", 76 | i, req->lsa_type, req->lsa.id, req->lsa.rt, req->lsa.sn, req->lsa.age); 77 | 78 | u32 etype = lsa_get_etype(&req->lsa, p); 79 | lsrs[i].type = htonl(etype); 80 | lsrs[i].rt = htonl(req->lsa.rt); 81 | lsrs[i].id = htonl(req->lsa.id); 82 | i++; 83 | } 84 | 85 | /* We store the position to see whether requested LSAs have been received */ 86 | n->lsrqi = req; 87 | 88 | length = ospf_pkt_hdrlen(p) + i * sizeof(struct ospf_lsreq_header); 89 | pkt->length = htons(length); 90 | 91 | OSPF_PACKET(ospf_dump_lsreq, pkt, "LSREQ packet sent to nbr %R on %s", n->rid, ifa->ifname); 92 | ospf_send_to(ifa, n->ip); 93 | } 94 | 95 | 96 | void 97 | ospf_receive_lsreq(struct ospf_packet *pkt, struct ospf_iface *ifa, 98 | struct ospf_neighbor *n) 99 | { 100 | struct ospf_proto *p = ifa->oa->po; 101 | struct ospf_lsreq_header *lsrs; 102 | uint i, lsr_count; 103 | 104 | /* RFC 2328 10.7 */ 105 | 106 | /* No need to check length, lsreq has only basic header */ 107 | 108 | OSPF_PACKET(ospf_dump_lsreq, pkt, "LSREQ packet received from nbr %R on %s", n->rid, ifa->ifname); 109 | 110 | if (n->state < NEIGHBOR_EXCHANGE) 111 | { 112 | OSPF_TRACE(D_PACKETS, "LSREQ packet ignored - lesser state than Exchange"); 113 | return; 114 | } 115 | 116 | ospf_neigh_sm(n, INM_HELLOREC); /* Not in RFC */ 117 | 118 | ospf_lsreq_body(p, pkt, &lsrs, &lsr_count); 119 | 120 | struct top_hash_entry *en, *entries[lsr_count]; 121 | 122 | for (i = 0; i < lsr_count; i++) 123 | { 124 | u32 id, rt, type, domain; 125 | 126 | id = ntohl(lsrs[i].id); 127 | rt = ntohl(lsrs[i].rt); 128 | lsa_get_type_domain_(ntohl(lsrs[i].type), ifa, &type, &domain); 129 | 130 | DBG("Processing requested LSA: Type: %04x, Id: %R, Rt: %R\n", type, id, rt); 131 | 132 | en = ospf_hash_find(p->gr, domain, id, rt, type); 133 | if (!en) 134 | { 135 | LOG_LSA1("Bad LSR (Type: %04x, Id: %R, Rt: %R) in LSREQ", type, id, rt); 136 | LOG_LSA2(" received from nbr %R on %s - LSA is missing", n->rid, ifa->ifname); 137 | 138 | ospf_neigh_sm(n, INM_BADLSREQ); 139 | return; 140 | } 141 | 142 | entries[i] = en; 143 | } 144 | 145 | ospf_send_lsupd(p, entries, lsr_count, n); 146 | } 147 | -------------------------------------------------------------------------------- /proto/pipe/Doc: -------------------------------------------------------------------------------- 1 | S pipe.c 2 | -------------------------------------------------------------------------------- /proto/pipe/Makefile: -------------------------------------------------------------------------------- 1 | source=pipe.c 2 | root-rel=../../ 3 | dir-name=proto/pipe 4 | 5 | include ../../Rules 6 | 7 | -------------------------------------------------------------------------------- /proto/pipe/config.Y: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Table-to-Table Protocol Configuration 3 | * 4 | * (c) 1999 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | CF_HDR 10 | 11 | #include "proto/pipe/pipe.h" 12 | 13 | CF_DEFINES 14 | 15 | #define PIPE_CFG ((struct pipe_config *) this_proto) 16 | 17 | CF_DECLS 18 | 19 | CF_KEYWORDS(PIPE, PEER, TABLE, MODE, OPAQUE, TRANSPARENT) 20 | 21 | CF_GRAMMAR 22 | 23 | CF_ADDTO(proto, pipe_proto '}') 24 | 25 | pipe_proto_start: proto_start PIPE { 26 | this_proto = proto_config_new(&proto_pipe, $1); 27 | PIPE_CFG->mode = PIPE_TRANSPARENT; 28 | } 29 | ; 30 | 31 | pipe_proto: 32 | pipe_proto_start proto_name '{' 33 | | pipe_proto proto_item ';' 34 | | pipe_proto PEER TABLE SYM ';' { 35 | if ($4->class != SYM_TABLE) 36 | cf_error("Routing table name expected"); 37 | PIPE_CFG->peer = $4->def; 38 | } 39 | | pipe_proto MODE OPAQUE ';' { PIPE_CFG->mode = PIPE_OPAQUE; } 40 | | pipe_proto MODE TRANSPARENT ';' { PIPE_CFG->mode = PIPE_TRANSPARENT; } 41 | ; 42 | 43 | CF_CODE 44 | 45 | CF_END 46 | -------------------------------------------------------------------------------- /proto/pipe/pipe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Table-to-Table Routing Protocol a.k.a Pipe 3 | * 4 | * (c) 1999 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_PIPE_H_ 10 | #define _BIRD_PIPE_H_ 11 | 12 | #define PIPE_OPAQUE 0 13 | #define PIPE_TRANSPARENT 1 14 | 15 | struct pipe_config { 16 | struct proto_config c; 17 | struct rtable_config *peer; /* Table we're connected to */ 18 | int mode; /* PIPE_OPAQUE or PIPE_TRANSPARENT */ 19 | }; 20 | 21 | struct pipe_proto { 22 | struct proto p; 23 | struct rtable *peer_table; 24 | struct announce_hook *peer_ahook; /* Announce hook for direction peer->primary */ 25 | struct proto_stats peer_stats; /* Statistics for the direction peer->primary */ 26 | int mode; /* PIPE_OPAQUE or PIPE_TRANSPARENT */ 27 | }; 28 | 29 | 30 | extern struct protocol proto_pipe; 31 | 32 | static inline int proto_is_pipe(struct proto *p) 33 | { return p->proto == &proto_pipe; } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /proto/radv/Doc: -------------------------------------------------------------------------------- 1 | S radv.c 2 | S packets.c 3 | -------------------------------------------------------------------------------- /proto/radv/Makefile: -------------------------------------------------------------------------------- 1 | source=radv.c packets.c 2 | root-rel=../../ 3 | dir-name=proto/radv 4 | 5 | include ../../Rules 6 | -------------------------------------------------------------------------------- /proto/rip/Doc: -------------------------------------------------------------------------------- 1 | S rip.c 2 | S auth.c 3 | -------------------------------------------------------------------------------- /proto/rip/Makefile: -------------------------------------------------------------------------------- 1 | source=rip.c auth.c 2 | root-rel=../../ 3 | dir-name=proto/rip 4 | 5 | include ../../Rules 6 | -------------------------------------------------------------------------------- /proto/rip/config.Y: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- RIP Configuration 3 | * 4 | * Can be freely distributed and used under the terms of the GNU GPL. 5 | */ 6 | 7 | /* 8 | To add: 9 | 10 | version1 switch 11 | 12 | */ 13 | 14 | 15 | CF_HDR 16 | 17 | #include "proto/rip/rip.h" 18 | #include "nest/iface.h" 19 | 20 | CF_DEFINES 21 | 22 | #define RIP_CFG ((struct rip_proto_config *) this_proto) 23 | #define RIP_IPATT ((struct rip_patt *) this_ipatt) 24 | 25 | #ifdef IPV6 26 | #define RIP_DEFAULT_TTL_SECURITY 2 27 | #else 28 | #define RIP_DEFAULT_TTL_SECURITY 0 29 | #endif 30 | 31 | CF_DECLS 32 | 33 | CF_KEYWORDS(RIP, INFINITY, METRIC, PORT, PERIOD, GARBAGE, TIMEOUT, 34 | MODE, BROADCAST, MULTICAST, QUIET, NOLISTEN, VERSION1, 35 | AUTHENTICATION, NONE, PLAINTEXT, MD5, TTL, SECURITY, 36 | HONOR, NEVER, NEIGHBOR, ALWAYS, TX, PRIORITY, ONLY, 37 | RIP_METRIC, RIP_TAG) 38 | 39 | %type <i> rip_mode rip_auth 40 | 41 | CF_GRAMMAR 42 | 43 | CF_ADDTO(proto, rip_cfg '}' { RIP_CFG->passwords = get_passwords(); } ) 44 | 45 | rip_cfg_start: proto_start RIP { 46 | this_proto = proto_config_new(&proto_rip, $1); 47 | rip_init_config(RIP_CFG); 48 | } 49 | ; 50 | 51 | rip_cfg: 52 | rip_cfg_start proto_name '{' 53 | | rip_cfg proto_item ';' 54 | | rip_cfg INFINITY expr ';' { RIP_CFG->infinity = $3; } 55 | | rip_cfg PORT expr ';' { RIP_CFG->port = $3; } 56 | | rip_cfg PERIOD expr ';' { RIP_CFG->period = $3; } 57 | | rip_cfg GARBAGE TIME expr ';' { RIP_CFG->garbage_time = $4; } 58 | | rip_cfg TIMEOUT TIME expr ';' { RIP_CFG->timeout_time = $4; } 59 | | rip_cfg AUTHENTICATION rip_auth ';' {RIP_CFG->authtype = $3; } 60 | | rip_cfg password_list ';' 61 | | rip_cfg HONOR ALWAYS ';' { RIP_CFG->honor = HO_ALWAYS; } 62 | | rip_cfg HONOR NEIGHBOR ';' { RIP_CFG->honor = HO_NEIGHBOR; } 63 | | rip_cfg HONOR NEVER ';' { RIP_CFG->honor = HO_NEVER; } 64 | | rip_cfg INTERFACE rip_iface ';' 65 | ; 66 | 67 | rip_auth: 68 | PLAINTEXT { $$=AT_PLAINTEXT; } 69 | | MD5 { $$=AT_MD5; } 70 | | NONE { $$=AT_NONE; } 71 | ; 72 | 73 | 74 | rip_mode: 75 | BROADCAST { $$=IM_BROADCAST; } 76 | | MULTICAST { $$=0; } 77 | | QUIET { $$=IM_QUIET; } 78 | | NOLISTEN { $$=IM_NOLISTEN; } 79 | | VERSION1 { $$=IM_VERSION1 | IM_BROADCAST; } 80 | ; 81 | 82 | rip_iface_item: 83 | | METRIC expr { RIP_IPATT->metric = $2; } 84 | | MODE rip_mode { RIP_IPATT->mode |= $2; } 85 | | TX tos { RIP_IPATT->tx_tos = $2; } 86 | | TX PRIORITY expr { RIP_IPATT->tx_priority = $3; } 87 | | TTL SECURITY bool { RIP_IPATT->ttl_security = $3; } 88 | | TTL SECURITY TX ONLY { RIP_IPATT->ttl_security = 2; } 89 | ; 90 | 91 | rip_iface_opts: 92 | /* empty */ 93 | | rip_iface_opts rip_iface_item ';' 94 | ; 95 | 96 | rip_iface_opt_list: 97 | /* empty */ 98 | | '{' rip_iface_opts '}' 99 | ; 100 | 101 | rip_iface_init: 102 | /* EMPTY */ { 103 | this_ipatt = cfg_allocz(sizeof(struct rip_patt)); 104 | add_tail(&RIP_CFG->iface_list, NODE this_ipatt); 105 | init_list(&this_ipatt->ipn_list); 106 | RIP_IPATT->metric = 1; 107 | RIP_IPATT->tx_tos = IP_PREC_INTERNET_CONTROL; 108 | RIP_IPATT->tx_priority = sk_priority_control; 109 | RIP_IPATT->ttl_security = RIP_DEFAULT_TTL_SECURITY; 110 | } 111 | ; 112 | 113 | rip_iface: /* TODO: switch to iface_patt_list_nopx */ 114 | rip_iface_init iface_patt_list rip_iface_opt_list 115 | ; 116 | 117 | CF_ADDTO(dynamic_attr, RIP_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_RIP_METRIC); }) 118 | CF_ADDTO(dynamic_attr, RIP_TAG { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_RIP_TAG); }) 119 | 120 | CF_CODE 121 | 122 | CF_END 123 | -------------------------------------------------------------------------------- /proto/rip/rip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Structures for RIP protocol 3 | * 4 | FIXME: in V6, they insert additional entry whenever next hop differs. Such entry is identified by 0xff in metric. 5 | */ 6 | 7 | #include "nest/route.h" 8 | #include "nest/password.h" 9 | #include "nest/locks.h" 10 | 11 | #define EA_RIP_TAG EA_CODE(EAP_RIP, 0) 12 | #define EA_RIP_METRIC EA_CODE(EAP_RIP, 1) 13 | 14 | #define PACKET_MAX 25 15 | #define PACKET_MD5_MAX 18 /* FIXME */ 16 | 17 | 18 | #define RIP_V1 1 19 | #define RIP_V2 2 20 | #define RIP_NG 1 /* A new version numbering */ 21 | 22 | #ifndef IPV6 23 | #define RIP_PORT 520 /* RIP for IPv4 */ 24 | #else 25 | #define RIP_PORT 521 /* RIPng */ 26 | #endif 27 | 28 | struct rip_connection { 29 | node n; 30 | 31 | int num; 32 | struct proto *proto; 33 | ip_addr addr; 34 | sock *send; 35 | struct rip_interface *rif; 36 | struct fib_iterator iter; 37 | 38 | ip_addr daddr; 39 | int dport; 40 | int done; 41 | }; 42 | 43 | struct rip_packet_heading { /* 4 bytes */ 44 | u8 command; 45 | #define RIPCMD_REQUEST 1 /* want info */ 46 | #define RIPCMD_RESPONSE 2 /* responding to request */ 47 | #define RIPCMD_TRACEON 3 /* turn tracing on */ 48 | #define RIPCMD_TRACEOFF 4 /* turn it off */ 49 | #define RIPCMD_MAX 5 50 | u8 version; 51 | #define RIP_V1 1 52 | #define RIP_V2 2 53 | #define RIP_NG 1 /* this is verion 1 of RIPng */ 54 | u16 unused; 55 | }; 56 | 57 | #ifndef IPV6 58 | struct rip_block { /* 20 bytes */ 59 | u16 family; /* 0xffff on first message means this is authentication */ 60 | u16 tag; 61 | ip_addr network; 62 | ip_addr netmask; 63 | ip_addr nexthop; 64 | u32 metric; 65 | }; 66 | #else 67 | struct rip_block { /* IPv6 version!, 20 bytes, too */ 68 | ip_addr network; 69 | u16 tag; 70 | u8 pxlen; 71 | u8 metric; 72 | }; 73 | #endif 74 | 75 | struct rip_block_auth { /* 20 bytes */ 76 | u16 mustbeFFFF; 77 | u16 authtype; 78 | u16 packetlen; 79 | u8 keyid; 80 | u8 authlen; 81 | u32 seq; 82 | u32 zero0; 83 | u32 zero1; 84 | }; 85 | 86 | struct rip_md5_tail { /* 20 bytes */ 87 | u16 mustbeFFFF; 88 | u16 mustbe0001; 89 | char md5[16]; 90 | }; 91 | 92 | struct rip_entry { 93 | struct fib_node n; 94 | 95 | ip_addr whotoldme; 96 | ip_addr nexthop; 97 | int metric; 98 | u16 tag; 99 | 100 | bird_clock_t updated, changed; 101 | int flags; 102 | }; 103 | 104 | struct rip_packet { 105 | struct rip_packet_heading heading; 106 | struct rip_block block[PACKET_MAX]; 107 | }; 108 | 109 | struct rip_interface { 110 | node n; 111 | struct proto *proto; 112 | struct iface *iface; 113 | sock *sock; 114 | struct rip_connection *busy; 115 | int metric; /* You don't want to put struct rip_patt *patt here -- think about reconfigure */ 116 | int mode; 117 | int check_ttl; /* Check incoming packets for TTL 255 */ 118 | int triggered; 119 | struct object_lock *lock; 120 | int multicast; 121 | }; 122 | 123 | struct rip_patt { 124 | struct iface_patt i; 125 | 126 | int metric; /* If you add entries here, don't forget to modify patt_compare! */ 127 | int mode; 128 | #define IM_BROADCAST 2 129 | #define IM_QUIET 4 130 | #define IM_NOLISTEN 8 131 | #define IM_VERSION1 16 132 | int tx_tos; 133 | int tx_priority; 134 | int ttl_security; /* bool + 2 for TX only (send, but do not check on RX) */ 135 | }; 136 | 137 | struct rip_proto_config { 138 | struct proto_config c; 139 | list iface_list; /* Patterns configured -- keep it first; see rip_reconfigure why */ 140 | list *passwords; /* Passwords, keep second */ 141 | 142 | int infinity; /* User configurable data; must be comparable with memcmp */ 143 | int port; 144 | int period; 145 | int garbage_time; 146 | int timeout_time; 147 | 148 | int authtype; 149 | #define AT_NONE 0 150 | #define AT_PLAINTEXT 2 151 | #define AT_MD5 3 152 | int honor; 153 | #define HO_NEVER 0 154 | #define HO_NEIGHBOR 1 155 | #define HO_ALWAYS 2 156 | }; 157 | 158 | struct rip_proto { 159 | struct proto inherited; 160 | timer *timer; 161 | list connections; 162 | struct fib rtable; 163 | list garbage; 164 | list interfaces; /* Interfaces we really know about */ 165 | #ifdef LOCAL_DEBUG 166 | int magic; 167 | #endif 168 | int tx_count; /* Do one regular update once in a while */ 169 | int rnd_count; /* Randomize sending time */ 170 | }; 171 | 172 | #ifdef LOCAL_DEBUG 173 | #define RIP_MAGIC 81861253 174 | #define CHK_MAGIC do { if (P->magic != RIP_MAGIC) bug( "Not enough magic" ); } while (0) 175 | #else 176 | #define CHK_MAGIC do { } while (0) 177 | #endif 178 | 179 | 180 | void rip_init_config(struct rip_proto_config *c); 181 | 182 | /* Authentication functions */ 183 | 184 | int rip_incoming_authentication( struct proto *p, struct rip_block_auth *block, struct rip_packet *packet, int num, ip_addr whotoldme ); 185 | int rip_outgoing_authentication( struct proto *p, struct rip_block_auth *block, struct rip_packet *packet, int num ); 186 | -------------------------------------------------------------------------------- /proto/static/Doc: -------------------------------------------------------------------------------- 1 | S static.c 2 | -------------------------------------------------------------------------------- /proto/static/Makefile: -------------------------------------------------------------------------------- 1 | source=static.c 2 | root-rel=../../ 3 | dir-name=proto/static 4 | 5 | include ../../Rules 6 | 7 | -------------------------------------------------------------------------------- /proto/static/config.Y: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Static Protocol Configuration 3 | * 4 | * (c) 1998--1999 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | CF_HDR 10 | 11 | #include "proto/static/static.h" 12 | 13 | CF_DEFINES 14 | 15 | #define STATIC_CFG ((struct static_config *) this_proto) 16 | static struct static_route *this_srt, *this_srt_nh, *last_srt_nh; 17 | static struct f_inst **this_srt_last_cmd; 18 | 19 | static void 20 | static_route_finish(void) 21 | { 22 | struct static_route *r; 23 | 24 | /* Update undefined use_bfd entries in multipath nexthops */ 25 | if (this_srt->dest == RTD_MULTIPATH) 26 | for (r = this_srt->mp_next; r; r = r->mp_next) 27 | if (r->use_bfd < 0) 28 | r->use_bfd = this_srt->use_bfd; 29 | } 30 | 31 | CF_DECLS 32 | 33 | CF_KEYWORDS(STATIC, ROUTE, VIA, DROP, REJECT, PROHIBIT, PREFERENCE, CHECK, LINK) 34 | CF_KEYWORDS(MULTIPATH, WEIGHT, RECURSIVE, IGP, TABLE, BLACKHOLE, UNREACHABLE, BFD) 35 | 36 | 37 | CF_GRAMMAR 38 | 39 | CF_ADDTO(proto, static_proto '}') 40 | 41 | static_proto_start: proto_start STATIC { 42 | this_proto = proto_config_new(&proto_static, $1); 43 | static_init_config((struct static_config *) this_proto); 44 | } 45 | ; 46 | 47 | static_proto: 48 | static_proto_start proto_name '{' 49 | | static_proto proto_item ';' 50 | | static_proto CHECK LINK bool ';' { STATIC_CFG->check_link = $4; } 51 | | static_proto IGP TABLE rtable ';' { STATIC_CFG->igp_table = $4; } 52 | | static_proto stat_route stat_route_opt_list ';' { static_route_finish(); } 53 | ; 54 | 55 | stat_route0: ROUTE prefix { 56 | this_srt = cfg_allocz(sizeof(struct static_route)); 57 | add_tail(&STATIC_CFG->other_routes, &this_srt->n); 58 | this_srt->net = $2.addr; 59 | this_srt->masklen = $2.len; 60 | this_srt_last_cmd = &(this_srt->cmds); 61 | } 62 | ; 63 | 64 | stat_multipath1: 65 | VIA ipa ipa_scope { 66 | last_srt_nh = this_srt_nh; 67 | this_srt_nh = cfg_allocz(sizeof(struct static_route)); 68 | this_srt_nh->dest = RTD_NONE; 69 | this_srt_nh->via = $2; 70 | this_srt_nh->via_if = $3; 71 | this_srt_nh->if_name = (void *) this_srt; /* really */ 72 | this_srt_nh->use_bfd = -1; /* undefined */ 73 | } 74 | | stat_multipath1 WEIGHT expr { 75 | this_srt_nh->masklen = $3 - 1; /* really */ 76 | if (($3<1) || ($3>256)) cf_error("Weight must be in range 1-256"); 77 | } 78 | | stat_multipath1 BFD bool { 79 | this_srt_nh->use_bfd = $3; cf_check_bfd($3); 80 | } 81 | ; 82 | 83 | stat_multipath: 84 | stat_multipath1 { this_srt->mp_next = this_srt_nh; } 85 | | stat_multipath stat_multipath1 { last_srt_nh->mp_next = this_srt_nh; } 86 | ; 87 | 88 | stat_route: 89 | stat_route0 VIA ipa ipa_scope { 90 | this_srt->dest = RTD_ROUTER; 91 | this_srt->via = $3; 92 | this_srt->via_if = $4; 93 | } 94 | | stat_route0 VIA TEXT { 95 | this_srt->dest = RTD_DEVICE; 96 | this_srt->if_name = $3; 97 | rem_node(&this_srt->n); 98 | add_tail(&STATIC_CFG->iface_routes, &this_srt->n); 99 | } 100 | | stat_route0 MULTIPATH stat_multipath { 101 | this_srt->dest = RTD_MULTIPATH; 102 | } 103 | | stat_route0 RECURSIVE ipa { 104 | this_srt->dest = RTDX_RECURSIVE; 105 | this_srt->via = $3; 106 | } 107 | 108 | | stat_route0 DROP { this_srt->dest = RTD_BLACKHOLE; } 109 | | stat_route0 REJECT { this_srt->dest = RTD_UNREACHABLE; } 110 | | stat_route0 BLACKHOLE { this_srt->dest = RTD_BLACKHOLE; } 111 | | stat_route0 UNREACHABLE { this_srt->dest = RTD_UNREACHABLE; } 112 | | stat_route0 PROHIBIT { this_srt->dest = RTD_PROHIBIT; } 113 | ; 114 | 115 | stat_route_item: 116 | cmd { *this_srt_last_cmd = $1; this_srt_last_cmd = &($1->next); } 117 | | BFD bool ';' { this_srt->use_bfd = $2; cf_check_bfd($2); } 118 | ; 119 | 120 | stat_route_opts: 121 | /* empty */ 122 | | stat_route_opts stat_route_item 123 | ; 124 | 125 | stat_route_opt_list: 126 | /* empty */ 127 | | '{' stat_route_opts '}' 128 | ; 129 | 130 | 131 | CF_CLI(SHOW STATIC, optsym, [<name>], [[Show details of static protocol]]) 132 | { static_show(proto_get_named($3, &proto_static)); } ; 133 | 134 | CF_CODE 135 | 136 | CF_END 137 | -------------------------------------------------------------------------------- /proto/static/static.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Static Route Generator 3 | * 4 | * (c) 1998--2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_STATIC_H_ 10 | #define _BIRD_STATIC_H_ 11 | 12 | #include "nest/route.h" 13 | #include "nest/bfd.h" 14 | 15 | struct static_config { 16 | struct proto_config c; 17 | list iface_routes; /* Routes to search on interface events */ 18 | list other_routes; /* Routes hooked to neighbor cache and reject routes */ 19 | int check_link; /* Whether iface link state is used */ 20 | struct rtable_config *igp_table; /* Table used for recursive next hop lookups */ 21 | }; 22 | 23 | 24 | void static_init_config(struct static_config *); 25 | 26 | struct static_route { 27 | node n; 28 | struct static_route *chain; /* Next for the same neighbor */ 29 | ip_addr net; /* Network we route */ 30 | int masklen; /* Mask length */ 31 | int dest; /* Destination type (RTD_*) */ 32 | ip_addr via; /* Destination router */ 33 | struct iface *via_if; /* Destination iface, for link-local vias */ 34 | struct neighbor *neigh; 35 | byte *if_name; /* Name for RTD_DEVICE routes */ 36 | struct static_route *mp_next; /* Nexthops for RTD_MULTIPATH routes */ 37 | struct f_inst *cmds; /* List of commands for setting attributes */ 38 | int installed; /* Installed in rt table, -1 for reinstall */ 39 | int use_bfd; /* Configured to use BFD */ 40 | struct bfd_request *bfd_req; /* BFD request, if BFD is used */ 41 | }; 42 | 43 | /* Dummy nodes (parts of multipath route) abuses masklen field for weight 44 | and if_name field for a ptr to the master (RTD_MULTIPATH) node. */ 45 | 46 | 47 | #define RTDX_RECURSIVE 0x7f /* Phony dest value for recursive routes */ 48 | 49 | void static_show(struct proto *); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /sysdep/Doc: -------------------------------------------------------------------------------- 1 | D sysdep.sgml 2 | C unix 3 | -------------------------------------------------------------------------------- /sysdep/autoconf.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains all system parameters automatically 3 | * discovered by the configure script. 4 | */ 5 | 6 | /* System configuration file */ 7 | #define SYSCONF_INCLUDE ? 8 | 9 | /* Include debugging code */ 10 | #undef DEBUGGING 11 | 12 | /* 8-bit integer type */ 13 | #define INTEGER_8 ? 14 | 15 | /* 16-bit integer type */ 16 | #define INTEGER_16 ? 17 | 18 | /* 32-bit integer type */ 19 | #define INTEGER_32 ? 20 | 21 | /* 64-bit integer type */ 22 | #define INTEGER_64 ? 23 | 24 | /* CPU endianity */ 25 | #undef CPU_LITTLE_ENDIAN 26 | #undef CPU_BIG_ENDIAN 27 | 28 | /* Usual alignment for structures */ 29 | #define CPU_STRUCT_ALIGN 1 30 | 31 | /* Characteristics of time_t */ 32 | #undef TIME_T_IS_64BIT 33 | #undef TIME_T_IS_SIGNED 34 | 35 | /* We have struct ip_mreqn in <netinet/in.h> */ 36 | #undef HAVE_STRUCT_IP_MREQN 37 | 38 | /* Protocols compiled in */ 39 | #undef CONFIG_STATIC 40 | #undef CONFIG_RIP 41 | #undef CONFIG_RADV 42 | #undef CONFIG_BFD 43 | #undef CONFIG_BGP 44 | #undef CONFIG_OSPF 45 | #undef CONFIG_PIPE 46 | 47 | /* We use multithreading */ 48 | #undef USE_PTHREADS 49 | 50 | /* We have <syslog.h> and syslog() */ 51 | #undef HAVE_SYSLOG 52 | 53 | /* We have <alloca.h> */ 54 | #undef HAVE_ALLOCA_H 55 | 56 | /* Are we using dmalloc? */ 57 | #undef HAVE_LIBDMALLOC 58 | 59 | /* Readline stuff */ 60 | #undef HAVE_RL_CRLF 61 | #undef HAVE_RL_DING 62 | 63 | /* struct sockaddr_in(6) */ 64 | #undef HAVE_SIN_LEN 65 | 66 | /* We have stdint.h */ 67 | #undef HAVE_STDINT_H 68 | 69 | #define CONFIG_PATH ? 70 | -------------------------------------------------------------------------------- /sysdep/bsd/Modules: -------------------------------------------------------------------------------- 1 | krt-sock.c 2 | krt-sock.Y 3 | krt-sys.h 4 | sysio.h 5 | -------------------------------------------------------------------------------- /sysdep/bsd/krt-sock.Y: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- BSD Kernel Syncer Configuration 3 | * 4 | * (c) 1999--2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | CF_HDR 10 | 11 | CF_DECLS 12 | 13 | CF_KEYWORDS(KERNEL, TABLE) 14 | 15 | CF_GRAMMAR 16 | 17 | CF_ADDTO(kern_proto, kern_proto kern_sys_item ';') 18 | 19 | kern_sys_item: 20 | KERNEL TABLE expr { 21 | if ($3 && (krt_max_tables == 1)) 22 | cf_error("Multiple kernel routing tables not supported"); 23 | if ($3 < 0 || $3 >= krt_max_tables) 24 | cf_error("Kernel table id must be in range 0-%d", krt_max_tables - 1); 25 | 26 | THIS_KRT->sys.table_id = $3; 27 | } 28 | ; 29 | 30 | CF_CODE 31 | 32 | CF_END 33 | -------------------------------------------------------------------------------- /sysdep/bsd/krt-sys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- *BSD Kernel Route Syncer 3 | * 4 | * (c) 2004 Ondrej Filip <feela@network.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_KRT_SYS_H_ 10 | #define _BIRD_KRT_SYS_H_ 11 | 12 | struct birdsock; 13 | 14 | /* Kernel interfaces */ 15 | 16 | struct kif_params { 17 | }; 18 | 19 | struct kif_state { 20 | }; 21 | 22 | 23 | static inline void kif_sys_init(struct kif_proto *p UNUSED) { } 24 | static inline int kif_sys_reconfigure(struct kif_proto *p UNUSED, struct kif_config *n UNUSED, struct kif_config *o UNUSED) { return 1; } 25 | 26 | static inline void kif_sys_preconfig(struct config *c UNUSED) { } 27 | static inline void kif_sys_postconfig(struct kif_config *c UNUSED) { } 28 | static inline void kif_sys_init_config(struct kif_config *c UNUSED) { } 29 | static inline void kif_sys_copy_config(struct kif_config *d UNUSED, struct kif_config *s UNUSED) { } 30 | 31 | 32 | /* Kernel routes */ 33 | 34 | extern int krt_max_tables; 35 | 36 | struct krt_params { 37 | int table_id; /* Kernel table ID we sync with */ 38 | }; 39 | 40 | struct krt_state { 41 | struct birdsock *sk; 42 | }; 43 | 44 | 45 | static inline void krt_sys_init(struct krt_proto *p UNUSED) { } 46 | 47 | static inline int krt_sys_get_attr(eattr *a UNUSED, byte *buf UNUSED, int buflen UNUSED) { } 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /sysdep/cf/README: -------------------------------------------------------------------------------- 1 | Available configuration variables: 2 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | 4 | CONFIG_AUTO_ROUTES Device routes are added automagically by the kernel 5 | CONFIG_SELF_CONSCIOUS We're able to recognize whether route was installed by us 6 | CONFIG_MULTIPLE_TABLES The kernel supports multiple routing tables 7 | CONFIG_ALL_TABLES_AT_ONCE Kernel scanner wants to process all tables at once 8 | CONFIG_SINGLE_ROUTE There is only one route per network 9 | 10 | CONFIG_MC_PROPER_SRC Multicast packets have source address according to socket saddr field 11 | CONFIG_SKIP_MC_BIND Don't call bind on multicast socket (def for *BSD) 12 | CONFIG_NO_IFACE_BIND Bind to iface is not available, use workarounds (def for *BSD) 13 | CONFIG_UNIX_DONTROUTE Use setsockopts DONTROUTE (undef for *BSD) 14 | CONFIG_USE_HDRINCL Use IP_HDRINCL instead of control messages for source address on raw IP sockets. 15 | 16 | CONFIG_RESTRICTED_PRIVILEGES Implements restricted privileges using drop_uid() 17 | -------------------------------------------------------------------------------- /sysdep/cf/bsd-v6.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Configuration for *BSD based systems (tested on FreeBSD and NetBSD) 3 | * 4 | * (c) 2004 Ondrej Filip <feela@network.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #define IPV6 10 | 11 | #define CONFIG_AUTO_ROUTES 12 | #define CONFIG_SELF_CONSCIOUS 13 | #define CONFIG_MULTIPLE_TABLES 14 | #define CONFIG_SINGLE_ROUTE 15 | 16 | #define CONFIG_SKIP_MC_BIND 17 | #define CONFIG_NO_IFACE_BIND 18 | 19 | /* 20 | Link: sysdep/unix 21 | Link: sysdep/bsd 22 | */ 23 | -------------------------------------------------------------------------------- /sysdep/cf/bsd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Configuration for *BSD based systems (tested on FreeBSD and NetBSD) 3 | * 4 | * (c) 2004 Ondrej Filip <feela@network.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #define CONFIG_AUTO_ROUTES 10 | #define CONFIG_SELF_CONSCIOUS 11 | #define CONFIG_MULTIPLE_TABLES 12 | #define CONFIG_SINGLE_ROUTE 13 | 14 | #define CONFIG_SKIP_MC_BIND 15 | #define CONFIG_NO_IFACE_BIND 16 | #define CONFIG_USE_HDRINCL 17 | 18 | /* 19 | Link: sysdep/unix 20 | Link: sysdep/bsd 21 | */ 22 | -------------------------------------------------------------------------------- /sysdep/cf/linux-v6.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Configuration for Linux based systems running IPv6 3 | * 4 | * (c) 1998--1999 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #define IPV6 10 | 11 | #define CONFIG_AUTO_ROUTES 12 | #define CONFIG_SELF_CONSCIOUS 13 | #define CONFIG_MULTIPLE_TABLES 14 | #define CONFIG_ALL_TABLES_AT_ONCE 15 | 16 | #define CONFIG_RESTRICTED_PRIVILEGES 17 | 18 | /* 19 | Link: sysdep/linux 20 | Link: sysdep/unix 21 | */ 22 | -------------------------------------------------------------------------------- /sysdep/cf/linux.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Configuration for Linux based systems 3 | * 4 | * (c) 1998--1999 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #define CONFIG_AUTO_ROUTES 10 | #define CONFIG_SELF_CONSCIOUS 11 | #define CONFIG_MULTIPLE_TABLES 12 | #define CONFIG_ALL_TABLES_AT_ONCE 13 | 14 | #define CONFIG_MC_PROPER_SRC 15 | #define CONFIG_UNIX_DONTROUTE 16 | 17 | #define CONFIG_RESTRICTED_PRIVILEGES 18 | 19 | /* 20 | Link: sysdep/linux 21 | Link: sysdep/unix 22 | */ 23 | -------------------------------------------------------------------------------- /sysdep/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains all parameters dependent on the 3 | * operating system and build-time configuration. 4 | */ 5 | 6 | #ifndef _BIRD_CONFIG_H_ 7 | #define _BIRD_CONFIG_H_ 8 | 9 | /* BIRD version */ 10 | #define BIRD_VERSION "1.5.0" 11 | 12 | /* Include parameters determined by configure script */ 13 | #include "sysdep/autoconf.h" 14 | 15 | /* Include OS configuration file as chosen in autoconf.h */ 16 | #include SYSCONF_INCLUDE 17 | 18 | #ifndef MACROS_ONLY 19 | 20 | /* 21 | * Of course we could add the paths to autoconf.h, but autoconf 22 | * is stupid and puts make-specific substitutious to the paths. 23 | */ 24 | #include "sysdep/paths.h" 25 | 26 | /* Types */ 27 | typedef signed INTEGER_8 s8; 28 | typedef unsigned INTEGER_8 u8; 29 | typedef INTEGER_16 s16; 30 | typedef unsigned INTEGER_16 u16; 31 | typedef INTEGER_32 s32; 32 | typedef unsigned INTEGER_32 u32; 33 | typedef INTEGER_64 s64; 34 | typedef unsigned INTEGER_64 u64; 35 | typedef u8 byte; 36 | typedef u16 word; 37 | typedef unsigned int uint; 38 | 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /sysdep/linux/Modules: -------------------------------------------------------------------------------- 1 | krt-sys.h 2 | netlink.c 3 | netlink.Y 4 | sysio.h 5 | syspriv.h 6 | -------------------------------------------------------------------------------- /sysdep/linux/krt-sys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Linux Kernel Netlink Route Syncer 3 | * 4 | * (c) 1998--2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_KRT_SYS_H_ 10 | #define _BIRD_KRT_SYS_H_ 11 | 12 | 13 | /* Kernel interfaces */ 14 | 15 | struct kif_params { 16 | }; 17 | 18 | struct kif_state { 19 | }; 20 | 21 | 22 | static inline void kif_sys_init(struct kif_proto *p UNUSED) { } 23 | static inline int kif_sys_reconfigure(struct kif_proto *p UNUSED, struct kif_config *n UNUSED, struct kif_config *o UNUSED) { return 1; } 24 | 25 | static inline void kif_sys_preconfig(struct config *c UNUSED) { } 26 | static inline void kif_sys_postconfig(struct kif_config *c UNUSED) { } 27 | static inline void kif_sys_init_config(struct kif_config *c UNUSED) { } 28 | static inline void kif_sys_copy_config(struct kif_config *d UNUSED, struct kif_config *s UNUSED) { } 29 | 30 | static inline struct ifa * kif_get_primary_ip(struct iface *i) { return NULL; } 31 | 32 | 33 | /* Kernel routes */ 34 | 35 | #define EA_KRT_PREFSRC EA_CODE(EAP_KRT, 0x10) 36 | #define EA_KRT_REALM EA_CODE(EAP_KRT, 0x11) 37 | 38 | 39 | #define KRT_METRICS_MAX 0x10 /* RTAX_QUICKACK+1 */ 40 | #define KRT_METRICS_OFFSET 0x20 /* Offset of EA_KRT_* vs RTAX_* */ 41 | 42 | #define KRT_FEATURES_MAX 4 43 | 44 | /* 45 | * Following attributes are parts of RTA_METRICS kernel route attribute, their 46 | * ids must be consistent with their RTAX_* constants (+ KRT_METRICS_OFFSET) 47 | */ 48 | #define EA_KRT_METRICS EA_CODE(EAP_KRT, 0x20) /* Dummy one */ 49 | #define EA_KRT_LOCK EA_CODE(EAP_KRT, 0x21) 50 | #define EA_KRT_MTU EA_CODE(EAP_KRT, 0x22) 51 | #define EA_KRT_WINDOW EA_CODE(EAP_KRT, 0x23) 52 | #define EA_KRT_RTT EA_CODE(EAP_KRT, 0x24) 53 | #define EA_KRT_RTTVAR EA_CODE(EAP_KRT, 0x25) 54 | #define EA_KRT_SSTRESH EA_CODE(EAP_KRT, 0x26) 55 | #define EA_KRT_CWND EA_CODE(EAP_KRT, 0x27) 56 | #define EA_KRT_ADVMSS EA_CODE(EAP_KRT, 0x28) 57 | #define EA_KRT_REORDERING EA_CODE(EAP_KRT, 0x29) 58 | #define EA_KRT_HOPLIMIT EA_CODE(EAP_KRT, 0x2a) 59 | #define EA_KRT_INITCWND EA_CODE(EAP_KRT, 0x2b) 60 | #define EA_KRT_FEATURES EA_CODE(EAP_KRT, 0x2c) 61 | #define EA_KRT_RTO_MIN EA_CODE(EAP_KRT, 0x2d) 62 | #define EA_KRT_INITRWND EA_CODE(EAP_KRT, 0x2e) 63 | #define EA_KRT_QUICKACK EA_CODE(EAP_KRT, 0x2f) 64 | 65 | /* Bits of EA_KRT_LOCK, also based on RTAX_* constants */ 66 | #define EA_KRT_LOCK_MTU EA_KRT_LOCK | EA_BIT(0x2) 67 | #define EA_KRT_LOCK_WINDOW EA_KRT_LOCK | EA_BIT(0x3) 68 | #define EA_KRT_LOCK_RTT EA_KRT_LOCK | EA_BIT(0x4) 69 | #define EA_KRT_LOCK_RTTVAR EA_KRT_LOCK | EA_BIT(0x5) 70 | #define EA_KRT_LOCK_SSTHRESH EA_KRT_LOCK | EA_BIT(0x6) 71 | #define EA_KRT_LOCK_CWND EA_KRT_LOCK | EA_BIT(0x7) 72 | #define EA_KRT_LOCK_ADVMSS EA_KRT_LOCK | EA_BIT(0x8) 73 | #define EA_KRT_LOCK_REORDERING EA_KRT_LOCK | EA_BIT(0x9) 74 | #define EA_KRT_LOCK_HOPLIMIT EA_KRT_LOCK | EA_BIT(0xa) 75 | // define EA_KRT_LOCK_INITCWND EA_KRT_LOCK | EA_BIT(0xb) 76 | // define EA_KRT_LOCK_FEATURES EA_KRT_LOCK | EA_BIT(0xc) 77 | #define EA_KRT_LOCK_RTO_MIN EA_KRT_LOCK | EA_BIT(0xd) 78 | // define EA_KRT_LOCK_INITRWND EA_KRT_LOCK | EA_BIT(0xe) 79 | 80 | /* Bits of EA_KRT_FEATURES, based on RTAX_FEATURE_* constants */ 81 | #define EA_KRT_FEATURE_ECN EA_KRT_FEATURES | EA_BIT(0x0) 82 | // define EA_KRT_FEATURE_SACK EA_KRT_FEATURES | EA_BIT(0x1) 83 | // define EA_KRT_FEATURE_TSTAMP EA_KRT_FEATURES | EA_BIT(0x2) 84 | #define EA_KRT_FEATURE_ALLFRAG EA_KRT_FEATURES | EA_BIT(0x3) 85 | 86 | 87 | 88 | #define NL_NUM_TABLES 256 89 | 90 | struct krt_params { 91 | int table_id; /* Kernel table ID we sync with */ 92 | }; 93 | 94 | struct krt_state { 95 | }; 96 | 97 | 98 | static inline void krt_sys_init(struct krt_proto *p UNUSED) { } 99 | 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /sysdep/linux/netlink.Y: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Linux Netlink Configuration 3 | * 4 | * (c) 1999--2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | CF_HDR 10 | 11 | CF_DECLS 12 | 13 | CF_KEYWORDS(KERNEL, TABLE, KRT_PREFSRC, KRT_REALM, KRT_MTU, KRT_WINDOW, KRT_RTT, 14 | KRT_RTTVAR, KRT_SSTRESH, KRT_CWND, KRT_ADVMSS, KRT_REORDERING, 15 | KRT_HOPLIMIT, KRT_INITCWND, KRT_RTO_MIN, KRT_INITRWND, KRT_QUICKACK, 16 | KRT_LOCK_MTU, KRT_LOCK_WINDOW, KRT_LOCK_RTT, KRT_LOCK_RTTVAR, 17 | KRT_LOCK_SSTRESH, KRT_LOCK_CWND, KRT_LOCK_ADVMSS, KRT_LOCK_REORDERING, 18 | KRT_LOCK_HOPLIMIT, KRT_LOCK_RTO_MIN, KRT_FEATURE_ECN, KRT_FEATURE_ALLFRAG) 19 | 20 | CF_GRAMMAR 21 | 22 | CF_ADDTO(kern_proto, kern_proto kern_sys_item ';') 23 | 24 | kern_sys_item: 25 | KERNEL TABLE expr { 26 | if ($3 <= 0 || $3 >= NL_NUM_TABLES) 27 | cf_error("Kernel routing table number out of range"); 28 | THIS_KRT->sys.table_id = $3; 29 | } 30 | ; 31 | 32 | CF_ADDTO(dynamic_attr, KRT_PREFSRC { $$ = f_new_dynamic_attr(EAF_TYPE_IP_ADDRESS, T_IP, EA_KRT_PREFSRC); }) 33 | CF_ADDTO(dynamic_attr, KRT_REALM { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_REALM); }) 34 | 35 | CF_ADDTO(dynamic_attr, KRT_MTU { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_MTU); }) 36 | CF_ADDTO(dynamic_attr, KRT_WINDOW { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_WINDOW); }) 37 | CF_ADDTO(dynamic_attr, KRT_RTT { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_RTT); }) 38 | CF_ADDTO(dynamic_attr, KRT_RTTVAR { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_RTTVAR); }) 39 | CF_ADDTO(dynamic_attr, KRT_SSTRESH { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_SSTRESH); }) 40 | CF_ADDTO(dynamic_attr, KRT_CWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_CWND); }) 41 | CF_ADDTO(dynamic_attr, KRT_ADVMSS { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_ADVMSS); }) 42 | CF_ADDTO(dynamic_attr, KRT_REORDERING { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_REORDERING); }) 43 | CF_ADDTO(dynamic_attr, KRT_HOPLIMIT { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_HOPLIMIT); }) 44 | CF_ADDTO(dynamic_attr, KRT_INITCWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_INITCWND); }) 45 | CF_ADDTO(dynamic_attr, KRT_RTO_MIN { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_RTO_MIN); }) 46 | CF_ADDTO(dynamic_attr, KRT_INITRWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_INITRWND); }) 47 | CF_ADDTO(dynamic_attr, KRT_QUICKACK { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_QUICKACK); }) 48 | 49 | CF_ADDTO(dynamic_attr, KRT_LOCK_MTU { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_MTU); }) 50 | CF_ADDTO(dynamic_attr, KRT_LOCK_WINDOW { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_WINDOW); }) 51 | CF_ADDTO(dynamic_attr, KRT_LOCK_RTT { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_RTT); }) 52 | CF_ADDTO(dynamic_attr, KRT_LOCK_RTTVAR { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_RTTVAR); }) 53 | CF_ADDTO(dynamic_attr, KRT_LOCK_SSTRESH { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_SSTHRESH); }) 54 | CF_ADDTO(dynamic_attr, KRT_LOCK_CWND { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_CWND); }) 55 | CF_ADDTO(dynamic_attr, KRT_LOCK_ADVMSS { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_ADVMSS); }) 56 | CF_ADDTO(dynamic_attr, KRT_LOCK_REORDERING { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_REORDERING); }) 57 | CF_ADDTO(dynamic_attr, KRT_LOCK_HOPLIMIT { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_HOPLIMIT); }) 58 | CF_ADDTO(dynamic_attr, KRT_LOCK_RTO_MIN { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_RTO_MIN); }) 59 | 60 | CF_ADDTO(dynamic_attr, KRT_FEATURE_ECN { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_FEATURE_ECN); }) 61 | CF_ADDTO(dynamic_attr, KRT_FEATURE_ALLFRAG { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_FEATURE_ALLFRAG); }) 62 | 63 | 64 | CF_CODE 65 | 66 | CF_END 67 | -------------------------------------------------------------------------------- /sysdep/linux/syspriv.h: -------------------------------------------------------------------------------- 1 | 2 | #include <sys/prctl.h> 3 | #include <linux/capability.h> 4 | 5 | #ifndef _LINUX_CAPABILITY_VERSION_3 6 | #define _LINUX_CAPABILITY_VERSION_3 0x20080522 7 | #define _LINUX_CAPABILITY_U32S_3 2 8 | #endif 9 | 10 | /* CAP_TO_MASK is missing in CentOS header files */ 11 | #ifndef CAP_TO_MASK 12 | #define CAP_TO_MASK(x) (1 << ((x) & 31)) 13 | #endif 14 | 15 | /* capset() prototype is missing ... */ 16 | int capset(cap_user_header_t hdrp, const cap_user_data_t datap); 17 | 18 | static inline int 19 | set_capabilities(u32 caps) 20 | { 21 | struct __user_cap_header_struct cap_hdr; 22 | struct __user_cap_data_struct cap_dat[_LINUX_CAPABILITY_U32S_3]; 23 | int err; 24 | 25 | cap_hdr.version = _LINUX_CAPABILITY_VERSION_3; 26 | cap_hdr.pid = 0; 27 | 28 | memset(cap_dat, 0, sizeof(cap_dat)); 29 | cap_dat[0].effective = cap_dat[0].permitted = caps; 30 | 31 | err = capset(&cap_hdr, cap_dat); 32 | if (!err) 33 | return 0; 34 | 35 | /* Kernel may support do not support our version of capability interface. 36 | The last call returned supported version so we just retry it. */ 37 | if (errno == EINVAL) 38 | { 39 | err = capset(&cap_hdr, cap_dat); 40 | if (!err) 41 | return 0; 42 | } 43 | 44 | return -1; 45 | } 46 | 47 | static void 48 | drop_uid(uid_t uid) 49 | { 50 | u32 caps = 51 | CAP_TO_MASK(CAP_NET_BIND_SERVICE) | 52 | CAP_TO_MASK(CAP_NET_BROADCAST) | 53 | CAP_TO_MASK(CAP_NET_ADMIN) | 54 | CAP_TO_MASK(CAP_NET_RAW); 55 | 56 | /* change effective user ID to be able to switch to that 57 | user ID completely after dropping CAP_SETUID */ 58 | if (seteuid(uid) < 0) 59 | die("seteuid: %m"); 60 | 61 | /* restrict the capabilities */ 62 | if (set_capabilities(caps) < 0) 63 | die("capset: %m"); 64 | 65 | /* keep the capabilities after dropping root ID */ 66 | if (prctl(PR_SET_KEEPCAPS, 1) < 0) 67 | die("prctl: %m"); 68 | 69 | /* completely switch to the unprivileged user ID */ 70 | if (setresuid(uid, uid, uid) < 0) 71 | die("setresuid: %m"); 72 | } 73 | -------------------------------------------------------------------------------- /sysdep/sysdep.sgml: -------------------------------------------------------------------------------- 1 | <!-- 2 | BIRD Programmer's Guide: Sysdeps 3 | 4 | (c) 2000 Martin Mares <mj@ucw.cz> 5 | --> 6 | 7 | <chapt>System dependent parts 8 | 9 | <sect>Introduction 10 | 11 | <p>We've tried to make BIRD as portable as possible, but unfortunately 12 | communication with the network stack differs from one OS to another, 13 | so we need at least some OS specific code. The good news is that this 14 | code is isolated in a small set of modules: 15 | 16 | <descrip> 17 | <tagp><tt/config.h/</tagp> is a header file with configuration information, 18 | definition of the standard set of types and so on. 19 | <tagp/Startup module/ controls BIRD startup. Common for a family of OS's (e.g., 20 | for all Unices). 21 | <tagp/Logging module/ manages the system logs. [per OS family] 22 | <tagp/IO module/ gives an implementation of sockets, timers and the 23 | global event queue. [per OS family] 24 | <tagp/KRT module/ implements the Kernel and Device protocols. This 25 | is the most arcane part of the system dependent stuff and some 26 | functions differ even between various releases of a single OS. 27 | </descrip> 28 | -------------------------------------------------------------------------------- /sysdep/unix/Doc: -------------------------------------------------------------------------------- 1 | S log.c 2 | S krt.c 3 | # io.c is documented under Resources 4 | -------------------------------------------------------------------------------- /sysdep/unix/Modules: -------------------------------------------------------------------------------- 1 | log.c 2 | main.c 3 | timer.h 4 | io.c 5 | unix.h 6 | endian.h 7 | config.Y 8 | random.c 9 | 10 | krt.c 11 | krt.h 12 | krt.Y 13 | -------------------------------------------------------------------------------- /sysdep/unix/endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Endianity Conversion 3 | * 4 | * (c) 1999 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_ENDIAN_H_ 10 | #define _BIRD_ENDIAN_H_ 11 | 12 | /* hton[sl] and ntoh[sl] are defined here */ 13 | 14 | #include <sys/types.h> 15 | #include <netinet/in.h> 16 | #ifdef HAVE_STDINT_H 17 | #include <stdint.h> 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /sysdep/unix/krt.Y: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- UNIX Kernel Syncer Configuration 3 | * 4 | * (c) 1998--2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | CF_HDR 10 | 11 | #include "lib/krt.h" 12 | 13 | CF_DEFINES 14 | 15 | #define THIS_KRT ((struct krt_config *) this_proto) 16 | #define THIS_KIF ((struct kif_config *) this_proto) 17 | 18 | CF_DECLS 19 | 20 | CF_KEYWORDS(KERNEL, PERSIST, SCAN, TIME, LEARN, DEVICE, ROUTES, GRACEFUL, RESTART, KRT_SOURCE, KRT_METRIC, MERGE, PATHS) 21 | 22 | CF_GRAMMAR 23 | 24 | /* Kernel syncer protocol */ 25 | 26 | CF_ADDTO(proto, kern_proto '}') 27 | 28 | kern_proto_start: proto_start KERNEL { this_proto = krt_init_config($1); } 29 | ; 30 | 31 | CF_ADDTO(kern_proto, kern_proto_start proto_name '{') 32 | CF_ADDTO(kern_proto, kern_proto proto_item ';') 33 | CF_ADDTO(kern_proto, kern_proto kern_item ';') 34 | 35 | kern_item: 36 | PERSIST bool { THIS_KRT->persist = $2; } 37 | | SCAN TIME expr { 38 | /* Scan time of 0 means scan on startup only */ 39 | THIS_KRT->scan_time = $3; 40 | } 41 | | LEARN bool { 42 | THIS_KRT->learn = $2; 43 | #ifndef KRT_ALLOW_LEARN 44 | if ($2) 45 | cf_error("Learning of kernel routes not supported in this configuration"); 46 | #endif 47 | } 48 | | DEVICE ROUTES bool { THIS_KRT->devroutes = $3; } 49 | | GRACEFUL RESTART bool { THIS_KRT->graceful_restart = $3; } 50 | | MERGE PATHS bool { THIS_KRT->merge_paths = $3 ? KRT_DEFAULT_ECMP_LIMIT : 0; } 51 | | MERGE PATHS bool LIMIT expr { THIS_KRT->merge_paths = $3 ? $5 : 0; if (($5 <= 0) || ($5 > 255)) cf_error("Merge paths limit must be in range 1-255"); } 52 | ; 53 | 54 | /* Kernel interface protocol */ 55 | 56 | CF_ADDTO(proto, kif_proto '}') 57 | 58 | kif_proto_start: proto_start DEVICE { this_proto = kif_init_config($1); } 59 | ; 60 | 61 | CF_ADDTO(kif_proto, kif_proto_start proto_name '{') 62 | CF_ADDTO(kif_proto, kif_proto proto_item ';') 63 | CF_ADDTO(kif_proto, kif_proto kif_item ';') 64 | 65 | kif_item: 66 | SCAN TIME expr { 67 | /* Scan time of 0 means scan on startup only */ 68 | THIS_KIF->scan_time = $3; 69 | } 70 | | PRIMARY text_or_none prefix_or_ipa { 71 | struct kif_primary_item *kpi = cfg_alloc(sizeof (struct kif_primary_item)); 72 | kpi->pattern = $2; 73 | kpi->prefix = $3.addr; 74 | kpi->pxlen = $3.len; 75 | add_tail(&THIS_KIF->primary, &kpi->n); 76 | } 77 | ; 78 | 79 | CF_ADDTO(dynamic_attr, KRT_SOURCE { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_KRT_SOURCE); }) 80 | CF_ADDTO(dynamic_attr, KRT_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_KRT_METRIC); }) 81 | 82 | CF_CODE 83 | 84 | CF_END 85 | -------------------------------------------------------------------------------- /sysdep/unix/random.c: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD Internet Routing Daemon -- Random Numbers 3 | * 4 | * (c) 2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #include <stdlib.h> 10 | 11 | #include "nest/bird.h" 12 | 13 | u32 14 | random_u32(void) 15 | { 16 | long int rand_low, rand_high; 17 | 18 | rand_low = random(); 19 | rand_high = random(); 20 | return (rand_low & 0xffff) | ((rand_high & 0xffff) << 16); 21 | } 22 | -------------------------------------------------------------------------------- /sysdep/unix/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Unix Timers 3 | * 4 | * (c) 1998 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_TIMER_H_ 10 | #define _BIRD_TIMER_H_ 11 | 12 | #include <time.h> 13 | 14 | #include "lib/resource.h" 15 | 16 | typedef time_t bird_clock_t; /* Use instead of time_t */ 17 | 18 | typedef struct timer { 19 | resource r; 20 | void (*hook)(struct timer *); 21 | void *data; 22 | unsigned randomize; /* Amount of randomization */ 23 | unsigned recurrent; /* Timer recurrence */ 24 | node n; /* Internal link */ 25 | bird_clock_t expires; /* 0=inactive */ 26 | } timer; 27 | 28 | timer *tm_new(pool *); 29 | void tm_start(timer *, unsigned after); 30 | void tm_stop(timer *); 31 | void tm_dump_all(void); 32 | 33 | extern bird_clock_t now; /* Relative, monotonic time in seconds */ 34 | extern bird_clock_t now_real; /* Time in seconds since fixed known epoch */ 35 | extern bird_clock_t boot_time; 36 | 37 | static inline int 38 | tm_active(timer *t) 39 | { 40 | return t->expires != 0; 41 | } 42 | 43 | static inline bird_clock_t 44 | tm_remains(timer *t) 45 | { 46 | return t->expires ? t->expires - now : 0; 47 | } 48 | 49 | static inline void 50 | tm_start_max(timer *t, unsigned after) 51 | { 52 | bird_clock_t rem = tm_remains(t); 53 | tm_start(t, (rem > after) ? rem : after); 54 | } 55 | 56 | static inline timer * 57 | tm_new_set(pool *p, void (*hook)(struct timer *), void *data, unsigned rand, unsigned rec) 58 | { 59 | timer *t = tm_new(p); 60 | t->hook = hook; 61 | t->data = data; 62 | t->randomize = rand; 63 | t->recurrent = rec; 64 | return t; 65 | } 66 | 67 | 68 | struct timeformat { 69 | char *fmt1, *fmt2; 70 | bird_clock_t limit; 71 | }; 72 | 73 | bird_clock_t tm_parse_date(char *); /* Convert date to bird_clock_t */ 74 | bird_clock_t tm_parse_datetime(char *); /* Convert date to bird_clock_t */ 75 | 76 | #define TM_DATETIME_BUFFER_SIZE 32 /* Buffer size required by tm_format_datetime */ 77 | void 78 | tm_format_datetime(char *x, struct timeformat *fmt_spec, bird_clock_t t); 79 | 80 | #ifdef TIME_T_IS_64BIT 81 | #define TIME_INFINITY 0x7fffffffffffffff 82 | #else 83 | #ifdef TIME_T_IS_SIGNED 84 | #define TIME_INFINITY 0x7fffffff 85 | #else 86 | #define TIME_INFINITY 0xffffffff 87 | #endif 88 | #endif 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /sysdep/unix/unix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BIRD -- Declarations Common to Unix Port 3 | * 4 | * (c) 1998--2000 Martin Mares <mj@ucw.cz> 5 | * 6 | * Can be freely distributed and used under the terms of the GNU GPL. 7 | */ 8 | 9 | #ifndef _BIRD_UNIX_H_ 10 | #define _BIRD_UNIX_H_ 11 | 12 | #include <sys/socket.h> 13 | 14 | struct pool; 15 | struct iface; 16 | struct birdsock; 17 | 18 | /* main.c */ 19 | 20 | extern char *bird_name; 21 | void async_config(void); 22 | void async_dump(void); 23 | void async_shutdown(void); 24 | void cmd_check_config(char *name); 25 | void cmd_reconfig(char *name, int type, int timeout); 26 | void cmd_reconfig_confirm(void); 27 | void cmd_reconfig_undo(void); 28 | void cmd_shutdown(void); 29 | 30 | #define UNIX_DEFAULT_CONFIGURE_TIMEOUT 300 31 | 32 | #define UNIX_DEFAULT_LATENCY_LIMIT (1 S_) 33 | #define UNIX_DEFAULT_WATCHDOG_WARNING (5 S_) 34 | 35 | /* io.c */ 36 | 37 | #define ERR(c) do { s->err = c; return -1; } while (0) 38 | #define ERR2(c) do { s->err = c; goto err; } while (0) 39 | #define ERR_MSG(c) do { errno = 0; s->err = c; return -1; } while (0) 40 | 41 | 42 | #define SOCKADDR_SIZE 32 43 | 44 | typedef struct sockaddr_bird { 45 | struct sockaddr sa; 46 | char padding[SOCKADDR_SIZE - sizeof(struct sockaddr)]; 47 | } sockaddr; 48 | 49 | 50 | #ifdef IPV6 51 | #define BIRD_AF AF_INET6 52 | #define ipa_from_sa(x) ipa_from_sa6(x) 53 | #else 54 | #define BIRD_AF AF_INET 55 | #define ipa_from_sa(x) ipa_from_sa4(x) 56 | #endif 57 | 58 | 59 | /* This is sloppy hack, it should be detected by configure script */ 60 | /* Linux systems have it defined so this is definition for BSD systems */ 61 | #ifndef s6_addr32 62 | #define s6_addr32 __u6_addr.__u6_addr32 63 | #endif 64 | 65 | 66 | static inline ip_addr ipa_from_in4(struct in_addr a) 67 | { return ipa_from_u32(ntohl(a.s_addr)); } 68 | 69 | static inline ip_addr ipa_from_in6(struct in6_addr a) 70 | { return ipa_build6(ntohl(a.s6_addr32[0]), ntohl(a.s6_addr32[1]), ntohl(a.s6_addr32[2]), ntohl(a.s6_addr32[3])); } 71 | 72 | static inline ip_addr ipa_from_sa4(sockaddr *sa) 73 | { return ipa_from_in4(((struct sockaddr_in *) sa)->sin_addr); } 74 | 75 | static inline ip_addr ipa_from_sa6(sockaddr *sa) 76 | { return ipa_from_in6(((struct sockaddr_in6 *) sa)->sin6_addr); } 77 | 78 | static inline struct in_addr ipa_to_in4(ip_addr a) 79 | { return (struct in_addr) { htonl(ipa_to_u32(a)) }; } 80 | 81 | #ifdef IPV6 82 | static inline struct in6_addr ipa_to_in6(ip_addr a) 83 | { return (struct in6_addr) { .s6_addr32 = { htonl(_I0(a)), htonl(_I1(a)), htonl(_I2(a)), htonl(_I3(a)) } }; } 84 | #else 85 | /* Temporary dummy */ 86 | static inline struct in6_addr ipa_to_in6(ip_addr a) 87 | { return (struct in6_addr) { .s6_addr32 = { 0, 0, 0, 0 } }; } 88 | #endif 89 | 90 | void sockaddr_fill(sockaddr *sa, int af, ip_addr a, struct iface *ifa, uint port); 91 | int sockaddr_read(sockaddr *sa, int af, ip_addr *a, struct iface **ifa, uint *port); 92 | 93 | 94 | #ifndef SUN_LEN 95 | #define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) + strlen ((ptr)->sun_path)) 96 | #endif 97 | 98 | volatile int async_config_flag; 99 | volatile int async_dump_flag; 100 | volatile int async_shutdown_flag; 101 | 102 | void io_init(void); 103 | void io_loop(void); 104 | void io_log_dump(void); 105 | int sk_open_unix(struct birdsock *s, char *name); 106 | void *tracked_fopen(struct pool *, char *name, char *mode); 107 | void test_old_bird(char *path); 108 | 109 | 110 | /* krt.c bits */ 111 | 112 | void krt_io_init(void); 113 | 114 | /* log.c */ 115 | 116 | void main_thread_init(void); 117 | void log_init_debug(char *); /* Initialize debug dump to given file (NULL=stderr, ""=off) */ 118 | void log_switch(int debug, list *l, char *); /* Use l=NULL for initial switch */ 119 | 120 | struct log_config { 121 | node n; 122 | uint mask; /* Classes to log */ 123 | void *fh; /* FILE to log to, NULL=syslog */ 124 | int terminal_flag; 125 | }; 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /tools/Makefile-top.in: -------------------------------------------------------------------------------- 1 | # Makefile for in place build of BIRD 2 | # (c) 1999--2000 Martin Mares <mj@ucw.cz> 3 | 4 | objdir=@objdir@ 5 | 6 | all depend tags install install-docs: 7 | $(MAKE) -C $(objdir) $@ 8 | 9 | docs userdocs progdocs: 10 | $(MAKE) -C doc $@ 11 | 12 | clean: 13 | $(MAKE) -C $(objdir) clean 14 | find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core -or -name depend -or -name ".#*" | xargs rm -f 15 | 16 | distclean: clean 17 | $(MAKE) -C doc distclean 18 | rm -rf $(objdir) autom4te.cache 19 | rm -f config.* configure sysdep/autoconf.h sysdep/paths.h Makefile 20 | 21 | -------------------------------------------------------------------------------- /tools/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile for the BIRD Internet Routing Daemon 2 | # (c) 1999--2000 Martin Mares <mj@ucw.cz> 3 | 4 | include Rules 5 | 6 | .PHONY: all daemon birdc birdcl subdir depend clean distclean tags docs userdocs progdocs 7 | 8 | all: sysdep/paths.h .dep-stamp subdir daemon birdcl @CLIENT@ 9 | 10 | daemon: $(exedir)/bird 11 | 12 | birdc: $(exedir)/birdc 13 | 14 | birdcl: $(exedir)/birdcl 15 | 16 | bird-dep := $(addsuffix /all.o, $(static-dirs)) conf/all.o lib/birdlib.a 17 | 18 | $(bird-dep): sysdep/paths.h .dep-stamp subdir 19 | 20 | birdc-dep := client/birdc.o client/all.o lib/birdlib.a 21 | 22 | $(birdc-dep): sysdep/paths.h .dep-stamp subdir 23 | 24 | birdcl-dep := client/birdcl.o client/all.o lib/birdlib.a 25 | 26 | $(birdcl-dep): sysdep/paths.h .dep-stamp subdir 27 | 28 | 29 | export client := @CLIENT@ 30 | 31 | depend: sysdep/paths.h .dir-stamp 32 | set -e ; for a in $(dynamic-dirs) ; do $(MAKE) -C $$a $@ ; done 33 | set -e ; for a in $(static-dirs) $(client-dirs) ; do $(MAKE) -C $$a -f $(srcdir_abs)/$$a/Makefile $@ ; done 34 | 35 | subdir: sysdep/paths.h .dir-stamp .dep-stamp 36 | set -e ; for a in $(dynamic-dirs) ; do $(MAKE) -C $$a $@ ; done 37 | set -e ; for a in $(static-dirs) $(client-dirs) ; do $(MAKE) -C $$a -f $(srcdir_abs)/$$a/Makefile $@ ; done 38 | 39 | $(exedir)/bird: $(bird-dep) 40 | @echo LD $(LDFLAGS) -o $@ $^ $(LIBS) 41 | @$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) 42 | 43 | $(exedir)/birdc: $(birdc-dep) 44 | @echo LD $(LDFLAGS) -o $@ $^ $(LIBS) $(CLIENT_LIBS) 45 | @$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) $(CLIENT_LIBS) 46 | 47 | $(exedir)/birdcl: $(birdcl-dep) 48 | @echo LD $(LDFLAGS) -o $@ $^ $(LIBS) 49 | @$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) 50 | 51 | .dir-stamp: sysdep/paths.h 52 | mkdir -p $(static-dirs) $(client-dirs) $(doc-dirs) 53 | touch .dir-stamp 54 | 55 | .dep-stamp: 56 | $(MAKE) depend 57 | touch .dep-stamp 58 | 59 | docs: userdocs progdocs 60 | 61 | userdocs progdocs: .dir-stamp 62 | $(MAKE) -C doc -f $(srcdir_abs)/doc/Makefile $@ 63 | 64 | sysdep/paths.h: 65 | echo >sysdep/paths.h "/* Generated by Makefile, don't edit manually! */" 66 | echo >>sysdep/paths.h "#define PATH_CONFIG_FILE \"@CONFIG_FILE@\"" 67 | echo >>sysdep/paths.h "#define PATH_CONTROL_SOCKET \"@CONTROL_SOCKET@\"" 68 | if test -n "@iproutedir@" ; then echo >>sysdep/paths.h "#define PATH_IPROUTE_DIR \"@iproutedir@\"" ; fi 69 | 70 | tags: 71 | cd $(srcdir) ; etags -lc `find $(static-dirs) $(addprefix $(objdir)/,$(dynamic-dirs)) $(client-dirs) -name *.[chY]` 72 | 73 | install: all 74 | $(INSTALL) -d $(DESTDIR)/$(sbindir) $(DESTDIR)/$(sysconfdir) $(DESTDIR)/@runtimedir@ 75 | $(INSTALL_PROGRAM) $(exedir)/bird $(DESTDIR)/$(sbindir)/bird@SUFFIX@ 76 | $(INSTALL_PROGRAM) $(exedir)/birdcl $(DESTDIR)/$(sbindir)/birdcl@SUFFIX@ 77 | if test -n "@CLIENT@" ; then \ 78 | $(INSTALL_PROGRAM) $(exedir)/birdc $(DESTDIR)/$(sbindir)/birdc@SUFFIX@ ; \ 79 | fi 80 | if ! test -f $(DESTDIR)/@CONFIG_FILE@ ; then \ 81 | $(INSTALL_DATA) $(srcdir)/doc/bird.conf.example $(DESTDIR)/@CONFIG_FILE@ ; \ 82 | else \ 83 | echo "Not overwriting old bird@SUFFIX@.conf" ; \ 84 | fi 85 | 86 | install-docs: 87 | $(INSTALL) -d $(DESTDIR)/$(docdir) 88 | $(INSTALL_DATA) $(srcdir)/doc/{bird,prog}{,-*}.html $(DESTDIR)/$(docdir)/ 89 | 90 | clean: 91 | find . -name "*.[oa]" -o -name core -o -name depend -o -name "*.html" | xargs rm -f 92 | rm -f conf/cf-lex.c conf/cf-parse.* conf/commands.h conf/keywords.h 93 | rm -f $(exedir)/bird $(exedir)/birdcl $(exedir)/birdc $(exedir)/bird.ctl $(exedir)/bird6.ctl .dep-stamp 94 | 95 | distclean: clean 96 | rm -f config.* configure sysdep/autoconf.h sysdep/paths.h Makefile Rules 97 | rm -rf .dir-stamp $(clean-dirs) 98 | -------------------------------------------------------------------------------- /tools/Rules.in: -------------------------------------------------------------------------------- 1 | # Makefile fragments for the BIRD Internet Routing Daemon 2 | # (c) 1999--2000 Martin Mares <mj@ucw.cz> 3 | 4 | srcdir=@srcdir_rel_mf@ 5 | srcdir_abs := $(shell cd $(srcdir) ; pwd) 6 | objdir=@objdir@ 7 | exedir=@exedir@ 8 | 9 | protocols=@protocols@ 10 | static-dirs := nest filter $(addprefix proto/,$(protocols)) 11 | static-dir-paths := $(addprefix $(srcdir)/,$(static-dirs)) 12 | dynamic-dirs := lib conf 13 | dynamic-dir-paths := $(dynamic-dirs) 14 | client-dirs := client 15 | client-dir-paths := $(client-dirs) 16 | doc-dirs := doc 17 | doc-dir-paths := $(doc-dirs) 18 | 19 | all-dirs:=$(static-dirs) $(dynamic-dirs) $(client-dirs) $(doc-dirs) 20 | clean-dirs:=$(all-dirs) proto sysdep 21 | 22 | CPPFLAGS=-I$(root-rel) -I$(srcdir) @CPPFLAGS@ 23 | CFLAGS=$(CPPFLAGS) @CFLAGS@ 24 | LDFLAGS=@LDFLAGS@ 25 | LIBS=@LIBS@ 26 | CLIENT_LIBS=@CLIENT_LIBS@ 27 | CC=@CC@ 28 | M4=@M4@ 29 | BISON=@BISON@ 30 | FLEX=@FLEX@ 31 | RANLIB=@RANLIB@ 32 | INSTALL=@INSTALL@ 33 | INSTALL_PROGRAM=@INSTALL_PROGRAM@ 34 | INSTALL_DATA=@INSTALL_DATA@ 35 | 36 | prefix=@prefix@ 37 | exec_prefix=@exec_prefix@ 38 | bindir=@bindir@ 39 | sbindir=@sbindir@ 40 | sysconfdir=@sysconfdir@ 41 | localstatedir=@localstatedir@ 42 | docdir=@prefix@/doc 43 | 44 | ifdef source 45 | 46 | objs := $(subst .c,.o,$(source)) 47 | 48 | ifdef dir-name 49 | src-path := $(srcdir)/$(dir-name)/ 50 | endif 51 | 52 | all: 53 | cd $(root-rel) && make 54 | 55 | ifdef lib-dest 56 | 57 | subdir: $(lib-dest) 58 | 59 | $(lib-dest): $(objs) 60 | rm -f $@ 61 | ar rcs $@ $^ 62 | $(RANLIB) $@ 63 | 64 | else 65 | 66 | subdir: all.o 67 | 68 | all.o: $(objs) 69 | # $(LD) -r -o $@ $^ 70 | # Changed to $(CC) because $(LD) has problems with crosscompiling 71 | @echo LD -r -o $@ $^ 72 | @$(CC) -nostdlib -r -o $@ $^ 73 | 74 | endif 75 | 76 | %.o: $(src-path)%.c 77 | @echo CC -o $@ -c $< 78 | @$(CC) $(CFLAGS) -o $@ -c $< 79 | 80 | ifndef source-dep 81 | source-dep := $(source) 82 | endif 83 | 84 | depend: 85 | $(CC) $(CPPFLAGS) -MM $(addprefix $(src-path),$(source-dep)) >depend 86 | 87 | ifneq ($(wildcard depend),) 88 | include depend 89 | endif 90 | 91 | endif 92 | -------------------------------------------------------------------------------- /tools/cvslog: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # Process `cvs log' output to get a resonable changelog 3 | # (c) 2003--2004 Martin Mares <mj@ucw.cz> 4 | 5 | use Digest::MD5; 6 | use POSIX; 7 | 8 | my %names= ( 9 | 'mj' => 'Martin Mares <mj@ucw.cz>', 10 | 'feela' => 'Ondrej Filip <feela@network.cz>', 11 | 'pavel' => 'Pavel Machek <pavel@ucw.cz>' 12 | ); 13 | 14 | while (<STDIN>) { 15 | chomp; 16 | /^$/ && next; 17 | /^[?]/ && next; 18 | /^RCS file: / || die; 19 | $_ = <STDIN>; 20 | chomp; 21 | my ($file) = /^Working file: (.*)$/ or die; 22 | #print "$file\n"; 23 | do { 24 | $_ = <STDIN> or die; 25 | } while (!/^description:/); 26 | $_ = <STDIN>; 27 | for(;;) { 28 | /^======/ && last; 29 | if (/^------/) { $_ = <STDIN>; next; } 30 | /^revision / || die; 31 | $_ = <STDIN>; 32 | my ($author) = /;\s*author:\s*([^;]+)/ or die; 33 | my ($yy,$mm,$dd,$HH,$MM,$SS) = /^date: (....)\/(..)\/(..) (..):(..):(..);/ or die; 34 | my $t = POSIX::mktime($SS,$MM,$HH,$dd,$mm-1,$yy-1900) or die; 35 | my $T = sprintf("%06d", int(($t + 1800)/3600)); 36 | $d = ""; 37 | while ($_ = <STDIN>) { 38 | /^(-----|=====)/ && last; 39 | $d .= " $_"; 40 | } 41 | my $id = "$T:" . Digest::MD5::md5_hex($d); 42 | if (!defined $msg{$id}) { 43 | $date{$id} = "$yy-$mm-$dd $HH:$MM:$SS"; 44 | $msg{$id} = $d; 45 | $files{$id} = ""; 46 | $author{$id} = $author; 47 | } 48 | $files{$id} .= " * $file\n"; 49 | #print "\t$id\n"; 50 | } 51 | } 52 | 53 | foreach $id (sort keys %date) { 54 | if (!exists ($names{$author{$id}})) { 55 | die "Unknown commiter $author{$id}"; 56 | } 57 | print "### ", $date{$id}, " ", $names{$author{$id}}, "\n\n"; 58 | print $files{$id}, "\n"; 59 | print $msg{$id}, "\n"; 60 | } 61 | -------------------------------------------------------------------------------- /tools/gendist: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Generate BIRD Distribution Archive 4 | # (c) 2000--2004 Martin Mares <mj@ucw.cz> 5 | # 6 | 7 | set -e 8 | AC=`if [ -x /usr/bin/autoconf2.50 ] ; then echo autoconf2.50 ; else echo autoconf ; fi` 9 | $AC 10 | ./configure 11 | make distclean 12 | $AC 13 | rm -rf autom4te*cache 14 | ( cd doc ; make docs ; make clean ) 15 | VERSION=`sed <sysdep/config.h '/BIRD_VERSION/!d;s/^.*"\(.*\)"$/\1/'` 16 | REL=bird-$VERSION 17 | DREL=bird-doc-$VERSION 18 | T=/tmp/bird 19 | echo Building $REL 20 | rm -rf $T/$REL $T/$DREL 21 | mkdir -p $T/$REL $T/$DREL $T/$DREL/doc 22 | cp -a . $T/$REL 23 | echo Generating ChangeLog 24 | git log >$T/$REL/ChangeLog 25 | mv $T/$REL/doc/*.ps $T/$DREL/doc 26 | rm -f $T/$REL/bird.conf* 27 | rm -rf $T/$REL/.git/ 28 | rm -rf `find $T/$REL -name CVS -o -name tmp` $T/$REL/{misc,rfc,doc/slides} 29 | ( cd $T ; tar czvvf $REL.tar.gz $REL ) 30 | ( cd $T ; tar czvvf $DREL.tar.gz $DREL ) 31 | rm -rf $T/$REL $T/$DREL 32 | echo -n "OK? " 33 | read OK 34 | echo Uploading to Atrey... 35 | scp $T/$REL.tar.gz $T/$DREL.tar.gz atrey.karlin.mff.cuni.cz:~ftp/pub/bird/ 36 | echo Uploading to Trubka... 37 | scp $T/$REL.tar.gz $T/$DREL.tar.gz bird.network.cz:~ftp/pub/bird/ 38 | echo Done. 39 | -------------------------------------------------------------------------------- /tools/mergedirs: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z "$4" ] ; then 4 | echo "Usage: mergedirs <src-dir> <src-dir-rel> <obj-dir> <list-of-dirs>" 5 | exit 1 6 | fi 7 | cpp=${CPP:-cc -E} 8 | SRCDIR=$1 9 | shift 10 | SRCREL=$1 11 | case $SRCDIR in 12 | /*) ;; 13 | *) SRCREL="../$SRCREL" ;; 14 | esac 15 | shift 16 | OBJDIR=$1 17 | LIBDIR=$OBJDIR/lib 18 | CONFDIR=$OBJDIR/conf 19 | shift 20 | 21 | echo "Merging system-dependent modules ($@)" 22 | MODULES=`for a in $@ ; do 23 | cat $SRCDIR/sysdep/config.h $SRCDIR/$a/Modules | 24 | $cpp -U unix -D MACROS_ONLY -I $OBJDIR - | 25 | sed "/^[ ]*\$/d;/^#/d;s@\\(.*\\)@\\1 $a/\\1@" 26 | done | 27 | sort -k1,1 -u | 28 | cut -d ' ' -f 2` 29 | rm -rf $LIBDIR $CONFDIR 30 | mkdir -p $LIBDIR $CONFDIR 31 | for a in $MODULES ; do 32 | b=`basename $a` 33 | case $b in 34 | *.h) ln -s $SRCREL/$a $LIBDIR/$b 35 | ;; 36 | *.c) OBJ=`echo $b | sed 's/\.c$/\.o/'` 37 | OBJS="$OBJS $OBJ" 38 | SRCS="$SRCS \\ 39 | $b" 40 | ln -s $SRCREL/$a $LIBDIR/$b 41 | ;; 42 | *.Y) CONFS="$CONFS\$(srcdir)/$a " 43 | ln -s $SRCREL/$a $CONFDIR/$b 44 | ;; 45 | *) echo "$b: Unknown file type" 46 | exit 1 47 | ;; 48 | esac 49 | done 50 | 51 | cat >$LIBDIR/Makefile <<EOF 52 | source=$SRCS 53 | lib-dest=birdlib.a 54 | root-rel=../ 55 | 56 | include ../Rules 57 | EOF 58 | 59 | sed <$SRCDIR/conf/Makefile >$CONFDIR/Makefile "s|@CONFS@|$CONFS|" 60 | CONFS=`cd $SRCDIR ; ls conf/*.[chl]` 61 | for a in $CONFS ; do 62 | ln -s $SRCREL/$a $CONFDIR/ 63 | done 64 | -------------------------------------------------------------------------------- /tools/progdoc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | $srcdir = $ARGV[0]; 4 | 5 | open(OUT, ">prog.sgml") || die "Cannot create output file"; 6 | include("doc/prog-head.sgml"); 7 | process(""); 8 | include("doc/prog-foot.sgml"); 9 | close OUT; 10 | exit 0; 11 | 12 | sub include { 13 | my $f = shift @_; 14 | open(IN, "$srcdir/$f") || die "Unable to find $f"; 15 | while (<IN>) { 16 | print OUT; 17 | } 18 | close IN; 19 | } 20 | 21 | sub process { 22 | my $dir = shift @_; 23 | print "$dir/Doc\n"; 24 | open(IN, "$srcdir/$dir/Doc") || die "Unable to read $dir/Doc"; 25 | my @docfile = <IN>; 26 | close IN; 27 | foreach $_ (@docfile) { 28 | chomp; 29 | /^#/ && next; 30 | /^([A-Z]+)\s*(.*)/ || die "Parse error: $_"; 31 | $cmd = $1; 32 | $arg = $2; 33 | if ($cmd eq "C") { process("$dir/$arg"); } 34 | elsif ($cmd eq "H") { 35 | push @stack, "H"; 36 | print OUT "<chapt>$arg\n"; 37 | } elsif ($cmd eq "S") { 38 | print " $arg\n"; 39 | open(DOC, "cd $srcdir/$dir ; $srcdir/doc/kernel-doc -bird $arg |") || die "Unable to start kernel-doc"; 40 | while (<DOC>) { print OUT; } 41 | close DOC; 42 | } elsif ($cmd eq "D") { 43 | print " $arg\n"; 44 | include("$dir/$arg"); 45 | } else { die "Unknown command: $cmd"; } 46 | } 47 | } 48 | --------------------------------------------------------------------------------