mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-10 07:12:05 +00:00
tailcfg: add FilterRule.IPProto
Updates #1516 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
32562a82a9
commit
90a6fb7ffe
@@ -9,9 +9,17 @@ import (
|
||||
"strings"
|
||||
|
||||
"inet.af/netaddr"
|
||||
"tailscale.com/net/packet"
|
||||
"tailscale.com/tailcfg"
|
||||
)
|
||||
|
||||
var defaultProtos = []packet.IPProto{
|
||||
packet.TCP,
|
||||
packet.UDP,
|
||||
packet.ICMPv4,
|
||||
packet.ICMPv6,
|
||||
}
|
||||
|
||||
// MatchesFromFilterRules converts tailcfg FilterRules into Matches.
|
||||
// If an error is returned, the Matches result is still valid,
|
||||
// containing the rules that were successfully converted.
|
||||
@@ -22,6 +30,17 @@ func MatchesFromFilterRules(pf []tailcfg.FilterRule) ([]Match, error) {
|
||||
for _, r := range pf {
|
||||
m := Match{}
|
||||
|
||||
if len(r.IPProto) == 0 {
|
||||
m.IPProto = append([]packet.IPProto(nil), defaultProtos...)
|
||||
} else {
|
||||
m.IPProto = make([]packet.IPProto, 0, len(r.IPProto))
|
||||
for _, n := range r.IPProto {
|
||||
if n >= 0 && n <= 0xff {
|
||||
m.IPProto = append(m.IPProto, packet.IPProto(n))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i, s := range r.SrcIPs {
|
||||
var bits *int
|
||||
if len(r.SrcBits) > i {
|
||||
|
||||
Reference in New Issue
Block a user