-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: re-implement Interfaces and InterfaceAddrs for IPNet, IPv6 on Windows #5395
Comments
unfortunately implementing network facility API for Windows does not complete yet. for now both InterfaceAddrs and Addrs of Interface will return an IPAddr (just an addr) instead of an IPNet (an address prefix). also it does not fetch IPv6 stuff inside the kernel. as usual, we very welcome a series of CLs on this issue. Labels changed: added priority-later, removed priority-triage. |
Issue #7955 has been merged into this issue. |
Comment 13 by everton.marques: I think one possible fix is to replace net.IPAddr from net/interface_windows.go, line 145, with net.IPNet: current: 145 ifa := IPAddr{IP: parseIPv4(bytePtrToString(&ipl.IpAddress.String[0]))} fix: 145 ifa := parseIPNet(ipl.IpAddress.String, ipl.IpMask.String) (http://golang.org/src/pkg/net/interface_windows.go) func parseIPNet(addr, mask [16]byte) IPNet { ipnet := IPNet{IP: parseIPv4(bytePtrToString(&addr[0]))} m := parseIPv4(bytePtrToString(&mask[0])) if m == nil { ipnet.Mask = IPMask{} return ipnet } p4 := ipnet.IP.To4() if len(p4) == IPv4len { m4 := m.To4() ipnet.Mask = net.IPv4Mask(m4[0], m4[1], m4[2], m4[3]) } else { ipnet.Mask = net.IPMask{ m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9], m[10], m[11], m[12], m[13], m[14], m[15], } } return ipnet } Unfortunately I don't have the skill to actually it. :( |
Thanks, but we don't use here for discussion and/or code review purposes. FWIW, here are a few hints: - use GetAdaptersAddresses instead http://msdn.microsoft.com/en-us/library/windows/desktop/aa365915(v=vs.85).aspx - then, parse IP_ADAPTER_ADDRESSES instead http://msdn.microsoft.com/en-us/library/windows/desktop/aa366058(v=vs.85).aspx |
It seems that I was working on this. I will send mail to gerrit in later. |
https://codereview.appspot.com/4590050/#msg11 alex says:
Go1.4 doesn't support windows2k no longer. So is it ok to re-implement by GetAdaptersAddresses() ? |
Sure @mattn. Hopefuly I will have time to review it. Please no changes to syscall package. We have to put all new syscall changes into internal/syscall/windows. Thank you. Alex |
@alexbrainman what structure of internal package do you expect? net/internal ? internal/syscall ? |
I suggest we put all new windows syscalls into internal/syscall/windows. This we'll be able to use both old syscall and new windows package names in the same source file. We can always change our mind because it is under internal/... Alex |
I wonder we should avoid new package name with renaming |
I don't like newstdcall package name. But you can ask others. |
rename old syscall to stdsyscall? |
I don't like it either. A package's name should describe what it does, not what it contains.
|
No we cannot touch syscall package. Other people use it. |
I don't talking about renaming package name of syscall. I'm talking that we must rename old syscall to use in new syscall like below. internal/syscall/windows.go
|
I didn't propose to create internal/syscall package. I proposed to create internal/syscall/windows package. We won't need to rename anything then. |
That's OK. (import "syscall" as stdsyscall in package internal/syscall) |
fair enough. we must put mksyscall_windows.go into there also. |
I was hoping we just call mksyscall_windows.go from where it is now. |
I think we should stick to "internal/syscall", instead of Because the existing use of "internal/syscall“ isn't called |
@minux
is this an another issue to file? |
I disagree. Once we start using new package we would have to use both old and new in the same source file most of the time. If we name both syscall, then one package would have to be renamed once imported. Why should we think about new name every time we import internal/syscall? Why not come up with good name now, name the package and use it from now on? Alex |
CL https://golang.org/cl/17412 mentions this issue. |
…on on windows The current implementation including Go 1.5 through 1.5.2 misuses Windows API and mishandles the returned values from GetAdapterAddresses on Windows. This change fixes various issues related to network facility information by readjusting interface and interface address parsers. Updates #5395. Updates #10530. Updates #12301. Updates #12551. Updates #13542. Fixes #12691. Fixes #12811. Fixes #13476. Fixes #13544. Also fixes fragile screen scraping test cases in net_windows_test.go. Additional information for reviewers: It seems like almost all the issues above have the same root cause and it is misunderstanding of Windows API. If my interpretation of the information on MSDN is correctly, current implementation contains the following bugs: - SIO_GET_INTERFACE_LIST should not be used for IPv6. The behavior of SIO_GET_INTERFACE_LIST is different on kernels and probably it doesn't work correctly for IPv6 on old kernels such as Windows XP w/ SP2. Unfortunately MSDN doesn't describe the detail of SIO_GET_INTERFACE_LIST, but information on the net suggests so. - Fetching IP_ADAPTER_ADDRESSES structures with fixed size area may not work when using IPv6. IPv6 generates ton of interface addresses for various addressing scopes. We need to adjust the area appropriately. - PhysicalAddress field of IP_ADAPTER_ADDRESSES structure may have extra space. We cannot ignore PhysicalAddressLength field of IP_ADAPTER_ADDRESS structure. - Flags field of IP_ADAPTER_ADDRESSES structure doesn't represent any of administratively and operatinal statuses. It just represents settings for windows network adapter. - MTU field of IP_ADAPTER_ADDRESSES structure may have a uint32(-1) on 64-bit platform. We need to convert the value to interger appropriately. - IfType field of IP_ADAPTER_ADDRESSES structure is not a bit field. Bitwire operation for the field is completely wrong. - OperStatus field of IP_ADAPTER_ADDRESSES structure is not a bit field. Bitwire operation for the field is completely wrong. - IPv6IfIndex field of IP_ADAPTER_ADDRESSES structure is just a substitute for IfIndex field. We cannot prefer IPv6IfIndex to IfIndex. - Windows XP, 2003 server and below don't set OnLinkPrefixLength field of IP_ADAPTER_UNICAST_ADDRESS structure. We cannot rely on the field on old kernels. We can use FirstPrefix field of IP_ADAPTER_ADDRESSES structure and IP_ADAPTER_PREFIX structure instead. - Length field of IP_ADAPTER_{UNICAST,ANYCAST,MULTICAST}_ADDRESS sturecures doesn't represent an address prefix length. It just represents a socket address length. Change-Id: Icabdaf7bd1d41360a981d2dad0b830b02b584528 Reviewed-on: https://go-review.googlesource.com/17412 Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
by tom.walsh@expresshosting.net:
The text was updated successfully, but these errors were encountered: