Skip to content

Commit

Permalink
Merge pull request #180 from dfr/freebsd
Browse files Browse the repository at this point in the history
pkg/ocicni: Use 'ifconfig -j' to access jail network state
  • Loading branch information
openshift-merge-bot[bot] authored Dec 14, 2023
2 parents 0885782 + 4e25248 commit e3223f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion hack/find-godeps.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#
# $1 - base path of the source tree
# $2 - subpath under $1 to find *.go dependencies for
Expand Down
28 changes: 13 additions & 15 deletions pkg/ocicni/util_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@ import (
"strings"
)

var defaultJexecCommandName = "jexec"

type nsManager struct {
jexecPath string
}
type nsManager struct{}

func (nsm *nsManager) init() error {
var err error
nsm.jexecPath, err = exec.LookPath(defaultJexecCommandName)
return err
return nil
}

func getContainerDetails(nsm *nsManager, netnsJailName, interfaceName, addrType string) (*net.IPNet, *net.HardwareAddr, error) {
// Try to retrieve ip inside container network namespace
if addrType == "-4" {
addrType = "inet"
} else {
addrType = "inet6"
}
output, err := exec.Command(
nsm.jexecPath, netnsJailName,
"ifconfig", "-f", "inet:cidr,inet6:cidr",
"ifconfig", "-j", netnsJailName,
"-f", "inet:cidr,inet6:cidr",
interfaceName,
addrType).CombinedOutput()
if err != nil {
Expand All @@ -38,7 +37,7 @@ func getContainerDetails(nsm *nsManager, netnsJailName, interfaceName, addrType
return nil, nil, fmt.Errorf("Unexpected command output %s", output)
}
fields := strings.Fields(strings.TrimSpace(lines[2]))
if len(fields) < 4 {
if len(fields) < 2 {
return nil, nil, fmt.Errorf("Unexpected address output %s ", lines[0])
}
ip, ipNet, err := net.ParseCIDR(fields[1])
Expand All @@ -53,8 +52,7 @@ func getContainerDetails(nsm *nsManager, netnsJailName, interfaceName, addrType

// Try to retrieve MAC inside container network namespace
output, err = exec.Command(
nsm.jexecPath, netnsJailName,
"ifconfig", "-f", "inet:cidr,inet6:cidr",
"ifconfig", "-j", netnsJailName, "-f", "inet:cidr,inet6:cidr",
interfaceName,
"ether").CombinedOutput()
if err != nil {
Expand All @@ -65,7 +63,7 @@ func getContainerDetails(nsm *nsManager, netnsJailName, interfaceName, addrType
if len(lines) < 3 {
return nil, nil, fmt.Errorf("unexpected ifconfig command output %s", output)
}
fields = strings.Fields(strings.TrimSpace(lines[1]))
fields = strings.Fields(strings.TrimSpace(lines[2]))
if len(fields) < 2 {
return nil, nil, fmt.Errorf("unexpected ether output %s ", lines[0])
}
Expand All @@ -78,7 +76,7 @@ func getContainerDetails(nsm *nsManager, netnsJailName, interfaceName, addrType
}

func bringUpLoopback(netns string) error {
if err := exec.Command("jexec", netns, "ifconfig", "lo0", "inet", "127.0.0.1").Run(); err != nil {
if err := exec.Command("ifconfig", "-j", netns, "lo0", "inet", "127.0.0.1").Run(); err != nil {
return fmt.Errorf("failed to initialize loopback: %w", err)
}
return nil
Expand Down

0 comments on commit e3223f5

Please sign in to comment.