共用方式為


處理通知註標

篩選引擎會呼叫 callout 的 notifyFn 函數,以通知 callout 驅動程式關於與 callout 相關的事件。

新增篩選器

將指定篩選器動作回呼的篩選條件新增至篩選引擎時,篩選引擎會呼叫回呼函式 notifyFn,並在 notifyType 參數中傳遞 FWPS_CALLOUT_NOTIFY_ADD_FILTER。

描述驅動程式可以在那些指定描述為篩選條件動作的篩選器已經加入篩選引擎後,於篩選引擎中註冊描述。 在此情況下,篩選引擎不會呼叫 notifyFn 回調函式,以通知回調有任何現有的篩選條件。

篩選引擎只有在新增指定該呼出程序進行篩選操作的新篩選條件時,才會呼叫呼出程序的 notifyFn 函式來通知呼出程序。 在此情況下,notifyFn callout 函式可能不會被指定用於篩選操作的篩選引擎中的每個篩選呼叫。

如果呼叫端驅動程式在啟動篩選引擎之後註冊了呼叫端,而且呼叫端必須接收篩選引擎中指定該呼叫端作為篩選動作的每個篩選的資訊,則呼叫端驅動程式必須呼叫適當的管理功能,以列舉篩選引擎中的所有篩選。 呼叫驅動程式必須排序所有篩選器的結果清單,以找出那些為篩選器行動指定呼叫項目的篩選器。 如需呼叫這些函式的詳細資訊,請參閱 呼叫其他 Windows 篩選平臺函式

篩選刪除

從篩選引擎中刪除指定篩選動作註標的篩選條件時,篩選引擎會呼叫圖說文字的 notifyFn 圖說函式,並在 notifyType 參數中傳遞FWPS_CALLOUT_NOTIFY_DELETE_FILTER,並在 filterKey 參數中傳遞 null。 篩選引擎會針對篩選引擎中每個已刪除的篩選條件呼叫圖說文字 notifyFn 圖說文字函式,以指定篩選動作的圖說文字。 這包括在呼叫驅動程式向篩選引擎註冊呼叫之前已新增至篩選引擎的任何篩選。 因此,掛鉤可能會針對未收到篩選新增通知的篩選,接收篩選刪除通知。

如果提示的 notifyFn 提示函式無法辨識傳入 notifyType 參數中的通知類型,則它應該忽略通知並傳回 STATUS_SUCCESS。

當篩選器新增至篩選引擎時,呼出驅動程式可以指定一個要與該篩選器相關聯的上下文。 這類內容對篩選引擎而言是不透明的。 註解的 classifyFn 註解函式可以利用此上下文來儲存狀態資訊,以便在下一次由篩選引擎呼叫它時使用。 從過濾器引擎刪除過濾器時,回撥驅動程式會執行上下文的必要清理。

例如:

// Context structure to be associated with the filters
typedef struct FILTER_CONTEXT_ {
  .
  .  // Driver-specific content
  .
} FILTER_CONTEXT, *PFILTER_CONTEXT;

// Memory pool tag for filter context structures
#define FILTER_CONTEXT_POOL_TAG 'fcpt'

// notifyFn callout function
NTSTATUS NTAPI
 NotifyFn(
    IN FWPS_CALLOUT_NOTIFY_TYPE  notifyType,
    IN const GUID  *filterKey,
    IN const FWPS_FILTER0  *filter
    )
{
  PFILTER_CONTEXT context;

 ASSERT(filter != NULL);

  // Switch on the type of notification
 switch(notifyType) {

    // A filter is being added to the filter engine
 case FWPS_CALLOUT_NOTIFY_ADD_FILTER:

      // Allocate the filter context structure
 context =
        (PFILTER_CONTEXT)ExAllocatePoolWithTag(
 NonPagedPool,
 sizeof(FILTER_CONTEXT),
          FILTER_CONTEXT_POOL_TAG
          );

      // Check the result of the memory allocation
 if (context == NULL) {

        // Return error
 return STATUS_INSUFFICIENT_RESOURCES;
      }

      // Initialize the filter context structure
      ...

      // Associate the filter context structure with the filter
 filter->context = (UINT64)context;

 break;

    // A filter is being removed from the filter engine
 case FWPS_CALLOUT_NOTIFY_DELETE_FILTER:

      // Get the filter context structure from the filter
 context = (PFILTER_CONTEXT)filter->context;

 // Check whether the filter has a context
 if (context) {

        // Cleanup the filter context structure
        ...

        // Free the memory for the filter context structure
 ExFreePoolWithTag(
 context,
          FILTER_CONTEXT_POOL_TAG
          );

      }
 break;

    // Unknown notification
 default:

      // Do nothing
 break;
  }

 return STATUS_SUCCESS;
}