Skip to content

Commit 45d1d2b

Browse files
authored
Update dependencies - 2022-04 (slackhq#664)
Updated github.com/kardianos/service kardianos/service@v1.2.0...v1.2.1 Updated github.com/miekg/dns miekg/dns@v1.1.43...v1.1.48 Updated github.com/prometheus/client_golang prometheus/client_golang@v1.11.0...v1.12.1 Updated github.com/prometheus/common prometheus/common@v0.32.1...v0.33.0 Updated github.com/stretchr/testify stretchr/testify@v1.7.0...v1.7.1 Updated golang.org/x/crypto golang/crypto@5770296...ae2d966 Updated golang.org/x/net golang/net@69e39ba...749bd19 Updated golang.org/x/sys golang/sys@7861aae...289d7a0 Updated golang.zx2c4.com/wireguard/windows v0.5.1...v0.5.3 Updated google.golang.org/protobuf v1.27.1...v1.28.0
1 parent 3913062 commit 45d1d2b

File tree

12 files changed

+129
-63
lines changed

12 files changed

+129
-63
lines changed

cert/cert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
"net"
1414
"time"
1515

16-
"github.com/golang/protobuf/proto"
1716
"golang.org/x/crypto/curve25519"
1817
"golang.org/x/crypto/ed25519"
18+
"google.golang.org/protobuf/proto"
1919
)
2020

2121
const publicKeyLen = 32

cert/cert.pb.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cert/cert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"testing"
99
"time"
1010

11-
"github.com/golang/protobuf/proto"
1211
"github.com/slackhq/nebula/test"
1312
"github.com/stretchr/testify/assert"
1413
"golang.org/x/crypto/curve25519"
1514
"golang.org/x/crypto/ed25519"
15+
"google.golang.org/protobuf/proto"
1616
)
1717

1818
func TestMarshalingNebulaCertificate(t *testing.T) {

go.mod

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,44 @@ go 1.18
55
require (
66
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be
77
github.com/armon/go-radix v1.0.0
8-
github.com/cespare/xxhash/v2 v2.1.2 // indirect
98
github.com/cyberdelia/go-metrics-graphite v0.0.0-20161219230853-39f87cc3b432
109
github.com/flynn/noise v1.0.0
1110
github.com/gogo/protobuf v1.3.2
12-
github.com/golang/protobuf v1.5.2
1311
github.com/google/gopacket v1.1.19
1412
github.com/imdario/mergo v0.3.8
15-
github.com/kardianos/service v1.2.0
16-
github.com/miekg/dns v1.1.43
13+
github.com/kardianos/service v1.2.1
14+
github.com/miekg/dns v1.1.48
1715
github.com/nbrownus/go-metrics-prometheus v0.0.0-20210712211119-974a6260965f
18-
github.com/prometheus/client_golang v1.11.0
19-
github.com/prometheus/client_model v0.2.0 // indirect
20-
github.com/prometheus/procfs v0.7.3 // indirect
16+
github.com/prometheus/client_golang v1.12.1
2117
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
2218
github.com/sirupsen/logrus v1.8.1
2319
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
2420
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
25-
github.com/stretchr/testify v1.7.0
21+
github.com/stretchr/testify v1.7.1
2622
github.com/vishvananda/netlink v1.1.0
27-
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect
28-
golang.org/x/crypto v0.0.0-20211202192323-5770296d904e
29-
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2
30-
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b
23+
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29
24+
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b
25+
golang.org/x/sys v0.0.0-20220406155245-289d7a0edf71
3126
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224
32-
golang.zx2c4.com/wireguard/windows v0.5.1
33-
google.golang.org/protobuf v1.27.1
27+
golang.zx2c4.com/wireguard/windows v0.5.3
28+
google.golang.org/protobuf v1.28.0
3429
gopkg.in/yaml.v2 v2.4.0
3530
)
3631

3732
require (
3833
github.com/beorn7/perks v1.0.1 // indirect
34+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
3935
github.com/davecgh/go-spew v1.1.1 // indirect
36+
github.com/golang/protobuf v1.5.2 // indirect
4037
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
4138
github.com/pmezard/go-difflib v1.0.0 // indirect
42-
github.com/prometheus/common v0.32.1 // indirect
39+
github.com/prometheus/client_model v0.2.0 // indirect
40+
github.com/prometheus/common v0.33.0 // indirect
41+
github.com/prometheus/procfs v0.7.3 // indirect
42+
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect
43+
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
4344
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
44-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
45+
golang.org/x/tools v0.1.10 // indirect
46+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
47+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
4548
)

go.sum

Lines changed: 49 additions & 23 deletions
Large diffs are not rendered by default.

handshake_ix.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"time"
66

77
"github.com/flynn/noise"
8-
"github.com/golang/protobuf/proto"
98
"github.com/slackhq/nebula/header"
109
"github.com/slackhq/nebula/iputil"
1110
"github.com/slackhq/nebula/udp"
@@ -43,7 +42,7 @@ func ixHandshakeStage0(f *Interface, vpnIp iputil.VpnIp, hostinfo *HostInfo) {
4342
hs := &NebulaHandshake{
4443
Details: hsProto,
4544
}
46-
hsBytes, err = proto.Marshal(hs)
45+
hsBytes, err = hs.Marshal()
4746

4847
if err != nil {
4948
f.l.WithError(err).WithField("vpnIp", vpnIp).
@@ -83,7 +82,7 @@ func ixHandshakeStage1(f *Interface, addr *udp.Addr, packet []byte, h *header.H)
8382
}
8483

8584
hs := &NebulaHandshake{}
86-
err = proto.Unmarshal(msg, hs)
85+
err = hs.Unmarshal(msg)
8786
/*
8887
l.Debugln("GOT INDEX: ", hs.Details.InitiatorIndex)
8988
*/
@@ -154,7 +153,7 @@ func ixHandshakeStage1(f *Interface, addr *udp.Addr, packet []byte, h *header.H)
154153
// Update the time in case their clock is way off from ours
155154
hs.Details.Time = uint64(time.Now().UnixNano())
156155

157-
hsBytes, err := proto.Marshal(hs)
156+
hsBytes, err := hs.Marshal()
158157
if err != nil {
159158
f.l.WithError(err).WithField("vpnIp", hostinfo.vpnIp).WithField("udpAddr", addr).
160159
WithField("certName", certName).
@@ -364,7 +363,7 @@ func ixHandshakeStage2(f *Interface, addr *udp.Addr, hostinfo *HostInfo, packet
364363
}
365364

366365
hs := &NebulaHandshake{}
367-
err = proto.Unmarshal(msg, hs)
366+
err = hs.Unmarshal(msg)
368367
if err != nil || hs.Details == nil {
369368
f.l.WithError(err).WithField("vpnIp", hostinfo.vpnIp).WithField("udpAddr", addr).
370369
WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).Error("Failed unmarshal handshake message")

iputil/util.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/binary"
55
"fmt"
66
"net"
7+
"net/netip"
78
)
89

910
type VpnIp uint32
@@ -39,13 +40,39 @@ func (ip VpnIp) ToIP() net.IP {
3940
return nip
4041
}
4142

43+
func (ip VpnIp) ToNetIpAddr() netip.Addr {
44+
var nip [4]byte
45+
binary.BigEndian.PutUint32(nip[:], uint32(ip))
46+
return netip.AddrFrom4(nip)
47+
}
48+
4249
func Ip2VpnIp(ip []byte) VpnIp {
4350
if len(ip) == 16 {
4451
return VpnIp(binary.BigEndian.Uint32(ip[12:16]))
4552
}
4653
return VpnIp(binary.BigEndian.Uint32(ip))
4754
}
4855

56+
func ToNetIpAddr(ip net.IP) (netip.Addr, error) {
57+
addr, ok := netip.AddrFromSlice(ip)
58+
if !ok {
59+
return netip.Addr{}, fmt.Errorf("invalid net.IP: %v", ip)
60+
}
61+
return addr, nil
62+
}
63+
64+
func ToNetIpPrefix(ipNet net.IPNet) (netip.Prefix, error) {
65+
addr, err := ToNetIpAddr(ipNet.IP)
66+
if err != nil {
67+
return netip.Prefix{}, err
68+
}
69+
ones, bits := ipNet.Mask.Size()
70+
if ones == 0 && bits == 0 {
71+
return netip.Prefix{}, fmt.Errorf("invalid net.IP: %v", ipNet)
72+
}
73+
return netip.PrefixFrom(addr, ones), nil
74+
}
75+
4976
// ubtoa encodes the string form of the integer v to dst[start:] and
5077
// returns the number of bytes written to dst. The caller must ensure
5178
// that dst has sufficient length.

lighthouse.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"time"
1212
"unsafe"
1313

14-
"github.com/golang/protobuf/proto"
1514
"github.com/rcrowley/go-metrics"
1615
"github.com/sirupsen/logrus"
1716
"github.com/slackhq/nebula/config"
@@ -356,7 +355,7 @@ func (lh *LightHouse) QueryServer(ip iputil.VpnIp, f udp.EncWriter) {
356355
}
357356

358357
// Send a query to the lighthouses and hope for the best next time
359-
query, err := proto.Marshal(NewLhQueryByInt(ip))
358+
query, err := NewLhQueryByInt(ip).Marshal()
360359
if err != nil {
361360
lh.l.WithError(err).WithField("vpnIp", ip).Error("Failed to marshal lighthouse query payload")
362361
return
@@ -612,7 +611,7 @@ func (lh *LightHouse) SendUpdate(f udp.EncWriter) {
612611
nb := make([]byte, 12, 12)
613612
out := make([]byte, mtu)
614613

615-
mm, err := proto.Marshal(m)
614+
mm, err := m.Marshal()
616615
if err != nil {
617616
lh.l.WithError(err).Error("Error while marshaling for lighthouse update")
618617
return

lighthouse_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"net"
66
"testing"
77

8-
"github.com/golang/protobuf/proto"
98
"github.com/slackhq/nebula/config"
109
"github.com/slackhq/nebula/header"
1110
"github.com/slackhq/nebula/iputil"
@@ -20,7 +19,7 @@ func TestOldIPv4Only(t *testing.T) {
2019
// This test ensures our new ipv6 enabled LH protobuf IpAndPorts works with the old style to enable backwards compatibility
2120
b := []byte{8, 129, 130, 132, 80, 16, 10}
2221
var m Ip4AndPort
23-
err := proto.Unmarshal(b, &m)
22+
err := m.Unmarshal(b)
2423
assert.NoError(t, err)
2524
assert.Equal(t, "10.1.1.1", iputil.VpnIp(m.GetIp()).String())
2625
}
@@ -36,12 +35,12 @@ func TestNewLhQuery(t *testing.T) {
3635
assert.IsType(t, &NebulaMeta{}, a)
3736

3837
// It should also Marshal fine
39-
b, err := proto.Marshal(a)
38+
b, err := a.Marshal()
4039
assert.Nil(t, err)
4140

4241
// and then Unmarshal fine
4342
n := &NebulaMeta{}
44-
err = proto.Unmarshal(b, n)
43+
err = n.Unmarshal(b)
4544
assert.Nil(t, err)
4645

4746
}
@@ -112,7 +111,7 @@ func BenchmarkLighthouseHandleRequest(b *testing.B) {
112111
Ip4AndPorts: nil,
113112
},
114113
}
115-
p, err := proto.Marshal(req)
114+
p, err := req.Marshal()
116115
assert.NoError(b, err)
117116
for n := 0; n < b.N; n++ {
118117
lhh.HandleRequest(rAddr, 2, p, mw)
@@ -127,7 +126,7 @@ func BenchmarkLighthouseHandleRequest(b *testing.B) {
127126
Ip4AndPorts: nil,
128127
},
129128
}
130-
p, err := proto.Marshal(req)
129+
p, err := req.Marshal()
131130
assert.NoError(b, err)
132131

133132
for n := 0; n < b.N; n++ {
@@ -375,7 +374,7 @@ type testEncWriter struct {
375374

376375
func (tw *testEncWriter) SendMessageToVpnIp(t header.MessageType, st header.MessageSubType, vpnIp iputil.VpnIp, p, _, _ []byte) {
377376
msg := &NebulaMeta{}
378-
err := proto.Unmarshal(p, msg)
377+
err := msg.Unmarshal(p)
379378
if tw.metaFilter == nil || msg.Type == *tw.metaFilter {
380379
tw.lastReply = testLhReply{
381380
nebType: t,

metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package nebula
33
/*
44
55
import (
6-
proto "github.com/golang/protobuf/proto"
6+
proto "google.golang.org/protobuf/proto"
77
)
88
99
func HandleMetaProto(p []byte) {

outside.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import (
77
"time"
88

99
"github.com/flynn/noise"
10-
"github.com/golang/protobuf/proto"
1110
"github.com/sirupsen/logrus"
1211
"github.com/slackhq/nebula/cert"
1312
"github.com/slackhq/nebula/firewall"
1413
"github.com/slackhq/nebula/header"
1514
"github.com/slackhq/nebula/iputil"
1615
"github.com/slackhq/nebula/udp"
1716
"golang.org/x/net/ipv4"
17+
"google.golang.org/protobuf/proto"
1818
)
1919

2020
const (

overlay/tun_wintun_windows.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"net"
8+
"net/netip"
89
"unsafe"
910

1011
"github.com/sirupsen/logrus"
@@ -20,6 +21,7 @@ const tunGUIDLabel = "Fixed Nebula Windows GUID v1"
2021
type winTun struct {
2122
Device string
2223
cidr *net.IPNet
24+
prefix netip.Prefix
2325
MTU int
2426
Routes []Route
2527
routeTree *cidr.Tree4
@@ -62,9 +64,15 @@ func newWinTun(l *logrus.Logger, deviceName string, cidr *net.IPNet, defaultMTU
6264
return nil, err
6365
}
6466

67+
prefix, err := iputil.ToNetIpPrefix(*cidr)
68+
if err != nil {
69+
return nil, err
70+
}
71+
6572
return &winTun{
6673
Device: deviceName,
6774
cidr: cidr,
75+
prefix: prefix,
6876
MTU: defaultMTU,
6977
Routes: routes,
7078
routeTree: routeTree,
@@ -76,7 +84,7 @@ func newWinTun(l *logrus.Logger, deviceName string, cidr *net.IPNet, defaultMTU
7684
func (t *winTun) Activate() error {
7785
luid := winipcfg.LUID(t.tun.LUID())
7886

79-
if err := luid.SetIPAddresses([]net.IPNet{*t.cidr}); err != nil {
87+
if err := luid.SetIPAddresses([]netip.Prefix{t.prefix}); err != nil {
8088
return fmt.Errorf("failed to set address: %w", err)
8189
}
8290

@@ -95,10 +103,15 @@ func (t *winTun) Activate() error {
95103
}
96104
}
97105

106+
prefix, err := iputil.ToNetIpPrefix(*r.Cidr)
107+
if err != nil {
108+
return err
109+
}
110+
98111
// Add our unsafe route
99112
routes = append(routes, &winipcfg.RouteData{
100-
Destination: *r.Cidr,
101-
NextHop: r.Via.ToIP(),
113+
Destination: prefix,
114+
NextHop: r.Via.ToNetIpAddr(),
102115
Metric: uint32(r.Metric),
103116
})
104117
}

0 commit comments

Comments
 (0)