[systemd-commits] 4 commits - src/libsystemd src/network src/shared src/systemd src/timesync

Lennart Poettering lennart at kemper.freedesktop.org
Tue Aug 12 06:23:27 PDT 2014


 src/libsystemd/sd-network/sd-network.c |   89 +++++++--
 src/network/networkctl.c               |  295 +++++++++++++++++++--------------
 src/shared/socket-util.c               |   16 +
 src/shared/socket-util.h               |    2 
 src/systemd/sd-network.h               |   20 +-
 src/timesync/timesyncd.c               |   16 -
 6 files changed, 272 insertions(+), 166 deletions(-)

New commits:
commit 9085f64a6694f2928c79fcce365edb1dca6937d4
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Aug 12 15:19:30 2014 +0200

    networkctl: add new switch "-a" to "networkctl status" to show verbose status of all local links

diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index 7ae8804..2da5c83 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -36,6 +36,7 @@
 
 static bool arg_no_pager = false;
 static bool arg_legend = true;
+static bool arg_all = false;
 
 static void pager_open_if_enabled(void) {
 
@@ -208,13 +209,137 @@ static void dump_list(const char *prefix, char **l) {
         }
 }
 
+static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
+        _cleanup_strv_free_ char **dns = NULL, **ntp = NULL;
+        _cleanup_free_ char *state = NULL, *operational_state = NULL;
+        _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
+        _cleanup_udev_device_unref_ struct udev_device *d = NULL;
+        char devid[2 + DECIMAL_STR_MAX(int)];
+        _cleanup_free_ char *t = NULL;
+        const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL;
+        struct ether_addr e;
+        unsigned iftype;
+        int r, ifindex;
+        bool have_mac;
+        uint32_t mtu;
+
+        assert(rtnl);
+        assert(udev);
+        assert(name);
+
+        if (safe_atoi(name, &ifindex) >= 0 && ifindex > 0)
+                r = sd_rtnl_message_new_link(rtnl, &req, RTM_GETLINK, ifindex);
+        else {
+                r = sd_rtnl_message_new_link(rtnl, &req, RTM_GETLINK, 0);
+                if (r < 0)
+                        return rtnl_log_create_error(r);
+
+                r = sd_rtnl_message_append_string(req, IFLA_IFNAME, name);
+        }
+
+        if (r < 0)
+                return rtnl_log_create_error(r);
+
+        r = sd_rtnl_call(rtnl, req, 0, &reply);
+        if (r < 0) {
+                log_error("Failed to query link: %s", strerror(-r));
+                return r;
+        }
+
+        r = sd_rtnl_message_link_get_ifindex(reply, &ifindex);
+        if (r < 0)
+                return rtnl_log_parse_error(r);
+
+        r = sd_rtnl_message_read_string(reply, IFLA_IFNAME, &name);
+        if (r < 0)
+                return rtnl_log_parse_error(r);
+
+        r = sd_rtnl_message_link_get_type(reply, &iftype);
+        if (r < 0)
+                return rtnl_log_parse_error(r);
+
+        have_mac = sd_rtnl_message_read_ether_addr(reply, IFLA_ADDRESS, &e) >= 0;
+
+        if (have_mac) {
+                const uint8_t *p;
+                bool all_zeroes = true;
+
+                for (p = (uint8_t*) &e; p < (uint8_t*) &e + sizeof(e); p++)
+                        if (*p != 0) {
+                                all_zeroes = false;
+                                break;
+                        }
+
+                if (all_zeroes)
+                        have_mac = false;
+        }
+
+        sd_rtnl_message_read_u32(reply, IFLA_MTU, &mtu);
+
+        sd_network_get_link_state(ifindex, &state);
+        sd_network_get_link_operational_state(ifindex, &operational_state);
+
+        sd_network_get_link_dns(ifindex, &dns);
+        sd_network_get_link_ntp(ifindex, &ntp);
+
+        sprintf(devid, "n%i", ifindex);
+        d = udev_device_new_from_device_id(udev, devid);
+
+        link_get_type_string(iftype, d, &t);
+
+        if (d) {
+                driver = udev_device_get_property_value(d, "ID_NET_DRIVER");
+                path = udev_device_get_property_value(d, "ID_PATH");
+
+                vendor = udev_device_get_property_value(d, "ID_VENDOR_FROM_DATABASE");
+                if (!vendor)
+                        vendor = udev_device_get_property_value(d, "ID_VENDOR");
+
+                model = udev_device_get_property_value(d, "ID_MODEL_FROM_DATABASE");
+                if (!model)
+                        model = udev_device_get_property_value(d, "ID_MODEL");
+        }
+
+        printf("%i: %s\n", ifindex, name);
+
+        printf("        Type: %s\n"
+               "       State: %s (%s)\n",
+               strna(t),
+               strna(operational_state),
+               strna(state));
+
+        if (path)
+                printf("        Path: %s\n", path);
+        if (driver)
+                printf("      Driver: %s\n", driver);
+        if (vendor)
+                printf("      Vendor: %s\n", vendor);
+        if (model)
+                printf("       Model: %s\n", model);
+
+        if (have_mac)
+                printf("  HW Address: %s\n", ether_ntoa(&e));
+
+        if (mtu > 0)
+                printf("         MTU: %u\n", mtu);
+
+        dump_addresses(rtnl, "     Address: ", ifindex);
+
+        if (!strv_isempty(dns))
+                dump_list("         DNS: ", dns);
+        if (!strv_isempty(ntp))
+                dump_list("         NTP: ", ntp);
+
+        return 0;
+}
+
 static int link_status(char **args, unsigned n) {
         _cleanup_udev_unref_ struct udev *udev = NULL;
         _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
         char **name;
         int r;
 
-        if (n <= 1) {
+        if (n <= 1 && !arg_all) {
                 _cleanup_free_ char *operational_state = NULL;
                 _cleanup_strv_free_ char **dns = NULL, **ntp = NULL;
 
@@ -247,126 +372,53 @@ static int link_status(char **args, unsigned n) {
                 return -errno;
         }
 
-        STRV_FOREACH(name, args + 1) {
-                _cleanup_strv_free_ char **dns = NULL, **ntp = NULL;
-                _cleanup_free_ char *state = NULL, *operational_state = NULL;
+        if (arg_all) {
                 _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
-                _cleanup_udev_device_unref_ struct udev_device *d = NULL;
-                const char *canonical_name = NULL;
-                char devid[2 + DECIMAL_STR_MAX(int)];
-                int ifindex, canonical_ifindex;
-                _cleanup_free_ char *t = NULL;
-                const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL;
-                struct ether_addr e;
-                unsigned iftype;
-                bool have_mac;
-                uint32_t mtu;
-
-                if (name != args+1)
-                        printf("\n");
-
-                if (safe_atoi(*name, &ifindex) >= 0 && ifindex > 0)
-                        r = sd_rtnl_message_new_link(rtnl, &req, RTM_GETLINK, ifindex);
-                else {
-                        r = sd_rtnl_message_new_link(rtnl, &req, RTM_GETLINK, 0);
-                        if (r < 0)
-                                return rtnl_log_create_error(r);
+                sd_rtnl_message *i;
+                bool space = false;
+                uint16_t type;
 
-                        r = sd_rtnl_message_append_string(req, IFLA_IFNAME, *name);
-                }
+                r = sd_rtnl_message_new_link(rtnl, &req, RTM_GETLINK, 0);
+                if (r < 0)
+                        return rtnl_log_create_error(r);
 
+                r = sd_rtnl_message_request_dump(req, true);
                 if (r < 0)
                         return rtnl_log_create_error(r);
 
                 r = sd_rtnl_call(rtnl, req, 0, &reply);
                 if (r < 0) {
-                        log_error("Failed to query link: %s", strerror(-r));
-                        continue;
-                }
-
-                r = sd_rtnl_message_link_get_ifindex(reply, &canonical_ifindex);
-                if (r < 0)
-                        return rtnl_log_parse_error(r);
-
-                r = sd_rtnl_message_read_string(reply, IFLA_IFNAME, &canonical_name);
-                if (r < 0)
-                        return rtnl_log_parse_error(r);
-
-                r = sd_rtnl_message_link_get_type(reply, &iftype);
-                if (r < 0)
-                        return rtnl_log_parse_error(r);
-
-                have_mac = sd_rtnl_message_read_ether_addr(reply, IFLA_ADDRESS, &e) >= 0;
-
-                if (have_mac) {
-                        const uint8_t *p;
-                        bool all_zeroes = true;
-
-                        for (p = (uint8_t*) &e; p < (uint8_t*) &e + sizeof(e); p++)
-                                if (*p != 0) {
-                                        all_zeroes = false;
-                                        break;
-                                }
-
-                        if (all_zeroes)
-                                have_mac = false;
+                        log_error("Failed to enumerate links: %s", strerror(-r));
+                        return r;
                 }
 
-                sd_rtnl_message_read_u32(reply, IFLA_MTU, &mtu);
-
-                sd_network_get_link_state(canonical_ifindex, &state);
-                sd_network_get_link_operational_state(canonical_ifindex, &operational_state);
-
-                sd_network_get_link_dns(canonical_ifindex, &dns);
-                sd_network_get_link_ntp(canonical_ifindex, &ntp);
+                for (i = reply; i; i = sd_rtnl_message_next(i)) {
+                        const char *nn;
 
-                sprintf(devid, "n%i", canonical_ifindex);
-                d = udev_device_new_from_device_id(udev, devid);
+                        r = sd_rtnl_message_get_type(i, &type);
+                        if (r < 0)
+                                return rtnl_log_parse_error(r);
 
-                link_get_type_string(iftype, d, &t);
+                        if (type != RTM_NEWLINK)
+                                continue;
 
-                if (d) {
-                        driver = udev_device_get_property_value(d, "ID_NET_DRIVER");
-                        path = udev_device_get_property_value(d, "ID_PATH");
+                        r = sd_rtnl_message_read_string(i, IFLA_IFNAME, &nn);
+                        if (r < 0)
+                                return rtnl_log_parse_error(r);
 
-                        vendor = udev_device_get_property_value(d, "ID_VENDOR_FROM_DATABASE");
-                        if (!vendor)
-                                vendor = udev_device_get_property_value(d, "ID_VENDOR");
+                        if (space)
+                                fputc('\n', stdout);
 
-                        model = udev_device_get_property_value(d, "ID_MODEL_FROM_DATABASE");
-                        if (!model)
-                                model = udev_device_get_property_value(d, "ID_MODEL");
+                        link_status_one(rtnl, udev, nn);
+                        space = true;
                 }
+        }
 
-                printf("%i: %s\n", canonical_ifindex, canonical_name);
-
-                printf("        Type: %s\n"
-                       "       State: %s (%s)\n",
-                       strna(t),
-                       strna(operational_state),
-                       strna(state));
-
-                if (path)
-                        printf("        Path: %s\n", path);
-                if (driver)
-                        printf("      Driver: %s\n", driver);
-                if (vendor)
-                        printf("      Vendor: %s\n", vendor);
-                if (model)
-                        printf("       Model: %s\n", model);
-
-                if (have_mac)
-                        printf("  HW Address: %s\n", ether_ntoa(&e));
-
-                if (mtu > 0)
-                        printf("         MTU: %u\n", mtu);
-
-                dump_addresses(rtnl, "     Address: ", canonical_ifindex);
+        STRV_FOREACH(name, args + 1) {
+                if (name != args+1)
+                        fputc('\n', stdout);
 
-                if (!strv_isempty(dns))
-                        dump_list("         DNS: ", dns);
-                if (!strv_isempty(ntp))
-                        dump_list("         NTP: ", ntp);
+                link_status_one(rtnl, udev, *name);
         }
 
         return 0;
@@ -376,7 +428,10 @@ static void help(void) {
         printf("%s [OPTIONS...]\n\n"
                "Query and control the networking subsystem.\n\n"
                "  -h --help             Show this help\n"
-               "     --version          Show package version\n\n"
+               "     --version          Show package version\n"
+               "     --no-pager         Do not pipe output into a pager\n"
+               "     --no-legend        Do not show the headers and footers\n"
+               "  -a --all              Show status for all links\n\n"
                "Commands:\n"
                "  list                  List links\n"
                "  status LINK           Show link status\n"
@@ -396,6 +451,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "version",   no_argument,       NULL, ARG_VERSION   },
                 { "no-pager",  no_argument,       NULL, ARG_NO_PAGER  },
                 { "no-legend", no_argument,       NULL, ARG_NO_LEGEND },
+                { "all",       no_argument,       NULL, 'a'           },
                 {}
         };
 
@@ -404,7 +460,7 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 0);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
+        while ((c = getopt_long(argc, argv, "ha", options, NULL)) >= 0) {
 
                 switch (c) {
 
@@ -425,6 +481,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_legend = false;
                         break;
 
+                case 'a':
+                        arg_all = true;
+                        break;
+
                 case '?':
                         return -EINVAL;
 

commit 1b17f21198e79cabe9e196cff69a9d96653bcdd3
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Aug 12 15:08:09 2014 +0200

    networkctl: properly format MAC addresses

diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index d5d3c80..7ae8804 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -355,15 +355,8 @@ static int link_status(char **args, unsigned n) {
                 if (model)
                         printf("       Model: %s\n", model);
 
-                if (have_mac) {
-                        _cleanup_free_ char *h = NULL;
-
-                        h = hexmem(&e, sizeof(e));
-                        if (!h)
-                                return log_oom();
-
-                        printf("  HW Address: %s\n", h);
-                }
+                if (have_mac)
+                        printf("  HW Address: %s\n", ether_ntoa(&e));
 
                 if (mtu > 0)
                         printf("         MTU: %u\n", mtu);

commit 03cc0fd1431b82e59c11ae12a274c1f2df23169d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Aug 12 15:05:21 2014 +0200

    sd-network: add API to output all collected system-wide NTP and DNS servers
    
    Also, output the collected information in "networkctl".

diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c
index 6375788..d2e608c 100644
--- a/src/libsystemd/sd-network/sd-network.c
+++ b/src/libsystemd/sd-network/sd-network.c
@@ -34,26 +34,19 @@
 #include "sd-network.h"
 #include "network-internal.h"
 
-_public_ int sd_network_get_link_state(int ifindex, char **state) {
-        _cleanup_free_ char *s = NULL, *p = NULL;
+_public_ int sd_network_get_operational_state(char **state) {
+        _cleanup_free_ char *s = NULL;
         int r;
 
-        assert_return(ifindex > 0, -EINVAL);
         assert_return(state, -EINVAL);
 
-        if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
-                return -ENOMEM;
-
-        r = parse_env_file(p, NEWLINE, "ADMIN_STATE", &s, NULL);
+        r = parse_env_file("/run/systemd/netif/state", NEWLINE, "OPER_STATE", &s, NULL);
         if (r == -ENOENT)
                 return -ENODATA;
-        else if (r < 0)
+        if (r < 0)
                 return r;
-        else if (!s)
-                return -EIO;
-
-        if (streq(s, "initializing"))
-                return -EBUSY;
+        if (isempty(s))
+                return -ENODATA;
 
         *state = s;
         s = NULL;
@@ -61,20 +54,63 @@ _public_ int sd_network_get_link_state(int ifindex, char **state) {
         return 0;
 }
 
-_public_ int sd_network_get_operational_state(char **state) {
+static int network_get_strv(const char *key, char ***ret) {
+        _cleanup_strv_free_ char **a = NULL;
         _cleanup_free_ char *s = NULL;
         int r;
 
+        assert_return(ret, -EINVAL);
+
+        r = parse_env_file("/run/systemd/netif/state", NEWLINE, key, &s, NULL);
+        if (r == -ENOENT)
+                return -ENODATA;
+        if (r < 0)
+                return r;
+        if (isempty(s)) {
+                *ret = NULL;
+                return 0;
+        }
+
+        a = strv_split(s, " ");
+        if (!a)
+                return -ENOMEM;
+
+        strv_uniq(a);
+        r = strv_length(a);
+
+        *ret = a;
+        a = NULL;
+
+        return r;
+}
+
+_public_ int sd_network_get_dns(char ***ret) {
+        return network_get_strv("DNS", ret);
+}
+
+_public_ int sd_network_get_ntp(char ***ret) {
+        return network_get_strv("NTP", ret);
+}
+
+_public_ int sd_network_get_link_state(int ifindex, char **state) {
+        _cleanup_free_ char *s = NULL, *p = NULL;
+        int r;
+
+        assert_return(ifindex > 0, -EINVAL);
         assert_return(state, -EINVAL);
 
-        r = parse_env_file("/run/systemd/netif/state", NEWLINE, "OPER_STATE",
-                           &s, NULL);
+        if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
+                return -ENOMEM;
+
+        r = parse_env_file(p, NEWLINE, "ADMIN_STATE", &s, NULL);
         if (r == -ENOENT)
                 return -ENODATA;
-        else if (r < 0)
+        if (r < 0)
                 return r;
-        else if (!s)
-                return -EIO;
+        if (isempty(s))
+                return -ENODATA;
+        if (streq(s, "initializing"))
+                return -EBUSY;
 
         *state = s;
         s = NULL;
@@ -95,10 +131,10 @@ _public_ int sd_network_get_link_operational_state(int ifindex, char **state) {
         r = parse_env_file(p, NEWLINE, "OPER_STATE", &s, NULL);
         if (r == -ENOENT)
                 return -ENODATA;
-        else if (r < 0)
+        if (r < 0)
                 return r;
-        else if (!s)
-                return -EIO;
+        if (isempty(s))
+                return -ENODATA;
 
         *state = s;
         s = NULL;
@@ -119,9 +155,9 @@ _public_ int sd_network_get_link_llmnr(int ifindex, char **llmnr) {
         r = parse_env_file(p, NEWLINE, "LLMNR", &s, NULL);
         if (r == -ENOENT)
                 return -ENODATA;
-        else if (r < 0)
+        if (r < 0)
                 return r;
-        else if (!s)
+        if (isempty(s))
                 return -ENODATA;
 
         *llmnr = s;
@@ -142,11 +178,12 @@ static int network_get_link_strv(const char *key, int ifindex, char ***ret) {
                 return -ENOMEM;
 
         r = parse_env_file(p, NEWLINE, key, &s, NULL);
+        if (r == -ENOENT)
+                return -ENODATA;
         if (r < 0)
                 return r;
-        else if (!s) {
+        if (isempty(s)) {
                 *ret = NULL;
-
                 return 0;
         }
 
diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index 93b1293..d5d3c80 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -216,14 +216,20 @@ static int link_status(char **args, unsigned n) {
 
         if (n <= 1) {
                 _cleanup_free_ char *operational_state = NULL;
+                _cleanup_strv_free_ char **dns = NULL, **ntp = NULL;
 
-                r = sd_network_get_operational_state(&operational_state);
-                if (r < 0) {
-                        log_error("Failed to get operational state: %s", strerror(-r));
-                        return r;
-                }
+                sd_network_get_operational_state(&operational_state);
+                if (operational_state)
+                        printf("       State: %s\n", operational_state);
+
+                sd_network_get_dns(&dns);
+                if (!strv_isempty(dns))
+                        dump_list("         DNS: ", dns);
+
+                sd_network_get_dns(&ntp);
+                if (!strv_isempty(ntp))
+                        dump_list("         NTP: ", ntp);
 
-                printf("State: %s\n", operational_state);
                 return 0;
         }
 
@@ -312,7 +318,7 @@ static int link_status(char **args, unsigned n) {
                 sd_network_get_link_operational_state(canonical_ifindex, &operational_state);
 
                 sd_network_get_link_dns(canonical_ifindex, &dns);
-                sd_network_get_link_dns(canonical_ifindex, &ntp);
+                sd_network_get_link_ntp(canonical_ifindex, &ntp);
 
                 sprintf(devid, "n%i", canonical_ifindex);
                 d = udev_device_new_from_device_id(udev, devid);
diff --git a/src/systemd/sd-network.h b/src/systemd/sd-network.h
index 3e95072..44c4e97 100644
--- a/src/systemd/sd-network.h
+++ b/src/systemd/sd-network.h
@@ -56,6 +56,14 @@ _SD_BEGIN_DECLARATIONS;
  */
 int sd_network_get_operational_state(char **state);
 
+/* Get DNS entries for all links. These are string representations of
+ * IP addresses */
+int sd_network_get_dns(char ***addr);
+
+/* Get NTP entries for all links. These are domain names or string
+ * reperesentations of IP addresses */
+int sd_network_get_ntp(char ***addr);
+
 /* Get state from ifindex.
  * Possible states: failed, configuring, configured, unmanaged
  * Possible return codes:
@@ -71,12 +79,6 @@ int sd_network_get_link_state(int ifindex, char **state);
  */
 int sd_network_get_link_operational_state(int ifindex, char **state);
 
-/* Indicates whether or not LLMNR should be enabled for the link
- * Possible levels of support: yes, no, resolve
- * Possible return codes:
- *   -ENODATA: networkd is not aware of the link*/
-int sd_network_get_link_llmnr(int ifindex, char **llmnr);
-
 /* Get DNS entries for a given link. These are string representations of
  * IP addresses */
 int sd_network_get_link_dns(int ifindex, char ***addr);
@@ -85,6 +87,12 @@ int sd_network_get_link_dns(int ifindex, char ***addr);
  * reperesentations of IP addresses */
 int sd_network_get_link_ntp(int ifindex, char ***addr);
 
+/* Indicates whether or not LLMNR should be enabled for the link
+ * Possible levels of support: yes, no, resolve
+ * Possible return codes:
+ *   -ENODATA: networkd is not aware of the link*/
+int sd_network_get_link_llmnr(int ifindex, char **llmnr);
+
 /* Monitor object */
 typedef struct sd_network_monitor sd_network_monitor;
 

commit f01e5736f1555eec9183e48448fa3454f265b73e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Aug 12 14:54:32 2014 +0200

    timesyncd: move the generic sockaddr_equal() call to socket-util.h

diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
index 0a0726d..1a04f32 100644
--- a/src/shared/socket-util.c
+++ b/src/shared/socket-util.c
@@ -711,3 +711,19 @@ static const char* const socket_address_bind_ipv6_only_table[_SOCKET_ADDRESS_BIN
 };
 
 DEFINE_STRING_TABLE_LOOKUP(socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
+
+bool sockaddr_equal(const union sockaddr_union *a, const union sockaddr_union *b) {
+        assert(a);
+        assert(b);
+
+        if (a->sa.sa_family != b->sa.sa_family)
+                return false;
+
+        if (a->sa.sa_family == AF_INET)
+                return a->in.sin_addr.s_addr == b->in.sin_addr.s_addr;
+
+        if (a->sa.sa_family == AF_INET6)
+                return memcmp(&a->in6.sin6_addr, &b->in6.sin6_addr, sizeof(a->in6.sin6_addr)) == 0;
+
+        return false;
+}
diff --git a/src/shared/socket-util.h b/src/shared/socket-util.h
index 9883ab0..0b4998d 100644
--- a/src/shared/socket-util.h
+++ b/src/shared/socket-util.h
@@ -109,3 +109,5 @@ SocketAddressBindIPv6Only socket_address_bind_ipv6_only_from_string(const char *
 
 int netlink_family_to_string_alloc(int b, char **s);
 int netlink_family_from_string(const char *s) _pure_;
+
+bool sockaddr_equal(const union sockaddr_union *a, const union sockaddr_union *b);
diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c
index e5a8a57..500f83f 100644
--- a/src/timesync/timesyncd.c
+++ b/src/timesync/timesyncd.c
@@ -536,22 +536,6 @@ static void manager_adjust_poll(Manager *m, double offset, bool spike) {
         }
 }
 
-static bool sockaddr_equal(union sockaddr_union *a, union sockaddr_union *b) {
-        assert(a);
-        assert(b);
-
-        if (a->sa.sa_family != b->sa.sa_family)
-                return false;
-
-        if (a->sa.sa_family == AF_INET)
-                return a->in.sin_addr.s_addr == b->in.sin_addr.s_addr;
-
-        if (a->sa.sa_family == AF_INET6)
-                return memcmp(&a->in6.sin6_addr, &b->in6.sin6_addr, sizeof(a->in6.sin6_addr)) == 0;
-
-        return false;
-}
-
 static int manager_receive_response(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
         Manager *m = userdata;
         struct ntp_msg ntpmsg;



More information about the systemd-commits mailing list