Compare commits

..

No commits in common. "simpler" and "master" have entirely different histories.

5 changed files with 38 additions and 35 deletions

View file

@ -91,7 +91,10 @@ func truncate(values []string, contextValueLen int) (string, error) {
return "", fmt.Errorf("unable to dump metas: %s", err)
}
ret = string(valueByte)
for len(ret) > contextValueLen {
for {
if len(ret) <= contextValueLen {
break
}
// if there is only 1 value left and that the size is too big, truncate it
if len(values) == 1 {
valueToTruncate := values[0]

View file

@ -911,17 +911,12 @@ func (a *apic) UpdateBlocklists(links *modelscapi.GetDecisionsStreamResponseLink
}
func setAlertScenario(alert *models.Alert, addCounters map[string]map[string]int, deleteCounters map[string]map[string]int) {
switch *alert.Source.Scope {
case types.CAPIOrigin:
if *alert.Source.Scope == types.CAPIOrigin {
*alert.Source.Scope = types.CommunityBlocklistPullSourceScope
alert.Scenario = ptr.Of(fmt.Sprintf("update : +%d/-%d IPs",
addCounters[types.CAPIOrigin]["all"],
deleteCounters[types.CAPIOrigin]["all"]))
case types.ListOrigin:
alert.Scenario = ptr.Of(fmt.Sprintf("update : +%d/-%d IPs", addCounters[types.CAPIOrigin]["all"], deleteCounters[types.CAPIOrigin]["all"]))
} else if *alert.Source.Scope == types.ListOrigin {
*alert.Source.Scope = fmt.Sprintf("%s:%s", types.ListOrigin, *alert.Scenario)
alert.Scenario = ptr.Of(fmt.Sprintf("update : +%d/-%d IPs",
addCounters[types.ListOrigin][*alert.Scenario],
deleteCounters[types.ListOrigin][*alert.Scenario]))
alert.Scenario = ptr.Of(fmt.Sprintf("update : +%d/-%d IPs", addCounters[types.ListOrigin][*alert.Scenario], deleteCounters[types.ListOrigin][*alert.Scenario]))
}
}
@ -993,12 +988,11 @@ func makeAddAndDeleteCounters() (map[string]map[string]int, map[string]map[strin
}
func updateCounterForDecision(counter map[string]map[string]int, origin *string, scenario *string, totalDecisions int) {
switch *origin {
case types.CAPIOrigin:
if *origin == types.CAPIOrigin {
counter[*origin]["all"] += totalDecisions
case types.ListOrigin:
} else if *origin == types.ListOrigin {
counter[*origin][*scenario] += totalDecisions
default:
} else {
log.Warningf("Unknown origin %s", *origin)
}
}

View file

@ -49,17 +49,20 @@ func LastAddress(n *net.IPNet) net.IP {
ip[3]|^n.Mask[3])
}
// GetIpsFromIpRange takes a CIDR range and returns the start and end IP
func GetIpsFromIpRange(host string) (int64, int64, error) {
_, parsedRange, err := net.ParseCIDR(host)
if err != nil {
return 0, 0, fmt.Errorf("'%s' is not a valid CIDR", host)
var ipStart int64
var ipEnd int64
var err error
var parsedRange *net.IPNet
if _, parsedRange, err = net.ParseCIDR(host); err != nil {
return ipStart, ipEnd, fmt.Errorf("'%s' is not a valid CIDR", host)
}
if parsedRange == nil {
return 0, 0, fmt.Errorf("unable to parse network : %s", err)
return ipStart, ipEnd, fmt.Errorf("unable to parse network : %s", err)
}
ipStart := int64(IP2Int(parsedRange.IP))
ipEnd := int64(IP2Int(LastAddress(parsedRange)))
ipStart = int64(IP2Int(parsedRange.IP))
ipEnd = int64(IP2Int(LastAddress(parsedRange)))
return ipStart, ipEnd, nil
}

View file

@ -380,17 +380,19 @@ func LoadBucket(bucketFactory *BucketFactory, tomb *tomb.Tomb) error {
bucketFactory.processors = append(bucketFactory.processors, &BayesianBucket{})
}
for _, data := range bucketFactory.Data {
if data.DestPath == "" {
bucketFactory.logger.Errorf("no dest_file provided for '%s'", bucketFactory.Name)
continue
}
err = exprhelpers.FileInit(bucketFactory.DataDir, data.DestPath, data.Type)
if err != nil {
bucketFactory.logger.Errorf("unable to init data for file '%s': %s", data.DestPath, err)
}
if data.Type == "regexp" { //cache only makes sense for regexp
exprhelpers.RegexpCacheInit(data.DestPath, *data)
if len(bucketFactory.Data) > 0 {
for _, data := range bucketFactory.Data {
if data.DestPath == "" {
bucketFactory.logger.Errorf("no dest_file provided for '%s'", bucketFactory.Name)
continue
}
err = exprhelpers.FileInit(bucketFactory.DataDir, data.DestPath, data.Type)
if err != nil {
bucketFactory.logger.Errorf("unable to init data for file '%s': %s", data.DestPath, err)
}
if data.Type == "regexp" { //cache only makes sense for regexp
exprhelpers.RegexpCacheInit(data.DestPath, *data)
}
}
}

View file

@ -97,12 +97,13 @@ func IP2Ints(pip net.IP) (int, int64, int64, error) {
if pip4 != nil {
ip_nw32 := binary.BigEndian.Uint32(pip4)
return 4, uint2int(uint64(ip_nw32)), uint2int(ip_sfx), nil
}
if pip16 != nil {
} else if pip16 != nil {
ip_nw = binary.BigEndian.Uint64(pip16[0:8])
ip_sfx = binary.BigEndian.Uint64(pip16[8:16])
return 16, uint2int(ip_nw), uint2int(ip_sfx), nil
} else {
return -1, 0, 0, fmt.Errorf("unexpected len %d for %s", len(pip), pip)
}
return -1, 0, 0, fmt.Errorf("unexpected len %d for %s", len(pip), pip)
}