From db67de6f31a062dc1995d4561be83cd51609d6c4 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 4 Mar 2014 12:54:21 +0000 Subject: [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 --- src/net/ipv4.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/net/ipv4.c') diff --git a/src/net/ipv4.c b/src/net/ipv4.c index d9a54adeb..8bda5c86f 100644 --- a/src/net/ipv4.c +++ b/src/net/ipv4.c @@ -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 */ -- cgit v1.2.3-55-g7522