summaryrefslogtreecommitdiff
path: root/src/libsystemd-dhcp/sd-dhcp-client.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-02-24 01:09:21 +0100
committerTom Gundersen <teg@jklm.no>2014-02-24 03:28:19 +0100
commit55dab2ed837c17236b7df12decaffbc4388d1dff (patch)
tree44b39f61128131327baf3311277d4694311b7446 /src/libsystemd-dhcp/sd-dhcp-client.c
parent872c2ab3e2887c1c2b6c9815a201683e246e56fc (diff)
sd-dhcp-client: respect TP_STATUS_CSUMNOTREADY
If an UDP packet has not passed through a hardware device, its checksum may not have been computed. This is exposed through the TP_STATUS_CSUMNOTREADY sockopt. When using raw sockets, skip checksum validation when TP_STATUS_CSUMNOTREADY is set. This is necessary for dhcp to work directly over a veth tunnel, e.g. as done in systemd-nspawn.
Diffstat (limited to 'src/libsystemd-dhcp/sd-dhcp-client.c')
-rw-r--r--src/libsystemd-dhcp/sd-dhcp-client.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index ee6e89eacb..0c82260dfd 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -886,8 +886,18 @@ static int client_receive_message_raw(sd_event_source *s, int fd,
uint32_t revents, void *userdata) {
sd_dhcp_client *client = userdata;
_cleanup_free_ DHCPPacket *packet = NULL;
- int buflen = 0, len, r;
usec_t time_now;
+ uint8_t cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
+ struct iovec iov = {};
+ struct msghdr msg = {
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_control = cmsgbuf,
+ .msg_controllen = sizeof(cmsgbuf),
+ };
+ struct cmsghdr *cmsg;
+ bool checksum = true;
+ int buflen = 0, len, r;
assert(s);
assert(client);
@@ -901,11 +911,26 @@ static int client_receive_message_raw(sd_event_source *s, int fd,
if (!packet)
return -ENOMEM;
- len = read(fd, packet, buflen);
- if (len < 0)
+ iov.iov_base = packet;
+ iov.iov_len = buflen;
+
+ len = recvmsg(fd, &msg, 0);
+ if (len < 0) {
+ log_dhcp_client(client, "could not receive message from raw "
+ "socket: %s", strerror(errno));
return 0;
+ }
+
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ if (cmsg->cmsg_level == SOL_PACKET && cmsg->cmsg_type == PACKET_AUXDATA) {
+ struct tpacket_auxdata *aux = (void *)CMSG_DATA(cmsg);
+
+ checksum = !(aux->tp_status & TP_STATUS_CSUMNOTREADY);
+ break;
+ }
+ }
- r = dhcp_packet_verify_headers(packet, len);
+ r = dhcp_packet_verify_headers(packet, len, checksum);
if (r < 0)
return 0;