[ovs-dev] [PATCH] bridge: New appctl command iface/set-admin-state.
Ethan Jackson
ethan at nicira.com
Fri Aug 10 01:21:43 UTC 2012
There's currently no way to set the admin state on dummy netdevs.
This patch provides a mechanism to do so that generalizes to all
netdevs cleanly.
Signed-off-by: Ethan Jackson <ethan at nicira.com>
---
vswitchd/bridge.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 2c1142b..69304bb 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -177,6 +177,8 @@ static void bridge_destroy(struct bridge *);
static struct bridge *bridge_lookup(const char *name);
static unixctl_cb_func bridge_unixctl_dump_flows;
static unixctl_cb_func bridge_unixctl_reconnect;
+static unixctl_cb_func iface_unixctl_set_admin_state;
+
static size_t bridge_get_controllers(const struct bridge *br,
struct ovsrec_controller ***controllersp);
static void bridge_add_del_ports(struct bridge *,
@@ -345,6 +347,9 @@ bridge_init(const char *remote)
bridge_unixctl_dump_flows, NULL);
unixctl_command_register("bridge/reconnect", "[bridge]", 0, 1,
bridge_unixctl_reconnect, NULL);
+ unixctl_command_register("iface/set-admin-state", "[iface] up|down", 1, 2,
+ iface_unixctl_set_admin_state, NULL);
+
lacp_init();
bond_init();
cfm_init();
@@ -2442,6 +2447,54 @@ bridge_unixctl_reconnect(struct unixctl_conn *conn, int argc,
unixctl_command_reply(conn, NULL);
}
+static void
+iface_set_admin_state(struct iface *iface, bool up)
+{
+ if (up) {
+ netdev_turn_flags_on(iface->netdev, NETDEV_UP, true);
+ } else {
+ netdev_turn_flags_off(iface->netdev, NETDEV_UP, true);
+ }
+}
+
+static void
+iface_unixctl_set_admin_state(struct unixctl_conn *conn, int argc,
+ const char *argv[], void *aux OVS_UNUSED)
+{
+ bool up;
+
+ if (!strcasecmp(argv[argc - 1] , "up")) {
+ up = true;
+ } else if ( !strcasecmp(argv[argc - 1] , "down")) {
+ up = false;
+ } else {
+ unixctl_command_reply_error(conn, "Invalid Admin State");
+ return;
+ }
+
+ if (argc > 2) {
+ struct iface *iface = iface_find(argv[1]);
+
+ if (iface) {
+ iface_set_admin_state(iface, up);
+ } else {
+ unixctl_command_reply_error(conn, "Unknown Interface");
+ return;
+ }
+ } else {
+ struct bridge *br;
+
+ HMAP_FOR_EACH (br, node, &all_bridges) {
+ struct iface *iface;
+
+ HMAP_FOR_EACH (iface, name_node, &br->iface_by_name) {
+ iface_set_admin_state(iface, up);
+ }
+ }
+ }
+ unixctl_command_reply(conn, "OK");
+}
+
static size_t
bridge_get_controllers(const struct bridge *br,
struct ovsrec_controller ***controllersp)
--
1.7.11.4
More information about the dev
mailing list