Lines Matching defs:ifc

97 static void	if_clone_free(struct if_clone *ifc);
98 static int if_clone_createif(struct if_clone *ifc, char *name, size_t len,
118 #define IF_CLONE_LOCK_INIT(ifc) \
119 mtx_init(&(ifc)->ifc_mtx, "if_clone lock", NULL, MTX_DEF)
120 #define IF_CLONE_LOCK_DESTROY(ifc) mtx_destroy(&(ifc)->ifc_mtx)
121 #define IF_CLONE_LOCK_ASSERT(ifc) mtx_assert(&(ifc)->ifc_mtx, MA_OWNED)
122 #define IF_CLONE_LOCK(ifc) mtx_lock(&(ifc)->ifc_mtx)
123 #define IF_CLONE_UNLOCK(ifc) mtx_unlock(&(ifc)->ifc_mtx)
125 #define IF_CLONE_ADDREF(ifc) \
127 IF_CLONE_LOCK(ifc); \
128 IF_CLONE_ADDREF_LOCKED(ifc); \
129 IF_CLONE_UNLOCK(ifc); \
131 #define IF_CLONE_ADDREF_LOCKED(ifc) \
133 IF_CLONE_LOCK_ASSERT(ifc); \
134 KASSERT((ifc)->ifc_refcnt >= 0, \
135 ("negative refcnt %ld", (ifc)->ifc_refcnt)); \
136 (ifc)->ifc_refcnt++; \
138 #define IF_CLONE_REMREF(ifc) \
140 IF_CLONE_LOCK(ifc); \
141 IF_CLONE_REMREF_LOCKED(ifc); \
143 #define IF_CLONE_REMREF_LOCKED(ifc) \
145 IF_CLONE_LOCK_ASSERT(ifc); \
146 KASSERT((ifc)->ifc_refcnt > 0, \
147 ("bogus refcnt %ld", (ifc)->ifc_refcnt)); \
148 if (--(ifc)->ifc_refcnt == 0) { \
149 IF_CLONE_UNLOCK(ifc); \
150 if_clone_free(ifc); \
153 IF_CLONE_UNLOCK(ifc); \
184 struct if_clone *ifc;
188 LIST_FOREACH(ifc, &V_if_cloners, ifc_list)
189 if (ifc->ifc_type == SIMPLE) {
190 if (ifc_simple_match(ifc, name))
193 if (ifc->ifc_match(ifc, name))
197 if (ifc == NULL && !IS_DEFAULT_VNET(curvnet)) {
199 LIST_FOREACH(ifc, &V_if_cloners, ifc_list)
200 if (ifc->ifc_type == SIMPLE) {
201 if (ifc_simple_match(ifc, name))
204 if (ifc->ifc_match(ifc, name))
212 if (ifc == NULL)
215 return (if_clone_createif(ifc, name, len, params));
222 if_clone_createif(struct if_clone *ifc, char *name, size_t len, caddr_t params)
230 if (ifc->ifc_type == SIMPLE)
231 err = ifc_simple_create(ifc, name, len, params);
233 err = (*ifc->ifc_create)(ifc, name, len, params);
240 if_addgroup(ifp, ifc->ifc_name);
242 IF_CLONE_LOCK(ifc);
243 IFC_IFLIST_INSERT(ifc, ifp);
244 IF_CLONE_UNLOCK(ifc);
257 struct if_clone *ifc;
266 LIST_FOREACH(ifc, &V_if_cloners, ifc_list) {
267 if (strcmp(ifc->ifc_name, ifp->if_dname) == 0) {
272 if (ifc == NULL && !IS_DEFAULT_VNET(curvnet)) {
274 LIST_FOREACH(ifc, &V_if_cloners, ifc_list)
275 if (ifc->ifc_type == SIMPLE) {
276 if (ifc_simple_match(ifc, name))
279 if (ifc->ifc_match(ifc, name))
286 if (ifc == NULL) {
291 err = if_clone_destroyif(ifc, ifp);
300 if_clone_destroyif(struct if_clone *ifc, struct ifnet *ifp)
305 if (ifc->ifc_type == ADVANCED && ifc->ifc_destroy == NULL)
315 IF_CLONE_LOCK(ifc);
316 LIST_FOREACH(ifcifp, &ifc->ifc_iflist, if_clones) {
318 IFC_IFLIST_REMOVE(ifc, ifp);
322 IF_CLONE_UNLOCK(ifc);
328 if_delgroup(ifp, ifc->ifc_name);
330 if (ifc->ifc_type == SIMPLE)
331 err = ifc_simple_destroy(ifc, ifp);
333 err = (*ifc->ifc_destroy)(ifc, ifp);
336 if_addgroup(ifp, ifc->ifc_name);
338 IF_CLONE_LOCK(ifc);
339 IFC_IFLIST_INSERT(ifc, ifp);
340 IF_CLONE_UNLOCK(ifc);
349 struct if_clone *ifc;
353 ifc = malloc(sizeof(struct if_clone), M_CLONE, M_WAITOK | M_ZERO);
354 strncpy(ifc->ifc_name, name, IFCLOSIZ-1);
355 IF_CLONE_LOCK_INIT(ifc);
356 IF_CLONE_ADDREF(ifc);
357 ifc->ifc_maxunit = maxunit ? maxunit : IF_MAXUNIT;
358 ifc->ifc_unrhdr = new_unrhdr(0, ifc->ifc_maxunit, &ifc->ifc_mtx);
359 LIST_INIT(&ifc->ifc_iflist);
361 return (ifc);
365 if_clone_attach(struct if_clone *ifc)
371 if (strcmp(ifc->ifc_name, ifc1->ifc_name) == 0) {
373 IF_CLONE_REMREF(ifc);
376 LIST_INSERT_HEAD(&V_if_cloners, ifc, ifc_list);
387 struct if_clone *ifc;
389 ifc = if_clone_alloc(name, maxunit);
390 ifc->ifc_type = ADVANCED;
391 ifc->ifc_match = match;
392 ifc->ifc_create = create;
393 ifc->ifc_destroy = destroy;
395 if (if_clone_attach(ifc) != 0) {
396 if_clone_free(ifc);
400 EVENTHANDLER_INVOKE(if_clone_event, ifc);
402 return (ifc);
409 struct if_clone *ifc;
412 ifc = if_clone_alloc(name, 0);
413 ifc->ifc_type = SIMPLE;
414 ifc->ifcs_create = create;
415 ifc->ifcs_destroy = destroy;
416 ifc->ifcs_minifs = minifs;
418 if (if_clone_attach(ifc) != 0) {
419 if_clone_free(ifc);
427 snprintf(name, IFNAMSIZ, "%s%d", ifc->ifc_name, unit);
428 error = if_clone_createif(ifc, name, IFNAMSIZ, NULL);
434 EVENTHANDLER_INVOKE(if_clone_event, ifc);
436 return (ifc);
443 if_clone_detach(struct if_clone *ifc)
447 LIST_REMOVE(ifc, ifc_list);
452 if (ifc->ifc_type == SIMPLE)
453 ifc->ifcs_minifs = 0;
456 while (!LIST_EMPTY(&ifc->ifc_iflist))
457 if_clone_destroyif(ifc, LIST_FIRST(&ifc->ifc_iflist));
459 IF_CLONE_REMREF(ifc);
463 if_clone_free(struct if_clone *ifc)
466 KASSERT(LIST_EMPTY(&ifc->ifc_iflist),
469 IF_CLONE_LOCK_DESTROY(ifc);
470 delete_unrhdr(ifc->ifc_unrhdr);
471 free(ifc, M_CLONE);
481 struct if_clone *ifc;
512 for (ifc = LIST_FIRST(&V_if_cloners), buf = outbuf;
513 ifc != NULL && count != 0;
514 ifc = LIST_NEXT(ifc, ifc_list), count--, buf += IFNAMSIZ) {
515 strlcpy(buf, ifc->ifc_name, IFNAMSIZ);
563 ifc_alloc_unit(struct if_clone *ifc, int *unit)
570 if (*unit > ifc->ifc_maxunit)
573 *unit = alloc_unr(ifc->ifc_unrhdr);
577 *unit = alloc_unr_specific(ifc->ifc_unrhdr, *unit);
587 snprintf(name, IFNAMSIZ, "%s%d", ifc->ifc_name, *unit);
589 free_unr(ifc->ifc_unrhdr, *unit);
597 IF_CLONE_ADDREF(ifc);
603 ifc_free_unit(struct if_clone *ifc, int unit)
606 free_unr(ifc->ifc_unrhdr, unit);
607 IF_CLONE_REMREF(ifc);
611 ifc_simple_match(struct if_clone *ifc, const char *name)
617 for (cp = name, i = 0; i < strlen(ifc->ifc_name); i++, cp++) {
618 if (ifc->ifc_name[i] != *cp)
632 ifc_simple_create(struct if_clone *ifc, char *name, size_t len, caddr_t params)
645 err = ifc_alloc_unit(ifc, &unit);
649 err = ifc->ifcs_create(ifc, unit, params);
651 ifc_free_unit(ifc, unit);
674 ifc_simple_destroy(struct if_clone *ifc, struct ifnet *ifp)
680 if (unit < ifc->ifcs_minifs)
683 ifc->ifcs_destroy(ifp);
685 ifc_free_unit(ifc, unit);