mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
sd-network: unify packet processing logic a bit
Let's always check for errno being EAGAIN/EINTR the same way, and always log if we receive weirdly short packets.
This commit is contained in:
parent
e81f253967
commit
004845d18e
@ -65,4 +65,5 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum);
|
|||||||
#define DHCP_CLIENT_DONT_DESTROY(client) \
|
#define DHCP_CLIENT_DONT_DESTROY(client) \
|
||||||
_cleanup_(sd_dhcp_client_unrefp) _unused_ sd_dhcp_client *_dont_destroy_##client = sd_dhcp_client_ref(client)
|
_cleanup_(sd_dhcp_client_unrefp) _unused_ sd_dhcp_client *_dont_destroy_##client = sd_dhcp_client_ref(client)
|
||||||
|
|
||||||
#define log_dhcp_client(client, fmt, ...) log_internal(LOG_DEBUG, 0, __FILE__, __LINE__, __func__, "DHCP CLIENT (0x%x): " fmt, client->xid, ##__VA_ARGS__)
|
#define log_dhcp_client_errno(client, error, fmt, ...) log_internal(LOG_DEBUG, error, __FILE__, __LINE__, __func__, "DHCP CLIENT (0x%x): " fmt, client->xid, ##__VA_ARGS__)
|
||||||
|
#define log_dhcp_client(client, fmt, ...) log_dhcp_client_errno(client, 0, fmt, ##__VA_ARGS__)
|
||||||
|
@ -1645,9 +1645,9 @@ static int client_receive_message_udp(
|
|||||||
if (errno == EAGAIN || errno == EINTR)
|
if (errno == EAGAIN || errno == EINTR)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
log_dhcp_client(client, "Could not receive message from UDP socket: %m");
|
return log_dhcp_client_errno(client, errno, "Could not receive message from UDP socket: %m");
|
||||||
return -errno;
|
}
|
||||||
} else if ((size_t)len < sizeof(DHCPMessage)) {
|
if ((size_t) len < sizeof(DHCPMessage)) {
|
||||||
log_dhcp_client(client, "Too small to be a DHCP message: ignoring");
|
log_dhcp_client(client, "Too small to be a DHCP message: ignoring");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -898,7 +898,12 @@ static int client_receive_advertise(sd_dhcp6_client *client, DHCP6Message *adver
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int client_receive_message(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
|
static int client_receive_message(
|
||||||
|
sd_event_source *s,
|
||||||
|
int fd, uint32_t
|
||||||
|
revents,
|
||||||
|
void *userdata) {
|
||||||
|
|
||||||
sd_dhcp6_client *client = userdata;
|
sd_dhcp6_client *client = userdata;
|
||||||
DHCP6_CLIENT_DONT_DESTROY(client);
|
DHCP6_CLIENT_DONT_DESTROY(client);
|
||||||
_cleanup_free_ DHCP6Message *message = NULL;
|
_cleanup_free_ DHCP6Message *message = NULL;
|
||||||
@ -924,8 +929,11 @@ static int client_receive_message(sd_event_source *s, int fd, uint32_t revents,
|
|||||||
|
|
||||||
return log_dhcp6_client_errno(client, errno, "Could not receive message from UDP socket: %m");
|
return log_dhcp6_client_errno(client, errno, "Could not receive message from UDP socket: %m");
|
||||||
|
|
||||||
} else if ((size_t)len < sizeof(DHCP6Message))
|
}
|
||||||
|
if ((size_t) len < sizeof(DHCP6Message)) {
|
||||||
|
log_dhcp6_client(client, "Too small to be DHCP6 message: ignoring");
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
switch(message->type) {
|
switch(message->type) {
|
||||||
case DHCP6_SOLICIT:
|
case DHCP6_SOLICIT:
|
||||||
|
@ -366,6 +366,9 @@ static int ipv4acd_on_packet(
|
|||||||
|
|
||||||
n = recv(fd, &packet, sizeof(struct ether_arp), 0);
|
n = recv(fd, &packet, sizeof(struct ether_arp), 0);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
|
if (errno == EAGAIN || errno == EINTR)
|
||||||
|
return 0;
|
||||||
|
|
||||||
r = log_ipv4acd_debug_errno(ll, errno, "Failed to read ARP packet: %m");
|
r = log_ipv4acd_debug_errno(ll, errno, "Failed to read ARP packet: %m");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -517,9 +517,13 @@ static int ndisc_router_advertisment_recv(sd_event_source *s, int fd, uint32_t r
|
|||||||
|
|
||||||
log_ndisc(nd, "Could not receive message from ICMPv6 socket: %m");
|
log_ndisc(nd, "Could not receive message from ICMPv6 socket: %m");
|
||||||
return -errno;
|
return -errno;
|
||||||
} else if ((size_t)len < sizeof(struct nd_router_advert)) {
|
}
|
||||||
|
if ((size_t) len < sizeof(struct nd_router_advert)) {
|
||||||
|
log_ndisc(nd, "Too small to be a router advertisement: ignoring");
|
||||||
return 0;
|
return 0;
|
||||||
} else if (msg.msg_namelen == 0)
|
}
|
||||||
|
|
||||||
|
if (msg.msg_namelen == 0)
|
||||||
gw = NULL; /* only happens when running the test-suite over a socketpair */
|
gw = NULL; /* only happens when running the test-suite over a socketpair */
|
||||||
else if (msg.msg_namelen != sizeof(sa.in6)) {
|
else if (msg.msg_namelen != sizeof(sa.in6)) {
|
||||||
log_ndisc(nd, "Received invalid source address size from ICMPv6 socket: %zu bytes", (size_t)msg.msg_namelen);
|
log_ndisc(nd, "Received invalid source address size from ICMPv6 socket: %zu bytes", (size_t)msg.msg_namelen);
|
||||||
|
Loading…
Reference in New Issue
Block a user