summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-08-10 09:58:50 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-08-16 12:52:56 +0200
commit1f2db2e31516929c9ee7dad801079edd991fb0fb (patch)
tree5599102da2184ff003145a79866f5d1bd5b557da
parentlibsystemd: use _NEG_ macros, adjust some comments (diff)
downloadsystemd-1f2db2e31516929c9ee7dad801079edd991fb0fb.tar.xz
systemd-1f2db2e31516929c9ee7dad801079edd991fb0fb.zip
libsystemd-network: use _NEG_ macros to reduce indentation
No functional change intended.
-rw-r--r--src/libsystemd-network/sd-dhcp-client.c15
-rw-r--r--src/libsystemd-network/sd-dhcp-server.c10
-rw-r--r--src/libsystemd-network/sd-dhcp6-client.c10
-rw-r--r--src/libsystemd-network/sd-lldp-rx.c5
-rw-r--r--src/libsystemd-network/sd-ndisc.c23
-rw-r--r--src/libsystemd-network/sd-radv.c23
6 files changed, 34 insertions, 52 deletions
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index aaca8b792e..272201abfd 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -1848,10 +1848,9 @@ static int client_receive_message_udp(
assert(s);
buflen = next_datagram_size_fd(fd);
+ if (ERRNO_IS_NEG_TRANSIENT(buflen) || ERRNO_IS_NEG_DISCONNECT(buflen))
+ return 0;
if (buflen < 0) {
- if (ERRNO_IS_TRANSIENT(buflen) || ERRNO_IS_DISCONNECT(buflen))
- return 0;
-
log_dhcp_client_errno(client, buflen, "Failed to determine datagram size to read, ignoring: %m");
return 0;
}
@@ -1941,10 +1940,9 @@ static int client_receive_message_raw(
assert(s);
buflen = next_datagram_size_fd(fd);
+ if (ERRNO_IS_NEG_TRANSIENT(buflen) || ERRNO_IS_NEG_DISCONNECT(buflen))
+ return 0;
if (buflen < 0) {
- if (ERRNO_IS_TRANSIENT(buflen) || ERRNO_IS_DISCONNECT(buflen))
- return 0;
-
log_dhcp_client_errno(client, buflen, "Failed to determine datagram size to read, ignoring: %m");
return 0;
}
@@ -1956,10 +1954,9 @@ static int client_receive_message_raw(
iov = IOVEC_MAKE(packet, buflen);
len = recvmsg_safe(fd, &msg, 0);
+ if (ERRNO_IS_NEG_TRANSIENT(len) || ERRNO_IS_NEG_DISCONNECT(len))
+ return 0;
if (len < 0) {
- if (ERRNO_IS_TRANSIENT(len) || ERRNO_IS_DISCONNECT(len))
- return 0;
-
log_dhcp_client_errno(client, len, "Could not receive message from raw socket, ignoring: %m");
return 0;
}
diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c
index 0aa500d7d2..a9bb7657d1 100644
--- a/src/libsystemd-network/sd-dhcp-server.c
+++ b/src/libsystemd-network/sd-dhcp-server.c
@@ -1316,10 +1316,9 @@ static int server_receive_message(sd_event_source *s, int fd,
int r;
datagram_size = next_datagram_size_fd(fd);
+ if (ERRNO_IS_NEG_TRANSIENT(datagram_size) || ERRNO_IS_NEG_DISCONNECT(datagram_size))
+ return 0;
if (datagram_size < 0) {
- if (ERRNO_IS_TRANSIENT(datagram_size) || ERRNO_IS_DISCONNECT(datagram_size))
- return 0;
-
log_dhcp_server_errno(server, datagram_size, "Failed to determine datagram size to read, ignoring: %m");
return 0;
}
@@ -1336,10 +1335,9 @@ static int server_receive_message(sd_event_source *s, int fd,
iov = IOVEC_MAKE(message, datagram_size);
len = recvmsg_safe(fd, &msg, 0);
+ if (ERRNO_IS_NEG_TRANSIENT(len) || ERRNO_IS_NEG_DISCONNECT(len))
+ return 0;
if (len < 0) {
- if (ERRNO_IS_TRANSIENT(len) || ERRNO_IS_DISCONNECT(len))
- return 0;
-
log_dhcp_server_errno(server, len, "Could not receive message, ignoring: %m");
return 0;
}
diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c
index 9a4f3ab1bf..2f4053caad 100644
--- a/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/libsystemd-network/sd-dhcp6-client.c
@@ -1283,10 +1283,9 @@ static int client_receive_message(
ssize_t buflen, len;
buflen = next_datagram_size_fd(fd);
+ if (ERRNO_IS_NEG_TRANSIENT(buflen) || ERRNO_IS_NEG_DISCONNECT(buflen))
+ return 0;
if (buflen < 0) {
- if (ERRNO_IS_TRANSIENT(buflen) || ERRNO_IS_DISCONNECT(buflen))
- return 0;
-
log_dhcp6_client_errno(client, buflen, "Failed to determine datagram size to read, ignoring: %m");
return 0;
}
@@ -1298,10 +1297,9 @@ static int client_receive_message(
iov = IOVEC_MAKE(message, buflen);
len = recvmsg_safe(fd, &msg, MSG_DONTWAIT);
+ if (ERRNO_IS_NEG_TRANSIENT(len) || ERRNO_IS_NEG_DISCONNECT(len))
+ return 0;
if (len < 0) {
- if (ERRNO_IS_TRANSIENT(len) || ERRNO_IS_DISCONNECT(len))
- return 0;
-
log_dhcp6_client_errno(client, len, "Could not receive message from UDP socket, ignoring: %m");
return 0;
}
diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c
index 03e8986049..8dafa41812 100644
--- a/src/libsystemd-network/sd-lldp-rx.c
+++ b/src/libsystemd-network/sd-lldp-rx.c
@@ -198,10 +198,9 @@ static int lldp_rx_receive_datagram(sd_event_source *s, int fd, uint32_t revents
assert(fd >= 0);
space = next_datagram_size_fd(fd);
+ if (ERRNO_IS_NEG_TRANSIENT(space) || ERRNO_IS_NEG_DISCONNECT(space))
+ return 0;
if (space < 0) {
- if (ERRNO_IS_TRANSIENT(space) || ERRNO_IS_DISCONNECT(space))
- return 0;
-
log_lldp_rx_errno(lldp_rx, space, "Failed to determine datagram size to read, ignoring: %m");
return 0;
}
diff --git a/src/libsystemd-network/sd-ndisc.c b/src/libsystemd-network/sd-ndisc.c
index 2e446fece3..ca5365b95f 100644
--- a/src/libsystemd-network/sd-ndisc.c
+++ b/src/libsystemd-network/sd-ndisc.c
@@ -208,10 +208,9 @@ static int ndisc_recv(sd_event_source *s, int fd, uint32_t revents, void *userda
assert(nd->event);
buflen = next_datagram_size_fd(fd);
+ if (ERRNO_IS_NEG_TRANSIENT(buflen) || ERRNO_IS_NEG_DISCONNECT(buflen))
+ return 0;
if (buflen < 0) {
- if (ERRNO_IS_TRANSIENT(buflen) || ERRNO_IS_DISCONNECT(buflen))
- return 0;
-
log_ndisc_errno(nd, buflen, "Failed to determine datagram size to read, ignoring: %m");
return 0;
}
@@ -221,32 +220,28 @@ static int ndisc_recv(sd_event_source *s, int fd, uint32_t revents, void *userda
return -ENOMEM;
r = icmp6_receive(fd, NDISC_ROUTER_RAW(rt), rt->raw_size, &rt->address, &rt->timestamp);
- if (r < 0) {
- if (ERRNO_IS_TRANSIENT(r) || ERRNO_IS_DISCONNECT(r))
- return 0;
-
+ if (ERRNO_IS_NEG_TRANSIENT(r) || ERRNO_IS_NEG_DISCONNECT(r))
+ return 0;
+ if (r < 0)
switch (r) {
case -EADDRNOTAVAIL:
log_ndisc(nd, "Received RA from non-link-local address %s. Ignoring.",
IN6_ADDR_TO_STRING(&rt->address));
- break;
+ return 0;
case -EMULTIHOP:
log_ndisc(nd, "Received RA with invalid hop limit. Ignoring.");
- break;
+ return 0;
case -EPFNOSUPPORT:
log_ndisc(nd, "Received invalid source address from ICMPv6 socket. Ignoring.");
- break;
+ return 0;
default:
log_ndisc_errno(nd, r, "Unexpected error while reading from ICMPv6, ignoring: %m");
- break;
+ return 0;
}
- return 0;
- }
-
(void) event_source_disable(nd->timeout_event_source);
(void) ndisc_handle_datagram(nd, rt);
return 0;
diff --git a/src/libsystemd-network/sd-radv.c b/src/libsystemd-network/sd-radv.c
index 20458b9f97..890c146295 100644
--- a/src/libsystemd-network/sd-radv.c
+++ b/src/libsystemd-network/sd-radv.c
@@ -252,10 +252,9 @@ static int radv_recv(sd_event_source *s, int fd, uint32_t revents, void *userdat
assert(ra->event);
ssize_t buflen = next_datagram_size_fd(fd);
+ if (ERRNO_IS_NEG_TRANSIENT(buflen) || ERRNO_IS_NEG_DISCONNECT(buflen))
+ return 0;
if (buflen < 0) {
- if (ERRNO_IS_TRANSIENT(buflen) || ERRNO_IS_DISCONNECT(buflen))
- return 0;
-
log_radv_errno(ra, buflen, "Failed to determine datagram size to read, ignoring: %m");
return 0;
}
@@ -265,32 +264,28 @@ static int radv_recv(sd_event_source *s, int fd, uint32_t revents, void *userdat
return -ENOMEM;
r = icmp6_receive(fd, buf, buflen, &src, &timestamp);
- if (r < 0) {
- if (ERRNO_IS_TRANSIENT(r) || ERRNO_IS_DISCONNECT(r))
- return 0;
-
+ if (ERRNO_IS_NEG_TRANSIENT(r) || ERRNO_IS_NEG_DISCONNECT(r))
+ return 0;
+ if (r < 0)
switch (r) {
case -EADDRNOTAVAIL:
log_radv(ra, "Received RS from non-link-local address %s. Ignoring",
IN6_ADDR_TO_STRING(&src));
- break;
+ return 0;
case -EMULTIHOP:
log_radv(ra, "Received RS with invalid hop limit. Ignoring.");
- break;
+ return 0;
case -EPFNOSUPPORT:
log_radv(ra, "Received invalid source address from ICMPv6 socket. Ignoring.");
- break;
+ return 0;
default:
log_radv_errno(ra, r, "Unexpected error receiving from ICMPv6 socket, ignoring: %m");
- break;
+ return 0;
}
- return 0;
- }
-
if ((size_t) buflen < sizeof(struct nd_router_solicit)) {
log_radv(ra, "Too short packet received, ignoring");
return 0;