Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
4.4 KiB

  1. #include "oscfg.h"
  2. #include "ndis.h"
  3. #include "ip6imp.h"
  4. #include "ip6def.h"
  5. #include "ipexport.h"
  6. #include "icmp.h"
  7. #include "neighbor.h"
  8. #include "route.h"
  9. #include <tdiinfo.h>
  10. #include <tdi.h>
  11. #include <tdistat.h>
  12. #include "info.h"
  13. #include "fragment.h"
  14. //* IPv6QueryInfo - IP query information handler.
  15. //
  16. // Called by the upper layer when it wants to query information about us.
  17. // We take in an ID, a buffer and length, and a context value, and return
  18. // whatever information we can.
  19. //
  20. // Input: ID - Pointer to ID structure.
  21. // Buffer - Pointer to buffer chain.
  22. // Size - Pointer to size in bytes of buffer. On return, filled
  23. // in with bytes read.
  24. // Context - Pointer to context value.
  25. //
  26. // Returns: TDI_STATUS of attempt to read information.
  27. //
  28. TDI_STATUS
  29. IPv6QueryInfo(
  30. TDIObjectID *ID,
  31. PNDIS_BUFFER Buffer,
  32. uint *Size,
  33. void *Context,
  34. uint ContextSize)
  35. {
  36. uint BufferSize = *Size;
  37. uint BytesCopied;
  38. uint Entity;
  39. uint Instance;
  40. Entity = ID->toi_entity.tei_entity;
  41. Instance = ID->toi_entity.tei_instance;
  42. *Size = 0; // Set to 0 in case of an error.
  43. // See if it's something we might handle.
  44. if ((Entity != CL_NL_ENTITY) || (Instance != 0))
  45. return TDI_INVALID_REQUEST;
  46. // The request is for us.
  47. if ((ID->toi_class != INFO_CLASS_PROTOCOL) &&
  48. (ID->toi_type != INFO_TYPE_PROVIDER))
  49. return TDI_INVALID_PARAMETER;
  50. switch (ID->toi_id) {
  51. case IP6_MIB_STATS_ID: {
  52. uint Offset = 0;
  53. int fStatus;
  54. IPInternalPerCpuStats SumCpuStats;
  55. if (BufferSize < sizeof(IPSNMPInfo))
  56. return TDI_BUFFER_TOO_SMALL;
  57. IPSInfo.ipsi_defaultttl = DefaultCurHopLimit;
  58. IPSInfo.ipsi_reasmtimeout = DEFAULT_REASSEMBLY_TIMEOUT;
  59. IPSInfo.ipsi_forwarding = (NumForwardingInterfaces > 0)?
  60. IP_FORWARDING : IP_NOT_FORWARDING;
  61. IPSGetTotalCounts(&SumCpuStats);
  62. IPSInfo.ipsi_inreceives = SumCpuStats.ics_inreceives;
  63. IPSInfo.ipsi_indelivers = SumCpuStats.ics_indelivers;
  64. IPSInfo.ipsi_outrequests = SumCpuStats.ics_outrequests;
  65. IPSInfo.ipsi_forwdatagrams = SumCpuStats.ics_forwdatagrams;
  66. fStatus = CopyToNdisSafe(Buffer, NULL, (PVOID)&IPSInfo,
  67. sizeof(IPSNMPInfo), &Offset);
  68. if (!fStatus)
  69. return TDI_NO_RESOURCES;
  70. BytesCopied = sizeof(IPSNMPInfo);
  71. }
  72. break;
  73. case ICMP6_MIB_STATS_ID: {
  74. uint Offset = 0;
  75. int fStatus;
  76. if (BufferSize < sizeof(ICMPv6SNMPInfo))
  77. return TDI_BUFFER_TOO_SMALL;
  78. fStatus = CopyToNdisSafe(Buffer, &Buffer, (uchar *) &ICMPv6InStats,
  79. sizeof(ICMPv6Stats), &Offset);
  80. if (!fStatus)
  81. return (TDI_NO_RESOURCES);
  82. fStatus = CopyToNdisSafe(Buffer, NULL, (uchar *) &ICMPv6OutStats,
  83. sizeof(ICMPv6Stats), &Offset);
  84. if (!fStatus)
  85. return (TDI_NO_RESOURCES);
  86. BytesCopied = sizeof(ICMPv6SNMPInfo);
  87. }
  88. break;
  89. case IP6_GET_BEST_ROUTE_ID: {
  90. TDI_ADDRESS_IP6 *In = (TDI_ADDRESS_IP6 *) Context;
  91. IP6RouteEntry Ire;
  92. uint Offset;
  93. IP_STATUS Status;
  94. int fStatus;
  95. if (ContextSize < sizeof(TDI_ADDRESS_IP6))
  96. return TDI_INVALID_PARAMETER;
  97. if (BufferSize < sizeof(IP6RouteEntry))
  98. return TDI_BUFFER_OVERFLOW;
  99. Status = GetBestRouteInfo((struct in6_addr *)In->sin6_addr,
  100. In->sin6_scope_id, &Ire);
  101. if (Status != IP_SUCCESS)
  102. return TDI_DEST_HOST_UNREACH;
  103. Offset = 0;
  104. fStatus = CopyToNdisSafe(Buffer, &Buffer, (PVOID)&Ire,
  105. Ire.ire_Length, &Offset);
  106. if (!fStatus)
  107. return TDI_NO_RESOURCES;
  108. BytesCopied = sizeof(IP6RouteEntry);
  109. }
  110. break;
  111. default:
  112. return TDI_INVALID_PARAMETER;
  113. }
  114. *Size = BytesCopied;
  115. return TDI_SUCCESS;
  116. }