@@ -10,23 +10,22 @@ import (
10
10
"strings"
11
11
)
12
12
13
- var defaultJexecCommandName = "jexec"
14
-
15
- type nsManager struct {
16
- jexecPath string
17
- }
13
+ type nsManager struct {}
18
14
19
15
func (nsm * nsManager ) init () error {
20
- var err error
21
- nsm .jexecPath , err = exec .LookPath (defaultJexecCommandName )
22
- return err
16
+ return nil
23
17
}
24
18
25
19
func getContainerDetails (nsm * nsManager , netnsJailName , interfaceName , addrType string ) (* net.IPNet , * net.HardwareAddr , error ) {
26
20
// Try to retrieve ip inside container network namespace
21
+ if addrType == "-4" {
22
+ addrType = "inet"
23
+ } else {
24
+ addrType = "inet6"
25
+ }
27
26
output , err := exec .Command (
28
- nsm . jexecPath , netnsJailName ,
29
- "ifconfig" , " -f" , "inet:cidr,inet6:cidr" ,
27
+ "ifconfig" , "-j" , netnsJailName ,
28
+ "-f" , "inet:cidr,inet6:cidr" ,
30
29
interfaceName ,
31
30
addrType ).CombinedOutput ()
32
31
if err != nil {
@@ -38,7 +37,7 @@ func getContainerDetails(nsm *nsManager, netnsJailName, interfaceName, addrType
38
37
return nil , nil , fmt .Errorf ("Unexpected command output %s" , output )
39
38
}
40
39
fields := strings .Fields (strings .TrimSpace (lines [2 ]))
41
- if len (fields ) < 4 {
40
+ if len (fields ) < 2 {
42
41
return nil , nil , fmt .Errorf ("Unexpected address output %s " , lines [0 ])
43
42
}
44
43
ip , ipNet , err := net .ParseCIDR (fields [1 ])
@@ -53,8 +52,7 @@ func getContainerDetails(nsm *nsManager, netnsJailName, interfaceName, addrType
53
52
54
53
// Try to retrieve MAC inside container network namespace
55
54
output , err = exec .Command (
56
- nsm .jexecPath , netnsJailName ,
57
- "ifconfig" , "-f" , "inet:cidr,inet6:cidr" ,
55
+ "ifconfig" , "-j" , netnsJailName , "-f" , "inet:cidr,inet6:cidr" ,
58
56
interfaceName ,
59
57
"ether" ).CombinedOutput ()
60
58
if err != nil {
@@ -65,7 +63,7 @@ func getContainerDetails(nsm *nsManager, netnsJailName, interfaceName, addrType
65
63
if len (lines ) < 3 {
66
64
return nil , nil , fmt .Errorf ("unexpected ifconfig command output %s" , output )
67
65
}
68
- fields = strings .Fields (strings .TrimSpace (lines [1 ]))
66
+ fields = strings .Fields (strings .TrimSpace (lines [2 ]))
69
67
if len (fields ) < 2 {
70
68
return nil , nil , fmt .Errorf ("unexpected ether output %s " , lines [0 ])
71
69
}
@@ -78,7 +76,7 @@ func getContainerDetails(nsm *nsManager, netnsJailName, interfaceName, addrType
78
76
}
79
77
80
78
func bringUpLoopback (netns string ) error {
81
- if err := exec .Command ("jexec " , netns , "ifconfig" , "lo0" , "inet" , "127.0.0.1" ).Run (); err != nil {
79
+ if err := exec .Command ("ifconfig " , "-j" , netns , "lo0" , "inet" , "127.0.0.1" ).Run (); err != nil {
82
80
return fmt .Errorf ("failed to initialize loopback: %w" , err )
83
81
}
84
82
return nil
0 commit comments