From a9d00cbdfff465f20be3a6bc5b2f16fec5a91b71 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 13 Aug 2017 15:13:07 +0200 Subject: [PATCH] lldpcli: add "configure system hostname ." to use node name 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 | 2 ++ src/client/conf-system.c | 9 +++++++++ src/client/lldpcli.8.in | 4 +++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 90ed7bdd..223bc0eb 100644 --- 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. diff --git a/src/client/conf-system.c b/src/client/conf-system.c index b403d466..3d6e5ffd 100644 --- a/src/client/conf-system.c +++ b/src/client/conf-system.c @@ -17,6 +17,7 @@ #include #include +#include #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", diff --git a/src/client/lldpcli.8.in b/src/client/lldpcli.8.in index 0d227482..5f064f03 100644 --- a/src/client/lldpcli.8.in +++ b/src/client/lldpcli.8.in @@ -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 -- 2.39.5