lldpd-structs: Declare Boolean member as one bit, not two.
[cascardo/ovs.git] / lib / lldp / lldpd.c
index 9fcfee2..f3d142e 100644 (file)
@@ -66,9 +66,8 @@ lldpd_get_hardware(struct lldpd *cfg, char *name, int index,
     struct lldpd_hardware *hw;
 
     LIST_FOR_EACH (hw, h_entries, &cfg->g_hardware.h_entries) {
-        if ((strcmp(hw->h_ifname, name) == 0) &&
-            (hw->h_ifindex == index) &&
-            ((!ops) || (ops == hw->h_ops))) {
+        if (!strcmp(hw->h_ifname, name) && hw->h_ifindex == index
+            && (!ops || ops == hw->h_ops)) {
             return hw;
         }
     }
@@ -87,10 +86,10 @@ lldpd_alloc_hardware(struct lldpd *cfg, char *name, int index)
     hw->h_cfg = cfg;
     ovs_strlcpy(hw->h_ifname, name, sizeof hw->h_ifname);
     hw->h_ifindex = index;
-    hw->h_lport.p_chassis = (struct lldpd_chassis *)
-    list_front(&cfg->g_chassis.list);
+    hw->h_lport.p_chassis = CONTAINER_OF(list_front(&cfg->g_chassis.list),
+                                         struct lldpd_chassis, list);
     hw->h_lport.p_chassis->c_refcount++;
-    list_init(&hw->h_rports.p_entries);
+    list_init(&hw->h_rports);
 
     return hw;
 }
@@ -181,15 +180,12 @@ lldpd_move_chassis(struct lldpd_chassis *ochassis,
      * marshaling.
      */
     memcpy(ochassis, chassis, sizeof *ochassis);
-    list_init(&ochassis->c_mgmt.m_entries);
+    list_init(&ochassis->c_mgmt);
 
     /* Copy of management addresses */
-    LIST_FOR_EACH_SAFE (mgmt,
-                        mgmt_next,
-                        m_entries,
-                        &chassis->c_mgmt.m_entries) {
+    LIST_FOR_EACH_SAFE (mgmt, mgmt_next, m_entries, &chassis->c_mgmt) {
         list_remove(&mgmt->m_entries);
-        list_insert(&ochassis->c_mgmt.m_entries, &mgmt->m_entries);
+        list_insert(&ochassis->c_mgmt, &mgmt->m_entries);
     }
 
     /* Restore saved values */
@@ -262,10 +258,10 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s,
         s -= 4;
     }
 
-    LIST_FOR_EACH (oport, p_entries, &hw->h_rports.p_entries) {
-        if ((oport->p_lastframe != NULL) &&
-            (oport->p_lastframe->size == s) &&
-            (memcmp(oport->p_lastframe->frame, frame, s) == 0)) {
+    LIST_FOR_EACH (oport, p_entries, &hw->h_rports) {
+        if (oport->p_lastframe &&
+            oport->p_lastframe->size == s &&
+            !memcmp(oport->p_lastframe->frame, frame, s)) {
             /* Already received the same frame */
             VLOG_DBG("duplicate frame, no need to decode");
             oport->p_lastupdate = time_now();
@@ -304,16 +300,16 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s,
     /* Do we already have the same MSAP somewhere? */
     VLOG_DBG("search for the same MSAP");
 
-    LIST_FOR_EACH (oport, p_entries, &hw->h_rports.p_entries) {
+    LIST_FOR_EACH (oport, p_entries, &hw->h_rports) {
         if (port->p_protocol == oport->p_protocol) {
             count++;
-            if ((port->p_id_subtype == oport->p_id_subtype) &&
-                (port->p_id_len == oport->p_id_len) &&
-                (memcmp(port->p_id, oport->p_id, port->p_id_len) == 0) &&
-                (chassis->c_id_subtype == oport->p_chassis->c_id_subtype) &&
-                (chassis->c_id_len == oport->p_chassis->c_id_len) &&
-                (memcmp(chassis->c_id, oport->p_chassis->c_id,
-                chassis->c_id_len) == 0)) {
+            if (port->p_id_subtype == oport->p_id_subtype &&
+                port->p_id_len == oport->p_id_len &&
+                !memcmp(port->p_id, oport->p_id, port->p_id_len) &&
+                chassis->c_id_subtype == oport->p_chassis->c_id_subtype &&
+                chassis->c_id_len == oport->p_chassis->c_id_len &&
+                !memcmp(chassis->c_id, oport->p_chassis->c_id,
+                        chassis->c_id_len)) {
                 ochassis = oport->p_chassis;
                 VLOG_DBG("MSAP is already known");
                 found = true;
@@ -389,7 +385,7 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s,
     port->p_lastframe = xmalloc(s + sizeof(struct lldpd_frame));
     port->p_lastframe->size = s;
     memcpy(port->p_lastframe->frame, frame, s);
-    list_insert(&hw->h_rports.p_entries, &port->p_entries);
+    list_insert(&hw->h_rports, &port->p_entries);
 
     port->p_chassis = chassis;
     port->p_chassis->c_refcount++;
@@ -406,8 +402,7 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s,
      * freed with lldpd_port_cleanup() and therefore, the refcount
      * of the chassis that was attached to it is decreased.
      */
-    /* coverity[use_after_free] TAILQ_REMOVE does the right thing */
-    i = list_size((struct ovs_list *) &hw->h_rports);
+    i = list_size(&hw->h_rports);
     VLOG_DBG("%"PRIuSIZE " neighbors for %s", i, hw->h_ifname);
 
     if (!oport)  {
@@ -435,7 +430,7 @@ lldpd_hide_ports(struct lldpd *cfg,
         protocols[i] = 0;
     }
 
-    LIST_FOR_EACH (port, p_entries, &hw->h_rports.p_entries) {
+    LIST_FOR_EACH (port, p_entries, &hw->h_rports) {
         protocols[port->p_protocol]++;
     }
 
@@ -450,7 +445,7 @@ lldpd_hide_ports(struct lldpd *cfg,
         }
     }
     for (i = 0; i <= LLDPD_MODE_MAX; i++) {
-        if ((protocols[i] == min) && !found) {
+        if (protocols[i] == min && !found) {
             /* If we need a tie breaker, we take the first protocol only */
             if (cfg->g_config.c_smart & mask &
                 (SMART_OUTGOING_ONE_PROTO | SMART_INCOMING_ONE_PROTO)) {
@@ -463,7 +458,7 @@ lldpd_hide_ports(struct lldpd *cfg,
     }
 
     /* We set the p_hidden flag to 1 if the protocol is disabled */
-    LIST_FOR_EACH (port, p_entries, &hw->h_rports.p_entries) {
+    LIST_FOR_EACH (port, p_entries, &hw->h_rports) {
         if (mask == SMART_OUTGOING) {
             port->p_hidden_out = protocols[port->p_protocol] ? false : true;
         } else {
@@ -476,7 +471,7 @@ lldpd_hide_ports(struct lldpd *cfg,
         (SMART_OUTGOING_ONE_NEIGH | SMART_INCOMING_ONE_NEIGH)) {
         found = false;
 
-        LIST_FOR_EACH (port, p_entries, &hw->h_rports.p_entries) {
+        LIST_FOR_EACH (port, p_entries, &hw->h_rports) {
             if (mask == SMART_OUTGOING) {
                 if (found) {
                     port->p_hidden_out = true;
@@ -502,9 +497,9 @@ lldpd_hide_ports(struct lldpd *cfg,
     }
 
     k = j = 0;
-    LIST_FOR_EACH (port, p_entries, &hw->h_rports.p_entries) {
-        if (!(((mask == SMART_OUTGOING) && port->p_hidden_out) ||
-              ((mask == SMART_INCOMING) && port->p_hidden_in))) {
+    LIST_FOR_EACH (port, p_entries, &hw->h_rports) {
+        if (!((mask == SMART_OUTGOING && port->p_hidden_out) ||
+              (mask == SMART_INCOMING && port->p_hidden_in))) {
             k++;
             protocols[port->p_protocol] = 1;
         }
@@ -603,7 +598,7 @@ lldpd_send(struct lldpd_hardware *hw, struct dp_packet *p)
         /* We send only if we have at least one remote system
          * speaking this protocol or if the protocol is forced */
         if (cfg->g_protocols[i].enabled > 1) {
-            if ((lldp_size = cfg->g_protocols[i].send(cfg, hw, p)) != E2BIG) {
+            if ((lldp_size = cfg->g_protocols[i].send(cfg, hw, p)) != -E2BIG) {
                 sent++;
                 continue;
             } else {
@@ -612,7 +607,7 @@ lldpd_send(struct lldpd_hardware *hw, struct dp_packet *p)
             }
         }
 
-        LIST_FOR_EACH (port, p_entries, &hw->h_rports.p_entries) {
+        LIST_FOR_EACH (port, p_entries, &hw->h_rports) {
             /* If this remote port is disabled, we don't consider it */
             if (port->p_hidden_out) {
                 continue;