From 86b4ad7dd56c5d05ddc371767926b1545edacf5a Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Fri, 3 Aug 2018 22:55:58 +0000 Subject: [PATCH] Use if_tunnel_check_nesting() for ng_iface(4). --- sys/netgraph/ng_iface.c | 18 +++--------------- sys/netgraph/ng_iface.h | 3 --- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/sys/netgraph/ng_iface.c b/sys/netgraph/ng_iface.c index 81546bd11beb..bef19a0b8b53 100644 --- a/sys/netgraph/ng_iface.c +++ b/sys/netgraph/ng_iface.c @@ -344,7 +344,6 @@ static int ng_iface_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst, struct route *ro) { - struct m_tag *mtag; uint32_t af; int error; @@ -356,22 +355,11 @@ ng_iface_output(struct ifnet *ifp, struct mbuf *m, } /* Protect from deadly infinite recursion. */ - mtag = NULL; - while ((mtag = m_tag_locate(m, MTAG_NGIF, MTAG_NGIF_CALLED, mtag))) { - 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) { + error = if_tunnel_check_nesting(ifp, m, NGM_IFACE_COOKIE, 1); + if (error) { m_freem(m); - return (ENOMEM); + return (error); } - *(struct ifnet **)(mtag + 1) = ifp; - m_tag_prepend(m, mtag); /* BPF writes need to be handled specially. */ if (dst->sa_family == AF_UNSPEC) diff --git a/sys/netgraph/ng_iface.h b/sys/netgraph/ng_iface.h index 3497e9d39d46..891422b4b359 100644 --- a/sys/netgraph/ng_iface.h +++ b/sys/netgraph/ng_iface.h @@ -70,7 +70,4 @@ enum { NGM_IFACE_GET_IFINDEX, }; -#define MTAG_NGIF NGM_IFACE_COOKIE -#define MTAG_NGIF_CALLED 0 | MTAG_PERSISTENT - #endif /* _NETGRAPH_NG_IFACE_H_ */