Skip to content

Commit

Permalink
Fix downtime on NAT client startup (#288)
Browse files Browse the repository at this point in the history
fix missing traffic on NAT client startup

Signed-off-by: terashima <[email protected]>

Signed-off-by: Tomoki Sugiura <[email protected]>

---------

Signed-off-by: terashima <[email protected]>
Signed-off-by: Tomoki Sugiura <[email protected]>
Co-authored-by: Tomoki Sugiura <[email protected]>
  • Loading branch information
terassyi and chez-shanpu authored May 27, 2024
1 parent 5faaa12 commit b78fcd7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
10 changes: 8 additions & 2 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,7 +404,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", ncNarrowTableID, n.String(), err)
}
return nil
}
Expand All @@ -410,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
}
5 changes: 5 additions & 0 deletions v2/pkg/founat/egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func (e *egress) AddClient(addr net.IP, link netlink.Link) error {
}
}

// 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{
Dst: netlink.NewIPNet(addr),
LinkIndex: link.Attrs().Index,
Expand Down
2 changes: 0 additions & 2 deletions v2/pkg/founat/fou.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ func (t *fouTunnel) addOrRecreatePeer4(addr net.IP, sportAuto bool) (string, err

attrs := netlink.NewLinkAttrs()
attrs.Name = linkName
attrs.Flags = net.FlagUp
encapSport := uint16(t.port)
if sportAuto {
encapSport = 0
Expand Down Expand Up @@ -311,7 +310,6 @@ func (t *fouTunnel) addOrRecreatePeer6(addr net.IP, sportAuto bool) (string, err

attrs := netlink.NewLinkAttrs()
attrs.Name = linkName
attrs.Flags = net.FlagUp
encapSport := uint16(t.port)
if sportAuto {
encapSport = 0
Expand Down

0 comments on commit b78fcd7

Please sign in to comment.