mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-10 01:17:44 +03:00
tree-wide: use cmsg_find() helper at various places where appropriate
This commit is contained in:
parent
0f4a141744
commit
dac556fa7b
@ -887,7 +887,7 @@ ssize_t receive_one_fd_iov(
|
||||
.msg_iov = iov,
|
||||
.msg_iovlen = iovlen,
|
||||
};
|
||||
struct cmsghdr *cmsg, *found = NULL;
|
||||
struct cmsghdr *found;
|
||||
ssize_t k;
|
||||
|
||||
assert(transport_fd >= 0);
|
||||
@ -905,16 +905,7 @@ ssize_t receive_one_fd_iov(
|
||||
if (k < 0)
|
||||
return k;
|
||||
|
||||
CMSG_FOREACH(cmsg, &mh) {
|
||||
if (cmsg->cmsg_level == SOL_SOCKET &&
|
||||
cmsg->cmsg_type == SCM_RIGHTS &&
|
||||
cmsg->cmsg_len == CMSG_LEN(sizeof(int))) {
|
||||
assert(!found);
|
||||
found = cmsg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
found = cmsg_find(&mh, SOL_SOCKET, SCM_RIGHTS, CMSG_LEN(sizeof(int)));
|
||||
if (!found) {
|
||||
cmsg_close_all(&mh);
|
||||
|
||||
|
@ -921,19 +921,11 @@ static int process_socket(int fd) {
|
||||
/* The final zero-length datagram carries the file descriptor and tells us
|
||||
* that we're done. */
|
||||
if (n == 0) {
|
||||
struct cmsghdr *cmsg, *found = NULL;
|
||||
struct cmsghdr *found;
|
||||
|
||||
free(iovec.iov_base);
|
||||
|
||||
CMSG_FOREACH(cmsg, &mh) {
|
||||
if (cmsg->cmsg_level == SOL_SOCKET &&
|
||||
cmsg->cmsg_type == SCM_RIGHTS &&
|
||||
cmsg->cmsg_len == CMSG_LEN(sizeof(int))) {
|
||||
assert(!found);
|
||||
found = cmsg;
|
||||
}
|
||||
}
|
||||
|
||||
found = cmsg_find(&mh, SOL_SOCKET, SCM_RIGHTS, CMSG_LEN(sizeof(int)));
|
||||
if (!found) {
|
||||
cmsg_close_all(&mh);
|
||||
r = log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
|
||||
|
@ -1937,15 +1937,11 @@ static int client_receive_message_raw(
|
||||
} else if ((size_t)len < sizeof(DHCPPacket))
|
||||
return 0;
|
||||
|
||||
CMSG_FOREACH(cmsg, &msg)
|
||||
if (cmsg->cmsg_level == SOL_PACKET &&
|
||||
cmsg->cmsg_type == PACKET_AUXDATA &&
|
||||
cmsg->cmsg_len == CMSG_LEN(sizeof(struct tpacket_auxdata))) {
|
||||
struct tpacket_auxdata *aux = (struct tpacket_auxdata*)CMSG_DATA(cmsg);
|
||||
|
||||
checksum = !(aux->tp_status & TP_STATUS_CSUMNOTREADY);
|
||||
break;
|
||||
}
|
||||
cmsg = cmsg_find(&msg, SOL_PACKET, PACKET_AUXDATA, CMSG_LEN(sizeof(struct tpacket_auxdata)));
|
||||
if (cmsg) {
|
||||
struct tpacket_auxdata *aux = (struct tpacket_auxdata*) CMSG_DATA(cmsg);
|
||||
checksum = !(aux->tp_status & TP_STATUS_CSUMNOTREADY);
|
||||
}
|
||||
|
||||
r = dhcp_packet_verify_headers(packet, len, checksum, client->port);
|
||||
if (r < 0)
|
||||
|
@ -238,7 +238,7 @@ int socket_write_message(sd_netlink *nl, sd_netlink_message *m) {
|
||||
return k;
|
||||
}
|
||||
|
||||
static int socket_recv_message(int fd, struct iovec *iov, uint32_t *_group, bool peek) {
|
||||
static int socket_recv_message(int fd, struct iovec *iov, uint32_t *ret_mcast_group, bool peek) {
|
||||
union sockaddr_union sender;
|
||||
uint8_t cmsg_buffer[CMSG_SPACE(sizeof(struct nl_pktinfo))];
|
||||
struct msghdr msg = {
|
||||
@ -249,8 +249,6 @@ static int socket_recv_message(int fd, struct iovec *iov, uint32_t *_group, bool
|
||||
.msg_control = cmsg_buffer,
|
||||
.msg_controllen = sizeof(cmsg_buffer),
|
||||
};
|
||||
struct cmsghdr *cmsg;
|
||||
uint32_t group = 0;
|
||||
ssize_t n;
|
||||
|
||||
assert(fd >= 0);
|
||||
@ -281,20 +279,16 @@ static int socket_recv_message(int fd, struct iovec *iov, uint32_t *_group, bool
|
||||
return 0;
|
||||
}
|
||||
|
||||
CMSG_FOREACH(cmsg, &msg) {
|
||||
if (cmsg->cmsg_level == SOL_NETLINK &&
|
||||
cmsg->cmsg_type == NETLINK_PKTINFO &&
|
||||
cmsg->cmsg_len == CMSG_LEN(sizeof(struct nl_pktinfo))) {
|
||||
struct nl_pktinfo *pktinfo = (void *)CMSG_DATA(cmsg);
|
||||
if (ret_mcast_group) {
|
||||
struct cmsghdr *cmsg;
|
||||
|
||||
/* multi-cast group */
|
||||
group = pktinfo->group;
|
||||
}
|
||||
cmsg = cmsg_find(&msg, SOL_NETLINK, NETLINK_PKTINFO, CMSG_LEN(sizeof(struct nl_pktinfo)));
|
||||
if (ret_mcast_group)
|
||||
*ret_mcast_group = ((struct nl_pktinfo*) CMSG_DATA(cmsg))->group;
|
||||
else
|
||||
*ret_mcast_group = 0;
|
||||
}
|
||||
|
||||
if (_group)
|
||||
*_group = group;
|
||||
|
||||
return (int) n;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user