From a9f3e17433e07b2aa0bc51e8194a7fd7952fe44f Mon Sep 17 00:00:00 2001 From: Sam Leffler Date: Thu, 1 Apr 1982 03:37:05 -0800 Subject: [PATCH] routing tried and working, add logical host stuff SCCS-vsn: sys/vax/if/if_en.c 4.47 SCCS-vsn: sys/netinet/ip_input.c 1.38 SCCS-vsn: sys/netinet/ip_output.c 1.31 SCCS-vsn: sys/net/route.c 4.6 SCCS-vsn: sys/net/route.h 4.7 --- usr/src/sys/net/route.c | 17 +++++++--- usr/src/sys/net/route.h | 25 ++++++++++----- usr/src/sys/netinet/ip_input.c | 9 ++++-- usr/src/sys/netinet/ip_output.c | 11 ++++--- usr/src/sys/vax/if/if_en.c | 57 +++++++++++++++++++++++++++++++-- 5 files changed, 96 insertions(+), 23 deletions(-) diff --git a/usr/src/sys/net/route.c b/usr/src/sys/net/route.c index 406ff9de50..f9b9e232e5 100644 --- a/usr/src/sys/net/route.c +++ b/usr/src/sys/net/route.c @@ -1,4 +1,4 @@ -/* route.c 4.5 82/03/30 */ +/* route.c 4.6 82/03/31 */ #include "../h/param.h" #include "../h/systm.h" @@ -57,13 +57,14 @@ COUNT(RTALLOC); } found: ro->ro_rt = rtmin; + if (rtmin) + rtmin->rt_refcnt++; } rtfree(rt) register struct rtentry *rt; { -COUNT(FREEROUTE); if (rt == 0) panic("freeroute"); rt->rt_refcnt--; @@ -87,6 +88,7 @@ rtrequest(req, new) register struct sockaddr *sa = &new->rt_dst; register struct sockaddr *gate = &new->rt_gateway; struct afhash h; + struct mbuf **oldmprev; int af = sa->sa_family, doinghost, s, error = 0; COUNT(RTREQUEST); @@ -120,6 +122,7 @@ again: } if (m == 0 && doinghost) { hash = h.afh_nethash; + oldmprev = mprev; mprev = &rtnet[hash % RTHASHSIZ]; match = afswitch[af].af_netmatch; doinghost = 0; @@ -157,11 +160,15 @@ found: } m->m_off = MMINOFF; m->m_len = sizeof (struct rtentry); - *mprev = m; rt = mtod(m, struct rtentry *); *rt = *new; - rt->rt_hash = new->rt_flags & RTF_HOST ? - h.afh_hosthash : h.afh_nethash; + if (new->rt_flags & RTF_HOST) { + rt->rt_hash = h.afh_hosthash; + *oldmprev = m; + } else { + rt->rt_hash = h.afh_nethash; + *mprev = m; + } rt->rt_use = 0; rt->rt_refcnt = 0; newneighbor: diff --git a/usr/src/sys/net/route.h b/usr/src/sys/net/route.h index 10e2bfec4a..9b70060243 100644 --- a/usr/src/sys/net/route.h +++ b/usr/src/sys/net/route.h @@ -1,14 +1,17 @@ -/* route.h 4.6 82/03/30 */ +/* route.h 4.7 82/03/31 */ /* - * Structure of kernel resident routing - * data base. Assumption is user routing - * daemon maintains this data base based - * on routing information it gleans from - * gateway protocols it listens to (e.g. GGP). + * Kernel resident routing tables. + * + * Each interface makes an entry at boot time so that + * correspondents directly addressible can be found. + * User programs can update this data base from information + * stored in the file system or information gleaned from + * routing protocol interactions with gateways. * - * TO ADD: - * more statistics -- smooth usage figures + * TODO: + * keep statistics + * smooth usage figures */ struct rtentry { u_long rt_hash; /* for net or for host */ @@ -33,6 +36,12 @@ struct route { #define RTF_DIRECT 0x2 /* destination is a neighbor */ #define RTF_HOST 0x4 /* host entry (net otherwise) */ +#define RTFREE(rt) \ + if ((rt)->rt_refcnt == 1) \ + rtfree(rt); \ + else \ + (rt)->rt_refcnt--; + #ifdef KERNEL /* * Lookup are hashed by a key. Each hash bucket diff --git a/usr/src/sys/netinet/ip_input.c b/usr/src/sys/netinet/ip_input.c index 109f234a02..04fc07c13f 100644 --- a/usr/src/sys/netinet/ip_input.c +++ b/usr/src/sys/netinet/ip_input.c @@ -1,4 +1,4 @@ -/* ip_input.c 1.37 82/03/30 */ +/* ip_input.c 1.38 82/03/31 */ #include "../h/param.h" #include "../h/systm.h" @@ -45,7 +45,8 @@ COUNT(IP_INIT); u_char ipcksum = 1; struct ip *ip_reass(); -int ipforwarding = 0; +int ipforwarding = 1; +int ipprintfs = 0; struct sockaddr_in ipaddr = { AF_INET }; /* @@ -142,7 +143,9 @@ next: } ipaddr.sin_addr = ip->ip_dst; if (if_ifwithaddr((struct sockaddr *)&ipaddr) == 0) { -printf("forward: src %x dst %x ttl %x\n", ip->ip_src, ip->ip_dst, ip->ip_ttl); + if (ipprintfs) + printf("forward: src %x dst %x ttl %x\n", ip->ip_src, + ip->ip_dst, ip->ip_ttl); if (ipforwarding == 0) goto bad; if (ip->ip_ttl < IPTTLDEC) { diff --git a/usr/src/sys/netinet/ip_output.c b/usr/src/sys/netinet/ip_output.c index 5eb920b65c..26e041ae42 100644 --- a/usr/src/sys/netinet/ip_output.c +++ b/usr/src/sys/netinet/ip_output.c @@ -1,4 +1,4 @@ -/* ip_output.c 1.30 82/03/30 */ +/* ip_output.c 1.31 82/03/31 */ #include "../h/param.h" #include "../h/mbuf.h" @@ -49,15 +49,16 @@ COUNT(IP_OUTPUT); ro->ro_dst.sa_family = AF_INET; ((struct sockaddr_in *)&ro->ro_dst)->sin_addr = ip->ip_dst; rtalloc(ro); - if (ro != &iproute) - ro->ro_rt->rt_refcnt++; } if (ro->ro_rt == 0 || (ifp = ro->ro_rt->rt_ifp) == 0) { -printf("no route to %x\n", ip->ip_dst.s_addr); + printf("no route to %x (from %x, len %d)\n", + ip->ip_dst.s_addr, ip->ip_src.s_addr, ip->ip_len); goto bad; -} + } dst = ro->ro_rt->rt_flags&RTF_DIRECT ? (struct sockaddr *)&ro->ro_dst : &ro->ro_rt->rt_gateway; + if (ro == &iproute) + RTFREE(ro->ro_rt); if (!allowbroadcast && (ifp->if_flags & IFF_BROADCAST)) { struct sockaddr_in *sin; diff --git a/usr/src/sys/vax/if/if_en.c b/usr/src/sys/vax/if/if_en.c index e31a3d8a0d..ac72e24207 100644 --- a/usr/src/sys/vax/if/if_en.c +++ b/usr/src/sys/vax/if/if_en.c @@ -1,6 +1,7 @@ -/* if_en.c 4.46 82/03/30 */ +/* if_en.c 4.47 82/03/31 */ #include "en.h" +#include "imp.h" /* * Xerox prototype (3 Mb) Ethernet interface driver. @@ -101,7 +102,7 @@ COUNT(ENATTACH); es->es_if.if_unit = ui->ui_unit; es->es_if.if_name = "en"; es->es_if.if_mtu = ENMTU; - es->es_if.if_net = ui->ui_flags; + es->es_if.if_net = ui->ui_flags & 0xffff; es->es_if.if_host[0] = (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff; sin = (struct sockaddr_in *)&es->es_if.if_addr; @@ -116,6 +117,10 @@ COUNT(ENATTACH); es->es_if.if_ubareset = enreset; es->es_ifuba.ifu_flags = UBA_NEEDBDP | UBA_NEED16; if_attach(&es->es_if); +#if NIMP == 0 + /* here's one for you john baby.... */ + enlhinit(&es->es_if, (ui->ui_flags &~ 0xff) | 0x0a); +#endif } /* @@ -556,3 +561,51 @@ gottype: splx(s); return (1); } + +#if NIMP == 0 && NEN > 0 +/* + * Logical host interface driver. + * Allows host to appear as an ARPAnet + * logical host. Must also have routing + * table entry set up to forward packets + * to appropriate gateway on localnet. + */ + +struct ifnet enlhif; +int enlhoutput(); + +/* + * Called by localnet interface to allow logical + * host interface to "attach". Nothing should ever + * be sent locally to this interface, it's purpose + * is simply to establish the host's arpanet address. + */ +enlhinit(addr) + int addr; +{ + register struct ifnet *ifp = &enlhif; + register struct sockaddr_in *sin; + +COUNT(ENLHINIT); + ifp->if_name = "lh"; + ifp->if_mtu = ENMTU; + sin = (struct sockaddr_in *)&ifp->if_addr; + sin->sin_family = AF_INET; + sin->sin_addr.s_addr = addr; + ifp->if_net = sin->sin_addr.s_net; + ifp->if_flags = IFF_UP; + ifp->if_output = enlhoutput; /* should never be used */ + if_attach(ifp); +} + +enlhoutput(ifp, m0, dst) + struct ifnet *ifp; + struct mbuf *m0; + struct sockaddr *dst; +{ +COUNT(ENLHOUTPUT); + ifp->if_oerrors++; + m_freem(m0); + return (0); +} +#endif -- 2.20.1