使用 WFP 过滤器允许端口和 ip 对

Using WFP filter to allow pair of port and ip

我希望有防火墙将我的设备与网络隔离,但我希望允许的少数 port/ip 对除外。

例如,为了允许某些端口(对于所有 ip 地址),我使用以下过滤器:

FWPM_FILTER_CONDITION0 条件[2];

conditions[0].fieldKey = FWPM_CONDITION_IP_REMOTE_PORT;
conditions[0].conditionValue.type = FWP_UINT16;
conditions[0].conditionValue.uint16 = port;

conditions[1].fieldKey = FWPM_CONDITION_IP_PROTOCOL;
conditions[1].conditionValue.type = FWP_UINT8;
conditions[1].conditionValue.uint32 = 0;
conditions[1].matchType = FWP_MATCH_GREATER_OR_EQUAL;

Filter.subLayerKey = myGUID;
Filter.displayData.name = L"myFirewall";
Filter.action.type = FWP_ACTION_PERMIT;
Filter.weight.type = FWP_UINT64;

uint64 weightvalue = 0x102;

Filter.weight.uint64 = &weightvalue;
Filter.flags = FWPM_FILTER_FLAG_PERSISTENT;
Filter.filterCondition = conditions;
Filter.layerKey = FWPM_LAYER_OUTBOUND_TRANSPORT_V4
Filter.numFilterConditions = 2;

此过滤器允许具有单个目标端口的数据包忽略其 ip。 如何将特定 ip 添加到过滤条件?

感谢

匹配远程IP地址的过滤条件

conditions[1].fieldKey = FWPM_CONDITION_IP_PROTOCOL;
conditions[1].conditionValue.type = FWP_V4_ADDR_MASK;
conditions[1].conditionValue.v4AddrMask = new FWP_V4_ADDR_AND_MASK;
conditions[1].conditionValue.v4AddrMask->addr = ip;
conditions[1].conditionValue.v4AddrMask->mask = VISTA_SUBNET_MASK;
conditions[1].matchType = FWP_MATCH_EQUAL;