From 385a705826ec33bedbb7d6d327ea1e18efb7d14f Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Wed, 6 Oct 2010 10:37:42 +0200 Subject: [PATCH] lldpad: fix enabling DCB on reboot During I&QP testing, it was observed that DCB would not always be enabled on certain interfaces during a reboot. This was observed only on the SLES11 SP1 version of lldpad. This patch syncs up the SLES11 SP1 version of lldpad to be essentially identical to the 0.9.38 version of lldpad. Version 0.9.38 has undergone months of validation and has been quite stable. Doing a full sync up vs. cherrypicking specific changes between 0.9.32 and 0.9.38 to fix issues observed in the SLES11 SP1 version seems less risky overall. Also, this will position the SLES11 SP1 version of lldpad to be able to easily take any additional fixes that are developed for lldpad. This patch does not change the versioning of the package - it remains at 0.9.32. References: bnc#637949 Signed-off-by: Eric Multanen Acked-by: Hannes Reinecke diff --git a/README b/README index d5a0e5c..72cd9e7 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ Link Layer Discovery Protocol (LLDP) Agent with Data Center Bridging (DCB) for Intel(R) Network Connections =========================================================== -February 23, 2010 +April 7, 2010 Contents ======== @@ -68,8 +68,9 @@ Requirements Flex source can be obtained from http://flex.sourceforge.net/ - An up to date netlink library needs to be installed in order to compile lldpad. -- For DCB features - an 82598-based or 82599-based Intel adapter with ixgbe - driver. +- For DCB features - a driver which supports the dcbnl rtnetlink interface + in the kernel (e.g. the ixgbe driver for 82598-based or 82599-based Intel + adapters). Functionality ============= @@ -214,10 +215,10 @@ DCBX Operation lldpad and dcbtool can be used to configure a DCB capable driver, such as the ixgbe driver, which supports the rtnetlink DCB interface. Once the DCB features are configured, the next step is to classify traffic to be -identified with an 802.1p priority and the associated DCB features. This can -be done by using the 'tc' command to setup the qdisc and filters to cause -network traffic to be transmitted on different queues. +identified with an 802.1p priority and the associated DCB features. +This can be done using a couple different methods. +1. qdisc and filter method The skbedit action mechanism can be used in a tc filter to classify traffic patterns to a specific queue_mapping value from 0-7. The ixgbe driver will place traffic with a given queue_mapping value onto the corresponding hardware @@ -228,20 +229,14 @@ Set up the multi-queue qdisc for the selected interface: # tc qdisc add dev ethX root handle 1: multiq Setting the queue_mapping in a TC filter allows the ixgbe driver to classify a -packet into a queue. Here are some examples of how to filter traffic into -various queues using the flow ids: +packet into a queue. Here is an example of a filter to cause iSCSI traffic +(running on the well known port number 3260) to be tagged with priority 4. -# tc filter add dev ethX protocol ip parent 1: u32 match ip dport 80 \ -0xffff action skbedit queue_mapping 0 +# tc filter add dev ethX protocol ip parent 1: u32 match ip dport 3260 \ +0xffff action skbedit queue_mapping 4 -# tc filter add dev ethX protocol ip parent 1: u32 match ip dport 53 \ -0xffff action skbedit queue_mapping 1 - -# tc filter add dev ethX protocol ip parent 1: u32 match ip dport 5001 \ -0xffff action skbedit queue_mapping 2 - -# tc filter add dev ethX protocol ip parent 1: u32 match ip dport 20 \ -0xffff action skbedit queue_mapping 7 +# tc filter add dev ethX protocol ip parent 1: u32 match ip sport 3260 \ +0xffff action skbedit queue_mapping 4 Here is an example that sets up a filter based on EtherType. In this example, the EtherType is 0x8906. @@ -249,6 +244,20 @@ the EtherType is 0x8906. # tc filter add dev ethX protocol 802_3 parent 1: handle 0xfc0e basic match \ 'cmp(u16 at 12 layer 1 mask 0xffff eq 35078)' action skbedit queue_mapping 3 +2. VLAN egress map method +Alternatively, traffic can be classified by configuring the egress map of a +VLAN interface. For example, if iSCSI traffic is desired to be on priority 4 +and VLAN 101 is dedicated for iSCSI, then the following configuration could +be performed to map the skb_priorities on VLAN 101 to the 802.1p priority 4. +# vconfig set_egress_map ethX.101 0 4 +# vconfig set_egress_map ethX.101 1 4 +# vconfig set_egress_map ethX.101 2 4 +... +# vconfig set_egress_map ethX.101 7 4 + +Note: since DCB features use the 802.1p priority in the VLAN tag to distinguish +traffic, it is expected that traffic in a DCB network will need to be on a +tagged VLAN. Testing ======= diff --git a/config.c b/config.c index c6bf061..5cfac83 100644 --- a/config.c +++ b/config.c @@ -36,6 +36,7 @@ #include #include #include "common.h" +#include "eloop.h" #include "lldpad.h" #include "lldp.h" #include "lldp_util.h" @@ -48,30 +49,30 @@ #include "drv_cfg.h" #include "config.h" #include "clif_msgs.h" -#include "eloop.h" #include "lldp/l2_packet.h" config_t lldpad_cfg; -static int cfg_loaded = FALSE; +static int cfg_loaded = false; /* * init_cfg - initialze the global lldpad_cfg via config_init * - * Returns TRUE (1) for succes and FALSE (0) for failed + * Returns true (1) for succes and false (0) for failed * * check to see if lldpad_cfs is already initailzied */ int init_cfg(void) { - if (cfg_loaded == FALSE) { + if (cfg_loaded == false) { config_init(&lldpad_cfg); - if (!config_read_file(&lldpad_cfg, cfg_file_name)) { - TRACE("config file failed to load\n") - TRACE2("error: ", config_error_text(&lldpad_cfg)) - TRACE1("line: ", config_error_line(&lldpad_cfg)) - } else { - cfg_loaded = TRUE; - } + if (!config_read_file(&lldpad_cfg, cfg_file_name)) + printf("config file failed to load\n"); + else + cfg_loaded = true; + } else { + if (check_cfg_file() || + (!config_read_file(&lldpad_cfg, cfg_file_name))) + cfg_loaded = false; } return cfg_loaded; } @@ -79,15 +80,15 @@ int init_cfg(void) /* * destroy_cfg - destroy the initialzed global lldpad_cfg * - * Sets the cfgReturn TRUE (1) for succes and FALSE (0) for failed + * Sets the cfgReturn true (1) for succes and false (0) for failed * - * check to see if lldpad_cfs is already initailzied + * check to see if lldpad_cfg is already initialized */ void destroy_cfg(void) { - if (cfg_loaded == TRUE) { + if (cfg_loaded == true) { config_destroy(&lldpad_cfg); - cfg_loaded = FALSE; + cfg_loaded = false; } } @@ -158,7 +159,6 @@ void scan_port(void *eloop_data, void *user_ctx) p++; } - destroy_cfg(); err_out: if_freenameindex(nameidx); return; @@ -169,10 +169,8 @@ error_out: void create_default_cfg_file(void) { - if (init_cfg()) { + if (cfg_loaded || init_cfg()) config_write_file(&lldpad_cfg, cfg_file_name); - destroy_cfg(); - } } /* check for existence of cfg file. If it does not exist, @@ -189,6 +187,8 @@ int check_cfg_file(void) if (access(cfg_file_name, R_OK | W_OK)) { if (access(cfg_file_name, F_OK)) { + printf("config file failed to load, "); + printf("create a new file.\n"); fd = open(cfg_file_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); if (fd < 0) { @@ -210,52 +210,52 @@ int check_cfg_file(void) return (retval); } -static boolean_t check_bool(int bool_setting) +static bool check_bool(int bool_setting) { if (bool_setting ==1 || bool_setting==0) - return TRUE; + return true; else - return FALSE; + return false; } -static boolean_t check_percentage(int percentage_setting) +static bool check_percentage(int percentage_setting) { if (percentage_setting < 0 ||percentage_setting > 100) - return FALSE; + return false; else - return TRUE; + return true; } -static boolean_t check_char(int int_setting) +static bool check_char(int int_setting) { if (int_setting < 0 || int_setting > 255) - return FALSE; + return false; else - return TRUE; + return true; } -static boolean_t check_int(int int_setting) +static bool check_int(int int_setting) { if (int_setting < 0 || int_setting > 1000000) - return FALSE; + return false; else - return TRUE; + return true; } -static boolean_t check_priority(int priority_setting) +static bool check_priority(int priority_setting) { if (priority_setting < dcb_none || priority_setting >= dcb_invalid) - return FALSE; + return false; else - return TRUE; + return true; } -static boolean_t check_double(double double_setting) +static bool check_double(double double_setting) { if (double_setting < 0 ) - return FALSE; + return false; else - return TRUE; + return true; } int get_int_config(config_setting_t *s, char *attr, int int_type, @@ -263,7 +263,7 @@ int get_int_config(config_setting_t *s, char *attr, int int_type, { char buf[64]; config_setting_t *setting = NULL; - int rval = FALSE; + int rval = false; setting = config_setting_get_member(s, attr); if (setting) { @@ -300,7 +300,7 @@ int get_array_config(config_setting_t *s, char *attr, int int_type, char buf[64]; config_setting_t *setting = NULL; config_setting_t *setting_value = NULL; - int rval = FALSE; + int rval = false; int i; setting = config_setting_get_member(s, attr); @@ -341,34 +341,6 @@ int get_array_config(config_setting_t *s, char *attr, int int_type, return rval; } -static int get_double_config(config_setting_t *s, char *attr, int int_type, - double *result) -{ - char buf[64]; - config_setting_t *setting = NULL; - int rval = FALSE; - - setting = config_setting_get_member(s, attr); - if (setting) { - *result = (double)config_setting_get_float(setting); - - switch(int_type) { - case TYPE_DOUBLE: - rval = check_double(*result); - break; - default: - break; - } - } - - if (!rval) { - snprintf(buf, sizeof(buf), "invalid value for %s", attr); - log_message(MSG_ERR_DCB_INVALID_CONFIG_FILE, "%s", buf); - } - - return rval; -} - void init_ports(void) { struct lldp_module *np; @@ -404,7 +376,6 @@ void init_ports(void) } p++; } - destroy_cfg(); if_freenameindex(nameidx); } @@ -486,7 +457,6 @@ int get_cfg(const char *ifname, char *path, void *value, int type) if (init_cfg()) { rval = get_config_setting(ifname, path, value, type); - destroy_cfg(); } return rval; } @@ -559,7 +529,6 @@ int set_config_setting(const char *ifname, char *path, void *value, int type) if (setting) { if (!set_config_value(setting, value, type)) { rval = cmd_failed; - printf("config set failed\n"); } else if (!config_write_file(&lldpad_cfg, cfg_file_name)) { printf("config write failed\n"); rval = cmd_failed; @@ -573,7 +542,6 @@ int set_cfg(const char *ifname, char *path, void *value, int type) int rval = cmd_failed; if (init_cfg()) { rval = set_config_setting(ifname, path, value, type); - destroy_cfg(); } return rval; } @@ -592,17 +560,16 @@ int set_cfg(const char *ifname, char *path, void *value, int type) */ int get_config_tlvfield(const char *ifname, u32 tlvid, const char *field, void *val, int type) { - int rc = 0; + int rc; char path[256]; memset(path, 0, sizeof(path)); rc = snprintf(path, sizeof(path), "tlvid%08x.%s", tlvid, field); if (get_config_setting(ifname, path, val, type)) { - fprintf(stderr, "### %s:%s:path=%s:failed on get_config_setting\n", - __func__, ifname, path); rc = EIO; goto out_err; } + rc = 0; out_err: return rc; @@ -611,7 +578,7 @@ out_err: /* libconfig uses long for int */ int get_config_tlvfield_int(const char *ifname, u32 tlvid, const char *field, int *value) { - int rc; + int rc = 0; long int val = (long int) *value; rc = get_config_tlvfield(ifname, tlvid, field, &val, CONFIG_TYPE_INT); @@ -727,7 +694,7 @@ int set_config_tlvfield_bool(const char *ifname, u32 tlvid, const char *field, i int is_tlv_txenabled(const char *ifname, u32 tlvid) { char arg[64]; - int enabletx = FALSE; + int enabletx = false; snprintf(arg, sizeof(arg), "%s%08x.%s", TLVID_PREFIX, tlvid, ARG_TLVTXENABLE); @@ -739,14 +706,14 @@ int is_tlv_txenabled(const char *ifname, u32 tlvid) int tlv_enabletx(const char *ifname, u32 tlvid) { - int enabletx = TRUE; + int enabletx = true; return set_config_tlvfield_bool(ifname, tlvid, ARG_TLVTXENABLE, (void *)&enabletx); } int tlv_disabletx(const char *ifname, u32 tlvid) { - int enabletx = FALSE; + int enabletx = false; return set_config_tlvfield_bool(ifname, tlvid, ARG_TLVTXENABLE, (void *)&enabletx); } diff --git a/ctrl_iface.c b/ctrl_iface.c index 2ec02e4..f55c577 100644 --- a/ctrl_iface.c +++ b/ctrl_iface.c @@ -56,7 +56,6 @@ struct ctrl_dst { }; static char *hexlist = "0123456789abcdef"; -static char *hexlistcaps = "0123456789ABCDEF"; struct clif_cmds { int cmd; @@ -174,7 +173,7 @@ int clif_iface_attach(struct clif_data *clifd, /* * There are two cases here one, the user provided - * no string in which case we must send dcbd events + * no string in which case we must send DCBX events * to be compatible with legacy clients. Two the * user sent a comma seperated string of tlv module * ids it expects events from @@ -406,7 +405,7 @@ static char *ctrl_iface_path(struct clif_data *clifd) } -void ctrl_iface_register(struct clif_data *clifd) +int ctrl_iface_register(struct clif_data *clifd) { eloop_register_read_sock(clifd->ctrl_sock, ctrl_iface_receive, clifd, NULL); @@ -537,13 +536,13 @@ int is_ctrl_listening(struct ctrl_dst *dst, u32 type) int i; u32 term = ~0; u32 all = 0; - u32 dcbd = LLDP_MOD_DCBX; + u32 dcbx = LLDP_MOD_DCBX; if (!dst) return 0; for (i=0; dst->tlv_types[i] != term; i++) { - if ((!type && dst->tlv_types[i] == dcbd) || + if ((!type && dst->tlv_types[i] == dcbx) || dst->tlv_types[i] == type || dst->tlv_types[i] == all) return 1; } diff --git a/dcb_protocol.c b/dcb_protocol.c index 51902cf..d49bfaa 100644 --- a/dcb_protocol.c +++ b/dcb_protocol.c @@ -25,6 +25,7 @@ *******************************************************************************/ +#include #include #include "dcb_protocol.h" #include "dcb_driver_interface.h" @@ -42,7 +43,7 @@ u8 gdcbx_subtype = dcbx_subtype2; int set_configuration(char *device_name, u32 EventFlag); -int pg_not_initted = TRUE; +int pg_not_initted = true; struct pg_store1 { char ifname[MAX_DESCRIPTION_LEN]; pg_attribs *second; @@ -62,16 +63,6 @@ struct pg_store1 *pg_find(struct pghead *head, char *ifname) return p; } -/*void *list_find(void *head, char *ifname) -{ - struct pg_store1 *p = NULL; - - for (p = head->lh_first; p != NULL; p = p->entries.le_next) - if (!strcmp(p->ifname, ifname)) - return p; - return p; -}*/ - void pg_insert(struct pghead *head, char *ifname, pg_attribs *store) { struct pg_store1 *entry = NULL; @@ -79,16 +70,9 @@ void pg_insert(struct pghead *head, char *ifname, pg_attribs *store) if (!entry) return; strncpy(entry->ifname, ifname, sizeof(entry->ifname)); - entry->second = store; /*todo: will store be gone?*/ + entry->second = store; LIST_INSERT_HEAD(head, entry, entries); } -/*todo: void pg_erase(struct pghead *head, char *ifname) -{ - struct pg_store1 *p; - p = pg_find(head, ifname); - if (p) - LIST_REMOVE(p, entries); -}*/ void pg_erase(pg_it *p) { @@ -107,7 +91,7 @@ void pg_erase(pg_it *p) *p = NULL; } -int pfc_not_initted = TRUE; /*todo*/ +int pfc_not_initted = true; struct pfc_store { char ifname[MAX_DESCRIPTION_LEN]; pfc_attribs *second; @@ -149,7 +133,7 @@ void pfc_erase(pfc_it *p) *p = NULL; } -int pgdesc_not_initted = TRUE; /*todo*/ +int pgdesc_not_initted = true; struct pg_desc_store { char ifname[MAX_DESCRIPTION_LEN]; pg_info *second; @@ -190,7 +174,7 @@ void pgdesc_erase(pg_desc_it *p) *p = NULL; } -int app_not_initted = TRUE; /*todo*/ +int app_not_initted = true; struct app_store { char ifname[MAX_DESCRIPTION_LEN]; u32 app_subtype; @@ -236,7 +220,7 @@ void apptlv_erase(app_it *p) } -int llink_not_initted = TRUE; /*todo*/ +int llink_not_initted = true; struct llink_store { char ifname[MAX_DESCRIPTION_LEN]; u32 llink_subtype; @@ -281,7 +265,7 @@ void llink_erase(llink_it *p) *p = NULL; } -int ctrl_not_initted = TRUE; /*todo*/ +int ctrl_not_initted = true; struct dcb_control_protocol { char ifname[MAX_DESCRIPTION_LEN]; control_protocol_attribs *second; @@ -326,7 +310,7 @@ void ctrl_prot_erase(control_prot_it *p) *p = NULL; } -int feature_not_initted = TRUE; /*todo*/ +int feature_not_initted = true; struct features_store { char ifname[MAX_DESCRIPTION_LEN]; feature_support *second; @@ -381,21 +365,21 @@ void init_pg(pg_attribs *Attrib, pg_attribs *Store) Attrib->protocol.Max_version = DCB_PG_MAX_VERSION; Attrib->protocol.State = DCB_INIT; - Attrib->protocol.Advertise_prev = FALSE; - Attrib->protocol.tlv_sent = FALSE; + Attrib->protocol.Advertise_prev = false; + Attrib->protocol.tlv_sent = false; Attrib->protocol.dcbx_st = gdcbx_subtype; memcpy(Store, Attrib, sizeof (*Attrib)); } /* pass in the pointer to attrib */ -boolean_t add_pg(char *device_name, pg_attribs *Attrib) +bool add_pg(char *device_name, pg_attribs *Attrib) { pg_it it = pg_find(&pg, device_name); if (it == NULL) { /* Device not present: add */ pg_attribs *store = (pg_attribs*)malloc(sizeof(*store)); - if (!store) return FALSE; + if (!store) return false; init_pg(Attrib, store); pg_insert(&pg, device_name, store); @@ -410,7 +394,7 @@ boolean_t add_pg(char *device_name, pg_attribs *Attrib) memcpy(&(it->second->rx), &(Attrib->rx), sizeof(Attrib->rx)); memcpy(&(it->second->tx), &(Attrib->tx), sizeof(Attrib->tx)); } - return TRUE; + return true; } void init_oper_pg(pg_attribs *Attrib) @@ -427,7 +411,7 @@ void init_oper_pg(pg_attribs *Attrib) memcpy(&(Attrib->tx), &(itpg->second->tx), sizeof(Attrib->tx)); } -boolean_t add_oper_pg(char *device_name) +bool add_oper_pg(char *device_name) { pg_it it = pg_find(&oper_pg, device_name); if (it == NULL) { @@ -435,33 +419,33 @@ boolean_t add_oper_pg(char *device_name) pg_attribs *store = (pg_attribs*)malloc(sizeof(*store)); - if (!store) return FALSE; + if (!store) return false; init_oper_pg( store); pg_insert(&oper_pg, device_name, store); } - return TRUE; + return true; } void init_peer_pg(pg_attribs *Attrib) { memset(Attrib,0,sizeof(*Attrib)); - Attrib->protocol.TLVPresent = FALSE; + Attrib->protocol.TLVPresent = false; } -boolean_t add_peer_pg(char *device_name) +bool add_peer_pg(char *device_name) { pg_it it = pg_find(&peer_pg, device_name); if (it == NULL) { /* Device not present: add */ pg_attribs *store = (pg_attribs*)malloc(sizeof(*store)); - if (!store) return FALSE; + if (!store) return false; init_peer_pg( store); pg_insert(&peer_pg, device_name, store); } - return TRUE; + return true; } void init_apptlv(app_attribs *Attrib, app_attribs *Store) @@ -469,13 +453,13 @@ void init_apptlv(app_attribs *Attrib, app_attribs *Store) memset(Store,0,sizeof(*Store)); Attrib->protocol.Max_version = DCB_APPTLV_MAX_VERSION; Attrib->protocol.State = DCB_INIT; - Attrib->protocol.Advertise_prev = FALSE; - Attrib->protocol.tlv_sent = FALSE; + Attrib->protocol.Advertise_prev = false; + Attrib->protocol.tlv_sent = false; Attrib->protocol.dcbx_st = gdcbx_subtype; memcpy(Store, Attrib, sizeof (*Attrib)); } -boolean_t add_apptlv(char *device_name, app_attribs *Attrib, u32 Subtype, +bool add_apptlv(char *device_name, app_attribs *Attrib, u32 Subtype, dcbx_state *state) { full_dcb_attrib_ptrs attr_ptr; @@ -485,14 +469,14 @@ boolean_t add_apptlv(char *device_name, app_attribs *Attrib, u32 Subtype, */ if (state && Subtype == APP_FCOE_STYPE && state->FCoEenable && !Attrib->protocol.Enable) { - Attrib->protocol.Enable = TRUE; + Attrib->protocol.Enable = true; memset(&attr_ptr, 0, sizeof(attr_ptr)); attr_ptr.app = Attrib; attr_ptr.app_subtype = (u8)Subtype; if (set_persistent(device_name, &attr_ptr) != dcb_success) { printf("Set persistent failed in add_apptlv\n"); - return FALSE; + return false; } } @@ -501,7 +485,7 @@ boolean_t add_apptlv(char *device_name, app_attribs *Attrib, u32 Subtype, /* Device not present: add */ app_attribs *store = (app_attribs*)malloc(sizeof(*store)); if (!store) - return FALSE; + return false; init_apptlv(Attrib, store); apptlv_insert(&apptlv, device_name, Subtype, store); @@ -515,7 +499,7 @@ boolean_t add_apptlv(char *device_name, app_attribs *Attrib, u32 Subtype, it->second->Length = Attrib->Length; memcpy(it->second->AppData, Attrib->AppData, Attrib->Length); } - return TRUE; + return true; } void init_oper_apptlv(app_attribs *Store, u32 Subtype) @@ -531,18 +515,18 @@ void init_oper_apptlv(app_attribs *Store, u32 Subtype) sizeof(Store->Length)); } -boolean_t add_oper_apptlv(char *device_name, u32 Subtype) +bool add_oper_apptlv(char *device_name, u32 Subtype) { app_it it = apptlv_find(&oper_apptlv, device_name, Subtype); if (it == NULL) { /* Device not present: add */ app_attribs *store = (app_attribs*)malloc(sizeof(*store)); if (!store) - return FALSE; + return false; init_oper_apptlv(store, Subtype); apptlv_insert(&oper_apptlv, device_name, Subtype, store); } - return TRUE; + return true; } void init_peer_apptlv(app_attribs *Store) @@ -550,19 +534,19 @@ void init_peer_apptlv(app_attribs *Store) memset(Store,0,sizeof(*Store)); } -boolean_t add_peer_apptlv(char *device_name, u32 Subtype) +bool add_peer_apptlv(char *device_name, u32 Subtype) { app_it it = apptlv_find(&peer_apptlv, device_name, Subtype); if (it == NULL) { /* Device not present: add */ app_attribs *store = (app_attribs*)malloc(sizeof(*store)); if (!store) - return FALSE; + return false; init_peer_apptlv(store); apptlv_insert(&peer_apptlv, device_name, Subtype, store); } - return TRUE; + return true; } void init_control_prot(control_protocol_attribs *Attrib, dcbx_state *state) @@ -575,7 +559,7 @@ void init_control_prot(control_protocol_attribs *Attrib, dcbx_state *state) Attrib->MyAckNo = state->SeqNo; } -boolean_t add_control_protocol(char *device_name, dcbx_state *state) +bool add_control_protocol(char *device_name, dcbx_state *state) { control_prot_it it = ctrl_prot_find(&dcb_control_prot, device_name); if (it == NULL) { @@ -584,12 +568,12 @@ boolean_t add_control_protocol(char *device_name, dcbx_state *state) (control_protocol_attribs*)malloc(sizeof(*store)); if (!store) - return FALSE; + return false; init_control_prot(store, state); ctrl_prot_insert(&dcb_control_prot, device_name, store); } - return TRUE; + return true; } void init_peer_control_prot(control_protocol_attribs *Attrib) @@ -600,7 +584,7 @@ void init_peer_control_prot(control_protocol_attribs *Attrib) Attrib->RxDCBTLVState = DCB_PEER_NONE; } -boolean_t add_peer_control_protocol(char *device_name) +bool add_peer_control_protocol(char *device_name) { control_prot_it it = ctrl_prot_find(&dcb_peer_control_prot, device_name); @@ -610,12 +594,12 @@ boolean_t add_peer_control_protocol(char *device_name) (control_protocol_attribs*)malloc(sizeof(*store)); if (!store) - return FALSE; + return false; init_peer_control_prot( store); ctrl_prot_insert(&dcb_peer_control_prot, device_name, store); } - return TRUE; + return true; } void init_pfc(pfc_attribs *Attrib, pfc_attribs *Store) @@ -623,13 +607,13 @@ void init_pfc(pfc_attribs *Attrib, pfc_attribs *Store) memset(Store,0,sizeof(*Store)); Attrib->protocol.Max_version = DCB_PFC_MAX_VERSION; Attrib->protocol.State = DCB_INIT; - Attrib->protocol.Advertise_prev = FALSE; - Attrib->protocol.tlv_sent = FALSE; + Attrib->protocol.Advertise_prev = false; + Attrib->protocol.tlv_sent = false; Attrib->protocol.dcbx_st = gdcbx_subtype; memcpy(Store, Attrib, sizeof(*Attrib)); } -boolean_t add_pfc(char *device_name, pfc_attribs *Attrib) +bool add_pfc(char *device_name, pfc_attribs *Attrib) { pfc_it it = pfc_find(&pfc, device_name); if (it == NULL) { @@ -637,7 +621,7 @@ boolean_t add_pfc(char *device_name, pfc_attribs *Attrib) pfc_attribs *store = (pfc_attribs*)malloc(sizeof(*store)); if (!store) - return FALSE; + return false; init_pfc(Attrib, store); pfc_insert(&pfc, device_name, store); @@ -650,7 +634,7 @@ boolean_t add_pfc(char *device_name, pfc_attribs *Attrib) memcpy(it->second->admin, Attrib->admin, sizeof(Attrib->admin)); } - return TRUE; + return true; } void init_oper_pfc(pfc_attribs *Attrib) @@ -666,7 +650,7 @@ void init_oper_pfc(pfc_attribs *Attrib) memcpy(&(Attrib->admin), &(itpfc->second->admin), sizeof(Attrib->admin)); } -boolean_t add_oper_pfc(char *device_name) +bool add_oper_pfc(char *device_name) { pfc_it it = pfc_find(&oper_pfc, device_name); if (it == NULL) { @@ -674,22 +658,22 @@ boolean_t add_oper_pfc(char *device_name) pfc_attribs *store = (pfc_attribs*)malloc(sizeof(*store)); if (!store) - return FALSE; + return false; init_oper_pfc(store); pfc_insert(&oper_pfc, device_name, store); } - return TRUE; + return true; } void init_peer_pfc(pfc_attribs *Attrib) { memset(Attrib,0,sizeof(*Attrib)); - Attrib->protocol.TLVPresent = FALSE; + Attrib->protocol.TLVPresent = false; } -boolean_t add_peer_pfc(char *device_name) +bool add_peer_pfc(char *device_name) { pfc_it it = pfc_find(&peer_pfc, device_name); if (it == NULL) { @@ -697,12 +681,12 @@ boolean_t add_peer_pfc(char *device_name) pfc_attribs *store = (pfc_attribs*)malloc(sizeof(*store)); if (!store) - return FALSE; + return false; init_peer_pfc(store); pfc_insert(&peer_pfc, device_name, store); } - return TRUE; + return true; } void init_bwg_desc(pg_info *Attrib, pg_info *Store) @@ -711,7 +695,7 @@ void init_bwg_desc(pg_info *Attrib, pg_info *Store) memcpy(Store, Attrib, sizeof(*Attrib)); } -boolean_t add_bwg_desc(char *device_name, pg_info *Attrib) +bool add_bwg_desc(char *device_name, pg_info *Attrib) { pg_desc_it it = pgdesc_find(&pg_desc, device_name); if (it == NULL) { @@ -719,13 +703,13 @@ boolean_t add_bwg_desc(char *device_name, pg_info *Attrib) pg_info *store = (pg_info*)malloc(sizeof(*store)); if (!store) - return FALSE; + return false; init_bwg_desc(Attrib, store); store->max_pgid_desc = 8; pgdesc_insert(&pg_desc, device_name, store); } - return TRUE; + return true; } /* Logical Link */ @@ -734,20 +718,20 @@ void init_llink(llink_attribs *Attrib, llink_attribs *Store) memset(Store,0,sizeof(*Store)); Attrib->protocol.Max_version = DCB_LLINK_MAX_VERSION; Attrib->protocol.State = DCB_INIT; - Attrib->protocol.Advertise_prev = FALSE; - Attrib->protocol.tlv_sent = FALSE; + Attrib->protocol.Advertise_prev = false; + Attrib->protocol.tlv_sent = false; Attrib->protocol.dcbx_st = gdcbx_subtype; memcpy(Store, Attrib, sizeof(*Attrib)); } -boolean_t add_llink(char *device_name, llink_attribs *Attrib, u32 subtype) +bool add_llink(char *device_name, llink_attribs *Attrib, u32 subtype) { llink_it it = llink_find(&llink, device_name, subtype); if (it == NULL) { /* Device not present: add */ llink_attribs *store = (llink_attribs*)malloc(sizeof(*store)); if (!store) - return FALSE; + return false; init_llink(Attrib, store); llink_insert(&llink, device_name, store, subtype); @@ -761,7 +745,7 @@ boolean_t add_llink(char *device_name, llink_attribs *Attrib, u32 subtype) memcpy(&(it->second->llink), &(Attrib->llink), sizeof(Attrib->llink)); } - return TRUE; + return true; } void init_oper_llink(llink_attribs *Attrib, u32 subtype) @@ -776,64 +760,64 @@ void init_oper_llink(llink_attribs *Attrib, u32 subtype) sizeof(Attrib->llink)); } -boolean_t add_oper_llink(char *device_name, u32 subtype) +bool add_oper_llink(char *device_name, u32 subtype) { llink_it it = llink_find(&oper_llink, device_name, subtype); if (it == NULL) { /* Device not present: add */ llink_attribs *store = (llink_attribs*)malloc(sizeof(*store)); if (!store) - return FALSE; + return false; init_oper_llink(store, subtype); llink_insert(&oper_llink, device_name, store, subtype); } - return TRUE; + return true; } void init_peer_llink(llink_attribs *Attrib) { memset(Attrib,0,sizeof(*Attrib)); - Attrib->protocol.TLVPresent = FALSE; + Attrib->protocol.TLVPresent = false; } -boolean_t add_peer_llink(char *device_name, u32 subtype) +bool add_peer_llink(char *device_name, u32 subtype) { llink_it it = llink_find(&peer_llink, device_name, subtype); if (it == NULL) { /* Device not present: add */ llink_attribs *store = (llink_attribs*)malloc(sizeof(*store)); if (!store) - return FALSE; + return false; init_peer_llink(store); llink_insert(&peer_llink, device_name, store, subtype); } - return TRUE; + return true; } -boolean_t init_dcb_support(char *device_name, full_dcb_attribs *attrib) +bool init_dcb_support(char *device_name, full_dcb_attribs *attrib) { feature_support dcb_support; memset(&dcb_support, 0, sizeof(feature_support)); if (get_dcb_capabilities(device_name, &dcb_support) != 0) { - return FALSE; + return false; } /*if (!dcb_support.pg) { - * attrib->pg.protocol.Enable = FALSE; - * attrib->pg.protocol.Advertise = FALSE; + * attrib->pg.protocol.Enable = false; + * attrib->pg.protocol.Advertise = false; *} *if (!dcb_support.pfc) { - * attrib->pfc.protocol.Enable = FALSE; - * attrib->pfc.protocol.Advertise = FALSE; + * attrib->pfc.protocol.Enable = false; + * attrib->pfc.protocol.Advertise = false; *} */ if (get_dcb_numtcs(device_name, &attrib->pg.num_tcs, &attrib->pfc.num_tcs) != 0) { - return FALSE; + return false; } features_it it = features_find(&feature_struct, device_name); @@ -842,12 +826,12 @@ boolean_t init_dcb_support(char *device_name, full_dcb_attribs *attrib) feature_support *store = (feature_support*) malloc(sizeof(*store)); if (!store) - return FALSE; + return false; memcpy(store, (void *)&dcb_support, sizeof(*store)); features_insert(&feature_struct, device_name, store); } - return TRUE; + return true; } dcb_result get_dcb_support(char *device_name, feature_support *dcb_support) @@ -891,7 +875,6 @@ void remove_dcb_support(void) { while (feature_struct.lh_first != NULL) /* Delete. */ features_erase(&feature_struct.lh_first); - } int dcbx_add_adapter(char *device_name) @@ -1089,23 +1072,23 @@ add_adapter_error: if (sResult != dcb_success) { printf("add_adapter: Service unable to use network adapter\n"); log_message(MSG_ERR_ADD_CARD_FAILURE, "%s", device_name); - return FALSE; + return false; } - return TRUE; + return true; } -boolean_t add_adapter(char *device_name) +int add_adapter(char *device_name) { - printf("add_adapter (%s)\n", device_name); + LLDPAD_DBG("%s:%s\n", __func__, device_name); if (add_port(device_name) < 0) { - printf("add_adapter: add_port failed.\n"); + LLDPAD_ERR("%s:%s: failed\n", __func__, device_name); log_message(MSG_ERR_ADD_CARD_FAILURE, "%s", device_name); - return FALSE; + return -1; } - return TRUE; + return 0; } int dcbx_remove_adapter(char *device_name) @@ -1233,21 +1216,20 @@ int dcbx_remove_adapter(char *device_name) printf("remove_adapter: oper llink not found\n"); } } - return TRUE; + return true; } -boolean_t remove_adapter(char *device_name) +int remove_adapter(char *device_name) { /* NOTE: the parameter "device_name" is freed during this routine * and must not be used after it is copied*/ char devName[MAX_DEVICE_NAME_LEN]; /* local copy of device_name */ int not_default = 1; - boolean_t retval = TRUE; /* save device name for remove port */ if (device_name == NULL) { printf("remove_adapter: null device\n"); - return FALSE; + return -1; } not_default = memcmp(DEF_CFG_STORE, device_name, @@ -1259,11 +1241,10 @@ boolean_t remove_adapter(char *device_name) set_linkmode(device_name, 0); if (remove_port(devName) < 0) { printf("remove_port: failed\n"); - retval = FALSE; + return -1; } } - - return retval; + return 0; } @@ -1311,7 +1292,7 @@ int dcbx_remove_all(void) snprintf(sTmp, MAX_DEVICE_NAME_LEN*2, /* Localization OK */ "Remove_all_adapters error: Bad device name: %.*s\n", MAX_DEVICE_NAME_LEN, it->ifname); - if (remove_adapter((char *) (it->ifname)) == FALSE) + if (remove_adapter((char *) (it->ifname)) < 0) printf(sTmp); } @@ -1332,7 +1313,7 @@ void remove_all_adapters() } /* the default attributes object needs to be removed last */ - if (remove_adapter(DEF_CFG_STORE) == FALSE) { + if (remove_adapter(DEF_CFG_STORE) < 0) { snprintf(sTmp, MAX_DEVICE_NAME_LEN*2, "Remove_all_adapters error: Bad device name: %.*s\n", MAX_DEVICE_NAME_LEN, DEF_CFG_STORE); @@ -1342,11 +1323,11 @@ void remove_all_adapters() return; } -boolean_t add_pg_defaults() +bool add_pg_defaults() { pg_attribs pg_data; char sTmp[MAX_DESCRIPTION_LEN]; - boolean_t result = TRUE; + bool result = true; int index, portion, rmndr, temp; /* todo: - must be a better way and place to do this */ @@ -1354,7 +1335,7 @@ boolean_t add_pg_defaults() LIST_INIT(&pg); LIST_INIT(&oper_pg); LIST_INIT(&peer_pg); - pg_not_initted = FALSE; + pg_not_initted = false; } memset(&pg_data, 0, sizeof(pg_attribs)); @@ -1401,32 +1382,31 @@ boolean_t add_pg_defaults() /* Create pg default data store for the device. */ if (!add_pg(sTmp, &pg_data)) - result = FALSE; + result = false; return result; } -boolean_t remove_pg_defaults() +bool remove_pg_defaults() { char sTmp[MAX_DESCRIPTION_LEN]; - pg_it itpg; snprintf(sTmp, MAX_DESCRIPTION_LEN, DEF_CFG_STORE); - itpg = pg_find(&pg, sTmp); + pg_it itpg = pg_find(&pg, sTmp); if (itpg == NULL) - return FALSE; + return false; /* erase and free memory */ pg_erase(&itpg); - return TRUE; + return true; } -boolean_t add_pfc_defaults() +bool add_pfc_defaults() { pfc_attribs pfc_data; char sTmp[MAX_DESCRIPTION_LEN]; - boolean_t result = TRUE; + bool result = true; int index; /* todo: - must be a better way and place to do this */ @@ -1434,7 +1414,7 @@ boolean_t add_pfc_defaults() LIST_INIT(&pfc); LIST_INIT(&oper_pfc); LIST_INIT(&peer_pfc); - pfc_not_initted = FALSE; + pfc_not_initted = false; } memset (&pfc_data, 0, sizeof(pfc_attribs)); @@ -1450,40 +1430,39 @@ boolean_t add_pfc_defaults() snprintf(sTmp, MAX_DESCRIPTION_LEN, DEF_CFG_STORE); /* Create pfc default data store for the device. */ if (!add_pfc(sTmp, &pfc_data)) - result = FALSE; + result = false; return result; } -boolean_t remove_pfc_defaults() +bool remove_pfc_defaults() { char sTmp[MAX_DESCRIPTION_LEN]; - pfc_it itpfc; snprintf(sTmp, MAX_DESCRIPTION_LEN, DEF_CFG_STORE); - itpfc = pfc_find(&pfc, sTmp); + pfc_it itpfc = pfc_find(&pfc, sTmp); if (itpfc == NULL) { - return FALSE; + return false; } /* erase and free memory */ pfc_erase(&itpfc); - return TRUE; + return true; } -boolean_t add_app_defaults(u32 subtype) +bool add_app_defaults(u32 subtype) { app_attribs app_data; char sTmp[MAX_DESCRIPTION_LEN]; - boolean_t result = TRUE; + bool result = true; /* todo: - must be a better way and place to do this */ if (app_not_initted) { LIST_INIT(&apptlv); LIST_INIT(&oper_apptlv); LIST_INIT(&peer_apptlv); - app_not_initted = FALSE; + app_not_initted = false; } memset (&app_data, 0, sizeof(app_attribs)); @@ -1505,42 +1484,41 @@ boolean_t add_app_defaults(u32 subtype) /* Create app default data store for the device and app subtype. */ if (!add_apptlv(sTmp, &app_data, subtype, NULL)) - result = FALSE; + result = false; return result; } -boolean_t remove_app_defaults(u32 subtype) +bool remove_app_defaults(u32 subtype) { char sTmp[MAX_DESCRIPTION_LEN]; - app_it it; snprintf(sTmp, MAX_DESCRIPTION_LEN, "%s", /* Localization OK */ DEF_CFG_STORE); - it = apptlv_find(&apptlv, sTmp, subtype); + app_it it = apptlv_find(&apptlv, sTmp, subtype); if (it == NULL) { - return FALSE; + return false; } /* erase and free memory */ apptlv_erase(&it); - return TRUE; + return true; } -boolean_t add_llink_defaults(u32 subtype) +bool add_llink_defaults(u32 subtype) { llink_attribs llink_data; char sTmp[MAX_DESCRIPTION_LEN]; - boolean_t result = TRUE; + bool result = true; /* todo: - must be a better way and place to do this */ if (llink_not_initted) { LIST_INIT(&llink); LIST_INIT(&oper_llink); LIST_INIT(&peer_llink); - llink_not_initted = FALSE; + llink_not_initted = false; } memset (&llink_data, 0, sizeof(llink_attribs)); @@ -1553,27 +1531,26 @@ boolean_t add_llink_defaults(u32 subtype) snprintf(sTmp, MAX_DESCRIPTION_LEN, DEF_CFG_STORE); /* Create llink default data store for the device. */ if (!add_llink(sTmp, &llink_data, subtype)) - result = FALSE; + result = false; return result; } -boolean_t remove_llink_defaults(u32 subtype) +bool remove_llink_defaults(u32 subtype) { char sTmp[MAX_DESCRIPTION_LEN]; - llink_it itllink; snprintf(sTmp, MAX_DESCRIPTION_LEN, "%s", /* Localization OK */ DEF_CFG_STORE); - itllink = llink_find(&llink, sTmp, subtype); + llink_it itllink = llink_find(&llink, sTmp, subtype); if (itllink == NULL) { - return FALSE; + return false; } /* erase and free memory */ llink_erase(&itllink); - return TRUE; + return true; } dcb_result get_pg(char *device_name, pg_attribs *pg_data) @@ -1591,13 +1568,10 @@ dcb_result get_pg(char *device_name, pg_attribs *pg_data) } else { result = get_persistent(device_name, &attribs); - if (result == dcb_success) { + if (result == dcb_success) memcpy(pg_data, &attribs.pg, sizeof(*pg_data)); - } - else { - CheckForDevice(device_name); + else result = dcb_device_not_found; - } } return result; } @@ -1619,12 +1593,10 @@ dcb_result get_oper_pg(char *device_name, pg_attribs *pg_data) if (!pg_data) return dcb_bad_params; pg_it it = pg_find(&oper_pg, device_name); - if (it != NULL) { + if (it != NULL) memcpy(pg_data, it->second, sizeof(*pg_data)); - } else { - CheckForDevice(device_name); + else result = dcb_device_not_found; - } return result; } @@ -1648,28 +1620,28 @@ void mark_pg_sent(char *device_name) { pg_it it = pg_find(&pg, device_name); if (it != NULL) - it->second->protocol.tlv_sent = TRUE; + it->second->protocol.tlv_sent = true; } void mark_pfc_sent(char *device_name) { pfc_it it = pfc_find(&pfc, device_name); if (it != NULL) - it->second->protocol.tlv_sent = TRUE; + it->second->protocol.tlv_sent = true; } void mark_app_sent(char *device_name, u32 subtype) { app_it it = apptlv_find(&apptlv, device_name, subtype); if (it != NULL) - it->second->protocol.tlv_sent = TRUE; + it->second->protocol.tlv_sent = true; } void mark_llink_sent(char *device_name, u32 subtype) { llink_it it = llink_find(&llink, device_name, subtype); if (it != NULL) - it->second->protocol.tlv_sent = TRUE; + it->second->protocol.tlv_sent = true; } dcb_result put_pg(char *device_name, pg_attribs *pg_data) @@ -1678,7 +1650,7 @@ dcb_result put_pg(char *device_name, pg_attribs *pg_data) full_dcb_attrib_ptrs attr_ptr; u32 EventFlag = 0; dcb_result result = dcb_success; - boolean_t bChange = FALSE; + bool bChange = false; if (!pg_data) return dcb_bad_params; @@ -1701,7 +1673,7 @@ dcb_result put_pg(char *device_name, pg_attribs *pg_data) result = dcb_bad_params; goto Exit; } - bChange = TRUE; + bChange = true; if (set_persistent(device_name, &attr_ptr) != dcb_success) { printf("Set persistent failed put_pg()\n"); @@ -1718,7 +1690,7 @@ dcb_result put_pg(char *device_name, pg_attribs *pg_data) dStore->Advertise = pg_data->protocol.Advertise; dStore->Enable = pg_data->protocol.Enable; dStore->Willing = pg_data->protocol.Willing; - dStore->tlv_sent = FALSE; + dStore->tlv_sent = false; memcpy(&(it->second->rx), &(pg_data->rx), sizeof(pg_data->rx)); memcpy(&(it->second->tx), &(pg_data->tx), sizeof(pg_data->tx)); @@ -1748,10 +1720,7 @@ dcb_result put_pg(char *device_name, pg_attribs *pg_data) result = dcb_device_not_found; } } -Exit: /*todo: why stub CheckForDevice() */ - if (dcb_device_not_found == result) { - CheckForDevice(device_name); - } +Exit: return result; } @@ -1801,9 +1770,6 @@ dcb_result put_peer_pg(char *device_name, pg_attribs *peer_pg_data) peer_it->second->num_tcs = peer_pg_data->num_tcs; } Exit: - if (dcb_device_not_found == result) { - CheckForDevice(device_name); - } return result; } @@ -1864,7 +1830,7 @@ dcb_result put_pfc(char *device_name, pfc_attribs *pfc_data) u32 EventFlag = 0; dcb_result result = dcb_success; full_dcb_attribs attribs; - boolean_t bChange = FALSE; + bool bChange = false; full_dcb_attrib_ptrs attr_ptr; if (!pfc_data) @@ -1877,7 +1843,7 @@ dcb_result put_pfc(char *device_name, pfc_attribs *pfc_data) if (memcmp(it->second, pfc_data, sizeof(*pfc_data)) == 0) { goto Exit; } - bChange = TRUE; + bChange = true; memset(&attr_ptr, 0, sizeof(attr_ptr)); attr_ptr.pfc = pfc_data; if (set_persistent(device_name, &attr_ptr) != dcb_success) { @@ -1894,7 +1860,7 @@ dcb_result put_pfc(char *device_name, pfc_attribs *pfc_data) dStore->Advertise = pfc_data->protocol.Advertise; dStore->Enable = pfc_data->protocol.Enable; dStore->Willing = pfc_data->protocol.Willing; - dStore->tlv_sent = FALSE; + dStore->tlv_sent = false; memcpy(it->second->admin, pfc_data->admin, sizeof(pfc_data->admin)); @@ -1923,9 +1889,6 @@ dcb_result put_pfc(char *device_name, pfc_attribs *pfc_data) result = dcb_device_not_found; } Exit: - if (dcb_device_not_found == result) { - CheckForDevice(device_name); - } return result; } @@ -1968,9 +1931,6 @@ dcb_result put_peer_pfc(char *device_name, pfc_attribs *peer_pfc_data) peer_it->second->num_tcs = peer_pfc_data->num_tcs; } Exit: - if (dcb_device_not_found == result) { - CheckForDevice(device_name); - } return result; } @@ -2028,7 +1988,7 @@ dcb_result put_app(char *device_name, u32 subtype, app_attribs *app_data) full_dcb_attribs attribs; full_dcb_attrib_ptrs attr_ptr; u32 EventFlag = 0; - boolean_t bChange = FALSE; + bool bChange = false; dcb_result result = dcb_success; if (!app_data) @@ -2043,7 +2003,7 @@ dcb_result put_app(char *device_name, u32 subtype, app_attribs *app_data) goto Exit; } /* Store in persistent storage */ - bChange = TRUE; + bChange = true; memset(&attr_ptr, 0, sizeof(attr_ptr)); attr_ptr.app = app_data; attr_ptr.app_subtype = (u8)subtype; @@ -2060,7 +2020,7 @@ dcb_result put_app(char *device_name, u32 subtype, app_attribs *app_data) dStore->Advertise = app_data->protocol.Advertise; dStore->Enable = app_data->protocol.Enable; dStore->Willing = app_data->protocol.Willing; - dStore->tlv_sent = FALSE; + dStore->tlv_sent = false; if (app_data->Length) { it->second->Length = app_data->Length; @@ -2091,9 +2051,6 @@ dcb_result put_app(char *device_name, u32 subtype, app_attribs *app_data) } } Exit: - if (dcb_device_not_found == result) { - CheckForDevice(device_name); - } return result; } @@ -2133,9 +2090,6 @@ dcb_result put_peer_app(char *device_name, u32 subtype, memcpy(&(peer_it->second->AppData), &(peer_app_data->AppData), peer_app_data->Length); Exit: - if (dcb_device_not_found == result) { - CheckForDevice(device_name); - } return result; } @@ -2145,7 +2099,7 @@ dcb_result put_llink(char *device_name, u32 subtype, llink_attribs *llink_data) full_dcb_attribs attribs; u32 EventFlag = 0; dcb_result result = dcb_success; - boolean_t bChange = FALSE; + bool bChange = false; if (!llink_data) return dcb_bad_params; @@ -2160,7 +2114,7 @@ dcb_result put_llink(char *device_name, u32 subtype, llink_attribs *llink_data) sizeof(*llink_data)) == 0) { goto Exit; } - bChange = TRUE; + bChange = true; memset(&attr_ptr, 0, sizeof(attr_ptr)); attr_ptr.llink = llink_data; attr_ptr.llink_subtype = LLINK_FCOE_STYPE; @@ -2178,7 +2132,7 @@ dcb_result put_llink(char *device_name, u32 subtype, llink_attribs *llink_data) dStore->Advertise = llink_data->protocol.Advertise; dStore->Enable = llink_data->protocol.Enable; dStore->Willing = llink_data->protocol.Willing; - dStore->tlv_sent = FALSE; + dStore->tlv_sent = false; it->second->llink.llink_status = llink_data->llink.llink_status; @@ -2207,9 +2161,6 @@ dcb_result put_llink(char *device_name, u32 subtype, llink_attribs *llink_data) result = dcb_device_not_found; } Exit: - if (dcb_device_not_found == result) { - CheckForDevice(device_name); - } return result; } @@ -2250,9 +2201,6 @@ dcb_result put_peer_llink(char *device_name, u32 subtype, sizeof(peer_llink_data->llink)); Exit: - if (dcb_device_not_found == result) { - CheckForDevice(device_name); - } return result; } @@ -2276,9 +2224,6 @@ dcb_result get_llink(char *device_name, u32 subtype, llink_attribs *llink_data) result = dcb_device_not_found; } - if (dcb_device_not_found == result) { - CheckForDevice(device_name); - } return result; } @@ -2296,10 +2241,6 @@ dcb_result get_oper_llink(char *device_name, u32 subtype, result = dcb_device_not_found; } - if (dcb_device_not_found == result) { - CheckForDevice(device_name); - } - return result; } @@ -2318,9 +2259,6 @@ dcb_result get_peer_llink(char *device_name, u32 subtype, result = dcb_device_not_found; } - /*todo:if (dcb_device_not_found == result) { - CheckForDevice(device_name); - }*/ return result; } @@ -2337,9 +2275,6 @@ dcb_result get_control(char *device_name, } else { result = dcb_device_not_found; } - /*todo:if (dcb_device_not_found == result) { - CheckForDevice(device_name); - }*/ return result; } @@ -2359,9 +2294,7 @@ dcb_result get_peer_control(char *device_name, } else { result = dcb_device_not_found; } - /*todo:if (dcb_device_not_found == result) { - CheckForDevice(device_name); - }*/ + return result; } @@ -2394,9 +2327,6 @@ dcb_result put_peer_control(char *device_name, result = dcb_device_not_found; } - /*todo:if (dcb_device_not_found == result) { - CheckForDevice(device_name); - }*/ return result; } @@ -2444,9 +2374,6 @@ dcb_result get_bwg_descrpt(char *device_name, u8 bwgid, char **name) } } return result; - /*todo:if (dcb_device_not_found == result) { - CheckForDevice(device_name); - }*/ Error: printf("get_bwg_descrpt: Failed memory alloc\n"); return dcb_failed; @@ -2505,9 +2432,7 @@ dcb_result put_bwg_descrpt(char *device_name, u8 bwgid, char *name) else result = dcb_device_not_found; } - /*todo:if (dcb_device_not_found == result) { - CheckForDevice(device_name); - }*/ + return result; } @@ -2524,7 +2449,7 @@ dcb_result put_bwg_descrpt(char *device_name, u8 bwgid, char *name) ** u32 SubType - This is valid only for DCB_LOCAL_CHANGE_APPTLV and ** DCB_REMOTE_CHANGE_APPTLV ** -** Returns: TRUE if successful, failure code otherwise. +** Returns: true if successful, failure code otherwise. ** ******************************************************************************/ void CopyConfigToOper(char *device_name, u32 SrcFlag, u32 EventFlag, @@ -2711,10 +2636,10 @@ void CopyConfigToOper(char *device_name, u32 SrcFlag, u32 EventFlag, ** ULONG SubType - This is valid only for DCB_LOCAL_CHANGE_APPTLV ** and DCB_REMOTE_CHANGE_APPTLV ** -** Returns: TRUE if successful, failure code otherwise. +** Returns: true if successful, failure code otherwise. ** ******************************************************************************/ -boolean_t LocalPeerCompatible(char *device_name, u32 EventFlag, u32 Subtype) +bool LocalPeerCompatible(char *device_name, u32 EventFlag, u32 Subtype) { int i = 0; @@ -2726,7 +2651,7 @@ boolean_t LocalPeerCompatible(char *device_name, u32 EventFlag, u32 Subtype) pg_it Local = pg_find(&pg, device_name); pg_attribs *lpg; pg_attribs *ppg; - boolean_t match = FALSE; + bool match = false; if (Local == NULL) { goto Error; @@ -2738,28 +2663,28 @@ boolean_t LocalPeerCompatible(char *device_name, u32 EventFlag, u32 Subtype) lpg = Local->second; ppg = Peer->second; - match = TRUE; + match = true; if (ppg->protocol.dcbx_st == dcbx_subtype1) { for (i = 0; i < MAX_USER_PRIORITIES; i++) { if (lpg->tx.up[i].pgid != ppg->tx.up[i].pgid) - match = FALSE; + match = false; if (lpg->tx.up[i].strict_priority != ppg->tx.up[i].strict_priority) - match = FALSE; + match = false; if (lpg->tx.up[i].percent_of_pg_cap != ppg->tx.up[i].percent_of_pg_cap) - match = FALSE; + match = false; } for (i = 0; i < MAX_BANDWIDTH_GROUPS; i++) { if (lpg->tx.pg_percent[i] != ppg->tx.pg_percent[i]) - match = FALSE; + match = false; } } if (match) { printf(" COMPAT PG - passed\n"); - return TRUE; + return true; } printf(" COMPAT PG - failed\n"); } else if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_PFC, @@ -2780,7 +2705,7 @@ boolean_t LocalPeerCompatible(char *device_name, u32 EventFlag, u32 Subtype) &Peer->second->admin, sizeof(Local->second->admin))) { printf(" COMPAT PFC - passed\n"); - return TRUE; + return true; } printf(" COMPAT PFC - failed\n"); } else if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_APPTLV, @@ -2803,7 +2728,7 @@ boolean_t LocalPeerCompatible(char *device_name, u32 EventFlag, u32 Subtype) if (!memcmp(Local->second->AppData, Peer->second->AppData, Local->second->Length)) { - return TRUE; + return true; } } printf(" COMPAT APP - failed\n"); @@ -2813,13 +2738,13 @@ boolean_t LocalPeerCompatible(char *device_name, u32 EventFlag, u32 Subtype) DCB_REMOTE_CHANGE_LLINK)) { printf(" COMPAT LLINK - failed\n"); - return FALSE; + return false; } - return FALSE; + return false; Error: printf(" LocalPeerCompatible: device not found\n"); - return FALSE; + return false; } /* returns: 0 on success @@ -2902,7 +2827,7 @@ int set_configuration(char *device_name, u32 EventFlag) ** Method: handle_opermode_true ** ** Description: This routine is called by remove_adapter. -** For any feature whose OperMode is TRUE, send an +** For any feature whose OperMode is true, send an ** event since the port is going away - indicating an ** OperMode change. ** @@ -2962,9 +2887,9 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) feature_protocol_attribs *peer_feat_prot = NULL; control_prot_it ctrl_prot = NULL; control_prot_it peer_ctrl_prot = NULL; - boolean_t ErrorChanged = FALSE; - boolean_t Err, local_change; - boolean_t just_added = FALSE; + bool ErrorChanged = false; + bool Err, local_change; + bool just_added = false; pg_attribs old_pg_opcfg; int old_pg_opmode = 0; u32 pg_events = 0; @@ -3149,7 +3074,7 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) goto ErrNoDevice; } if (peer_ctrl_prot->second->Error_Flag & TOO_MANY_NGHBRS) { - peer_feat_prot->TLVPresent = FALSE; + peer_feat_prot->TLVPresent = false; printf("** Set Flag: TOO MANY NEIGHBORS \n"); feat_prot->Error_Flag |= FEAT_ERR_MULTI_PEER; } else { @@ -3158,8 +3083,8 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) if (feat_prot->State == DCB_INIT) { feat_prot->Oper_version = feat_prot->Max_version; - feat_prot->OperMode = FALSE; - feat_prot->Error = FALSE; + feat_prot->OperMode = false; + feat_prot->Error = false; /* Set the parameters. */ feat_prot->FeatureSeqNo = @@ -3173,11 +3098,11 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) /* Ensure PFC settings are synced up on initialization */ if (DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS, DCB_LOCAL_CHANGE_PFC)) - just_added = TRUE; + just_added = true; } if (feat_prot->State == DCB_LISTEN) { printf("Feature state machine (flags %x)\n", EventFlag); - local_change = FALSE; + local_change = false; if (DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS, DCB_LOCAL_CHANGE_PG) || DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS, @@ -3188,7 +3113,7 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) DCB_LOCAL_CHANGE_LLINK) ) { - local_change = TRUE; + local_change = true; printf(" Local change:"); printf(" %s", (EventFlag & DCB_LOCAL_CHANGE_PG) ? "PG" : ""); @@ -3214,16 +3139,16 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) ctrl_prot->second->SeqNo + 1; /* If Syncd false, then control state machine * will TX LLDP message with local config. */ - if ((feat_prot->Advertise == TRUE) || - (feat_prot->Advertise_prev == TRUE)) { - feat_prot->Syncd = FALSE; + if ((feat_prot->Advertise == true) || + (feat_prot->Advertise_prev == true)) { + feat_prot->Syncd = false; printf(" Set Syncd to %u [%u]\n", feat_prot->Syncd, __LINE__); } else { - feat_prot->Syncd = TRUE; + feat_prot->Syncd = true; printf(" Set Syncd to %u [%u]\n", feat_prot->Syncd, __LINE__); - feat_prot->tlv_sent = TRUE; + feat_prot->tlv_sent = true; } } /* F4 If don't advertise, then copy the local config to @@ -3245,7 +3170,7 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) EventFlag, Subtype); /* State already in Listen so don't have to * change. */ - feat_prot->Error = FALSE; + feat_prot->Error = false; // maintain TOO_MANY_NGHBRS & FEAT_ERR_MULTI_TLV errors Err = feat_prot->Error_Flag; @@ -3313,9 +3238,9 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) printf(" F6.2 - Peer DCBX TLV Expired\n"); CopyConfigToOper(device_name, LOCAL_STORE,EventFlag,Subtype); - feat_prot->OperMode = FALSE; - feat_prot->Syncd = FALSE; - feat_prot->Error = TRUE; + feat_prot->OperMode = false; + feat_prot->Syncd = false; + feat_prot->Error = true; feat_prot->FeatureSeqNo = 1; feat_prot->Error_Flag |= FEAT_ERR_NO_TLV; set_configuration(device_name, @@ -3330,16 +3255,16 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) /* copy the local config to Oper config. */ CopyConfigToOper(device_name, LOCAL_STORE, EventFlag, Subtype); - feat_prot->OperMode = FALSE; - feat_prot->Syncd = TRUE; + feat_prot->OperMode = false; + feat_prot->Syncd = true; printf(" Set Syncd to %u [%u]\n", feat_prot->Syncd, __LINE__); feat_prot->Oper_version = feat_prot->Max_version; if (feat_prot->dcbx_st == dcbx_subtype2) { - feat_prot->Error = TRUE; + feat_prot->Error = true; } else { - feat_prot->Error = FALSE; + feat_prot->Error = false; } feat_prot->Error_Flag |= FEAT_ERR_NO_TLV; set_configuration(device_name, EventFlag); @@ -3364,15 +3289,15 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) /* Copy Local config to Oper config. */ CopyConfigToOper(device_name, LOCAL_STORE, EventFlag, Subtype); - feat_prot->OperMode = FALSE; + feat_prot->OperMode = false; Err = feat_prot->Error; - feat_prot->Error = TRUE; - feat_prot->force_send = TRUE; + feat_prot->Error = true; + feat_prot->force_send = true; /* Set_configuration to driver. */ if (set_configuration(device_name, EventFlag)) feat_prot->Error_Flag |= FEAT_ERR_CFG; if (Err != feat_prot->Error) { - ErrorChanged = TRUE; + ErrorChanged = true; } goto ErrProt; } @@ -3389,14 +3314,14 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) printf(" Update feature oper version to %d " "and signal send\n", feat_prot->Oper_version); - feat_prot->Syncd = FALSE; + feat_prot->Syncd = false; printf(" Set Syncd to %u [%u]\n", feat_prot->Syncd, __LINE__); feat_prot->FeatureSeqNo = ctrl_prot->second->SeqNo + 1; goto OperChange; } - feat_prot->Syncd = TRUE; + feat_prot->Syncd = true; printf(" Set Syncd to %u [%u]\n", feat_prot->Syncd, __LINE__); /* F13/F14 */ @@ -3417,13 +3342,13 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) /* Copy Local config to Oper config. */ CopyConfigToOper(device_name, LOCAL_STORE, EventFlag, Subtype); - feat_prot->OperMode = FALSE; + feat_prot->OperMode = false; feat_prot->Error_Flag = FEAT_ERR_NONE; Err = feat_prot->Error; /* Set_configuration to driver. */ if (feat_prot->dcbx_st == dcbx_subtype2) { feat_prot->Syncd = !(feat_prot->Error); - feat_prot->Error = FALSE; + feat_prot->Error = false; if (set_configuration(device_name, EventFlag)) feat_prot->Error_Flag @@ -3437,7 +3362,7 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) FEAT_ERR_CFG; } if (Err != feat_prot->Error) { - ErrorChanged = TRUE; + ErrorChanged = true; } goto ErrProt; } @@ -3464,14 +3389,14 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) Subtype); } feat_prot->Syncd = !(feat_prot->Error); - feat_prot->Error = FALSE; + feat_prot->Error = false; /* Set_configuration to driver. */ if (set_configuration(device_name, EventFlag)) feat_prot->Error_Flag |= FEAT_ERR_CFG; } else { - feat_prot->OperMode = TRUE; + feat_prot->OperMode = true; /* Copy Peer config to Oper config. */ CopyConfigToOper(device_name, PEER_STORE, EventFlag,Subtype); @@ -3484,7 +3409,7 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) FEAT_ERR_CFG; } if (Err != feat_prot->Error) { - ErrorChanged = TRUE; + ErrorChanged = true; } goto ErrProt; } @@ -3505,13 +3430,13 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) feat_prot->OperMode = !peer_feat_prot->Error; feat_prot->Syncd = !(feat_prot->Error); - feat_prot->Error = FALSE; + feat_prot->Error = false; if (set_configuration(device_name, EventFlag)) feat_prot->Error_Flag |= FEAT_ERR_CFG; } else { - feat_prot->OperMode = TRUE; + feat_prot->OperMode = true; feat_prot->Error = (set_configuration( device_name, EventFlag) != dcb_success); @@ -3520,7 +3445,7 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) FEAT_ERR_CFG; } if (Err != feat_prot->Error) - ErrorChanged = TRUE; + ErrorChanged = true; goto ErrProt; } @@ -3542,13 +3467,13 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) feat_prot->OperMode = !peer_feat_prot->Error; feat_prot->Syncd = !(feat_prot->Error); - feat_prot->Error = FALSE; + feat_prot->Error = false; if (set_configuration(device_name, EventFlag)) feat_prot->Error_Flag |= FEAT_ERR_CFG; } else { - feat_prot->OperMode = TRUE; + feat_prot->OperMode = true; feat_prot->Error = (set_configuration( device_name, EventFlag) != dcb_success); @@ -3557,26 +3482,26 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) FEAT_ERR_CFG; } if (Err != feat_prot->Error) - ErrorChanged = TRUE; + ErrorChanged = true; } else { printf(" F23 - Local & Peer config not" " compatible\n"); /* Copy Local config to Oper config. */ CopyConfigToOper(device_name, LOCAL_STORE, EventFlag, Subtype); - feat_prot->OperMode = FALSE; + feat_prot->OperMode = false; Err = feat_prot->Error; /* Set default configuration */ if (feat_prot->dcbx_st == dcbx_subtype2) { feat_prot->Syncd = feat_prot->Error; - feat_prot->Error = TRUE; + feat_prot->Error = true; if (set_configuration(device_name, EventFlag)) feat_prot->Error_Flag |= FEAT_ERR_CFG; } else { - feat_prot->Error = TRUE; + feat_prot->Error = true; if (set_configuration(device_name, EventFlag) != dcb_success) feat_prot->Error_Flag |= @@ -3584,7 +3509,7 @@ dcb_result run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype) } feat_prot->Error_Flag |= FEAT_ERR_MISMATCH; if (Err != feat_prot->Error) - ErrorChanged = TRUE; + ErrorChanged = true; } ErrProt: if (peer_feat_prot->Error) @@ -3600,7 +3525,7 @@ ErrProt: feat_prot->Error_Flag, EventFlag); if (feat_prot->OperMode) { - feat_prot->OperMode = FALSE; + feat_prot->OperMode = false; /* Set default configuration */ set_configuration(device_name, EventFlag); @@ -3610,7 +3535,7 @@ ErrProt: if (ErrorChanged) { printf(" ErrorChanged \n"); if (feat_prot->dcbx_st == dcbx_subtype1) { - feat_prot->Syncd = FALSE; + feat_prot->Syncd = false; printf(" Set Syncd to %u [%u]\n", feat_prot->Syncd, __LINE__); } @@ -3716,11 +3641,11 @@ OperChange: if (feat_prot->OperMode != old_llink_opmode) { llink_events = llink_events | EVENT_OPERMODE; if (feat_prot->OperMode) { - printf("llink opmode = TRUE\n"); + printf("llink opmode = true\n"); log_message(MSG_INFO_LLINK_OPER, "%s", device_name); } else { - printf("llink opmode = FALSE\n"); + printf("llink opmode = false\n"); log_message(MSG_ERR_LLINK_NONOPER,"%s", device_name); } @@ -3764,40 +3689,40 @@ dcb_result GetDCBTLVState(char *device_name, u8 *State) return dcb_success; } -boolean_t FeaturesSynched(char *device_name) +bool FeaturesSynched(char *device_name) { int i = 0; pg_it it = pg_find(&pg, device_name); if (it == NULL) { - return FALSE; + return false; } if (it->second->protocol.State == DCB_LISTEN) { - if ((it->second->protocol.Syncd == FALSE) || - (it->second->protocol.tlv_sent == FALSE)) - return FALSE; + if ((it->second->protocol.Syncd == false) || + (it->second->protocol.tlv_sent == false)) + return false; } /* Get the local PFC feature protocol */ pfc_it it1 = pfc_find(&pfc, device_name); if (it1 == NULL) { - return FALSE; + return false; } if (it1->second->protocol.State == DCB_LISTEN) { - if (it1->second->protocol.Syncd == FALSE || - it1->second->protocol.tlv_sent == FALSE) - return FALSE; + if (it1->second->protocol.Syncd == false || + it1->second->protocol.tlv_sent == false) + return false; } /* Get the APP TLV feature protocol. */ for (i = 0; i < DCB_MAX_APPTLV ; i++) { app_it it2 = apptlv_find(&apptlv, device_name, i); if (it2 == NULL) { - return FALSE; + return false; } if (it2->second->protocol.State == DCB_LISTEN) { - if (it2->second->protocol.Syncd == FALSE || - it2->second->protocol.tlv_sent ==FALSE) - return FALSE; + if (it2->second->protocol.Syncd == false || + it2->second->protocol.tlv_sent ==false) + return false; } } @@ -3805,19 +3730,19 @@ boolean_t FeaturesSynched(char *device_name) /* Get the local LLINK feature protocol */ llink_it it4 = llink_find(&llink, device_name, i); if (it4 == NULL) { - return FALSE; + return false; } if (it4->second->protocol.State == DCB_LISTEN) { - if (it4->second->protocol.Syncd == FALSE || - it4->second->protocol.tlv_sent == FALSE) - return FALSE; + if (it4->second->protocol.Syncd == false || + it4->second->protocol.tlv_sent == false) + return false; } } - return TRUE; + return true; } -/* Set the Syncd value to TRUE for features which are not advertising. +/* Set the Syncd value to true for features which are not advertising. */ void update_feature_syncd(char *device_name) { @@ -3825,28 +3750,28 @@ void update_feature_syncd(char *device_name) /* Get the local PG feature protocol */ pg_it it = pg_find(&pg, device_name); if (it != NULL) { - if (it->second->protocol.Advertise == FALSE) - it->second->protocol.Syncd = TRUE; - if (it->second->protocol.force_send == TRUE) - it->second->protocol.Syncd = TRUE; + if (it->second->protocol.Advertise == false) + it->second->protocol.Syncd = true; + if (it->second->protocol.force_send == true) + it->second->protocol.Syncd = true; } /* Get the local PFC feature protocol */ pfc_it it1 = pfc_find(&pfc, device_name); if (it1 != NULL) { - if (it1->second->protocol.Advertise == FALSE) - it1->second->protocol.Syncd = TRUE; - if (it1->second->protocol.force_send == TRUE) - it1->second->protocol.Syncd = TRUE; + if (it1->second->protocol.Advertise == false) + it1->second->protocol.Syncd = true; + if (it1->second->protocol.force_send == true) + it1->second->protocol.Syncd = true; } /* Get the APP TLV feature protocol. */ for (i = 0; i < DCB_MAX_APPTLV ; i++) { app_it it2 = apptlv_find(&apptlv, device_name, i); if (it2 != NULL) { - if (it2->second->protocol.Advertise == FALSE) - it2->second->protocol.Syncd = TRUE; - if (it2->second->protocol.force_send == TRUE) - it2->second->protocol.Syncd = TRUE; + if (it2->second->protocol.Advertise == false) + it2->second->protocol.Syncd = true; + if (it2->second->protocol.force_send == true) + it2->second->protocol.Syncd = true; } } @@ -3854,10 +3779,10 @@ void update_feature_syncd(char *device_name) /* Get the local LLINK feature protocol */ llink_it it4 = llink_find(&llink, device_name, i); if (it4 != NULL) { - if (it4->second->protocol.Advertise == FALSE) - it4->second->protocol.Syncd = TRUE; - if (it4->second->protocol.force_send == TRUE) - it4->second->protocol.Syncd = TRUE; + if (it4->second->protocol.Advertise == false) + it4->second->protocol.Syncd = true; + if (it4->second->protocol.force_send == true) + it4->second->protocol.Syncd = true; } } } @@ -3951,7 +3876,7 @@ dcb_result run_control_protocol(char *device_name, u32 EventFlag) DCB_REMOTE_CHANGE_LLINK) ) { - boolean_t SendDCBTLV = FALSE; + bool SendDCBTLV = false; printf(" Remote change detected: "); printf(" %s", (EventFlag & DCB_REMOTE_CHANGE_PG) ? "PG" : ""); @@ -3987,7 +3912,7 @@ dcb_result run_control_protocol(char *device_name, u32 EventFlag) return dcb_success; } else { /* Send the updated DCB TLV */ - SendDCBTLV = TRUE; + SendDCBTLV = true; goto send; } } @@ -4008,7 +3933,7 @@ dcb_result run_control_protocol(char *device_name, u32 EventFlag) ctrl_prot->second->Max_version); /* Send the updated DCB TLV */ - SendDCBTLV = TRUE; + SendDCBTLV = true; printf(" Change Oper Version \n"); goto send; } @@ -4035,7 +3960,7 @@ dcb_result run_control_protocol(char *device_name, u32 EventFlag) & TOO_MANY_NGHBRS)) { ctrl_prot->second->AckNo = peer_ctrl_prot->second->SeqNo; - SendDCBTLV = TRUE; + SendDCBTLV = true; } } @@ -4098,7 +4023,7 @@ send: dcb_result run_dcb_protocol(char *device_name, u32 EventFlag, u32 Subtype) { dcb_result result = dcb_success; - boolean_t LocalChange = FALSE; + bool LocalChange = false; u32 i, SubTypeMin, SubTypeMax; int oper; @@ -4119,14 +4044,14 @@ dcb_result run_dcb_protocol(char *device_name, u32 EventFlag, u32 Subtype) && (result != dcb_ctrl_vers_not_compatible)) { result = run_feature_protocol(device_name,DCB_LOCAL_CHANGE_PG, SUBTYPE_DEFAULT); - LocalChange = TRUE; + LocalChange = true; } if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_PFC, DCB_LOCAL_CHANGE_PFC) && (result != dcb_ctrl_vers_not_compatible)) { result = run_feature_protocol(device_name, DCB_LOCAL_CHANGE_PFC, SUBTYPE_DEFAULT); - LocalChange = TRUE; + LocalChange = true; } if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_APPTLV, DCB_LOCAL_CHANGE_APPTLV) && @@ -4136,7 +4061,7 @@ dcb_result run_dcb_protocol(char *device_name, u32 EventFlag, u32 Subtype) result = run_feature_protocol(device_name, DCB_LOCAL_CHANGE_APPTLV, i); } - LocalChange = TRUE; + LocalChange = true; } if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_LLINK, DCB_LOCAL_CHANGE_LLINK) @@ -4146,7 +4071,7 @@ dcb_result run_dcb_protocol(char *device_name, u32 EventFlag, u32 Subtype) result = run_feature_protocol(device_name, DCB_LOCAL_CHANGE_LLINK, i); } - LocalChange = TRUE; + LocalChange = true; } /* Only allow local or remote change at a time. */ if (!LocalChange) { diff --git a/dcb_rule_chk.c b/dcb_rule_chk.c index ffa4ade..434ffe7 100644 --- a/dcb_rule_chk.c +++ b/dcb_rule_chk.c @@ -49,7 +49,7 @@ dcb_check_config (full_dcb_attrib_ptrs *attribs) pg_attribs *pg; u8 i, tx_bw, rx_bw, tx_bw_id, rx_bw_id; u8 tx_bw_sum[MAX_BW_GROUP],rx_bw_sum[MAX_BW_GROUP]; - boolean_t tx_link_strict[MAX_BW_GROUP], rx_link_strict[MAX_BW_GROUP]; + bool tx_link_strict[MAX_BW_GROUP], rx_link_strict[MAX_BW_GROUP]; u8 link_strict_pgid; if (attribs == NULL) { @@ -156,7 +156,7 @@ dcb_check_config (full_dcb_attrib_ptrs *attribs) return dcb_bad_params; } if (pg->tx.up[i].strict_priority == dcb_link) { - tx_link_strict[tx_bw_id] = TRUE; + tx_link_strict[tx_bw_id] = true; /* Link strict should have zero bandwidth */ if (tx_bw){ log_message( @@ -180,7 +180,7 @@ dcb_check_config (full_dcb_attrib_ptrs *attribs) return dcb_bad_params; } if (pg->rx.up[i].strict_priority == dcb_link) { - rx_link_strict[rx_bw_id] = TRUE; + rx_link_strict[rx_bw_id] = true; /* Link strict class should have zero bandwidth */ if (rx_bw){ log_message(MSG_ERR_DCB_INVALID_RX_LSP_NZERO_BW_TC, @@ -259,20 +259,20 @@ void rebalance_uppcts(pg_attribs *pg) u8 uplist[MAX_USER_PRIORITIES]; int pgid; int num_found; - int link_strict; + bool link_strict; int adjust; int value; int i; for (pgid = 0; pgid < MAX_BW_GROUP; pgid++) { num_found = 0; - link_strict = FALSE; + link_strict = false; memset(uplist, 0xff, sizeof(uplist)); for (i = 0; i < MAX_USER_PRIORITIES; i++) { if (pg->tx.up[i].pgid == pgid) { uplist[num_found++] = (u8)i; if (pg->tx.up[i].strict_priority == dcb_link) { - link_strict = TRUE; + link_strict = true; pg->tx.up[i].percent_of_pg_cap = 0; pg->rx.up[i].percent_of_pg_cap = 0; } diff --git a/dcbtool.c b/dcbtool.c index 96a6881..2bf240d 100644 --- a/dcbtool.c +++ b/dcbtool.c @@ -106,10 +106,10 @@ static const char *cli_full_license = static const char *commands_help = "DCBX Commands:\n" " dcbx get configured or operational DCBX versions\n" -" the operational version takes effect on next\n" -" restart of the dcbd service\n" +" the configured version takes effect on next\n" +" restart of the lldpad service\n" " sc dcbx v:[12] set the DCBX version to be used after next\n" -" dcbd restart\n" +" lldpad restart\n" "Per Port Commands:\n" " gc get configuration of on port \n" " go get operational status of \n" @@ -300,7 +300,7 @@ static int _clif_command(struct clif *clif, char *cmd, int print) print_raw_message(cmd, print); if (clif_conn == NULL) { - printf("Not connected to dcbd - command dropped.\n"); + printf("Not connected to lldpad - command dropped.\n"); return -1; } len = sizeof(buf) - 1; @@ -394,9 +394,10 @@ static int cli_cmd_interface(struct clif *clif, int argc, if (clif_attach(clif_conn, NULL) == 0) cli_attached = 1; else - printf("Warning: Failed to attach to dcbd.\n"); + printf("Warning: Failed to attach to lldpad.\n"); } else { - printf("Could not connect to interface '%s' - re-trying\n", + printf( + "Could not connect to lldpad interface '%s' - re-trying\n", clif_ifname); } return 0; @@ -534,17 +535,18 @@ static void cli_terminate(int sig) static void cli_alarm(int sig) { if (clif_conn && _clif_command(clif_conn, "P", SHOW_NO_OUTPUT)) { - printf("Connection to dcbd lost - trying to reconnect\n"); + printf("Connection to lldpad lost - trying to reconnect\n"); cli_close_connection(); } if (!clif_conn) { clif_conn = cli_open_connection(clif_ifname); if (clif_conn) { - printf("Connection to dcbd re-established\n"); + printf("Connection to lldpad re-established\n"); if (clif_attach(clif_conn, NULL) == 0) cli_attached = 1; else - printf("Warning: Failed to attach to dcbd.\n"); + printf( + "Warning: Failed to attach to lldpad.\n"); } } if (clif_conn) @@ -623,12 +625,12 @@ int main(int argc, char *argv[]) } if (!interactive) { - perror("Failed to connect to dcbd - clif_open"); + perror("Failed to connect to lldpad - clif_open"); return -1; } if (!warning_displayed) { - printf("Could not connect to dcbd - re-trying\n"); + printf("Could not connect to lldpad - re-trying\n"); warning_displayed = 1; } sleep(1); @@ -643,7 +645,7 @@ int main(int argc, char *argv[]) if (clif_attach(clif_conn, NULL) == 0) cli_attached = 1; else - printf("Warning: Failed to attach to dcbd.\n"); + printf("Warning: Failed to attach to lldpad.\n"); cli_interactive(raw); } else ret = request(clif_conn, argc - optind, &argv[optind], raw); diff --git a/dcbtool_cmds.c b/dcbtool_cmds.c index 72f8860..237e35d 100644 --- a/dcbtool_cmds.c +++ b/dcbtool_cmds.c @@ -587,8 +587,8 @@ void print_dcb_cmd_response(char *buf, int status) case CMD_GET_OPER: if (feature == FEATURE_DCBX) break; - printf("Oper Version\t%d\n", hex2int(buf+doff+OPER_OPER_VER)); - printf("Max Version\t%d\n", hex2int(buf+doff+OPER_MAX_VER)); + printf("Oper Version:\t%d\n", hex2int(buf+doff+OPER_OPER_VER)); + printf("Max Version:\t%d\n", hex2int(buf+doff+OPER_MAX_VER)); printf("Errors: \t"); print_errors(hex2int(buf+doff+OPER_ERROR)); printf("Oper Mode: \t%s\n", (*(buf+doff+OPER_OPER_MODE) == '1')? @@ -603,8 +603,8 @@ void print_dcb_cmd_response(char *buf, int status) ("true"):("false")); printf("Willing: \t%s\n", (*(buf+doff+PEER_WILLING) == '1')? ("true"):("false")); - printf("Oper Version\t%d\n", hex2int(buf+doff+PEER_OPER_VER)); - printf("Max Version\t%d\n", hex2int(buf+doff+PEER_MAX_VER)); + printf("Oper Version:\t%d\n", hex2int(buf+doff+PEER_OPER_VER)); + printf("Max Version:\t%d\n", hex2int(buf+doff+PEER_MAX_VER)); printf("Error: \t%s\n", (*(buf+doff+PEER_ERROR) == '1')? ("true"):("false")); dcbx_st = (*(buf+doff+PEER_SUBTYPE)) & 0x0f; diff --git a/drv_cfg.c b/drv_cfg.c index 46383ec..6c02555 100644 --- a/drv_cfg.c +++ b/drv_cfg.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -38,12 +39,12 @@ #include #include #include "lldpad.h" -#include "lldp_rtnl.h" #include "dcb_driver_if_types.h" #include "dcb_driver_interface.h" #include "dcb_protocol.h" #include "drv_cfg.h" #include "lldp/ports.h" +#include "messages.h" static int nl_sd = 0; static int rtseq = 0; @@ -189,7 +190,7 @@ static struct nlmsghdr *get_msg(unsigned int seq) break; } if (!(NLMSG_OK(nlh, (unsigned int)len))) { - printf("get_msg: NLMSG_OK is FALSE\n"); + printf("get_msg: NLMSG_OK is false\n"); free(nlh); nlh = NULL; break; @@ -606,7 +607,7 @@ int set_hw_state(char *ifname, int dcb_state) /* returns: 0 on success * 1 on failure */ -int set_hw_pg(char *ifname, pgroup_attribs *pg_data, boolean_t oper_mode) +int set_hw_pg(char *ifname, pgroup_attribs *pg_data, bool oper_mode) { int i; int rval = 0; @@ -654,7 +655,7 @@ int set_hw_pg(char *ifname, pgroup_attribs *pg_data, boolean_t oper_mode) * non-zero on failure */ int set_hw_pfc(char *ifname, dcb_pfc_list_type pfc_data, - boolean_t oper_mode) + bool oper_mode) { int i; __u8 pfc[MAX_TRAFFIC_CLASSES]; @@ -782,28 +783,39 @@ int get_perm_hwaddr(const char *ifname, u8 *buf_perm, u8 *buf_san) NLMSG_ALIGN(sizeof(struct dcbmsg))); if (d->cmd != DCB_CMD_GPERM_HWADDR) { - printf("Hmm, this is not the message we were expecting.\n"); + LLDPAD_ERR("%s:%s:expecting GPERM_HWADDR but got 0x%x\n", + __func__, ifname, d->cmd); rval = -EIO; goto get_error; } if (rta->rta_type != DCB_ATTR_PERM_HWADDR) { /* Do we really want to code up an attribute parser?? */ - printf("A full libnetlink (with genl and attribute support) " - "would sure be nice.\n"); + LLDPAD_ERR("%s:%s:expecting PERM_HWADDR but got 0x%x\n", + __func__, ifname, rta->rta_type); rval = -EIO; goto get_error; } memcpy(buf_perm, NLA_DATA(rta), ETH_ALEN); - memcpy(buf_san, NLA_DATA(rta + ETH_ALEN*sizeof(u8)), ETH_ALEN); + memcpy(buf_san, NLA_DATA(rta) + ETH_ALEN, ETH_ALEN); + + LLDPAD_DBG("%s:%s:LAN MAC=%2x:%2x:%2x:%2x:%2x:%2x\n", + __func__, ifname, + buf_perm[0], buf_perm[1], buf_perm[2], + buf_perm[3], buf_perm[4], buf_perm[5]); + + LLDPAD_DBG("%s:%s:SAN MAC=%2x:%2x:%2x:%2x:%2x:%2x\n", + __func__, ifname, + buf_san[0], buf_san[1], buf_san[2], + buf_san[3], buf_san[4], buf_san[5]); get_error: free(nlh); return 0; } -boolean_t check_port_dcb_mode(char *ifname) +bool check_port_dcb_mode(char *ifname) { int dcb_state = 0; @@ -812,9 +824,9 @@ boolean_t check_port_dcb_mode(char *ifname) if (dcb_state) { TRACE2("config.c: %s dcb mode is ON.\n", ifname); - return TRUE; + return true; } else { TRACE2("config.c: %s dcb mode is OFF. \n", ifname); - return FALSE; + return false; } } diff --git a/event_iface.c b/event_iface.c index 5a5fd70..439e4d0 100644 --- a/event_iface.c +++ b/event_iface.c @@ -42,6 +42,7 @@ #include "drv_cfg.h" #include "event_iface.h" #include "lldp_util.h" +#include "dcb_driver_interface.h" #include "config.h" #include "lldp/l2_packet.h" #include "config.h" @@ -132,7 +133,6 @@ static void event_if_decode_nlmsg(int route_type, void *data, int len) struct lldp_module *np; const struct lldp_mod_ops *ops; struct rtattr *rta; - struct port *port; int attrlen; int val, err; @@ -164,6 +164,7 @@ static void event_if_decode_nlmsg(int route_type, void *data, int len) TRACE1("link status: ", link_status); TRACE2("device name: ", device_name); + switch (link_status) { case IF_OPER_DOWN: printf("******* LINK DOWN: %s\n", device_name); @@ -172,32 +173,12 @@ static void event_if_decode_nlmsg(int route_type, void *data, int len) if (!err) break; - port = porthead; - while (port != NULL) { - if (!strncmp(device_name, port->ifname, - MAX_DEVICE_NAME_LEN)) - break; - port = port->next; - } - - if (!port) { - printf("%s: %s: Unknown device!\n", - __func__, device_name); - - break; - } - - if (!init_cfg()) - break; - LIST_FOREACH(np, &lldp_head, lldp) { ops = np->ops; if (ops->lldp_mod_ifdown) ops->lldp_mod_ifdown(device_name); } - destroy_cfg(); - /* Disable Port */ set_lldp_port_enable_state(device_name, 0); @@ -227,8 +208,8 @@ static void event_if_decode_nlmsg(int route_type, void *data, int len) break; default: break; - } - break; + } + break; case RTM_NEWADDR: case RTM_DELADDR: case RTM_GETADDR: @@ -308,8 +289,3 @@ int event_iface_deinit() { return 0; } - -void CheckForDevice(char *sysName) -{ - return; -} diff --git a/include/common.h b/include/common.h index a890bde..01746ea 100644 --- a/include/common.h +++ b/include/common.h @@ -387,7 +387,4 @@ typedef int socklen_t; const char * wpa_ssid_txt(u8 *ssid, size_t ssid_len); -#define TRUE 1 -#define FALSE 0 - #endif /* COMMON_H */ diff --git a/include/ctrl_iface.h b/include/ctrl_iface.h index 947cf7c..a735933 100644 --- a/include/ctrl_iface.h +++ b/include/ctrl_iface.h @@ -48,7 +48,7 @@ struct clif_data { }; int ctrl_iface_init(struct clif_data *clifd); -void ctrl_iface_register(struct clif_data *clifd); +int ctrl_iface_register(struct clif_data *clifd); void ctrl_iface_deinit(struct clif_data *clifd); void ctrl_iface_send(struct clif_data *clifd, int level, u32 moduleid, char *buf, size_t len); diff --git a/include/dcb_driver_interface.h b/include/dcb_driver_interface.h index 593685d..3a3f639 100644 --- a/include/dcb_driver_interface.h +++ b/include/dcb_driver_interface.h @@ -33,9 +33,8 @@ extern "C" { #endif -int set_hw_pg(char *device_name, pgroup_attribs *pg_data, boolean_t Opermode); -int set_hw_pfc(char *device_name, dcb_pfc_list_type pfc_data, boolean_t - Opermode); +int set_hw_pg(char *device_name, pgroup_attribs *pg_data, bool Opermode); +int set_hw_pfc(char *device_name, dcb_pfc_list_type pfc_data, bool Opermode); #ifdef DCB_APP_DRV_IF_SUPPORTED int set_hw_app(char *device_name, appgroup_attribs *app_data); #endif /* DCB_APP_DRV_IF_SUPPORTED */ diff --git a/include/dcb_osdep.h b/include/dcb_osdep.h index aac5944..13aa2de 100644 --- a/include/dcb_osdep.h +++ b/include/dcb_osdep.h @@ -39,12 +39,6 @@ typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; -typedef char boolean_t; /* Boolean type used in shared code */ -typedef boolean_t BOOLEAN; - -#define TRUE 1 -#define FALSE 0 - #define IN #define max(x,y) ((x>y)?(x):(y)) diff --git a/include/dcb_protocol.h b/include/dcb_protocol.h index 4bbe314..63e2d3c 100644 --- a/include/dcb_protocol.h +++ b/include/dcb_protocol.h @@ -62,22 +62,17 @@ typedef enum { #define MIN(x, y) ((x) < (y) ? x : y) //#endif -#ifdef __cplusplus -extern "C" { -#endif - #define INIT_DCB_OUI {0x00,0x1b,0x21} -boolean_t add_adapter(char *device_name); -boolean_t remove_adapter(char *device_name); +int add_adapter(char *device_name); +int remove_adapter(char *device_name); int dcbx_add_adapter(char *device_name); int dcbx_remove_adapter(char *device_name); int dcbx_remove_all(void); -boolean_t init_dcb_support(char *device_name, full_dcb_attribs *attribs); +bool init_dcb_support(char *device_name, full_dcb_attribs *attribs); dcb_result get_dcb_support(char *device_name, struct feature_support *dcb_capabilites); void remove_dcb_support(void); -void CheckForDevice(char* sysName); /* unique strings for default data storage */ #define DEF_CFG_STORE "default_cfg_attribs" /* Localization OK */ @@ -85,17 +80,17 @@ void CheckForDevice(char* sysName); #define SUBTYPE_DEFAULT 0 -boolean_t add_pg_defaults(void); -boolean_t add_pfc_defaults(void); -boolean_t add_app_defaults(u32 subtype); -boolean_t remove_pg_defaults(void); -boolean_t remove_pfc_defaults(void); -boolean_t remove_app_defaults(u32 subtype); +bool add_pg_defaults(void); +bool add_pfc_defaults(void); +bool add_app_defaults(u32 subtype); +bool remove_pg_defaults(void); +bool remove_pfc_defaults(void); +bool remove_app_defaults(u32 subtype); void mark_pg_sent(char *device_name); void mark_pfc_sent(char *device_name); void mark_app_sent(char *device_name, u32 subtype); -boolean_t add_llink_defaults(u32 subtype); -boolean_t remove_llink_defaults(u32 subtype); +bool add_llink_defaults(u32 subtype); +bool remove_llink_defaults(u32 subtype); void mark_llink_sent(char *device_name, u32 subtype); dcb_result test_device_dstore(char *device_name); @@ -150,10 +145,4 @@ int set_dcbx_state(const char *device_name, dcbx_state *state); int get_dcbx_state(const char *device_name, dcbx_state *state); int clear_dcbx_state(); -void log_message(u32 dwMsgId, const char *pFormat, ...); - -#ifdef __cplusplus -} -#endif - #endif /*_DCB_PROTOCOL_H_ */ diff --git a/include/dcb_types.h b/include/dcb_types.h index 642a81b..f72f57b 100644 --- a/include/dcb_types.h +++ b/include/dcb_types.h @@ -174,20 +174,20 @@ typedef struct dcb_pfc_stats_type{ /* Field Error_Flag for feature Oper_state_config */ typedef struct feature_protocol_attribs { - boolean_t Enable; - boolean_t Willing; - boolean_t Advertise; - boolean_t Advertise_prev; - boolean_t OperMode; - boolean_t PeerWilling; /* for local data */ - boolean_t Error; - boolean_t Syncd; + bool Enable; + bool Willing; + bool Advertise; + bool Advertise_prev; + bool OperMode; + bool PeerWilling; /* for local data */ + bool Error; + bool Syncd; u32 Oper_version; u32 Max_version; u32 FeatureSeqNo; - boolean_t TLVPresent; /* for Peer data */ - boolean_t tlv_sent; /* for local config */ - boolean_t force_send; /* for local config */ + bool TLVPresent; /* for Peer data */ + bool tlv_sent; /* for local config */ + bool force_send; /* for local config */ u8 dcbx_st; u16 State; u8 Error_Flag; /* bitmap of Oper and Peer errors */ @@ -276,7 +276,7 @@ typedef struct feature_support { typedef struct dcbx_state { u32 SeqNo; u32 AckNo; - boolean_t FCoEenable; + bool FCoEenable; } dcbx_state; #endif /* DCB_CLIENT_IF_TYPES_H_ */ diff --git a/include/drv_cfg.h b/include/drv_cfg.h index a843310..6c80a9c 100644 --- a/include/drv_cfg.h +++ b/include/drv_cfg.h @@ -27,6 +27,7 @@ #ifndef _DRV_CFG_H #define _DRV_CFG_H +#include #ifdef DCB_NL @@ -177,11 +178,11 @@ struct tc_config { /* Maximum size of response requested or message sent */ -#define MAX_MSG_SIZE 4096 +#define MAX_MSG_SIZE 4096 int get_perm_hwaddr(const char *ifname, u8 *buf_perm, u8 *buf_san); int set_hw_state(char *device_name, int dcb_state); int get_hw_state(char *device_name, int *dcb_state); int init_drv_if(void); -boolean_t check_port_dcb_mode(char *device_name); +bool check_port_dcb_mode(char *device_name); diff --git a/include/includes.h b/include/includes.h index bc45806..518269e 100644 --- a/include/includes.h +++ b/include/includes.h @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include diff --git a/include/lldp_8023_clif.h b/include/lldp_8023_clif.h index 694c8b0..144752d 100644 --- a/include/lldp_8023_clif.h +++ b/include/lldp_8023_clif.h @@ -30,6 +30,6 @@ struct lldp_module *ieee8023_cli_register(void); void ieee8023_cli_unregister(struct lldp_module *); -int ieee8023_print_tlv(u32, u16, u8 *); +int ieee8023_print_tlv(u32, u16, char *); #endif diff --git a/include/lldp_basman_clif.h b/include/lldp_basman_clif.h index c336009..ca44ed8 100644 --- a/include/lldp_basman_clif.h +++ b/include/lldp_basman_clif.h @@ -30,7 +30,7 @@ struct lldp_module *basman_cli_register(void); void basman_cli_unregister(struct lldp_module *); -int basman_print_tlv(u32, u16, u8 *); +int basman_print_tlv(u32, u16, char *); #define ARG_IPV4_ADDR "ipv4" #define ARG_IPV6_ADDR "ipv6" diff --git a/include/lldp_dcbx_clif.h b/include/lldp_dcbx_clif.h index ce384ef..5ae41e7 100644 --- a/include/lldp_dcbx_clif.h +++ b/include/lldp_dcbx_clif.h @@ -30,6 +30,6 @@ struct lldp_module *dcbx_cli_register(void); void dcbx_cli_unregister(struct lldp_module *); -int dcbx_print_tlv(u32, u16, u8 *); +int dcbx_print_tlv(u32, u16, char *); #endif diff --git a/include/lldp_dcbx_cmds.h b/include/lldp_dcbx_cmds.h index 821e6dd..b1bed6e 100644 --- a/include/lldp_dcbx_cmds.h +++ b/include/lldp_dcbx_cmds.h @@ -32,6 +32,7 @@ #include "clif_msgs.h" struct arg_handlers *dcbx_get_arg_handlers(); +void dont_advertise_dcbx_all(char *ifname); #define CLIF_RSP_MSG_OFF 0 diff --git a/include/lldp_mand_clif.h b/include/lldp_mand_clif.h index f1f7575..350c340 100644 --- a/include/lldp_mand_clif.h +++ b/include/lldp_mand_clif.h @@ -32,7 +32,7 @@ struct lldp_module *mand_cli_register(void); void mand_cli_unregister(struct lldp_module *); -int mand_print_tlv(u32, u16, u8 *); +int mand_print_tlv(u32, u16, char *); typedef enum { cmd_getstats, diff --git a/include/lldp_med_clif.h b/include/lldp_med_clif.h index 6ae0f8d..3c54813 100644 --- a/include/lldp_med_clif.h +++ b/include/lldp_med_clif.h @@ -30,7 +30,7 @@ struct lldp_module *med_cli_register(void); void med_cli_unregister(struct lldp_module *); -int med_print_tlv(u32, u16, u8 *); +int med_print_tlv(u32, u16, char *); #define ARG_MED_DEVTYPE "devtype" #define VAL_MED_NOT "none" diff --git a/include/lldp_mod.h b/include/lldp_mod.h index 30fd710..154fc99 100644 --- a/include/lldp_mod.h +++ b/include/lldp_mod.h @@ -68,7 +68,7 @@ struct lldp_mod_ops { struct sockaddr_un *from, socklen_t fromlen, char *ibuf, int ilen, char *rbuf); - int (* print_tlv)(u32, u16, u8 *); + int (* print_tlv)(u32, u16, char *); u32 (* lookup_tlv_name)(char *); int (* print_help)(); int (* timer)(); diff --git a/include/lldp_rtnl.h b/include/lldp_rtnl.h index fc4c53d..8005b8b 100644 --- a/include/lldp_rtnl.h +++ b/include/lldp_rtnl.h @@ -25,14 +25,10 @@ *******************************************************************************/ -#ifndef _LLDP_RTNL_H #define _LLDP_RTNL_H - -#include "dcb_protocol.h" +#include typedef int rtnl_handler(struct nlmsghdr *nh, void *arg); int set_operstate(char *ifname, __u8 operstate); int set_linkmode(char *ifname, __u8 linkmode); - -#endif /* _LLDP_RTNL_H */ diff --git a/include/lldpad_shm.h b/include/lldpad_shm.h index 1bf1ae6..b888da9 100644 --- a/include/lldpad_shm.h +++ b/include/lldpad_shm.h @@ -32,7 +32,7 @@ #include #include "lldpad.h" -#define LLDPAD_SHM_KEY (('l'<<24) | ('l'<<16) | ('d'<<8) | ('p') + 'a' + 'd') +#define LLDPAD_SHM_KEY ((('l'<<24) | ('l'<<16) | ('d'<<8) | ('p')) + 'a' + 'd') #define LLDPAD_SHM_SIZE 4096 /* PID value used to indicate pid field is uninitialized */ diff --git a/include/messages.h b/include/messages.h index 3d691de..c277793 100644 --- a/include/messages.h +++ b/include/messages.h @@ -27,6 +27,7 @@ #ifndef _MESSAGES_H_ #define _MESSAGES_H_ +#include #define MSG_INFO_DEBUG_STRING 1 #define MSG_INFO_PG_ENABLED 2 @@ -74,4 +75,19 @@ #define MSG_INFO_LLINK_OPER 39 #define MSG_ERR_LLINK_NONOPER 40 +/* the following msgid match up to syslog LOG_xxx */ +#define MSG_SYSLOG_START (MSG_ERR_LLINK_NONOPER + LOG_EMERG + 1) +#define MSG_SYSLOG_END (MSG_SYSLOG_START + LOG_DEBUG) +#define MSG_SYSLOG(t) (LOG_##t + MSG_SYSLOG_START) +#define MSG2SYSLOG(i) ((i) - MSG_SYSLOG_START) +#define MSG_IS_SYSLOG(i) \ + (((i) >= MSG_SYSLOG_START) && ((i) <= MSG_SYSLOG_END)) + +void log_message(u32 dwMsgId, const char *pFormat, ...); + +#define LLDPAD_ERR(...) log_message(MSG_SYSLOG(ERR), __VA_ARGS__) +#define LLDPAD_WARN(...) log_message(MSG_SYSLOG(WARNING), __VA_ARGS__) +#define LLDPAD_INFO(...) log_message(MSG_SYSLOG(INFO), __VA_ARGS__) +#define LLDPAD_DBG(...) log_message(MSG_SYSLOG(DEBUG), __VA_ARGS__) + #endif diff --git a/include/tlv_dcbx.h b/include/tlv_dcbx.h index fcd3f93..98459d3 100644 --- a/include/tlv_dcbx.h +++ b/include/tlv_dcbx.h @@ -233,24 +233,24 @@ void process_dcbx_tlv(struct port *,struct unpacked_tlv *); struct unpacked_tlv *bld_dcbx1_tlv(struct dcbx_tlvs *dcbx); struct unpacked_tlv *bld_dcbx2_tlv(struct dcbx_tlvs *dcbx); struct unpacked_tlv *bld_dcbx_ctrl_tlv(struct dcbx_tlvs *dcbx); -struct unpacked_tlv *bld_dcbx1_pg_tlv(struct dcbx_tlvs *, boolean_t *success); -struct unpacked_tlv *bld_dcbx2_pg_tlv(struct dcbx_tlvs *, boolean_t *success); -struct unpacked_tlv *bld_dcbx1_pfc_tlv(struct dcbx_tlvs *, boolean_t *success); -struct unpacked_tlv *bld_dcbx2_pfc_tlv(struct dcbx_tlvs *, boolean_t *success); +struct unpacked_tlv *bld_dcbx1_pg_tlv(struct dcbx_tlvs *, bool *success); +struct unpacked_tlv *bld_dcbx2_pg_tlv(struct dcbx_tlvs *, bool *success); +struct unpacked_tlv *bld_dcbx1_pfc_tlv(struct dcbx_tlvs *, bool *success); +struct unpacked_tlv *bld_dcbx2_pfc_tlv(struct dcbx_tlvs *, bool *success); struct unpacked_tlv *bld_dcbx1_app_tlv(struct dcbx_tlvs *dcbx, u32 sub_type, - boolean_t *success); + bool *success); struct unpacked_tlv *bld_dcbx2_app_tlv(struct dcbx_tlvs *, u32 sub_type, - boolean_t *success); + bool *success); struct unpacked_tlv *bld_dcbx_llink_tlv(struct dcbx_tlvs *, u32 sub_type, - boolean_t *success); - -boolean_t unpack_dcbx1_tlvs(struct port *, struct unpacked_tlv *); -boolean_t unpack_dcbx2_tlvs(struct port *, struct unpacked_tlv *); -boolean_t process_dcbx_ctrl_tlv(struct port *); -boolean_t process_dcbx_pg_tlv(struct port *); -boolean_t process_dcbx_pfc_tlv(struct port *); -boolean_t process_dcbx_app_tlv(struct port *); -boolean_t process_dcbx_llink_tlv(struct port *); + bool *success); + +bool unpack_dcbx1_tlvs(struct port *, struct unpacked_tlv *); +bool unpack_dcbx2_tlvs(struct port *, struct unpacked_tlv *); +bool process_dcbx_ctrl_tlv(struct port *); +bool process_dcbx_pg_tlv(struct port *); +bool process_dcbx_pfc_tlv(struct port *); +bool process_dcbx_app_tlv(struct port *); +bool process_dcbx_llink_tlv(struct port *); #ifdef __cplusplus } diff --git a/lldp/agent.c b/lldp/agent.c index 94d2682..7a27e93 100644 --- a/lldp/agent.c +++ b/lldp/agent.c @@ -30,6 +30,7 @@ #include "eloop.h" #include "states.h" #include "lldp_tlv.h" +#include "messages.h" #include "lldp/l2_packet.h" #include "lldp_mod.h" @@ -39,8 +40,8 @@ static void timer(void *eloop_data, void *user_ctx) struct lldp_module *n; while (port != NULL) { - run_tx_sm(port, TRUE); - run_rx_sm(port, TRUE); + run_tx_sm(port, true); + run_rx_sm(port, true); LIST_FOREACH(n, &lldp_head, lldp) { if (n->ops && n->ops->timer) n->ops->timer(port); diff --git a/lldp/l2_packet_linux.c b/lldp/l2_packet_linux.c index d5c58d7..b2326b6 100644 --- a/lldp/l2_packet_linux.c +++ b/lldp/l2_packet_linux.c @@ -34,6 +34,7 @@ #include "common.h" #include "eloop.h" #include "ports.h" +#include "messages.h" #include "l2_packet.h" #include "lldp_util.h" #include "dcb_types.h" @@ -228,7 +229,7 @@ struct l2_packet_data * l2_packet_init( return NULL; } - printf("%s MAC address is " MACSTR "\n", + LLDPAD_INFO("%s MAC address is " MACSTR "\n", ifname, MAC2STR(l2->perm_mac_addr)); eloop_register_read_sock(l2->fd, l2_packet_receive, l2, NULL); diff --git a/lldp/ports.c b/lldp/ports.c index 75eab99..ad1dbf7 100644 --- a/lldp/ports.c +++ b/lldp/ports.c @@ -125,8 +125,8 @@ void set_lldp_port_admin(const char *ifname, int admin) if (port->adminStatus != admin) { port->adminStatus = admin; somethingChangedLocal(ifname); - run_tx_sm(port, FALSE); - run_rx_sm(port, FALSE); + run_tx_sm(port, false); + run_rx_sm(port, false); } if (!all) @@ -157,10 +157,10 @@ void set_lldp_port_enable_state(const char *ifname, int enable) /* port->adminStatus = enabledRxTx; */ } else { /* port->adminStatus = disabled; */ - port->rx.rxInfoAge = FALSE; + port->rx.rxInfoAge = false; } - run_tx_sm(port, FALSE); - run_rx_sm(port, FALSE); + run_tx_sm(port, false); + run_rx_sm(port, false); } void set_port_oper_delay(const char *ifname) @@ -242,14 +242,14 @@ int reinit_port(const char *ifname) /* Reset relevant port variables */ port->tx.state = TX_LLDP_INITIALIZE; port->rx.state = LLDP_WAIT_PORT_OPERATIONAL; - port->hw_resetting = FALSE; - port->portEnabled = FALSE; + port->hw_resetting = false; + port->portEnabled = false; port->tx.txTTL = 0; port->msap.length1 = 0; port->msap.msap1 = NULL; port->msap.length2 = 0; port->msap.msap2 = NULL; - port->lldpdu = FALSE; + port->lldpdu = false; port->timers.dormantDelay = DORMANT_DELAY; /* init & enable RX path */ @@ -292,20 +292,19 @@ int add_port(const char *ifname) /* Initialize relevant port variables */ newport->tx.state = TX_LLDP_INITIALIZE; newport->rx.state = LLDP_WAIT_PORT_OPERATIONAL; - newport->hw_resetting = FALSE; - newport->portEnabled = FALSE; + newport->hw_resetting = false; + newport->portEnabled = false; if (init_cfg()) { if (get_config_setting(newport->ifname, ARG_ADMINSTATUS, (void *)&newport->adminStatus, CONFIG_TYPE_INT)) newport->adminStatus = disabled; - destroy_cfg(); } newport->tx.txTTL = 0; newport->msap.length1 = 0; newport->msap.msap1 = NULL; newport->msap.length2 = 0; newport->msap.msap2 = NULL; - newport->lldpdu = FALSE; + newport->lldpdu = false; newport->timers.dormantDelay = DORMANT_DELAY; /* init & enable RX path */ @@ -365,7 +364,7 @@ int remove_port(const char *ifname) /* Re-initialize relevant port variables */ port->tx.state = TX_LLDP_INITIALIZE; port->rx.state = LLDP_WAIT_PORT_OPERATIONAL; - port->portEnabled = FALSE; + port->portEnabled = false; port->adminStatus = disabled; port->tx.txTTL = 0; diff --git a/lldp/ports.h b/lldp/ports.h index 453b9cc..0138efe 100644 --- a/lldp/ports.h +++ b/lldp/ports.h @@ -170,7 +170,6 @@ int set_port_hw_resetting(const char *ifname, int resetting); int get_port_hw_resetting(const char *ifname); void set_lldp_port_enable_state(const char *ifname, int enable); void set_lldp_port_admin(const char *ifname, int enable); -void set_port_oper_delay(const char *ifname); int get_lldp_port_statistics(char *ifname, struct portstats *stats); diff --git a/lldp/rx.c b/lldp/rx.c index b950839..92acb8c 100644 --- a/lldp/rx.c +++ b/lldp/rx.c @@ -40,10 +40,10 @@ void rxInitializeLLDP(struct port *port) { - port->rx.rcvFrame = FALSE; - port->rx.badFrame = FALSE; - port->rx.tooManyNghbrs = FALSE; - port->rx.rxInfoAge = FALSE; + port->rx.rcvFrame = false; + port->rx.badFrame = false; + port->rx.tooManyNghbrs = false; + port->rx.rxInfoAge = false; if (port->rx.framein) { free(port->rx.framein); port->rx.framein = NULL; @@ -119,7 +119,7 @@ void rxReceiveFrame(void *ctx, unsigned int ifindex, const u8 *buf, size_t len) port->stats.statsFramesInTotal++; port->rx.rcvFrame = 1; } - run_rx_sm(port, FALSE); + run_rx_sm(port, false); } void rxProcessFrame(struct port * port) @@ -130,10 +130,10 @@ void rxProcessFrame(struct port * port) u16 tlv_offset = 0; u16 *tlv_head_ptr = NULL; u8 frame_error = 0; - boolean_t msap_compare_1 = FALSE; - boolean_t msap_compare_2 = FALSE; - boolean_t good_neighbor = FALSE; - boolean_t tlv_stored = FALSE; + bool msap_compare_1 = false; + bool msap_compare_2 = false; + bool good_neighbor = false; + bool tlv_stored = false; int err; struct lldp_module *np; @@ -239,7 +239,7 @@ void rxProcessFrame(struct port * port) } else { port->lldpdu |= RCVD_LLDP_TLV_TYPE1; port->rx.manifest->chassis = tlv; - tlv_stored = TRUE; + tlv_stored = true; } if (port->msap.msap1 == NULL) { @@ -256,7 +256,7 @@ void rxProcessFrame(struct port * port) if (tlv->length == port->msap.length1) { if ((memcmp(tlv->info,port->msap.msap1, tlv->length) == 0)) - msap_compare_1 = TRUE; + msap_compare_1 = true; } } } @@ -270,7 +270,7 @@ void rxProcessFrame(struct port * port) } else { port->lldpdu |= RCVD_LLDP_TLV_TYPE2; port->rx.manifest->portid = tlv; - tlv_stored = TRUE; + tlv_stored = true; } if (port->msap.msap2 == NULL) { @@ -286,16 +286,16 @@ void rxProcessFrame(struct port * port) if (tlv->length == port->msap.length2) { if ((memcmp(tlv->info,port->msap.msap2, tlv->length) == 0)) - msap_compare_2 = TRUE; + msap_compare_2 = true; } - if ((msap_compare_1 == TRUE) && - (msap_compare_2 == TRUE)) { - msap_compare_1 = FALSE; - msap_compare_2 = FALSE; - good_neighbor = TRUE; + if ((msap_compare_1 == true) && + (msap_compare_2 == true)) { + msap_compare_1 = false; + msap_compare_2 = false; + good_neighbor = true; } else { /* New neighbor */ - port->rx.tooManyNghbrs = TRUE; + port->rx.tooManyNghbrs = true; printf("** TOO_MANY_NGHBRS\n"); } } @@ -310,46 +310,46 @@ void rxProcessFrame(struct port * port) } else { port->lldpdu |= RCVD_LLDP_TLV_TYPE3; port->rx.manifest->ttl = tlv; - tlv_stored = TRUE; + tlv_stored = true; } - if ((port->rx.tooManyNghbrs == TRUE) && - (good_neighbor == FALSE)) { + if ((port->rx.tooManyNghbrs == true) && + (good_neighbor == false)) { printf("** set tooManyNghbrsTimer\n"); port->timers.tooManyNghbrsTimer = max(ntohs(*(u16 *)tlv->info), port->timers.tooManyNghbrsTimer); - msap_compare_1 = FALSE; - msap_compare_2 = FALSE; + msap_compare_1 = false; + msap_compare_2 = false; } else { port->timers.rxTTL = ntohs(*(u16 *)tlv->info); port->timers.lastrxTTL = port->timers.rxTTL; - good_neighbor = FALSE; + good_neighbor = false; } } if (tlv->type == TYPE_4) { /* port description */ port->lldpdu |= RCVD_LLDP_TLV_TYPE4; port->rx.manifest->portdesc = tlv; - tlv_stored = TRUE; + tlv_stored = true; } if (tlv->type == TYPE_5) { /* system name */ port->lldpdu |= RCVD_LLDP_TLV_TYPE5; port->rx.manifest->sysname = tlv; - tlv_stored = TRUE; + tlv_stored = true; } if (tlv->type == TYPE_6) { /* system description */ port->lldpdu |= RCVD_LLDP_TLV_TYPE6; port->rx.manifest->sysdesc = tlv; - tlv_stored = TRUE; + tlv_stored = true; } if (tlv->type == TYPE_7) { /* system capabilities */ port->lldpdu |= RCVD_LLDP_TLV_TYPE7; port->rx.manifest->syscap = tlv; - tlv_stored = TRUE; + tlv_stored = true; } if (tlv->type == TYPE_8) { /* mgmt address */ port->lldpdu |= RCVD_LLDP_TLV_TYPE8; port->rx.manifest->mgmtadd = tlv; - tlv_stored = TRUE; + tlv_stored = true; } /* rx per lldp module */ @@ -360,7 +360,7 @@ void rxProcessFrame(struct port * port) err = np->ops->lldp_mod_rchange(port, tlv); if (!err) - tlv_stored = TRUE; + tlv_stored = true; else if (err == TLV_ERR) { frame_error++; free_unpkd_tlv(tlv); @@ -375,7 +375,7 @@ void rxProcessFrame(struct port * port) port->stats.statsTLVsUnrecognizedTotal++; } tlv = NULL; - tlv_stored = FALSE; + tlv_stored = false; } while(tlv_type != 0); out: @@ -383,7 +383,7 @@ out: /* discard the frame because of errors. */ port->stats.statsFramesDiscardedTotal++; port->stats.statsFramesInErrorsTotal++; - port->rx.badFrame = TRUE; + port->rx.badFrame = true; /* return; */ } /* Maybe want to zero out the frame buffer on exit? @@ -432,7 +432,7 @@ u8 mibDeleteObjects(struct port *port) return 0; } -void run_rx_sm(struct port *port, int update_timers) +void run_rx_sm(struct port *port, bool update_timers) { set_rx_state(port); do { @@ -462,74 +462,74 @@ void run_rx_sm(struct port *port, int update_timers) printf("ERROR: The RX State Machine is broken!\n"); log_message(MSG_ERR_TX_SM_INVALID, "%s", port->ifname); } - } while (set_rx_state(port) == TRUE); + } while (set_rx_state(port) == true); - if (update_timers == TRUE) + if (update_timers) update_rx_timers(port); } -boolean_t set_rx_state(struct port *port) +bool set_rx_state(struct port *port) { - if ((port->rx.rxInfoAge == FALSE) && (port->portEnabled == FALSE)) { + if ((port->rx.rxInfoAge == false) && (port->portEnabled == false)) { rx_change_state(port, LLDP_WAIT_PORT_OPERATIONAL); } switch(port->rx.state) { case LLDP_WAIT_PORT_OPERATIONAL: - if (port->rx.rxInfoAge == TRUE) { + if (port->rx.rxInfoAge == true) { rx_change_state(port, DELETE_AGED_INFO); - return TRUE; + return true; } - else if (port->portEnabled == TRUE) { + else if (port->portEnabled == true) { rx_change_state(port, RX_LLDP_INITIALIZE); - return TRUE; + return true; } - return FALSE; + return false; case DELETE_AGED_INFO: rx_change_state(port, LLDP_WAIT_PORT_OPERATIONAL); - return TRUE; + return true; case RX_LLDP_INITIALIZE: if ((port->adminStatus == enabledRxTx) || (port->adminStatus == enabledRxOnly)) { rx_change_state(port, RX_WAIT_FOR_FRAME); - return TRUE; + return true; } - return FALSE; + return false; case RX_WAIT_FOR_FRAME: if ((port->adminStatus == disabled) || (port->adminStatus == enabledTxOnly)) { rx_change_state(port, RX_LLDP_INITIALIZE); - return TRUE; + return true; } - if (port->rx.rxInfoAge == TRUE) { + if (port->rx.rxInfoAge == true) { rx_change_state(port, DELETE_INFO); - return TRUE; - } else if (port->rx.rcvFrame == TRUE) { + return true; + } else if (port->rx.rcvFrame == true) { rx_change_state(port, RX_FRAME); - return TRUE; + return true; } - return FALSE; + return false; case DELETE_INFO: rx_change_state(port, RX_WAIT_FOR_FRAME); - return TRUE; + return true; case RX_FRAME: if (port->timers.rxTTL == 0) { rx_change_state(port, DELETE_INFO); - return TRUE; + return true; } else if ((port->timers.rxTTL != 0) && - (port->rxChanges == TRUE)) { + (port->rxChanges == true)) { rx_change_state(port, UPDATE_INFO); - return TRUE; + return true; } rx_change_state(port, RX_WAIT_FOR_FRAME); - return TRUE; + return true; case UPDATE_INFO: rx_change_state(port, RX_WAIT_FOR_FRAME); - return TRUE; + return true; default: printf("ERROR: The RX State Machine is broken!\n"); log_message(MSG_ERR_RX_SM_INVALID, "%s", port->ifname); - return FALSE; + return false; } } @@ -541,32 +541,32 @@ void process_wait_port_operational(struct port *port) void process_delete_aged_info(struct port *port) { - port->rx.remoteChange = FALSE; + port->rx.remoteChange = false; mibDeleteObjects(port); - port->rx.rxInfoAge = FALSE; - port->rx.remoteChange = TRUE; + port->rx.rxInfoAge = false; + port->rx.remoteChange = true; return; } void process_rx_lldp_initialize(struct port *port) { rxInitializeLLDP(port); - port->rx.rcvFrame = FALSE; + port->rx.rcvFrame = false; return; } void process_wait_for_frame(struct port *port) { - port->rx.badFrame = FALSE; - port->rx.rxInfoAge = FALSE; - port->rx.remoteChange = FALSE; + port->rx.badFrame = false; + port->rx.rxInfoAge = false; + port->rx.remoteChange = false; return; } void process_rx_frame(struct port *port) { - port->rxChanges = FALSE; - port->rx.rcvFrame = FALSE; + port->rxChanges = false; + port->rx.rcvFrame = false; rxProcessFrame(port); return; } @@ -574,13 +574,13 @@ void process_rx_frame(struct port *port) void process_delete_info(struct port *port) { mibDeleteObjects(port); - port->rx.remoteChange = TRUE; + port->rx.remoteChange = true; return; } void process_update_info(struct port *port) { - port->rx.remoteChange = TRUE; + port->rx.remoteChange = true; return; } @@ -590,11 +590,11 @@ void update_rx_timers(struct port *port) if (port->timers.rxTTL) { port->timers.rxTTL--; if (port->timers.rxTTL == 0) { - port->rx.rxInfoAge = TRUE; + port->rx.rxInfoAge = true; if (port->timers.tooManyNghbrsTimer != 0) { printf("** clear tooManyNghbrsTimer\n"); port->timers.tooManyNghbrsTimer = 0; - port->rx.tooManyNghbrs = FALSE; + port->rx.tooManyNghbrs = false; } } } @@ -602,7 +602,7 @@ void update_rx_timers(struct port *port) port->timers.tooManyNghbrsTimer--; if (port->timers.tooManyNghbrsTimer == 0) { printf("** tooManyNghbrsTimer timeout\n"); - port->rx.tooManyNghbrs = FALSE; + port->rx.tooManyNghbrs = false; } } } diff --git a/lldp/states.h b/lldp/states.h index 125f497..0081f57 100644 --- a/lldp/states.h +++ b/lldp/states.h @@ -57,14 +57,14 @@ void txInitializeLLDP(struct port *port); * LLDP MIB management function, the transmit state machine does not include a * separate procedure for this purpose (see 10.2.1.1). */ -boolean_t mibConstrInfoLLDPDU(struct port *port); +bool mibConstrInfoLLDPDU(struct port *port); /** * The mibConstrShutdownLLDPDU () procedure constructs a shutdown LLDPDU as * defined in 10.2.1.2 and according to the LLDPDU and the associated TLV * formats specified in 9.2 and 9.5. */ -boolean_t mibConstrShutdownLLDPDU(struct port *port); +bool mibConstrShutdownLLDPDU(struct port *port); /** * The txFrame () procedure prepends the source and destinations addresses @@ -73,13 +73,13 @@ boolean_t mibConstrShutdownLLDPDU(struct port *port); */ u8 txFrame(struct port *port); -void run_tx_sm(struct port *, int); +void run_tx_sm(struct port *, bool); void process_tx_initialize_sm(struct port *); void process_tx_idle(struct port *); void process_tx_shutdown_frame(struct port *); void process_tx_info_frame(struct port *); void update_tx_timers(struct port *); -boolean_t set_tx_state(struct port *); +bool set_tx_state(struct port *); void tx_change_state(struct port *, u8 ); /******************************************************************************/ @@ -145,17 +145,17 @@ u8 mibDeleteObjects(struct port *port); */ void mibUpdateObjects(struct port *); -void run_rx_sm(struct port *, int); -boolean_t set_rx_state(struct port *); -void rx_change_state(struct port *, u8 ); -void process_wait_port_operational(struct port *); -void process_delete_aged_info(struct port *); -void process_rx_lldp_initialize(struct port *); -void process_wait_for_frame(struct port *); -void process_rx_frame(struct port *); -void process_delete_info(struct port *); -void process_update_info(struct port *); -void update_rx_timers(struct port *); -void load_peer_tlvs(struct port *,struct unpacked_tlv *, int); -void clear_manifest(struct port *); +void run_rx_sm(struct port *, bool); +bool set_rx_state(struct port *); +void rx_change_state(struct port *, u8 ); +void process_wait_port_operational(struct port *); +void process_delete_aged_info(struct port *); +void process_rx_lldp_initialize(struct port *); +void process_wait_for_frame(struct port *); +void process_rx_frame(struct port *); +void process_delete_info(struct port *); +void process_update_info(struct port *); +void update_rx_timers(struct port *); +void load_peer_tlvs(struct port *,struct unpacked_tlv *, int); +void clear_manifest(struct port *); #endif /* STATES_H */ diff --git a/lldp/tx.c b/lldp/tx.c index 09f0f2e..6434e74 100644 --- a/lldp/tx.c +++ b/lldp/tx.c @@ -35,7 +35,7 @@ #include "lldp_mod.h" #include "lldp_mand.h" -boolean_t mibConstrInfoLLDPDU(struct port *port) +bool mibConstrInfoLLDPDU(struct port *port) { struct l2_ethhdr eth; u8 own_addr[ETH_ALEN]; @@ -56,7 +56,7 @@ boolean_t mibConstrInfoLLDPDU(struct port *port) port->tx.frameout = (u8 *)malloc(ETH_FRAME_LEN); if (port->tx.frameout == NULL) { printf("InfoLLDPDU: Failed to malloc frame buffer \n"); - return FALSE; + return false; } memset(port->tx.frameout,0,ETH_FRAME_LEN); memcpy(port->tx.frameout, (void *)ð, sizeof(struct l2_ethhdr)); @@ -93,7 +93,7 @@ boolean_t mibConstrInfoLLDPDU(struct port *port) else port->tx.sizeout = fb_offset; - return TRUE; + return true; error: ptlv = free_pkd_tlv(ptlv); @@ -101,7 +101,7 @@ error: free(port->tx.frameout); port->tx.frameout = NULL; printf("InfoLLDPDU: packed TLV too large for tx frame\n"); - return FALSE; + return false; } void txInitializeLLDP(struct port *port) @@ -121,7 +121,7 @@ void txInitializeLLDP(struct port *port) return; } -boolean_t mibConstrShutdownLLDPDU(struct port *port) +bool mibConstrShutdownLLDPDU(struct port *port) { struct l2_ethhdr eth; u8 own_addr[ETH_ALEN]; @@ -142,7 +142,7 @@ boolean_t mibConstrShutdownLLDPDU(struct port *port) port->tx.frameout = (u8 *)malloc(ETH_FRAME_LEN); if (port->tx.frameout == NULL) { printf("ShutdownLLDPDU: Failed to malloc frame buffer \n"); - return FALSE; + return false; } memset(port->tx.frameout,0,ETH_FRAME_LEN); memcpy(port->tx.frameout, (void *)ð, sizeof(struct l2_ethhdr)); @@ -179,7 +179,7 @@ boolean_t mibConstrShutdownLLDPDU(struct port *port) } else { port->tx.sizeout = fb_offset; } - return TRUE; + return true; error: ptlv = free_pkd_tlv(ptlv); @@ -187,7 +187,7 @@ error: free(port->tx.frameout); port->tx.frameout = NULL; printf("InfoLLDPDU: packed TLV too large for tx frame\n"); - return FALSE; + return false; } u8 txFrame(struct port *port) @@ -208,9 +208,9 @@ u8 txFrame(struct port *port) } -void run_tx_sm(struct port *port, int update_timers) +void run_tx_sm(struct port *port, bool update_timers) { - if (update_timers == TRUE) + if (update_timers) update_tx_timers(port); set_tx_state(port); @@ -232,14 +232,14 @@ void run_tx_sm(struct port *port, int update_timers) printf("ERROR The TX State Machine is broken!\n"); log_message(MSG_ERR_TX_SM_INVALID, "%s", port->ifname); } - } while (set_tx_state(port) == TRUE); + } while (set_tx_state(port) == true); return; } -boolean_t set_tx_state(struct port *port) +bool set_tx_state(struct port *port) { - if ((port->portEnabled == FALSE) && (port->prevPortEnabled == TRUE)) { + if ((port->portEnabled == false) && (port->prevPortEnabled == true)) { printf("set_tx_state: port was disabled\n"); tx_change_state(port, TX_LLDP_INITIALIZE); } @@ -250,35 +250,35 @@ boolean_t set_tx_state(struct port *port) if (port->portEnabled && ((port->adminStatus == enabledRxTx) || (port->adminStatus == enabledTxOnly))) { tx_change_state(port, TX_IDLE); - return TRUE; + return true; } - return FALSE; + return false; case TX_IDLE: if ((port->adminStatus == disabled) || (port->adminStatus == enabledRxOnly)) { tx_change_state(port, TX_SHUTDOWN_FRAME); - return TRUE; + return true; } if ((port->timers.txDelayWhile == 0) && ((port->timers.txTTR == 0) || (port->tx.localChange))) { tx_change_state(port, TX_INFO_FRAME); - return TRUE; + return true; } - return FALSE; + return false; case TX_SHUTDOWN_FRAME: if (port->timers.txShutdownWhile == 0) { tx_change_state(port, TX_LLDP_INITIALIZE); - return TRUE; + return true; } - return FALSE; + return false; case TX_INFO_FRAME: tx_change_state(port, TX_IDLE); - return TRUE; + return true; default: printf("ERROR: The TX State Machine is broken!\n"); log_message(MSG_ERR_TX_SM_INVALID, "%s", port->ifname); - return FALSE; + return false; } } @@ -304,7 +304,7 @@ void process_tx_info_frame(struct port *port) mibConstrInfoLLDPDU(port); txFrame(port); - port->tx.localChange = FALSE; + port->tx.localChange = false; return; } diff --git a/lldp_8023.c b/lldp_8023.c index 70c356c..6d666bb 100644 --- a/lldp_8023.c +++ b/lldp_8023.c @@ -323,30 +323,27 @@ static int ieee8023_bld_tlv(struct ieee8023_data *bd) } if (ieee8023_bld_maccfg_tlv(bd)) { - fprintf(stderr, "### %s:%s:ieee8023_bld_macfg_tlv() failed\n", + LLDPAD_DBG("%s:%s:ieee8023_bld_macfg_tlv() failed\n", __func__, bd->ifname); - goto out_err_destroy; + goto out_err; } if (ieee8023_bld_powvmdi_tlv(bd)) { - fprintf(stderr, "### %s:%s:ieee8023_bld_powvmdi_tlv() failed\n", + LLDPAD_DBG("%s:%s:ieee8023_bld_powvmdi_tlv() failed\n", __func__, bd->ifname); - goto out_err_destroy; + goto out_err; } if (ieee8023_bld_linkagg_tlv(bd)) { - fprintf(stderr, "### %s:%s:ieee8023_bld_linkagg_tlv() failed\n", + LLDPAD_DBG("%s:%s:ieee8023_bld_linkagg_tlv() failed\n", __func__, bd->ifname); - goto out_err_destroy; + goto out_err; } if (ieee8023_bld_maxfs_tlv(bd)) { - fprintf(stderr, "### %s:%s:ieee8023_bld_maxfs_tlv() failed\n", + LLDPAD_DBG("%s:%s:ieee8023_bld_maxfs_tlv() failed\n", __func__, bd->ifname); - goto out_err_destroy; + goto out_err; } rc = 0; -out_err_destroy: - destroy_cfg(); - out_err: return rc; } @@ -376,7 +373,7 @@ struct packed_tlv *ieee8023_gettlv(struct port *port) ieee8023_free_tlv(bd); if (ieee8023_bld_tlv(bd)) { - fprintf(stderr, "### %s:%s ieee8023_bld_tlv failed\n", + LLDPAD_DBG("%s:%s ieee8023_bld_tlv failed\n", __func__, port->ifname); goto out_err; } @@ -405,7 +402,7 @@ struct packed_tlv *ieee8023_gettlv(struct port *port) out_free: ptlv = free_pkd_tlv(ptlv); out_err: - fprintf(stderr,"### %s:%s: failed\n", __func__, port->ifname); + LLDPAD_DBG("%s:%s: failed\n", __func__, port->ifname); return NULL; } @@ -422,10 +419,10 @@ void ieee8023_ifdown(char *ifname) LIST_REMOVE(bd, entry); ieee8023_free_tlv(bd); free(bd); - fprintf(stderr, "### %s:port %s removed\n", __func__, ifname); + LLDPAD_INFO("%s:port %s removed\n", __func__, ifname); return; out_err: - fprintf(stderr, "### %s:port %s adding failed\n", __func__, ifname); + LLDPAD_INFO("%s:port %s adding failed\n", __func__, ifname); return; } @@ -437,31 +434,31 @@ void ieee8023_ifup(char *ifname) bd = ieee8023_data(ifname); if (bd) { - fprintf(stderr, "### %s:%s exists\n", __func__, ifname); + LLDPAD_INFO("%s:%s exists\n", __func__, ifname); goto out_err; } /* not found, alloc/init per-port tlv data */ bd = (struct ieee8023_data *) malloc(sizeof(*bd)); if (!bd) { - fprintf(stderr, "### %s:%s malloc %ld failed\n", + LLDPAD_INFO("%s:%s malloc %ld failed\n", __func__, ifname, sizeof(*bd)); goto out_err; } memset(bd, 0, sizeof(struct ieee8023_data)); strncpy(bd->ifname, ifname, IFNAMSIZ); if (ieee8023_bld_tlv(bd)) { - fprintf(stderr, "### %s:%s mand_bld_tlv failed\n", __func__, ifname); + LLDPAD_INFO("%s:%s mand_bld_tlv failed\n", __func__, ifname); free(bd); goto out_err; } ud = find_module_user_data_by_if(ifname, &lldp_head, LLDP_MOD_8023); LIST_INSERT_HEAD(&ud->head, bd, entry); - fprintf(stderr, "### %s:port %s added\n", __func__, ifname); + LLDPAD_INFO("%s:port %s added\n", __func__, ifname); return; out_err: - fprintf(stderr, "### %s:port %s adding failed\n", __func__, ifname); + LLDPAD_INFO("%s:port %s adding failed\n", __func__, ifname); return; } @@ -472,27 +469,23 @@ struct lldp_module *ieee8023_register(void) mod = malloc(sizeof(*mod)); if (!mod) { - fprintf(stderr, "failed to malloc module data\n"); - log_message(MSG_ERR_SERVICE_START_FAILURE, - "%s", "failed to malloc module data"); + LLDPAD_ERR("failed to malloc LLDP 802.3 module data"); goto out_err; } ud = malloc(sizeof(struct ieee8023_user_data)); if (!ud) { free(mod); - fprintf(stderr, "failed to malloc module user data\n"); - log_message(MSG_ERR_SERVICE_START_FAILURE, - "%s", "failed to malloc module user data"); + LLDPAD_ERR("failed to malloc LLDP 802.3 module user data"); goto out_err; } LIST_INIT(&ud->head); mod->id = LLDP_MOD_8023; mod->ops = &ieee8023_ops; mod->data = ud; - fprintf(stderr, "### %s:done\n", __func__); + LLDPAD_INFO("%s:done\n", __func__); return mod; out_err: - fprintf(stderr, "### %s:failed\n", __func__); + LLDPAD_INFO("%s:failed\n", __func__); return NULL; } @@ -504,5 +497,5 @@ void ieee8023_unregister(struct lldp_module *mod) free(mod->data); } free(mod); - fprintf(stderr, "### %s:done\n", __func__); + LLDPAD_INFO("%s:done\n", __func__); } diff --git a/lldp_8023_clif.c b/lldp_8023_clif.c index 4388bd4..0ba3640 100644 --- a/lldp_8023_clif.c +++ b/lldp_8023_clif.c @@ -336,7 +336,7 @@ void print_mtu(u16 len, char *info) /* return 1: if it printed the TLV * 0: if it did not */ -int ieee8023_print_tlv(u32 tlvid, u16 len, u8 *info) +int ieee8023_print_tlv(u32 tlvid, u16 len, char *info) { struct type_name_info *tn = &ieee8023_tlv_names[0]; diff --git a/lldp_8023_cmds.c b/lldp_8023_cmds.c index 2c6af81..effd361 100644 --- a/lldp_8023_cmds.c +++ b/lldp_8023_cmds.c @@ -72,7 +72,7 @@ static int get_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue, if (get_config_setting(cmd->ifname, arg_path, (void *)&value, CONFIG_TYPE_BOOL)) - value = FALSE; + value = false; break; case INVALID_TLVID: return cmd_invalid; @@ -85,7 +85,8 @@ static int get_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue, else s = VAL_NO; - sprintf(obuf, "%02x%s%04x%s", strlen(arg), arg, strlen(s), s); + sprintf(obuf, "%02x%s%04x%s", (unsigned int)strlen(arg), arg, + (unsigned int)strlen(s), s); return cmd_success; } diff --git a/lldp_basman.c b/lldp_basman.c index ecc40c9..b9a8b5d 100644 --- a/lldp_basman.c +++ b/lldp_basman.c @@ -119,7 +119,7 @@ static int basman_bld_portdesc_tlv(struct basman_data *bd) FREE_UNPKD_TLV(bd, portdesc); if (!is_tlv_txenabled(bd->ifname, PORT_DESCRIPTION_TLV)) { - fprintf(stderr, "### %s:%s:Port Description disabled\n", + LLDPAD_DBG("%s:%s:Port Description disabled\n", __func__, bd->ifname); goto out_err; } @@ -129,11 +129,11 @@ static int basman_bld_portdesc_tlv(struct basman_data *bd) desc, sizeof(desc))) { /* use what's in the config */ length = strlen(desc); - fprintf(stderr, "### %s:%s:configed as %s\n", __func__, bd->ifname, desc); + LLDPAD_DBG("%s:%s:configed as %s\n", __func__, bd->ifname, desc); } else { length = snprintf(desc, sizeof(desc), "Interface %3d as %s", if_nametoindex(bd->ifname), bd->ifname); - fprintf(stderr, "### %s:%s:built as %s\n", __func__, bd->ifname, desc); + LLDPAD_DBG("%s:%s:built as %s\n", __func__, bd->ifname, desc); } if (length >= sizeof(desc)) length = sizeof(desc) - 1; @@ -177,7 +177,7 @@ static int basman_bld_sysname_tlv(struct basman_data *bd) FREE_UNPKD_TLV(bd, sysname); if (!is_tlv_txenabled(bd->ifname, SYSTEM_NAME_TLV)) { - fprintf(stderr, "### %s:%s:System Name disabled\n", + LLDPAD_DBG("%s:%s:System Name disabled\n", __func__, bd->ifname); goto out_err; } @@ -187,14 +187,14 @@ static int basman_bld_sysname_tlv(struct basman_data *bd) desc, sizeof(desc))) { /* use what's in the config */ length = strlen(desc); - fprintf(stderr, "### %s:%s:configed as %s\n", + LLDPAD_DBG("%s:%s:configed as %s\n", __func__, bd->ifname, desc); } else { if (uname(&uts)) length = snprintf(desc, sizeof(desc), SYSNAME_DEFAULT); else length = snprintf(desc, sizeof(desc), uts.nodename); - fprintf(stderr, "### %s:%s:built as %s\n", + LLDPAD_DBG("%s:%s:built as %s\n", __func__, bd->ifname, desc); } if (length >= sizeof(desc)) @@ -242,7 +242,7 @@ static int basman_bld_sysdesc_tlv(struct basman_data *bd) FREE_UNPKD_TLV(bd, sysdesc); if (!is_tlv_txenabled(bd->ifname, SYSTEM_DESCRIPTION_TLV)) { - fprintf(stderr, "### %s:%s:System Description disabled\n", + LLDPAD_DBG("%s:%s:System Description disabled\n", __func__, bd->ifname); goto out_err; } @@ -252,7 +252,7 @@ static int basman_bld_sysdesc_tlv(struct basman_data *bd) desc, sizeof(desc))) { /* use what's in the config */ length = strlen(desc); - fprintf(stderr, "### %s:%s:configed as %s\n", + LLDPAD_DBG("%s:%s:configed as %s\n", __func__, bd->ifname, desc); } else { if (uname(&uts)) { @@ -262,7 +262,7 @@ static int basman_bld_sysdesc_tlv(struct basman_data *bd) uts.sysname, uts.nodename, uts.release, uts.version, uts.machine); } - fprintf(stderr, "### %s:%s:built as %s\n", + LLDPAD_DBG("%s:%s:built as %s\n", __func__, bd->ifname, desc); } if (length >= sizeof(desc)) @@ -309,7 +309,7 @@ static int basman_bld_syscaps_tlv(struct basman_data *bd) FREE_UNPKD_TLV(bd, syscaps); if (!is_tlv_txenabled(bd->ifname, SYSTEM_CAPABILITIES_TLV)) { - fprintf(stderr, "### %s:%s:System Capabilities disabled\n", + LLDPAD_DBG("%s:%s:System Capabilities disabled\n", __func__, bd->ifname); goto out_err; } @@ -318,7 +318,7 @@ static int basman_bld_syscaps_tlv(struct basman_data *bd) if (get_config_tlvinfo_bin(bd->ifname, TLVID_NOUI(SYSTEM_CAPABILITIES_TLV), (void *)&syscaps, sizeof(syscaps))) { u16 *caps = (u16 *)&syscaps; - fprintf(stderr, "### %s:%s:Build System Caps from scratch\n", + LLDPAD_DBG("%s:%s:Build System Caps from scratch\n", __func__, bd->ifname); caps[0] = htons(get_caps(bd->ifname)); caps[1] = (is_active(bd->ifname)) ? caps[0] : 0; @@ -369,7 +369,7 @@ static int basman_get_manaddr_sub(struct basman_data *bd, u8 masub) struct unpacked_tlv *tlv = NULL; if (bd->macnt >= MANADDR_MAX) { - fprintf(stderr, "### %s:%s:reached max %d Management Address\n", + LLDPAD_DBG("%s:%s:reached max %d Management Address\n", __func__, bd->ifname, bd->macnt); goto out_err; } @@ -395,7 +395,7 @@ static int basman_get_manaddr_sub(struct basman_data *bd, u8 masub) m->len = sizeof(m->a.mac); break; default: - fprintf(stderr, "### %s:%s:unsupported sub type %d\n", + LLDPAD_DBG("%s:%s:unsupported sub type %d\n", __func__, bd->ifname, masub); goto out_err; } @@ -405,7 +405,7 @@ static int basman_get_manaddr_sub(struct basman_data *bd, u8 masub) if (get_config_tlvfield_str(bd->ifname, TLVID_NOUI(MANAGEMENT_ADDRESS_TLV), field, (void *)maddr, sizeof(maddr))) { - fprintf(stderr, "### %s:%s:failed to get %s from config\n", + LLDPAD_DBG("%s:%s:failed to get %s from config\n", __func__, bd->ifname, field); goto out_bld; } @@ -416,12 +416,12 @@ static int basman_get_manaddr_sub(struct basman_data *bd, u8 masub) out_bld: /* failed to get from config, so build from scratch */ if (get_addr(bd->ifname, domain, &m->a)) { - fprintf(stderr, "### %s:%s:get_addr() for domain %d failed\n", + LLDPAD_DBG("%s:%s:get_addr() for domain %d failed\n", __func__, bd->ifname, domain); goto out_err; } if (addr2str(domain, &m->a, maddr, sizeof(maddr))) { - fprintf(stderr, "### %s:%s:get_addr() for domain %d failed\n", + LLDPAD_DBG("%s:%s:get_addr() for domain %d failed\n", __func__, bd->ifname, domain); goto out_err; } @@ -463,7 +463,7 @@ out_set: bd->manaddr[bd->macnt] = tlv; bd->macnt++; - fprintf(stderr, "### %s:%s:maddr[%d]:tlv->len %d bytes \n", + LLDPAD_DBG("%s:%s:maddr[%d]:tlv->len %d bytes \n", __func__, bd->ifname, bd->macnt, tlv->length); rc = 0; @@ -498,7 +498,7 @@ static int basman_bld_manaddr_tlv(struct basman_data *bd) /* ignore manaddr if it's not enabled for tx */ if (!is_tlv_txenabled(bd->ifname, MANAGEMENT_ADDRESS_TLV)) { - fprintf(stderr, "### %s:%s:Management Address disabled\n", + LLDPAD_DBG("%s:%s:Management Address disabled\n", __func__, bd->ifname); goto out_err; } @@ -543,34 +543,32 @@ static int basman_bld_tlv(struct basman_data *bd) goto out_err; if (basman_bld_portdesc_tlv(bd)) { - fprintf(stderr, "### %s:%s:basman_bld_portdesc_tlv() failed\n", + LLDPAD_DBG("%s:%s:basman_bld_portdesc_tlv() failed\n", __func__, bd->ifname); - goto out_err_destroy; + goto out_err; } if (basman_bld_sysname_tlv(bd)) { - fprintf(stderr, "### %s:%s:basman_bld_sysname_tlv() failed\n", + LLDPAD_DBG("%s:%s:basman_bld_sysname_tlv() failed\n", __func__, bd->ifname); - goto out_err_destroy; + goto out_err; } if (basman_bld_sysdesc_tlv(bd)) { - fprintf(stderr, "### %s:%s:basman_bld_sysdesc_tlv() failed\n", + LLDPAD_DBG("%s:%s:basman_bld_sysdesc_tlv() failed\n", __func__, bd->ifname); - goto out_err_destroy; + goto out_err; } if (basman_bld_syscaps_tlv(bd)) { - fprintf(stderr, "### %s:%s:basman_bld_syscaps_tlv() failed\n", + LLDPAD_DBG("%s:%s:basman_bld_syscaps_tlv() failed\n", __func__, bd->ifname); - goto out_err_destroy; + goto out_err; } if (basman_bld_manaddr_tlv(bd)) { - fprintf(stderr, "### %s:%s:basman_bld_manaddr_tlv() failed\n", + LLDPAD_DBG("%s:%s:basman_bld_manaddr_tlv() failed\n", __func__, bd->ifname); - goto out_err_destroy; + goto out_err; } rc = 0; -out_err_destroy: - destroy_cfg(); out_err: return rc; } @@ -602,7 +600,7 @@ struct packed_tlv *basman_gettlv(struct port *port) /* free and rebuild the TLVs */ basman_free_tlv(bd); if (basman_bld_tlv(bd)) { - fprintf(stderr, "### %s:%s basman_bld_tlv failed\n", + LLDPAD_DBG("%s:%s basman_bld_tlv failed\n", __func__, port->ifname); goto out_err; } @@ -620,8 +618,8 @@ struct packed_tlv *basman_gettlv(struct port *port) ptlv = create_ptlv(); if (!ptlv) { - fprintf(stderr, "### %s:%s malloc(ptlv) failed\n", - __func__, port->ifname); + LLDPAD_DBG("%s:%s malloc(ptlv) failed\n", + __func__, port->ifname); goto out_err; } @@ -641,7 +639,7 @@ struct packed_tlv *basman_gettlv(struct port *port) out_free: ptlv = free_pkd_tlv(ptlv); out_err: - fprintf(stderr,"### %s:%s: failed\n", __func__, port->ifname); + LLDPAD_DBG("%s:%s: failed\n", __func__, port->ifname); return NULL; } @@ -656,10 +654,10 @@ void basman_ifdown(char *ifname) LIST_REMOVE(bd, entry); basman_free_tlv(bd); free(bd); - fprintf(stderr, "### %s:port %s removed\n", __func__, ifname); + LLDPAD_DBG("%s:port %s removed\n", __func__, ifname); return; out_err: - fprintf(stderr, "### %s:port %s adding failed\n", __func__, ifname); + LLDPAD_DBG("%s:port %s adding failed\n", __func__, ifname); return; } @@ -670,31 +668,31 @@ void basman_ifup(char *ifname) bd = basman_data(ifname); if (bd) { - fprintf(stderr, "### %s:%s exists\n", __func__, ifname); + LLDPAD_DBG("%s:%s exists\n", __func__, ifname); goto out_err; } /* not found, alloc/init per-port tlv data */ bd = (struct basman_data *) malloc(sizeof(*bd)); if (!bd) { - fprintf(stderr, "### %s:%s malloc %ld failed\n", + LLDPAD_DBG("%s:%s malloc %ld failed\n", __func__, ifname, sizeof(*bd)); goto out_err; } memset(bd, 0, sizeof(struct basman_data)); strncpy(bd->ifname, ifname, IFNAMSIZ); if (basman_bld_tlv(bd)) { - fprintf(stderr, "### %s:%s mand_bld_tlv failed\n", __func__, ifname); + LLDPAD_DBG("%s:%s mand_bld_tlv failed\n", __func__, ifname); free(bd); goto out_err; } bud = find_module_user_data_by_if(ifname, &lldp_head, LLDP_MOD_BASIC); LIST_INSERT_HEAD(&bud->head, bd, entry); - fprintf(stderr, "### %s:port %s added\n", __func__, ifname); + LLDPAD_DBG("%s:port %s added\n", __func__, ifname); return; out_err: - fprintf(stderr, "### %s:port %s adding failed\n", __func__, ifname); + LLDPAD_DBG("%s:port %s adding failed\n", __func__, ifname); return; } @@ -705,27 +703,23 @@ struct lldp_module *basman_register(void) mod = malloc(sizeof(*mod)); if (!mod) { - fprintf(stderr, "failed to malloc module data\n"); - log_message(MSG_ERR_SERVICE_START_FAILURE, - "%s", "failed to malloc module data"); + LLDPAD_ERR("failed to malloc LLDP Basic Management module data\n"); goto out_err; } bud = malloc(sizeof(struct basman_user_data)); if (!bud) { free(mod); - fprintf(stderr, "failed to malloc module user data\n"); - log_message(MSG_ERR_SERVICE_START_FAILURE, - "%s", "failed to malloc module user data"); + LLDPAD_ERR("failed to malloc LLDP Basic Management module user data\n"); goto out_err; } LIST_INIT(&bud->head); mod->id = LLDP_MOD_BASIC; mod->ops = &basman_ops; mod->data = bud; - fprintf(stderr, "### %s:done\n", __func__); + LLDPAD_DBG("%s:done\n", __func__); return mod; out_err: - fprintf(stderr, "### %s:failed\n", __func__); + LLDPAD_DBG("%s:failed\n", __func__); return NULL; } @@ -736,5 +730,5 @@ void basman_unregister(struct lldp_module *mod) free(mod->data); } free(mod); - fprintf(stderr, "### %s:done\n", __func__); + LLDPAD_DBG("%s:done\n", __func__); } diff --git a/lldp_basman_clif.c b/lldp_basman_clif.c index 7ba6337..d365241 100644 --- a/lldp_basman_clif.c +++ b/lldp_basman_clif.c @@ -274,7 +274,7 @@ void print_mng_addr(u16 len, char *info) /* return 1: if it printed the TLV * 0: if it did not */ -int basman_print_tlv(u32 tlvid, u16 len, u8 *info) +int basman_print_tlv(u32 tlvid, u16 len, char *info) { struct type_name_info *tn = &basman_tlv_names[0]; diff --git a/lldp_basman_cmds.c b/lldp_basman_cmds.c index fa393c4..7098d97 100644 --- a/lldp_basman_cmds.c +++ b/lldp_basman_cmds.c @@ -79,7 +79,7 @@ static int get_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue, if (get_config_setting(cmd->ifname, arg_path, (void *)&value, CONFIG_TYPE_BOOL)) - value = FALSE; + value = false; break; case INVALID_TLVID: return cmd_invalid; @@ -92,7 +92,8 @@ static int get_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue, else s = VAL_NO; - sprintf(obuf, "%02x%s%04x%s", strlen(arg), arg, strlen(s), s); + sprintf(obuf, "%02x%s%04x%s", (unsigned int)strlen(arg), arg, + (unsigned int)strlen(s), s); return cmd_success; } @@ -142,19 +143,9 @@ struct arg_handlers *basman_get_arg_handlers() return &arg_handlers[0]; } -void format_ipv4(unsigned char *ipv4addr, char *obuf, int osize) -{ - struct in_addr addr; - - hexstr2bin(ipv4addr, (u8 *)&addr, sizeof(addr)); - - inet_ntop(AF_INET, (void *)&addr, obuf, osize); -} - int get_arg_ipv4(struct cmd *cmd, char *arg, char *argvalue, char *obuf) { char *p; - char s[32]; char arg_path[256]; if (cmd->cmd != cmd_gettlv || cmd->tlvid != MANAGEMENT_ADDRESS_TLV) @@ -167,13 +158,13 @@ int get_arg_ipv4(struct cmd *cmd, char *arg, char *argvalue, char *obuf) CONFIG_TYPE_STRING)) return cmd_failed; - sprintf(obuf, "%02x%s%04x%s", strlen(arg), arg, strlen(p), p); + sprintf(obuf, "%02x%s%04x%s", (unsigned int)strlen(arg), arg, + (unsigned int)strlen(p), p); return cmd_success; } int get_arg_ipv6(struct cmd *cmd, char *arg, char *argvalue, char *obuf) { - int value; char *p; char arg_path[256]; @@ -187,53 +178,17 @@ int get_arg_ipv6(struct cmd *cmd, char *arg, char *argvalue, char *obuf) CONFIG_TYPE_STRING)) return cmd_failed; - sprintf(obuf, "%02x%s%04x%s", strlen(arg), arg, strlen(p), p); + sprintf(obuf, "%02x%s%04x%s", (unsigned int)strlen(arg), arg, + (unsigned int)strlen(p), p); return cmd_success; } - -/* -static int parse_ipv4(char *nptr, u8 *ipv4addr) -{ - char *p; - char *eptr; - int i = 0; - unsigned int value; - - p = nptr; - - while (1) { - value = strtoul(p, &eptr, 10); - - if (value > 0xff) - return 0; - - if (*eptr != '\0' && *eptr != '.') - return 0; - - ipv4addr[i++] = value; - if (*eptr == '\0') - if (i != 4) - return 0; - else - break; - else - p = eptr + 1; - } - - return 1; -} -*/ - int set_arg_ipv4(struct cmd *cmd, char *arg, char *argvalue, char *obuf) { - int value; struct in_addr ipv4addr; char arg_path[256]; - char arg_string[16]; char *p; - int i; if (cmd->cmd != cmd_settlv || cmd->tlvid != MANAGEMENT_ADDRESS_TLV) return cmd_bad_params; @@ -256,11 +211,9 @@ int set_arg_ipv4(struct cmd *cmd, char *arg, char *argvalue, char *obuf) int set_arg_ipv6(struct cmd *cmd, char *arg, char *argvalue, char *obuf) { - int value; struct in6_addr ipv6addr; char arg_path[256]; char *p; - int i; if (cmd->cmd != cmd_settlv || cmd->tlvid != MANAGEMENT_ADDRESS_TLV) return cmd_bad_params; diff --git a/lldp_dcbx.c b/lldp_dcbx.c index 5f04d3a..443f277 100644 --- a/lldp_dcbx.c +++ b/lldp_dcbx.c @@ -41,6 +41,7 @@ #include "drv_cfg.h" #include "lldp_dcbx_cfg.h" #include "lldp_dcbx_cmds.h" +#include "lldp_rtnl.h" #include extern u8 gdcbx_subtype; @@ -81,7 +82,6 @@ static int dcbx_check_operstate(struct port *port) err = get_pfc(port->ifname, &pfc_data); if (err) goto err_out; - destroy_cfg(); if ((pfc_data.protocol.Enable && pfc_data.protocol.OperMode) || !pfc_data.protocol.Enable) @@ -100,8 +100,8 @@ static int dcbx_check_operstate(struct port *port) } return 0; + err_out: - destroy_cfg(); return -1; } @@ -123,7 +123,7 @@ struct dcbx_tlvs *dcbx_data(const char *ifname) int dcbx_bld_tlv(struct port *newport) { - boolean_t success; + bool success; struct dcbx_tlvs *tlvs; int enabletx; long adminstatus = disabled; @@ -138,7 +138,6 @@ int dcbx_bld_tlv(struct port *newport) enabletx = is_tlv_txenabled(newport->ifname, (OUI_CEE_DCBX << 8) | tlvs->dcbx_st); - destroy_cfg(); if (!enabletx || adminstatus != enabledRxTx) return 0; @@ -345,24 +344,19 @@ struct lldp_module * dcbx_register(void) if (get_dcbx_version(&dcbx_version)) { gdcbx_subtype = dcbx_version; } else { - log_message(MSG_ERR_SERVICE_START_FAILURE, - "%s", "failed to get DCBX version"); + LLDPAD_ERR("failed to get DCBX version"); goto out_err; } mod = malloc(sizeof(struct lldp_module)); if (!mod) { - fprintf(stderr, "failed to malloc module data\n"); - log_message(MSG_ERR_SERVICE_START_FAILURE, - "%s", "failed to malloc module data"); + LLDPAD_ERR("failed to malloc LLDP DCBX module data\n"); goto out_err; } dud = malloc(sizeof(*dud)); if (!dud) { free(mod); - fprintf(stderr, "failed to malloc module user data\n"); - log_message(MSG_ERR_SERVICE_START_FAILURE, - "%s", "failed to malloc module user data"); + LLDPAD_ERR("failed to malloc LLDP DCBX module user data\n"); goto out_err; } @@ -373,10 +367,6 @@ struct lldp_module * dcbx_register(void) /* store pg defaults */ if (!add_pg_defaults()) { - /* - if (!daemonize) - fprintf(stderr, "failed to add default PG data\n"); - */ log_message(MSG_ERR_SERVICE_START_FAILURE, "%s", "failed to add default PG data"); goto out_err; @@ -384,10 +374,6 @@ struct lldp_module * dcbx_register(void) /* store pg defaults */ if (!add_pfc_defaults()) { - /* - if (!daemonize) - fprintf(stderr, "failed to add default PFC data\n"); - */ log_message(MSG_ERR_SERVICE_START_FAILURE, "%s", "failed to add default PFC data"); goto out_err; @@ -396,11 +382,6 @@ struct lldp_module * dcbx_register(void) /* store app defaults */ for (i = 0; i < DCB_MAX_APPTLV; i++) { if (!add_app_defaults(i)) { - /* - if (!daemonize) - fprintf(stderr, - "failed to add default APP data\n"); - */ log_message(MSG_ERR_SERVICE_START_FAILURE, "%s:%d", "failed to add default APP data", i); goto out_err; @@ -410,11 +391,6 @@ struct lldp_module * dcbx_register(void) for (i = 0; i < DCB_MAX_APPTLV; i++) { if (!add_llink_defaults(i)) { - /* - if (!daemonize) - fprintf(stderr, - "failed to add default APP data\n"); - */ log_message(MSG_ERR_SERVICE_START_FAILURE, "%s:%d", "failed to add default APP data", i); goto out_err; @@ -426,10 +402,10 @@ struct lldp_module * dcbx_register(void) goto out_err; } - fprintf(stderr, "### %s:done\n", __func__); + LLDPAD_DBG("%s:done\n", __func__); return mod; out_err: - fprintf(stderr, "### %s:failed\n", __func__); + LLDPAD_DBG("%s:failed\n", __func__); return NULL; } @@ -442,7 +418,7 @@ void dcbx_unregister(struct lldp_module *mod) free(mod->data); } free(mod); - fprintf(stderr, "### %s:done\n", __func__); + LLDPAD_DBG("%s:done\n", __func__); } void dcbx_ifup(char *ifname) @@ -476,17 +452,8 @@ void dcbx_ifup(char *ifname) dud = find_module_user_data_by_if(ifname, &lldp_head, LLDP_MOD_DCBX); tlvs = dcbx_data(ifname); - if (tlvs) { - fprintf(stderr, "### %s: ifname %s tlvs exists\n", - __func__, ifname); - return; - } - - if (!port || !check_port_dcb_mode(ifname)) { - fprintf(stderr, "### %s: ifname %s not a DCB port\n", - __func__, ifname); + if (!port || !check_port_dcb_mode(ifname)) return; - } /* if no adminStatus setting or wrong setting for adminStatus, * then set adminStatus to enabledRxTx. @@ -496,12 +463,12 @@ void dcbx_ifup(char *ifname) adminstatus == enabledTxOnly || adminstatus == enabledRxOnly) { - /* set enableTx to TRUE if it is not already set */ + /* set enableTx to true if it is not already set */ snprintf(arg_path, sizeof(arg_path), "%s%08x.%s", TLVID_PREFIX, (OUI_CEE_DCBX << 8) | 1, ARG_TLVTXENABLE); if (get_config_setting(ifname, arg_path, (void *)&enabletx, CONFIG_TYPE_BOOL)) { - enabletx = TRUE; + enabletx = true; set_config_setting(ifname, arg_path, (void *)&enabletx, CONFIG_TYPE_BOOL); } @@ -510,7 +477,7 @@ void dcbx_ifup(char *ifname) (OUI_CEE_DCBX << 8) | 2, ARG_TLVTXENABLE); if (get_config_setting(ifname, arg_path, (void *)&enabletx, CONFIG_TYPE_BOOL)) { - enabletx = TRUE; + enabletx = true; set_config_setting(ifname, arg_path, (void *)&enabletx, CONFIG_TYPE_BOOL); } @@ -524,7 +491,7 @@ void dcbx_ifup(char *ifname) tlvs = malloc(sizeof(*tlvs)); if (!tlvs) { - fprintf(stderr, "### %s: ifname %s malloc failed.\n", + LLDPAD_DBG("%s: ifname %s malloc failed.\n", __func__, ifname); return; } @@ -533,7 +500,7 @@ void dcbx_ifup(char *ifname) manifest = malloc(sizeof(*manifest)); if (!manifest) { free(tlvs); - fprintf(stderr, "### %s: %s malloc failure\n", + LLDPAD_DBG("%s: %s malloc failure\n", __func__, ifname); return; } @@ -547,9 +514,12 @@ void dcbx_ifup(char *ifname) LIST_INSERT_HEAD(&dud->head, tlvs, entry); dcbx_add_adapter(ifname); + /* ensure advertise bits are set consistently with enabletx */ + enabletx = is_tlv_txenabled(ifname, (OUI_CEE_DCBX << 8) | + tlvs->dcbx_st); + if (!enabletx) + dont_advertise_dcbx_all(ifname); dcbx_bld_tlv(port); - - destroy_cfg(); } void dcbx_ifdown(char *device_name) @@ -694,7 +664,7 @@ int dcbx_rchange(struct port *port, struct unpacked_tlv *tlv) load_peer_tlvs(port, dcbx->manifest->dcbx2, CURRENT_PEER); if (unpack_dcbx2_tlvs(port, - dcbx->manifest->dcbx2) == FALSE) { + dcbx->manifest->dcbx2) == false) { printf("Error unpacking the DCBX2" "TLVs - Discarding LLDPDU\n"); return TLV_ERR; @@ -706,7 +676,7 @@ int dcbx_rchange(struct port *port, struct unpacked_tlv *tlv) dcbx->manifest->dcbx1, CURRENT_PEER); if (unpack_dcbx1_tlvs(port, - dcbx->manifest->dcbx1) == FALSE) { + dcbx->manifest->dcbx1) == false) { printf("Error unpacking the DCBX1" "TLVs - Discarding LLDPDU\n"); return TLV_ERR; @@ -736,8 +706,8 @@ u8 dcbx_mibDeleteObjects(struct port *port) /* Set any stored values for this TLV to !Present */ if (get_peer_pg(port->ifname, &peer_pg) == dcb_success) { - if (peer_pg.protocol.TLVPresent == TRUE) { - peer_pg.protocol.TLVPresent = FALSE; + if (peer_pg.protocol.TLVPresent == true) { + peer_pg.protocol.TLVPresent = false; put_peer_pg(port->ifname, &peer_pg); DCB_SET_FLAGS(EventFlag, DCB_REMOTE_CHANGE_PG); } @@ -746,8 +716,8 @@ u8 dcbx_mibDeleteObjects(struct port *port) } if (get_peer_pfc(port->ifname, &peer_pfc) == dcb_success) { - if (peer_pfc.protocol.TLVPresent == TRUE) { - peer_pfc.protocol.TLVPresent = FALSE; + if (peer_pfc.protocol.TLVPresent == true) { + peer_pfc.protocol.TLVPresent = false; put_peer_pfc(port->ifname, &peer_pfc); DCB_SET_FLAGS(EventFlag, DCB_REMOTE_CHANGE_PFC); } @@ -757,8 +727,8 @@ u8 dcbx_mibDeleteObjects(struct port *port) if (get_peer_app(port->ifname, subtype, &peer_app) == dcb_success) { - if (peer_app.protocol.TLVPresent == TRUE) { - peer_app.protocol.TLVPresent = FALSE; + if (peer_app.protocol.TLVPresent == true) { + peer_app.protocol.TLVPresent = false; peer_app.Length = 0; put_peer_app(port->ifname, subtype, &peer_app); DCB_SET_FLAGS(EventFlag, DCB_REMOTE_CHANGE_APPTLV); @@ -768,8 +738,8 @@ u8 dcbx_mibDeleteObjects(struct port *port) } if (get_peer_llink(port->ifname, subtype, &peer_llink) == dcb_success) { - if (peer_llink.protocol.TLVPresent == TRUE) { - peer_llink.protocol.TLVPresent = FALSE; + if (peer_llink.protocol.TLVPresent == true) { + peer_llink.protocol.TLVPresent = false; put_peer_llink(port->ifname, subtype, &peer_llink); DCB_SET_FLAGS(EventFlag, DCB_REMOTE_CHANGE_LLINK); } diff --git a/lldp_dcbx_cfg.c b/lldp_dcbx_cfg.c index 6ab1d59..318e1fe 100644 --- a/lldp_dcbx_cfg.c +++ b/lldp_dcbx_cfg.c @@ -186,12 +186,12 @@ static int check_for_old_file_format() if (config_lookup_string(&lldpad_cfg, "version", (const char **)&p)) { destroy_cfg(); if (remove(cfg_file_name)) - return 1; + return dcb_failed; check_cfg_file(); if (!init_cfg()) - return 1; + return dcb_failed; } - return 0; + return dcb_success; } void dcbx_default_cfg_file(void) @@ -210,7 +210,7 @@ void dcbx_default_cfg_file(void) /* dcbx configuration exists abort creating cfg */ if (!dcbx_setting) - goto out; + return; tmp_setting = config_setting_add(dcbx_setting, "version", CONFIG_TYPE_STRING); @@ -220,8 +220,6 @@ void dcbx_default_cfg_file(void) config_setting_set_int(tmp_setting, DEFAULT_DCBX_VERSION); config_write_file(&lldpad_cfg, cfg_file_name); -out: - destroy_cfg(); } @@ -626,11 +624,9 @@ static dcb_result _set_persistent(char *device_name, int dcb_enable, config_write_file(&lldpad_cfg, cfg_file_name); TRACE("Done!\n"); - destroy_cfg(); return dcb_success; set_error: - destroy_cfg(); snprintf(buf, sizeof(buf), "update of config file failed %s", cfg_file_name); log_message(MSG_ERR_DCB_INVALID_CONFIG_FILE, "%s", buf); @@ -689,14 +685,12 @@ dcb_result save_dcbx_version(int dcbx_version) !config_write_file(&lldpad_cfg, cfg_file_name)) rval = dcb_failed; - destroy_cfg(); - return dcb_success; } dcb_result set_persistent(char *device_name, full_dcb_attrib_ptrs *attribs) { - return _set_persistent(device_name, TRUE, attribs->pg, attribs->pfc, + return _set_persistent(device_name, true, attribs->pg, attribs->pfc, attribs->pgid, attribs->app, attribs->app_subtype, attribs->llink); } @@ -1041,7 +1035,6 @@ int get_dcb_enable_state(char *ifname, int *result) } } *result = (int)config_setting_get_int(settings); - printf("### %s:%s:result=%d\n", __func__, ifname, *result); rc = 0; out_err: return rc; @@ -1077,8 +1070,6 @@ int get_dcbx_version(int *result) } } - destroy_cfg(); - return rval; } diff --git a/lldp_dcbx_clif.c b/lldp_dcbx_clif.c index 3ae0d79..df3ce25 100644 --- a/lldp_dcbx_clif.c +++ b/lldp_dcbx_clif.c @@ -119,7 +119,6 @@ static void print_dcbx_feature_header(char *info, int offset, u8 *subtype) void print_dcbx_v1(u16 len, char *info) { int offset = 0; - int suboff; u16 tlvtype; u16 tlvlen; u8 pgid; @@ -130,7 +129,6 @@ void print_dcbx_v1(u16 len, char *info) u8 pfcmap; u8 op_version, max_version; u32 seqno, ackno; - u8 flags; u8 subtype; int i, j, cnt; int print_comma; @@ -256,7 +254,7 @@ void print_dcbx_v1(u16 len, char *info) if (subtype == 0) printf("\tFCoE Logical Link TLV:\n"); else if (subtype == 1) - printf("LAN Logical Link TLV:\n"); + printf("\tLAN Logical Link TLV:\n"); print_dcbx_feature_header(info, offset, &subtype); hexstr2bin(info+offset+8, (u8 *)&llink, sizeof(llink)); @@ -286,7 +284,6 @@ void print_dcbx_v2(u16 len, char *info) u8 numtcs; u8 op_version, max_version; u32 seqno, ackno; - u8 flags; u8 subtype; int i, j; int print_comma; @@ -444,7 +441,7 @@ void print_dcbx_v2(u16 len, char *info) /* return 1: if it printed the TLV * 0: if it did not */ -int dcbx_print_tlv(u32 tlvid, u16 len, u8 *info) +int dcbx_print_tlv(u32 tlvid, u16 len, char *info) { struct type_name_info *tn = &dcbx_tlv_names[0]; diff --git a/lldp_dcbx_cmds.c b/lldp_dcbx_cmds.c index 151fab4..b2173f9 100644 --- a/lldp_dcbx_cmds.c +++ b/lldp_dcbx_cmds.c @@ -42,6 +42,7 @@ #include "drv_cfg.h" #include "lldp/states.h" #include "lldp_dcbx.h" +#include "lldp_rtnl.h" extern u8 gdcbx_subtype; @@ -70,14 +71,13 @@ static int get_llink_data(llink_attribs *llink_data, int cmd, char *port_id, u32 subtype, int dcbx_st, char *rbuf); static dcb_result get_bwg_desc(char *port_id, char *ibuf, int ilen, char *rbuf); static dcb_result set_bwg_desc(char *port_id, char *ibuf, int ilen); -static void set_protocol_data(feature_protocol_attribs *protocol, char *ibuf, - int plen); +static void set_protocol_data(feature_protocol_attribs *protocol, char *ifname, + char *ibuf, int plen); static dcb_result get_cmd_protocol_data(feature_protocol_attribs *protocol, u8 cmd, char *rbuf); static int get_arg_tlvtxenable(struct cmd *, char *, char *, char *); static int set_arg_tlvtxenable(struct cmd *, char *, char *, char *); -static int set_arg_adminstatus(struct cmd *, char *, char *, char *); static struct arg_handlers arg_handlers[] = { { ARG_TLVTXENABLE, get_arg_tlvtxenable, set_arg_tlvtxenable }, @@ -99,9 +99,10 @@ static int get_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue, case (OUI_CEE_DCBX << 8) | 2: snprintf(arg_path, sizeof(arg_path), "%s%08x.%s", TLVID_PREFIX, cmd->tlvid, arg); + if (get_config_setting(cmd->ifname, arg_path, (void *)&value, CONFIG_TYPE_BOOL)) - value = FALSE; + value = false; break; case INVALID_TLVID: return cmd_invalid; @@ -113,16 +114,58 @@ static int get_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue, s = VAL_YES; else s = VAL_NO; - - sprintf(obuf, "%02x%s%04x%s", (int)strlen(arg), arg, (int)strlen(s), s); + + sprintf(obuf, "%02x%s%04x%s", (unsigned int)strlen(arg), arg, + (unsigned int)strlen(s), s); return cmd_success; } +void dont_advertise_dcbx_all(char *ifname) +{ + int i; + pfc_attribs pfc_data; + pg_attribs pg_data; + app_attribs app_data; + llink_attribs llink_data; + u32 event_flag = 0; + + if (get_pg(ifname, &pg_data) == dcb_success && + pg_data.protocol.Advertise) { + pg_data.protocol.Advertise = 0; + put_pg(ifname, &pg_data); + event_flag |= DCB_LOCAL_CHANGE_PG; + } + + if (get_pfc(ifname, &pfc_data) == dcb_success && + pfc_data.protocol.Advertise) { + pfc_data.protocol.Advertise = 0; + put_pfc(ifname, &pfc_data); + event_flag |= DCB_LOCAL_CHANGE_PFC; + } + + for (i = 0; i < DCB_MAX_APPTLV ; i++) { + if (get_app(ifname, (u32)i, &app_data) == dcb_success && + app_data.protocol.Advertise) { + app_data.protocol.Advertise = 0; + put_app(ifname, (u32)i, &app_data); + event_flag |= DCB_LOCAL_CHANGE_APPTLV; + } + + if (get_llink(ifname, (u32)i, &llink_data) == dcb_success && + llink_data.protocol.Advertise) { + llink_data.protocol.Advertise = 0; + put_llink(ifname, (u32)i, &llink_data); + event_flag |= DCB_LOCAL_CHANGE_LLINK; + } + } +} + static int set_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue, char *obuf) { int value; + int current_value; char arg_path[256]; if (cmd->cmd != cmd_settlv) @@ -145,12 +188,22 @@ static int set_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue, else return cmd_invalid; + current_value = is_tlv_txenabled(cmd->ifname, cmd->tlvid); + if (current_value == value) + return cmd_success; + snprintf(arg_path, sizeof(arg_path), "%s%08x.%s", TLVID_PREFIX, cmd->tlvid, arg); if (set_cfg(cmd->ifname, arg_path, (void *)&value, CONFIG_TYPE_BOOL)) return cmd_failed; + /* if DCBX tlv is changed to disabled, then ensure all DCBX features + * are set to 'not advertise' + */ + if (!value) + dont_advertise_dcbx_all(cmd->ifname); + somethingChangedLocal(cmd->ifname); return cmd_success; @@ -176,7 +229,7 @@ static int get_dcb_state(char *port_id, char *rbuf) static dcb_result set_dcb_state(char *port_id, char *ibuf, int ilen) { - int state; + bool state; int tmp; int off; int plen; @@ -187,7 +240,7 @@ static dcb_result set_dcb_state(char *port_id, char *ibuf, int ilen) if (ilen == (off + CFG_DCB_DLEN)) { state = (*(ibuf+off+DCB_STATE)) ^ '0'; - if (state == FALSE || state == TRUE) { + if (state == false || state == true) { /* if get_hw_state fails, then don't bother * trying to set the state. */ @@ -308,7 +361,6 @@ static dcb_result set_bwg_desc(char *port_id, char *ibuf, int ilen) if (init_cfg()) { rval = put_bwg_descrpt(port_id, pgid-1, ibuf+DCB_PORT_OFF+plen+PG_DESC_DATA); - destroy_cfg(); } else { rval = dcb_failed; } @@ -322,18 +374,28 @@ static dcb_result set_bwg_desc(char *port_id, char *ibuf, int ilen) return rval; } -static void set_protocol_data(feature_protocol_attribs *protocol, char *ibuf, - int plen) +static void set_protocol_data(feature_protocol_attribs *protocol, char *ifname, + char *ibuf, int plen) { u8 flag; + int last; flag = *(ibuf+DCB_PORT_OFF+plen+CFG_ENABLE); if (flag == '0' || flag == '1') protocol->Enable = flag & 0x01; flag = *(ibuf+DCB_PORT_OFF+plen+CFG_ADVERTISE); - if (flag == '0' || flag == '1') + if (flag == '0' || flag == '1') { + last = protocol->Advertise; protocol->Advertise = flag & 0x01; + if (last != protocol->Advertise && protocol->Advertise) { + if (init_cfg()) { + tlv_enabletx(ifname, (OUI_CEE_DCBX << 8) | + protocol->dcbx_st); + somethingChangedLocal(ifname); + } + } + } flag = *(ibuf+DCB_PORT_OFF+plen+CFG_WILLING); if (flag == '0' || flag == '1') @@ -362,7 +424,7 @@ static dcb_result get_cmd_protocol_data(feature_protocol_attribs *protocol, protocol->Syncd); break; case CMD_GET_PEER: - if (protocol->TLVPresent == TRUE) + if (protocol->TLVPresent == true) sprintf(rbuf, "%1x%1x%02x%02x%1x%1x", protocol->Enable, protocol->Willing, @@ -438,7 +500,7 @@ int dcbx_clif_cmd(void *data, if (ilen < DCB_PORT_OFF) return dcb_invalid_cmd; - + if (ibuf[DCB_VER_OFF] != (CLIF_MSG_VERSION | 0x30)) { printf("unsupported client interface message version %x\n", ibuf[DCB_VER_OFF]); @@ -457,7 +519,7 @@ int dcbx_clif_cmd(void *data, port_id[plen] = '\0'; /* check that interface is present and in DCB state */ - if (feature != FEATURE_DCB && check_port_dcb_mode(port_id) == FALSE) + if (feature != FEATURE_DCB && check_port_dcb_mode(port_id) == false) return dcb_device_not_found; switch(feature) { @@ -476,7 +538,6 @@ int dcbx_clif_cmd(void *data, } else { if (init_cfg()) { status = get_pg(port_id, &pg_data); - destroy_cfg(); } else { status = dcb_failed; } @@ -493,8 +554,8 @@ int dcbx_clif_cmd(void *data, printf("set command too short\n"); status = dcb_invalid_cmd; } else { - set_protocol_data(&pg_data.protocol, ibuf, - plen); + set_protocol_data(&pg_data.protocol, port_id, + ibuf, plen); status = set_pg_config(&pg_data, port_id, ibuf, ilen); } @@ -514,7 +575,6 @@ int dcbx_clif_cmd(void *data, } else { if (init_cfg()) { status = get_pfc(port_id, &pfc_data); - destroy_cfg(); } else { status = dcb_failed; } @@ -531,8 +591,8 @@ int dcbx_clif_cmd(void *data, printf("set command too short\n"); status = dcb_failed; } else { - set_protocol_data(&pfc_data.protocol, ibuf, - plen); + set_protocol_data(&pfc_data.protocol, port_id, + ibuf, plen); status = set_pfc_config(&pfc_data, port_id, ibuf, ilen); } @@ -554,7 +614,6 @@ int dcbx_clif_cmd(void *data, if (init_cfg()) { status = get_app(port_id, (u32)subtype, &app_data); - destroy_cfg(); } else { status = dcb_failed; } @@ -571,8 +630,8 @@ int dcbx_clif_cmd(void *data, printf("set command too short\n"); status = dcb_failed; } else { - set_protocol_data(&app_data.protocol, ibuf, - plen); + set_protocol_data(&app_data.protocol, port_id, + ibuf, plen); status = set_app_config(&app_data, port_id, (u32)subtype, ibuf, ilen); } @@ -594,7 +653,6 @@ int dcbx_clif_cmd(void *data, if (init_cfg()) { status = get_llink(port_id, (u32)subtype, &llink_data); - destroy_cfg(); } else { status = dcb_failed; } @@ -611,8 +669,8 @@ int dcbx_clif_cmd(void *data, printf("set command too short\n"); status = dcb_failed; } else { - set_protocol_data(&llink_data.protocol, ibuf, - plen); + set_protocol_data(&llink_data.protocol, port_id, + ibuf, plen); status = set_llink_config(&llink_data, port_id, (u32)subtype, ibuf, ilen); } @@ -632,7 +690,6 @@ int dcbx_clif_cmd(void *data, if (init_cfg()) { status = get_bwg_desc(port_id, ibuf, ilen, rbuf+strlen(rbuf)); - destroy_cfg(); } else { status = dcb_failed; } @@ -838,8 +895,8 @@ static int set_pg_config(pg_attribs *pg_data, char *port_id, char *ibuf, int i; int plen; int off; - u8 used[MAX_BANDWIDTH_GROUPS]; - u8 uppcts_changed = FALSE; + bool used[MAX_BANDWIDTH_GROUPS]; + bool uppcts_changed = false; plen=strlen(port_id); off = DCB_PORT_OFF + plen + CFG_LEN; @@ -852,7 +909,7 @@ static int set_pg_config(pg_attribs *pg_data, char *port_id, char *ibuf, pg_data->tx.up[i].tcmap = flag & 0x07; pg_data->rx.up[i].tcmap = flag & 0x07; } - memset(used, FALSE, sizeof(used)); + memset(used, false, sizeof(used)); for (i = 0; i < MAX_BANDWIDTH_GROUPS; i++) { if (*(ibuf+off+PG_PG_PCNT(i)) == CLIF_NOT_SUPPLIED) continue; @@ -885,12 +942,12 @@ static int set_pg_config(pg_attribs *pg_data, char *port_id, char *ibuf, * link strict PGID). */ if (flag < MAX_BANDWIDTH_GROUPS) - used[flag] = TRUE; + used[flag] = true; } for (i = 0; i < MAX_USER_PRIORITIES; i++) { if (*(ibuf+off+PG_UP_PCNT(i)) == CLIF_NOT_SUPPLIED) continue; - uppcts_changed = TRUE; + uppcts_changed = true; if (hexstr2bin(ibuf+off+PG_UP_PCNT(i), &flag, sizeof(flag))) return dcb_bad_params; @@ -963,7 +1020,6 @@ static int set_pg_config(pg_attribs *pg_data, char *port_id, char *ibuf, if (init_cfg()) { status = put_pg(port_id, pg_data); - destroy_cfg(); } else { status = dcb_failed; } @@ -1004,7 +1060,6 @@ static int set_pfc_config(pfc_attribs *pfc_data, char *port_id, char *ibuf, if (init_cfg()) { status = put_pfc(port_id, pfc_data); - destroy_cfg(); } else { status = dcb_failed; } @@ -1039,7 +1094,6 @@ static int set_app_config(app_attribs *app_data, char *port_id, u32 subtype, if (init_cfg()) { status = put_app(port_id, subtype, app_data); - destroy_cfg(); } else { status = dcb_failed; } @@ -1070,7 +1124,6 @@ static int set_llink_config(llink_attribs *llink_data, char *port_id, if (init_cfg()) { status = put_llink(port_id, subtype, llink_data); - destroy_cfg(); } else { status = dcb_failed; } diff --git a/lldp_mand.c b/lldp_mand.c index 2c11884..400a5ff 100644 --- a/lldp_mand.c +++ b/lldp_mand.c @@ -181,13 +181,13 @@ static int mand_bld_chassis_tlv(struct mand_data *md) /* check for value in shared memory first */ if (lldpad_shm_get_msap(md->ifname, CHASSIS_ID_TLV, (char *)&chassis, &length)) goto bld_tlv; - + /* subtype may differ when LLDP-MED is enabled */ if (!is_tlv_txenabled(md->ifname, TLVID_MED(LLDP_MED_RESERVED))) goto bld_config; devtype = get_med_devtype(md->ifname); - fprintf(stderr, "### %s:%s:MED enabled w/ devtype=%d)\n", + LLDPAD_DBG("%s:%s:MED enabled w/ devtype=%d)\n", __func__, md->ifname, devtype); if (devtype == LLDP_MED_DEVTYPE_NETWORK_CONNECTIVITY) goto bld_macaddr; @@ -210,7 +210,7 @@ bld_config: /* if invalid subtype, fall back to build */ if (!CHASSIS_ID_INVALID(chassis.sub)) { - fprintf(stderr, "### %s:%s:from config %d bytes:str=%s\n", + LLDPAD_DBG("%s:%s:from config %d bytes:str=%s\n", __func__, md->ifname, length, chastr); /* TODO: validate the loaded tlv */ goto bld_tlv; @@ -237,7 +237,6 @@ bld_netaddr: goto bld_tlv; } - /* ipv4 fails, get ipv6 */ if (!get_ipaddr6(md->ifname, &chassis.id.na.ip.v6)) { chassis.sub = CHASSIS_ID_NETWORK_ADDRESS; @@ -269,7 +268,8 @@ bld_tlv: md->chassis = tlv; md->rebuild_chassis = 0; /* write this back */ - lldpad_shm_set_msap(md->ifname, CHASSIS_ID_TLV, tlv->info, tlv->length); + lldpad_shm_set_msap(md->ifname, CHASSIS_ID_TLV, (char *)tlv->info, + tlv->length); set_config_tlvinfo_bin(md->ifname, TLVID_NOUI(CHASSIS_ID_TLV), tlv->info, tlv->length); @@ -338,7 +338,7 @@ static int mand_bld_portid_tlv(struct mand_data *md) goto bld_config; devtype = get_med_devtype(md->ifname); - fprintf(stderr, "### %s:%s:MED enabled w/ devtype=%d)\n", + LLDPAD_DBG("%s:%s:MED enabled w/ devtype=%d)\n", __func__, md->ifname, devtype); if (LLDP_MED_DEVTYPE_DEFINED(devtype)) @@ -357,7 +357,7 @@ bld_config: /* if invalid subtype, fall back to build */ if (!PORT_ID_INVALID(portid.sub)) { - fprintf(stderr, "### %s:%s:from config %d bytes:str=%s\n", + LLDPAD_DBG("%s:%s:from config %d bytes:str=%s\n", __func__, md->ifname, length, porstr); /* TODO: validate the loaded tlv */ goto bld_tlv; @@ -373,8 +373,6 @@ bld_macaddr: goto bld_tlv; } -bld_netaddr: -bld_ipv4: /* uses ipv4 first */ if (!get_ipaddr(md->ifname, &portid.id.na.ip.v4)) { portid.sub = PORT_ID_NETWORK_ADDRESS; @@ -385,7 +383,6 @@ bld_ipv4: goto bld_tlv; } -bld_ipv6: /* ipv4 fails, get ipv6 */ if (!get_ipaddr6(md->ifname, &portid.id.na.ip.v6)) { portid.sub = PORT_ID_NETWORK_ADDRESS; @@ -396,7 +393,6 @@ bld_ipv6: goto bld_tlv; } -bld_ifname: /* use ifname */ portid.sub = PORT_ID_INTERFACE_NAME; strncpy(portid.id.ifname, md->ifname, IFNAMSIZ); @@ -418,7 +414,8 @@ bld_tlv: md->portid = tlv; md->rebuild_portid = 0; /* write this back */ - lldpad_shm_set_msap(md->ifname, PORT_ID_TLV, tlv->info, tlv->length); + lldpad_shm_set_msap(md->ifname, PORT_ID_TLV, (char *)tlv->info, + tlv->length); set_config_tlvinfo_bin(md->ifname, TLVID_NOUI(PORT_ID_TLV), tlv->info, tlv->length); @@ -454,7 +451,7 @@ static int mand_bld_ttl_tlv(struct mand_data *md) ttl = htons(DEFAULT_TX_HOLD * DEFAULT_TX_INTERVAL); memcpy(tlv->info, &ttl, tlv->length); - fprintf(stderr, "### %s:%s:done:type=%d length=%d ttl=%d\n", __func__, + LLDPAD_DBG("%s:%s:done:type=%d length=%d ttl=%d\n", __func__, md->ifname, tlv->type, tlv->length, ntohs(ttl)); md->ttl = tlv; rc = 0; @@ -470,7 +467,7 @@ struct packed_tlv *mand_gettlv(struct port *port) md = mand_data(port->ifname); if (!md) { - fprintf(stderr, "### %s:%s: not found port\n", __func__, port->ifname); + LLDPAD_DBG("%s:%s: not found port\n", __func__, port->ifname); goto out_err; } @@ -496,7 +493,7 @@ struct packed_tlv *mand_gettlv(struct port *port) out_free: ptlv = free_pkd_tlv(ptlv); out_err: - fprintf(stderr,"### %s:%s: failed\n", __func__, port->ifname); + LLDPAD_DBG("%s:%s: failed\n", __func__, port->ifname); return NULL; } @@ -525,29 +522,27 @@ static int mand_bld_tlv(struct mand_data *md) goto out_err; if (mand_bld_chassis_tlv(md)) { - fprintf(stderr, "### %s:%s:mand_bld_chassis_tlv() failed\n", + LLDPAD_DBG("%s:%s:mand_bld_chassis_tlv() failed\n", __func__, md->ifname); - goto out_err_destroy; + goto out_err; } if (mand_bld_portid_tlv(md)) { - fprintf(stderr, "### %s:%s:mand_bld_portid_tlv() failed\n", + LLDPAD_DBG("%s:%s:mand_bld_portid_tlv() failed\n", __func__, md->ifname); - goto out_err_destroy; + goto out_err; } if (mand_bld_ttl_tlv(md)) { - fprintf(stderr, "### %s:%s:mand_bld_ttl_tlv() failed\n", + LLDPAD_DBG("%s:%s:mand_bld_ttl_tlv() failed\n", __func__, md->ifname); - goto out_err_destroy; + goto out_err; } if (mand_bld_end_tlv(md)) { - fprintf(stderr, "### %s:%s:mand_bld_end_tlv() failed\n", + LLDPAD_DBG("%s:%s:mand_bld_end_tlv() failed\n", __func__, md->ifname); - goto out_err_destroy; + goto out_err; } rc = 0; -out_err_destroy: - destroy_cfg(); out_err: return rc; @@ -577,10 +572,10 @@ void mand_ifdown(char *ifname) LIST_REMOVE(md, entry); mand_free_tlv(md); free(md); - fprintf(stderr, "### %s:port %s removed\n", __func__, ifname); + LLDPAD_INFO("%s:port %s removed\n", __func__, ifname); return; out_err: - fprintf(stderr, "### %s:port %s adding failed\n", __func__, ifname); + LLDPAD_INFO("%s:port %s adding failed\n", __func__, ifname); return; } @@ -591,19 +586,19 @@ void mand_ifup(char *ifname) md = mand_data(ifname); if (md) { - fprintf(stderr, "### %s:%s exists\n", __func__, ifname); + LLDPAD_INFO("%s:%s exists\n", __func__, ifname); goto out_err; } /* not found, alloc/init per-port tlv data */ md = (struct mand_data *) malloc(sizeof(*md)); if (!md) { - fprintf(stderr, "### %s:%s malloc %lu failed\n", __func__, ifname, sizeof(*md)); + LLDPAD_INFO("%s:%s malloc %lu failed\n", __func__, ifname, sizeof(*md)); goto out_err; } memset(md, 0, sizeof(struct mand_data)); strncpy(md->ifname, ifname, IFNAMSIZ); if (mand_bld_tlv(md)) { - fprintf(stderr, "### %s:%s mand_bld_tlv failed\n", __func__, ifname); + LLDPAD_INFO("%s:%s mand_bld_tlv failed\n", __func__, ifname); free(md); goto out_err; } @@ -614,10 +609,10 @@ void mand_ifup(char *ifname) md->rebuild_portid = 1; mud = find_module_user_data_by_if(ifname, &lldp_head, LLDP_MOD_MAND); LIST_INSERT_HEAD(&mud->head, md, entry); - fprintf(stderr, "### %s:port %s added\n", __func__, ifname); + LLDPAD_INFO("%s:port %s added\n", __func__, ifname); return; out_err: - fprintf(stderr, "### %s:port %s adding failed\n", __func__, ifname); + LLDPAD_INFO("%s:port %s adding failed\n", __func__, ifname); return; } @@ -628,27 +623,23 @@ struct lldp_module *mand_register(void) mod = malloc(sizeof(*mod)); if (!mod) { - fprintf(stderr, "failed to malloc module data\n"); - log_message(MSG_ERR_SERVICE_START_FAILURE, - "%s", "failed to malloc module data"); + LLDPAD_ERR("failed to malloc LLDP Mandatory module data\n"); goto out_err; } mud = malloc(sizeof(struct mand_user_data)); if (!mud) { free(mod); - fprintf(stderr, "failed to malloc module user data\n"); - log_message(MSG_ERR_SERVICE_START_FAILURE, - "%s", "failed to malloc module user data"); + LLDPAD_ERR("failed to malloc LLDP Mandatory module user data\n"); goto out_err; } LIST_INIT(&mud->head); mod->id = LLDP_MOD_MAND; mod->ops = &mand_ops; mod->data = mud; - fprintf(stderr, "### %s:done\n", __func__); + LLDPAD_INFO("%s:done\n", __func__); return mod; out_err: - fprintf(stderr, "### %s:failed\n", __func__); + LLDPAD_INFO("%s:failed\n", __func__); return NULL; } @@ -659,5 +650,5 @@ void mand_unregister(struct lldp_module *mod) free(mod->data); } free(mod); - fprintf(stderr, "### %s:done\n", __func__); + LLDPAD_INFO("%s:done\n", __func__); } diff --git a/lldp_mand_clif.c b/lldp_mand_clif.c index 563cd92..a0b4b81 100644 --- a/lldp_mand_clif.c +++ b/lldp_mand_clif.c @@ -157,7 +157,7 @@ void print_chassis_id(u16 len, char *info) sizeof(buf)); printf("IPv6: %s\n", buf); } else { - printf("Bad IPv6: %*.*s\n", len-2, len-2, + printf("Bad IPv6: %*.*s\n", 2*(len-2), 2*(len-2), info+4); } break; @@ -250,7 +250,7 @@ void print_port_id(u16 len, char *info) sizeof(buf)); printf("IPv6: %s\n", buf); } else { - printf("Bad IPv6: %*.*s\n", len-2, len-2, + printf("Bad IPv6: %*.*s\n", 2*(len-2), 2*(len-2), info+4); } break; @@ -298,7 +298,7 @@ void print_ttl(u16 len, char *info) /* return 1: if it printed the TLV * 0: if it did not */ -int mand_print_tlv(u32 tlvid, u16 len, u8 *info) +int mand_print_tlv(u32 tlvid, u16 len, char *info) { struct type_name_info *tn = &mand_tlv_names[0]; diff --git a/lldp_mand_cmds.c b/lldp_mand_cmds.c index 5f444f3..d9871e3 100644 --- a/lldp_mand_cmds.c +++ b/lldp_mand_cmds.c @@ -93,7 +93,8 @@ int get_arg_adminstatus(struct cmd *cmd, char *arg, char *argvalue, char *obuf) return cmd_invalid; } - sprintf(obuf, "%02x%s%04x%s", strlen(arg), arg, strlen(s), s); + sprintf(obuf, "%02x%s%04x%s", (unsigned int)strlen(arg), arg, + (unsigned int)strlen(s), s); return cmd_success; } @@ -101,7 +102,6 @@ int get_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue, char *obuf) { int value; char *s; - char arg_path[256]; if (cmd->cmd != cmd_gettlv) return cmd_bad_params; @@ -111,7 +111,7 @@ int get_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue, char *obuf) case PORT_ID_TLV: case TIME_TO_LIVE_TLV: case END_OF_LLDPDU_TLV: - value = TRUE; + value = true; break; case INVALID_TLVID: return cmd_invalid; @@ -124,7 +124,8 @@ int get_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue, char *obuf) else s = VAL_NO; - sprintf(obuf, "%02x%s%04x%s", strlen(arg), arg, strlen(s), s); + sprintf(obuf, "%02x%s%04x%s", (unsigned int)strlen(arg), arg, + (unsigned int)strlen(s), s); return cmd_success; } @@ -155,7 +156,6 @@ int handle_get_arg(struct cmd *cmd, char *arg, char *argvalue, char *obuf) ah++; } } - destroy_cfg(); return rval; } @@ -192,9 +192,6 @@ int set_arg_adminstatus(struct cmd *cmd, char *arg, char *argvalue, char *obuf) int set_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue, char *obuf) { - int value; - char arg_path[256]; - if (cmd->cmd != cmd_settlv) return cmd_bad_params; @@ -240,7 +237,7 @@ int handle_set_arg(struct cmd *cmd, char *arg, char *argvalue, char *obuf) ah++; } } - destroy_cfg(); + return cmd_success; } @@ -384,7 +381,7 @@ int mand_clif_cmd(void *data, argvalue[argvalue_len] = '\0'; sprintf(rbuf, "%c%1x%02x%08x%02x%s", CMD_REQUEST, CLIF_MSG_VERSION, - cmd.cmd, cmd.ops, strlen(cmd.ifname), cmd.ifname); + cmd.cmd, cmd.ops, (unsigned int)strlen(cmd.ifname), cmd.ifname); roff = strlen(rbuf); switch (cmd.cmd) { diff --git a/lldp_med.c b/lldp_med.c index 5405c8f..3c225bc 100644 --- a/lldp_med.c +++ b/lldp_med.c @@ -125,15 +125,15 @@ static u16 med_get_caps(u8 devtype) LLDP_MED_CAPABILITY_LOCATION_ID); break; case LLDP_MED_DEVTYPE_NETWORK_CONNECTIVITY: - fprintf(stderr, "###:%s:WARNING:NETWORK_CONNECTIVITY is" - "supported for bridge only\n", __func__); + LLDPAD_DBG("%s:WARNING:NETWORK_CONNECTIVITY is" + "supported for bridge only\n", __func__); medcaps = (LLDP_MED_CAPABILITY_CAPAPILITIES | LLDP_MED_CAPABILITY_NETWORK_POLICY | LLDP_MED_CAPABILITY_LOCATION_ID); break; case LLDP_MED_DEVTYPE_NOT_DEFINED: default: - fprintf(stderr, "###:%s:devtype %d not supported\n", + LLDPAD_DBG("%s:devtype %d not supported\n", __func__, devtype); break; } @@ -160,7 +160,7 @@ static int med_bld_medcaps_tlv(struct med_data *md) /* must be enabled */ if (!is_tlv_txenabled(md->ifname, TLVID_MED(LLDP_MED_CAPABILITIES))) { - fprintf(stderr, "### %s:%s:MED Caps is not enabled\n", + LLDPAD_DBG("%s:%s:MED Caps is not enabled\n", __func__, md->ifname); rc = 0; goto out_err; @@ -170,7 +170,7 @@ static int med_bld_medcaps_tlv(struct med_data *md) memset(&medcaps, 0, sizeof(medcaps)); if (get_config_tlvinfo_bin(md->ifname, TLVID_MED(LLDP_MED_CAPABILITIES), (void *)&medcaps, sizeof(medcaps))) { - fprintf(stderr, "### %s:%s:Build MED Caps from scratch\n", + LLDPAD_DBG("%s:%s:Build MED Caps as Endpoint Class I\n", __func__, md->ifname); goto out_bld; } @@ -178,11 +178,11 @@ static int med_bld_medcaps_tlv(struct med_data *md) /* validate the data loaded */ if (LLDP_MED_DEVTYPE_DEFINED(medcaps.devtype) && (medcaps.devtype == get_med_devtype(md->ifname))) { - fprintf(stderr, "### %s:%s:MED Caps loaded from config as type %d\n", + LLDPAD_DBG("%s:%s:MED Caps loaded from config as type %d\n", __func__, md->ifname, medcaps.devtype); goto out_create; } - fprintf(stderr, "### %s:%s:Loaded MED Caps is invalid, build from scrach\n", + LLDPAD_DBG("%s:%s:Load MED Caps is invalid\n", __func__, md->ifname); out_bld: @@ -251,7 +251,7 @@ int med_read_inventory(u8 subtype, char *buf, size_t size) strncpy(buf, uts.release, size - 1); goto out_err; } - fprintf(stderr, "###:%s: uname() failed for %d, try" + LLDPAD_DBG("%s: uname() failed for %d, try" " proc fs\n", __func__, subtype); strncpy(path, PATH_INV_SWREV, sizeof(path) - 1); break; @@ -268,18 +268,18 @@ int med_read_inventory(u8 subtype, char *buf, size_t size) strncpy(path, PATH_INV_ASSETID, sizeof(path) - 1); break; default: - fprintf(stderr, "###:%s: unknown inventory subtype %d\n", + LLDPAD_DBG("%s: unknown inventory subtype %d\n", __func__, subtype); goto out_err; } f = fopen(path, "r"); if (!f) { - fprintf(stderr, "###:%s: fopen(%s) failed for type %d\n", + LLDPAD_DBG("%s: fopen(%s) failed for type %d\n", __func__, path, subtype); goto out_err; } if (!fgets(buf, size, f)) { - fprintf(stderr, "###:%s: fgets(%s) failed for type %d\n", + LLDPAD_DBG("%s: fgets(%s) failed for type %d\n", __func__, path, subtype); memset(buf, 0, size); } @@ -302,14 +302,14 @@ static struct unpacked_tlv *med_bld_invtlv(struct med_data *md, u8 subtype) struct unpacked_tlv *tlv = NULL; if (!is_tlv_txenabled(md->ifname, TLVID_MED(subtype))) { - fprintf(stderr, "###:%s:%s:subtype %d tx disabled\n", + LLDPAD_DBG("%s:%s:subtype %d tx disabled\n", __func__, md->ifname, subtype); goto out_err; } length = med_read_inventory(subtype, (char *)desc, sizeof(desc)); if (!length) { - fprintf(stderr, "###:%s:%s:med_read_inventory(%d) failed\n", + LLDPAD_DBG("%s:%s:med_read_inventory(%d) failed\n", __func__, md->ifname, subtype); goto out_err; } @@ -318,7 +318,7 @@ static struct unpacked_tlv *med_bld_invtlv(struct med_data *md, u8 subtype) tlv = create_tlv(); if (!tlv) { - fprintf(stderr, "###:%s:%s:creat_tlv(%d) failed\n", + LLDPAD_DBG("%s:%s:creat_tlv(%d) failed\n", __func__, md->ifname, subtype); goto out_err; } @@ -366,14 +366,14 @@ static int med_bld_inventory_tlv(struct med_data *md) static int med_is_pd(const char *ifname) { - fprintf(stderr, "### %s:%s: TODO\n", __func__, ifname); + LLDPAD_DBG("%s:%s: TODO\n", __func__, ifname); return 0; } static int med_is_pse(const char *ifname) { - fprintf(stderr, "### %s:%s: TODO\n", __func__, ifname); + LLDPAD_DBG("%s:%s: TODO\n", __func__, ifname); return 0; } @@ -414,21 +414,21 @@ static int med_bld_powvmdi_tlv(struct med_data *md) mandatory = med_is_pd(md->ifname); break; default: - fprintf(stderr,"### %s:%s: Unknown device type %d\n", + LLDPAD_DBG("%s:%s: Unknown device type %d\n", __func__, md->ifname, devtype); rc = EINVAL; goto out_err; } if (!mandatory) { - fprintf(stderr,"### %s:%s: No need to send Extended Power via MDI TLV\n", + LLDPAD_DBG("%s:%s: No need to send Extended Power via MDI TLV\n", __func__, md->ifname); rc = 0; goto out_err; } /* Mandatory */ if (!is_tlv_txenabled(md->ifname, TLVID_MED(LLDP_MED_EXTENDED_PVMDI))) { - fprintf(stderr,"### %s:%s: Must enable Extended Power via MDI TLV as it" + LLDPAD_DBG("%s:%s: Must enable Extended Power via MDI TLV as it" " mandatory for device type %d\n", __func__, md->ifname, devtype); rc = EPERM; @@ -437,7 +437,7 @@ static int med_bld_powvmdi_tlv(struct med_data *md) /* Load from config */ if (get_config_tlvinfo_bin(md->ifname, TLVID_MED(LLDP_MED_NETWORK_POLICY), (void *)&extpvm, sizeof(extpvm))) { - fprintf(stderr,"### %s:%s: Must configure Extended Power via MDI TLV as " + LLDPAD_DBG("%s:%s: Must configure Extended Power via MDI TLV as " " currently it has to be manually configured\n", __func__, md->ifname); rc = EINVAL; @@ -448,7 +448,7 @@ static int med_bld_powvmdi_tlv(struct med_data *md) /* We should have a valid tlv_info_extpvm here */ if (extpvm.subtype != LLDP_MED_EXTENDED_PVMDI) { - fprintf(stderr,"### %s:%s: Wrong subtype %d: should be %d\n", + LLDPAD_DBG("%s:%s: Wrong subtype %d: should be %d\n", __func__, md->ifname, extpvm.subtype, LLDP_MED_EXTENDED_PVMDI); rc = EINVAL; goto out_err; @@ -500,7 +500,7 @@ static int med_bld_locid_tlv(struct med_data *md) FREE_UNPKD_TLV(md, locid); if (!is_tlv_txenabled(md->ifname, TLVID_MED(LLDP_MED_LOCATION_ID))) { - fprintf(stderr,"### %s:%s:Location Id TLV is not enabled\n", + LLDPAD_DBG("%s:%s:Location Id TLV is not enabled\n", __func__, md->ifname); rc = 0; goto out_err; @@ -515,7 +515,7 @@ static int med_bld_locid_tlv(struct med_data *md) memset(locstr, 0, length); if (get_config_tlvinfo_str(md->ifname, TLVID_MED(LLDP_MED_LOCATION_ID), (void *)locstr, length)) { - fprintf(stderr,"### %s:%s:Location Id TLV must be" + LLDPAD_DBG("%s:%s:Location Id TLV must be" " adminilocstratively configured\n", __func__, md->ifname); goto out_err; @@ -524,14 +524,14 @@ static int med_bld_locid_tlv(struct med_data *md) /* calculate the size in binary */ length = strlen(locstr) / 2; if (hexstr2bin(locstr, (u8 *)&locid, length)) { - fprintf(stderr,"### %s:%s:Location Id TLV info corrupted: %s\n", + LLDPAD_DBG("%s:%s:Location Id TLV info corrupted: %s\n", __func__, md->ifname, locstr); goto out_err; } /* validate the loaded data */ if (LLDP_MED_LOCID_FORMAT_INVALID(locid.format)) { - fprintf(stderr,"### %s:%s:Location Id TLV info invalid: %s\n", + LLDPAD_DBG("%s:%s:Location Id TLV info invalid: %s\n", __func__, md->ifname, locstr); goto out_err; } @@ -608,7 +608,7 @@ static int med_bld_netpoli_tlv(struct med_data *md) if (rc == ENOENT) goto out_nobld; if (rc == EPERM) { - fprintf(stderr,"### %s:%s: Must configure Network" + LLDPAD_DBG("%s:%s: Must configure Network" " Policy TLV if it is enabled for Network" " Connectivity Devcie\n", __func__, md->ifname); @@ -618,7 +618,7 @@ static int med_bld_netpoli_tlv(struct med_data *md) case LLDP_MED_DEVTYPE_ENDPOINT_CLASS_I: /* Optional: skip if failed to get it */ if (med_get_netpoli(md, &netpoli)) { - fprintf(stderr,"### %s:%s: Skipping" + LLDPAD_DBG("%s:%s: Skipping" " Network Policy TLV for Class I Device\n", __func__, md->ifname); goto out_nobld; @@ -628,21 +628,21 @@ static int med_bld_netpoli_tlv(struct med_data *md) case LLDP_MED_DEVTYPE_ENDPOINT_CLASS_III: /* Mandatory */ if (med_get_netpoli(md, &netpoli)) { - fprintf(stderr,"### %s:%s: Must enable and configure" + LLDPAD_DBG("%s:%s: Must enable and configure" " Network Policy TLV for Class II/III Device\n", __func__, md->ifname); goto out_err; } break; default: - fprintf(stderr,"### %s:%s: unknown dev type %d:\n", + LLDPAD_DBG("%s:%s: unknown dev type %d:\n", __func__, md->ifname, devtype); goto out_err; } /* We should have a valid tlv_info_netpoli */ if (netpoli.subtype != LLDP_MED_NETWORK_POLICY) { - fprintf(stderr,"### %s:%s: Wrong subtype %d: should be %d\n", + LLDPAD_DBG("%s:%s: Wrong subtype %d: should be %d\n", __func__, md->ifname, netpoli.subtype, LLDP_MED_NETWORK_POLICY); rc = EINVAL; goto out_err; @@ -694,24 +694,24 @@ static int med_bld_tlv(struct med_data *md) /* no build if not enabled */ if (!is_tlv_txenabled(md->ifname, TLVID_MED(LLDP_MED_RESERVED))) { - fprintf(stderr, "### %s:%s:LLDP-MED is not enabled\n", + LLDPAD_DBG("%s:%s:LLDP-MED is not enabled\n", __func__, md->ifname); rc = 0; - goto out_err_destroy; + goto out_err; } /* no build if enabled no devtype is given */ if (!LLDP_MED_DEVTYPE_DEFINED(get_med_devtype(md->ifname))) { - fprintf(stderr, "### %s:%s:LLDP-MED devtype is not defined\n", + LLDPAD_DBG("%s:%s:LLDP-MED devtype is not defined\n", __func__, md->ifname); - goto out_err_destroy; + goto out_err; } /* MED Cap is always mandatory for MED */ if (med_bld_medcaps_tlv(md)) { - fprintf(stderr, "### %s:%s:MED Capabilities TLV is mandatory!\n", + LLDPAD_DBG("%s:%s:MED Capabilities TLV is mandatory!\n", __func__, md->ifname); - goto out_err_destroy; + goto out_err; } /* Build optional and conditional ones based on device type: @@ -744,29 +744,27 @@ static int med_bld_tlv(struct med_data *md) * */ if (med_bld_netpoli_tlv(md)) { - fprintf(stderr, "### %s:%s:med_bld_netpoli_tlv() failed\n", + LLDPAD_DBG("%s:%s:med_bld_netpoli_tlv() failed\n", __func__, md->ifname); - goto out_err_destroy; + goto out_err; } if (med_bld_locid_tlv(md)) { - fprintf(stderr, "### %s:%s:med_bld_locid_tlv() failed\n", + LLDPAD_DBG("%s:%s:med_bld_locid_tlv() failed\n", __func__, md->ifname); - goto out_err_destroy; + goto out_err; } if (med_bld_powvmdi_tlv(md)) { - fprintf(stderr, "### %s:%s:med_bld_powvmdi_tlv() failed\n", + LLDPAD_DBG("%s:%s:med_bld_powvmdi_tlv() failed\n", __func__, md->ifname); - goto out_err_destroy; + goto out_err; } if (med_bld_inventory_tlv(md)) { - fprintf(stderr, "### %s:%s:med_bld_inventory_tlv() failed\n", + LLDPAD_DBG("%s:%s:med_bld_inventory_tlv() failed\n", __func__, md->ifname); - goto out_err_destroy; + goto out_err; } rc = 0; -out_err_destroy: - destroy_cfg(); out_err: return rc; } @@ -861,7 +859,7 @@ struct packed_tlv *med_gettlv(struct port *port) out_free: free_pkd_tlv(ptlv); out_err: - fprintf(stderr,"### %s:%s: failed\n", __func__, port->ifname); + LLDPAD_DBG("%s:%s: failed\n", __func__, port->ifname); return NULL; } @@ -876,10 +874,10 @@ void med_ifdown(char *ifname) LIST_REMOVE(md, entry); med_free_tlv(md); free(md); - fprintf(stderr, "### %s:port %s removed\n", __func__, ifname); + LLDPAD_INFO("%s:port %s removed\n", __func__, ifname); return; out_err: - fprintf(stderr, "### %s:port %s adding failed\n", __func__, ifname); + LLDPAD_INFO("%s:port %s adding failed\n", __func__, ifname); return; } @@ -890,14 +888,14 @@ void med_ifup(char *ifname) md = med_data(ifname); if (md) { - fprintf(stderr, "### %s:%s exists\n", __func__, ifname); + LLDPAD_DBG("%s:%s exists\n", __func__, ifname); goto out_err; } /* not found, alloc/init per-port tlv data */ md = (struct med_data *) malloc(sizeof(*md)); if (!md) { - fprintf(stderr, "### %s:%s malloc %ld failed\n", + LLDPAD_DBG("%s:%s malloc %ld failed\n", __func__, ifname, sizeof(*md)); goto out_err; } @@ -905,17 +903,17 @@ void med_ifup(char *ifname) strncpy(md->ifname, ifname, IFNAMSIZ); if (med_bld_tlv(md)) { - fprintf(stderr, "### %s:%s med_bld_tlv failed\n", + LLDPAD_DBG("%s:%s med_bld_tlv failed\n", __func__, ifname); free(md); goto out_err; } mud = find_module_user_data_by_if(ifname, &lldp_head, LLDP_MOD_MED); LIST_INSERT_HEAD(&mud->head, md, entry); - fprintf(stderr, "### %s:port %s added\n", __func__, ifname); + LLDPAD_INFO("%s:port %s added\n", __func__, ifname); return; out_err: - fprintf(stderr, "### %s:port %s adding failed\n", __func__, ifname); + LLDPAD_INFO("%s:port %s adding failed\n", __func__, ifname); return; } @@ -926,17 +924,13 @@ struct lldp_module *med_register(void) mod = malloc(sizeof(*mod)); if (!mod) { - fprintf(stderr, "failed to malloc module data\n"); - log_message(MSG_ERR_SERVICE_START_FAILURE, - "%s", "failed to malloc module data"); + LLDPAD_ERR(" failed to malloc LLDP-MED module data"); goto out_err; } mud = malloc(sizeof(struct med_user_data)); if (!mud) { free(mod); - fprintf(stderr, "failed to malloc module user data\n"); - log_message(MSG_ERR_SERVICE_START_FAILURE, - "%s", "failed to malloc module user data"); + LLDPAD_ERR(" failed to malloc LLDP-MED module user data"); goto out_err; } LIST_INIT(&mud->head); @@ -944,10 +938,10 @@ struct lldp_module *med_register(void) mod->ops = &med_ops; mod->data = mud; - fprintf(stderr, "### %s:done\n", __func__); + LLDPAD_INFO("%s:done\n", __func__); return mod; out_err: - fprintf(stderr, "### %s:failed\n", __func__); + LLDPAD_INFO("%s:failed\n", __func__); return NULL; } @@ -959,5 +953,5 @@ void med_unregister(struct lldp_module *mod) free(mod->data); } free(mod); - fprintf(stderr, "### %s:done\n", __func__); + LLDPAD_INFO("%s:done\n", __func__); } diff --git a/lldp_med_clif.c b/lldp_med_clif.c index dbfd3c6..c82326b 100644 --- a/lldp_med_clif.c +++ b/lldp_med_clif.c @@ -224,7 +224,7 @@ void med_print_string_tlv(u16 len, char *info) /* return 1: if it printed the TLV * 0: if it did not */ -int med_print_tlv(u32 tlvid, u16 len, u8 *info) +int med_print_tlv(u32 tlvid, u16 len, char *info) { struct type_name_info *tn = &med_tlv_names[0]; diff --git a/lldp_med_cmds.c b/lldp_med_cmds.c index 5bd0bba..cc38d0e 100644 --- a/lldp_med_cmds.c +++ b/lldp_med_cmds.c @@ -84,7 +84,7 @@ static int get_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue, if (get_config_setting(cmd->ifname, arg_path, (void *)&value, CONFIG_TYPE_BOOL)) - value = FALSE; + value = false; break; case INVALID_TLVID: return cmd_invalid; @@ -97,7 +97,8 @@ static int get_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue, else s = VAL_NO; - sprintf(obuf, "%02x%s%04x%s", strlen(arg), arg, strlen(s), s); + sprintf(obuf, "%02x%s%04x%s", (unsigned int)strlen(arg), arg, + (unsigned int)strlen(s), s); return cmd_success; } @@ -200,7 +201,8 @@ static int get_arg_med_devtype(struct cmd *cmd, char *arg, char *argvalue, return cmd_failed; } - sprintf(obuf, "%02x%s%04x%s", strlen(arg), arg, strlen(s), s); + sprintf(obuf, "%02x%s%04x%s", (unsigned int)strlen(arg), arg, + (unsigned int)strlen(s), s); return cmd_success; } diff --git a/lldp_rtnl.c b/lldp_rtnl.c index 1c0f648..da65371 100644 --- a/lldp_rtnl.c +++ b/lldp_rtnl.c @@ -50,9 +50,9 @@ #include #include +#include "common.h" #include "lldp_rtnl.h" #include "messages.h" -#include "common.h" #define NLMSG(c) ((struct nlmsghdr *) (c)) @@ -296,7 +296,6 @@ int get_operstate(char *ifname) return s; rtnl_recv_operstate(s, ifindex, ifname, &operstate); -out: close(s); return operstate; } diff --git a/lldp_tlv.c b/lldp_tlv.c index db47d37..9a0ae7e 100644 --- a/lldp_tlv.c +++ b/lldp_tlv.c @@ -44,7 +44,6 @@ void somethingChangedLocal(char *ifname) return; port->tx.localChange = 1; -printf("SETTING SOMETHING LOCALCHANGE TO TRUE %s\n", ifname); return; } diff --git a/lldp_util.c b/lldp_util.c index 56c2c24..f39fe6b 100644 --- a/lldp_util.c +++ b/lldp_util.c @@ -45,11 +45,14 @@ #include #include "lldp.h" #include "lldp_util.h" +#include "messages.h" #include "drv_cfg.h" int is_valid_lldp_device(const char *device_name) { + if (is_loopback(device_name)) + return 0; if (is_vlan(device_name)) return 0; if (is_bridge(device_name)) @@ -249,12 +252,8 @@ int get_ifflags(const char *ifname) memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFFLAGS, &ifr) == 0) { - fprintf(stderr, "### %s:%s::SIOCGIFFLAGS:flags=0x%x\n", - __func__, ifname, ifr.ifr_flags); flags = ifr.ifr_flags; } else { - fprintf(stderr, "### %s:%s:SIOCGIFFLAGS:failed\n", - __func__, ifname); } close(fd); } @@ -273,12 +272,8 @@ int get_ifpflags(const char *ifname) memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFPFLAGS, &ifr) == 0) { - fprintf(stderr, "### %s:%s::SIOCGIFFLAGS:flags=0x%x\n", - __func__, ifname, ifr.ifr_flags); flags = ifr.ifr_flags; } else { - fprintf(stderr, "### %s:%s:SIOCGIFFLAGS:failed\n", - __func__, ifname); } close(fd); } @@ -459,8 +454,6 @@ int is_bridge(const char *ifname) DIR *dirp; if (!is_ether(ifname)) { - fprintf(stderr, "### %s:%s:not an ether device\n", - __func__, ifname); return 0; } /* check for bridge in sysfs */ @@ -596,10 +589,6 @@ int is_autoneg_supported(const char *ifname) } else { perror("is_autoneg_supported() open socket failed"); } - - fprintf(stderr, "### %s:%s:autoneg supported:%s\n", - __func__, ifname, rc ? "yes" : "no"); - return rc; } @@ -623,8 +612,6 @@ int is_autoneg_enabled(const char *ifname) } else { perror("is_autoneg_enabled() open socket failed"); } - fprintf(stderr, "### %s:%s:autoneg enabled:%s\n", - __func__, ifname, rc ? "yes" : "no"); return rc; } @@ -678,9 +665,6 @@ int get_maucaps(const char *ifname) caps |= MAUCAPADV_bFdxAPause; if (cmd.advertising & (ADVERTISED_Asym_Pause | ADVERTISED_Pause)) caps |= MAUCAPADV_bFdxBPause; - - fprintf(stderr, "### %s:%s:ifMauAutoNegCapAdvertisedBits=%x\n", - __func__, ifname, caps); } close(fd); } else { @@ -747,9 +731,6 @@ int get_mautype(const char *ifname) rc = DOT3MAUTYPE_100BaseTXFD; else if (speed == SPEED_1000) rc = DOT3MAUTYPE_1000BaseTFD; - - fprintf(stderr, "### %s:%s:rc=%d\n", - __func__, ifname, rc); } close(fd); } else { @@ -770,8 +751,6 @@ int get_mtu(const char *ifname) strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFMTU, &ifr) == 0) { rc = ifr.ifr_mtu; - fprintf(stderr, "### %s:%s:mtu=%d\n", - __func__, ifname, rc); } close(fd); } else { diff --git a/lldpad.c b/lldpad.c index cc5c056..a89b5a4 100644 --- a/lldpad.c +++ b/lldpad.c @@ -147,11 +147,13 @@ int main(int argc, char *argv[]) char buf[32]; int shm_remove = 0; int killme = 0; + int print_v = 0; pid_t pid; int cnt; + int loglvl = LOG_WARNING; for (;;) { - c = getopt(argc, argv, "dhkvsf:"); + c = getopt(argc, argv, "dhkvsf:V:"); if (c < 0) break; switch (c) { @@ -172,14 +174,30 @@ int main(int argc, char *argv[]) shm_remove = 1; break; case 'v': - printf("%s\n", lldpad_version); - exit(0); + print_v = 1; + break; + case 'V': + loglvl = atoi(optarg); + if (loglvl > LOG_DEBUG) + loglvl = LOG_DEBUG; + if (loglvl < LOG_EMERG) + loglvl = LOG_EMERG; + break; case 'h': default: usage(); break; } } + /* exit if invalid input in the command line */ + if (optind < argc ) + usage(); + + if (print_v) { + printf("%s\n", lldpad_version); + exit(0); + } + if (cfg_file_name == NULL) { cfg_file_name = DEFAULT_CFG_FILE; } @@ -232,6 +250,8 @@ int main(int argc, char *argv[]) "%s", "lldpad_shm_setpid failed after kill"); exit (1); } + + destroy_cfg(); exit (0); } @@ -344,6 +364,7 @@ int main(int argc, char *argv[]) } openlog("lldpad", LOG_CONS | LOG_PID, LOG_DAEMON); + setlogmask(LOG_UPTO(loglvl)); if (check_cfg_file()) { exit(1); @@ -378,7 +399,9 @@ int main(int argc, char *argv[]) exit(1); } + LLDPAD_WARN("%s is starting", argv[0]); eloop_run(); + LLDPAD_WARN("%s is stopping", argv[0]); clean_lldp_agent(); deinit_modules(); @@ -387,7 +410,7 @@ int main(int argc, char *argv[]) event_iface_deinit(); stop_lldp_agent(); out: - + destroy_cfg(); closelog(); unlink(PID_FILE); eloop_destroy(); diff --git a/lldpad.init b/lldpad.init index 187f3b3..2cf0804 100644 --- a/lldpad.init +++ b/lldpad.init @@ -34,7 +34,7 @@ # lldpad (including DCB capabilities exchange protocol) # # chkconfig: 345 20 80 -# description: Data Center Bridging Exchange protocol daemon +# description: Link Layer Discovery Protocol Agent Daemon # ### BEGIN INIT INFO # Provides: lldpad @@ -42,7 +42,7 @@ # Required-Stop: $network # Default-Start: 3 5 # Default-Stop: -# Description: Data Center Bridging Exchange protocol daemon +# Description: Link Layer Discovery Protocol Agent Daemon ### END INIT INFO LLDPAD=lldpad @@ -164,21 +164,7 @@ case "$1" in ;; status) echo -n "Checking for service $LLDPAD: " - ## Check status with checkproc(8), if process is running - ## checkproc will return with exit status 0. - - # Return value is slightly different for the status command: - # 0 - service up and running - # 1 - service dead, but /var/run/ pid file exists - # 2 - service dead, but /var/lock/ lock file exists - # 3 - service not running (unused) - # 4 - service status unknown :-( - # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) - - # NOTE: checkproc returns LSB compliant status values. - checkproc $LLDPAD_BIN - # NOTE: rc_status knows that we called this init script with - # "status" option and adapts its messages accordingly. + p=`pidof $LLDPAD` rc_status -v ;; try-restart|condrestart) diff --git a/lldptool.8 b/lldptool.8 index 6c0a03f..1ef5746 100644 --- a/lldptool.8 +++ b/lldptool.8 @@ -50,7 +50,7 @@ Review the help output to see the list of supported TLV keywords. .TP .B \-n -"neighbor" option for commands which can use it (e.g. gettlv) +"neighbor" option for commands which can use it (e.g. get-tlv) .TP .B \-a "add" option for commands which can use it @@ -83,16 +83,16 @@ show version information .B \-S, stats get LLDP statistics .TP -.B \-t, gettlv +.B \-t, get-tlv get TLV information .TP -.B \-T, settlv +.B \-T, set-tlv set TLV information .TP -.B \-l, getlldp +.B \-l, get-lldp get LLDP parameters .TP -.B \-L, setlldp +.B \-L, set-lldp set LLDP parameters .TP .B \-q, quit @@ -103,19 +103,19 @@ exit from interactive mode .TP .B adminStatus Argument for the -.B getlldp/setlldp +.B get-lldp/set-lldp commands. May be applied per port or globbally. Valid values are: \fIdisabled\fR, \fIrx\fR, \fItx\fR, \fIrxtx\fR .TP .B enableTx Argument for the -.B gettlv/settlv -commands. May be applied per port or globbally. Valid values are: \fIyes\fR, \fIno\fR +.B get-tlv/set-tlv +commands. May be applied per port for a specified TLV. Valid values are: \fIyes\fR, \fIno\fR. If the DCBX TLV enableTx is set to \fIno\fR, then all of the DCB feature TLVs DCBX advertise settings will be turned off as well. Setting enableTx to \fIyes\fR for a DCBX TLV will not affect the DCBX advertise settings. .TP .B ipv4 Argument for the -.B gettlv/settlv +.B get-tlv/set-tlv commands with respect to the Management Address TLV. May be applied per port or globally. The get command will retrieve the configured value. Set values take the form of an IPv4 address: \fIA.B.C.D\fR @@ -123,7 +123,7 @@ take the form of an IPv4 address: \fIA.B.C.D\fR .TP .B ipv6 Argument for the -.B gettlv/settlv +.B get-tlv/set-tlv commands with respect to the Management Address TLV. May be applied per port or globally. The get command will retrieve the configured value. Set values take the form of an IPv6 address: \fI1111:2222:3333:4444:5555:6666:7777:8888\fR @@ -135,17 +135,17 @@ and various shorthand variations. Configure LLDP adminStatus to Receive and Transmit for interface \fIeth2\fR .B lldptool -L -i eth2 adminStatus=rxtx .br -.B lldptool setlldp -i eth2 adminStatus=rxtx +.B lldptool set-lldp -i eth2 adminStatus=rxtx .TP Disable the LLDP adminStatus for all interfaces -.B lldptool setlldp adminStatus=disabled +.B lldptool set-lldp adminStatus=disabled .TP Query the LLDP adminStatus for interface \fIeth3\fR .B lldptool -l -i eth3 adminStatus=disabled .br -.B lldptool getlldp -i eth3 adminStatus=disabled +.B lldptool get-lldp -i eth3 adminStatus=disabled .TP Query the LLDP statistics for interface \fIeth3\fR @@ -157,37 +157,37 @@ Query the LLDP statistics for interface \fIeth3\fR Query the local TLVs which are being transmitted for a given interface: .B lldptool -t -i eth3 .br -.B lldptool gettlv -i eth3 +.B lldptool get-tlv -i eth3 .TP Query the received neighbor TLVs received on a given interface: .B lldptool -t -n -i eth3 .br -.B lldptool gettlv -n -i eth3 +.B lldptool get-tlv -n -i eth3 .TP Query the value of the System Description TLV as received from the neighbor on a given interface: .B lldptool -t -n -i eth3 -V sysDesc .br -.B lldptool gettlv -n -i eth3 -V 6 +.B lldptool get-tlv -n -i eth3 -V 6 .TP Disable transmit of the IEEE 802.3 MAC/PHY Configuration Status TLV for a given interface: .B lldptool -T -i eth3 -V macPhyCfg enableTx=no .br -.B lldptool settlv -i eth3 -V 0x120f01 enableTx=no +.B lldptool set-tlv -i eth3 -V 0x120f01 enableTx=no .TP Enable transmit of the Port Description TLV for all interfaces: .B lldptool -T -V portDesc enableTx=yes .br -.B lldptool settlv -V 4 enableTx=yes +.B lldptool set-tlv -V 4 enableTx=yes .TP Query value of the transmit setting for the Port Description TLV for a given interface: .B lldptool -t -V portDesc enableTx .br -.B lldptool gettlv -V 4 enableTx +.B lldptool get-tlv -V 4 enableTx .TP Set a Management Address TLV on eth3 to carry IPv4 address 192.168.10.10 diff --git a/lldptool.c b/lldptool.c index 37850cc..a5e24d3 100644 --- a/lldptool.c +++ b/lldptool.c @@ -136,10 +136,10 @@ static const char *commands_help = " -v|version show version\n" " -q|quit exit lldptool (interactive mode)\n" " -S|stats get LLDP statistics for ifname\n" -" -t|gettlv get TLVs from ifname\n" -" -T|settlv set arg for tlvid to value\n" -" -l|getlldp get the LLDP parameters for ifname\n" -" -L|setlldp set the LLDP parameter for ifname\n"; +" -t|get-tlv get TLVs from ifname\n" +" -T|set-tlv set arg for tlvid to value\n" +" -l|get-lldp get the LLDP parameters for ifname\n" +" -L|set-lldp set the LLDP parameter for ifname\n"; static struct clif *clif_conn; static int cli_quit = 0; @@ -457,9 +457,13 @@ static struct cli_cmd cli_commands[] = { { cmd_quit, "quit", cli_cmd_quit }, { cmd_getstats, "stats", cli_cmd_getstats }, { cmd_gettlv, "gettlv", cli_cmd_gettlv }, + { cmd_gettlv, "get-tlv", cli_cmd_gettlv }, { cmd_settlv, "settlv", cli_cmd_settlv }, + { cmd_settlv, "set-tlv", cli_cmd_settlv }, { cmd_get_lldp, "getlldp", cli_cmd_getlldp }, + { cmd_get_lldp, "get-lldp", cli_cmd_getlldp }, { cmd_set_lldp, "setlldp", cli_cmd_setlldp }, + { cmd_set_lldp, "set-lldp", cli_cmd_setlldp }, { cmd_nop, NULL, cli_cmd_nop } }; @@ -510,6 +514,10 @@ static int request(struct clif *clif, int argc, char *argv[]) if (c < 0) break; switch (c) { + case '?': + printf("missing argument for option %s\n\n", argv[optind-1]); + usage(); + return -1; case 'S': command.cmd = cmd_getstats; break; @@ -522,7 +530,7 @@ static int request(struct clif *clif, int argc, char *argv[]) if (!command.tlvid) command.tlvid = lookup_tlvid(optarg); if (command.tlvid == INVALID_TLVID) { - printf("invalid TLV specifier: %s\n", optarg); + printf("invalid TLV identifier: %s\n\n", optarg); return -1; } break; @@ -793,6 +801,7 @@ int main(int argc, char *argv[]) cli_interactive(); } else { ret = request(clif_conn, argc, &argv[0]); + ret = !!ret; } free(clif_ifname); diff --git a/lldptool_cmds.c b/lldptool_cmds.c index 08845c1..25d8d5d 100644 --- a/lldptool_cmds.c +++ b/lldptool_cmds.c @@ -48,7 +48,8 @@ int render_cmd(struct cmd *cmd, char *arg, char *argvalue) /* all command messages begin this way */ snprintf(cmd->obuf, len, "%c%08x%c%1x%02x%08x%02x%s", MOD_CMD, cmd->module_id, CMD_REQUEST, CLIF_MSG_VERSION, - cmd->cmd, cmd->ops, strlen(cmd->ifname), cmd->ifname); + cmd->cmd, cmd->ops, (unsigned int) strlen(cmd->ifname), + cmd->ifname); /* if the command is a tlv command, add the tlvid to the message */ if (cmd->cmd == cmd_gettlv || cmd->cmd == cmd_settlv) @@ -58,10 +59,10 @@ int render_cmd(struct cmd *cmd, char *arg, char *argvalue) /* add any arg and argvalue to the command message */ if (arg) snprintf(cmd->obuf+strlen(cmd->obuf), len-strlen(cmd->obuf), - "%02x%s", strlen(arg), arg); + "%02x%s", (unsigned int)strlen(arg), arg); if (argvalue) snprintf(cmd->obuf+strlen(cmd->obuf), len-strlen(cmd->obuf), - "%04x%s", strlen(argvalue), argvalue); + "%04x%s", (unsigned int)strlen(argvalue), argvalue); return strlen(cmd->obuf); } diff --git a/log.c b/log.c index a072bce..3f05092 100644 --- a/log.c +++ b/log.c @@ -144,7 +144,7 @@ void log_message(u32 msgid, const char *format, ...) break; case MSG_ERR_DCB_INVALID_CONFIG_FILE: syslog(LOG_ERR, - "dcbd failed to read config file - %s", + "lldpad failed to read config file - %s", va_arg(va, char *)); break; case MSG_INFO_LLINK_DISABLED: @@ -168,6 +168,8 @@ void log_message(u32 msgid, const char *format, ...) va_arg(va, char *)); break; default: + if (MSG_IS_SYSLOG(msgid)) + vsyslog(MSG2SYSLOG(msgid), format, vb); break; } diff --git a/parse_cli.c b/parse_cli.c index efe8930..6c81c84 100644 --- a/parse_cli.c +++ b/parse_cli.c @@ -761,30 +761,6 @@ static int llsubtype = -1; static int llstatus = -1; static int desc_id = 0; static char *desc_str = NULL; -static float alpha = -1; -static int alpha_idx = 0; -static float beta = -1; -static int beta_idx = 0; -static float gd = -1; -static int gd_idx = 0; -static float gi = -1; -static int gi_idx = 0; -static int tmax = 0; -static int tmax_idx = 0; -static int td = 0; -static int td_idx = 0; -static int rmin = 0; -static int rmin_idx = 0; -static int w = 0; -static int w_idx = 0; -static int rd = 0; -static int rd_idx = 0; -static int ru = 0; -static int ru_idx = 0; -static int wrtt = -1; -static int wrtt_idx = 0; -static int ri = -1; -static int ri_idx = 0; static int fargs = 0; @@ -822,7 +798,7 @@ static int fargs = 0; -#line 826 "parse_cli.c" +#line 802 "parse_cli.c" #define INITIAL 0 #define dcb 1 @@ -1009,10 +985,10 @@ YY_DECL register char *yy_cp, *yy_bp; register int yy_act; -#line 139 "parse_cli.l" +#line 113 "parse_cli.l" -#line 1016 "parse_cli.c" +#line 992 "parse_cli.c" if ( !(yy_init) ) { @@ -1097,12 +1073,12 @@ do_action: /* This label is used only to access EOF actions. */ case 1: YY_RULE_SETUP -#line 141 "parse_cli.l" +#line 115 "parse_cli.l" YY_BREAK case 2: YY_RULE_SETUP -#line 143 "parse_cli.l" +#line 117 "parse_cli.l" { if (!cmd) { cmd = CMD_GET_CONFIG; } else { @@ -1114,7 +1090,7 @@ YY_RULE_SETUP YY_BREAK case 3: YY_RULE_SETUP -#line 152 "parse_cli.l" +#line 126 "parse_cli.l" { if (!cmd) { cmd = CMD_SET_CONFIG; } else { @@ -1126,7 +1102,7 @@ YY_RULE_SETUP YY_BREAK case 4: YY_RULE_SETUP -#line 161 "parse_cli.l" +#line 135 "parse_cli.l" { if (!cmd) { cmd = CMD_GET_OPER; } else { @@ -1138,7 +1114,7 @@ YY_RULE_SETUP YY_BREAK case 5: YY_RULE_SETUP -#line 170 "parse_cli.l" +#line 144 "parse_cli.l" { if (!cmd) { cmd = CMD_GET_PEER; } else { @@ -1151,19 +1127,19 @@ YY_RULE_SETUP case 6: /* rule 6 can match eol */ YY_RULE_SETUP -#line 179 "parse_cli.l" +#line 153 "parse_cli.l" { if (!badarg) badarg = strdup(yytext); error = 1; } YY_BREAK case 7: YY_RULE_SETUP -#line 183 "parse_cli.l" +#line 157 "parse_cli.l" YY_BREAK case 8: YY_RULE_SETUP -#line 184 "parse_cli.l" +#line 158 "parse_cli.l" { feature = FEATURE_DCBX; /* 'dcbx' is a global feature which does not * require a port name. @@ -1181,19 +1157,19 @@ YY_RULE_SETUP YY_BREAK case 9: YY_RULE_SETUP -#line 199 "parse_cli.l" +#line 173 "parse_cli.l" { port_id = strdup(yytext); BEGIN(getfeature); } YY_BREAK case 10: YY_RULE_SETUP -#line 204 "parse_cli.l" +#line 178 "parse_cli.l" YY_BREAK case 11: YY_RULE_SETUP -#line 205 "parse_cli.l" +#line 179 "parse_cli.l" { feature = FEATURE_DCB; if (cmd == CMD_SET_CONFIG) BEGIN(getdcbargs); @@ -1203,7 +1179,7 @@ YY_RULE_SETUP YY_BREAK case 12: YY_RULE_SETUP -#line 212 "parse_cli.l" +#line 186 "parse_cli.l" { feature = FEATURE_PFC; if (cmd == CMD_SET_CONFIG) BEGIN(getpfcargs); @@ -1213,7 +1189,7 @@ YY_RULE_SETUP YY_BREAK case 13: YY_RULE_SETUP -#line 219 "parse_cli.l" +#line 193 "parse_cli.l" { feature = FEATURE_PG; if (cmd == CMD_SET_CONFIG) BEGIN(getpgargs); @@ -1223,28 +1199,28 @@ YY_RULE_SETUP YY_BREAK case 14: YY_RULE_SETUP -#line 226 "parse_cli.l" +#line 200 "parse_cli.l" { feature = FEATURE_PG_DESC; BEGIN(getpgdescargs); } YY_BREAK case 15: YY_RULE_SETUP -#line 230 "parse_cli.l" +#line 204 "parse_cli.l" { feature = FEATURE_APP; BEGIN(getappsubtype); } YY_BREAK case 16: YY_RULE_SETUP -#line 233 "parse_cli.l" +#line 207 "parse_cli.l" { feature = FEATURE_LLINK; BEGIN(getllsubtype); } YY_BREAK case 17: YY_RULE_SETUP -#line 237 "parse_cli.l" +#line 211 "parse_cli.l" { if (!badarg) badarg = strdup(yytext); error = 1; @@ -1252,45 +1228,45 @@ YY_RULE_SETUP YY_BREAK case 18: YY_RULE_SETUP -#line 242 "parse_cli.l" +#line 216 "parse_cli.l" YY_BREAK case 19: YY_RULE_SETUP -#line 244 "parse_cli.l" +#line 218 "parse_cli.l" { BEGIN(getdcbxver); } YY_BREAK case 20: YY_RULE_SETUP -#line 248 "parse_cli.l" +#line 222 "parse_cli.l" { dcbx_version = atoi(yytext); BEGIN(cmddone); } YY_BREAK case 21: YY_RULE_SETUP -#line 252 "parse_cli.l" +#line 226 "parse_cli.l" YY_BREAK case 22: YY_RULE_SETUP -#line 254 "parse_cli.l" +#line 228 "parse_cli.l" { dcb_state = 1; BEGIN(cmddone); } YY_BREAK case 23: YY_RULE_SETUP -#line 258 "parse_cli.l" +#line 232 "parse_cli.l" { dcb_state = 0; BEGIN(cmddone); } YY_BREAK case 24: YY_RULE_SETUP -#line 262 "parse_cli.l" +#line 236 "parse_cli.l" { desc_id = *yytext & 0x0f; if (cmd == CMD_SET_CONFIG) @@ -1301,12 +1277,12 @@ YY_RULE_SETUP YY_BREAK case 25: YY_RULE_SETUP -#line 270 "parse_cli.l" +#line 244 "parse_cli.l" YY_BREAK case 26: YY_RULE_SETUP -#line 272 "parse_cli.l" +#line 246 "parse_cli.l" { desc_str = strdup(yytext); BEGIN(cmddone); @@ -1315,7 +1291,7 @@ YY_RULE_SETUP case 27: /* rule 27 can match eol */ YY_RULE_SETUP -#line 277 "parse_cli.l" +#line 251 "parse_cli.l" { error = 1; if (!badarg) badarg = strdup(yytext); @@ -1323,7 +1299,7 @@ YY_RULE_SETUP YY_BREAK case 28: YY_RULE_SETUP -#line 282 "parse_cli.l" +#line 256 "parse_cli.l" { if (got_args & GOT_ADVERTISE) { if (!badarg) badarg = @@ -1337,7 +1313,7 @@ YY_RULE_SETUP YY_BREAK case 29: YY_RULE_SETUP -#line 293 "parse_cli.l" +#line 267 "parse_cli.l" { if (got_args & GOT_ENABLE) { if (!badarg) badarg = @@ -1351,7 +1327,7 @@ YY_RULE_SETUP YY_BREAK case 30: YY_RULE_SETUP -#line 304 "parse_cli.l" +#line 278 "parse_cli.l" { if (got_args & GOT_WILLING) { if (!badarg) badarg = @@ -1365,7 +1341,7 @@ YY_RULE_SETUP YY_BREAK case 31: YY_RULE_SETUP -#line 315 "parse_cli.l" +#line 289 "parse_cli.l" { advertise = atoi(yytext); switch (feature) { case FEATURE_PG: BEGIN(getpgargs); break; @@ -1381,7 +1357,7 @@ YY_RULE_SETUP YY_BREAK case 32: YY_RULE_SETUP -#line 328 "parse_cli.l" +#line 302 "parse_cli.l" { enable = atoi(yytext); switch (feature) { case FEATURE_PG: BEGIN(getpgargs); break; @@ -1397,7 +1373,7 @@ YY_RULE_SETUP YY_BREAK case 33: YY_RULE_SETUP -#line 341 "parse_cli.l" +#line 315 "parse_cli.l" { willing = atoi(yytext); switch (feature) { case FEATURE_PG: BEGIN(getpgargs); break; @@ -1414,7 +1390,7 @@ YY_RULE_SETUP case 34: /* rule 34 can match eol */ YY_RULE_SETUP -#line 354 "parse_cli.l" +#line 328 "parse_cli.l" { error = 1; if (!badarg) badarg = strdup(yytext); @@ -1422,7 +1398,7 @@ YY_RULE_SETUP YY_BREAK case 35: YY_RULE_SETUP -#line 359 "parse_cli.l" +#line 333 "parse_cli.l" { if (got_args & GOT_UP2TC) { if (!badarg) badarg = @@ -1436,7 +1412,7 @@ YY_RULE_SETUP YY_BREAK case 36: YY_RULE_SETUP -#line 370 "parse_cli.l" +#line 344 "parse_cli.l" { if (got_args & GOT_PGPCT) { if (!badarg) badarg = @@ -1450,7 +1426,7 @@ YY_RULE_SETUP YY_BREAK case 37: YY_RULE_SETUP -#line 381 "parse_cli.l" +#line 355 "parse_cli.l" { if (got_args & GOT_PGID) { if (!badarg) badarg = @@ -1464,7 +1440,7 @@ YY_RULE_SETUP YY_BREAK case 38: YY_RULE_SETUP -#line 392 "parse_cli.l" +#line 366 "parse_cli.l" { if (got_args & GOT_UPPCT) { if (!badarg) badarg = @@ -1478,7 +1454,7 @@ YY_RULE_SETUP YY_BREAK case 39: YY_RULE_SETUP -#line 403 "parse_cli.l" +#line 377 "parse_cli.l" { if (got_args & GOT_STRICT) { if (!badarg) badarg = @@ -1492,7 +1468,7 @@ YY_RULE_SETUP YY_BREAK case 40: YY_RULE_SETUP -#line 414 "parse_cli.l" +#line 388 "parse_cli.l" { if (got_args & GOT_PFCUP) { if (!badarg) badarg = @@ -1506,7 +1482,7 @@ YY_RULE_SETUP YY_BREAK case 41: YY_RULE_SETUP -#line 425 "parse_cli.l" +#line 399 "parse_cli.l" { appsubtype = atoi(yytext+1); if (appsubtype >= DCB_MAX_APPTLV) { appsubtype = -1; @@ -1523,7 +1499,7 @@ YY_RULE_SETUP YY_BREAK case 42: YY_RULE_SETUP -#line 439 "parse_cli.l" +#line 413 "parse_cli.l" { appsubtype = 0; if (cmd == CMD_SET_CONFIG) BEGIN(getappargs); @@ -1533,7 +1509,7 @@ YY_RULE_SETUP YY_BREAK case 43: YY_RULE_SETUP -#line 446 "parse_cli.l" +#line 420 "parse_cli.l" { if (got_args & GOT_APPCFG) { if (!badarg) badarg = @@ -1547,7 +1523,7 @@ YY_RULE_SETUP YY_BREAK case 44: YY_RULE_SETUP -#line 457 "parse_cli.l" +#line 431 "parse_cli.l" { llsubtype = atoi(yytext+1); if (cmd == CMD_SET_CONFIG) BEGIN(getllargs); @@ -1557,7 +1533,7 @@ YY_RULE_SETUP YY_BREAK case 45: YY_RULE_SETUP -#line 464 "parse_cli.l" +#line 438 "parse_cli.l" { llsubtype = 0; if (cmd == CMD_SET_CONFIG) BEGIN(getllargs); @@ -1567,7 +1543,7 @@ YY_RULE_SETUP YY_BREAK case 46: YY_RULE_SETUP -#line 471 "parse_cli.l" +#line 445 "parse_cli.l" { if (got_args & GOT_LLSTATUS) { if (!badarg) badarg = @@ -1581,7 +1557,7 @@ YY_RULE_SETUP YY_BREAK case 47: YY_RULE_SETUP -#line 482 "parse_cli.l" +#line 456 "parse_cli.l" { llstatus = atoi(yytext); BEGIN(getllargs); } @@ -1589,14 +1565,14 @@ YY_RULE_SETUP case 48: /* rule 48 can match eol */ YY_RULE_SETUP -#line 487 "parse_cli.l" +#line 460 "parse_cli.l" { if (!badarg) badarg = strdup(yytext); error = 1; } YY_BREAK case 49: YY_RULE_SETUP -#line 491 "parse_cli.l" +#line 464 "parse_cli.l" { up2tc_a[up2tc_idx++] = atoi(yytext); if (up2tc_idx == 8) { BEGIN(getpgargs); @@ -1605,12 +1581,12 @@ YY_RULE_SETUP YY_BREAK case 50: YY_RULE_SETUP -#line 497 "parse_cli.l" +#line 470 "parse_cli.l" YY_BREAK case 51: YY_RULE_SETUP -#line 498 "parse_cli.l" +#line 471 "parse_cli.l" { pgpct_a[pgpct_idx] = atoi(yytext); if (pgpct_a[pgpct_idx] > 100) { if (!badarg) badarg = @@ -1626,7 +1602,7 @@ YY_RULE_SETUP YY_BREAK case 52: YY_RULE_SETUP -#line 511 "parse_cli.l" +#line 484 "parse_cli.l" { uppct_a[uppct_idx] = atoi(yytext); if (uppct_a[uppct_idx] > 100) { if (!badarg) badarg = @@ -1642,13 +1618,13 @@ YY_RULE_SETUP YY_BREAK case 53: YY_RULE_SETUP -#line 524 "parse_cli.l" +#line 497 "parse_cli.l" { BEGIN(getpgargs); } YY_BREAK case 54: YY_RULE_SETUP -#line 527 "parse_cli.l" +#line 500 "parse_cli.l" { pgid_a[pgid_idx++] = strtol(yytext, NULL, 16); if (pgid_idx == 8) { BEGIN(getpgargs); @@ -1657,7 +1633,7 @@ YY_RULE_SETUP YY_BREAK case 55: YY_RULE_SETUP -#line 533 "parse_cli.l" +#line 506 "parse_cli.l" { strict_a[strict_idx++] = atoi(yytext); if (strict_idx == 8) { BEGIN(getpgargs); @@ -1666,7 +1642,7 @@ YY_RULE_SETUP YY_BREAK case 56: YY_RULE_SETUP -#line 539 "parse_cli.l" +#line 512 "parse_cli.l" { pfcup_a[pfcup_idx++] = atoi(yytext); if (pfcup_idx == 8) { BEGIN(getpfcargs); @@ -1675,14 +1651,14 @@ YY_RULE_SETUP YY_BREAK case 57: YY_RULE_SETUP -#line 545 "parse_cli.l" +#line 518 "parse_cli.l" { appcfg_p = strdup(yytext); BEGIN(getappargs); } YY_BREAK case 58: YY_RULE_SETUP -#line 549 "parse_cli.l" +#line 522 "parse_cli.l" { error = 1; if (!badarg) badarg = strdup(yytext); @@ -1691,7 +1667,7 @@ YY_RULE_SETUP case 59: /* rule 59 can match eol */ YY_RULE_SETUP -#line 554 "parse_cli.l" +#line 527 "parse_cli.l" { if (!badarg) badarg = strdup(yytext); error = 1; } @@ -1733,7 +1709,7 @@ case YY_STATE_EOF(getappcfg): case YY_STATE_EOF(getllsubtype): case YY_STATE_EOF(getllstatus): case YY_STATE_EOF(cmddone): -#line 558 "parse_cli.l" +#line 531 "parse_cli.l" { BEGIN(INITIAL); yyterminate(); @@ -1741,10 +1717,10 @@ case YY_STATE_EOF(cmddone): YY_BREAK case 60: YY_RULE_SETUP -#line 562 "parse_cli.l" +#line 535 "parse_cli.l" ECHO; YY_BREAK -#line 1748 "parse_cli.c" +#line 1724 "parse_cli.c" case YY_END_OF_BUFFER: { @@ -2691,7 +2667,7 @@ void yyfree (void * ptr ) #define YYTABLES_NAME "yytables" -#line 562 "parse_cli.l" +#line 535 "parse_cli.l" @@ -3154,7 +3130,6 @@ int parse_dcb_cmd(char *buf) } break; - default: if (!badarg) badarg = strdup("invalid feature"); diff --git a/parse_cli.l b/parse_cli.l index 6ab5c80..420d037 100644 --- a/parse_cli.l +++ b/parse_cli.l @@ -65,30 +65,6 @@ static int llsubtype = -1; static int llstatus = -1; static int desc_id = 0; static char *desc_str = NULL; -static float alpha = -1; -static int alpha_idx = 0; -static float beta = -1; -static int beta_idx = 0; -static float gd = -1; -static int gd_idx = 0; -static float gi = -1; -static int gi_idx = 0; -static int tmax = 0; -static int tmax_idx = 0; -static int td = 0; -static int td_idx = 0; -static int rmin = 0; -static int rmin_idx = 0; -static int w = 0; -static int w_idx = 0; -static int rd = 0; -static int rd_idx = 0; -static int ru = 0; -static int ru_idx = 0; -static int wrtt = -1; -static int wrtt_idx = 0; -static int ri = -1; -static int ri_idx = 0; static int fargs = 0; %} @@ -100,14 +76,12 @@ static int fargs = 0; %x app %x ll - %x up2tc %x pgpct %x pgid %x uppct %x strict - %x getport %x getfeature %x getdcbargs @@ -483,7 +457,6 @@ gp { if (!cmd) { BEGIN(getllargs); } - [[:alnum:][:punct:][:cntrl:]] { if (!badarg) badarg = strdup(yytext); error = 1; } @@ -1020,7 +993,6 @@ int parse_dcb_cmd(char *buf) } break; - default: if (!badarg) badarg = strdup("invalid feature"); diff --git a/tlv_dcbx.c b/tlv_dcbx.c index 9b539fc..7d46887 100644 --- a/tlv_dcbx.c +++ b/tlv_dcbx.c @@ -32,20 +32,20 @@ #include "lldp_dcbx.h" #include "lldp/states.h" -boolean_t process_dcbx_ctrl_tlv(struct port *port); -boolean_t process_dcbx_pg_tlv(struct port *port); -boolean_t process_dcbx_pfc_tlv(struct port *port); -boolean_t process_dcbx_app_tlv(struct port *port); -boolean_t process_dcbx_llink_tlv(struct port *port); +bool process_dcbx_ctrl_tlv(struct port *port); +bool process_dcbx_pg_tlv(struct port *port); +bool process_dcbx_pfc_tlv(struct port *port); +bool process_dcbx_app_tlv(struct port *port); +bool process_dcbx_llink_tlv(struct port *port); /* for the specified remote feature, if the feature is not present in the * EventFlag parameter (indicating it was not received in the DCB TLV), then * check and update the peer data store object for the feature if it is * currently marked as being present. * - * returns TRUE if the feature is not present now + * returns true if the feature is not present now * the peer data store feature object is set to 'not present' - * FALSE otherwise. + * false otherwise. */ static u32 check_feature_not_present(char *device_name, u32 subtype, u32 EventFlag, u32 feature) @@ -57,28 +57,28 @@ static u32 check_feature_not_present(char *device_name, u32 subtype, /* if (!DCB_TEST_FLAGS(EventFlag, feature, feature)) { */ if (DCB_TEST_FLAGS(EventFlag, feature, feature)) - return FALSE; + return false; switch (feature) { case DCB_REMOTE_CHANGE_PG: if ((get_peer_pg(device_name, &peer_pg) == dcb_success) - && (peer_pg.protocol.TLVPresent == TRUE)) { - peer_pg.protocol.TLVPresent = FALSE; + && (peer_pg.protocol.TLVPresent == true)) { + peer_pg.protocol.TLVPresent = false; put_peer_pg(device_name, &peer_pg); } break; case DCB_REMOTE_CHANGE_PFC: if ((get_peer_pfc(device_name, &peer_pfc) == dcb_success) - && (peer_pfc.protocol.TLVPresent == TRUE)) { - peer_pfc.protocol.TLVPresent = FALSE; + && (peer_pfc.protocol.TLVPresent == true)) { + peer_pfc.protocol.TLVPresent = false; put_peer_pfc(device_name, &peer_pfc); } break; case DCB_REMOTE_CHANGE_APPTLV: if ((get_peer_app(device_name, subtype, &peer_app) == dcb_success) && - (peer_app.protocol.TLVPresent == TRUE)) { - peer_app.protocol.TLVPresent = FALSE; + (peer_app.protocol.TLVPresent == true)) { + peer_app.protocol.TLVPresent = false; peer_app.Length = 0; put_peer_app(device_name, subtype, &peer_app); } @@ -86,8 +86,8 @@ static u32 check_feature_not_present(char *device_name, u32 subtype, case DCB_REMOTE_CHANGE_LLINK: if ((get_peer_llink(device_name, subtype, &peer_llink) == dcb_success) && (peer_llink.protocol.TLVPresent == - TRUE)) { - peer_llink.protocol.TLVPresent = FALSE; + true)) { + peer_llink.protocol.TLVPresent = false; put_peer_llink(device_name, subtype, &peer_llink); } break; @@ -95,7 +95,7 @@ static u32 check_feature_not_present(char *device_name, u32 subtype, break; } - return TRUE; + return true; } struct unpacked_tlv *bld_dcbx1_tlv(struct dcbx_tlvs *dcbx) @@ -333,7 +333,7 @@ struct unpacked_tlv *bld_dcbx_ctrl_tlv(struct dcbx_tlvs *dcbx) return tlv; } -struct unpacked_tlv *bld_dcbx1_pg_tlv(struct dcbx_tlvs *dcbx, boolean_t *success) +struct unpacked_tlv *bld_dcbx1_pg_tlv(struct dcbx_tlvs *dcbx, bool *success) { struct dcbx1_pg_info *pg_info; struct unpacked_tlv *tlv = create_tlv(); @@ -341,7 +341,7 @@ struct unpacked_tlv *bld_dcbx1_pg_tlv(struct dcbx_tlvs *dcbx, boolean_t *success int result, i; u8 tmpbyte = 0; - *success = FALSE; + *success = false; if (!tlv) { return NULL; } @@ -350,7 +350,7 @@ struct unpacked_tlv *bld_dcbx1_pg_tlv(struct dcbx_tlvs *dcbx, boolean_t *success mark_pg_sent(dcbx->ifname); if (!(pg_cfg.protocol.Advertise)) { free(tlv); - *success = TRUE; + *success = true; return NULL; } } else { @@ -364,11 +364,11 @@ struct unpacked_tlv *bld_dcbx1_pg_tlv(struct dcbx_tlvs *dcbx, boolean_t *success pg_info->hdr.oper_version = (u8)pg_cfg.protocol.Oper_version; pg_info->hdr.max_version = (u8)pg_cfg.protocol.Max_version; /* ewe Enable Willing Error */ - if (pg_cfg.protocol.Enable == TRUE) + if (pg_cfg.protocol.Enable == true) pg_info->hdr.ewe |= BIT7; - if (pg_cfg.protocol.Willing == TRUE) + if (pg_cfg.protocol.Willing == true) pg_info->hdr.ewe |= BIT6; - if (pg_cfg.protocol.Error == TRUE) + if (pg_cfg.protocol.Error == true) pg_info->hdr.ewe |= BIT5; pg_info->hdr.sub_type = DEFAULT_SUBTYPE; @@ -396,11 +396,11 @@ struct unpacked_tlv *bld_dcbx1_pg_tlv(struct dcbx_tlvs *dcbx, boolean_t *success } tlv->type = DCB_PRIORITY_GROUPS_TLV; tlv->info = (u8 *)pg_info; - *success = TRUE; + *success = true; return tlv; } -struct unpacked_tlv *bld_dcbx2_pg_tlv(struct dcbx_tlvs *dcbx, boolean_t *success) +struct unpacked_tlv *bld_dcbx2_pg_tlv(struct dcbx_tlvs *dcbx, bool *success) { struct dcbx2_pg_info *pg_info; struct unpacked_tlv *tlv = create_tlv(); @@ -409,7 +409,7 @@ struct unpacked_tlv *bld_dcbx2_pg_tlv(struct dcbx_tlvs *dcbx, boolean_t *success u8 tmpbyte = 0; int j, k; - *success = FALSE; + *success = false; if (!tlv) { return NULL; } @@ -418,7 +418,7 @@ struct unpacked_tlv *bld_dcbx2_pg_tlv(struct dcbx_tlvs *dcbx, boolean_t *success mark_pg_sent(dcbx->ifname); if (!(pg_cfg.protocol.Advertise)) { free(tlv); - *success = TRUE; + *success = true; return NULL; } } else { @@ -432,11 +432,11 @@ struct unpacked_tlv *bld_dcbx2_pg_tlv(struct dcbx_tlvs *dcbx, boolean_t *success pg_info->hdr.oper_version = (u8)pg_cfg.protocol.Oper_version; pg_info->hdr.max_version = (u8)pg_cfg.protocol.Max_version; /* ewe Enable Willing Error */ - if (pg_cfg.protocol.Enable == TRUE) + if (pg_cfg.protocol.Enable == true) pg_info->hdr.ewe |= BIT7; - if (pg_cfg.protocol.Willing == TRUE) + if (pg_cfg.protocol.Willing == true) pg_info->hdr.ewe |= BIT6; - if (pg_cfg.protocol.Error == TRUE) + if (pg_cfg.protocol.Error == true) pg_info->hdr.ewe |= BIT5; pg_info->hdr.sub_type = DEFAULT_SUBTYPE; @@ -468,18 +468,18 @@ struct unpacked_tlv *bld_dcbx2_pg_tlv(struct dcbx_tlvs *dcbx, boolean_t *success } tlv->type = DCB_PRIORITY_GROUPS_TLV2; tlv->info = (u8 *)pg_info; - *success = TRUE; + *success = true; return tlv; } -struct unpacked_tlv *bld_dcbx1_pfc_tlv(struct dcbx_tlvs *dcbx, boolean_t *success) +struct unpacked_tlv *bld_dcbx1_pfc_tlv(struct dcbx_tlvs *dcbx, bool *success) { struct dcbx1_pfc_info *pfc_info; struct unpacked_tlv *tlv = create_tlv(); pfc_attribs pfc_cfg; int result,i; - *success = FALSE; + *success = false; if (!tlv) return NULL; result = get_pfc(dcbx->ifname, &pfc_cfg); @@ -487,7 +487,7 @@ struct unpacked_tlv *bld_dcbx1_pfc_tlv(struct dcbx_tlvs *dcbx, boolean_t *succes mark_pfc_sent(dcbx->ifname); if (!(pfc_cfg.protocol.Advertise)) { free(tlv); - *success = TRUE; + *success = true; return NULL; } } else { @@ -501,11 +501,11 @@ struct unpacked_tlv *bld_dcbx1_pfc_tlv(struct dcbx_tlvs *dcbx, boolean_t *succes pfc_info->hdr.oper_version = (u8)pfc_cfg.protocol.Oper_version; pfc_info->hdr.max_version = (u8)pfc_cfg.protocol.Max_version; /* ewe Enable Willing Error */ - if(pfc_cfg.protocol.Enable == TRUE) + if(pfc_cfg.protocol.Enable == true) pfc_info->hdr.ewe |= BIT7; - if(pfc_cfg.protocol.Willing == TRUE) + if(pfc_cfg.protocol.Willing == true) pfc_info->hdr.ewe |= BIT6; - if(pfc_cfg.protocol.Error == TRUE) + if(pfc_cfg.protocol.Error == true) pfc_info->hdr.ewe |= BIT5; pfc_info->hdr.sub_type = DEFAULT_SUBTYPE; u8 temp = 0; @@ -522,18 +522,18 @@ struct unpacked_tlv *bld_dcbx1_pfc_tlv(struct dcbx_tlvs *dcbx, boolean_t *succes } tlv->type = DCB_PRIORITY_FLOW_CONTROL_TLV; tlv->info = (u8 *)pfc_info; - *success = TRUE; + *success = true; return tlv; } -struct unpacked_tlv *bld_dcbx2_pfc_tlv(struct dcbx_tlvs *dcbx, boolean_t *success) +struct unpacked_tlv *bld_dcbx2_pfc_tlv(struct dcbx_tlvs *dcbx, bool *success) { struct dcbx2_pfc_info *pfc_info; struct unpacked_tlv *tlv = create_tlv(); pfc_attribs pfc_cfg; int result,i; - *success = FALSE; + *success = false; if (!tlv) return NULL; result = get_pfc(dcbx->ifname, &pfc_cfg); @@ -541,7 +541,7 @@ struct unpacked_tlv *bld_dcbx2_pfc_tlv(struct dcbx_tlvs *dcbx, boolean_t *succes mark_pfc_sent(dcbx->ifname); if (!(pfc_cfg.protocol.Advertise)) { free(tlv); - *success = TRUE; + *success = true; return NULL; } } else { @@ -555,11 +555,11 @@ struct unpacked_tlv *bld_dcbx2_pfc_tlv(struct dcbx_tlvs *dcbx, boolean_t *succes pfc_info->hdr.oper_version = (u8)pfc_cfg.protocol.Oper_version; pfc_info->hdr.max_version = (u8)pfc_cfg.protocol.Max_version; /* ewe Enable Willing Error */ - if(pfc_cfg.protocol.Enable == TRUE) + if(pfc_cfg.protocol.Enable == true) pfc_info->hdr.ewe |= BIT7; - if(pfc_cfg.protocol.Willing == TRUE) + if(pfc_cfg.protocol.Willing == true) pfc_info->hdr.ewe |= BIT6; - if(pfc_cfg.protocol.Error == TRUE) + if(pfc_cfg.protocol.Error == true) pfc_info->hdr.ewe |= BIT5; pfc_info->hdr.sub_type = DEFAULT_SUBTYPE; u8 temp = 0; @@ -577,13 +577,13 @@ struct unpacked_tlv *bld_dcbx2_pfc_tlv(struct dcbx_tlvs *dcbx, boolean_t *succes } tlv->type = DCB_PRIORITY_FLOW_CONTROL_TLV2; tlv->info = (u8 *)pfc_info; - *success = TRUE; + *success = true; return tlv; } struct unpacked_tlv *bld_dcbx1_app_tlv(struct dcbx_tlvs *dcbx, u32 sub_type, - boolean_t *success) + bool *success) { struct dcbx1_app_info *app_info; struct unpacked_tlv *tlv = create_tlv(); @@ -591,7 +591,7 @@ struct unpacked_tlv *bld_dcbx1_app_tlv(struct dcbx_tlvs *dcbx, int result; u32 i,len; - *success = FALSE; + *success = false; if (!tlv) return NULL; @@ -601,7 +601,7 @@ struct unpacked_tlv *bld_dcbx1_app_tlv(struct dcbx_tlvs *dcbx, mark_app_sent(dcbx->ifname, sub_type); if (!(app_cfg.protocol.Advertise)) { free(tlv); - *success = TRUE; + *success = true; return NULL; } } else { @@ -615,11 +615,11 @@ struct unpacked_tlv *bld_dcbx1_app_tlv(struct dcbx_tlvs *dcbx, app_info->hdr.oper_version = (u8)app_cfg.protocol.Oper_version; app_info->hdr.max_version = (u8)app_cfg.protocol.Max_version; /* ewe Enable Willing Error */ - if(app_cfg.protocol.Enable == TRUE) + if(app_cfg.protocol.Enable == true) app_info->hdr.ewe |= BIT7; - if(app_cfg.protocol.Willing == TRUE) + if(app_cfg.protocol.Willing == true) app_info->hdr.ewe |= BIT6; - if(app_cfg.protocol.Error == TRUE) + if(app_cfg.protocol.Error == true) app_info->hdr.ewe |= BIT5; app_info->hdr.sub_type = (u8)sub_type; for (i = 0; i < (int)app_cfg.Length; i++) { @@ -633,13 +633,13 @@ struct unpacked_tlv *bld_dcbx1_app_tlv(struct dcbx_tlvs *dcbx, } tlv->type = DCB_APPLICATION_TLV; tlv->info = (u8 *)app_info; - *success = TRUE; + *success = true; return tlv; } struct unpacked_tlv *bld_dcbx2_app_tlv(struct dcbx_tlvs *dcbx, u32 sub_type, - boolean_t *success) + bool *success) { struct dcbx2_app_info *app_info; struct unpacked_tlv *tlv = create_tlv(); @@ -647,7 +647,7 @@ struct unpacked_tlv *bld_dcbx2_app_tlv(struct dcbx_tlvs *dcbx, app_attribs app_cfg; int result; - *success = FALSE; + *success = false; if (!tlv) return NULL; @@ -657,7 +657,7 @@ struct unpacked_tlv *bld_dcbx2_app_tlv(struct dcbx_tlvs *dcbx, mark_app_sent(dcbx->ifname, sub_type); if (!(app_cfg.protocol.Advertise)) { free(tlv); - *success = TRUE; + *success = true; return NULL; } } else { @@ -670,11 +670,11 @@ struct unpacked_tlv *bld_dcbx2_app_tlv(struct dcbx_tlvs *dcbx, app_info->hdr.oper_version = (u8)app_cfg.protocol.Oper_version; app_info->hdr.max_version = (u8)app_cfg.protocol.Max_version; /* ewe Enable Willing Error */ - if(app_cfg.protocol.Enable == TRUE) + if(app_cfg.protocol.Enable == true) app_info->hdr.ewe |= BIT7; - if(app_cfg.protocol.Willing == TRUE) + if(app_cfg.protocol.Willing == true) app_info->hdr.ewe |= BIT6; - if(app_cfg.protocol.Error == TRUE) + if(app_cfg.protocol.Error == true) app_info->hdr.ewe |= BIT5; app_info->hdr.sub_type = (u8)sub_type; @@ -693,12 +693,12 @@ struct unpacked_tlv *bld_dcbx2_app_tlv(struct dcbx_tlvs *dcbx, } tlv->type = DCB_APPLICATION_TLV2; tlv->info = (u8 *)app_info; - *success = TRUE; + *success = true; return tlv; } struct unpacked_tlv *bld_dcbx_llink_tlv(struct dcbx_tlvs *dcbx, u32 sub_type, - boolean_t *success) + bool *success) { struct dcbx_llink_info *llink_info; struct unpacked_tlv *tlv = create_tlv(); @@ -708,7 +708,7 @@ struct unpacked_tlv *bld_dcbx_llink_tlv(struct dcbx_tlvs *dcbx, u32 sub_type, int result; - *success = FALSE; + *success = false; if (!tlv) { return NULL; } @@ -717,7 +717,7 @@ struct unpacked_tlv *bld_dcbx_llink_tlv(struct dcbx_tlvs *dcbx, u32 sub_type, mark_llink_sent(dcbx->ifname, sub_type); if (!(llk_cfg.protocol.Advertise)) { free(tlv); - *success = TRUE; + *success = true; return NULL; } } else { @@ -732,18 +732,18 @@ struct unpacked_tlv *bld_dcbx_llink_tlv(struct dcbx_tlvs *dcbx, u32 sub_type, (u8)llk_cfg.protocol.Oper_version; llink_info->hdr.max_version = (u8)llk_cfg.protocol.Max_version; /* ewe Enable Willing Error */ - if (llk_cfg.protocol.Enable == TRUE) + if (llk_cfg.protocol.Enable == true) llink_info->hdr.ewe |= BIT7; - if (llk_cfg.protocol.Willing == TRUE) + if (llk_cfg.protocol.Willing == true) llink_info->hdr.ewe |= BIT6; - if (llk_cfg.protocol.Error == TRUE) + if (llk_cfg.protocol.Error == true) llink_info->hdr.ewe |= BIT5; llink_info->hdr.sub_type = (u8)sub_type; cfg = &(llk_cfg.llink); pkt = &(llink_info->data); - if(cfg->llink_status == TRUE) + if(cfg->llink_status == true) pkt->byte1 |= BIT7; tlv->length = DCBX_LLINK_LEN; } else { @@ -753,11 +753,11 @@ struct unpacked_tlv *bld_dcbx_llink_tlv(struct dcbx_tlvs *dcbx, u32 sub_type, } tlv->type = DCB_LLINK_TLV; tlv->info = (u8 *)llink_info; - *success = TRUE; + *success = true; return tlv; } -boolean_t unpack_dcbx1_tlvs(struct port *port, struct unpacked_tlv *tlv) +bool unpack_dcbx1_tlvs(struct port *port, struct unpacked_tlv *tlv) { /* unpack the tlvs and store in manifest */ u8 *offset = NULL; /* iterator */ @@ -782,7 +782,7 @@ boolean_t unpack_dcbx1_tlvs(struct port *port, struct unpacked_tlv *tlv) if (!dcbtlv) { printf("ERROR: Failed to malloc space for incoming " "DCB TLV. \n"); - return FALSE; + return false; } memcpy(&tl, offset, sizeof(tl)); offset += sizeof(tl); @@ -790,7 +790,7 @@ boolean_t unpack_dcbx1_tlvs(struct port *port, struct unpacked_tlv *tlv) if (dcbtlv->length==0) { printf("ERROR: dcbtlv->length==0 \n"); free_unpkd_tlv(dcbtlv); - return FALSE; + return false; } dcbtlv->type = (u8)(ntohs(tl) >> 9); dcbtlv->info = (u8 *)malloc(dcbtlv->length); @@ -801,7 +801,7 @@ boolean_t unpack_dcbx1_tlvs(struct port *port, struct unpacked_tlv *tlv) printf("ERROR: Failed to malloc space for incoming " "TLV info \n"); free_unpkd_tlv(dcbtlv); - return FALSE; + return false; } current += dcbtlv->length + sizeof(tl); offset += dcbtlv->length; @@ -885,10 +885,10 @@ boolean_t unpack_dcbx1_tlvs(struct port *port, struct unpacked_tlv *tlv) dcbtlv = NULL; } while(current < end); - return TRUE; + return true; } -boolean_t unpack_dcbx2_tlvs(struct port *port, struct unpacked_tlv *tlv) +bool unpack_dcbx2_tlvs(struct port *port, struct unpacked_tlv *tlv) { /* unpack the tlvs and store in manifest */ u8 *offset = NULL; /* iterator */ @@ -913,7 +913,7 @@ boolean_t unpack_dcbx2_tlvs(struct port *port, struct unpacked_tlv *tlv) if (!dcbtlv) { printf("ERROR: Failed to malloc space for incoming " "DCB TLV. \n"); - return FALSE; + return false; } memcpy(&tl, offset, sizeof(tl)); offset += sizeof(tl); @@ -921,7 +921,7 @@ boolean_t unpack_dcbx2_tlvs(struct port *port, struct unpacked_tlv *tlv) if (dcbtlv->length==0) { printf("ERROR: dcbtlv->length==0 \n"); free_unpkd_tlv(dcbtlv); - return FALSE; + return false; } dcbtlv->type = (u8)(ntohs(tl) >> 9); dcbtlv->info = (u8 *)malloc(dcbtlv->length); @@ -932,7 +932,7 @@ boolean_t unpack_dcbx2_tlvs(struct port *port, struct unpacked_tlv *tlv) printf("ERROR: Failed to malloc space for incoming " "TLV info \n"); free_unpkd_tlv(dcbtlv); - return FALSE; + return false; } current += dcbtlv->length + sizeof(tl); offset += dcbtlv->length; @@ -993,7 +993,7 @@ boolean_t unpack_dcbx2_tlvs(struct port *port, struct unpacked_tlv *tlv) dcbtlv = NULL; } while(current < end); - return TRUE; + return true; } void mibUpdateObjects(struct port *port) @@ -1004,7 +1004,7 @@ void mibUpdateObjects(struct port *port) tlvs = dcbx_data(port->ifname); if (tlvs->manifest->dcbx_ctrl) { - if (process_dcbx_ctrl_tlv(port) != TRUE) { + if (process_dcbx_ctrl_tlv(port) != true) { /* Error Set error condition for all features * on this port and trash DCB TLV */ } @@ -1013,7 +1013,7 @@ void mibUpdateObjects(struct port *port) * on this port and trash DCB TLV */ } if (tlvs->manifest->dcbx_pg) { - if (process_dcbx_pg_tlv(port) != TRUE) { + if (process_dcbx_pg_tlv(port) != true) { /* mark feature not present */ if (check_feature_not_present(port->ifname, 0, EventFlag, DCB_REMOTE_CHANGE_PG)) { @@ -1029,7 +1029,7 @@ void mibUpdateObjects(struct port *port) } } if (tlvs->manifest->dcbx_pfc) { - if (process_dcbx_pfc_tlv(port) != TRUE) { + if (process_dcbx_pfc_tlv(port) != true) { /* mark feature not present */ if (check_feature_not_present(port->ifname, 0, EventFlag, DCB_REMOTE_CHANGE_PFC)) { @@ -1045,7 +1045,7 @@ void mibUpdateObjects(struct port *port) } } if (tlvs->manifest->dcbx_app) { - if (process_dcbx_app_tlv(port) != TRUE) { + if (process_dcbx_app_tlv(port) != true) { /* mark feature not present */ if (check_feature_not_present(port->ifname, 0, EventFlag, DCB_REMOTE_CHANGE_APPTLV)) { @@ -1063,7 +1063,7 @@ void mibUpdateObjects(struct port *port) } } if (tlvs->manifest->dcbx_llink) { - if (process_dcbx_llink_tlv(port) != TRUE) { + if (process_dcbx_llink_tlv(port) != true) { /* mark feature not present */ if (check_feature_not_present(port->ifname, 0, EventFlag, DCB_REMOTE_CHANGE_LLINK)) { @@ -1083,7 +1083,7 @@ void mibUpdateObjects(struct port *port) /* Run the feature & control protocol for all features and subtypes */ run_dcb_protocol(port->ifname, EventFlag, DCB_MAX_APPTLV+1); EventFlag = 0; - port->rxChanges = TRUE; + port->rxChanges = true; return; } @@ -1136,7 +1136,7 @@ void process_dcbx_tlv(struct port *port,struct unpacked_tlv *tlv) return; } -boolean_t process_dcbx_ctrl_tlv(struct port *port) +bool process_dcbx_ctrl_tlv(struct port *port) { struct dcbx_tlvs *tlvs; control_protocol_attribs peer_control; @@ -1145,7 +1145,7 @@ boolean_t process_dcbx_ctrl_tlv(struct port *port) if (tlvs->manifest->dcbx_ctrl->length != DCBX_CTRL_LEN) { printf("process_dcbx_ctrl_tlv: ERROR - len\n"); - return(FALSE); + return(false); } memset(&peer_control, 0, sizeof(control_protocol_attribs)); @@ -1177,10 +1177,10 @@ boolean_t process_dcbx_ctrl_tlv(struct port *port) put_peer_control(port->ifname, &peer_control); - return(TRUE); + return(true); } -boolean_t process_dcbx_pg_tlv(struct port *port) +bool process_dcbx_pg_tlv(struct port *port) { pg_attribs peer_pg; struct dcbx_tlvs *tlvs; @@ -1193,38 +1193,38 @@ boolean_t process_dcbx_pg_tlv(struct port *port) if (port->rx.dcbx_st == dcbx_subtype2) { if (tlvs->manifest->dcbx_pg->length != DCBX2_PG_LEN) { printf("process_dcbx2_pg_tlv: ERROR - len\n"); - return(FALSE); + return(false); } } else { if (tlvs->manifest->dcbx_pg->length != DCBX1_PG_LEN) { printf("process_dcbx1_pg_tlv: ERROR - len\n"); - return(FALSE); + return(false); } } memset(&peer_pg, 0, sizeof(pg_attribs)); - peer_pg.protocol.Advertise = TRUE; + peer_pg.protocol.Advertise = true; peer_pg.protocol.Oper_version = tlvs->manifest->dcbx_pg->info [DCBX_HDR_OPER_VERSION_OFFSET]; peer_pg.protocol.Max_version = tlvs->manifest->dcbx_pg->info [DCBX_HDR_MAX_VERSION_OFFSET]; if (tlvs->manifest->dcbx_pg->info[DCBX_HDR_EWE_OFFSET] & BIT7) { - peer_pg.protocol.Enable = TRUE; + peer_pg.protocol.Enable = true; } else { - peer_pg.protocol.Enable = FALSE; + peer_pg.protocol.Enable = false; } if (tlvs->manifest->dcbx_pg->info[DCBX_HDR_EWE_OFFSET] & BIT6) { - peer_pg.protocol.Willing = TRUE; + peer_pg.protocol.Willing = true; } else { - peer_pg.protocol.Willing = FALSE; + peer_pg.protocol.Willing = false; } if (tlvs->manifest->dcbx_pg->info[DCBX_HDR_EWE_OFFSET] & BIT5) { - peer_pg.protocol.Error = TRUE; + peer_pg.protocol.Error = true; } else { - peer_pg.protocol.Error = FALSE; + peer_pg.protocol.Error = false; } peer_pg.protocol.dcbx_st = port->rx.dcbx_st; - peer_pg.protocol.TLVPresent = TRUE; + peer_pg.protocol.TLVPresent = true; if (port->rx.dupTlvs & DUP_DCBX_TLV_CTRL) { printf("** STORE: DUP CTRL TLV \n"); @@ -1236,7 +1236,7 @@ boolean_t process_dcbx_pg_tlv(struct port *port) } if (port->rx.dcbx_st == dcbx_subtype2) { - memset(used, FALSE, sizeof(used)); + memset(used, false, sizeof(used)); for (j=0,k=0 ; k < MAX_BANDWIDTH_GROUPS; j++, k=k+2) { u8 tmpbyte = tlvs->manifest->dcbx_pg->info [DCBX2_PG_PGID_UP+j]; @@ -1248,13 +1248,13 @@ boolean_t process_dcbx_pg_tlv(struct port *port) peer_pg.tx.up[k+1].strict_priority = dcb_link; peer_pg.rx.up[k+1].strict_priority = dcb_link; } else { - used[peer_pg.tx.up[k+1].pgid] = TRUE; + used[peer_pg.tx.up[k+1].pgid] = true; } if (peer_pg.tx.up[k].pgid == LINK_STRICT_PGID) { peer_pg.tx.up[k].strict_priority = dcb_link; peer_pg.rx.up[k].strict_priority = dcb_link; } else { - used[peer_pg.tx.up[k].pgid] = TRUE; + used[peer_pg.tx.up[k].pgid] = true; } } /* assign LINK_STRICT_PGID's to an unused pgid value */ @@ -1318,10 +1318,10 @@ boolean_t process_dcbx_pg_tlv(struct port *port) } put_peer_pg(port->ifname, &peer_pg); - return(TRUE); + return(true); } -boolean_t process_dcbx_pfc_tlv(struct port *port) +bool process_dcbx_pfc_tlv(struct port *port) { pfc_attribs peer_pfc; struct dcbx_tlvs *tlvs; @@ -1332,38 +1332,38 @@ boolean_t process_dcbx_pfc_tlv(struct port *port) if (port->rx.dcbx_st == dcbx_subtype2) { if (tlvs->manifest->dcbx_pfc->length != DCBX2_PFC_LEN) { printf("process_dcbx2_pfc_tlv: ERROR - len\n"); - return(FALSE); + return(false); } } else { if (tlvs->manifest->dcbx_pfc->length != DCBX1_PFC_LEN) { printf("process_dcbx1_pfc_tlv: ERROR - len\n"); - return(FALSE); + return(false); } } memset(&peer_pfc, 0, sizeof(pfc_attribs)); - peer_pfc.protocol.Advertise = TRUE; + peer_pfc.protocol.Advertise = true; peer_pfc.protocol.Oper_version = tlvs->manifest->dcbx_pfc->info [DCBX_HDR_OPER_VERSION_OFFSET]; peer_pfc.protocol.Max_version = tlvs->manifest->dcbx_pfc->info [DCBX_HDR_MAX_VERSION_OFFSET]; if (tlvs->manifest->dcbx_pfc->info[DCBX_HDR_EWE_OFFSET] & BIT7) { - peer_pfc.protocol.Enable = TRUE; + peer_pfc.protocol.Enable = true; } else { - peer_pfc.protocol.Enable = FALSE; + peer_pfc.protocol.Enable = false; } if (tlvs->manifest->dcbx_pfc->info[DCBX_HDR_EWE_OFFSET] & BIT6) { - peer_pfc.protocol.Willing = TRUE; + peer_pfc.protocol.Willing = true; } else { - peer_pfc.protocol.Willing = FALSE; + peer_pfc.protocol.Willing = false; } if (tlvs->manifest->dcbx_pfc->info[DCBX_HDR_EWE_OFFSET] & BIT5) { - peer_pfc.protocol.Error = TRUE; + peer_pfc.protocol.Error = true; } else { - peer_pfc.protocol.Error = FALSE; + peer_pfc.protocol.Error = false; } peer_pfc.protocol.dcbx_st = port->rx.dcbx_st; - peer_pfc.protocol.TLVPresent = TRUE; + peer_pfc.protocol.TLVPresent = true; if (port->rx.dupTlvs & DUP_DCBX_TLV_CTRL) { printf("** STORE: DUP CTRL TLV \n"); @@ -1385,10 +1385,10 @@ boolean_t process_dcbx_pfc_tlv(struct port *port) } put_peer_pfc(port->ifname, &peer_pfc); - return(TRUE); + return(true); } -boolean_t process_dcbx_app_tlv(struct port *port) +bool process_dcbx_app_tlv(struct port *port) { app_attribs peer_app; u32 i=0, len=0; @@ -1404,12 +1404,12 @@ boolean_t process_dcbx_app_tlv(struct port *port) if (port->rx.dcbx_st == dcbx_subtype2) { if (len < DCBX2_APP_LEN) { printf("process_dcbx2_app_tlv: ERROR - len\n"); - return(FALSE); + return(false); } } else { if (len < DCBX1_APP_LEN) { printf("process_dcbx1_app_tlv: ERROR - len\n"); - return(FALSE); + return(false); } } @@ -1420,19 +1420,19 @@ boolean_t process_dcbx_app_tlv(struct port *port) peer_app.protocol.Oper_version = pBuf[DCBX_HDR_OPER_VERSION_OFFSET]; peer_app.protocol.Max_version = pBuf[DCBX_HDR_MAX_VERSION_OFFSET]; if (pBuf[DCBX_HDR_EWE_OFFSET] & BIT7) { - peer_app.protocol.Enable = TRUE; + peer_app.protocol.Enable = true; } else { - peer_app.protocol.Enable = FALSE; + peer_app.protocol.Enable = false; } if (pBuf[DCBX_HDR_EWE_OFFSET] & BIT6) { - peer_app.protocol.Willing = TRUE; + peer_app.protocol.Willing = true; } else { - peer_app.protocol.Willing = FALSE; + peer_app.protocol.Willing = false; } if (pBuf[DCBX_HDR_EWE_OFFSET] & BIT5) { - peer_app.protocol.Error = TRUE; + peer_app.protocol.Error = true; } else { - peer_app.protocol.Error = FALSE; + peer_app.protocol.Error = false; } peer_app.protocol.dcbx_st = port->rx.dcbx_st; @@ -1480,13 +1480,13 @@ boolean_t process_dcbx_app_tlv(struct port *port) pBuf = &pBuf[DCBX2_APP_SIZE]; continue; } - peer_app.protocol.TLVPresent = TRUE; + peer_app.protocol.TLVPresent = true; peer_app.Length = APP_FCOE_STYPE_LEN; memcpy (&(peer_app.AppData[0]), &(pBuf[DCBX2_APP_UP_MAP_OFFSET]), peer_app.Length); put_peer_app(port->ifname, sub_type, &peer_app); - return(TRUE); + return(true); } } else { sub_type = pBuf[DCBX_HDR_SUB_TYPE_OFFSET]; @@ -1494,19 +1494,19 @@ boolean_t process_dcbx_app_tlv(struct port *port) sizeof(struct dcbx_tlv_header); peer_app.Length = len; if (DCB_MAX_TLV_LENGTH < len) { - return FALSE; + return false; } for (i = 0; i < len; i++) { peer_app.AppData[i] = pBuf[DCBX1_APP_DATA_OFFSET + i]; } - peer_app.protocol.TLVPresent = TRUE; + peer_app.protocol.TLVPresent = true; put_peer_app(port->ifname, sub_type, &peer_app); - return(TRUE); + return(true); } - return(FALSE); + return(false); } -boolean_t process_dcbx_llink_tlv(struct port *port) +bool process_dcbx_llink_tlv(struct port *port) { llink_attribs peer_llk; struct dcbx_tlvs *tlvs; @@ -1515,32 +1515,32 @@ boolean_t process_dcbx_llink_tlv(struct port *port) if (tlvs->manifest->dcbx_llink->length != DCBX_LLINK_LEN) { printf("process_dcbx_llink_tlv: ERROR - len\n"); - return(FALSE); + return(false); } memset(&peer_llk, 0, sizeof(llink_attribs)); - peer_llk.protocol.Advertise = TRUE; + peer_llk.protocol.Advertise = true; peer_llk.protocol.Oper_version = tlvs->manifest->dcbx_llink->info [DCBX_HDR_OPER_VERSION_OFFSET]; peer_llk.protocol.Max_version = tlvs->manifest->dcbx_llink->info [DCBX_HDR_MAX_VERSION_OFFSET]; if (tlvs->manifest->dcbx_llink->info[DCBX_HDR_EWE_OFFSET] & BIT7) { - peer_llk.protocol.Enable = TRUE; + peer_llk.protocol.Enable = true; } else { - peer_llk.protocol.Enable = FALSE; + peer_llk.protocol.Enable = false; } if (tlvs->manifest->dcbx_llink->info[DCBX_HDR_EWE_OFFSET] & BIT6) { - peer_llk.protocol.Willing = TRUE; + peer_llk.protocol.Willing = true; } else { - peer_llk.protocol.Willing = FALSE; + peer_llk.protocol.Willing = false; } if (tlvs->manifest->dcbx_llink->info[DCBX_HDR_EWE_OFFSET] & BIT5) { - peer_llk.protocol.Error = TRUE; + peer_llk.protocol.Error = true; } else { - peer_llk.protocol.Error = FALSE; + peer_llk.protocol.Error = false; } peer_llk.protocol.dcbx_st = port->rx.dcbx_st; - peer_llk.protocol.TLVPresent = TRUE; + peer_llk.protocol.TLVPresent = true; if (port->rx.dupTlvs & DUP_DCBX_TLV_CTRL) { printf("** STORE: DUP CTRL TLV \n"); @@ -1555,6 +1555,6 @@ boolean_t process_dcbx_llink_tlv(struct port *port) [DCBX_LLINK_STATUS_OFFSET]) & BIT7); put_peer_llink(port->ifname, LLINK_FCOE_STYPE, &peer_llk); - return(TRUE); + return(true); }