PERFORCE change 123812 for review

Alexey Tarasov taleks at FreeBSD.org
Fri Jul 20 17:23:13 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=123812

Change 123812 by taleks at taleks_th on 2007/07/20 17:22:11

	all: added license, updated rest of files with style problems, added debug macro for modules, which produces too many debug output, printf() format characters changed in many places to be more correct.. Some other cosmetic changes.
	pxe_http: started implementing of keep-alive connections, previous pxe_get() became pxe_get_close() function, which closes connection after every reading operation. Some changes also in parameter types.
	pxe_connection: added pxe_force_filter_release() and force_alloc_connection() functions to use structures for connections in TIME_WAIT state, if there are no other free structures.

Affected files ...

.. //depot/projects/soc2007/taleks-pxe_http/Makefile#10 edit
.. //depot/projects/soc2007/taleks-pxe_http/httpfs.c#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/httpfs.h#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_arp.c#12 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_arp.h#8 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_await.c#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_await.h#4 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.c#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.h#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_connection.c#9 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_connection.h#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_conv.c#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_conv.h#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.c#22 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.h#18 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.c#6 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.h#6 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dns.c#5 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dns.h#5 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_filter.c#5 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_filter.h#4 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_http.c#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_http.h#5 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.c#12 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.h#8 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_ip.c#13 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_ip.h#9 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_isr.S#5 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_isr.h#4 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_mem.c#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_mem.h#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_segment.c#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_segment.h#5 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.c#15 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.h#13 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_tcp.c#10 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_tcp.h#8 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_udp.c#8 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_udp.h#5 edit

Differences ...

==== //depot/projects/soc2007/taleks-pxe_http/Makefile#10 (text+ko) ====

@@ -17,4 +17,19 @@
 #CFLAGS+=	-DPXE_DEBUG
 #CFLAGS+=	-DPXE_DEBUG_HELL
 
+# core module debug
+#CFLAGS+=	-DPXE_CORE_DEBUG_HELL
+#CFLAGS+=	-DPXE_CORE_DEBUG
+# TCP module debug 
+#CFLAGS+=	-DPXE_TCP_DEBUG
+#CFLAGS+=	-DPXE_TCP_DEBUG_HELL
+# IP module debug
+#CFLAGS+=	-DPXE_IP_DEBUG
+#CFLAGS+=	-DPXE_IP_DEBUG_HELL
+# ARP module debug
+#CFLAGS+=	-DPXE_ARP_DEBUG
+#CFLAGS+=	-DPXE_ARP_DEBUG_HELL
+# httpfs module
+#CFLAGS+=	-DPXE_HTTP_DEBUG
+
 .include <bsd.lib.mk>

==== //depot/projects/soc2007/taleks-pxe_http/httpfs.c#3 (text+ko) ====

@@ -1,3 +1,30 @@
+/*-
+ * Copyright (c) 2007 Alexey Tarasov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+ 
 #include <sys/types.h>
 #include <stand.h>
 
@@ -28,6 +55,9 @@
 void
 handle_cleanup(PXE_HTTP_HANDLE *httpfile)
 {
+	if (httpfile == NULL)
+		return;
+		
 	if (httpfile->buf != NULL)
 		free(httpfile->buf);
 
@@ -37,22 +67,30 @@
 	if (httpfile->servername != NULL)
 		free(httpfile->servername);
 
+	if (httpfile->socket != -1)
+		pxe_close(httpfile->socket);
+	
 	free(httpfile);
 }
 
 static int 
 http_open(const char *path, struct open_file *f)
 {
+#ifdef PXE_HTTP_DEBUG
+	printf("http_open(): %s\n", path);
+#endif
 	PXE_HTTP_HANDLE *httpfile =
 	    (PXE_HTTP_HANDLE *)malloc(sizeof(PXE_HTTP_HANDLE));
 	
-	if (!httpfile)
+	if (httpfile == NULL)
 		return (ENOMEM);
 
 	pxe_memset(httpfile, 0, sizeof(PXE_HTTP_HANDLE));
 								
 	httpfile->ip = pxe_get_ip32(PXE_IP_WWW);
 	httpfile->offset = 0;
+	httpfile->socket = -1;
+	
         httpfile->filename = strdup(path);
 	
 	if (httpfile->filename == NULL) {
@@ -65,7 +103,7 @@
 	PXE_IPADDR server;
 	server.ip = httpfile->ip;
 	
-	httpfile->servername = malloc(16);
+	httpfile->servername = strdup(inet_ntoa(server.ip));
 	
 	if (httpfile->servername == NULL) {
 		handle_cleanup(httpfile);
@@ -94,15 +132,49 @@
 http_read(struct open_file *f, void *addr, size_t size, size_t *resid)
 {
 	PXE_HTTP_HANDLE *httpfile = (PXE_HTTP_HANDLE *) f->f_fsdata;
+	
+	if (httpfile == NULL) {
+		printf("http_read(): NULL file descriptor.\n");
+		return (EINVAL);
+	}
+	
+#ifdef PXE_HTTP_DEBUG	
+	printf("http_read(): %s:%llu+%lu\n",
+	    httpfile->filename, httpfile->offset, size);
+#endif
+	if (((httpfile->size != PXE_HTTP_SIZE_UNKNOWN) &&
+	     (httpfile->offset >= httpfile->size)) ||
+	     (size == 0))
+	{
+	    if (resid)
+		*resid = size;
+#ifdef PXE_HTTP_DEBUG
+	    printf("http_read(): EOF\n");
+#endif
+	    return (0);
+	}
+	
+	size_t to_read = (httpfile->offset + size < httpfile->size) ?
+			    size: httpfile->size - (size_t)httpfile->offset;
+	
+	int result = pxe_get(httpfile, to_read, addr);
 
-	int result = pxe_get(httpfile, size, addr);
-
 	if (result == -1) {
+		printf("http_read(): failed to read\n");
 		return (EINVAL);
 	}
 
+	httpfile->offset += result;
+
+#ifdef PXE_HTTP_DEBUG
+	if (httpfile->size != PXE_HTTP_SIZE_UNKNOWN)
+		printf("http_read(): %llu bytes read (%llu %% read)\n",
+		    httpfile->offset, 100LL * httpfile->offset / httpfile->size);
+	else
+		printf("http_read(): %llu byte(s) read\n", httpfile->offset);
+#endif
 	if (resid)
-		*resid = result;
+		*resid = size - result;
 
 	return (0);
 }
@@ -112,6 +184,9 @@
 {
 	PXE_HTTP_HANDLE *httpfile = (PXE_HTTP_HANDLE *) f->f_fsdata;
 
+#ifdef PXE_HTTP_DEBUG
+	printf("http_close(): closing file %s\n", httpfile->filename);
+#endif
 	handle_cleanup(httpfile);
 	
 	return (0);
@@ -127,12 +202,17 @@
 static int 
 http_stat(struct open_file *f, struct stat *sb)
 {
-
+	PXE_HTTP_HANDLE *httpfile = (PXE_HTTP_HANDLE *) f->f_fsdata;
+	
+#ifdef PXE_HTTP_DEBUG
+	printf("http_stat(): stat for file %s\n", httpfile->filename);
+#endif
 	sb->st_mode = 0444 | S_IFREG;
 	sb->st_nlink = 1;
 	sb->st_uid = 0;
 	sb->st_gid = 0;
-	sb->st_size = -1;
+
+	sb->st_size = (httpfile != NULL) ? httpfile->size : -1;
 	
 	return (0);
 }
@@ -141,6 +221,10 @@
 http_seek(struct open_file *f, off_t offset, int where)
 {
 	PXE_HTTP_HANDLE *httpfile = (PXE_HTTP_HANDLE *) f->f_fsdata;
+	
+#ifdef PXE_HTTP_DEBUG
+	printf("http_seek(): file 0x%x\n", httpfile);
+#endif
 
 	if (httpfile == NULL) {	/* to be sure */
 		errno = EINVAL;

==== //depot/projects/soc2007/taleks-pxe_http/httpfs.h#3 (text+ko) ====

@@ -1,8 +1,39 @@
+/*-
+ * Copyright (c) 2007 Alexey Tarasov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
 #ifndef HTTPFS_INCLUDED
 #define HTTPFS_INCLUDED
 
+/* 
+ * Implements httpfs - illusion of filesystem through http
+ */
+ 
 #include <stand.h>
 
 extern struct fs_ops http_fsops;
 
-#endif+#endif

==== //depot/projects/soc2007/taleks-pxe_http/pxe_arp.c#12 (text+ko) ====

@@ -1,3 +1,30 @@
+/*-
+ * Copyright (c) 2007 Alexey Tarasov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+ 
 #include <stand.h>
 
 #include "pxe_arp.h"
@@ -21,7 +48,7 @@
 void
 pxe_arp_init()
 {
-#ifdef PXE_DEBUG
+#ifdef PXE_ARP_DEBUG
 	printf("pxe_arp_init() started.\n");
 	
 	if (packet_to_send.hdr.hsize != 0) {
@@ -63,7 +90,7 @@
 const MAC_ADDR *
 pxe_arp_table_search(uint32_t ip)
 {
-#ifdef PXE_DEBUG_HELL
+#ifdef PXE_ARP_DEBUG_HELL
 	printf("pxe_arp_table_search(): started\n");
 #endif		
 	int entry = 0;
@@ -73,7 +100,7 @@
 		if (arp_table[entry].ip4.ip == ip) {
 		
 			uint8_t *mac = &arp_table[entry].mac[0];
-#ifdef PXE_DEBUG_HELL
+#ifdef PXE_ARP_DEBUG_HELL
 			printf("pxe_arp_table_search(): %6D\n", mac, ":");
 #endif			
 			return (const MAC_ADDR *)mac;
@@ -125,7 +152,7 @@
 int
 pxe_arp_protocol(PXE_PACKET *pack, uint8_t function)
 {
-#ifdef PXE_DEBUG_HELL
+#ifdef PXE_ARP_DEBUG_HELL
 	printf("pxe_arp_protocol() started.\n");
 #endif
 	PXE_ARP_PACK_DATA *arp_reply = (PXE_ARP_PACK_DATA *)pack->raw_data;
@@ -142,13 +169,13 @@
 		
 		if (ip4_src.ip == pxe_get_ip32(PXE_IP_MY)) {
 			/* got broadcast send by us */
-#ifdef PXE_DEBUG_HELL
+#ifdef PXE_ARP_DEBUG_HELL
 			printf("arp request from myself ignored.\n");
 #endif
 			return (0);
 		}
 		
-#ifdef PXE_DEBUG		
+#ifdef PXE_ARP_DEBUG		
 		printf("arp request from %x:%x:%x:%x:%x:%x/%d.%d.%d.%d\n\t"
 		    " to: %x:%x:%x:%x:%x:%x/%d.%d.%d.%d\n",
 		    mac_src[0], mac_src[1], mac_src[2],
@@ -220,7 +247,7 @@
 	 
 	const MAC_ADDR *kmac = pxe_arp_table_search(arp_reply->body.src_paddr);
 	if (NULL != kmac) {
-#ifdef PXE_DEBUG
+#ifdef PXE_ARP_DEBUG
 	        uint8_t *octet = (uint8_t *)&arp_reply->body.src_paddr;
 	        printf("MAC of %d.%d.%d.%d already known: %x:%x:%x:%x:%x:%x\n",
 		    octet[0], octet[1], octet[2], octet[3],
@@ -240,7 +267,7 @@
 	    
 	++arp_usage;
 
-#ifdef PXE_DEBUG_HELL	
+#ifdef PXE_ARP_DEBUG_HELL	
 	printf("pxe_arp_protocol(): arp usage = %d\n", arp_usage);
 #endif
 	
@@ -259,7 +286,6 @@
 int
 pxe_arp_send_whois(uint32_t ip)
 {
-	
         PXE_PACKET	pack;
 	
 	pack.raw_size = sizeof(PXE_ARP_PACK_DATA);

==== //depot/projects/soc2007/taleks-pxe_http/pxe_arp.h#8 (text+ko) ====

@@ -1,3 +1,30 @@
+/*-
+ * Copyright (c) 2007 Alexey Tarasov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+ 
 #ifndef PXE_ARP_H
 #define PXE_ARP_H
 

==== //depot/projects/soc2007/taleks-pxe_http/pxe_await.c#3 (text+ko) ====

@@ -1,3 +1,30 @@
+/*-
+ * Copyright (c) 2007 Alexey Tarasov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+ 
 #include <stand.h>
 
 #include "pxe_await.h"
@@ -89,4 +116,4 @@
 	 */
 	return (0);
 }
-																														     +																												     
==== //depot/projects/soc2007/taleks-pxe_http/pxe_await.h#4 (text+ko) ====

@@ -1,6 +1,37 @@
+/*-
+ * Copyright (c) 2007 Alexey Tarasov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
 #ifndef PXE_AWAIT_H_INCLUDED
 #define PXE_AWAIT_H_INCLUDED
 
+/*
+ * Implements await functions wrapper
+ */
+
 #include <stdint.h>
 
 /* await callback function type */

==== //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.c#7 (text+ko) ====

@@ -1,3 +1,32 @@
+/*-
+ * Copyright (c) 2007 Alexey Tarasov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+ 
+#include <stand.h>
+
 #include "pxe_buffer.h"
 #include "pxe_mem.h"
 
@@ -12,8 +41,19 @@
 uint16_t
 pxe_buffer_write(PXE_BUFFER *buf, const void *from, uint16_t size)
 {
+
+	if (buf == NULL) {
+		printf("pxe_buffer_write(): NULL buffer\n");
+		return (0);
+	}
+	
 	uint16_t	to_write = (size < buf->bufleft) ? size : buf->bufleft;
 
+	if (buf->data == NULL) {
+		printf("pxe_buffer_write(): NULL buffer data\n");
+		return (0);
+	}
+	
 #ifdef PXE_DEBUG_HELL
 	printf("pxe_buffer_write(): fstart %d, fend %d, bufleft %d (of %d),"
 	       " to_write %d (%d)\n", buf->fstart, buf->fend, buf->bufleft,
@@ -68,13 +108,23 @@
 uint16_t
 pxe_buffer_read(PXE_BUFFER *buf, void *to, uint16_t size)
 {
+
+	if (buf == NULL) {
+		printf("pxe_buffer_read(): NULL buffer\n");
+		return (0);
+	}
+	
+	if (buf->data == NULL) {
+		printf("pxe_buffer_read(): NULL buffer data\n");
+		return (0);
+	}
+	
 	uint16_t	usage = buf->bufsize - buf->bufleft;
 	uint16_t	to_read = (size <= usage) ? size : usage;
-	
+
 	if (to_read == 0)	/* nothing to read */
 		return (0);
 	
-	
 	uint16_t fstart = buf->fstart;
 	uint16_t fend = buf->fend;
 	uint16_t bufsize = buf->bufsize;
@@ -127,6 +177,13 @@
 pxe_buffer_space(PXE_BUFFER *buffer)
 {
 
+	if (buffer == NULL) {
+#ifdef PXE_DEBUG
+		printf("pxe_buffer_space(): NULL buffer\n");
+#endif
+		return (0);
+	}
+	
 	return (buffer->bufleft);
 }
 
@@ -142,11 +199,21 @@
 pxe_buffer_memalloc(PXE_BUFFER *buffer, uint16_t size)
 {
 
+	if (buffer == NULL) {
+#ifdef PXE_DEBUG
+		printf("pxe_buffer_memalloc(): NULL buffer\n");
+#endif
+		return (0);
+	}
+	
 	if (buffer->data == NULL) { /* alloc if not already allocated */
 		buffer->data = pxe_alloc(size);
 	
 		if (buffer->data == NULL)
 			return (0);
+	} else {
+		printf("pxe_buffer_memalloc(): already %u bytes, asked %u.\n",
+		    buffer->bufsize, size);
 	}
 
 	buffer->bufsize = size;
@@ -155,7 +222,7 @@
         buffer->fend = size;
 
 #ifdef PXE_DEBUG_HELL
-	printf("pxe_buffer_memalloc(): buffer 0x%x, data 0x%x.\n",
+	printf("pxe_buffer_memalloc(): buffer 0x%x, data 0x%x, bufleft %u.\n",
 	    buffer, buffer->data, buffer->bufleft
 	);
 #endif
@@ -172,8 +239,17 @@
 pxe_buffer_memfree(PXE_BUFFER *buffer)
 {
 
-	if (buffer->data == NULL)  /* already released */
+	if (buffer == NULL) {
+#ifdef PXE_DEBUG
+		printf("pxe_buffer_memfree(): NULL buffer\n");
+#endif
+		return;
+	}
+	
+	if (buffer->data == NULL) { /* already released */
+		printf("pxe_buffer_memfree(): already released.\n");
 		return;
+	}
 
 #ifdef PXE_DEBUG_HELL
 	printf("pxe_buffer_memfree(): buffer 0x%x, data 0x%x, bufleft: %d.\n",
@@ -181,4 +257,5 @@
 	);
 #endif	
 	pxe_free(buffer->data);
+	buffer->data = NULL;
 }

==== //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.h#7 (text+ko) ====

@@ -1,6 +1,37 @@
+/*-
+ * Copyright (c) 2007 Alexey Tarasov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
 #ifndef PXE_BUFFER_H_INCLUDED
 #define PXE_BUFFER_H_INCLUDED
 
+/*
+ * Implements cyclic buffer routines
+ */
+ 
 #include <stdint.h>
 
 /* buffer size choosed by default for sending/recieving */

==== //depot/projects/soc2007/taleks-pxe_http/pxe_connection.c#9 (text+ko) ====

@@ -1,3 +1,30 @@
+/*-
+ * Copyright (c) 2007 Alexey Tarasov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+ 
 #include <stand.h>
 
 #include "pxe_await.h"
@@ -48,6 +75,7 @@
 PXE_TCP_CONNECTION *
 alloc_connection()
 {
+
 	if (all_connections == PXE_MAX_TCP_CONNECTIONS)
 		return (NULL);
 		
@@ -66,6 +94,78 @@
 	return (NULL);
 }
 
+/* force_alloc_connection() - returns pointer to free connection structure
+ *			forces connection structures in TIME_WAIT state to
+ *			be allocated if there are no free connection
+ *			structure.
+ * in:
+ *	none
+ * out:
+ *	NULL	- failed to alloc
+ *	non NULL- pointer to allocated structure
+ */
+PXE_TCP_CONNECTION *
+force_alloc_connection()
+{
+
+	if (all_connections < PXE_MAX_TCP_CONNECTIONS)
+		return alloc_connection();
+		
+	uint16_t	index = 0;
+	
+	for ( ; index < PXE_MAX_TCP_CONNECTIONS; ++index) {
+	
+		if (tcp_connections[index].state == PXE_TCP_TIME_WAIT) {
+			
+			tcp_connections[index].state = PXE_TCP_CLOSED;
+			
+			/* release filter */
+			PXE_FILTER_ENTRY *filter = tcp_connections[index].filter;
+					
+			if (filter != NULL) /* it must always be non NULL */
+			        pxe_filter_remove(filter);
+#ifdef PXE_TCP_DEBUG
+			printf("force_alloc_connection(): forced allocation\n");
+#endif
+			return &tcp_connections[index];
+		}
+	}
+	
+	return (NULL);
+}
+
+/* pxe_force_filter_release() - releases filter if used by connections
+ *			in TIME_WAIT state. Needed when filters table
+ *			is full, but there are no really active connections.
+ * in/out:
+ *	none
+ */
+void
+pxe_force_filter_release()
+{
+	uint16_t	index = 0;
+	
+	for ( ; index < PXE_MAX_TCP_CONNECTIONS; ++index) {
+	
+		if (tcp_connections[index].state == PXE_TCP_TIME_WAIT) {
+			/* free also connection structure */
+			tcp_connections[index].state = PXE_TCP_CLOSED;
+			
+			/* release filter */
+			PXE_FILTER_ENTRY *filter = tcp_connections[index].filter;
+					
+			if (filter != NULL) /* it must always be non NULL */
+			        pxe_filter_remove(filter);
+				
+			all_connections -= 1;
+#ifdef PXE_TCP_DEBUG
+			printf("pxe_force_filter_release(): filter released.\n");
+#endif
+			break;
+		}
+	}
+}
+
 /* free_connection() - releases connections
  * in:
  *	connection - pointer to connection to release
@@ -79,6 +179,9 @@
 
 	connection->state = PXE_TCP_CLOSED;
 	all_connections -= 1;
+#ifdef PXE_TCP_DEBUG_HELL
+	printf("free_connection(): %d connections used\n", all_connections);
+#endif
 }
 
 /* tcp_await() - await function for some TCP protocol functions (handshaking,
@@ -133,16 +236,18 @@
 pxe_tcp_connect(PXE_SOCKET *sock)
 {
 
-	if (all_connections == PXE_MAX_TCP_CONNECTIONS) {
-		printf("pxe_tcp_connections(): too many connections.\n");
+/*	if (all_connections == PXE_MAX_TCP_CONNECTIONS) {
+		printf("pxe_tcp_connect(): too many connections.\n");
 		return (0);
 	}
-
+*/
 	PXE_FILTER_ENTRY	*filter = sock->filter;	
-	PXE_TCP_CONNECTION	*connection = alloc_connection();
+	PXE_TCP_CONNECTION	*connection = force_alloc_connection();
 
-	if (connection == NULL)
+	if (connection == NULL) {
+		printf("pxe_tcp_connect(): too many connections.\n");
 		return (0);
+	}
 	
 	pxe_memset(connection, 0, sizeof(PXE_TCP_CONNECTION));
 			
@@ -171,7 +276,7 @@
 
 	connection->state = PXE_TCP_SYN_SENT;
 	connection->next_send = connection->iss + 1;
-#ifdef PXE_DEBUG
+#ifdef PXE_TCP_DEBUG
 	printf("pxe_tcp_connect(): new state - SYN_SENT\n");
 #endif		
 	PXE_TCP_WAIT_DATA wait_data;
@@ -189,7 +294,7 @@
 		return (0);
 	}
 
-#ifdef PXE_DEBUG
+#ifdef PXE_TCP_DEBUG
 	printf("pxe_tcp_connect(): connection established.\n");
 #endif	
 	return (1);
@@ -205,20 +310,23 @@
 int
 pxe_tcp_disconnect(PXE_SOCKET *sock)
 {
-#ifdef PXE_DEBUG
+#ifdef PXE_TCP_DEBUG
 	printf("pxe_tcp_disconnect(): started.\n");
 #endif
 	PXE_FILTER_ENTRY	*filter = sock->filter;	
 	
 	if (filter == NULL) {
 		/* NULL filters means there are no connection for socket */
+		printf("pxe_tcp_disconnect(): NULL filter\n");
 		return (1);
 	}
 	
 	PXE_TCP_CONNECTION	*connection = filter_to_connection(filter);
 
-	if (connection == NULL)
+	if (connection == NULL) {
+		printf("pxe_tcp_disconnect(): NULL connection\n");
 		return (0);
+	}
 
 	/* process recieved,  queued but not processed packets.
 	 * This is useful if server requested breaking of connection
@@ -227,8 +335,8 @@
 	 */
 	pxe_core_recv_packets();
 	
-	if (connection->state == PXE_TCP_CLOSED) { /* already  closed */
-#ifdef PXE_DEBUG
+	if ( connection->state == PXE_TCP_CLOSED) { /* already  closed */
+#ifdef PXE_TCP_DEBUG
 		printf("pxe_tcp_disconnect(): connection already is closed.\n");
 #endif
 		return (1);
@@ -248,7 +356,7 @@
 	if (connection->state == PXE_TCP_ESTABLISHED) {
 		/* active closing by our host */
 		connection->state = PXE_TCP_FIN_WAIT1;
-#ifdef PXE_DEBUG
+#ifdef PXE_TCP_DEBUG
 		printf("pxe_tcp_disconnect(): new state - FIN_WAIT_1\n");
 #endif
 		wait_data.state = PXE_TCP_TIME_WAIT;
@@ -267,16 +375,22 @@
 		/* failed to get expected state */
 	    	free_connection(connection);
 	
-		if (connection->state != PXE_TCP_CLOSED)
+		if (connection->state != PXE_TCP_CLOSED) {
+#ifdef PXE_TCP_DEBUG		
+			printf("pxe_tcp_disconnect(): felt to wrong state.\n");
+#endif
 			return (0);
+		}
 	}
 
-	if (connection->state == PXE_TCP_CLOSED)
+	if (connection->state == PXE_TCP_CLOSED) {
 		pxe_filter_remove(filter);
-			
+		free_connection(connection);
+	}
+	
 	pxe_resend_free(connection);
 	
-#ifdef PXE_DEBUG
+#ifdef PXE_TCP_DEBUG
 	printf("pxe_tcp_disconnect(): connection closed.\n");
 #endif
 	return (1);
@@ -514,7 +628,7 @@
 int
 pxe_tcp_check_connection(PXE_SOCKET *sock)
 {
-#ifdef PXE_DEBUG
+#ifdef PXE_TCP_DEBUG
 	printf("pxe_tcp_check_connection(): started.\n");
 #endif
 	PXE_TCP_CONNECTION	*connection = filter_to_connection(sock->filter);
@@ -554,7 +668,7 @@
 void
 pxe_connection_stats()
 {
-	printf("pxe_connection_stats():\n");
+	printf("pxe_connection_stats(): %d connections\n", all_connections);
 
 	int con_index = 0;
 	PXE_TCP_CONNECTION *connection = NULL;
@@ -564,8 +678,9 @@
 		connection = &tcp_connections[con_index];
 		
 		printf("%d: filter: 0x%x, state: %d\n"
-		       "  nxt_snd: %d, nxt_rcv: %d, iss: %d, irs: %d\n",
+		       "  nxt_snd: %lu, nxt_rcv: %lu, iss: %lu, irs: %lu\n",
 		       con_index, connection->filter, connection->state,
-		       connection->next_send, connection->next_recv);
+		       connection->next_send, connection->next_recv,
+		       connection->iss, connection->irs);
 	}
 }

==== //depot/projects/soc2007/taleks-pxe_http/pxe_connection.h#7 (text+ko) ====

@@ -1,6 +1,37 @@
+/*-
+ * Copyright (c) 2007 Alexey Tarasov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright

>>> TRUNCATED FOR MAIL (1000 lines) <<<


More information about the p4-projects mailing list