[PATCH] dhcpc: Check for kernel support for PACKET_AUXDATA

Dan Moulding dan.moulding at rackwareinc.com
Tue Apr 29 14:37:17 UTC 2014


Rather than simply assuming that the kernel supports
PACKET_AUXDATA, check to see if it is defined before trying
to use it.

Signed-off-by: Dan Moulding <dan.moulding at rackwareinc.com>
---
 networking/udhcp/dhcpc.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 7dfc160..052ad86 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -845,10 +845,13 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
 	int bytes;
 	struct ip_udp_dhcp_packet packet;
 	uint16_t check;
-	unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
 	struct iovec iov;
 	struct msghdr msg;
+
+#ifdef PACKET_AUXDATA
+	unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
 	struct cmsghdr *cmsg;
+#endif
 
 	/* used to use just safe_read(fd, &packet, sizeof(packet))
 	 * but we need to check for TP_STATUS_CSUMNOTREADY :(
@@ -858,8 +861,12 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
 	memset(&msg, 0, sizeof(msg));
 	msg.msg_iov = &iov;
 	msg.msg_iovlen = 1;
+
+#ifdef PACKET_AUXDATA
 	msg.msg_control = cmsgbuf;
 	msg.msg_controllen = sizeof(cmsgbuf);
+#endif
+
 	for (;;) {
 		bytes = recvmsg(fd, &msg, 0);
 		if (bytes < 0) {
@@ -906,6 +913,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
 		return -2;
 	}
 
+#ifdef PACKET_AUXDATA
 	for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
 		if (cmsg->cmsg_level == SOL_PACKET
 		 && cmsg->cmsg_type == PACKET_AUXDATA
@@ -919,6 +927,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
 				goto skip_udp_sum_check;
 		}
 	}
+#endif
 
 	/* verify UDP checksum. IP header has to be modified for this */
 	memset(&packet.ip, 0, offsetof(struct iphdr, protocol));
@@ -930,7 +939,10 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
 		log1("Packet with bad UDP checksum received, ignoring");
 		return -2;
 	}
+
+#ifdef PACKET_AUXDATA
  skip_udp_sum_check:
+#endif
 
 	if (packet.data.cookie != htonl(DHCP_MAGIC)) {
 		bb_info_msg("Packet with bad magic, ignoring");
@@ -1043,12 +1055,14 @@ static int udhcp_raw_socket(int ifindex)
 	}
 #endif
 
+#ifdef PACKET_AUXDATA
 	if (setsockopt(fd, SOL_PACKET, PACKET_AUXDATA,
 			&const_int_1, sizeof(int)) < 0
 	) {
 		if (errno != ENOPROTOOPT)
 			log1("Can't set PACKET_AUXDATA on raw socket");
 	}
+#endif
 
 	log1("Created raw socket");
 
-- 
1.8.2.1



More information about the busybox mailing list