diff --git a/include/stp_externs.h b/include/stp_externs.h index 6452da2..22c5c87 100755 --- a/include/stp_externs.h +++ b/include/stp_externs.h @@ -23,7 +23,7 @@ extern struct STPD_CONTEXT stpd_context; extern STP_GLOBAL stp_global; extern uint32_t g_max_stp_port; extern uint16_t g_stp_bmp_po_offset; -struct timeval g_stp_100ms_tv; +extern struct timeval g_stp_100ms_tv; extern MAC_ADDRESS bridge_group_address; extern MAC_ADDRESS pvst_bridge_group_address; extern MAC_ADDRESS g_stp_base_mac_addr; diff --git a/include/stp_main.h b/include/stp_main.h index 4e45643..4cf348f 100644 --- a/include/stp_main.h +++ b/include/stp_main.h @@ -128,8 +128,8 @@ typedef struct #define STPD_INCR_PKT_COUNT(x, y) (g_stpd_intf_stats[x]->y)++ #define STPD_GET_PKT_COUNT(x, y) (g_stpd_intf_stats[x]->y) -struct tm *g_tm; -struct timespec g_ts; +extern struct tm *g_tm; +extern struct timespec g_ts; typedef struct { diff --git a/include/stp_netlink.h b/include/stp_netlink.h index c37ca40..e485f78 100644 --- a/include/stp_netlink.h +++ b/include/stp_netlink.h @@ -85,7 +85,7 @@ typedef struct netlink_db_s }netlink_db_t; typedef void stp_netlink_cb_ptr (netlink_db_t *if_db, uint8_t add, bool init_in_prog); -stp_netlink_cb_ptr *stp_netlink_cb; +extern stp_netlink_cb_ptr *stp_netlink_cb; #define PRINT_MAC_FORMAT "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx" #define PRINT_MAC_VAL(x) *(char *)x,*((char *)x)+1,*((char *)x)+2,*((char *)x)+3,*((char *)x)+4,*((char *)x)+5 diff --git a/lib/applog.h b/lib/applog.h index 852ee53..3f2eb81 100644 --- a/lib/applog.h +++ b/lib/applog.h @@ -42,6 +42,7 @@ int applog_write(int priority, const char *fmt, ...); #define APP_LOG_LEVEL_MIN (APP_LOG_LEVEL_EMERG) #define APP_LOG_LEVEL_DEFAULT (APP_LOG_LEVEL_ERR) +//#define APP_LOG_LEVEL_DEFAULT (APP_LOG_LEVEL_DEBUG) #define APP_LOG_LEVEL_MAX (APP_LOG_LEVEL_DEBUG) #define APP_LOG_STATUS_OK (0) diff --git a/stp/Makefile.am b/stp/Makefile.am index a8603ed..6d32fea 100644 --- a/stp/Makefile.am +++ b/stp/Makefile.am @@ -9,5 +9,6 @@ else DBGFLAGS = -g -DNDEBUG endif -libstp_a_CFLAGS = -Werror $(COV_CFLAGS) +#libstp_a_CFLAGS = -Werror $(COV_CFLAGS) +libstp_a_CFLAGS = $(COV_CFLAGS) libstp_a_SOURCES = stp.c stp_pkt.c stp_data.c stp_debug.c stp_intf.c stp_main.c stp_mgr.c stp_netlink.c stp_timer.c stp_util.c diff --git a/stp/stp.c b/stp/stp.c index 5fe3bec..d47dd8f 100755 --- a/stp/stp.c +++ b/stp/stp.c @@ -881,9 +881,12 @@ void send_config_bpdu(STP_CLASS* stp_class, PORT_ID port_number) if (!g_sstp_enabled) + { stputil_send_pvst_bpdu(stp_class, port_number, CONFIG_BPDU_TYPE); - else + } else + { stputil_send_bpdu(stp_class, port_number, CONFIG_BPDU_TYPE); + } } void send_tcn_bpdu(STP_CLASS* stp_class, PORT_ID port_number) @@ -896,7 +899,10 @@ void send_tcn_bpdu(STP_CLASS* stp_class, PORT_ID port_number) return; if (!g_sstp_enabled) + { stputil_send_pvst_bpdu(stp_class, port_number, TCN_BPDU_TYPE); - else + } else + { stputil_send_bpdu(stp_class, port_number, TCN_BPDU_TYPE); + } } diff --git a/stp/stp_intf.c b/stp/stp_intf.c index c7bdafb..afb6635 100755 --- a/stp/stp_intf.c +++ b/stp/stp_intf.c @@ -16,6 +16,8 @@ */ #include "stp_inc.h" +#include +#include int stp_intf_get_netlink_fd() { @@ -421,10 +423,14 @@ bool stp_intf_update_po_members(netlink_db_t * if_db, INTERFACE_NODE * node) } } + INTERFACE_NODE * stp_intf_update_intf_db(netlink_db_t *if_db, uint8_t is_add, bool init_in_prog, bool eth_if) { INTERFACE_NODE *node = NULL; uint32_t port_id = 0; + char *ifname_trim; + char num_str[ STP_ETH_NAME_PREFIX_LEN ]; + int index=0, i; if(is_add) { @@ -438,7 +444,24 @@ INTERFACE_NODE * stp_intf_update_intf_db(netlink_db_t *if_db, uint8_t is_add, bo /* Update port id */ if(eth_if) { - port_id = strtol(((char *)if_db->ifname + STP_ETH_NAME_PREFIX_LEN), NULL, 10); + //Ensure that Inerface name contains min STP_ETH_NAME_PREFIX_LEN chars + if (strlen((char *)if_db->ifname) < STP_ETH_NAME_PREFIX_LEN) + { + STP_LOG_ERR("Port id update failed for invalid interface name: %s", if_db->ifname); + return node; + } + // Perform the conversion using strtol + ifname_trim = (char *)if_db->ifname + STP_ETH_NAME_PREFIX_LEN; + memset(num_str,0, sizeof(num_str)); + for (i=0; ifname_trim[i] != '\0' && index < STP_ETH_NAME_PREFIX_LEN; i++) + { + if (isdigit(ifname_trim[i]) ) + { + num_str[index++] = ifname_trim[i]; + } + } + num_str[index] = '\0'; + port_id = strtol(num_str, NULL, 10); node->port_id = port_id; /* Derive Max Port */ diff --git a/stp/stp_main.c b/stp/stp_main.c index 9a384c6..8c1b2ec 100644 --- a/stp/stp_main.c +++ b/stp/stp_main.c @@ -16,6 +16,9 @@ */ #include "stp_main.h" +#include +#include +#include STPD_CONTEXT stpd_context; @@ -32,7 +35,7 @@ int stpd_ipc_init() STP_LOG_ERR("ipc socket error %s", strerror(errno)); return -1; } - + // setup socket address structure memset(&sa, 0, sizeof(struct sockaddr_un)); sa.sun_family = AF_UNIX; @@ -54,7 +57,7 @@ int stpd_ipc_init() return -1; } - STP_LOG_DEBUG("ipc init done"); + STP_LOG_DEBUG("stpd: ipc init done"); return 0; } diff --git a/stp/stp_mgr.c b/stp/stp_mgr.c index 3504f9d..cd93c57 100755 --- a/stp/stp_mgr.c +++ b/stp/stp_mgr.c @@ -17,6 +17,7 @@ #include "stp_inc.h" #include "stp_main.h" +#include MAC_ADDRESS g_stp_base_mac_addr; @@ -73,7 +74,6 @@ struct event *stpmgr_libevent_create(struct event_base *base, STP_LOG_DEBUG("base : %p, sock : %d, flags : %x, cb_fn : %p", base, sock, flags, cb_fn); if (tv) STP_LOG_DEBUG("tv.sec : %u, tv.usec : %u", tv->tv_sec, tv->tv_usec); - return ev; } } @@ -115,7 +115,6 @@ void stpmgr_initialize_stp_class(STP_CLASS *stp_class, VLAN_ID vlan_id) stp_index = GET_STP_INDEX(stp_class); stp_class->vlan_id = vlan_id; - stputil_set_bridge_priority(&stp_class->bridge_info.bridge_id, STP_DFLT_PRIORITY, vlan_id); NET_TO_HOST_MAC(&stp_class->bridge_info.bridge_id.address, &g_stp_base_mac_addr); @@ -1125,8 +1124,6 @@ static bool stpmgr_config_fastspan(PORT_ID port_id, bool enable) if (enable) { - if(is_member(g_fastspan_config_mask, port_id)) - return ret; set_mask_bit(g_fastspan_config_mask, port_id); set_mask_bit(g_fastspan_mask, port_id); stpsync_update_port_fast(stp_intf_get_port_name(port_id), true); @@ -1490,7 +1487,6 @@ static void stpmgr_process_bridge_config_msg(void *msg) pmsg->opcode, pmsg->stp_mode, pmsg->rootguard_timeout, pmsg->base_mac_addr[0], pmsg->base_mac_addr[1], pmsg->base_mac_addr[2], pmsg->base_mac_addr[3], pmsg->base_mac_addr[4], pmsg->base_mac_addr[5]); - if (pmsg->opcode == STP_SET_COMMAND) { stp_global.enable = true; diff --git a/stp/stp_netlink.c b/stp/stp_netlink.c index 2b13f22..f76bd63 100644 --- a/stp/stp_netlink.c +++ b/stp/stp_netlink.c @@ -15,8 +15,9 @@ * limitations under the License. */ -#include "stp_netlink.h" +#include +stp_netlink_cb_ptr *stp_netlink_cb; int stp_intf_get_netlink_fd(); diff --git a/stpd_main.cpp b/stpd_main.cpp index f3d9f36..2fbba93 100644 --- a/stpd_main.cpp +++ b/stpd_main.cpp @@ -16,11 +16,25 @@ */ #include +#include "swss/logger.h" + +using namespace std; extern "C" void stpd_main(); int main(int argc, char **argv) { + + swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG); + SWSS_LOG_ENTER(); + + swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE); + + swss::Logger::linkToDbNative("stpd"); + + + SWSS_LOG_NOTICE("--- Starting stpd ---"); + stpd_main(); return 0; } diff --git a/stpsync/stp_sync.cpp b/stpsync/stp_sync.cpp index 0a2b7bb..d0ddaf1 100644 --- a/stpsync/stp_sync.cpp +++ b/stpsync/stp_sync.cpp @@ -48,94 +48,94 @@ StpSync::StpSync(DBConnector *db, DBConnector *cfgDb) : DBConnector db(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0); DBConnector cfgDb(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0); -StpSync sync(&db, &cfgDb); +StpSync stpSync(&db, &cfgDb); extern "C" { void stpsync_add_vlan_to_instance(uint16_t vlan_id, uint16_t instance) { - sync.addVlanToInstance(vlan_id, instance); + stpSync.addVlanToInstance(vlan_id, instance); } void stpsync_del_vlan_from_instance(uint16_t vlan_id, uint16_t instance) { - sync.delVlanFromInstance(vlan_id, instance); + stpSync.delVlanFromInstance(vlan_id, instance); } void stpsync_update_stp_class(STP_VLAN_TABLE * stp_vlan) { - sync.updateStpVlanInfo(stp_vlan); + stpSync.updateStpVlanInfo(stp_vlan); } void stpsync_del_stp_class(uint16_t vlan_id) { - sync.delStpVlanInfo(vlan_id); + stpSync.delStpVlanInfo(vlan_id); } void stpsync_update_port_class(STP_VLAN_PORT_TABLE * stp_vlan_intf) { - sync.updateStpVlanInterfaceInfo(stp_vlan_intf); + stpSync.updateStpVlanInterfaceInfo(stp_vlan_intf); } void stpsync_del_port_class(char * if_name, uint16_t vlan_id) { - sync.delStpVlanInterfaceInfo(if_name, vlan_id); + stpSync.delStpVlanInterfaceInfo(if_name, vlan_id); } void stpsync_update_port_state(char * ifName, uint16_t instance, uint8_t state) { - sync.updateStpPortState(ifName, instance, state); + stpSync.updateStpPortState(ifName, instance, state); } void stpsync_del_port_state(char * ifName, uint16_t instance) { - sync.delStpPortState(ifName, instance); + stpSync.delStpPortState(ifName, instance); } #if 0 void stpsync_update_vlan_port_state(char * ifName, uint16_t vlan_id, uint8_t state) { - sync.updateStpVlanPortState(ifName, vlan_id, state); + stpSync.updateStpVlanPortState(ifName, vlan_id, state); } void stpsync_del_vlan_port_state(char * ifName, uint16_t vlan_id) { - sync.delStpVlanPortState(ifName, vlan_id); + stpSync.delStpVlanPortState(ifName, vlan_id); } #endif void stpsync_update_fastage_state(uint16_t vlan_id, bool add) { - sync.updateStpVlanFastage(vlan_id, add); + stpSync.updateStpVlanFastage(vlan_id, add); } void stpsync_update_port_admin_state(char * ifName, bool up, bool physical) { - sync.updatePortAdminState(ifName, up, physical); + stpSync.updatePortAdminState(ifName, up, physical); } uint32_t stpsync_get_port_speed(char * ifName) { - return sync.getPortSpeed(ifName); + return stpSync.getPortSpeed(ifName); } void stpsync_update_bpdu_guard_shutdown(char * ifName, bool enabled) { - sync.updateBpduGuardShutdown(ifName, enabled); + stpSync.updateBpduGuardShutdown(ifName, enabled); } void stpsync_update_port_fast(char * ifName, bool enabled) { - sync.updatePortFast(ifName, enabled); + stpSync.updatePortFast(ifName, enabled); } void stpsync_del_stp_port(char * ifName) { - sync.delStpInterface(ifName); + stpSync.delStpInterface(ifName); } void stpsync_clear_appdb_stp_tables(void) { - sync.clearAllStpAppDbTables(); + stpSync.clearAllStpAppDbTables(); } }