bschaatsbergen / cidr

Simplifies IPv4/IPv6 CIDR network prefix management with counting, overlap checking, explanation, and subdivision.
https://formulae.brew.sh/formula/cidr
MIT License
168 stars 9 forks source link

[Feature Request] rfc6052 support #72

Open ewpratten opened 8 months ago

ewpratten commented 8 months ago

It would be nice to have support for rfc6052 addresses, which follow a pretty weird format.

Two commands (rfc6052-pack and rfc6052-extract) would be handy.

Heres an at-a-glance view of how this addressing scheme works:

+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|PL| 0-------------32--40--48--56--64--72--80--88--96--104---------|
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|32|     prefix    |v4(32)         | u | suffix                    |
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|40|     prefix        |v4(24)     | u |(8)| suffix                |
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|48|     prefix            |v4(16) | u | (16)  | suffix            |
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|56|     prefix                |(8)| u |  v4(24)   | suffix        |
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|64|     prefix                    | u |   v4(32)      | suffix    |
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|96|     prefix                                    |    v4(32)     |
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

Example syntax could be:

$ cidr rfc6052-pack <prefix>/<mask> <ipv4> [<suffix>]
$ cidr rfc6052-extract <address>/<mask>

The first command would return an IPv6 address, and the second would return an IPv6 prefix, an IPv4 address, and an optional suffix. (or just error, if its invalid)

ewpratten commented 8 months ago

I realize that this is the wrong language, but I do have an implementation of this hiding away here if you are curious: https://github.com/ewpratten/protomask/tree/ewpratten/reorg2/libs/rfc6052/src

bschaatsbergen commented 8 months ago

Hello @ewpratten, I appreciate you bringing up this issue. Personally, I'm not well-acquainted with rfc6052, and I plan to dedicate some time to thoroughly understand it. In the meantime, could you share a few use cases and elaborate on why you believe integrating rfc6052 would add value to cidr? Additionally, does rfc6052 take into account both IPv4 and IPv6 (the intention behind cidr is to be agnostic to both IPv4 and IPv6, offering features that naturally support both) ? I'll also be doing my research on this topic. Thanks again!