From ad33aae9e768d5cc109d5830881677d5f62134d8 Mon Sep 17 00:00:00 2001 From: Luiz Otavio O Souza Date: Sat, 28 Jan 2017 20:08:09 -0600 Subject: Update the interface name before return and fix the kernel panic when pf is loaded and the stf interface is created without the unit number: Ticket #7124 (cherry picked from commit c050d42a2646d2e582c46cc6f61531150ffb6cb9) --- sys/net/if_stf.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/sys/net/if_stf.c b/sys/net/if_stf.c index 5209bc8..d11ec54 100644 --- a/sys/net/if_stf.c +++ b/sys/net/if_stf.c @@ -202,10 +202,16 @@ stf_clone_match(struct if_clone *ifc, const char *name) static int stf_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) { - int err, unit; + char *dp; + int err, unit, wildcard; struct stf_softc *sc; struct ifnet *ifp; + err = ifc_name2unit(name, &unit); + if (err != 0) + return (err); + wildcard = (unit < 0); + /* * We can only have one unit, but since unit allocation is * already locked, we use it to keep from allocating extra @@ -229,7 +235,20 @@ stf_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) /* * Set the name manually rather then using if_initname because * we don't conform to the default naming convention for interfaces. + * In the wildcard case, we need to update the name. */ + if (wildcard) { + for (dp = name; *dp != '\0'; dp++); + if (snprintf(dp, len - (dp-name), "%d", unit) > + len - (dp-name) - 1) { + /* + * This can only be a programmer error and + * there's no straightforward way to recover if + * it happens. + */ + panic("if_clone_create(): interface name too long"); + } + } strlcpy(ifp->if_xname, name, IFNAMSIZ); ifp->if_dname = stfname; ifp->if_dunit = IF_DUNIT_NONE; -- cgit v1.1