// ParseNode parses a kubernetes node to a cilium node
435946
func ParseNode(k8sNode *types.Node, source node.Source) *node.Node {
	scopedLog := log.WithFields(logrus.Fields{
		logfields.NodeName:  k8sNode.Name,
		logfields.K8sNodeID: k8sNode.UID,
	})
	addrs := []node.Address{}
	for _, addr := range k8sNode.StatusAddresses {
		// We only care about this address types,
		// we ignore all other types.
		switch addr.Type {
		case v1.NodeInternalIP, v1.NodeExternalIP:
		default:
			continue
		}
		// If the address is not set let's not parse it at all.
		// This can be the case for v1.NodeExternalIPs
		if addr.Address == "" {
			continue
		}
		ip := net.ParseIP(addr.Address)
		if ip == nil {
			scopedLog.WithFields(logrus.Fields{
				logfields.IPAddr: addr.Address,
				"type":           addr.Type,
			}).Warn("Ignoring invalid node IP")
			continue
		}

		addressType, err := ParseNodeAddressType(addr.Type)

		if err != nil {
			scopedLog.WithError(err).Warn("invalid address type for node")
		}

		na := node.Address{
			Type: addressType,
			IP:   ip,
		}
		addrs = append(addrs, na)
	}

	k8sNodeAddHostIP := func(annotation string) {
		if ciliumInternalIP, ok := k8sNode.Annotations[annotation]; !ok {
			scopedLog.Debugf("Missing %s. Annotation required when IPSec Enabled", annotation)
		} else if ip := net.ParseIP(ciliumInternalIP); ip == nil {
			scopedLog.Debugf("ParseIP %s error", ciliumInternalIP)
		} else {
			na := node.Address{
				Type: addressing.NodeCiliumInternalIP,
				IP:   ip,
			}
			addrs = append(addrs, na)
			scopedLog.Debugf("Add NodeCiliumInternalIP: %s", ip)
		}
	}

	k8sNodeAddHostIP(annotation.CiliumHostIP)
	k8sNodeAddHostIP(annotation.CiliumHostIPv6)

	newNode := &node.Node{
		Name:        k8sNode.Name,
		Cluster:     option.Config.ClusterName,
		IPAddresses: addrs,
		Source:      source,
	}

	if len(k8sNode.SpecPodCIDR) != 0 {
		if allocCIDR, err := cidr.ParseCIDR(k8sNode.SpecPodCIDR); err != nil {
			scopedLog.WithError(err).WithField(logfields.V4Prefix, k8sNode.SpecPodCIDR).Warn("Invalid PodCIDR value for node")
		} else {
			if allocCIDR.IP.To4() != nil {
				newNode.IPv4AllocCIDR = allocCIDR
			} else {
				newNode.IPv6AllocCIDR = allocCIDR
			}
		}
	}
	// Spec.PodCIDR takes precedence since it's
	// the CIDR assigned by k8s controller manager
	// In case it's invalid or empty then we fall back to our annotations.
	if newNode.IPv4AllocCIDR == nil {
		if ipv4CIDR, ok := k8sNode.Annotations[annotation.V4CIDRName]; !ok {
			scopedLog.Debug("Empty IPv4 CIDR annotation in node")
		} else {
			allocCIDR, err := cidr.ParseCIDR(ipv4CIDR)
			if err != nil {
				scopedLog.WithError(err).WithField(logfields.V4Prefix, ipv4CIDR).Error("BUG, invalid IPv4 annotation CIDR in node")
			} else {
				newNode.IPv4AllocCIDR = allocCIDR
			}
		}
	}

	if newNode.IPv6AllocCIDR == nil {
		if ipv6CIDR, ok := k8sNode.Annotations[annotation.V6CIDRName]; !ok {
			scopedLog.Debug("Empty IPv6 CIDR annotation in node")
		} else {
			allocCIDR, err := cidr.ParseCIDR(ipv6CIDR)
			if err != nil {
				scopedLog.WithError(err).WithField(logfields.V6Prefix, ipv6CIDR).Error("BUG, invalid IPv6 annotation CIDR in node")
			} else {
				newNode.IPv6AllocCIDR = allocCIDR
			}
		}
	}

	if newNode.IPv4HealthIP == nil {
		if healthIP, ok := k8sNode.Annotations[annotation.V4HealthName]; !ok {
			scopedLog.Debug("Empty IPv4 health endpoint annotation in node")
		} else if ip := net.ParseIP(healthIP); ip == nil {
			scopedLog.WithField(logfields.V4HealthIP, healthIP).Error("BUG, invalid IPv4 health endpoint annotation in node")
		} else {
			newNode.IPv4HealthIP = ip
		}
	}

	if newNode.IPv6HealthIP == nil {
		if healthIP, ok := k8sNode.Annotations[annotation.V6HealthName]; !ok {
			scopedLog.Debug("Empty IPv6 health endpoint annotation in node")
		} else if ip := net.ParseIP(healthIP); ip == nil {
			scopedLog.WithField(logfields.V6HealthIP, healthIP).Error("BUG, invalid IPv6 health endpoint annotation in node")
		} else {
			newNode.IPv6HealthIP = ip
		}
	}

	return newNode
}
1369083
func NewNode() *ConfigDataNode {
	return &ConfigDataNode{
		mutex: new(sync.Mutex),
		table: make(map[string]ctypes.ConfigValue),
	}
}
429377
func (c *Config) ProvisionerHarvestMode() HarvestMode {
	if v, ok := c.defined[ProvisionerHarvestModeKey].(string); ok {
		if method, err := ParseHarvestMode(v); err != nil {
			// This setting should have already been validated. Don't
			// burden the caller with handling any errors.
			panic(err)
		} else {
			return method
		}
	} else {
		return HarvestDestroyed
	}
}
779960
func (net *Network) GetNode(id enode.ID) *Node {
	net.lock.RLock()
	defer net.lock.RUnlock()
	return net.getNode(id)
}
1264510
func (t *Tree) parseLenFunc() (Node, error) {
	node := new(FuncNode)

	t.scanner.accept = acceptOneHash
	t.scanner.mode = scanIdent
	switch t.scanner.scan() {
	case tokenIdent:
		node.Name = t.scanner.string()
	default:
		return nil, ErrBadSubstitution
	}

	t.scanner.accept = acceptIdent
	t.scanner.mode = scanIdent
	switch t.scanner.scan() {
	case tokenIdent:
		node.Param = t.scanner.string()
	default:
		return nil, ErrBadSubstitution
	}

	return node, t.consumeRbrack()
}
589459
func (cniReq *cniServer) parseCniArgs(httpBody []byte) error {

	if err := json.Unmarshal(httpBody, &cniReq.pluginArgs); err != nil {
		return fmt.Errorf("failed to parse JSON req: %s", err.Error())
	}

	cniLog.Debugf("parsed ifname: %s, netns: %s, container-id: %s,"+
		"tenant: %s, network-name: %s, network-group: %s",
		cniReq.pluginArgs.CniIfname, cniReq.pluginArgs.CniNetns,
		cniReq.pluginArgs.CniContainerid,
		cniReq.pluginArgs.Labels.TenantName,
		cniReq.pluginArgs.Labels.NetworkName,
		cniReq.pluginArgs.Labels.NetworkGroup)

	// set defaults
	cniReq.endPointLabels = map[string]string{cniapi.LabelNetworkName: "default-net",
		cniapi.LabelTenantName: "default"}

	for _, label := range []string{cniapi.LabelTenantName, cniapi.LabelNetworkName,
		cniapi.LabelNetworkGroup} {

		switch label {
		case cniapi.LabelTenantName:
			if len(cniReq.pluginArgs.Labels.TenantName) > 0 {
				cniReq.endPointLabels[label] = cniReq.pluginArgs.Labels.TenantName
			}
			cniLog.Infof("netplugin label %s = %s", cniapi.LabelTenantName,
				cniReq.endPointLabels[label])

		case cniapi.LabelNetworkName:
			if len(cniReq.pluginArgs.Labels.NetworkName) > 0 {
				cniReq.endPointLabels[label] = cniReq.pluginArgs.Labels.NetworkName
			}
			cniLog.Infof("netplugin label %s = %s", cniapi.LabelNetworkName,
				cniReq.endPointLabels[label])

		case cniapi.LabelNetworkGroup:
			if len(cniReq.pluginArgs.Labels.NetworkGroup) > 0 {
				cniReq.endPointLabels[label] = cniReq.pluginArgs.Labels.NetworkGroup
			}
			cniLog.Infof("netplugin label %s = %s", cniapi.LabelNetworkGroup,
				cniReq.endPointLabels[label])
		}
	}

	cniReq.networkID = cniReq.endPointLabels[cniapi.LabelNetworkName] + "." +
		cniReq.endPointLabels[cniapi.LabelTenantName]
	cniLog.Infof("network fdn  %s", cniReq.networkID)
	cniReq.endpointID = cniReq.networkID + "-" +
		cniReq.pluginArgs.CniContainerid
	cniLog.Infof("endpoint fdn %s", cniReq.endpointID)
	return nil
}
634184
func nextNode(it iterator.Iterator) *Node {
	for end := false; !end; end = !it.Next() {
		id, rest := splitNodeKey(it.Key())
		if string(rest) != dbDiscoverRoot {
			continue
		}
		return mustDecodeNode(id[:], it.Value())
	}
	return nil
}
311029
func (t *Terminal) CharMode() error {
	// Disable canonical mode, and set buffer size to 1 byte.
	t.lastState.Lflag &^= sys.ICANON
	t.lastState.Cc[sys.VTIME] = 0
	t.lastState.Cc[sys.VMIN] = 1

	if err := sys.Setattr(t.fd, sys.TCSANOW, &t.lastState); err != nil {
		return os.NewSyscallError("sys.Setattr", err)
	}
	t.mode |= CharMode
	return nil
}
749071
func mapToAWSInstanceIDs(nodes []*v1.Node) ([]InstanceID, error) {
	var instanceIDs []InstanceID
	for _, node := range nodes {
		if node.Spec.ProviderID == "" {
			return nil, fmt.Errorf("node %q did not have ProviderID set", node.Name)
		}
		instanceID, err := KubernetesInstanceID(node.Spec.ProviderID).MapToAWSInstanceID()
		if err != nil {
			return nil, fmt.Errorf("unable to parse ProviderID %q for node %q", node.Spec.ProviderID, node.Name)
		}
		instanceIDs = append(instanceIDs, instanceID)
	}

	return instanceIDs, nil
}
784940
func parseNodes(path string) []*node {
	var i, j int
	l := len(path)
	var nodes = make([]*node, 0)
	var bracket int
	for ; i < l; i++ {
		if path[i] == ':' {
			nodes = append(nodes, &node{tp: snode, content: path[j : i-bracket]})
			j = i
			var regex string
			if bracket == 1 {
				var start = -1
				for ; i < l && ')' != path[i]; i++ {
					if start == -1 && isSpecial(path[i]) {
						start = i
					}
				}
				if path[i] != ')' {
					panic("lack of )")
				}
				if start > -1 {
					regex = path[start:i]
				}
			} else {
				i = i + 1
				for ; i < l && isAlnum(path[i]); i++ {
				}
			}

			if len(regex) > 0 {
				nodes = append(nodes, &node{tp: rnode,
					regexp:  regexp.MustCompile("(" + regex + ")"),
					content: path[j : i-len(regex)]})
			} else {
				nodes = append(nodes, &node{tp: nnode, content: path[j:i]})
			}
			i = i + bracket
			j = i
			bracket = 0
			if i == l {
				return nodes
			}
		} else if path[i] == '*' {
			nodes = append(nodes, &node{tp: snode, content: path[j : i-bracket]})
			j = i
			if bracket == 1 {
				for ; i < l && ')' != path[i]; i++ {
				}
			} else {
				i = i + 1
				for ; i < l && isAlnum(path[i]); i++ {
				}
			}
			nodes = append(nodes, &node{tp: anode, content: path[j:i]})
			i = i + bracket
			bracket = 0
			j = i
			if i == l {
				return nodes
			}
		} else if path[i] == '(' {
			bracket = 1
		} else if path[i] == '/' {
			if bracket == 0 && i > j {
				nodes = append(nodes, &node{tp: snode, content: path[j:i]})
				j = i
			}
		} else {
			bracket = 0
		}
	}

	nodes = append(nodes, &node{
		tp:      snode,
		content: path[j:i],
	})

	return nodes
}
1373299
func ParseServiceIDFrom(dn string) *ServiceID {
	// typical service name "cilium-etcd-client.kube-system.svc"
	idx1 := strings.IndexByte(dn, '.')
	if idx1 >= 0 {
		svc := ServiceID{
			Name: dn[:idx1],
		}
		idx2 := strings.IndexByte(dn[idx1+1:], '.')
		if idx2 >= 0 {
			// "cilium-etcd-client.kube-system.svc"
			//                     ^idx1+1    ^ idx1+1+idx2
			svc.Namespace = dn[idx1+1 : idx1+1+idx2]
		} else {
			// "cilium-etcd-client.kube-system"
			//                     ^idx1+1
			svc.Namespace = dn[idx1+1:]
		}
		return &svc
	}
	return nil
}
119571
func ParseCiliumID(id string) (int64, error) {
	prefix, id := splitID(id)
	if prefix != CiliumLocalIdPrefix {
		return 0, fmt.Errorf("not a cilium identifier")
	}
	n, err := strconv.ParseInt(id, 0, 64)
	if err != nil {
		return 0, fmt.Errorf("invalid numeric cilium id: %s", err)
	}
	return n, nil
}
1190989
func decodeNode(hash, buf []byte) (node, error) {
	if len(buf) == 0 {
		return nil, io.ErrUnexpectedEOF
	}
	elems, _, err := rlp.SplitList(buf)
	if err != nil {
		return nil, fmt.Errorf("decode error: %v", err)
	}
	switch c, _ := rlp.CountValues(elems); c {
	case 2:
		n, err := decodeShort(hash, elems)
		return n, wrapError(err, "short")
	case 17:
		n, err := decodeFull(hash, elems)
		return n, wrapError(err, "full")
	default:
		return nil, fmt.Errorf("invalid number of list elements: %v", c)
	}
}
1315893
func NewDoNode(expr Expr, pos Pos) *DoNode {
	return &DoNode{pos, TrimmableNode{}, expr}
}
594500
func Parse(r io.Reader) (*Node, error) {
	p := &parser{
		tokenizer: NewTokenizer(r),
		doc: &Node{
			Type: DocumentNode,
		},
		scripting:  true,
		framesetOK: true,
		im:         initialIM,
	}
	err := p.parse()
	if err != nil {
		return nil, err
	}
	return p.doc, nil
}
997579
func EncodeToNode(element interface{}) (*Node, error) {
	rValue := reflect.ValueOf(element)
	node := &Node{Name: "traefik"}

	err := setNodeValue(node, rValue)
	if err != nil {
		return nil, err
	}

	return node, nil
}
695972
func (p *frameParser) ParseNext(r *bytes.Reader, encLevel protocol.EncryptionLevel) (Frame, error) {
	for r.Len() != 0 {
		typeByte, _ := r.ReadByte()
		if typeByte == 0x0 { // PADDING frame
			continue
		}
		r.UnreadByte()

		return p.parseFrame(r, typeByte, encLevel)
	}
	return nil, nil
}