satz@sri-tsc.UUCP (Greg Satz) (06/29/84)
Here are some fixes to the network code. I found a few bugs while bringing up the 4.2 version of rwho/rwhod. I modified the loop-back driver to look more like 4.2. *** /tmp/,RCSt1017261 Fri Jun 29 13:20:34 1984 --- in.h Wed Jun 27 23:48:00 1984 *************** *** 54,59 */ #define IPPORT_BIFFUDP 512 #define IPPORT_WHOSERVER 513 #define IPPORT_ROUTESERVER 520 #define IPPORT_SYSLOG 2222 --- 54,60 ----- */ #define IPPORT_BIFFUDP 512 #define IPPORT_WHOSERVER 513 + #define IPPORT_SYSLOG 514 #define IPPORT_ROUTESERVER 520 /* *************** *** 55,61 #define IPPORT_BIFFUDP 512 #define IPPORT_WHOSERVER 513 #define IPPORT_ROUTESERVER 520 - #define IPPORT_SYSLOG 2222 /* * Ports < IPPORT_RESERVED are reserved for --- 56,61 ----- #define IPPORT_WHOSERVER 513 #define IPPORT_SYSLOG 514 #define IPPORT_ROUTESERVER 520 /* * Ports < IPPORT_RESERVED are reserved for *************** *** 127,133 ((in).s_addr&IN_CLASSB) == 0 ? (in).s_addr&IN_CLASSB_LNA : \ (in).s_addr&IN_CLASSC_LNA) ! #define INADDR_ANY 0x00000000 /* * Socket address, internet style. --- 127,133 ----- ((in).s_addr&IN_CLASSB) == 0 ? (in).s_addr&IN_CLASSB_LNA : \ (in).s_addr&IN_CLASSC_LNA) ! #define INADDR_ANY 0x00000000L /* * Socket address, internet style. *** /tmp/,RCSt1017296 Fri Jun 29 13:23:25 1984 --- if.c Wed Jun 27 23:39:51 1984 *************** *** 207,215 register struct ifreq *ifr; struct ifreq uifr; /* user's ifreq structure */ - if (copyin(data, (caddr_t) &uifr, sizeof(uifr))) { - return(EFAULT); - } switch (cmd) { case SIOCGIFCONF: --- 207,212 ----- register struct ifreq *ifr; struct ifreq uifr; /* user's ifreq structure */ switch (cmd) { case SIOCGIFCONF: *************** *** 213,219 switch (cmd) { case SIOCGIFCONF: ! return (ifconf(cmd, (caddr_t)&uifr)); case SIOCSIFADDR: case SIOCSIFFLAGS: --- 210,216 ----- switch (cmd) { case SIOCGIFCONF: ! return (ifconf(cmd, data)); case SIOCSIFADDR: case SIOCSIFFLAGS: *************** *** 222,227 return (u.u_error); break; } ifr = (struct ifreq *)&uifr; ifp = ifunit(ifr->ifr_name); if (ifp == (struct ifnet *)0) --- 219,226 ----- return (u.u_error); break; } + if (copyin(data, (caddr_t) &uifr, sizeof(struct ifreq))) + return(EFAULT); ifr = (struct ifreq *)&uifr; ifp = ifunit(ifr->ifr_name); if (ifp == (struct ifnet *)0) *************** *** 256,262 return (EOPNOTSUPP); return ((*ifp->if_ioctl)(ifp, cmd, (caddr_t)&uifr)); } ! if (copyout((caddr_t)&uifr, data, sizeof(uifr))) { return(EFAULT); } return (0); --- 255,261 ----- return (EOPNOTSUPP); return ((*ifp->if_ioctl)(ifp, cmd, (caddr_t)&uifr)); } ! if (copyout((caddr_t)&uifr, data, sizeof(struct ifreq))) return(EFAULT); return (0); } *************** *** 258,264 } if (copyout((caddr_t)&uifr, data, sizeof(uifr))) { return(EFAULT); - } return (0); } --- 257,262 ----- } if (copyout((caddr_t)&uifr, data, sizeof(struct ifreq))) return(EFAULT); return (0); } *************** *** 273,279 int cmd; caddr_t data; { ! register struct ifconf *ifc = (struct ifconf *)data; register struct ifnet *ifp = ifnet; register char *cp, *ep; struct ifreq ifr, *ifrp; --- 271,277 ----- int cmd; caddr_t data; { ! register struct ifconf ifcnf, *ifc; register struct ifnet *ifp = ifnet; register char *cp, *ep; struct ifreq ifr, *ifrp; *************** *** 277,283 register struct ifnet *ifp = ifnet; register char *cp, *ep; struct ifreq ifr, *ifrp; ! int space = ifc->ifc_len, error = 0; ifrp = ifc->ifc_req; ep = ifr.ifr_name + sizeof (ifr.ifr_name) - 2; --- 275,281 ----- register struct ifnet *ifp = ifnet; register char *cp, *ep; struct ifreq ifr, *ifrp; ! int space, error = 0; if (copyin(data, (caddr_t) &ifcnf, sizeof(struct ifconf))) return(EFAULT); *************** *** 279,284 struct ifreq ifr, *ifrp; int space = ifc->ifc_len, error = 0; ifrp = ifc->ifc_req; ep = ifr.ifr_name + sizeof (ifr.ifr_name) - 2; for (; space > sizeof (ifr) && ifp; ifp = ifp->if_next) { --- 277,286 ----- struct ifreq ifr, *ifrp; int space, error = 0; + if (copyin(data, (caddr_t) &ifcnf, sizeof(struct ifconf))) + return(EFAULT); + ifc = &ifcnf; + space = ifc->ifc_len; ifrp = ifc->ifc_req; ep = ifr.ifr_name + sizeof (ifr.ifr_name) - 2; for (; space > sizeof (ifr) && ifp; ifp = ifp->if_next) { *************** *** 285,291 bcopy(ifp->if_name, ifr.ifr_name, sizeof (ifr.ifr_name) - 2); for (cp = ifr.ifr_name; cp < ep && *cp; cp++) ; ! *cp+= '0' + ifp->if_unit; *cp = '\0'; ifr.ifr_addr = ifp->if_addr; error = copyout((caddr_t)&ifr, (caddr_t)ifrp, sizeof (ifr)); if (error) --- 287,293 ----- bcopy(ifp->if_name, ifr.ifr_name, sizeof (ifr.ifr_name) - 2); for (cp = ifr.ifr_name; cp < ep && *cp; cp++) ; ! *cp++ = '0' + ifp->if_unit; *cp = '\0'; ifr.ifr_addr = ifp->if_addr; error = copyout((caddr_t)&ifr, (caddr_t)ifrp, sizeof (ifr)); if (error) *************** *** 293,297 space -= sizeof (ifr), ifrp++; } ifc->ifc_len -= space; return (error); } --- 295,301 ----- space -= sizeof (ifr), ifrp++; } ifc->ifc_len -= space; + if (copyout((caddr_t)&ifcnf, data, sizeof(struct ifconf))) + error = EFAULT; return (error); } *** /tmp/,RCSt1017287 Fri Jun 29 13:22:45 1984 --- if_loop.c Wed Jun 27 23:43:30 1984 *************** *** 8,13 #include <sys/systm.h> #include <sys/mbuf.h> #include <sys/socket.h> #include "../net/in.h" #include "../net/in_systm.h" #include "../net/if.h" --- 8,15 ----- #include <sys/systm.h> #include <sys/mbuf.h> #include <sys/socket.h> + #include <errno.h> + #include <sys/ioctl.h> #include "../net/in.h" #include "../net/in_systm.h" #include "../net/if.h" *************** *** 14,20 #include "../net/ip.h" #include "../net/ip_var.h" #include "../net/route.h" - #include <errno.h> #define LONET 0x7f000000 #define LOMTU (1024+512) --- 16,21 ----- #include "../net/ip.h" #include "../net/ip_var.h" #include "../net/route.h" #define LONET 0x7f000000 #define LOHOST 1 *************** *** 17,22 #include <errno.h> #define LONET 0x7f000000 #define LOMTU (1024+512) struct ifnet loif; --- 18,24 ----- #include "../net/route.h" #define LONET 0x7f000000 + #define LOHOST 1 #define LOMTU (1024+512) struct ifnet loif; *************** *** 20,26 #define LOMTU (1024+512) struct ifnet loif; ! int looutput(); loattach() { --- 22,28 ----- #define LOMTU (1024+512) struct ifnet loif; ! int looutput(), loioctl(); loattach() { *************** *** 30,35 ifp->if_name = "lo"; ifp->if_mtu = LOMTU; ifp->if_net = htonl((u_long)LONET); sin = (struct sockaddr_in *)&ifp->if_addr; sin->sin_family = AF_INET; sin->sin_addr = if_makeaddr(ifp->if_net, 0); --- 32,38 ----- ifp->if_name = "lo"; ifp->if_mtu = LOMTU; ifp->if_net = htonl((u_long)LONET); + ifp->if_host[0] = LOHOST; sin = (struct sockaddr_in *)&ifp->if_addr; sin->sin_family = AF_INET; sin->sin_addr = if_makeaddr(ifp->if_net, LOHOST); *************** *** 32,39 ifp->if_net = htonl((u_long)LONET); sin = (struct sockaddr_in *)&ifp->if_addr; sin->sin_family = AF_INET; ! sin->sin_addr = if_makeaddr(ifp->if_net, 0); ! ifp->if_flags = IFF_UP; ifp->if_output = looutput; if_attach(ifp); if_rtinit(ifp, RTF_UP); --- 35,43 ----- ifp->if_host[0] = LOHOST; sin = (struct sockaddr_in *)&ifp->if_addr; sin->sin_family = AF_INET; ! sin->sin_addr = if_makeaddr(ifp->if_net, LOHOST); ! ifp->if_flags = IFF_UP | IFF_RUNNING; ! ifp->if_ioctl = loioctl; ifp->if_output = looutput; if_attach(ifp); if_rtinit(ifp, RTF_UP); *************** *** 73,76 ifp->if_ipackets++; splx(s); return (0); } --- 77,111 ----- ifp->if_ipackets++; splx(s); return (0); + } + + /* + * Process an ioctl request. + */ + loioctl(ifp, cmd, data) + register struct ifnet *ifp; + int cmd; + caddr_t data; + { + struct ifreq *ifr = (struct ifreq *)data; + struct sockaddr_in *sin; + int s = splimp(), error = 0; + + switch (cmd) { + + case SIOCSIFADDR: + if (ifp->if_flags & IFF_RUNNING) + if_rtinit(ifp, -1); /* delete previous route */ + ifp->if_addr = ifr->ifr_addr; + sin = (struct sockaddr_in *)&ifp->if_addr; + ifp->if_net = in_netof(sin->sin_addr); + ifp->if_host[0] = in_lnaof(sin->sin_addr); + if_rtinit(ifp, RTF_UP); + break; + + default: + error = EINVAL; + } + splx(s); + return (error); }