[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

@@ -137,6 +137,25 @@ static struct ipv4_miniroute * ipv4_route ( struct in_addr *dest ) {
return NULL;
}
/**
* Determine transmitting network device
*
* @v st_dest Destination network-layer address
* @ret netdev Transmitting network device, or NULL
*/
static struct net_device * ipv4_netdev ( struct sockaddr_tcpip *st_dest ) {
struct sockaddr_in *sin_dest = ( ( struct sockaddr_in * ) st_dest );
struct in_addr dest = sin_dest->sin_addr;
struct ipv4_miniroute *miniroute;
/* Find routing table entry */
miniroute = ipv4_route ( &dest );
if ( ! miniroute )
return NULL;
return miniroute->netdev;
}
/**
* Check if IPv4 fragment matches fragment reassembly buffer
*
@@ -603,6 +622,7 @@ struct tcpip_net_protocol ipv4_tcpip_protocol __tcpip_net_protocol = {
.name = "IPv4",
.sa_family = AF_INET,
.tx = ipv4_tx,
.netdev = ipv4_netdev,
};
/** IPv4 ARP protocol */