[syslinux:pathbased] Changes missing from previous checkin

syslinux-bot for H. Peter Anvin hpa at zytor.com
Sun Mar 7 21:30:07 PST 2010


Commit-ID:  63131163a0cf623582dc92e26eddc0e0a7f0d923
Gitweb:     http://syslinux.zytor.com/commit/63131163a0cf623582dc92e26eddc0e0a7f0d923
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Sun, 7 Mar 2010 21:27:15 -0800
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Sun, 7 Mar 2010 21:27:15 -0800

Changes missing from previous checkin

Add files missing from previous checkin...

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 com32/include/syslinux/pxe_api.h |    5 +++
 core/fs/pxe/dnsresolv.c          |   22 +++++++++---
 core/fs/pxe/pxe.c                |   66 ++++++++++++++------------------------
 core/fs/pxe/pxe.h                |    6 ++-
 4 files changed, 49 insertions(+), 50 deletions(-)

diff --git a/com32/include/syslinux/pxe_api.h b/com32/include/syslinux/pxe_api.h
index fcc4f87..27166b0 100644
--- a/com32/include/syslinux/pxe_api.h
+++ b/com32/include/syslinux/pxe_api.h
@@ -403,6 +403,11 @@ typedef struct s_PXENV_FILE_OPEN {
     uint32_t Reserved;
 } __packed t_PXENV_FILE_OPEN;
 
+typedef struct s_PXENV_FILE_CLOSE {
+    pxenv_status_t Status;
+    uint16_t FileHandle;
+} __packed t_PXENV_FILE_CLOSE;
+
 typedef struct s_PXENV_GET_FILE_SIZE {
     pxenv_status_t Status;
     uint16_t FileHandle;
diff --git a/core/fs/pxe/dnsresolv.c b/core/fs/pxe/dnsresolv.c
index 18cfc48..df7f33c 100644
--- a/core/fs/pxe/dnsresolv.c
+++ b/core/fs/pxe/dnsresolv.c
@@ -191,6 +191,11 @@ uint32_t dns_resolv(const char *name)
     struct dnsrr *rr;
     static __lowmem struct s_PXENV_UDP_WRITE udp_write;
     static __lowmem struct s_PXENV_UDP_READ udp_read;
+    uint16_t local_port;
+    uint32_t result = 0;
+
+    /* Get a local port number */
+    local_port = get_port();
 
     /* First, fill the DNS header struct */
     hd1->id++;                      /* New query ID */
@@ -225,7 +230,7 @@ uint32_t dns_resolv(const char *name)
         udp_write.status      = 0;
         udp_write.ip          = srv;
         udp_write.gw          = ((srv ^ MyIP) & net_mask) ? gate_way : 0;
-        udp_write.src_port    = DNS_LOCAL_PORT;
+        udp_write.src_port    = local_port;
         udp_write.dst_port    = DNS_PORT;
         udp_write.buffer_size = p - DNSSendBuf;
         udp_write.buffer      = FAR_PTR(DNSSendBuf);
@@ -239,7 +244,7 @@ uint32_t dns_resolv(const char *name)
             udp_read.src_ip      = srv;
             udp_read.dest_ip     = MyIP;
             udp_read.s_port      = DNS_PORT;
-            udp_read.d_port      = DNS_LOCAL_PORT;
+            udp_read.d_port      = local_port;
             udp_read.buffer_size = DNS_MAX_PACKET;
             udp_read.buffer      = FAR_PTR(DNSRecvBuf);
             err = pxe_call(PXENV_UDP_READ, &udp_read);
@@ -254,7 +259,7 @@ uint32_t dns_resolv(const char *name)
 		/* time out */
 		timeout = *timeout_ptr++;
 		if (!timeout)
-		    return 0;     /* All time ticks run out */
+		    goto done;	/* All time ticks run out */
 		else 
 		    goto again;
 	    }
@@ -280,8 +285,10 @@ uint32_t dns_resolv(const char *name)
             if (same && ntohs(rr->class) == CLASS_IN) {
 		switch (ntohs(rr->type)) {
 		case TYPE_A:
-		    if (rd_len == 4)
-			return *(uint32_t *)rr->rdata;
+		    if (rd_len == 4) {
+			result = *(uint32_t *)rr->rdata;
+			goto done;
+		    }
 		    break;
 		case TYPE_CNAME:
 		    dns_copylabel(DNSSendBuf + sizeof(struct dnshdr),
@@ -327,7 +334,10 @@ uint32_t dns_resolv(const char *name)
 	continue;
     }
 
-    return 0;
+done:
+    free_port(local_port);	/* Return port number to the free pool */
+
+    return result;
 }
     
     
diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c
index 0bc9b36..011ef29 100644
--- a/core/fs/pxe/pxe.c
+++ b/core/fs/pxe/pxe.c
@@ -30,12 +30,6 @@ static uint32_t gpxe_funcs;
 static uint8_t uuid_dashes[] = {4, 2, 2, 2, 6, 0};
 bool have_uuid = false;
 
-/* Port number bitmap - port numbers 49152 (0xc000) to 57343 (0xefff) */
-#define PORT_NUMBER_BASE	49152
-#define PORT_NUMBER_COUNT	8192 /* Power of 2, please */
-static uint32_t port_number_bitmap[PORT_NUMBER_COUNT/32];
-static uint16_t first_port_number /* = 0 */;
-
 /* Common receive buffer */
 static __lowmem char packet_buf[PKTBUF_SIZE] __aligned(16);
 
@@ -64,26 +58,6 @@ static void tftp_error(struct inode *file, uint16_t errnum,
 		       const char *errstr);
 
 /*
- * Bitmap functions
- */
-static bool test_bit(const uint32_t *bitmap, int32_t index)
-{
-    uint8_t st;
-    asm("btl %2,%1 ; setc %0" : "=qm" (st) : "m" (*bitmap), "r" (index));
-    return st;
-}
-
-static void set_bit(uint32_t *bitmap, int32_t index)
-{
-    asm volatile("btsl %1,%0" : "+m" (*bitmap) : "r" (index) : "memory");
-}
-
-static void clr_bit(uint32_t *bitmap, int32_t index)
-{
-    asm volatile("btcl %1,%0" : "+m" (*bitmap) : "r" (index) : "memory");
-}
-
-/*
  * Allocate a local UDP port structure and assign it a local port number.
  * Return the inode pointer if success, or null if failure
  */
@@ -95,15 +69,7 @@ static struct inode *allocate_socket(struct fs_info *fs)
 	malloc_error("socket structure");
     } else {
 	struct pxe_pvt_inode *socket = PVT(inode);
-	uint16_t port;
-
-	do {
-	    port = first_port_number++;
-	    first_port_number &= PORT_NUMBER_COUNT - 1;
-	} while (test_bit(port_number_bitmap, port));
-
-	set_bit(port_number_bitmap, port);
-	socket->tftp_localport = htons(port + PORT_NUMBER_BASE);
+	socket->tftp_localport = get_port();
     }
 
     return inode;
@@ -113,20 +79,36 @@ static void free_socket(struct inode *inode)
 {
     struct pxe_pvt_inode *socket = PVT(inode);
 
-    clr_bit(port_number_bitmap,
-	    ntohs(socket->tftp_localport) - PORT_NUMBER_BASE);
+    free_port(socket->tftp_localport);
     free_inode(inode);
 }
 
+#if GPXE
+static void gpxe_close_file(struct inode *inode)
+{
+    struct pxe_pvt_inode *socket = PVT(inode);
+    static __lowmem struct s_PXENV_FILE_CLOSE file_close;
+
+    file_close.FileHandle = socket->tftp_remoteport;
+    pxe_call(PXENV_FILE_CLOSE, &file_close);
+}
+#endif
+
 static void pxe_close_file(struct file *file)
 {
     struct inode *inode = file->inode;
     struct pxe_pvt_inode *socket = PVT(inode);
 
-    /* XXX: handle gPXE close */
-
-    if (socket->tftp_localport && !socket->tftp_goteof)
-	tftp_error(inode, 0, "No error, file close");
+    if (!socket->tftp_goteof) {
+#if GPXE
+	if (socket->tftp_localport == 0xffff) {
+	    gpxe_close_file(inode);
+	} else
+#endif
+	if (socket->tftp_localport != 0) {
+	    tftp_error(inode, 0, "No error, file close");
+	}
+    }
 
     free_socket(inode);
 }
@@ -470,7 +452,7 @@ static void get_packet_gpxe(struct inode *inode)
 
     /* Got EOF, close it */
     socket->tftp_goteof = 1;
-    pxe_call(PXENV_FILE_CLOSE, &file_read);
+    gpxe_close_file(inode);
 }
 #endif /* GPXE */
 
diff --git a/core/fs/pxe/pxe.h b/core/fs/pxe/pxe.h
index 493d276..e801aea 100644
--- a/core/fs/pxe/pxe.h
+++ b/core/fs/pxe/pxe.h
@@ -76,8 +76,6 @@ static inline int hexval(char c)
 /* Defines for DNS */
 #define DNS_PORT	htons(53)		/* Default DNS port */
 #define DNS_MAX_PACKET	512			/* Defined by protocol */
-/* All local DNS queries come from this port */
-#define DNS_LOCAL_PORT	htons(60053) 
 #define DNS_MAX_SERVERS 4			/* Max no of DNS servers */
 
 
@@ -231,4 +229,8 @@ uint32_t dns_resolv(const char *);
 void pxe_idle_init(void);
 void pxe_idle_cleanup(void);
 
+/* socknum.c */
+uint16_t get_port(void);
+void free_port(uint16_t port);
+
 #endif /* pxe.h */



More information about the Syslinux-commits mailing list