2020-02-05 22:16:58 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2020-11-10 05:22:36 +00:00
|
|
|
// Package filter is a stateful packet filter.
|
2020-02-05 22:16:58 +00:00
|
|
|
package filter
|
|
|
|
|
|
|
|
import (
|
2020-07-30 17:57:30 +00:00
|
|
|
"fmt"
|
2020-02-05 22:16:58 +00:00
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/golang/groupcache/lru"
|
2020-05-08 18:30:22 +00:00
|
|
|
"golang.org/x/time/rate"
|
2020-11-10 04:12:21 +00:00
|
|
|
"inet.af/netaddr"
|
2020-11-10 00:16:04 +00:00
|
|
|
"tailscale.com/net/packet"
|
Add tstest.PanicOnLog(), and fix various problems detected by this.
If a test calls log.Printf, 'go test' horrifyingly rearranges the
output to no longer be in chronological order, which makes debugging
virtually impossible. Let's stop that from happening by making
log.Printf panic if called from any module, no matter how deep, during
tests.
This required us to change the default error handler in at least one
http.Server, as well as plumbing a bunch of logf functions around,
especially in magicsock and wgengine, but also in logtail and backoff.
To add insult to injury, 'go test' also rearranges the output when a
parent test has multiple sub-tests (all the sub-test's t.Logf is always
printed after all the parent tests t.Logf), so we need to screw around
with a special Logf that can point at the "current" t (current_t.Logf)
in some places. Probably our entire way of using subtests is wrong,
since 'go test' would probably like to run them all in parallel if you
called t.Parallel(), but it definitely can't because the're all
manipulating the shared state created by the parent test. They should
probably all be separate toplevel tests instead, with common
setup/teardown logic. But that's a job for another time.
Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2020-05-14 02:59:54 +00:00
|
|
|
"tailscale.com/types/logger"
|
2020-02-05 22:16:58 +00:00
|
|
|
)
|
|
|
|
|
2020-03-25 15:40:36 +00:00
|
|
|
// Filter is a stateful packet filter.
|
2020-02-05 22:16:58 +00:00
|
|
|
type Filter struct {
|
2020-05-22 02:41:18 +00:00
|
|
|
logf logger.Logf
|
2020-11-10 04:12:21 +00:00
|
|
|
// localNets is the list of IP prefixes that we know to be
|
|
|
|
// "local" to this node. All packets coming in over tailscale
|
|
|
|
// must have a destination within localNets, regardless of the
|
|
|
|
// policy filter below. A nil localNets rejects all incoming
|
|
|
|
// traffic.
|
|
|
|
local4 []net4
|
|
|
|
// matches4 is a list of match->action rules applied to all
|
|
|
|
// packets arriving over tailscale tunnels. Matches are
|
|
|
|
// checked in order, and processing stops at the first
|
|
|
|
// matching rule. The default policy if no rules match is to
|
|
|
|
// drop the packet.
|
|
|
|
matches4 matches4
|
2020-05-22 02:41:18 +00:00
|
|
|
// state is the connection tracking state attached to this
|
|
|
|
// filter. It is used to allow incoming traffic that is a response
|
|
|
|
// to an outbound connection that this node made, even if those
|
|
|
|
// incoming packets don't get accepted by matches above.
|
|
|
|
state *filterState
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 05:22:36 +00:00
|
|
|
// tuple is a 4-tuple of source and destination IPv4 and port. It's
|
|
|
|
// used as a lookup key in filterState.
|
|
|
|
type tuple struct {
|
|
|
|
SrcIP packet.IP4
|
|
|
|
DstIP packet.IP4
|
|
|
|
SrcPort uint16
|
|
|
|
DstPort uint16
|
|
|
|
}
|
|
|
|
|
|
|
|
// filterState is a state cache of past seen packets.
|
|
|
|
type filterState struct {
|
|
|
|
mu sync.Mutex
|
|
|
|
lru *lru.Cache // of tuple
|
|
|
|
}
|
|
|
|
|
|
|
|
// lruMax is the size of the LRU cache in filterState.
|
|
|
|
const lruMax = 512
|
|
|
|
|
|
|
|
// Response is a verdict from the packet filter.
|
2020-02-05 22:16:58 +00:00
|
|
|
type Response int
|
|
|
|
|
|
|
|
const (
|
2020-11-10 05:22:36 +00:00
|
|
|
Drop Response = iota // do not continue processing packet.
|
|
|
|
Accept // continue processing packet.
|
|
|
|
noVerdict // no verdict yet, continue running filter
|
2020-02-05 22:16:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (r Response) String() string {
|
|
|
|
switch r {
|
|
|
|
case Drop:
|
|
|
|
return "Drop"
|
|
|
|
case Accept:
|
|
|
|
return "Accept"
|
|
|
|
case noVerdict:
|
|
|
|
return "noVerdict"
|
|
|
|
default:
|
|
|
|
return "???"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-25 15:40:36 +00:00
|
|
|
// RunFlags controls the filter's debug log verbosity at runtime.
|
2020-02-05 22:16:58 +00:00
|
|
|
type RunFlags int
|
|
|
|
|
|
|
|
const (
|
2020-11-10 05:22:36 +00:00
|
|
|
LogDrops RunFlags = 1 << iota // write dropped packet info to logf
|
|
|
|
LogAccepts // write accepted packet info to logf
|
|
|
|
HexdumpDrops // print packet hexdump when logging drops
|
|
|
|
HexdumpAccepts // print packet hexdump when logging accepts
|
2020-02-05 22:16:58 +00:00
|
|
|
)
|
|
|
|
|
2020-05-22 02:41:18 +00:00
|
|
|
// NewAllowAll returns a packet filter that accepts everything to and
|
|
|
|
// from localNets.
|
2020-11-10 04:12:21 +00:00
|
|
|
func NewAllowAll(localNets []netaddr.IPPrefix, logf logger.Logf) *Filter {
|
2020-11-10 05:33:41 +00:00
|
|
|
return New([]Match{Match{NetPortRangeAny, NetAny}}, localNets, nil, logf)
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
|
2020-03-25 15:40:36 +00:00
|
|
|
// NewAllowNone returns a packet filter that rejects everything.
|
Add tstest.PanicOnLog(), and fix various problems detected by this.
If a test calls log.Printf, 'go test' horrifyingly rearranges the
output to no longer be in chronological order, which makes debugging
virtually impossible. Let's stop that from happening by making
log.Printf panic if called from any module, no matter how deep, during
tests.
This required us to change the default error handler in at least one
http.Server, as well as plumbing a bunch of logf functions around,
especially in magicsock and wgengine, but also in logtail and backoff.
To add insult to injury, 'go test' also rearranges the output when a
parent test has multiple sub-tests (all the sub-test's t.Logf is always
printed after all the parent tests t.Logf), so we need to screw around
with a special Logf that can point at the "current" t (current_t.Logf)
in some places. Probably our entire way of using subtests is wrong,
since 'go test' would probably like to run them all in parallel if you
called t.Parallel(), but it definitely can't because the're all
manipulating the shared state created by the parent test. They should
probably all be separate toplevel tests instead, with common
setup/teardown logic. But that's a job for another time.
Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2020-05-14 02:59:54 +00:00
|
|
|
func NewAllowNone(logf logger.Logf) *Filter {
|
2020-05-22 02:41:18 +00:00
|
|
|
return New(nil, nil, nil, logf)
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-22 02:41:18 +00:00
|
|
|
// New creates a new packet filter. The filter enforces that incoming
|
|
|
|
// packets must be destined to an IP in localNets, and must be allowed
|
|
|
|
// by matches. If shareStateWith is non-nil, the returned filter
|
2020-11-10 05:22:36 +00:00
|
|
|
// shares state with the previous one, to enable changing rules at
|
|
|
|
// runtime without breaking existing stateful flows.
|
2020-11-10 05:33:41 +00:00
|
|
|
func New(matches []Match, localNets []netaddr.IPPrefix, shareStateWith *Filter, logf logger.Logf) *Filter {
|
2020-03-25 07:47:55 +00:00
|
|
|
var state *filterState
|
|
|
|
if shareStateWith != nil {
|
|
|
|
state = shareStateWith.state
|
|
|
|
} else {
|
|
|
|
state = &filterState{
|
2020-03-25 15:40:36 +00:00
|
|
|
lru: lru.New(lruMax),
|
2020-03-25 07:47:55 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-05 22:16:58 +00:00
|
|
|
f := &Filter{
|
2020-11-10 04:12:21 +00:00
|
|
|
logf: logf,
|
|
|
|
matches4: newMatches4(matches),
|
|
|
|
local4: nets4FromIPPrefixes(localNets),
|
|
|
|
state: state,
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
|
|
|
func maybeHexdump(flag RunFlags, b []byte) string {
|
2020-05-08 18:30:22 +00:00
|
|
|
if flag == 0 {
|
2020-02-05 22:16:58 +00:00
|
|
|
return ""
|
|
|
|
}
|
2020-05-08 18:30:22 +00:00
|
|
|
return packet.Hexdump(b) + "\n"
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(apenwarr): use a bigger bucket for specifically TCP SYN accept logging?
|
|
|
|
// Logging is a quick way to record every newly opened TCP connection, but
|
|
|
|
// we have to be cautious about flooding the logs vs letting people use
|
|
|
|
// flood protection to hide their traffic. We could use a rate limiter in
|
|
|
|
// the actual *filter* for SYN accepts, perhaps.
|
2020-05-08 18:30:22 +00:00
|
|
|
var acceptBucket = rate.NewLimiter(rate.Every(10*time.Second), 3)
|
|
|
|
var dropBucket = rate.NewLimiter(rate.Every(5*time.Second), 10)
|
2020-02-05 22:16:58 +00:00
|
|
|
|
2020-07-29 05:10:58 +00:00
|
|
|
func (f *Filter) logRateLimit(runflags RunFlags, q *packet.ParsedPacket, dir direction, r Response, why string) {
|
2020-06-02 12:09:20 +00:00
|
|
|
var verdict string
|
|
|
|
|
2020-07-30 17:57:30 +00:00
|
|
|
if r == Drop && omitDropLogging(q, dir) {
|
2020-07-29 05:10:58 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-05-08 18:30:22 +00:00
|
|
|
if r == Drop && (runflags&LogDrops) != 0 && dropBucket.Allow() {
|
2020-06-02 12:09:20 +00:00
|
|
|
verdict = "Drop"
|
|
|
|
runflags &= HexdumpDrops
|
|
|
|
} else if r == Accept && (runflags&LogAccepts) != 0 && acceptBucket.Allow() {
|
|
|
|
verdict = "Accept"
|
|
|
|
runflags &= HexdumpAccepts
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: it is crucial that q.String() be called only if {accept,drop}Bucket.Allow() passes,
|
|
|
|
// since it causes an allocation.
|
|
|
|
if verdict != "" {
|
2020-06-08 22:19:26 +00:00
|
|
|
b := q.Buffer()
|
|
|
|
f.logf("%s: %s %d %s\n%s", verdict, q.String(), len(b), why, maybeHexdump(runflags, b))
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-10 05:22:36 +00:00
|
|
|
// RunIn determines whether this node is allowed to receive q from a
|
|
|
|
// Tailscale peer.
|
2020-06-08 22:19:26 +00:00
|
|
|
func (f *Filter) RunIn(q *packet.ParsedPacket, rf RunFlags) Response {
|
2020-07-29 05:10:58 +00:00
|
|
|
dir := in
|
|
|
|
r := f.pre(q, rf, dir)
|
2020-02-05 22:16:58 +00:00
|
|
|
if r == Accept || r == Drop {
|
|
|
|
// already logged
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
r, why := f.runIn(q)
|
2020-07-29 05:10:58 +00:00
|
|
|
f.logRateLimit(rf, q, dir, r, why)
|
2020-02-05 22:16:58 +00:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2020-11-10 05:22:36 +00:00
|
|
|
// RunOut determines whether this node is allowed to send q to a
|
|
|
|
// Tailscale peer.
|
2020-06-08 22:19:26 +00:00
|
|
|
func (f *Filter) RunOut(q *packet.ParsedPacket, rf RunFlags) Response {
|
2020-07-29 05:10:58 +00:00
|
|
|
dir := out
|
|
|
|
r := f.pre(q, rf, dir)
|
2020-02-05 22:16:58 +00:00
|
|
|
if r == Drop || r == Accept {
|
|
|
|
// already logged
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
r, why := f.runOut(q)
|
2020-07-29 05:10:58 +00:00
|
|
|
f.logRateLimit(rf, q, dir, r, why)
|
2020-02-05 22:16:58 +00:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2020-11-10 05:22:36 +00:00
|
|
|
// runIn runs the input-specific part of the filter logic.
|
2020-06-04 22:42:44 +00:00
|
|
|
func (f *Filter) runIn(q *packet.ParsedPacket) (r Response, why string) {
|
2020-05-22 02:41:18 +00:00
|
|
|
// A compromised peer could try to send us packets for
|
|
|
|
// destinations we didn't explicitly advertise. This check is to
|
|
|
|
// prevent that.
|
2020-11-10 04:12:21 +00:00
|
|
|
if !ip4InList(q.DstIP, f.local4) {
|
2020-05-22 02:41:18 +00:00
|
|
|
return Drop, "destination not allowed"
|
|
|
|
}
|
|
|
|
|
2020-07-28 23:02:15 +00:00
|
|
|
if q.IPVersion == 6 {
|
|
|
|
// TODO: support IPv6.
|
|
|
|
return Drop, "no rules matched"
|
|
|
|
}
|
|
|
|
|
2020-02-05 22:16:58 +00:00
|
|
|
switch q.IPProto {
|
|
|
|
case packet.ICMP:
|
2020-04-29 07:53:32 +00:00
|
|
|
if q.IsEchoResponse() || q.IsError() {
|
|
|
|
// ICMP responses are allowed.
|
|
|
|
// TODO(apenwarr): consider using conntrack state.
|
|
|
|
// We could choose to reject all packets that aren't
|
|
|
|
// related to an existing ICMP-Echo, TCP, or UDP
|
|
|
|
// session.
|
|
|
|
return Accept, "icmp response ok"
|
2020-11-10 04:12:21 +00:00
|
|
|
} else if f.matches4.matchIPsOnly(q) {
|
2020-04-29 07:53:32 +00:00
|
|
|
// If any port is open to an IP, allow ICMP to it.
|
2020-02-05 22:16:58 +00:00
|
|
|
return Accept, "icmp ok"
|
|
|
|
}
|
|
|
|
case packet.TCP:
|
|
|
|
// For TCP, we want to allow *outgoing* connections,
|
|
|
|
// which means we want to allow return packets on those
|
|
|
|
// connections. To make this restriction work, we need to
|
|
|
|
// allow non-SYN packets (continuation of an existing session)
|
|
|
|
// to arrive. This should be okay since a new incoming session
|
|
|
|
// can't be initiated without first sending a SYN.
|
|
|
|
// It happens to also be much faster.
|
|
|
|
// TODO(apenwarr): Skip the rest of decoding in this path?
|
|
|
|
if q.IPProto == packet.TCP && !q.IsTCPSyn() {
|
|
|
|
return Accept, "tcp non-syn"
|
|
|
|
}
|
2020-11-10 04:12:21 +00:00
|
|
|
if f.matches4.match(q) {
|
2020-02-05 22:16:58 +00:00
|
|
|
return Accept, "tcp ok"
|
|
|
|
}
|
|
|
|
case packet.UDP:
|
|
|
|
t := tuple{q.SrcIP, q.DstIP, q.SrcPort, q.DstPort}
|
|
|
|
|
2020-03-25 07:47:55 +00:00
|
|
|
f.state.mu.Lock()
|
|
|
|
_, ok := f.state.lru.Get(t)
|
|
|
|
f.state.mu.Unlock()
|
2020-02-05 22:16:58 +00:00
|
|
|
|
|
|
|
if ok {
|
|
|
|
return Accept, "udp cached"
|
|
|
|
}
|
2020-11-10 04:12:21 +00:00
|
|
|
if f.matches4.match(q) {
|
2020-02-05 22:16:58 +00:00
|
|
|
return Accept, "udp ok"
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return Drop, "Unknown proto"
|
|
|
|
}
|
|
|
|
return Drop, "no rules matched"
|
|
|
|
}
|
|
|
|
|
2020-11-10 05:22:36 +00:00
|
|
|
// runIn runs the output-specific part of the filter logic.
|
2020-06-04 22:42:44 +00:00
|
|
|
func (f *Filter) runOut(q *packet.ParsedPacket) (r Response, why string) {
|
2020-02-05 22:16:58 +00:00
|
|
|
if q.IPProto == packet.UDP {
|
|
|
|
t := tuple{q.DstIP, q.SrcIP, q.DstPort, q.SrcPort}
|
2020-03-25 15:40:36 +00:00
|
|
|
var ti interface{} = t // allocate once, rather than twice inside mutex
|
2020-02-05 22:16:58 +00:00
|
|
|
|
2020-03-25 07:47:55 +00:00
|
|
|
f.state.mu.Lock()
|
2020-03-25 15:40:36 +00:00
|
|
|
f.state.lru.Add(ti, ti)
|
2020-03-25 07:47:55 +00:00
|
|
|
f.state.mu.Unlock()
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
return Accept, "ok out"
|
|
|
|
}
|
|
|
|
|
2020-11-10 05:22:36 +00:00
|
|
|
// direction is whether a packet was flowing in to this machine, or
|
|
|
|
// flowing out.
|
2020-07-29 05:10:58 +00:00
|
|
|
type direction int
|
|
|
|
|
|
|
|
const (
|
2020-11-10 05:22:36 +00:00
|
|
|
in direction = iota // from Tailscale peer to local machine
|
|
|
|
out // from local machine to Tailscale peer
|
2020-07-29 05:10:58 +00:00
|
|
|
)
|
|
|
|
|
2020-07-30 17:57:30 +00:00
|
|
|
func (d direction) String() string {
|
|
|
|
switch d {
|
|
|
|
case in:
|
|
|
|
return "in"
|
|
|
|
case out:
|
|
|
|
return "out"
|
|
|
|
default:
|
|
|
|
return fmt.Sprintf("[??dir=%d]", int(d))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-10 05:22:36 +00:00
|
|
|
// pre runs the direction-agnostic filter logic. dir is only used for
|
|
|
|
// logging.
|
2020-07-29 05:10:58 +00:00
|
|
|
func (f *Filter) pre(q *packet.ParsedPacket, rf RunFlags, dir direction) Response {
|
2020-06-08 22:19:26 +00:00
|
|
|
if len(q.Buffer()) == 0 {
|
2020-02-05 22:16:58 +00:00
|
|
|
// wireguard keepalive packet, always permit.
|
|
|
|
return Accept
|
|
|
|
}
|
2020-06-08 22:19:26 +00:00
|
|
|
if len(q.Buffer()) < 20 {
|
2020-07-29 05:10:58 +00:00
|
|
|
f.logRateLimit(rf, q, dir, Drop, "too short")
|
2020-02-05 22:16:58 +00:00
|
|
|
return Drop
|
|
|
|
}
|
|
|
|
|
2020-07-28 23:02:15 +00:00
|
|
|
if q.IPVersion == 6 {
|
2020-07-29 05:10:58 +00:00
|
|
|
f.logRateLimit(rf, q, dir, Drop, "ipv6")
|
2020-07-28 23:02:15 +00:00
|
|
|
return Drop
|
|
|
|
}
|
2020-09-25 18:06:48 +00:00
|
|
|
if q.DstIP.IsMulticast() {
|
|
|
|
f.logRateLimit(rf, q, dir, Drop, "multicast")
|
|
|
|
return Drop
|
|
|
|
}
|
2020-09-25 18:47:38 +00:00
|
|
|
if q.DstIP.IsLinkLocalUnicast() {
|
|
|
|
f.logRateLimit(rf, q, dir, Drop, "link-local-unicast")
|
|
|
|
return Drop
|
|
|
|
}
|
2020-09-25 18:06:48 +00:00
|
|
|
|
2020-06-04 22:42:44 +00:00
|
|
|
switch q.IPProto {
|
|
|
|
case packet.Unknown:
|
|
|
|
// Unknown packets are dangerous; always drop them.
|
2020-07-29 05:10:58 +00:00
|
|
|
f.logRateLimit(rf, q, dir, Drop, "unknown")
|
2020-06-04 22:42:44 +00:00
|
|
|
return Drop
|
|
|
|
case packet.Fragment:
|
2020-02-05 22:16:58 +00:00
|
|
|
// Fragments after the first always need to be passed through.
|
2020-06-04 22:42:44 +00:00
|
|
|
// Very small fragments are considered Junk by ParsedPacket.
|
2020-07-29 05:10:58 +00:00
|
|
|
f.logRateLimit(rf, q, dir, Accept, "fragment")
|
2020-02-05 22:16:58 +00:00
|
|
|
return Accept
|
|
|
|
}
|
|
|
|
|
|
|
|
return noVerdict
|
|
|
|
}
|
2020-07-29 05:10:58 +00:00
|
|
|
|
2020-07-30 17:57:30 +00:00
|
|
|
const (
|
|
|
|
// ipv6AllRoutersLinkLocal is ff02::2 (All link-local routers)
|
|
|
|
ipv6AllRoutersLinkLocal = "\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02"
|
|
|
|
// ipv6AllMLDv2CapableRouters is ff02::16 (All MLDv2-capable routers)
|
|
|
|
ipv6AllMLDv2CapableRouters = "\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x16"
|
|
|
|
)
|
|
|
|
|
2020-07-29 05:10:58 +00:00
|
|
|
// omitDropLogging reports whether packet p, which has already been
|
2020-11-10 04:12:21 +00:00
|
|
|
// deemed a packet to Drop, should bypass the [rate-limited] logging.
|
|
|
|
// We don't want to log scary & spammy reject warnings for packets
|
|
|
|
// that are totally normal, like IPv6 route announcements.
|
2020-07-30 17:57:30 +00:00
|
|
|
func omitDropLogging(p *packet.ParsedPacket, dir direction) bool {
|
|
|
|
b := p.Buffer()
|
2020-07-29 05:10:58 +00:00
|
|
|
switch dir {
|
|
|
|
case out:
|
|
|
|
switch p.IPVersion {
|
|
|
|
case 4:
|
2020-07-30 17:57:30 +00:00
|
|
|
// ParsedPacket.Decode zeros out ParsedPacket.IPProtocol for protocols
|
|
|
|
// it doesn't know about, so parse it out ourselves if needed.
|
|
|
|
ipProto := p.IPProto
|
|
|
|
if ipProto == 0 && len(b) > 8 {
|
2020-11-09 23:34:03 +00:00
|
|
|
ipProto = packet.IP4Proto(b[9])
|
2020-07-30 17:57:30 +00:00
|
|
|
}
|
|
|
|
// Omit logging about outgoing IGMP.
|
|
|
|
if ipProto == packet.IGMP {
|
2020-07-29 05:10:58 +00:00
|
|
|
return true
|
|
|
|
}
|
2020-09-25 18:47:38 +00:00
|
|
|
if p.DstIP.IsMulticast() || p.DstIP.IsLinkLocalUnicast() {
|
2020-09-25 18:06:48 +00:00
|
|
|
return true
|
|
|
|
}
|
2020-07-29 05:10:58 +00:00
|
|
|
case 6:
|
|
|
|
if len(b) < 40 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
src, dst := b[8:8+16], b[24:24+16]
|
|
|
|
// Omit logging for outgoing IPv6 ICMP-v6 queries to ff02::2,
|
|
|
|
// as sent by the OS, looking for routers.
|
|
|
|
if p.IPProto == packet.ICMPv6 {
|
|
|
|
if isLinkLocalV6(src) && string(dst) == ipv6AllRoutersLinkLocal {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
2020-07-30 17:57:30 +00:00
|
|
|
if string(dst) == ipv6AllMLDv2CapableRouters {
|
|
|
|
return true
|
|
|
|
}
|
2020-08-01 19:40:09 +00:00
|
|
|
// Actually, just catch all multicast.
|
|
|
|
if dst[0] == 0xff {
|
|
|
|
return true
|
|
|
|
}
|
2020-07-29 05:10:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// isLinkLocalV6 reports whether src is in fe80::/10.
|
|
|
|
func isLinkLocalV6(src []byte) bool {
|
|
|
|
return len(src) == 16 && src[0] == 0xfe && src[1]>>6 == 0x80>>6
|
|
|
|
}
|