Quellcode durchsuchen

Minor changes to the network layer rx() functions

tags/v0.9.3
Nikhil Chandru Rao vor 18 Jahren
Ursprung
Commit
c24546c70b
5 geänderte Dateien mit 79 neuen und 10 gelöschten Zeilen
  1. 1
    1
      src/include/gpxe/ip.h
  2. 14
    3
      src/include/gpxe/tcpip.h
  3. 4
    1
      src/net/ipv4.c
  4. 36
    2
      src/net/ipv6.c
  5. 24
    3
      src/net/tcpip.c

+ 1
- 1
src/include/gpxe/ip.h Datei anzeigen

@@ -66,6 +66,6 @@ extern void del_ipv4_address ( struct net_device *netdev );
66 66
 
67 67
 extern int ipv4_uip_tx ( struct pk_buff *pkb );
68 68
 extern int ipv4_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip,
69
-		     struct in_addr *dest );
69
+		     struct sockaddr *sock );
70 70
 
71 71
 #endif /* _GPXE_IP_H */

+ 14
- 3
src/include/gpxe/tcpip.h Datei anzeigen

@@ -31,7 +31,9 @@ struct tcpip_protocol {
31 31
          *
32 32
          * This method takes ownership of the packet buffer.
33 33
          */
34
-        void ( * rx ) ( struct pk_buff *pkb, struct in_addr *src_net_addr, struct in_addr *dest_net_addr );
34
+        void ( * rx ) ( struct pk_buff *pkb, struct in_addr *src_net_addr,
35
+			struct in_addr *dest_net_addr );
36
+
35 37
         /** 
36 38
 	 * Transport-layer protocol number
37 39
 	 *
@@ -42,8 +44,8 @@ struct tcpip_protocol {
42 44
 	 * Checksum offset
43 45
 	 *
44 46
 	 * A negative number indicates that the protocol does not require
45
-	 * checksumming to be performed by the network layer. A positive number is
46
-	 * the offset of the checksum field in the transport-layer header.
47
+	 * checksumming to be performed by the network layer. A positive number
48
+	 * is the offset of the checksum field in the transport-layer header.
47 49
 	 */
48 50
 	int csum_offset;
49 51
 };
@@ -56,6 +58,15 @@ struct tcpip_net_protocol {
56 58
 	struct net_protocol *net_protocol;
57 59
 	/** Network address family */
58 60
 	sa_family_t sa_family;
61
+	/**
62
+	 * Transmit packet
63
+	 *
64
+	 * @v pkb		Packet buffer
65
+ 	 * @v tcpip		Transport-layer TCP/IP protocol
66
+	 * @v sock		Socket address
67
+	 */
68
+	int ( * tx ) ( struct pk_buff *pkb, struct tcpip_protocol *tcpip,
69
+			struct sockaddr *sock ); 
59 70
 	/** Complete transport-layer checksum calculation
60 71
 	 *
61 72
 	 * @v pkb		Packet buffer

+ 4
- 1
src/net/ipv4.c Datei anzeigen

@@ -347,7 +347,8 @@ int ipv4_uip_tx ( struct pk_buff *pkb ) {
347 347
  * This function expects a transport-layer segment and prepends the IP header
348 348
  */
349 349
 int ipv4_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip,
350
-	      struct in_addr *dest ) {
350
+	      struct sockaddr* sock ) {
351
+	struct in_addr *dest = &sock->sin.sin_addr;
351 352
 	struct iphdr *iphdr = pkb_push ( pkb, sizeof ( *iphdr ) );
352 353
 	struct ipv4_miniroute *miniroute;
353 354
 	struct net_device *netdev = NULL;
@@ -613,6 +614,8 @@ NET_PROTOCOL ( ipv4_protocol );
613 614
 /** IPv4 TCPIP net protocol */
614 615
 struct tcpip_net_protocol ipv4_tcpip_protocol = {
615 616
 	.net_protocol = &ipv4_protocol,
617
+	.sa_family = AF_INET,
618
+	.tx = ipv4_tx,
616 619
 	.tx_csum = ipv4_tx_csum,
617 620
 };
618 621
 

+ 36
- 2
src/net/ipv6.c Datei anzeigen

@@ -1,12 +1,16 @@
1 1
 #include <errno.h>
2
+#include <stdlib.h>
3
+#include <stdint.h>
4
+#include <string.h>
5
+#include <byteswap.h>
2 6
 #include <gpxe/pkbuff.h>
3 7
 #include <gpxe/netdevice.h>
4 8
 #include <gpxe/in.h>
9
+#include <gpxe/if_ether.h>
10
+#include <gpxe/tcpip.h>
5 11
 
6 12
 /**
7 13
  * Transmit IP6 packets
8
- *
9
- * Placeholder to allow linking. The function should be placed in net/ipv6.c
10 14
  */
11 15
 int ipv6_tx ( struct pk_buff *pkb __unused, uint16_t trans_proto __unused,
12 16
 	      struct in6_addr *dest __unused) {
@@ -22,3 +26,33 @@ void ipv6_rx ( struct pk_buff *pkb __unused,
22 26
 	       struct net_device *netdev __unused,
23 27
 	       const void *ll_source __unused ) {
24 28
 }
29
+
30
+void ipv6_tx_csum ( struct pk_buff *pkb, struct tcpip_protocol *tcpip ) {
31
+	return;
32
+}
33
+
34
+static const char * ipv6_ntoa ( const void *net_addr ) {
35
+//	return inet6_ntoa ( * ( ( struct in6_addr * ) net_addr ) );
36
+	return "no support yet";
37
+}
38
+
39
+/** IPv6 protocol */
40
+struct net_protocol ipv6_protocol = {
41
+	.name = "IP6",
42
+	.net_proto = htons ( ETH_P_IPV6 ),
43
+	.net_addr_len = sizeof ( struct in6_addr ),
44
+	.rx = ipv6_rx,
45
+	.ntoa = ipv6_ntoa,
46
+};
47
+
48
+NET_PROTOCOL ( ipv6_protocol );
49
+
50
+/** IPv6 TCPIP net protocol */
51
+struct tcpip_net_protocol ipv6_tcpip_protocol = {
52
+	.net_protocol = &ipv6_protocol,
53
+	.sa_family = AF_INET6,
54
+	.tx = ipv6_tx,
55
+	.tx_csum = ipv6_tx_csum,
56
+};
57
+
58
+TCPIP_NET_PROTOCOL ( ipv6_tcpip_protocol );

+ 24
- 3
src/net/tcpip.c Datei anzeigen

@@ -5,6 +5,7 @@
5 5
 #include <byteswap.h>
6 6
 #include <gpxe/in.h>
7 7
 #include <gpxe/ip.h>
8
+#include <gpxe/ip6.h>
8 9
 #include <gpxe/pkbuff.h>
9 10
 #include <gpxe/tables.h>
10 11
 #include <gpxe/netdevice.h>
@@ -41,7 +42,6 @@ void tcpip_rx ( struct pk_buff *pkb, uint8_t trans_proto, struct in_addr *src,
41 42
 	/* Identify the transport layer protocol */
42 43
 	for ( tcpip = tcpip_protocols; tcpip <= tcpip_protocols_end; ++tcpip ) {
43 44
 		if ( tcpip->trans_proto == trans_proto ) {
44
-			DBG ( "Packet sent to %s module", tcpip->name );
45 45
 			tcpip->rx ( pkb, src, dest );
46 46
 		}
47 47
 	}
@@ -57,17 +57,38 @@ void tcpip_rx ( struct pk_buff *pkb, uint8_t trans_proto, struct in_addr *src,
57 57
 int tcpip_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip,
58 58
 	       struct sockaddr *sock ) {
59 59
 
60
+#if 0 /* This is the right thing to do */
61
+
62
+	struct tcpip_net_protocol *tcpip_net;
63
+
64
+	/* Identify the network layer protocol */
65
+	for ( tcpip_net = tcpip_net_protocols; 
66
+			tcpip_net <= tcpip_net_protocols_end; ++tcpip_net ) {
67
+		if ( tcpip_net->sa_family == sock->sa_family ) {
68
+			DBG ( "Packet sent to %s module\n", tcpip_net->net_protocol->name );
69
+			return tcpip_net->tx ( pkb, tcpip, sock );
70
+		}
71
+	}
72
+	DBG ( "No suitable network layer protocol found for sa_family %s\n",
73
+						( sock->sa_family );
74
+	return -EAFNOSUPPORT;
75
+}
76
+
77
+#else
78
+
60 79
 	/* Identify the network layer protocol and send it using xxx_tx() */
61 80
 	switch ( sock->sa_family ) {
62 81
 	case AF_INET: /* IPv4 network family */
63
-		return ipv4_tx ( pkb, tcpip, &sock->sin.sin_addr );
82
+		return ipv4_tx ( pkb, tcpip, sock );
64 83
 	case AF_INET6: /* IPv6 network family */
65
-		return ipv6_tx ( pkb, tcpip, &sock->sin6.sin6_addr );
84
+		return ipv6_tx ( pkb, tcpip, sock );
66 85
 	}
67 86
 	DBG ( "Network family %d not supported", sock->sa_family );
68 87
 	return -EAFNOSUPPORT;
69 88
 }
70 89
 
90
+#endif
91
+
71 92
 /**
72 93
  * Calculate continued TCP/IP checkum
73 94
  *

Laden…
Abbrechen
Speichern