mirror of https://github.com/ipxe/ipxe.git
[tcpip] Allow supported address families to be detected at runtime
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/41/head
parent
f6e1da5cbf
commit
8430642642
|
@ -106,6 +106,8 @@ struct tcpip_net_protocol {
|
||||||
sa_family_t sa_family;
|
sa_family_t sa_family;
|
||||||
/** Fixed header length */
|
/** Fixed header length */
|
||||||
size_t header_len;
|
size_t header_len;
|
||||||
|
/** Network-layer protocol */
|
||||||
|
struct net_protocol *net_protocol;
|
||||||
/**
|
/**
|
||||||
* Transmit packet
|
* Transmit packet
|
||||||
*
|
*
|
||||||
|
@ -156,6 +158,7 @@ extern int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip,
|
||||||
struct sockaddr_tcpip *st_dest,
|
struct sockaddr_tcpip *st_dest,
|
||||||
struct net_device *netdev,
|
struct net_device *netdev,
|
||||||
uint16_t *trans_csum );
|
uint16_t *trans_csum );
|
||||||
|
extern struct tcpip_net_protocol * tcpip_net_protocol ( sa_family_t sa_family );
|
||||||
extern struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest );
|
extern struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest );
|
||||||
extern size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest );
|
extern size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest );
|
||||||
extern uint16_t generic_tcpip_continue_chksum ( uint16_t partial,
|
extern uint16_t generic_tcpip_continue_chksum ( uint16_t partial,
|
||||||
|
|
|
@ -714,6 +714,7 @@ struct tcpip_net_protocol ipv4_tcpip_protocol __tcpip_net_protocol = {
|
||||||
.name = "IPv4",
|
.name = "IPv4",
|
||||||
.sa_family = AF_INET,
|
.sa_family = AF_INET,
|
||||||
.header_len = sizeof ( struct iphdr ),
|
.header_len = sizeof ( struct iphdr ),
|
||||||
|
.net_protocol = &ipv4_protocol,
|
||||||
.tx = ipv4_tx,
|
.tx = ipv4_tx,
|
||||||
.netdev = ipv4_netdev,
|
.netdev = ipv4_netdev,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1001,6 +1001,7 @@ struct tcpip_net_protocol ipv6_tcpip_protocol __tcpip_net_protocol = {
|
||||||
.name = "IPv6",
|
.name = "IPv6",
|
||||||
.sa_family = AF_INET6,
|
.sa_family = AF_INET6,
|
||||||
.header_len = sizeof ( struct ipv6_header ),
|
.header_len = sizeof ( struct ipv6_header ),
|
||||||
|
.net_protocol = &ipv6_protocol,
|
||||||
.tx = ipv6_tx,
|
.tx = ipv6_tx,
|
||||||
.netdev = ipv6_netdev,
|
.netdev = ipv6_netdev,
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,19 +62,18 @@ int tcpip_rx ( struct io_buffer *iobuf, struct net_device *netdev,
|
||||||
/**
|
/**
|
||||||
* Find TCP/IP network-layer protocol
|
* Find TCP/IP network-layer protocol
|
||||||
*
|
*
|
||||||
* @v st_dest Destination address
|
* @v sa_family Address family
|
||||||
* @ret tcpip_net TCP/IP network-layer protocol, or NULL if not found
|
* @ret tcpip_net TCP/IP network-layer protocol, or NULL if not found
|
||||||
*/
|
*/
|
||||||
static struct tcpip_net_protocol *
|
struct tcpip_net_protocol * tcpip_net_protocol ( sa_family_t sa_family ) {
|
||||||
tcpip_net_protocol ( struct sockaddr_tcpip *st_dest ) {
|
|
||||||
struct tcpip_net_protocol *tcpip_net;
|
struct tcpip_net_protocol *tcpip_net;
|
||||||
|
|
||||||
for_each_table_entry ( tcpip_net, TCPIP_NET_PROTOCOLS ) {
|
for_each_table_entry ( tcpip_net, TCPIP_NET_PROTOCOLS ) {
|
||||||
if ( tcpip_net->sa_family == st_dest->st_family )
|
if ( tcpip_net->sa_family == sa_family )
|
||||||
return tcpip_net;
|
return tcpip_net;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBG ( "Unrecognised TCP/IP address family %d\n", st_dest->st_family );
|
DBG ( "Unrecognised TCP/IP address family %d\n", sa_family );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +94,7 @@ int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip_protocol,
|
||||||
struct tcpip_net_protocol *tcpip_net;
|
struct tcpip_net_protocol *tcpip_net;
|
||||||
|
|
||||||
/* Hand off packet to the appropriate network-layer protocol */
|
/* Hand off packet to the appropriate network-layer protocol */
|
||||||
tcpip_net = tcpip_net_protocol ( st_dest );
|
tcpip_net = tcpip_net_protocol ( st_dest->st_family );
|
||||||
if ( tcpip_net ) {
|
if ( tcpip_net ) {
|
||||||
DBG ( "TCP/IP sending %s packet\n", tcpip_net->name );
|
DBG ( "TCP/IP sending %s packet\n", tcpip_net->name );
|
||||||
return tcpip_net->tx ( iobuf, tcpip_protocol, st_src, st_dest,
|
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 ) {
|
||||||
struct tcpip_net_protocol *tcpip_net;
|
struct tcpip_net_protocol *tcpip_net;
|
||||||
|
|
||||||
/* Hand off to the appropriate network-layer protocol */
|
/* Hand off to the appropriate network-layer protocol */
|
||||||
tcpip_net = tcpip_net_protocol ( st_dest );
|
tcpip_net = tcpip_net_protocol ( st_dest->st_family );
|
||||||
if ( tcpip_net )
|
if ( tcpip_net )
|
||||||
return tcpip_net->netdev ( st_dest );
|
return tcpip_net->netdev ( st_dest );
|
||||||
|
|
||||||
|
@ -135,7 +134,7 @@ size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest ) {
|
||||||
size_t mtu;
|
size_t mtu;
|
||||||
|
|
||||||
/* Find appropriate network-layer protocol */
|
/* Find appropriate network-layer protocol */
|
||||||
tcpip_net = tcpip_net_protocol ( st_dest );
|
tcpip_net = tcpip_net_protocol ( st_dest->st_family );
|
||||||
if ( ! tcpip_net )
|
if ( ! tcpip_net )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue