netdev: Fix carrier status for down interfaces.
[sliver-openvswitch.git] / lib / netdev-linux.c
index f7d9cd3..6fe8dcb 100644 (file)
@@ -1008,7 +1008,7 @@ netdev_linux_update_is_pseudo(struct netdev_dev_linux *netdev_dev)
     if (!(netdev_dev->cache_valid & VALID_IS_PSEUDO)) {
         const char *name = netdev_dev_get_name(&netdev_dev->netdev_dev);
         const char *type = netdev_dev_get_type(&netdev_dev->netdev_dev);
-        
+
         netdev_dev->is_tap = !strcmp(type, "tap");
         netdev_dev->is_internal = false;
         if (!netdev_dev->is_tap) {
@@ -1360,6 +1360,9 @@ netdev_linux_remove_policing(struct netdev *netdev)
     int error;
 
     tcmsg = tc_make_request(netdev, RTM_DELQDISC, 0, &request);
+    if (!tcmsg) {
+        return ENODEV;
+    }
     tcmsg->tcm_handle = tc_make_handle(0xffff, 0);
     tcmsg->tcm_parent = TC_H_INGRESS;
     nl_msg_put_string(&request, TCA_KIND, "ingress");
@@ -1617,16 +1620,20 @@ netdev_linux_get_queue_stats(const struct netdev *netdev,
     return netdev_dev->tc->ops->class_get_stats(netdev, queue_id, stats);
 }
 
-static void
+static bool
 start_queue_dump(const struct netdev *netdev, struct nl_dump *dump)
 {
     struct ofpbuf request;
     struct tcmsg *tcmsg;
 
     tcmsg = tc_make_request(netdev, RTM_GETTCLASS, 0, &request);
+    if (!tcmsg) {
+        return false;
+    }
     tcmsg->tcm_parent = 0;
     nl_dump_start(dump, rtnl_sock, &request);
     ofpbuf_uninit(&request);
+    return true;
 }
 
 static int
@@ -1684,7 +1691,9 @@ netdev_linux_dump_queue_stats(const struct netdev *netdev,
     }
 
     last_error = 0;
-    start_queue_dump(netdev, &dump);
+    if (!start_queue_dump(netdev, &dump)) {
+        return ENODEV;
+    }
     while (nl_dump_next(&dump, &msg)) {
         error = netdev_dev->tc->ops->class_dump_stats(netdev, &msg, cb, aux);
         if (error) {
@@ -1872,7 +1881,7 @@ netdev_linux_get_next_hop(const struct in_addr *host, struct in_addr *next_hop,
                        iface, &dest, &gateway, &flags, &refcnt,
                        &use, &metric, &mask, &mtu, &window, &irtt) != 11) {
 
-                VLOG_WARN_RL(&rl, "%s: could not parse line %d: %s", 
+                VLOG_WARN_RL(&rl, "%s: could not parse line %d: %s",
                         fn, ln, line);
                 continue;
             }
@@ -1882,7 +1891,7 @@ netdev_linux_get_next_hop(const struct in_addr *host, struct in_addr *next_hop,
             }
 
             /* The output of 'dest', 'mask', and 'gateway' were given in
-             * network byte order, so we don't need need any endian 
+             * network byte order, so we don't need need any endian
              * conversions here. */
             if ((dest & mask) == (host->s_addr & mask)) {
                 if (!gateway) {
@@ -2237,6 +2246,9 @@ htb_setup_qdisc__(struct netdev *netdev)
 
     tcmsg = tc_make_request(netdev, RTM_NEWQDISC,
                             NLM_F_EXCL | NLM_F_CREATE, &request);
+    if (!tcmsg) {
+        return ENODEV;
+    }
     tcmsg->tcm_handle = tc_make_handle(1, 0);
     tcmsg->tcm_parent = TC_H_ROOT;
 
@@ -2277,6 +2289,9 @@ htb_setup_class__(struct netdev *netdev, unsigned int handle,
     opt.prio = class->priority;
 
     tcmsg = tc_make_request(netdev, RTM_NEWTCLASS, NLM_F_CREATE, &request);
+    if (!tcmsg) {
+        return ENODEV;
+    }
     tcmsg->tcm_handle = handle;
     tcmsg->tcm_parent = parent;
 
@@ -2384,13 +2399,13 @@ htb_parse_class_details__(struct netdev *netdev,
     const char *priority_s = shash_find_data(details, "priority");
     int mtu;
 
-    /* min-rate */
+    /* min-rate.  Don't allow a min-rate below 1500 bytes/s. */
     if (!min_rate_s) {
         /* min-rate is required. */
         return EINVAL;
     }
     hc->min_rate = strtoull(min_rate_s, NULL, 10) / 8;
-    hc->min_rate = MAX(hc->min_rate, 0);
+    hc->min_rate = MAX(hc->min_rate, 1500);
     hc->min_rate = MIN(hc->min_rate, htb->max_rate);
 
     /* max-rate */
@@ -2484,7 +2499,9 @@ htb_tc_load(struct netdev *netdev, struct ofpbuf *nlmsg OVS_UNUSED)
     htb = htb_install__(netdev, hc.max_rate);
 
     /* Get queues. */
-    start_queue_dump(netdev, &dump);
+    if (!start_queue_dump(netdev, &dump)) {
+        return ENODEV;
+    }
     shash_init(&details);
     while (nl_dump_next(&dump, &msg)) {
         unsigned int queue_id;
@@ -2621,7 +2638,7 @@ htb_class_dump_stats(const struct netdev *netdev OVS_UNUSED,
     major = tc_get_major(handle);
     minor = tc_get_minor(handle);
     if (major == 1 && minor > 0 && minor <= HTB_N_QUEUES) {
-        (*cb)(tc_get_minor(handle), &stats, aux);
+        (*cb)(minor - 1, &stats, aux);
     }
     return 0;
 }
@@ -2898,7 +2915,7 @@ tc_bytes_to_ticks(unsigned int rate, unsigned int size)
     if (!buffer_hz) {
         read_psched();
     }
-    return ((unsigned long long int) ticks_per_s * size) / rate;
+    return rate ? ((unsigned long long int) ticks_per_s * size) / rate : 0;
 }
 
 /* Returns the number of bytes that need to be reserved for qdisc buffering at
@@ -3044,6 +3061,9 @@ tc_query_class(const struct netdev *netdev,
     int error;
 
     tcmsg = tc_make_request(netdev, RTM_GETTCLASS, NLM_F_ECHO, &request);
+    if (!tcmsg) {
+        return ENODEV;
+    }
     tcmsg->tcm_handle = handle;
     tcmsg->tcm_parent = parent;
 
@@ -3067,6 +3087,9 @@ tc_delete_class(const struct netdev *netdev, unsigned int handle)
     int error;
 
     tcmsg = tc_make_request(netdev, RTM_DELTCLASS, 0, &request);
+    if (!tcmsg) {
+        return ENODEV;
+    }
     tcmsg->tcm_handle = handle;
     tcmsg->tcm_parent = 0;
 
@@ -3091,6 +3114,9 @@ tc_del_qdisc(struct netdev *netdev)
     int error;
 
     tcmsg = tc_make_request(netdev, RTM_DELQDISC, 0, &request);
+    if (!tcmsg) {
+        return ENODEV;
+    }
     tcmsg->tcm_handle = tc_make_handle(1, 0);
     tcmsg->tcm_parent = TC_H_ROOT;
 
@@ -3142,6 +3168,9 @@ tc_query_qdisc(const struct netdev *netdev)
      * We could check for Linux 2.6.35+ and use a more straightforward method
      * there. */
     tcmsg = tc_make_request(netdev, RTM_GETQDISC, NLM_F_ECHO, &request);
+    if (!tcmsg) {
+        return ENODEV;
+    }
     tcmsg->tcm_handle = tc_make_handle(1, 0);
     tcmsg->tcm_parent = 0;
 
@@ -3244,9 +3273,7 @@ tc_put_rtab(struct ofpbuf *msg, uint16_t type, const struct tc_ratespec *rate)
 /* Calculates the proper value of 'buffer' or 'cbuffer' in HTB options given a
  * rate of 'Bps' bytes per second, the specified 'mtu', and a user-requested
  * burst size of 'burst_bytes'.  (If no value was requested, a 'burst_bytes' of
- * 0 is fine.)
- *
- * This */
+ * 0 is fine.) */
 static int
 tc_calc_buffer(unsigned int Bps, int mtu, uint64_t burst_bytes)
 {