Skip to content

Commit

Permalink
WIP: Drop driverConfiguresNet in favour of ChildDriverInfo()
Browse files Browse the repository at this point in the history
I'm not sure what I'm doing and it doesn't work yet...

Signed-off-by: Stefano Brivio <[email protected]>
  • Loading branch information
sbrivio-rh committed Aug 16, 2024
1 parent 2fafeba commit ee73b07
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 7 deletions.
2 changes: 0 additions & 2 deletions cmd/rootlesskit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,6 @@ func createChildOpt(clicontext *cli.Context) (child.Opt, error) {
DetachNetNS: detachNetNS,
Propagation: clicontext.String("propagation"),
EvacuateCgroup2: clicontext.String("evacuate-cgroup2") != "",
ConfigureNet: false,
}
switch reaperStr := clicontext.String("reaper"); reaperStr {
case "auto":
Expand All @@ -626,7 +625,6 @@ func createChildOpt(clicontext *cli.Context) (child.Opt, error) {
// NOP
case "pasta":
opt.NetworkDriver = pasta.NewChildDriver()
opt.ConfigureNet = true
case "slirp4netns":
opt.NetworkDriver = slirp4netns.NewChildDriver()
case "vpnkit":
Expand Down
6 changes: 6 additions & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Info struct {
ChildPID int `json:"childPID"`
NetworkDriver *NetworkDriverInfo `json:"networkDriver,omitempty"`
PortDriver *PortDriverInfo `json:"portDriver,omitempty"`
ChildDriver *ChildDriverInfo `json:"childDriver,omitempty"`
}

// NetworkDriverInfo in Info
Expand All @@ -32,3 +33,8 @@ type PortDriverInfo struct {
Protos []string `json:"protos"`
DisallowLoopbackChildIP bool `json:"disallowLoopbackChildIP,omitempty"` // since API v1.1.1
}

type ChildDriverInfo struct {
ConfiguresInterface bool `json:"configuresInterface"`
}

11 changes: 6 additions & 5 deletions pkg/child/child.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func setupCopyDir(driver copyup.ChildDriver, dirs []string) (bool, error) {
// setupNet sets up the network driver.
//
// NOTE: msg is altered during calling driver.ConfigureNetworkChild
func setupNet(stateDir string, msg *messages.ParentInitNetworkDriverCompleted, etcWasCopied bool, driver network.ChildDriver, driverConfiguresNet bool, detachedNetNSPath string) error {
func setupNet(stateDir string, msg *messages.ParentInitNetworkDriverCompleted, etcWasCopied bool, driver network.ChildDriver, detachedNetNSPath string) error {
// HostNetwork
if driver == nil {
return nil
Expand Down Expand Up @@ -215,7 +215,8 @@ func setupNet(stateDir string, msg *messages.ParentInitNetworkDriverCompleted, e
if err := os.WriteFile(stateDirResolvConf, generateResolvConf(msg.DNS), 0644); err != nil {
return fmt.Errorf("writing %s: %w", stateDirResolvConf, err)
}
if !driverConfiguresNet {
Info, _ := driver.ChildDriverInfo()
if !Info.ConfiguresInterface {
if err := activateDev(dev, msg.IP, msg.Netmask, msg.Gateway, msg.MTU); err != nil {
return err
}
Expand Down Expand Up @@ -257,7 +258,8 @@ func setupNet(stateDir string, msg *messages.ParentInitNetworkDriverCompleted, e
return fmt.Errorf("writing %s: %w", stateDirResolvConf, err)
}
if err := ns.WithNetNSPath(detachedNetNSPath, func(_ ns.NetNS) error {
if !driverConfiguresNet {
Info, _ := driver.ChildDriverInfo()
if !Info.ConfiguresInterface {
return activateDev(dev, msg.IP, msg.Netmask, msg.Gateway, msg.MTU)
}
return nil
Expand All @@ -283,7 +285,6 @@ type Opt struct {
Propagation string // mount propagation type
Reaper bool
EvacuateCgroup2 bool // needs to correspond to parent.Opt.EvacuateCgroup2 is set
ConfigureNet bool // driver configures network interface by itself
}

// statPIDNS is from https://github.com/containerd/containerd/blob/v1.7.2/services/introspection/pidns_linux.go#L25-L36
Expand Down Expand Up @@ -464,7 +465,7 @@ func Child(opt Opt) error {
return err
}
}
if err := setupNet(stateDir, netMsg, etcWasCopied, opt.NetworkDriver, opt.ConfigureNet, detachedNetNSPath); err != nil {
if err := setupNet(stateDir, netMsg, etcWasCopied, opt.NetworkDriver, detachedNetNSPath); err != nil {
return err
}
portQuitCh := make(chan struct{})
Expand Down
6 changes: 6 additions & 0 deletions pkg/network/lxcusernic/lxcusernic.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ func exchangeDHCP(c *client4.Client, dev string, detachedNetNSPath string) (*dhc
return ack, nil
}

func (d *childDriver) ChildDriverInfo() (*api.ChildDriverInfo, error) {
return &api.ChildDriverInfo {
ConfiguresInterface: false,
}, nil
}

func (d *childDriver) ConfigureNetworkChild(netmsg *messages.ParentInitNetworkDriverCompleted, detachedNetNSPath string) (string, error) {
dev := netmsg.Dev
if dev == "" {
Expand Down
6 changes: 6 additions & 0 deletions pkg/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ type ParentDriver interface {
ConfigureNetwork(childPID int, stateDir, detachedNetNSPath string) (netmsg *messages.ParentInitNetworkDriverCompleted, cleanup func() error, err error)
}

type childDriverInfo struct {
ConfiguresInterface bool
}

// ChildDriver is called from the child namespace
type ChildDriver interface {
// ConfigureNetworkChild is executed in the child's namespaces, excluding detached-netns.
//
// netmsg MAY be modified.
// devName is like "tap" or "eth0"
ConfigureNetworkChild(netmsg *messages.ParentInitNetworkDriverCompleted, detachedNetNSPath string) (devName string, err error)

ChildDriverInfo() (*api.ChildDriverInfo, error)
}
11 changes: 11 additions & 0 deletions pkg/network/pasta/pasta.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,18 @@ func NewChildDriver() network.ChildDriver {
return &childDriver{}
}

//type childDriverInfo struct {
//ConfiguresInterface bool
//}

type childDriver struct {
info func() *api.ChildDriverInfo
}

func (d *childDriver) ChildDriverInfo() (*api.ChildDriverInfo, error) {
return &api.ChildDriverInfo {
ConfiguresInterface: true,
}, nil
}

func (d *childDriver) ConfigureNetworkChild(netmsg *messages.ParentInitNetworkDriverCompleted, detachedNetNSPath string) (string, error) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/network/slirp4netns/slirp4netns.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ func NewChildDriver() network.ChildDriver {
type childDriver struct {
}

func (d *childDriver) ChildDriverInfo() (*api.ChildDriverInfo, error) {
return &api.ChildDriverInfo {
ConfiguresInterface: false,
}, nil
}

func (d *childDriver) ConfigureNetworkChild(netmsg *messages.ParentInitNetworkDriverCompleted, detachedNetNSPath string) (string, error) {
tap := netmsg.Dev
if tap == "" {
Expand Down
6 changes: 6 additions & 0 deletions pkg/network/vpnkit/vpnkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ func NewChildDriver() network.ChildDriver {
type childDriver struct {
}

func (d *childDriver) ChildDriverInfo() (*api.ChildDriverInfo, error) {
return &api.ChildDriverInfo {
ConfiguresInterface: false,
}, nil
}

func (d *childDriver) ConfigureNetworkChild(netmsg *messages.ParentInitNetworkDriverCompleted, detachedNetNSPath string) (tap string, err error) {
tapName := netmsg.Dev
if tapName == "" {
Expand Down

0 comments on commit ee73b07

Please sign in to comment.