diff options
author | Michael Brown | 2014-03-04 13:54:21 +0100 |
---|---|---|
committer | Michael Brown | 2014-03-04 14:02:58 +0100 |
commit | db67de6f31a062dc1995d4561be83cd51609d6c4 (patch) | |
tree | 642ebb50e33c2a720d40769dd59010ce0d5b8e05 /src/net/ipv4.c | |
parent | [prefix] Ignore PCI autoboot device location if set to 00:00.0 (diff) | |
download | ipxe-db67de6f31a062dc1995d4561be83cd51609d6c4.tar.gz ipxe-db67de6f31a062dc1995d4561be83cd51609d6c4.tar.xz ipxe-db67de6f31a062dc1995d4561be83cd51609d6c4.zip |
[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>
Diffstat (limited to 'src/net/ipv4.c')
-rw-r--r-- | src/net/ipv4.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/net/ipv4.c b/src/net/ipv4.c index d9a54ade..8bda5c86 100644 --- a/src/net/ipv4.c +++ b/src/net/ipv4.c @@ -138,6 +138,25 @@ static struct ipv4_miniroute * ipv4_route ( struct in_addr *dest ) { } /** + * 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 * * @v fragment 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 */ |