| 194 | } |
| 195 | |
| 196 | static int |
| 197 | stf_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) |
| 198 | { |
| 199 | char *dp; |
| 200 | int err, unit, wildcard; |
| 201 | struct stf_softc *sc; |
| 202 | struct ifnet *ifp; |
| 203 | |
| 204 | err = ifc_name2unit(name, &unit); |
| 205 | if (err != 0) |
| 206 | return (err); |
| 207 | wildcard = (unit < 0); |
| 208 | |
| 209 | /* |
| 210 | * We can only have one unit, but since unit allocation is |
| 211 | * already locked, we use it to keep from allocating extra |
| 212 | * interfaces. |
| 213 | */ |
| 214 | unit = STFUNIT; |
| 215 | err = ifc_alloc_unit(ifc, &unit); |
| 216 | if (err != 0) |
| 217 | return (err); |
| 218 | |
| 219 | sc = malloc(sizeof(struct stf_softc), M_STF, M_WAITOK | M_ZERO); |
| 220 | ifp = STF2IFP(sc) = if_alloc(IFT_STF); |
| 221 | if (ifp == NULL) { |
| 222 | free(sc, M_STF); |
| 223 | ifc_free_unit(ifc, unit); |
| 224 | return (ENOSPC); |
| 225 | } |
| 226 | ifp->if_softc = sc; |
| 227 | sc->sc_fibnum = curthread->td_proc->p_fibnum; |
| 228 | |
| 229 | /* |
| 230 | * Set the name manually rather then using if_initname because |
| 231 | * we don't conform to the default naming convention for interfaces. |
| 232 | * In the wildcard case, we need to update the name. |
| 233 | */ |
| 234 | if (wildcard) { |
| 235 | for (dp = name; *dp != '\0'; dp++); |
| 236 | if (snprintf(dp, len - (dp-name), "%d", unit) > |
| 237 | len - (dp-name) - 1) { |
| 238 | /* |
| 239 | * This can only be a programmer error and |
| 240 | * there's no straightforward way to recover if |
| 241 | * it happens. |
| 242 | */ |
| 243 | panic("if_clone_create(): interface name too long"); |
| 244 | } |
| 245 | } |
| 246 | strlcpy(ifp->if_xname, name, IFNAMSIZ); |
| 247 | ifp->if_dname = stfname; |
| 248 | ifp->if_dunit = IF_DUNIT_NONE; |
| 249 | |
| 250 | sc->encap_cookie = ip_encap_attach(&ipv4_encap_cfg, sc, M_WAITOK); |
| 251 | if (sc->encap_cookie == NULL) { |
| 252 | if_printf(ifp, "attach failed\n"); |
| 253 | free(sc, M_STF); |
nothing calls this directly
no test coverage detected