diff options
author | Alexander Motin <mav@FreeBSD.org> | 2009-01-31 12:48:09 +0000 |
---|---|---|
committer | Alexander Motin <mav@FreeBSD.org> | 2009-01-31 12:48:09 +0000 |
commit | 38d34b673a8a3bd439a0191c00a865f304217775 (patch) | |
tree | 8037ef593d4f5bee77809695ab2f361b733d6f45 | |
parent | 915c2a84f830eec0c47bccbc1ae018d40116eebd (diff) |
Notes
-rw-r--r-- | sys/netgraph/ng_iface.c | 18 | ||||
-rw-r--r-- | sys/netgraph/ng_iface.h | 3 |
2 files changed, 21 insertions, 0 deletions
diff --git a/sys/netgraph/ng_iface.c b/sys/netgraph/ng_iface.c index fec243215d35..f40cbe498eeb 100644 --- a/sys/netgraph/ng_iface.c +++ b/sys/netgraph/ng_iface.c @@ -353,6 +353,7 @@ static int ng_iface_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt0) { + struct m_tag *mtag; uint32_t af; int error; @@ -363,6 +364,23 @@ ng_iface_output(struct ifnet *ifp, struct mbuf *m, return (ENETDOWN); } + /* Protect from deadly infinite recursion. */ + while ((mtag = m_tag_locate(m, MTAG_NGIF, MTAG_NGIF_CALLED, NULL))) { + if (*(struct ifnet **)(mtag + 1) == ifp) { + log(LOG_NOTICE, "Loop detected on %s\n", ifp->if_xname); + m_freem(m); + return (EDEADLK); + } + } + mtag = m_tag_alloc(MTAG_NGIF, MTAG_NGIF_CALLED, sizeof(struct ifnet *), + M_NOWAIT); + if (mtag == NULL) { + m_freem(m); + return (ENOMEM); + } + *(struct ifnet **)(mtag + 1) = ifp; + m_tag_prepend(m, mtag); + /* BPF writes need to be handled specially. */ if (dst->sa_family == AF_UNSPEC) { bcopy(dst->sa_data, &af, sizeof(af)); diff --git a/sys/netgraph/ng_iface.h b/sys/netgraph/ng_iface.h index 54dfa8c78690..58fb44230582 100644 --- a/sys/netgraph/ng_iface.h +++ b/sys/netgraph/ng_iface.h @@ -72,4 +72,7 @@ enum { NGM_IFACE_GET_IFINDEX, }; +#define MTAG_NGIF NGM_IFACE_COOKIE +#define MTAG_NGIF_CALLED 0 | MTAG_PERSISTENT + #endif /* _NETGRAPH_NG_IFACE_H_ */ |