[ovs-dev] [PATCH 30/32] lldpd: Fix use of list of struct lldpd_hardware.

Ben Pfaff blp at nicira.com
Mon Feb 23 05:20:22 UTC 2015


A list of some type should have type "struct ovs_list", not some other
type that encapsulates it.

This ovs_list is a bit puzzling in itself, because it appears to always
have exactly one element.

Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 lib/lldp/lldpd.c |  6 +++---
 lib/lldp/lldpd.h |  9 ++++++++-
 lib/ovs-lldp.c   | 28 ++++++++++++----------------
 tests/test-aa.c  |  5 ++---
 4 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/lib/lldp/lldpd.c b/lib/lldp/lldpd.c
index d309f32..c1bfdaf 100644
--- a/lib/lldp/lldpd.c
+++ b/lib/lldp/lldpd.c
@@ -64,7 +64,7 @@ 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) {
+    LIST_FOR_EACH (hw, h_entries, &cfg->g_hardware) {
         if (!strcmp(hw->h_ifname, name) && hw->h_ifindex == index
             && (!ops || ops == hw->h_ops)) {
             return hw;
@@ -137,7 +137,7 @@ lldpd_cleanup(struct lldpd *cfg)
 
     VLOG_DBG("cleanup all ports");
 
-    LIST_FOR_EACH_SAFE (hw, hw_next, h_entries, &cfg->g_hardware.h_entries) {
+    LIST_FOR_EACH_SAFE (hw, hw_next, h_entries, &cfg->g_hardware) {
         if (!hw->h_flags) {
             list_remove(&hw->h_entries);
             lldpd_remote_cleanup(hw, NULL, true);
@@ -542,7 +542,7 @@ lldpd_hide_all(struct lldpd *cfg)
 
     VLOG_DBG("apply smart filter results on all ports");
 
-    LIST_FOR_EACH (hw, h_entries, &cfg->g_hardware.h_entries) {
+    LIST_FOR_EACH (hw, h_entries, &cfg->g_hardware) {
         if (cfg->g_config.c_smart & SMART_INCOMING_FILTER) {
             lldpd_hide_ports(cfg, hw, SMART_INCOMING);
         }
diff --git a/lib/lldp/lldpd.h b/lib/lldp/lldpd.h
index aa7665e..3aaf790 100644
--- a/lib/lldp/lldpd.h
+++ b/lib/lldp/lldpd.h
@@ -84,9 +84,16 @@ struct lldpd {
     int                 g_lastrid;
 
     struct ovs_list     g_chassis; /* Contains "struct lldp_chassis". */
-    struct lldpd_hardware g_hardware;
+    struct ovs_list     g_hardware; /* Contains "struct lldpd_hardware". */
 };
 
+static inline struct lldpd_hardware *
+lldpd_first_hardware(struct lldpd *lldpd)
+{
+    return CONTAINER_OF(list_front(&lldpd->g_hardware),
+                        struct lldpd_hardware, h_entries);
+}
+
 /* lldpd.c */
 struct lldpd_hardware *lldpd_get_hardware(struct lldpd *,
     char *, int, struct lldpd_ops *);
diff --git a/lib/ovs-lldp.c b/lib/ovs-lldp.c
index abea477..4ac5d90 100644
--- a/lib/ovs-lldp.c
+++ b/lib/ovs-lldp.c
@@ -179,7 +179,7 @@ aa_print_lldp_and_aa_stats(struct ds *ds, struct lldp *lldp)
         return;
     }
 
-    LIST_FOR_EACH (hw, h_entries, &lldp->lldpd->g_hardware.h_entries) {
+    LIST_FOR_EACH (hw, h_entries, &lldp->lldpd->g_hardware) {
         ds_put_format(ds, "\ttx cnt: %"PRIu64"\n", hw->h_tx_cnt);
         ds_put_format(ds, "\trx cnt: %"PRIu64"\n", hw->h_rx_cnt);
         ds_put_format(ds, "\trx discarded cnt: %"PRIu64"\n",
@@ -244,7 +244,7 @@ aa_print_element_status(struct ds *ds, struct lldp *lldp) OVS_REQUIRES(mutex)
         return;
     }
 
-    LIST_FOR_EACH (hw, h_entries, &lldp->lldpd->g_hardware.h_entries) {
+    LIST_FOR_EACH (hw, h_entries, &lldp->lldpd->g_hardware) {
         aa_print_element_status_port(ds, hw);
     }
 }
@@ -305,7 +305,7 @@ aa_print_isid_status(struct ds *ds, struct lldp *lldp) OVS_REQUIRES(mutex)
 
     ds_put_format(ds, "LLDP: %s\n", lldp->name);
 
-    LIST_FOR_EACH (hw, h_entries, &lldp->lldpd->g_hardware.h_entries) {
+    LIST_FOR_EACH (hw, h_entries, &lldp->lldpd->g_hardware) {
         aa_print_isid_status_port(lldp, hw);
     }
 
@@ -546,7 +546,7 @@ aa_mapping_register(void *aux, const struct aa_mapping_settings *s)
                     hash_pointer(m->aux, 0));
 
         /* Configure the mapping on each port of the LLDP stack. */
-        LIST_FOR_EACH (hw, h_entries, &lldp->lldpd->g_hardware.h_entries) {
+        LIST_FOR_EACH (hw, h_entries, &lldp->lldpd->g_hardware) {
             update_mapping_on_lldp(lldp, hw, m);
         }
     }
@@ -622,7 +622,7 @@ aa_mapping_unregister(void *aux)
             free(m);
 
             /* Remove from all the lldp instances */
-            LIST_FOR_EACH (hw, h_entries, &lldp->lldpd->g_hardware.h_entries) {
+            LIST_FOR_EACH (hw, h_entries, &lldp->lldpd->g_hardware) {
                 if (hw->h_ifname) {
                     VLOG_INFO("\t\t hardware->h_ifname=%s", hw->h_ifname);
                 }
@@ -672,11 +672,8 @@ void
 lldp_process_packet(struct lldp *lldp, const struct ofpbuf *p)
 {
     if (lldp) {
-        lldpd_recv(lldp->lldpd,
-                   (struct lldpd_hardware *)
-                       lldp->lldpd->g_hardware.h_entries.next,
-                   (char *) p->data_,
-                   p->size_);
+        lldpd_recv(lldp->lldpd, lldpd_first_hardware(lldp->lldpd),
+                   (char *) p->data_, p->size_);
     }
 }
 
@@ -730,8 +727,7 @@ lldp_put_packet(struct lldp *lldp, struct ofpbuf *packet,
                 uint8_t eth_src[ETH_ADDR_LEN]) OVS_EXCLUDED(mutex)
 {
     struct lldpd *mylldpd = lldp->lldpd;
-    struct lldpd_hardware *hw = (struct lldpd_hardware *)
-        mylldpd->g_hardware.h_entries.next;
+    struct lldpd_hardware *hw = lldpd_first_hardware(mylldpd);
     uint32_t lldp_size = 0;
     static const uint8_t eth_addr_lldp[6] =
         {0x01, 0x80, 0xC2, 0x00, 0x00, 0x0e};
@@ -838,8 +834,8 @@ lldp_create(const struct netdev *netdev,
     hw->h_lport.p_element.system_id.mlt_id[1] = 0;
 
     list_init(&hw->h_lport.p_isid_vlan_maps);
-    list_init(&lldp->lldpd->g_hardware.h_entries);
-    list_push_back(&lldp->lldpd->g_hardware.h_entries, &hw->h_entries);
+    list_init(&lldp->lldpd->g_hardware);
+    list_push_back(&lldp->lldpd->g_hardware, &hw->h_entries);
 
     ovs_mutex_lock(&mutex);
 
@@ -923,8 +919,8 @@ lldp_create_dummy(void)
     hw->h_lport.p_element.system_id.mlt_id[1] = 0;
 
     list_init(&hw->h_lport.p_isid_vlan_maps);
-    list_init(&lldp->lldpd->g_hardware.h_entries);
-    list_push_back(&lldp->lldpd->g_hardware.h_entries, &hw->h_entries);
+    list_init(&lldp->lldpd->g_hardware);
+    list_push_back(&lldp->lldpd->g_hardware, &hw->h_entries);
 
     return lldp;
 }
diff --git a/tests/test-aa.c b/tests/test-aa.c
index 95a5d0d..fc98b60 100644
--- a/tests/test-aa.c
+++ b/tests/test-aa.c
@@ -200,14 +200,13 @@ test_aa_send(void)
     lldp = lldp_create_dummy();
     if ((lldp == NULL) ||
         (lldp->lldpd == NULL) ||
-        (lldp->lldpd->g_hardware.h_entries.next == NULL)) {
-
+        list_is_empty(&lldp->lldpd->g_hardware)) {
         printf("Error: unable to create dummy lldp instance");
         return 1;
     }
 
     /* Populate instance with local chassis info */
-    hw = (struct lldpd_hardware *) lldp->lldpd->g_hardware.h_entries.next;
+    hw = lldpd_first_hardware(lldp->lldpd);
     ch = hw->h_lport.p_chassis;
     ch->c_id_subtype = chassis.c_id_subtype;
     ch->c_id = chassis.c_id;
-- 
2.1.3




More information about the dev mailing list