[PATCH] Allow compile without IPv6.
Gustavo Sverzut Barbieri
barbieri at profusion.mobi
Wed Sep 8 07:36:19 PDT 2010
This patch isolates code using IPv6, AF_INET6 and in6 usage inside
'#ifdef HAVE_IPV6' blocks.
Some code assumed IPv6 and relied on its specific features, such as
binding to a specific interface by means of sin6_scope_id like in
socket-util.c:socket_address_parse(). Now a IPv4 solution is provided
that uses SIOCGIFADDR ioctl to discover the address to use.
---
configure.ac | 8 ++++++
src/build.h | 8 +++++-
src/dbus-socket.c | 13 ++++++++-
src/kmod-setup.c | 2 +
src/load-fragment.c | 6 ++++
src/loopback-setup.c | 14 +++++++++-
src/sd-daemon.c | 18 +++++++++++--
src/socket-util.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++--
src/socket-util.h | 8 ++++++
src/socket.c | 23 +++++++++++++---
src/socket.h | 2 +
src/tcpwrap.c | 15 +++++++++-
12 files changed, 171 insertions(+), 15 deletions(-)
diff --git a/configure.ac b/configure.ac
index 30b291f..339aec6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -126,6 +126,13 @@ if test "x$enable_selinux" != "xno"; then
fi
AM_CONDITIONAL(HAVE_SELINUX, [test "$have_selinux" = "yes"])
+have_ipv6=no
+AC_ARG_ENABLE(ipv6, AS_HELP_STRING([--disable-ipv6], [Disable IPv6 support]))
+if test "x${enable_ipv6}" != "xno"; then
+ have_ipv6=yes
+ AC_DEFINE(HAVE_IPV6, 1, [Define if IPv6 is available])
+fi
+
AC_ARG_ENABLE([tcpwrap],
AS_HELP_STRING([--disable-tcpwrap],[Disable optional TCP wrappers support]),
[case "${enableval}" in
@@ -427,6 +434,7 @@ echo "
SysV rc?.d directories: ${SYSTEM_SYSVRCND_PATH}
Syslog service: ${SPECIAL_SYSLOG_SERVICE}
Gtk: ${have_gtk}
+ IPv6: ${have_ipv6}
tcpwrap: ${have_tcpwrap}
PAM: ${have_pam}
AUDIT: ${have_audit}
diff --git a/src/build.h b/src/build.h
index b7f647a..5c6512c 100644
--- a/src/build.h
+++ b/src/build.h
@@ -52,6 +52,12 @@
#define _SYSVINIT_FEATURE_ "-SYSVINIT"
#endif
-#define SYSTEMD_FEATURES _PAM_FEATURE_ " " _LIBWRAP_FEATURE_ " " _AUDIT_FEATURE_ " " _SELINUX_FEATURE_ " " _SYSVINIT_FEATURE_
+#ifdef HAVE_IPV6
+#define _IPV6_FEATURE_ "+IPV6"
+#else
+#define _IPV6_FEATURE_ "-IPV6"
+#endif
+
+#define SYSTEMD_FEATURES _PAM_FEATURE_ " " _LIBWRAP_FEATURE_ " " _AUDIT_FEATURE_ " " _SELINUX_FEATURE_ " " _SYSVINIT_FEATURE_ " " _IPV6_FEATURE_
#endif
diff --git a/src/dbus-socket.c b/src/dbus-socket.c
index 5931f00..8283461 100644
--- a/src/dbus-socket.c
+++ b/src/dbus-socket.c
@@ -25,9 +25,16 @@
#include "dbus-socket.h"
#include "dbus-execute.h"
+#ifdef HAVE_IPV6
+#define BUS_INTERFACE_PROP_BIND_IPV6_ONLY " <property name=\"BindIPv6Only\" type=\"b\" access=\"read\"/>\n"
+#else
+#define BUS_INTERFACE_PROP_BIND_IPV6_ONLY ""
+#endif
+
+
#define BUS_SOCKET_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Socket\">\n" \
- " <property name=\"BindIPv6Only\" type=\"b\" access=\"read\"/>\n" \
+ BUS_INTERFACE_PROP_BIND_IPV6_ONLY \
" <property name=\"Backlog\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
BUS_EXEC_COMMAND_INTERFACE("ExecStartPre") \
@@ -76,12 +83,16 @@ const char bus_socket_invalidating_properties[] =
"NConnections\0"
"\0";
+#ifdef HAVE_IPV6
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_socket_append_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
+#endif
DBusHandlerResult bus_socket_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
+#ifdef HAVE_IPV6
{ "org.freedesktop.systemd1.Socket", "BindIPv6Only", bus_socket_append_bind_ipv6_only, "s", &u->socket.bind_ipv6_only },
+#endif
{ "org.freedesktop.systemd1.Socket", "Backlog", bus_property_append_unsigned, "u", &u->socket.backlog },
{ "org.freedesktop.systemd1.Socket", "TimeoutUSec", bus_property_append_usec, "t", &u->socket.timeout_usec },
BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Socket", u->service.exec_command[SOCKET_EXEC_START_PRE], "ExecStartPre"),
diff --git a/src/kmod-setup.c b/src/kmod-setup.c
index e614295..efd9c7c 100644
--- a/src/kmod-setup.c
+++ b/src/kmod-setup.c
@@ -31,7 +31,9 @@
static const char * const kmod_table[] = {
"autofs4", "/sys/class/misc/autofs",
+#ifdef HAVE_IPV6
"ipv6", "/sys/module/ipv6",
+#endif
"unix", "/proc/net/unix"
};
diff --git a/src/load-fragment.c b/src/load-fragment.c
index 636de8d..466fdcf 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -232,6 +232,7 @@ static int config_parse_listen(
return 0;
}
+#ifdef HAVE_IPV6
static int config_parse_socket_bind(
const char *filename,
unsigned line,
@@ -265,6 +266,7 @@ static int config_parse_socket_bind(
return 0;
}
+#endif
static int config_parse_nice(
const char *filename,
@@ -1452,7 +1454,9 @@ static void dump_items(FILE *f, const ConfigItem *items) {
{ config_parse_kill_mode, "KILLMODE" },
{ config_parse_kill_signal, "SIGNAL" },
{ config_parse_listen, "SOCKET [...]" },
+#ifdef HAVE_IPV6
{ config_parse_socket_bind, "SOCKETBIND" },
+#endif
{ config_parse_bindtodevice, "NETWORKINTERFACE" },
{ config_parse_usec, "SECONDS" },
{ config_parse_path_strv, "PATH [...]" },
@@ -1609,7 +1613,9 @@ static int load_from_path(Unit *u, const char *path) {
{ "ListenDatagram", config_parse_listen, &u->socket, "Socket" },
{ "ListenSequentialPacket", config_parse_listen, &u->socket, "Socket" },
{ "ListenFIFO", config_parse_listen, &u->socket, "Socket" },
+#ifdef HAVE_IPV6
{ "BindIPv6Only", config_parse_socket_bind, &u->socket, "Socket" },
+#endif
{ "Backlog", config_parse_unsigned, &u->socket.backlog, "Socket" },
{ "BindToDevice", config_parse_bindtodevice, &u->socket, "Socket" },
{ "ExecStartPre", config_parse_exec, u->socket.exec_command+SOCKET_EXEC_START_PRE, "Socket" },
diff --git a/src/loopback-setup.c b/src/loopback-setup.c
index c852ed7..dec29b6 100644
--- a/src/loopback-setup.c
+++ b/src/loopback-setup.c
@@ -37,9 +37,14 @@
enum {
REQUEST_NONE = 0,
REQUEST_ADDRESS_IPV4 = 1,
+#ifdef HAVE_IPV6
REQUEST_ADDRESS_IPV6 = 2,
REQUEST_FLAGS = 4,
REQUEST_ALL = 7
+#else
+ REQUEST_FLAGS = 2,
+ REQUEST_ALL = 3
+#endif
};
#define NLMSG_TAIL(nmsg) \
@@ -98,7 +103,12 @@ static int add_adresses(int fd, int if_loopback) {
struct nlmsghdr header;
uint8_t buf[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
NLMSG_ALIGN(sizeof(struct ifaddrmsg)) +
- RTA_LENGTH(sizeof(struct in6_addr))];
+#ifdef HAVE_IPV6
+ RTA_LENGTH(sizeof(struct in6_addr))
+#else
+ RTA_LENGTH(sizeof(struct in_addr))
+#endif
+ ];
} request;
struct ifaddrmsg *ifaddrmsg;
@@ -128,6 +138,7 @@ static int add_adresses(int fd, int if_loopback) {
if (sendto_loop(fd, &request, request.header.nlmsg_len, 0, &sa.sa, sizeof(sa)) < 0)
return -errno;
+#ifdef HAVE_IPV6
request.header.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
request.header.nlmsg_seq = REQUEST_ADDRESS_IPV6;
@@ -139,6 +150,7 @@ static int add_adresses(int fd, int if_loopback) {
if (sendto_loop(fd, &request, request.header.nlmsg_len, 0, &sa.sa, sizeof(sa)) < 0)
return -errno;
+#endif
return 0;
}
diff --git a/src/sd-daemon.c b/src/sd-daemon.c
index 9c23b91..b2166c3 100644
--- a/src/sd-daemon.c
+++ b/src/sd-daemon.c
@@ -203,7 +203,9 @@ static int sd_is_socket_internal(int fd, int type, int listening) {
union sockaddr_union {
struct sockaddr sa;
struct sockaddr_in in4;
+#ifdef HAVE_IPV6
struct sockaddr_in6 in6;
+#endif
struct sockaddr_un un;
struct sockaddr_storage storage;
};
@@ -241,7 +243,14 @@ int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port
socklen_t l;
int r;
- if (family != 0 && family != AF_INET && family != AF_INET6)
+#ifdef HAVE_IPV6
+#define SOCKET_FAMILY_IS_INET(family) \
+ (family == AF_INET || family == AF_INET6)
+#else
+#define SOCKET_FAMILY_IS_INET(family) (family == AF_INET)
+#endif
+
+ if (family != 0 && !SOCKET_FAMILY_IS_INET(family))
return -EINVAL;
if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
@@ -256,8 +265,7 @@ int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port
if (l < sizeof(sa_family_t))
return -EINVAL;
- if (sockaddr.sa.sa_family != AF_INET &&
- sockaddr.sa.sa_family != AF_INET6)
+ if (!SOCKET_FAMILY_IS_INET(sockaddr.sa.sa_family))
return 0;
if (family > 0)
@@ -270,14 +278,18 @@ int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port
return -EINVAL;
return htons(port) == sockaddr.in4.sin_port;
+#ifdef HAVE_IPV6
} else {
if (l < sizeof(struct sockaddr_in6))
return -EINVAL;
return htons(port) == sockaddr.in6.sin6_port;
+#endif
}
}
+#undef SOCKET_FAMILY_IS_INET
+
return 1;
}
diff --git a/src/socket-util.c b/src/socket-util.c
index 151757c..ae1d702 100644
--- a/src/socket-util.c
+++ b/src/socket-util.c
@@ -36,6 +36,35 @@
#include "missing.h"
#include "label.h"
+#ifndef HAVE_IPV6
+#include <sys/ioctl.h>
+
+static int ipv4_inetaddr(const char *iface, struct in_addr *ret)
+{
+ int fd;
+ struct ifreq ifr;
+
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (fd < 0)
+ return -errno;
+
+ ifr.ifr_addr.sa_family = AF_INET;
+ strncpy(ifr.ifr_name, iface, IF_NAMESIZE-1);
+
+ if (ioctl(fd, SIOCGIFADDR, &ifr) < 0) {
+ int r = -errno;
+ close(fd);
+ return r;
+ }
+
+ close(fd);
+
+ ret->s_addr = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
+
+ return 0;
+}
+#endif
+
int socket_address_parse(SocketAddress *a, const char *s) {
int r;
char *e, *n;
@@ -48,6 +77,7 @@ int socket_address_parse(SocketAddress *a, const char *s) {
a->type = SOCK_STREAM;
if (*s == '[') {
+#ifdef HAVE_IPV6
/* IPv6 in [x:.....:z]:p notation */
if (!(e = strchr(s+1, ']')))
@@ -78,7 +108,9 @@ int socket_address_parse(SocketAddress *a, const char *s) {
a->sockaddr.in6.sin6_family = AF_INET6;
a->sockaddr.in6.sin6_port = htons((uint16_t) u);
a->size = sizeof(struct sockaddr_in6);
-
+#else
+ log_warning("IPv6 support is disabled.");
+#endif
} else if (*s == '/') {
/* AF_UNIX socket */
@@ -140,17 +172,29 @@ int socket_address_parse(SocketAddress *a, const char *s) {
/* Uh, our last resort, an interface name */
idx = if_nametoindex(n);
- free(n);
- if (idx == 0)
+ if (idx == 0) {
+ free(n);
return -EINVAL;
+ }
+#ifdef HAVE_IPV6
a->sockaddr.in6.sin6_family = AF_INET6;
a->sockaddr.in6.sin6_port = htons((uint16_t) u);
a->sockaddr.in6.sin6_scope_id = idx;
a->sockaddr.in6.sin6_addr = in6addr_any;
a->size = sizeof(struct sockaddr_in6);
+#else
+ a->sockaddr.in4.sin_family = AF_INET;
+ a->sockaddr.in4.sin_port = htons((uint16_t) u);
+ a->size = sizeof(struct sockaddr_in);
+ if (ipv4_inetaddr(n, &a->sockaddr.in4.sin_addr) < 0) {
+ free(n);
+ return -EINVAL;
+ }
+#endif
+ free(n);
}
} else {
@@ -161,10 +205,17 @@ int socket_address_parse(SocketAddress *a, const char *s) {
if (u <= 0 || u > 0xFFFF)
return -EINVAL;
+#ifdef HAVE_IPV6
a->sockaddr.in6.sin6_family = AF_INET6;
a->sockaddr.in6.sin6_port = htons((uint16_t) u);
a->sockaddr.in6.sin6_addr = in6addr_any;
a->size = sizeof(struct sockaddr_in6);
+#else
+ a->sockaddr.in4.sin_family = AF_INET;
+ a->sockaddr.in4.sin_port = htons((uint16_t) u);
+ a->sockaddr.in4.sin_addr.s_addr = INADDR_ANY;
+ a->size = sizeof(struct sockaddr_in);
+#endif
}
}
@@ -184,6 +235,7 @@ int socket_address_verify(const SocketAddress *a) {
return 0;
+#ifdef HAVE_IPV6
case AF_INET6:
if (a->size != sizeof(struct sockaddr_in6))
return -EINVAL;
@@ -192,6 +244,7 @@ int socket_address_verify(const SocketAddress *a) {
return -EINVAL;
return 0;
+#endif
case AF_UNIX:
if (a->size < sizeof(sa_family_t))
@@ -243,6 +296,7 @@ int socket_address_print(const SocketAddress *a, char **p) {
return 0;
}
+#ifdef HAVE_IPV6
case AF_INET6: {
char *ret;
@@ -259,6 +313,7 @@ int socket_address_print(const SocketAddress *a, char **p) {
*p = ret;
return 0;
}
+#endif
case AF_UNIX: {
char *ret;
@@ -301,7 +356,9 @@ int socket_address_print(const SocketAddress *a, char **p) {
int socket_address_listen(
const SocketAddress *a,
int backlog,
+#ifdef HAVE_IPV6
SocketAddressBindIPv6Only only,
+#endif
const char *bind_to_device,
bool free_bind,
mode_t directory_mode,
@@ -328,12 +385,14 @@ int socket_address_listen(
if (r < 0)
return r;
+#ifdef HAVE_IPV6
if (socket_address_family(a) == AF_INET6 && only != SOCKET_ADDRESS_DEFAULT) {
int flag = only == SOCKET_ADDRESS_IPV6_ONLY;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &flag, sizeof(flag)) < 0)
goto fail;
}
+#endif
if (bind_to_device)
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, bind_to_device, strlen(bind_to_device)+1) < 0)
@@ -426,6 +485,7 @@ bool socket_address_equal(const SocketAddress *a, const SocketAddress *b) {
break;
+#ifdef HAVE_IPV6
case AF_INET6:
if (memcmp(&a->sockaddr.in6.sin6_addr, &b->sockaddr.in6.sin6_addr, sizeof(a->sockaddr.in6.sin6_addr)) != 0)
return false;
@@ -434,6 +494,7 @@ bool socket_address_equal(const SocketAddress *a, const SocketAddress *b) {
return false;
break;
+#endif
case AF_UNIX:
@@ -484,6 +545,7 @@ bool socket_address_needs_mount(const SocketAddress *a, const char *prefix) {
return path_startswith(a->sockaddr.un.sun_path, prefix);
}
+#ifdef HAVE_IPV6
static const char* const socket_address_bind_ipv6_only_table[_SOCKET_ADDRESS_BIND_IPV6_ONLY_MAX] = {
[SOCKET_ADDRESS_DEFAULT] = "default",
[SOCKET_ADDRESS_BOTH] = "both",
@@ -491,3 +553,4 @@ static const char* const socket_address_bind_ipv6_only_table[_SOCKET_ADDRESS_BIN
};
DEFINE_STRING_TABLE_LOOKUP(socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
+#endif
diff --git a/src/socket-util.h b/src/socket-util.h
index 6eb3b5c..e6ae982 100644
--- a/src/socket-util.h
+++ b/src/socket-util.h
@@ -33,7 +33,9 @@
union sockaddr_union {
struct sockaddr sa;
struct sockaddr_in in4;
+#ifdef HAVE_IPV6
struct sockaddr_in6 in6;
+#endif
struct sockaddr_un un;
struct sockaddr_storage storage;
};
@@ -49,6 +51,7 @@ typedef struct SocketAddress {
int type;
} SocketAddress;
+#ifdef HAVE_IPV6
typedef enum SocketAddressBindIPv6Only {
SOCKET_ADDRESS_DEFAULT,
SOCKET_ADDRESS_BOTH,
@@ -56,6 +59,7 @@ typedef enum SocketAddressBindIPv6Only {
_SOCKET_ADDRESS_BIND_IPV6_ONLY_MAX,
_SOCKET_ADDRESS_BIND_IPV6_ONLY_INVALID = -1
} SocketAddressBindIPv6Only;
+#endif
#define socket_address_family(a) ((a)->sockaddr.sa.sa_family)
@@ -68,7 +72,9 @@ bool socket_address_can_accept(const SocketAddress *a);
int socket_address_listen(
const SocketAddress *a,
int backlog,
+#ifdef HAVE_IPV6
SocketAddressBindIPv6Only only,
+#endif
const char *bind_to_device,
bool free_bind,
mode_t directory_mode,
@@ -82,7 +88,9 @@ bool socket_address_equal(const SocketAddress *a, const SocketAddress *b);
bool socket_address_needs_mount(const SocketAddress *a, const char *prefix);
+#ifdef HAVE_IPV6
const char* socket_address_bind_ipv6_only_to_string(SocketAddressBindIPv6Only b);
SocketAddressBindIPv6Only socket_address_bind_ipv6_only_from_string(const char *s);
+#endif
#endif
diff --git a/src/socket.c b/src/socket.c
index 34068b9..5df4204 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -371,7 +371,9 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f,
"%sSocket State: %s\n"
+#ifdef HAVE_IPV6
"%sBindIPv6Only: %s\n"
+#endif
"%sBacklog: %u\n"
"%sSocketMode: %04o\n"
"%sDirectoryMode: %04o\n"
@@ -379,7 +381,9 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
"%sFreeBind: %s\n"
"%sTCPCongestion: %s\n",
prefix, socket_state_to_string(s->state),
+#ifdef HAVE_IPV6
prefix, socket_address_bind_ipv6_only_to_string(s->bind_ipv6_only),
+#endif
prefix, s->backlog,
prefix, s->socket_mode,
prefix, s->directory_mode,
@@ -481,7 +485,9 @@ static int instance_from_socket(int fd, unsigned nr, char **instance) {
struct sockaddr sa;
struct sockaddr_un un;
struct sockaddr_in in;
+#ifdef HAVE_IPV6
struct sockaddr_in6 in6;
+#endif
struct sockaddr_storage storage;
} local, remote;
@@ -514,6 +520,7 @@ static int instance_from_socket(int fd, unsigned nr, char **instance) {
break;
}
+#ifdef HAVE_IPV6
case AF_INET6: {
static const char ipv4_prefix[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF
@@ -546,6 +553,7 @@ static int instance_from_socket(int fd, unsigned nr, char **instance) {
break;
}
+#endif
case AF_UNIX: {
struct ucred ucred;
@@ -631,13 +639,18 @@ static void socket_apply_socket_options(Socket *s, int fd) {
log_warning("IP_TOS failed: %m");
if (s->ip_ttl >= 0) {
- int r, x;
+ int r;
r = setsockopt(fd, IPPROTO_IP, IP_TTL, &s->ip_ttl, sizeof(s->ip_ttl));
- x = setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &s->ip_ttl, sizeof(s->ip_ttl));
+ if (r < 0)
+ log_warning("IP_TTL failed: %m");
+
+#ifdef HAVE_IPV6
+ r = setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &s->ip_ttl, sizeof(s->ip_ttl));
+ if (r < 0)
+ log_warning("IPV6_UNICAST_HOPS failed: %m");
+#endif
- if (r < 0 && x < 0)
- log_warning("IP_TTL/IPV6_UNICAST_HOPS failed: %m");
}
if (s->tcp_congestion)
@@ -749,7 +762,9 @@ static int socket_open_fds(Socket *s) {
if ((r = socket_address_listen(
&p->address,
s->backlog,
+#ifdef HAVE_IPV6
s->bind_ipv6_only,
+#endif
s->bind_to_device,
s->free_bind,
s->directory_mode,
diff --git a/src/socket.h b/src/socket.h
index 9dd9f55..1008313 100644
--- a/src/socket.h
+++ b/src/socket.h
@@ -101,8 +101,10 @@ struct Socket {
SocketExecCommand control_command_id;
pid_t control_pid;
+#ifdef HAVE_IPV6
/* Only for INET6 sockets: issue IPV6_V6ONLY sockopt */
SocketAddressBindIPv6Only bind_ipv6_only;
+#endif
mode_t directory_mode;
mode_t socket_mode;
diff --git a/src/tcpwrap.c b/src/tcpwrap.c
index 0aab142..1d08bdf 100644
--- a/src/tcpwrap.c
+++ b/src/tcpwrap.c
@@ -37,7 +37,9 @@ bool socket_tcpwrap(int fd, const char *name) {
union {
struct sockaddr sa;
struct sockaddr_in in;
+#ifdef HAVE_IPV6
struct sockaddr_in6 in6;
+#endif
struct sockaddr_un un;
struct sockaddr_storage storage;
} sa_union;
@@ -46,8 +48,14 @@ bool socket_tcpwrap(int fd, const char *name) {
if (getsockname(fd, &sa_union.sa, &l) < 0)
return true;
- if (sa_union.sa.sa_family != AF_INET &&
- sa_union.sa.sa_family != AF_INET6)
+#ifdef HAVE_IPV6
+#define SOCKET_FAMILY_IS_INET(family) \
+ (family == AF_INET || family == AF_INET6)
+#else
+#define SOCKET_FAMILY_IS_INET(family) (family == AF_INET)
+#endif
+
+ if (!SOCKET_FAMILY_IS_INET(sa_union.sa.sa_family))
return true;
request_init(&req,
@@ -63,6 +71,9 @@ bool socket_tcpwrap(int fd, const char *name) {
}
log_debug("Connection accepted by tcpwrap.");
+
+#undef SOCKET_FAMILY_IS_INET
+
#endif
return true;
}
--
1.7.1
More information about the systemd-devel
mailing list