From c7c0e8d6e5d9722ff0adfd102181bf9a10d7258b Mon Sep 17 00:00:00 2001 From: terashima Date: Fri, 24 May 2024 09:02:22 +0000 Subject: [PATCH] Update link setup Signed-off-by: terashima --- v2/pkg/founat/client.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/v2/pkg/founat/client.go b/v2/pkg/founat/client.go index ec813d6b..dcf5cb36 100644 --- a/v2/pkg/founat/client.go +++ b/v2/pkg/founat/client.go @@ -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 @@ -398,17 +404,11 @@ 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, @@ -416,7 +416,7 @@ 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", ncWideTableID, n.String(), err) } return nil }