Skip to content

Commit 4987aa5

Browse files
committed
Add support for socket activation by ipv6 socket
iodined may accept ipv4 and ipv6 sockets via systemd socket activation, we need to figure out type of sockets.
1 parent 36df8dc commit 4987aa5

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/iodined.c

+22-6
Original file line numberDiff line numberDiff line change
@@ -2671,14 +2671,11 @@ main(int argc, char **argv)
26712671

26722672
#ifdef HAVE_SYSTEMD
26732673
nb_fds = sd_listen_fds(0);
2674-
if (nb_fds > 1) {
2674+
if (nb_fds < 0) {
2675+
warnx("Failed to receive file descriptors from systemd: %s", strerror(-nb_fds));
26752676
retval = 1;
2676-
warnx("Too many file descriptors received!\n");
26772677
goto cleanup;
2678-
} else if (nb_fds == 1) {
2679-
/* XXX: assume we get IPv4 socket */
2680-
dns_fds.v4fd = SD_LISTEN_FDS_START;
2681-
} else {
2678+
} else if (nb_fds == 0) {
26822679
#endif
26832680
if ((addrfamily == AF_UNSPEC || addrfamily == AF_INET) &&
26842681
(dns_fds.v4fd = open_dns(&dns4addr, dns4addr_len)) < 0) {
@@ -2694,6 +2691,25 @@ main(int argc, char **argv)
26942691
goto cleanup;
26952692
}
26962693
#ifdef HAVE_SYSTEMD
2694+
} else if (nb_fds <= 2) {
2695+
/* systemd may pass up to two sockets, for ip4 and ip6, try to figure out
2696+
which is which */
2697+
for (int i = 0; i < nb_fds; i++) {
2698+
int fd = SD_LISTEN_FDS_START + i;
2699+
if (sd_is_socket(fd, AF_INET, SOCK_DGRAM, -1)) {
2700+
dns_fds.v4fd = fd;
2701+
} else if (sd_is_socket(fd, AF_INET6, SOCK_DGRAM, -1)) {
2702+
dns_fds.v6fd = fd;
2703+
} else {
2704+
retval = 1;
2705+
warnx("Unknown socket %d passed to iodined!\n", fd);
2706+
goto cleanup;
2707+
}
2708+
}
2709+
} else {
2710+
retval = 1;
2711+
warnx("Too many file descriptors received!\n");
2712+
goto cleanup;
26972713
}
26982714
#endif
26992715

0 commit comments

Comments
 (0)