📄 stp_in.c
字号:
STP_IN_stpm_get_cfg(&old);
semTake(sem_rstp,WAIT_FOREVER);
/*对照field_mask,凡是1的位,说明不是默认值,用默认值来设置*/
if (BR_CFG_PRIO & uid_cfg->field_mask)
{
old.bridge_priority = uid_cfg->bridge_priority;
}
if (BR_CFG_AGE & uid_cfg->field_mask)
{
old.max_age = uid_cfg->max_age;
}
if (BR_CFG_HELLO & uid_cfg->field_mask)
{
old.hello_time = uid_cfg->hello_time;
}
if (BR_CFG_DELAY & uid_cfg->field_mask)
{
old.forward_delay = uid_cfg->forward_delay;
}
if (BR_CFG_FORCE_VER & uid_cfg->field_mask)
{
old.force_version = uid_cfg->force_version;
}
/* 检查参数的有效性*/
rc = _check_stpm_config (&old,vty);
if (0 != rc)
{
/*stp_trace ("_check_stpm_config failed %d", (int) rc);*/
semGive(sem_rstp);
return rc;
}
/*参数检查通过*/
if ((BR_CFG_STATE & uid_cfg->field_mask) && (STP_DISABLED == uid_cfg->stp_enabled))
{
rc = _stp_in_stpm_enable ( STP_DISABLED);
if (0 != rc)
{
/* stp_trace ("can't disable rc=%d", (int) rc);*/
semGive(sem_rstp);
return rc;
}
uid_cfg->field_mask &= !BR_CFG_STATE;
/*如果fieldmask的所有位都为0,则返回*/
if (!uid_cfg->field_mask)
{
semGive(sem_rstp);
return 0;
}
}
/* get current state */
this = /*bridge_list*/br_get_byname("default");/*modified by wl 2007-8-3*/
created_here = False;
enabled_here = False;
prev_prio = this->BrId.prio;
this->BrId.prio = old.bridge_priority;
if (STP_ENABLED == this->admin_state)
{
if (0 != STP_stpm_check_bridge_priority (this))
{
this->BrId.prio = prev_prio;
/* stp_trace ("%s", "STP_stpm_check_bridge_priority failed");*/
semGive(sem_rstp);
return STP_Invalid_Bridge_Priority;
}
}
this->BrTimes.MaxAge = old.max_age;
this->BrTimes.HelloTime = old.hello_time;
this->BrTimes.ForwardDelay = old.forward_delay;
this->ForceVersion = (PROTOCOL_VERSION_T) old.force_version;
if ((BR_CFG_STATE & uid_cfg->field_mask) &&
STP_DISABLED != uid_cfg->stp_enabled &&
STP_DISABLED == this->admin_state)
{
rc = _stp_in_stpm_enable (uid_cfg->stp_enabled);
if (0 != rc)
{
/* stp_trace ("%s", "cannot enable");*/
semGive(sem_rstp);
return rc;
}
enabled_here = True;
}
if (!enabled_here && STP_DISABLED != this->admin_state)
{
STP_stpm_update_after_bridge_management (this);
}
semGive(sem_rstp);;
return 0;
}
#ifdef _CTC_
int
STP_IN_set_port_cfg (IN int vlan_id, IN UID_STP_PORT_CFG_T* uid_cfg, IN int port_index)
{
struct net_bridge* this;
struct net_bridge_port* port;
register int port_no;
/* RSTP_CRITICAL_PATH_START;*/
tev = RSTP_PORT_MNGR_T; INCR100(nev);
/*this = stpapi_stpm_find (vlan_id);*/
/*this = bridge_list;*/
this = br_get_byname("default");/*modified by wl 2007-8-3*/
if (! this)
{ /* it had not yet been created :( */
/* RSTP_CRITICAL_PATH_END;*/
printf("RSTP instance with tag %d hasn't been created\n", (int) vlan_id);
return -1;
}
for (port_no = 18; port_no <= 24; port_no++)
{
/*if (! BitmapGetBit(&uid_cfg->port_bmp, port_no - 1))
continue;
*/
if (port_no!=port_index)
continue;
port = br_get_port_byno(port_no);
if (! port)
{/* port is absent in the stpm :( */
continue;
}
if (PT_CFG_MCHECK & uid_cfg->field_mask)
{
if (this->ForceVersion >= NORMAL_RSTP)
port->mcheck = True;
}
if (PT_CFG_COST & uid_cfg->field_mask)
{
port->adminPCost = uid_cfg->admin_port_path_cost;
}
if (PT_CFG_PRIO & uid_cfg->field_mask)
{
port->port_id = (uid_cfg->port_priority << 8) + port_no;
}
if (PT_CFG_P2P & uid_cfg->field_mask)
{
port->adminPointToPointMac = uid_cfg->admin_point2point;
port->p2p_recompute = True;
}
if (PT_CFG_EDGE & uid_cfg->field_mask)
{
port->adminEdge = uid_cfg->admin_edge;
port->operEdge = port->adminEdge;
#ifdef STP_DBG
if (port->edge->debug)
{
stp_trace ("port %s is operEdge=%c in STP_IN_set_port_cfg",
port->port_name,
port->operEdge ? 'Y' : 'n');
}
#endif
}
if (PT_CFG_NON_STP & uid_cfg->field_mask)
{
#ifdef STP_DBG
if (port->roletrns->debug && port->admin_non_stp != uid_cfg->admin_non_stp)
{
stp_trace ("port %s is adminNonStp=%c in STP_IN_set_port_cfg",
port->port_name,
uid_cfg->admin_non_stp ? 'Y' : 'n');
}
#endif
port->admin_non_stp = uid_cfg->admin_non_stp;
}
#ifdef STP_DBG
if (PT_CFG_DBG_SKIP_RX & uid_cfg->field_mask)
{
port->skip_rx = uid_cfg->skip_rx;
}
if (PT_CFG_DBG_SKIP_TX & uid_cfg->field_mask)
{
port->skip_tx = uid_cfg->skip_tx;
}
#endif
port->reselect = True;
port->selected = False;
}
STP_stpm_update (this);
/* RSTP_CRITICAL_PATH_END;*/
return 0;
}
#endif
int STP_IN_stpm_disable_cfg (IN UID_STP_CFG_T * uid_cfg)
{
int rc = 0, prev_prio, err_code;
Bool created_here, enabled_here;
register struct net_bridge *this;
/* UID_STP_CFG_T old;
STP_IN_stpm_get_cfg(&old);
*/
semTake(sem_rstp,WAIT_FOREVER);
/*this = bridge_list;*/
this = br_get_byname("default");/*modified by wl 2007-8-3*/
this->ForceVersion = NORMAL_RSTP;
this->BrId.prio = DEF_BR_PRIO;
this->BrTimes.MaxAge = DEF_BR_MAXAGE;
this->BrTimes.HelloTime = DEF_BR_HELLOT;
this->BrTimes.ForwardDelay = DEF_BR_FWDELAY;
if ((BR_CFG_STATE & uid_cfg->field_mask) && (STP_DISABLED == uid_cfg->stp_enabled))
{
rc = _stp_in_stpm_disable ();
if (0 != rc)
{
/* stp_trace ("can't disable rc=%d", (int) rc);*/
semGive(sem_rstp);
return rc;
}
uid_cfg->field_mask &= !BR_CFG_STATE;
/*如果fieldmask的所有位都为0,则返回*/
if (!uid_cfg->field_mask)
{
semGive(sem_rstp);
return 0;
}
}
}
#if 0
int STP_IN_set_port_cfg (IN int vlan_id, IN UID_STP_PORT_CFG_T * uid_cfg)
{
register STPM_T *this;
register PORT_T *port;
register int port_no;
RSTP_CRITICAL_PATH_START;
tev = RSTP_PORT_MNGR_T;
INCR100 (nev);
this = stpapi_stpm_find (vlan_id);
if (!this)
{ /* it had not yet been created :( */
RSTP_CRITICAL_PATH_END;
Print ("RSTP instance with tag %d hasn't been created\n",
(int) vlan_id);
return STP_Vlan_Had_Not_Yet_Been_Created;
}
for (port_no = 1; port_no <= max_port; port_no++)
{
if (!BitmapGetBit (&uid_cfg->port_bmp, port_no - 1))
continue;
port = _stpapi_port_find (this, port_no);
if (!port)
{ /* port is absent in the stpm :( */
continue;
}
if (PT_CFG_MCHECK & uid_cfg->field_mask)
{
if (this->ForceVersion >= NORMAL_RSTP)
port->mcheck = True;
}
if (PT_CFG_COST & uid_cfg->field_mask)
{
port->adminPCost = uid_cfg->admin_port_path_cost;
}
if (PT_CFG_PRIO & uid_cfg->field_mask)
{
port->port_id = (uid_cfg->port_priority << 8) + port_no;
}
if (PT_CFG_P2P & uid_cfg->field_mask)
{
port->adminPointToPointMac = uid_cfg->admin_point2point;
port->p2p_recompute = True;
}
if (PT_CFG_EDGE & uid_cfg->field_mask)
{
port->adminEdge = uid_cfg->admin_edge;
port->operEdge = port->adminEdge;
#ifdef STP_DBG
if (port->edge->debug)
{
stp_trace ("port %s is operEdge=%c in STP_IN_set_port_cfg",
port->port_name, port->operEdge ? 'Y' : 'n');
}
#endif
}
if (PT_CFG_NON_STP & uid_cfg->field_mask)
{
#ifdef STP_DBG
if (port->roletrns->debug &&
port->admin_non_stp != uid_cfg->admin_non_stp)
{
stp_trace ("port %s is adminNonStp=%c in STP_IN_set_port_cfg",
port->port_name, uid_cfg->admin_non_stp ? 'Y' : 'n');
}
#endif
port->admin_non_stp = uid_cfg->admin_non_stp;
}
#ifdef STP_DBG
if (PT_CFG_DBG_SKIP_RX & uid_cfg->field_mask)
{
port->skip_rx = uid_cfg->skip_rx;
}
if (PT_CFG_DBG_SKIP_TX & uid_cfg->field_mask)
{
port->skip_tx = uid_cfg->skip_tx;
}
#endif
port->reselect = True;
port->selected = False;
}
STP_stpm_update (this);
RSTP_CRITICAL_PATH_END;
return 0;
}
#ifdef STP_DBG
int STP_IN_dbg_set_port_trace (char *mach_name, int enadis, int vlan_id,
BITMAP_T * ports, int is_print_err)
{
register STPM_T *this;
register PORT_T *port;
register int port_no;
RSTP_CRITICAL_PATH_START;
this = stpapi_stpm_find (vlan_id);
if (!this)
{ /* it had not yet been created :( */
RSTP_CRITICAL_PATH_END;
if (is_print_err)
{
Print ("RSTP instance with tag %d hasn't been created\n",
(int) vlan_id);
}
return STP_Vlan_Had_Not_Yet_Been_Created;
}
for (port_no = 1; port_no <= max_port; port_no++)
{
if (!BitmapGetBit (ports, port_no - 1))
continue;
port = _stpapi_port_find (this, port_no);
if (!port)
{ /* port is absent in the stpm :( */
continue;
}
STP_port_trace_state_machine (port, mach_name, enadis, vlan_id);
}
RSTP_CRITICAL_PATH_END;
return 0;
}
#endif
const char *STP_IN_get_error_explanation (int rstp_err_no)
{
#define CHOOSE(a) #a
static char *rstp_error_names[] = RSTP_ERRORS;
#undef CHOOSE
if (rstp_err_no < STP_OK)
{
return "Too small error code :(";
}
if (rstp_err_no >= STP_LAST_DUMMY)
{
return "Too big error code :(";
}
return rstp_error_names[rstp_err_no];
}
#endif
/***************************************************************************************
To debug
****************************************************************************************/
void STP_port_link()
{
/*struct net_bridge *stpm = bridge_list;*/
struct net_bridge *stpm = br_get_byname("default");/*modified by wl 2007-8-3*/
struct net_bridge_port *port = stpm->port_list;
if (port->portEnabled == 1)
{ /* nothing to do :) */
return;
}
port->uptime = 0;
if (1)
{ /* clear port statistics */
port->rx_cfg_bpdu_cnt = port->rx_rstp_bpdu_cnt = port->rx_tcn_bpdu_cnt =
0;
}
/* if (port->edge->debug)*/
{
mn_fd_printf(cl_serv_console_fd,"Port %d became enable adminEdge=%c", port->port_no,
port->adminEdge ? 'Y' : 'N');
}
port->adminEnable = 1;
port->fdWhile = port->helloWhen = port->mdelayWhile = port->rbWhile =
port->rcvdInfoWhile = port->rrWhile = port->tcWhile = port->txCount = 0;
port->msgPortRole = RSTP_PORT_ROLE_UNKN;
port->selectedRole = DisabledPort;
port->sendRSTP = True;
port->operSpeed = STP_OUT_get_port_oper_speed (port->port_no);
port->p2p_recompute = True;
port->reselect = True;
port->selected = False;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -