1 /* 2 * Copyright (c) 1983, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)defs.h 8.1 (Berkeley) 6/5/93 30 * 31 * $FreeBSD: src/sbin/routed/defs.h,v 1.13 1999/09/05 17:49:11 peter Exp $ 32 */ 33 34 /* Definitions for RIPv2 routing process. 35 * 36 * This code is based on the 4.4BSD `routed` daemon, with extensions to 37 * support: 38 * RIPv2, including variable length subnet masks. 39 * Router Discovery 40 * aggregate routes in the kernel tables. 41 * aggregate advertised routes. 42 * maintain spare routes for faster selection of another gateway 43 * when the current gateway dies. 44 * timers on routes with second granularity so that selection 45 * of a new route does not wait 30-60 seconds. 46 * tolerance of static routes. 47 * tell the kernel hop counts 48 * do not advertise if ipforwarding=0 49 * 50 * The vestigial support for other protocols has been removed. There 51 * is no likelihood that IETF RIPv1 or RIPv2 will ever be used with 52 * other protocols. The result is far smaller, faster, cleaner, and 53 * perhaps understandable. 54 * 55 * The accumulation of special flags and kludges added over the many 56 * years have been simplified and integrated. 57 */ 58 59 #include <stdio.h> 60 #include <netdb.h> 61 #include <stdlib.h> 62 #include <unistd.h> 63 #include <errno.h> 64 #include <string.h> 65 #include <stdarg.h> 66 #include <syslog.h> 67 #include <time.h> 68 #include <sys/cdefs.h> 69 #include <sys/time.h> 70 #include <sys/types.h> 71 #include <sys/param.h> 72 #include <sys/ioctl.h> 73 #include <sys/sysctl.h> 74 #include <sys/socket.h> 75 #include "radix.h" 76 #define UNUSED __attribute__((unused)) 77 #define PATTRIB(f,l) __attribute__((format (printf,f,l))) 78 #include <net/if.h> 79 #include <net/route.h> 80 #include <net/if_dl.h> 81 #include <netinet/in.h> 82 #include <arpa/inet.h> 83 #define RIPVERSION RIPv2 84 #include <protocols/routed.h> 85 86 87 /* Type of an IP address. 88 * Some systems do not like to pass structures, so do not use in_addr. 89 * Some systems think a long has 64 bits, which would be a gross waste. 90 * So define it here so it can be changed for the target system. 91 * It should be defined somewhere netinet/in.h, but it is not. 92 */ 93 #if defined (__NetBSD__) 94 #define naddr u_int32_t 95 #define _HAVE_SA_LEN 96 #define _HAVE_SIN_LEN 97 #else 98 #define naddr u_long 99 #define _HAVE_SA_LEN 100 #define _HAVE_SIN_LEN 101 #endif 102 103 /* Turn on if IP_DROP_MEMBERSHIP and IP_ADD_MEMBERSHIP do not look at 104 * the dstaddr of point-to-point interfaces. 105 */ 106 #ifdef __NetBSD__ 107 #define MCAST_PPP_BUG 108 #endif 109 110 #define DAY (24*60*60) 111 #define NEVER DAY /* a long time */ 112 #define EPOCH NEVER /* bias time by this to avoid <0 */ 113 114 /* Scan the kernel regularly to see if any interfaces have appeared or been 115 * turned off. These must be less than STALE_TIME. 116 */ 117 #define CHECK_BAD_INTERVAL 5 /* when an interface is known bad */ 118 #define CHECK_ACT_INTERVAL 30 /* when advertising */ 119 #define CHECK_QUIET_INTERVAL 300 /* when not */ 120 121 #define LIM_SEC(s,l) ((s).tv_sec = MIN((s).tv_sec, (l))) 122 123 /* Metric used for fake default routes. It ought to be 15, but when 124 * processing advertised routes, previous versions of `routed` added 125 * to the received metric and discarded the route if the total was 16 126 * or larger. 127 */ 128 #define FAKE_METRIC (HOPCNT_INFINITY-2) 129 130 131 /* Router Discovery parameters */ 132 #define INADDR_ALLROUTERS_GROUP 0xe0000002 /* 224.0.0.2 */ 133 #define MaxMaxAdvertiseInterval 1800 134 #define MinMaxAdvertiseInterval 4 135 #define DefMaxAdvertiseInterval 600 136 #define DEF_PreferenceLevel 0 137 #define MIN_PreferenceLevel 0x80000000 138 139 #define MAX_INITIAL_ADVERT_INTERVAL 16 140 #define MAX_INITIAL_ADVERTS 3 141 #define MAX_RESPONSE_DELAY 2 142 143 #define MAX_SOLICITATION_DELAY 1 144 #define SOLICITATION_INTERVAL 3 145 #define MAX_SOLICITATIONS 3 146 147 148 /* Bloated packet size for systems that simply add authentication to 149 * full-sized packets 150 */ 151 #define OVER_MAXPACKETSIZE (MAXPACKETSIZE+sizeof(struct netinfo)*2) 152 /* typical packet buffers */ 153 union pkt_buf { 154 char packet[OVER_MAXPACKETSIZE*2]; 155 struct rip rip; 156 }; 157 158 #define GNAME_LEN 64 /* assumed=64 in parms.c */ 159 /* bigger than IFNAMSIZ, with room for "external()" or "remote()" */ 160 #define IF_NAME_LEN (GNAME_LEN+15) 161 162 /* No more routes than this, to protect ourself in case something goes 163 * whacko and starts broadcasting zillions of bogus routes. 164 */ 165 #define MAX_ROUTES (128*1024) 166 extern int total_routes; 167 168 /* Main, daemon routing table structure 169 */ 170 struct rt_entry { 171 struct radix_node rt_nodes[2]; /* radix tree glue */ 172 u_int rt_state; 173 # define RS_IF 0x001 /* for network interface */ 174 # define RS_NET_INT 0x002 /* authority route */ 175 # define RS_NET_SYN 0x004 /* fake net route for subnet */ 176 # define RS_NO_NET_SYN (RS_LOCAL | RS_LOCAL | RS_IF) 177 # define RS_SUBNET 0x008 /* subnet route from any source */ 178 # define RS_LOCAL 0x010 /* loopback for pt-to-pt */ 179 # define RS_MHOME 0x020 /* from -m */ 180 # define RS_STATIC 0x040 /* from the kernel */ 181 # define RS_RDISC 0x080 /* from router discovery */ 182 struct sockaddr_in rt_dst_sock; 183 naddr rt_mask; 184 struct rt_spare { 185 struct interface *rts_ifp; 186 naddr rts_gate; /* forward packets here */ 187 naddr rts_router; /* on the authority of this router */ 188 char rts_metric; 189 u_short rts_tag; 190 time_t rts_time; /* timer to junk stale routes */ 191 u_int rts_de_ag; /* de-aggregation level */ 192 #define NUM_SPARES 4 193 } rt_spares[NUM_SPARES]; 194 u_int rt_seqno; /* when last changed */ 195 char rt_poison_metric; /* to notice maximum recently */ 196 time_t rt_poison_time; /* advertised metric */ 197 }; 198 #define rt_dst rt_dst_sock.sin_addr.s_addr 199 #define rt_ifp rt_spares[0].rts_ifp 200 #define rt_gate rt_spares[0].rts_gate 201 #define rt_router rt_spares[0].rts_router 202 #define rt_metric rt_spares[0].rts_metric 203 #define rt_tag rt_spares[0].rts_tag 204 #define rt_time rt_spares[0].rts_time 205 #define rt_de_ag rt_spares[0].rts_de_ag 206 207 #define HOST_MASK 0xffffffff 208 #define RT_ISHOST(rt) ((rt)->rt_mask == HOST_MASK) 209 210 /* age all routes that 211 * are not from -g, -m, or static routes from the kernel 212 * not unbroken interface routes 213 * but not broken interfaces 214 * nor non-passive, remote interfaces that are not aliases 215 * (i.e. remote & metric=0) 216 */ 217 #define AGE_RT(rt_state,ifp) (0 == ((rt_state) & (RS_MHOME | RS_STATIC \ 218 | RS_NET_SYN | RS_RDISC)) \ 219 && (!((rt_state) & RS_IF) \ 220 || (ifp) == 0 \ 221 || (((ifp)->int_state & IS_REMOTE) \ 222 && !((ifp)->int_state & IS_PASSIVE)))) 223 224 /* true if A is better than B 225 * Better if 226 * - A is not a poisoned route 227 * - and A is not stale 228 * - and A has a shorter path 229 * - or is the router speaking for itself 230 * - or the current route is equal but stale 231 * - or it is a host route advertised by a system for itself 232 */ 233 #define BETTER_LINK(rt,A,B) ((A)->rts_metric < HOPCNT_INFINITY \ 234 && now_stale <= (A)->rts_time \ 235 && ((A)->rts_metric < (B)->rts_metric \ 236 || ((A)->rts_gate == (A)->rts_router \ 237 && (B)->rts_gate != (B)->rts_router) \ 238 || ((A)->rts_metric == (B)->rts_metric \ 239 && now_stale > (B)->rts_time) \ 240 || (RT_ISHOST(rt) \ 241 && (rt)->rt_dst == (A)->rts_router \ 242 && (A)->rts_metric == (B)->rts_metric))) 243 244 245 /* An "interface" is similar to a kernel ifnet structure, except it also 246 * handles "logical" or "IS_REMOTE" interfaces (remote gateways). 247 */ 248 struct interface { 249 struct interface *int_next, **int_prev; 250 struct interface *int_ahash, **int_ahash_prev; 251 struct interface *int_bhash, **int_bhash_prev; 252 struct interface *int_rlink, **int_rlink_prev; 253 struct interface *int_nhash, **int_nhash_prev; 254 char int_name[IF_NAME_LEN+1]; 255 u_short int_index; 256 naddr int_addr; /* address on this host (net order) */ 257 naddr int_brdaddr; /* broadcast address (n) */ 258 naddr int_dstaddr; /* other end of pt-to-pt link (n) */ 259 naddr int_net; /* working network # (host order)*/ 260 naddr int_mask; /* working net mask (host order) */ 261 naddr int_ripv1_mask; /* for inferring a mask (n) */ 262 naddr int_std_addr; /* class A/B/C address (n) */ 263 naddr int_std_net; /* class A/B/C network (h) */ 264 naddr int_std_mask; /* class A/B/C netmask (h) */ 265 int int_rip_sock; /* for queries */ 266 int int_if_flags; /* some bits copied from kernel */ 267 u_int int_state; 268 time_t int_act_time; /* last thought healthy */ 269 time_t int_query_time; 270 u_short int_transitions; /* times gone up-down */ 271 char int_metric; 272 char int_d_metric; /* for faked default route */ 273 struct int_data { 274 u_int ipackets; /* previous network stats */ 275 u_int ierrors; 276 u_int opackets; 277 u_int oerrors; 278 time_t ts; /* timestamp on network stats */ 279 } int_data; 280 # define MAX_AUTH_KEYS 5 281 struct auth { /* authentication info */ 282 u_int16_t type; 283 u_char key[RIP_AUTH_PW_LEN]; 284 u_char keyid; 285 time_t start, end; 286 } int_auth[MAX_AUTH_KEYS]; 287 /* router discovery parameters */ 288 int int_rdisc_pref; /* signed preference to advertise */ 289 int int_rdisc_int; /* MaxAdvertiseInterval */ 290 int int_rdisc_cnt; 291 struct timeval int_rdisc_timer; 292 }; 293 294 /* bits in int_state */ 295 #define IS_ALIAS 0x0000001 /* interface alias */ 296 #define IS_SUBNET 0x0000002 /* interface on subnetted network */ 297 #define IS_REMOTE 0x0000004 /* interface is not on this machine */ 298 #define IS_PASSIVE 0x0000008 /* remote and does not do RIP */ 299 #define IS_EXTERNAL 0x0000010 /* handled by EGP or something */ 300 #define IS_CHECKED 0x0000020 /* still exists */ 301 #define IS_ALL_HOSTS 0x0000040 /* in INADDR_ALLHOSTS_GROUP */ 302 #define IS_ALL_ROUTERS 0x0000080 /* in INADDR_ALLROUTERS_GROUP */ 303 #define IS_DISTRUST 0x0000100 /* ignore untrusted routers */ 304 #define IS_REDIRECT_OK 0x0000200 /* accept ICMP redirects */ 305 #define IS_BROKE 0x0000400 /* seems to be broken */ 306 #define IS_SICK 0x0000800 /* seems to be broken */ 307 #define IS_DUP 0x0001000 /* has a duplicate address */ 308 #define IS_NEED_NET_SYN 0x0002000 /* need RS_NET_SYN route */ 309 #define IS_NO_AG 0x0004000 /* do not aggregate subnets */ 310 #define IS_NO_SUPER_AG 0x0008000 /* do not aggregate networks */ 311 #define IS_NO_RIPV1_IN 0x0010000 /* no RIPv1 input at all */ 312 #define IS_NO_RIPV2_IN 0x0020000 /* no RIPv2 input at all */ 313 #define IS_NO_RIP_IN (IS_NO_RIPV1_IN | IS_NO_RIPV2_IN) 314 #define IS_RIP_IN_OFF(s) (((s) & IS_NO_RIP_IN) == IS_NO_RIP_IN) 315 #define IS_NO_RIPV1_OUT 0x0040000 /* no RIPv1 output at all */ 316 #define IS_NO_RIPV2_OUT 0x0080000 /* no RIPv2 output at all */ 317 #define IS_NO_RIP_OUT (IS_NO_RIPV1_OUT | IS_NO_RIPV2_OUT) 318 #define IS_NO_RIP (IS_NO_RIP_OUT | IS_NO_RIP_IN) 319 #define IS_RIP_OUT_OFF(s) (((s) & IS_NO_RIP_OUT) == IS_NO_RIP_OUT) 320 #define IS_RIP_OFF(s) (((s) & IS_NO_RIP) == IS_NO_RIP) 321 #define IS_NO_RIP_MCAST 0x0100000 /* broadcast RIPv2 */ 322 #define IS_NO_ADV_IN 0x0200000 /* do not listen to advertisements */ 323 #define IS_NO_SOL_OUT 0x0400000 /* send no solicitations */ 324 #define IS_SOL_OUT 0x0800000 /* send solicitations */ 325 #define GROUP_IS_SOL_OUT (IS_SOL_OUT | IS_NO_SOL_OUT) 326 #define IS_NO_ADV_OUT 0x1000000 /* do not advertise rdisc */ 327 #define IS_ADV_OUT 0x2000000 /* advertise rdisc */ 328 #define GROUP_IS_ADV_OUT (IS_NO_ADV_OUT | IS_ADV_OUT) 329 #define IS_BCAST_RDISC 0x4000000 /* broadcast instead of multicast */ 330 #define IS_NO_RDISC (IS_NO_ADV_IN | IS_NO_SOL_OUT | IS_NO_ADV_OUT) 331 #define IS_PM_RDISC 0x8000000 /* poor-man's router discovery */ 332 333 #define iff_up(f) ((f) & IFF_UP) 334 335 336 /* Information for aggregating routes */ 337 #define NUM_AG_SLOTS 32 338 struct ag_info { 339 struct ag_info *ag_fine; /* slot with finer netmask */ 340 struct ag_info *ag_cors; /* more coarse netmask */ 341 naddr ag_dst_h; /* destination in host byte order */ 342 naddr ag_mask; 343 naddr ag_gate; 344 naddr ag_nhop; 345 char ag_metric; /* metric to be advertised */ 346 char ag_pref; /* aggregate based on this */ 347 u_int ag_seqno; 348 u_short ag_tag; 349 u_short ag_state; 350 #define AGS_SUPPRESS 0x001 /* combine with coarser mask */ 351 #define AGS_AGGREGATE 0x002 /* synthesize combined routes */ 352 #define AGS_REDUN0 0x004 /* redundant, finer routes output */ 353 #define AGS_REDUN1 0x008 354 #define AG_IS_REDUN(state) (((state) & (AGS_REDUN0 | AGS_REDUN1)) \ 355 == (AGS_REDUN0 | AGS_REDUN1)) 356 #define AGS_GATEWAY 0x010 /* tell kernel RTF_GATEWAY */ 357 #define AGS_IF 0x020 /* for an interface */ 358 #define AGS_RIPV2 0x040 /* send only as RIPv2 */ 359 #define AGS_FINE_GATE 0x080 /* ignore differing ag_gate when this 360 * has the finer netmask */ 361 #define AGS_CORS_GATE 0x100 /* ignore differing gate when this 362 * has the coarser netmasks */ 363 #define AGS_SPLIT_HZ 0x200 /* suppress for split horizon */ 364 365 /* some bits are set if they are set on either route */ 366 #define AGS_AGGREGATE_EITHER (AGS_RIPV2 | AGS_GATEWAY | \ 367 AGS_SUPPRESS | AGS_CORS_GATE) 368 }; 369 370 371 /* parameters for interfaces */ 372 extern struct parm { 373 struct parm *parm_next; 374 char parm_name[IF_NAME_LEN+1]; 375 naddr parm_net; 376 naddr parm_mask; 377 378 char parm_d_metric; 379 u_int parm_int_state; 380 int parm_rdisc_pref; /* signed IRDP preference */ 381 int parm_rdisc_int; /* IRDP advertising interval */ 382 struct auth parm_auth[MAX_AUTH_KEYS]; 383 } *parms; 384 385 /* authority for internal networks */ 386 extern struct intnet { 387 struct intnet *intnet_next; 388 naddr intnet_addr; /* network byte order */ 389 naddr intnet_mask; 390 char intnet_metric; 391 } *intnets; 392 393 /* defined RIPv1 netmasks */ 394 extern struct r1net { 395 struct r1net *r1net_next; 396 naddr r1net_net; /* host order */ 397 naddr r1net_match; 398 naddr r1net_mask; 399 } *r1nets; 400 401 /* trusted routers */ 402 extern struct tgate { 403 struct tgate *tgate_next; 404 naddr tgate_addr; 405 #define MAX_TGATE_NETS 32 406 struct tgate_net { 407 naddr net; /* host order */ 408 naddr mask; 409 } tgate_nets[MAX_TGATE_NETS]; 410 } *tgates; 411 412 enum output_type {OUT_QUERY, OUT_UNICAST, OUT_BROADCAST, OUT_MULTICAST, 413 NO_OUT_MULTICAST, NO_OUT_RIPV2}; 414 415 /* common output buffers */ 416 extern struct ws_buf { 417 struct rip *buf; 418 struct netinfo *n; 419 struct netinfo *base; 420 struct netinfo *lim; 421 enum output_type type; 422 } v12buf, v2buf; 423 424 extern pid_t mypid; 425 extern naddr myaddr; /* main address of this system */ 426 427 extern int stopint; /* !=0 to stop */ 428 429 extern int sock_max; 430 extern int rip_sock; /* RIP socket */ 431 extern struct interface *rip_sock_mcast; /* current multicast interface */ 432 extern int rt_sock; /* routing socket */ 433 extern int rt_sock_seqno; 434 extern int rdisc_sock; /* router-discovery raw socket */ 435 436 extern int seqno; /* sequence number for messages */ 437 extern int supplier; /* process should supply updates */ 438 extern int supplier_set; /* -s or -q requested */ 439 extern int lookforinterfaces; /* 1=probe for new up interfaces */ 440 extern int ridhosts; /* 1=reduce host routes */ 441 extern int mhome; /* 1=want multi-homed host route */ 442 extern int advertise_mhome; /* 1=must continue advertising it */ 443 extern int auth_ok; /* 1=ignore auth if we do not care */ 444 445 extern struct timeval clk; /* system clock's idea of time */ 446 extern struct timeval epoch; /* system clock when started */ 447 extern struct timeval now; /* current idea of time */ 448 extern time_t now_stale; 449 extern time_t now_expire; 450 extern time_t now_garbage; 451 452 extern struct timeval next_bcast; /* next general broadcast */ 453 extern struct timeval age_timer; /* next check of old routes */ 454 extern struct timeval no_flash; /* inhibit flash update until then */ 455 extern struct timeval rdisc_timer; /* next advert. or solicitation */ 456 extern int rdisc_ok; /* using solicited route */ 457 458 extern struct timeval ifinit_timer; /* time to check interfaces */ 459 460 extern naddr loopaddr; /* our address on loopback */ 461 extern int tot_interfaces; /* # of remote and local interfaces */ 462 extern int rip_interfaces; /* # of interfaces doing RIP */ 463 extern struct interface *ifnet; /* all interfaces */ 464 extern struct interface *remote_if; /* remote interfaces */ 465 extern int have_ripv1_out; /* have a RIPv1 interface */ 466 extern int have_ripv1_in; 467 extern int need_flash; /* flash update needed */ 468 extern struct timeval need_kern; /* need to update kernel table */ 469 extern u_int update_seqno; /* a route has changed */ 470 471 extern int tracelevel, new_tracelevel; 472 #define MAX_TRACELEVEL 4 473 #define TRACEKERNEL (tracelevel >= 4) /* log kernel changes */ 474 #define TRACECONTENTS (tracelevel >= 3) /* display packet contents */ 475 #define TRACEPACKETS (tracelevel >= 2) /* note packets */ 476 #define TRACEACTIONS (tracelevel != 0) 477 extern FILE *ftrace; /* output trace file */ 478 extern char inittracename[MAXPATHLEN+1]; 479 480 extern struct radix_node_head *rhead; 481 482 483 extern void fix_sock(int, const char *); 484 extern void fix_select(void); 485 extern void rip_off(void); 486 extern void rip_on(struct interface *); 487 488 extern void bufinit(void); 489 extern int output(enum output_type, struct sockaddr_in *, 490 struct interface *, struct rip *, int); 491 extern void clr_ws_buf(struct ws_buf *, struct auth *); 492 extern void rip_query(void); 493 extern void rip_bcast(int); 494 extern void supply(struct sockaddr_in *, struct interface *, 495 enum output_type, int, int, int); 496 497 extern void msglog(const char *, ...) PATTRIB(1,2); 498 struct msg_limit { 499 time_t reuse; 500 struct msg_sub { 501 naddr addr; 502 time_t until; 503 # define MSG_SUBJECT_N 8 504 } subs[MSG_SUBJECT_N]; 505 }; 506 extern void msglim(struct msg_limit *, naddr, 507 const char *, ...) PATTRIB(3,4); 508 #define LOGERR(msg) msglog(msg ": %s", strerror(errno)) 509 extern void logbad(int, const char *, ...) PATTRIB(2,3); 510 #define BADERR(dump,msg) logbad(dump,msg ": %s", strerror(errno)) 511 #ifdef DEBUG 512 #define DBGERR(dump,msg) BADERR(dump,msg) 513 #else 514 #define DBGERR(dump,msg) LOGERR(msg) 515 #endif 516 extern char *naddr_ntoa(naddr); 517 extern const char *saddr_ntoa(struct sockaddr *); 518 519 extern void *rtmalloc(size_t, const char *); 520 extern void timevaladd(struct timeval *, struct timeval *); 521 extern void intvl_random(struct timeval *, u_long, u_long); 522 extern int getnet(char *, naddr *, naddr *); 523 extern int gethost(char *, naddr *); 524 extern void gwkludge(void); 525 extern const char *parse_parms(char *, int); 526 extern const char *check_parms(struct parm *); 527 extern void get_parms(struct interface *); 528 529 extern void lastlog(void); 530 extern void trace_close(int); 531 extern void set_tracefile(const char *, const char *, int); 532 extern void tracelevel_msg(const char *, int); 533 extern void trace_off(const char*, ...) PATTRIB(1,2); 534 extern void set_tracelevel(void); 535 extern void trace_flush(void); 536 extern void trace_misc(const char *, ...) PATTRIB(1,2); 537 extern void trace_act(const char *, ...) PATTRIB(1,2); 538 extern void trace_pkt(const char *, ...) PATTRIB(1,2); 539 extern void trace_add_del(const char *, struct rt_entry *); 540 extern void trace_change(struct rt_entry *, u_int, struct rt_spare *, 541 const char *); 542 extern void trace_if(const char *, struct interface *); 543 extern void trace_upslot(struct rt_entry *, struct rt_spare *, 544 struct rt_spare *); 545 extern void trace_rip(const char*, const char*, struct sockaddr_in *, 546 struct interface *, struct rip *, int); 547 extern char *addrname(naddr, naddr, int); 548 extern char *rtname(naddr, naddr, naddr); 549 550 extern void rdisc_age(naddr); 551 extern void set_rdisc_mg(struct interface *, int); 552 extern void set_supplier(void); 553 extern void if_bad_rdisc(struct interface *); 554 extern void if_ok_rdisc(struct interface *); 555 extern void read_rip(int, struct interface *); 556 extern void read_rt(void); 557 extern void read_d(void); 558 extern void rdisc_adv(void); 559 extern void rdisc_sol(void); 560 561 extern void sigalrm(int); 562 extern void sigterm(int); 563 564 extern void sigtrace_on(int); 565 extern void sigtrace_off(int); 566 567 extern void flush_kern(void); 568 extern void age(naddr); 569 570 extern void ag_flush(naddr, naddr, void (*)(struct ag_info *)); 571 extern void ag_check(naddr, naddr, naddr, naddr, char, char, u_int, 572 u_short, u_short, void (*)(struct ag_info *)); 573 extern void del_static(naddr, naddr, naddr, int); 574 extern void del_redirects(naddr, time_t); 575 extern struct rt_entry *rtget(naddr, naddr); 576 extern struct rt_entry *rtfind(naddr); 577 extern void rtinit(void); 578 extern void rtadd(naddr, naddr, u_int, struct rt_spare *); 579 extern void rtchange(struct rt_entry *, u_int, struct rt_spare *, char *); 580 extern void rtdelete(struct rt_entry *); 581 extern void rts_delete(struct rt_entry *, struct rt_spare *); 582 extern void rtbad_sub(struct rt_entry *); 583 extern void rtswitch(struct rt_entry *, struct rt_spare *); 584 extern void rtbad(struct rt_entry *); 585 586 #define S_ADDR(x) (((struct sockaddr_in *)(x))->sin_addr.s_addr) 587 #define INFO_DST(I) ((I)->rti_info[RTAX_DST]) 588 #define INFO_GATE(I) ((I)->rti_info[RTAX_GATEWAY]) 589 #define INFO_MASK(I) ((I)->rti_info[RTAX_NETMASK]) 590 #define INFO_IFA(I) ((I)->rti_info[RTAX_IFA]) 591 #define INFO_IFP(I) ((I)->rti_info[RTAX_IFP]) 592 #define INFO_AUTHOR(I) ((I)->rti_info[RTAX_AUTHOR]) 593 #define INFO_BRD(I) ((I)->rti_info[RTAX_BRD]) 594 void rt_xaddrs(struct rt_addrinfo *, struct sockaddr *, struct sockaddr *, 595 int); 596 597 extern naddr std_mask(naddr); 598 extern naddr ripv1_mask_net(naddr, struct interface *); 599 extern naddr ripv1_mask_host(naddr,struct interface *); 600 #define on_net(a,net,mask) (((ntohl(a) ^ (net)) & (mask)) == 0) 601 extern int check_dst(naddr); 602 extern struct interface *check_dup(naddr, naddr, naddr, int); 603 extern int check_remote(struct interface *); 604 extern int addrouteforif(struct interface *); 605 extern void ifinit(void); 606 extern int walk_bad(struct radix_node *, struct walkarg *); 607 extern int if_ok(struct interface *, const char *); 608 extern void if_sick(struct interface *); 609 extern void if_bad(struct interface *); 610 extern void if_link(struct interface *); 611 extern struct interface *ifwithaddr(naddr, int, int); 612 extern struct interface *ifwithname(char *, naddr); 613 extern struct interface *ifwithindex(u_short, int); 614 extern struct interface *iflookup(naddr); 615 616 extern struct auth *find_auth(struct interface *); 617 extern void end_md5_auth(struct ws_buf *, struct auth *); 618 619 #define MD5_DIGEST_LEN 16 620 typedef struct { 621 u_int32_t state[4]; /* state (ABCD) */ 622 u_int32_t count[2]; /* # of bits, modulo 2^64 (LSB 1st) */ 623 unsigned char buffer[64]; /* input buffer */ 624 } MD5_CTX; 625 extern void MD5Init(MD5_CTX*); 626 extern void MD5Update(MD5_CTX*, u_char*, u_int); 627 extern void MD5Final(u_char[MD5_DIGEST_LEN], MD5_CTX*); 628