Lines Matching full:ifc

112 static void	if_clone_free(struct if_clone *ifc);
113 static int if_clone_createif_nl(struct if_clone *ifc, const char *name,
116 static int ifc_simple_match(struct if_clone *ifc, const char *name);
117 static int ifc_handle_unit(struct if_clone *ifc, char *name, size_t len, int *punit);
122 static int ifc_simple_create_wrapper(struct if_clone *ifc, char *name, size_t maxlen,
124 static int ifc_advanced_create_wrapper(struct if_clone *ifc, char *name, size_t maxlen,
140 #define IF_CLONE_LOCK_INIT(ifc) \
141 mtx_init(&(ifc)->ifc_mtx, "if_clone lock", NULL, MTX_DEF)
142 #define IF_CLONE_LOCK_DESTROY(ifc) mtx_destroy(&(ifc)->ifc_mtx)
143 #define IF_CLONE_LOCK_ASSERT(ifc) mtx_assert(&(ifc)->ifc_mtx, MA_OWNED)
144 #define IF_CLONE_LOCK(ifc) mtx_lock(&(ifc)->ifc_mtx)
145 #define IF_CLONE_UNLOCK(ifc) mtx_unlock(&(ifc)->ifc_mtx)
147 #define IF_CLONE_ADDREF(ifc) \
149 IF_CLONE_LOCK(ifc); \
150 IF_CLONE_ADDREF_LOCKED(ifc); \
151 IF_CLONE_UNLOCK(ifc); \
153 #define IF_CLONE_ADDREF_LOCKED(ifc) \
155 IF_CLONE_LOCK_ASSERT(ifc); \
156 KASSERT((ifc)->ifc_refcnt >= 0, \
157 ("negative refcnt %ld", (ifc)->ifc_refcnt)); \
158 (ifc)->ifc_refcnt++; \
160 #define IF_CLONE_REMREF(ifc) \
162 IF_CLONE_LOCK(ifc); \
163 IF_CLONE_REMREF_LOCKED(ifc); \
165 #define IF_CLONE_REMREF_LOCKED(ifc) \
167 IF_CLONE_LOCK_ASSERT(ifc); \
168 KASSERT((ifc)->ifc_refcnt > 0, \
169 ("bogus refcnt %ld", (ifc)->ifc_refcnt)); \
170 if (--(ifc)->ifc_refcnt == 0) { \
171 IF_CLONE_UNLOCK(ifc); \
172 if_clone_free(ifc); \
175 IF_CLONE_UNLOCK(ifc); \
199 struct if_clone *ifc = ifc_find_cloner_match(name);
201 if (ifc == NULL)
210 int error = if_clone_createif_nl(ifc, name, &ifd_new);
221 struct if_clone *ifc = ifc_find_cloner_match(name);
222 if (ifc == NULL) {
227 ifd->error = if_clone_createif_nl(ifc, name, ifd);
249 struct if_clone *ifc = ifc_find_cloner(ifp->if_dname);
250 if (ifc == NULL) {
255 ifd->error = (*ifc->modify_nl)(ifp, ifd);
262 struct if_clone *ifc = ifc_find_cloner(ifp->if_dname);
263 if (ifc == NULL)
266 (*ifc->dump_nl)(ifp, nw);
271 ifc_create_ifp_nl_default(struct if_clone *ifc, char *name, size_t len,
280 return ((*ifc->ifc_create)(ifc, name, len, &ifd_new, &ifd->ifp));
303 ifc_link_ifp(struct if_clone *ifc, struct ifnet *ifp)
306 if_addgroup(ifp, ifc->ifc_name);
308 IF_CLONE_LOCK(ifc);
309 IFC_IFLIST_INSERT(ifc, ifp);
310 IF_CLONE_UNLOCK(ifc);
314 if_clone_addif(struct if_clone *ifc, struct ifnet *ifp)
316 ifc_link_ifp(ifc, ifp);
320 ifc_unlink_ifp(struct if_clone *ifc, struct ifnet *ifp)
324 IF_CLONE_LOCK(ifc);
325 LIST_FOREACH(ifcifp, &ifc->ifc_iflist, if_clones) {
327 IFC_IFLIST_REMOVE(ifc, ifp);
331 IF_CLONE_UNLOCK(ifc);
334 if_delgroup(ifp, ifc->ifc_name);
342 struct if_clone *ifc;
345 LIST_FOREACH(ifc, &V_if_cloners, ifc_list) {
346 if (ifc->ifc_match(ifc, name))
351 return (ifc);
357 struct if_clone *ifc;
360 LIST_FOREACH(ifc, &V_if_cloners, ifc_list) {
361 if (strcmp(ifc->ifc_name, name) == 0) {
367 return (ifc);
374 struct if_clone *ifc = ifc_find_cloner(name);
377 return (ifc);
384 if_clone_createif_nl(struct if_clone *ifc, const char *ifname, struct ifc_data_nl *ifd)
394 if (ifc->ifc_flags & IFC_F_AUTOUNIT) {
395 if ((error = ifc_handle_unit(ifc, name, sizeof(name), &ifd->unit)) != 0)
400 error = (*ifc->create_nl)(ifc, name, sizeof(name), ifd);
402 error = ifc_create_ifp_nl_default(ifc, name, sizeof(name), ifd);
404 if (ifc->ifc_flags & IFC_F_AUTOUNIT)
405 ifc_free_unit(ifc, ifd->unit);
410 if_clone_addif(ifc, ifd->ifp);
413 error = (*ifc->modify_nl)(ifd->ifp, ifd);
425 struct if_clone *ifc;
432 ifc = ifc_find_cloner_in_vnet(ifp->if_dname, ifp->if_home_vnet);
433 if (ifc == NULL) {
438 err = if_clone_destroyif(ifc, ifp);
447 if_clone_destroyif_flags(struct if_clone *ifc, struct ifnet *ifp, uint32_t flags)
458 if (!ifc_unlink_ifp(ifc, ifp)) {
464 err = (*ifc->ifc_destroy)(ifc, ifp, flags);
467 ifc_link_ifp(ifc, ifp);
468 else if (ifc->ifc_flags & IFC_F_AUTOUNIT)
469 ifc_free_unit(ifc, unit);
475 if_clone_destroyif(struct if_clone *ifc, struct ifnet *ifp)
477 return (if_clone_destroyif_flags(ifc, ifp, 0));
483 struct if_clone *ifc;
488 ifc = malloc(sizeof(struct if_clone), M_CLONE, M_WAITOK | M_ZERO);
489 strncpy(ifc->ifc_name, name, IFCLOSIZ-1);
490 IF_CLONE_LOCK_INIT(ifc);
491 IF_CLONE_ADDREF(ifc);
492 ifc->ifc_maxunit = maxunit;
493 ifc->ifc_unrhdr = new_unrhdr(0, ifc->ifc_maxunit, &ifc->ifc_mtx);
494 LIST_INIT(&ifc->ifc_iflist);
496 ifc->create_nl = ifc_create_ifp_nl_default;
497 ifc->modify_nl = ifc_modify_ifp_nl_default;
498 ifc->dump_nl = ifc_dump_ifp_nl_default;
500 return (ifc);
504 if_clone_attach(struct if_clone *ifc)
510 if (strcmp(ifc->ifc_name, ifc1->ifc_name) == 0) {
512 IF_CLONE_REMREF(ifc);
515 LIST_INSERT_HEAD(&V_if_cloners, ifc, ifc_list);
526 struct if_clone *ifc;
534 ifc = if_clone_alloc(name, maxunit);
535 ifc->ifc_match = req->match_f != NULL ? req->match_f : ifc_simple_match;
536 ifc->ifc_create = req->create_f;
537 ifc->ifc_destroy = req->destroy_f;
538 ifc->ifc_flags = (req->flags & IFC_F_AUTOUNIT);
543 ifc->create_nl = req2->create_nl_f;
544 ifc->modify_nl = req2->modify_nl_f;
545 ifc->dump_nl = req2->dump_nl_f;
548 ifc->dump_nl = ifc_dump_ifp_nl_default;
550 if (if_clone_attach(ifc) != 0)
553 EVENTHANDLER_INVOKE(if_clone_event, ifc);
555 return (ifc);
559 ifc_detach_cloner(struct if_clone *ifc)
561 if_clone_detach(ifc);
568 ifc_advanced_create_wrapper(struct if_clone *ifc, char *name, size_t maxlen,
571 int error = ifc->ifca_create(ifc, name, maxlen, ifc_data->params);
579 ifc_advanced_destroy_wrapper(struct if_clone *ifc, struct ifnet *ifp, uint32_t flags)
581 if (ifc->ifca_destroy == NULL)
583 return (ifc->ifca_destroy(ifc, ifp));
590 struct if_clone *ifc;
592 ifc = if_clone_alloc(name, maxunit ? maxunit : IF_MAXUNIT);
593 ifc->ifc_match = match;
594 ifc->ifc_create = ifc_advanced_create_wrapper;
595 ifc->ifc_destroy = ifc_advanced_destroy_wrapper;
596 ifc->ifca_destroy = destroy;
597 ifc->ifca_create = create;
599 if (if_clone_attach(ifc) != 0)
602 EVENTHANDLER_INVOKE(if_clone_event, ifc);
604 return (ifc);
608 ifc_simple_create_wrapper(struct if_clone *ifc, char *name, size_t maxlen,
614 int error = ifc->ifcs_create(ifc, unit, ifc_data->params);
621 ifc_simple_destroy_wrapper(struct if_clone *ifc, struct ifnet *ifp, uint32_t flags)
623 if (ifp->if_dunit < ifc->ifcs_minifs && (flags & IFC_F_FORCE) == 0)
626 ifc->ifcs_destroy(ifp);
634 struct if_clone *ifc;
637 ifc = if_clone_alloc(name, IF_MAXUNIT);
638 ifc->ifc_match = ifc_simple_match;
639 ifc->ifc_create = ifc_simple_create_wrapper;
640 ifc->ifc_destroy = ifc_simple_destroy_wrapper;
641 ifc->ifcs_create = create;
642 ifc->ifcs_destroy = destroy;
643 ifc->ifcs_minifs = minifs;
644 ifc->ifc_flags = IFC_F_AUTOUNIT;
646 if (if_clone_attach(ifc) != 0)
654 snprintf(name, IFNAMSIZ, "%s%d", ifc->ifc_name, unit);
655 error = if_clone_createif_nl(ifc, name, &ifd);
661 EVENTHANDLER_INVOKE(if_clone_event, ifc);
663 return (ifc);
671 if_clone_detach(struct if_clone *ifc)
675 LIST_REMOVE(ifc, ifc_list);
680 while (!LIST_EMPTY(&ifc->ifc_iflist))
681 if_clone_destroyif_flags(ifc, LIST_FIRST(&ifc->ifc_iflist), IFC_F_FORCE);
683 IF_CLONE_REMREF(ifc);
687 if_clone_free(struct if_clone *ifc)
690 KASSERT(LIST_EMPTY(&ifc->ifc_iflist),
693 IF_CLONE_LOCK_DESTROY(ifc);
694 delete_unrhdr(ifc->ifc_unrhdr);
695 free(ifc, M_CLONE);
705 struct if_clone *ifc;
736 for (ifc = LIST_FIRST(&V_if_cloners), buf = outbuf;
737 ifc != NULL && count != 0;
738 ifc = LIST_NEXT(ifc, ifc_list), count--, buf += IFNAMSIZ) {
739 strlcpy(buf, ifc->ifc_name, IFNAMSIZ);
764 struct if_clone *ifc;
770 LIST_FOREACH(ifc, &V_if_cloners, ifc_list) {
771 IF_CLONE_LOCK(ifc);
772 LIST_FOREACH(ifcifp, &ifc->ifc_iflist, if_clones) {
774 strncpy(ifc_name, ifc->ifc_name, IFCLOSIZ-1);
778 IF_CLONE_UNLOCK(ifc);
783 LIST_FOREACH(ifc, &V_if_cloners, ifc_list)
784 if (strcmp(ifc->ifc_name, ifc_name) == 0)
788 if (ifc != NULL)
830 ifc_alloc_unit_specific(struct if_clone *ifc, int *unit)
834 if (*unit > ifc->ifc_maxunit)
837 if (alloc_unr_specific(ifc->ifc_unrhdr, *unit) == -1)
840 snprintf(name, IFNAMSIZ, "%s%d", ifc->ifc_name, *unit);
842 free_unr(ifc->ifc_unrhdr, *unit);
846 IF_CLONE_ADDREF(ifc);
852 ifc_alloc_unit_next(struct if_clone *ifc, int *unit)
856 *unit = alloc_unr(ifc->ifc_unrhdr);
860 free_unr(ifc->ifc_unrhdr, *unit);
862 error = ifc_alloc_unit_specific(ifc, unit);
873 ifc_alloc_unit(struct if_clone *ifc, int *unit)
876 return (ifc_alloc_unit_next(ifc, unit));
878 return (ifc_alloc_unit_specific(ifc, unit));
882 ifc_free_unit(struct if_clone *ifc, int unit)
885 free_unr(ifc->ifc_unrhdr, unit);
886 IF_CLONE_REMREF(ifc);
890 ifc_simple_match(struct if_clone *ifc, const char *name)
896 for (cp = name, i = 0; i < strlen(ifc->ifc_name); i++, cp++) {
897 if (ifc->ifc_name[i] != *cp)
911 ifc_handle_unit(struct if_clone *ifc, char *name, size_t len, int *punit)
924 err = ifc_alloc_unit(ifc, &unit);