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.92.2.1 retrieving revision 1.105 diff -u -p -r1.92.2.1 -r1.105 --- src/sys/netinet/ip_input.c 1999/12/27 18:36:16 1.92.2.1 +++ src/sys/netinet/ip_input.c 2000/03/03 13:07:42 1.105 @@ -1,4 +1,4 @@ -/* $NetBSD: ip_input.c,v 1.92.2.1 1999/12/27 18:36:16 wrstuden Exp $ */ +/* $NetBSD: ip_input.c,v 1.105 2000/03/03 13:07:42 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -194,8 +194,6 @@ int ipprintfs = 0; struct rttimer_queue *ip_mtudisc_timeout_q = NULL; extern struct domain inetdomain; -extern struct protosw inetsw[]; -u_char ip_protox[IPPROTO_MAX]; int ipqmaxlen = IFQ_MAXLEN; struct in_ifaddrhead in_ifaddr; struct in_ifaddrhashhead *in_ifaddrhashtbl; @@ -348,6 +346,7 @@ ip_input(struct mbuf *m) register struct ifaddr *ifa; struct ipqent *ipqe; int hlen = 0, mff, len; + int downmatch; #ifdef PFIL_HOOKS struct packet_filter_hook *pfh; struct mbuf *m0; @@ -397,11 +396,13 @@ ip_input(struct mbuf *m) } ip = mtod(m, struct ip *); } + /* - * we drop packets that have a multicast address as source - * as wanted by rfc 1112 + * RFC1122: packets with a multicast source address are + * not allowed. */ if (IN_MULTICAST(ip->ip_src.s_addr)) { + /* XXX stat */ goto bad; } @@ -463,9 +464,11 @@ ip_input(struct mbuf *m) * in the list may have previously cleared it. */ m0 = m; - for (pfh = pfil_hook_get(PFIL_IN); pfh; pfh = pfh->pfil_link.tqe_next) + pfh = pfil_hook_get(PFIL_IN, &inetsw[ip_protox[IPPROTO_IP]].pr_pfh); + for (; pfh; pfh = pfh->pfil_link.tqe_next) if (pfh->pfil_func) { - rv = pfh->pfil_func(ip, hlen, m->m_pkthdr.rcvif, 0, &m0); + rv = pfh->pfil_func(ip, hlen, + m->m_pkthdr.rcvif, 0, &m0); if (rv) return; m = m0; @@ -487,8 +490,22 @@ ip_input(struct mbuf *m) /* * Check our list of addresses, to see if the packet is for us. - */ - INADDR_TO_IA(ip->ip_dst, ia); + * + * Traditional 4.4BSD did not consult IFF_UP at all. + * The behavior here is to treat addresses on !IFF_UP interface + * as not mine. + */ + downmatch = 0; + for (ia = IN_IFADDR_HASH(ip->ip_dst.s_addr).lh_first; + ia != NULL; + ia = ia->ia_hash.le_next) { + if (in_hosteq(ia->ia_addr.sin_addr, ip->ip_dst)) { + if ((ia->ia_ifp->if_flags & IFF_UP) != 0) + break; + else + downmatch++; + } + } if (ia != NULL) goto ours; if (m->m_pkthdr.rcvif->if_flags & IFF_BROADCAST) { @@ -577,8 +594,20 @@ ip_input(struct mbuf *m) if (ipforwarding == 0) { ipstat.ips_cantforward++; m_freem(m); - } else + } else { + /* + * If ip_dst matched any of my address on !IFF_UP interface, + * and there's no IFF_UP interface that matches ip_dst, + * send icmp unreach. Forwarding it will result in in-kernel + * forwarding loop till TTL goes to 0. + */ + if (downmatch) { + icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0); + ipstat.ips_cantforward++; + return; + } ip_forward(m, 0); + } return; ours: @@ -814,8 +843,6 @@ insert: * Make header visible. */ ip->ip_len = next; - ip->ip_ttl = 0; /* xxx */ - ip->ip_sum = 0; ip->ip_src = fp->ipq_src; ip->ip_dst = fp->ipq_dst; LIST_REMOVE(fp, ipq_q); @@ -920,11 +947,11 @@ ip_dooptions(m) struct mbuf *m; { register struct ip *ip = mtod(m, struct ip *); - register u_char *cp; + register u_char *cp, *cp0; register struct ip_timestamp *ipt; register struct in_ifaddr *ia; int opt, optlen, cnt, off, code, type = ICMP_PARAMPROB, forward = 0; - struct in_addr *sin, dst; + struct in_addr dst; n_time ntime; dst = ip->ip_dst; @@ -995,11 +1022,9 @@ ip_dooptions(m) */ bcopy((caddr_t)(cp + off), (caddr_t)&ipaddr.sin_addr, sizeof(ipaddr.sin_addr)); - if (opt == IPOPT_SSRR) { -#define INA struct in_ifaddr * -#define SA struct sockaddr * - ia = (INA)ifa_ifwithladdr((SA)&ipaddr); - } else + if (opt == IPOPT_SSRR) + ia = ifatoia(ifa_ifwithaddr(sintosa(&ipaddr))); + else ia = ip_rtaddr(ipaddr.sin_addr); if (ia == 0) { type = ICMP_UNREACH; @@ -1033,8 +1058,9 @@ ip_dooptions(m) * locate outgoing interface; if we're the destination, * use the incoming interface (should be same). */ - if ((ia = (INA)ifa_ifwithaddr((SA)&ipaddr)) == 0 && - (ia = ip_rtaddr(ipaddr.sin_addr)) == 0) { + if ((ia = ifatoia(ifa_ifwithaddr(sintosa(&ipaddr)))) + == NULL && + (ia = ip_rtaddr(ipaddr.sin_addr)) == NULL) { type = ICMP_UNREACH; code = ICMP_UNREACH_HOST; goto bad; @@ -1054,7 +1080,7 @@ ip_dooptions(m) goto bad; break; } - sin = (struct in_addr *)(cp + ipt->ipt_ptr - 1); + cp0 = (cp + ipt->ipt_ptr - 1); switch (ipt->ipt_flg) { case IPOPT_TS_TSONLY: @@ -1065,12 +1091,12 @@ ip_dooptions(m) sizeof(struct in_addr) > ipt->ipt_len) goto bad; ipaddr.sin_addr = dst; - ia = (INA)ifaof_ifpforaddr((SA)&ipaddr, - m->m_pkthdr.rcvif); + ia = ifatoia(ifaof_ifpforaddr(sintosa(&ipaddr), + m->m_pkthdr.rcvif)); if (ia == 0) continue; - bcopy((caddr_t)&ia->ia_addr.sin_addr, - (caddr_t)sin, sizeof(struct in_addr)); + bcopy(&ia->ia_addr.sin_addr, + cp0, sizeof(struct in_addr)); ipt->ipt_ptr += sizeof(struct in_addr); break; @@ -1078,9 +1104,10 @@ ip_dooptions(m) if (ipt->ipt_ptr - 1 + sizeof(n_time) + sizeof(struct in_addr) > ipt->ipt_len) goto bad; - bcopy((caddr_t)sin, (caddr_t)&ipaddr.sin_addr, + bcopy(cp0, &ipaddr.sin_addr, sizeof(struct in_addr)); - if (ifa_ifwithaddr((SA)&ipaddr) == 0) + if (ifatoia(ifa_ifwithaddr(sintosa(&ipaddr))) + == NULL) continue; ipt->ipt_ptr += sizeof(struct in_addr); break; @@ -1089,7 +1116,8 @@ ip_dooptions(m) goto bad; } ntime = iptime(); - bcopy((caddr_t)&ntime, (caddr_t)cp + ipt->ipt_ptr - 1, + cp0 = (u_char *) &ntime; /* XXX GCC BUG */ + bcopy(cp0, (caddr_t)cp + ipt->ipt_ptr - 1, sizeof(n_time)); ipt->ipt_ptr += sizeof(n_time); } @@ -1374,8 +1402,9 @@ ip_forward(m, srcrt) } #ifdef IPSEC - m->m_pkthdr.rcvif = NULL; -#endif /*IPSEC*/ + /* Don't lookup socket in forwading case */ + ipsec_setsocket(m, NULL); +#endif error = ip_output(m, (struct mbuf *)0, &ipforward_rt, (IP_FORWARDING | (ip_directedbcast ? IP_ALLOWBROADCAST : 0)), 0); if (error) @@ -1430,18 +1459,21 @@ ip_forward(m, srcrt) if (ipforward_rt.ro_rt) { struct secpolicy *sp; int ipsecerror; - int ipsechdr; + size_t ipsechdr; struct route *ro; sp = ipsec4_getpolicybyaddr(mcopy, - IP_FORWARDING, - &ipsecerror); + IPSEC_DIR_OUTBOUND, + IP_FORWARDING, + &ipsecerror); if (sp == NULL) destifp = ipforward_rt.ro_rt->rt_ifp; else { /* count IPsec header size */ - ipsechdr = ipsec4_hdrsiz(mcopy, NULL); + ipsechdr = ipsec4_hdrsiz(mcopy, + IPSEC_DIR_OUTBOUND, + NULL); /* * find the correct route for outer IPv4 @@ -1454,8 +1486,9 @@ ip_forward(m, srcrt) /*XXX*/ destifp = NULL; if (sp->req != NULL - && sp->req->sa != NULL) { - ro = &sp->req->sa->saidx->sa_route; + && sp->req->sav != NULL + && sp->req->sav->sah != NULL) { + ro = &sp->req->sav->sah->sa_route; if (ro->ro_rt && ro->ro_rt->rt_ifp) { dummyifp.if_mtu = ro->ro_rt->rt_ifp->if_mtu;