Skip to content

Commit

Permalink
Added support for 6to4 and Teredo.
Browse files Browse the repository at this point in the history
  • Loading branch information
ip2location committed Jul 19, 2019
1 parent 91df180 commit 2c89cd3
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion source/ip2proxy-d/ip2proxy.d
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ const ubyte[9] ASN_POSITION = [0, 0, 0, 0, 0, 0, 0, 9, 9];
const ubyte[9] AS_POSITION = [0, 0, 0, 0, 0, 0, 0, 10, 10];
const ubyte[9] LASTSEEN_POSITION = [0, 0, 0, 0, 0, 0, 0, 0, 11];

protected const string MODULE_VERSION = "2.0.0";
protected const string MODULE_VERSION = "2.1.0";

protected const BigInt MAX_IPV4_RANGE = BigInt("4294967295");
protected const BigInt MAX_IPV6_RANGE = BigInt("340282366920938463463374607431768211455");
protected const BigInt FROM_6TO4 = BigInt("42545680458834377588178886921629466624");
protected const BigInt TO_6TO4 = BigInt("42550872755692912415807417417958686719");
protected const BigInt FROM_TEREDO = BigInt("42540488161975842760550356425300246528");
protected const BigInt TO_TEREDO = BigInt("42540488241204005274814694018844196863");
protected const BigInt LAST_32BITS = BigInt("4294967295");

protected const uint COUNTRYSHORT = 0X00001;
protected const uint COUNTRYLONG = 0X00002;
Expand Down Expand Up @@ -322,6 +327,26 @@ class ip2proxy {
ipdata.ipindex = ((ipno2 >> 16) << 3) + meta.ipv4indexbaseaddr;
}
}
else if (ipdata.ipnum >= FROM_6TO4 && ipdata.ipnum <= TO_6TO4) {
// 6to4 so need to remap to ipv4
ipdata.iptype = 4;
ipdata.ipnum = ipdata.ipnum >> 80;
ipdata.ipnum = ipdata.ipnum & LAST_32BITS;
uint ipno2 = to!uint(ipdata.ipnum);
if (meta.ipv4indexbaseaddr > 0) {
ipdata.ipindex = ((ipno2 >> 16) << 3) + meta.ipv4indexbaseaddr;
}
}
else if (ipdata.ipnum >= FROM_TEREDO && ipdata.ipnum <= TO_TEREDO) {
// Teredo so need to remap to ipv4
ipdata.iptype = 4;
ipdata.ipnum = ~ipdata.ipnum; // bitwise NOT
ipdata.ipnum = ipdata.ipnum & LAST_32BITS;
uint ipno2 = to!uint(ipdata.ipnum);
if (meta.ipv4indexbaseaddr > 0) {
ipdata.ipindex = ((ipno2 >> 16) << 3) + meta.ipv4indexbaseaddr;
}
}
}
}
catch (Exception e) {
Expand Down

0 comments on commit 2c89cd3

Please sign in to comment.