int bridge_control (int port_index,UID_CNTRL_BODY_T* cntrl) { switch (cntrl->cmd) { case UID_PORT_CONNECT: #ifdef MY_PRINT_RSTP printf("connected port p%02d\n", port_index); #endif BitmapSetBit(&enabled_ports, port_index - 1); STP_IN_enable_port (port_index, True); break; case UID_PORT_DISCONNECT: #ifdef MY_PRINT_RSTP printf("disconnected port p%02d\n", port_index); #endif BitmapClearBit(&enabled_ports, port_index - 1); STP_IN_enable_port (port_index, False); break; case UID_BRIDGE_SHUTDOWN: #ifdef MY_PRINT_RSTP printf("shutdown from manager :(\n"); #endif return 1; default: printf("Unknown control command <%d> for port %d\n", cntrl->cmd,port_index); } return 0; }
/*ARGSUSED*/ static void dlpi_notify(dlpi_handle_t dlpi, dlpi_notifyinfo_t *info, void *arg) { struct portdata *port = arg; int rc; switch (info->dni_note) { case DL_NOTE_SPEED: /* libdlpi gives us Kbps, and we want Mbps */ if (port->speed == info->dni_speed / 1000) break; port->speed = info->dni_speed / 1000; if ((rc = STP_IN_changed_port_speed(port->port_index, port->speed)) != 0) syslog(LOG_ERR, "STP can't change port speed on %s: %s", port->name, STP_IN_get_error_explanation(rc)); break; case DL_NOTE_PHYS_ADDR: if (memcmp(info->dni_physaddr, port->mac_addr, ETHERADDRL) != 0) rstp_change_mac(port, info->dni_physaddr); break; case DL_NOTE_LINK_DOWN: if (!port->phys_status) break; port->phys_status = B_FALSE; if (!port->admin_status || protect != DLADM_BRIDGE_PROT_STP || port->sdu_failed) break; if ((rc = STP_IN_enable_port(port->port_index, False)) != 0) syslog(LOG_ERR, "STP can't disable port %s: %s", port->name, STP_IN_get_error_explanation(rc)); break; case DL_NOTE_LINK_UP: if (port->phys_status) break; port->phys_status = B_TRUE; if (!port->admin_status || protect != DLADM_BRIDGE_PROT_STP || port->sdu_failed) { port->bpdu_protect = B_FALSE; break; } /* * If we're not running STP, and the link state has just come * up, then clear out any protection shutdown state, and allow * us to forward again. */ if (port->admin_non_stp && port->bpdu_protect) { port->bpdu_protect = B_FALSE; enable_forwarding(port); } if ((rc = STP_IN_enable_port(port->port_index, True)) != 0) syslog(LOG_ERR, "STP can't enable port %s: %s", port->name, STP_IN_get_error_explanation(rc)); break; } }
void CHECK_on_down(uint16_t The_XOR,uint16_t The_current) { uint8_t loops; for (loops = 15; loops >= 0; loops--) { if( (The_XOR & 0x8000) && (loops == 7) ) { STP_IN_changed_port_duplex (2); } if( (The_XOR & 0x8000) && (loops == 6) ) { if(The_current & 0x0040 ) STP_IN_changed_port_speed (2, 100000); else STP_IN_changed_port_speed (2, 10000); } if( ( The_XOR & 0x8000 )&& (loops == 5) ) { if(The_current & 0x0020 ) STP_IN_enable_port (2,1); else STP_IN_enable_port (2,0); } if( ( The_XOR & 0x8000 )&& (loops == 2) ) { STP_IN_changed_port_duplex (1); } if( ( The_XOR & 0x8000 )&& (loops == 1) ) { if(The_current & 0x0040 ) STP_IN_changed_port_speed (1, 100000); else STP_IN_changed_port_speed (1, 10000); } if( ( The_XOR & 0x8000 )&& (loops == 0) ) { if(The_current & 0x0020 ) STP_IN_enable_port (1,1); else STP_IN_enable_port (1,0); } The_XOR = The_XOR << 1 ; } }