func()

in tcpdumpw/pkg/filter/l3_proto_filter_provider.go [40:77]


func (p *L3ProtoFilterProvider) Get(ctx context.Context) (*string, bool) {
	if *p.Raw == "" ||
		strings.EqualFold(*p.Raw, "ALL") ||
		strings.EqualFold(*p.Raw, "ANY") ||
		strings.EqualFold(*p.Raw, l3_PROTO_DEFAULT_FILTER) {
		filter := string(l3_PROTO_DEFAULT_FILTER)
		return &filter, true
	}

	protos := strings.Split(*p.Raw, ",")
	if len(protos) == 0 || (len(protos) == 1 && protos[0] == "") {
		filter := string(l3_PROTO_DEFAULT_FILTER)
		return &filter, true
	}

	l3Protos := mapset.NewThreadUnsafeSet[string]()

	for _, proto := range protos {
		switch proto {
		case "ip", "ip4", "ipv4", "4", "0x04":
			l3Protos.Add(string(l3_PROTO_IPv4_FILTER))
			p.AddL3Proto(pcap.L3_PROTO_IPv4)
		case "ip6", "ipv6", "41", "0x29":
			l3Protos.Add(string(l3_PROTO_IPv6_FILTER))
			p.AddL3Proto(pcap.L3_PROTO_IPv6)
		case "arp", "0x0806":
			l3Protos.Add(string(l3_PROTO_ARP_FILTER))
		}
	}

	if l3Protos.IsEmpty() {
		filter := string(l3_PROTO_DEFAULT_FILTER)
		return &filter, true
	}

	filter := stringFormatter.Format("{0}", strings.Join(l3Protos.ToSlice(), " or "))
	return &filter, true
}