Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- made sure to attach packet addresses to every mbuf even after m_cop…

…y().

- added a supplement function m_copy_withpktaddrs() for this purpose.
  • Loading branch information...
commit 9b4e16e25294f4aa767dfee3b484ff95cdc45313 1 parent 9970ede
jinmei authored
Showing with 39 additions and 10 deletions.
  1. +39 −10 kame/sys/netinet6/ip6_mroute.c
View
49 kame/sys/netinet6/ip6_mroute.c
@@ -1,4 +1,4 @@
-/* $KAME: ip6_mroute.c,v 1.61 2002/03/02 08:28:42 jinmei Exp $ */
+/* $KAME: ip6_mroute.c,v 1.62 2002/03/10 10:58:09 jinmei Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@@ -120,6 +120,8 @@ static int socket_send __P((struct socket *, struct mbuf *,
static int register_send __P((struct ip6_hdr *, struct mif6 *, struct mbuf *,
struct sockaddr_in6 *, struct sockaddr_in6 *));
+static struct mbuf *m_copy_withpktaddrs __P((struct mbuf *, int, int));
+
/*
* Globals. All but ip6_mrouter, ip6_mrtproto and mrt6stat could be static,
* except for netstat or debugging purposes.
@@ -1200,7 +1202,7 @@ ip6_mforward(ip6, ifp, m)
splx(s);
return ENOBUFS;
}
- mb0 = m_copy(m, 0, M_COPYALL);
+ mb0 = m_copy_withpktaddrs(m, 0, M_COPYALL);
/*
* Pullup packet header if needed before storing it,
* as other references may modify it in the meantime.
@@ -1244,7 +1246,8 @@ ip6_mforward(ip6, ifp, m)
* Make a copy of the header to send to the user
* level process
*/
- mm = m_copy(mb0, 0, sizeof(struct ip6_hdr));
+ mm = m_copy_withpktaddrs(mb0, 0,
+ sizeof(struct ip6_hdr));
if (mm == NULL) {
free(rte, M_MRTABLE);
@@ -1503,7 +1506,7 @@ ip6_mdq(m, ifp, rt)
struct omrt6msg *oim;
#endif
- mm = m_copy(m, 0, sizeof(struct ip6_hdr));
+ mm = m_copy_withpktaddrs(m, 0, sizeof(struct ip6_hdr));
if (mm &&
(M_HASCL(mm) ||
mm->m_len < sizeof(struct ip6_hdr)))
@@ -1651,7 +1654,7 @@ phyint_send(ip6, mifp, m, src, dst)
* the IPv6 header is actually copied, not just referenced,
* so that ip6_output() only scribbles on the copy.
*/
- mb_copy = m_copy(m, 0, M_COPYALL);
+ mb_copy = m_copy_withpktaddrs(m, 0, M_COPYALL);
if (mb_copy &&
(M_HASCL(mb_copy) || mb_copy->m_len < sizeof(struct ip6_hdr)))
mb_copy = m_pullup(mb_copy, sizeof(struct ip6_hdr));
@@ -1661,11 +1664,6 @@ phyint_send(ip6, mifp, m, src, dst)
}
/* set MCAST flag to the outgoing packet */
mb_copy->m_flags |= M_MCAST;
- if (!ip6_setpktaddrs(mb_copy, src, dst)) {
- m_freem(mb_copy);
- splx(s);
- return;
- }
/*
* If we sourced the packet, call ip6_output since we may devide
@@ -2052,3 +2050,34 @@ pim6_input(mp, offp, proto)
rip6_input(&m, offp, proto);
return(IPPROTO_DONE);
}
+
+/*
+ * a local wrapper function of m_copy(). It basically copies a given mbuf
+ * by m_copy(), but keeps the aux mbuf in the source mbuf except packet
+ * addresses, which are copied to the copied mbuf with a new aux mbuf.
+ */
+static struct mbuf *
+m_copy_withpktaddrs(m, off, len)
+ struct mbuf *m;
+ int off, len;
+{
+ struct mbuf *copym, *aux;
+ struct sockaddr_in6 *src, *dst;
+
+ if (!(m->m_flags & M_PKTHDR) || !(aux = m->m_pkthdr.aux))
+ panic("ip6_mloopback: null mbuf aux\n");
+
+ if (ip6_getpktaddrs(m, &src, &dst))
+ return(NULL); /* XXX: impossible! */
+
+ m->m_pkthdr.aux = NULL;
+ copym = m_copy(m, off, len);
+ m->m_pkthdr.aux = aux;
+
+ if (copym && !ip6_setpktaddrs(copym, src, dst)) {
+ m_freem(copym);
+ copym = NULL;
+ }
+
+ return(copym);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.