diff options
author | H. Peter Anvin <hpa@zytor.com> | 2011-04-24 15:16:23 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2011-04-24 15:16:23 -0700 |
commit | 0502b06c879cace4c5a27698f8ec8d8bad8e075a (patch) | |
tree | 6c42dd41b1fbe91c259cb01bd914486c2db6936d | |
parent | 2061baaf73bbb5f83e675552d6097693da200eef (diff) | |
download | syslinux-4.10-pre3.tar.gz |
pxe, tftp: let lwIP manage port numberssyslinux-4.10-pre3
lwIP needs to manage port numbers for TCP and for DNS, so just let it
do it for TFTP as well.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r-- | core/fs/pxe/portnum.c | 68 | ||||
-rw-r--r-- | core/fs/pxe/pxe.c | 3 | ||||
-rw-r--r-- | core/fs/pxe/pxe.h | 9 | ||||
-rw-r--r-- | core/fs/pxe/tftp.c | 9 |
4 files changed, 7 insertions, 82 deletions
diff --git a/core/fs/pxe/portnum.c b/core/fs/pxe/portnum.c deleted file mode 100644 index 19af0cd0..00000000 --- a/core/fs/pxe/portnum.c +++ /dev/null @@ -1,68 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2010 Intel Corporation; author: H. Peter Anvin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston MA 02110-1301, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -#include <stdint.h> -#include <stdbool.h> -#include <netinet/in.h> -#include "pxe.h" - -/* 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 */; - -/* - * 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"); -} - -/* - * Get and free a port number (host byte order) - */ -uint16_t get_port(void) -{ - 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); - return htons(port + PORT_NUMBER_BASE); -} - -void free_port(uint16_t port) -{ - port = ntohs(port) - PORT_NUMBER_BASE; - - if (port >= PORT_NUMBER_COUNT) - return; - - clr_bit(port_number_bitmap, port); -} diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c index 939ce719..2bcb27f5 100644 --- a/core/fs/pxe/pxe.c +++ b/core/fs/pxe/pxe.c @@ -56,8 +56,6 @@ static struct inode *allocate_socket(struct fs_info *fs) if (!inode) { malloc_error("socket structure"); } else { - struct pxe_pvt_inode *socket = PVT(inode); - socket->tftp_localport = get_port(); inode->mode = DT_REG; /* No other types relevant for PXE */ } @@ -69,7 +67,6 @@ void free_socket(struct inode *inode) struct pxe_pvt_inode *socket = PVT(inode); free(socket->tftp_pktbuf); /* If we allocated a buffer, free it now */ - free_port(socket->tftp_localport); free_inode(inode); } diff --git a/core/fs/pxe/pxe.h b/core/fs/pxe/pxe.h index 841e5ef4..9dec35e2 100644 --- a/core/fs/pxe/pxe.h +++ b/core/fs/pxe/pxe.h @@ -127,10 +127,9 @@ struct netbuf; struct pxe_pvt_inode { struct netconn *conn; /* lwip network connection */ struct netbuf *buf; /* lwip cached buffer */ - uint16_t tftp_localport; /* Local port number (0=not in us)*/ uint16_t tftp_remoteport; /* Remote port number */ - uint32_t tftp_remoteip; /* Remote IP address */ - uint32_t tftp_filepos; /* bytes downloaded (includeing buffer) */ + uint32_t tftp_remoteip; /* Remote IP address (0 = disconnected) */ + uint32_t tftp_filepos; /* bytes downloaded (including buffer) */ uint32_t tftp_blksize; /* Block size for this connection(*) */ uint16_t tftp_bytesleft; /* Unclaimed data bytes */ uint16_t tftp_lastpkt; /* Sequence number of last packet (NBO) */ @@ -239,10 +238,6 @@ 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); - /* tftp.c */ void tftp_open(struct url_info *url, struct inode *inode, const char **redir); diff --git a/core/fs/pxe/tftp.c b/core/fs/pxe/tftp.c index 77efe49a..e7a6e01a 100644 --- a/core/fs/pxe/tftp.c +++ b/core/fs/pxe/tftp.c @@ -30,7 +30,7 @@ static void tftp_error(struct inode *file, uint16_t errnum, static void tftp_close_file(struct inode *inode) { struct pxe_pvt_inode *socket = PVT(inode); - if (socket->tftp_localport != 0) { + if (socket->tftp_remoteip) { tftp_error(inode, 0, "No error, file close"); } if (socket->conn) { @@ -242,22 +242,23 @@ void tftp_open(struct url_info *url, struct inode *inode, const char **redir) */ url_unescape(url->path, ';'); } + if (!url->port) url->port = TFTP_PORT; socket->fill_buffer = tftp_get_packet; socket->close = tftp_close_file; - socket->conn = netconn_new(NETCONN_UDP); if (!socket->conn) return; socket->conn->recv_timeout = 15; /* A 15 ms recv timeout... */ - err = netconn_bind(socket->conn, NULL, ntohs(socket->tftp_localport)); + err = netconn_bind(socket->conn, NULL, 0); if (err) { printf("netconn_bind error %d\n", err); return; } + socket->tftp_remoteip = url->ip; buf = rrq_packet_buf; *(uint16_t *)buf = TFTP_RRQ; /* TFTP opcode */ @@ -282,7 +283,7 @@ sendreq: nbuf = netbuf_new(); netbuf_ref(nbuf, rrq_packet_buf, rrq_len); - addr.addr = socket->tftp_remoteip = url->ip; + addr.addr = socket->tftp_remoteip; netconn_sendto(socket->conn, nbuf, &addr, url->port); netbuf_delete(nbuf); |