Browse Source

Minor changes to the network layer rx() functions

tags/v0.9.3
Nikhil Chandru Rao 18 years ago
parent
commit
c24546c70b
5 changed files with 79 additions and 10 deletions
  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 View File

66
 
66
 
67
 extern int ipv4_uip_tx ( struct pk_buff *pkb );
67
 extern int ipv4_uip_tx ( struct pk_buff *pkb );
68
 extern int ipv4_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip,
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
 #endif /* _GPXE_IP_H */
71
 #endif /* _GPXE_IP_H */

+ 14
- 3
src/include/gpxe/tcpip.h View File

31
          *
31
          *
32
          * This method takes ownership of the packet buffer.
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
 	 * Transport-layer protocol number
38
 	 * Transport-layer protocol number
37
 	 *
39
 	 *
42
 	 * Checksum offset
44
 	 * Checksum offset
43
 	 *
45
 	 *
44
 	 * A negative number indicates that the protocol does not require
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
 	int csum_offset;
50
 	int csum_offset;
49
 };
51
 };
56
 	struct net_protocol *net_protocol;
58
 	struct net_protocol *net_protocol;
57
 	/** Network address family */
59
 	/** Network address family */
58
 	sa_family_t sa_family;
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
 	/** Complete transport-layer checksum calculation
70
 	/** Complete transport-layer checksum calculation
60
 	 *
71
 	 *
61
 	 * @v pkb		Packet buffer
72
 	 * @v pkb		Packet buffer

+ 4
- 1
src/net/ipv4.c View File

347
  * This function expects a transport-layer segment and prepends the IP header
347
  * This function expects a transport-layer segment and prepends the IP header
348
  */
348
  */
349
 int ipv4_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip,
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
 	struct iphdr *iphdr = pkb_push ( pkb, sizeof ( *iphdr ) );
352
 	struct iphdr *iphdr = pkb_push ( pkb, sizeof ( *iphdr ) );
352
 	struct ipv4_miniroute *miniroute;
353
 	struct ipv4_miniroute *miniroute;
353
 	struct net_device *netdev = NULL;
354
 	struct net_device *netdev = NULL;
613
 /** IPv4 TCPIP net protocol */
614
 /** IPv4 TCPIP net protocol */
614
 struct tcpip_net_protocol ipv4_tcpip_protocol = {
615
 struct tcpip_net_protocol ipv4_tcpip_protocol = {
615
 	.net_protocol = &ipv4_protocol,
616
 	.net_protocol = &ipv4_protocol,
617
+	.sa_family = AF_INET,
618
+	.tx = ipv4_tx,
616
 	.tx_csum = ipv4_tx_csum,
619
 	.tx_csum = ipv4_tx_csum,
617
 };
620
 };
618
 
621
 

+ 36
- 2
src/net/ipv6.c View File

1
 #include <errno.h>
1
 #include <errno.h>
2
+#include <stdlib.h>
3
+#include <stdint.h>
4
+#include <string.h>
5
+#include <byteswap.h>
2
 #include <gpxe/pkbuff.h>
6
 #include <gpxe/pkbuff.h>
3
 #include <gpxe/netdevice.h>
7
 #include <gpxe/netdevice.h>
4
 #include <gpxe/in.h>
8
 #include <gpxe/in.h>
9
+#include <gpxe/if_ether.h>
10
+#include <gpxe/tcpip.h>
5
 
11
 
6
 /**
12
 /**
7
  * Transmit IP6 packets
13
  * Transmit IP6 packets
8
- *
9
- * Placeholder to allow linking. The function should be placed in net/ipv6.c
10
  */
14
  */
11
 int ipv6_tx ( struct pk_buff *pkb __unused, uint16_t trans_proto __unused,
15
 int ipv6_tx ( struct pk_buff *pkb __unused, uint16_t trans_proto __unused,
12
 	      struct in6_addr *dest __unused) {
16
 	      struct in6_addr *dest __unused) {
22
 	       struct net_device *netdev __unused,
26
 	       struct net_device *netdev __unused,
23
 	       const void *ll_source __unused ) {
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 View File

5
 #include <byteswap.h>
5
 #include <byteswap.h>
6
 #include <gpxe/in.h>
6
 #include <gpxe/in.h>
7
 #include <gpxe/ip.h>
7
 #include <gpxe/ip.h>
8
+#include <gpxe/ip6.h>
8
 #include <gpxe/pkbuff.h>
9
 #include <gpxe/pkbuff.h>
9
 #include <gpxe/tables.h>
10
 #include <gpxe/tables.h>
10
 #include <gpxe/netdevice.h>
11
 #include <gpxe/netdevice.h>
41
 	/* Identify the transport layer protocol */
42
 	/* Identify the transport layer protocol */
42
 	for ( tcpip = tcpip_protocols; tcpip <= tcpip_protocols_end; ++tcpip ) {
43
 	for ( tcpip = tcpip_protocols; tcpip <= tcpip_protocols_end; ++tcpip ) {
43
 		if ( tcpip->trans_proto == trans_proto ) {
44
 		if ( tcpip->trans_proto == trans_proto ) {
44
-			DBG ( "Packet sent to %s module", tcpip->name );
45
 			tcpip->rx ( pkb, src, dest );
45
 			tcpip->rx ( pkb, src, dest );
46
 		}
46
 		}
47
 	}
47
 	}
57
 int tcpip_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip,
57
 int tcpip_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip,
58
 	       struct sockaddr *sock ) {
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
 	/* Identify the network layer protocol and send it using xxx_tx() */
79
 	/* Identify the network layer protocol and send it using xxx_tx() */
61
 	switch ( sock->sa_family ) {
80
 	switch ( sock->sa_family ) {
62
 	case AF_INET: /* IPv4 network family */
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
 	case AF_INET6: /* IPv6 network family */
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
 	DBG ( "Network family %d not supported", sock->sa_family );
86
 	DBG ( "Network family %d not supported", sock->sa_family );
68
 	return -EAFNOSUPPORT;
87
 	return -EAFNOSUPPORT;
69
 }
88
 }
70
 
89
 
90
+#endif
91
+
71
 /**
92
 /**
72
  * Calculate continued TCP/IP checkum
93
  * Calculate continued TCP/IP checkum
73
  *
94
  *

Loading…
Cancel
Save