diff options
author | ru <ru@FreeBSD.org> | 2001-11-30 10:40:28 +0000 |
---|---|---|
committer | ru <ru@FreeBSD.org> | 2001-11-30 10:40:28 +0000 |
commit | cfe5212a8b36139b260e85fe117efef6bbbc5a4b (patch) | |
tree | 82b53760121aef4c5d76f4488915d6330e0edb1b /sys/netinet/ip_icmp.c | |
parent | dedc5f403f182feca669fb72974226b658f334af (diff) | |
download | FreeBSD-src-cfe5212a8b36139b260e85fe117efef6bbbc5a4b.zip FreeBSD-src-cfe5212a8b36139b260e85fe117efef6bbbc5a4b.tar.gz |
- Make ip_rtaddr() global, and use it to look up the correct source
address in icmp_reflect().
- Two new "struct icmpstat" members: icps_badaddr and icps_noroute.
PR: kern/31575
Obtained from: BSD/OS
MFC after: 1 week
Diffstat (limited to 'sys/netinet/ip_icmp.c')
-rw-r--r-- | sys/netinet/ip_icmp.c | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 62bcd7e..dba581f 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -109,7 +109,7 @@ int icmpprintfs = 0; #endif static void icmp_reflect __P((struct mbuf *)); -static void icmp_send __P((struct mbuf *, struct mbuf *)); +static void icmp_send __P((struct mbuf *, struct mbuf *, struct route *)); static int ip_next_mtu __P((int, int)); extern struct protosw inetsw[]; @@ -589,11 +589,13 @@ icmp_reflect(m) struct in_addr t; struct mbuf *opts = 0; int optlen = (IP_VHL_HL(ip->ip_vhl) << 2) - sizeof(struct ip); + struct route *ro = NULL, rt; if (!in_canforward(ip->ip_src) && ((ntohl(ip->ip_src.s_addr) & IN_CLASSA_NET) != (IN_LOOPBACKNET << IN_CLASSA_NSHIFT))) { m_freem(m); /* Bad return address */ + icmpstat.icps_badaddr++; goto done; /* Ip_output() will check for broadcast */ } t = ip->ip_dst; @@ -618,26 +620,13 @@ icmp_reflect(m) goto match; } } - icmpdst.sin_addr = t; - ia = (struct in_ifaddr *)ifaof_ifpforaddr( - (struct sockaddr *)&icmpdst, m->m_pkthdr.rcvif); - /* - * The following happens if the packet was not addressed to us, - * and was received on an interface with no IP address: - * We find the first AF_INET address on the first non-loopback - * interface. - */ - if (ia == NULL) - TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) - if ((ia->ia_ifp->if_flags & IFF_LOOPBACK) == 0) - break; - - /* - * If we still didn't find an address, punt. We could have an - * interface up and (and receiving packets) with no address. - */ + ro = &rt; + bzero(ro, sizeof(*ro)); + ia = ip_rtaddr(ip->ip_dst, ro); + /* We need a route to do anything useful. */ if (ia == NULL) { m_freem(m); + icmpstat.icps_noroute++; goto done; } match: @@ -718,10 +707,12 @@ match: (unsigned)(m->m_len - sizeof(struct ip))); } m->m_flags &= ~(M_BCAST|M_MCAST); - icmp_send(m, opts); + icmp_send(m, opts, ro); done: if (opts) (void)m_free(opts); + if (ro && ro->ro_rt) + RTFREE(ro->ro_rt); } /* @@ -729,14 +720,14 @@ done: * after supplying a checksum. */ static void -icmp_send(m, opts) +icmp_send(m, opts, rt) register struct mbuf *m; struct mbuf *opts; + struct route *rt; { register struct ip *ip = mtod(m, struct ip *); register int hlen; register struct icmp *icp; - struct route ro; hlen = IP_VHL_HL(ip->ip_vhl) << 2; m->m_data += hlen; @@ -755,10 +746,7 @@ icmp_send(m, opts) buf, inet_ntoa(ip->ip_src)); } #endif - bzero(&ro, sizeof ro); - (void) ip_output(m, opts, &ro, 0, NULL); - if (ro.ro_rt) - RTFREE(ro.ro_rt); + (void) ip_output(m, opts, rt, 0, NULL); } n_time |