| 460 | } |
| 461 | |
| 462 | bool addFilterV6(HANDLE engineHandle, std::vector<UINT64> *filterId, FWP_ACTION_TYPE type, UINT8 weight, |
| 463 | GUID subLayerKey, wchar_t *subLayerName, PNET_LUID pluid, |
| 464 | const std::vector<types::IpAddressRange> *ranges, |
| 465 | uint16_t localPort, uint16_t remotePort, AppsIds *appsIds, bool persistent) |
| 466 | { |
| 467 | UINT64 id = 0; |
| 468 | bool success = true; |
| 469 | DWORD dwFwApiRetCode = 0; |
| 470 | std::vector<FWP_V6_ADDR_AND_MASK> addrMasks; |
| 471 | if (ranges) { |
| 472 | addrMasks.reserve(ranges->size()); |
| 473 | } |
| 474 | // See addFilterV4 for rationale: if ranges are present but contain no v6 entries, |
| 475 | // skip filter creation rather than registering an "all v6 traffic" rule. |
| 476 | if (ranges && !ranges->empty()) { |
| 477 | bool anyV6 = false; |
| 478 | for (const auto &r : *ranges) { |
| 479 | if (r.isV6()) { anyV6 = true; break; } |
| 480 | } |
| 481 | if (!anyV6) { |
| 482 | return true; |
| 483 | } |
| 484 | } |
| 485 | GUID guids[2] = {FWPM_LAYER_ALE_AUTH_CONNECT_V6, FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6}; |
| 486 | |
| 487 | for (int i = 0; i < 2; i++) { |
| 488 | FWPM_FILTER0 filter = { 0 }; |
| 489 | std::vector<FWPM_FILTER_CONDITION0> conditions; |
| 490 | |
| 491 | filter.subLayerKey = subLayerKey; |
| 492 | filter.displayData.name = subLayerName; |
| 493 | filter.layerKey = guids[i]; |
| 494 | filter.action.type = type; |
| 495 | filter.flags = 0; |
| 496 | if (persistent) { |
| 497 | filter.flags |= FWPM_FILTER_FLAG_PERSISTENT; |
| 498 | } |
| 499 | // only veto block rules |
| 500 | if (type == FWP_ACTION_BLOCK) { |
| 501 | filter.flags |= FWPM_FILTER_FLAG_CLEAR_ACTION_RIGHT; |
| 502 | } |
| 503 | filter.weight.type = FWP_UINT8; |
| 504 | filter.weight.uint8 = weight; |
| 505 | |
| 506 | if (ranges) { |
| 507 | addrMasks.clear(); |
| 508 | for (const auto &r : *ranges) { |
| 509 | if (!r.isV6()) { |
| 510 | continue; |
| 511 | } |
| 512 | FWP_V6_ADDR_AND_MASK m; |
| 513 | CopyMemory(m.addr, r.address().bytes(), 16); |
| 514 | m.prefixLength = r.prefixLength(); |
| 515 | addrMasks.push_back(m); |
| 516 | |
| 517 | FWPM_FILTER_CONDITION0 condition; |
| 518 | condition.fieldKey = FWPM_CONDITION_IP_REMOTE_ADDRESS; |
| 519 | condition.matchType = FWP_MATCH_EQUAL; |
no test coverage detected