使用圖說文字進行深度檢查

當圖說文字執行深層檢查時,其 classifyFn 圖說文字函式可以檢查固定資料欄位、元資料欄位和任何傳遞至該欄位的原始封包資料,以及任何已儲存在與篩選或資料流程相關內容中的相關資料。

例如:

// classifyFn callout function
VOID NTAPI
 ClassifyFn(
    IN const FWPS_INCOMING_VALUES0  *inFixedValues,
    IN const FWPS_INCOMING_METADATA_VALUES0  *inMetaValues,
    IN OUT VOID  *layerData,
    IN const FWPS_FILTER0  *filter,
    IN UINT64  flowContext,
    IN OUT FWPS_CLASSIFY_OUT  *classifyOut
    )
{
  PNET_BUFFER_LIST rawData;
  ...

  // Test for the FWPS_RIGHT_ACTION_WRITE flag to check the rights
  // for this callout to return an action. If this flag is not set,
  // a callout can still return a BLOCK action in order to VETO a
  // PERMIT action that was returned by a previous filter. In this
  // example the function just exits if the flag is not set.
 if (!(classifyOut->rights & FWPS_RIGHT_ACTION_WRITE))
  {
    // Return without specifying an action
 return;
  }

  // Get the data fields from inFixedValues
  ...

  // Get any metadata fields from inMetaValues
  ...

  // Get the pointer to the raw data
 rawData = (PNET_BUFFER_LIST)layerData;

  // Get any filter context data from filter->context
  ...

  // Get any flow context data from flowContext
  ...

  // Inspect the various data sources to determine
  // the action to be taken on the data
  ...

  // If the data should be permitted...
 if (...) {

    // Set the action to permit the data
 classifyOut->actionType = FWP_ACTION_PERMIT;

    // Check whether the FWPS_RIGHT_ACTION_WRITE flag should be cleared
 if (filter->flags & FWPS_FILTER_FLAG_CLEAR_ACTION_RIGHT)
    {
       // Clear the FWPS_RIGHT_ACTION_WRITE flag
 classifyOut->rights &= ~FWPS_RIGHT_ACTION_WRITE;
    }

 return;
  }

  ...

  // If the data should be blocked...
 if (...) {

    // Set the action to block the data
 classifyOut->actionType = FWP_ACTION_BLOCK;

    // Clear the FWPS_RIGHT_ACTION_WRITE flag
 classifyOut->rights &= ~FWPS_RIGHT_ACTION_WRITE;

 return;
  }

  ...

  // If the decision to permit or block should be passed
  // to the next filter in the filter engine...
 if (...) {

    // Set the action to continue with the next filter
 classifyOut->actionType = FWP_ACTION_CONTINUE;

 return;
  }

  ...
}

filter-action.type >中的值會決定圖說文字的 classifyFn圖說文字函式應該在classifyOut參數所指向之結構的actionType成員中傳回哪些動作。 如需這些動作的詳細資訊,請參閱 FWPS_ACTION0 結構。

如果圖說文字必須在 其 classifyFn 圖說文字函式之外執行封包資料的額外處理,才能判斷資料是否應該允許或封鎖,它必須傳送封包資料,直到資料處理完成為止。 如需如何畫筆封包資料的詳細資訊,請參閱 圖說文字 類型和 FwpsPendOperation0

在某些篩選層中,篩選引擎傳遞給圖說文字的 classFn圖說文字函式的layerData參數為Null

如需如何對資料流程資料執行深層檢查的資訊,請參閱 使用圖說文字進行串流資料的深入檢查