Lines Matching defs:ifc

54 static void	if_clone_free(struct if_clone *ifc);
55 static int if_clone_createif(struct if_clone *ifc, char *name, size_t len,
71 #define IF_CLONE_LOCK_INIT(ifc) \
72 mtx_init(&(ifc)->ifc_mtx, "if_clone lock", NULL, MTX_DEF)
73 #define IF_CLONE_LOCK_DESTROY(ifc) mtx_destroy(&(ifc)->ifc_mtx)
74 #define IF_CLONE_LOCK_ASSERT(ifc) mtx_assert(&(ifc)->ifc_mtx, MA_OWNED)
75 #define IF_CLONE_LOCK(ifc) mtx_lock(&(ifc)->ifc_mtx)
76 #define IF_CLONE_UNLOCK(ifc) mtx_unlock(&(ifc)->ifc_mtx)
78 #define IF_CLONE_ADDREF(ifc) \
80 IF_CLONE_LOCK(ifc); \
81 IF_CLONE_ADDREF_LOCKED(ifc); \
82 IF_CLONE_UNLOCK(ifc); \
84 #define IF_CLONE_ADDREF_LOCKED(ifc) \
86 IF_CLONE_LOCK_ASSERT(ifc); \
87 KASSERT((ifc)->ifc_refcnt >= 0, \
88 ("negative refcnt %ld", (ifc)->ifc_refcnt)); \
89 (ifc)->ifc_refcnt++; \
91 #define IF_CLONE_REMREF(ifc) \
93 IF_CLONE_LOCK(ifc); \
94 IF_CLONE_REMREF_LOCKED(ifc); \
96 #define IF_CLONE_REMREF_LOCKED(ifc) \
98 IF_CLONE_LOCK_ASSERT(ifc); \
99 KASSERT((ifc)->ifc_refcnt > 0, \
100 ("bogus refcnt %ld", (ifc)->ifc_refcnt)); \
101 if (--(ifc)->ifc_refcnt == 0) { \
102 IF_CLONE_UNLOCK(ifc); \
103 if_clone_free(ifc); \
106 IF_CLONE_UNLOCK(ifc); \
137 struct if_clone *ifc;
141 LIST_FOREACH(ifc, &V_if_cloners, ifc_list) {
142 if (ifc->ifc_match(ifc, name)) {
147 if (ifc == NULL && !IS_DEFAULT_VNET(curvnet)) {
149 LIST_FOREACH(ifc, &V_if_cloners, ifc_list) {
150 if (ifc->ifc_match(ifc, name))
158 if (ifc == NULL)
161 return (if_clone_createif(ifc, name, len, params));
168 if_clone_createif(struct if_clone *ifc, char *name, size_t len, caddr_t params)
176 err = (*ifc->ifc_create)(ifc, name, len, params);
183 if_addgroup(ifp, ifc->ifc_name);
185 IF_CLONE_LOCK(ifc);
186 IFC_IFLIST_INSERT(ifc, ifp);
187 IF_CLONE_UNLOCK(ifc);
200 struct if_clone *ifc;
209 LIST_FOREACH(ifc, &V_if_cloners, ifc_list) {
210 if (strcmp(ifc->ifc_name, ifp->if_dname) == 0) {
215 if (ifc == NULL && !IS_DEFAULT_VNET(curvnet)) {
217 LIST_FOREACH(ifc, &V_if_cloners, ifc_list) {
218 if (ifc->ifc_match(ifc, name))
225 if (ifc == NULL) {
230 err = if_clone_destroyif(ifc, ifp);
239 if_clone_destroyif(struct if_clone *ifc, struct ifnet *ifp)
244 if (ifc->ifc_destroy == NULL)
254 IF_CLONE_LOCK(ifc);
255 LIST_FOREACH(ifcifp, &ifc->ifc_iflist, if_clones) {
257 IFC_IFLIST_REMOVE(ifc, ifp);
261 IF_CLONE_UNLOCK(ifc);
267 if_delgroup(ifp, ifc->ifc_name);
269 err = (*ifc->ifc_destroy)(ifc, ifp);
272 if_addgroup(ifp, ifc->ifc_name);
274 IF_CLONE_LOCK(ifc);
275 IFC_IFLIST_INSERT(ifc, ifp);
276 IF_CLONE_UNLOCK(ifc);
286 if_clone_attach(struct if_clone *ifc)
293 maxclone = ifc->ifc_maxunit + 1;
297 ifc->ifc_units = malloc(len, M_CLONE, M_WAITOK | M_ZERO);
298 ifc->ifc_bmlen = len;
299 IF_CLONE_LOCK_INIT(ifc);
300 IF_CLONE_ADDREF(ifc);
303 LIST_INSERT_HEAD(&V_if_cloners, ifc, ifc_list);
307 LIST_INIT(&ifc->ifc_iflist);
309 if (ifc->ifc_attach != NULL)
310 (*ifc->ifc_attach)(ifc);
311 EVENTHANDLER_INVOKE(if_clone_event, ifc);
318 if_clone_detach(struct if_clone *ifc)
320 struct ifc_simple_data *ifcs = ifc->ifc_data;
323 LIST_REMOVE(ifc, ifc_list);
328 if (ifc->ifc_attach == ifc_simple_attach)
332 while (!LIST_EMPTY(&ifc->ifc_iflist))
333 if_clone_destroyif(ifc, LIST_FIRST(&ifc->ifc_iflist));
335 IF_CLONE_REMREF(ifc);
339 if_clone_free(struct if_clone *ifc)
341 for (int bytoff = 0; bytoff < ifc->ifc_bmlen; bytoff++) {
342 KASSERT(ifc->ifc_units[bytoff] == 0x00,
346 KASSERT(LIST_EMPTY(&ifc->ifc_iflist),
349 IF_CLONE_LOCK_DESTROY(ifc);
350 free(ifc->ifc_units, M_CLONE);
360 struct if_clone *ifc;
391 for (ifc = LIST_FIRST(&V_if_cloners), buf = outbuf;
392 ifc != NULL && count != 0;
393 ifc = LIST_NEXT(ifc, ifc_list), count--, buf += IFNAMSIZ) {
394 strlcpy(buf, ifc->ifc_name, IFNAMSIZ);
442 ifc_alloc_unit(struct if_clone *ifc, int *unit)
447 IF_CLONE_LOCK(ifc);
455 while ((bytoff < ifc->ifc_bmlen)
456 && (ifc->ifc_units[bytoff] == 0xff))
458 if (bytoff >= ifc->ifc_bmlen) {
462 while ((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0)
467 if (*unit > ifc->ifc_maxunit) {
477 if((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0) {
484 KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) == 0,
486 ifc->ifc_units[bytoff] |= (1 << bitoff);
487 IF_CLONE_ADDREF_LOCKED(ifc);
490 IF_CLONE_UNLOCK(ifc);
495 ifc_free_unit(struct if_clone *ifc, int unit)
506 IF_CLONE_LOCK(ifc);
507 KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0,
509 ifc->ifc_units[bytoff] &= ~(1 << bitoff);
510 IF_CLONE_REMREF_LOCKED(ifc); /* releases lock */
514 ifc_simple_attach(struct if_clone *ifc)
519 struct ifc_simple_data *ifcs = ifc->ifc_data;
521 KASSERT(ifcs->ifcs_minifs - 1 <= ifc->ifc_maxunit,
523 __func__, ifc->ifc_name, ifcs->ifcs_minifs,
524 ifc->ifc_maxunit + 1));
527 snprintf(name, IFNAMSIZ, "%s%d", ifc->ifc_name, unit);
528 err = if_clone_createif(ifc, name, IFNAMSIZ, NULL);
536 ifc_simple_match(struct if_clone *ifc, const char *name)
542 for (cp = name, i = 0; i < strlen(ifc->ifc_name); i++, cp++) {
543 if (ifc->ifc_name[i] != *cp)
557 ifc_simple_create(struct if_clone *ifc, char *name, size_t len, caddr_t params)
563 struct ifc_simple_data *ifcs = ifc->ifc_data;
571 err = ifc_alloc_unit(ifc, &unit);
575 err = ifcs->ifcs_create(ifc, unit, params);
577 ifc_free_unit(ifc, unit);
600 ifc_simple_destroy(struct if_clone *ifc, struct ifnet *ifp)
603 struct ifc_simple_data *ifcs = ifc->ifc_data;
612 ifc_free_unit(ifc, unit);