summaryrefslogtreecommitdiff
path: root/libpod/networking_linux.go
diff options
context:
space:
mode:
authorQi Wang <qiwan@redhat.com>2020-06-23 11:29:11 -0400
committerQi Wang <qiwan@redhat.com>2020-06-23 16:14:27 -0400
commitf586c006f8428a04fce5a5c7ae6b921e6337ebe6 (patch)
tree66aa9e658e7bd3efca34b66354b16a2a4ba0b20d /libpod/networking_linux.go
parent81f4204e4e0c8074e2709bd7c4db3f1f61d1b351 (diff)
downloadpodman-f586c006f8428a04fce5a5c7ae6b921e6337ebe6.tar.gz
podman-f586c006f8428a04fce5a5c7ae6b921e6337ebe6.tar.bz2
podman-f586c006f8428a04fce5a5c7ae6b921e6337ebe6.zip
Reformat inspect network settings
Reformat ports of inspect network settings to compatible with docker inspect. Close #5380 Signed-off-by: Qi Wang <qiwan@redhat.com>
Diffstat (limited to 'libpod/networking_linux.go')
-rw-r--r--libpod/networking_linux.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go
index 0c9d28701..f53573645 100644
--- a/libpod/networking_linux.go
+++ b/libpod/networking_linux.go
@@ -587,10 +587,20 @@ func getContainerNetIO(ctr *Container) (*netlink.LinkStatistics, error) {
// network.
func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, error) {
settings := new(define.InspectNetworkSettings)
- settings.Ports = []ocicni.PortMapping{}
+ settings.Ports = make(map[string][]define.InspectHostPort)
if c.config.PortMappings != nil {
- // TODO: This may not be safe.
- settings.Ports = c.config.PortMappings
+ for _, port := range c.config.PortMappings {
+ key := fmt.Sprintf("%d/%s", port.ContainerPort, port.Protocol)
+ mapping := settings.Ports[key]
+ if mapping == nil {
+ mapping = []define.InspectHostPort{}
+ }
+ mapping = append(mapping, define.InspectHostPort{
+ HostIP: port.HostIP,
+ HostPort: fmt.Sprintf("%d", port.HostPort),
+ })
+ settings.Ports[key] = mapping
+ }
}
// We can't do more if the network is down.