Hi, Hope this is not completly ridiculous? I havnt tested this since im not entirely sure how to do it. So tips and comments regarding that are very welcome, im tempt to research further and maybe eventually provide a test for socket-proxy.
Best regards. --- Makefile.am | 4 +++- TODO | 2 -- src/socket-proxy/socket-proxyd.c | 29 +++++++++++++++++++++++------ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Makefile.am b/Makefile.am index 03a65bf..a50a032 100644 --- a/Makefile.am +++ b/Makefile.am @@ -195,6 +195,7 @@ AM_CPPFLAGS = \ -I $(top_builddir)/src/udev \ -I $(top_srcdir)/src/libsystemd/sd-bus \ -I $(top_srcdir)/src/libsystemd/sd-event \ + -I $(top_srcdir)/src/libsystemd/sd-resolve \ -I $(top_srcdir)/src/libsystemd/sd-rtnl \ $(OUR_CPPFLAGS) @@ -3315,7 +3316,8 @@ systemd_socket_proxyd_LDADD = \ libsystemd-logs.la \ libsystemd-internal.la \ libsystemd-journal-internal.la \ - libsystemd-shared.la + libsystemd-shared.la \ + -lresolv # ------------------------------------------------------------------------------ if ENABLE_COREDUMP diff --git a/TODO b/TODO index 0ae1427..c6ccc8c 100644 --- a/TODO +++ b/TODO @@ -113,8 +113,6 @@ Features: * Automatically configure swap partition to use for hibernation by looking for largest swap partition on the root disk? -* socket-proxyd: Use sd-resolve to resolve the server address - * rfkill,backlight: we probably should run the load tools inside of the udev rules so that the state is properly initialized by the time other software sees it * move config_parse_path_strv() out of conf-parser.c diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c index a42e5ae..cd9b95b 100644 --- a/src/socket-proxy/socket-proxyd.c +++ b/src/socket-proxy/socket-proxyd.c @@ -40,13 +40,12 @@ #include "build.h" #include "set.h" #include "path-util.h" +#include "sd-resolve.h" +#include "resolve-util.h" #define BUFFER_SIZE (256 * 1024) #define CONNECTIONS_MAX 256 -#define _cleanup_freeaddrinfo_ _cleanup_(freeaddrinfop) -DEFINE_TRIVIAL_CLEANUP_FUNC(struct addrinfo *, freeaddrinfo); - typedef struct Context { Set *listen; Set *connections; @@ -125,7 +124,9 @@ static int get_remote_sockaddr(union sockaddr_union *sa, socklen_t *salen) { *salen = offsetof(union sockaddr_union, un.sun_path) + 1 + strlen(sa->un.sun_path + 1); } else { - _cleanup_freeaddrinfo_ struct addrinfo *result = NULL; + _cleanup_resolve_unref_ sd_resolve *resolve = NULL; + _cleanup_resolve_addrinfo_free_ struct addrinfo *result = NULL; + sd_resolve_query *q = NULL; const char *node, *service; struct addrinfo hints = { @@ -134,6 +135,10 @@ static int get_remote_sockaddr(union sockaddr_union *sa, socklen_t *salen) { .ai_flags = AI_ADDRCONFIG }; + r = sd_resolve_new(&resolve); + if (r < 0) + return -ENOMEM; + service = strrchr(arg_remote_host, ':'); if (service) { node = strndupa(arg_remote_host, service - arg_remote_host); @@ -144,8 +149,20 @@ static int get_remote_sockaddr(union sockaddr_union *sa, socklen_t *salen) { } log_debug("Looking up address info for %s:%s", node, service); - r = getaddrinfo(node, service, &hints, &result); - if (r != 0) { + r = sd_resolve_getaddrinfo(resolve, &q, node, service, &hints); + if (r < 0) + log_error("Error: %s %d\n", gai_strerror(r), r); + + while (!sd_resolve_is_done(q)) { + r = sd_resolve_wait(resolve, (uint64_t) -1); + if (r < 0) { + log_error("Error: %s\n", strerror(-r)); + assert_not_reached("sd_resolve_wait() failed"); + } + } + + r = sd_resolve_getaddrinfo_done(q, &result); + if (r < 0) { log_error("Failed to resolve host %s:%s: %s", node, service, gai_strerror(r)); return -EHOSTUNREACH; } -- 1.9.0 _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel