|
|
@ -6,6 +6,9 @@
|
|
|
|
package filter
|
|
|
|
package filter
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"strconv"
|
|
|
|
"sync"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
@ -139,7 +142,7 @@ var dropBucket = rate.NewLimiter(rate.Every(5*time.Second), 10)
|
|
|
|
func (f *Filter) logRateLimit(runflags RunFlags, q *packet.ParsedPacket, dir direction, r Response, why string) {
|
|
|
|
func (f *Filter) logRateLimit(runflags RunFlags, q *packet.ParsedPacket, dir direction, r Response, why string) {
|
|
|
|
var verdict string
|
|
|
|
var verdict string
|
|
|
|
|
|
|
|
|
|
|
|
if r == Drop && f.omitDropLogging(q, dir) {
|
|
|
|
if r == Drop && omitDropLogging(q, dir) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -266,6 +269,17 @@ const (
|
|
|
|
out
|
|
|
|
out
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (d direction) String() string {
|
|
|
|
|
|
|
|
switch d {
|
|
|
|
|
|
|
|
case in:
|
|
|
|
|
|
|
|
return "in"
|
|
|
|
|
|
|
|
case out:
|
|
|
|
|
|
|
|
return "out"
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return fmt.Sprintf("[??dir=%d]", int(d))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (f *Filter) pre(q *packet.ParsedPacket, rf RunFlags, dir direction) Response {
|
|
|
|
func (f *Filter) pre(q *packet.ParsedPacket, rf RunFlags, dir direction) Response {
|
|
|
|
if len(q.Buffer()) == 0 {
|
|
|
|
if len(q.Buffer()) == 0 {
|
|
|
|
// wireguard keepalive packet, always permit.
|
|
|
|
// wireguard keepalive packet, always permit.
|
|
|
@ -295,24 +309,36 @@ func (f *Filter) pre(q *packet.ParsedPacket, rf RunFlags, dir direction) Respons
|
|
|
|
return noVerdict
|
|
|
|
return noVerdict
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ipv6AllRoutersLinkLocal is ff02::2 (All link-local routers).
|
|
|
|
const (
|
|
|
|
const ipv6AllRoutersLinkLocal = "\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02"
|
|
|
|
// 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"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var debugLogDroppedPackets, _ = strconv.ParseBool(os.Getenv("TS_DEBUG_LOG_DROPPED_PACKETS"))
|
|
|
|
|
|
|
|
|
|
|
|
// omitDropLogging reports whether packet p, which has already been
|
|
|
|
// omitDropLogging reports whether packet p, which has already been
|
|
|
|
// deemded a packet to Drop, should bypass the [rate-limited] logging.
|
|
|
|
// deemded a packet to Drop, should bypass the [rate-limited] logging.
|
|
|
|
// We don't want to log scary & spammy reject warnings for packets that
|
|
|
|
// We don't want to log scary & spammy reject warnings for packets that
|
|
|
|
// are totally normal, like IPv6 route announcements.
|
|
|
|
// are totally normal, like IPv6 route announcements.
|
|
|
|
func (f *Filter) omitDropLogging(p *packet.ParsedPacket, dir direction) bool {
|
|
|
|
func omitDropLogging(p *packet.ParsedPacket, dir direction) bool {
|
|
|
|
|
|
|
|
b := p.Buffer()
|
|
|
|
switch dir {
|
|
|
|
switch dir {
|
|
|
|
case out:
|
|
|
|
case out:
|
|
|
|
switch p.IPVersion {
|
|
|
|
switch p.IPVersion {
|
|
|
|
case 4:
|
|
|
|
case 4:
|
|
|
|
// Omit logging about outgoing IGMP queries being dropped.
|
|
|
|
// ParsedPacket.Decode zeros out ParsedPacket.IPProtocol for protocols
|
|
|
|
if p.IPProto == packet.IGMP {
|
|
|
|
// it doesn't know about, so parse it out ourselves if needed.
|
|
|
|
|
|
|
|
ipProto := p.IPProto
|
|
|
|
|
|
|
|
if ipProto == 0 && len(b) > 8 {
|
|
|
|
|
|
|
|
ipProto = packet.IPProto(b[9])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Omit logging about outgoing IGMP.
|
|
|
|
|
|
|
|
if ipProto == packet.IGMP {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
case 6:
|
|
|
|
b := p.Buffer()
|
|
|
|
|
|
|
|
if len(b) < 40 {
|
|
|
|
if len(b) < 40 {
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -324,6 +350,10 @@ func (f *Filter) omitDropLogging(p *packet.ParsedPacket, dir direction) bool {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if string(dst) == ipv6AllMLDv2CapableRouters {
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
panic(fmt.Sprintf("Got proto=%2x; src=%x dst=%x", int(p.IPProto), src, dst))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|