[OpenPower-Firmware] [PATCH 4/7] udhcpc: Store hardware address length and type

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


Store the hardware address length and type for constructing DHCP
requests on non-MAC interfaces.

Signed-off-by: Daniel M. Weeks <weeksd2 at rpi.edu>
---
 networking/udhcp/common.h    |  2 +-
 networking/udhcp/dhcpc.c     |  8 ++++++--
 networking/udhcp/dhcpd.c     |  4 +++-
 networking/udhcp/dhcprelay.c |  4 ++--
 networking/udhcp/socket.c    | 12 ++++++++++--
 5 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index 72bdaff7b..6c7d3cc65 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -324,7 +324,7 @@ void udhcp_sp_setup(void) FAST_FUNC;
 void udhcp_sp_fd_set(struct pollfd *pfds, int extra_fd) FAST_FUNC;
 int udhcp_sp_read(void) FAST_FUNC;
 
-int udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac) FAST_FUNC;
+int udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac, uint8_t *hlen, uint8_t *htype) FAST_FUNC;
 
 int udhcp_listen_socket(/*uint32_t ip,*/ int port, const char *inf) FAST_FUNC;
 
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index c2805a009..41c1e70e5 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -1341,7 +1341,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
 	if (udhcp_read_interface(client_config.interface,
 			&client_config.ifindex,
 			NULL,
-			client_config.client_mac)
+			client_config.client_mac,
+			&client_config.client_hlen,
+			&client_config.client_htype)
 	) {
 		return 1;
 	}
@@ -1446,7 +1448,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
 			if (udhcp_read_interface(client_config.interface,
 					&client_config.ifindex,
 					NULL,
-					client_config.client_mac)
+					client_config.client_mac,
+					&client_config.client_hlen,
+					&client_config.client_htype)
 			) {
 				goto ret0; /* iface is gone? */
 			}
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index a8cd3f03b..e2bd84444 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -890,7 +890,9 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
 	if (udhcp_read_interface(server_config.interface,
 			&server_config.ifindex,
 			(server_config.server_nip == 0 ? &server_config.server_nip : NULL),
-			server_config.server_mac)
+			server_config.server_mac,
+			server_config.server_hlen,
+			server_config.server_htype)
 	) {
 		retval = 1;
 		goto ret;
diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c
index 86dcb1af0..68c9c670b 100644
--- a/networking/udhcp/dhcprelay.c
+++ b/networking/udhcp/dhcprelay.c
@@ -284,7 +284,7 @@ int dhcprelay_main(int argc UNUSED_PARAM, char **argv)
 	max_socket = init_sockets(iface_list, num_sockets, fds);
 
 	/* Get our IP on server_iface */
-	if (udhcp_read_interface(argv[2], NULL, &our_nip, NULL))
+	if (udhcp_read_interface(argv[2], NULL, &our_nip, NULL, NULL, NULL))
 		return 1;
 
 	/* Main loop */
@@ -364,7 +364,7 @@ int dhcprelay_main(int argc UNUSED_PARAM, char **argv)
 //   of the 'giaddr' field does not match one of the relay agent's
 //   directly-connected logical interfaces, the BOOTREPLY message MUST be
 //   silently discarded.
-				if (udhcp_read_interface(iface_list[i], NULL, &dhcp_msg.gateway_nip, NULL)) {
+				if (udhcp_read_interface(iface_list[i], NULL, &dhcp_msg.gateway_nip, NULL, NULL, NULL)) {
 					/* Fall back to our IP on server iface */
 // this makes more sense!
 					dhcp_msg.gateway_nip = our_nip;
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c
index 60ec0e3c0..b165d1b1c 100644
--- a/networking/udhcp/socket.c
+++ b/networking/udhcp/socket.c
@@ -27,7 +27,7 @@
 #include <ifaddrs.h>
 #include <netpacket/packet.h>
 
-int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac)
+int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac, uint8_t *hlen, uint8_t *htype)
 {
 	struct ifaddrs *ifap, *ifa;
 	struct sockaddr_ll *sll;
@@ -54,7 +54,15 @@ int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t
 			log1("IP %s", inet_ntoa(sip->sin_addr));
 		}
 
-		retval = sll->sll_hatype;
+		if (hlen) {
+			*hlen = sll->sll_halen;
+		}
+
+		if (htype) {
+			*htype = sll->sll_hatype;
+		}
+
+		retval = 0;
 	}
 	freeifaddrs(ifap);
 
-- 
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