소스 검색

[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 년 전
부모
커밋
8430642642
4개의 변경된 파일12개의 추가작업 그리고 8개의 파일을 삭제
  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 파일 보기

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

+ 1
- 0
src/net/ipv4.c 파일 보기

@@ -714,6 +714,7 @@ struct tcpip_net_protocol ipv4_tcpip_protocol __tcpip_net_protocol = {
714 714
 	.name = "IPv4",
715 715
 	.sa_family = AF_INET,
716 716
 	.header_len = sizeof ( struct iphdr ),
717
+	.net_protocol = &ipv4_protocol,
717 718
 	.tx = ipv4_tx,
718 719
 	.netdev = ipv4_netdev,
719 720
 };

+ 1
- 0
src/net/ipv6.c 파일 보기

@@ -1001,6 +1001,7 @@ struct tcpip_net_protocol ipv6_tcpip_protocol __tcpip_net_protocol = {
1001 1001
 	.name = "IPv6",
1002 1002
 	.sa_family = AF_INET6,
1003 1003
 	.header_len = sizeof ( struct ipv6_header ),
1004
+	.net_protocol = &ipv6_protocol,
1004 1005
 	.tx = ipv6_tx,
1005 1006
 	.netdev = ipv6_netdev,
1006 1007
 };

+ 7
- 8
src/net/tcpip.c 파일 보기

@@ -62,19 +62,18 @@ int tcpip_rx ( struct io_buffer *iobuf, struct net_device *netdev,
62 62
 /**
63 63
  * Find TCP/IP network-layer protocol
64 64
  *
65
- * @v st_dest		Destination address
65
+ * @v sa_family		Address family
66 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 69
 	struct tcpip_net_protocol *tcpip_net;
71 70
 
72 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 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 77
 	return NULL;
79 78
 }
80 79
 
@@ -95,7 +94,7 @@ int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip_protocol,
95 94
 	struct tcpip_net_protocol *tcpip_net;
96 95
 
97 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 98
 	if ( tcpip_net ) {
100 99
 		DBG ( "TCP/IP sending %s packet\n", tcpip_net->name );
101 100
 		return tcpip_net->tx ( iobuf, tcpip_protocol, st_src, st_dest,
@@ -116,7 +115,7 @@ struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest ) {
116 115
 	struct tcpip_net_protocol *tcpip_net;
117 116
 
118 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 119
 	if ( tcpip_net )
121 120
 		return tcpip_net->netdev ( st_dest );
122 121
 
@@ -135,7 +134,7 @@ size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest ) {
135 134
 	size_t mtu;
136 135
 
137 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 138
 	if ( ! tcpip_net )
140 139
 		return 0;
141 140
 

Loading…
취소
저장