[PATCH v3 6/6] geoip: put database into country subdirectory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Philip Prindeville <philipp@xxxxxxxxxxxxxxxxxxxxx>

Useful if we start supporting multiple indicies like ASN or ORG handle.

Signed-off-by: Philip Prindeville <philipp@xxxxxxxxxxxxxxxxxxxxx>
---
 extensions/libxt_geoip.c | 4 ++--
 geoip/xt_geoip_build     | 7 ++++++-
 geoip/xt_geoip_fetch     | 2 +-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/extensions/libxt_geoip.c b/extensions/libxt_geoip.c
index ffbbb7de5429c0ea8bae91426cd6f5bdc76b9443..c09995760481c1b23d878ea25e264d0d0eae412a 100644
--- a/extensions/libxt_geoip.c
+++ b/extensions/libxt_geoip.c
@@ -94,9 +94,9 @@ geoip_get_subnets(const char *code, uint32_t *count, uint8_t nfproto)
 
 	/* Use simple integer vector files */
 	if (nfproto == NFPROTO_IPV6)
-		snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/%s.iv6", code);
+		snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/cc/%s.iv6", code);
 	else
-		snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/%s.iv4", code);
+		snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/cc/%s.iv4", code);
 
 	if ((fd = open(buf, O_RDONLY)) < 0) {
 		fprintf(stderr, "Could not open %s: %s\n", buf, strerror(errno));
diff --git a/geoip/xt_geoip_build b/geoip/xt_geoip_build
index 1955fbdb7583554a54b211e8b9cf72386ddabc2b..b97445f281c1ae80ee5fc2bdab14e8aa962c38f5 100755
--- a/geoip/xt_geoip_build
+++ b/geoip/xt_geoip_build
@@ -28,6 +28,11 @@ if (!-d $target_dir) {
 	exit 1;
 }
 
+if (!-d "$target_dir/cc" && !mkdir "$target_dir/cc") {
+	print STDERR "Couldn't create country subdirectory.\n";
+	exit 1;
+}
+
 my %countryId;
 my %countryName;
 
@@ -265,7 +270,7 @@ sub writeCountry
 		($family == AF_INET ? '4' : '6'),
 		$iso_code, $name;
 
-	my $file = "$target_dir/".uc($iso_code).".iv".($family == AF_INET ? '4' : '6');
+	my $file = "$target_dir/cc/".uc($iso_code).".iv".($family == AF_INET ? '4' : '6');
 	if (!open($fh, '>', $file)) {
 		print STDERR "Error opening $file: $!\n";
 		exit 1;
diff --git a/geoip/xt_geoip_fetch b/geoip/xt_geoip_fetch
index 4a35760b77c9509347a3846f37eeb9574aeb9883..8ca475c46f9cc3d821737d2088b3393429e158d8 100755
--- a/geoip/xt_geoip_fetch
+++ b/geoip/xt_geoip_fetch
@@ -38,7 +38,7 @@ foreach my $cc (@ARGV) {
 		exit 1;
 	}
 
-	my $file = $target_dir . '/' . uc($cc) . '.iv4';
+	my $file = "$target_dir/cc/".uc($cc).'.iv4';
 
 	if (! -f $file) {
 		printf STDERR "Can't find data for country '$cc'\n";
-- 
2.17.1




[Index of Archives]     [Linux Netfilter Development]     [Linux Kernel Networking Development]     [Netem]     [Berkeley Packet Filter]     [Linux Kernel Development]     [Advanced Routing & Traffice Control]     [Bugtraq]

  Powered by Linux