tree-wide: introduce setsockopt_int() helper and make use of it everywhere
As suggested by @heftig: https://github.com/systemd/systemd/commit/6d5e65f6454212cd400d0ebda34978a9f20cc26a#commitcomment-30938667
This commit is contained in:
+15
-12
@@ -62,10 +62,9 @@ int socket_address_listen(
|
||||
return r;
|
||||
|
||||
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)
|
||||
return -errno;
|
||||
r = setsockopt_int(fd, IPPROTO_IPV6, IPV6_V6ONLY, only == SOCKET_ADDRESS_IPV6_ONLY);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (IN_SET(socket_address_family(a), AF_INET, AF_INET6)) {
|
||||
@@ -74,23 +73,27 @@ int socket_address_listen(
|
||||
return -errno;
|
||||
|
||||
if (reuse_port) {
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &const_int_one, sizeof(const_int_one)) < 0)
|
||||
log_warning_errno(errno, "SO_REUSEPORT failed: %m");
|
||||
r = setsockopt_int(fd, SOL_SOCKET, SO_REUSEPORT, true);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "SO_REUSEPORT failed: %m");
|
||||
}
|
||||
|
||||
if (free_bind) {
|
||||
if (setsockopt(fd, IPPROTO_IP, IP_FREEBIND, &const_int_one, sizeof(const_int_one)) < 0)
|
||||
log_warning_errno(errno, "IP_FREEBIND failed: %m");
|
||||
r = setsockopt_int(fd, IPPROTO_IP, IP_FREEBIND, true);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "IP_FREEBIND failed: %m");
|
||||
}
|
||||
|
||||
if (transparent) {
|
||||
if (setsockopt(fd, IPPROTO_IP, IP_TRANSPARENT, &const_int_one, sizeof(const_int_one)) < 0)
|
||||
log_warning_errno(errno, "IP_TRANSPARENT failed: %m");
|
||||
r = setsockopt_int(fd, IPPROTO_IP, IP_TRANSPARENT, true);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "IP_TRANSPARENT failed: %m");
|
||||
}
|
||||
}
|
||||
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &const_int_one, sizeof(const_int_one)) < 0)
|
||||
return -errno;
|
||||
r = setsockopt_int(fd, SOL_SOCKET, SO_REUSEADDR, true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
p = socket_address_get_path(a);
|
||||
if (p) {
|
||||
|
||||
Reference in New Issue
Block a user