詳細検査へのコールアウトの使用

コールアウトが詳細な検査を実行する場合、その 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の値は、classifyOut パラメーターによって示される構造体の actionType メンバー内に、コールアウトの classifyFn コールアウト関数が返すべきアクションを決定します。 これらのアクションの詳細については、FWPS_ACTION0 構造をご覧ください。

データを許可するかブロックするかを判断する前に、コールアウトが classifyFn コールアウトの外部でパケット データの追加処理を実行する必要がある場合は、データの処理が完了するまでパケット データを保留にする必要があります。 パケット データを保留にする方法については、コールアウトの種類および FwpsPendOperation0 をご覧ください。

一部のフィルター レイヤーでは、フィルター エンジンによってコールアウトの classifyFn コールアウト関数に渡される layerData パラメーターは NULL です。

ストリーム データの詳細な検査を実行する方法については、ストリーム データの詳細な検査にコールアウトを使用するをご覧ください。