Skip to content

Commit 81082ee

Browse files
committed
chore(deps): replace deprecated syscall with golang.org/x/sys/unix
1 parent 867932d commit 81082ee

File tree

9 files changed

+37
-33
lines changed

9 files changed

+37
-33
lines changed

netnsbuilder/create.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import (
44
"context"
55
"os"
66
"os/exec"
7-
"syscall"
87

9-
"github.com/Scalingo/sand/api/types"
10-
"github.com/Scalingo/sand/config"
118
"github.com/docker/docker/pkg/reexec"
129
"github.com/pkg/errors"
10+
"golang.org/x/sys/unix"
11+
12+
"github.com/Scalingo/sand/api/types"
13+
"github.com/Scalingo/sand/config"
1314
)
1415

1516
var (
@@ -60,8 +61,8 @@ func (m *manager) createNS(ctx context.Context, path string) error {
6061
Stdout: os.Stdout,
6162
Stderr: os.Stderr,
6263
}
63-
cmd.SysProcAttr = &syscall.SysProcAttr{}
64-
cmd.SysProcAttr.Cloneflags = syscall.CLONE_NEWNET
64+
cmd.SysProcAttr = &unix.SysProcAttr{}
65+
cmd.SysProcAttr.Cloneflags = unix.CLONE_NEWNET
6566

6667
if err = cmd.Run(); err != nil {
6768
return errors.Wrap(err, "namespace creation reexec command failed")

netnsbuilder/init.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package netnsbuilder
33
import (
44
"context"
55
"os"
6-
"syscall"
76

8-
"github.com/Scalingo/go-utils/logger"
97
"github.com/docker/docker/pkg/reexec"
108
"github.com/sirupsen/logrus"
9+
"golang.org/x/sys/unix"
10+
11+
"github.com/Scalingo/go-utils/logger"
1112
)
1213

1314
func init() {
@@ -28,5 +29,5 @@ func reexecCreateNamespace() {
2829
func mountNetworkNamespace(ctx context.Context, basePath string, lnPath string) error {
2930
log := logger.Get(ctx)
3031
log.Info("mounting")
31-
return syscall.Mount(basePath, lnPath, "bind", syscall.MS_BIND, "")
32+
return unix.Mount(basePath, lnPath, "bind", unix.MS_BIND, "")
3233
}

netnsbuilder/umount.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ package netnsbuilder
33
import (
44
"context"
55
"os"
6-
"syscall"
76

8-
"github.com/Scalingo/go-utils/logger"
97
"github.com/pkg/errors"
8+
"golang.org/x/sys/unix"
9+
10+
"github.com/Scalingo/go-utils/logger"
1011
)
1112

1213
func UnmountNetworkNamespace(ctx context.Context, path string) error {
1314
log := logger.Get(ctx).WithField("mount-netns", path)
1415
log.Info("unmounting")
15-
err := syscall.Unmount(path, syscall.MNT_DETACH)
16+
err := unix.Unmount(path, unix.MNT_DETACH)
1617
if err != nil {
1718
return errors.Wrapf(err, "fail to umount %v", path)
1819
}

netutils/delete_if.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package netutils
22

33
import (
44
"context"
5-
"syscall"
65

76
"github.com/pkg/errors"
87
"github.com/vishvananda/netlink"
98
"github.com/vishvananda/netns"
9+
"golang.org/x/sys/unix"
1010
)
1111

1212
func DeleteInterfaceIfExists(ctx context.Context, nsfd netns.NsHandle, ifname string) error {
13-
nlh, err := netlink.NewHandleAt(nsfd, syscall.NETLINK_ROUTE)
13+
nlh, err := netlink.NewHandleAt(nsfd, unix.NETLINK_ROUTE)
1414
if err != nil {
1515
return errors.Wrapf(err, "fail to get netlink handler of netns")
1616
}

network/overlay/deactivate.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import (
44
"context"
55
"os"
66
"strings"
7-
"syscall"
87

9-
"github.com/Scalingo/sand/api/types"
108
"github.com/pkg/errors"
119
"github.com/vishvananda/netlink"
1210
"github.com/vishvananda/netns"
11+
"golang.org/x/sys/unix"
12+
13+
"github.com/Scalingo/sand/api/types"
1314
)
1415

1516
func (netm manager) Deactivate(ctx context.Context, network types.Network) error {
@@ -22,7 +23,7 @@ func (netm manager) Deactivate(ctx context.Context, network types.Network) error
2223
}
2324
defer nsfd.Close()
2425

25-
nlh, err := netlink.NewHandleAt(nsfd, syscall.NETLINK_ROUTE)
26+
nlh, err := netlink.NewHandleAt(nsfd, unix.NETLINK_ROUTE)
2627
if err != nil {
2728
return errors.Wrapf(err, "fail to get netlink handler of netns")
2829
}

network/overlay/ensure.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import (
44
"context"
55
"fmt"
66
"math/rand"
7-
"syscall"
87
"time"
98

109
"github.com/pkg/errors"
1110
"github.com/vishvananda/netlink"
1211
"github.com/vishvananda/netlink/nl"
1312
"github.com/vishvananda/netns"
13+
"golang.org/x/sys/unix"
1414

1515
"github.com/Scalingo/sand/api/types"
1616
"github.com/Scalingo/sand/netnsbuilder"
@@ -31,7 +31,7 @@ func (netm manager) Ensure(ctx context.Context, network types.Network) error {
3131
}
3232

3333
// Get a netlink handle to the root network namespace
34-
rootNetlinkHandle, err := netlink.NewHandle(syscall.NETLINK_ROUTE)
34+
rootNetlinkHandle, err := netlink.NewHandle(unix.NETLINK_ROUTE)
3535
if err != nil {
3636
return errors.Wrapf(err, "could not create netlink handle on initial root namespace")
3737
}
@@ -50,7 +50,7 @@ func (netm manager) Ensure(ctx context.Context, network types.Network) error {
5050
}
5151
defer nsfd.Close()
5252

53-
nlh, err := netlink.NewHandleAt(nsfd, syscall.NETLINK_ROUTE)
53+
nlh, err := netlink.NewHandleAt(nsfd, unix.NETLINK_ROUTE)
5454
if err != nil {
5555
return errors.Wrapf(err, "fail to get netlink handler of netns")
5656
}

network/overlay/ensure_endpoint.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package overlay
33
import (
44
"context"
55
"net"
6-
"syscall"
76

87
"github.com/pkg/errors"
98
"github.com/vishvananda/netlink/nl"
109
"github.com/vishvananda/netns"
10+
"golang.org/x/sys/unix"
1111

1212
"github.com/Scalingo/go-utils/logger"
1313
"github.com/Scalingo/sand/api/params"
@@ -44,13 +44,13 @@ func (m manager) EnsureEndpoint(ctx context.Context, network types.Network, endp
4444
defer targetnsfd.Close()
4545
}
4646

47-
hostnlh, err := netlink.NewHandleAt(hostnsfd, syscall.NETLINK_ROUTE)
47+
hostnlh, err := netlink.NewHandleAt(hostnsfd, unix.NETLINK_ROUTE)
4848
if err != nil {
4949
return endpoint, errors.Wrapf(err, "fail to get host namespace handler")
5050
}
5151
defer hostnlh.Delete()
5252

53-
targetnlh, err := netlink.NewHandleAt(targetnsfd, syscall.NETLINK_ROUTE)
53+
targetnlh, err := netlink.NewHandleAt(targetnsfd, unix.NETLINK_ROUTE)
5454
if err != nil {
5555
return endpoint, errors.Wrapf(err, "fail to get target namespace netlink handler")
5656
}
@@ -62,7 +62,7 @@ func (m manager) EnsureEndpoint(ctx context.Context, network types.Network, endp
6262
}
6363
defer overlaynsfd.Close()
6464

65-
overlaynlh, err := netlink.NewHandleAt(overlaynsfd, syscall.NETLINK_ROUTE)
65+
overlaynlh, err := netlink.NewHandleAt(overlaynsfd, unix.NETLINK_ROUTE)
6666
if err != nil {
6767
return endpoint, errors.Wrapf(err, "fail to get netlink handler of netns")
6868
}

network/overlay/neigh.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package overlay
33
import (
44
"context"
55
"net"
6-
"syscall"
76

8-
"github.com/Scalingo/go-utils/logger"
9-
"github.com/Scalingo/sand/api/types"
107
"github.com/pkg/errors"
118
"github.com/sirupsen/logrus"
129
"github.com/vishvananda/netlink"
1310
"github.com/vishvananda/netns"
11+
"golang.org/x/sys/unix"
12+
13+
"github.com/Scalingo/go-utils/logger"
14+
"github.com/Scalingo/sand/api/types"
1415
)
1516

1617
func (m manager) EnsureEndpointsNeigh(ctx context.Context, network types.Network, endpoints []types.Endpoint) error {
@@ -56,7 +57,7 @@ func (m manager) endpointNeighAction(ctx context.Context, network types.Network,
5657
}
5758
defer nsfd.Close()
5859

59-
nlh, err := netlink.NewHandleAt(nsfd, syscall.NETLINK_ROUTE)
60+
nlh, err := netlink.NewHandleAt(nsfd, unix.NETLINK_ROUTE)
6061
if err != nil {
6162
return errors.Wrapf(err, "fail to get netlink handler of netns")
6263
}
@@ -95,7 +96,7 @@ func (m manager) endpointNeighAction(ctx context.Context, network types.Network,
9596
HardwareAddr: mac,
9697
State: netlink.NUD_PERMANENT,
9798
LinkIndex: link.Attrs().Index,
98-
Family: syscall.AF_BRIDGE,
99+
Family: unix.AF_BRIDGE,
99100
Flags: netlink.NTF_SELF,
100101
}
101102
if err := action(nlh, nlnh); err != nil {

web/networks_controller_connect.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import (
88
"net/http"
99
"os"
1010
"sync"
11-
"syscall"
12-
13-
"gopkg.in/errgo.v1"
1411

1512
"github.com/pkg/errors"
1613
"github.com/sirupsen/logrus"
14+
"golang.org/x/sys/unix"
15+
"gopkg.in/errgo.v1"
1716

1817
"github.com/Scalingo/go-utils/logger"
1918
"github.com/Scalingo/sand/api/params"
@@ -83,13 +82,13 @@ func (c NetworksController) Connect(w http.ResponseWriter, r *http.Request, urlp
8382
if localEndpoint.ID != "" {
8483
err := netutils.ForwardConnection(ctx, socket, localEndpoint.TargetNetnsPath, ip, port)
8584
if operr, ok := errors.Cause(err).(*net.OpError); ok {
86-
if syscallerr, ok := operr.Err.(*os.SyscallError); ok && syscallerr.Err == syscall.ECONNREFUSED {
85+
if syscallerr, ok := operr.Err.(*os.SyscallError); ok && syscallerr.Err == unix.ECONNREFUSED {
8786
// It happens that the target from the network connection (ip:port) is not
8887
// actually bound in the network namespace, in this case a standard
8988
// connection refused error is sent, this should not be an error, the
9089
// connection to the SAND client should just be stopped normally
9190
log.WithError(err).Infof("local endpoint %v not binding port", localEndpoint)
92-
} else if syscallerr, ok := operr.Err.(*os.SyscallError); ok && syscallerr.Err == syscall.EHOSTUNREACH {
91+
} else if syscallerr, ok := operr.Err.(*os.SyscallError); ok && syscallerr.Err == unix.EHOSTUNREACH {
9392
// It's also possible that the targeted IP is not reachable anymore and it leads
9493
// to a no route to host error. This error is not related to sand itself
9594
log.WithError(err).Infof("local endpoint %v no route to host", localEndpoint)

0 commit comments

Comments
 (0)