]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared: move in_addr_ifindex_name_from_string_auto() there
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Tue, 28 Apr 2020 15:58:24 +0000 (17:58 +0200)
committerMarc-André Lureau <marcandre.lureau@redhat.com>
Thu, 7 May 2020 20:36:52 +0000 (22:36 +0200)
src/resolve/meson.build
src/resolve/resolved-conf.c
src/resolve/resolved-util.c [deleted file]
src/resolve/resolved-util.h [deleted file]
src/resolve/test-resolved-util.c [deleted file]
src/shared/socket-netlink.c
src/shared/socket-netlink.h
src/test/test-socket-util.c

index c4d8d4e5d9a3bb309017553f7b6c813b22b6bfc8..92b67b6333d764ce474aeb05a7085fcfebd178ae 100644 (file)
@@ -64,8 +64,6 @@ systemd_resolved_sources = files('''
         resolved-etc-hosts.h
         resolved-etc-hosts.c
         resolved-dnstls.h
-        resolved-util.c
-        resolved-util.h
 '''.split())
 
 resolvectl_sources = files('''
@@ -230,10 +228,4 @@ tests += [
          [],
          [],
          'ENABLE_RESOLVE', 'manual'],
-
-        [['src/resolve/test-resolved-util.c',
-          'src/resolve/resolved-util.c',
-          'src/resolve/resolved-util.h'],
-         [],
-         []],
 ]
index cdca0afbea87131b9f8e4662f7aa187c04796953..e915343c01216051e85e8bf5692d7c5c14e1e34b 100644 (file)
@@ -8,10 +8,10 @@
 #include "parse-util.h"
 #include "resolved-conf.h"
 #include "resolved-dnssd.h"
-#include "resolved-util.h"
 #include "resolved-manager.h"
 #include "resolved-dns-search-domain.h"
 #include "dns-domain.h"
+#include "socket-netlink.h"
 #include "specifier.h"
 #include "string-table.h"
 #include "string-util.h"
diff --git a/src/resolve/resolved-util.c b/src/resolve/resolved-util.c
deleted file mode 100644 (file)
index ac8df63..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
-
-#include "alloc-util.h"
-#include "macro.h"
-#include "resolved-util.h"
-#include "socket-netlink.h"
-
-int in_addr_ifindex_name_from_string_auto(const char *s, int *family, union in_addr_union *ret, int *ifindex, char **server_name) {
-        _cleanup_free_ char *buf = NULL, *name = NULL;
-        const char *m;
-        int r;
-
-        assert(s);
-
-        m = strchr(s, '#');
-        if (m) {
-                name = strdup(m+1);
-                if (!name)
-                        return -ENOMEM;
-
-                buf = strndup(s, m - s);
-                if (!buf)
-                        return -ENOMEM;
-
-                s = buf;
-        }
-
-        r = in_addr_ifindex_from_string_auto(s, family, ret, ifindex);
-        if (r < 0)
-                return r;
-
-        if (server_name)
-                *server_name = TAKE_PTR(name);
-
-        return r;
-}
diff --git a/src/resolve/resolved-util.h b/src/resolve/resolved-util.h
deleted file mode 100644 (file)
index 10ebbc0..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
-#pragma once
-
-#include "in-addr-util.h"
-
-int in_addr_ifindex_name_from_string_auto(const char *s, int *family, union in_addr_union *ret, int *ifindex, char **server_name);
diff --git a/src/resolve/test-resolved-util.c b/src/resolve/test-resolved-util.c
deleted file mode 100644 (file)
index 35bd73c..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
-
-#include "log.h"
-#include "resolved-util.h"
-#include "string-util.h"
-#include "tests.h"
-
-
-static void test_in_addr_ifindex_name_from_string_auto_one(const char *a, const char *expected) {
-        int family, ifindex;
-        union in_addr_union ua;
-        _cleanup_free_ char *server_name = NULL;
-
-        assert_se(in_addr_ifindex_name_from_string_auto(a, &family, &ua, &ifindex, &server_name) >= 0);
-        assert_se(streq_ptr(server_name, expected));
-}
-
-static void test_in_addr_ifindex_name_from_string_auto(void) {
-        log_info("/* %s */", __func__);
-
-        test_in_addr_ifindex_name_from_string_auto_one("192.168.0.1", NULL);
-        test_in_addr_ifindex_name_from_string_auto_one("192.168.0.1#test.com", "test.com");
-        test_in_addr_ifindex_name_from_string_auto_one("fe80::18%19", NULL);
-        test_in_addr_ifindex_name_from_string_auto_one("fe80::18%19#another.test.com", "another.test.com");
-}
-
-int main(int argc, char **argv) {
-        test_setup_logging(LOG_DEBUG);
-
-        test_in_addr_ifindex_name_from_string_auto();
-        return 0;
-}
index ba33825340b831db0078ea1b91a5ffe5b6f2692c..16b0e6a5c3c609313819d1e3e20465094dddbc57 100644 (file)
@@ -362,3 +362,33 @@ int in_addr_ifindex_from_string_auto(const char *s, int *family, union in_addr_u
 
         return r;
 }
+
+int in_addr_ifindex_name_from_string_auto(const char *s, int *family, union in_addr_union *ret, int *ifindex, char **server_name) {
+        _cleanup_free_ char *buf = NULL, *name = NULL;
+        const char *m;
+        int r;
+
+        assert(s);
+
+        m = strchr(s, '#');
+        if (m) {
+                name = strdup(m+1);
+                if (!name)
+                        return -ENOMEM;
+
+                buf = strndup(s, m - s);
+                if (!buf)
+                        return -ENOMEM;
+
+                s = buf;
+        }
+
+        r = in_addr_ifindex_from_string_auto(s, family, ret, ifindex);
+        if (r < 0)
+                return r;
+
+        if (server_name)
+                *server_name = TAKE_PTR(name);
+
+        return r;
+}
index fa58409d6182f77c937cf52f149d2574d969faa7..35c35db52d1999ff7e8aa5f470a52e28d0f59c5c 100644 (file)
@@ -21,3 +21,4 @@ bool socket_address_is(const SocketAddress *a, const char *s, int type);
 bool socket_address_is_netlink(const SocketAddress *a, const char *s);
 
 int in_addr_ifindex_from_string_auto(const char *s, int *family, union in_addr_union *ret, int *ifindex);
+int in_addr_ifindex_name_from_string_auto(const char *s, int *family, union in_addr_union *ret, int *ifindex, char **server_name);
index d36caaa71e73375637af4cbc61d09332625c3644..05c375d79ba0848b8b62f5314792aa897d1755eb 100644 (file)
@@ -245,6 +245,24 @@ static void test_in_addr_ifindex_from_string_auto(void) {
         assert_se(in_addr_ifindex_from_string_auto("fe80::19%thisinterfacecantexist", &family, &ua, &ifindex) == -ENODEV);
 }
 
+static void test_in_addr_ifindex_name_from_string_auto_one(const char *a, const char *expected) {
+        int family, ifindex;
+        union in_addr_union ua;
+        _cleanup_free_ char *server_name = NULL;
+
+        assert_se(in_addr_ifindex_name_from_string_auto(a, &family, &ua, &ifindex, &server_name) >= 0);
+        assert_se(streq_ptr(server_name, expected));
+}
+
+static void test_in_addr_ifindex_name_from_string_auto(void) {
+        log_info("/* %s */", __func__);
+
+        test_in_addr_ifindex_name_from_string_auto_one("192.168.0.1", NULL);
+        test_in_addr_ifindex_name_from_string_auto_one("192.168.0.1#test.com", "test.com");
+        test_in_addr_ifindex_name_from_string_auto_one("fe80::18%19", NULL);
+        test_in_addr_ifindex_name_from_string_auto_one("fe80::18%19#another.test.com", "another.test.com");
+}
+
 static void test_sockaddr_equal(void) {
         union sockaddr_union a = {
                 .in.sin_family = AF_INET,
@@ -676,6 +694,7 @@ int main(int argc, char *argv[]) {
         test_in_addr_to_string();
         test_in_addr_ifindex_to_string();
         test_in_addr_ifindex_from_string_auto();
+        test_in_addr_ifindex_name_from_string_auto();
 
         test_sockaddr_equal();