]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
location: Handle special country codes
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 29 Sep 2021 18:07:17 +0000 (18:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 4 Dec 2021 12:44:16 +0000 (12:44 +0000)
Globally, people use some special country codes for special cases (e.g.
anonymous proxies, satellite providers, anycast, etc.).

IPFire Location preserves the original country code and codes this
information in binary flags which are being checked instead.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/detect-location.c

index 1588a6506ee519429c242e58d47256e4f36a22ba..0d212581dc10586d1f9c05685738c5ff321c4c8a 100644 (file)
@@ -277,12 +277,12 @@ ERROR:
     return -1;
 }
 
-static int DetectLocationMatchCountryCode(const struct DetectLocationData* data, const char* cc) {
+static int DetectLocationMatchCountryCode(const struct DetectLocationData* data, struct loc_network* network) {
     int found = 0;
 
     if (data->countries) {
         for (char** country = data->countries; *country; country++) {
-            if (strcmp(*country, cc) == 0) {
+            if (loc_network_matches_country_code(network, *country)) {
                 found = 1;
                 break;
             }
@@ -304,9 +304,7 @@ static int DetectLocationMatchAddress(const struct DetectLocationData* data, con
 
     // If we found a network, let's check whether the country matches
     if (network) {
-        const char* country = loc_network_get_country_code(network);
-
-        if (DetectLocationMatchCountryCode(data, country))
+        if (DetectLocationMatchCountryCode(data, network))
             r = 1;
 
         loc_network_unref(network);