Vista fixes.
authorThomas Lopatic <thomas@lopatic.de>
Mon, 26 Mar 2007 15:33:44 +0000 (15:33 +0000)
committerThomas Lopatic <thomas@lopatic.de>
Mon, 26 Mar 2007 15:33:44 +0000 (15:33 +0000)
make/Makefile.win32
src/win32/ifnet.c
src/win32/kernel_routes.c

index 3a05d8a..5f68847 100644 (file)
@@ -8,7 +8,7 @@ EXENAME = olsrd.exe
 SRCS +=                $(wildcard src/win32/*.c)
 HDRS +=                $(wildcard src/win32/*.h)
 
-DEFINES +=     -DWIN32 -D_WIN32_WINNT=0x0501
+DEFINES +=     -DWIN32 -D_WIN32_WINNT=0x0600
 LIBS +=                -mno-cygwin -lws2_32 -liphlpapi
 INCLUDES +=    -I$(TOPDIR)/src/win32
 CFLAGS +=      -mno-cygwin
index a8e9703..74c4e5b 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: ifnet.c,v 1.32 2006/10/11 20:58:45 tlopatic Exp $
+ * $Id: ifnet.c,v 1.33 2007/03/26 15:33:44 tlopatic Exp $
  */
 
 #include "interfaces.h"
 #include <iphlpapi.h>
 #include <iprtrmib.h>
 
+struct MibIpInterfaceRow
+{
+  USHORT Family;
+  ULONG64 InterfaceLuid;
+  ULONG InterfaceIndex;
+  ULONG MaxReassemblySize;
+  ULONG64 InterfaceIdentifier;
+  ULONG MinRouterAdvertisementInterval;
+  ULONG MaxRouterAdvertisementInterval;
+  BOOLEAN AdvertisingEnabled;
+  BOOLEAN ForwardingEnabled;
+  BOOLEAN WeakHostSend;
+  BOOLEAN WeakHostReceive;
+  BOOLEAN UseAutomaticMetric;
+  BOOLEAN UseNeighborUnreachabilityDetection;   
+  BOOLEAN ManagedAddressConfigurationSupported;
+  BOOLEAN OtherStatefulConfigurationSupported;
+  BOOLEAN AdvertiseDefaultRoute;
+  INT RouterDiscoveryBehavior;
+  ULONG DadTransmits;
+  ULONG BaseReachableTime;
+  ULONG RetransmitTime;
+  ULONG PathMtuDiscoveryTimeout;
+  INT LinkLocalAddressBehavior;
+  ULONG LinkLocalAddressTimeout;
+  ULONG ZoneIndices[16];
+  ULONG SitePrefixLength;
+  ULONG Metric;
+  ULONG NlMtu;    
+  BOOLEAN Connected;
+  BOOLEAN SupportsWakeUpPatterns;   
+  BOOLEAN SupportsNeighborDiscovery;
+  BOOLEAN SupportsRouterDiscovery;
+  ULONG ReachableTime;
+  BYTE TransmitOffload;
+  BYTE ReceiveOffload; 
+  BOOLEAN DisableDefaultRoutes;
+};
+
+typedef DWORD (__stdcall *GETIPINTERFACEENTRY)
+  (struct MibIpInterfaceRow *Row);
+
+typedef DWORD (__stdcall *GETADAPTERSADDRESSES)
+  (ULONG Family, DWORD Flags, PVOID Reserved,
+   PIP_ADAPTER_ADDRESSES pAdapterAddresses, PULONG pOutBufLen);
+
 struct InterfaceInfo
 {
   unsigned int Index;
   int Mtu;
+  int Metric;
   unsigned int Addr;
   unsigned int Mask;
   unsigned int Broad;
@@ -134,11 +181,6 @@ static int IntNameToMiniIndex(int *MiniIndex, char *String)
 
 static int FriendlyNameToMiniIndex(int *MiniIndex, char *String)
 {
-  typedef DWORD (*GETADAPTERSADDRESSES)(ULONG Family,
-                                        DWORD Flags,
-                                        PVOID Reserved,
-                                        PIP_ADAPTER_ADDRESSES pAdapterAddresses,
-                                        PULONG pOutBufLen);
   unsigned long BuffLen;
   unsigned long Res;
   IP_ADAPTER_ADDRESSES AdAddr[MAX_INTERFACES], *WalkerAddr;
@@ -202,6 +244,8 @@ int GetIntInfo(struct InterfaceInfo *Info, char *Name)
   unsigned long Res;
   int TabIdx;
   IP_ADAPTER_INFO AdInfo[MAX_INTERFACES], *Walker;
+  HMODULE Lib;
+  struct MibIpInterfaceRow Row;
 
   if (olsr_cnf->ip_version == AF_INET6)
   {
@@ -260,6 +304,47 @@ int GetIntInfo(struct InterfaceInfo *Info, char *Name)
   Info->Mtu -= (olsr_cnf->ip_version == AF_INET6) ?
     UDP_IPV6_HDRSIZE : UDP_IPV4_HDRSIZE;
 
+  Lib = LoadLibrary("iphlpapi.dll");
+
+  if (Lib == NULL)
+  {
+    fprintf(stderr, "Cannot load iphlpapi.dll: %08lx\n", GetLastError());
+    return -1;
+  }
+
+  GETIPINTERFACEENTRY InterfaceEntry =
+    (GETIPINTERFACEENTRY)GetProcAddress(Lib, "GetIpInterfaceEntry");
+
+  if (InterfaceEntry == NULL)
+  {
+    OLSR_PRINTF(5, "Not running on Vista - setting interface metric to 0.\n");
+
+    Info->Metric = 0;
+  }
+
+  else
+  {
+    memset(&Row, 0, sizeof (struct MibIpInterfaceRow));
+
+    Row.Family = AF_INET;
+    Row.InterfaceIndex = Info->Index;
+
+    Res = InterfaceEntry(&Row);
+
+    if (Res != NO_ERROR)
+    {
+      fprintf(stderr, "GetIpInterfaceEntry() = %08lx", Res);
+      FreeLibrary(Lib);
+      return -1;
+    }
+
+    Info->Metric = Row.Metric;
+
+    OLSR_PRINTF(5, "Running on Vista - interface metric is %d.\n", Info->Metric);
+  }
+
+  FreeLibrary(Lib);
+
   BuffLen = sizeof (AdInfo);
 
   Res = GetAdaptersInfo(AdInfo, &BuffLen);
@@ -357,7 +442,7 @@ static int IsWireless(char *IntName)
 
     CloseHandle(DevHand);
 
-    if (ErrNo == ERROR_GEN_FAILURE)
+    if (ErrNo == ERROR_GEN_FAILURE || ErrNo == ERROR_INVALID_PARAMETER)
     {
       OLSR_PRINTF(5, "OID not supported. Device probably not wireless.\n")
       return 0;
@@ -739,7 +824,7 @@ int chk_if_changed(struct olsr_if *IntConf)
       Int->int_metric = IntConf->cnf->weight.value;
 
     else
-      Int->int_metric = IsWlan;
+      Int->int_metric = Info.Metric;
 
     Res = 1;
   }
@@ -911,7 +996,7 @@ int chk_if_up(struct olsr_if *IntConf, int DebugLevel)
     New->int_metric = IntConf->cnf->weight.value;
 
   else
-    New->int_metric = IsWlan;
+    New->int_metric = Info.Metric;
 
   New->olsr_seqnum = random() & 0xffff;
 
index 457e718..e54c95e 100644 (file)
@@ -36,7 +36,7 @@
  * to the project. For more information see the website or contact
  * the copyright holders.
  *
- * $Id: kernel_routes.c,v 1.15 2005/02/27 10:48:05 kattemat Exp $
+ * $Id: kernel_routes.c,v 1.16 2007/03/26 15:33:44 tlopatic Exp $
  */
 
 #include <stdio.h>
@@ -63,17 +63,25 @@ int olsr_ioctl_add_route(struct rt_entry *Dest)
   inet_ntop(AF_INET, &Dest->rt_router.v4, Str3, 16);
 
   OLSR_PRINTF(1, "Adding IPv4 route with metric %d to %s/%s via %s and I/F 0x%x.\n",
-              Dest->rt_metric, Str1, Str2, Str3, Dest->rt_if->if_index)
+              Dest->rt_metric + Dest->rt_if->int_metric, Str1, Str2, Str3, Dest->rt_if->if_index)
 
   memset(&Row, 0, sizeof (MIB_IPFORWARDROW));
 
   Row.dwForwardDest = Dest->rt_dst.v4;
   Row.dwForwardMask = Dest->rt_mask.v4;
+  Row.dwForwardPolicy = 0;
   Row.dwForwardNextHop = Dest->rt_router.v4;
   Row.dwForwardIfIndex = Dest->rt_if->if_index;
+  // MIB_IPROUTE_TYPE_DIRECT and MIB_IPROUTE_TYPE_INDIRECT
   Row.dwForwardType = (Dest->rt_dst.v4 == Dest->rt_router.v4) ? 3 : 4;
-  Row.dwForwardProto = 3; // PROTO_IP_NETMGMT
-  Row.dwForwardMetric1 = Dest->rt_metric;
+  Row.dwForwardProto = 3; // MIB_IPPROTO_NETMGMT
+  Row.dwForwardAge = INFINITE;
+  Row.dwForwardNextHopAS = 0;
+  Row.dwForwardMetric1 = Dest->rt_metric + Dest->rt_if->int_metric;
+  Row.dwForwardMetric2 = -1;
+  Row.dwForwardMetric3 = -1;
+  Row.dwForwardMetric4 = -1;
+  Row.dwForwardMetric5 = -1;
 
   Res = SetIpForwardEntry(&Row);
 
@@ -119,17 +127,25 @@ int olsr_ioctl_del_route(struct rt_entry *Dest)
   inet_ntop(AF_INET, &Dest->rt_router.v4, Str3, 16);
 
   OLSR_PRINTF(1, "Deleting IPv4 route with metric %d to %s/%s via %s and I/F 0x%x.\n",
-              Dest->rt_metric, Str1, Str2, Str3, Dest->rt_if->if_index)
+              Dest->rt_metric + Dest->rt_if->int_metric, Str1, Str2, Str3, Dest->rt_if->if_index)
 
   memset(&Row, 0, sizeof (MIB_IPFORWARDROW));
 
   Row.dwForwardDest = Dest->rt_dst.v4;
   Row.dwForwardMask = Dest->rt_mask.v4;
+  Row.dwForwardPolicy = 0;
   Row.dwForwardNextHop = Dest->rt_router.v4;
   Row.dwForwardIfIndex = Dest->rt_if->if_index;
+  // MIB_IPROUTE_TYPE_DIRECT and MIB_IPROUTE_TYPE_INDIRECT
   Row.dwForwardType = (Dest->rt_dst.v4 == Dest->rt_router.v4) ? 3 : 4;
-  Row.dwForwardProto = 3; // PROTO_IP_NETMGMT
-  Row.dwForwardMetric1 = Dest->rt_metric;
+  Row.dwForwardProto = 3; // MIB_IPPROTO_NETMGMT
+  Row.dwForwardAge = INFINITE;
+  Row.dwForwardNextHopAS = 0;
+  Row.dwForwardMetric1 = Dest->rt_metric + Dest->rt_if->int_metric;
+  Row.dwForwardMetric2 = -1;
+  Row.dwForwardMetric3 = -1;
+  Row.dwForwardMetric4 = -1;
+  Row.dwForwardMetric5 = -1;
 
   Res = DeleteIpForwardEntry(&Row);