* [PATCH] fixes libipt_geoip.c country check-up and print() output
@ 2004-11-16 2:38 Samuel Jean
0 siblings, 0 replies; only message in thread
From: Samuel Jean @ 2004-11-16 2:38 UTC (permalink / raw)
To: netfilter-devel; +Cc: nib
[-- Attachment #1: Type: text/plain, Size: 579 bytes --]
Hi there,
I know that geoip isn't in the svn yet, but here's the patch anyway.
*For those who need it*
It removes useless static country check-up.
This wasn't smart as it prevents users from using newly-added
countries in the db. (and vice-versa)
Anyway, they will get warned if the country isn't in the database.
This patch also adds a trailing space for a correct --list output.
Nicolas, please rebuild a new package with this patch.
Thanks,
Samuel
CookingLinux TM
[diff -Nru -p1 geoip.orig/iptables/extensions/libipt_geoip.c
geoip/iptables/extensions/libipt_geoip.c]
[-- Attachment #2: libipt_geoip.c.patch --]
[-- Type: text/x-patch, Size: 3637 bytes --]
--- geoip.orig/iptables/extensions/libipt_geoip.c 2004-11-07 11:08:42.000000000 -0500
+++ geoip/iptables/extensions/libipt_geoip.c 2004-11-15 21:14:06.000000000 -0500
@@ -27,28 +27,2 @@
-// We need it to verify inputed country code
-// This shouldn't go in ipt_geoip.h because only this library needs it.
-// Also, those country codes *MUST* stand in alphabetic order due to the
-// algorithm used to seek through this list.
-#define COUNTRYCOUNT 243 /* Always re-adjust this value when
- adding/removing a country */
-#define COUNTRYCODESZ 2 // This value shouldn't be changed.
-static char *cc_list[COUNTRYCOUNT] = {
-"A1","A2", // Anonymous Proxies and Satellite Providers
-"AD","AE","AF","AG","AI","AL","AM","AN","AO","AQ","AR","AS","AT","AU","AW","AZ",
-"BA","BB","BD","BE","BF","BG","BH","BI","BJ","BM","BN","BO","BR","BS","BT","BV",
-"BW","BY","BZ","CA","CC","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR",
-"CU","CV","CX","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER",
-"ES","ET","FI","FJ","FK","FM","FO","FR","FX","GA","GB","GD","GE","GF","GH","GI",
-"GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HM","HN","HR","HT",
-"HU","ID","IE","IL","IN","IO","IQ","IR","IS","IT","JM","JO","JP","KE","KG","KH",
-"KI","KM","KN","KP","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT",
-"LU","LV","LY","MA","MC","MD","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR",
-"MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO",
-"NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS",
-"PT","PW","PY","QA","RE","RO","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI",
-"SJ","SK","SL","SM","SN","SO","SR","ST","SV","SY","SZ","TC","TD","TF","TG","TH",
-"TJ","TK","TM","TN","TO","TP","TR","TT","TV","TW","TZ","UA","UG","UM","US","UY",
-"UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","YE","YT","YU","ZA","ZM","ZR",
-"ZW" };
-
static void help(void)
@@ -90,16 +64,2 @@ static void geoip_free(struct geoip_info
-static u_int8_t
-binary_search(const char *key, u_int8_t low, u_int8_t hi)
-{
- u_int8_t mid = (hi-low)/2 + low;
- if (low >= hi)
- return strncmp(key, cc_list[mid], 2);
- if (!strncmp(key, cc_list[mid], 2))
- return 0;
- if (strncmp(key, cc_list[mid], 2) > 0)
- return binary_search(key, mid+1, hi);
- else
- return binary_search(key, low, mid);
-}
-
struct geoip_index {
@@ -196,3 +156,3 @@ check_geoip_cc(char *cc, u_int16_t cc_us
- if (strlen(cc) != COUNTRYCODESZ) /* Country must be 2 chars long according
+ if (strlen(cc) != 2) /* Country must be 2 chars long according
to the ISO3166 standard */
@@ -203,10 +163,9 @@ check_geoip_cc(char *cc, u_int16_t cc_us
// Make sure they are..
- for (i = 0; i < COUNTRYCODESZ; i++)
- cc[i] = toupper(cc[i]);
+ for (i = 0; i < 2; i++)
+ if (isalnum(cc[i]) != 0)
+ cc[i] = toupper(cc[i]);
+ else
+ exit_error(PARAMETER_PROBLEM,
+ "geoip match: invalid country code '%s'", cc);
- // Verify for a valid value against the country code list.
- if (binary_search(cc, 0, COUNTRYCOUNT-1) != 0)
- exit_error(PARAMETER_PROBLEM,
- "geoip match: invalid country code '%s'", cc);
-
/* Convert chars into a single 16 bit integer.
@@ -338,2 +297,3 @@ print(const struct ipt_ip *ip,
printf("%s%c%c", i ? "," : "", COUNTRY(info->cc[i]));
+ printf(" ");
}
@@ -357,3 +317,2 @@ save(const struct ipt_ip *ip,
printf("%s%c%c", i ? "," : "", COUNTRY(info->cc[i]));
-
printf(" ");
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-11-16 2:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-16 2:38 [PATCH] fixes libipt_geoip.c country check-up and print() output Samuel Jean
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.