summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys/netinet/if_ether.c63
-rw-r--r--sys/netinet6/nd6.c70
2 files changed, 36 insertions, 97 deletions
diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c
index 91f24e2f10b..f7f418287d9 100644
--- a/sys/netinet/if_ether.c
+++ b/sys/netinet/if_ether.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ether.c,v 1.209 2016/05/23 09:23:43 mpi Exp $ */
+/* $OpenBSD: if_ether.c,v 1.210 2016/05/31 07:50:34 mpi Exp $ */
/* $NetBSD: if_ether.c,v 1.31 1996/05/11 12:59:58 mycroft Exp $ */
/*
@@ -281,9 +281,8 @@ arpresolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m,
struct llinfo_arp *la = NULL;
struct sockaddr_dl *sdl;
struct rtentry *rt = NULL;
- struct mbuf *mh;
char addr[INET_ADDRSTRLEN];
- int error, created = 0;
+ int error;
if (m->m_flags & M_BCAST) { /* broadcast */
memcpy(desten, etherbroadcastaddr, sizeof(etherbroadcastaddr));
@@ -294,41 +293,20 @@ arpresolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m,
return (0);
}
- if (rt0 != NULL) {
- error = rt_checkgate(rt0, &rt);
- if (error) {
- m_freem(m);
- return (error);
- }
-
- if ((rt->rt_flags & RTF_LLINFO) == 0) {
- log(LOG_DEBUG, "%s: %s: route contains no arp"
- " information\n", __func__, inet_ntop(AF_INET,
- &satosin(rt_key(rt))->sin_addr, addr,
- sizeof(addr)));
- m_freem(m);
- return (EINVAL);
- }
+ error = rt_checkgate(rt0, &rt);
+ if (error) {
+ m_freem(m);
+ return (error);
+ }
- la = (struct llinfo_arp *)rt->rt_llinfo;
- if (la == NULL)
- log(LOG_DEBUG, "%s: %s: route without link "
- "local address\n", __func__, inet_ntop(AF_INET,
- &satosin(dst)->sin_addr, addr, sizeof(addr)));
- } else {
- rt = arplookup(&satosin(dst)->sin_addr, 1, 0, ifp->if_rdomain);
- if (rt != NULL) {
- created = 1;
- la = ((struct llinfo_arp *)rt->rt_llinfo);
- }
- if (la == NULL)
- log(LOG_DEBUG, "%s: %s: can't allocate llinfo\n",
- __func__,
- inet_ntop(AF_INET, &satosin(dst)->sin_addr,
- addr, sizeof(addr)));
+ if (!ISSET(rt->rt_flags, RTF_LLINFO)) {
+ log(LOG_DEBUG, "%s: %s: route contains no arp information\n",
+ __func__, inet_ntop(AF_INET, &satosin(rt_key(rt))->sin_addr,
+ addr, sizeof(addr)));
+ m_freem(m);
+ return (EINVAL);
}
- if (la == NULL || rt == NULL)
- goto bad;
+
sdl = satosdl(rt->rt_gateway);
if (sdl->sdl_alen > 0 && sdl->sdl_alen != ETHER_ADDR_LEN) {
log(LOG_DEBUG, "%s: %s: incorrect arp information\n", __func__,
@@ -336,6 +314,7 @@ arpresolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m,
addr, sizeof(addr)));
goto bad;
}
+
/*
* Check the address family and length is valid, the address
* is resolved; otherwise, try to resolve.
@@ -343,10 +322,9 @@ arpresolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m,
if ((rt->rt_expire == 0 || rt->rt_expire > time_second) &&
sdl->sdl_family == AF_LINK && sdl->sdl_alen != 0) {
memcpy(desten, LLADDR(sdl), sdl->sdl_alen);
- if (created)
- rtfree(rt);
return (0);
}
+
if (ifp->if_flags & IFF_NOARP)
goto bad;
@@ -355,7 +333,11 @@ arpresolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m,
* response yet. Insert mbuf in hold queue if below limit
* if above the limit free the queue without queuing the new packet.
*/
+ la = (struct llinfo_arp *)rt->rt_llinfo;
+ KASSERT(la != NULL);
if (la_hold_total < LA_HOLD_TOTAL && la_hold_total < nmbclust / 64) {
+ struct mbuf *mh;
+
if (ml_len(&la->la_ml) >= LA_HOLD_QUEUE) {
mh = ml_dequeue(&la->la_ml);
la_hold_total--;
@@ -396,14 +378,11 @@ arpresolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m,
}
}
}
- if (created)
- rtfree(rt);
+
return (EAGAIN);
bad:
m_freem(m);
- if (created)
- rtfree(rt);
return (EINVAL);
}
diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c
index e80e24228ec..35ab0aa09d0 100644
--- a/sys/netinet6/nd6.c
+++ b/sys/netinet6/nd6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nd6.c,v 1.180 2016/05/30 23:37:37 dlg Exp $ */
+/* $OpenBSD: nd6.c,v 1.181 2016/05/31 07:50:34 mpi Exp $ */
/* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */
/*
@@ -1488,20 +1488,15 @@ nd6_output(struct ifnet *ifp, struct mbuf *m0, struct sockaddr_in6 *dst,
struct mbuf *m = m0;
struct rtentry *rt = rt0;
struct llinfo_nd6 *ln = NULL;
- int created = 0, error = 0;
+ int error = 0;
if (IN6_IS_ADDR_MULTICAST(&dst->sin6_addr))
goto sendpkt;
- /*
- * next hop determination.
- */
- if (rt0 != NULL) {
- error = rt_checkgate(rt0, &rt);
- if (error) {
- m_freem(m);
- return (error);
- }
+ error = rt_checkgate(rt0, &rt);
+ if (error) {
+ m_freem(m);
+ return (error);
}
if (nd6_need_cache(ifp) == 0)
@@ -1513,42 +1508,17 @@ nd6_output(struct ifnet *ifp, struct mbuf *m0, struct sockaddr_in6 *dst,
* At this point, the destination of the packet must be a unicast
* or an anycast address(i.e. not a multicast).
*/
-
- /* Look up the neighbor cache for the nexthop */
- if (rt != NULL && (rt->rt_flags & RTF_LLINFO) != 0)
- ln = (struct llinfo_nd6 *)rt->rt_llinfo;
- else {
- /*
- * Since nd6_is_addr_neighbor() internally calls nd6_lookup(),
- * the condition below is not very efficient. But we believe
- * it is tolerable, because this should be a rare case.
- */
- if (nd6_is_addr_neighbor(dst, ifp)) {
- rt = nd6_lookup(&dst->sin6_addr, 1, ifp,
- ifp->if_rdomain);
- if (rt != NULL) {
- created = 1;
- ln = (struct llinfo_nd6 *)rt->rt_llinfo;
- }
- }
+ if (!ISSET(rt->rt_flags, RTF_LLINFO)) {
+ char addr[INET6_ADDRSTRLEN];
+ log(LOG_DEBUG, "%s: %s: route contains no ND information\n",
+ __func__, inet_ntop(AF_INET6,
+ &satosin6(rt_key(rt))->sin6_addr, addr, sizeof(addr)));
+ m_freem(m);
+ return (EINVAL);
}
- if (ln == NULL || rt == NULL) {
- if ((ND_IFINFO(ifp)->flags & ND6_IFF_PERFORMNUD) == 0) {
- char addr[INET6_ADDRSTRLEN];
-
- log(LOG_DEBUG, "%s: can't allocate llinfo for %s "
- "(ln=%p, rt=%p)\n", __func__,
- inet_ntop(AF_INET6, &dst->sin6_addr,
- addr, sizeof(addr)),
- ln, rt);
- m_freem(m);
- if (created)
- rtfree(rt);
- return (EIO); /* XXX: good error? */
- }
- goto sendpkt; /* send anyway */
- }
+ ln = (struct llinfo_nd6 *)rt->rt_llinfo;
+ KASSERT(ln != NULL);
/*
* Move this entry to the head of the queue so that it is less likely
@@ -1598,14 +1568,10 @@ nd6_output(struct ifnet *ifp, struct mbuf *m0, struct sockaddr_in6 *dst,
(long)ND_IFINFO(ifp)->retrans * hz / 1000);
nd6_ns_output(ifp, NULL, &dst->sin6_addr, ln, 0);
}
- if (created)
- rtfree(rt);
return (0);
sendpkt:
error = ifp->if_output(ifp, m, sin6tosa(dst), rt);
- if (created)
- rtfree(rt);
return (error);
}
@@ -1648,12 +1614,6 @@ nd6_storelladdr(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m,
}
}
- if (rt0 == NULL) {
- /* this could happen, if we could not allocate memory */
- m_freem(m);
- return (ENOMEM);
- }
-
error = rt_checkgate(rt0, &rt);
if (error) {
m_freem(m);