]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpcli: split `conf.c` into `conf-system.c` and `conf-lldp.c`.
authorVincent Bernat <bernat@luffy.cx>
Thu, 20 Jun 2013 23:01:46 +0000 (01:01 +0200)
committerVincent Bernat <bernat@luffy.cx>
Thu, 20 Jun 2013 23:01:46 +0000 (01:01 +0200)
src/client/Makefile.am
src/client/client.h
src/client/conf-lldp.c [new file with mode: 0644]
src/client/conf-system.c [new file with mode: 0644]
src/client/conf.c

index 44b6fefeb0ebb819fb560ab6af525645bb35d203..371d5b50f662d718c4fa6a22f3fc384410300c76 100644 (file)
@@ -11,6 +11,7 @@ uninstall-local:
 
 lldpcli_SOURCES  = client.h lldpcli.c display.c \
        conf.c conf-med.c conf-dot3.c conf-power.c \
+       conf-lldp.c conf-system.c \
        commands.c show.c \
        misc.c tokenizer.c \
        writer.h text_writer.c kv_writer.c
index 1b460d358ca588ca29bfa41c2146f38687a0db90..a2de319250f0e4fd6a2fa800ba3170402155c420 100644 (file)
@@ -124,6 +124,8 @@ void register_commands_watch(struct cmd_node *);
 
 /* conf*.c */
 void register_commands_configure(struct cmd_node *);
+void register_commands_configure_system(struct cmd_node *);
+void register_commands_configure_lldp(struct cmd_node *);
 void register_commands_configure_med(struct cmd_node *, struct cmd_node *);
 void register_commands_configure_dot3(struct cmd_node *);
 void register_commands_medpow(struct cmd_node *);
diff --git a/src/client/conf-lldp.c b/src/client/conf-lldp.c
new file mode 100644 (file)
index 0000000..e5389ad
--- /dev/null
@@ -0,0 +1,105 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2013 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <unistd.h>
+#include <string.h>
+
+#include "client.h"
+#include "../log.h"
+
+static int
+cmd_txdelay(struct lldpctl_conn_t *conn, struct writer *w,
+    struct cmd_env *env, void *arg)
+{
+       log_debug("lldpctl", "set transmit delay");
+
+       lldpctl_atom_t *config = lldpctl_get_configuration(conn);
+       if (config == NULL) {
+               log_warnx("lldpctl", "unable to get configuration from lldpd. %s",
+                   lldpctl_last_strerror(conn));
+               return 0;
+       }
+       if (lldpctl_atom_set_str(config,
+               lldpctl_k_config_tx_interval, cmdenv_get(env, "tx-interval")) == NULL) {
+               log_warnx("lldpctl", "unable to set transmit delay. %s",
+                   lldpctl_last_strerror(conn));
+               lldpctl_atom_dec_ref(config);
+               return 0;
+       }
+       log_info("lldpctl", "transmit delay set to new value");
+       lldpctl_atom_dec_ref(config);
+       return 1;
+}
+
+static int
+cmd_txhold(struct lldpctl_conn_t *conn, struct writer *w,
+    struct cmd_env *env, void *arg)
+{
+       log_debug("lldpctl", "set transmit hold");
+
+       lldpctl_atom_t *config = lldpctl_get_configuration(conn);
+       if (config == NULL) {
+               log_warnx("lldpctl", "unable to get configuration from lldpd. %s",
+                   lldpctl_last_strerror(conn));
+               return 0;
+       }
+       if (lldpctl_atom_set_str(config,
+               lldpctl_k_config_tx_hold, cmdenv_get(env, "tx-hold")) == NULL) {
+               log_warnx("lldpctl", "unable to set transmit hold. %s",
+                   lldpctl_last_strerror(conn));
+               lldpctl_atom_dec_ref(config);
+               return 0;
+       }
+       log_info("lldpctl", "transmit hold set to new value %s", cmdenv_get(env, "tx-hold"));
+       lldpctl_atom_dec_ref(config);
+       return 1;
+}
+
+/**
+ * Register `configure lldp` commands.
+ *
+ * Those are the commands that are related to the LLDP protocol but not
+ * Dot1/Dot3/MED. Commands not related to LLDP should go in system instead.
+ */
+void
+register_commands_configure_lldp(struct cmd_node *configure)
+{
+       struct cmd_node *configure_lldp = commands_new(
+               configure,
+               "lldp", "LLDP configuration",
+               NULL, NULL, NULL);
+
+        commands_new(
+               commands_new(
+                       commands_new(configure_lldp,
+                           "tx-interval", "Set LLDP transmit delay",
+                           cmd_check_no_env, NULL, "ports"),
+                       NULL, "LLDP transmit delay in seconds",
+                       NULL, cmd_store_env_value, "tx-interval"),
+               NEWLINE, "Set LLDP transmit delay",
+               NULL, cmd_txdelay, NULL);
+
+        commands_new(
+               commands_new(
+                       commands_new(configure_lldp,
+                           "tx-hold", "Set LLDP transmit hold",
+                           cmd_check_no_env, NULL, "ports"),
+                       NULL, "LLDP transmit hold in seconds",
+                       NULL, cmd_store_env_value, "tx-hold"),
+               NEWLINE, "Set LLDP transmit hold",
+               NULL, cmd_txhold, NULL);
+}
diff --git a/src/client/conf-system.c b/src/client/conf-system.c
new file mode 100644 (file)
index 0000000..4972800
--- /dev/null
@@ -0,0 +1,74 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2013 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <unistd.h>
+#include <string.h>
+
+#include "client.h"
+#include "../log.h"
+
+static int
+cmd_iface_pattern(struct lldpctl_conn_t *conn, struct writer *w,
+    struct cmd_env *env, void *arg)
+{
+       log_debug("lldpctl", "set iface pattern");
+
+       lldpctl_atom_t *config = lldpctl_get_configuration(conn);
+       if (config == NULL) {
+               log_warnx("lldpctl", "unable to get configuration from lldpd. %s",
+                   lldpctl_last_strerror(conn));
+               return 0;
+       }
+       if (lldpctl_atom_set_str(config,
+               lldpctl_k_config_iface_pattern, cmdenv_get(env, "iface-pattern")) == NULL) {
+               log_warnx("lldpctl", "unable to set iface-pattern. %s",
+                   lldpctl_last_strerror(conn));
+               lldpctl_atom_dec_ref(config);
+               return 0;
+       }
+       log_info("lldpctl", "iface-pattern set to new value %s", cmdenv_get(env, "iface-pattern"));
+       lldpctl_atom_dec_ref(config);
+       return 1;
+}
+
+/**
+ * Register `configure system` commands.
+ *
+ * Those are the commands to configure protocol-independant stuff.
+ */
+void
+register_commands_configure_system(struct cmd_node *configure)
+{
+       struct cmd_node *configure_system = commands_new(
+               configure,
+               "system", "System configuration",
+               cmd_check_no_env, NULL, "ports");
+       struct cmd_node *configure_interface = commands_new(
+               configure_system,
+               "interface", "Configure interface related items",
+               NULL, NULL, NULL);
+
+        commands_new(
+               commands_new(
+                       commands_new(configure_interface,
+                           "pattern", "Set active interface pattern",
+                           NULL, NULL, NULL),
+                       NULL, "Interface pattern (comma separated list of wildcards)",
+                       NULL, cmd_store_env_value, "iface-pattern"),
+               NEWLINE, "Set active interface pattern",
+               NULL, cmd_iface_pattern, NULL);
+}
index f11324d45414e9794ad1ef90c9377298a3ed93a6..7b8e68acdba501b2badce6ba8d5c240982ae7628 100644 (file)
 #include "client.h"
 #include "../log.h"
 
-static int
-cmd_txdelay(struct lldpctl_conn_t *conn, struct writer *w,
-    struct cmd_env *env, void *arg)
-{
-       log_debug("lldpctl", "set transmit delay");
-
-       lldpctl_atom_t *config = lldpctl_get_configuration(conn);
-       if (config == NULL) {
-               log_warnx("lldpctl", "unable to get configuration from lldpd. %s",
-                   lldpctl_last_strerror(conn));
-               return 0;
-       }
-       if (lldpctl_atom_set_str(config,
-               lldpctl_k_config_tx_interval, cmdenv_get(env, "tx-interval")) == NULL) {
-               log_warnx("lldpctl", "unable to set transmit delay. %s",
-                   lldpctl_last_strerror(conn));
-               lldpctl_atom_dec_ref(config);
-               return 0;
-       }
-       log_info("lldpctl", "transmit delay set to new value");
-       lldpctl_atom_dec_ref(config);
-       return 1;
-}
-
-static int
-cmd_txhold(struct lldpctl_conn_t *conn, struct writer *w,
-    struct cmd_env *env, void *arg)
-{
-       log_debug("lldpctl", "set transmit hold");
-
-       lldpctl_atom_t *config = lldpctl_get_configuration(conn);
-       if (config == NULL) {
-               log_warnx("lldpctl", "unable to get configuration from lldpd. %s",
-                   lldpctl_last_strerror(conn));
-               return 0;
-       }
-       if (lldpctl_atom_set_str(config,
-               lldpctl_k_config_tx_hold, cmdenv_get(env, "tx-hold")) == NULL) {
-               log_warnx("lldpctl", "unable to set transmit hold. %s",
-                   lldpctl_last_strerror(conn));
-               lldpctl_atom_dec_ref(config);
-               return 0;
-       }
-       log_info("lldpctl", "transmit hold set to new value %s", cmdenv_get(env, "tx-hold"));
-       lldpctl_atom_dec_ref(config);
-       return 1;
-}
-
-static int
-cmd_iface_pattern(struct lldpctl_conn_t *conn, struct writer *w,
-    struct cmd_env *env, void *arg)
-{
-       log_debug("lldpctl", "set iface pattern");
-
-       lldpctl_atom_t *config = lldpctl_get_configuration(conn);
-       if (config == NULL) {
-               log_warnx("lldpctl", "unable to get configuration from lldpd. %s",
-                   lldpctl_last_strerror(conn));
-               return 0;
-       }
-       if (lldpctl_atom_set_str(config,
-               lldpctl_k_config_iface_pattern, cmdenv_get(env, "iface-pattern")) == NULL) {
-               log_warnx("lldpctl", "unable to set iface-pattern. %s",
-                   lldpctl_last_strerror(conn));
-               lldpctl_atom_dec_ref(config);
-               return 0;
-       }
-       log_info("lldpctl", "iface-pattern set to new value %s", cmdenv_get(env, "iface-pattern"));
-       lldpctl_atom_dec_ref(config);
-       return 1;
-}
-
-/**
- * Register `configure system` commands.
- *
- * Those are the commands to configure protocol-independant stuff.
- */
-static void
-register_commands_configure_system(struct cmd_node *configure)
-{
-       struct cmd_node *configure_system = commands_new(
-               configure,
-               "system", "System configuration",
-               cmd_check_no_env, NULL, "ports");
-       struct cmd_node *configure_interface = commands_new(
-               configure_system,
-               "interface", "Configure interface related items",
-               NULL, NULL, NULL);
-
-        commands_new(
-               commands_new(
-                       commands_new(configure_interface,
-                           "pattern", "Set active interface pattern",
-                           NULL, NULL, NULL),
-                       NULL, "Interface pattern (comma separated list of wildcards)",
-                       NULL, cmd_store_env_value, "iface-pattern"),
-               NEWLINE, "Set active interface pattern",
-               NULL, cmd_iface_pattern, NULL);
-}
-
-/**
- * Register `configure lldp` commands.
- *
- * Those are the commands that are related to the LLDP protocol but not
- * Dot1/Dot3/MED. Commands not related to LLDP should go in system instead.
- */
-static void
-register_commands_configure_lldp(struct cmd_node *configure)
-{
-       struct cmd_node *configure_lldp = commands_new(
-               configure,
-               "lldp", "LLDP configuration",
-               NULL, NULL, NULL);
-
-        commands_new(
-               commands_new(
-                       commands_new(configure_lldp,
-                           "tx-interval", "Set LLDP transmit delay",
-                           cmd_check_no_env, NULL, "ports"),
-                       NULL, "LLDP transmit delay in seconds",
-                       NULL, cmd_store_env_value, "tx-interval"),
-               NEWLINE, "Set LLDP transmit delay",
-               NULL, cmd_txdelay, NULL);
-
-        commands_new(
-               commands_new(
-                       commands_new(configure_lldp,
-                           "tx-hold", "Set LLDP transmit hold",
-                           cmd_check_no_env, NULL, "ports"),
-                       NULL, "LLDP transmit hold in seconds",
-                       NULL, cmd_store_env_value, "tx-hold"),
-               NEWLINE, "Set LLDP transmit hold",
-               NULL, cmd_txhold, NULL);
-}
-
 /**
  * Register `configure` and `no configure` commands.
  */