⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stp_in.c

📁 快速生成树协议的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
      else        memset (name, 0, buffsize);      iret = 0;      break;    }  }  RSTP_CRITICAL_PATH_END;  return iret;}int /* call it, when link Up/Down */STP_IN_enable_port (int port_index, Bool enable){  register STPM_T* stpm;  RSTP_CRITICAL_PATH_START;  tev = enable ? RSTP_PORT_EN_T : RSTP_PORT_DIS_T; INCR100(nev);  if (! enable) {#ifdef STP_DBG    stp_trace("%s (p%02d, all, %s, '%s')",        "clearFDB", (int) port_index, "this port", "disable port");#endif    STP_OUT_flush_lt (port_index, 0, LT_FLASH_ONLY_THE_PORT, "disable port");  }  for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {    if (STP_ENABLED != stpm->admin_state) continue;        _stp_in_enable_port_on_stpm (stpm, port_index, enable);  	/* STP_stpm_update (stpm);*/  }  RSTP_CRITICAL_PATH_END;  return 0;}int /* call it, when port speed has been changed, speed in Kb/s  */STP_IN_changed_port_speed (int port_index, long speed){  register STPM_T* stpm;  register PORT_T* port;  RSTP_CRITICAL_PATH_START;  tev = RSTP_PORT_SPEED_T; INCR100(nev);  for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {    if (STP_ENABLED != stpm->admin_state) continue;        port = _stpapi_port_find (stpm, port_index);    if (! port) continue;     port->operSpeed = speed;#ifdef STP_DBG    if (port->pcost->debug) {      stp_trace ("changed operSpeed=%lu", port->operSpeed);    }#endif    port->reselect = True;    port->selected = False;  }  RSTP_CRITICAL_PATH_END;  return 0;}int /* call it, when port duplex mode has been changed  */STP_IN_changed_port_duplex (int port_index){  register STPM_T* stpm;  register PORT_T* port;  RSTP_CRITICAL_PATH_START;  tev = RSTP_PORT_DPLEX_T; INCR100(nev);  for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {    if (STP_ENABLED != stpm->admin_state) continue;        port = _stpapi_port_find (stpm, port_index);    if (! port) continue; #ifdef STP_DBG    if (port->p2p->debug) {      stp_trace ("STP_IN_changed_port_duplex(%s)", port->port_name);    }#endif    port->p2p_recompute = True;    port->reselect = True;    port->selected = False;  }  RSTP_CRITICAL_PATH_END;  return 0;}intSTP_IN_check_bpdu_header (BPDU_T* bpdu, size_t len){  unsigned short len8023;  len8023 = ntohs (*(unsigned short*) bpdu->eth.len8023);  if (len8023 > 1500) {/* big len8023 format :( */    return STP_Big_len8023_Format;  }  if (len8023 < MIN_BPDU) { /* small len8023 format :( */    return STP_Small_len8023_Format;  }  if (len8023 + 14 > len) { /* len8023 format gt len :( */    return STP_len8023_Format_Gt_Len;  }  if (bpdu->eth.dsap != BPDU_L_SAP                 ||      bpdu->eth.ssap != BPDU_L_SAP                 ||      bpdu->eth.llc != LLC_UI) {    /* this is not a proper 802.3 pkt! :( */    return STP_Not_Proper_802_3_Packet;  }  if (bpdu->hdr.protocol[0] || bpdu->hdr.protocol[1]) {    return STP_Invalid_Protocol;  }#if 0  if (bpdu->hdr.version != BPDU_VERSION_ID) {    return STP_Invalid_Version;    }#endif  /* see also 9.3.4: think & TBD :( */  return 0;}#ifdef STP_DBGint dbg_rstp_deny = 0;#endifintSTP_IN_rx_bpdu (int vlan_id, int port_index, BPDU_T* bpdu, size_t len){  register PORT_T* port;  register STPM_T* this;  int              iret;#ifdef STP_DBG  if (1 == dbg_rstp_deny) {    return 0;  }#endif  RSTP_CRITICAL_PATH_START;  tev = RSTP_PORT_RX_T; INCR100(nev);  this = stpapi_stpm_find (vlan_id);  if (! this) { /*  the stpm had not yet been created :( */    RSTP_CRITICAL_PATH_END;    return STP_Vlan_Had_Not_Yet_Been_Created;  }  if (STP_DISABLED == this->admin_state) {/* the stpm had not yet been enabled :( */    RSTP_CRITICAL_PATH_END;    return STP_Had_Not_Yet_Been_Enabled_On_The_Vlan;  }  port = _stpapi_port_find (this, port_index);  if (! port) {/* port is absent in the stpm :( */    stp_trace ("RX bpdu vlan_id=%d port=%d port is absent in the stpm :(", (int) vlan_id, (int) port_index);    RSTP_CRITICAL_PATH_END;    return STP_Port_Is_Absent_In_The_Vlan;  }#ifdef STP_DBG  if (port->skip_rx > 0) {    if (1 == port->skip_rx)      stp_trace ("port %s stop rx skipping",                 port->port_name);    else      stp_trace ("port %s skip rx %d",                 port->port_name, port->skip_rx);    port->skip_rx--;    RSTP_CRITICAL_PATH_END;    return STP_Nothing_To_Do;  }#endif  if (port->operEdge && ! port->lnkWhile && port->portEnabled) {#ifdef STP_DBG	  if (port->topoch->debug) {    	stp_trace ("port %s tc=TRUE by operEdge", port->port_name);	  }#endif    port->tc = True; /* IEEE 802.1y, 17.30 */  }  if (! port->portEnabled) {/* port link change indication will come later :( */    _stp_in_enable_port_on_stpm (this, port->port_index, True);  }  #ifdef STP_DBG  if (port->edge->debug && port->operEdge) {    stp_trace ("port %s not operEdge !", port->port_name);  }#endif  port->operEdge = False;  port->wasInitBpdu = True;    iret = STP_port_rx_bpdu (port, bpdu, len);  STP_stpm_update (this);  RSTP_CRITICAL_PATH_END;  return iret;}intSTP_IN_one_second (void){  register STPM_T* stpm;  register int     dbg_cnt = 0;  RSTP_CRITICAL_PATH_START;  tev = RSTP_PORT_TIME_T; INCR100(nev);  for (stpm = STP_stpm_get_the_list (); stpm; stpm = stpm->next) {    if (STP_ENABLED == stpm->admin_state) {      /* stp_trace ("STP_IN_one_second vlan_id=%d", (int) stpm->vlan_id); */      STP_stpm_one_second (stpm);      dbg_cnt++;    }  }    RSTP_CRITICAL_PATH_END;  return dbg_cnt;}intSTP_IN_stpm_set_cfg (IN int vlan_id,                     IN BITMAP_T* port_bmp,                     IN UID_STP_CFG_T* uid_cfg){  int rc = 0, prev_prio, err_code;  Bool created_here, enabled_here;  register STPM_T* this;  UID_STP_CFG_T old;             /* stp_trace ("STP_IN_stpm_set_cfg"); */  if (0 != STP_IN_stpm_get_cfg (vlan_id, &old)) {    STP_OUT_get_init_stpm_cfg (vlan_id, &old);  }    RSTP_CRITICAL_PATH_START;  tev = RSTP_PORT_MNGR_T; INCR100(nev);  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);  if (0 != rc) {    stp_trace ("_check_stpm_config failed %d", (int) rc);    RSTP_CRITICAL_PATH_END;    return rc;  }  if ((BR_CFG_STATE & uid_cfg->field_mask) &&      (STP_DISABLED == uid_cfg->stp_enabled)) {    rc = _stp_in_stpm_enable (vlan_id, uid_cfg->vlan_name, port_bmp, STP_DISABLED);    if (0 != rc) {      stp_trace ("can't disable rc=%d", (int) rc);      RSTP_CRITICAL_PATH_END;      return rc;    }    uid_cfg->field_mask &= ! BR_CFG_STATE;    if (! uid_cfg->field_mask)  {      RSTP_CRITICAL_PATH_END;      return 0;    }  }  /* get current state */  this = stpapi_stpm_find (vlan_id);  created_here = False;  enabled_here = False;  if (! this) { /* it had not yet been created */    this = stp_in_stpm_create (vlan_id, uid_cfg->vlan_name, port_bmp, &err_code);/*STP_IN_stpm_set_cfg*/    if (! this) {      RSTP_CRITICAL_PATH_END;      return err_code;    }  }  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");      RSTP_CRITICAL_PATH_END;      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 (vlan_id, uid_cfg->vlan_name, port_bmp, uid_cfg->stp_enabled);    if (0 != rc) {      stp_trace ("%s", "cannot enable");      if (created_here) {        STP_stpm_delete (this);      }      RSTP_CRITICAL_PATH_END;      return rc;    }    enabled_here = True;  }  if (! enabled_here && STP_DISABLED != this->admin_state) {    STP_stpm_update_after_bridge_management (this);  }  RSTP_CRITICAL_PATH_END;  return 0;}intSTP_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_DBGintSTP_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;}#endifconst char*STP_IN_get_error_explanation (int rstp_err_no){#define CHOOSE(a) #astatic 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];}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -