Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subnet info is lost when converting to v4 address. #123

Open
momchil-anachkov opened this issue Nov 5, 2020 · 4 comments
Open

Subnet info is lost when converting to v4 address. #123

momchil-anachkov opened this issue Nov 5, 2020 · 4 comments

Comments

@momchil-anachkov
Copy link

momchil-anachkov commented Nov 5, 2020

Hi there,

It seems when converting to a v4 from a v6 address the the resulting v4 address does not retain any of the subnet information even when coming from a "v4 in v6" address.

Steps to reproduce:

const a = Address6.fromAddress4('192.168.0.1/24'); // 24 bit mask
console.log(a.address); // ::ffff:192.168.0.1/120
console.log(a.subnet); // '/120'
console.log(a.subnetMask); // 120
console.log(a.is4()); // true
console.log(a.v4); // true

// This is where the funkiness starts

console.log(a.parsedAddress4); // '192.168.0.1' -- no mask
console.log(a.address4.address); // '192.168.0.1' -- no mask
console.log(a.to4().subnet); // '/32'
console.log(a.to4().subnetMask); // 32

I was expecting if the address is a valid v4 address for it to be preserved with the subnet (24), and not get the default (32).
Am I missing something?

Cheers

@asergeyev
Copy link

asergeyev commented Apr 7, 2021

What would imply /24 as the default for you? An address without netmask normally means "host" address, even one that ends in .0 could be a host in a lots of cases.

Quick quest for an example gives me
mx1.calmtug.com has address 40.76.49.0, host in 40.76.0.0/14 network

When operating with different addresses it's best to assume nothing and treat all addresses without netmask as individual hosts, which is an equivalent of /32 subnet

@beaugunderson
Copy link
Owner

beaugunderson commented Apr 7, 2021 via email

@momchil-anachkov
Copy link
Author

momchil-anachkov commented Apr 7, 2021

What would imply /24 as the default for you? An address without netmask normally means "host" address, even one that ends in .0 could be a host in a lots of cases.

Quick quest for an example gives me
mx1.calmtug.com has address 40.76.49.0, host in 40.76.0.0/14 network

When operating with different addresses it's best to assume nothing and treat all addresses without netmask as individual hosts, which is an equivalent of /32 subnet

@asergeyev

Nothing implies that. /24 is a pretty poor default. /32 probably should be the default.
That's not at all what the ticket is about. The issue is that you start from an address with specifically /24, and you lose that information.

Please read the code example. 🙂

@momchil-anachkov
Copy link
Author

momchil-anachkov commented Apr 7, 2021

if I remember correctly parsedAddress4 should be viewed as internal,
though

I see. Thanks. I'll keep that in mind.

Hmm, I'm not sure if I foresaw that use case, of instantiating from an
Address4 with a subnet and then converting back to an Address4… will have
to figure out how to work correctly!

That's okay. It's easy-enough to do some math as a consumer and figure things out.

In this case the ipv6 address has a mask of 120 (8 bits off from 128, which is the max),
So the ipv4 address should have a mask 8 bits off from 32, which would end at 24.

It's just some weird behaviour that I noticed, and thought I'd bring it up. 🙂

Thanks for looking into it.
And thanks for the great library!

Cheers 🥂

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

No branches or pull requests

3 participants