-
Notifications
You must be signed in to change notification settings - Fork 46
/
analysistcpip.go
82 lines (75 loc) · 2.28 KB
/
analysistcpip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package webconnectivitylte
//
// TCP/IP analysis
//
import (
"fmt"
"net"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
// analysisTCPIPToplevel is the toplevel analysis function for TCP/IP results.
//
// This algorithm has two objectives:
//
// 1. walk the list of TCP connect attempts and mark each of them as
// Status.Blocked = true | false | null depending on what the TH observed
// for the same set of IP addresses (it's ugly to modify a data struct
// in place, but this algorithm is defined by the spec);
//
// 2. assign the analysisFlagTCPIPBlocking flag to XBlockingFlags if
// we see any TCP endpoint for which Status.Blocked is true.
func (tk *TestKeys) analysisTCPIPToplevel(logger model.Logger) {
// if we don't have a control result, do nothing.
if tk.Control == nil || len(tk.Control.TCPConnect) <= 0 {
return
}
var (
istrue = true
isfalse = false
)
// walk the list of probe results and compare with TH results
for _, entry := range tk.TCPConnect {
// skip successful entries
failure := entry.Status.Failure
if failure == nil {
entry.Status.Blocked = &isfalse
continue // did not fail
}
// make sure we exclude the IPv6 failures caused by lack of
// proper IPv6 support by the probe
ipv6, err := netxlite.IsIPv6(entry.IP)
if err != nil {
continue // looks like a bug
}
if ipv6 {
ignore := (*failure == netxlite.FailureNetworkUnreachable ||
*failure == netxlite.FailureHostUnreachable)
if ignore {
// this occurs when we don't have IPv6 on the probe
continue
}
}
// obtain the corresponding endpoint
epnt := net.JoinHostPort(entry.IP, fmt.Sprintf("%d", entry.Port))
ctrl, found := tk.Control.TCPConnect[epnt]
if !found {
continue // only the probe tested this, so hard to say anything...
}
if ctrl.Failure != nil {
// If the TH failed as well, don't set XBlockingFlags and
// also don't bother with setting .Status.Blocked thus leaving
// it null. Performing precise error mapping should be a job
// for the pipeline rather than for the probe.
continue
}
logger.Warnf(
"TCP/IP: unexpected failure %s for %s (see #%d)",
*failure,
epnt,
entry.TransactionID,
)
entry.Status.Blocked = &istrue
tk.BlockingFlags |= analysisFlagTCPIPBlocking
}
}