Use if_tunnel_check_nesting() for ng_iface(4).

This commit is contained in:
Gleb Smirnoff 2018-08-03 22:55:58 +00:00
parent 82533b026a
commit 86b4ad7dd5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=337278
2 changed files with 3 additions and 18 deletions

View File

@ -344,7 +344,6 @@ static int
ng_iface_output(struct ifnet *ifp, struct mbuf *m, ng_iface_output(struct ifnet *ifp, struct mbuf *m,
const struct sockaddr *dst, struct route *ro) const struct sockaddr *dst, struct route *ro)
{ {
struct m_tag *mtag;
uint32_t af; uint32_t af;
int error; int error;
@ -356,22 +355,11 @@ ng_iface_output(struct ifnet *ifp, struct mbuf *m,
} }
/* Protect from deadly infinite recursion. */ /* Protect from deadly infinite recursion. */
mtag = NULL; error = if_tunnel_check_nesting(ifp, m, NGM_IFACE_COOKIE, 1);
while ((mtag = m_tag_locate(m, MTAG_NGIF, MTAG_NGIF_CALLED, mtag))) { if (error) {
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); m_freem(m);
return (ENOMEM); return (error);
} }
*(struct ifnet **)(mtag + 1) = ifp;
m_tag_prepend(m, mtag);
/* BPF writes need to be handled specially. */ /* BPF writes need to be handled specially. */
if (dst->sa_family == AF_UNSPEC) if (dst->sa_family == AF_UNSPEC)

View File

@ -70,7 +70,4 @@ enum {
NGM_IFACE_GET_IFINDEX, NGM_IFACE_GET_IFINDEX,
}; };
#define MTAG_NGIF NGM_IFACE_COOKIE
#define MTAG_NGIF_CALLED 0 | MTAG_PERSISTENT
#endif /* _NETGRAPH_NG_IFACE_H_ */ #endif /* _NETGRAPH_NG_IFACE_H_ */