FreeBSD/sys/net/bridgestp.c
/*
 * Calculate the path cost according to the link speed.
 */
Calculate the path cost according to the link speed.
Calculate the path cost according to the link speed .
static uint32_t
bstp_calc_path_cost(struct bstp_port *bp)
{
	struct ifnet *ifp = bp->bp_ifp;
	uint32_t path_cost;
	if (bp->bp_flags & BSTP_PORT_ADMCOST)
		return bp->bp_path_cost;
	if (ifp->if_link_state == LINK_STATE_DOWN) {
		bp->bp_flags |= BSTP_PORT_PNDCOST;
		return (BSTP_DEFAULT_PATH_COST);
	}
	if (ifp->if_baudrate < 1000)
		return (BSTP_DEFAULT_PATH_COST);
	path_cost = 20000000000ULL / (ifp->if_baudrate / 1000);
	if (path_cost > BSTP_MAX_PATH_COST)
		path_cost = BSTP_MAX_PATH_COST;
	if (bp->bp_protover == BSTP_PROTO_STP && path_cost > 65535)
		path_cost = 65535;
	return (path_cost);
}
static uint32_t bstp_calc_path_cost ( struct bstp_port * bp ) { struct ifnet * ifp = bp -> bp_ifp ; uint32_t path_cost ; if ( bp -> bp_flags & BSTP_PORT_ADMCOST ) return bp -> bp_path_cost ; if ( ifp -> if_link_state == LINK_STATE_DOWN ) { bp -> bp_flags |= BSTP_PORT_PNDCOST ; return ( BSTP_DEFAULT_PATH_COST ) ; } if ( ifp -> if_baudrate < 1000 ) return ( BSTP_DEFAULT_PATH_COST ) ; path_cost = 20000000000ULL / ( ifp -> if_baudrate / 1000 ) ; if ( path_cost > BSTP_MAX_PATH_COST ) path_cost = BSTP_MAX_PATH_COST ; if ( bp -> bp_protover == BSTP_PROTO_STP && path_cost > 65535 ) path_cost = 65535 ; return ( path_cost ) ; }
Calculate the path cost according to the link speed.
Calculate the path cost according to the link speed .
/* If the priority has been manually set then retain the value */ /* Recalc when the link comes up again */ /* formula from section 17.14, IEEE Std 802.1D-2004 */ /* STP compat mode only uses 16 bits of the 32 */