diff options
Diffstat (limited to 'src/libsystemd-network/sd-dhcp-server.c')
-rw-r--r-- | src/libsystemd-network/sd-dhcp-server.c | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index 15a0145959..05c0cddfd0 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -407,7 +407,7 @@ static int dhcp_server_send_udp(sd_dhcp_server *server, be32_t destination, rather than binding the socket. This will be mostly useful when we gain support for arbitrary number of server addresses */ - pktinfo = (struct in_pktinfo*) CMSG_DATA(cmsg); + pktinfo = CMSG_TYPED_DATA(cmsg, struct in_pktinfo); assert(pktinfo); pktinfo->ipi_ifindex = server->ifindex; @@ -1270,7 +1270,6 @@ static int server_receive_message(sd_event_source *s, int fd, .msg_control = &control, .msg_controllen = sizeof(control), }; - struct cmsghdr *cmsg; ssize_t datagram_size, len; int r; @@ -1306,19 +1305,10 @@ static int server_receive_message(sd_event_source *s, int fd, if ((size_t) len < sizeof(DHCPMessage)) return 0; - CMSG_FOREACH(cmsg, &msg) - if (cmsg->cmsg_level == IPPROTO_IP && - cmsg->cmsg_type == IP_PKTINFO && - cmsg->cmsg_len == CMSG_LEN(sizeof(struct in_pktinfo))) { - struct in_pktinfo *info = CMSG_TYPED_DATA(cmsg, struct in_pktinfo); - - /* TODO figure out if this can be done as a filter on - * the socket, like for IPv6 */ - if (server->ifindex != info->ipi_ifindex) - return 0; - - break; - } + /* TODO figure out if this can be done as a filter on the socket, like for IPv6 */ + struct in_pktinfo *info = CMSG_FIND_DATA(&msg, IPPROTO_IP, IP_PKTINFO, struct in_pktinfo); + if (info && info->ipi_ifindex != server->ifindex) + return 0; if (sd_dhcp_server_is_in_relay_mode(server)) { r = dhcp_server_relay_message(server, message, len - sizeof(DHCPMessage), buflen); |