2004-09-29 05:10:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1997-1998 University of Utah and the Flux Group.
|
|
|
|
* All rights reserved.
|
2005-05-08 02:16:32 +00:00
|
|
|
*
|
2004-09-29 05:10:48 +00:00
|
|
|
* This file is part of the Flux OSKit. The OSKit is free software, also known
|
|
|
|
* as "open source;" you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License (GPL), version 2, as published by the Free
|
|
|
|
* Software Foundation (FSF). To explore alternate licensing terms, contact
|
|
|
|
* the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
|
2005-05-08 02:16:32 +00:00
|
|
|
*
|
2004-09-29 05:10:48 +00:00
|
|
|
* The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have
|
|
|
|
* received a copy of the GPL along with the OSKit; see the file COPYING. If
|
|
|
|
* not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
int if_index = 0;
|
|
|
|
struct ifaddr **ifnet_addrs;
|
|
|
|
|
|
|
|
int ifqmaxlen = OSK_IFQ_MAXLEN;
|
|
|
|
struct ifnet *ifnet;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Network interface utility routines.
|
|
|
|
*
|
|
|
|
* Routines with ifa_ifwith* names take sockaddr *'s as
|
|
|
|
* parameters.
|
|
|
|
*/
|
|
|
|
|
|
|
|
PVOID TCPPrepareInterface( PIP_INTERFACE IF ) {
|
|
|
|
NTSTATUS Status;
|
|
|
|
POSK_IFADDR ifaddr = exAllocatePool
|
|
|
|
( NonPagedPool, sizeof(*ifaddr) + 2 * sizeof( struct sockaddr_in ) );
|
2008-09-03 00:32:07 +00:00
|
|
|
if( !ifaddr ) return NULL;
|
2004-09-29 05:10:48 +00:00
|
|
|
struct sockaddr_in *addr_in = (struct sockaddr_in *)&ifaddr[1];
|
|
|
|
struct sockaddr_in *dstaddr_in = (struct sockaddr_in *)&addr_in[1];
|
|
|
|
|
2004-12-04 23:29:56 +00:00
|
|
|
TI_DbgPrint(DEBUG_TCPIF,("Called\n"));
|
2004-09-29 05:10:48 +00:00
|
|
|
|
|
|
|
ifaddr->ifa_dstaddr = (struct sockaddr *)dstaddr_in;
|
|
|
|
/* XXX - Point-to-point interfaces not supported yet */
|
|
|
|
memset( &ifaddr->ifa_dstaddr, 0, sizeof( struct sockaddr ) );
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2004-09-29 05:10:48 +00:00
|
|
|
ifaddr->ifa_addr = (struct sockaddr *)addr_in;
|
|
|
|
Status = GetInterfaceIPv4Address( IF,
|
|
|
|
ADE_UNICAST,
|
|
|
|
(PULONG)&addr_in->sin_addr.s_addr );
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2004-09-29 05:10:48 +00:00
|
|
|
if( !NT_SUCCESS(Status) )
|
|
|
|
addr_in->sin_addr.s_addr = 0;
|
|
|
|
|
2004-12-04 23:29:56 +00:00
|
|
|
TI_DbgPrint(DEBUG_TCPIF,("Prepare interface %x : addr %x\n",
|
2004-09-29 05:10:48 +00:00
|
|
|
IF, addr_in->sin_addr.s_addr));
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2004-09-29 05:10:48 +00:00
|
|
|
ifaddr->ifa_flags = 0; /* XXX what goes here? */
|
|
|
|
ifaddr->ifa_refcnt = 0; /* Anachronistic */
|
|
|
|
ifaddr->ifa_metric = 1; /* We can get it like in ninfo.c, if we want */
|
|
|
|
ifaddr->ifa_mtu = IF->MTU;
|
|
|
|
|
2004-12-04 23:29:56 +00:00
|
|
|
TI_DbgPrint(DEBUG_TCPIF,("Leaving\n"));
|
2004-09-29 05:10:48 +00:00
|
|
|
|
|
|
|
return ifaddr;
|
|
|
|
}
|
|
|
|
|
2005-04-17 07:55:24 +00:00
|
|
|
VOID TCPDisposeInterfaceData( PVOID Ptr ) {
|
|
|
|
exFreePool( Ptr );
|
|
|
|
}
|
|
|
|
|
2004-09-29 05:10:48 +00:00
|
|
|
POSK_IFADDR TCPFindInterface( void *ClientData,
|
|
|
|
OSK_UINT AddrType,
|
|
|
|
OSK_UINT FindType,
|
|
|
|
OSK_SOCKADDR *ReqAddr,
|
|
|
|
OSK_IFADDR *Interface ) {
|
2009-05-13 01:16:30 +00:00
|
|
|
PIP_INTERFACE IF;
|
2004-09-29 05:10:48 +00:00
|
|
|
IP_ADDRESS Destination;
|
|
|
|
struct sockaddr_in *addr_in = (struct sockaddr_in *)ReqAddr;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2004-12-04 23:29:56 +00:00
|
|
|
TI_DbgPrint(DEBUG_TCPIF,("called for type %d\n", FindType));
|
2004-09-29 05:10:48 +00:00
|
|
|
|
|
|
|
if( !ReqAddr ) {
|
2004-12-04 23:29:56 +00:00
|
|
|
TI_DbgPrint(DEBUG_TCPIF,("no addr or no ifaddr (%x)\n", ReqAddr));
|
2004-09-29 05:10:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Destination.Type = IP_ADDRESS_V4;
|
|
|
|
Destination.Address.IPv4Address = addr_in->sin_addr.s_addr;
|
|
|
|
|
2004-12-04 23:29:56 +00:00
|
|
|
TI_DbgPrint(DEBUG_TCPIF,("Address is %x\n", addr_in->sin_addr.s_addr));
|
2004-09-29 05:10:48 +00:00
|
|
|
|
2009-05-13 01:16:30 +00:00
|
|
|
IF = FindOnLinkInterface(&Destination);
|
2004-09-29 05:10:48 +00:00
|
|
|
|
2009-05-13 01:16:30 +00:00
|
|
|
if (!IF || !IF->TCPContext) {
|
|
|
|
/* TCPContext can be NULL if we don't have an IP address yet */
|
|
|
|
TI_DbgPrint(DEBUG_TCPIF, ("No interface or TCP context (%x) (%x)\n",
|
|
|
|
IF, IF ? IF->TCPContext : 0));
|
|
|
|
return NULL;
|
2004-09-29 05:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addr_in = (struct sockaddr_in *)
|
2009-05-13 01:16:30 +00:00
|
|
|
((POSK_IFADDR)IF->TCPContext)->ifa_addr;
|
|
|
|
|
2004-12-04 23:29:56 +00:00
|
|
|
TI_DbgPrint(DEBUG_TCPIF,("returning addr %x\n", addr_in->sin_addr.s_addr));
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2009-05-13 01:16:30 +00:00
|
|
|
return IF->TCPContext;
|
2004-09-29 05:10:48 +00:00
|
|
|
}
|
|
|
|
|