refactor(netxlite/filtering): use strings for blocking policies (#563)
This change will simplify follow-up work done as part of https://github.com/ooni/probe/issues/1803#issuecomment-957323297 to implement a comprehensive self-censoring solution. While there, rename the "proxy" action to "pass" because what we are effectively doing is passing traffic to the network (that's a minor change but it seems a better analogy).
This commit is contained in:
parent
f91de2ecd6
commit
d9c43f1d1b
|
@ -13,27 +13,27 @@ import (
|
||||||
"github.com/ooni/probe-cli/v3/internal/runtimex"
|
"github.com/ooni/probe-cli/v3/internal/runtimex"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DNSAction is the action that this proxy should take.
|
// DNSAction is a DNS filtering action that this proxy should take.
|
||||||
type DNSAction int
|
type DNSAction string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// DNSActionProxy proxies the traffic to the upstream server.
|
// DNSActionPass passes the traffic to the upstream server.
|
||||||
DNSActionProxy = DNSAction(iota)
|
DNSActionPass = DNSAction("pass")
|
||||||
|
|
||||||
// DNSActionNXDOMAIN replies with NXDOMAIN.
|
// DNSActionNXDOMAIN replies with NXDOMAIN.
|
||||||
DNSActionNXDOMAIN
|
DNSActionNXDOMAIN = DNSAction("nxdomain")
|
||||||
|
|
||||||
// DNSActionRefused replies with Refused.
|
// DNSActionRefused replies with Refused.
|
||||||
DNSActionRefused
|
DNSActionRefused = DNSAction("refused")
|
||||||
|
|
||||||
// DNSActionLocalHost replies with `127.0.0.1` and `::1`.
|
// DNSActionLocalHost replies with `127.0.0.1` and `::1`.
|
||||||
DNSActionLocalHost
|
DNSActionLocalHost = DNSAction("localhost")
|
||||||
|
|
||||||
// DNSActionEmpty returns an empty reply.
|
// DNSActionNoAnswer returns an empty reply.
|
||||||
DNSActionEmpty
|
DNSActionNoAnswer = DNSAction("no-answer")
|
||||||
|
|
||||||
// DNSActionTimeout never replies to the query.
|
// DNSActionTimeout never replies to the query.
|
||||||
DNSActionTimeout
|
DNSActionTimeout = DNSAction("timeout")
|
||||||
)
|
)
|
||||||
|
|
||||||
// DNSProxy is a DNS proxy that routes traffic to an upstream
|
// DNSProxy is a DNS proxy that routes traffic to an upstream
|
||||||
|
@ -121,13 +121,13 @@ func (p *DNSProxy) replyDefault(query *dns.Msg) (*dns.Msg, error) {
|
||||||
}
|
}
|
||||||
name := query.Question[0].Name
|
name := query.Question[0].Name
|
||||||
switch p.OnQuery(name) {
|
switch p.OnQuery(name) {
|
||||||
case DNSActionProxy:
|
case DNSActionPass:
|
||||||
return p.proxy(query)
|
return p.proxy(query)
|
||||||
case DNSActionNXDOMAIN:
|
case DNSActionNXDOMAIN:
|
||||||
return p.nxdomain(query), nil
|
return p.nxdomain(query), nil
|
||||||
case DNSActionLocalHost:
|
case DNSActionLocalHost:
|
||||||
return p.localHost(query), nil
|
return p.localHost(query), nil
|
||||||
case DNSActionEmpty:
|
case DNSActionNoAnswer:
|
||||||
return p.empty(query), nil
|
return p.empty(query), nil
|
||||||
case DNSActionTimeout:
|
case DNSActionTimeout:
|
||||||
return nil, errors.New("let's ignore this query")
|
return nil, errors.New("let's ignore this query")
|
||||||
|
|
|
@ -31,7 +31,7 @@ func TestDNSProxy(t *testing.T) {
|
||||||
|
|
||||||
t.Run("DNSActionProxy with default proxy", func(t *testing.T) {
|
t.Run("DNSActionProxy with default proxy", func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
listener, done, err := newproxy(DNSActionProxy)
|
listener, done, err := newproxy(DNSActionPass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ func TestDNSProxy(t *testing.T) {
|
||||||
|
|
||||||
t.Run("DNSActionEmpty", func(t *testing.T) {
|
t.Run("DNSActionEmpty", func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
listener, done, err := newproxy(DNSActionEmpty)
|
listener, done, err := newproxy(DNSActionNoAnswer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,29 +9,29 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TLSAction is the action that this proxy should take.
|
// TLSAction is a TLS filtering action that this proxy should take.
|
||||||
type TLSAction int
|
type TLSAction string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// TLSActionProxy proxies the traffic to the destination.
|
// TLSActionPass passes the traffic to the destination.
|
||||||
TLSActionProxy = TLSAction(iota)
|
TLSActionPass = TLSAction("pass")
|
||||||
|
|
||||||
// TLSActionReset resets the connection.
|
// TLSActionReset resets the connection.
|
||||||
TLSActionReset
|
TLSActionReset = TLSAction("reset")
|
||||||
|
|
||||||
// TLSActionTimeout causes the connection to timeout.
|
// TLSActionTimeout causes the connection to timeout.
|
||||||
TLSActionTimeout
|
TLSActionTimeout = TLSAction("timeout")
|
||||||
|
|
||||||
// TLSActionEOF closes the connection.
|
// TLSActionEOF closes the connection.
|
||||||
TLSActionEOF
|
TLSActionEOF = TLSAction("eof")
|
||||||
|
|
||||||
// TLSActionAlertInternalError sends an internal error
|
// TLSActionAlertInternalError sends an internal error
|
||||||
// alert message to the TLS client.
|
// alert message to the TLS client.
|
||||||
TLSActionAlertInternalError
|
TLSActionAlertInternalError = TLSAction("internal-error")
|
||||||
|
|
||||||
// TLSActionAlertUnrecognizedName tells the client that
|
// TLSActionAlertUnrecognizedName tells the client that
|
||||||
// it's handshaking with an unknown SNI.
|
// it's handshaking with an unknown SNI.
|
||||||
TLSActionAlertUnrecognizedName
|
TLSActionAlertUnrecognizedName = TLSAction("alert-unrecognized-name")
|
||||||
)
|
)
|
||||||
|
|
||||||
// TLSProxy is a TLS proxy that routes the traffic depending
|
// TLSProxy is a TLS proxy that routes the traffic depending
|
||||||
|
@ -86,7 +86,7 @@ func (p *TLSProxy) handle(conn net.Conn) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch p.OnIncomingSNI(sni) {
|
switch p.OnIncomingSNI(sni) {
|
||||||
case TLSActionProxy:
|
case TLSActionPass:
|
||||||
p.proxy(conn, sni, hello)
|
p.proxy(conn, sni, hello)
|
||||||
case TLSActionTimeout:
|
case TLSActionTimeout:
|
||||||
p.timeout(conn)
|
p.timeout(conn)
|
||||||
|
|
|
@ -36,7 +36,7 @@ func TestTLSProxy(t *testing.T) {
|
||||||
|
|
||||||
t.Run("TLSActionProxy with default proxy", func(t *testing.T) {
|
t.Run("TLSActionProxy with default proxy", func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
listener, done, err := newproxy(TLSActionProxy)
|
listener, done, err := newproxy(TLSActionPass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ func TestTLSProxy(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("handle cannot read ClientHello", func(t *testing.T) {
|
t.Run("handle cannot read ClientHello", func(t *testing.T) {
|
||||||
listener, done, err := newproxy(TLSActionProxy)
|
listener, done, err := newproxy(TLSActionPass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ func TestTLSProxy(t *testing.T) {
|
||||||
|
|
||||||
t.Run("TLSActionProxy fails because we don't have SNI", func(t *testing.T) {
|
t.Run("TLSActionProxy fails because we don't have SNI", func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
listener, done, err := newproxy(TLSActionProxy)
|
listener, done, err := newproxy(TLSActionPass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ func TestTLSProxy(t *testing.T) {
|
||||||
|
|
||||||
t.Run("TLSActionProxy fails because we can't dial", func(t *testing.T) {
|
t.Run("TLSActionProxy fails because we can't dial", func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
listener, done, err := newproxy(TLSActionProxy)
|
listener, done, err := newproxy(TLSActionPass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user