Skip to content

Commit

Permalink
fixup! dnsmasq: add veth generation and configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Tortuyaux committed Apr 15, 2021
1 parent 493c08a commit a97a548
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions platform/local/dnsmasq.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,28 @@ func newSegment(s byte) (*Segment, error) {
return nil, fmt.Errorf("LinkSetUp() failed: %v", err)
}

// we first create an unique virtual ethernet pair in current network namespace accross the multiple kola instances
// we first create an unique virtual ethernet pair in the root network namespace
// we use linux network random port attribution to assert the uniqueness of the IP range in order to avoid IP
// range clashes
root, err := netns.GetFromPid(1)
if err != nil {
return nil, fmt.Errorf("unable to get NS from PID 1: %w", err)
}

rootExit, err := ns.Enter(root)
if err != nil {
return nil, fmt.Errorf("unable to enter root namespace: %w", err)
}

listener, err := net.Listen("tcp", ":0")
if err != nil {
return nil, fmt.Errorf("unable to listen on random port: %w", err)
}

if err := rootExit(); err != nil {
return nil, fmt.Errorf("unable to exit root namespace: %w", err)
}

// keep the created listener for destroying later
seg.Listener = listener

Expand Down Expand Up @@ -301,12 +315,12 @@ func newSegment(s byte) (*Segment, error) {
return nil, fmt.Errorf("unable to configure NAT: %w", err)
}

root, err := netns.GetFromPid(1)
root, err = netns.GetFromPid(1)
if err != nil {
return nil, fmt.Errorf("unable to get NS from PID 1: %w", err)
}

rootExit, err := ns.Enter(root)
rootExit, err = ns.Enter(root)
if err != nil {
return nil, fmt.Errorf("unable to enter root namespace: %w", err)
}
Expand Down

0 comments on commit a97a548

Please sign in to comment.