]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpcli: add "configure system hostname ." to use node name
authorVincent Bernat <vincent@bernat.im>
Sun, 13 Aug 2017 13:13:07 +0000 (15:13 +0200)
committerVincent Bernat <vincent@bernat.im>
Sun, 13 Aug 2017 13:13:07 +0000 (15:13 +0200)
This is a shortcut to "configure system hostname nodename". By default,
lldpd will use the FQDN (resolving the node name using the local
resolver). We let lldpcli interpret "." as a special request to override
this value with the node name (output of "uname -n").

Fix #154

NEWS
src/client/conf-system.c
src/client/lldpcli.8.in

diff --git a/NEWS b/NEWS
index 90ed7bddbb27e66022d2b1cbfe126bb240a567c4..223bc0eb875dcb90d88e124097348cfe86f1defe 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ lldpd (0.9.8)
       devices may still use the previous method.
     + Don't run ethtool as root. Kernels older than 2.6.19 won't get
       link information anymore.
+    + Add "configure system hostname ." option to not use a FQDN
+      for system name.
   * Fixes:
     + Handle team interfaces like a bond. Real MAC address cannot be
       retrieved yet.
index b403d46641fd07d3f6e67f65f97c933af24f6947..3d6e5ffdef393de98d62b5eaf6f6bfc5544462ed 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <unistd.h>
 #include <string.h>
+#include <sys/utsname.h>
 
 #include "client.h"
 #include "../log.h"
@@ -139,6 +140,7 @@ static int
 cmd_hostname(struct lldpctl_conn_t *conn, struct writer *w,
     struct cmd_env *env, void *arg)
 {
+       struct utsname un;
        log_debug("lldpctl", "set system name");
 
        lldpctl_atom_t *config = lldpctl_get_configuration(conn);
@@ -149,6 +151,13 @@ cmd_hostname(struct lldpctl_conn_t *conn, struct writer *w,
        }
 
        const char *value = cmdenv_get(env, "hostname");
+       if (value && strlen(value) == 1 && value[0] == '.') {
+               if (uname(&un) < 0) {
+                       log_warn("lldpctl", "cannot get node name");
+                       return 0;
+               }
+               value = un.nodename;
+       }
        if (lldpctl_atom_set_str(config,
                lldpctl_k_config_hostname, value) == NULL) {
                log_warnx("lldpctl", "unable to set system name. %s",
index 0d227482f5eb5e2108ab63a08178827473bec68b..5f064f03211eb5a666db0511b4cbbbccf0a30512 100644 (file)
@@ -186,8 +186,10 @@ update its information and send new LLDP PDU on all interfaces.
 .Cd system hostname Ar name
 .Bd -ragged -offset XXXXXX
 Override system hostname with the provided value. By default, the
-system name is found from the resolved value of
+system name is the FQDN found from the resolved value of
 .Ic uname -n .
+As a special value, use "." (dot) to use the short hostname instead of
+a FQDN.
 .Ed
 
 .Cd unconfigure