[ovs-dev] [PATCH] netdev-linux: fix bug of ovs ingress policing with linux tc

ychen ychen103103 at 163.com
Thu Aug 20 03:29:07 UTC 2015


port's ingress qdisc rule will automatically disappeared after
the following steps:
1)use ip tuntap to create port tapA and tapB
2)set tapA and tapB to ingress qdisc with linux tc command
3)add tapA to ovs bridge
4)add tapB to the same ovs bridge(ingress rule disappear for tapA)
ingress_policing_rate equals to 0 means disable ingress policing,
so set flag VALID_POLICING only when this paramter is effective,
and before send deleteing ingress qdisc message to kernel, first check
whether need to do this action. if settings not changed or policing is not
enabled with ingress_policing_rate equal to 0, do not send any message.
when interface's MAC,MTU,link state changed, there will be a RTM_NETLINK 
message from kernel, and keep the flag VALID_POLICING as it is.


diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 0656f36..b219ba4 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -678,6 +678,8 @@ netdev_linux_update(struct netdev_linux *dev,
     OVS_REQUIRES(dev->mutex)
 {
     if (change->nlmsg_type == RTM_NEWLINK) {
+        int old_flag = dev->cache_valid;
+
         /* Keep drv-info */
         netdev_linux_changed(dev, change->ifi_flags, VALID_DRVINFO);


@@ -694,6 +696,10 @@ netdev_linux_update(struct netdev_linux *dev,
             dev->ether_addr_error = 0;
         }


+        if (old_flag & VALID_POLICING){
+            dev->cache_valid |= VALID_POLICING;
+        }
+
         dev->ifindex = change->ifi_index;
         dev->cache_valid |= VALID_IFINDEX;
         dev->get_ifindex_error = 0;
@@ -1974,13 +1980,14 @@ netdev_linux_set_policing(struct netdev *netdev_,
                    : kbits_burst);       /* Stick with user-specified value. */


     ovs_mutex_lock(&netdev->mutex);
-    if (netdev->cache_valid & VALID_POLICING) {
-        error = netdev->netdev_policing_error;
-        if (error || (netdev->kbits_rate == kbits_rate &&
-                      netdev->kbits_burst == kbits_burst)) {
-            /* Assume that settings haven't changed since we last set them. */
-            goto out;
-        }
+
+    error = netdev->netdev_policing_error;
+    if (error || (netdev->kbits_rate == kbits_rate &&
+                  netdev->kbits_burst == kbits_burst)) {
+        /* Assume that settings haven't changed since we last set them. */
+        goto out;
+    }
+    if (netdev->cache_valid & VALID_POLICING){
         netdev->cache_valid &= ~VALID_POLICING;
     }


@@ -2007,15 +2014,15 @@ netdev_linux_set_policing(struct netdev *netdev_,
                     netdev_name, ovs_strerror(error));
             goto out;
         }
-    }


-    netdev->kbits_rate = kbits_rate;
-    netdev->kbits_burst = kbits_burst;
+        netdev->kbits_rate = kbits_rate;
+        netdev->kbits_burst = kbits_burst;
+        netdev->cache_valid |= VALID_POLICING;
+    }


 out:
     if (!error || error == ENODEV) {
         netdev->netdev_policing_error = error;
-        netdev->cache_valid |= VALID_POLICING;
     }
     ovs_mutex_unlock(&netdev->mutex);
     return error;


More information about the dev mailing list