[PATCH] gdhcp: Allow client to work on veth devices

Denis Kenzior <[email protected]>
Newsgroups dev.linux.lists.connman
Message-ID <[email protected]>
veth devices do not compute a checksum over the entire message.  They
simply pre-compute the pseudo-header portion and include this in the
checksum field.  Support such devices by computing the partial checksum.
If the partial checksum matches, accept the packet.
---
 gdhcp/client.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/gdhcp/client.c b/gdhcp/client.c
index c58c7be91143..2afa19e6e2ea 100644
--- a/gdhcp/client.c
+++ b/gdhcp/client.c
@@ -1355,8 +1355,13 @@ static int dhcp_recv_l2_packet(struct dhcp_packet *dhcp_pkt, int fd,
 	packet.ip.tot_len = packet.udp.len; /* yes, this is needed */
 	check = packet.udp.check;
 	packet.udp.check = 0;
-	if (check && check != dhcp_checksum(&packet, bytes))
-		return -1;
+
+	if (check) {
+		uint16_t partial = ~dhcp_checksum(&packet, sizeof(struct iphdr));
+
+		if (check != partial && check != dhcp_checksum(&packet, bytes))
+			return -1;
+	}
 
 	memcpy(dhcp_pkt, &packet.data, bytes - (sizeof(packet.ip) +
 							sizeof(packet.udp)));
-- 
2.44.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.