PERFORCE change 123209 for review
Alexey Tarasov
taleks at FreeBSD.org
Mon Jul 9 16:26:06 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=123209
Change 123209 by taleks at taleks_th on 2007/07/09 16:25:29
all: changed pxe_protocol_call definition (removed unused data parameter), removed PXE_CORE_CHECK, small fixes of text formatting.
pxe_buffer: fixed error caused corruption of data
pxe_connection: changes in awaiting function in order to handle LAST_ACK state and speedup connection refused detect in handshaking.
pxe_dhcp: added definition for www-server option. May be will be used to get address of web-server to work with.
Affected files ...
.. //depot/projects/soc2007/taleks-pxe_http/pxe_arp.c#10 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_arp.h#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.c#5 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.h#5 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_connection.c#6 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.c#19 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.h#15 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.c#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.h#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.c#10 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_ip.c#10 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.c#13 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.h#11 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_tcp.c#8 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_udp.c#7 edit
Differences ...
==== //depot/projects/soc2007/taleks-pxe_http/pxe_arp.c#10 (text+ko) ====
@@ -116,23 +116,21 @@
/*
* pxe_arp_protocol() - process received arp packet, this function is called in style
- * of pxe_protocol_call function type, but last two parameters are unused
+ * of pxe_protocol_call function type, but last parameter is unused
* in:
* pack - rceived packet data
* function - protocal function (will be always PXE_CORE_FRAG)
- * data - always NULL
* out:
* always 0 - we are not interested in storing this packet in pxe_core queue
*/
int
-pxe_arp_protocol(PXE_PACKET *pack, uint8_t function, void *data)
+pxe_arp_protocol(PXE_PACKET *pack, uint8_t function)
{
#ifdef PXE_DEBUG_HELL
printf("pxe_arp_protocol() started.\n");
#endif
PXE_ARP_PACK_DATA *arp_reply = (PXE_ARP_PACK_DATA *)pack->raw_data;
-
if (arp_reply->hdr.operation == le2be16(PXE_ARPOP_REQUEST) ) {
uint8_t *mac_src = arp_reply->body.src_hwaddr;
@@ -208,7 +206,6 @@
if (NULL != kmac) {
#ifdef PXE_DEBUG
uint8_t *octet = (uint8_t *)&arp_reply->body.src_paddr;
-/* uint8_t *mac = arp_reply->body.src_hwaddr; */
printf("MAC of %d.%d.%d.%d already known: %x:%x:%x:%x:%x:%x\n",
octet[0], octet[1], octet[2], octet[3],
(*kmac)[0], (*kmac)[1], (*kmac)[2], (*kmac)[3], (*kmac)[4], (*kmac)[5]
@@ -324,7 +321,6 @@
const MAC_ADDR *
pxe_arp_ip4mac(uint32_t ip)
{
-
const MAC_ADDR *res = pxe_arp_table_search(ip);
if (res != NULL)
==== //depot/projects/soc2007/taleks-pxe_http/pxe_arp.h#7 (text+ko) ====
@@ -37,7 +37,7 @@
const MAC_ADDR *pxe_arp_ip4mac(uint32_t ip);
/* protocol handler for received packets */
-int pxe_arp_protocol(PXE_PACKET *pack, uint8_t function, void *data);
+int pxe_arp_protocol(PXE_PACKET *pack, uint8_t function);
/* ARP table statistics */
void pxe_arp_stats();
@@ -49,7 +49,6 @@
/* protocol types */
#define PXE_PTYPE_IP 0x0800 /* IP4 protocol, used in ARP request */
-
/* NOTE: here will be realised ARP for Ethernet and IP4 */
typedef struct pxe_arp_packet {
uint16_t hwtype; /* hardware type */
==== //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.c#5 (text+ko) ====
@@ -23,7 +23,6 @@
return (0);
/* check if possible to place without cycling */
-
if (buf->fstart < buf->fend) { /* possible to place without cycling */
pxe_memcpy(from, buf->data + buf->fstart, to_write);
@@ -37,23 +36,14 @@
uint16_t part2 = to_write - part1;
if (part1)
- pxe_memcpy(from, buf->data + buf->fstart, part1);
+ pxe_memcpy(from, buf->data + buf->fstart, (part1 < to_write) ? part1 : to_write);
if (part1 >= to_write) {
buf->fstart += to_write;
-
- if (buf->fstart > buf->bufsize) {
- printf("pxe_buffer_write(): internal error! fstart = %d", buf->fstart);
- }
} else {
pxe_memcpy(from + part1, buf->data, part2);
buf->fstart = part2;
}
-
-#ifdef PXE_DEBUG_HELL
- printf("pxe_buffer_write(): fstart %d, fend %d, bufsize %d\n\tpart1 %d, part2 %d, to_write %d (%d)\n",
- buf->fstart, buf->fend, buf->bufsize, part1, part2, to_write, size);
-#endif
}
buf->bufleft -= to_write;
@@ -87,13 +77,14 @@
uint16_t bufsize = buf->bufsize;
if (fstart <= fend) { /* two cases handling: |*s...e**|, |***se***| */
+
/* right part of buffer */
uint16_t part1 = bufsize - fend;
/* left part of buffer */
uint16_t part2 = to_read - part1;
if (part1 && (to != NULL) )
- pxe_memcpy(buf->data + fend, to, part1);
+ pxe_memcpy(buf->data + fend, to, (part1 < to_read) ? part1 : to_read);
if (part1 >= to_read) {
buf->fend += to_read;
@@ -153,13 +144,17 @@
if (buffer->data == NULL)
return (0);
}
-
buffer->bufsize = size;
buffer->bufleft = size;
buffer->fstart = 0;
buffer->fend = size;
-
+
+#ifdef PXE_DEBUG_HELL
+ printf("pxe_buffer_memalloc(): buffer 0x%x, data 0x%x.\n",
+ buffer, buffer->data, buffer->bufleft
+ );
+#endif
return (1);
}
@@ -176,7 +171,8 @@
if (buffer->data == NULL) { /* already released */
return;
}
-#ifdef PXE_DEBUG
+
+#ifdef PXE_DEBUG_HELL
printf("pxe_buffer_memfree(): buffer 0x%x, data 0x%x, bufleft: %d.\n",
buffer, buffer->data, buffer->bufleft
);
==== //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.h#5 (text+ko) ====
==== //depot/projects/soc2007/taleks-pxe_http/pxe_connection.c#6 (text+ko) ====
@@ -88,24 +88,28 @@
tcp_await(uint8_t function, uint16_t try_number, uint32_t timeout, void *data)
{
PXE_TCP_WAIT_DATA *wait_data = (PXE_TCP_WAIT_DATA *)data;
+ PXE_TCP_CONNECTION *conn = wait_data->connection;
switch(function) {
case PXE_AWAIT_NEWPACKETS: /* check current state with needed to wait for */
- {
- PXE_TCP_CONNECTION *conn = wait_data->connection;
- if (wait_data->state == conn->state)
+
+ if (wait_data->state <= conn->state)
return (PXE_AWAIT_COMPLETED);
- /* CLOSED at waiting means connections was breaked */
+ /* CLOSED at waiting means connection was breaked */
if (conn->state == PXE_TCP_CLOSED)
return (PXE_AWAIT_BREAK);
- }
- break;
+
+ break;
- case PXE_AWAIT_STARTTRY: /* nothing to do */
case PXE_AWAIT_FINISHTRY:
+ if (conn->state == PXE_TCP_CLOSED)
+ return (PXE_AWAIT_BREAK);
+
pxe_resend_check(wait_data->connection);
break;
+
+ case PXE_AWAIT_STARTTRY: /* nothing to do */
case PXE_AWAIT_END:
default:
break;
@@ -225,7 +229,6 @@
return (1);
}
- /* if connection in established state - initiate active close */
if (!pxe_tcp_syssend(connection, PXE_TCP_FIN | PXE_TCP_ACK)) {
printf("pxe_tcp_disconnect(): failed to send FIN.\n");
free_connection(connection);
@@ -233,26 +236,32 @@
}
/* update sequence number */
connection->next_send += 1;
+
+ PXE_TCP_WAIT_DATA wait_data;
+ wait_data.connection = connection;
- if (connection->state == PXE_TCP_ESTABLISHED)
+ if (connection->state == PXE_TCP_ESTABLISHED) {
+ /* active closing by our host */
connection->state = PXE_TCP_FIN_WAIT1;
-
- connection->state_out = PXE_TCP_FIN;
#ifdef PXE_DEBUG
printf("pxe_tcp_disconnect(): new state - FIN_WAIT_1\n");
#endif
- PXE_TCP_WAIT_DATA wait_data;
- wait_data.connection = connection;
+ wait_data.state = PXE_TCP_TIME_WAIT;
- wait_data.state = PXE_TCP_TIME_WAIT;
-
- /* await TIME_WITE state.
- * connection will fell in this state in pxe_tcp_callback(),
- * TODO: add waiting of LAST_ACK also
+ } else { /* if connection breaked by remote host */
+ wait_data.state = PXE_TCP_LAST_ACK;
+ }
+
+ connection->state_out = PXE_TCP_FIN;
+
+
+ /* awaiting expected state to close connection
+ * connection will fell in this state in pxe_tcp_callback()
*/
- if (!pxe_await(tcp_await, 5, PXE_TCP_MSL / 5, &wait_data)) { /* failed to get to TIME_WAIT state */
+ if (!pxe_await(tcp_await, 5, PXE_TCP_MSL / 5, &wait_data)) { /* failed to get expected state */
+
free_connection(connection);
-
+
if (connection->state != PXE_TCP_CLOSED)
return (0);
}
@@ -347,7 +356,6 @@
}
/* if we got here, then we need to finish current segment and alloc new segment */
-
pxe_memcpy(data + sent_data, segment_data + segment->size, bufleft);
segment->size += bufleft;
sent_data += bufleft;
@@ -501,8 +509,8 @@
PXE_BUFFER *buffer = connection->recv;
- /* send ACK ony if we place for one segment at least */
- if (buffer->bufleft < buffer->bufsize / 2) {
+ /* send ACK ony if we place enough space */
+ if (buffer->bufleft < buffer->bufsize / 3) {
return (0);
}
==== //depot/projects/soc2007/taleks-pxe_http/pxe_core.c#19 (text+ko) ====
@@ -11,15 +11,12 @@
#include "pxe_ip.h"
#include "pxe_isr.h"
#include "pxe_mem.h"
-#include "pxe_mutex.h"
#include "pxe_udp.h"
/* PXE API calls here will be made in same way as in pxeboot.
* the only difference - installation of isr, that was not needed in pxe.c.
*/
-/* NOTE: to think about using of this buffers */
-#define PXE_BUFFER_SIZE 0x1000
static uint8_t scratch_buffer[PXE_BUFFER_SIZE];
static uint8_t data_buffer[PXE_BUFFER_SIZE];
static uint8_t exclusive_protocol = 0;
@@ -27,14 +24,9 @@
static pxe_t *pxe = NULL; /* !PXE */
static BOOTPLAYER bootplayer; /* PXE Cached information. */
-/* TODO: to think if packets queue must be in pxe_core.
- * It seems, it'll be used only by TCP
- */
-
/* pxe core structures*/
PXE_PACKET core_packet; /* current processing packet */
pxe_protocol_call core_protocol[256]; /* protocol's callback fuctions */
-PXE_MUTEX core_mutex = {0, 0}; /* mutex used in packet allocation */
/* NIC info */
MAC_ADDR nic_mac; /* may be init it also by zero? */
@@ -113,7 +105,6 @@
#ifdef PXE_DEBUG
printf("pxe_core_init(): started (pxenv_p = 0x%x, pxe_p = 0x%x).\n", pxenv_p, pxe_p);
#endif
-
int counter = 0;
uint8_t checksum = 0;
uint8_t *checkptr = NULL;
@@ -255,9 +246,9 @@
pxe_set_ip32(PXE_IP_MY, bootplayer.yip); /* nic ip */
pxe_set_ip32(PXE_IP_SERVER, bootplayer.sip); /* boot server ip */
-/* pxe_set_ip32(PXE_IP_NAMESERVER, 0x0100a8c0); /* nameserver ip, default to 192.168.0.1 */
-/* pxe_set_ip32(PXE_IP_GATEWAY, 0x0100a8c0); /* gateway ip, default to 192.168.0.1 */
-/* pxe_set_ip32(PXE_IP_NETMASK, 0x00ffffff); /* gateway ip, default to 255.255.255.0 */
+ pxe_set_ip32(PXE_IP_NAMESERVER, 0x0100a8c0); /* nameserver ip, default to 192.168.0.1 */
+ pxe_set_ip32(PXE_IP_GATEWAY, 0x0100a8c0); /* gateway ip, default to 192.168.0.1 */
+ pxe_set_ip32(PXE_IP_NETMASK, 0x00ffffff); /* gateway ip, default to 255.255.255.0 */
pxe_set_ip32(PXE_IP_BROADCAST, 0xffffffff); /* broadcast address, default to 255.255.255.255 */
/* initing modules */
@@ -395,7 +386,6 @@
int
pxe_core_shutdown()
{
- int i = 1;
if (core_packet.data)
pxe_free(core_packet.data);
@@ -404,7 +394,6 @@
pxe_core_remove_isr();
/* 2. shutdown PXE */
-
t_PXENV_UNLOAD_STACK *unload_stack_p =
(t_PXENV_UNLOAD_STACK *)scratch_buffer;
@@ -462,8 +451,6 @@
int
pxe_core_transmit(PXE_PACKET *pack)
{
- /* NOTE: is all provided data must be in base memory?
- */
t_PXENV_UNDI_TRANSMIT *undi_send =
(t_PXENV_UNDI_TRANSMIT *)scratch_buffer;
@@ -475,11 +462,6 @@
tbd.ImmedLength = pack->data_size; /* packet length */
tbd.Xmit.segment = VTOPSEG(pack->data); /* immediate transmit buffer */
tbd.Xmit.offset = VTOPOFF(pack->data); /* segment & offset */
-
-/* tbd.ImmedLength = pack->raw_size;
- tbd.Xmit.segment = VTOPSEG(pack->raw_data);
- tbd.Xmit.offset = VTOPOFF(pack->raw_data);
-*/
tbd.DataBlkCount = 0 ; /* only immediate data */
undi_send->Protocol = pack->protocol;
@@ -631,9 +613,9 @@
int protocol = 0; /* protocol */
int received = 0; /* bytes received to buffer */
- int frame_size = 0; /* size of frame */
- int drop_flag = 0;
- int processed_packets = 0;
+ int frame_size = 0; /* size of frame */
+ int drop_flag = 0; /* 1 if current packet must be dropped */
+ int processed_packets = 0; /* total count of processed packets during call*/
PXE_PACKET *pack=NULL; /* allocated packet */
PXE_PACKET dummy_pack; /* temporary struct, used to mimic
@@ -698,9 +680,10 @@
/* sanity check */
if (frame_size < PXE_BUFFER_SIZE) {
- pxe_core_copy( undi_isr->Frame.segment, undi_isr->Frame.offset,
+/* pxe_core_copy( undi_isr->Frame.segment, undi_isr->Frame.offset,
VTOPSEG(data_buffer), VTOPOFF(data_buffer), frame_size);
-/* pxe_memcpy(PTOV(undi_isr->Frame.segment * 16 + undi_isr->Frame.offset), data_buffer, frame_size); */
+ */
+ pxe_memcpy(PTOV(undi_isr->Frame.segment * 16 + undi_isr->Frame.offset), data_buffer, frame_size);
} else {
printf("pxe_core_recv_packets(): not enough buffer size (%d bytes) for frame size %d bytes.\n",
PXE_BUFFER_SIZE, frame_size);
@@ -729,7 +712,7 @@
if (protocol == PXE_PROTOCOL_ARP) {
- pxe_arp_protocol(&dummy_pack, PXE_CORE_HANDLE, NULL);
+ pxe_arp_protocol(&dummy_pack, PXE_CORE_HANDLE);
++processed_packets;
/* aasume ARP packet always in one fragment */
@@ -739,11 +722,11 @@
goto packet_start;
}
- /* TODO: calc ip checksum */
+ /* TODO: calc ip checksum */
if ( (!core_protocol[iphdr->protocol]) ||
(!core_protocol[iphdr->protocol](&dummy_pack,
- (buffer_size == frame_size) ? PXE_CORE_HANDLE : PXE_CORE_FRAG, NULL)) ) {
+ (buffer_size == frame_size) ? PXE_CORE_HANDLE : PXE_CORE_FRAG)) ) {
drop_flag = 1;
} else {
@@ -773,8 +756,11 @@
frame_size = undi_isr->FrameLength;
if (frame_size < PXE_BUFFER_SIZE) {
- pxe_core_copy( undi_isr->Frame.segment, undi_isr->Frame.offset,
+/* pxe_core_copy( undi_isr->Frame.segment, undi_isr->Frame.offset,
VTOPSEG(data_buffer), VTOPOFF(data_buffer), frame_size);
+ */
+ pxe_memcpy(PTOV(undi_isr->Frame.segment * 16 + undi_isr->Frame.offset),
+ data_buffer, frame_size);
} else {
printf("pxe_core_recv_packets(): not enough buffer size (%d bytes) for frame size %d bytes.",
PXE_BUFFER_SIZE, frame_size);
@@ -807,7 +793,7 @@
pack->protocol = protocol;
if ( (!core_protocol[iphdr->protocol]) ||
- (!core_protocol[iphdr->protocol](pack, PXE_CORE_HANDLE, NULL)) ) {
+ (!core_protocol[iphdr->protocol](pack, PXE_CORE_HANDLE)) ) {
/* protocol not interested in it */
pxe_core_drop(pack);
}
@@ -818,10 +804,6 @@
func = PXENV_UNDI_ISR_IN_GET_NEXT;
-/* if (received == buffer_size)
- return processed_packets;
-*/
-
goto packet_start;
/* never getting here */
@@ -837,7 +819,7 @@
* 0 - failed
* 1 - success
*/
-int
+static int
pxe_core_recieve(PXE_PACKET *pack, void *frame_data, size_t frame_size)
{
@@ -860,7 +842,6 @@
PXE_PACKET *
pxe_core_alloc_packet(size_t packet_size)
{
- int i = 1; /* packet index */
if (core_packet.state == PXE_PACKET_STATE_FREE) {
/* packet structure seems to be free */
@@ -874,7 +855,6 @@
pxe_free(core_packet.data);
core_packet.raw_data = data;
-
/* failed to allocate enough memory for packet */
if (data == NULL) {
core_packet.data_size = 0;
@@ -896,16 +876,6 @@
}
/* TODO: think if this function is useful
- * commits choosed packet, free used structures
- */
-void
-pxe_core_commit(PXE_PACKET *pack)
-{
-
- pack->state = PXE_PACKET_STATE_FREE;
-}
-
-/* TODO: think if this function is useful
* drops choosed packet
*/
void
@@ -913,7 +883,7 @@
{
++packets_dropped;
- pxe_core_commit(pack);
+ pack->state = PXE_PACKET_STATE_FREE;
}
/* pxe_core_register() - registers protocol in protocols table
@@ -932,7 +902,7 @@
/* pxe_core_exclusive() - sets protocol exclusive when receiving packets
* in:
- * proto - IP protocol number
+ * proto - protocol number (PXE_PROTOCOL_...)
* out:
* none
*/
@@ -1001,5 +971,5 @@
time(&secs);
- return (secs);
+ return (secs);
}
==== //depot/projects/soc2007/taleks-pxe_http/pxe_core.h#15 (text+ko) ====
@@ -11,22 +11,18 @@
* contains wrappers for UNDI functions
*/
-#define PXE_MAX_PACKETS 32
+#define PXE_BUFFER_SIZE 0x1000
#define PXE_PACKET_STATE_FREE 0
#define PXE_PACKET_STATE_USING 1
-#define PXE_PACKET_STATE_RECIEVED 2
-#define PXE_PACKET_STATE_SENT 3
-#define PXE_PACKET_STATE_PENDING 4
-#define PXE_PACKET_STATE_ABORTED 5
-
/* size of media header, used in allocating memmory for packet */
#define MEDIAHDR_LEN_ETH 14
+/* packet type: broadcast and directed */
#define PXE_BCAST 1
#define PXE_SINGLE 0
/*
- * structure, used in queueing packets in pxe_core
+ * structure, used to provide information about packet in pxe_core
*/
typedef struct pxe_packet {
@@ -62,9 +58,6 @@
/* sends packet to a network */
int pxe_core_transmit(PXE_PACKET *pack);
-/* commits that packet will not be used */
-void pxe_core_commit(PXE_PACKET *pack);
-
/* allocates buffer for packet */
PXE_PACKET *pxe_core_alloc_packet(size_t packet_size);
@@ -77,7 +70,7 @@
/* calls PXE/UNDI API, registers of processor must be filled in with
* appropriate values.
*/
-int pxe_core_call(int func);
+static int pxe_core_call(int func);
/* copies in real mode from one segment to another. */
void pxe_core_copy(uint16_t seg_from, uint16_t off_from, uint16_t seg_to, uint16_t off_to, uint16_t size);
@@ -89,7 +82,7 @@
void pxe_core_remove_isr();
/* stores data in packet */
-int pxe_core_recieve(PXE_PACKET *pack, void *data, size_t size);
+static int pxe_core_recieve(PXE_PACKET *pack, void *data, size_t size);
/* drops allocated packet, updates drop count */
void pxe_core_drop(PXE_PACKET *pack);
@@ -98,10 +91,9 @@
void pxe_core_stats();
#define PXE_CORE_HANDLE 0x0
-#define PXE_CORE_CHECK 0x1
-#define PXE_CORE_FRAG 0x2
-/* protocol callback function type*/
-typedef int (*pxe_protocol_call)(PXE_PACKET *pack, uint8_t function, void *data);
+#define PXE_CORE_FRAG 0x1
+/* protocol callback function type */
+typedef int (*pxe_protocol_call)(PXE_PACKET *pack, uint8_t function);
/* registers protocol */
void pxe_core_register(uint8_t ip_proto, pxe_protocol_call proc);
==== //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.c#3 (text+ko) ====
@@ -112,7 +112,13 @@
#ifdef PXE_DEBUG
printf("domain name: %s\n", (p+1));
#endif
- break;
+ break;
+
+ case PXE_DHCP_OPT_WWW_SERVER:
+#ifdef PXE_DEBUG
+ printf("server ip: %d.%d.%d.%d\n", *(p+1), *(p+2), *(p+3), *(p+4));
+#endif
+ break;
default:
printf("DHCP option %d is unknown (%d bytes ignored)\n", code, len);
break;
==== //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.h#3 (text+ko) ====
@@ -78,6 +78,7 @@
#define PXE_DHCP_OPT_ID 54
#define PXE_DHCP_OPT_RENEWAL_TIME 58
#define PXE_DHCP_OPT_REBINDING_TIME 59
+#define PXE_DHCP_OPT_WWW_SERVER 72
#define PXE_DHCP_OPT_END 255
/* used in await function */
@@ -103,4 +104,5 @@
/* prints out known DHCP options */
void pxe_dhcp_parse_options(uint8_t *opts, uint16_t max_size, PXE_DHCP_PARSE_RESULT *res);
+
#endif
==== //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.c#10 (text+ko) ====
@@ -17,25 +17,20 @@
* in:
* pack - packet describing data
* function- function, which must be performed
- * data - additional data [unused]
* out:
* always 0
*/
int
-pxe_icmp_callback(PXE_PACKET *pack, uint8_t function, void *data)
+pxe_icmp_callback(PXE_PACKET *pack, uint8_t function)
{
-
/* we don't store icmp packets, so they cannot steal memory
* in pxe core packet table
*/
- if (function == PXE_CORE_CHECK) {
- return (0);
+ if (function == PXE_CORE_FRAG) {
+ return (1);
}
- /* PXE_CORE_HANDLE - to handle packet
- */
-
/* icmp header*/
PXE_IP_HDR *iphdr = (PXE_IP_HDR *)pack->data;
size_t iphdr_len = (iphdr->ver_ihl & 0x0f) * 4;
@@ -67,7 +62,6 @@
return (0); /* instruct pxe core to drop packet*/
};
-
if (icmphdr->type == PXE_ICMP_ECHO_REPLY) {
if ( (reply_number != seq_number) && (icmphdr->code != 0)) {
@@ -87,12 +81,6 @@
if (pinging.ip == iphdr->src_ip) {
-/* uint16_t sum_orig = icmphdr->checksum;
- icmphdr->checksum = 0;
- uint16_t sum = ~pxe_ip_checksum(icmphdr, sizeof(PXE_ICMP_HDR) + data_size);
-
- printf("checksums: 0x%x %s 0x%x\n", sum_orig, (sum_orig == sum) ? "==" : "!=", sum );
-*/
if (echo_flags) {
printf("pxe_ping(): echo reply from %d.%d.%d.%d, seq=%ld ",
pinging.octet[0], pinging.octet[1],
@@ -107,7 +95,6 @@
/* all we need now is echo reply */
-
/* using buffer of recieved packet to avoid additional memory copy operations */
reply_iphdr = (PXE_IP_HDR *)pack->data;
@@ -137,7 +124,6 @@
int
pxe_icmp_init()
{
-
/* register protocol in pxe_core protocols table. */
pxe_core_register(PXE_ICMP_PROTOCOL, pxe_icmp_callback);
@@ -155,11 +141,11 @@
int
pxe_ping(PXE_IPADDR *ip, int count, int flags)
{
+
seq_number = 0;
last_accepted = 0xffff;
echo_flags = flags;
-
/* creating data storage for packet */
uint8_t data[sizeof(PXE_IP_HDR) + sizeof(PXE_ICMP_HDR) + 32];
@@ -216,7 +202,6 @@
++scount;
break;
}
-
}
if ( (last_accepted != seq_number) && flags)
==== //depot/projects/soc2007/taleks-pxe_http/pxe_ip.c#10 (text+ko) ====
@@ -134,14 +134,12 @@
gw_ip.octet[0], gw_ip.octet[1], gw_ip.octet[2], gw_ip.octet[3]
);
-
for ( ; route_index < all_routes; ++route_index) {
if ((route_table[route_index].net == net_ip.ip) &&
(route_table[route_index].gw == gw) &&
(route_table[route_index].mask == mask))
{
-
--all_routes;
if (route_index == all_routes)
@@ -157,7 +155,6 @@
route_table[shift_index].mask == route_table[shift_index + 1].mask;
}
-
return (1);
}
@@ -262,13 +259,13 @@
const uint8_t *mac = (uint8_t *)pxe_arp_ip4mac(gw);
- if (mac != NULL)
- printf("%2x:%2x:%2x:%2x:%2x:%2x",
- mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
- );
- }
-
- printf("\n");
+ if (mac != NULL) {
+ printf("%2x:%2x:%2x:%2x:%2x:%2x",
+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
+ );
+ }
+ }
+ printf("\n");
}
}
==== //depot/projects/soc2007/taleks-pxe_http/pxe_sock.c#13 (text+ko) ====
@@ -453,18 +453,24 @@
return (-1);
}
- PXE_SOCKET *sock = &pxe_sockets[socket];
- PXE_FILTER_ENTRY *filter = sock->filter;
+ PXE_SOCKET *sock = &pxe_sockets[socket];
+ PXE_FILTER_ENTRY *filter = sock->filter;
+ int result = -1;
if (filter->protocol == PXE_UDP_PROTOCOL) {
- return pxe_udp_write(sock, buf, buflen);
+ result = pxe_udp_write(sock, buf, buflen);
} else if (filter->protocol == PXE_TCP_PROTOCOL) {
- return pxe_tcp_write(sock, buf, buflen);
- }
- printf("pxe_send(): only TCP and UDP sockets are implemented.\n");
+ result = pxe_tcp_write(sock, buf, buflen);
+
+ } else {
+ printf("pxe_send(): only TCP and UDP sockets are implemented.\n");
+ }
+
+ if (result > 0)
+ sock->sent += result;
return (-1);
}
@@ -516,7 +522,7 @@
if (result != 0)
break;
- if (timer > PXE_SOCKET_TIMEOUT * 1000)
+ if (timer > PXE_SOCKET_TIMEOUT)
break;
if (filter->protocol == PXE_TCP_PROTOCOL) {
@@ -533,6 +539,9 @@
delay(10000);
}
+ if (result > 0)
+ sock->recv += result;
+
return (result);
}
==== //depot/projects/soc2007/taleks-pxe_http/pxe_sock.h#11 (text+ko) ====
@@ -12,10 +12,10 @@
#define PXE_DEFAULT_SOCKETS 8
/* default count of waiting queue */
#define PXE_DEFAULT_WAITCOUNT 3
-/* socket timeout when receiving data, in seconds */
-#define PXE_SOCKET_TIMEOUT 30
+/* socket timeout when receiving data, in milliseconds */
+#define PXE_SOCKET_TIMEOUT 30000
/* timeout, after that force connection checking, in milliseconds */
-#define PXE_SOCKET_CHECK_TIMEOUT 200
+#define PXE_SOCKET_CHECK_TIMEOUT 100
/* socket states */
#define PXE_SOCKET_FREE 0x0 /* socket unused and free for allocating */
#define PXE_SOCKET_USED 0x1 /* socket structure used */
==== //depot/projects/soc2007/taleks-pxe_http/pxe_tcp.c#8 (text+ko) ====
@@ -320,7 +320,7 @@
if (tcp_packet->tcphdr.flags & (PXE_TCP_SYN | PXE_TCP_FIN) )
connection->next_recv += 1;
-/* printf("tcp_process_7(): ack = %d, seq = %d, seglen = %d\n",
+/* printf("tcp_process_7(): seq = %d, ack = %d, seglen = %d\n",
connection->next_recv - connection->irs, connection->next_send - connection->iss, seglen
);
*/
@@ -808,21 +808,17 @@
* in:
* pack - packet description
* function- function to perform
- * data - additional data [unused]
* out:
* 1 - if packet is fragment and code is interested in it
* 0 - if success or error
*/
int
-pxe_tcp_callback(PXE_PACKET *pack, uint8_t function, void *data)
+pxe_tcp_callback(PXE_PACKET *pack, uint8_t function)
{
PXE_TCP_PACKET *tcp_packet = pack->data;
PXE_IPADDR from;
PXE_IPADDR to;
- if (function == PXE_CORE_CHECK) /* informm, we are not using pxe_core queue */
- return (0);
-
from.ip = tcp_packet->iphdr.src_ip;
to.ip = tcp_packet->iphdr.dst_ip;
==== //depot/projects/soc2007/taleks-pxe_http/pxe_udp.c#7 (text+ko) ====
@@ -11,21 +11,17 @@
* in:
* pack - packet description
* function- function to perform
- * data - additional data [unused]
* out:
* 1 - if packet is fragment and code is interested in it
* 0 - if success or error
*/
int
-pxe_udp_callback(PXE_PACKET *pack, uint8_t function, void *data)
+pxe_udp_callback(PXE_PACKET *pack, uint8_t function)
{
PXE_UDP_PACKET *udp_packet = pack->data;
PXE_IPADDR from;
PXE_IPADDR to;
- if (function == PXE_CORE_CHECK) /* informm, we are not using pxe_core queue */
- return (0);
-
from.ip = udp_packet->iphdr.src_ip;
to.ip = udp_packet->iphdr.dst_ip;
@@ -52,12 +48,8 @@
if (function == PXE_CORE_FRAG) /* informm, we are interested in whole packet*/
return (1);
-/* uint16_t buf_free = sock->recv_buffer.bufleft; */
uint16_t data_size = pack->data_size - sizeof(PXE_UDP_PACKET);
-/* if (buf_free < data_size)
- return (0);
-*/
PXE_BUFFER* recv_buffer = &sock->recv_buffer;
PXE_UDP_DGRAM udp_dgram;
More information about the p4-projects
mailing list