Kaynağa Gözat

Split non-TCP portions of the stack out into ip.[ch].

Added set_ipaddr().
tags/v0.9.3
Michael Brown 19 yıl önce
ebeveyn
işleme
b44332eb7d
5 değiştirilmiş dosya ile 137 ekleme ve 89 silme
  1. 18
    0
      src/include/gpxe/ip.h
  2. 0
    2
      src/include/gpxe/tcp.h
  3. 109
    0
      src/proto/ip.c
  4. 0
    77
      src/proto/tcp.c
  5. 10
    10
      src/proto/uip/uipopt.h

+ 18
- 0
src/include/gpxe/ip.h Dosyayı Görüntüle

@@ -0,0 +1,18 @@
1
+#ifndef _IP_H
2
+#define _IP_H
3
+
4
+/** @file
5
+ *
6
+ * IP protocol
7
+ *
8
+ * This file defines the gPXE IP API.
9
+ *
10
+ */
11
+
12
+#include <gpxe/in.h>
13
+
14
+extern void set_ipaddr ( struct in_addr address );
15
+extern void init_tcpip ( void );
16
+extern void run_tcpip ( void );
17
+
18
+#endif /* _IP_H */

+ 0
- 2
src/include/gpxe/tcp.h Dosyayı Görüntüle

@@ -96,7 +96,5 @@ extern int tcp_connect ( struct tcp_connection *conn );
96 96
 extern void tcp_send ( struct tcp_connection *conn, const void *data,
97 97
 		       size_t len );
98 98
 extern void tcp_close ( struct tcp_connection *conn );
99
-extern void init_tcpip ( void );
100
-extern void run_tcpip ( void );
101 99
 
102 100
 #endif /* _TCP_H */

+ 109
- 0
src/proto/ip.c Dosyayı Görüntüle

@@ -0,0 +1,109 @@
1
+#include <string.h>
2
+#include <stdint.h>
3
+#include <byteswap.h>
4
+#include <gpxe/in.h>
5
+#include <gpxe/ip.h>
6
+#include "uip/uip.h"
7
+#include "uip/uip_arp.h"
8
+
9
+/** @file
10
+ *
11
+ * IP protocol
12
+ *
13
+ * The gPXE IP stack is currently implemented on top of the uIP
14
+ * protocol stack.  This file provides wrappers around uIP so that
15
+ * higher-level protocol implementations do not need to talk directly
16
+ * to uIP (which has a somewhat baroque API).
17
+ *
18
+ */
19
+
20
+/**
21
+ * Set IP address
22
+ *
23
+ */
24
+void set_ipaddr ( struct in_addr address ) {
25
+	union {
26
+		struct in_addr address;
27
+		uint16_t uip_address[2];
28
+	} u;
29
+
30
+	u.address = address;
31
+	uip_sethostaddr ( u.uip_address );
32
+}
33
+
34
+/**
35
+ * Initialise TCP/IP stack
36
+ *
37
+ */
38
+void init_tcpip ( void ) {
39
+	uip_init();
40
+	uip_arp_init();
41
+}
42
+
43
+#define UIP_HLEN ( 40 + UIP_LLH_LEN )
44
+
45
+/**
46
+ * Transmit TCP data
47
+ *
48
+ * This is a wrapper around netdev_transmit().  It gathers up the
49
+ * packet produced by uIP, and then passes it to netdev_transmit() as
50
+ * a single buffer.
51
+ */
52
+static void uip_transmit ( void ) {
53
+	uip_arp_out();
54
+	if ( uip_len > UIP_HLEN ) {
55
+		memcpy ( uip_buf + UIP_HLEN, ( void * ) uip_appdata,
56
+			 uip_len - UIP_HLEN );
57
+	}
58
+	netdev_transmit ( uip_buf, uip_len );
59
+	uip_len = 0;
60
+}
61
+
62
+/**
63
+ * Run the TCP/IP stack
64
+ *
65
+ * Call this function in a loop in order to allow TCP/IP processing to
66
+ * take place.  This call takes the stack through a single iteration;
67
+ * it will typically be used in a loop such as
68
+ *
69
+ * @code
70
+ *
71
+ * struct tcp_connection *my_connection;
72
+ * ...
73
+ * tcp_connect ( my_connection );
74
+ * while ( ! my_connection->finished ) {
75
+ *   run_tcpip();
76
+ * }
77
+ *
78
+ * @endcode
79
+ *
80
+ * where @c my_connection->finished is set by one of the connection's
81
+ * #tcp_operations methods to indicate completion.
82
+ */
83
+void run_tcpip ( void ) {
84
+	void *data;
85
+	size_t len;
86
+	uint16_t type;
87
+	int i;
88
+	
89
+	if ( netdev_poll ( 1, &data, &len ) ) {
90
+		/* We have data */
91
+		memcpy ( uip_buf, data, len );
92
+		uip_len = len;
93
+		type = ntohs ( *( ( uint16_t * ) ( uip_buf + 12 ) ) );
94
+		if ( type == UIP_ETHTYPE_ARP ) {
95
+			uip_arp_arpin();
96
+		} else {
97
+			uip_arp_ipin();
98
+			uip_input();
99
+		}
100
+		if ( uip_len > 0 )
101
+			uip_transmit();
102
+	} else {
103
+		for ( i = 0 ; i < UIP_CONNS ; i++ ) {
104
+			uip_periodic ( i );
105
+			if ( uip_len > 0 )
106
+				uip_transmit();
107
+		}
108
+	}
109
+}

+ 0
- 77
src/proto/tcp.c Dosyayı Görüntüle

@@ -25,83 +25,6 @@
25 25
  *
26 26
  */
27 27
 
28
-/**
29
- * Initialise TCP/IP stack
30
- *
31
- */
32
-void init_tcpip ( void ) {
33
-	uip_init();
34
-	uip_arp_init();
35
-}
36
-
37
-#define UIP_HLEN ( 40 + UIP_LLH_LEN )
38
-
39
-/**
40
- * Transmit TCP data
41
- *
42
- * This is a wrapper around netdev_transmit().  It gathers up the
43
- * packet produced by uIP, and then passes it to netdev_transmit() as
44
- * a single buffer.
45
- */
46
-static void uip_transmit ( void ) {
47
-	uip_arp_out();
48
-	if ( uip_len > UIP_HLEN ) {
49
-		memcpy ( uip_buf + UIP_HLEN, ( void * ) uip_appdata,
50
-			 uip_len - UIP_HLEN );
51
-	}
52
-	netdev_transmit ( uip_buf, uip_len );
53
-	uip_len = 0;
54
-}
55
-
56
-/**
57
- * Run the TCP/IP stack
58
- *
59
- * Call this function in a loop in order to allow TCP/IP processing to
60
- * take place.  This call takes the stack through a single iteration;
61
- * it will typically be used in a loop such as
62
- *
63
- * @code
64
- *
65
- * struct tcp_connection *my_connection;
66
- * ...
67
- * tcp_connect ( my_connection );
68
- * while ( ! my_connection->finished ) {
69
- *   run_tcpip();
70
- * }
71
- *
72
- * @endcode
73
- *
74
- * where @c my_connection->finished is set by one of the connection's
75
- * #tcp_operations methods to indicate completion.
76
- */
77
-void run_tcpip ( void ) {
78
-	void *data;
79
-	size_t len;
80
-	uint16_t type;
81
-	int i;
82
-	
83
-	if ( netdev_poll ( 1, &data, &len ) ) {
84
-		/* We have data */
85
-		memcpy ( uip_buf, data, len );
86
-		uip_len = len;
87
-		type = ntohs ( *( ( uint16_t * ) ( uip_buf + 12 ) ) );
88
-		if ( type == UIP_ETHTYPE_ARP ) {
89
-			uip_arp_arpin();
90
-		} else {
91
-			uip_arp_ipin();
92
-			uip_input();
93
-		}
94
-		if ( uip_len > 0 )
95
-			uip_transmit();
96
-	} else {
97
-		for ( i = 0 ; i < UIP_CONNS ; i++ ) {
98
-			uip_periodic ( i );
99
-			if ( uip_len > 0 )
100
-				uip_transmit();
101
-		}
102
-	}
103
-}
104
-
105 28
 /**
106 29
  * Open a TCP connection
107 30
  *

+ 10
- 10
src/proto/uip/uipopt.h Dosyayı Görüntüle

@@ -114,7 +114,7 @@ typedef unsigned short uip_stats_t;
114 114
  *
115 115
  * \hideinitializer
116 116
  */
117
-#define UIP_FIXEDADDR    1
117
+#define UIP_FIXEDADDR    0
118 118
 
119 119
 /**
120 120
  * Ping IP address asignment.
@@ -130,42 +130,42 @@ typedef unsigned short uip_stats_t;
130 130
  */
131 131
 #define UIP_PINGADDRCONF 0
132 132
 
133
-#define UIP_IPADDR0     192 /**< The first octet of the IP address of
133
+#define UIP_IPADDR0     0   /**< The first octet of the IP address of
134 134
 			       this uIP node, if UIP_FIXEDADDR is
135 135
 			       1. \hideinitializer */
136
-#define UIP_IPADDR1     168 /**< The second octet of the IP address of
136
+#define UIP_IPADDR1     0   /**< The second octet of the IP address of
137 137
 			       this uIP node, if UIP_FIXEDADDR is
138 138
 			       1. \hideinitializer */
139 139
 #define UIP_IPADDR2     0   /**< The third octet of the IP address of
140 140
 			       this uIP node, if UIP_FIXEDADDR is
141 141
 			       1. \hideinitializer */
142
-#define UIP_IPADDR3     2   /**< The fourth octet of the IP address of
142
+#define UIP_IPADDR3     0   /**< The fourth octet of the IP address of
143 143
 			       this uIP node, if UIP_FIXEDADDR is
144 144
 			       1. \hideinitializer */
145 145
 
146
-#define UIP_NETMASK0    255 /**< The first octet of the netmask of
146
+#define UIP_NETMASK0    0   /**< The first octet of the netmask of
147 147
 			       this uIP node, if UIP_FIXEDADDR is
148 148
 			       1. \hideinitializer */
149
-#define UIP_NETMASK1    255 /**< The second octet of the netmask of
149
+#define UIP_NETMASK1    0   /**< The second octet of the netmask of
150 150
 			       this uIP node, if UIP_FIXEDADDR is
151 151
 			       1. \hideinitializer */
152
-#define UIP_NETMASK2    255 /**< The third octet of the netmask of
152
+#define UIP_NETMASK2    0   /**< The third octet of the netmask of
153 153
 			       this uIP node, if UIP_FIXEDADDR is
154 154
 			       1. \hideinitializer */
155 155
 #define UIP_NETMASK3    0   /**< The fourth octet of the netmask of
156 156
 			       this uIP node, if UIP_FIXEDADDR is
157 157
 			       1. \hideinitializer */
158 158
 
159
-#define UIP_DRIPADDR0   192 /**< The first octet of the IP address of
159
+#define UIP_DRIPADDR0   0   /**< The first octet of the IP address of
160 160
 			       the default router, if UIP_FIXEDADDR is
161 161
 			       1. \hideinitializer */
162
-#define UIP_DRIPADDR1   168 /**< The second octet of the IP address of
162
+#define UIP_DRIPADDR1   0   /**< The second octet of the IP address of
163 163
 			       the default router, if UIP_FIXEDADDR is
164 164
 			       1. \hideinitializer */
165 165
 #define UIP_DRIPADDR2   0   /**< The third octet of the IP address of
166 166
 			       the default router, if UIP_FIXEDADDR is
167 167
 			       1. \hideinitializer */
168
-#define UIP_DRIPADDR3   1   /**< The fourth octet of the IP address of
168
+#define UIP_DRIPADDR3   0   /**< The fourth octet of the IP address of
169 169
 			       the default router, if UIP_FIXEDADDR is
170 170
 			       1. \hideinitializer */
171 171
 

Loading…
İptal
Kaydet