summaryrefslogtreecommitdiff
path: root/lib/netdev-linux.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2010-05-03 15:31:38 -0700
committerBen Pfaff <blp@nicira.com>2010-05-05 14:00:50 -0700
commit8e46022197dd9f04a3e73f741482d98972f6b70a (patch)
tree80e4c1b91b214366fdb2f6e0290bcaa953a8dc30 /lib/netdev-linux.c
parenta5af30fbaa19b78ecd236f0549379a141032119b (diff)
downloadopenvswitch-8e46022197dd9f04a3e73f741482d98972f6b70a.tar.gz
netdev-linux: Factor out removing policing.
This is duplicated code that the following commit will rewrite.
Diffstat (limited to 'lib/netdev-linux.c')
-rw-r--r--lib/netdev-linux.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index abd905c3c..c44d6baf6 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -1280,6 +1280,24 @@ done:
*/
#define POLICE_DEL_CMD "/sbin/tc qdisc del dev %s handle ffff: ingress 2>/dev/null"
+/* Remove ingress policing from 'netdev'. Returns 0 if successful, otherwise a
+ * positive errno value. */
+static int
+netdev_linux_remove_policing(struct netdev *netdev)
+{
+ const char *netdev_name = netdev_get_name(netdev);
+ char command[1024];
+
+ /* xxx This should be more careful about only adding if it
+ * xxx actually exists, as opposed to always deleting it. */
+ snprintf(command, sizeof(command), POLICE_DEL_CMD, netdev_name);
+ if (system(command) == -1) {
+ VLOG_WARN_RL(&rl, "%s: problem removing policing", netdev_name);
+ return ECHILD;
+ }
+ return 0;
+}
+
/* Attempts to set input rate limiting (policing) policy. */
static int
netdev_linux_set_policing(struct netdev *netdev,
@@ -1289,19 +1307,14 @@ netdev_linux_set_policing(struct netdev *netdev,
char command[1024];
COVERAGE_INC(netdev_set_policing);
+
+ netdev_linux_remove_policing(netdev);
if (kbits_rate) {
if (!kbits_burst) {
/* Default to 1000 kilobits if not specified. */
kbits_burst = 1000;
}
- /* xxx This should be more careful about only adding if it
- * xxx actually exists, as opposed to always deleting it. */
- snprintf(command, sizeof(command), POLICE_DEL_CMD, netdev_name);
- if (system(command) == -1) {
- VLOG_WARN_RL(&rl, "%s: problem removing policing", netdev_name);
- }
-
snprintf(command, sizeof(command), POLICE_ADD_CMD, netdev_name);
if (system(command) != 0) {
VLOG_WARN_RL(&rl, "%s: problem adding policing", netdev_name);
@@ -1315,11 +1328,6 @@ netdev_linux_set_policing(struct netdev *netdev,
netdev_name);
return -1;
}
- } else {
- snprintf(command, sizeof(command), POLICE_DEL_CMD, netdev_name);
- if (system(command) == -1) {
- VLOG_WARN_RL(&rl, "%s: problem removing policing", netdev_name);
- }
}
return 0;