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.

189 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. dod.c
  5. Abstract:
  6. This module contains code for a simple map-route-to-interface driver
  7. Author:
  8. Abolade Gbadegesin (aboladeg) 15-Aug-1999
  9. Revision History:
  10. Based on tcpip\tools\pfd.
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. extern PDEVICE_OBJECT IpDeviceObject = NULL;
  15. extern PFILE_OBJECT IpFileObject = NULL;
  16. extern PDEVICE_OBJECT DodDeviceObject = NULL;
  17. uint
  18. DodMapRouteToInterface(
  19. ROUTE_CONTEXT Context,
  20. IPAddr Destination,
  21. IPAddr Source,
  22. uchar Protocol,
  23. uchar* Buffer,
  24. uint Length,
  25. IPAddr HdrSrc
  26. )
  27. {
  28. return INVALID_IF_INDEX;
  29. } // DodMapRouteToInterface
  30. NTSTATUS
  31. DodSetMapRouteToInterfaceHook(
  32. BOOLEAN Install
  33. )
  34. {
  35. IP_SET_MAP_ROUTE_HOOK_INFO HookInfo;
  36. IO_STATUS_BLOCK IoStatus;
  37. PIRP Irp;
  38. KEVENT LocalEvent;
  39. NTSTATUS status;
  40. KdPrint(("DodSetMapRouteToInterfaceHook\n"));
  41. HookInfo.MapRoutePtr = Install ? DodMapRouteToInterface : NULL;
  42. KeInitializeEvent(&LocalEvent, SynchronizationEvent, FALSE);
  43. Irp = IoBuildDeviceIoControlRequest(IOCTL_IP_SET_MAP_ROUTE_POINTER,
  44. IpDeviceObject,
  45. (PVOID)&HookInfo, sizeof(HookInfo),
  46. NULL, 0, FALSE, &LocalEvent, &IoStatus);
  47. if (!Irp) {
  48. KdPrint(("DodSetMapRouteToInterfaceHook: IoBuildDeviceIoControlRequest=0\n"));
  49. return STATUS_UNSUCCESSFUL;
  50. }
  51. status = IoCallDriver(IpDeviceObject, Irp);
  52. if (status == STATUS_PENDING) {
  53. KeWaitForSingleObject(&LocalEvent, Executive, KernelMode, FALSE, NULL);
  54. status = IoStatus.Status;
  55. }
  56. if (!NT_SUCCESS(status)) {
  57. KdPrint(("DodSetMapRouteToInterfaceHook: SetMapRoutePointer=%x\n", status));
  58. }
  59. return status;
  60. } // DodSetMapRouteToInterfaceHook
  61. NTSTATUS
  62. DodInitializeDriver(
  63. VOID
  64. )
  65. {
  66. OBJECT_ATTRIBUTES ObjectAttributes;
  67. NTSTATUS status;
  68. UNICODE_STRING UnicodeString;
  69. KdPrint(("DodInitializeDriver\n"));
  70. RtlInitUnicodeString(&UnicodeString, DD_IP_DEVICE_NAME);
  71. status = IoGetDeviceObjectPointer(&UnicodeString,
  72. SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE,
  73. &IpFileObject, &IpDeviceObject);
  74. if (!NT_SUCCESS(status)) {
  75. KdPrint(("DodInitializeDriver: error %X getting IP object\n", status));
  76. return status;
  77. }
  78. ObReferenceObject(IpDeviceObject);
  79. return DodSetMapRouteToInterfaceHook(TRUE);
  80. } // DodInitializeDriver
  81. VOID
  82. DodUnloadDriver(
  83. IN PDRIVER_OBJECT DriverObject
  84. )
  85. /*++
  86. Routine Description:
  87. Performs cleanup for the filter-driver.
  88. Arguments:
  89. DriverObject - reference to the module's driver-object
  90. Return Value:
  91. --*/
  92. {
  93. KdPrint(("DodUnloadDriver\n"));
  94. DodSetMapRouteToInterfaceHook(FALSE);
  95. IoDeleteDevice(DriverObject->DeviceObject);
  96. ObDereferenceObject((PVOID)IpFileObject);
  97. ObDereferenceObject(IpDeviceObject);
  98. } // DodUnloadDriver
  99. NTSTATUS
  100. DriverEntry(
  101. IN PDRIVER_OBJECT DriverObject,
  102. IN PUNICODE_STRING RegistryPath
  103. )
  104. /*++
  105. Routine Description:
  106. Performs driver-initialization for the filter driver.
  107. Arguments:
  108. Return Value:
  109. STATUS_SUCCESS if initialization succeeded, error code otherwise.
  110. --*/
  111. {
  112. WCHAR DeviceName[] = DD_IP_DOD_DEVICE_NAME;
  113. UNICODE_STRING DeviceString;
  114. NTSTATUS status;
  115. PAGED_CODE();
  116. KdPrint(("DodDriverEntry\n"));
  117. RtlInitUnicodeString(&DeviceString, DeviceName);
  118. status = IoCreateDevice(DriverObject, 0, &DeviceString,
  119. FILE_DEVICE_NETWORK, FILE_DEVICE_SECURE_OPEN,
  120. FALSE, &DodDeviceObject);
  121. if (!NT_SUCCESS(status)) {
  122. KdPrint(("IoCreateDevice failed (0x%08X)\n", status));
  123. return status;
  124. }
  125. DriverObject->DriverUnload = DodUnloadDriver;
  126. DriverObject->DriverStartIo = NULL;
  127. status = DodInitializeDriver();
  128. return status;
  129. } // DriverEntry