// Return a MatchField for Input port matching
540484
func NewInPortField(inPort uint32) *MatchField {
	f := new(MatchField)
	f.Class = OXM_CLASS_OPENFLOW_BASIC
	f.Field = OXM_FIELD_IN_PORT
	f.HasMask = false

	inPortField := new(InPortField)
	inPortField.InPort = inPort
	f.Value = inPortField
	f.Length = uint8(inPortField.Len())

	return f
}
620919
func matchSymbol(names []string, start, end uint64, r *regexp.Regexp, address uint64) []string {
	if address != 0 && address >= start && address <= end {
		return names
	}
	for _, name := range names {
		if r == nil || r.MatchString(name) {
			return []string{name}
		}

		// Match all possible demangled versions of the name.
		for _, o := range [][]demangle.Option{
			{demangle.NoClones},
			{demangle.NoParams},
			{demangle.NoParams, demangle.NoTemplateParams},
		} {
			if demangled, err := demangle.ToString(name, o...); err == nil && r.MatchString(demangled) {
				return []string{demangled}
			}
		}
	}
	return nil
}
219006
func (cfg *Config) GetPort() int {
	if cfg.Endpoint != "" && cfg.Endpoint != ":" {
		index := strings.LastIndex(cfg.Endpoint, ":")
		if index >= 0 {
			port, err := strconv.Atoi(cfg.Endpoint[index+1:])
			if err == nil {
				return port
			}
		}
	}

	return 0
}
860894
func GteF(field1, field2 string) Matcher {
	return NewField2FieldMatcher(field1, field2, token.GEQ)
}
1020751
func (n *Net) MatchCIDR(s string) (route *net.IPNet, value interface{}, err error) {
	var r *net.IPNet
	if _, r, err = net.ParseCIDR(s); err == nil {
		route, value, err = n.Match(r)
	}
	return
}
657030
func (c *EndpointConfig) getDefaultMatchingURL(searchKey string) string {
	if strings.Contains(searchKey, ":") {
		return searchKey
	}
	return ""
}
214945
func patternMatch(str string, patChars, patTypes []byte) bool {
	return stringutil.DoMatch(str, patChars, patTypes)
}
1137875
func GetMatch(c C) Match {
	if c.Env == nil {
		return Match{}
	}
	mi, ok := c.Env[MatchKey]
	if !ok {
		return Match{}
	}
	if m, ok := mi.(Match); ok {
		return m
	}
	return Match{}
}
441275
func (c *ACLCache) GetMatchingAction(ip []byte, port uint16) (report *policy.FlowPolicy, packet *policy.FlowPolicy, err error) {

	report, packet, err = c.reject.getMatchingAction(ip, port, report)
	if err == nil {
		return
	}

	report, packet, err = c.accept.getMatchingAction(ip, port, report)
	if err == nil {
		return
	}

	report, packet, err = c.observe.getMatchingAction(ip, port, report)
	if err == nil {
		return
	}

	if report == nil {
		report = catchAllPolicy
	}

	if packet == nil {
		packet = catchAllPolicy
	}

	return report, packet, errors.New("no match")
}
693227
func NewIpv4SrcField(ipSrc net.IP, ipSrcMask *net.IP) *MatchField {
	f := new(MatchField)
	f.Class = OXM_CLASS_OPENFLOW_BASIC
	f.Field = OXM_FIELD_IPV4_SRC
	f.HasMask = false

	ipSrcField := new(Ipv4SrcField)
	ipSrcField.Ipv4Src = ipSrc
	f.Value = ipSrcField
	f.Length = uint8(ipSrcField.Len())

	// Add the mask
	if ipSrcMask != nil {
		mask := new(Ipv4SrcField)
		mask.Ipv4Src = *ipSrcMask
		f.Mask = mask
		f.HasMask = true
		f.Length += uint8(mask.Len())
	}

	return f
}
576800
func (filters Args) ExactMatch(field, source string) bool {
	fieldValues, ok := filters.fields[field]
	//do not filter if there is no filter set or cannot determine filter
	if !ok || len(fieldValues) == 0 {
		return true
	}

	// try to match full name value to avoid O(N) regular expression matching
	return fieldValues[source]
}
899545
func MatchHost(req *http.Request, ereq *Request) (bool, error) {
	url := ereq.URLStruct
	if strings.EqualFold(url.Host, req.URL.Host) {
		return true, nil
	}
	return regexp.MatchString(url.Host, req.URL.Host)
}
596501
func (p *PortCache) GetSpecValueFromPort(port uint16) (interface{}, error) {
	if spec, err := p.ports.Get(port); err == nil {
		return spec.(*portspec.PortSpec).Value(), nil
	}

	p.Lock()
	defer p.Unlock()
	for _, s := range p.ranges {
		if s.Min <= port && port < s.Max {
			return s.Value(), nil
		}
	}

	return nil, fmt.Errorf("No match for port %d", port)
}
852868
func KeyMatch(xu *xgbutil.XUtil,
	keyStr string, mods uint16, keycode xproto.Keycode) bool {

	guess := LookupString(xu, mods, keycode)
	return strings.ToLower(guess) == strings.ToLower(keyStr)
}
323241
func HeaderMatch(hdr http.Header, nm string, matchType HeaderMatchType, test string) bool {
	// First get the header value
	val := hdr[http.CanonicalHeaderKey(nm)]
	if len(val) == 0 {
		return false
	}
	// Prepare the match test
	test = strings.ToLower(test)
	for _, v := range val {
		v = strings.Trim(strings.ToLower(v), " \n\t")
		switch matchType {
		case HmEquals:
			if v == test {
				return true
			}
		case HmStartsWith:
			if strings.HasPrefix(v, test) {
				return true
			}
		case HmEndsWith:
			if strings.HasSuffix(v, test) {
				return true
			}
		case HmContains:
			if strings.Contains(v, test) {
				return true
			}
		}
	}
	return false
}
510610
func (n EndpointSelector) GetMatch(key string) ([]string, bool) {
	if value, ok := n.MatchLabels[key]; ok {
		return []string{value}, true
	}
	for _, v := range n.MatchExpressions {
		if v.Key == key && v.Operator == metav1.LabelSelectorOpIn {
			return v.Values, true
		}
	}
	return nil, false
}
838604
func (r *Request) MatchParam(key, value string) *Request {
	query := r.URLStruct.Query()
	query.Set(key, value)
	r.URLStruct.RawQuery = query.Encode()
	return r
}