summaryrefslogtreecommitdiff
path: root/sys/net/if_bridge.c
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2019-03-12 11:45:01 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2019-03-12 11:45:01 +0000
commitd9f16b4b3f4aa854b9c126c68e88201b998099cc (patch)
tree1db6107517a51aea7ea1c0e4e1707a844f2e4dbc /sys/net/if_bridge.c
parentc456969731f70c3030cafcfcd4a67fc5aa1cd36c (diff)
Merge copy/pasted code to export STP states via ioctl into a function.
Diffstat (limited to 'sys/net/if_bridge.c')
-rw-r--r--sys/net/if_bridge.c91
1 files changed, 38 insertions, 53 deletions
diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c
index 7b241500f96..e75c22bcba4 100644
--- a/sys/net/if_bridge.c
+++ b/sys/net/if_bridge.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_bridge.c,v 1.324 2019/03/08 17:49:36 mpi Exp $ */
+/* $OpenBSD: if_bridge.c,v 1.325 2019/03/12 11:45:00 mpi Exp $ */
/*
* Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
@@ -112,6 +112,8 @@ void bridge_spanremove(struct bridge_iflist *);
int bridge_input(struct ifnet *, struct mbuf *, void *);
void bridge_process(struct ifnet *, struct mbuf *);
void bridgeintr_frame(struct bridge_softc *, struct ifnet *, struct mbuf *);
+void bridge_bifgetstp(struct bridge_softc *, struct bridge_iflist *,
+ struct ifbreq *);
void bridge_broadcast(struct bridge_softc *, struct ifnet *,
struct ether_header *, struct mbuf *);
int bridge_localbroadcast(struct ifnet *, struct ether_header *,
@@ -423,31 +425,8 @@ bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
req->ifbr_ifsflags = bif->bif_flags;
req->ifbr_portno = bif->ifp->if_index & 0xfff;
req->ifbr_protected = bif->bif_protected;
- if (bif->bif_flags & IFBIF_STP) {
- bp = bif->bif_stp;
- req->ifbr_state = bstp_getstate(bs, bp);
- req->ifbr_priority = bp->bp_priority;
- req->ifbr_path_cost = bp->bp_path_cost;
- req->ifbr_proto = bp->bp_protover;
- req->ifbr_role = bp->bp_role;
- req->ifbr_stpflags = bp->bp_flags;
- req->ifbr_fwd_trans = bp->bp_forward_transitions;
- req->ifbr_desg_bridge = bp->bp_desg_pv.pv_dbridge_id;
- req->ifbr_desg_port = bp->bp_desg_pv.pv_dport_id;
- req->ifbr_root_bridge = bp->bp_desg_pv.pv_root_id;
- req->ifbr_root_cost = bp->bp_desg_pv.pv_cost;
- req->ifbr_root_port = bp->bp_desg_pv.pv_port_id;
-
- /* Copy STP state options as flags */
- if (bp->bp_operedge)
- req->ifbr_ifsflags |= IFBIF_BSTP_EDGE;
- if (bp->bp_flags & BSTP_PORT_AUTOEDGE)
- req->ifbr_ifsflags |= IFBIF_BSTP_AUTOEDGE;
- if (bp->bp_ptp_link)
- req->ifbr_ifsflags |= IFBIF_BSTP_PTP;
- if (bp->bp_flags & BSTP_PORT_AUTOPTP)
- req->ifbr_ifsflags |= IFBIF_BSTP_AUTOPTP;
- }
+ if (bif->bif_flags & IFBIF_STP)
+ bridge_bifgetstp(sc, bif, req);
break;
case SIOCBRDGSIFFLGS:
if ((error = suser(curproc)) != 0)
@@ -599,12 +578,41 @@ bridge_spandetach(void *xbif)
bridge_spanremove(bif);
}
+void
+bridge_bifgetstp(struct bridge_softc *sc, struct bridge_iflist *bif,
+ struct ifbreq *breq)
+{
+ struct bstp_state *bs = sc->sc_stp;
+ struct bstp_port *bp = bif->bif_stp;
+
+ breq->ifbr_state = bstp_getstate(bs, bp);
+ breq->ifbr_priority = bp->bp_priority;
+ breq->ifbr_path_cost = bp->bp_path_cost;
+ breq->ifbr_proto = bp->bp_protover;
+ breq->ifbr_role = bp->bp_role;
+ breq->ifbr_stpflags = bp->bp_flags;
+ breq->ifbr_fwd_trans = bp->bp_forward_transitions;
+ breq->ifbr_root_bridge = bs->bs_root_pv.pv_root_id;
+ breq->ifbr_root_cost = bs->bs_root_pv.pv_cost;
+ breq->ifbr_root_port = bs->bs_root_pv.pv_port_id;
+ breq->ifbr_desg_bridge = bs->bs_root_pv.pv_dbridge_id;
+ breq->ifbr_desg_port = bs->bs_root_pv.pv_dport_id;
+
+ /* Copy STP state options as flags */
+ if (bp->bp_operedge)
+ breq->ifbr_ifsflags |= IFBIF_BSTP_EDGE;
+ if (bp->bp_flags & BSTP_PORT_AUTOEDGE)
+ breq->ifbr_ifsflags |= IFBIF_BSTP_AUTOEDGE;
+ if (bp->bp_ptp_link)
+ breq->ifbr_ifsflags |= IFBIF_BSTP_PTP;
+ if (bp->bp_flags & BSTP_PORT_AUTOPTP)
+ breq->ifbr_ifsflags |= IFBIF_BSTP_AUTOPTP;
+}
+
int
bridge_bifconf(struct bridge_softc *sc, struct ifbifconf *bifc)
{
struct bridge_iflist *bif;
- struct bstp_port *bp;
- struct bstp_state *bs = sc->sc_stp;
u_int32_t total = 0, i = 0;
int error = 0;
struct ifbreq *breq, *breqs = NULL;
@@ -633,31 +641,8 @@ bridge_bifconf(struct bridge_softc *sc, struct ifbifconf *bifc)
breq->ifbr_ifsflags = bif->bif_flags;
breq->ifbr_portno = bif->ifp->if_index & 0xfff;
breq->ifbr_protected = bif->bif_protected;
- if (bif->bif_flags & IFBIF_STP) {
- bp = bif->bif_stp;
- breq->ifbr_state = bstp_getstate(sc->sc_stp, bp);
- breq->ifbr_priority = bp->bp_priority;
- breq->ifbr_path_cost = bp->bp_path_cost;
- breq->ifbr_proto = bp->bp_protover;
- breq->ifbr_role = bp->bp_role;
- breq->ifbr_stpflags = bp->bp_flags;
- breq->ifbr_fwd_trans = bp->bp_forward_transitions;
- breq->ifbr_root_bridge = bs->bs_root_pv.pv_root_id;
- breq->ifbr_root_cost = bs->bs_root_pv.pv_cost;
- breq->ifbr_root_port = bs->bs_root_pv.pv_port_id;
- breq->ifbr_desg_bridge = bs->bs_root_pv.pv_dbridge_id;
- breq->ifbr_desg_port = bs->bs_root_pv.pv_dport_id;
-
- /* Copy STP state options as flags */
- if (bp->bp_operedge)
- breq->ifbr_ifsflags |= IFBIF_BSTP_EDGE;
- if (bp->bp_flags & BSTP_PORT_AUTOEDGE)
- breq->ifbr_ifsflags |= IFBIF_BSTP_AUTOEDGE;
- if (bp->bp_ptp_link)
- breq->ifbr_ifsflags |= IFBIF_BSTP_PTP;
- if (bp->bp_flags & BSTP_PORT_AUTOPTP)
- breq->ifbr_ifsflags |= IFBIF_BSTP_AUTOPTP;
- }
+ if (bif->bif_flags & IFBIF_STP)
+ bridge_bifgetstp(sc, bif, breq);
i++;
}
SLIST_FOREACH(bif, &sc->sc_spanlist, bif_next) {