#!/bin/sh # this is vxrouted_5.1.1-shar.06 (part 6 of a multipart archive) # do not concatenate these parts, unpack them in order with /bin/sh # file vxrouted_5.1.1/BSDrouted/defs.h continued # touch -am 1231235999 $$.touch >/dev/null 2>&1 if test ! -f 1231235999 && test -f $$.touch; then shar_touch=touch else shar_touch=: echo 'WARNING: not restoring timestamps' fi rm -f 1231235999 $$.touch # if test ! -r _sharseq.tmp; then echo 'Please unpack part 1 first!' exit 1 fi shar_sequence=`cat _sharseq.tmp` if test "$shar_sequence" != 6; then echo "Please unpack part $shar_sequence next!" exit 1 fi if test ! -f _sharnew.tmp; then echo 'x - still skipping vxrouted_5.1.1/BSDrouted/defs.h' else echo 'x - continuing file vxrouted_5.1.1/BSDrouted/defs.h' sed 's/^X//' << 'SHAR_EOF' >> 'vxrouted_5.1.1/BSDrouted/defs.h' && char *malloc(); char *ctime(); int exit(); int sendmsg(); int supply(); int timer(); int cleanup(); SHAR_EOF echo 'File vxrouted_5.1.1/BSDrouted/defs.h is complete' && $shar_touch -am 0218122889 'vxrouted_5.1.1/BSDrouted/defs.h' && chmod 0444 'vxrouted_5.1.1/BSDrouted/defs.h' || echo 'restore of vxrouted_5.1.1/BSDrouted/defs.h failed' shar_count="`wc -c < 'vxrouted_5.1.1/BSDrouted/defs.h'`" test 2540 -eq "$shar_count" || echo "vxrouted_5.1.1/BSDrouted/defs.h: original size 2540, current size $shar_count" rm -f _sharnew.tmp fi # ============= vxrouted_5.1.1/BSDrouted/af.c ============== if test -f 'vxrouted_5.1.1/BSDrouted/af.c' && test X"$1" != X"-c"; then echo 'x - skipping vxrouted_5.1.1/BSDrouted/af.c (File already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting vxrouted_5.1.1/BSDrouted/af.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'vxrouted_5.1.1/BSDrouted/af.c' && /* X * Copyright (c) 1983 Regents of the University of California. X * All rights reserved. X * X * Redistribution and use in source and binary forms are permitted X * provided that the above copyright notice and this paragraph are X * duplicated in all such forms and that any documentation, X * advertising materials, and other materials related to such X * distribution and use acknowledge that the software was developed X * by the University of California, Berkeley. The name of the X * University may not be used to endorse or promote products derived X * from this software without specific prior written permission. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. X */ X #ifndef lint static char sccsid[] = "@(#)af.c 5.8 (Berkeley) 6/18/88"; #endif /* not lint */ X #include "defs.h" X /* X * Address family support routines X */ int inet_hash(), inet_netmatch(), inet_output(), X inet_portmatch(), inet_portcheck(), X inet_checkhost(), inet_rtflags(), inet_sendroute(), inet_canon(); char *inet_format(); X #define NIL { 0 } #define INET \ X { inet_hash, inet_netmatch, inet_output, \ X inet_portmatch, inet_portcheck, inet_checkhost, \ X inet_rtflags, inet_sendroute, inet_canon, \ X inet_format \ X } X struct afswitch afswitch[AF_MAX] = { X NIL, /* 0- unused */ X NIL, /* 1- Unix domain, unused */ X INET, /* Internet */ }; X int af_max = sizeof(afswitch) / sizeof(afswitch[0]); X struct sockaddr_in inet_default = { AF_INET, INADDR_ANY }; X inet_hash(sin, hp) X register struct sockaddr_in *sin; X struct afhash *hp; { X register u_long n; X X n = inet_netof(sin->sin_addr); X if (n) X while ((n & 0xff) == 0) X n >>= 8; X hp->afh_nethash = n; X hp->afh_hosthash = ntohl(sin->sin_addr.s_addr); X hp->afh_hosthash &= 0x7fffffff; } X inet_netmatch(sin1, sin2) X struct sockaddr_in *sin1, *sin2; { X X return (inet_netof(sin1->sin_addr) == inet_netof(sin2->sin_addr)); } X /* X * Verify the message is from the right port. X */ inet_portmatch(sin) X register struct sockaddr_in *sin; { X X return (sin->sin_port == sp->s_port); } X /* X * Verify the message is from a "trusted" port. X */ inet_portcheck(sin) X struct sockaddr_in *sin; { X X return (ntohs(sin->sin_port) <= IPPORT_RESERVED); } X /* X * Internet output routine. X */ inet_output(s, flags, sin, size) X int s, flags; X struct sockaddr_in *sin; X int size; { X struct sockaddr_in dst; X X dst = *sin; X sin = &dst; X if (sin->sin_port == 0) X sin->sin_port = sp->s_port; X if (sendto(s, packet, size, flags, sin, sizeof (*sin)) < 0) X perror("sendto"); } X /* X * Return 1 if the address is believed X * for an Internet host -- THIS IS A KLUDGE. X */ inet_checkhost(sin) X struct sockaddr_in *sin; { X u_long i = ntohl(sin->sin_addr.s_addr); X #ifndef IN_EXPERIMENTAL #define IN_EXPERIMENTAL(i) (((long) (i) & 0xe0000000) == 0xe0000000) #endif X X if (IN_EXPERIMENTAL(i) || sin->sin_port != 0) X return (0); X if (i != 0 && (i & 0xff000000) == 0) X return (0); X for (i = 0; i < sizeof(sin->sin_zero)/sizeof(sin->sin_zero[0]); i++) X if (sin->sin_zero[i]) X return (0); X return (1); } X inet_canon(sin) X struct sockaddr_in *sin; { X X sin->sin_port = 0; } X char * inet_format(sin) X struct sockaddr_in *sin; { X char *inet_ntoa(); X X return (inet_ntoa(sin->sin_addr)); } SHAR_EOF $shar_touch -am 0618145688 'vxrouted_5.1.1/BSDrouted/af.c' && chmod 0444 'vxrouted_5.1.1/BSDrouted/af.c' || echo 'restore of vxrouted_5.1.1/BSDrouted/af.c failed' shar_count="`wc -c < 'vxrouted_5.1.1/BSDrouted/af.c'`" test 3334 -eq "$shar_count" || echo "vxrouted_5.1.1/BSDrouted/af.c: original size 3334, current size $shar_count" rm -f _sharnew.tmp fi # ============= vxrouted_5.1.1/BSDrouted/af.h ============== if test -f 'vxrouted_5.1.1/BSDrouted/af.h' && test X"$1" != X"-c"; then echo 'x - skipping vxrouted_5.1.1/BSDrouted/af.h (File already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting vxrouted_5.1.1/BSDrouted/af.h (Text)' sed 's/^X//' << 'SHAR_EOF' > 'vxrouted_5.1.1/BSDrouted/af.h' && /* X * Copyright (c) 1983 Regents of the University of California. X * All rights reserved. X * X * Redistribution and use in source and binary forms are permitted X * provided that the above copyright notice and this paragraph are X * duplicated in all such forms and that any documentation, X * advertising materials, and other materials related to such X * distribution and use acknowledge that the software was developed X * by the University of California, Berkeley. The name of the X * University may not be used to endorse or promote products derived X * from this software without specific prior written permission. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. X * X * @(#)af.h 5.6 (Berkeley) 6/18/88 X */ X /* X * Routing table management daemon. X */ X /* X * Per address family routines. X */ struct afswitch { X int (*af_hash)(); /* returns keys based on address */ X int (*af_netmatch)(); /* verifies net # matching */ X int (*af_output)(); /* interprets address for sending */ X int (*af_portmatch)(); /* packet from some other router? */ X int (*af_portcheck)(); /* packet from privileged peer? */ X int (*af_checkhost)(); /* tells if address is valid */ X int (*af_rtflags)(); /* get flags for route (host or net) */ X int (*af_sendroute)(); /* check bounds of subnet broadcast */ X int (*af_canon)(); /* canonicalize address for compares */ X char *(*af_format)(); /* convert address to string */ }; X /* X * Structure returned by af_hash routines. X */ struct afhash { X u_int afh_hosthash; /* host based hash */ X u_int afh_nethash; /* network based hash */ }; X struct afswitch afswitch[]; /* table proper */ int af_max; /* number of entries in table */ SHAR_EOF $shar_touch -am 0618145688 'vxrouted_5.1.1/BSDrouted/af.h' && chmod 0444 'vxrouted_5.1.1/BSDrouted/af.h' || echo 'restore of vxrouted_5.1.1/BSDrouted/af.h failed' shar_count="`wc -c < 'vxrouted_5.1.1/BSDrouted/af.h'`" test 1806 -eq "$shar_count" || echo "vxrouted_5.1.1/BSDrouted/af.h: original size 1806, current size $shar_count" rm -f _sharnew.tmp fi # ============= vxrouted_5.1.1/BSDrouted/if.c ============== if test -f 'vxrouted_5.1.1/BSDrouted/if.c' && test X"$1" != X"-c"; then echo 'x - skipping vxrouted_5.1.1/BSDrouted/if.c (File already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting vxrouted_5.1.1/BSDrouted/if.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'vxrouted_5.1.1/BSDrouted/if.c' && /* X * Copyright (c) 1983 Regents of the University of California. X * All rights reserved. X * X * Redistribution and use in source and binary forms are permitted X * provided that the above copyright notice and this paragraph are X * duplicated in all such forms and that any documentation, X * advertising materials, and other materials related to such X * distribution and use acknowledge that the software was developed X * by the University of California, Berkeley. The name of the X * University may not be used to endorse or promote products derived X * from this software without specific prior written permission. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. X */ X #ifndef lint static char sccsid[] = "@(#)if.c 5.5 (Berkeley) 6/18/88"; #endif /* not lint */ X /* X * Routing Table Management Daemon X */ #include "defs.h" X extern struct interface *ifnet; X /* X * Find the interface with address addr. X */ struct interface * if_ifwithaddr(addr) X struct sockaddr *addr; { X register struct interface *ifp; X #define same(a1, a2) \ X (bcmp((caddr_t)((a1)->sa_data), (caddr_t)((a2)->sa_data), 14) == 0) X for (ifp = ifnet; ifp; ifp = ifp->int_next) { X if (ifp->int_flags & IFF_REMOTE) X continue; X if (ifp->int_addr.sa_family != addr->sa_family) X continue; X if (same(&ifp->int_addr, addr)) X break; X if ((ifp->int_flags & IFF_BROADCAST) && X same(&ifp->int_broadaddr, addr)) X break; X } X return (ifp); } X /* X * Find the point-to-point interface with destination address addr. X */ struct interface * if_ifwithdstaddr(addr) X struct sockaddr *addr; { X register struct interface *ifp; X X for (ifp = ifnet; ifp; ifp = ifp->int_next) { X if ((ifp->int_flags & IFF_POINTOPOINT) == 0) X continue; X if (same(&ifp->int_dstaddr, addr)) X break; X } X return (ifp); } X /* X * Find the interface on the network X * of the specified address. X */ struct interface * if_ifwithnet(addr) X register struct sockaddr *addr; { X register struct interface *ifp; X register int af = addr->sa_family; X register int (*netmatch)(); X X if (af >= af_max) X return (0); X netmatch = afswitch[af].af_netmatch; X for (ifp = ifnet; ifp; ifp = ifp->int_next) { X if (ifp->int_flags & IFF_REMOTE) X continue; X if (af != ifp->int_addr.sa_family) X continue; X if ((*netmatch)(addr, &ifp->int_addr)) X break; X } X return (ifp); } X /* X * Find an interface from which the specified address X * should have come from. Used for figuring out which X * interface a packet came in on -- for tracing. X */ struct interface * if_iflookup(addr) X struct sockaddr *addr; { X register struct interface *ifp, *maybe; X register int af = addr->sa_family; X register int (*netmatch)(); X X if (af >= af_max) X return (0); X maybe = 0; X netmatch = afswitch[af].af_netmatch; X for (ifp = ifnet; ifp; ifp = ifp->int_next) { X if (ifp->int_addr.sa_family != af) X continue; X if (same(&ifp->int_addr, addr)) X break; X if ((ifp->int_flags & IFF_BROADCAST) && X same(&ifp->int_broadaddr, addr)) X break; X if ((ifp->int_flags & IFF_POINTOPOINT) && X same(&ifp->int_dstaddr, addr)) X break; X if (maybe == 0 && (*netmatch)(addr, &ifp->int_addr)) X maybe = ifp; X } X if (ifp == 0) X ifp = maybe; X return (ifp); } SHAR_EOF $shar_touch -am 0217120589 'vxrouted_5.1.1/BSDrouted/if.c' && chmod 0444 'vxrouted_5.1.1/BSDrouted/if.c' || echo 'restore of vxrouted_5.1.1/BSDrouted/if.c failed' shar_count="`wc -c < 'vxrouted_5.1.1/BSDrouted/if.c'`" test 3311 -eq "$shar_count" || echo "vxrouted_5.1.1/BSDrouted/if.c: original size 3311, current size $shar_count" rm -f _sharnew.tmp fi # ============= vxrouted_5.1.1/BSDrouted/inet.c ============== if test -f 'vxrouted_5.1.1/BSDrouted/inet.c' && test X"$1" != X"-c"; then echo 'x - skipping vxrouted_5.1.1/BSDrouted/inet.c (File already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting vxrouted_5.1.1/BSDrouted/inet.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'vxrouted_5.1.1/BSDrouted/inet.c' && /* X * Copyright (c) 1983 Regents of the University of California. X * All rights reserved. X * X * Redistribution and use in source and binary forms are permitted X * provided that the above copyright notice and this paragraph are X * duplicated in all such forms and that any documentation, X * advertising materials, and other materials related to such X * distribution and use acknowledge that the software was developed X * by the University of California, Berkeley. The name of the X * University may not be used to endorse or promote products derived X * from this software without specific prior written permission. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. X */ X #ifndef lint static char sccsid[] = "@(#)inet.c 5.7 (Berkeley) 6/18/88"; #endif /* not lint */ X /* X * Temporarily, copy these routines from the kernel, X * as we need to know about subnets. X */ #include "defs.h" X extern struct interface *ifnet; X /* X * Formulate an Internet address from network + host. X */ struct in_addr inet_makeaddr(net, host) X u_long net, host; { X register struct interface *ifp; X register u_long mask; X u_long addr; X X if (IN_CLASSA(net)) X mask = IN_CLASSA_HOST; X else if (IN_CLASSB(net)) X mask = IN_CLASSB_HOST; X else X mask = IN_CLASSC_HOST; X for (ifp = ifnet; ifp; ifp = ifp->int_next) X if ((ifp->int_netmask & net) == ifp->int_net) { X mask = ~ifp->int_subnetmask; X break; X } X addr = net | (host & mask); X addr = htonl(addr); X return (*(struct in_addr *)&addr); } X /* X * Return the network number from an internet address. X */ inet_netof(in) X struct in_addr in; { X register u_long i = ntohl(in.s_addr); X register u_long net; X register struct interface *ifp; X X if (IN_CLASSA(i)) X net = i & IN_CLASSA_NET; X else if (IN_CLASSB(i)) X net = i & IN_CLASSB_NET; X else X net = i & IN_CLASSC_NET; X X /* X * Check whether network is a subnet; X * if so, return subnet number. X */ X for (ifp = ifnet; ifp; ifp = ifp->int_next) X if ((ifp->int_netmask & net) == ifp->int_net) X return (i & ifp->int_subnetmask); X return (net); } X /* X * Return the host portion of an internet address. X */ inet_lnaof(in) X struct in_addr in; { X register u_long i = ntohl(in.s_addr); X register u_long net, host; X register struct interface *ifp; X X if (IN_CLASSA(i)) { X net = i & IN_CLASSA_NET; X host = i & IN_CLASSA_HOST; X } else if (IN_CLASSB(i)) { X net = i & IN_CLASSB_NET; X host = i & IN_CLASSB_HOST; X } else { X net = i & IN_CLASSC_NET; X host = i & IN_CLASSC_HOST; X } X X /* X * Check whether network is a subnet; X * if so, use the modified interpretation of `host'. X */ X for (ifp = ifnet; ifp; ifp = ifp->int_next) X if ((ifp->int_netmask & net) == ifp->int_net) X return (host &~ ifp->int_subnetmask); X return (host); } X /* X * Return RTF_HOST if the address is X * for an Internet host, RTF_SUBNET for a subnet, X * 0 for a network. X */ inet_rtflags(sin) X struct sockaddr_in *sin; { X register u_long i = ntohl(sin->sin_addr.s_addr); X register u_long net, host; X register struct interface *ifp; X X if (IN_CLASSA(i)) { X net = i & IN_CLASSA_NET; X host = i & IN_CLASSA_HOST; X } else if (IN_CLASSB(i)) { X net = i & IN_CLASSB_NET; X host = i & IN_CLASSB_HOST; X } else { X net = i & IN_CLASSC_NET; X host = i & IN_CLASSC_HOST; X } X X /* X * Check whether this network is subnetted; X * if so, check whether this is a subnet or a host. X */ X for (ifp = ifnet; ifp; ifp = ifp->int_next) X if (net == ifp->int_net) { X if (host &~ ifp->int_subnetmask) X return (RTF_HOST); X else if (ifp->int_subnetmask != ifp->int_netmask) X return (RTF_SUBNET); X else X return (0); /* network */ X } X if (host == 0) X return (0); /* network */ X else X return (RTF_HOST); } X /* X * Return true if a route to subnet/host of route rt should be sent to dst. X * Send it only if dst is on the same logical network if not "internal", X * otherwise only if the route is the "internal" route for the logical net. X */ inet_sendroute(rt, dst) X struct rt_entry *rt; X struct sockaddr_in *dst; { X register u_long r = X ntohl(((struct sockaddr_in *)&rt->rt_dst)->sin_addr.s_addr); X register u_long d = ntohl(dst->sin_addr.s_addr); X X if (IN_CLASSA(r)) { X if ((r & IN_CLASSA_NET) == (d & IN_CLASSA_NET)) { X if ((r & IN_CLASSA_HOST) == 0) X return ((rt->rt_state & RTS_INTERNAL) == 0); X return (1); X } X if (r & IN_CLASSA_HOST) X return (0); X return ((rt->rt_state & RTS_INTERNAL) != 0); X } else if (IN_CLASSB(r)) { X if ((r & IN_CLASSB_NET) == (d & IN_CLASSB_NET)) { X if ((r & IN_CLASSB_HOST) == 0) X return ((rt->rt_state & RTS_INTERNAL) == 0); X return (1); X } X if (r & IN_CLASSB_HOST) X return (0); X return ((rt->rt_state & RTS_INTERNAL) != 0); X } else { X if ((r & IN_CLASSC_NET) == (d & IN_CLASSC_NET)) { X if ((r & IN_CLASSC_HOST) == 0) X return ((rt->rt_state & RTS_INTERNAL) == 0); X return (1); X } X if (r & IN_CLASSC_HOST) X return (0); X return ((rt->rt_state & RTS_INTERNAL) != 0); X } } SHAR_EOF $shar_touch -am 0618145688 'vxrouted_5.1.1/BSDrouted/inet.c' && chmod 0444 'vxrouted_5.1.1/BSDrouted/inet.c' || echo 'restore of vxrouted_5.1.1/BSDrouted/inet.c failed' shar_count="`wc -c < 'vxrouted_5.1.1/BSDrouted/inet.c'`" test 5026 -eq "$shar_count" || echo "vxrouted_5.1.1/BSDrouted/inet.c: original size 5026, current size $shar_count" rm -f _sharnew.tmp fi # ============= vxrouted_5.1.1/BSDrouted/input.c ============== if test -f 'vxrouted_5.1.1/BSDrouted/input.c' && test X"$1" != X"-c"; then echo 'x - skipping vxrouted_5.1.1/BSDrouted/input.c (File already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting vxrouted_5.1.1/BSDrouted/input.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'vxrouted_5.1.1/BSDrouted/input.c' && /* X * Copyright (c) 1983, 1988 Regents of the University of California. X * All rights reserved. X * X * Redistribution and use in source and binary forms are permitted X * provided that the above copyright notice and this paragraph are X * duplicated in all such forms and that any documentation, X * advertising materials, and other materials related to such X * distribution and use acknowledge that the software was developed X * by the University of California, Berkeley. The name of the X * University may not be used to endorse or promote products derived X * from this software without specific prior written permission. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. X */ X #ifndef lint static char sccsid[] = "@(#)input.c 5.20 (Berkeley) 2/20/89"; #endif /* not lint */ X /* X * Routing Table Management Daemon X */ #include "defs.h" #include X /* X * Process a newly received packet. X */ rip_input(from, rip, size) X struct sockaddr *from; X register struct rip *rip; X int size; { X register struct rt_entry *rt; X register struct netinfo *n; X register struct interface *ifp; X struct interface *if_ifwithdstaddr(); X int count, changes = 0; X register struct afswitch *afp; X static struct sockaddr badfrom, badfrom2; X X ifp = 0; X TRACE_INPUT(ifp, from, (char *)rip, size); X if (from->sa_family >= af_max || X (afp = &afswitch[from->sa_family])->af_hash == (int (*)())0) { X syslog(LOG_INFO, X "\"from\" address in unsupported address family (%d), cmd %d\n", X from->sa_family, rip->rip_cmd); X return; X } X if (rip->rip_vers == 0) { X syslog(LOG_ERR, X "RIP version 0 packet received from %s! (cmd %d)", X (*afswitch[from->sa_family].af_format)(from), rip->rip_cmd); X return; X } X switch (rip->rip_cmd) { X X case RIPCMD_REQUEST: X n = rip->rip_nets; X count = size - ((char *)n - (char *)rip); X if (count < sizeof (struct netinfo)) X return; X for (; count > 0; n++) { X if (count < sizeof (struct netinfo)) X break; X count -= sizeof (struct netinfo); X #if BSD < 198810 X if (sizeof(n->rip_dst.sa_family) > 1)/* XXX */ X n->rip_dst.sa_family = X ntohs(n->rip_dst.sa_family); #endif X n->rip_metric = ntohl(n->rip_metric); X /* X * A single entry with sa_family == AF_UNSPEC and X * metric ``infinity'' means ``all routes''. X * We respond to routers only if we are acting X * as a supplier, or to anyone other than a router X * (eg, query). X */ X if (n->rip_dst.sa_family == AF_UNSPEC && X n->rip_metric == HOPCNT_INFINITY && count == 0) { X if (supplier || (*afp->af_portmatch)(from) == 0) X supply(from, 0, 0, 0); X return; X } X if (n->rip_dst.sa_family < af_max && X afswitch[n->rip_dst.sa_family].af_hash) X rt = rtlookup(&n->rip_dst); X else X rt = 0; X n->rip_metric = rt == 0 ? HOPCNT_INFINITY : X min(rt->rt_metric + 1, HOPCNT_INFINITY); #if BSD < 198810 X if (sizeof(n->rip_dst.sa_family) > 1) /* XXX */ X n->rip_dst.sa_family = htons(n->rip_dst.sa_family); #endif X n->rip_metric = htonl(n->rip_metric); X } X rip->rip_cmd = RIPCMD_RESPONSE; X bcopy((char *)rip, packet, size); X (*afp->af_output)(s, 0, from, size); X return; X X case RIPCMD_TRACEON: X case RIPCMD_TRACEOFF: X /* verify message came from a privileged port */ X if ((*afp->af_portcheck)(from) == 0) X return; X if ((ifp = if_iflookup(from)) == 0 || (ifp->int_flags & X (IFF_BROADCAST | IFF_POINTOPOINT | IFF_REMOTE)) == 0 || X ifp->int_flags & IFF_PASSIVE) { X syslog(LOG_ERR, "trace command from unknown router, %s", X (*afswitch[from->sa_family].af_format)(from)); X return; X } X ((char *)rip)[size] = '\0'; X if (rip->rip_cmd == RIPCMD_TRACEON) X traceon(rip->rip_tracefile); X else X traceoff(); X return; X X case RIPCMD_RESPONSE: X /* verify message came from a router */ X if ((*afp->af_portmatch)(from) == 0) X return; X (*afp->af_canon)(from); X /* are we talking to ourselves? */ X ifp = if_ifwithaddr(from); X if (ifp) { X if (ifp->int_flags & IFF_PASSIVE) { X syslog(LOG_ERR, X "bogus input (from passive interface, %s)", X (*afswitch[from->sa_family].af_format)(from)); X return; X } X rt = rtfind(from); X if (rt == 0 || ((rt->rt_state & RTS_INTERFACE) == 0) && X rt->rt_metric >= ifp->int_metric) X addrouteforif(ifp); X else X rt->rt_timer = 0; X return; X } X /* X * Update timer for interface on which the packet arrived. X * If from other end of a point-to-point link that isn't X * in the routing tables, (re-)add the route. X */ X if ((rt = rtfind(from)) && X (rt->rt_state & (RTS_INTERFACE | RTS_REMOTE))) X rt->rt_timer = 0; X else if ((ifp = if_ifwithdstaddr(from)) && X (rt == 0 || rt->rt_metric >= ifp->int_metric)) X addrouteforif(ifp); X /* X * "Authenticate" router from which message originated. X * We accept routing packets from routers directly connected X * via broadcast or point-to-point networks, X * and from those listed in /etc/gateways. X */ X if ((ifp = if_iflookup(from)) == 0 || (ifp->int_flags & X (IFF_BROADCAST | IFF_POINTOPOINT | IFF_REMOTE)) == 0 || X ifp->int_flags & IFF_PASSIVE) { X if (bcmp((char *)from, (char *)&badfrom, X sizeof(badfrom)) != 0) { X syslog(LOG_ERR, X "packet from unknown router, %s", X (*afswitch[from->sa_family].af_format)(from)); X badfrom = *from; X } X return; X } X size -= 4 * sizeof (char); X n = rip->rip_nets; X for (; size > 0; size -= sizeof (struct netinfo), n++) { X if (size < sizeof (struct netinfo)) X break; #if BSD < 198810 X if (sizeof(n->rip_dst.sa_family) > 1) /* XXX */ X n->rip_dst.sa_family = X ntohs(n->rip_dst.sa_family); #endif X n->rip_metric = ntohl(n->rip_metric); X if (n->rip_dst.sa_family >= af_max || X (afp = &afswitch[n->rip_dst.sa_family])->af_hash == X (int (*)())0) { X syslog(LOG_INFO, X "route in unsupported address family (%d), from %s (af %d)\n", X n->rip_dst.sa_family, X (*afswitch[from->sa_family].af_format)(from), X from->sa_family); X continue; X } X if (((*afp->af_checkhost)(&n->rip_dst)) == 0) { X syslog(LOG_DEBUG, X "bad host in route from %s (af %d)\n", X (*afswitch[from->sa_family].af_format)(from), X from->sa_family); X continue; X } X if (n->rip_metric == 0 || X (unsigned) n->rip_metric > HOPCNT_INFINITY) { X if (bcmp((char *)from, (char *)&badfrom2, X sizeof(badfrom2)) != 0) { X syslog(LOG_ERR, X "bad metric (%d) from %s\n", X n->rip_metric, X (*afswitch[from->sa_family].af_format)(from)); X badfrom2 = *from; X } X continue; X } X /* X * Adjust metric according to incoming interface. X */ X if ((unsigned) n->rip_metric < HOPCNT_INFINITY) X n->rip_metric += ifp->int_metric; X if ((unsigned) n->rip_metric > HOPCNT_INFINITY) X n->rip_metric = HOPCNT_INFINITY; X rt = rtlookup(&n->rip_dst); X if (rt == 0 || X (rt->rt_state & (RTS_INTERNAL|RTS_INTERFACE)) == X (RTS_INTERNAL|RTS_INTERFACE)) { X /* X * If we're hearing a logical network route X * back from a peer to which we sent it, X * ignore it. X */ X if (rt && rt->rt_state & RTS_SUBNET && X (*afp->af_sendroute)(rt, from)) X continue; X if ((unsigned)n->rip_metric < HOPCNT_INFINITY) { X /* X * Look for an equivalent route that X * includes this one before adding X * this route. X */ X rt = rtfind(&n->rip_dst); X if (rt && equal(from, &rt->rt_router)) X continue; X rtadd(&n->rip_dst, from, n->rip_metric, 0); X changes++; X } X continue; X } X X /* X * Update if from gateway and different, X * shorter, or equivalent but old route X * is getting stale. X */ X if (equal(from, &rt->rt_router)) { X if (n->rip_metric != rt->rt_metric) { X rtchange(rt, from, n->rip_metric); X changes++; X rt->rt_timer = 0; X if (rt->rt_metric >= HOPCNT_INFINITY) X rt->rt_timer = X GARBAGE_TIME - EXPIRE_TIME; X } else if (rt->rt_metric < HOPCNT_INFINITY) X rt->rt_timer = 0; X } else if ((unsigned) n->rip_metric < rt->rt_metric || X (rt->rt_metric == n->rip_metric && X rt->rt_timer > (EXPIRE_TIME/2) && X (unsigned) n->rip_metric < HOPCNT_INFINITY)) { X rtchange(rt, from, n->rip_metric); X changes++; X rt->rt_timer = 0; X } X } X break; X } X X /* X * If changes have occurred, and if we have not sent a broadcast X * recently, send a dynamic update. This update is sent only X * on interfaces other than the one on which we received notice X * of the change. If we are within MIN_WAITTIME of a full update, X * don't bother sending; if we just sent a dynamic update X * and set a timer (nextbcast), delay until that time. X * If we just sent a full update, delay the dynamic update. X * Set a timer for a randomized value to suppress additional X * dynamic updates until it expires; if we delayed sending X * the current changes, set needupdate. X */ X if (changes && supplier && X now.tv_sec - lastfullupdate.tv_sec < SUPPLY_INTERVAL-MAX_WAITTIME) { X u_long delay; X extern long random(); X X if (now.tv_sec - lastbcast.tv_sec >= MIN_WAITTIME && X timercmp(&nextbcast, &now, <)) { X if (traceactions) X fprintf(ftrace, "send dynamic update\n"); X toall(supply, RTS_CHANGED, ifp); X lastbcast = now; X needupdate = 0; X nextbcast.tv_sec = 0; X } else { X needupdate++; X if (traceactions) X fprintf(ftrace, "delay dynamic update\n"); X } #define RANDOMDELAY() (MIN_WAITTIME * 1000000 + \ X (u_long)random() % ((MAX_WAITTIME - MIN_WAITTIME) * 1000000)) X X if (nextbcast.tv_sec == 0) { X delay = RANDOMDELAY(); X if (traceactions) X fprintf(ftrace, X "inhibit dynamic update for %d usec\n", X delay); X nextbcast.tv_sec = delay / 1000000; X nextbcast.tv_usec = delay % 1000000; X timevaladd(&nextbcast, &now); X /* X * If the next possibly dynamic update X * is within MIN_WAITTIME of the next full update, X * force the delay past the full update, X * or we might send a dynamic update just before X * the full update. X */ X if (nextbcast.tv_sec > lastfullupdate.tv_sec + X SUPPLY_INTERVAL - MIN_WAITTIME) X nextbcast.tv_sec = lastfullupdate.tv_sec + X SUPPLY_INTERVAL + 1; X } X } } SHAR_EOF $shar_touch -am 0220182189 'vxrouted_5.1.1/BSDrouted/input.c' && chmod 0444 'vxrouted_5.1.1/BSDrouted/input.c' || echo 'restore of vxrouted_5.1.1/BSDrouted/input.c failed' shar_count="`wc -c < 'vxrouted_5.1.1/BSDrouted/input.c'`" test 10333 -eq "$shar_count" || echo "vxrouted_5.1.1/BSDrouted/input.c: original size 10333, current size $shar_count" rm -f _sharnew.tmp fi # ============= vxrouted_5.1.1/BSDrouted/interface.h ============== if test -f 'vxrouted_5.1.1/BSDrouted/interface.h' && test X"$1" != X"-c"; then echo 'x - skipping vxrouted_5.1.1/BSDrouted/interface.h (File already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting vxrouted_5.1.1/BSDrouted/interface.h (Text)' sed 's/^X//' << 'SHAR_EOF' > 'vxrouted_5.1.1/BSDrouted/interface.h' && /* X * Copyright (c) 1983 Regents of the University of California. X * All rights reserved. X * X * Redistribution and use in source and binary forms are permitted X * provided that the above copyright notice and this paragraph are X * duplicated in all such forms and that any documentation, X * advertising materials, and other materials related to such X * distribution and use acknowledge that the software was developed X * by the University of California, Berkeley. The name of the X * University may not be used to endorse or promote products derived X * from this software without specific prior written permission. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. X * X * @(#)interface.h 5.5 (Berkeley) 6/18/88 X */ X /* X * Routing table management daemon. X */ X /* X * An ``interface'' is similar to an ifnet structure, X * except it doesn't contain q'ing info, and it also X * handles ``logical'' interfaces (remote gateways X * that we want to keep polling even if they go down). X * The list of interfaces which we maintain is used X * in supplying the gratuitous routing table updates. X */ struct interface { X struct interface *int_next; X struct sockaddr int_addr; /* address on this host */ X union { X struct sockaddr intu_broadaddr; X struct sockaddr intu_dstaddr; X } int_intu; #define int_broadaddr int_intu.intu_broadaddr /* broadcast address */ #define int_dstaddr int_intu.intu_dstaddr /* other end of p-to-p link */ X int int_metric; /* init's routing entry */ X int int_flags; /* see below */ X /* START INTERNET SPECIFIC */ X u_long int_net; /* network # */ X u_long int_netmask; /* net mask for addr */ X u_long int_subnet; /* subnet # */ X u_long int_subnetmask; /* subnet mask for addr */ X /* END INTERNET SPECIFIC */ X struct ifdebug int_input, int_output; /* packet tracing stuff */ X int int_ipackets; /* input packets received */ X int int_opackets; /* output packets sent */ X char *int_name; /* from kernel if structure */ X u_short int_transitions; /* times gone up-down */ }; X /* X * 0x1 to 0x10 are reused from the kernel's ifnet definitions, X * the others agree with the RTS_ flags defined elsewhere. X */ #define IFF_UP 0x1 /* interface is up */ #define IFF_BROADCAST 0x2 /* broadcast address valid */ #define IFF_DEBUG 0x4 /* turn on debugging */ #define IFF_LOOPBACK 0x8 /* software loopback net */ #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ X #define IFF_SUBNET 0x1000 /* interface on subnetted network */ #define IFF_PASSIVE 0x2000 /* can't tell if up/down */ #define IFF_INTERFACE 0x4000 /* hardware interface */ #define IFF_REMOTE 0x8000 /* interface isn't on this machine */ X struct interface *if_ifwithaddr(); struct interface *if_ifwithdstaddr(); struct interface *if_ifwithnet(); struct interface *if_iflookup(); SHAR_EOF $shar_touch -am 0726103088 'vxrouted_5.1.1/BSDrouted/interface.h' && chmod 0444 'vxrouted_5.1.1/BSDrouted/interface.h' || echo 'restore of vxrouted_5.1.1/BSDrouted/interface.h failed' shar_count="`wc -c < 'vxrouted_5.1.1/BSDrouted/interface.h'`" test 2933 -eq "$shar_count" || echo "vxrouted_5.1.1/BSDrouted/interface.h: original size 2933, current size $shar_count" rm -f _sharnew.tmp fi # ============= vxrouted_5.1.1/BSDrouted/main.c ============== if test -f 'vxrouted_5.1.1/BSDrouted/main.c' && test X"$1" != X"-c"; then echo 'x - skipping vxrouted_5.1.1/BSDrouted/main.c (File already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting vxrouted_5.1.1/BSDrouted/main.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'vxrouted_5.1.1/BSDrouted/main.c' && /* X * Copyright (c) 1983, 1988 Regents of the University of California. X * All rights reserved. X * X * Redistribution and use in source and binary forms are permitted X * provided that the above copyright notice and this paragraph are X * duplicated in all such forms and that any documentation, X * advertising materials, and other materials related to such X * distribution and use acknowledge that the software was developed X * by the University of California, Berkeley. The name of the X * University may not be used to endorse or promote products derived X * from this software without specific prior written permission. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. X */ X #ifndef lint char copyright[] = "@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\ X All rights reserved.\n"; #endif /* not lint */ X #ifndef lint static char sccsid[] = "@(#)main.c 5.17 (Berkeley) 2/20/89"; #endif /* not lint */ X /* X * Routing Table Management Daemon X */ #include "defs.h" #include #include X #include X #include #include #include X int supplier = -1; /* process should supply updates */ int gateway = 0; /* 1 if we are a gateway to parts beyond */ int debug = 0; int bufspace = 127*1024; /* max. input buffer size to request */ X struct rip *msg = (struct rip *)packet; int hup(), rtdeleteall(), sigtrace(); X main(argc, argv) X int argc; X char *argv[]; { X int n, cc, nfd, omask, tflags = 0; X struct sockaddr from; X struct timeval *tvp, waittime; X struct itimerval itval; X fd_set ibits; X u_char retry; X X argv0 = argv; #if BSD >= 43 X openlog("routed", LOG_PID | LOG_ODELAY, LOG_DAEMON); X setlogmask(LOG_UPTO(LOG_WARNING)); #else X openlog("routed", LOG_PID); #define LOG_UPTO(x) (x) #define setlogmask(x) (x) #endif X sp = getservbyname("router", "udp"); X if (sp == NULL) { X fprintf(stderr, "routed: router/udp: unknown service\n"); X exit(1); X } X addr.sin_family = AF_INET; X addr.sin_port = sp->s_port; X s = getsocket(AF_INET, SOCK_DGRAM, &addr); X if (s < 0) X exit(1); X argv++, argc--; X while (argc > 0 && **argv == '-') { X if (strcmp(*argv, "-s") == 0) { X supplier = 1; X argv++, argc--; X continue; X } X if (strcmp(*argv, "-q") == 0) { X supplier = 0; X argv++, argc--; X continue; X } X if (strcmp(*argv, "-t") == 0) { X tflags++; X setlogmask(LOG_UPTO(LOG_DEBUG)); X argv++, argc--; X continue; X } X if (strcmp(*argv, "-d") == 0) { X debug++; X setlogmask(LOG_UPTO(LOG_DEBUG)); X argv++, argc--; X continue; X } X if (strcmp(*argv, "-g") == 0) { X gateway = 1; X argv++, argc--; X continue; X } X fprintf(stderr, X "usage: routed [ -s ] [ -q ] [ -t ] [ -g ]\n"); X exit(1); X } X X if (debug == 0) { X int t; X X if (fork()) X exit(0); X for (t = 0; t < 20; t++) X if (t != s) X (void) close(t); X (void) open("/", 0); X (void) dup2(0, 1); X (void) dup2(0, 2); X t = open("/dev/tty", 2); X if (t >= 0) { X ioctl(t, TIOCNOTTY, (char *)0); X (void) close(t); X } X } X /* X * Any extra argument is considered X * a tracing log file. X */ X if (argc > 0) X traceon(*argv); X while (tflags-- > 0) X bumploglevel(); X X (void) gettimeofday(&now, (struct timezone *)NULL); X /* X * Collect an initial view of the world by X * checking the interface configuration and the gateway kludge X * file. Then, send a request packet on all X * directly connected networks to find out what X * everyone else thinks. X */ X rtinit(); X ifinit(); X gwkludge(); X if (gateway > 0) X rtdefault(); X if (supplier < 0) X supplier = 0; X msg->rip_cmd = RIPCMD_REQUEST; X msg->rip_vers = RIPVERSION; X if (sizeof(msg->rip_nets[0].rip_dst.sa_family) > 1) /* XXX */ X msg->rip_nets[0].rip_dst.sa_family = htons((u_short)AF_UNSPEC); X else X msg->rip_nets[0].rip_dst.sa_family = AF_UNSPEC; X msg->rip_nets[0].rip_metric = htonl((u_long)HOPCNT_INFINITY); X toall(sendmsg); X signal(SIGALRM, timer); X signal(SIGHUP, hup); X signal(SIGTERM, hup); X signal(SIGINT, rtdeleteall); X signal(SIGUSR1, sigtrace); X signal(SIGUSR2, sigtrace); X itval.it_interval.tv_sec = TIMER_RATE; X itval.it_value.tv_sec = TIMER_RATE; X itval.it_interval.tv_usec = 0; X itval.it_value.tv_usec = 0; X srandom(getpid()); X if (setitimer(ITIMER_REAL, &itval, (struct itimerval *)NULL) < 0) X syslog(LOG_ERR, "setitimer: %m\n"); X X FD_ZERO(&ibits); X nfd = s + 1; /* 1 + max(fd's) */ X for (;;) { X FD_SET(s, &ibits); X /* X * If we need a dynamic update that was held off, X * needupdate will be set, and nextbcast is the time X * by which we want select to return. Compute time X * until dynamic update should be sent, and select only X * until then. If we have already passed nextbcast, X * just poll. X */ X if (needupdate) { X waittime = nextbcast; X timevalsub(&waittime, &now); X if (waittime.tv_sec < 0) { X waittime.tv_sec = 0; X waittime.tv_usec = 0; X } X if (traceactions) X fprintf(ftrace, X "select until dynamic update %d/%d sec/usec\n", X waittime.tv_sec, waittime.tv_usec); X tvp = &waittime; X } else X tvp = (struct timeval *)NULL; X n = select(nfd, &ibits, 0, 0, tvp); X if (n <= 0) { X /* X * Need delayed dynamic update if select returned X * nothing and we timed out. Otherwise, ignore X * errors (e.g. EINTR). X */ X if (n < 0) { X if (errno == EINTR) X continue; X syslog(LOG_ERR, "select: %m"); X } X omask = sigblock(sigmask(SIGALRM)); X if (n == 0 && needupdate) { X if (traceactions) X fprintf(ftrace, X "send delayed dynamic update\n"); X (void) gettimeofday(&now, X (struct timezone *)NULL); X toall(supply, RTS_CHANGED, X (struct interface *)NULL); X lastbcast = now; X needupdate = 0; X nextbcast.tv_sec = 0; X } X sigsetmask(omask); X continue; X } X (void) gettimeofday(&now, (struct timezone *)NULL); X omask = sigblock(sigmask(SIGALRM)); #ifdef doesntwork /* printf("s %d, ibits %x index %d, mod %d, sh %x, or %x &ibits %x\n", X s, X ibits.fds_bits[0], X (s)/(sizeof(fd_mask) * 8), X ((s) % (sizeof(fd_mask) * 8)), X (1 << ((s) % (sizeof(fd_mask) * 8))), SHAR_EOF : || echo 'restore of vxrouted_5.1.1/BSDrouted/main.c failed' fi echo 'End of archive part 6' echo 'File vxrouted_5.1.1/BSDrouted/main.c is continued in part 7' echo 7 > _sharseq.tmp exit 0