@@ -19,17 +19,22 @@ import (
19
19
var (
20
20
localnet []netip.Prefix = []netip.Prefix {
21
21
netip .MustParsePrefix ("127.0.0.1/8" ),
22
+ netip .MustParsePrefix ("::1/128" ),
22
23
}
23
24
24
25
privatenet []netip.Prefix = []netip.Prefix {
25
26
netip .MustParsePrefix ("10.0.0.0/8" ),
26
27
netip .MustParsePrefix ("172.16.0.0/12" ),
27
28
netip .MustParsePrefix ("192.168.0.0/16" ),
29
+ netip .MustParsePrefix ("2002:c0a8::/32" ),
28
30
}
29
31
30
- privateIP netip.Addr = netip .MustParseAddr ("192.168.0.1" )
31
- publicIP netip.Addr = netip .MustParseAddr ("8.8.8.8" )
32
- localhost netip.Addr = netip .MustParseAddr ("127.0.0.1" )
32
+ privateIP netip.Addr = netip .MustParseAddr ("192.168.0.1" )
33
+ privateIP6 netip.Addr = netip .MustParseAddr ("::ffff:c0a8:1" )
34
+ publicIP netip.Addr = netip .MustParseAddr ("8.8.8.8" )
35
+ publicIP6 netip.Addr = netip .MustParseAddr ("::ffff:808:808" )
36
+ localhost netip.Addr = netip .MustParseAddr ("127.0.0.1" )
37
+ localhost6 netip.Addr = netip .MustParseAddr ("::1" )
33
38
)
34
39
35
40
func localhostPeer () * peer.Peer {
@@ -40,6 +45,14 @@ func localhostPeer() *peer.Peer {
40
45
}
41
46
}
42
47
48
+ func localhost6Peer () * peer.Peer {
49
+ return & peer.Peer {
50
+ Addr : & net.TCPAddr {
51
+ IP : net .ParseIP (localhost6 .String ()),
52
+ },
53
+ }
54
+ }
55
+
43
56
func publicPeer () * peer.Peer {
44
57
return & peer.Peer {
45
58
Addr : & net.TCPAddr {
@@ -56,6 +69,14 @@ func privatePeer() *peer.Peer {
56
69
}
57
70
}
58
71
72
+ func private6Peer () * peer.Peer {
73
+ return & peer.Peer {
74
+ Addr : & net.TCPAddr {
75
+ IP : net .ParseIP (privateIP6 .String ()),
76
+ },
77
+ }
78
+ }
79
+
59
80
type testCase struct {
60
81
trustedPeers []netip.Prefix
61
82
headerKeys []string
@@ -331,6 +352,37 @@ func TestInterceptor(t *testing.T) {
331
352
testStreamServerInterceptor (t , tc )
332
353
})
333
354
})
355
+ t .Run ("ipv6 from grpc peer" , func (t * testing.T ) {
356
+ tc := testCase {
357
+ trustedPeers : localnet ,
358
+ headerKeys : []string {},
359
+ peer : localhost6Peer (),
360
+ expectedIP : localhost6 ,
361
+ }
362
+ t .Run ("unary" , func (t * testing.T ) {
363
+ testUnaryServerInterceptor (t , tc )
364
+ })
365
+ t .Run ("stream" , func (t * testing.T ) {
366
+ testStreamServerInterceptor (t , tc )
367
+ })
368
+ })
369
+ t .Run ("ipv6 from header" , func (t * testing.T ) {
370
+ tc := testCase {
371
+ trustedPeers : privatenet ,
372
+ headerKeys : []string {XForwardedFor },
373
+ inputHeaders : map [string ]string {
374
+ XForwardedFor : publicIP6 .String (),
375
+ },
376
+ peer : private6Peer (),
377
+ expectedIP : publicIP6 ,
378
+ }
379
+ t .Run ("unary" , func (t * testing.T ) {
380
+ testUnaryServerInterceptor (t , tc )
381
+ })
382
+ t .Run ("stream" , func (t * testing.T ) {
383
+ testStreamServerInterceptor (t , tc )
384
+ })
385
+ })
334
386
t .Run ("unix" , func (t * testing.T ) {
335
387
tc := testCase {
336
388
trustedPeers : localnet ,
0 commit comments