PERFORCE change 121853 for review
Alexey Tarasov
taleks at FreeBSD.org
Sun Jun 17 15:08:31 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=121853
Change 121853 by taleks at taleks_th on 2007/06/17 15:07:31
First step of TCP implementation. Added pxe_tcp_connection structure to handle connections. Added pxe_tcp module to available earlier header and functions to send packets. First variant of handhaking function pxe_tcp_connect() and pxe_tcp_callback function.
Other minor changes to init TCP module in pxe_core and checking for NIC's ip to avoid broadcast return in pxe_arp.
Affected files ...
.. //depot/projects/soc2007/taleks-pxe_http/pxe_arp.c#8 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.c#15 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.c#8 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_tcp.c#1 add
.. //depot/projects/soc2007/taleks-pxe_http/pxe_tcp.h#3 edit
Differences ...
==== //depot/projects/soc2007/taleks-pxe_http/pxe_arp.c#8 (text+ko) ====
@@ -132,6 +132,13 @@
ip4_src.ip = arp_reply->body.src_paddr;
ip4_dst.ip = arp_reply->body.target_paddr;
+ if (ip4_src.ip == pxe_get_ip32(PXE_IP_MY)) { /* got broadcast send by us */
+#ifdef PXE_DEBUG_HELL
+ printf("arp request from myself ignored.\n");
+#endif
+ return (0);
+ }
+
#ifdef PXE_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], mac_src[3], mac_src[4], mac_src[5],
@@ -179,8 +186,6 @@
if (arp_reply->hdr.operation != le2be16(PXE_ARPOP_REPLY) ) /* we don't need anything except replies on that stage */
return (0);
-
-
/* if arp_usage exceeds MAX_ARP_ENTRIES, occurs rewriting of earlier placed ARP entries.
* MAC may be lost, so protocol must check this case when creating packet (cause
* there used pointer to MAC in arp_table). May be better way is to panic if arp_table
@@ -192,7 +197,7 @@
if (NULL != kmac) {
#ifdef PXE_DEBUG
uint8_t *octet = (uint8_t *)&arp_reply->body.src_paddr;
- uint8_t *mac = arp_reply->body.src_hwaddr;
+/* 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]
@@ -283,8 +288,9 @@
return (PXE_AWAIT_CONTINUE);
break;
- case PXE_AWAIT_FINISHTRY: /* don't handle finish of try */
- printf("\npxe_arp_await(): ARP reply timeout.\n");
+ case PXE_AWAIT_FINISHTRY:
+ if (wait_data->mac == NULL) /* nothing got during try */
+ printf("\npxe_arp_await(): ARP reply timeout.\n");
break;
case PXE_AWAIT_END: /* wait ended */
==== //depot/projects/soc2007/taleks-pxe_http/pxe_core.c#15 (text+ko) ====
@@ -266,6 +266,7 @@
pxe_icmp_init();
pxe_socket_init();
pxe_udp_init();
+ pxe_tcp_init();
/* trying to get gateway/nameserver info from DHCP server */
pxe_dhcp_query(bootplayer.ident);
==== //depot/projects/soc2007/taleks-pxe_http/pxe_sock.c#8 (text+ko) ====
@@ -5,6 +5,7 @@
#include "pxe_filter.h"
#include "pxe_mem.h"
#include "pxe_sock.h"
+#include "pxe_tcp.h"
#include "pxe_udp.h"
static PXE_SOCKET pxe_sockets[PXE_DEFAULT_SOCKETS]; /* storage for socket describing structures */
@@ -418,6 +419,16 @@
sock->filter = entry;
sock->state = PXE_SOCKET_CONNECTED;
+
+ if (proto == PXE_TCP_PROTOCOL) {
+ /* trying handshaking */
+ if (pxe_tcp_connect(sock)) {
+ sock->state = PXE_SOCKET_ESTABLISHED;
+ } else { /* failed, cleanup */
+ pxe_filter_remove(entry);
+ return (0);
+ }
+ }
#ifdef PXE_DEBUG
printf("pxe_connect(): socket %d connected, 0x%x:%d -> 0x%x:%d\n", socket, pxe_get_ip32(PXE_IP_MY), lport, ip, port);
==== //depot/projects/soc2007/taleks-pxe_http/pxe_tcp.h#3 (text+ko) ====
@@ -8,6 +8,12 @@
#include <stdint.h>
#include <stddef.h>
#include "pxe_ip.h"
+#include "pxe_sock.h"
+
+/* maximum existing connections at one time */
+#define PXE_MAX_TCP_CONNECTIONS 4
+/* TCP IP stack protocol number*/
+#define PXE_TCP_PROTOCOL 6
/* tcp packet flags */
#define PXE_TCP_FIN 0x01
@@ -24,9 +30,7 @@
#define PXE_TCP_SYN_SENT 0x01 /* active */
#define PXE_TCP_SYN_RECIEVED 0x02 /* sent & received SYN */
-#define PXE_TCP_ESTABLISHED 0x03 /* established connection,
- * ready to send data
- */
+#define PXE_TCP_ESTABLISHED 0x03 /* established connection */
#define PXE_TCP_CLOSE_WAIT 0x04 /* got FIN, waiting to close */
#define PXE_TCP_LAST_ACK 0x05 /* got FIN, closing and waiting FIN ACK */
@@ -35,29 +39,54 @@
#define PXE_TCP_FIN_WAIT2 0x08 /* got FIN ACK */
#define PXE_TCP_TIME_WAIT 0x09 /* closed, waiting 2MSL*/
-#define PXE_TCP_MARK 0xf0 /* mark busy sockets */
+typedef struct pxe_tcp_hdr {
+
+ uint16_t src_port; /* local port */
+ uint16_t dst_port; /* remote port */
+ uint32_t sequence; /* seqence number */
+ uint32_t ack_next; /* ACK'd number */
+ uint8_t data_off; /* offset to data */
+ uint8_t flags; /* TCP flags, see higher TCP_FLAG_ */
+ uint16_t window_size; /* current window size */
+ uint16_t checksum; /* packet checksum*/
+ uint16_t urgent; /* urgent flags */
+} __packed PXE_TCP_HDR;
+
+typedef struct pxe_tcp_packet {
+
+ PXE_IP_HDR iphdr;
+ PXE_TCP_HDR tcphdr;
+} __packed PXE_TCP_PACKET;
+
+typedef struct pxe_tcp_connecton {
+
+ uint8_t state;
+ uint32_t next_recv;
+ uint32_t next_send;
+ uint16_t src_port;
+ uint16_t dst_port;
+ uint32_t dst_ip;
+ PXE_BUFFER *recv;
+ PXE_BUFFER *send;
+ PXE_SOCKET *sock;
+ time_t last_sent;
+ time_t last_recv;
+} PXE_TCP_CONNECTION;
+
+typedef struct pxe_tcp_wait_data {
-typedef struct pxe_tcp_header {
- uint16_t src_port;
- uint16_t dst_port;
- uint32_t sequence;
- uint32_t ack;
- uint8_t data_off;
- uint8_t flags;
- uint16_t window_size;
- uint16_t check_sum;
- uint16_t urgent;
- uint8_t options[3];
- uint8_t align;
-} PXE_TCP_HEADER;
+ uint8_t state; /* what state is waited for */
+ PXE_TCP_CONNECTION *connection; /* which connection is monitored */
+} __packed PXE_TCP_WAIT_DATA;
/* init tcp */
-int pxe_tcp_init();
+void pxe_tcp_init();
+
+/* sends data */
+int pxe_tcp_send(PXE_TCP_CONNECTION *connection, uint16_t size, uint8_t tcp_flags);
+
+/* initates handshaking */
+int pxe_tcp_connect(PXE_SOCKET* sock);
-/* send/recieve. Calling convention is still decided. */
-/* int pxe_tcp_send_packet(const pxe_socket* socket, void* data,
- size_t size, uint8_t flags);
- int pxe_tcp_recv_packet(const void* data, size_t size);
-*/
#endif // PXE_TCP_H_INCLUDED
More information about the p4-projects
mailing list