Bring in support for the Rapid Spanning Tree Protocol (802.1w).

RSTP provides faster spanning tree convergence, the protocol will exchange
information with neighboring switches to quickly transition to forwarding
without creating loops. The code will default to RSTP mode but will downgrade
any port connected to a legacy STP network so is fully backward compatible.

Reviewed by:	syrinx
Tested by:	syrinx
This commit is contained in:
Andrew Thompson 2006-11-01 09:07:47 +00:00
parent 618fd0a605
commit 3fab76690c
6 changed files with 2275 additions and 1090 deletions

View File

@ -61,6 +61,27 @@ static const char rcsid[] =
#include "ifconfig.h"
static const char *stpstates[] = {
"disabled",
"listening",
"learning",
"forwarding",
"blocking",
"discarding"
};
static const char *stpproto[] = {
"stp",
"-",
"rstp"
};
static const char *stproles[] = {
"disabled",
"root",
"designated",
"alternate",
"backup"
};
static int
get_val(const char *cp, u_long *valp)
{
@ -113,13 +134,6 @@ do_bridgeflag(int sock, const char *ifs, int flag, int set)
static void
bridge_interfaces(int s, const char *prefix)
{
static const char *stpstates[] = {
"disabled",
"listening",
"learning",
"forwarding",
"blocking",
};
struct ifbifconf bifc;
struct ifbreq *req;
char *inbuf = NULL, *ninbuf;
@ -159,12 +173,35 @@ bridge_interfaces(int s, const char *prefix)
printf("port %u priority %u",
req->ifbr_portno, req->ifbr_priority);
printf(" path cost %u", req->ifbr_path_cost);
if (req->ifbr_proto <
sizeof(stpproto) / sizeof(stpproto[0]))
printf(" proto %s", stpproto[req->ifbr_proto]);
else
printf(" <unknown proto %d>",
req->ifbr_proto);
printf("\n%s", pad);
if (req->ifbr_role <
sizeof(stproles) / sizeof(stproles[0]))
printf("role %s", stproles[req->ifbr_role]);
else
printf("<unknown role %d>",
req->ifbr_role);
if (req->ifbr_state <
sizeof(stpstates) / sizeof(stpstates[0]))
printf(" %s", stpstates[req->ifbr_state]);
printf(" state %s", stpstates[req->ifbr_state]);
else
printf(" <unknown state %d>",
req->ifbr_state);
if (req->ifbr_p2p)
printf(" p2p");
else
printf(" shared");
if (req->ifbr_edge)
printf(" edge");
if (req->ifbr_autoedge)
printf(" autoedge");
printf("\n");
}
}
@ -210,28 +247,22 @@ bridge_addresses(int s, const char *prefix)
static void
bridge_status(int s)
{
struct ifbrparam param;
struct ifbropreq param;
u_int16_t pri;
u_int8_t ht, fd, ma;
u_int8_t ht, fd, ma, hc, pro;
if (do_cmd(s, BRDGGPRI, &param, sizeof(param), 0) < 0)
if (do_cmd(s, BRDGPARAM, &param, sizeof(param), 0) < 0)
return;
pri = param.ifbrp_prio;
pri = param.ifbop_priority;
pro = param.ifbop_protocol;
ht = param.ifbop_hellotime;
fd = param.ifbop_fwddelay;
hc = param.ifbop_holdcount;
ma = param.ifbop_maxage;
if (do_cmd(s, BRDGGHT, &param, sizeof(param), 0) < 0)
return;
ht = param.ifbrp_hellotime;
if (do_cmd(s, BRDGGFD, &param, sizeof(param), 0) < 0)
return;
fd = param.ifbrp_fwddelay;
if (do_cmd(s, BRDGGMA, &param, sizeof(param), 0) < 0)
return;
ma = param.ifbrp_maxage;
printf("\tpriority %u hellotime %u fwddelay %u maxage %u\n",
pri, ht, fd, ma);
printf("\tpriority %u hellotime %u fwddelay %u"
" maxage %u hc %u proto %s\n",
pri, ht, fd, ma, hc, stpproto[pro]);
bridge_interfaces(s, "\tmember: ");
@ -325,6 +356,54 @@ unsetbridge_stp(const char *val, int d, int s, const struct afswtch *afp)
do_bridgeflag(s, val, IFBIF_STP, 0);
}
static void
setbridge_edge(const char *val, int d, int s, const struct afswtch *afp)
{
struct ifbreq req;
memset(&req, 0, sizeof(req));
strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
req.ifbr_edge = 1;
if (do_cmd(s, BRDGSEDGE, &req, sizeof(req), 1) < 0)
err(1, "BRDGSEDGE %s", val);
}
static void
unsetbridge_edge(const char *val, int d, int s, const struct afswtch *afp)
{
struct ifbreq req;
memset(&req, 0, sizeof(req));
strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
req.ifbr_edge = 0;
if (do_cmd(s, BRDGSEDGE, &req, sizeof(req), 1) < 0)
err(1, "BRDGSEDGE %s", val);
}
static void
setbridge_autoedge(const char *val, int d, int s, const struct afswtch *afp)
{
struct ifbreq req;
memset(&req, 0, sizeof(req));
strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
req.ifbr_autoedge = 1;
if (do_cmd(s, BRDGSAEDGE, &req, sizeof(req), 1) < 0)
err(1, "BRDGSAEDGE %s", val);
}
static void
unsetbridge_autoedge(const char *val, int d, int s, const struct afswtch *afp)
{
struct ifbreq req;
memset(&req, 0, sizeof(req));
strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
req.ifbr_autoedge = 0;
if (do_cmd(s, BRDGSAEDGE, &req, sizeof(req), 1) < 0)
err(1, "BRDGSAEDGE %s", val);
}
static void
setbridge_flush(const char *val, int d, int s, const struct afswtch *afp)
{
@ -468,6 +547,38 @@ setbridge_priority(const char *arg, int d, int s, const struct afswtch *afp)
err(1, "BRDGSPRI %s", arg);
}
static void
setbridge_protocol(const char *arg, int d, int s, const struct afswtch *afp)
{
struct ifbrparam param;
if (strcasecmp(arg, "stp") == 0) {
param.ifbrp_proto = 0;
} else if (strcasecmp(arg, "rstp") == 0) {
param.ifbrp_proto = 2;
} else {
errx(1, "unknown stp protocol");
}
if (do_cmd(s, BRDGSPROTO, &param, sizeof(param), 1) < 0)
err(1, "BRDGSPROTO %s", arg);
}
static void
setbridge_holdcount(const char *arg, int d, int s, const struct afswtch *afp)
{
struct ifbrparam param;
u_long val;
if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
errx(1, "invalid value: %s", arg);
param.ifbrp_txhc = val & 0xff;
if (do_cmd(s, BRDGSTXHC, &param, sizeof(param), 1) < 0)
err(1, "BRDGSTXHC %s", arg);
}
static void
setbridge_ifpriority(const char *ifn, const char *pri, int s,
const struct afswtch *afp)
@ -496,11 +607,11 @@ setbridge_ifpathcost(const char *ifn, const char *cost, int s,
memset(&req, 0, sizeof(req));
if (get_val(cost, &val) < 0 || (val & ~0xff) != 0)
if (get_val(cost, &val) < 0)
errx(1, "invalid value: %s", cost);
strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname));
req.ifbr_path_cost = val & 0xffff;
req.ifbr_path_cost = val;
if (do_cmd(s, BRDGSIFCOST, &req, sizeof(req), 1) < 0)
err(1, "BRDGSIFCOST %s", cost);
@ -532,6 +643,10 @@ static struct cmd bridge_cmds[] = {
DEF_CMD_ARG("-span", unsetbridge_span),
DEF_CMD_ARG("stp", setbridge_stp),
DEF_CMD_ARG("-stp", unsetbridge_stp),
DEF_CMD_ARG("edge", setbridge_edge),
DEF_CMD_ARG("-edge", unsetbridge_edge),
DEF_CMD_ARG("autoedge", setbridge_autoedge),
DEF_CMD_ARG("-autoedge", unsetbridge_autoedge),
DEF_CMD("flush", 0, setbridge_flush),
DEF_CMD("flushall", 0, setbridge_flushall),
DEF_CMD_ARG2("static", setbridge_static),
@ -542,6 +657,8 @@ static struct cmd bridge_cmds[] = {
DEF_CMD_ARG("fwddelay", setbridge_fwddelay),
DEF_CMD_ARG("maxage", setbridge_maxage),
DEF_CMD_ARG("priority", setbridge_priority),
DEF_CMD_ARG("proto", setbridge_protocol),
DEF_CMD_ARG("holdcount", setbridge_holdcount),
DEF_CMD_ARG2("ifpriority", setbridge_ifpriority),
DEF_CMD_ARG2("ifpathcost", setbridge_ifpathcost),
DEF_CMD_ARG("timeout", setbridge_timeout),

View File

@ -1267,38 +1267,67 @@ Spanning Tree is used to detect and remove loops in a network topology.
Disable Spanning Tree protocol on
.Ar interface .
This is the default for all interfaces added to a bridge.
.It Cm edge Ar interface
Set
.Ar interface
as an edge port.
An edge port connects directly to end stations cannot create bridging
loops in the network, this allows it to transition straight to forwarding.
.It Cm -edge Ar interface
Disable edge status on
.Ar interface .
.It Cm autoedge Ar interface
Allow
.Ar interface
to automatically detect edge status.
This is the default for all interfaces added to a bridge.
.It Cm -autoedge Ar interface
Disable automatic edge status on
.Ar interface .
.It Cm maxage Ar seconds
Set the time that a Spanning Tree protocol configuration is valid.
The default is 20 seconds.
The minimum is 1 second and the maximum is 255 seconds.
The minimum is 6 seconds and the maximum is 40 seconds.
.It Cm fwddelay Ar seconds
Set the time that must pass before an interface begins forwarding
packets when Spanning Tree is enabled.
The default is 15 seconds.
The minimum is 1 second and the maximum is 255 seconds.
The minimum is 4 seconds and the maximum is 30 seconds.
.It Cm hellotime Ar seconds
Set the time between broadcasting of Spanning Tree protocol
configuration messages.
The hello time may only be changed when operating in legacy stp mode.
The default is 2 seconds.
The minimum is 1 second and the maximum is 255 seconds.
The minimum is 1 second and the maximum is 2 seconds.
.It Cm priority Ar value
Set the bridge priority for Spanning Tree.
The default is 32768.
The minimum is 0 and the maximum is 65536.
The minimum is 0 and the maximum is 61440.
.It Cm protocol Ar value
Set the Spanning Tree protocol.
The default is rstp.
The available options are stp and rstp.
.It Cm holdcount Ar value
Set the transmit hold count for Spanning Tree.
This is the number of packets transmitted before being rate limited.
The default is 6.
The minimum is 1 and the maximum is 10.
.It Cm ifpriority Ar interface Ar value
Set the Spanning Tree priority of
.Ar interface
to
.Ar value .
The default is 128.
The minimum is 0 and the maximum is 255.
The minimum is 0 and the maximum is 240.
.It Cm ifpathcost Ar interface Ar value
Set the Spanning Tree path cost of
.Ar interface
to
.Ar value .
The default is 55.
The minimum is 0 and the maximum is 65535.
The default is calculated from the link speed.
To change a previously selected path cost back to automatic, set the
cost to 0.
The minimum is 1 and the maximum is 200000000.
.El
.Pp
The following parameters are specific to IP tunnel interfaces,

File diff suppressed because it is too large Load Diff

View File

@ -83,9 +83,56 @@
#define BSTP_IFSTATE_LEARNING 2
#define BSTP_IFSTATE_FORWARDING 3
#define BSTP_IFSTATE_BLOCKING 4
#define BSTP_IFSTATE_DISCARDING 5
#define BSTP_TCSTATE_ACTIVE 1
#define BSTP_TCSTATE_DETECTED 2
#define BSTP_TCSTATE_INACTIVE 3
#define BSTP_TCSTATE_LEARNING 4
#define BSTP_TCSTATE_PROPAG 5
#define BSTP_TCSTATE_ACK 6
#define BSTP_TCSTATE_TC 7
#define BSTP_TCSTATE_TCN 8
#define BSTP_ROLE_DISABLED 0
#define BSTP_ROLE_ROOT 1
#define BSTP_ROLE_DESIGNATED 2
#define BSTP_ROLE_ALTERNATE 3
#define BSTP_ROLE_BACKUP 4
#ifdef _KERNEL
/* STP port flags */
#define BSTP_PORT_CANMIGRATE 0x0001
#define BSTP_PORT_NEWINFO 0x0002
#define BSTP_PORT_DISPUTED 0x0004
#define BSTP_PORT_ADMCOST 0x0008
#define BSTP_PORT_AUTOEDGE 0x0010
/* BPDU priority */
#define BSTP_PDU_SUPERIOR 1
#define BSTP_PDU_REPEATED 2
#define BSTP_PDU_INFERIOR 3
#define BSTP_PDU_INFERIORALT 4
#define BSTP_PDU_OTHER 5
/* BPDU flags */
#define BSTP_PDU_PRMASK 0x0c /* Port Role */
#define BSTP_PDU_PRSHIFT 2 /* Port Role offset */
#define BSTP_PDU_F_UNKN 0x00 /* Unknown port (00) */
#define BSTP_PDU_F_ALT 0x01 /* Alt/Backup port (01) */
#define BSTP_PDU_F_ROOT 0x02 /* Root port (10) */
#define BSTP_PDU_F_DESG 0x03 /* Designated port (11) */
#define BSTP_PDU_STPMASK 0x81 /* strip unused STP flags */
#define BSTP_PDU_RSTPMASK 0x7f /* strip unused RSTP flags */
#define BSTP_PDU_F_TC 0x01 /* Topology change */
#define BSTP_PDU_F_P 0x02 /* Proposal flag */
#define BSTP_PDU_F_L 0x10 /* Learning flag */
#define BSTP_PDU_F_F 0x20 /* Forwarding flag */
#define BSTP_PDU_F_A 0x40 /* Agreement flag */
#define BSTP_PDU_F_TCA 0x80 /* Topology change ack */
/*
* Spanning tree defaults.
*/
@ -93,26 +140,49 @@
#define BSTP_DEFAULT_HELLO_TIME (2 * 256)
#define BSTP_DEFAULT_FORWARD_DELAY (15 * 256)
#define BSTP_DEFAULT_HOLD_TIME (1 * 256)
#define BSTP_DEFAULT_MIGRATE_DELAY (3 * 256)
#define BSTP_DEFAULT_HOLD_COUNT 6
#define BSTP_DEFAULT_BRIDGE_PRIORITY 0x8000
#define BSTP_DEFAULT_PORT_PRIORITY 0x80
#define BSTP_DEFAULT_PATH_COST 55
#define BSTP_MIN_HELLO_TIME (1 * 256)
#define BSTP_MIN_MAX_AGE (6 * 256)
#define BSTP_MIN_FORWARD_DELAY (4 * 256)
#define BSTP_MIN_HOLD_COUNT 1
#define BSTP_MAX_HELLO_TIME (2 * 256)
#define BSTP_MAX_MAX_AGE (40 * 256)
#define BSTP_MAX_FORWARD_DELAY (30 * 256)
#define BSTP_MAX_HOLD_COUNT 10
#define BSTP_MAX_PRIORITY 61440
#define BSTP_MAX_PORT_PRIORITY 240
#define BSTP_MAX_PATH_COST 200000000
/* BPDU message types */
#define BSTP_MSGTYPE_CFG 0x00 /* Configuration */
#define BSTP_MSGTYPE_RSTP 0x02 /* Rapid STP */
#define BSTP_MSGTYPE_TCN 0x80 /* Topology chg notification */
/* BPDU flags */
#define BSTP_FLAG_TC 0x01 /* Topology change */
#define BSTP_FLAG_TCA 0x80 /* Topology change ack */
/* Protocol versions */
#define BSTP_PROTO_ID 0x00
#define BSTP_PROTO_STP 0x00
#define BSTP_PROTO_RSTP 0x02
#define BSTP_PROTO_MAX BSTP_PROTO_RSTP
#define BSTP_INFO_RECIEVED 1
#define BSTP_INFO_MINE 2
#define BSTP_INFO_AGED 3
#define BSTP_INFO_DISABLED 4
#define BSTP_MESSAGE_AGE_INCR (1 * 256) /* in 256ths of a second */
#define BSTP_TICK_VAL (1 * 256) /* in 256ths of a second */
#define BSTP_LINK_TIMER (BSTP_TICK_VAL * 30)
#define BSTP_LINK_TIMER (BSTP_TICK_VAL * 15)
/*
* * Driver callbacks for STP state changes
* */
* Driver callbacks for STP state changes
*/
typedef void (*bstp_state_cb_t)(struct ifnet *, int);
typedef void (*bstp_rtage_cb_t)(struct ifnet *, int);
/*
* Because BPDU's do not make nicely aligned structures, two different
@ -132,7 +202,7 @@ struct bstp_cbpdu {
/* root id */
uint16_t cbu_rootpri; /* root priority */
uint8_t cbu_rootaddr[6]; /* root address */
uint8_t cbu_rootaddr[6]; /* root address */
uint32_t cbu_rootpathcost; /* root path cost */
@ -145,7 +215,10 @@ struct bstp_cbpdu {
uint16_t cbu_maxage; /* maximum age */
uint16_t cbu_hellotime; /* hello time */
uint16_t cbu_forwarddelay; /* forwarding delay */
uint8_t cbu_versionlen; /* version 1 length */
} __attribute__((__packed__));
#define BSTP_BPDU_STP_LEN (3 + 35) /* LLC + STP pdu */
#define BSTP_BPDU_RSTP_LEN (3 + 36) /* LLC + RSTP pdu */
/* topology change notification bridge protocol data unit */
struct bstp_tbpdu {
@ -161,53 +234,91 @@ struct bstp_tbpdu {
* Timekeeping structure used in spanning tree code.
*/
struct bstp_timer {
uint16_t active;
uint16_t value;
int active;
int latched;
int value;
};
struct bstp_pri_vector {
uint64_t pv_root_id;
uint32_t pv_cost;
uint64_t pv_dbridge_id;
uint16_t pv_dport_id;
uint16_t pv_port_id;
};
struct bstp_config_unit {
uint64_t cu_rootid;
uint64_t cu_bridge_id;
uint32_t cu_root_path_cost;
struct bstp_pri_vector cu_pv;
uint16_t cu_message_age;
uint16_t cu_max_age;
uint16_t cu_hello_time;
uint16_t cu_forward_delay;
uint16_t cu_port_id;
uint16_t cu_hello_time;
uint8_t cu_message_type;
uint8_t cu_topology_change_acknowledgment;
uint8_t cu_topology_change_ack;
uint8_t cu_topology_change;
uint8_t cu_proposal;
uint8_t cu_agree;
uint8_t cu_learning;
uint8_t cu_forwarding;
uint8_t cu_role;
};
struct bstp_tcn_unit {
uint8_t tu_message_type;
};
/*
* Bridge interface list entry.
*/
struct bstp_port {
LIST_ENTRY(bstp_port) bp_next;
struct ifnet *bp_ifp; /* parent if */
struct bstp_state *bp_bs;
int bp_active;
uint64_t bp_designated_root;
uint64_t bp_designated_bridge;
uint8_t bp_active;
uint8_t bp_protover;
uint32_t bp_flags;
uint32_t bp_path_cost;
uint32_t bp_designated_cost;
struct bstp_timer bp_hold_timer;
struct bstp_timer bp_message_age_timer;
uint16_t bp_port_msg_age;
uint16_t bp_port_max_age;
uint16_t bp_port_fdelay;
uint16_t bp_port_htime;
uint16_t bp_desg_msg_age;
uint16_t bp_desg_max_age;
uint16_t bp_desg_fdelay;
uint16_t bp_desg_htime;
struct bstp_timer bp_edge_delay_timer;
struct bstp_timer bp_forward_delay_timer;
struct bstp_config_unit bp_config_bpdu;
struct bstp_timer bp_hello_timer;
struct bstp_timer bp_message_age_timer;
struct bstp_timer bp_migrate_delay_timer;
struct bstp_timer bp_recent_backup_timer;
struct bstp_timer bp_recent_root_timer;
struct bstp_timer bp_tc_timer;
struct bstp_config_unit bp_msg_cu;
struct bstp_pri_vector bp_desg_pv;
struct bstp_pri_vector bp_port_pv;
uint16_t bp_port_id;
uint16_t bp_designated_port;
uint8_t bp_state;
uint8_t bp_topology_change_acknowledge;
uint8_t bp_config_pending;
uint8_t bp_change_detection_enabled;
uint8_t bp_tcstate;
uint8_t bp_role;
uint8_t bp_infois;
uint8_t bp_tc_ack;
uint8_t bp_tc_prop;
uint8_t bp_fdbflush;
uint8_t bp_priority;
uint8_t bp_p2p_link;
uint8_t bp_agree;
uint8_t bp_agreed;
uint8_t bp_sync;
uint8_t bp_synced;
uint8_t bp_proposing;
uint8_t bp_proposed;
uint8_t bp_operedge;
uint8_t bp_reroot;
uint8_t bp_rcvdtc;
uint8_t bp_rcvdtca;
uint8_t bp_rcvdtcn;
uint32_t bp_forward_transitions;
uint8_t bp_txcount;
struct task bp_statetask;
struct task bp_rtagetask;
};
/*
@ -216,51 +327,59 @@ struct bstp_port {
struct bstp_state {
LIST_ENTRY(bstp_state) bs_list;
struct mtx bs_mtx;
uint64_t bs_designated_root;
uint64_t bs_bridge_id;
struct bstp_pri_vector bs_bridge_pv;
struct bstp_pri_vector bs_root_pv;
struct bstp_port *bs_root_port;
uint32_t bs_root_path_cost;
uint16_t bs_max_age;
uint16_t bs_hello_time;
uint16_t bs_forward_delay;
uint8_t bs_protover;
uint16_t bs_migration_delay;
uint16_t bs_edge_delay;
uint16_t bs_bridge_max_age;
uint16_t bs_bridge_hello_time;
uint16_t bs_bridge_forward_delay;
uint16_t bs_topology_change_time;
uint16_t bs_bridge_fdelay;
uint16_t bs_bridge_htime;
uint16_t bs_root_msg_age;
uint16_t bs_root_max_age;
uint16_t bs_root_fdelay;
uint16_t bs_root_htime;
uint16_t bs_hold_time;
uint16_t bs_bridge_priority;
uint8_t bs_topology_change_detected;
uint8_t bs_topology_change;
struct bstp_timer bs_hello_timer;
struct bstp_timer bs_topology_change_timer;
struct bstp_timer bs_tcn_timer;
uint8_t bs_txholdcount;
uint8_t bs_allsynced;
struct callout bs_bstpcallout; /* STP callout */
struct bstp_timer bs_link_timer;
struct timeval bs_last_tc_time;
LIST_HEAD(, bstp_port) bs_bplist;
bstp_state_cb_t bs_state_cb;
bstp_rtage_cb_t bs_rtage_cb;
};
#define BSTP_LOCK_INIT(_bs) mtx_init(&(_bs)->bs_mtx, "bstp", \
NULL, MTX_DEF)
#define BSTP_LOCK_DESTROY(_bs) mtx_destroy(&(_bs)->bs_mtx)
#define BSTP_LOCK(_bs) mtx_lock(&(_bs)->bs_mtx)
#define BSTP_UNLOCK(_bs) mtx_unlock(&(_bs)->bs_mtx)
#define BSTP_LOCK_ASSERT(_bs) mtx_assert(&(_bs)->bs_mtx, MA_OWNED)
#define BSTP_LOCK_INIT(_bs) mtx_init(&(_bs)->bs_mtx, "bstp", NULL, MTX_DEF)
#define BSTP_LOCK_DESTROY(_bs) mtx_destroy(&(_bs)->bs_mtx)
#define BSTP_LOCK(_bs) mtx_lock(&(_bs)->bs_mtx)
#define BSTP_UNLOCK(_bs) mtx_unlock(&(_bs)->bs_mtx)
#define BSTP_LOCK_ASSERT(_bs) mtx_assert(&(_bs)->bs_mtx, MA_OWNED)
extern const uint8_t bstp_etheraddr[];
extern void (*bstp_linkstate_p)(struct ifnet *ifp, int state);
void bstp_attach(struct bstp_state *, bstp_state_cb_t);
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_reinit(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 *);
void bstp_linkstate(struct ifnet *, int);
int bstp_set_htime(struct bstp_state *, int);
int bstp_set_fdelay(struct bstp_state *, int);
int bstp_set_maxage(struct bstp_state *, int);
int bstp_set_holdcount(struct bstp_state *, int);
int bstp_set_protocol(struct bstp_state *, int);
int bstp_set_priority(struct bstp_state *, int);
int bstp_set_port_priority(struct bstp_port *, int);
int bstp_set_path_cost(struct bstp_port *, uint32_t);
int bstp_set_edge(struct bstp_port *, int);
int bstp_set_autoedge(struct bstp_port *, int);
struct mbuf *bstp_input(struct bstp_port *, struct ifnet *, struct mbuf *);
#endif /* _KERNEL */

View File

@ -266,6 +266,7 @@ static int bridge_rtnode_insert(struct bridge_softc *,
struct bridge_rtnode *);
static void bridge_rtnode_destroy(struct bridge_softc *,
struct bridge_rtnode *);
static void bridge_rtable_expire(struct ifnet *, int);
static void bridge_state_change(struct ifnet *, int);
static struct bridge_iflist *bridge_lookup_member(struct bridge_softc *,
@ -305,6 +306,10 @@ static int bridge_ioctl_delspan(struct bridge_softc *, void *);
static int bridge_ioctl_gbparam(struct bridge_softc *, void *);
static int bridge_ioctl_grte(struct bridge_softc *, void *);
static int bridge_ioctl_gifsstp(struct bridge_softc *, void *);
static int bridge_ioctl_sproto(struct bridge_softc *, void *);
static int bridge_ioctl_stxhc(struct bridge_softc *, void *);
static int bridge_ioctl_sedge(struct bridge_softc *, void *);
static int bridge_ioctl_saedge(struct bridge_softc *, void *);
static int bridge_pfil(struct mbuf **, struct ifnet *, struct ifnet *,
int);
static int bridge_ip_checkbasic(struct mbuf **mp);
@ -418,6 +423,18 @@ const struct bridge_control bridge_control_table[] = {
{ bridge_ioctl_gifsstp, sizeof(struct ifbpstpconf),
BC_F_COPYOUT },
{ bridge_ioctl_sproto, sizeof(struct ifbrparam),
BC_F_COPYIN|BC_F_SUSER },
{ bridge_ioctl_stxhc, sizeof(struct ifbrparam),
BC_F_COPYIN|BC_F_SUSER },
{ bridge_ioctl_sedge, sizeof(struct ifbreq),
BC_F_COPYIN|BC_F_SUSER },
{ bridge_ioctl_saedge, sizeof(struct ifbreq),
BC_F_COPYIN|BC_F_SUSER },
};
const int bridge_control_table_size =
sizeof(bridge_control_table) / sizeof(bridge_control_table[0]);
@ -531,7 +548,6 @@ bridge_clone_create(struct if_clone *ifc, int unit, caddr_t params)
sc->sc_brtmax = BRIDGE_RTABLE_MAX;
sc->sc_brttimeout = BRIDGE_RTABLE_TIMEOUT;
getmicrotime(&(sc->sc_stp.bs_last_tc_time));
/* Initialize our routing table. */
bridge_rtable_init(sc);
@ -574,7 +590,7 @@ bridge_clone_create(struct if_clone *ifc, int unit, caddr_t params)
mtx_unlock(&bridge_list_mtx);
}
bstp_attach(&sc->sc_stp, bridge_state_change);
bstp_attach(&sc->sc_stp, bridge_state_change, bridge_rtable_expire);
ether_ifattach(ifp, eaddr);
/* Now undo some of the damage... */
ifp->if_baudrate = 0;
@ -988,16 +1004,24 @@ bridge_ioctl_gifflags(struct bridge_softc *sc, void *arg)
{
struct ifbreq *req = arg;
struct bridge_iflist *bif;
struct bstp_port *bp;
bif = bridge_lookup_member(sc, req->ifbr_ifsname);
if (bif == NULL)
return (ENOENT);
bp = &bif->bif_stp;
req->ifbr_ifsflags = bif->bif_flags;
req->ifbr_state = bif->bif_stp.bp_state;
req->ifbr_priority = bif->bif_stp.bp_priority;
req->ifbr_path_cost = bif->bif_stp.bp_path_cost;
req->ifbr_portno = bif->bif_ifp->if_index & 0xff;
req->ifbr_state = bp->bp_state;
req->ifbr_priority = bp->bp_priority;
req->ifbr_path_cost = bp->bp_path_cost;
req->ifbr_portno = bif->bif_ifp->if_index & 0xfff;
req->ifbr_proto = bp->bp_protover;
req->ifbr_role = bp->bp_role;
req->ifbr_stpflags = bp->bp_flags;
req->ifbr_edge = bp->bp_operedge;
req->ifbr_autoedge = (bp->bp_flags & BSTP_PORT_AUTOEDGE) ? 1 : 0;
req->ifbr_p2p = bp->bp_p2p_link;
return (0);
}
@ -1060,6 +1084,7 @@ bridge_ioctl_gifs(struct bridge_softc *sc, void *arg)
{
struct ifbifconf *bifc = arg;
struct bridge_iflist *bif;
struct bstp_port *bp;
struct ifbreq breq;
int count, len, error = 0;
@ -1083,11 +1108,18 @@ bridge_ioctl_gifs(struct bridge_softc *sc, void *arg)
strlcpy(breq.ifbr_ifsname, bif->bif_ifp->if_xname,
sizeof(breq.ifbr_ifsname));
bp = &bif->bif_stp;
breq.ifbr_ifsflags = bif->bif_flags;
breq.ifbr_state = bif->bif_stp.bp_state;
breq.ifbr_priority = bif->bif_stp.bp_priority;
breq.ifbr_path_cost = bif->bif_stp.bp_path_cost;
breq.ifbr_portno = bif->bif_ifp->if_index & 0xff;
breq.ifbr_state = bp->bp_state;
breq.ifbr_priority = bp->bp_priority;
breq.ifbr_path_cost = bp->bp_path_cost;
breq.ifbr_portno = bif->bif_ifp->if_index & 0xfff;
breq.ifbr_proto = bp->bp_protover;
breq.ifbr_role = bp->bp_role;
breq.ifbr_stpflags = bp->bp_flags;
breq.ifbr_edge = bp->bp_operedge;
breq.ifbr_autoedge = (bp->bp_flags & BSTP_PORT_AUTOEDGE) ? 1:0;
breq.ifbr_p2p = bp->bp_p2p_link;
error = copyout(&breq, bifc->ifbic_req + count, sizeof(breq));
if (error)
break;
@ -1101,10 +1133,7 @@ bridge_ioctl_gifs(struct bridge_softc *sc, void *arg)
strlcpy(breq.ifbr_ifsname, bif->bif_ifp->if_xname,
sizeof(breq.ifbr_ifsname));
breq.ifbr_ifsflags = bif->bif_flags;
breq.ifbr_state = bif->bif_stp.bp_state;
breq.ifbr_priority = bif->bif_stp.bp_priority;
breq.ifbr_path_cost = bif->bif_stp.bp_path_cost;
breq.ifbr_portno = bif->bif_ifp->if_index & 0xff;
breq.ifbr_portno = bif->bif_ifp->if_index & 0xfff;
error = copyout(&breq, bifc->ifbic_req + count, sizeof(breq));
if (error)
break;
@ -1219,12 +1248,8 @@ static int
bridge_ioctl_spri(struct bridge_softc *sc, void *arg)
{
struct ifbrparam *param = arg;
struct bstp_state *bs = &sc->sc_stp;
bs->bs_bridge_priority = param->ifbrp_prio;
bstp_reinit(bs);
return (0);
return (bstp_set_priority(&sc->sc_stp, param->ifbrp_prio));
}
static int
@ -1233,7 +1258,7 @@ bridge_ioctl_ght(struct bridge_softc *sc, void *arg)
struct ifbrparam *param = arg;
struct bstp_state *bs = &sc->sc_stp;
param->ifbrp_hellotime = bs->bs_bridge_hello_time >> 8;
param->ifbrp_hellotime = bs->bs_bridge_htime >> 8;
return (0);
}
@ -1241,14 +1266,8 @@ static int
bridge_ioctl_sht(struct bridge_softc *sc, void *arg)
{
struct ifbrparam *param = arg;
struct bstp_state *bs = &sc->sc_stp;
if (param->ifbrp_hellotime == 0)
return (EINVAL);
bs->bs_bridge_hello_time = param->ifbrp_hellotime << 8;
bstp_reinit(bs);
return (0);
return (bstp_set_htime(&sc->sc_stp, param->ifbrp_hellotime));
}
static int
@ -1257,7 +1276,7 @@ bridge_ioctl_gfd(struct bridge_softc *sc, void *arg)
struct ifbrparam *param = arg;
struct bstp_state *bs = &sc->sc_stp;
param->ifbrp_fwddelay = bs->bs_bridge_forward_delay >> 8;
param->ifbrp_fwddelay = bs->bs_bridge_fdelay >> 8;
return (0);
}
@ -1265,14 +1284,8 @@ static int
bridge_ioctl_sfd(struct bridge_softc *sc, void *arg)
{
struct ifbrparam *param = arg;
struct bstp_state *bs = &sc->sc_stp;
if (param->ifbrp_fwddelay == 0)
return (EINVAL);
bs->bs_bridge_forward_delay = param->ifbrp_fwddelay << 8;
bstp_reinit(bs);
return (0);
return (bstp_set_fdelay(&sc->sc_stp, param->ifbrp_fwddelay));
}
static int
@ -1289,14 +1302,8 @@ static int
bridge_ioctl_sma(struct bridge_softc *sc, void *arg)
{
struct ifbrparam *param = arg;
struct bstp_state *bs = &sc->sc_stp;
if (param->ifbrp_maxage == 0)
return (EINVAL);
bs->bs_bridge_max_age = param->ifbrp_maxage << 8;
bstp_reinit(bs);
return (0);
return (bstp_set_maxage(&sc->sc_stp, param->ifbrp_maxage));
}
static int
@ -1309,10 +1316,7 @@ bridge_ioctl_sifprio(struct bridge_softc *sc, void *arg)
if (bif == NULL)
return (ENOENT);
bif->bif_stp.bp_priority = req->ifbr_priority;
bstp_reinit(&sc->sc_stp);
return (0);
return (bstp_set_port_priority(&bif->bif_stp, req->ifbr_priority));
}
static int
@ -1325,10 +1329,7 @@ bridge_ioctl_sifcost(struct bridge_softc *sc, void *arg)
if (bif == NULL)
return (ENOENT);
bif->bif_stp.bp_path_cost = req->ifbr_path_cost;
bstp_reinit(&sc->sc_stp);
return (0);
return (bstp_set_path_cost(&bif->bif_stp, req->ifbr_path_cost));
}
static int
@ -1397,22 +1398,26 @@ static int
bridge_ioctl_gbparam(struct bridge_softc *sc, void *arg)
{
struct ifbropreq *req = arg;
struct bstp_state *bs = &sc->sc_stp;
struct bstp_port *root_port;
req->ifbop_maxage = sc->sc_stp.bs_max_age;
req->ifbop_hellotime = sc->sc_stp.bs_hello_time;
req->ifbop_fwddelay = sc->sc_stp.bs_forward_delay;
req->ifbop_maxage = bs->bs_bridge_max_age >> 8;
req->ifbop_hellotime = bs->bs_bridge_htime >> 8;
req->ifbop_fwddelay = bs->bs_bridge_fdelay >> 8;
root_port = sc->sc_stp.bs_root_port;
root_port = bs->bs_root_port;
if (root_port == NULL)
req->ifbop_root_port = 0;
else
req->ifbop_root_port = root_port->bp_ifp->if_index;
req->ifbop_root_path_cost = sc->sc_stp.bs_root_path_cost;
req->ifbop_designated_root = sc->sc_stp.bs_designated_root;
req->ifbop_last_tc_time.tv_sec = sc->sc_stp.bs_last_tc_time.tv_sec;
req->ifbop_last_tc_time.tv_usec = sc->sc_stp.bs_last_tc_time.tv_usec;
req->ifbop_holdcount = bs->bs_txholdcount;
req->ifbop_priority = bs->bs_bridge_priority;
req->ifbop_protocol = bs->bs_protover;
req->ifbop_root_path_cost = bs->bs_root_pv.pv_cost;
req->ifbop_designated_root = bs->bs_root_pv.pv_root_id;
req->ifbop_last_tc_time.tv_sec = bs->bs_last_tc_time.tv_sec;
req->ifbop_last_tc_time.tv_usec = bs->bs_last_tc_time.tv_usec;
return (0);
}
@ -1431,6 +1436,7 @@ bridge_ioctl_gifsstp(struct bridge_softc *sc, void *arg)
{
struct ifbpstpconf *bifstp = arg;
struct bridge_iflist *bif;
struct bstp_port *bp;
struct ifbpstpreq bpreq;
int count, len, error = 0;
@ -1455,12 +1461,13 @@ bridge_ioctl_gifsstp(struct bridge_softc *sc, void *arg)
if ((bif->bif_flags & IFBIF_STP) == 0)
continue;
bpreq.ifbp_portno = bif->bif_ifp->if_index & 0xff;
bpreq.ifbp_fwd_trans = bif->bif_stp.bp_forward_transitions;
bpreq.ifbp_design_cost = bif->bif_stp.bp_designated_cost;
bpreq.ifbp_design_port = bif->bif_stp.bp_designated_port;
bpreq.ifbp_design_bridge = bif->bif_stp.bp_designated_bridge;
bpreq.ifbp_design_root = bif->bif_stp.bp_designated_root;
bp = &bif->bif_stp;
bpreq.ifbp_portno = bif->bif_ifp->if_index & 0xfff;
bpreq.ifbp_fwd_trans = bp->bp_forward_transitions;
bpreq.ifbp_design_cost = bp->bp_desg_pv.pv_cost;
bpreq.ifbp_design_port = bp->bp_desg_pv.pv_port_id;
bpreq.ifbp_design_bridge = bp->bp_desg_pv.pv_dbridge_id;
bpreq.ifbp_design_root = bp->bp_desg_pv.pv_root_id;
error = copyout(&bpreq, bifstp->ifbpstp_req + count,
sizeof(bpreq));
@ -1475,6 +1482,48 @@ bridge_ioctl_gifsstp(struct bridge_softc *sc, void *arg)
return (error);
}
static int
bridge_ioctl_sproto(struct bridge_softc *sc, void *arg)
{
struct ifbrparam *param = arg;
return (bstp_set_protocol(&sc->sc_stp, param->ifbrp_proto));
}
static int
bridge_ioctl_stxhc(struct bridge_softc *sc, void *arg)
{
struct ifbrparam *param = arg;
return (bstp_set_holdcount(&sc->sc_stp, param->ifbrp_txhc));
}
static int
bridge_ioctl_sedge(struct bridge_softc *sc, void *arg)
{
struct ifbreq *req = arg;
struct bridge_iflist *bif;
bif = bridge_lookup_member(sc, req->ifbr_ifsname);
if (bif == NULL)
return (ENOENT);
return (bstp_set_edge(&bif->bif_stp, req->ifbr_edge));
}
static int
bridge_ioctl_saedge(struct bridge_softc *sc, void *arg)
{
struct ifbreq *req = arg;
struct bridge_iflist *bif;
bif = bridge_lookup_member(sc, req->ifbr_ifsname);
if (bif == NULL)
return (ENOENT);
return (bstp_set_autoedge(&bif->bif_stp, req->ifbr_autoedge));
}
/*
* bridge_ifdetach:
*
@ -1716,15 +1765,9 @@ bridge_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *sa,
* tree, make sure the port is in a state that
* allows forwarding.
*/
if (dst_if != ifp &&
(bif->bif_flags & IFBIF_STP) != 0) {
switch (bif->bif_stp.bp_state) {
case BSTP_IFSTATE_BLOCKING:
case BSTP_IFSTATE_LISTENING:
case BSTP_IFSTATE_DISABLED:
continue;
}
}
if (dst_if != ifp && (bif->bif_flags & IFBIF_STP) &&
bif->bif_stp.bp_state == BSTP_IFSTATE_DISCARDING)
continue;
if (LIST_NEXT(bif, bif_next) == NULL) {
used = 1;
@ -1834,15 +1877,11 @@ bridge_forward(struct bridge_softc *sc, struct mbuf *m)
return;
}
if (bif->bif_flags & IFBIF_STP) {
switch (bif->bif_stp.bp_state) {
case BSTP_IFSTATE_BLOCKING:
case BSTP_IFSTATE_LISTENING:
case BSTP_IFSTATE_DISABLED:
BRIDGE_UNLOCK(sc);
m_freem(m);
return;
}
if ((bif->bif_flags & IFBIF_STP) &&
bif->bif_stp.bp_state == BSTP_IFSTATE_DISCARDING) {
BRIDGE_UNLOCK(sc);
m_freem(m);
return;
}
eh = mtod(m, struct ether_header *);
@ -1941,14 +1980,11 @@ bridge_forward(struct bridge_softc *sc, struct mbuf *m)
return;
}
if (bif->bif_flags & IFBIF_STP) {
switch (bif->bif_stp.bp_state) {
case BSTP_IFSTATE_DISABLED:
case BSTP_IFSTATE_BLOCKING:
BRIDGE_UNLOCK(sc);
m_freem(m);
return;
}
if ((bif->bif_flags & IFBIF_STP) &&
bif->bif_stp.bp_state == BSTP_IFSTATE_DISCARDING) {
BRIDGE_UNLOCK(sc);
m_freem(m);
return;
}
BRIDGE_UNLOCK(sc);
@ -2040,14 +2076,10 @@ bridge_input(struct ifnet *ifp, struct mbuf *m)
}
}
if (bif->bif_flags & IFBIF_STP) {
switch (bif->bif_stp.bp_state) {
case BSTP_IFSTATE_BLOCKING:
case BSTP_IFSTATE_LISTENING:
case BSTP_IFSTATE_DISABLED:
BRIDGE_UNLOCK(sc);
return (m);
}
if ((bif->bif_flags & IFBIF_STP) &&
bif->bif_stp.bp_state == BSTP_IFSTATE_DISCARDING) {
BRIDGE_UNLOCK(sc);
return (m);
}
if (bcmp(etherbroadcastaddr, eh->ether_dhost,
@ -2093,14 +2125,10 @@ bridge_input(struct ifnet *ifp, struct mbuf *m)
return (m);
}
if (bif->bif_flags & IFBIF_STP) {
switch (bif->bif_stp.bp_state) {
case BSTP_IFSTATE_BLOCKING:
case BSTP_IFSTATE_LISTENING:
case BSTP_IFSTATE_DISABLED:
BRIDGE_UNLOCK(sc);
return (m);
}
if ((bif->bif_flags & IFBIF_STP) &&
bif->bif_stp.bp_state == BSTP_IFSTATE_DISCARDING) {
BRIDGE_UNLOCK(sc);
return (m);
}
/*
@ -2186,13 +2214,9 @@ bridge_broadcast(struct bridge_softc *sc, struct ifnet *src_if,
if (dst_if == src_if)
continue;
if (bif->bif_flags & IFBIF_STP) {
switch (bif->bif_stp.bp_state) {
case BSTP_IFSTATE_BLOCKING:
case BSTP_IFSTATE_DISABLED:
continue;
}
}
if ((bif->bif_flags & IFBIF_STP) &&
bif->bif_stp.bp_state == BSTP_IFSTATE_DISCARDING)
continue;
if ((bif->bif_flags & IFBIF_DISCOVER) == 0 &&
(m->m_flags & (M_BCAST|M_MCAST)) == 0)
@ -2652,6 +2676,37 @@ bridge_rtnode_destroy(struct bridge_softc *sc, struct bridge_rtnode *brt)
uma_zfree(bridge_rtnode_zone, brt);
}
/*
* bridge_rtable_expire:
*
* Set the expiry time for all routes on an interface.
*/
static void
bridge_rtable_expire(struct ifnet *ifp, int age)
{
struct bridge_softc *sc = ifp->if_bridge;
struct bridge_rtnode *brt;
BRIDGE_LOCK(sc);
/*
* If the age is zero then flush, otherwise set all the expiry times to
* age for the interface
*/
if (age == 0)
bridge_rtdelete(sc, ifp, IFBF_FLUSHDYN);
else {
LIST_FOREACH(brt, &sc->sc_rtlist, brt_list) {
/* Cap the expiry time to 'age' */
if (brt->brt_ifp == ifp &&
brt->brt_expire > time_uptime + age &&
(brt->brt_flags & IFBAF_TYPEMASK) == IFBAF_DYNAMIC)
brt->brt_expire = time_uptime + age;
}
}
BRIDGE_UNLOCK(sc);
}
/*
* bridge_state_change:
*
@ -2667,20 +2722,12 @@ bridge_state_change(struct ifnet *ifp, int state)
"learning",
"forwarding",
"blocking",
"discarding"
};
if (log_stp)
log(LOG_NOTICE, "%s: state changed to %s on %s\n",
sc->sc_ifp->if_xname, stpstates[state], ifp->if_xname);
/* if the port is blocking then remove any routes to it */
switch (state) {
case BSTP_IFSTATE_DISABLED:
case BSTP_IFSTATE_BLOCKING:
BRIDGE_LOCK(sc);
bridge_rtdelete(sc, ifp, IFBF_FLUSHDYN);
BRIDGE_UNLOCK(sc);
}
}
/*

View File

@ -112,6 +112,10 @@
#define BRDGGRTE 26 /* get cache drops (ifbrparam) */
#define BRDGGIFSSTP 27 /* get member STP params list
* (ifbpstpconf) */
#define BRDGSPROTO 28 /* set protocol (ifbrparam) */
#define BRDGSTXHC 29 /* set tx hold count (ifbrparam) */
#define BRDGSEDGE 30 /* set edge status (ifbreq) */
#define BRDGSAEDGE 31 /* set autoedge status (ifbreq) */
/*
* Generic bridge control request.
@ -119,10 +123,16 @@
struct ifbreq {
char ifbr_ifsname[IFNAMSIZ]; /* member if name */
uint32_t ifbr_ifsflags; /* member if flags */
uint8_t ifbr_state; /* member if STP state */
uint8_t ifbr_priority; /* member if STP priority */
uint8_t ifbr_path_cost; /* member if STP cost */
uint32_t ifbr_stpflags; /* member if STP flags */
uint8_t ifbr_edge; /* member if STP edge */
uint8_t ifbr_autoedge; /* member if STP autoedge */
uint8_t ifbr_p2p; /* member if STP p2p */
uint32_t ifbr_path_cost; /* member if STP cost */
uint8_t ifbr_portno; /* member if port number */
uint8_t ifbr_priority; /* member if STP priority */
uint8_t ifbr_proto; /* member if STP protocol */
uint8_t ifbr_role; /* member if STP role */
uint8_t ifbr_state; /* member if STP state */
};
/* BRDGGIFFLAGS, BRDGSIFFLAGS */
@ -192,6 +202,8 @@ struct ifbrparam {
#define ifbrp_csize ifbrp_ifbrpu.ifbrpu_int32 /* cache size */
#define ifbrp_ctime ifbrp_ifbrpu.ifbrpu_int32 /* cache time (sec) */
#define ifbrp_prio ifbrp_ifbrpu.ifbrpu_int16 /* bridge priority */
#define ifbrp_proto ifbrp_ifbrpu.ifbrpu_int8 /* bridge protocol */
#define ifbrp_txhc ifbrp_ifbrpu.ifbrpu_int8 /* bpdu tx holdcount */
#define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_int8 /* hello time (sec) */
#define ifbrp_fwddelay ifbrp_ifbrpu.ifbrpu_int8 /* fwd time (sec) */
#define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_int8 /* max age (sec) */
@ -201,9 +213,12 @@ struct ifbrparam {
* Bridge current operational parameters structure.
*/
struct ifbropreq {
uint8_t ifbop_holdcount;
uint8_t ifbop_maxage;
uint8_t ifbop_hellotime;
uint8_t ifbop_fwddelay;
uint8_t ifbop_protocol;
uint16_t ifbop_priority;
uint16_t ifbop_root_port;
uint32_t ifbop_root_path_cost;
uint64_t ifbop_designated_root;