summaryrefslogtreecommitdiffstats
path: root/src/proto
diff options
context:
space:
mode:
authorMichael Brown2006-03-24 18:22:09 +0100
committerMichael Brown2006-03-24 18:22:09 +0100
commitb44332eb7d76c329995c38993f8c7727d095cb81 (patch)
tree1bd0b2aab6611ad63d22a134a2d28adfe8691062 /src/proto
parentPut in a substitute pcap_inject() function, since earlier versions of (diff)
downloadipxe-b44332eb7d76c329995c38993f8c7727d095cb81.tar.gz
ipxe-b44332eb7d76c329995c38993f8c7727d095cb81.tar.xz
ipxe-b44332eb7d76c329995c38993f8c7727d095cb81.zip
Split non-TCP portions of the stack out into ip.[ch].
Added set_ipaddr().
Diffstat (limited to 'src/proto')
-rw-r--r--src/proto/ip.c109
-rw-r--r--src/proto/tcp.c77
-rw-r--r--src/proto/uip/uipopt.h20
3 files changed, 119 insertions, 87 deletions
diff --git a/src/proto/ip.c b/src/proto/ip.c
new file mode 100644
index 00000000..3f46377c
--- /dev/null
+++ b/src/proto/ip.c
@@ -0,0 +1,109 @@
+#include <string.h>
+#include <stdint.h>
+#include <byteswap.h>
+#include <gpxe/in.h>
+#include <gpxe/ip.h>
+#include "uip/uip.h"
+#include "uip/uip_arp.h"
+
+/** @file
+ *
+ * IP protocol
+ *
+ * The gPXE IP stack is currently implemented on top of the uIP
+ * protocol stack. This file provides wrappers around uIP so that
+ * higher-level protocol implementations do not need to talk directly
+ * to uIP (which has a somewhat baroque API).
+ *
+ */
+
+/**
+ * Set IP address
+ *
+ */
+void set_ipaddr ( struct in_addr address ) {
+ union {
+ struct in_addr address;
+ uint16_t uip_address[2];
+ } u;
+
+ u.address = address;
+ uip_sethostaddr ( u.uip_address );
+}
+
+/**
+ * Initialise TCP/IP stack
+ *
+ */
+void init_tcpip ( void ) {
+ uip_init();
+ uip_arp_init();
+}
+
+#define UIP_HLEN ( 40 + UIP_LLH_LEN )
+
+/**
+ * Transmit TCP data
+ *
+ * This is a wrapper around netdev_transmit(). It gathers up the
+ * packet produced by uIP, and then passes it to netdev_transmit() as
+ * a single buffer.
+ */
+static void uip_transmit ( void ) {
+ uip_arp_out();
+ if ( uip_len > UIP_HLEN ) {
+ memcpy ( uip_buf + UIP_HLEN, ( void * ) uip_appdata,
+ uip_len - UIP_HLEN );
+ }
+ netdev_transmit ( uip_buf, uip_len );
+ uip_len = 0;
+}
+
+/**
+ * Run the TCP/IP stack
+ *
+ * Call this function in a loop in order to allow TCP/IP processing to
+ * take place. This call takes the stack through a single iteration;
+ * it will typically be used in a loop such as
+ *
+ * @code
+ *
+ * struct tcp_connection *my_connection;
+ * ...
+ * tcp_connect ( my_connection );
+ * while ( ! my_connection->finished ) {
+ * run_tcpip();
+ * }
+ *
+ * @endcode
+ *
+ * where @c my_connection->finished is set by one of the connection's
+ * #tcp_operations methods to indicate completion.
+ */
+void run_tcpip ( void ) {
+ void *data;
+ size_t len;
+ uint16_t type;
+ int i;
+
+ if ( netdev_poll ( 1, &data, &len ) ) {
+ /* We have data */
+ memcpy ( uip_buf, data, len );
+ uip_len = len;
+ type = ntohs ( *( ( uint16_t * ) ( uip_buf + 12 ) ) );
+ if ( type == UIP_ETHTYPE_ARP ) {
+ uip_arp_arpin();
+ } else {
+ uip_arp_ipin();
+ uip_input();
+ }
+ if ( uip_len > 0 )
+ uip_transmit();
+ } else {
+ for ( i = 0 ; i < UIP_CONNS ; i++ ) {
+ uip_periodic ( i );
+ if ( uip_len > 0 )
+ uip_transmit();
+ }
+ }
+}
diff --git a/src/proto/tcp.c b/src/proto/tcp.c
index 8c732015..e12fff7c 100644
--- a/src/proto/tcp.c
+++ b/src/proto/tcp.c
@@ -26,83 +26,6 @@
*/
/**
- * Initialise TCP/IP stack
- *
- */
-void init_tcpip ( void ) {
- uip_init();
- uip_arp_init();
-}
-
-#define UIP_HLEN ( 40 + UIP_LLH_LEN )
-
-/**
- * Transmit TCP data
- *
- * This is a wrapper around netdev_transmit(). It gathers up the
- * packet produced by uIP, and then passes it to netdev_transmit() as
- * a single buffer.
- */
-static void uip_transmit ( void ) {
- uip_arp_out();
- if ( uip_len > UIP_HLEN ) {
- memcpy ( uip_buf + UIP_HLEN, ( void * ) uip_appdata,
- uip_len - UIP_HLEN );
- }
- netdev_transmit ( uip_buf, uip_len );
- uip_len = 0;
-}
-
-/**
- * Run the TCP/IP stack
- *
- * Call this function in a loop in order to allow TCP/IP processing to
- * take place. This call takes the stack through a single iteration;
- * it will typically be used in a loop such as
- *
- * @code
- *
- * struct tcp_connection *my_connection;
- * ...
- * tcp_connect ( my_connection );
- * while ( ! my_connection->finished ) {
- * run_tcpip();
- * }
- *
- * @endcode
- *
- * where @c my_connection->finished is set by one of the connection's
- * #tcp_operations methods to indicate completion.
- */
-void run_tcpip ( void ) {
- void *data;
- size_t len;
- uint16_t type;
- int i;
-
- if ( netdev_poll ( 1, &data, &len ) ) {
- /* We have data */
- memcpy ( uip_buf, data, len );
- uip_len = len;
- type = ntohs ( *( ( uint16_t * ) ( uip_buf + 12 ) ) );
- if ( type == UIP_ETHTYPE_ARP ) {
- uip_arp_arpin();
- } else {
- uip_arp_ipin();
- uip_input();
- }
- if ( uip_len > 0 )
- uip_transmit();
- } else {
- for ( i = 0 ; i < UIP_CONNS ; i++ ) {
- uip_periodic ( i );
- if ( uip_len > 0 )
- uip_transmit();
- }
- }
-}
-
-/**
* Open a TCP connection
*
* @v conn TCP connection
diff --git a/src/proto/uip/uipopt.h b/src/proto/uip/uipopt.h
index 15070a71..811284e1 100644
--- a/src/proto/uip/uipopt.h
+++ b/src/proto/uip/uipopt.h
@@ -114,7 +114,7 @@ typedef unsigned short uip_stats_t;
*
* \hideinitializer
*/
-#define UIP_FIXEDADDR 1
+#define UIP_FIXEDADDR 0
/**
* Ping IP address asignment.
@@ -130,42 +130,42 @@ typedef unsigned short uip_stats_t;
*/
#define UIP_PINGADDRCONF 0
-#define UIP_IPADDR0 192 /**< The first octet of the IP address of
+#define UIP_IPADDR0 0 /**< The first octet of the IP address of
this uIP node, if UIP_FIXEDADDR is
1. \hideinitializer */
-#define UIP_IPADDR1 168 /**< The second octet of the IP address of
+#define UIP_IPADDR1 0 /**< The second octet of the IP address of
this uIP node, if UIP_FIXEDADDR is
1. \hideinitializer */
#define UIP_IPADDR2 0 /**< The third octet of the IP address of
this uIP node, if UIP_FIXEDADDR is
1. \hideinitializer */
-#define UIP_IPADDR3 2 /**< The fourth octet of the IP address of
+#define UIP_IPADDR3 0 /**< The fourth octet of the IP address of
this uIP node, if UIP_FIXEDADDR is
1. \hideinitializer */
-#define UIP_NETMASK0 255 /**< The first octet of the netmask of
+#define UIP_NETMASK0 0 /**< The first octet of the netmask of
this uIP node, if UIP_FIXEDADDR is
1. \hideinitializer */
-#define UIP_NETMASK1 255 /**< The second octet of the netmask of
+#define UIP_NETMASK1 0 /**< The second octet of the netmask of
this uIP node, if UIP_FIXEDADDR is
1. \hideinitializer */
-#define UIP_NETMASK2 255 /**< The third octet of the netmask of
+#define UIP_NETMASK2 0 /**< The third octet of the netmask of
this uIP node, if UIP_FIXEDADDR is
1. \hideinitializer */
#define UIP_NETMASK3 0 /**< The fourth octet of the netmask of
this uIP node, if UIP_FIXEDADDR is
1. \hideinitializer */
-#define UIP_DRIPADDR0 192 /**< The first octet of the IP address of
+#define UIP_DRIPADDR0 0 /**< The first octet of the IP address of
the default router, if UIP_FIXEDADDR is
1. \hideinitializer */
-#define UIP_DRIPADDR1 168 /**< The second octet of the IP address of
+#define UIP_DRIPADDR1 0 /**< The second octet of the IP address of
the default router, if UIP_FIXEDADDR is
1. \hideinitializer */
#define UIP_DRIPADDR2 0 /**< The third octet of the IP address of
the default router, if UIP_FIXEDADDR is
1. \hideinitializer */
-#define UIP_DRIPADDR3 1 /**< The fourth octet of the IP address of
+#define UIP_DRIPADDR3 0 /**< The fourth octet of the IP address of
the default router, if UIP_FIXEDADDR is
1. \hideinitializer */