From: mpi Date: Thu, 14 May 2015 10:55:28 +0000 (+0000) Subject: Allocate the input packet handler as part of the trunk_port structure X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d9c00aaa0d6217b19da8351e52e0e40a6cd964e9;p=openbsd Allocate the input packet handler as part of the trunk_port structure since they have the same lifetime. Requested by and ok dlg@ --- diff --git a/sys/net/if_trunk.c b/sys/net/if_trunk.c index 4bdc88100c3..2997d2e8927 100644 --- a/sys/net/if_trunk.c +++ b/sys/net/if_trunk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_trunk.c,v 1.97 2015/05/13 08:16:01 mpi Exp $ */ +/* $OpenBSD: if_trunk.c,v 1.98 2015/05/14 10:55:28 mpi Exp $ */ /* * Copyright (c) 2005, 2006, 2007 Reyk Floeter @@ -291,7 +291,6 @@ trunk_port_create(struct trunk_softc *tr, struct ifnet *ifp) { struct trunk_softc *tr_ptr; struct trunk_port *tp; - struct ifih *trunk_ifih; int error = 0; /* Limit the maximal number of trunk ports */ @@ -330,19 +329,12 @@ trunk_port_create(struct trunk_softc *tr, struct ifnet *ifp) M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL) return (ENOMEM); - trunk_ifih = malloc(sizeof(*trunk_ifih), M_DEVBUF, M_NOWAIT); - if (trunk_ifih == NULL) { - free(tp, M_DEVBUF, 0); - return (ENOMEM); - } - /* Check if port is a stacked trunk */ SLIST_FOREACH(tr_ptr, &trunk_list, tr_entries) { if (ifp == &tr_ptr->tr_ac.ac_if) { tp->tp_flags |= TRUNK_PORT_STACK; if (trunk_port_checkstacking(tr_ptr) >= TRUNK_MAX_STACKING) { - free(trunk_ifih, M_DEVBUF, sizeof(*trunk_ifih)); free(tp, M_DEVBUF, 0); return (E2BIG); } @@ -354,8 +346,8 @@ trunk_port_create(struct trunk_softc *tr, struct ifnet *ifp) ifp->if_type = IFT_IEEE8023ADLAG; /* Change input handler of the physical interface. */ - trunk_ifih->ifih_input = trunk_input; - SLIST_INSERT_HEAD(&ifp->if_inputs, trunk_ifih, ifih_next); + tp->tp_ifih.ifih_input = trunk_input; + SLIST_INSERT_HEAD(&ifp->if_inputs, &tp->tp_ifih, ifih_next); ifp->if_tp = (caddr_t)tp; tp->tp_ioctl = ifp->if_ioctl; @@ -430,7 +422,6 @@ trunk_port_destroy(struct trunk_port *tp) { struct trunk_softc *tr = (struct trunk_softc *)tp->tp_trunk; struct trunk_port *tp_ptr; - struct ifih *trunk_ifih; struct ifnet *ifp = tp->tp_if; if (tr->tr_port_destroy != NULL) @@ -449,10 +440,7 @@ trunk_port_destroy(struct trunk_port *tp) ifp->if_type = tp->tp_iftype; /* Restore previous input handler. */ - trunk_ifih = SLIST_FIRST(&ifp->if_inputs); - SLIST_REMOVE_HEAD(&ifp->if_inputs, ifih_next); - KASSERT(trunk_ifih->ifih_input == trunk_input); - free(trunk_ifih, M_DEVBUF, sizeof(*trunk_ifih)); + SLIST_REMOVE(&ifp->if_inputs, &tp->tp_ifih, ifih, ifih_next); ifp->if_watchdog = tp->tp_watchdog; ifp->if_ioctl = tp->tp_ioctl; diff --git a/sys/net/if_trunk.h b/sys/net/if_trunk.h index b335d2360b0..2f392a13ba0 100644 --- a/sys/net/if_trunk.h +++ b/sys/net/if_trunk.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_trunk.h,v 1.21 2015/05/13 08:16:01 mpi Exp $ */ +/* $OpenBSD: if_trunk.h,v 1.22 2015/05/14 10:55:28 mpi Exp $ */ /* * Copyright (c) 2005, 2006, 2007 Reyk Floeter @@ -137,6 +137,7 @@ struct trunk_port { u_int32_t tp_flags; /* port flags */ void *lh_cookie; /* if state hook */ void *dh_cookie; /* if detach hook */ + struct ifih tp_ifih; /* input handler */ /* Redirected callbacks */ void (*tp_watchdog)(struct ifnet *);