// Return a MatchField for ipv4 protocol
167043
func NewIpProtoField(protocol uint8) *MatchField {
	f := new(MatchField)
	f.Class = OXM_CLASS_OPENFLOW_BASIC
	f.Field = OXM_FIELD_IP_PROTO
	f.HasMask = false

	ipProtoField := new(IpProtoField)
	ipProtoField.protocol = protocol
	f.Value = ipProtoField
	f.Length = uint8(ipProtoField.Len())

	return f
}
1035408
func getMatchingGlobalIP(addrs []net.Addr, family AddressFamily) (net.IP, error) {
	if len(addrs) > 0 {
		for i := range addrs {
			klog.V(4).Infof("Checking addr  %s.", addrs[i].String())
			ip, _, err := net.ParseCIDR(addrs[i].String())
			if err != nil {
				return nil, err
			}
			if memberOf(ip, family) {
				if ip.IsGlobalUnicast() {
					klog.V(4).Infof("IP found %v", ip)
					return ip, nil
				} else {
					klog.V(4).Infof("Non-global unicast address found %v", ip)
				}
			} else {
				klog.V(4).Infof("%v is not an IPv%d address", ip, int(family))
			}

		}
	}
	return nil, nil
}
927409
func (a *acl) getMatchingAction(ip []byte, port uint16, preReport *policy.FlowPolicy) (report *policy.FlowPolicy, packet *policy.FlowPolicy, err error) {

	report = preReport

	addr := binary.BigEndian.Uint32(ip)

	// Iterate over all the bitmasks we have
	for _, len := range a.sortedPrefixLens {

		rules, ok := a.prefixLenMap[len]
		if !ok {
			continue
		}

		// Do a lookup as a hash to see if we have a match
		actionList, ok := rules.rules[addr&rules.mask]
		if !ok {
			continue
		}

		report, packet, err = actionList.lookup(port, report)
		if err == nil {
			return
		}
	}

	return report, packet, errors.New("No match")
}
882972
func (m *Match) matchIndex(cap int) int {
	i := m.matches[cap][m.matchcount[cap]*2-2]
	if i >= 0 {
		return i
	}

	return m.matches[cap][-3-i]
}
647144
func MatchIPv6ExtHeader(header uint16) ofp.XM {
	return basic(ofp.XMTypeIPv6ExtHeader, bytesOf(header), nil)
}
989553
func (n *Net) Match(r *net.IPNet) (route *net.IPNet, value interface{}, err error) {
	var ip net.IP
	if ip, _, err = netValidateIP(r.IP); err == nil {
		if k, v := n.match(netIPNetToKey(ip, r.Mask)); k != nil {
			route = netKeyToIPNet(k)
			value = v
		}
	}
	return
}
1326110
func validateMatchClient(value string) bool {
	match_client := [5]string{"MAC_ADDRESS", "CLIENT_ID", "RESERVED", "CIRCUIT_ID", "REMOTE_ID"}

	for _, val := range match_client {
		if val == value {
			return true
		}
	}
	return false
}
531391
func (r MatchRule) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error) {
	if r.Type == IPWhitelist {
		return CheckIPWhitelist(remoteAddr, r.IPRange)
	}
	if r.Type == ScalrSignature {
		return CheckScalrSignature(*headers, *body, r.Secret, true)
	}

	if arg, ok := r.Parameter.Get(headers, query, payload); ok {
		switch r.Type {
		case MatchValue:
			return arg == r.Value, nil
		case MatchRegex:
			return regexp.MatchString(r.Regex, arg)
		case MatchHashSHA1:
			_, err := CheckPayloadSignature(*body, r.Secret, arg)
			return err == nil, err
		case MatchHashSHA256:
			_, err := CheckPayloadSignature256(*body, r.Secret, arg)
			return err == nil, err
		}
	}
	return false, nil
}
736573
func (pg *GoEvtxMap) RegexMatch(path *GoEvtxPath, pattern *regexp.Regexp) bool {
	s, err := pg.GetString(path)
	if err != nil {
		return false
	}
	return pattern.MatchString(s)
}
707046
func HTTP2HeaderFieldPrefix(name, valuePrefix string) Matcher {
	return func(r io.Reader) bool {
		return matchHTTP2Field(ioutil.Discard, r, name, func(gotValue string) bool {
			return strings.HasPrefix(gotValue, valuePrefix)
		})
	}
}
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
}
99345
func (c *Criterion) MatchFunc(match MatchFunc) *Query {
	if c.query.currentField == Key {
		panic("Match func cannot be used against Keys, as the Key type is unknown at runtime, and there is no value compare against")
	}

	return c.op(fn, match)
}
151219
func NetIPv4Decoder(s string) (string, error) {

	if !ipv4RegExp.MatchString(s) {
		return "", errors.New("Cannot decode ipv4 address: " + s)
	}

	i := strings.Split(s, ":")

	b := make([]byte, 4)

	for j := 0; j < 4; j++ {

		x := j * 2
		y := x + 2
		z := 3 - j

		// Extract 2 characters from hex string, 4 times.
		//
		// s: "0100007F" -> [
		//     h: "01", h: "00", h: "00", h: "7F",
		// ]
		h := i[0][x:y]

		// Reverse byte order
		n, _ := strconv.ParseUint(h, 16, 8)
		b[z] = byte(n)

	}

	h := net.IP(b).String()
	n, _ := strconv.ParseUint(i[1], 16, 64)
	p := strconv.FormatUint(n, 10)

	// ipv4:port
	v := h + ":" + p

	return v, nil
}
1319081
func isIP4AddrResolvable(fl FieldLevel) bool {

	if !isIPv4(fl) {
		return false
	}

	_, err := net.ResolveIPAddr("ip4", fl.Field().String())

	return err == nil
}
244409
func (h *Hostsfile) LookupStaticHostV4(host string) []net.IP {
	return h.lookupStaticHost(h.hmap.byNameV4, host)
}
483639
func (n *network) getSubnetforIPv4(ip *net.IPNet) *ipv4Subnet {
	for _, s := range n.config.Ipv4Subnets {
		_, snet, err := net.ParseCIDR(s.SubnetIP)
		if err != nil {
			return nil
		}
		// first check if the mask lengths are the same
		i, _ := snet.Mask.Size()
		j, _ := ip.Mask.Size()
		if i != j {
			continue
		}
		if snet.Contains(ip.IP) {
			return s
		}
	}

	return nil
}
838604
func (r *Request) MatchParam(key, value string) *Request {
	query := r.URLStruct.Query()
	query.Set(key, value)
	r.URLStruct.RawQuery = query.Encode()
	return r
}