Browse Source

[tcpip] Allow supported address families to be detected at runtime

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
8430642642
4 changed files with 12 additions and 8 deletions
  1. 3
    0
      src/include/ipxe/tcpip.h
  2. 1
    0
      src/net/ipv4.c
  3. 1
    0
      src/net/ipv6.c
  4. 7
    8
      src/net/tcpip.c

+ 3
- 0
src/include/ipxe/tcpip.h View File

106
 	sa_family_t sa_family;
106
 	sa_family_t sa_family;
107
 	/** Fixed header length */
107
 	/** Fixed header length */
108
 	size_t header_len;
108
 	size_t header_len;
109
+	/** Network-layer protocol */
110
+	struct net_protocol *net_protocol;
109
 	/**
111
 	/**
110
 	 * Transmit packet
112
 	 * Transmit packet
111
 	 *
113
 	 *
156
 		      struct sockaddr_tcpip *st_dest,
158
 		      struct sockaddr_tcpip *st_dest,
157
 		      struct net_device *netdev,
159
 		      struct net_device *netdev,
158
 		      uint16_t *trans_csum );
160
 		      uint16_t *trans_csum );
161
+extern struct tcpip_net_protocol * tcpip_net_protocol ( sa_family_t sa_family );
159
 extern struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest );
162
 extern struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest );
160
 extern size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest );
163
 extern size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest );
161
 extern uint16_t generic_tcpip_continue_chksum ( uint16_t partial,
164
 extern uint16_t generic_tcpip_continue_chksum ( uint16_t partial,

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

714
 	.name = "IPv4",
714
 	.name = "IPv4",
715
 	.sa_family = AF_INET,
715
 	.sa_family = AF_INET,
716
 	.header_len = sizeof ( struct iphdr ),
716
 	.header_len = sizeof ( struct iphdr ),
717
+	.net_protocol = &ipv4_protocol,
717
 	.tx = ipv4_tx,
718
 	.tx = ipv4_tx,
718
 	.netdev = ipv4_netdev,
719
 	.netdev = ipv4_netdev,
719
 };
720
 };

+ 1
- 0
src/net/ipv6.c View File

1001
 	.name = "IPv6",
1001
 	.name = "IPv6",
1002
 	.sa_family = AF_INET6,
1002
 	.sa_family = AF_INET6,
1003
 	.header_len = sizeof ( struct ipv6_header ),
1003
 	.header_len = sizeof ( struct ipv6_header ),
1004
+	.net_protocol = &ipv6_protocol,
1004
 	.tx = ipv6_tx,
1005
 	.tx = ipv6_tx,
1005
 	.netdev = ipv6_netdev,
1006
 	.netdev = ipv6_netdev,
1006
 };
1007
 };

+ 7
- 8
src/net/tcpip.c View File

62
 /**
62
 /**
63
  * Find TCP/IP network-layer protocol
63
  * Find TCP/IP network-layer protocol
64
  *
64
  *
65
- * @v st_dest		Destination address
65
+ * @v sa_family		Address family
66
  * @ret tcpip_net	TCP/IP network-layer protocol, or NULL if not found
66
  * @ret tcpip_net	TCP/IP network-layer protocol, or NULL if not found
67
  */
67
  */
68
-static struct tcpip_net_protocol *
69
-tcpip_net_protocol ( struct sockaddr_tcpip *st_dest ) {
68
+struct tcpip_net_protocol * tcpip_net_protocol ( sa_family_t sa_family ) {
70
 	struct tcpip_net_protocol *tcpip_net;
69
 	struct tcpip_net_protocol *tcpip_net;
71
 
70
 
72
 	for_each_table_entry ( tcpip_net, TCPIP_NET_PROTOCOLS ) {
71
 	for_each_table_entry ( tcpip_net, TCPIP_NET_PROTOCOLS ) {
73
-		if ( tcpip_net->sa_family == st_dest->st_family )
72
+		if ( tcpip_net->sa_family == sa_family )
74
 			return tcpip_net;
73
 			return tcpip_net;
75
 	}
74
 	}
76
 
75
 
77
-	DBG ( "Unrecognised TCP/IP address family %d\n", st_dest->st_family );
76
+	DBG ( "Unrecognised TCP/IP address family %d\n", sa_family );
78
 	return NULL;
77
 	return NULL;
79
 }
78
 }
80
 
79
 
95
 	struct tcpip_net_protocol *tcpip_net;
94
 	struct tcpip_net_protocol *tcpip_net;
96
 
95
 
97
 	/* Hand off packet to the appropriate network-layer protocol */
96
 	/* Hand off packet to the appropriate network-layer protocol */
98
-	tcpip_net = tcpip_net_protocol ( st_dest );
97
+	tcpip_net = tcpip_net_protocol ( st_dest->st_family );
99
 	if ( tcpip_net ) {
98
 	if ( tcpip_net ) {
100
 		DBG ( "TCP/IP sending %s packet\n", tcpip_net->name );
99
 		DBG ( "TCP/IP sending %s packet\n", tcpip_net->name );
101
 		return tcpip_net->tx ( iobuf, tcpip_protocol, st_src, st_dest,
100
 		return tcpip_net->tx ( iobuf, tcpip_protocol, st_src, st_dest,
116
 	struct tcpip_net_protocol *tcpip_net;
115
 	struct tcpip_net_protocol *tcpip_net;
117
 
116
 
118
 	/* Hand off to the appropriate network-layer protocol */
117
 	/* Hand off to the appropriate network-layer protocol */
119
-	tcpip_net = tcpip_net_protocol ( st_dest );
118
+	tcpip_net = tcpip_net_protocol ( st_dest->st_family );
120
 	if ( tcpip_net )
119
 	if ( tcpip_net )
121
 		return tcpip_net->netdev ( st_dest );
120
 		return tcpip_net->netdev ( st_dest );
122
 
121
 
135
 	size_t mtu;
134
 	size_t mtu;
136
 
135
 
137
 	/* Find appropriate network-layer protocol */
136
 	/* Find appropriate network-layer protocol */
138
-	tcpip_net = tcpip_net_protocol ( st_dest );
137
+	tcpip_net = tcpip_net_protocol ( st_dest->st_family );
139
 	if ( ! tcpip_net )
138
 	if ( ! tcpip_net )
140
 		return 0;
139
 		return 0;
141
 
140
 

Loading…
Cancel
Save