Skip to content

Commit

Permalink
Update link setup
Browse files Browse the repository at this point in the history
Signed-off-by: terashima <[email protected]>
  • Loading branch information
terassyi committed May 24, 2024
1 parent 61cd40f commit c7c0e8d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions v2/pkg/founat/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,12 @@ func (c *natClient) addEgress1(link netlink.Link, n *net.IPNet) error {
priv = c.v6priv
}

// link up here to minimize the down time
// See https://github.com/cybozu-go/coil/issues/287.
if err := netlink.LinkSetUp(link); err != nil {
return fmt.Errorf("netlink: failed to link up %s: %w", link.Attrs().Name, err)
}

for _, p := range priv {
if !p.Contains(n.IP) {
continue
Expand All @@ -398,25 +404,19 @@ func (c *natClient) addEgress1(link netlink.Link, n *net.IPNet) error {
Protocol: ncProtocolID,
})
if err != nil {
return fmt.Errorf("netlink: failed to add route to %s: %w", n.String(), err)
return fmt.Errorf("netlink: failed to add route(table %d) to %s: %w", ncNarrowTableID, n.String(), err)
}
return nil
}

// link up here to minimize the down time
// See https://github.com/cybozu-go/coil/issues/287.
if err := netlink.LinkSetUp(link); err != nil {
return fmt.Errorf("netlink: failed to link up %s: %w", link.Attrs().Name, err)
}

err := netlink.RouteAdd(&netlink.Route{
Table: ncWideTableID,
Dst: n,
LinkIndex: link.Attrs().Index,
Protocol: ncProtocolID,
})
if err != nil {
return fmt.Errorf("netlink: failed to add route to %s: %w", n.String(), err)
return fmt.Errorf("netlink: failed to add route(table %d) to %s: %w", ncWideTableID, n.String(), err)
}
return nil
}

0 comments on commit c7c0e8d

Please sign in to comment.