Return to BSD News archive
Newsgroups: comp.bugs.2bsd Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!yarrina.connect.com.au!classic.iinet.com.au!swing.iinet.net.au!news.uoregon.edu!usenet.eel.ufl.edu!brutus.bright.net!chi-news.cic.net!news.wctc.net!spcuna!wlbr!sms From: sms@wlv.iipo.gtegsc.com (Steven M. Schultz) Subject: sysctl networking functions (#276) Sender: news@wlbr.iipo.gtegsc.com (Steven M. Schultz) Organization: GTE Government Systems, Thousand Oaks CA USA Message-ID: <DGu7p1.Fu6@wlbr.iipo.gtegsc.com> X-Nntp-Posting-Host: wlv.iipo.gtegsc.com Date: Sun, 22 Oct 1995 06:36:36 GMT Lines: 1541 Subject: sysctl networking functions (#276) Index: bin/sysctl,netinet/<several>,sys/kern_sysctl.c 2.11BSD Description: The network commands were omitted when the sysctl syscall was initially added to the system. Repeat-By: Do a "sysctl -a" and observe that the net.inet.ip.forwarding = 1 net.inet.ip.redirect = 1 net.inet.ip.ttl = 64 net.inet.ip.forwsrcrt = 1 net.inet.icmp.maskrepl = 0 net.inet.udp.checksum = 1 lines do not appear. Fix: The patch below adds the ability to turn on/off the following: forwarding of IP packets generating redirect responses forwarding of source routed packets responding to netmask requests also added is the ability to set the default TTL on IP packets. The network image (/netnix) is actually smaller after applying this update because the 'tcp_debug' module and its associated strings have been made #ifdef'd option with the default being to not include the tcp_debug logic. Since tcp_debug was of limited utility anyways due to the small number of debug buffers (only 2 ) omitting it is not a big loss. To apply this update cut where indicated and save to a file (/tmp/276) and then: patch -p0 < /tmp/276 cd /usr/src/bin/sysctl make make install make clean Next the kernel needs to be recompiled: cd /sys/YOURKERNELNAME make clean make mv /unix /ounix mv /netnix /onetnix mv unix netnix / chmod 744 /unix /netnix reboot ==================cut here=============== *** /usr/src/bin/sysctl/sysctl.c.old Fri Feb 3 23:10:32 1995 --- /usr/src/bin/sysctl/sysctl.c Wed Oct 11 19:58:59 1995 *************** *** 36,42 **** "@(#) Copyright (c) 1993\n\ The Regents of the University of California. All rights reserved.\n"; ! static char sccsid[] = "@(#)sysctl.c 8.1.2 (2.11BSD GTE) 2/3/95"; #endif /* not lint */ #include <sys/param.h> --- 36,42 ---- "@(#) Copyright (c) 1993\n\ The Regents of the University of California. All rights reserved.\n"; ! static char sccsid[] = "@(#)sysctl.c 8.1.3 (2.11BSD GTE) 1995/10/11"; #endif /* not lint */ #include <sys/param.h> *************** *** 283,289 **** return; case CTL_NET: - #ifdef notyet if (mib[1] == PF_INET) { len = sysctl_inet(string, &bufp, mib, flags, &type); if (len >= 0) --- 283,288 ---- *************** *** 290,296 **** break; return; } - #endif if (flags == 0) return; fprintf(stderr, "Use netstat to view %s information\n", string); --- 289,294 ---- *************** *** 462,469 **** } } - #ifdef notyet - struct ctlname inetname[] = CTL_IPPROTO_NAMES; struct ctlname ipname[] = IPCTL_NAMES; struct ctlname icmpname[] = ICMPCTL_NAMES; --- 460,465 ---- *************** *** 529,535 **** *typep = lp->list[indx].ctl_type; return (4); } - #endif /* notyet */ /* * Scan a list of names searching for a particular name. --- 525,530 ---- *** /usr/src/sys/h/protosw.h.old Sun Feb 20 14:33:53 1994 --- /usr/src/sys/h/protosw.h Mon Oct 9 21:57:47 1995 *************** *** 9,15 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)protosw.h 7.2.1 (2.11BSD GTE) 2/20/94 */ /* --- 9,15 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)protosw.h 7.2.2 (2.11BSD GTE) 1995/10/09 */ /* *************** *** 51,56 **** --- 51,57 ---- int (*pr_fasttimo)(); /* fast timeout (200ms) */ int (*pr_slowtimo)(); /* slow timeout (500ms) */ int (*pr_drain)(); /* flush any excess space possible */ + int (*pr_sysctl)(); /* sysctl for protocol */ }; #define PR_SLOWHZ 2 /* 2 slow timeouts per second */ *** /usr/src/sys/h/socket.h.old Fri Dec 31 21:56:16 1993 --- /usr/src/sys/h/socket.h Wed Oct 11 20:13:16 1995 *************** *** 9,17 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)socket.h 7.2.1 (2.11BSD GTE) 12/31/93 */ /* * Definitions related to sockets: types, address families, options. */ --- 9,20 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)socket.h 7.2.2 (2.11BSD GTE) 1995/10/11 */ + #ifndef _SYS_SOCKET_H_ + #define _SYS_SOCKET_H_ + /* * Definitions related to sockets: types, address families, options. */ *************** *** 128,133 **** --- 131,168 ---- #define PF_MAX AF_MAX /* + * Definitions for network related sysctl, CTL_NET. + * + * Second level is protocol family. + * Third level is protocol number. + * + * Further levels are defined by the individual families below. + */ + #define NET_MAXID AF_MAX + + #ifndef KERNEL + #define CTL_NET_NAMES { \ + { 0, 0 }, \ + { "unix", CTLTYPE_NODE }, \ + { "inet", CTLTYPE_NODE }, \ + { "implink", CTLTYPE_NODE }, \ + { "pup", CTLTYPE_NODE }, \ + { "chaos", CTLTYPE_NODE }, \ + { "xerox_ns", CTLTYPE_NODE }, \ + { "iso", CTLTYPE_NODE }, \ + { "emca", CTLTYPE_NODE }, \ + { "datakit", CTLTYPE_NODE }, \ + { "ccitt", CTLTYPE_NODE }, \ + { "ibm_sna", CTLTYPE_NODE }, \ + { "decnet", CTLTYPE_NODE }, \ + { "dec_dli", CTLTYPE_NODE }, \ + { "lat", CTLTYPE_NODE }, \ + { "hylink", CTLTYPE_NODE }, \ + { "appletalk", CTLTYPE_NODE }, \ + } + #endif + + /* * Maximum queue length specifiable by listen. */ #define SOMAXCONN 5 *************** *** 149,151 **** --- 184,187 ---- #define MSG_DONTROUTE 0x4 /* send without using routing tables */ #define MSG_MAXIOVLEN 16 + #endif /* _SYS_SOCKET_H_ */ *** /usr/src/sys/netinet/icmp_var.h.old Mon Jan 10 21:34:24 1994 --- /usr/src/sys/netinet/icmp_var.h Mon Oct 9 22:20:51 1995 *************** *** 9,15 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)icmp_var.h 7.3.1 (2.11BSD GTE) 12/31/93 */ /* --- 9,15 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)icmp_var.h 7.3.2 (2.11BSD GTE) 1995/10/09 */ /* *************** *** 31,36 **** --- 31,49 ---- long icps_reflect; /* number of responses */ long icps_inhist[ICMP_MAXTYPE + 1]; }; + + /* + * Names for ICMP sysctl objects + */ + #define ICMPCTL_MASKREPL 1 /* allow replies to netmask requests */ + #define ICMPCTL_MAXID 2 + + #ifndef KERNEL + #define ICMPCTL_NAMES { \ + { 0, 0 }, \ + { "maskrepl", CTLTYPE_INT }, \ + } + #endif #ifdef SUPERVISOR struct icmpstat icmpstat; *** /usr/src/sys/netinet/in.c.old Sat Apr 30 18:01:15 1988 --- /usr/src/sys/netinet/in.c Tue Oct 10 23:03:39 1995 *************** *** 9,15 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)in.c 7.7 (Berkeley) 4/3/88 */ #include "param.h" --- 9,15 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)in.c 7.7.1 (2.11BSD) 1995/10/10 */ #include "param.h" *************** *** 187,193 **** return (1); } - int in_interfaces; /* number of external internet interfaces */ extern struct ifnet loif; /* --- 187,192 ---- *************** *** 244,251 **** ifp->if_addrlist = (struct ifaddr *) ia; ia->ia_ifp = ifp; IA_SIN(ia)->sin_family = AF_INET; - if (ifp != &loif) - in_interfaces++; } break; --- 243,248 ---- *** /usr/src/sys/netinet/in.h.old Sun Feb 20 18:15:04 1994 --- /usr/src/sys/netinet/in.h Mon Oct 9 22:16:12 1995 *************** *** 9,15 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)in.h 7.5.2 (2.11BSD GTE) 2/20/94 */ /* --- 9,15 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)in.h 7.5.3 (2.11BSD GTE) 1995/10/09 */ /* *************** *** 106,111 **** --- 106,170 ---- * Options for use with [gs]etsockopt at the IP level. */ #define IP_OPTIONS 1 /* set/get IP per-packet options */ + + /* + * Definitions for inet sysctl operations. + * + * Third level is protocol number. + * Fourth level is desired variable within that protocol. + */ + #define IPPROTO_MAXID (IPPROTO_IDP + 1) /* don't list to IPPROTO_MAX */ + + #ifndef KERNEL + #define CTL_IPPROTO_NAMES { \ + { "ip", CTLTYPE_NODE }, \ + { "icmp", CTLTYPE_NODE }, \ + { "igmp", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "tcp", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "udp", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "idp", CTLTYPE_NODE }, \ + } + #endif /* KERNEL */ + + /* + * Names for IP sysctl objects + */ + #define IPCTL_FORWARDING 1 /* act as router */ + #define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */ + #define IPCTL_DEFTTL 3 /* default TTL */ + #ifdef notyet + #define IPCTL_DEFMTU 4 /* default MTU */ + #endif + #define IPCTL_FORWSRCRT 5 /* forward source-routed dgrams */ + #define IPCTL_MAXID 6 + + #ifndef KERNEL + #define IPCTL_NAMES { \ + { 0, 0 }, \ + { "forwarding", CTLTYPE_INT }, \ + { "redirect", CTLTYPE_INT }, \ + { "ttl", CTLTYPE_INT }, \ + { "mtu", CTLTYPE_INT }, \ + { "forwsrcrt", CTLTYPE_INT }, \ + } + #endif /* KERNEL */ /* * Macros for number representation conversion. *** /usr/src/sys/netinet/in_proto.c.old Wed Apr 27 10:32:09 1988 --- /usr/src/sys/netinet/in_proto.c Mon Oct 9 23:08:00 1995 *************** *** 9,15 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)in_proto.c 7.2 (Berkeley) 12/7/87 */ #include "param.h" --- 9,15 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)in_proto.c 7.2.1 (2.11BSD) 1995/10/09 */ #include "param.h" *************** *** 20,33 **** #include "in.h" #include "in_systm.h" /* * TCP/IP protocol family: IP, ICMP, UDP, TCP. */ int ip_output(),ip_ctloutput(); ! int ip_init(),ip_slowtimo(),ip_drain(); ! int icmp_input(); ! int udp_input(),udp_ctlinput(); int udp_usrreq(); int udp_init(); int tcp_input(),tcp_ctlinput(); --- 20,34 ---- #include "in.h" #include "in_systm.h" + #include "ip.h" /* * TCP/IP protocol family: IP, ICMP, UDP, TCP. */ int ip_output(),ip_ctloutput(); ! int ip_init(),ip_slowtimo(),ip_drain(), ip_sysctl(); ! int icmp_input(), icmp_sysctl(); ! int udp_input(),udp_ctlinput(), udp_sysctl(); int udp_usrreq(); int udp_init(); int tcp_input(),tcp_ctlinput(); *************** *** 55,66 **** { 0, &inetdomain, 0, 0, 0, ip_output, 0, 0, 0, ! ip_init, 0, ip_slowtimo, ip_drain, }, { SOCK_DGRAM, &inetdomain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR, udp_input, 0, udp_ctlinput, ip_ctloutput, udp_usrreq, ! udp_init, 0, 0, 0, }, { SOCK_STREAM, &inetdomain, IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD, tcp_input, 0, tcp_ctlinput, tcp_ctloutput, --- 56,67 ---- { 0, &inetdomain, 0, 0, 0, ip_output, 0, 0, 0, ! ip_init, 0, ip_slowtimo, ip_drain, ip_sysctl }, { SOCK_DGRAM, &inetdomain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR, udp_input, 0, udp_ctlinput, ip_ctloutput, udp_usrreq, ! udp_init, 0, 0, 0, udp_sysctl }, { SOCK_STREAM, &inetdomain, IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD, tcp_input, 0, tcp_ctlinput, tcp_ctloutput, *************** *** 75,81 **** { SOCK_RAW, &inetdomain, IPPROTO_ICMP, PR_ATOMIC|PR_ADDR, icmp_input, rip_output, 0, rip_ctloutput, raw_usrreq, ! 0, 0, 0, 0, }, #ifdef NSIP { SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR, --- 76,82 ---- { SOCK_RAW, &inetdomain, IPPROTO_ICMP, PR_ATOMIC|PR_ADDR, icmp_input, rip_output, 0, rip_ctloutput, raw_usrreq, ! 0, 0, 0, 0, icmp_sysctl }, #ifdef NSIP { SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR, *************** *** 130,133 **** --- 131,161 ---- struct domain hydomain = { AF_HYLINK, "hy", 0, 0, 0, hysw, &hysw[sizeof (hysw)/sizeof(hysw[0])] }; + #endif + + #ifndef IPFORWARDING + #define IPFORWARDING 1 + #endif + + #ifndef IPSENDREDIRECTS + #define IPSENDREDIRECTS 1 + #endif + + #ifndef IPFORWARDSRCRT + #if !defined(IPFORWARDING) + #define IPFORWARDSRCRT 0 + #else + #define IPFORWARDSRCRT 1 + #endif + #endif + + int ipforwarding = IPFORWARDING; + int ipsendredirects = IPSENDREDIRECTS; + int ipforward_srcrt = IPFORWARDSRCRT; + int ip_defttl = IPDEFTTL; + + #ifdef GATEWAY + int icmpmaskrepl = 1; + #else + int icmpmaskrepl = 0; #endif *** /usr/src/sys/netinet/ip.h.old Thu Apr 28 15:21:04 1988 --- /usr/src/sys/netinet/ip.h Mon Oct 9 22:51:26 1995 *************** *** 9,15 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)ip.h 7.6.1.1 (Berkeley) 3/15/88 */ #ifndef BYTE_ORDER /* --- 9,15 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)ip.h 7.6.1.2 (2.11BSD) 1995/10/09 */ #ifndef BYTE_ORDER /* *************** *** 147,152 **** --- 147,153 ---- * Internet implementation parameters. */ #define MAXTTL 255 /* maximum time to live (seconds) */ + #define IPDEFTTL 64 /* default ttl, from RFC 1340 */ #define IPFRAGTTL 60 /* time to live for frags, slowhz */ #define IPTTLDEC 1 /* subtracted when forwarding */ *** /usr/src/sys/netinet/ip_icmp.c.old Sun Feb 20 13:54:20 1994 --- /usr/src/sys/netinet/ip_icmp.c Tue Oct 10 22:45:29 1995 *************** *** 9,15 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)ip_icmp.c 7.7.1 (2.11BSD GTE) 2/20/94 */ #include "param.h" --- 9,15 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)ip_icmp.c 7.7.2 (2.11BSD GTE) 1995/10/10 */ #include "param.h" *************** *** 19,24 **** --- 19,25 ---- #include "socket.h" #include "time.h" #include "kernel.h" + #include "errno.h" #include "../net/route.h" #include "../net/if.h" *************** *** 31,36 **** --- 32,38 ---- #include "ip_icmp.h" #include "icmp_var.h" + extern int icmpmaskrepl; #ifdef ICMPPRINTFS /* * ICMP routines: error generation, receive packet processing, and *************** *** 256,263 **** --- 258,278 ---- goto reflect; case ICMP_MASKREQ: + if (icmpmaskrepl == 0) + break; + /* + * We are not able to respond with all ones broadcast + * unless we receive it over a point-to-point interface. + * This check is a 'switch' in 4.4BSD but 2.11's C compiler + * does not allow "long"s in a switch statement. + */ if (icmplen < ICMP_MASKLEN || (ia = ifptoia(ifp)) == 0) break; + if ((ip->ip_dst.s_addr == INADDR_BROADCAST || + ip->ip_dst.s_addr == INADDR_ANY)) + icmpdst.sin_addr = ip->ip_src; + else + icmpdst.sin_addr = ip->ip_dst; icp->icmp_type = ICMP_MASKREPLY; icp->icmp_mask = htonl(ia->ia_subnetmask); if (ip->ip_src.s_addr == 0) { *************** *** 437,440 **** --- 452,478 ---- + (long)mfkd(&lbolt) * 1000L / (long)hz; splx(s); return (htonl(t)); + } + + int + icmp_sysctl(name, namelen, oldp, oldlenp, newp, newlen) + int *name; + u_int namelen; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; + { + + /* All sysctl names at this level are terminal. */ + if (namelen != 1) + return (ENOTDIR); + + switch (name[0]) { + case ICMPCTL_MASKREPL: + return (sysctl_int(oldp, oldlenp, newp, newlen, &icmpmaskrepl)); + default: + return (ENOPROTOOPT); + } + /* NOTREACHED */ } *** /usr/src/sys/netinet/ip_input.c.old Mon Jan 10 21:34:09 1994 --- /usr/src/sys/netinet/ip_input.c Wed Oct 11 19:51:53 1995 *************** *** 9,15 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)ip_input.c 7.9.1 (2.11BSD GTE) 12/31/93 */ #include "param.h" --- 9,15 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)ip_input.c 7.9.2 (2.11BSD GTE) 1995/10/09 */ #include "param.h" *************** *** 34,41 **** --- 34,43 ---- #include "ip_icmp.h" #include "tcp.h" + extern int ipforwarding, ipsendredirects, ipforward_srcrt, ip_defttl; u_char ip_protox[IPPROTO_MAX]; int ipqmaxlen = IFQ_MAXLEN; + int ipprintfs = 0; struct in_ifaddr *in_ifaddr; /* first inet address */ /* *************** *** 228,234 **** /* * Not for us; forward if possible and desirable. */ ! ip_forward(ip, ifp); goto next; ours: --- 230,240 ---- /* * Not for us; forward if possible and desirable. */ ! if (ipforwarding == 0) { ! ipstat.ips_cantforward++; ! m_freem(m); ! } else ! ip_forward(ip, ifp, 0); goto next; ours: *************** *** 520,526 **** struct ifnet *ifp; { register u_char *cp; ! int opt, optlen, cnt, off, code, type = ICMP_PARAMPROB; register struct ip_timestamp *ipt; register struct in_ifaddr *ia; struct in_addr *sin; --- 526,532 ---- struct ifnet *ifp; { register u_char *cp; ! int opt, optlen, cnt, off, code, type = ICMP_PARAMPROB, forward = 0; register struct ip_timestamp *ipt; register struct in_ifaddr *ia; struct in_addr *sin; *************** *** 600,605 **** --- 606,616 ---- bcopy((caddr_t)&(IA_SIN(ia)->sin_addr), (caddr_t)(cp + off), sizeof(struct in_addr)); cp[IPOPT_OFFSET] += sizeof(struct in_addr); + /* + * Since 2.11 will never have multicasting so the following line from 4.4 + * is effectively always 1. + */ + forward = !IN_MULTICAST(ip->ip_dst.s_addr); break; case IPOPT_RR: *************** *** 674,681 **** --- 685,702 ---- ipt->ipt_ptr += sizeof(n_time); } } + if (forward) { + if (ipforward_srcrt == 0) { + type = ICMP_UNREACH; + code = ICMP_UNREACH_SRCFAIL; + goto bad; + } + ip_forward(ip, ifp, 1); + return(1); + } return (0); bad: + ip->ip_len -= ip->ip_hl << 2; /* XXX icmp_error adds in hdr length */ icmp_error(ip, type, code, ifp); return (1); } *************** *** 723,729 **** struct in_addr dst; { unsigned olen; - extern ipprintfs; olen = option[IPOPT_OLEN]; if (olen > sizeof(ip_srcrt) - 1) { --- 744,749 ---- *************** *** 815,830 **** ENOPROTOOPT }; - #ifndef IPFORWARDING - #define IPFORWARDING 1 - #endif - #ifndef IPSENDREDIRECTS - #define IPSENDREDIRECTS 1 - #endif - int ipprintfs = 0; - int ipforwarding = IPFORWARDING; extern int in_interfaces; - int ipsendredirects = IPSENDREDIRECTS; /* * Forward a packet. If some error occurs return the sender --- 835,841 ---- *************** *** 836,845 **** * network), just drop the packet. This could be confusing if ipforwarding * was zero but some routing protocol was advancing us as a gateway * to somewhere. However, we must let the routing protocol deal with that. */ ! ip_forward(ip, ifp) register struct ip *ip; struct ifnet *ifp; { register int error, type = 0, code; register struct sockaddr_in *sin; --- 847,860 ---- * network), just drop the packet. This could be confusing if ipforwarding * was zero but some routing protocol was advancing us as a gateway * to somewhere. However, we must let the routing protocol deal with that. + * + * The srcrt parameter indicates whether the packet is being forwarded + * via a source route. */ ! ip_forward(ip, ifp, srcrt) register struct ip *ip; struct ifnet *ifp; + int srcrt; { register int error, type = 0, code; register struct sockaddr_in *sin; *************** *** 851,882 **** printf("forward: src %X dst %X ttl %x\n", ntohl(ip->ip_src), ntohl(ip->ip_dst), ip->ip_ttl); ip->ip_id = htons(ip->ip_id); ! if (ipforwarding == 0 || in_interfaces <= 1) { ipstat.ips_cantforward++; - #ifdef GATEWAY - type = ICMP_UNREACH, code = ICMP_UNREACH_NET; - goto sendicmp; - #else m_freem(dtom(ip)); return; - #endif } ! if (in_canforward(ip->ip_dst) == 0) { ! m_freem(dtom(ip)); ! return; ! } ! if (UCHAR(ip->ip_ttl) < IPTTLDEC) { type = ICMP_TIMXCEED, code = ICMP_TIMXCEED_INTRANS; goto sendicmp; } ip->ip_ttl -= IPTTLDEC; - /* - * Save at most 64 bytes of the packet in case - * we need to generate an ICMP message to the src. - */ - mcopy = m_copy(dtom(ip), 0, MIN((int)ip->ip_len, 64)); - sin = (struct sockaddr_in *)&ipforward_rt.ro_dst; if (ipforward_rt.ro_rt == 0 || ip->ip_dst.s_addr != sin->sin_addr.s_addr) { --- 866,882 ---- printf("forward: src %X dst %X ttl %x\n", ntohl(ip->ip_src), ntohl(ip->ip_dst), ip->ip_ttl); ip->ip_id = htons(ip->ip_id); ! if (in_canforward(ip->ip_dst) == 0) { ipstat.ips_cantforward++; m_freem(dtom(ip)); return; } ! if (ip->ip_ttl < IPTTLDEC) { type = ICMP_TIMXCEED, code = ICMP_TIMXCEED_INTRANS; goto sendicmp; } ip->ip_ttl -= IPTTLDEC; sin = (struct sockaddr_in *)&ipforward_rt.ro_dst; if (ipforward_rt.ro_rt == 0 || ip->ip_dst.s_addr != sin->sin_addr.s_addr) { *************** *** 888,895 **** --- 888,907 ---- sin->sin_addr = ip->ip_dst; rtalloc(&ipforward_rt); + if (ipforward_rt.ro_rt == 0) { + ip->ip_len -= ip->ip_hl << 2; /* icmp_error assumes this */ + icmp_error(ip,ICMP_UNREACH,ICMP_UNREACH_HOST,ifp,dest); + return; + } } + /* + * Save at most 64 bytes of the packet in case + * we need to generate an ICMP message to the src. + */ + mcopy = m_copy(dtom(ip), 0, MIN((int)ip->ip_len, 64)); + + /* * If forwarding packet using same interface that it came in on, * perhaps should send a redirect to sender to shortcut a hop. * Only send redirect if source is sending directly to us, *************** *** 901,907 **** if (ipforward_rt.ro_rt && ipforward_rt.ro_rt->rt_ifp == ifp && (ipforward_rt.ro_rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0 && satosin(&ipforward_rt.ro_rt->rt_dst)->sin_addr.s_addr != 0 && ! ipsendredirects && ip->ip_hl == (sizeof(struct ip) >> 2)) { struct in_ifaddr *ia; u_long src = ntohl(ip->ip_src.s_addr); u_long dst = ntohl(ip->ip_dst.s_addr); --- 913,919 ---- if (ipforward_rt.ro_rt && ipforward_rt.ro_rt->rt_ifp == ifp && (ipforward_rt.ro_rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0 && satosin(&ipforward_rt.ro_rt->rt_dst)->sin_addr.s_addr != 0 && ! ipsendredirects && !srcrt && ip->ip_hl == (sizeof(struct ip) >> 2)){ struct in_ifaddr *ia; u_long src = ntohl(ip->ip_src.s_addr); u_long dst = ntohl(ip->ip_dst.s_addr); *************** *** 983,987 **** --- 995,1034 ---- break; } sendicmp: + ip->ip_len -= ip->ip_hl << 2; /* icmp_error assumes this */ icmp_error(ip, type, code, ifp, dest); + } + + int + ip_sysctl(name, namelen, oldp, oldlenp, newp, newlen) + int *name; + u_int namelen; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; + { + /* All sysctl names at this level are terminal. */ + if (namelen != 1) + return (ENOTDIR); + + switch (name[0]) { + case IPCTL_FORWARDING: + return (sysctl_int(oldp, oldlenp, newp, newlen, &ipforwarding)); + case IPCTL_SENDREDIRECTS: + return (sysctl_int(oldp, oldlenp, newp, newlen, + &ipsendredirects)); + case IPCTL_DEFTTL: + return (sysctl_int(oldp, oldlenp, newp, newlen, &ip_defttl)); + #ifdef notyet + case IPCTL_DEFMTU: + return (sysctl_int(oldp, oldlenp, newp, newlen, &ip_mtu)); + #endif + case IPCTL_FORWSRCRT: + return (sysctl_int(oldp, oldlenp, newp, newlen, + &ipforward_srcrt)); + default: + return (EOPNOTSUPP); + } + /* NOTREACHED */ } *** /usr/src/sys/netinet/ip_var.h.old Mon Jan 10 21:33:49 1994 --- /usr/src/sys/netinet/ip_var.h Tue Oct 10 22:30:33 1995 *************** *** 115,120 **** --- 115,121 ---- struct ipstat ipstat; struct ipq ipq; /* ip reass. queue */ u_short ip_id; /* ip packet ctr, for ids */ + int ip_defttl; /* default IP ttl */ struct mbuf *ip_srcroute(); #endif *** /usr/src/sys/netinet/tcp_debug.c.old Thu Apr 28 16:13:05 1988 --- /usr/src/sys/netinet/tcp_debug.c Wed Oct 11 19:47:26 1995 *************** *** 9,23 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)tcp_debug.c 7.2 (Berkeley) 12/7/87 */ #include "param.h" #include "systm.h" #include "mbuf.h" #include "socket.h" #include "socketvar.h" - #define PRUREQUESTS #include "protosw.h" #include "errno.h" --- 9,29 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)tcp_debug.c 7.2.1 (2.11BSD) 1995/10/11 */ + #ifdef TCPDEBUG + #define TCPTIMERS + #define TANAMES + #define PRUREQUESTS + #define TCPSTATES + #endif + #include "param.h" #include "systm.h" #include "mbuf.h" #include "socket.h" #include "socketvar.h" #include "protosw.h" #include "errno.h" *************** *** 31,47 **** #include "ip.h" #include "ip_var.h" #include "tcp.h" - #define TCPSTATES #include "tcp_fsm.h" #include "tcp_seq.h" - #define TCPTIMERS #include "tcp_timer.h" #include "tcp_var.h" #include "tcpip.h" - #define TANAMES #include "tcp_debug.h" int tcpconsdebug = 0; /* * Tcp debug routines */ --- 37,53 ---- #include "ip.h" #include "ip_var.h" #include "tcp.h" #include "tcp_fsm.h" #include "tcp_seq.h" #include "tcp_timer.h" #include "tcp_var.h" #include "tcpip.h" #include "tcp_debug.h" + #ifdef TCPDEBUG int tcpconsdebug = 0; + #endif + /* * Tcp debug routines */ *************** *** 70,75 **** --- 76,82 ---- else bzero((caddr_t)&td->td_ti, sizeof (*ti)); td->td_req = req; + #ifdef TCPDEBUG if (tcpconsdebug == 0) return; if (tp) *************** *** 127,130 **** --- 134,138 ---- tp->snd_max); printf("\tsnd_(wl1,wl2,wnd) (%X,%X,%x)\n", tp->snd_wl1, tp->snd_wl2, tp->snd_wnd); + #endif /* TCPDEBUG */ } *** /usr/src/sys/netinet/tcp_output.c.old Thu Apr 28 16:19:52 1988 --- /usr/src/sys/netinet/tcp_output.c Tue Oct 10 22:39:54 1995 *************** *** 9,15 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)tcp_output.c 7.13.1.3 (Berkeley) 3/24/88 */ #include "param.h" --- 9,15 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)tcp_output.c 7.13.1.4 (Berkeley) 1995/10/10 */ #include "param.h" *************** *** 389,395 **** * send to IP level. */ ((struct ip *)ti)->ip_len = sizeof (struct tcpiphdr) + optlen + len; ! ((struct ip *)ti)->ip_ttl = TCP_TTL; #if BSD>=43 error = ip_output(m, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route, so->so_options & SO_DONTROUTE); --- 389,395 ---- * send to IP level. */ ((struct ip *)ti)->ip_len = sizeof (struct tcpiphdr) + optlen + len; ! ((struct ip *)ti)->ip_ttl = ip_defttl; /* XXX */ #if BSD>=43 error = ip_output(m, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route, so->so_options & SO_DONTROUTE); *** /usr/src/sys/netinet/tcp_subr.c.old Sun Feb 20 14:03:43 1994 --- /usr/src/sys/netinet/tcp_subr.c Tue Oct 10 22:42:21 1995 *************** *** 9,15 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)tcp_subr.c 7.13.2 (2.11BSD GTE) 2/20/94 */ #include "param.h" --- 9,15 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)tcp_subr.c 7.13.3 (2.11BSD GTE) 1995/10/10 */ #include "param.h" *************** *** 37,44 **** #include "tcp_var.h" #include "tcpip.h" - int tcp_ttl = TCP_TTL; - /* * Tcp initialization */ --- 37,42 ---- *************** *** 156,162 **** ti->ti_urp = 0; ti->ti_sum = in_cksum(m, sizeof (struct tcpiphdr) + tlen); ((struct ip *)ti)->ip_len = sizeof (struct tcpiphdr) + tlen; ! ((struct ip *)ti)->ip_ttl = tcp_ttl; (void) ip_output(m, (struct mbuf *)0, ro, 0); } --- 154,160 ---- ti->ti_urp = 0; ti->ti_sum = in_cksum(m, sizeof (struct tcpiphdr) + tlen); ((struct ip *)ti)->ip_len = sizeof (struct tcpiphdr) + tlen; ! ((struct ip *)ti)->ip_ttl = ip_defttl; (void) ip_output(m, (struct mbuf *)0, ro, 0); } *** /usr/src/sys/netinet/tcp_timer.h.old Thu Apr 28 09:04:14 1988 --- /usr/src/sys/netinet/tcp_timer.h Wed Oct 11 19:45:24 1995 *************** *** 9,15 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)tcp_timer.h 7.5 (Berkeley) 3/16/88 */ /* --- 9,15 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)tcp_timer.h 7.5.1 (2.11BSD) 1995/10/10 */ /* *************** *** 59,65 **** * amount of time probing, then we drop the connection. */ - #define TCP_TTL 30 /* default time to live for TCP segs */ /* * Time constants. */ --- 59,64 ---- *************** *** 105,110 **** extern int tcp_keepidle; /* time before keepalive probes begin */ extern int tcp_keepintvl; /* time between keepalive probes */ extern int tcp_maxidle; /* time to drop after starting probes */ - extern int tcp_ttl; /* time to live for TCP segs */ extern int tcp_backoff[]; #endif --- 104,108 ---- *** /usr/src/sys/netinet/udp_usrreq.c.old Sun Feb 20 16:02:28 1994 --- /usr/src/sys/netinet/udp_usrreq.c Tue Oct 10 22:33:40 1995 *************** *** 9,15 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)udp_usrreq.c 7.5.1 (2.11BSD GTE) 2/20/94 */ #include "param.h" --- 9,15 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)udp_usrreq.c 7.5.2 (2.11BSD GTE) 1995/10/09 */ #include "param.h" *************** *** 50,56 **** #else int udpcksum = 0; /* XXX */ #endif - int udp_ttl = UDP_TTL; struct sockaddr_in udp_in = { AF_INET }; --- 50,55 ---- *************** *** 260,266 **** ui->ui_sum = 0xffff; } ((struct ip *)ui)->ip_len = sizeof (struct udpiphdr) + len; ! ((struct ip *)ui)->ip_ttl = udp_ttl; udpstat.udps_opackets++; error = ip_output(m, inp->inp_options, &inp->inp_route, inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST)); --- 259,265 ---- ui->ui_sum = 0xffff; } ((struct ip *)ui)->ip_len = sizeof (struct udpiphdr) + len; ! ((struct ip *)ui)->ip_ttl = ip_defttl; udpstat.udps_opackets++; error = ip_output(m, inp->inp_options, &inp->inp_route, inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST)); *************** *** 420,423 **** --- 419,446 ---- udp_last_inpcb = &udb; in_pcbdetach(inp); splx(s); + } + + /* + * Sysctl for udp variables. + */ + udp_sysctl(name, namelen, oldp, oldlenp, newp, newlen) + int *name; + u_int namelen; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; + { + /* All sysctl names at this level are terminal. */ + if (namelen != 1) + return (ENOTDIR); + + switch (name[0]) { + case UDPCTL_CHECKSUM: + return (sysctl_int(oldp, oldlenp, newp, newlen, &udpcksum)); + default: + return (ENOPROTOOPT); + } + /* NOTREACHED */ } *** /usr/src/sys/netinet/udp_var.h.old Sun Feb 20 15:51:58 1994 --- /usr/src/sys/netinet/udp_var.h Tue Oct 10 22:32:40 1995 *************** *** 9,15 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)udp_var.h 7.3.1 (2.11BSD GTE) 2/20/94 */ /* --- 9,15 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)udp_var.h 7.3.2 (2.11BSD GTE) 1995/10/09 */ /* *************** *** 46,52 **** long udps_opackets; /* total output packets */ }; ! #define UDP_TTL 30 /* deflt time to live for UDP packets */ #ifdef SUPERVISOR struct inpcb udb; --- 46,63 ---- long udps_opackets; /* total output packets */ }; ! /* ! * Names for UDP sysctl objects ! */ ! #define UDPCTL_CHECKSUM 1 /* checksum UDP packets */ ! #define UDPCTL_MAXID 2 ! ! #ifndef KERNEL ! #define UDPCTL_NAMES { \ ! { 0, 0 }, \ ! { "checksum", CTLTYPE_INT }, \ ! } ! #endif #ifdef SUPERVISOR struct inpcb udb; *** /usr/src/sys/sys/kern_sysctl.c.old Mon Mar 6 20:56:41 1995 --- /usr/src/sys/sys/kern_sysctl.c Mon Oct 9 21:44:28 1995 *************** *** 33,39 **** * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ! * @(#)kern_sysctl.c 8.4.2 (2.11BSD GTE) 3/06/95 */ /* --- 33,39 ---- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ! * @(#)kern_sysctl.c 8.4.2 (2.11BSD GTE) 1995/10/09 */ /* *************** *** 64,70 **** #endif sysctlfn vm_sysctl; sysctlfn fs_sysctl; ! sysctlfn net_sysctl; sysctlfn cpu_sysctl; /* --- 64,71 ---- #endif sysctlfn vm_sysctl; sysctlfn fs_sysctl; ! sysctlfn NET_SYSCTL; ! extern int net_sysctl(); /* In supervisor space */ sysctlfn cpu_sysctl; /* *************** *** 115,121 **** fn = vm_sysctl; break; case CTL_NET: ! fn = net_sysctl; break; #ifdef notyet case CTL_FS: --- 116,122 ---- fn = vm_sysctl; break; case CTL_NET: ! fn = NET_SYSCTL; break; #ifdef notyet case CTL_FS: *************** *** 375,381 **** */ int ! net_sysctl(name, namelen, oldp, oldlenp, newp, newlen) int *name; u_int namelen; void *oldp; --- 376,382 ---- */ int ! NET_SYSCTL(name, namelen, oldp, oldlenp, newp, newlen) int *name; u_int namelen; void *oldp; *************** *** 383,389 **** void *newp; size_t newlen; { ! return(EOPNOTSUPP); /* Not yet. */ } /* --- 384,391 ---- void *newp; size_t newlen; { ! return(KScall(net_sysctl, 6 * sizeof (int), ! name, namelen, oldp, oldlenp, newp, newlen)); } /* *** /usr/src/sys/sys/sys_net.c.old Thu Dec 15 20:03:22 1994 --- /usr/src/sys/sys/sys_net.c Mon Oct 9 23:03:39 1995 *************** *** 3,9 **** * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * ! * @(#)sys_net.c 1.3 (2.11BSD GTE) 12/15/94 * * Change uiomove calling convention. The r/w type is now encapsulated * in the uio structure now. sms - 11/26/94 --- 3,9 ---- * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * ! * @(#)sys_net.c 1.4 (2.11BSD GTE) 1995/10/09 * * Change uiomove calling convention. The r/w type is now encapsulated * in the uio structure now. sms - 11/26/94 *************** *** 255,260 **** --- 255,282 ---- } u.u_error = EPERM; return (0); + } + + /* copied from kern_sysctl.c */ + sysctl_int(oldp, oldlenp, newp, newlen, valp) + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; + int *valp; + { + int error = 0; + + if (oldp && *oldlenp < sizeof(int)) + return (ENOMEM); + if (newp && newlen != sizeof(int)) + return (EINVAL); + *oldlenp = sizeof(int); + if (oldp) + error = copyout(valp, oldp, sizeof(int)); + if (error == 0 && newp) + error = copyin(newp, valp, sizeof(int)); + return (error); } /* *** /usr/src/sys/sys/uipc_domain.c.old Thu Dec 24 16:38:20 1992 --- /usr/src/sys/sys/uipc_domain.c Mon Oct 9 23:19:00 1995 *************** *** 9,15 **** * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)uipc_domain.c 7.2 (Berkeley) 12/30/87 */ #include "param.h" --- 9,15 ---- * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. * ! * @(#)uipc_domain.c 7.2.1 (2.11BSD) 1995/10/09 */ #include "param.h" *************** *** 19,24 **** --- 19,25 ---- #include "domain.h" #include "time.h" #include "kernel.h" + #include "errno.h" #define ADDDOMAIN(x) { \ extern struct domain x/**/domain; \ *************** *** 99,104 **** --- 100,141 ---- maybe = pr; } return (maybe); + } + + net_sysctl(name, namelen, oldp, oldlenp, newp, newlen) + int *name; + u_int namelen; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; + { + register struct domain *dp; + register struct protosw *pr; + int family, protocol; + + /* + * All sysctl names at this level are nonterminal; + * next two components are protocol family and protocol number, + * then at least one addition component. + */ + if (namelen < 3) + return (EISDIR); /* overloaded */ + family = name[0]; + protocol = name[1]; + + if (family == 0) + return (0); + for (dp = domains; dp; dp = dp->dom_next) + if (dp->dom_family == family) + goto found; + return (ENOPROTOOPT); + found: + for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) + if (pr->pr_protocol == protocol && pr->pr_sysctl) + return ((*pr->pr_sysctl)(name + 2, namelen - 2, + oldp, oldlenp, newp, newlen)); + return (ENOPROTOOPT); } pfctlinput(cmd, sa) *** /VERSION.old Sun Sep 10 18:04:39 1995 --- /VERSION Sat Oct 21 18:12:06 1995 *************** *** 1,4 **** ! Current Patch Level: 275 2.11 BSD ============ --- 1,4 ---- ! Current Patch Level: 276 2.11 BSD ============ *************** *** 56,58 **** --- 56,79 ---- "Changes To The System" document which describes the changes made to both the kernel and the application programs. + Steven M. Schultz + Contel Federal Systems + 31717 La Tienda Drive + Westlake Village CA 91359 + sms@wlv.imsd.contel.com + + Below is the original VERSION file distributed with 2.10.1BSD + ----------------------------------------------------------------------- + NOTE -- + This is the second release of 2.10BSD; most of the changes + are part of the addition of supervisor space networking in + the kernel, although there are other changes. + + To give some idea of the dates involved, distribution of + 2.10BSD by the USENIX Assoc. started in fall of 1987. + Distribution of this source started in January of 1989. + + Keith Bostic + Casey Leedom + Cyrus Rahman + Steven Schultz