From 628706137efbca8aaf753ccd063e5abf7e31aed5 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Wed, 8 Jan 2014 22:04:26 -0500 Subject: networkd: print the received DHCPv4 address and gateway It seems that networkd stores in_addr.s_addr contents in reverse order (little-endian, not network order). This is a bit confusing, but sd_rtnl evidently likes this order. --- src/network/networkd-link.c | 14 +++++++++++++- src/network/networkd.h | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 2ed5e6b63f..3c683a0ce0 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -379,7 +379,19 @@ static void dhcp_handler(sd_dhcp_client *client, int event, void *userdata) { _cleanup_address_free_ Address *addr = NULL; _cleanup_route_free_ Route *rt = NULL; - log_link_info(link, "received config over DHCPv4"); + log_struct_link(LOG_INFO, link, + "MESSAGE=%s: DHCPv4 address %u.%u.%u.%u/%u via %u.%u.%u.%u", + link->ifname, + ADDRESS_FMT_VAL(address), + prefixlen, + ADDRESS_FMT_VAL(gateway), + "ADDRESS=%u.%u.%u.%u", + ADDRESS_FMT_VAL(address), + "PREFIXLEN=%u", + prefixlen, + "GATEWAY=%u.%u.%u.%u", + ADDRESS_FMT_VAL(gateway), + NULL); r = address_new_dynamic(&addr); if (r < 0) { diff --git a/src/network/networkd.h b/src/network/networkd.h index 9be9330c99..2da852fea4 100644 --- a/src/network/networkd.h +++ b/src/network/networkd.h @@ -316,3 +316,8 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free); #define log_struct_bridge(level, bridge, ...) log_struct(level, "INTERFACE=%s", bridge->name, __VA_ARGS__) #define BRIDGE(bridge) "INTERFACE=%s", bridge->name +#define ADDRESS_FMT_VAL(address) \ + (address).s_addr & 0xFF, \ + ((address).s_addr >> 8) & 0xFF, \ + ((address).s_addr >> 16) & 0xFF, \ + (address).s_addr >> 24 -- cgit v1.2.3-54-g00ecf