ofp-actions: Rename ofpact_update_len() to ofpact_finish().
[cascardo/ovs.git] / lib / ovs-lldp.c
index 61534a4..bd1729c 100644 (file)
@@ -391,9 +391,7 @@ update_mapping_on_lldp(struct lldp *lldp, struct lldpd_hardware *hardware,
 {
     struct lldpd_aa_isid_vlan_maps_tlv *lm = xzalloc(sizeof *lm);
 
-    if (hardware->h_ifname) {
-        VLOG_INFO("\t\t hardware->h_ifname=%s", hardware->h_ifname);
-    }
+    VLOG_INFO("\t\t hardware->h_ifname=%s", hardware->h_ifname);
 
     lm->isid_vlan_data.isid = m->isid;
     lm->isid_vlan_data.vlan = m->vlan;
@@ -619,16 +617,13 @@ aa_mapping_unregister(void *aux)
             }
 
             hmap_remove(&lldp->mappings_by_aux, &m->hmap_node_aux);
-            free(m);
 
             /* Remove from all the lldp instances */
             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);
-                }
-
+                VLOG_INFO("\t\t hardware->h_ifname=%s", hw->h_ifname);
                 aa_mapping_unregister_mapping(lldp, hw, m);
             }
+            free(m);
 
             /* Remove from the all_mappings */
             HMAP_FOR_EACH (m, hmap_node_isid, all_mappings) {
@@ -660,9 +655,9 @@ lldp_init(void)
  * fields in 'wc' that were used to make the determination.
  */
 bool
-lldp_should_process_flow(const struct flow *flow)
+lldp_should_process_flow(struct lldp *lldp, const struct flow *flow)
 {
-    return (flow->dl_type == htons(ETH_TYPE_LLDP));
+    return (flow->dl_type == htons(ETH_TYPE_LLDP) && lldp->enabled);
 }
 
 
@@ -689,6 +684,9 @@ lldp_should_send_packet(struct lldp *cfg) OVS_EXCLUDED(mutex)
     ret = timer_expired(&cfg->tx_timer);
     ovs_mutex_unlock(&mutex);
 
+    /* LLDP must be enabled */
+    ret &= cfg->enabled;
+
     return ret;
 }
 
@@ -699,7 +697,7 @@ lldp_wake_time(const struct lldp *lldp) OVS_EXCLUDED(mutex)
 {
     long long int retval;
 
-    if (!lldp) {
+    if (!lldp || !lldp->enabled) {
         return LLONG_MAX;
     }
 
@@ -724,12 +722,12 @@ lldp_wait(struct lldp *lldp) OVS_EXCLUDED(mutex)
  */
 void
 lldp_put_packet(struct lldp *lldp, struct dp_packet *packet,
-                uint8_t eth_src[ETH_ADDR_LEN]) OVS_EXCLUDED(mutex)
+                const struct eth_addr eth_src) OVS_EXCLUDED(mutex)
 {
     struct lldpd *mylldpd = lldp->lldpd;
     struct lldpd_hardware *hw = lldpd_first_hardware(mylldpd);
-    static const uint8_t eth_addr_lldp[6] =
-        {0x01, 0x80, 0xC2, 0x00, 0x00, 0x0e};
+    static const struct eth_addr eth_addr_lldp =
+        { { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x0e } } };
 
     ovs_mutex_lock(&mutex);
 
@@ -744,9 +742,15 @@ lldp_put_packet(struct lldp *lldp, struct dp_packet *packet,
 /* Configures the LLDP stack.
  */
 bool
-lldp_configure(struct lldp *lldp) OVS_EXCLUDED(mutex)
+lldp_configure(struct lldp *lldp, const struct smap *cfg) OVS_EXCLUDED(mutex)
 {
     if (lldp) {
+        if (cfg && smap_get_bool(cfg, "enable", false)) {
+            lldp->enabled = true;
+        } else {
+            lldp->enabled = false;
+        }
+
         ovs_mutex_lock(&mutex);
         timer_set_expired(&lldp->tx_timer);
         timer_set_duration(&lldp->tx_timer, LLDP_DEFAULT_TRANSMIT_INTERVAL_MS);
@@ -787,8 +791,10 @@ lldp_create(const struct netdev *netdev,
     lchassis->c_cap_enabled = LLDP_CAP_BRIDGE;
     lchassis->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
     lchassis->c_id_len = ETH_ADDR_LEN;
-    lchassis->c_id = xmalloc(ETH_ADDR_LEN);
-    netdev_get_etheraddr(netdev, lchassis->c_id);
+
+    struct eth_addr *mac = xmalloc(ETH_ADDR_LEN);
+    netdev_get_etheraddr(netdev, mac);
+    lchassis->c_id = &mac->ea[0];
 
     list_init(&lchassis->c_mgmt);
     lchassis->c_ttl = lldp->lldpd->g_config.c_tx_interval *