lib: Move compiler.h to <openvswitch/compiler.h>
[cascardo/ovs.git] / vtep / vtep-ctl.c
index 25470ff..b7a6d2c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -115,19 +115,16 @@ static int timeout;
 /* Format for table output. */
 static struct table_style table_style = TABLE_STYLE_DEFAULT;
 
-/* All supported commands. */
-static const struct vtep_ctl_command_syntax all_commands[];
-
 /* The IDL we're using and the current transaction, if any.
  * This is for use by vtep_ctl_exit() only, to allow it to clean up.
  * Other code should use its context arguments. */
 static struct ovsdb_idl *the_idl;
 static struct ovsdb_idl_txn *the_idl_txn;
 
-static void vtep_ctl_exit(int status) NO_RETURN;
-static void vtep_ctl_fatal(const char *, ...) PRINTF_FORMAT(1, 2) NO_RETURN;
+OVS_NO_RETURN static void vtep_ctl_exit(int status);
+OVS_NO_RETURN static void vtep_ctl_fatal(const char *, ...) OVS_PRINTF_FORMAT(1, 2);
 static char *default_db(void);
-static void usage(void) NO_RETURN;
+OVS_NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[], struct shash *local_options);
 static bool might_write_to_db(char **argv);
 
@@ -155,6 +152,7 @@ static bool is_condition_satisfied(const struct vtep_ctl_table_class *,
 static struct vtep_ctl_lswitch *find_lswitch(struct vtep_ctl_context *,
                                              const char *name,
                                              bool must_exist);
+static const struct vtep_ctl_command_syntax *get_all_commands(void);
 
 int
 main(int argc, char *argv[])
@@ -285,7 +283,7 @@ parse_options(int argc, char *argv[], struct shash *local_options)
     options = xmemdup(global_long_options, sizeof global_long_options);
     allocated_options = ARRAY_SIZE(global_long_options);
     n_options = n_global_long_options;
-    for (p = all_commands; p->name; p++) {
+    for (p = get_all_commands(); p->name; p++) {
         if (p->options[0]) {
             char *save_ptr = NULL;
             char *name;
@@ -544,7 +542,7 @@ find_command(const char *name)
     if (shash_is_empty(&commands)) {
         const struct vtep_ctl_command_syntax *p;
 
-        for (p = all_commands; p->name; p++) {
+        for (p = get_all_commands(); p->name; p++) {
             shash_add_assert(&commands, p->name, p);
         }
     }
@@ -1078,6 +1076,7 @@ pre_get_info(struct vtep_ctl_context *ctx)
 
     ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_name);
     ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_ports);
+    ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_tunnels);
 
     ovsdb_idl_add_column(ctx->idl, &vteprec_physical_port_col_name);
     ovsdb_idl_add_column(ctx->idl, &vteprec_physical_port_col_vlan_bindings);
@@ -1113,6 +1112,9 @@ pre_get_info(struct vtep_ctl_context *ctx)
                          &vteprec_physical_locator_col_dst_ip);
     ovsdb_idl_add_column(ctx->idl,
                          &vteprec_physical_locator_col_encapsulation_type);
+
+    ovsdb_idl_add_column(ctx->idl, &vteprec_tunnel_col_local);
+    ovsdb_idl_add_column(ctx->idl, &vteprec_tunnel_col_remote);
 }
 
 static void
@@ -1124,6 +1126,7 @@ vtep_ctl_context_populate_cache(struct vtep_ctl_context *ctx)
     const struct vteprec_ucast_macs_remote *ucast_remote_cfg;
     const struct vteprec_mcast_macs_local *mcast_local_cfg;
     const struct vteprec_mcast_macs_remote *mcast_remote_cfg;
+    const struct vteprec_tunnel *tunnel_cfg;
     struct sset pswitches, ports, lswitches;
     size_t i;
 
@@ -1249,6 +1252,15 @@ vtep_ctl_context_populate_cache(struct vtep_ctl_context *ctx)
         mcast_mac->remote_cfg = mcast_remote_cfg;
     }
 
+    VTEPREC_TUNNEL_FOR_EACH (tunnel_cfg, ctx->idl) {
+        if (tunnel_cfg->local) {
+            add_ploc_to_cache(ctx, tunnel_cfg->local);
+        }
+        if (tunnel_cfg->remote) {
+            add_ploc_to_cache(ctx, tunnel_cfg->remote);
+        }
+    }
+
     sset_init(&pswitches);
     for (i = 0; i < vtep_global->n_switches; i++) {
         struct vteprec_physical_switch *ps_cfg = vtep_global->switches[i];
@@ -2285,6 +2297,10 @@ static const struct vtep_ctl_table_class tables[] = {
      {{&vteprec_table_physical_switch, &vteprec_physical_switch_col_name, NULL},
       {NULL, NULL, NULL}}},
 
+    {&vteprec_table_tunnel,
+     {{NULL, NULL, NULL},
+      {NULL, NULL, NULL}}},
+
     {NULL, {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}
 };
 
@@ -2570,7 +2586,7 @@ missing_operator_error(const char *arg, const char **allowed_operators,
  *
  * On success, returns NULL.  On failure, returned a malloc()'d string error
  * message and stores NULL into all of the nonnull output arguments. */
-static char * WARN_UNUSED_RESULT
+static char * OVS_WARN_UNUSED_RESULT
 parse_column_key_value(const char *arg,
                        const struct vtep_ctl_table_class *table,
                        const struct ovsdb_idl_column **columnp, char **keyp,
@@ -3201,11 +3217,11 @@ cmd_remove(struct vtep_ctl_context *ctx)
         error = ovsdb_datum_from_string(&rm, &rm_type,
                                         ctx->argv[i], ctx->symtab);
         if (error && ovsdb_type_is_map(&rm_type)) {
-            free(error);
             rm_type.value.type = OVSDB_TYPE_VOID;
             die_if_error(ovsdb_datum_from_string(&rm, &rm_type,
                                                  ctx->argv[i], ctx->symtab));
         }
+        free(error);
         ovsdb_datum_subtract(&old, type, &rm, &rm_type);
         ovsdb_datum_destroy(&rm, &rm_type);
     }
@@ -3890,3 +3906,8 @@ static const struct vtep_ctl_command_syntax all_commands[] = {
     {NULL, 0, 0, NULL, NULL, NULL, NULL, RO},
 };
 
+static const struct vtep_ctl_command_syntax *
+get_all_commands(void)
+{
+    return all_commands;
+}