[OpenPower-Firmware] [PATCH 5/7] udhcpc: Support sending DHCP requests on IB

Daniel M. Weeks weeksd2 at rpi.edu
Fri Apr 17 06:19:28 AEST 2020


Signed-off-by: Daniel M. Weeks <weeksd2 at rpi.edu>
---
 networking/udhcp/common.h |  2 +-
 networking/udhcp/dhcpc.c  | 11 +++++++++--
 networking/udhcp/dhcpd.c  |  2 +-
 networking/udhcp/packet.c | 25 +++++++++++++++----------
 4 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index 6c7d3cc65..d9cbf3b53 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -314,7 +314,7 @@ int udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd) FAST_FUNC;
 int udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
 		uint32_t source_nip, int source_port,
 		uint32_t dest_nip, int dest_port, const uint8_t *dest_arp,
-		int ifindex) FAST_FUNC;
+		int ifindex, uint8_t hlen, uint8_t htype) FAST_FUNC;
 
 int udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
 		uint32_t source_nip, int source_port,
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 41c1e70e5..95f738841 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -685,10 +685,17 @@ static void add_client_options(struct dhcp_packet *packet)
 
 static int raw_bcast_from_client_config_ifindex(struct dhcp_packet *packet, uint32_t src_nip)
 {
+	const uint8_t *bcast_addr;
+
+	if (client_config.client_htype == ARPHRD_INFINIBAND)
+		bcast_addr = IB_BCAST_ADDR;
+	else
+		bcast_addr = MAC_BCAST_ADDR;
+
 	return udhcp_send_raw_packet(packet,
 		/*src*/ src_nip, CLIENT_PORT,
-		/*dst*/ INADDR_BROADCAST, SERVER_PORT, MAC_BCAST_ADDR,
-		client_config.ifindex);
+		/*dst*/ INADDR_BROADCAST, SERVER_PORT, bcast_addr,
+		client_config.ifindex, client_config.client_hlen, client_config.client_htype);
 }
 
 static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t server)
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index e2bd84444..7809d3223 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -581,7 +581,7 @@ static void send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadc
 	udhcp_send_raw_packet(dhcp_pkt,
 		/*src*/ server_config.server_nip, SERVER_PORT,
 		/*dst*/ ciaddr, CLIENT_PORT, chaddr,
-		server_config.ifindex);
+		server_config.ifindex, 6, HTYPE_ETHER);
 }
 
 /* Send a packet to gateway_nip using the kernel ip stack */
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index ff16904f7..530b5c2a1 100644
--- a/networking/udhcp/packet.c
+++ b/networking/udhcp/packet.c
@@ -105,9 +105,13 @@ int FAST_FUNC udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd)
 int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
 		uint32_t source_nip, int source_port,
 		uint32_t dest_nip, int dest_port, const uint8_t *dest_arp,
-		int ifindex)
+		int ifindex, uint8_t hlen, uint8_t hatype)
 {
-	struct sockaddr_ll dest_sll;
+	union {
+		struct sockaddr_ll dest_sll;
+		struct sockaddr_storage ss;
+	} su;
+
 	struct ip_udp_dhcp_packet packet;
 	unsigned padding;
 	int fd;
@@ -120,19 +124,20 @@ int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
 		goto ret_msg;
 	}
 
-	memset(&dest_sll, 0, sizeof(dest_sll));
+	memset(&su, 0, sizeof(su));
 	memset(&packet, 0, offsetof(struct ip_udp_dhcp_packet, data));
 	packet.data = *dhcp_pkt; /* struct copy */
 
-	dest_sll.sll_family = AF_PACKET;
-	dest_sll.sll_protocol = htons(ETH_P_IP);
-	dest_sll.sll_ifindex = ifindex;
+	su.dest_sll.sll_family = AF_PACKET;
+	su.dest_sll.sll_protocol = htons(ETH_P_IP);
+	su.dest_sll.sll_ifindex = ifindex;
 	/*dest_sll.sll_hatype = ARPHRD_???;*/
 	/*dest_sll.sll_pkttype = PACKET_???;*/
-	dest_sll.sll_halen = 6;
-	memcpy(dest_sll.sll_addr, dest_arp, 6);
+	su.dest_sll.sll_hatype = htons(hatype);
+	su.dest_sll.sll_halen = hlen;
+	memcpy(&su.dest_sll.sll_addr, dest_arp, hlen);
 
-	if (bind(fd, (struct sockaddr *)&dest_sll, sizeof(dest_sll)) < 0) {
+	if (bind(fd, (struct sockaddr *)&su.dest_sll, sizeof(su.dest_sll)) < 0) {
 		msg = "bind(%s)";
 		goto ret_close;
 	}
@@ -175,7 +180,7 @@ int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
 
 	udhcp_dump_packet(dhcp_pkt);
 	result = sendto(fd, &packet, IP_UDP_DHCP_SIZE - padding, /*flags:*/ 0,
-			(struct sockaddr *) &dest_sll, sizeof(dest_sll));
+			(struct sockaddr *) &su.ss, sizeof(su));
 	msg = "sendto";
  ret_close:
 	close(fd);
-- 
Daniel M. Weeks


-- 
Daniel M. Weeks
Lead HPC Developer
Center for Computational Innovations
Rensselaer Polytechnic Institute
Troy, NY 12180
518-276-4458


More information about the OpenPower-Firmware mailing list