[SLOF] [PATCH v3 1/8] libnet: Pass ip_version via struct filename_ip

Thomas Huth thuth at redhat.com
Sat May 26 16:06:01 AEST 2018


When we will support loading of pxelinux.cfg files later, we have to call
the tftp load function multiple times from different places. To avoid that
we've also got to pass around the ip_version information via function para-
meters to all spots, let's rather put it into struct filename_ip instead
since we've got this struct filename_ip info available everywhere already.

While we're at it, also drop the  __attribute__((packed)) from the struct.
The struct is only used internally, without exchanging it with the outside
world, so the attribute is certainly not necessary here.

Signed-off-by: Thomas Huth <thuth at redhat.com>
---
 lib/libnet/netload.c | 11 ++++++-----
 lib/libnet/tftp.c    |  4 ++--
 lib/libnet/tftp.h    | 10 +++++-----
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/lib/libnet/netload.c b/lib/libnet/netload.c
index 8dca654..bce9bb7 100644
--- a/lib/libnet/netload.c
+++ b/lib/libnet/netload.c
@@ -404,13 +404,13 @@ static void seed_rng(uint8_t mac[])
 	srand(seed);
 }
 
-static int tftp_load(filename_ip_t *fnip, unsigned char *buffer, int len,
-		     unsigned int retries, int ip_vers)
+static int tftp_load(filename_ip_t *fnip, void *buffer, int len,
+                     unsigned int retries)
 {
 	tftp_err_t tftp_err;
 	int rc;
 
-	rc = tftp(fnip, buffer, len, retries, &tftp_err, ip_vers);
+	rc = tftp(fnip, buffer, len, retries, &tftp_err);
 
 	if (rc > 0) {
 		printf("  TFTP: Received %s (%d KBytes)\n", fnip->filename,
@@ -737,6 +737,8 @@ int netload(char *buffer, int len, char *args_fs, int alen)
 		fn_ip.filename[sizeof(fn_ip.filename)-1] = 0;
 	}
 
+	fn_ip.ip_version = ip_version;
+
 	if (ip_version == 4) {
 		printf("  Requesting file \"%s\" via TFTP from %d.%d.%d.%d\n",
 			fn_ip.filename,
@@ -752,8 +754,7 @@ int netload(char *buffer, int len, char *args_fs, int alen)
 	}
 
 	/* Do the TFTP load and print error message if necessary */
-	rc = tftp_load(&fn_ip, (unsigned char *)buffer, len,
-		       obp_tftp_args.tftp_retries, ip_version);
+	rc = tftp_load(&fn_ip, buffer, len, obp_tftp_args.tftp_retries);
 
 	if (obp_tftp_args.ip_init == IP_INIT_DHCP)
 		dhcp_send_release(fn_ip.fd);
diff --git a/lib/libnet/tftp.c b/lib/libnet/tftp.c
index 5e7951f..302c8f4 100644
--- a/lib/libnet/tftp.c
+++ b/lib/libnet/tftp.c
@@ -501,12 +501,12 @@ void handle_tftp_dun(uint8_t err_code)
  *                       NON ZERO - size of received file
  */
 int tftp(filename_ip_t * _fn_ip, unsigned char *_buffer, int _len,
-	 unsigned int _retries, tftp_err_t * _tftp_err, int _ip_version)
+	 unsigned int _retries, tftp_err_t * _tftp_err)
 {
 	retries     = _retries;
 	fn_ip       = _fn_ip;
 	len         = _len;
-	ip_version  = _ip_version;
+	ip_version  = _fn_ip->ip_version;
 	tftp_errno  = 0;
 	tftp_err    = _tftp_err;
 	tftp_err->bad_tftp_packets = 0;
diff --git a/lib/libnet/tftp.h b/lib/libnet/tftp.h
index a09cf71..c30fe78 100644
--- a/lib/libnet/tftp.h
+++ b/lib/libnet/tftp.h
@@ -29,8 +29,9 @@ struct filename_ip {
 	ip6_addr_t server_ip6;
 	ip6_addr_t dns_ip6;
 	char filename[256];
-	int    fd;
-} __attribute__ ((packed));
+	int fd;
+	int ip_version;
+};
 typedef struct filename_ip filename_ip_t;
 
 typedef struct {
@@ -40,9 +41,8 @@ typedef struct {
 	uint32_t blocks_received;
 } tftp_err_t;
 
-int tftp(filename_ip_t *, unsigned char  *, int, unsigned int,
-         tftp_err_t *, int ip_version);
-
+int tftp(filename_ip_t *fnip, unsigned char *buf, int len,
+         unsigned int retries, tftp_err_t *err);
 int32_t handle_tftp(int fd, uint8_t *, int32_t);
 void handle_tftp_dun(uint8_t err_code);
 int parse_tftp_args(char buffer[], char *server_ip, char filename[], int fd, int len);
-- 
1.8.3.1



More information about the SLOF mailing list