-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
net: add Interface.InterfaceAddrs #42694
Comments
Can you please point to the specific definitions of "temporary" and "deprecated" IP addresses in an RFC? I skimmed RFC4941 very quickly and do not see how to tell, given an IP, whether it is one of those. |
@rsc To be honest, I don't know exactly either. There should be an API for it, since
So, we need to look into the |
@jeroenjacobs79 What version of ifconfig are you running? What operating system? |
To the best of my knowledge, there is no way to identify an IPv6 temporary address by examining the address bits. RFC 8981 suggests generating temporary IIDs (interface identifiers) by simply generating the necessary number of random bits, and emphasizes, "Note: there are no special bits in an IID". RFC 7136 states that the 'u' and 'g' bits in IPv6 IIDs have no meaning for IIDs not generated from IEEE EUI-64 addresses, and that no conclusions can be drawn from the state of these bits. There is definitely no way to identify a deprecated address by examining its bits: A deprecated address is a temporary which has expired and will be used for existing connections, but not new ones. Presumably, |
I think I already mentioned that in the "possible solutions" section of my post. It's probably an interface thing, not sure how hard it is to add this information to the |
It's not clear that it fits into net.Interface either. This may be below the bar for being worth adding special API to a standard library for. |
/cc @mikioh |
If we want to do this, something like this might work:
There's probably other per-address information that could go in there. What's the use-case for detecting temporary and deprecated addresses? (Aside from implementing "ifconfig", of course.) The OS should generally manage address selection for you. |
My use-case for detecting IPv6 deprecated addresses is for a server which enumerates all local IP addresses via Concretely, I have a FreeBSD system with several jails. Each jail gets an IPv6 address allocated but these are on the same network interface as the host. To ensure the host doesn't use a jail IP address, they're marked as deprecated; the jail can still use it (as it's its only address) but the kernel won't use any jail IPs for outgoing connections from the host. I have noticed, though, that some services (such as Tailscale) are using jail IPv6 addresses even though they're marked as deprecated.
You're right, for when the OS is performing address selection - e.g. a client application tells the kernel "give me a socket so I can make an outbound connection" - but sometimes a service may do this selection on its own and it may use addresses which are not appropriate, as above. @rsc also said:
This is possibly true, although the syscall package already includes many Naively (I'm not sure I understand the Go internals well enough) I wonder if these can be added to the syscall package to be used by the net package. This does demonstrate the problem that the current |
No, this has nothing to do with the |
Or instead of a type, a net.Interface method? |
We'd need a new |
Retitling proposal: New methods on |
This proposal has been added to the active column of the proposals project |
It is unclear what the new API should be. Any ideas? net.Interfaces.Addrs and net.InterfaceAddrs return []net.Addr, so if we were going to expose the temporary/deprecated bit it would have to be an optional interface on that, but probably the concrete type of the net.Addr is net.IPNet, which has no room for bits. |
What do you think of this earlier suggestion? Add a new method to |
This makes sense to me. |
@neild, the new method returning []InterfaceAddr seems fine, but maybe InterfaceAddr should be an opaque struct to make it easier to add more information (and keep it read-only)? Especially with the potential netaddr changes. |
Ping @neild about interface vs struct. |
I think a struct makes the most sense here. The We can add new fields to a struct, so I don't think expansion is a concern. And we can copy any information that needs to be read-only when returning a That said, I don't feel terribly strongly about this. |
Retitled to match current proposal (#42694 (comment)) |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
Update, Sep 15 2021 Current proposal is #42694 -@rsc
Background
IPv6 has a concept of "privacy extensions" (RFC4941). When these extensions are active, a temporary IPv6 address is created, and is used for outbound connections. One this address expires, it gets the status "expired", and a new temporary IPv6 address is created.
Reason for this proposal
At the moment, when we use
net.Interfaces()
, we can get a list of associated addresses using the.Addrs()
method. However, there is no platform-independent way to determine if the IPv6 address are temporary or deprecated. We need to resort to running and parsing output ofip
,ifconfig
, andipconfig
. IPv6 keeps growing, so frameworks and programming languages need to support the more advanced features of IPv6 in the near future.Possible solutions
IsTemporary()
andisDeprecated()
tonet.IP
(similar toisLoopback
). However, that might not be the best solution, as the temporary nature of the address is not strictly tied to the numbers of the IP address.net.Interface
type to determine expired and temporary addresses?The text was updated successfully, but these errors were encountered: