Skip to content

Commit 041c807

Browse files
mrfuchsjukkar
authored andcommitted
net: hostname: Update unique hostname on link address change
Add Kconfig option NET_HOSTNAME_UNIQUE_UPDATE to allow the unique hostname - which is derived from the network interface's link address - to be updated on both initial assignment and updates of the link address. Signed-off-by: Markus Fuchs <[email protected]>
1 parent dafe376 commit 041c807

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

subsys/net/Kconfig.hostname

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ config NET_HOSTNAME_UNIQUE
2424
hostname. For example, zephyr00005e005357 could be the hostname
2525
if this setting is enabled.
2626

27+
config NET_HOSTNAME_UNIQUE_UPDATE
28+
bool "Update unique hostname"
29+
depends on NET_HOSTNAME_UNIQUE
30+
help
31+
This will update the unique hostname on link address changes. By
32+
default, this option is disabled, which means the unique hostname
33+
is set once at start-up and is not updated afterwards.
34+
2735
module = NET_HOSTNAME
2836
module-dep = NET_LOG
2937
module-str = Log level for hostname configuration

subsys/net/hostname.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ const char *net_hostname_get(void)
2727
int net_hostname_set_postfix(const uint8_t *hostname_postfix,
2828
int postfix_len)
2929
{
30+
#if !defined(CONFIG_NET_HOSTNAME_UNIQUE_UPDATE)
3031
static bool postfix_set;
32+
#endif
3133
int pos = 0;
3234
int i;
3335

36+
#if !defined(CONFIG_NET_HOSTNAME_UNIQUE_UPDATE)
3437
if (postfix_set) {
3538
return -EALREADY;
3639
}
40+
#endif
3741

3842
NET_ASSERT(postfix_len > 0);
3943

@@ -50,7 +54,9 @@ int net_hostname_set_postfix(const uint8_t *hostname_postfix,
5054

5155
NET_DBG("New hostname %s", log_strdup(hostname));
5256

57+
#if !defined(CONFIG_NET_HOSTNAME_UNIQUE_UPDATE)
5358
postfix_set = true;
59+
#endif
5460

5561
return 0;
5662
}

0 commit comments

Comments
 (0)