Skip to content

feat(datagen): add NetworkIdentity and IP/port/MAC generation utilities#145

Open
Dylan-M wants to merge 1 commit intomainfrom
04-06-feat_datagen_add_networkidentity_and_ip_port_mac_generation_utilities
Open

feat(datagen): add NetworkIdentity and IP/port/MAC generation utilities#145
Dylan-M wants to merge 1 commit intomainfrom
04-06-feat_datagen_add_networkidentity_and_ip_port_mac_generation_utilities

Conversation

@Dylan-M
Copy link
Copy Markdown
Contributor

@Dylan-M Dylan-M commented Apr 27, 2026

Proposed Change

Adds NetworkIdentity plus IP, port, and MAC address generation utilities.

Part of PIPE-927 common data generation package stack. Foundation for PIPE-785, PIPE-928, PIPE-943, and the rest of the simulator stack.

Checklist
  • Changes are tested
  • CI has passed

Copy link
Copy Markdown
Contributor Author

Dylan-M commented Apr 27, 2026

@Dylan-M Dylan-M marked this pull request as ready for review April 27, 2026 14:41
@Dylan-M Dylan-M requested review from a team as code owners April 27, 2026 14:41
@Dylan-M Dylan-M force-pushed the 04-06-feat_datagen_add_mythology_hostname_pools_and_generation_functions branch from 1cea5bc to 369a3ac Compare May 8, 2026 17:17
@Dylan-M Dylan-M force-pushed the 04-06-feat_datagen_add_networkidentity_and_ip_port_mac_generation_utilities branch 2 times, most recently from 608349c to ecdd932 Compare May 8, 2026 17:22
Comment thread internal/datagen/networks.go Outdated
d := r.Intn(254) + 1 // #nosec G404

ip := net.IPv4(byte(a), byte(b), byte(c), byte(d))
if ip.IsPrivate() || ip.IsLoopback() || ip.IsMulticast() || ip.IsLinkLocalUnicast() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It only filters out private, loopback, multicast, and link-local addresses, so it can still emit many non-routable/reserved blocks such as 100.64.0.0/10 (CGNAT). That will leak obviously fake or non-routable “public” IPs into any simulator output

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworked RandomPublicIPv4 to reject candidates against an explicit, RFC-attributed list of reserved IPv4 blocks. Each entry in reservedIPv4Blocks carries the originating RFC, a human-readable name, an ietf.org datatracker URL, and the parsed CIDRs. Coverage now includes:

  • RFC 1112 (Class E)
  • RFC 1122 (loopback + "this network")
  • RFC 1918 (private-use)
  • RFC 2544 (benchmark testing)
  • RFC 3927 (link-local)
  • RFC 5736 (IETF protocol assignments)
  • RFC 5737 (TEST-NET-1/2/3)
  • RFC 6598 (CGNAT)

RFC 6890 noted in a comment as the umbrella special-purpose registry; entries cite the originating RFC for traceability rather than referencing 6890 directly. Adding new reserved blocks as new RFCs land is a one-struct-append. The same paradigm scaffolds IPv6 — reservedIPv6Block + empty reservedIPv6Blocks slice are in place, with a comment listing v6 candidates (RFC 4291, 4193, 3849, 5180, 6052, 6666). Populating that and adding RandomPublicIPv6 is tracked in PIPE-1001.

While at it: also discovered that NetworkIdentity has no IPv6 field at all (the CIDR field is implicitly v4-only). PIPE-1001 covers wiring that through too. Thanks for the push on this — the framing turned a nit into a clean separation between "reserved-block list" (data) and "filter logic" (one method) that v6 work can reuse without restructuring.

Comment thread internal/datagen/networks.go Outdated
}

// RandomIPInCIDR generates a random IP within the given CIDR range.
// The network and broadcast addresses are excluded.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It says it excludes network and broadcast addresses, but for /31 and /32 ranges it falls back to ip.String(), which is the network address returned by ParseCIDR. That directly violates the documented behavior and will generate unusable host addresses for small subnets. The tests only exercise /24, so this edge case currently slips through.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that the /31 case violated the documented behavior, and the /24-only test coverage hid it. Reworked the contract per a discussion with Dylan: blitz networks model "subnets with hosts" — broadcast domains where simulated systems live — so /30, /31, and /32 are out of scope by design (P2P router links and host routes, not host-bearing subnets).

Concretely:

  • Floor at /29 (≥ 8 total addresses, 6 usable hosts). Anything stricter (/30, /31, /32) is rejected.
  • Added ValidateCIDR(cidr string) error and (*NetworkIdentity).Validate() error. Config-loading code that accepts user-supplied CIDRs MUST call these and fail the entire config load on error — blitz refuses to start rather than silently substituting defaults. PIPE-1002 tracks wiring this into the config-load path; the validation function is exported for that purpose.
  • RandomIPInCIDR retains a soft fallback to RandomIPv4(r) for unparseable / non-IPv4 / /30/32 inputs as defense in depth. Reaching that fallback indicates a missing validation call upstream, not behavior to depend on. The docstring says so explicitly.
  • New tests cover /29 (works), /30//31//32 (soft fallback returns a valid IPv4), and ValidateCIDR accepting /29 and shorter while rejecting /30//31//32, unparseable input, and IPv6 (the last per PIPE-1001).
  • docs/datagen.md (in this stack's docs PR) now spells out the contract explicitly under "NetworkIdentity CIDR contract".

Good catch — the /24-only test coverage was the actual hole; the /31 behavior just made it visible.

@Dylan-M Dylan-M force-pushed the 04-06-feat_datagen_add_mythology_hostname_pools_and_generation_functions branch from 369a3ac to c378aeb Compare May 8, 2026 18:25
@Dylan-M Dylan-M force-pushed the 04-06-feat_datagen_add_networkidentity_and_ip_port_mac_generation_utilities branch from ecdd932 to ee7b49c Compare May 8, 2026 18:25
Base automatically changed from 04-06-feat_datagen_add_mythology_hostname_pools_and_generation_functions to main May 8, 2026 18:35
@Dylan-M Dylan-M force-pushed the 04-06-feat_datagen_add_networkidentity_and_ip_port_mac_generation_utilities branch from ee7b49c to df89093 Compare May 8, 2026 19:52
@Dylan-M Dylan-M requested a review from eKuG May 8, 2026 19:54
@Dylan-M Dylan-M force-pushed the 04-06-feat_datagen_add_networkidentity_and_ip_port_mac_generation_utilities branch from df89093 to 4196ac8 Compare May 8, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants