From 070dba1cfe089a868d272eb83aee8cf810e20102 Mon Sep 17 00:00:00 2001 From: Maxim Sobolev Date: Thu, 5 Sep 2002 15:35:38 +0000 Subject: [PATCH] Make recursion prevention variable per-instance and remove XXX comment about thread-unsafety. MFC after: 2 weeks --- sys/net/if_gif.c | 11 ++++------- sys/net/if_gif.h | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/sys/net/if_gif.c b/sys/net/if_gif.c index dc3ad0e6a6c..fb81960d1c6 100644 --- a/sys/net/if_gif.c +++ b/sys/net/if_gif.c @@ -201,6 +201,7 @@ gif_clone_create(ifc, unit) sc->gif_if.if_output = gif_output; sc->gif_if.if_type = IFT_GIF; sc->gif_if.if_snd.ifq_maxlen = IFQ_MAXLEN; + sc->called = 0; if_attach(&sc->gif_if); bpfattach(&sc->gif_if, DLT_NULL, sizeof(u_int)); if (ng_gif_attach_p != NULL) @@ -340,7 +341,6 @@ gif_output(ifp, m, dst, rt) { struct gif_softc *sc = (struct gif_softc*)ifp; int error = 0; - static int called = 0; /* XXX: MUTEX */ #ifdef MAC error = mac_check_ifnet_transmit(ifp, m); @@ -353,14 +353,11 @@ gif_output(ifp, m, dst, rt) /* * gif may cause infinite recursion calls when misconfigured. * We'll prevent this by introducing upper limit. - * XXX: this mechanism may introduce another problem about - * mutual exclusion of the variable CALLED, especially if we - * use kernel thread. */ - if (++called > max_gif_nesting) { + if (++(sc->called) > max_gif_nesting) { log(LOG_NOTICE, "gif_output: recursively called too many times(%d)\n", - called); + sc->called); m_freem(m); error = EIO; /* is there better errno? */ goto end; @@ -417,7 +414,7 @@ gif_output(ifp, m, dst, rt) } end: - called = 0; /* reset recursion counter */ + sc->called = 0; /* reset recursion counter */ if (error) ifp->if_oerrors++; return error; diff --git a/sys/net/if_gif.h b/sys/net/if_gif.h index 1d02348e0bf..51e28db08d5 100644 --- a/sys/net/if_gif.h +++ b/sys/net/if_gif.h @@ -69,6 +69,7 @@ struct gif_softc { const struct encaptab *encap_cookie4; const struct encaptab *encap_cookie6; void *gif_netgraph; /* ng_gif(4) netgraph node info */ + int called; /* anti foot-shooter */ LIST_ENTRY(gif_softc) gif_link; /* all gif's are linked */ };