-
Notifications
You must be signed in to change notification settings - Fork 736
add MAC, IPv4, IPv6 addresses to nework inspect #4680
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
base: main
Are you sure you want to change the base?
Conversation
2385db1 to
eb356cf
Compare
Signed-off-by: Arjun Raja Yogidas <[email protected]>
eb356cf to
365205b
Compare
|
Apologies for the late reply, you're right we can skip the assert statements as the field existence is already validated through struct unmarshaling. |
| Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { | ||
| return helpers.Command("network", "inspect", data.Identifier("test-network")) | ||
| }, | ||
| Expected: func(data test.Data, helpers test.Helpers) *test.Expected { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no tests for the items added in this PR's changes. Should add assertions for IPv4Address, MacAddress, and IPv6Address.
| if ip4 := ip.To4(); ip4 != nil { | ||
| endpoint.IPv4Address = ip4.String() | ||
| } else if ip6 := ip.To16(); ip6 != nil { | ||
| // It's IPv6 | ||
| endpoint.IPv6Address = ip6.String() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Docker uses CIDR notation, both IPv4 and IPv6 addresses should be displayed using CIDR.
Details
$ docker network inspect hoge | jq -r '.[].Containers'
{
"1edfa9aa4b5fc45bd95d2b8c93da0a82096c81e84824a1590508766cd188ded8": {
"Name": "test",
"EndpointID": "6650361992e5f5f833d83f37e359f9309ac50dcc54f91f101c725287a83df025",
"MacAddress": "52:90:e4:23:91:21",
"IPv4Address": "172.21.0.2/16",
"IPv6Address": ""
}
}| endpoint.MacAddress = x.HardwareAddr | ||
|
|
||
| // Extract IPv4 and IPv6 addresses | ||
| for _, a := range x.Addrs { | ||
| ip, _, err := net.ParseCIDR(a) | ||
| if err != nil { | ||
| continue | ||
| } | ||
| if ip.IsLoopback() || ip.IsLinkLocalUnicast() { | ||
| continue | ||
| } | ||
|
|
||
| // Check for IPv4 | ||
| if ip4 := ip.To4(); ip4 != nil { | ||
| endpoint.IPv4Address = ip4.String() | ||
| } else if ip6 := ip.To16(); ip6 != nil { | ||
| // It's IPv6 | ||
| endpoint.IPv6Address = ip6.String() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the current implementation, even when a container belongs to multiple networks, it displays the same MAC address and IPv4 address:
Details
nerdctl
$ sudo nerdctl network inspect hoge | jq -r '.[].Containers'
{
"0fd9457578c4a886bf16e0251ab11c3748e82b7f19926b3a57178e4c3d25a2b5": {
"Name": "test",
"MacAddress": "6e:dc:83:0b:60:26",
"IPv4Address": "10.4.7.2",
"IPv6Address": ""
}
}
$ sudo nerdctl network inspect fuga | jq -r '.[].Containers'
{
"0fd9457578c4a886bf16e0251ab11c3748e82b7f19926b3a57178e4c3d25a2b5": {
"Name": "test",
"MacAddress": "6e:dc:83:0b:60:26",
"IPv4Address": "10.4.7.2",
"IPv6Address": ""
}
}docker
$ docker run -d --name test --network hoge --network fuga nginx
$ docker network inspect fuga | jq -r '.[].Containers'
{
"1edfa9aa4b5fc45bd95d2b8c93da0a82096c81e84824a1590508766cd188ded8": {
"Name": "test",
"EndpointID": "a48d749f71c74ac38891d01064c61bdfebbb65a073b67eb8d9c7f913cf27d6a3",
"MacAddress": "9a:43:51:15:58:4b",
"IPv4Address": "172.22.0.2/16",
"IPv6Address": ""
}
}
$ docker network inspect hoge | jq -r '.[].Containers'
{
"1edfa9aa4b5fc45bd95d2b8c93da0a82096c81e84824a1590508766cd188ded8": {
"Name": "test",
"EndpointID": "6650361992e5f5f833d83f37e359f9309ac50dcc54f91f101c725287a83df025",
"MacAddress": "52:90:e4:23:91:21",
"IPv4Address": "172.21.0.2/16",
"IPv6Address": ""
}
}Each network should display the corresponding interface's MacAddress, IPv4Address, and IPv6Address.
Current network inspect respone provides only container names
This PR adds other fields in the EndpointResource Struct