Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/netinet/ip_input.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/netinet/ip_input.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.26 retrieving revision 1.30.4.1 diff -u -p -r1.26 -r1.30.4.1 --- src/sys/netinet/ip_input.c 1996/01/15 21:11:55 1.26 +++ src/sys/netinet/ip_input.c 1996/11/10 21:57:51 1.30.4.1 @@ -1,4 +1,4 @@ -/* $NetBSD: ip_input.c,v 1.26 1996/01/15 21:11:55 thorpej Exp $ */ +/* $NetBSD: ip_input.c,v 1.30.4.1 1996/11/10 21:57:51 thorpej Exp $ */ /* * Copyright (c) 1982, 1986, 1988, 1993 @@ -45,6 +45,10 @@ #include #include #include +#include + +#include +#include #include #include @@ -70,10 +74,22 @@ #ifndef IPFORWSRCRT #define IPFORWSRCRT 1 /* allow source-routed packets */ #endif +/* + * Note: DIRECTED_BROADCAST is handled this way so that previous + * configuration using this option will Just Work. + */ +#ifndef IPDIRECTEDBCAST +#ifdef DIRECTED_BROADCAST +#define IPDIRECTEDBCAST 1 +#else +#define IPDIRECTEDBCAST 0 +#endif /* DIRECTED_BROADCAST */ +#endif /* IPDIRECTEDBCAST */ int ipforwarding = IPFORWARDING; int ipsendredirects = IPSENDREDIRECTS; int ip_defttl = IPDEFTTL; int ip_forwsrcrt = IPFORWSRCRT; +int ip_directedbcast = IPDIRECTEDBCAST; #ifdef DIAGNOSTIC int ipprintfs = 0; #endif @@ -187,7 +203,7 @@ next: } ip = mtod(m, struct ip *); } - if (ip->ip_sum = in_cksum(m, hlen)) { + if ((ip->ip_sum = in_cksum(m, hlen)) != 0) { ipstat.ips_badsum++; goto bad; } @@ -237,10 +253,8 @@ next: for (ia = in_ifaddr.tqh_first; ia; ia = ia->ia_list.tqe_next) { if (ip->ip_dst.s_addr == ia->ia_addr.sin_addr.s_addr) goto ours; - if ( -#ifdef DIRECTED_BROADCAST - ia->ia_ifp == m->m_pkthdr.rcvif && -#endif + if (((ip_directedbcast == 0) || (ip_directedbcast && + ia->ia_ifp == m->m_pkthdr.rcvif)) && (ia->ia_ifp->if_flags & IFF_BROADCAST)) { if (ip->ip_dst.s_addr == ia->ia_broadaddr.sin_addr.s_addr || ip->ip_dst.s_addr == ia->ia_netbroadcast.s_addr || @@ -517,10 +531,16 @@ insert: return (0); /* - * Reassembly is complete; concatenate fragments. + * Reassembly is complete. Check for a bogus message size and + * concatenate fragments. */ q = fp->ipq_fragq.lh_first; ip = q->ipqe_ip; + if ((next + (ip->ip_hl << 2)) > IP_MAXPACKET) { + ipstat.ips_toolong++; + ip_freef(fp); + return (0); + } m = dtom(q->ipqe_ip); t = m->m_next; m->m_next = 0; @@ -702,8 +722,7 @@ ip_dooptions(m) if (opt == IPOPT_SSRR) { #define INA struct in_ifaddr * #define SA struct sockaddr * - if ((ia = (INA)ifa_ifwithdstaddr((SA)&ipaddr)) == 0) - ia = (INA)ifa_ifwithnet((SA)&ipaddr); + ia = (INA)ifa_ifwithladdr((SA)&ipaddr); } else ia = ip_rtaddr(ipaddr.sin_addr); if (ia == 0) { @@ -901,7 +920,7 @@ ip_srcroute() *(mtod(m, struct in_addr *)) = *p--; #ifdef DIAGNOSTIC if (ipprintfs) - printf(" hops %lx", ntohl(mtod(m, struct in_addr *)->s_addr)); + printf(" hops %x", ntohl(mtod(m, struct in_addr *)->s_addr)); #endif /* @@ -921,7 +940,7 @@ ip_srcroute() while (p >= ip_srcrt.route) { #ifdef DIAGNOSTIC if (ipprintfs) - printf(" %lx", ntohl(q->s_addr)); + printf(" %x", ntohl(q->s_addr)); #endif *q++ = *p--; } @@ -931,7 +950,7 @@ ip_srcroute() *q = ip_srcrt.dst; #ifdef DIAGNOSTIC if (ipprintfs) - printf(" %lx\n", ntohl(q->s_addr)); + printf(" %x\n", ntohl(q->s_addr)); #endif return (m); } @@ -994,7 +1013,7 @@ ip_forward(m, srcrt) register struct ip *ip = mtod(m, struct ip *); register struct sockaddr_in *sin; register struct rtentry *rt; - int error, type = 0, code; + int error, type = 0, code = 0; struct mbuf *mcopy; n_long dest; struct ifnet *destifp; @@ -1002,8 +1021,8 @@ ip_forward(m, srcrt) dest = 0; #ifdef DIAGNOSTIC if (ipprintfs) - printf("forward: src %x dst %x ttl %x\n", ip->ip_src, - ip->ip_dst, ip->ip_ttl); + printf("forward: src %x dst %x ttl %x\n", + ip->ip_src.s_addr, ip->ip_dst.s_addr, ip->ip_ttl); #endif if (m->m_flags & M_BCAST || in_canforward(ip->ip_dst) == 0) { ipstat.ips_cantforward++; @@ -1066,16 +1085,13 @@ ip_forward(m, srcrt) code = ICMP_REDIRECT_HOST; #ifdef DIAGNOSTIC if (ipprintfs) - printf("redirect (%d) to %lx\n", code, (u_int32_t)dest); + printf("redirect (%d) to %x\n", code, (u_int32_t)dest); #endif } } - error = ip_output(m, (struct mbuf *)0, &ipforward_rt, IP_FORWARDING -#ifdef DIRECTED_BROADCAST - | IP_ALLOWBROADCAST -#endif - , 0); + error = ip_output(m, (struct mbuf *)0, &ipforward_rt, + (IP_FORWARDING | (ip_directedbcast ? IP_ALLOWBROADCAST : 0)), 0); if (error) ipstat.ips_cantforward++; else { @@ -1132,8 +1148,6 @@ ip_sysctl(name, namelen, oldp, oldlenp, void *newp; size_t newlen; { - int temp; - /* All sysctl names at this level are terminal. */ if (namelen != 1) return (ENOTDIR); @@ -1158,6 +1172,9 @@ ip_sysctl(name, namelen, oldp, oldlenp, return (EPERM); return (sysctl_int(oldp, oldlenp, newp, newlen, &ip_forwsrcrt)); + case IPCTL_DIRECTEDBCAST: + return (sysctl_int(oldp, oldlenp, newp, newlen, + &ip_directedbcast)); default: return (EOPNOTSUPP); }