Allow configuring DSCP on controller and manager connections.
[sliver-openvswitch.git] / lib / netdev-linux.c
index d177d38..d2a5c7a 100644 (file)
@@ -26,7 +26,6 @@
 #include <linux/gen_stats.h>
 #include <linux/if_ether.h>
 #include <linux/if_tun.h>
-#include <linux/ip.h>
 #include <linux/types.h>
 #include <linux/ethtool.h>
 #include <linux/mii.h>
@@ -381,11 +380,12 @@ struct netdev_dev_linux {
     int ether_addr_error;       /* Cached error code from set/get etheraddr. */
     int netdev_policing_error;  /* Cached error code from set policing. */
     int get_features_error;     /* Cached error code from ETHTOOL_GSET. */
+    int get_ifindex_error;      /* Cached error code from SIOCGIFINDEX. */
 
-    uint32_t current;           /* Cached from ETHTOOL_GSET. */
-    uint32_t advertised;        /* Cached from ETHTOOL_GSET. */
-    uint32_t supported;         /* Cached from ETHTOOL_GSET. */
-    uint32_t peer;              /* Cached from ETHTOOL_GSET. */
+    enum netdev_features current;    /* Cached from ETHTOOL_GSET. */
+    enum netdev_features advertised; /* Cached from ETHTOOL_GSET. */
+    enum netdev_features supported;  /* Cached from ETHTOOL_GSET. */
+    enum netdev_features peer;       /* Cached from ETHTOOL_GSET. */
 
     struct ethtool_drvinfo drvinfo;  /* Cached from ETHTOOL_GDRVINFO. */
     struct tc *tc;
@@ -543,6 +543,7 @@ netdev_dev_linux_update(struct netdev_dev_linux *dev,
         /* Keep drv-info */
         netdev_dev_linux_changed(dev, change->ifi_flags, VALID_DRVINFO);
 
+        /* Update netdev from rtnl-change msg. */
         if (change->mtu) {
             dev->mtu = change->mtu;
             dev->cache_valid |= VALID_MTU;
@@ -555,6 +556,10 @@ netdev_dev_linux_update(struct netdev_dev_linux *dev,
             dev->ether_addr_error = 0;
         }
 
+        dev->ifindex = change->ifi_index;
+        dev->cache_valid |= VALID_IFINDEX;
+        dev->get_ifindex_error = 0;
+
     } else {
         netdev_dev_linux_changed(dev, change->ifi_flags, 0);
     }
@@ -1620,8 +1625,10 @@ out:
  * errno value. */
 static int
 netdev_linux_get_features(const struct netdev *netdev_,
-                          uint32_t *current, uint32_t *advertised,
-                          uint32_t *supported, uint32_t *peer)
+                          enum netdev_features *current,
+                          enum netdev_features *advertised,
+                          enum netdev_features *supported,
+                          enum netdev_features *peer)
 {
     struct netdev_dev_linux *netdev_dev =
                                 netdev_dev_linux_cast(netdev_get_dev(netdev_));
@@ -1994,7 +2001,7 @@ netdev_linux_dump_queues(const struct netdev *netdev,
 {
     struct netdev_dev_linux *netdev_dev =
                                 netdev_dev_linux_cast(netdev_get_dev(netdev));
-    struct tc_queue *queue;
+    struct tc_queue *queue, *next_queue;
     struct shash details;
     int last_error;
     int error;
@@ -2008,7 +2015,8 @@ netdev_linux_dump_queues(const struct netdev *netdev,
 
     last_error = 0;
     shash_init(&details);
-    HMAP_FOR_EACH (queue, hmap_node, &netdev_dev->tc->queues) {
+    HMAP_FOR_EACH_SAFE (queue, next_queue, hmap_node,
+                        &netdev_dev->tc->queues) {
         shash_clear(&details);
 
         error = netdev_dev->tc->ops->class_get(netdev, queue, &details);
@@ -2263,7 +2271,7 @@ netdev_linux_get_next_hop(const struct in_addr *host, struct in_addr *next_hop,
 }
 
 static int
-netdev_linux_get_status(const struct netdev *netdev, struct shash *sh)
+netdev_linux_get_drv_info(const struct netdev *netdev, struct shash *sh)
 {
     int error;
     struct netdev_dev_linux *netdev_dev =
@@ -2279,7 +2287,7 @@ netdev_linux_get_status(const struct netdev *netdev, struct shash *sh)
 }
 
 static int
-netdev_internal_get_status(const struct netdev *netdev OVS_UNUSED, struct shash *sh)
+netdev_internal_get_drv_info(const struct netdev *netdev OVS_UNUSED, struct shash *sh)
 {
     shash_add(sh, "driver_name", xstrdup("openvswitch"));
     return 0;
@@ -2439,7 +2447,7 @@ const struct netdev_class netdev_linux_class =
         netdev_linux_get_stats,
         NULL,                    /* set_stats */
         netdev_linux_get_features,
-        netdev_linux_get_status);
+        netdev_linux_get_drv_info);
 
 const struct netdev_class netdev_tap_class =
     NETDEV_LINUX_CLASS(
@@ -2448,7 +2456,7 @@ const struct netdev_class netdev_tap_class =
         netdev_tap_get_stats,
         NULL,                   /* set_stats */
         netdev_linux_get_features,
-        netdev_linux_get_status);
+        netdev_linux_get_drv_info);
 
 const struct netdev_class netdev_internal_class =
     NETDEV_LINUX_CLASS(
@@ -2457,7 +2465,7 @@ const struct netdev_class netdev_internal_class =
         netdev_internal_get_stats,
         netdev_vport_set_stats,
         NULL,                  /* get_features */
-        netdev_internal_get_status);
+        netdev_internal_get_drv_info);
 \f
 /* HTB traffic control class. */
 
@@ -2650,7 +2658,7 @@ htb_parse_qdisc_details__(struct netdev *netdev,
     max_rate_s = shash_find_data(details, "max-rate");
     hc->max_rate = max_rate_s ? strtoull(max_rate_s, NULL, 10) / 8 : 0;
     if (!hc->max_rate) {
-        uint32_t current;
+        enum netdev_features current;
 
         netdev_get_features(netdev, &current, NULL, NULL, NULL);
         hc->max_rate = netdev_features_to_bps(current) / 8;
@@ -3129,7 +3137,7 @@ hfsc_parse_qdisc_details__(struct netdev *netdev, const struct shash *details,
     max_rate   = max_rate_s ? strtoull(max_rate_s, NULL, 10) / 8 : 0;
 
     if (!max_rate) {
-        uint32_t current;
+        enum netdev_features current;
 
         netdev_get_features(netdev, &current, NULL, NULL, NULL);
         max_rate = netdev_features_to_bps(current) / 8;
@@ -4404,17 +4412,22 @@ get_ifindex(const struct netdev *netdev_, int *ifindexp)
 {
     struct netdev_dev_linux *netdev_dev =
                                 netdev_dev_linux_cast(netdev_get_dev(netdev_));
-    *ifindexp = 0;
+
     if (!(netdev_dev->cache_valid & VALID_IFINDEX)) {
         int ifindex = do_get_ifindex(netdev_get_name(netdev_));
+
         if (ifindex < 0) {
-            return -ifindex;
+            netdev_dev->get_ifindex_error = -ifindex;
+            netdev_dev->ifindex = 0;
+        } else {
+            netdev_dev->get_ifindex_error = 0;
+            netdev_dev->ifindex = ifindex;
         }
         netdev_dev->cache_valid |= VALID_IFINDEX;
-        netdev_dev->ifindex = ifindex;
     }
+
     *ifindexp = netdev_dev->ifindex;
-    return 0;
+    return netdev_dev->get_ifindex_error;
 }
 
 static int