Commit efa47f1e authored by Ayesha Ayub's avatar Ayesha Ayub
Browse files

update validation of ip address in BWM API

parent ace910b1
Loading
Loading
Loading
Loading
+32 −37
Original line number Diff line number Diff line
@@ -1426,29 +1426,27 @@ func validateAppInfo(appInfo map[string]string) (int, string, error) {
func checkSrcIP(bw *BwInfo) (err error) {
	ueNameList := activeModel.GetNodeNames("UE")
	// if the provided source IP range matches with the existing UE IP(s)

	if len(ueNameList) > 0 {
		for _, ip := range bw.SessionFilter {
			ipFound := true
			if ip.SourceIp != "" {
				_, ueNetIP, _ := net.ParseCIDR(ip.SourceIp)
				if ueNetIP == nil {
					log.Error("IP not provided in the CIDR notation")
					err = errors.New("IP not provided in the CIDR notation in the request body")
					return err
				}
				ipName := net.ParseIP(ip.SourceIp)
				if ipName != nil {
					for _, name := range ueNameList {
						// Ignore disconnected UEs
						if !isUeConnected(name) || !isInLocality(name) {
							continue
						}
					ipName := net.ParseIP(name)
					if ueNetIP.Contains(ipName) {
						if ipName.String() == name {
							log.Info("Provided source IP range is valid against the existing UE IPs")
							ipFound = true
							break
						} else {
							ipFound = false
						}

					}
				}
				// Return error if IP not in ueNameList
				if !ipFound {
@@ -1474,27 +1472,24 @@ func checkDstIP(bw *BwInfo) (err error) {
		for _, ip := range bw.SessionFilter {
			ipFound := true
			if ip.DstAddress != "" {
				_, ueNetIP, _ := net.ParseCIDR(ip.DstAddress)
				if ueNetIP == nil {
					log.Error("IP not provided in the CIDR notation")
					err = errors.New("IP not provided in the CIDR notation in the request body")
					return err
				}
				ipName := net.ParseIP(ip.DstAddress)
				if ipName != nil {
					for _, name := range ueNameList {
						// Ignore disconnected UEs
						if !isUeConnected(name) || !isInLocality(name) {
							continue
						}
					ipName := net.ParseIP(name)
					if ueNetIP.Contains(ipName) {
						if ipName.String() == name {
							log.Info("Provided destination IP range is valid against the existing UE IPs")
							ipFound = true
							break
						} else {
							ipFound = false
						}

					}
				// Return error if IP not in ueNameList
				}

				if !ipFound {
					log.Error("Provided destination IP range is not valid against the existing UE IPs")
					err = errors.New("Provided destination IP range is not valid against the existing UE IPs in the request body")