[tcpip] Provide tcpip_netdev() to determine the transmitting network device

Provide the function tcpip_netdev() to allow external code to
determine the transmitting network device for a given socket address.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2014-03-04 12:54:21 +00:00
parent ff1e7fc72b
commit db67de6f31
4 changed files with 94 additions and 10 deletions

View File

@@ -321,6 +321,25 @@ static struct ipv6_miniroute * ipv6_route ( unsigned int scope_id,
return NULL;
}
/**
* Determine transmitting network device
*
* @v st_dest Destination network-layer address
* @ret netdev Transmitting network device, or NULL
*/
static struct net_device * ipv6_netdev ( struct sockaddr_tcpip *st_dest ) {
struct sockaddr_in6 *sin6_dest = ( ( struct sockaddr_in6 * ) st_dest );
struct in6_addr *dest = &sin6_dest->sin6_addr;
struct ipv6_miniroute *miniroute;
/* Find routing table entry */
miniroute = ipv6_route ( sin6_dest->sin6_scope_id, &dest );
if ( ! miniroute )
return NULL;
return miniroute->netdev;
}
/**
* Check that received options can be safely ignored
*
@@ -970,6 +989,7 @@ struct tcpip_net_protocol ipv6_tcpip_protocol __tcpip_net_protocol = {
.name = "IPv6",
.sa_family = AF_INET6,
.tx = ipv6_tx,
.netdev = ipv6_netdev,
};
/** IPv6 socket address converter */