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 55ea9ee commit 3d69f85
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions platform/local/dnsmasq.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,28 @@ func newSegment(s byte) (*Segment, error) {
return nil, fmt.Errorf("unable to set up link: %w", err)
}

// `ip route get 1.0.0.0` in order to get device to configure NAT on
d := net.IPv4(1, 0, 0, 0)

routes, err := netlink.RouteGet(d)
if err != nil {
return nil, fmt.Errorf("unable to get routes: %w", err)
}

if len(routes) < 0 {
return nil, fmt.Errorf("at least one default route is required")
}

route := routes[0]
l, err := netlink.LinkByIndex(route.LinkIndex)
if err != nil {
return nil, fmt.Errorf("unable to get link by index: %w", err)
}

if err := configureNAT(l.Attrs().Name); err != nil {
return nil, fmt.Errorf("unable to configure NAT: %w", err)
}

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

0 comments on commit 3d69f85

Please sign in to comment.