summaryrefslogtreecommitdiff
path: root/libpod/networking_linux.go
diff options
context:
space:
mode:
authorhaircommander <pehunt@redhat.com>2018-08-20 18:24:35 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-08-21 15:37:39 +0000
commit149481a57184becf3e9be329d253602654414118 (patch)
treedff153e67e834673756e2f10aed2c6bfb7494067 /libpod/networking_linux.go
parent021027a24b7b6906a2d7ed86c67e34167bc26284 (diff)
downloadpodman-149481a57184becf3e9be329d253602654414118.tar.gz
podman-149481a57184becf3e9be329d253602654414118.tar.bz2
podman-149481a57184becf3e9be329d253602654414118.zip
Fixed segfault in stats where container had netNS none or from container
Signed-off-by: haircommander <pehunt@redhat.com> Closes: #1306 Approved by: rhatdan
Diffstat (limited to 'libpod/networking_linux.go')
-rw-r--r--libpod/networking_linux.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go
index e5f935e30..77ab97910 100644
--- a/libpod/networking_linux.go
+++ b/libpod/networking_linux.go
@@ -249,9 +249,35 @@ func (r *Runtime) teardownNetNS(ctr *Container) error {
return nil
}
+func getContainerNetNS(ctr *Container) (string, error) {
+ if ctr.state.NetNS != nil {
+ return ctr.state.NetNS.Path(), nil
+ }
+ if ctr.config.NetNsCtr != "" {
+ c, err := ctr.runtime.GetContainer(ctr.config.NetNsCtr)
+ if err != nil {
+ return "", err
+ }
+ if err = c.syncContainer(); err != nil {
+ return "", err
+ }
+ return c.state.NetNS.Path(), nil
+ }
+ return "", nil
+}
+
func getContainerNetIO(ctr *Container) (*netlink.LinkStatistics, error) {
var netStats *netlink.LinkStatistics
- err := ns.WithNetNSPath(ctr.state.NetNS.Path(), func(_ ns.NetNS) error {
+ netNSPath, netPathErr := getContainerNetNS(ctr)
+ if netPathErr != nil {
+ return nil, netPathErr
+ }
+ if netNSPath == "" {
+ // If netNSPath is empty, it was set as none, and no netNS was set up
+ // this is a valid state and thus return no error, nor any statistics
+ return nil, nil
+ }
+ err := ns.WithNetNSPath(netNSPath, func(_ ns.NetNS) error {
link, err := netlink.LinkByName(ocicni.DefaultInterfaceName)
if err != nil {
return err