diff mbox series

[05/11] Add hwaddr length field to interface config

Message ID 851952481e8176e31ded29bb696a050f2797b1a1.1587059210.git.weeksd2@rpi.edu
State New
Headers show
Series IB netboot 1/3: flexible hwaddrs | expand

Commit Message

Daniel M. Weeks April 16, 2020, 5:54 p.m. UTC
This field allows hardware addresses of different lengths to be stored
in in the fixed-size field hwaddr. The pb interface_config (de)serialize
functions are updated to include this new field.

Signed-off-by: Daniel M. Weeks <weeksd2@rpi.edu>
---
 lib/pb-protocol/pb-protocol.c | 8 +++++++-
 lib/types/types.h             | 5 +++--
 2 files changed, 10 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c
index dbbda40..b5186ad 100644
--- a/lib/pb-protocol/pb-protocol.c
+++ b/lib/pb-protocol/pb-protocol.c
@@ -273,7 +273,7 @@  static int pb_protocol_interface_config_len(struct interface_config *conf)
 {
 	unsigned int len;
 
-	len =	sizeof(conf->hwaddr) +
+	len =	4 + sizeof(conf->hwaddr) +
 		4 /* conf->ignore */;
 
 	if (conf->ignore)
@@ -524,6 +524,9 @@  static int pb_protocol_serialise_config_interface(char *buf,
 {
 	char *pos = buf;
 
+	*(uint32_t *)pos = __cpu_to_be32(conf->hwaddr_len);
+	pos += 4;
+
 	memcpy(pos, conf->hwaddr, sizeof(conf->hwaddr));
 	pos += sizeof(conf->hwaddr);
 
@@ -1058,6 +1061,9 @@  static int pb_protocol_deserialise_config_interface(const char **buf,
 {
 	unsigned int tmp;
 
+	if (read_u32(buf, len, &iface->hwaddr_len))
+		return -1;
+
 	if (*len < sizeof(iface->hwaddr))
 		return -1;
 
diff --git a/lib/types/types.h b/lib/types/types.h
index 9ab2a43..719332a 100644
--- a/lib/types/types.h
+++ b/lib/types/types.h
@@ -139,8 +139,9 @@  struct system_info {
 #define HWADDR_SIZE	6
 
 struct interface_config {
-	uint8_t	hwaddr[HWADDR_SIZE];
-	bool	ignore;
+	unsigned int	hwaddr_len;
+	uint8_t		hwaddr[HWADDR_SIZE];
+	bool		ignore;
 	enum {
 		CONFIG_METHOD_DHCP,
 		CONFIG_METHOD_STATIC,