feat(libwebrtc): implement the rtc::IPAddress accessors, operator== and CountIPMaskBits #14095

Merged
alvaroelpob merged 6 commits from upstream-pr/14095 into main 2026-11-02 19:46:03 +00:00
alvaroelpob commented 2026-10-31 18:38:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-10-31T18:38:55Z.


What

Implements rtc::IPAddress::ipv4_address(), ipv6_address(), v4AddressAsHostOrderInteger(), operator== and rtc::CountIPMaskBits(const IPAddress&) in libwebrtc, which threw and were declared without parameters.

The module's WebRTC revision lies between M127 and M134, as recorded in the debt file by #13687. The bodies of these functions in rtc_base/ip_address.cc are the same at M127 branch-heads/6533 and M134 branch-heads/6998; only the includes differ. The members of IPAddress in ip_address.h are the same at both.

The functions are adapted from ip_address.cc and live in src/IpAddress.cpp, which starts with that file's WebRTC copyright notice and the BSD licence text from WebRTC's LICENSE. The debt entry says it is adapted from ip_address.cc.

WebRtcIpAddress is the 32-byte layout of ip_address.h: the vtable pointer of the virtual destructor at 0, int family_ at 8, and the in_addr/in6_addr union at 12. static_asserts check it. The constructors are inline in the header, so titles build these objects themselves; these functions only read them. AF_UNSPEC, AF_INET and AF_INET6 are 0, 2 and 28, as in FreeBSD's socket.h and NET_AF_INET6 in libSceNet.

  • ipv4_address() and ipv6_address() return the union as in_addr (4 bytes, in eax) and in6_addr (16 bytes, in rax:rdx), whatever the family.
  • v4AddressAsHostOrderInteger() returns the IPv4 address in host order for AF_INET and 0 otherwise.
  • operator== is false for different families, compares the 4 or 16 address bytes for AF_INET and AF_INET6, is true for two AF_UNSPEC addresses and false for any other family.
  • CountIPMaskBits returns 0 for families other than AF_INET and AF_INET6. Otherwise it skips the leading all-ones 32-bit words, then counts from the top bit of the next word down to its lowest set bit. As upstream, it does not check that the mask is contiguous: a gap is counted, and a zero word stops the count.

Upstream reads through a null address, so a null this or argument throws. The inventory drops from 405 to 400.

Tested

Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with BUILD_TESTING=ON.

  • New guest_webrtc_ip_address test, on addresses with a vtable sentinel and 0x5A padding:
    • ipv4_address() and ipv6_address() return the union bytes for IPv4 and IPv6 addresses, whichever family is set.
    • v4AddressAsHostOrderInteger() gives 0xC0A8010A for 192.168.1.10 and 0 for AF_INET6 and AF_UNSPEC.
    • operator==: equal and different IPv4 addresses, IPv4 bytes past the first 4 ignored, IPv4 against IPv6 with the same leading bytes, IPv6 differing in the last byte, two AF_UNSPEC addresses with different bytes (equal) and family 1 against itself (not equal).
    • CountIPMaskBits: IPv4 /24, /32, /1 and 0; 255.0.255.0 counts 24 and 0.0.0.1 counts 32; IPv6 prefixes of 0, 1, 31, 32, 33, 60, 64, 96, 127 and 128 bits; a /64 with a bit at 80 counts 80; an IPv6 mask whose first word is zero counts 0; AF_UNSPEC and family 1 count 0.
    • A null address throws std::invalid_argument in each function.
  • Full ctest -j16 on head 2555f26c85: 3034/3034 pass. check_conventions.py --base upstream/main passes. pr_overlap.py reports the open pull requests listed in Depends on.
  • Rebased onto main 1bc97b9527 after #13736 merged; the only conflicts were the include, CMake source and debt count lines. Full ctest -j16 on the top of the stack, #14148 head 0884de5716 (which contains this head, bc48f5d35e): 3087/3087 pass. check_conventions.py --base upstream/main passes.
  • Rebased onto main dc9dc7eaae after #13764 and #13816 merged. The conflicts were the debt count line and, in the AudioDeviceGeneric commit, the Export.cpp stubs next to the removed VAD stubs; that commit keeps main's side and removes only its own seven stubs. The count is now set from the stubs left in Export.cpp plus the 60 bound by NID (377
    31 on this head, 9b777019a3). Full ctest -j16 on the top of the stack, #14148 head 44e052f6dd: 3113/3113 pass. check_conventions.py --base upstream/main passes.
  • Not tested: Windows, a title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #14087
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5100437679 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14095). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-10-31T18:38:55Z. --- ### What Implements `rtc::IPAddress::ipv4_address()`, `ipv6_address()`, `v4AddressAsHostOrderInteger()`, `operator==` and `rtc::CountIPMaskBits(const IPAddress&)` in libwebrtc, which threw and were declared without parameters. The module's WebRTC revision lies between M127 and M134, as recorded in the debt file by #13687. The bodies of these functions in `rtc_base/ip_address.cc` are the same at [M127 branch-heads/6533](https://webrtc.googlesource.com/src/+/e0b28a6a81a989c1f5c89e30fcd247870047390d/rtc_base/ip_address.cc) and [M134 branch-heads/6998](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/rtc_base/ip_address.cc); only the includes differ. The members of `IPAddress` in `ip_address.h` are the same at both. The functions are adapted from `ip_address.cc` and live in `src/IpAddress.cpp`, which starts with that file's WebRTC copyright notice and the BSD licence text from WebRTC's `LICENSE`. The debt entry says it is adapted from `ip_address.cc`. `WebRtcIpAddress` is the 32-byte layout of `ip_address.h`: the vtable pointer of the virtual destructor at 0, `int family_` at 8, and the `in_addr`/`in6_addr` union at 12. `static_assert`s check it. The constructors are inline in the header, so titles build these objects themselves; these functions only read them. `AF_UNSPEC`, `AF_INET` and `AF_INET6` are 0, 2 and 28, as in [FreeBSD's `socket.h`](https://github.com/freebsd/freebsd-src/blob/55ac3c32b9ddba18b78bb3c58325294ba2e0bf6b/sys/sys/socket.h#L221-L256) and `NET_AF_INET6` in libSceNet. - `ipv4_address()` and `ipv6_address()` return the union as `in_addr` (4 bytes, in `eax`) and `in6_addr` (16 bytes, in `rax:rdx`), whatever the family. - `v4AddressAsHostOrderInteger()` returns the IPv4 address in host order for `AF_INET` and 0 otherwise. - `operator==` is false for different families, compares the 4 or 16 address bytes for `AF_INET` and `AF_INET6`, is true for two `AF_UNSPEC` addresses and false for any other family. - `CountIPMaskBits` returns 0 for families other than `AF_INET` and `AF_INET6`. Otherwise it skips the leading all-ones 32-bit words, then counts from the top bit of the next word down to its lowest set bit. As upstream, it does not check that the mask is contiguous: a gap is counted, and a zero word stops the count. Upstream reads through a null address, so a null `this` or argument throws. The inventory drops from 405 to 400. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with `BUILD_TESTING=ON`. - New `guest_webrtc_ip_address` test, on addresses with a vtable sentinel and 0x5A padding: - `ipv4_address()` and `ipv6_address()` return the union bytes for IPv4 and IPv6 addresses, whichever family is set. - `v4AddressAsHostOrderInteger()` gives `0xC0A8010A` for 192.168.1.10 and 0 for `AF_INET6` and `AF_UNSPEC`. - `operator==`: equal and different IPv4 addresses, IPv4 bytes past the first 4 ignored, IPv4 against IPv6 with the same leading bytes, IPv6 differing in the last byte, two `AF_UNSPEC` addresses with different bytes (equal) and family 1 against itself (not equal). - `CountIPMaskBits`: IPv4 /24, /32, /1 and 0; 255.0.255.0 counts 24 and 0.0.0.1 counts 32; IPv6 prefixes of 0, 1, 31, 32, 33, 60, 64, 96, 127 and 128 bits; a /64 with a bit at 80 counts 80; an IPv6 mask whose first word is zero counts 0; `AF_UNSPEC` and family 1 count 0. - A null address throws `std::invalid_argument` in each function. - Full `ctest -j16` on head 2555f26c85: 3034/3034 pass. `check_conventions.py --base upstream/main` passes. `pr_overlap.py` reports the open pull requests listed in Depends on. - Rebased onto main 1bc97b9527 after #13736 merged; the only conflicts were the include, CMake source and debt count lines. Full `ctest -j16` on the top of the stack, #14148 head 0884de5716 (which contains this head, bc48f5d35e): 3087/3087 pass. `check_conventions.py --base upstream/main` passes. - Rebased onto main dc9dc7eaae after #13764 and #13816 merged. The conflicts were the debt count line and, in the AudioDeviceGeneric commit, the `Export.cpp` stubs next to the removed VAD stubs; that commit keeps `main`'s side and removes only its own seven stubs. The count is now set from the stubs left in `Export.cpp` plus the 60 bound by NID (377 31 on this head, 9b777019a3). Full `ctest -j16` on the top of the stack, #14148 head 44e052f6dd: 3113/3113 pass. `check_conventions.py --base upstream/main` passes. - Not tested: Windows, a title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #14087 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
CnRJay commented 2026-11-01 19:49:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:49:22Z.

Review: COMMENTED


Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (Unblocks: none is allowed), and it contained no code review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729922062 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14095#pullrequestreview-5729922062). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:49:22Z. **Review:** COMMENTED --- Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (`Unblocks: none` is allowed), and it contained no code review.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14095
No description provided.