use two stage creation of stp ports, this means that the stp variables can be

set before the port is marked STP and they will no longer be overwrittten
This commit is contained in:
Andrew Thompson 2006-11-26 18:43:48 +00:00
parent a230a36b4d
commit 071fff62be
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=164626
3 changed files with 39 additions and 31 deletions

View File

@ -2114,8 +2114,34 @@ bstp_stop(struct bstp_state *bs)
}
int
bstp_add(struct bstp_state *bs, struct bstp_port *bp, struct ifnet *ifp)
bstp_create(struct bstp_state *bs, struct bstp_port *bp, struct ifnet *ifp)
{
bzero(bp, sizeof(struct bstp_port));
BSTP_LOCK(bs);
bp->bp_ifp = ifp;
bp->bp_bs = bs;
bp->bp_priority = BSTP_DEFAULT_PORT_PRIORITY;
TASK_INIT(&bp->bp_statetask, 0, bstp_notify_state, bp);
TASK_INIT(&bp->bp_rtagetask, 0, bstp_notify_rtage, bp);
/* Init state */
bp->bp_flags = BSTP_PORT_AUTOEDGE;
bstp_set_port_state(bp, BSTP_IFSTATE_DISCARDING);
bstp_set_port_proto(bp, bs->bs_protover);
bstp_set_port_role(bp, BSTP_ROLE_DISABLED);
bstp_set_port_tc(bp, BSTP_TCSTATE_INACTIVE);
bp->bp_path_cost = bstp_calc_path_cost(bp);
BSTP_UNLOCK(bs);
return (0);
}
int
bstp_enable(struct bstp_port *bp)
{
struct bstp_state *bs = bp->bp_bs;
struct ifnet *ifp = bp->bp_ifp;
KASSERT(bp->bp_active == 0, ("already a bstp member"));
switch (ifp->if_type) {
@ -2126,27 +2152,8 @@ bstp_add(struct bstp_state *bs, struct bstp_port *bp, struct ifnet *ifp)
return (EINVAL);
}
bzero(bp, sizeof(struct bstp_port));
BSTP_LOCK(bs);
bp->bp_ifp = ifp;
bp->bp_bs = bs;
bp->bp_priority = BSTP_DEFAULT_PORT_PRIORITY;
bp->bp_txcount = 0;
TASK_INIT(&bp->bp_statetask, 0, bstp_notify_state, bp);
TASK_INIT(&bp->bp_rtagetask, 0, bstp_notify_rtage, bp);
/* Init state */
bp->bp_infois = BSTP_INFO_DISABLED;
bp->bp_flags = BSTP_PORT_AUTOEDGE;
bstp_set_port_state(bp, BSTP_IFSTATE_DISCARDING);
bstp_set_port_proto(bp, bs->bs_protover);
bstp_set_port_role(bp, BSTP_ROLE_DISABLED);
bstp_set_port_tc(bp, BSTP_TCSTATE_INACTIVE);
bp->bp_path_cost = bstp_calc_path_cost(bp);
LIST_INSERT_HEAD(&bs->bs_bplist, bp, bp_next);
bp->bp_active = 1;
bp->bp_flags |= BSTP_PORT_NEWINFO;
bstp_reinit(bs);
@ -2156,15 +2163,15 @@ bstp_add(struct bstp_state *bs, struct bstp_port *bp, struct ifnet *ifp)
}
void
bstp_delete(struct bstp_port *bp)
bstp_disable(struct bstp_port *bp)
{
struct bstp_state *bs = bp->bp_bs;
KASSERT(bp->bp_active == 1, ("not a bstp member"));
BSTP_LOCK(bs);
bstp_disable_port(bs, bp);
LIST_REMOVE(bp, bp_next);
bp->bp_bs = NULL;
bp->bp_active = 0;
bstp_reinit(bs);
BSTP_UNLOCK(bs);
@ -2174,7 +2181,7 @@ bstp_delete(struct bstp_port *bp)
* The bstp_port structure is about to be freed by the parent bridge.
*/
void
bstp_drain(struct bstp_port *bp)
bstp_destroy(struct bstp_port *bp)
{
KASSERT(bp->bp_active == 0, ("port is still attached"));
taskqueue_drain(taskqueue_swi, &bp->bp_statetask);

View File

@ -367,9 +367,10 @@ void bstp_attach(struct bstp_state *, bstp_state_cb_t, bstp_rtage_cb_t);
void bstp_detach(struct bstp_state *);
void bstp_init(struct bstp_state *);
void bstp_stop(struct bstp_state *);
int bstp_add(struct bstp_state *, struct bstp_port *, struct ifnet *);
void bstp_delete(struct bstp_port *);
void bstp_drain(struct bstp_port *);
int bstp_create(struct bstp_state *, struct bstp_port *, struct ifnet *);
int bstp_enable(struct bstp_port *);
void bstp_disable(struct bstp_port *);
void bstp_destroy(struct bstp_port *);
void bstp_linkstate(struct ifnet *, int);
int bstp_set_htime(struct bstp_state *, int);
int bstp_set_fdelay(struct bstp_state *, int);

View File

@ -875,7 +875,7 @@ bridge_delete_member(struct bridge_softc *sc, struct bridge_iflist *bif,
}
if (bif->bif_flags & IFBIF_STP)
bstp_delete(&bif->bif_stp);
bstp_disable(&bif->bif_stp);
ifs->if_bridge = NULL;
BRIDGE_XLOCK(sc);
@ -885,7 +885,7 @@ bridge_delete_member(struct bridge_softc *sc, struct bridge_iflist *bif,
bridge_rtdelete(sc, ifs, IFBF_FLUSHALL);
BRIDGE_UNLOCK(sc);
bstp_drain(&bif->bif_stp); /* prepare to free */
bstp_destroy(&bif->bif_stp); /* prepare to free */
BRIDGE_LOCK(sc);
free(bif, M_DEVBUF);
}
@ -970,6 +970,7 @@ bridge_ioctl_add(struct bridge_softc *sc, void *arg)
}
ifs->if_bridge = sc;
bstp_create(&sc->sc_stp, &bif->bif_stp, bif->bif_ifp);
/*
* XXX: XLOCK HERE!?!
*
@ -1044,14 +1045,13 @@ bridge_ioctl_sifflags(struct bridge_softc *sc, void *arg)
if (req->ifbr_ifsflags & IFBIF_STP) {
if ((bif->bif_flags & IFBIF_STP) == 0) {
error = bstp_add(&sc->sc_stp, &bif->bif_stp,
bif->bif_ifp);
error = bstp_enable(&bif->bif_stp);
if (error)
return (error);
}
} else {
if ((bif->bif_flags & IFBIF_STP) != 0)
bstp_delete(&bif->bif_stp);
bstp_disable(&bif->bif_stp);
}
bif->bif_flags = req->ifbr_ifsflags;