Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
612c5fdabe | ||
|
|
5a776075bb | ||
|
|
ec8f193392 | ||
|
|
771682b840 | ||
|
|
45b6bfcccc | ||
|
|
4a271a9223 | ||
|
|
fc07e620e8 | ||
|
|
5d8801d468 | ||
|
|
1251ce0d7c | ||
|
|
638b058f96 | ||
|
|
ce631645e3 | ||
|
|
9c8ac4fd8d |
No files matched your search
+4
-3
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.xapek.andiodine"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
android:versionCode="2"
|
||||
android:versionName="1.1">
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="14"
|
||||
@@ -11,6 +11,7 @@
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<application
|
||||
android:debuggable="true"
|
||||
android:allowBackup="false"
|
||||
android:icon="@drawable/logo"
|
||||
android:label="@string/app_name"
|
||||
@@ -40,4 +41,4 @@
|
||||
</intent-filter>
|
||||
</service>
|
||||
</application>
|
||||
</manifest>
|
||||
</manifest>
|
||||
+42
-41
@@ -16,12 +16,13 @@ des Programs siehe 'Entwicklerdokumentation'.
|
||||
|
||||
Ein DNS Tunnel ermöglicht regulären IP Verkehr durch den Internet
|
||||
Namensauflösungsdienst DNS zu tunneln. Damit ist es möglich, in Netzen
|
||||
die keine normales Internet Routing unterstützen, Daten auszutauschen.
|
||||
Voraussetzung ist, dass das Netz gewöhnliche DNS-Auflösung unterstützt.
|
||||
in denen ein restriktiver Paket Filter arbeitet oder überhaupt keine Route ins
|
||||
Internet angekündigt wird, beliebige Daten mit dem Tunnel Endpunkt auszutauschen.
|
||||
Voraussetzung ist, dass das Netz gewöhnliche DNS-Auflösung unterstützt.
|
||||
Die Datenpakete werden in DNS-Anfragen kodiert, die durch die hierarchische
|
||||
Struktur an einen speziellen (i.d.R. third-level) Nameserver weitergeleitet werden.
|
||||
|
||||
Die Software <<iodine>> ist eine Implementierung eines DNS Tunnel für Linux,
|
||||
Die Software <<iodine>> ist eine Implementierung eines DNS Tunnel für Linux,
|
||||
Mac OS X, FreeBSD, NetBSD, OpenBSD and Windows. Diese Dokumentation beschreibt
|
||||
die Portierung auf Android mit einer angepassten Benutzeroberfläche.
|
||||
--
|
||||
@@ -38,12 +39,12 @@ http://code.kryo.se/iodine/iodine-latest-android.zip[cross-kompiliertes
|
||||
iodine] auszuführen.
|
||||
|
||||
|
||||
|
||||
|
||||
Funktionsweise eines DNS-Tunnel
|
||||
-------------------------------
|
||||
|
||||
Das Domain-Name-System (DNS) wird eingesetzt um Namen (wie
|
||||
"example.com") in IP-Adressen (wie "194.71.107.50" oder
|
||||
"example.com") in IP-Adressen (wie "203.0.113.23" oder
|
||||
"2001:db8:85a3:8d3:1319:8a2e:370:7347") zu übersetzen. DNS wurde in den
|
||||
1980er Jahren ursprünglich mit dem Ziel entwickelt lokale `hosts` Datei
|
||||
im Internet abzulösen. Inzwischen werden auch andere Informationen als
|
||||
@@ -58,14 +59,14 @@ Einbetten von beliebigen Daten
|
||||
Im folgenden ist der Datenverkehr zur Auflösung des Namens "bla.de" dekodiert dargestellt.
|
||||
Das erste Paket ist die Anfrage des A-Record zu "bla.de". Das zweite Paket die Antwort des DNS Relay.
|
||||
|
||||
Das DNS-Relay antwortet "bla.de A IN 217.160.95.28", diese Angabe soll "5 hours, 39 minutes,
|
||||
Das DNS-Relay antwortet "bla.de A IN 217.160.95.28", diese Angabe soll "5 hours, 39 minutes,
|
||||
47 seconds" gültig sein. `217.160.95.28` wurde direkt binär übertragen als `d9 a0 5f 1c`.
|
||||
|
||||
Nichts hält einen DNS Server davon ab andere Daten als IP-Adressen in der Antwort zu verschicken und
|
||||
nichts kann einen Client davon abhalten beliebige Daten in subdomains (hallowelt.bla.de) zu kodieren.
|
||||
|
||||
Aufgrund der hierarchischen Architektur von DNS kann der Inhaber einer Domains die Auflösung von
|
||||
Subdomains übernehmen. Nach RFC1035 ist die maximale Länge eines auflösbaren Namens 255 Zeichen.
|
||||
Subdomains übernehmen. Nach RFC1035 ist die maximale Länge eines auflösbaren Namens 255 Zeichen.
|
||||
|
||||
[source,c]
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
@@ -131,33 +132,33 @@ Gegenmaßnahmen
|
||||
|
||||
Die von einem idealen DNS Tunnel gestellten Anfragen sind gültig und unterscheiden sich
|
||||
in erster Linie nicht von denen einer gewöhnlichen Anwendung von DNS. Um Tunnel
|
||||
aufzuspüren wären daher statistische Verfahren nötig die Kriterien wie Anzahl,
|
||||
Größe und Inhalt der Pakete betrachten. Aufgrund der Fehleranfälligkeit ist
|
||||
es damit aber auch möglich legitime Anwendungen zu blockieren.
|
||||
aufzuspüren wären daher statistische Verfahren nötig die Kriterien wie Anzahl,
|
||||
Größe und Inhalt der Pakete betrachten. Aufgrund der Fehleranfälligkeit ist
|
||||
es damit aber auch möglich legitime Anwendungen zu blockieren.
|
||||
|
||||
Möchte man lediglich iodine als konkrete Implementierung blockieren ist dies sehr einfach möglich.
|
||||
Der vom iodine Client Verwendete "ping" Aufruf kann sehr einfach erkannt werden, es könnte jeder Client
|
||||
der regelmäßíg eine Subdomain mit dem Anfangsbuchstaben "p" der gleichen Restdomain erfragt geblockt werden.
|
||||
|
||||
In einem durch Proxy Server sowieso schon stark eingeschränkten Netzwerk ist es denkbar, dass auf die Auflösung von
|
||||
Namen ausserhalb der lokalen Domain durch den DNS Server allgemein verzichtet wird.
|
||||
In einem durch Proxy Server sowieso schon stark eingeschränkten Netzwerk ist es denkbar, dass auf die Auflösung von
|
||||
Namen ausserhalb der lokalen Domain durch den DNS Server allgemein verzichtet wird.
|
||||
Sowohl ein HTTP-Proxyserver als auch ein SOCKS Server kann dies für
|
||||
den Client übernehmen.
|
||||
|
||||
In einer Konfiguration für einen Internet Hotspot mit Autorisation der Benutzer (z.B. nach Bezahlvorgang) ist
|
||||
es unbedingt sinnvoll die Autoriserungsregeln auch auf den DNS Server anzuwenden, sodass für den nicht autorisierten
|
||||
Benutzer nur das Loginformular aufrufbar ist. Dies in vielen öffentlichen Hotspots momentan nicht umgesetzt.
|
||||
Für weitere Informationen zum Blockieren von DNS Tunneln siehe <<schillinger11>>.
|
||||
|
||||
Für weitere Informationen zum Blockieren von DNS Tunneln siehe <<schillinger11>>.
|
||||
|
||||
|
||||
Bedienung
|
||||
---------
|
||||
|
||||
Im folgenden wird die Bedienung der Android Oberfläche beschrieben. Die Anwendungen
|
||||
teilt sich für den Benutzer in zwei Bereiche: Die Steuerung der Tunnel und die
|
||||
teilt sich für den Benutzer in zwei Bereiche: Die Steuerung der Tunnel und die
|
||||
Verbindungskonfiguration.
|
||||
|
||||
|
||||
|
||||
Hauptbildschirm
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
@@ -165,10 +166,10 @@ unfloat::[]
|
||||
|
||||
image::bilder/screen_main.png[width="300px",scaledwidth="50%",float="left"]
|
||||
|
||||
Der Hauptbildschirm zeigt die konfigurierten Verbindungsprofile. Eine Verbindung wird
|
||||
Der Hauptbildschirm zeigt die konfigurierten Verbindungsprofile. Eine Verbindung wird
|
||||
mit Auswahl des Eintrags gestartet.
|
||||
|
||||
Mit dem Einstellungsbutton image:../res/drawable/ic_bt_config.png[width="32px"] können
|
||||
Mit dem Einstellungsbutton image:../res/drawable/ic_bt_config.png[width="32px"] können
|
||||
die Verbindungsparameter geändert werden.
|
||||
|
||||
Mit dem Button image:../res/drawable/device_access_new_account.png[width="32px"] in der ActionBar
|
||||
@@ -183,14 +184,14 @@ unfloat::[]
|
||||
|
||||
image::bilder/screen_pref.png[width="300px",scaledwidth="50%",float="left"]
|
||||
|
||||
In der Verbindungskonfiguration werden Parameter festgelegt die beim Starten
|
||||
In der Verbindungskonfiguration werden Parameter festgelegt die beim Starten
|
||||
des Tunnels gesetzt werden. Die Änderungen werden sofort übernommen.
|
||||
|
||||
Zu jeder Einstellung kann mit Drücken des Hilfebuttons die Hilfe aus der Nachfolgenden
|
||||
Zu jeder Einstellung kann mit Drücken des Hilfebuttons die Hilfe aus der Nachfolgenden
|
||||
Tabelle aufgerufen werden.
|
||||
|
||||
Mit mit der Auswahl von image:../res/drawable/delete.png[width="32px"] wird
|
||||
die aktuell geöffnete Konfiguration gelöscht.
|
||||
die aktuell geöffnete Konfiguration gelöscht.
|
||||
|
||||
unfloat::[]
|
||||
|
||||
@@ -199,26 +200,26 @@ unfloat::[]
|
||||
|=====================================
|
||||
|Parameter | Beschreibung
|
||||
|Name | Name für diese Verbindungskonfiguration<
|
||||
|Lazy-Mode | Lazy mode erhöht den Durchsatz und senkt die Reaktionszeit.
|
||||
Eine kleine Minderheit an DNS Relays scheint damit nicht klarzukommen was
|
||||
darin resultiert dass keine oder fast keine Daten übertragen werden.
|
||||
Der Client wird dies aber in der Regel feststellen und den Lazy mode ausschalten.
|
||||
|Lazy-Mode | Lazy mode erhöht den Durchsatz und senkt die Reaktionszeit.
|
||||
Eine kleine Minderheit an DNS Relays scheint damit nicht klarzukommen was
|
||||
darin resultiert dass keine oder fast keine Daten übertragen werden.
|
||||
Der Client wird dies aber in der Regel feststellen und den Lazy mode ausschalten.
|
||||
Falls nicht, kann lazy-mode mit dieser Option ausgeschaltet werden.
|
||||
|Tunnel Nameserver | Der Nameserver/DNS Relay, der verwendet wird um mit iodined zu kommunizieren.
|
||||
Dieses Feld ist optional und wenn es nicht gesetzt ist wird der im System hinterlegte
|
||||
|Tunnel Nameserver | Der Nameserver/DNS Relay, der verwendet wird um mit iodined zu kommunizieren.
|
||||
Dieses Feld ist optional und wenn es nicht gesetzt ist wird der im System hinterlegte
|
||||
DNS Server verwendet
|
||||
|Nameserver-Mode | Legt fest wie der Nameserver gesetzt werden soll nachdem der Tunnel aufgebaut wurde
|
||||
|Nameserver | IP-Adresse eine speziellen Nameserver der gesetzt werden soll
|
||||
|Nameserver | IP-Adresse eine speziellen Nameserver der gesetzt werden soll
|
||||
wenn Nameserver Modus = Custom ist.
|
||||
|Password | Dieses Feld ist optional. Es werden nur die ersten 32 Zeichen verwendet.
|
||||
pwasswo cont
|
||||
|Raw-Mode | Falls gesetzt wird iodine versuchen die öffentliche IP-Adresse des iodined Server
|
||||
aufzulösen und testen ob er direkt erreichbar ist. Falls ja, wird er den Traffic
|
||||
aufzulösen und testen ob er direkt erreichbar ist. Falls ja, wird er den Traffic
|
||||
direkt an den Server senden anstatt an ein DNS relay
|
||||
|Request-Type | Typ der DNS Abfragen. Standardmäßig wird die beste Request type automatisch ausgewählt.
|
||||
|Top-Domain | Der DNS Traffic wird als Anfragen für subdomains unterhalb dieser Topdomain gesendert.
|
||||
Dies ist gewöhnlich eine Domain die Dir gehört. Verwende eine kurze
|
||||
Domain um mehr Durchsatz zu erzielen.
|
||||
|Top-Domain | Der DNS Traffic wird als Anfragen für subdomains unterhalb dieser Topdomain gesendert.
|
||||
Dies ist gewöhnlich eine Domain die Dir gehört. Verwende eine kurze
|
||||
Domain um mehr Durchsatz zu erzielen.
|
||||
Diese Einstellung muss am Server und am Client gleich sein
|
||||
|Default Route | Legt fest ob die Default Route gesetzt wird nachdem die Verbindung aufgebaut wurde
|
||||
|====================================
|
||||
@@ -230,9 +231,9 @@ Vorraussetzung für den Betrieb eines Iodine Server ist eine öffentlich erreich
|
||||
ein freier Port 53/dns.
|
||||
|
||||
Es muss ein NS-Record für diese IP-Adresse eingerichtet werden. Angenommen die Tunnel Toplevel Domain
|
||||
soll "t.example.com" sein und der Server hat die IP-Adresse 192.0.43.10, dann lautet der Eintrag:
|
||||
soll "t.example.com" sein und der Server hat die IP-Adresse 203.0.113.42, dann lautet der Eintrag:
|
||||
|
||||
t.example.com. 8192 IN NS 192.0.43.10
|
||||
y.example.com. 8192 IN NS 203.0.113.42
|
||||
|
||||
Die Konfiguration der IP-Adressen erfolgt nicht über DHCP oder statisch, sondern diese werden den Clients
|
||||
vom iodine Server, aus einem IP Subnetz das beim Start festgelegt wird, zugewiesen.
|
||||
@@ -240,11 +241,11 @@ vom iodine Server, aus einem IP Subnetz das beim Start festgelegt wird, zugewies
|
||||
iodined -c -P PASSWORD 192.168.0.1/24 t.example.com
|
||||
|
||||
Die Option `-c` ist nicht immer erforderlich. Sie bewirkt, dass iodine die Quelladressen der Anfragen
|
||||
nicht überprüft. Die Überprüfung ist nicht möglich wenn die DNS Anfragen über ein Cluster verarbeitet werden,
|
||||
sodass die beim Server einkommenden Pakete von verschiedenen Quelladressen stammen.
|
||||
nicht überprüft. Die Überprüfung ist nicht möglich wenn die DNS Anfragen über ein Cluster verarbeitet werden,
|
||||
sodass die beim Server einkommenden Pakete von verschiedenen Quelladressen stammen.
|
||||
|
||||
Der Server legt ein TUN-Device an (typischerweise "dns0"), je nach Zweck ist noch das
|
||||
IP Routing/Masquerade zu konfigurieren.
|
||||
IP Routing/Masquerade zu konfigurieren.
|
||||
|
||||
Testen
|
||||
~~~~~~
|
||||
@@ -261,9 +262,9 @@ $ dig -t A zabc.t.example.com
|
||||
;; ANSWER SECTION:
|
||||
zabc.t.example.com. 0 IN CNAME hpjqweyzo.dh.
|
||||
|
||||
$ ./base32 d pjqweyz
|
||||
$ ./base32 d pjqweyz
|
||||
Decoded 4 bytes:
|
||||
0x7a (z) 0x61 (a) 0x62 (b) 0x63 (c)
|
||||
0x7a (z) 0x61 (a) 0x62 (b) 0x63 (c)
|
||||
--------------------------------------------------------------------------------------------------------
|
||||
|
||||
Unter http://code.kryo.se/iodine/check-it/ wird ein Online Service zum Testen der Konfiguration angeboten.
|
||||
@@ -273,7 +274,7 @@ Anhang
|
||||
------
|
||||
|
||||
[bibliography]
|
||||
- [[[schillinger11]]]
|
||||
http://www.data.ks.uni-freiburg.de/download/praxisseminarSS11/dns-tunnel/Fabian%20Schillinger%20-%20DNS-Tunnel.pdf[Fabian Schillinger, DNS-Tunnel, Universität Freiburg 2011]
|
||||
- [[[schillinger11]]]
|
||||
http://www.data.ks.uni-freiburg.de/download/praxisseminarSS11/dns-tunnel/Fabian%20Schillinger%20-%20DNS-Tunnel.pdf[Fabian Schillinger, DNS-Tunnel, Universität Freiburg 2011]
|
||||
- [[[iodine]]] http://code.kryo.se/iodine/
|
||||
|
||||
+45
-45
@@ -10,7 +10,7 @@ April 2013
|
||||
[abstract]
|
||||
--
|
||||
Die Dokumentation ist zweigeteilt. Dieser Teil enthält eine technische Beschreibung.
|
||||
Die Bedienung und Funktionsweise ist in der 'Anwenderdokumentation' beschrieben.
|
||||
Die Bedienung und Funktionsweise ist in der 'Anwenderdokumentation' beschrieben.
|
||||
--
|
||||
|
||||
Aufbau
|
||||
@@ -48,7 +48,7 @@ Konfiguration
|
||||
~~~~~~~~~~~~~
|
||||
Die Tunnelkonfigurationen werden in einer SQLite Datenbank abgelegt. Es
|
||||
existiert mit `.config.IodineConfiguration` ein leichtgewichtiger Proxy
|
||||
um die Android `ContentValues` Klasse. Die `.config.ConfigDatabase` Klasse
|
||||
um die Android `ContentValues` Klasse. Die `.config.ConfigDatabase` Klasse
|
||||
ist ein `SQLiteOpenHelper` und kann mehrfach instanziert werden.
|
||||
|
||||
VPN-Service
|
||||
@@ -58,11 +58,11 @@ Der VPN Service hat 5 Zustände die er über Broadcast Intents mitteilt.
|
||||
Eine solche Mitteilung wird verschickt wenn sich der Zustand ändert oder
|
||||
dies über ACTION_CONTROL_UPDATE angefordert wurde.
|
||||
|
||||
Die Kommunikation der Oberfläche mit dem VPN Service erfolgt mit Broadcasts Intents.
|
||||
Die Kommunikation der Oberfläche mit dem VPN Service erfolgt mit Broadcasts Intents.
|
||||
|
||||
<<whiteboard-intents>> zeigt die Zustände des Iodine VPN-Service. Rot nummeriert sind die
|
||||
Intents die der Service verschickt um über Statusänderungen zu informieren. Blau nummeriert
|
||||
sind Intents mit denen der Service gesteuert werden kann.
|
||||
sind Intents mit denen der Service gesteuert werden kann.
|
||||
|
||||
[[whiteboard-intents]]
|
||||
.Status Informations und Steuerungs Intents des VPN Service
|
||||
@@ -72,10 +72,10 @@ JNI
|
||||
~~~
|
||||
|
||||
Die JNI Methoden für iodine befinden sich in der Klasse `.IodineClient`
|
||||
bzw. `/jni/iodine-client.c`. `IodineClient#connect` ersetzt dabei prinzipiell
|
||||
bzw. `/jni/iodine-client.c`. `IodineClient#connect` ersetzt dabei prinzipiell
|
||||
die `main()` des ursprünglichen iodine Client.
|
||||
|
||||
Weitere Methoden dienen dem Austausch der vom Server übermittelten Konfiguration
|
||||
Weitere Methoden dienen dem Austausch der vom Server übermittelten Konfiguration
|
||||
und des im System eingestellten DNS Server.
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ Nachdem vom Server die IP-Konfiguration mitgeteilt wurde, wird diese im
|
||||
int tun_fd = parcelFD.detachFd();
|
||||
|
||||
// pass the filedescriptor to iodine
|
||||
IodineClient.tunnel(tun_fd);
|
||||
IodineClient.tunnel(tun_fd);
|
||||
--------------------------------------------------------
|
||||
|
||||
iodine
|
||||
@@ -162,7 +162,7 @@ Der folgende Text zeigt ein Beispiel für den Ablauf eines Handshake. Der genaue
|
||||
variieren jenachdem wie die Verbindungsparameter gewählt werden.
|
||||
|
||||
Hier sind gewählt -m 768 fragment size und ein 9 Zeichen
|
||||
Passwort. Die Gegenstelle ist `t.yves.tw`. Eine Raw (direkte UDP) Verbindung
|
||||
Passwort. Die Gegenstelle ist `t.yves.tw`. Eine Raw (direkte UDP) Verbindung
|
||||
wurde verhindert indem der Rechner zum Testzeitpunkt keine default Route hatte.
|
||||
|
||||
RX/TX aus der Sicht des Servers. Die "*" in den Hostnamen markieren Zeichen die
|
||||
@@ -171,18 +171,18 @@ sich aus Random Daten ergeben.
|
||||
[source,java]
|
||||
---------------------------------------------------------------------
|
||||
== Der Client testet die Qualitaet der Uebertragung
|
||||
<-- client.c:handshake_qtype_autodetect()
|
||||
-> handshake_qtypetest()
|
||||
<-- client.c:handshake_qtype_autodetect()
|
||||
-> handshake_qtypetest()
|
||||
-> send_downenctest()
|
||||
hostname[0] = "y"
|
||||
hostanme[1] = downenc = 'r'
|
||||
hostname[2] = variant = 1 = 'b' (b32)
|
||||
hostname[3..5] = rand_seed++
|
||||
RX: yrb***.t.yves.tw
|
||||
|
||||
|
||||
--> 48 bytes aus encoding.h:DOWNCODECHECK
|
||||
TX: yrb***.t.yves.tw, 48 bytes data
|
||||
|
||||
|
||||
== Austausch der Versionsinformationen
|
||||
<-- client.c:send_version()
|
||||
VERSION=0x00 00 05 02
|
||||
@@ -190,7 +190,7 @@ sich aus Random Daten ergeben.
|
||||
hostname[1..6] = b32(0,0,5,2,random<<8,random)
|
||||
hostname = "vAAAAKAR__"
|
||||
RX: vaaaaka****.t.yves.tw
|
||||
|
||||
|
||||
--> iodined.c:send_version_response()
|
||||
der Server bestaetigt mit
|
||||
data[0..8] = "VACK" b32(seed>>24, seed>>16, seed>>8, seed, userid)
|
||||
@@ -206,7 +206,7 @@ sich aus Random Daten ergeben.
|
||||
|
||||
--> iodined.c:handle_null_request()
|
||||
Sendet bei Erfolg die IP Einstellungen wie
|
||||
"172.16.0.1-172.16.0.2-1130-16"
|
||||
"172.16.0.1-172.16.0.2-1130-16"
|
||||
server="172.16.0.1"
|
||||
client="172.16.0.2"
|
||||
mtu=1130
|
||||
@@ -214,11 +214,11 @@ sich aus Random Daten ergeben.
|
||||
TX: lad24srn4ezmg21qjsfy13msagd0srfq.t.yves.tw
|
||||
= 3137322e31362e302e312d3137322e31362e302e322d313133302d3136 (_16)
|
||||
= 172.16.0.1-172.16.0.2-1130-16
|
||||
|
||||
|
||||
== Senden der IP Adresse des Clients
|
||||
<-- Request for IP address
|
||||
RX: iamin.t.yves.tw
|
||||
|
||||
|
||||
--> iodined.c:handle_null_request()
|
||||
addr = externe IP Adresse des Server (-n Switch)
|
||||
reply[0] = 'I';
|
||||
@@ -228,28 +228,28 @@ sich aus Random Daten ergeben.
|
||||
reply[4] = (addr >> 0) & 0xFF;
|
||||
TX: iamin.t.yves.tw
|
||||
= 494e2f737d (_16)
|
||||
|
||||
|
||||
== Testen auf EDNS Erweiterung
|
||||
<-- client.c:handshake_edns0_check()
|
||||
-> send_downenctest()
|
||||
downenc = 'r' fuer T_NULL 't'
|
||||
downenc = 'r' fuer T_NULL 't'
|
||||
variant = 1 = 'b' (b32)
|
||||
data[0..5] = "y" downenc variant rand_seed[0..2]
|
||||
RX: yrb***.t.yves.tw
|
||||
|
||||
--> iodined.c:handle_null_login() : 937
|
||||
-> write_dns( type='R')
|
||||
|
||||
--> iodined.c:handle_null_login() : 937
|
||||
-> write_dns( type='R')
|
||||
Der Server antwortet mit 48 bytes aus encoding.h:DOWNCODECHECK
|
||||
TX: yrb***.t.yves.tw, 48 bytes data
|
||||
|
||||
|
||||
|
||||
|
||||
== Testen der Kodierungen mit verschiedenen Patterns
|
||||
<-- client.c:handshake_upenc_autodetect()
|
||||
In den folgenden Tests testet der Client ob mit Base128
|
||||
kodierte Nachrichten vom DNS Relay korrekt verarbeitet werden.
|
||||
|
||||
|
||||
--> Der Server schickt die Patterns einfach wieder zurueck.
|
||||
|
||||
|
||||
== Client legt Kodierung fest, Server bestaetigt
|
||||
<-- client.c:handshake_switch_codec()
|
||||
hostname[0] = command 's'
|
||||
@@ -258,25 +258,25 @@ sich aus Random Daten ergeben.
|
||||
hostname[3..5] = rand_seed++
|
||||
rand_seed++;
|
||||
RX: sahmiut.yves.tw
|
||||
|
||||
|
||||
--> iodined.c:840
|
||||
Schreibt den Namen des ausgewaehlten Codecs:
|
||||
data="Base128" (kein encoding!)
|
||||
TX: sahmiut.yves.tw, 7 bytes of data
|
||||
|
||||
== Anschalten lazy mode (an: Server beantwortet Anfragen nicht sofort)
|
||||
TX: sahmiut.yves.tw, 7 bytes of data
|
||||
|
||||
== Anschalten lazy mode (an: Server beantwortet Anfragen nicht sofort)
|
||||
<-- client.c:send_lazy_switch()
|
||||
hostname[0] = 'o'
|
||||
hostname[1] = b32(userid) = 'a'
|
||||
hostname[2] = 'l' fuer lazy mode oder 'i'
|
||||
hostname[3..5] = rand_seed++
|
||||
RX: oalmiv.t.yves.tw
|
||||
|
||||
|
||||
--> iodined.c:919
|
||||
data="Lazy" (kein encoding!)
|
||||
TX: oalmiv.t.yves.tw, 4 bytes of data
|
||||
|
||||
==
|
||||
|
||||
==
|
||||
<-- client.c:send_set_downstream_fragsize()
|
||||
data[0] = userid;
|
||||
data[1] = (fragsize & 0xff00) >> 8;
|
||||
@@ -288,16 +288,16 @@ sich aus Random Daten ergeben.
|
||||
|
||||
--> iodined.c:1042
|
||||
bestaetigt empfangene Framesize durch Wiederholung
|
||||
|
||||
== Regelmaesige pings fragen den Server nach anstehenden Daten ab
|
||||
|
||||
== Regelmaesige pings fragen den Server nach anstehenden Daten ab
|
||||
<-- client.c:send_ping()
|
||||
data[0] = userid;
|
||||
data[1] = ((inpkt.seqno & 7) << 4) | (inpkt.fragment & 15);
|
||||
data[2] = (rand_seed >> 8) & 0xff;
|
||||
data[3] = (rand_seed >> 0) & 0xff;
|
||||
hostname = 'p' + b32(data)
|
||||
hostname = 'p' + b32(data)
|
||||
RX: paaalcfy.t.yves.tw
|
||||
|
||||
|
||||
--> iodined.c:1067
|
||||
Der Server nutzt die regelmaessigen Pings um Daten an den Client zu liefern.
|
||||
---------------------------------------------------------------------
|
||||
@@ -305,16 +305,16 @@ sich aus Random Daten ergeben.
|
||||
Der lazy Modus
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
Wie in der Anwenderdokumentation beschrieben erhöht der Lazy Modus den Durchsatz
|
||||
Wie in der Anwenderdokumentation beschrieben erhöht der Lazy Modus den Durchsatz
|
||||
und senkt die Latenzzeit, wird aber nicht von allen DNS-Relays unterstützt.
|
||||
|
||||
Lazy bezieht sich auf das Verhalten des Servers. Der Server wird im Lazy-mode
|
||||
alle Antworten auf Anfragen solange zurückhalten bis er neue Daten für den
|
||||
Client erhalten hat. Im Idealfall also bis das Antwortpaket der getunnelten
|
||||
IP Verbindung angekommen ist.
|
||||
IP Verbindung angekommen ist.
|
||||
|
||||
Diese Verzögerung kann mit manchen DNS-Relays Probleme machen. Der Server kann dies jedoch
|
||||
anhand der Duplikate in den Anfragen erkennen und damit den lazy-mode ausschalten.
|
||||
anhand der Duplikate in den Anfragen erkennen und damit den lazy-mode ausschalten.
|
||||
|
||||
Ohne diesen Mechanismus müsste der Client jedoch viel häufiger nach neuen Daten
|
||||
pollen (vgl. HTTP Long polling in Comet oder BOSH).
|
||||
@@ -343,15 +343,15 @@ int main(int argc, char *argv[]) {
|
||||
if (*argv[1] == 'd') {
|
||||
int r = b32->decode(buf, &len, argv[2], strlen(argv[2]));
|
||||
int i;
|
||||
printf("Decoded %d bytes:\n", r);
|
||||
printf("Decoded %d bytes:\n", r);
|
||||
for (i = 0; i< r; i++) {
|
||||
printf("0x%02hhx (%c) ", buf[i], (buf[i] >= '0' && buf[i] <= 'z') ? buf[i] : ' ');
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
} else if (*argv[1] == 'e') {
|
||||
int r = b32->encode(buf, &len, argv[2], strlen(argv[2]));
|
||||
printf("Encoded %d bytes in %ld output bytes: >%s<\n", len, r, buf);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
----------------------------------------------------------------------------------------------------
|
||||
@@ -375,7 +375,7 @@ sondern 'Bionic libc'. Dies ist eine besonders kleine, auf die BSD libc zurückg
|
||||
standard C Library. Es fehlen einige Features der glibc wie wide-character support,
|
||||
volle POSIX Thread Unterstützung oder locale Unterstützung. Das Ziel von Bionic ist
|
||||
nicht eine vollständige C Standardbibliothek sondern lediglich eine schlanke Implementierung
|
||||
aller für ein Android nötigen Funktionen.
|
||||
aller für ein Android nötigen Funktionen.
|
||||
|
||||
Im einfachsten Fall scheitert die Ausführung von iodine unter Android an einem `system()` Aufruf
|
||||
mit dem iodine die IP-Konfiguration anwendet.
|
||||
@@ -393,7 +393,7 @@ C-Quellen angestossen werden.
|
||||
org.xapek.andiodine % ~/$NDK_ROOT/ndk-build clean
|
||||
Clean: iodine-client [armeabi]
|
||||
Clean: stdc++ [armeabi]
|
||||
org.xapek.andiodine % ~/$NDK_ROOT/ndk-build
|
||||
org.xapek.andiodine % ~/$NDK_ROOT/ndk-build
|
||||
Compile thumb : iodine-client <= iodine-client.c
|
||||
Compile thumb : iodine-client <= tun.c
|
||||
Compile thumb : iodine-client <= dns.c
|
||||
@@ -530,7 +530,7 @@ Anhang
|
||||
------
|
||||
|
||||
[bibliography]
|
||||
- [[[vpnapi]]]
|
||||
- [[[vpnapi]]]
|
||||
http://developer.android.com/reference/android/net/VpnService.html Dokumentation
|
||||
zu den Android VPN Service API
|
||||
|
||||
+10
-11
@@ -16,6 +16,16 @@ LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
$(LOCAL_PATH)/iodine/src/base64u.c: $(LOCAL_PATH)/iodine/src/base64.c $(LOCAL_PATH)/iodine/src/base64u.h
|
||||
@echo Making $@
|
||||
@echo '/* No use in editing, produced by Makefile! */' > $@
|
||||
@sed -e 's/\([Bb][Aa][Ss][Ee]64\)/\1u/g ; s/0123456789+/0123456789_/' < $< >> $@
|
||||
|
||||
$(LOCAL_PATH)/iodine/src/base64u.h: $(LOCAL_PATH)/iodine/src/base64.h
|
||||
@echo Making $@
|
||||
@echo '/* No use in editing, produced by Makefile! */' > $@
|
||||
@sed -e 's/\([Bb][Aa][Ss][Ee]64\)/\1u/g ; s/0123456789+/0123456789_/' < $< >> $@
|
||||
|
||||
LOCAL_MODULE := iodine-client
|
||||
LOCAL_LDLIBS := -lz -llog
|
||||
LOCAL_CFLAGS := -Wall
|
||||
@@ -34,15 +44,4 @@ LOCAL_SRC_FILES := iodine-client.c \
|
||||
iodine/src/client.c \
|
||||
iodine/src/util.c
|
||||
|
||||
$(LOCAL_PATH)/iodine/src/base64u.c: $(LOCAL_PATH)/iodine/src/base64.c $(LOCAL_PATH)/iodine/src/base64u.h
|
||||
@echo Making $@
|
||||
@echo '/* No use in editing, produced by Makefile! */' > $@
|
||||
@sed -e 's/\([Bb][Aa][Ss][Ee]64\)/\1u/g ; s/0123456789+/0123456789_/' < $< >> $@
|
||||
|
||||
$(LOCAL_PATH)/iodine/src/base64u.h: $(LOCAL_PATH)/iodine/src/base64.h
|
||||
@echo Making $@
|
||||
@echo '/* No use in editing, produced by Makefile! */' > $@
|
||||
@sed -e 's/\([Bb][Aa][Ss][Ee]64\)/\1u/g ; s/0123456789+/0123456789_/' < $< >> $@
|
||||
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
+9
-3
@@ -3,6 +3,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
@@ -89,13 +90,18 @@ JNIEXPORT jint JNICALL Java_org_xapek_andiodine_IodineClient_connect(
|
||||
// XXX strdup leaks
|
||||
const char *__p_nameserv_addr = (*env)->GetStringUTFChars(env,
|
||||
j_nameserv_addr, NULL);
|
||||
const char *p_nameserv_addr = strdup(__p_nameserv_addr);
|
||||
char *p_nameserv_addr = strdup(__p_nameserv_addr);
|
||||
struct sockaddr_storage p_nameserv;
|
||||
int p_nameserv_len = get_addr(p_nameserv_addr, 53, AF_INET, 0, &p_nameserv);
|
||||
(*env)->ReleaseStringUTFChars(env, j_nameserv_addr, __p_nameserv_addr);
|
||||
|
||||
const char *__p_topdomain = (*env)->GetStringUTFChars(env, j_topdomain,
|
||||
NULL);
|
||||
const char *p_topdomain = strdup(__p_topdomain);
|
||||
__android_log_print(ANDROID_LOG_ERROR, "iodine", "Topdomain from vm: %s", p_topdomain);
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, j_topdomain, __p_topdomain);
|
||||
__android_log_print(ANDROID_LOG_ERROR, "iodine", "Topdomain from vm: %s", p_topdomain);
|
||||
|
||||
const char *p_password = (*env)->GetStringUTFChars(env, j_password, NULL);
|
||||
char passwordField[33];
|
||||
@@ -126,14 +132,14 @@ JNIEXPORT jint JNICALL Java_org_xapek_andiodine_IodineClient_connect(
|
||||
|
||||
srand((unsigned) time(NULL));
|
||||
client_init();
|
||||
client_set_nameserver(p_nameserv_addr, DNS_PORT);
|
||||
client_set_nameserver(&p_nameserv, p_nameserv_len);
|
||||
client_set_selecttimeout(selecttimeout);
|
||||
client_set_lazymode(lazy_mode);
|
||||
client_set_topdomain(p_topdomain);
|
||||
client_set_hostname_maxlen(hostname_maxlen);
|
||||
client_set_password(passwordField);
|
||||
|
||||
if ((dns_fd = open_dns(0, INADDR_ANY)) == -1) {
|
||||
if ((dns_fd = open_dns_from_host(NULL, 0, AF_INET, AI_PASSIVE)) == -1) {
|
||||
printf("Could not open dns socket: %s", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
+25
-1
@@ -5,7 +5,30 @@ iodine - http://code.kryo.se/iodine
|
||||
|
||||
CHANGES:
|
||||
|
||||
2010-02-13: 0.6.0-rc1 "Hotspotify"
|
||||
2014-06-16: 0.7.0 "Kryoptonite"
|
||||
- Partial IPv6 support (#107)
|
||||
Client can connect to iodined through an relaying IPv6
|
||||
nameserver. Server only supports IPv4 for now.
|
||||
Traffic inside tunnel is IPv4.
|
||||
- Add socket activation for systemd, by Michael Scherer.
|
||||
- Add automated lookup of external ip (via -n auto).
|
||||
- Bugfix for OS X (Can't assign requested address)
|
||||
- Fix DNS tunneling bug caused by uninitialized variable, #94
|
||||
- Handle spaces when entering password interactively, fixes #93.
|
||||
Patch by Hagar.
|
||||
- Add -R option to set OpenBSD routing domain for the DNS socket.
|
||||
Patch by laurent at gouloum fr, fixes #95.
|
||||
- Add android patches and makefile, from Marcel Bokhorst, fixes #105.
|
||||
- Added missing break in iodine.c, by Pavel Pergamenshchik, #108.
|
||||
- A number of minor patches from Frank Denis, Gregor Herrmann and
|
||||
Barak A. Pearlmutter.
|
||||
- Testcase compilation fixes for OS X and FreeBSD
|
||||
- Do not let sockets be inherited by sub-processes, fixes #99.
|
||||
- Add unspecified RR type (called PRIVATE; id 65399, in private use
|
||||
range). For servers with RFC3597 support. Fixes #97.
|
||||
- Fix authentication bypass vulnerability; found by Oscar Reparaz.
|
||||
|
||||
2010-02-06: 0.6.0-rc1 "Hotspotify"
|
||||
- Fixed tunnel not working on Windows.
|
||||
- Any device name is now supported on Windows, fixes #47.
|
||||
- Multiple installed TAP32 interfaces are now supported, fixes #46.
|
||||
@@ -30,6 +53,7 @@ CHANGES:
|
||||
- Merged low-latency patch from Anne Bezemer, fixes #76.
|
||||
- Resolve client nameserver argument if given as hostname, fixes #82.
|
||||
- Open log before chroot, fixes #86: logging on FreeBSD.
|
||||
- Merged big bugfix patch from Anne Bezemer, #88.
|
||||
|
||||
2009-06-01: 0.5.2 "WifiFree"
|
||||
- Fixed client segfault on OS X, #57
|
||||
|
||||
+61
-19
@@ -1,4 +1,4 @@
|
||||
prefix=/usr/local
|
||||
prefix?=/usr/local
|
||||
sbindir=$(prefix)/sbin
|
||||
datadir=$(prefix)/share
|
||||
mandir=$(datadir)/man
|
||||
@@ -16,24 +16,9 @@ RM_FLAGS=-f
|
||||
|
||||
TARGETOS = `uname`
|
||||
|
||||
all:
|
||||
all:
|
||||
@(cd src; $(MAKE) TARGETOS=$(TARGETOS) all)
|
||||
|
||||
cross-mingw:
|
||||
@(cd src; $(MAKE) TARGETOS=windows32 CC=i686-mingw32-gcc all)
|
||||
|
||||
cross-mingw-dist: cross-mingw
|
||||
@rm -rf iodine-latest-win32*
|
||||
@mkdir -p iodine-latest-win32/bin
|
||||
@for i in `ls bin`; do cp bin/$$i iodine-latest-win32/bin/$$i.exe; done
|
||||
@cp /usr/i686-mingw32/usr/bin/zlib1.dll iodine-latest-win32/bin
|
||||
@cp README* CH* TO* iodine-latest-win32
|
||||
@echo "Create date: " > iodine-latest-win32/VERSION
|
||||
@date >> iodine-latest-win32/VERSION
|
||||
@echo "SVN version: " >> iodine-latest-win32/VERSION
|
||||
@svnversion >> iodine-latest-win32/VERSION
|
||||
@zip -r iodine-latest-win32.zip iodine-latest-win32
|
||||
|
||||
install: all
|
||||
$(MKDIR) $(MKDIR_FLAGS) $(DESTDIR)$(sbindir)
|
||||
$(INSTALL) $(INSTALL_FLAGS) bin/iodine $(DESTDIR)$(sbindir)/iodine
|
||||
@@ -48,7 +33,7 @@ uninstall:
|
||||
$(RM) $(RM_FLAGS) $(DESTDIR)$(sbindir)/iodine
|
||||
$(RM) $(RM_FLAGS) $(DESTDIR)$(sbindir)/iodined
|
||||
$(RM) $(RM_FLAGS) $(DESTDIR)$(mandir)/man8/iodine.8
|
||||
|
||||
|
||||
test: all
|
||||
@echo "!! The check library is required for compiling and running the tests"
|
||||
@echo "!! Get it at http://check.sf.net"
|
||||
@@ -58,5 +43,62 @@ clean:
|
||||
@echo "Cleaning..."
|
||||
@(cd src; $(MAKE) clean)
|
||||
@(cd tests; $(MAKE) clean)
|
||||
@rm -rf bin iodine-latest-win32*
|
||||
@rm -rf bin iodine-latest*
|
||||
|
||||
#Helper target for windows/android zipfiles
|
||||
iodine-latest:
|
||||
@rm -rf iodine-latest*
|
||||
@mkdir -p iodine-latest
|
||||
@echo "Create date: " > iodine-latest/VERSION.txt
|
||||
@date >> iodine-latest/VERSION.txt
|
||||
@echo "Git version: " >> iodine-latest/VERSION.txt
|
||||
@git rev-parse HEAD >> iodine-latest/VERSION.txt
|
||||
@for i in README CHANGELOG TODO; do cp $$i iodine-latest/$$i.txt; done
|
||||
@unix2dos iodine-latest/*
|
||||
|
||||
cross-android:
|
||||
@(cd src; $(MAKE) base64u.c base64u.h)
|
||||
@(cd src; ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk)
|
||||
|
||||
iodine-latest-android.zip: iodine-latest
|
||||
@mv iodine-latest iodine-latest-android
|
||||
@mkdir -p iodine-latest-android/armeabi iodine-latest-android/x86
|
||||
@$(MAKE) cross-android TARGET_ARCH_ABI=armeabi
|
||||
@cp src/libs/armeabi/* iodine-latest-android/armeabi
|
||||
@$(MAKE) cross-android TARGET_ARCH_ABI=x86
|
||||
@cp src/libs/x86/* iodine-latest-android/x86
|
||||
@cp README-android.txt iodine-latest-android
|
||||
@zip -r iodine-latest-android.zip iodine-latest-android
|
||||
|
||||
cross-mingw32:
|
||||
@(cd src; $(MAKE) TARGETOS=windows32 CC=i686-w64-mingw32-gcc all)
|
||||
|
||||
cross-mingw64:
|
||||
@(cd src; $(MAKE) TARGETOS=windows32 CC=x86_64-w64-mingw32-gcc all)
|
||||
|
||||
iodine-latest-windows.zip: iodine-latest
|
||||
@mv iodine-latest iodine-latest-windows
|
||||
@mkdir -p iodine-latest-windows/64bit iodine-latest-windows/32bit
|
||||
@(cd src; $(MAKE) TARGETOS=windows32 CC=i686-w64-mingw32-gcc clean all)
|
||||
@i686-w64-mingw32-strip bin/iodine*
|
||||
@for i in `ls bin`; do cp bin/$$i iodine-latest-windows/32bit/$$i.exe; done
|
||||
@cp /usr/i686-w64-mingw32/bin/zlib1.dll iodine-latest-windows/32bit
|
||||
@(cd src; $(MAKE) TARGETOS=windows32 CC=x86_64-w64-mingw32-gcc clean all)
|
||||
@x86_64-w64-mingw32-strip bin/iodine*
|
||||
@for i in `ls bin`; do cp bin/$$i iodine-latest-windows/64bit/$$i.exe; done
|
||||
@cp /usr/x86_64-w64-mingw32/bin/zlib1.dll iodine-latest-windows/64bit
|
||||
@cp README-win32.txt iodine-latest-windows
|
||||
@zip -r iodine-latest-windows.zip iodine-latest-windows
|
||||
|
||||
cross-mingw:
|
||||
@(cd src; $(MAKE) TARGETOS=windows32 CC=i686-mingw32-gcc all)
|
||||
|
||||
iodine-latest-win32.zip: cross-mingw iodine-latest
|
||||
@mv iodine-latest iodine-latest-win32
|
||||
@mkdir -p iodine-latest-win32/bin
|
||||
@i686-mingw32-strip bin/iodine*
|
||||
@for i in `ls bin`; do cp bin/$$i iodine-latest-win32/bin/$$i.exe; done
|
||||
@cp /usr/i686-mingw32/usr/bin/zlib1.dll iodine-latest-win32/bin
|
||||
@cp README-win32.txt iodine-latest-win32
|
||||
@zip -r iodine-latest-win32.zip iodine-latest-win32
|
||||
|
||||
+36
-14
@@ -8,6 +8,17 @@ server. This can be usable in different situations where internet access is
|
||||
firewalled, but DNS queries are allowed.
|
||||
|
||||
|
||||
COMPILING:
|
||||
|
||||
Iodine has no configure script. There are two optional features for Linux
|
||||
(SELinux and systemd support) that will be enabled automatically if the
|
||||
relevant header files are found in /usr/include. (See script at ./src/osflags)
|
||||
|
||||
Run 'make' to compile the server and client binaries.
|
||||
Run 'make install' to copy binaries and manpage to the destination directory.
|
||||
Run 'make test' to compile and run the unit tests. (Requires the check library)
|
||||
|
||||
|
||||
QUICKSTART:
|
||||
|
||||
Try it out within your own LAN! Follow these simple steps:
|
||||
@@ -103,6 +114,16 @@ end of the tunnel. In this case, ping 192.168.99.1 from the iodine client, and
|
||||
|
||||
MISC. INFO:
|
||||
|
||||
IPv6:
|
||||
At the moment the iodined server only supports IPv4. The data inside the tunnel
|
||||
is IPv4 only.
|
||||
|
||||
The client can use IPv4 or IPv6 nameservers to connect to iodined. The relay
|
||||
nameservers will translate between protocols automatically if needed. Use
|
||||
options -4 or -6 to force the client to use a specific IP version for its DNS
|
||||
queries. The client has to force IPv4 if it has dual-stack connectivity and
|
||||
the hostname handling the tunnel domain has both A and AAAA records.
|
||||
|
||||
Routing:
|
||||
It is possible to route all traffic through the DNS tunnel. To do this, first
|
||||
add a host route to the nameserver used by iodine over the wired/wireless
|
||||
@@ -156,12 +177,13 @@ packet, and one query can be max 256 chars. Each domain name part can be max
|
||||
63 chars. So your domain name and subdomain should be as short as possible to
|
||||
allow maximum upstream throughput.
|
||||
|
||||
Several DNS request types are supported, with the NULL type expected to provide
|
||||
the largest downstream bandwidth. Other available types are TXT, SRV, MX,
|
||||
CNAME and A (returning CNAME), in decreasing bandwidth order. Normally the
|
||||
Several DNS request types are supported, with the NULL and PRIVATE types
|
||||
expected to provide the largest downstream bandwidth. The PRIVATE type uses
|
||||
value 65399 in the private-use range. Other available types are TXT, SRV, MX,
|
||||
CNAME and A (returning CNAME), in decreasing bandwidth order. Normally the
|
||||
"best" request type is autodetected and used. However, DNS relays may impose
|
||||
limits on for example NULL and TXT, making SRV or MX actually the best choice.
|
||||
This is not autodetected, but can be forced using the -T option. It is
|
||||
This is not autodetected, but can be forced using the -T option. It is
|
||||
advisable to try various alternatives especially when the autodetected request
|
||||
type provides a downstream fragment size of less than 200 bytes.
|
||||
|
||||
@@ -169,14 +191,14 @@ Note that SRV, MX and A (returning CNAME) queries may/will cause additional
|
||||
lookups by "smart" caching nameservers to get an actual IP address, which may
|
||||
either slow down or fail completely.
|
||||
|
||||
DNS responses for non-NULL queries can be encoded with the same set of codecs
|
||||
as upstream data. This is normally also autodetected, but no fully exhaustive
|
||||
tests are done, so some problems may not be noticed when selecting more
|
||||
advanced codecs. In that case, you'll see failures/corruption in the fragment
|
||||
size autoprobe. In particular, several DNS relays have been found that change
|
||||
replies returning hostnames (SRV, MX, CNAME, A) to lowercase only when that
|
||||
hostname exceeds ca. 180 characters. In these and similar cases, use the -O
|
||||
option to try other downstream codecs; Base32 should always work.
|
||||
DNS responses for non-NULL/PRIVATE queries can be encoded with the same set of
|
||||
codecs as upstream data. This is normally also autodetected, but no fully
|
||||
exhaustive tests are done, so some problems may not be noticed when selecting
|
||||
more advanced codecs. In that case, you'll see failures/corruption in the
|
||||
fragment size autoprobe. In particular, several DNS relays have been found that
|
||||
change replies returning hostnames (SRV, MX, CNAME, A) to lowercase only when
|
||||
that hostname exceeds ca. 180 characters. In these and similar cases, use the
|
||||
-O option to try other downstream codecs; Base32 should always work.
|
||||
|
||||
Normal operation now is for the server to _not_ answer a DNS request until
|
||||
the next DNS request has come in, a.k.a. being "lazy". This way, the server
|
||||
@@ -337,8 +359,8 @@ THANKS:
|
||||
|
||||
AUTHORS & LICENSE:
|
||||
|
||||
Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
Also major contributions by Anne Bezemer.
|
||||
Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>, 2006-2009 Bjorn
|
||||
Andersson <flex@kryo.se>. Also major contributions by Anne Bezemer.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any purpose
|
||||
with or without fee is hereby granted, provided that the above copyright notice
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
|
||||
|
||||
iodine - http://code.kryo.se/iodine
|
||||
|
||||
***********************************
|
||||
|
||||
Extra README file for Android
|
||||
|
||||
|
||||
== Running iodine on Android:
|
||||
1. Get root access on your android device
|
||||
|
||||
2. Find/build a compatible tun.ko for your specific Android kernel
|
||||
|
||||
3. Copy tun.ko and the iodine binary to your device:
|
||||
(Almost all devices need the armeabi binary. Only Intel powered
|
||||
ones need the x86 build.)
|
||||
|
||||
adb push tun.ko /data/local/tmp
|
||||
adb push iodine /data/local/tmp
|
||||
adb shell
|
||||
su
|
||||
cd /data/local/tmp
|
||||
chmod 777 iodine
|
||||
|
||||
4. Run iodine (see the man page for parameters)
|
||||
|
||||
./iodine ...
|
||||
|
||||
For more information: http://blog.bokhorst.biz/5123
|
||||
|
||||
== Building iodine for Android:
|
||||
1. Download and install the Android SDK and NDK
|
||||
|
||||
2. Download and unpack the iodine sources
|
||||
|
||||
3. Build:
|
||||
cd src
|
||||
make base64u.h base64u.c
|
||||
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk
|
||||
|
||||
or run "make cross-android" in the iodine root directory.
|
||||
To build for other archs, specify TARGET_ARCH_ABI:
|
||||
"make cross-android TARGET_ARCH_ABI=x86"
|
||||
|
||||
@@ -8,6 +8,9 @@ Extra README file for Win32 related stuff
|
||||
|
||||
|
||||
== Running iodine on Windows:
|
||||
|
||||
0. After iodine 0.6, you need Windows XP or newer to run.
|
||||
|
||||
1. Install the TAP32 driver
|
||||
http://openvpn.net/index.php/open-source/downloads.html
|
||||
Choose OpenVPN 2.0.9 Windows Installer, when installing you can
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Iodine Server
|
||||
After=local-fs.target network.target
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=-/etc/sysconfig/iodine-server
|
||||
ExecStart=/usr/local/bin/iodined -i 30 -f $OPTIONS
|
||||
StandardOutput=syslog
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=Iodine socket
|
||||
|
||||
[Socket]
|
||||
ListenDatagram=53
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
@@ -122,7 +122,8 @@ Server sends:
|
||||
s or S: Downstream encoding Base64, for TXT/CNAME/A/MX
|
||||
u or U: Downstream encoding Base64u, for TXT/CNAME/A/MX
|
||||
v or V: Downstream encoding Base128, for TXT/CNAME/A/MX
|
||||
r or R: Downstream encoding Raw, for TXT/NULL (default for NULL)
|
||||
r or R: Downstream encoding Raw, for PRIVATE/TXT/NULL (default for
|
||||
PRIVATE and NULL)
|
||||
If codec unsupported for request type, server will use Base32; note
|
||||
that server will answer any mix of request types that a client sends.
|
||||
Server may disregard this option; client must always use the downstream
|
||||
@@ -188,8 +189,8 @@ encoded with the chosen upstream codec.
|
||||
Downstream data starts with 2 byte header. Then payload data, which may be
|
||||
compressed.
|
||||
|
||||
In NULL responses, downstream data is always raw. In all other response types,
|
||||
downstream data is encoded (see Options above).
|
||||
In NULL and PRIVATE responses, downstream data is always raw. In all other
|
||||
response types, downstream data is encoded (see Options above).
|
||||
Encoding type is indicated by 1 prefix char:
|
||||
TXT:
|
||||
End result is always DNS-chopped (series of len-prefixed strings
|
||||
|
||||
+42
-12
@@ -1,5 +1,5 @@
|
||||
.\" groff -man -Tascii iodine.8
|
||||
.TH IODINE 8 "DEC 2009" "User Manuals"
|
||||
.TH IODINE 8 "JUN 2014" "User Manuals"
|
||||
.SH NAME
|
||||
iodine, iodined \- tunnel IPv4 over DNS
|
||||
.SH SYNOPSIS
|
||||
@@ -7,7 +7,7 @@ iodine, iodined \- tunnel IPv4 over DNS
|
||||
|
||||
.B iodine [-h]
|
||||
|
||||
.B iodine [-f] [-r] [-u
|
||||
.B iodine [-4] [-6] [-f] [-r] [-u
|
||||
.I user
|
||||
.B ] [-P
|
||||
.I password
|
||||
@@ -17,6 +17,8 @@ iodine, iodined \- tunnel IPv4 over DNS
|
||||
.I chrootdir
|
||||
.B ] [-d
|
||||
.I device
|
||||
.B ] [-R
|
||||
.I rdomain
|
||||
.B ] [-m
|
||||
.I fragsize
|
||||
.B ] [-M
|
||||
@@ -56,7 +58,11 @@ iodine, iodined \- tunnel IPv4 over DNS
|
||||
.B ] [-p
|
||||
.I port
|
||||
.B ] [-n
|
||||
(
|
||||
.B auto
|
||||
|
|
||||
.I external_ip
|
||||
)
|
||||
.B ] [-b
|
||||
.I dnsport
|
||||
.B ] [-P
|
||||
@@ -65,6 +71,8 @@ iodine, iodined \- tunnel IPv4 over DNS
|
||||
.I context
|
||||
.B ] [-F
|
||||
.I pidfile
|
||||
.B ] [-i
|
||||
.I max_idle_time
|
||||
.B ]
|
||||
.I tunnel_ip
|
||||
.B [
|
||||
@@ -124,11 +132,20 @@ Apply SELinux 'context' after initialization.
|
||||
Create 'pidfile' and write process id in it.
|
||||
.SS Client Options:
|
||||
.TP
|
||||
.B -4
|
||||
Force IPv4 DNS queries
|
||||
.TP
|
||||
.B -6
|
||||
Force IPv6 DNS queries
|
||||
.TP
|
||||
.B -r
|
||||
Skip raw UDP mode. If not used, iodine will try getting the public IP address
|
||||
of the iodined host and test if it is reachable directly. If it is, traffic
|
||||
will be sent to the server instead of the DNS relay.
|
||||
.TP
|
||||
.B -R rdomain
|
||||
Use OpenBSD routing domain 'rdomain' for the DNS connection.
|
||||
.TP
|
||||
.B -m fragsize
|
||||
Force maximum downstream fragment size. Not setting this will cause the
|
||||
client to automatically probe the maximum accepted downstream fragment size.
|
||||
@@ -139,7 +156,7 @@ Usable range ca. 100 to 255.
|
||||
Use this option to scale back upstream bandwidth in favor of downstream
|
||||
bandwidth.
|
||||
Also useful for DNS servers that perform unreliably when using full-length
|
||||
hostnames, noticable when fragment size autoprobe returns very
|
||||
hostnames, noticeable when fragment size autoprobe returns very
|
||||
different results each time.
|
||||
.TP
|
||||
.B -T dnstype
|
||||
@@ -152,6 +169,7 @@ more bandwidth.
|
||||
In that case, use this option to override the autodetection.
|
||||
In (expected) decreasing bandwidth order, the supported DNS request types are:
|
||||
.IR NULL ,
|
||||
.IR PRIVATE ,
|
||||
.IR TXT ,
|
||||
.IR SRV ,
|
||||
.IR MX ,
|
||||
@@ -166,7 +184,10 @@ and
|
||||
.I A
|
||||
may/will cause additional lookups by "smart" caching
|
||||
nameservers to get an actual IP address, which may either slow down or fail
|
||||
completely.
|
||||
completely. The
|
||||
.IR PRIVATE
|
||||
type uses value 65399 (in the 'private use' range) and requires servers
|
||||
implementing RFC 3597.
|
||||
.TP
|
||||
.B -O downenc
|
||||
Force downstream encoding type for all query type responses except NULL.
|
||||
@@ -218,7 +239,7 @@ connection after 60 seconds of inactivity.
|
||||
.TP
|
||||
.B -c
|
||||
Disable checking the client IP address on all incoming requests.
|
||||
By default, requests originating from non-matching IP adresses will be
|
||||
By default, requests originating from non-matching IP addresses will be
|
||||
rejected, however this will cause problems when requests are routed
|
||||
via a cluster of DNS servers.
|
||||
.TP
|
||||
@@ -232,10 +253,10 @@ Increase debug level. Level 1 prints info about each RX/TX packet.
|
||||
Implies the
|
||||
.B -f
|
||||
option.
|
||||
On level 2 (-DD) or higher, DNS queries will be printed literally.
|
||||
On level 2 (\-DD) or higher, DNS queries will be printed literally.
|
||||
When using Base128 upstream encoding, this is best viewed as
|
||||
ISO Latin-1 text instead of (illegal) UTF-8.
|
||||
This is easily done with : "LC_ALL=C luit iodined -DD ..."
|
||||
This is easily done with : "LC_ALL=C luit iodined \-DD ..."
|
||||
(see luit(1)).
|
||||
.TP
|
||||
.B -m mtu
|
||||
@@ -250,26 +271,36 @@ By default, incoming requests are accepted from all interfaces.
|
||||
.TP
|
||||
.B -p port
|
||||
Make the server listen on 'port' instead of 53 for traffic.
|
||||
If 'listen_ip' does not include localhost, this 'port' can be the same
|
||||
as 'dnsport'.
|
||||
.B Note:
|
||||
You must make sure the dns requests are forwarded to this port yourself.
|
||||
.TP
|
||||
.B -n external_ip
|
||||
.B -n auto|external_ip
|
||||
The IP address to return in NS responses. Default is to return the address used
|
||||
as destination in the query.
|
||||
If external_ip is 'auto', iodined will use externalip.net web service to
|
||||
retrieve the external IP of the host and use that for NS responses.
|
||||
.TP
|
||||
.B -b dnsport
|
||||
If this port is specified, all incoming requests not inside the tunnel domain
|
||||
will be forwarded to this port on localhost, to be handled by a real dns.
|
||||
If 'listen_ip' does not include localhost, this 'dnsport' can be the
|
||||
same as 'port'.
|
||||
.B Note:
|
||||
The forwarding is not fully transparent, and not advised for use
|
||||
in production environments.
|
||||
.TP
|
||||
.B -i max_idle_time
|
||||
Make the server stop itself after max_idle_time seconds if no traffic have been received.
|
||||
This should be combined with systemd or upstart on demand activation for being effective.
|
||||
.SS Client Arguments:
|
||||
.TP
|
||||
.B nameserver
|
||||
The nameserver to use to relay the dns traffic. This can be any relaying
|
||||
nameserver or the server running iodined if reachable. This field can be
|
||||
given as an IP address, or as a hostname. This argument is optional, and
|
||||
if not specified a nameserver will be read from the
|
||||
given as an IPv4/IPv6 address or as a hostname. This argument is optional,
|
||||
and if not specified a nameserver will be read from the
|
||||
.I /etc/resolv.conf
|
||||
file.
|
||||
.TP
|
||||
@@ -285,7 +316,7 @@ must be the same on both the client and the server.
|
||||
.B tunnel_ip[/netmask]
|
||||
This is the server's ip address on the tun interface. The client will be
|
||||
given the next ip number in the range. It is recommended to use the
|
||||
10.0.0.0 or 172.16.0.0 ranges. The default netmask is /27, can be overriden
|
||||
10.0.0.0 or 172.16.0.0 ranges. The default netmask is /27, can be overridden
|
||||
by specifying it here. Using a smaller network will limit the number of
|
||||
concurrent users.
|
||||
.TP
|
||||
@@ -327,7 +358,6 @@ is set, iodined will use the value it is set to as password instead of asking
|
||||
for one. The
|
||||
.B -P
|
||||
option still has precedence.
|
||||
.El
|
||||
.SH SEE ALSO
|
||||
The README file in the source distribution contains some more elaborate
|
||||
information.
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# iodine for Android
|
||||
#
|
||||
# by Marcel Bokhorst
|
||||
# http://blog.bokhorst.biz/5123/computers-en-internet/iodine-for-android/
|
||||
#
|
||||
# cd iodine-0.6.0-rc1/src
|
||||
# make base64u.h base64u.c
|
||||
# .../ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk
|
||||
#
|
||||
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := iodine
|
||||
LOCAL_SRC_FILES := tun.c dns.c read.c encoding.c login.c base32.c base64.c base64u.c base128.c md5.c common.c iodine.c client.c util.c
|
||||
LOCAL_CFLAGS := -c -DANDROID -DLINUX -DIFCONFIGPATH=\"/system/bin/\" -Wall
|
||||
LOCAL_LDLIBS := -lz
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
@@ -9,7 +9,7 @@ ARCH = `uname -m`
|
||||
|
||||
LIBPATH = -L.
|
||||
LDFLAGS += -lz `sh osflags $(TARGETOS) link` $(LIBPATH)
|
||||
CFLAGS += -c -g -Wall -D$(OS) -pedantic `sh osflags $(TARGETOS) cflags`
|
||||
CFLAGS += -std=c99 -c -g -Wall -D$(OS) -pedantic `sh osflags $(TARGETOS) cflags`
|
||||
|
||||
all: stateos $(CLIENT) $(SERVER)
|
||||
|
||||
@@ -26,7 +26,7 @@ $(SERVER): $(COMMONOBJS) $(SERVEROBJS)
|
||||
@mkdir -p ../bin
|
||||
@$(CC) $(COMMONOBJS) $(SERVEROBJS) -o $(SERVER) $(LDFLAGS)
|
||||
|
||||
.c.o:
|
||||
.c.o:
|
||||
@echo CC $<
|
||||
@$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
@@ -43,4 +43,5 @@ base64u.h: base64.h
|
||||
clean:
|
||||
@echo "Cleaning src/"
|
||||
@rm -f $(CLIENT){,.exe} $(SERVER){,.exe} *~ *.o *.core base64u.*
|
||||
@rm -rf obj libs #android stuff
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
#ifndef __FIX_ANDROID_H__
|
||||
#define __FIX_ANDROID_H__
|
||||
|
||||
typedef struct {
|
||||
unsigned id :16;
|
||||
unsigned rd :1;
|
||||
unsigned tc :1;
|
||||
unsigned aa :1;
|
||||
unsigned opcode :4;
|
||||
unsigned qr :1;
|
||||
unsigned rcode :4;
|
||||
unsigned cd: 1;
|
||||
unsigned ad: 1;
|
||||
unsigned unused :1;
|
||||
unsigned ra :1;
|
||||
unsigned qdcount :16;
|
||||
unsigned ancount :16;
|
||||
unsigned nscount :16;
|
||||
unsigned arcount :16;
|
||||
} HEADER;
|
||||
|
||||
#define NOERROR 0
|
||||
#define FORMERR 1
|
||||
#define SERVFAIL 2
|
||||
#define NXDOMAIN 3
|
||||
#define NOTIMP 4
|
||||
#define REFUSED 5
|
||||
|
||||
#define C_IN 1
|
||||
|
||||
#define T_A 1
|
||||
#define T_CNAME 5
|
||||
#define T_NULL 10
|
||||
#define T_MX 15
|
||||
#define T_TXT 16
|
||||
#define T_SRV 33
|
||||
|
||||
#endif
|
||||
@@ -42,7 +42,7 @@
|
||||
* accent chars since they might readily be entered in normal use,
|
||||
* don't use 254-255 because of possible function overloading in DNS systems.
|
||||
*/
|
||||
static const unsigned char cb128[] =
|
||||
static const unsigned char cb128[] =
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
"\274\275\276\277"
|
||||
"\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317"
|
||||
@@ -75,19 +75,19 @@ struct encoder
|
||||
return &base128_encoder;
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
base128_handles_dots()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
base128_blksize_raw()
|
||||
{
|
||||
return BLKSIZE_RAW;
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
base128_blksize_enc()
|
||||
{
|
||||
return BLKSIZE_ENC;
|
||||
@@ -109,7 +109,7 @@ base128_reverse_init()
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
base128_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
||||
/*
|
||||
* Fills *buf with max. *buflen characters, encoding size bytes of *data.
|
||||
@@ -231,7 +231,7 @@ base128_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
||||
if (iout >= *buflen || iin + 1 >= slen ||
|
||||
str[iin] == '\0' || str[iin + 1] == '\0')
|
||||
break;
|
||||
ubuf[iout] = ((REV128(ustr[iin]) & 0x7f) << 1) |
|
||||
ubuf[iout] = ((REV128(ustr[iin]) & 0x7f) << 1) |
|
||||
((REV128(ustr[iin + 1]) & 0x40) >> 6);
|
||||
iin++; /* 0 used up, iin=1 */
|
||||
iout++;
|
||||
|
||||
+11
-10
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
* Mostly rewritten 2009 J.A.Bezemer@opensourcepartners.nl
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
@@ -25,9 +26,9 @@
|
||||
#define BLKSIZE_RAW 5
|
||||
#define BLKSIZE_ENC 8
|
||||
|
||||
static const char cb32[] =
|
||||
static const char cb32[] =
|
||||
"abcdefghijklmnopqrstuvwxyz012345";
|
||||
static const char cb32_ucase[] =
|
||||
static const char cb32_ucase[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
|
||||
static unsigned char rev32[256];
|
||||
static int reverse_init = 0;
|
||||
@@ -55,19 +56,19 @@ struct encoder
|
||||
return &base32_encoder;
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
base32_handles_dots()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
base32_blksize_raw()
|
||||
{
|
||||
return BLKSIZE_RAW;
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
base32_blksize_enc()
|
||||
{
|
||||
return BLKSIZE_ENC;
|
||||
@@ -104,7 +105,7 @@ b32_8to5(int in)
|
||||
return rev32[in];
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
base32_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
||||
/*
|
||||
* Fills *buf with max. *buflen characters, encoding size bytes of *data.
|
||||
@@ -222,7 +223,7 @@ base32_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
||||
if (iout >= *buflen || iin + 1 >= slen ||
|
||||
str[iin] == '\0' || str[iin + 1] == '\0')
|
||||
break;
|
||||
ubuf[iout] = ((REV32(str[iin]) & 0x1f) << 3) |
|
||||
ubuf[iout] = ((REV32(str[iin]) & 0x1f) << 3) |
|
||||
((REV32(str[iin + 1]) & 0x1c) >> 2);
|
||||
iin++; /* 0 used up, iin=1 */
|
||||
iout++;
|
||||
@@ -231,8 +232,8 @@ base32_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
||||
str[iin] == '\0' || str[iin + 1] == '\0' ||
|
||||
str[iin + 2] == '\0')
|
||||
break;
|
||||
ubuf[iout] = ((REV32(str[iin]) & 0x03) << 6) |
|
||||
((REV32(str[iin + 1]) & 0x1f) << 1) |
|
||||
ubuf[iout] = ((REV32(str[iin]) & 0x03) << 6) |
|
||||
((REV32(str[iin + 1]) & 0x1f) << 1) |
|
||||
((REV32(str[iin + 2]) & 0x10) >> 4);
|
||||
iin += 2; /* 1,2 used up, iin=3 */
|
||||
iout++;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
* Mostly rewritten 2009 J.A.Bezemer@opensourcepartners.nl
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
@@ -27,7 +28,7 @@
|
||||
|
||||
/* Note: the "unofficial" char is last here, which means that the \377 pattern
|
||||
in DOWNCODECCHECK1 ('Y' request) will properly test it. */
|
||||
static const char cb64[] =
|
||||
static const char cb64[] =
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789+";
|
||||
static unsigned char rev64[256];
|
||||
static int reverse_init = 0;
|
||||
@@ -55,19 +56,19 @@ struct encoder
|
||||
return &base64_encoder;
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
base64_handles_dots()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
base64_blksize_raw()
|
||||
{
|
||||
return BLKSIZE_RAW;
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
base64_blksize_enc()
|
||||
{
|
||||
return BLKSIZE_ENC;
|
||||
@@ -177,7 +178,7 @@ base64_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
||||
if (iout >= *buflen || iin + 1 >= slen ||
|
||||
str[iin] == '\0' || str[iin + 1] == '\0')
|
||||
break;
|
||||
ubuf[iout] = ((REV64(str[iin]) & 0x3f) << 2) |
|
||||
ubuf[iout] = ((REV64(str[iin]) & 0x3f) << 2) |
|
||||
((REV64(str[iin + 1]) & 0x30) >> 4);
|
||||
iin++; /* 0 used up, iin=1 */
|
||||
iout++;
|
||||
@@ -185,7 +186,7 @@ base64_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
||||
if (iout >= *buflen || iin + 1 >= slen ||
|
||||
str[iin] == '\0' || str[iin + 1] == '\0')
|
||||
break;
|
||||
ubuf[iout] = ((REV64(str[iin]) & 0x0f) << 4) |
|
||||
ubuf[iout] = ((REV64(str[iin]) & 0x0f) << 4) |
|
||||
((REV64(str[iin + 1]) & 0x3c) >> 2);
|
||||
iin++; /* 1 used up, iin=2 */
|
||||
iout++;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
||||
+208
-255
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -19,6 +20,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
@@ -31,6 +33,9 @@
|
||||
#include "windows.h"
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#ifdef ANDROID
|
||||
#include "android_dns.h"
|
||||
#endif
|
||||
#include <arpa/nameser.h>
|
||||
#ifdef DARWIN
|
||||
#define BIND_8_COMPAT
|
||||
@@ -58,7 +63,8 @@ static void handshake_lazyoff(int dns_fd);
|
||||
static int running;
|
||||
static const char *password;
|
||||
|
||||
static struct sockaddr_in nameserv;
|
||||
static struct sockaddr_storage nameserv;
|
||||
static int nameserv_len;
|
||||
static struct sockaddr_in raw_serv;
|
||||
static const char *topdomain;
|
||||
|
||||
@@ -89,10 +95,10 @@ static struct encoder *b128;
|
||||
/* The encoder used for data packets
|
||||
* Defaults to Base32, can be changed after handshake */
|
||||
static struct encoder *dataenc;
|
||||
|
||||
|
||||
/* The encoder to use for downstream data */
|
||||
static char downenc = ' ';
|
||||
|
||||
|
||||
/* set query type to send */
|
||||
static unsigned short do_qtype = T_UNSET;
|
||||
|
||||
@@ -146,49 +152,10 @@ client_get_conn()
|
||||
}
|
||||
|
||||
void
|
||||
client_set_nameserver(const char *cp, int port)
|
||||
client_set_nameserver(struct sockaddr_storage *addr, int addrlen)
|
||||
{
|
||||
struct in_addr addr;
|
||||
|
||||
if (inet_aton(cp, &addr) != 1) {
|
||||
/* try resolving if a domain is given */
|
||||
struct hostent *host;
|
||||
const char *err;
|
||||
host = gethostbyname(cp);
|
||||
if (host != NULL && h_errno > 0) {
|
||||
int i = 0;
|
||||
while (host->h_addr_list[i] != 0) {
|
||||
addr = *(struct in_addr *) host->h_addr_list[i++];
|
||||
fprintf(stderr, "Resolved %s to %s\n", cp, inet_ntoa(addr));
|
||||
goto setaddr;
|
||||
}
|
||||
}
|
||||
#ifndef WINDOWS32
|
||||
err = hstrerror(h_errno);
|
||||
#else
|
||||
{
|
||||
DWORD wserr = WSAGetLastError();
|
||||
switch (wserr) {
|
||||
case WSAHOST_NOT_FOUND:
|
||||
err = "Host not found";
|
||||
break;
|
||||
case WSANO_DATA:
|
||||
err = "No data record found";
|
||||
break;
|
||||
default:
|
||||
err = "Unknown error";
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* !WINDOWS32 */
|
||||
errx(1, "error resolving nameserver '%s': %s", cp, err);
|
||||
}
|
||||
|
||||
setaddr:
|
||||
memset(&nameserv, 0, sizeof(nameserv));
|
||||
nameserv.sin_family = AF_INET;
|
||||
nameserv.sin_port = htons(port);
|
||||
nameserv.sin_addr = addr;
|
||||
memcpy(&nameserv, addr, addrlen);
|
||||
nameserv_len = addrlen;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -203,11 +170,13 @@ client_set_password(const char *cp)
|
||||
password = cp;
|
||||
}
|
||||
|
||||
void
|
||||
set_qtype(char *qtype)
|
||||
int
|
||||
client_set_qtype(char *qtype)
|
||||
{
|
||||
if (!strcasecmp(qtype, "NULL"))
|
||||
do_qtype = T_NULL;
|
||||
else if (!strcasecmp(qtype, "PRIVATE"))
|
||||
do_qtype = T_PRIVATE;
|
||||
else if (!strcasecmp(qtype, "CNAME"))
|
||||
do_qtype = T_CNAME;
|
||||
else if (!strcasecmp(qtype, "A"))
|
||||
@@ -218,14 +187,16 @@ set_qtype(char *qtype)
|
||||
do_qtype = T_SRV;
|
||||
else if (!strcasecmp(qtype, "TXT"))
|
||||
do_qtype = T_TXT;
|
||||
return (do_qtype == T_UNSET);
|
||||
}
|
||||
|
||||
char *
|
||||
get_qtype()
|
||||
client_get_qtype()
|
||||
{
|
||||
char *c = "UNDEFINED";
|
||||
|
||||
if (do_qtype == T_NULL) c = "NULL";
|
||||
else if (do_qtype == T_PRIVATE) c = "PRIVATE";
|
||||
else if (do_qtype == T_CNAME) c = "CNAME";
|
||||
else if (do_qtype == T_A) c = "A";
|
||||
else if (do_qtype == T_MX) c = "MX";
|
||||
@@ -236,7 +207,7 @@ get_qtype()
|
||||
}
|
||||
|
||||
void
|
||||
set_downenc(char *encoding)
|
||||
client_set_downenc(char *encoding)
|
||||
{
|
||||
if (!strcasecmp(encoding, "base32"))
|
||||
downenc = 'T';
|
||||
@@ -250,7 +221,7 @@ set_downenc(char *encoding)
|
||||
downenc = 'R';
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
client_set_selecttimeout(int select_timeout)
|
||||
{
|
||||
selecttimeout = select_timeout;
|
||||
@@ -302,7 +273,7 @@ send_query(int fd, char *hostname)
|
||||
fprintf(stderr, " Sendquery: id %5d name[0] '%c'\n", q.id, hostname[0]);
|
||||
#endif
|
||||
|
||||
sendto(fd, packet, len, 0, (struct sockaddr*)&nameserv, sizeof(nameserv));
|
||||
sendto(fd, packet, len, 0, (struct sockaddr*)&nameserv, nameserv_len);
|
||||
|
||||
/* There are DNS relays that time out quickly but don't send anything
|
||||
back on timeout.
|
||||
@@ -369,7 +340,7 @@ send_packet(int fd, char cmd, const char *data, const size_t datalen)
|
||||
char buf[4096];
|
||||
|
||||
buf[0] = cmd;
|
||||
|
||||
|
||||
build_hostname(buf + 1, sizeof(buf) - 1, data, datalen, topdomain,
|
||||
b32, hostname_maxlen);
|
||||
send_query(fd, buf);
|
||||
@@ -402,7 +373,7 @@ send_chunk(int fd)
|
||||
/* Build upstream data header (see doc/proto_xxxxxxxx.txt) */
|
||||
|
||||
buf[0] = userid_char; /* First byte is hex userid */
|
||||
|
||||
|
||||
code = ((outpkt.seqno & 7) << 2) | ((outpkt.fragment & 15) >> 2);
|
||||
buf[1] = b32_5to8(code); /* Second byte is 3 bits seqno, 2 upper bits fragment count */
|
||||
|
||||
@@ -416,7 +387,7 @@ send_chunk(int fd)
|
||||
datacmc++;
|
||||
if (datacmc >= 36)
|
||||
datacmc = 0;
|
||||
|
||||
|
||||
#if 0
|
||||
fprintf(stderr, " Send: down %d/%d up %d/%d, %d bytes\n",
|
||||
inpkt.seqno, inpkt.fragment, outpkt.seqno, outpkt.fragment,
|
||||
@@ -431,12 +402,12 @@ send_ping(int fd)
|
||||
{
|
||||
if (conn == CONN_DNS_NULL) {
|
||||
char data[4];
|
||||
|
||||
|
||||
data[0] = userid;
|
||||
data[1] = ((inpkt.seqno & 7) << 4) | (inpkt.fragment & 15);
|
||||
data[2] = (rand_seed >> 8) & 0xff;
|
||||
data[3] = (rand_seed >> 0) & 0xff;
|
||||
|
||||
|
||||
rand_seed++;
|
||||
|
||||
#if 0
|
||||
@@ -596,13 +567,13 @@ read_dns_withq(int dns_fd, int tun_fd, char *buf, int buflen, struct query *q)
|
||||
Returns >0 on correct replies; value is #valid bytes in *buf.
|
||||
*/
|
||||
{
|
||||
struct sockaddr_in from;
|
||||
struct sockaddr_storage from;
|
||||
char data[64*1024];
|
||||
socklen_t addrlen;
|
||||
int r;
|
||||
|
||||
addrlen = sizeof(struct sockaddr);
|
||||
if ((r = recvfrom(dns_fd, data, sizeof(data), 0,
|
||||
addrlen = sizeof(from);
|
||||
if ((r = recvfrom(dns_fd, data, sizeof(data), 0,
|
||||
(struct sockaddr*)&from, &addrlen)) < 0) {
|
||||
warn("recvfrom");
|
||||
return -1;
|
||||
@@ -624,9 +595,9 @@ read_dns_withq(int dns_fd, int tun_fd, char *buf, int buflen, struct query *q)
|
||||
/*
|
||||
* buf is a hostname or txt stream that we still need to
|
||||
* decode to binary
|
||||
*
|
||||
*
|
||||
* also update rv with the number of valid bytes
|
||||
*
|
||||
*
|
||||
* data is unused here, and will certainly hold the smaller binary
|
||||
*/
|
||||
|
||||
@@ -1180,11 +1151,11 @@ client_tunnel_cb(int tun_fd, int dns_fd, int
|
||||
warnx("No downstream data received in 60 seconds, shutting down.");
|
||||
running = 0;
|
||||
}
|
||||
|
||||
|
||||
if (running == 0)
|
||||
break;
|
||||
|
||||
if (i < 0)
|
||||
if (i < 0)
|
||||
err(1, "select");
|
||||
|
||||
if (i == 0) {
|
||||
@@ -1227,7 +1198,7 @@ client_tunnel_cb(int tun_fd, int dns_fd, int
|
||||
if (FD_ISSET(dns_fd, &fds)) {
|
||||
if (tunnel_dns(tun_fd, dns_fd) <= 0)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1245,7 +1216,7 @@ send_login(int fd, char *login, int len)
|
||||
|
||||
data[17] = (rand_seed >> 8) & 0xff;
|
||||
data[18] = (rand_seed >> 0) & 0xff;
|
||||
|
||||
|
||||
rand_seed++;
|
||||
|
||||
send_packet(fd, 'l', data, sizeof(data));
|
||||
@@ -1284,23 +1255,23 @@ static void
|
||||
send_set_downstream_fragsize(int fd, int fragsize)
|
||||
{
|
||||
char data[5];
|
||||
|
||||
|
||||
data[0] = userid;
|
||||
data[1] = (fragsize & 0xff00) >> 8;
|
||||
data[2] = (fragsize & 0x00ff);
|
||||
data[3] = (rand_seed >> 8) & 0xff;
|
||||
data[4] = (rand_seed >> 0) & 0xff;
|
||||
|
||||
|
||||
rand_seed++;
|
||||
|
||||
send_packet(fd, 'n', data, sizeof(data));
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
send_version(int fd, uint32_t version)
|
||||
{
|
||||
char data[6];
|
||||
|
||||
|
||||
data[0] = (version >> 24) & 0xff;
|
||||
data[1] = (version >> 16) & 0xff;
|
||||
data[2] = (version >> 8) & 0xff;
|
||||
@@ -1308,7 +1279,7 @@ send_version(int fd, uint32_t version)
|
||||
|
||||
data[4] = (rand_seed >> 8) & 0xff;
|
||||
data[5] = (rand_seed >> 0) & 0xff;
|
||||
|
||||
|
||||
rand_seed++;
|
||||
|
||||
send_packet(fd, 'v', data, sizeof(data));
|
||||
@@ -1319,7 +1290,7 @@ send_ip_request(int fd, int userid)
|
||||
{
|
||||
char buf[512] = "i____.";
|
||||
buf[1] = b32_5to8(userid);
|
||||
|
||||
|
||||
buf[2] = b32_5to8((rand_seed >> 10) & 0x1f);
|
||||
buf[3] = b32_5to8((rand_seed >> 5) & 0x1f);
|
||||
buf[4] = b32_5to8((rand_seed ) & 0x1f);
|
||||
@@ -1343,7 +1314,7 @@ send_upenctest(int fd, char *s)
|
||||
/* NOTE: String may be at most 63-4=59 chars to fit in 1 dns chunk. */
|
||||
{
|
||||
char buf[512] = "z___";
|
||||
|
||||
|
||||
buf[1] = b32_5to8((rand_seed >> 10) & 0x1f);
|
||||
buf[2] = b32_5to8((rand_seed >> 5) & 0x1f);
|
||||
buf[3] = b32_5to8((rand_seed ) & 0x1f);
|
||||
@@ -1379,7 +1350,7 @@ send_codec_switch(int fd, int userid, int bits)
|
||||
char buf[512] = "s_____.";
|
||||
buf[1] = b32_5to8(userid);
|
||||
buf[2] = b32_5to8(bits);
|
||||
|
||||
|
||||
buf[3] = b32_5to8((rand_seed >> 10) & 0x1f);
|
||||
buf[4] = b32_5to8((rand_seed >> 5) & 0x1f);
|
||||
buf[5] = b32_5to8((rand_seed ) & 0x1f);
|
||||
@@ -1442,33 +1413,31 @@ handshake_version(int dns_fd, int *seed)
|
||||
|
||||
read = handshake_waitdns(dns_fd, in, sizeof(in), 'v', 'V', i+1);
|
||||
|
||||
/*XXX START adjust indent 1 tab back*/
|
||||
if (read >= 9) {
|
||||
payload = (((in[4] & 0xff) << 24) |
|
||||
((in[5] & 0xff) << 16) |
|
||||
((in[6] & 0xff) << 8) |
|
||||
((in[7] & 0xff)));
|
||||
if (read >= 9) {
|
||||
payload = (((in[4] & 0xff) << 24) |
|
||||
((in[5] & 0xff) << 16) |
|
||||
((in[6] & 0xff) << 8) |
|
||||
((in[7] & 0xff)));
|
||||
|
||||
if (strncmp("VACK", in, 4) == 0) {
|
||||
*seed = payload;
|
||||
userid = in[8];
|
||||
userid_char = hex[userid & 15];
|
||||
userid_char2 = hex2[userid & 15];
|
||||
if (strncmp("VACK", in, 4) == 0) {
|
||||
*seed = payload;
|
||||
userid = in[8];
|
||||
userid_char = hex[userid & 15];
|
||||
userid_char2 = hex2[userid & 15];
|
||||
|
||||
fprintf(stderr, "Version ok, both using protocol v 0x%08x. You are user #%d\n", VERSION, userid);
|
||||
return 0;
|
||||
} else if (strncmp("VNAK", in, 4) == 0) {
|
||||
warnx("You use protocol v 0x%08x, server uses v 0x%08x. Giving up",
|
||||
VERSION, payload);
|
||||
return 1;
|
||||
} else if (strncmp("VFUL", in, 4) == 0) {
|
||||
warnx("Server full, all %d slots are taken. Try again later", payload);
|
||||
return 1;
|
||||
}
|
||||
} else if (read > 0)
|
||||
warnx("did not receive proper login challenge");
|
||||
|
||||
fprintf(stderr, "Version ok, both using protocol v 0x%08x. You are user #%d\n", VERSION, userid);
|
||||
return 0;
|
||||
} else if (strncmp("VNAK", in, 4) == 0) {
|
||||
warnx("You use protocol v 0x%08x, server uses v 0x%08x. Giving up",
|
||||
VERSION, payload);
|
||||
return 1;
|
||||
} else if (strncmp("VFUL", in, 4) == 0) {
|
||||
warnx("Server full, all %d slots are taken. Try again later", payload);
|
||||
return 1;
|
||||
}
|
||||
} else if (read > 0)
|
||||
warnx("did not receive proper login challenge");
|
||||
/*XXX END adjust indent 1 tab back*/
|
||||
|
||||
fprintf(stderr, "Retrying version check...\n");
|
||||
}
|
||||
warnx("couldn't connect to server (maybe other -T options will work)");
|
||||
@@ -1487,37 +1456,35 @@ handshake_login(int dns_fd, int seed)
|
||||
int read;
|
||||
|
||||
login_calculate(login, 16, password, seed);
|
||||
|
||||
|
||||
for (i=0; running && i<5 ;i++) {
|
||||
|
||||
send_login(dns_fd, login, 16);
|
||||
|
||||
read = handshake_waitdns(dns_fd, in, sizeof(in), 'l', 'L', i+1);
|
||||
|
||||
/*XXX START adjust indent 1 tab back*/
|
||||
if (read > 0) {
|
||||
int netmask;
|
||||
if (strncmp("LNAK", in, 4) == 0) {
|
||||
fprintf(stderr, "Bad password\n");
|
||||
return 1;
|
||||
} else if (sscanf(in, "%64[^-]-%64[^-]-%d-%d",
|
||||
server, client, &mtu, &netmask) == 4) {
|
||||
|
||||
server[64] = 0;
|
||||
client[64] = 0;
|
||||
if (tun_setip(client, server, netmask) == 0 &&
|
||||
tun_setmtu(mtu) == 0) {
|
||||
if (read > 0) {
|
||||
int netmask;
|
||||
if (strncmp("LNAK", in, 4) == 0) {
|
||||
fprintf(stderr, "Bad password\n");
|
||||
return 1;
|
||||
} else if (sscanf(in, "%64[^-]-%64[^-]-%d-%d",
|
||||
server, client, &mtu, &netmask) == 4) {
|
||||
|
||||
fprintf(stderr, "Server tunnel IP is %s\n", server);
|
||||
return 0;
|
||||
} else {
|
||||
errx(4, "Failed to set IP and MTU");
|
||||
}
|
||||
server[64] = 0;
|
||||
client[64] = 0;
|
||||
if (tun_setip(client, server, netmask) == 0 &&
|
||||
tun_setmtu(mtu) == 0) {
|
||||
|
||||
fprintf(stderr, "Server tunnel IP is %s\n", server);
|
||||
return 0;
|
||||
} else {
|
||||
fprintf(stderr, "Received bad handshake\n");
|
||||
errx(4, "Failed to set IP and MTU");
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Received bad handshake\n");
|
||||
}
|
||||
/*XXX END adjust indent 1 tab back*/
|
||||
}
|
||||
|
||||
fprintf(stderr, "Retrying login...\n");
|
||||
}
|
||||
@@ -1544,20 +1511,18 @@ handshake_raw_udp(int dns_fd, int seed)
|
||||
|
||||
len = handshake_waitdns(dns_fd, in, sizeof(in), 'i', 'I', i+1);
|
||||
|
||||
/*XXX START adjust indent 1 tab back*/
|
||||
if (len == 5 && in[0] == 'I') {
|
||||
/* Received IP address */
|
||||
remoteaddr = (in[1] & 0xff);
|
||||
remoteaddr <<= 8;
|
||||
remoteaddr |= (in[2] & 0xff);
|
||||
remoteaddr <<= 8;
|
||||
remoteaddr |= (in[3] & 0xff);
|
||||
remoteaddr <<= 8;
|
||||
remoteaddr |= (in[4] & 0xff);
|
||||
server.s_addr = ntohl(remoteaddr);
|
||||
break;
|
||||
}
|
||||
/*XXX END adjust indent 1 tab back*/
|
||||
if (len == 5 && in[0] == 'I') {
|
||||
/* Received IP address */
|
||||
remoteaddr = (in[1] & 0xff);
|
||||
remoteaddr <<= 8;
|
||||
remoteaddr |= (in[2] & 0xff);
|
||||
remoteaddr <<= 8;
|
||||
remoteaddr |= (in[3] & 0xff);
|
||||
remoteaddr <<= 8;
|
||||
remoteaddr |= (in[4] & 0xff);
|
||||
server.s_addr = ntohl(remoteaddr);
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(stderr, ".");
|
||||
fflush(stderr);
|
||||
@@ -1565,7 +1530,7 @@ handshake_raw_udp(int dns_fd, int seed)
|
||||
fprintf(stderr, "\n");
|
||||
if (!running)
|
||||
return 0;
|
||||
|
||||
|
||||
if (!remoteaddr) {
|
||||
fprintf(stderr, "Failed to get raw server IP, will use DNS mode.\n");
|
||||
return 0;
|
||||
@@ -1579,7 +1544,7 @@ handshake_raw_udp(int dns_fd, int seed)
|
||||
raw_serv.sin_port = htons(53);
|
||||
raw_serv.sin_addr = server;
|
||||
|
||||
/* do login against port 53 on remote server
|
||||
/* do login against port 53 on remote server
|
||||
* based on the old seed. If reply received,
|
||||
* switch to raw udp mode */
|
||||
for (i=0; running && i<4 ;i++) {
|
||||
@@ -1587,7 +1552,7 @@ handshake_raw_udp(int dns_fd, int seed)
|
||||
tv.tv_usec = 0;
|
||||
|
||||
send_raw_udp_login(dns_fd, userid, seed);
|
||||
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(dns_fd, &fds);
|
||||
|
||||
@@ -1600,7 +1565,7 @@ handshake_raw_udp(int dns_fd, int seed)
|
||||
char hash[16];
|
||||
login_calculate(hash, 16, password, seed - 1);
|
||||
if (memcmp(in, raw_header, RAW_HDR_IDENT_LEN) == 0
|
||||
&& RAW_HDR_GET_CMD(in) == RAW_HDR_CMD_LOGIN
|
||||
&& RAW_HDR_GET_CMD(in) == RAW_HDR_CMD_LOGIN
|
||||
&& memcmp(&in[RAW_HDR_LEN], hash, sizeof(hash)) == 0) {
|
||||
|
||||
fprintf(stderr, "OK\n");
|
||||
@@ -1611,7 +1576,7 @@ handshake_raw_udp(int dns_fd, int seed)
|
||||
fprintf(stderr, ".");
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
|
||||
fprintf(stderr, "failed\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -1840,7 +1805,7 @@ handshake_downenc_autodetect(int dns_fd)
|
||||
int base64uok = 0;
|
||||
int base128ok = 0;
|
||||
|
||||
if (do_qtype == T_NULL) {
|
||||
if (do_qtype == T_NULL || do_qtype == T_PRIVATE) {
|
||||
/* no other choice than raw */
|
||||
fprintf(stderr, "No alternative downstream codec available, using default (Raw)\n");
|
||||
return ' ';
|
||||
@@ -1894,13 +1859,14 @@ handshake_qtypetest(int dns_fd, int timeout)
|
||||
int trycodec;
|
||||
int k;
|
||||
|
||||
if (do_qtype == T_NULL)
|
||||
if (do_qtype == T_NULL || do_qtype == T_PRIVATE)
|
||||
trycodec = 'R';
|
||||
else
|
||||
trycodec = 'T';
|
||||
|
||||
/* We could use 'Z' bouncing here, but 'Y' also tests that 0-255
|
||||
byte values can be returned, which is needed for NULL to work. */
|
||||
byte values can be returned, which is needed for NULL/PRIVATE
|
||||
to work. */
|
||||
|
||||
send_downenctest(dns_fd, trycodec, 1, NULL, 0);
|
||||
|
||||
@@ -1925,11 +1891,12 @@ handshake_qtype_numcvt(int num)
|
||||
{
|
||||
switch (num) {
|
||||
case 0: return T_NULL;
|
||||
case 1: return T_TXT;
|
||||
case 2: return T_SRV;
|
||||
case 3: return T_MX;
|
||||
case 4: return T_CNAME;
|
||||
case 5: return T_A;
|
||||
case 1: return T_PRIVATE;
|
||||
case 2: return T_TXT;
|
||||
case 3: return T_SRV;
|
||||
case 4: return T_MX;
|
||||
case 5: return T_CNAME;
|
||||
case 6: return T_A;
|
||||
}
|
||||
return T_UNSET;
|
||||
}
|
||||
@@ -1972,7 +1939,7 @@ handshake_qtype_autodetect(int dns_fd)
|
||||
highestworking = qtypenum;
|
||||
#if 0
|
||||
fprintf(stderr, " Type %s timeout %d works\n",
|
||||
get_qtype(), timeout);
|
||||
client_get_qtype(), timeout);
|
||||
#endif
|
||||
break;
|
||||
/* try others with longer timeout */
|
||||
@@ -2079,27 +2046,25 @@ handshake_switch_codec(int dns_fd, int bits)
|
||||
for (i=0; running && i<5 ;i++) {
|
||||
|
||||
send_codec_switch(dns_fd, userid, bits);
|
||||
|
||||
|
||||
read = handshake_waitdns(dns_fd, in, sizeof(in), 's', 'S', i+1);
|
||||
|
||||
/*XXX START adjust indent 1 tab back*/
|
||||
if (read > 0) {
|
||||
if (strncmp("BADLEN", in, 6) == 0) {
|
||||
fprintf(stderr, "Server got bad message length. ");
|
||||
goto codec_revert;
|
||||
} else if (strncmp("BADIP", in, 5) == 0) {
|
||||
fprintf(stderr, "Server rejected sender IP address. ");
|
||||
goto codec_revert;
|
||||
} else if (strncmp("BADCODEC", in, 8) == 0) {
|
||||
fprintf(stderr, "Server rejected the selected codec. ");
|
||||
goto codec_revert;
|
||||
}
|
||||
in[read] = 0; /* zero terminate */
|
||||
fprintf(stderr, "Server switched upstream to codec %s\n", in);
|
||||
dataenc = tempenc;
|
||||
return;
|
||||
if (read > 0) {
|
||||
if (strncmp("BADLEN", in, 6) == 0) {
|
||||
fprintf(stderr, "Server got bad message length. ");
|
||||
goto codec_revert;
|
||||
} else if (strncmp("BADIP", in, 5) == 0) {
|
||||
fprintf(stderr, "Server rejected sender IP address. ");
|
||||
goto codec_revert;
|
||||
} else if (strncmp("BADCODEC", in, 8) == 0) {
|
||||
fprintf(stderr, "Server rejected the selected codec. ");
|
||||
goto codec_revert;
|
||||
}
|
||||
/*XXX END adjust indent 1 tab back*/
|
||||
in[read] = 0; /* zero terminate */
|
||||
fprintf(stderr, "Server switched upstream to codec %s\n", in);
|
||||
dataenc = tempenc;
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Retrying codec switch...\n");
|
||||
}
|
||||
@@ -2108,7 +2073,7 @@ handshake_switch_codec(int dns_fd, int bits)
|
||||
|
||||
fprintf(stderr, "No reply from server on codec switch. ");
|
||||
|
||||
codec_revert:
|
||||
codec_revert:
|
||||
fprintf(stderr, "Falling back to upstream codec %s\n", dataenc->name);
|
||||
}
|
||||
|
||||
@@ -2137,23 +2102,21 @@ handshake_switch_downenc(int dns_fd)
|
||||
|
||||
read = handshake_waitdns(dns_fd, in, sizeof(in), 'o', 'O', i+1);
|
||||
|
||||
/*XXX START adjust indent 1 tab back*/
|
||||
if (read > 0) {
|
||||
if (strncmp("BADLEN", in, 6) == 0) {
|
||||
fprintf(stderr, "Server got bad message length. ");
|
||||
goto codec_revert;
|
||||
} else if (strncmp("BADIP", in, 5) == 0) {
|
||||
fprintf(stderr, "Server rejected sender IP address. ");
|
||||
goto codec_revert;
|
||||
} else if (strncmp("BADCODEC", in, 8) == 0) {
|
||||
fprintf(stderr, "Server rejected the selected codec. ");
|
||||
goto codec_revert;
|
||||
}
|
||||
in[read] = 0; /* zero terminate */
|
||||
fprintf(stderr, "Server switched downstream to codec %s\n", in);
|
||||
return;
|
||||
if (read > 0) {
|
||||
if (strncmp("BADLEN", in, 6) == 0) {
|
||||
fprintf(stderr, "Server got bad message length. ");
|
||||
goto codec_revert;
|
||||
} else if (strncmp("BADIP", in, 5) == 0) {
|
||||
fprintf(stderr, "Server rejected sender IP address. ");
|
||||
goto codec_revert;
|
||||
} else if (strncmp("BADCODEC", in, 8) == 0) {
|
||||
fprintf(stderr, "Server rejected the selected codec. ");
|
||||
goto codec_revert;
|
||||
}
|
||||
/*XXX END adjust indent 1 tab back*/
|
||||
in[read] = 0; /* zero terminate */
|
||||
fprintf(stderr, "Server switched downstream to codec %s\n", in);
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Retrying codec switch...\n");
|
||||
}
|
||||
@@ -2162,7 +2125,7 @@ handshake_switch_downenc(int dns_fd)
|
||||
|
||||
fprintf(stderr, "No reply from server on codec switch. ");
|
||||
|
||||
codec_revert:
|
||||
codec_revert:
|
||||
fprintf(stderr, "Falling back to downstream codec Base32\n");
|
||||
}
|
||||
|
||||
@@ -2180,24 +2143,22 @@ handshake_try_lazy(int dns_fd)
|
||||
|
||||
read = handshake_waitdns(dns_fd, in, sizeof(in), 'o', 'O', i+1);
|
||||
|
||||
/*XXX START adjust indent 1 tab back*/
|
||||
if (read > 0) {
|
||||
if (strncmp("BADLEN", in, 6) == 0) {
|
||||
fprintf(stderr, "Server got bad message length. ");
|
||||
goto codec_revert;
|
||||
} else if (strncmp("BADIP", in, 5) == 0) {
|
||||
fprintf(stderr, "Server rejected sender IP address. ");
|
||||
goto codec_revert;
|
||||
} else if (strncmp("BADCODEC", in, 8) == 0) {
|
||||
fprintf(stderr, "Server rejected lazy mode. ");
|
||||
goto codec_revert;
|
||||
} else if (strncmp("Lazy", in, 4) == 0) {
|
||||
fprintf(stderr, "Server switched to lazy mode\n");
|
||||
lazymode = 1;
|
||||
return;
|
||||
}
|
||||
if (read > 0) {
|
||||
if (strncmp("BADLEN", in, 6) == 0) {
|
||||
fprintf(stderr, "Server got bad message length. ");
|
||||
goto codec_revert;
|
||||
} else if (strncmp("BADIP", in, 5) == 0) {
|
||||
fprintf(stderr, "Server rejected sender IP address. ");
|
||||
goto codec_revert;
|
||||
} else if (strncmp("BADCODEC", in, 8) == 0) {
|
||||
fprintf(stderr, "Server rejected lazy mode. ");
|
||||
goto codec_revert;
|
||||
} else if (strncmp("Lazy", in, 4) == 0) {
|
||||
fprintf(stderr, "Server switched to lazy mode\n");
|
||||
lazymode = 1;
|
||||
return;
|
||||
}
|
||||
/*XXX END adjust indent 1 tab back*/
|
||||
}
|
||||
|
||||
fprintf(stderr, "Retrying lazy mode switch...\n");
|
||||
}
|
||||
@@ -2206,7 +2167,7 @@ handshake_try_lazy(int dns_fd)
|
||||
|
||||
fprintf(stderr, "No reply from server on lazy switch. ");
|
||||
|
||||
codec_revert:
|
||||
codec_revert:
|
||||
fprintf(stderr, "Falling back to legacy mode\n");
|
||||
lazymode = 0;
|
||||
selecttimeout = 1;
|
||||
@@ -2226,14 +2187,12 @@ handshake_lazyoff(int dns_fd)
|
||||
|
||||
read = handshake_waitdns(dns_fd, in, sizeof(in), 'o', 'O', 1);
|
||||
|
||||
/*XXX START adjust indent 2 tabs back*/
|
||||
if (read == 9 && strncmp("Immediate", in, 9) == 0) {
|
||||
warnx("Server switched back to legacy mode.\n");
|
||||
lazymode = 0;
|
||||
selecttimeout = 1;
|
||||
return;
|
||||
}
|
||||
/*XXX END adjust indent 2 tabs back*/
|
||||
if (read == 9 && strncmp("Immediate", in, 9) == 0) {
|
||||
warnx("Server switched back to legacy mode.\n");
|
||||
lazymode = 0;
|
||||
selecttimeout = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!running)
|
||||
return;
|
||||
@@ -2288,28 +2247,26 @@ fragsize_check(char *in, int read, int proposed_fragsize, int *max_fragsize)
|
||||
okay = 1;
|
||||
v = in[3] & 0xff;
|
||||
|
||||
/*XXX START adjust indent 1 tab back*/
|
||||
for (i = 3; i < read; i++, v = (v + 107) & 0xff)
|
||||
if ((in[i] & 0xff) != v) {
|
||||
okay = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (okay) {
|
||||
fprintf(stderr, "%d ok.. ", acked_fragsize);
|
||||
fflush(stderr);
|
||||
*max_fragsize = acked_fragsize;
|
||||
return 1;
|
||||
} else {
|
||||
if (downenc != ' ' && downenc != 'T') {
|
||||
fprintf(stderr, "%d corrupted at %d.. (Try -O Base32)\n", acked_fragsize, i);
|
||||
} else {
|
||||
fprintf(stderr, "%d corrupted at %d.. ", acked_fragsize, i);
|
||||
}
|
||||
fflush(stderr);
|
||||
return 1;
|
||||
for (i = 3; i < read; i++, v = (v + 107) & 0xff)
|
||||
if ((in[i] & 0xff) != v) {
|
||||
okay = 0;
|
||||
break;
|
||||
}
|
||||
/*XXX END adjust indent 1 tab back*/
|
||||
|
||||
if (okay) {
|
||||
fprintf(stderr, "%d ok.. ", acked_fragsize);
|
||||
fflush(stderr);
|
||||
*max_fragsize = acked_fragsize;
|
||||
return 1;
|
||||
} else {
|
||||
if (downenc != ' ' && downenc != 'T') {
|
||||
fprintf(stderr, "%d corrupted at %d.. (Try -O Base32)\n", acked_fragsize, i);
|
||||
} else {
|
||||
fprintf(stderr, "%d corrupted at %d.. ", acked_fragsize, i);
|
||||
}
|
||||
fflush(stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* notreached */
|
||||
return 1;
|
||||
@@ -2327,7 +2284,7 @@ handshake_autoprobe_fragsize(int dns_fd)
|
||||
int max_fragsize;
|
||||
|
||||
max_fragsize = 0;
|
||||
fprintf(stderr, "Autoprobing max downstream fragment size... (skip with -m fragsize)\n");
|
||||
fprintf(stderr, "Autoprobing max downstream fragment size... (skip with -m fragsize)\n");
|
||||
while (running && range > 0 && (range >= 8 || max_fragsize < 300)) {
|
||||
/* stop the slow probing early when we have enough bytes anyway */
|
||||
for (i=0; running && i<3 ;i++) {
|
||||
@@ -2335,14 +2292,12 @@ handshake_autoprobe_fragsize(int dns_fd)
|
||||
send_fragsize_probe(dns_fd, proposed_fragsize);
|
||||
|
||||
read = handshake_waitdns(dns_fd, in, sizeof(in), 'r', 'R', 1);
|
||||
|
||||
/*XXX START adjust indent 1 tab back*/
|
||||
if (read > 0) {
|
||||
/* We got a reply */
|
||||
if (fragsize_check(in, read, proposed_fragsize, &max_fragsize) == 1)
|
||||
break;
|
||||
}
|
||||
/*XXX END adjust indent 1 tab back*/
|
||||
|
||||
if (read > 0) {
|
||||
/* We got a reply */
|
||||
if (fragsize_check(in, read, proposed_fragsize, &max_fragsize) == 1)
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(stderr, ".");
|
||||
fflush(stderr);
|
||||
@@ -2383,7 +2338,7 @@ handshake_autoprobe_fragsize(int dns_fd)
|
||||
fprintf(stderr, "Note: this probably won't work well.\n");
|
||||
fprintf(stderr, "Try setting -M to 200 or lower, or try other DNS types (-T option).\n");
|
||||
} else if (max_fragsize < 202 &&
|
||||
(do_qtype == T_NULL || do_qtype == T_TXT ||
|
||||
(do_qtype == T_NULL || do_qtype == T_PRIVATE || do_qtype == T_TXT ||
|
||||
do_qtype == T_SRV || do_qtype == T_MX)) {
|
||||
fprintf(stderr, "Note: this isn't very much.\n");
|
||||
fprintf(stderr, "Try setting -M to 200 or lower, or try other DNS types (-T option).\n");
|
||||
@@ -2406,22 +2361,20 @@ handshake_set_fragsize(int dns_fd, int fragsize)
|
||||
|
||||
read = handshake_waitdns(dns_fd, in, sizeof(in), 'n', 'N', i+1);
|
||||
|
||||
/*XXX START adjust indent 1 tab back*/
|
||||
if (read > 0) {
|
||||
int accepted_fragsize;
|
||||
if (read > 0) {
|
||||
|
||||
if (strncmp("BADFRAG", in, 7) == 0) {
|
||||
fprintf(stderr, "Server rejected fragsize. Keeping default.");
|
||||
return;
|
||||
} else if (strncmp("BADIP", in, 5) == 0) {
|
||||
fprintf(stderr, "Server rejected sender IP address.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
accepted_fragsize = ((in[0] & 0xff) << 8) | (in[1] & 0xff);
|
||||
if (strncmp("BADFRAG", in, 7) == 0) {
|
||||
fprintf(stderr, "Server rejected fragsize. Keeping default.");
|
||||
return;
|
||||
} else if (strncmp("BADIP", in, 5) == 0) {
|
||||
fprintf(stderr, "Server rejected sender IP address.\n");
|
||||
return;
|
||||
}
|
||||
/*XXX END adjust indent 1 tab back*/
|
||||
|
||||
/* The server returns the accepted fragsize:
|
||||
accepted_fragsize = ((in[0] & 0xff) << 8) | (in[1] & 0xff) */
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Retrying set fragsize...\n");
|
||||
}
|
||||
@@ -2448,7 +2401,7 @@ client_handshake(int dns_fd, int raw_mode, int autodetect_frag_size, int fragsiz
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "Using DNS type %s queries\n", get_qtype());
|
||||
fprintf(stderr, "Using DNS type %s queries\n", client_get_qtype());
|
||||
|
||||
r = handshake_version(dns_fd, &seed);
|
||||
if (r) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -23,12 +24,12 @@ void client_stop();
|
||||
enum connection client_get_conn();
|
||||
const char *client_get_raw_addr();
|
||||
|
||||
void client_set_nameserver(const char *cp, int port);
|
||||
void client_set_nameserver(struct sockaddr_storage *, int);
|
||||
void client_set_topdomain(const char *cp);
|
||||
void client_set_password(const char *cp);
|
||||
void set_qtype(char *qtype);
|
||||
char *get_qtype();
|
||||
void set_downenc(char *encoding);
|
||||
int client_set_qtype(char *qtype);
|
||||
char *client_get_qtype();
|
||||
void client_set_downenc(char *encoding);
|
||||
void client_set_selecttimeout(int select_timeout);
|
||||
void client_set_lazymode(int lazy_mode);
|
||||
void client_set_hostname_maxlen(int i);
|
||||
|
||||
+189
-69
@@ -1,4 +1,5 @@
|
||||
/* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
/* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
* Copyright (c) 2007 Albert Lee <trisk@acm.jhu.edu>.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
@@ -39,9 +40,11 @@
|
||||
#endif
|
||||
#include <termios.h>
|
||||
#include <err.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <syslog.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SETCON
|
||||
@@ -54,11 +57,11 @@
|
||||
const unsigned char raw_header[RAW_HDR_LEN] = { 0x10, 0xd1, 0x9e, 0x00 };
|
||||
|
||||
/* daemon(3) exists only in 4.4BSD or later, and in GNU libc */
|
||||
#if !defined(WINDOWS32) && !(defined(BSD) && (BSD >= 199306)) && !defined(__GLIBC__) && !defined(__ANDROID__)
|
||||
#if !defined(ANDROID) && !defined(WINDOWS32) && !(defined(BSD) && (BSD >= 199306)) && !defined(__GLIBC__)
|
||||
static int daemon(int nochdir, int noclose)
|
||||
{
|
||||
int fd, i;
|
||||
|
||||
|
||||
switch (fork()) {
|
||||
case 0:
|
||||
break;
|
||||
@@ -67,15 +70,15 @@ static int daemon(int nochdir, int noclose)
|
||||
default:
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
|
||||
if (!nochdir) {
|
||||
chdir("/");
|
||||
}
|
||||
|
||||
|
||||
if (setsid() < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!noclose) {
|
||||
if ((fd = open("/dev/null", O_RDWR)) >= 0) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
@@ -111,21 +114,69 @@ check_superuser(void (*usage_fn)(void))
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
open_dns(int localport, in_addr_t listen_ip)
|
||||
char *
|
||||
format_addr(struct sockaddr_storage *sockaddr, int sockaddr_len)
|
||||
{
|
||||
static char dst[INET6_ADDRSTRLEN + 1];
|
||||
|
||||
memset(dst, 0, sizeof(dst));
|
||||
if (sockaddr->ss_family == AF_INET && sockaddr_len >= sizeof(struct sockaddr_in)) {
|
||||
getnameinfo((struct sockaddr *)sockaddr, sockaddr_len, dst, sizeof(dst) - 1, NULL, 0, NI_NUMERICHOST);
|
||||
} else if (sockaddr->ss_family == AF_INET6 && sockaddr_len >= sizeof(struct sockaddr_in6)) {
|
||||
struct sockaddr_in6 *addr = (struct sockaddr_in6 *) sockaddr;
|
||||
if (IN6_IS_ADDR_V4MAPPED(&addr->sin6_addr)) {
|
||||
struct in_addr ia;
|
||||
/* Get mapped v4 addr from last 32bit field */
|
||||
memcpy(&ia.s_addr, &addr->sin6_addr.s6_addr[12], sizeof(ia));
|
||||
strcpy(dst, inet_ntoa(ia));
|
||||
} else {
|
||||
getnameinfo((struct sockaddr *)sockaddr, sockaddr_len, dst, sizeof(dst) - 1, NULL, 0, NI_NUMERICHOST);
|
||||
}
|
||||
} else {
|
||||
dst[0] = '?';
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
int
|
||||
get_addr(char *host, int port, int addr_family, int flags, struct sockaddr_storage *out)
|
||||
{
|
||||
struct addrinfo hints, *addr;
|
||||
int res;
|
||||
char portnum[8];
|
||||
|
||||
memset(portnum, 0, sizeof(portnum));
|
||||
snprintf(portnum, sizeof(portnum) - 1, "%d", port);
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = addr_family;
|
||||
#if defined(WINDOWS32) || defined(OPENBSD)
|
||||
/* AI_ADDRCONFIG misbehaves on windows, and does not exist in OpenBSD */
|
||||
hints.ai_flags = flags;
|
||||
#else
|
||||
hints.ai_flags = AI_ADDRCONFIG | flags;
|
||||
#endif
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
hints.ai_protocol = IPPROTO_UDP;
|
||||
|
||||
res = getaddrinfo(host, portnum, &hints, &addr);
|
||||
if (res == 0) {
|
||||
int addrlen = addr->ai_addrlen;
|
||||
/* Grab first result */
|
||||
memcpy(out, addr->ai_addr, addr->ai_addrlen);
|
||||
freeaddrinfo(addr);
|
||||
return addrlen;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int
|
||||
open_dns(struct sockaddr_storage *sockaddr, size_t sockaddr_len)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
int flag = 1;
|
||||
int fd;
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(localport);
|
||||
/* listen_ip already in network byte order from inet_addr, or 0 */
|
||||
addr.sin_addr.s_addr = listen_ip;
|
||||
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
||||
fprintf(stderr, "got fd %d\n", fd);
|
||||
if ((fd = socket(sockaddr->ss_family, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
||||
err(1, "socket");
|
||||
}
|
||||
|
||||
@@ -138,6 +189,8 @@ open_dns(int localport, in_addr_t listen_ip)
|
||||
#ifndef WINDOWS32
|
||||
/* To get destination address from each UDP datagram, see iodined.c:read_dns() */
|
||||
setsockopt(fd, IPPROTO_IP, DSTADDR_SOCKOPT, (const void*) &flag, sizeof(flag));
|
||||
|
||||
fd_set_close_on_exec(fd);
|
||||
#endif
|
||||
|
||||
#ifdef IP_OPT_DONT_FRAG
|
||||
@@ -146,14 +199,27 @@ open_dns(int localport, in_addr_t listen_ip)
|
||||
setsockopt(fd, IPPROTO_IP, IP_OPT_DONT_FRAG, (const void*) &flag, sizeof(flag));
|
||||
#endif
|
||||
|
||||
if(bind(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0)
|
||||
if(bind(fd, (struct sockaddr*) sockaddr, sockaddr_len) < 0)
|
||||
err(1, "bind");
|
||||
|
||||
fprintf(stderr, "Opened UDP socket\n");
|
||||
fprintf(stderr, "Opened IPv%d UDP socket\n", sockaddr->ss_family == AF_INET6 ? 6 : 4);
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
int
|
||||
open_dns_from_host(char *host, int port, int addr_family, int flags)
|
||||
{
|
||||
struct sockaddr_storage addr;
|
||||
int addrlen;
|
||||
|
||||
addrlen = get_addr(host, port, addr_family, flags, &addr);
|
||||
if (addrlen < 0)
|
||||
return addrlen;
|
||||
|
||||
return open_dns(&addr, addrlen);
|
||||
}
|
||||
|
||||
void
|
||||
close_dns(int fd)
|
||||
{
|
||||
@@ -167,8 +233,9 @@ do_chroot(char *newroot)
|
||||
if (chroot(newroot) != 0 || chdir("/") != 0)
|
||||
err(1, "%s", newroot);
|
||||
|
||||
seteuid(geteuid());
|
||||
setuid(getuid());
|
||||
if (seteuid(geteuid()) != 0 || setuid(getuid()) != 0) {
|
||||
err(1, "set[e]uid()");
|
||||
}
|
||||
#else
|
||||
warnx("chroot not available");
|
||||
#endif
|
||||
@@ -219,14 +286,14 @@ do_detach()
|
||||
void
|
||||
read_password(char *buf, size_t len)
|
||||
{
|
||||
char pwd[80];
|
||||
char pwd[80] = {0};
|
||||
#ifndef WINDOWS32
|
||||
struct termios old;
|
||||
struct termios tp;
|
||||
|
||||
tcgetattr(0, &tp);
|
||||
old = tp;
|
||||
|
||||
|
||||
tp.c_lflag &= (~ECHO);
|
||||
tcsetattr(0, TCSANOW, &tp);
|
||||
#else
|
||||
@@ -236,7 +303,7 @@ read_password(char *buf, size_t len)
|
||||
fprintf(stderr, "Enter password: ");
|
||||
fflush(stderr);
|
||||
#ifndef WINDOWS32
|
||||
scanf("%79s", pwd);
|
||||
fscanf(stdin, "%79[^\n]", pwd);
|
||||
#else
|
||||
for (i = 0; i < sizeof(pwd); i++) {
|
||||
pwd[i] = getch();
|
||||
@@ -252,7 +319,7 @@ read_password(char *buf, size_t len)
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
#ifndef WINDOWS32
|
||||
tcsetattr(0, TCSANOW, &old);
|
||||
tcsetattr(0, TCSANOW, &old);
|
||||
#endif
|
||||
|
||||
strncpy(buf, pwd, len);
|
||||
@@ -260,29 +327,75 @@ read_password(char *buf, size_t len)
|
||||
}
|
||||
|
||||
int
|
||||
check_topdomain(char *str)
|
||||
check_topdomain(char *str, char **errormsg)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
int dots = 0;
|
||||
int chunklen = 0;
|
||||
|
||||
if(str[0] == '.') /* special case */
|
||||
return 1;
|
||||
if (strlen(str) < 3) {
|
||||
if (errormsg) *errormsg = "Too short (< 3)";
|
||||
return 1;
|
||||
}
|
||||
if (strlen(str) > 128) {
|
||||
if (errormsg) *errormsg = "Too long (> 128)";
|
||||
return 1;
|
||||
}
|
||||
|
||||
for( i = 0; i < strlen(str); i++) {
|
||||
if( isalpha(str[i]) || isdigit(str[i]) || str[i] == '-' || str[i] == '.' )
|
||||
continue;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
if (str[0] == '.') {
|
||||
if (errormsg) *errormsg = "Starts with a dot";
|
||||
return 1;
|
||||
}
|
||||
|
||||
for( i = 0; i < strlen(str); i++) {
|
||||
if(str[i] == '.') {
|
||||
dots++;
|
||||
if (chunklen == 0) {
|
||||
if (errormsg) *errormsg = "Consecutive dots";
|
||||
return 1;
|
||||
}
|
||||
if (chunklen > 63) {
|
||||
if (errormsg) *errormsg = "Too long domain part (> 63)";
|
||||
return 1;
|
||||
}
|
||||
chunklen = 0;
|
||||
} else {
|
||||
chunklen++;
|
||||
}
|
||||
if( (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') ||
|
||||
isdigit(str[i]) || str[i] == '-' || str[i] == '.' ) {
|
||||
continue;
|
||||
} else {
|
||||
if (errormsg) *errormsg = "Contains illegal character (allowed: [a-zA-Z0-9-.])";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (dots == 0) {
|
||||
if (errormsg) *errormsg = "No dots";
|
||||
return 1;
|
||||
}
|
||||
if (chunklen == 0) {
|
||||
if (errormsg) *errormsg = "Ends with a dot";
|
||||
return 1;
|
||||
}
|
||||
if (chunklen > 63) {
|
||||
if (errormsg) *errormsg = "Too long domain part (> 63)";
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(WINDOWS32)
|
||||
#if defined(WINDOWS32) || defined(ANDROID)
|
||||
#ifndef ANDROID
|
||||
int
|
||||
inet_aton(const char *cp, struct in_addr *inp)
|
||||
{
|
||||
inp->s_addr = inet_addr(cp);
|
||||
return inp->s_addr != INADDR_ANY;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
warn(const char *fmt, ...)
|
||||
@@ -291,45 +404,16 @@ warn(const char *fmt, ...)
|
||||
|
||||
va_start(list, fmt);
|
||||
if (fmt) fprintf(stderr, fmt, list);
|
||||
#ifndef ANDROID
|
||||
if (errno == 0) {
|
||||
fprintf(stderr, ": WSA error %d\n", WSAGetLastError());
|
||||
fprintf(stderr, ": WSA error %d\n", WSAGetLastError());
|
||||
} else {
|
||||
fprintf(stderr, ": %s\n", strerror(errno));
|
||||
}
|
||||
va_end(list);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __ANDROID__
|
||||
|
||||
void android_printf(const char *fmt, ...)
|
||||
{
|
||||
static char buf[1024];
|
||||
va_list list;
|
||||
va_start(list, fmt);
|
||||
|
||||
snprintf(buf,1024,fmt,list);
|
||||
|
||||
android_log_callback(buf);
|
||||
|
||||
va_end(list);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
warn(const char *fmt, ...)
|
||||
{
|
||||
va_list list;
|
||||
|
||||
va_start(list, fmt);
|
||||
if (fmt) fprintf(stderr, fmt, list);
|
||||
if (errno != 0)
|
||||
fprintf(stderr, ": %s\n", strerror(errno));
|
||||
va_end(list);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(WINDOWS32) || defined(__ANDROID__)
|
||||
void
|
||||
warnx(const char *fmt, ...)
|
||||
{
|
||||
@@ -364,6 +448,23 @@ errx(int eval, const char *fmt, ...)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
void android_log_callback(const char *);
|
||||
static char printf_buf[1024];;
|
||||
void android_printf(const char *fmt, ...)
|
||||
{
|
||||
va_list list;
|
||||
va_start(list, fmt);
|
||||
|
||||
vsnprintf(printf_buf,1024,fmt,list);
|
||||
android_log_callback(printf_buf);
|
||||
|
||||
__android_log_vprint(ANDROID_LOG_INFO, "Iodine",
|
||||
fmt, list);
|
||||
va_end(list);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int recent_seqno(int ourseqno, int gotseqno)
|
||||
/* Return 1 if we've seen gotseqno recently (current or up to 3 back).
|
||||
@@ -379,3 +480,22 @@ int recent_seqno(int ourseqno, int gotseqno)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef WINDOWS32
|
||||
/* Set FD_CLOEXEC flag on file descriptor.
|
||||
* This stops it from being inherited by system() calls.
|
||||
*/
|
||||
void
|
||||
fd_set_close_on_exec(int fd)
|
||||
{
|
||||
int flags;
|
||||
|
||||
flags = fcntl(fd, F_GETFD);
|
||||
if (flags == -1)
|
||||
err(4, "Failed to get fd flags");
|
||||
flags |= FD_CLOEXEC;
|
||||
if (fcntl(fd, F_SETFD, flags) == -1)
|
||||
err(4, "Failed to set fd flags");
|
||||
}
|
||||
#endif
|
||||
|
||||
+30
-23
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -37,8 +38,8 @@ extern const unsigned char raw_header[RAW_HDR_LEN];
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <err.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#define DNS_PORT 53
|
||||
@@ -52,12 +53,12 @@ extern const unsigned char raw_header[RAW_HDR_LEN];
|
||||
|
||||
#define QUERY_NAME_SIZE 256
|
||||
|
||||
#if defined IP_RECVDSTADDR
|
||||
# define DSTADDR_SOCKOPT IP_RECVDSTADDR
|
||||
# define dstaddr(x) ((struct in_addr *) CMSG_DATA(x))
|
||||
#elif defined IP_PKTINFO
|
||||
# define DSTADDR_SOCKOPT IP_PKTINFO
|
||||
# define dstaddr(x) (&(((struct in_pktinfo *)(CMSG_DATA(x)))->ipi_addr))
|
||||
#if defined IP_RECVDSTADDR
|
||||
# define DSTADDR_SOCKOPT IP_RECVDSTADDR
|
||||
# define dstaddr(x) ((struct in_addr *) CMSG_DATA(x))
|
||||
#elif defined IP_PKTINFO
|
||||
# define DSTADDR_SOCKOPT IP_PKTINFO
|
||||
# define dstaddr(x) (&(((struct in_pktinfo *)(CMSG_DATA(x)))->ipi_addr))
|
||||
#endif
|
||||
|
||||
#if defined IP_MTU_DISCOVER
|
||||
@@ -74,10 +75,12 @@ extern const unsigned char raw_header[RAW_HDR_LEN];
|
||||
# define DONT_FRAG_VALUE 1
|
||||
#endif
|
||||
|
||||
#define T_PRIVATE 65399
|
||||
/* Undefined RR type; "private use" range, see http://www.bind9.net/dns-parameters */
|
||||
#define T_UNSET 65432
|
||||
/* Unused RR type; "private use" range, see http://www.bind9.net/dns-parameters */
|
||||
/* Unused RR type, never actually sent */
|
||||
|
||||
struct packet
|
||||
struct packet
|
||||
{
|
||||
int len; /* Total packet length */
|
||||
int sentlen; /* Length of chunk currently transmitted */
|
||||
@@ -93,7 +96,7 @@ struct query {
|
||||
unsigned short rcode;
|
||||
unsigned short id;
|
||||
struct in_addr destination;
|
||||
struct sockaddr from;
|
||||
struct sockaddr_storage from;
|
||||
int fromlen;
|
||||
unsigned short id2;
|
||||
struct sockaddr from2;
|
||||
@@ -107,7 +110,10 @@ enum connection {
|
||||
};
|
||||
|
||||
void check_superuser(void (*usage_fn)(void));
|
||||
int open_dns(int, in_addr_t);
|
||||
char *format_addr(struct sockaddr_storage *sockaddr, int sockaddr_len);
|
||||
int get_addr(char *, int, int, int, struct sockaddr_storage *);
|
||||
int open_dns(struct sockaddr_storage *, size_t);
|
||||
int open_dns_from_host(char *host, int port, int addr_family, int flags);
|
||||
void close_dns(int);
|
||||
|
||||
void do_chroot(char *);
|
||||
@@ -117,24 +123,21 @@ void do_pidfile(char *);
|
||||
|
||||
void read_password(char*, size_t);
|
||||
|
||||
int check_topdomain(char *);
|
||||
int check_topdomain(char *, char **);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
//#define printf(...) __android_log_print(ANDROID_LOG_DEBUG, "iodine", __VA_ARGS__)
|
||||
#include <android/log.h>
|
||||
|
||||
#define printf(...) android_printf(__VA_ARGS__)
|
||||
#define fprintf(egal,...) android_printf(__VA_ARGS__)
|
||||
|
||||
void android_printf(const char *fmt, ...);
|
||||
#endif
|
||||
|
||||
|
||||
#define fprintf(__fd_unused, ...) printf(__VA_ARGS__)
|
||||
|
||||
#include <android/log.h>
|
||||
void err(int eval, const char *fmt, ...);
|
||||
void warn(const char *fmt, ...);
|
||||
void errx(int eval, const char *fmt, ...);
|
||||
void warnx(const char *fmt, ...);
|
||||
#elif WINDOWS32
|
||||
#if defined(WINDOWS32) || defined(ANDROID)
|
||||
#ifndef ANDROID
|
||||
int inet_aton(const char *cp, struct in_addr *inp);
|
||||
#endif
|
||||
|
||||
void err(int eval, const char *fmt, ...);
|
||||
void warn(const char *fmt, ...);
|
||||
@@ -144,4 +147,8 @@ void warnx(const char *fmt, ...);
|
||||
|
||||
int recent_seqno(int , int);
|
||||
|
||||
#ifndef WINDOWS32
|
||||
void fd_set_close_on_exec(int fd);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+45
-41
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -20,16 +21,21 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef WINDOWS32
|
||||
#include "windows.h"
|
||||
#else
|
||||
#if defined(ANDROID) || defined(__ANDROID__)
|
||||
#include "android_dns.h"
|
||||
#endif
|
||||
#include <arpa/nameser.h>
|
||||
#ifdef DARWIN
|
||||
#define BIND_8_COMPAT
|
||||
#include <arpa/nameser_compat.h>
|
||||
#endif
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <err.h>
|
||||
#endif
|
||||
@@ -41,7 +47,7 @@
|
||||
|
||||
int dnsc_use_edns0 = 1;
|
||||
|
||||
#define CHECKLEN(x) if (buflen - (p-buf) < (x)) return 0
|
||||
#define CHECKLEN(x) if (buflen < (x) + (unsigned)(p-buf)) return 0
|
||||
|
||||
int
|
||||
dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_t datalen)
|
||||
@@ -56,9 +62,9 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||
return 0;
|
||||
|
||||
memset(buf, 0, buflen);
|
||||
|
||||
|
||||
header = (HEADER*)buf;
|
||||
|
||||
|
||||
header->id = htons(q->id);
|
||||
header->qr = (qr == QR_ANSWER);
|
||||
header->opcode = 0;
|
||||
@@ -72,7 +78,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||
switch (qr) {
|
||||
case QR_ANSWER:
|
||||
header->qdcount = htons(1);
|
||||
|
||||
|
||||
name = 0xc000 | ((p - buf) & 0x3fff);
|
||||
|
||||
/* Question section */
|
||||
@@ -91,7 +97,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||
int namelen;
|
||||
|
||||
CHECKLEN(10);
|
||||
putshort(&p, name);
|
||||
putshort(&p, name);
|
||||
if (q->type == T_A)
|
||||
/* answer CNAME to A question */
|
||||
putshort(&p, T_CNAME);
|
||||
@@ -121,7 +127,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||
ancnt = 1;
|
||||
while (1) {
|
||||
CHECKLEN(10);
|
||||
putshort(&p, name);
|
||||
putshort(&p, name);
|
||||
putshort(&p, q->type);
|
||||
putshort(&p, C_IN);
|
||||
putlong(&p, 0); /* TTL */
|
||||
@@ -156,7 +162,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||
int txtlen;
|
||||
|
||||
CHECKLEN(10);
|
||||
putshort(&p, name);
|
||||
putshort(&p, name);
|
||||
putshort(&p, q->type);
|
||||
putshort(&p, C_IN);
|
||||
putlong(&p, 0); /* TTL */
|
||||
@@ -173,7 +179,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||
/* NULL has raw binary data */
|
||||
|
||||
CHECKLEN(10);
|
||||
putshort(&p, name);
|
||||
putshort(&p, name);
|
||||
putshort(&p, q->type);
|
||||
putshort(&p, C_IN);
|
||||
putlong(&p, 0); /* TTL */
|
||||
@@ -192,7 +198,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||
/* Note that iodined also uses this for forward queries */
|
||||
|
||||
header->qdcount = htons(1);
|
||||
|
||||
|
||||
datalen = MIN(datalen, buflen - (p - buf));
|
||||
putname(&p, datalen, data);
|
||||
|
||||
@@ -204,20 +210,18 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||
(even CNAME/A/MX, 255+255+header would be >512) */
|
||||
if (dnsc_use_edns0) {
|
||||
header->arcount = htons(1);
|
||||
/*XXX START adjust indent 1 tab forward*/
|
||||
CHECKLEN(11);
|
||||
putbyte(&p, 0x00); /* Root */
|
||||
putshort(&p, 0x0029); /* OPT */
|
||||
putshort(&p, 0x1000); /* Payload size: 4096 */
|
||||
putshort(&p, 0x0000); /* Higher bits/edns version */
|
||||
putshort(&p, 0x8000); /* Z */
|
||||
putshort(&p, 0x0000); /* Data length */
|
||||
/*XXX END adjust indent 1 tab forward*/
|
||||
CHECKLEN(11);
|
||||
putbyte(&p, 0x00); /* Root */
|
||||
putshort(&p, 0x0029); /* OPT */
|
||||
putshort(&p, 0x1000); /* Payload size: 4096 */
|
||||
putshort(&p, 0x0000); /* Higher bits/edns version */
|
||||
putshort(&p, 0x8000); /* Z */
|
||||
putshort(&p, 0x0000); /* Data length */
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
len = p - buf;
|
||||
|
||||
return len;
|
||||
@@ -241,9 +245,9 @@ dns_encode_ns_response(char *buf, size_t buflen, struct query *q, char *topdomai
|
||||
return 0;
|
||||
|
||||
memset(buf, 0, buflen);
|
||||
|
||||
|
||||
header = (HEADER*)buf;
|
||||
|
||||
|
||||
header->id = htons(q->id);
|
||||
header->qr = 1;
|
||||
header->opcode = 0;
|
||||
@@ -330,9 +334,9 @@ dns_encode_a_response(char *buf, size_t buflen, struct query *q)
|
||||
return 0;
|
||||
|
||||
memset(buf, 0, buflen);
|
||||
|
||||
|
||||
header = (HEADER*)buf;
|
||||
|
||||
|
||||
header->id = htons(q->id);
|
||||
header->qr = 1;
|
||||
header->opcode = 0;
|
||||
@@ -389,7 +393,7 @@ dns_get_id(char *packet, size_t packetlen)
|
||||
return ntohs(header->id);
|
||||
}
|
||||
|
||||
#define CHECKLEN(x) if (packetlen - (data-packet) < (x)) return 0
|
||||
#define CHECKLEN(x) if (packetlen < (x) + (unsigned)(data-packet)) return 0
|
||||
|
||||
int
|
||||
dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, size_t packetlen)
|
||||
@@ -400,11 +404,11 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||
short qdcount;
|
||||
short ancount;
|
||||
uint32_t ttl;
|
||||
short class;
|
||||
short type;
|
||||
unsigned short class;
|
||||
unsigned short type;
|
||||
char *data;
|
||||
short rlen;
|
||||
int id;
|
||||
unsigned short rlen;
|
||||
int id;
|
||||
int rv;
|
||||
|
||||
q->id2 = 0;
|
||||
@@ -412,9 +416,9 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||
header = (HEADER*)packet;
|
||||
|
||||
/* Reject short packets */
|
||||
if (packetlen < sizeof(HEADER))
|
||||
if (packetlen < sizeof(HEADER))
|
||||
return 0;
|
||||
|
||||
|
||||
if (header->qr != qr) {
|
||||
warnx("header->qr does not match the requested qr");
|
||||
return -1;
|
||||
@@ -423,13 +427,13 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||
data = packet + sizeof(HEADER);
|
||||
qdcount = ntohs(header->qdcount);
|
||||
ancount = ntohs(header->ancount);
|
||||
|
||||
|
||||
id = ntohs(header->id);
|
||||
id = id & 0xFFFF; /* Kill any sign extension */
|
||||
|
||||
|
||||
rlen = 0;
|
||||
|
||||
if (q != NULL)
|
||||
if (q != NULL)
|
||||
q->rcode = header->rcode;
|
||||
|
||||
switch (qr) {
|
||||
@@ -439,7 +443,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (q != NULL)
|
||||
if (q != NULL)
|
||||
q->id = id;
|
||||
|
||||
/* Read name even if no answer, to give better error message */
|
||||
@@ -447,14 +451,14 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||
CHECKLEN(4);
|
||||
readshort(packet, &data, &type);
|
||||
readshort(packet, &data, &class);
|
||||
|
||||
|
||||
/* if CHECKLEN okay, then we're sure to have a proper name */
|
||||
if (q != NULL) {
|
||||
/* We only need the first char to check it */
|
||||
q->name[0] = name[0];
|
||||
q->name[1] = '\0';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ancount < 1) {
|
||||
/* DNS errors like NXDOMAIN have ancount=0 and
|
||||
stop here. CNAME may also have A; MX/SRV may have
|
||||
@@ -463,7 +467,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||
}
|
||||
|
||||
/* Here type is still the question type */
|
||||
if (type == T_NULL) {
|
||||
if (type == T_NULL || type == T_PRIVATE) {
|
||||
/* Assume that first answer is what we wanted */
|
||||
readname(packet, packetlen, &data, name, sizeof(name));
|
||||
CHECKLEN(10);
|
||||
@@ -505,7 +509,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||
*/
|
||||
char names[250][QUERY_NAME_SIZE];
|
||||
char *rdatastart;
|
||||
short pref;
|
||||
unsigned short pref;
|
||||
int i;
|
||||
int offset;
|
||||
|
||||
@@ -535,7 +539,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||
names[pref / 10 - 1][QUERY_NAME_SIZE-1] = '\0';
|
||||
}
|
||||
|
||||
/* always trust rlen, not name encoding */
|
||||
/* always trust rlen, not name encoding */
|
||||
data = rdatastart + rlen;
|
||||
CHECKLEN(0);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -32,8 +33,4 @@ int dns_encode_a_response(char *buf, size_t buflen, struct query *q);
|
||||
unsigned short dns_get_id(char *packet, size_t packetlen);
|
||||
int dns_decode(char *, size_t, struct query *, qr_t, char *, size_t);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include "dns_android.h"
|
||||
#endif
|
||||
|
||||
#endif /* _DNS_H_ */
|
||||
@@ -1,625 +0,0 @@
|
||||
/* This file is modified to serve minimal requirements of iodine */
|
||||
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1996-1999 by Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $BINDId: nameser.h,v 8.37 2000/03/30 21:16:49 vixie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _ARPA_NAMESER_H_
|
||||
#define _ARPA_NAMESER_H_
|
||||
|
||||
/*%
|
||||
* Revision information. This is the release date in YYYYMMDD format.
|
||||
* It can change every day so the right thing to do with it is use it
|
||||
* in preprocessor commands such as "#if (__NAMESER > 19931104)". Do not
|
||||
* compare for equality; rather, use it to determine whether your libbind.a
|
||||
* contains a new enough lib/nameser/ to support the feature you need.
|
||||
*/
|
||||
|
||||
#define __NAMESER 19991006 /*%< New interface version stamp. */
|
||||
/*
|
||||
* Define constants based on RFC 883, RFC 1034, RFC 1035
|
||||
*/
|
||||
#define NS_PACKETSZ 512 /*%< default UDP packet size */
|
||||
#define NS_MAXDNAME 1025 /*%< maximum domain name */
|
||||
#define NS_MAXMSG 65535 /*%< maximum message size */
|
||||
#define NS_MAXCDNAME 255 /*%< maximum compressed domain name */
|
||||
#define NS_MAXLABEL 63 /*%< maximum length of domain label */
|
||||
#define NS_HFIXEDSZ 12 /*%< #/bytes of fixed data in header */
|
||||
#define NS_QFIXEDSZ 4 /*%< #/bytes of fixed data in query */
|
||||
#define NS_RRFIXEDSZ 10 /*%< #/bytes of fixed data in r record */
|
||||
#define NS_INT32SZ 4 /*%< #/bytes of data in a u_int32_t */
|
||||
#define NS_INT16SZ 2 /*%< #/bytes of data in a u_int16_t */
|
||||
#define NS_INT8SZ 1 /*%< #/bytes of data in a u_int8_t */
|
||||
#define NS_INADDRSZ 4 /*%< IPv4 T_A */
|
||||
#define NS_IN6ADDRSZ 16 /*%< IPv6 T_AAAA */
|
||||
#define NS_CMPRSFLGS 0xc0 /*%< Flag bits indicating name compression. */
|
||||
#define NS_DEFAULTPORT 53 /*%< For both TCP and UDP. */
|
||||
/*
|
||||
* These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord()
|
||||
* in synch with it.
|
||||
*/
|
||||
typedef enum __ns_sect {
|
||||
ns_s_qd = 0, /*%< Query: Question. */
|
||||
ns_s_zn = 0, /*%< Update: Zone. */
|
||||
ns_s_an = 1, /*%< Query: Answer. */
|
||||
ns_s_pr = 1, /*%< Update: Prerequisites. */
|
||||
ns_s_ns = 2, /*%< Query: Name servers. */
|
||||
ns_s_ud = 2, /*%< Update: Update. */
|
||||
ns_s_ar = 3, /*%< Query|Update: Additional records. */
|
||||
ns_s_max = 4
|
||||
} ns_sect;
|
||||
|
||||
/*%
|
||||
* This is a message handle. It is caller allocated and has no dynamic data.
|
||||
* This structure is intended to be opaque to all but ns_parse.c, thus the
|
||||
* leading _'s on the member names. Use the accessor functions, not the _'s.
|
||||
*/
|
||||
typedef struct __ns_msg {
|
||||
const u_char *_msg, *_eom;
|
||||
u_int16_t _id, _flags, _counts[ns_s_max];
|
||||
const u_char *_sections[ns_s_max];
|
||||
ns_sect _sect;
|
||||
int _rrnum;
|
||||
const u_char *_msg_ptr;
|
||||
} ns_msg;
|
||||
|
||||
/* Private data structure - do not use from outside library. */
|
||||
struct _ns_flagdata { int mask, shift; };
|
||||
extern const struct _ns_flagdata _ns_flagdata[];
|
||||
|
||||
/* Accessor macros - this is part of the public interface. */
|
||||
|
||||
#define ns_msg_id(handle) ((handle)._id + 0)
|
||||
#define ns_msg_base(handle) ((handle)._msg + 0)
|
||||
#define ns_msg_end(handle) ((handle)._eom + 0)
|
||||
#define ns_msg_size(handle) ((handle)._eom - (handle)._msg)
|
||||
#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
|
||||
|
||||
/*%
|
||||
* This is a parsed record. It is caller allocated and has no dynamic data.
|
||||
*/
|
||||
typedef struct __ns_rr {
|
||||
char name[NS_MAXDNAME];
|
||||
u_int16_t type;
|
||||
u_int16_t rr_class;
|
||||
u_int32_t ttl;
|
||||
u_int16_t rdlength;
|
||||
const u_char * rdata;
|
||||
} ns_rr;
|
||||
|
||||
/* Accessor macros - this is part of the public interface. */
|
||||
#define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".")
|
||||
#define ns_rr_type(rr) ((ns_type)((rr).type + 0))
|
||||
#define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0))
|
||||
#define ns_rr_ttl(rr) ((rr).ttl + 0)
|
||||
#define ns_rr_rdlen(rr) ((rr).rdlength + 0)
|
||||
#define ns_rr_rdata(rr) ((rr).rdata + 0)
|
||||
|
||||
/*%
|
||||
* These don't have to be in the same order as in the packet flags word,
|
||||
* and they can even overlap in some cases, but they will need to be kept
|
||||
* in synch with ns_parse.c:ns_flagdata[].
|
||||
*/
|
||||
typedef enum __ns_flag {
|
||||
ns_f_qr, /*%< Question/Response. */
|
||||
ns_f_opcode, /*%< Operation code. */
|
||||
ns_f_aa, /*%< Authoritative Answer. */
|
||||
ns_f_tc, /*%< Truncation occurred. */
|
||||
ns_f_rd, /*%< Recursion Desired. */
|
||||
ns_f_ra, /*%< Recursion Available. */
|
||||
ns_f_z, /*%< MBZ. */
|
||||
ns_f_ad, /*%< Authentic Data (DNSSEC). */
|
||||
ns_f_cd, /*%< Checking Disabled (DNSSEC). */
|
||||
ns_f_rcode, /*%< Response code. */
|
||||
ns_f_max
|
||||
} ns_flag;
|
||||
|
||||
/*%
|
||||
* Currently defined opcodes.
|
||||
*/
|
||||
typedef enum __ns_opcode {
|
||||
ns_o_query = 0, /*%< Standard query. */
|
||||
ns_o_iquery = 1, /*%< Inverse query (deprecated/unsupported). */
|
||||
ns_o_status = 2, /*%< Name server status query (unsupported). */
|
||||
/* Opcode 3 is undefined/reserved. */
|
||||
ns_o_notify = 4, /*%< Zone change notification. */
|
||||
ns_o_update = 5, /*%< Zone update message. */
|
||||
ns_o_max = 6
|
||||
} ns_opcode;
|
||||
|
||||
/*%
|
||||
* Currently defined response codes.
|
||||
*/
|
||||
typedef enum __ns_rcode {
|
||||
ns_r_noerror = 0, /*%< No error occurred. */
|
||||
ns_r_formerr = 1, /*%< Format error. */
|
||||
ns_r_servfail = 2, /*%< Server failure. */
|
||||
ns_r_nxdomain = 3, /*%< Name error. */
|
||||
ns_r_notimpl = 4, /*%< Unimplemented. */
|
||||
ns_r_refused = 5, /*%< Operation refused. */
|
||||
/* these are for BIND_UPDATE */
|
||||
ns_r_yxdomain = 6, /*%< Name exists */
|
||||
ns_r_yxrrset = 7, /*%< RRset exists */
|
||||
ns_r_nxrrset = 8, /*%< RRset does not exist */
|
||||
ns_r_notauth = 9, /*%< Not authoritative for zone */
|
||||
ns_r_notzone = 10, /*%< Zone of record different from zone section */
|
||||
ns_r_max = 11,
|
||||
/* The following are EDNS extended rcodes */
|
||||
ns_r_badvers = 16,
|
||||
/* The following are TSIG errors */
|
||||
ns_r_badsig = 16,
|
||||
ns_r_badkey = 17,
|
||||
ns_r_badtime = 18
|
||||
} ns_rcode;
|
||||
|
||||
/* BIND_UPDATE */
|
||||
typedef enum __ns_update_operation {
|
||||
ns_uop_delete = 0,
|
||||
ns_uop_add = 1,
|
||||
ns_uop_max = 2
|
||||
} ns_update_operation;
|
||||
|
||||
/*%
|
||||
* This structure is used for TSIG authenticated messages
|
||||
*/
|
||||
struct ns_tsig_key {
|
||||
char name[NS_MAXDNAME], alg[NS_MAXDNAME];
|
||||
unsigned char *data;
|
||||
int len;
|
||||
};
|
||||
typedef struct ns_tsig_key ns_tsig_key;
|
||||
|
||||
/*%
|
||||
* This structure is used for TSIG authenticated TCP messages
|
||||
*/
|
||||
struct ns_tcp_tsig_state {
|
||||
int counter;
|
||||
struct dst_key *key;
|
||||
void *ctx;
|
||||
unsigned char sig[NS_PACKETSZ];
|
||||
int siglen;
|
||||
};
|
||||
typedef struct ns_tcp_tsig_state ns_tcp_tsig_state;
|
||||
|
||||
#define NS_TSIG_FUDGE 300
|
||||
#define NS_TSIG_TCP_COUNT 100
|
||||
#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"
|
||||
|
||||
#define NS_TSIG_ERROR_NO_TSIG -10
|
||||
#define NS_TSIG_ERROR_NO_SPACE -11
|
||||
#define NS_TSIG_ERROR_FORMERR -12
|
||||
|
||||
/*%
|
||||
* Currently defined type values for resources and queries.
|
||||
*/
|
||||
typedef enum __ns_type {
|
||||
ns_t_invalid = 0, /*%< Cookie. */
|
||||
ns_t_a = 1, /*%< Host address. */
|
||||
ns_t_ns = 2, /*%< Authoritative server. */
|
||||
ns_t_md = 3, /*%< Mail destination. */
|
||||
ns_t_mf = 4, /*%< Mail forwarder. */
|
||||
ns_t_cname = 5, /*%< Canonical name. */
|
||||
ns_t_soa = 6, /*%< Start of authority zone. */
|
||||
ns_t_mb = 7, /*%< Mailbox domain name. */
|
||||
ns_t_mg = 8, /*%< Mail group member. */
|
||||
ns_t_mr = 9, /*%< Mail rename name. */
|
||||
ns_t_null = 10, /*%< Null resource record. */
|
||||
ns_t_wks = 11, /*%< Well known service. */
|
||||
ns_t_ptr = 12, /*%< Domain name pointer. */
|
||||
ns_t_hinfo = 13, /*%< Host information. */
|
||||
ns_t_minfo = 14, /*%< Mailbox information. */
|
||||
ns_t_mx = 15, /*%< Mail routing information. */
|
||||
ns_t_txt = 16, /*%< Text strings. */
|
||||
ns_t_rp = 17, /*%< Responsible person. */
|
||||
ns_t_afsdb = 18, /*%< AFS cell database. */
|
||||
ns_t_x25 = 19, /*%< X_25 calling address. */
|
||||
ns_t_isdn = 20, /*%< ISDN calling address. */
|
||||
ns_t_rt = 21, /*%< Router. */
|
||||
ns_t_nsap = 22, /*%< NSAP address. */
|
||||
ns_t_nsap_ptr = 23, /*%< Reverse NSAP lookup (deprecated). */
|
||||
ns_t_sig = 24, /*%< Security signature. */
|
||||
ns_t_key = 25, /*%< Security key. */
|
||||
ns_t_px = 26, /*%< X.400 mail mapping. */
|
||||
ns_t_gpos = 27, /*%< Geographical position (withdrawn). */
|
||||
ns_t_aaaa = 28, /*%< Ip6 Address. */
|
||||
ns_t_loc = 29, /*%< Location Information. */
|
||||
ns_t_nxt = 30, /*%< Next domain (security). */
|
||||
ns_t_eid = 31, /*%< Endpoint identifier. */
|
||||
ns_t_nimloc = 32, /*%< Nimrod Locator. */
|
||||
ns_t_srv = 33, /*%< Server Selection. */
|
||||
ns_t_atma = 34, /*%< ATM Address */
|
||||
ns_t_naptr = 35, /*%< Naming Authority PoinTeR */
|
||||
ns_t_kx = 36, /*%< Key Exchange */
|
||||
ns_t_cert = 37, /*%< Certification record */
|
||||
ns_t_a6 = 38, /*%< IPv6 address (deprecated, use ns_t_aaaa) */
|
||||
ns_t_dname = 39, /*%< Non-terminal DNAME (for IPv6) */
|
||||
ns_t_sink = 40, /*%< Kitchen sink (experimentatl) */
|
||||
ns_t_opt = 41, /*%< EDNS0 option (meta-RR) */
|
||||
ns_t_apl = 42, /*%< Address prefix list (RFC3123) */
|
||||
ns_t_tkey = 249, /*%< Transaction key */
|
||||
ns_t_tsig = 250, /*%< Transaction signature. */
|
||||
ns_t_ixfr = 251, /*%< Incremental zone transfer. */
|
||||
ns_t_axfr = 252, /*%< Transfer zone of authority. */
|
||||
ns_t_mailb = 253, /*%< Transfer mailbox records. */
|
||||
ns_t_maila = 254, /*%< Transfer mail agent records. */
|
||||
ns_t_any = 255, /*%< Wildcard match. */
|
||||
ns_t_zxfr = 256, /*%< BIND-specific, nonstandard. */
|
||||
ns_t_max = 65536
|
||||
} ns_type;
|
||||
|
||||
/* Exclusively a QTYPE? (not also an RTYPE) */
|
||||
#define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
|
||||
(t) == ns_t_mailb || (t) == ns_t_maila)
|
||||
/* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */
|
||||
#define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
|
||||
/* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */
|
||||
#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))
|
||||
#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)
|
||||
#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \
|
||||
(t) == ns_t_zxfr)
|
||||
|
||||
/*%
|
||||
* Values for class field
|
||||
*/
|
||||
typedef enum __ns_class {
|
||||
ns_c_invalid = 0, /*%< Cookie. */
|
||||
ns_c_in = 1, /*%< Internet. */
|
||||
ns_c_2 = 2, /*%< unallocated/unsupported. */
|
||||
ns_c_chaos = 3, /*%< MIT Chaos-net. */
|
||||
ns_c_hs = 4, /*%< MIT Hesiod. */
|
||||
/* Query class values which do not appear in resource records */
|
||||
ns_c_none = 254, /*%< for prereq. sections in update requests */
|
||||
ns_c_any = 255, /*%< Wildcard match. */
|
||||
ns_c_max = 65536
|
||||
} ns_class;
|
||||
|
||||
/* DNSSEC constants. */
|
||||
|
||||
typedef enum __ns_key_types {
|
||||
ns_kt_rsa = 1, /*%< key type RSA/MD5 */
|
||||
ns_kt_dh = 2, /*%< Diffie Hellman */
|
||||
ns_kt_dsa = 3, /*%< Digital Signature Standard (MANDATORY) */
|
||||
ns_kt_private = 254 /*%< Private key type starts with OID */
|
||||
} ns_key_types;
|
||||
|
||||
typedef enum __ns_cert_types {
|
||||
cert_t_pkix = 1, /*%< PKIX (X.509v3) */
|
||||
cert_t_spki = 2, /*%< SPKI */
|
||||
cert_t_pgp = 3, /*%< PGP */
|
||||
cert_t_url = 253, /*%< URL private type */
|
||||
cert_t_oid = 254 /*%< OID private type */
|
||||
} ns_cert_types;
|
||||
|
||||
/* Flags field of the KEY RR rdata. */
|
||||
#define NS_KEY_TYPEMASK 0xC000 /*%< Mask for "type" bits */
|
||||
#define NS_KEY_TYPE_AUTH_CONF 0x0000 /*%< Key usable for both */
|
||||
#define NS_KEY_TYPE_CONF_ONLY 0x8000 /*%< Key usable for confidentiality */
|
||||
#define NS_KEY_TYPE_AUTH_ONLY 0x4000 /*%< Key usable for authentication */
|
||||
#define NS_KEY_TYPE_NO_KEY 0xC000 /*%< No key usable for either; no key */
|
||||
/* The type bits can also be interpreted independently, as single bits: */
|
||||
#define NS_KEY_NO_AUTH 0x8000 /*%< Key unusable for authentication */
|
||||
#define NS_KEY_NO_CONF 0x4000 /*%< Key unusable for confidentiality */
|
||||
#define NS_KEY_RESERVED2 0x2000 /* Security is *mandatory* if bit=0 */
|
||||
#define NS_KEY_EXTENDED_FLAGS 0x1000 /*%< reserved - must be zero */
|
||||
#define NS_KEY_RESERVED4 0x0800 /*%< reserved - must be zero */
|
||||
#define NS_KEY_RESERVED5 0x0400 /*%< reserved - must be zero */
|
||||
#define NS_KEY_NAME_TYPE 0x0300 /*%< these bits determine the type */
|
||||
#define NS_KEY_NAME_USER 0x0000 /*%< key is assoc. with user */
|
||||
#define NS_KEY_NAME_ENTITY 0x0200 /*%< key is assoc. with entity eg host */
|
||||
#define NS_KEY_NAME_ZONE 0x0100 /*%< key is zone key */
|
||||
#define NS_KEY_NAME_RESERVED 0x0300 /*%< reserved meaning */
|
||||
#define NS_KEY_RESERVED8 0x0080 /*%< reserved - must be zero */
|
||||
#define NS_KEY_RESERVED9 0x0040 /*%< reserved - must be zero */
|
||||
#define NS_KEY_RESERVED10 0x0020 /*%< reserved - must be zero */
|
||||
#define NS_KEY_RESERVED11 0x0010 /*%< reserved - must be zero */
|
||||
#define NS_KEY_SIGNATORYMASK 0x000F /*%< key can sign RR's of same name */
|
||||
#define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \
|
||||
NS_KEY_RESERVED4 | \
|
||||
NS_KEY_RESERVED5 | \
|
||||
NS_KEY_RESERVED8 | \
|
||||
NS_KEY_RESERVED9 | \
|
||||
NS_KEY_RESERVED10 | \
|
||||
NS_KEY_RESERVED11 )
|
||||
#define NS_KEY_RESERVED_BITMASK2 0xFFFF /*%< no bits defined here */
|
||||
/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
|
||||
#define NS_ALG_MD5RSA 1 /*%< MD5 with RSA */
|
||||
#define NS_ALG_DH 2 /*%< Diffie Hellman KEY */
|
||||
#define NS_ALG_DSA 3 /*%< DSA KEY */
|
||||
#define NS_ALG_DSS NS_ALG_DSA
|
||||
#define NS_ALG_EXPIRE_ONLY 253 /*%< No alg, no security */
|
||||
#define NS_ALG_PRIVATE_OID 254 /*%< Key begins with OID giving alg */
|
||||
/* Protocol values */
|
||||
/* value 0 is reserved */
|
||||
#define NS_KEY_PROT_TLS 1
|
||||
#define NS_KEY_PROT_EMAIL 2
|
||||
#define NS_KEY_PROT_DNSSEC 3
|
||||
#define NS_KEY_PROT_IPSEC 4
|
||||
#define NS_KEY_PROT_ANY 255
|
||||
|
||||
/* Signatures */
|
||||
#define NS_MD5RSA_MIN_BITS 512 /*%< Size of a mod or exp in bits */
|
||||
#define NS_MD5RSA_MAX_BITS 4096
|
||||
/* Total of binary mod and exp */
|
||||
#define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3)
|
||||
/* Max length of text sig block */
|
||||
#define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4)
|
||||
#define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS+7)/8)
|
||||
#define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS+7)/8)
|
||||
|
||||
#define NS_DSA_SIG_SIZE 41
|
||||
#define NS_DSA_MIN_SIZE 213
|
||||
#define NS_DSA_MAX_BYTES 405
|
||||
|
||||
/* Offsets into SIG record rdata to find various values */
|
||||
#define NS_SIG_TYPE 0 /*%< Type flags */
|
||||
#define NS_SIG_ALG 2 /*%< Algorithm */
|
||||
#define NS_SIG_LABELS 3 /*%< How many labels in name */
|
||||
#define NS_SIG_OTTL 4 /*%< Original TTL */
|
||||
#define NS_SIG_EXPIR 8 /*%< Expiration time */
|
||||
#define NS_SIG_SIGNED 12 /*%< Signature time */
|
||||
#define NS_SIG_FOOT 16 /*%< Key footprint */
|
||||
#define NS_SIG_SIGNER 18 /*%< Domain name of who signed it */
|
||||
/* How RR types are represented as bit-flags in NXT records */
|
||||
#define NS_NXT_BITS 8
|
||||
#define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS)))
|
||||
#define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
|
||||
#define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS)))
|
||||
#define NS_NXT_MAX 127
|
||||
|
||||
/*%
|
||||
* EDNS0 extended flags and option codes, host order.
|
||||
*/
|
||||
#define NS_OPT_DNSSEC_OK 0x8000U
|
||||
#define NS_OPT_NSID 3
|
||||
|
||||
/*%
|
||||
* Inline versions of get/put short/long. Pointer is advanced.
|
||||
*/
|
||||
#define NS_GET16(s, cp) do { \
|
||||
register const u_char *t_cp = (const u_char *)(cp); \
|
||||
(s) = ((u_int16_t)t_cp[0] << 8) \
|
||||
| ((u_int16_t)t_cp[1]) \
|
||||
; \
|
||||
(cp) += NS_INT16SZ; \
|
||||
} while (0)
|
||||
|
||||
#define NS_GET32(l, cp) do { \
|
||||
register const u_char *t_cp = (const u_char *)(cp); \
|
||||
(l) = ((u_int32_t)t_cp[0] << 24) \
|
||||
| ((u_int32_t)t_cp[1] << 16) \
|
||||
| ((u_int32_t)t_cp[2] << 8) \
|
||||
| ((u_int32_t)t_cp[3]) \
|
||||
; \
|
||||
(cp) += NS_INT32SZ; \
|
||||
} while (0)
|
||||
|
||||
#define NS_PUT16(s, cp) do { \
|
||||
register u_int16_t t_s = (u_int16_t)(s); \
|
||||
register u_char *t_cp = (u_char *)(cp); \
|
||||
*t_cp++ = t_s >> 8; \
|
||||
*t_cp = t_s; \
|
||||
(cp) += NS_INT16SZ; \
|
||||
} while (0)
|
||||
|
||||
#define NS_PUT32(l, cp) do { \
|
||||
register u_int32_t t_l = (u_int32_t)(l); \
|
||||
register u_char *t_cp = (u_char *)(cp); \
|
||||
*t_cp++ = t_l >> 24; \
|
||||
*t_cp++ = t_l >> 16; \
|
||||
*t_cp++ = t_l >> 8; \
|
||||
*t_cp = t_l; \
|
||||
(cp) += NS_INT32SZ; \
|
||||
} while (0)
|
||||
|
||||
#endif /* !_ARPA_NAMESER_H_ */
|
||||
/*! \file */
|
||||
|
||||
|
||||
|
||||
/*%
|
||||
* from nameser.h 8.1 (Berkeley) 6/2/93
|
||||
* $BINDId: nameser_compat.h,v 8.11 1999/01/02 08:00:58 vixie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _ARPA_NAMESER_COMPAT_
|
||||
#define _ARPA_NAMESER_COMPAT_
|
||||
|
||||
#define __BIND 19950621 /*%< (DEAD) interface version stamp. */
|
||||
|
||||
#include <endian.h>
|
||||
|
||||
/*%
|
||||
* Structure for query header. The order of the fields is machine- and
|
||||
* compiler-dependent, depending on the byte/bit order and the layout
|
||||
* of bit fields. We use bit fields only in int variables, as this
|
||||
* is all ANSI requires. This requires a somewhat confusing rearrangement.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
unsigned id :16; /*%< query identification number */
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
/* fields in third byte */
|
||||
unsigned qr: 1; /*%< response flag */
|
||||
unsigned opcode: 4; /*%< purpose of message */
|
||||
unsigned aa: 1; /*%< authoritive answer */
|
||||
unsigned tc: 1; /*%< truncated message */
|
||||
unsigned rd: 1; /*%< recursion desired */
|
||||
/* fields in fourth byte */
|
||||
unsigned ra: 1; /*%< recursion available */
|
||||
unsigned unused :1; /*%< unused bits (MBZ as of 4.9.3a3) */
|
||||
unsigned ad: 1; /*%< authentic data from named */
|
||||
unsigned cd: 1; /*%< checking disabled by resolver */
|
||||
unsigned rcode :4; /*%< response code */
|
||||
#endif
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
|
||||
/* fields in third byte */
|
||||
unsigned rd :1; /*%< recursion desired */
|
||||
unsigned tc :1; /*%< truncated message */
|
||||
unsigned aa :1; /*%< authoritive answer */
|
||||
unsigned opcode :4; /*%< purpose of message */
|
||||
unsigned qr :1; /*%< response flag */
|
||||
/* fields in fourth byte */
|
||||
unsigned rcode :4; /*%< response code */
|
||||
unsigned cd: 1; /*%< checking disabled by resolver */
|
||||
unsigned ad: 1; /*%< authentic data from named */
|
||||
unsigned unused :1; /*%< unused bits (MBZ as of 4.9.3a3) */
|
||||
unsigned ra :1; /*%< recursion available */
|
||||
#endif
|
||||
/* remaining bytes */
|
||||
unsigned qdcount :16; /*%< number of question entries */
|
||||
unsigned ancount :16; /*%< number of answer entries */
|
||||
unsigned nscount :16; /*%< number of authority entries */
|
||||
unsigned arcount :16; /*%< number of resource entries */
|
||||
} HEADER;
|
||||
|
||||
#define PACKETSZ NS_PACKETSZ
|
||||
#define MAXDNAME NS_MAXDNAME
|
||||
#define MAXCDNAME NS_MAXCDNAME
|
||||
#define MAXLABEL NS_MAXLABEL
|
||||
#define HFIXEDSZ NS_HFIXEDSZ
|
||||
#define QFIXEDSZ NS_QFIXEDSZ
|
||||
#define RRFIXEDSZ NS_RRFIXEDSZ
|
||||
#define INT32SZ NS_INT32SZ
|
||||
#define INT16SZ NS_INT16SZ
|
||||
#define INT8SZ NS_INT8SZ
|
||||
#define INADDRSZ NS_INADDRSZ
|
||||
#define IN6ADDRSZ NS_IN6ADDRSZ
|
||||
#define INDIR_MASK NS_CMPRSFLGS
|
||||
#define NAMESERVER_PORT NS_DEFAULTPORT
|
||||
|
||||
#define S_ZONE ns_s_zn
|
||||
#define S_PREREQ ns_s_pr
|
||||
#define S_UPDATE ns_s_ud
|
||||
#define S_ADDT ns_s_ar
|
||||
|
||||
#define QUERY ns_o_query
|
||||
#define IQUERY ns_o_iquery
|
||||
#define STATUS ns_o_status
|
||||
#define NS_NOTIFY_OP ns_o_notify
|
||||
#define NS_UPDATE_OP ns_o_update
|
||||
|
||||
#define NOERROR ns_r_noerror
|
||||
#define FORMERR ns_r_formerr
|
||||
#define SERVFAIL ns_r_servfail
|
||||
#define NXDOMAIN ns_r_nxdomain
|
||||
#define NOTIMP ns_r_notimpl
|
||||
#define REFUSED ns_r_refused
|
||||
#define YXDOMAIN ns_r_yxdomain
|
||||
#define YXRRSET ns_r_yxrrset
|
||||
#define NXRRSET ns_r_nxrrset
|
||||
#define NOTAUTH ns_r_notauth
|
||||
#define NOTZONE ns_r_notzone
|
||||
/*#define BADSIG ns_r_badsig*/
|
||||
/*#define BADKEY ns_r_badkey*/
|
||||
/*#define BADTIME ns_r_badtime*/
|
||||
|
||||
|
||||
#define DELETE ns_uop_delete
|
||||
#define ADD ns_uop_add
|
||||
|
||||
#define T_A ns_t_a
|
||||
#define T_NS ns_t_ns
|
||||
#define T_MD ns_t_md
|
||||
#define T_MF ns_t_mf
|
||||
#define T_CNAME ns_t_cname
|
||||
#define T_SOA ns_t_soa
|
||||
#define T_MB ns_t_mb
|
||||
#define T_MG ns_t_mg
|
||||
#define T_MR ns_t_mr
|
||||
#define T_NULL ns_t_null
|
||||
#define T_WKS ns_t_wks
|
||||
#define T_PTR ns_t_ptr
|
||||
#define T_HINFO ns_t_hinfo
|
||||
#define T_MINFO ns_t_minfo
|
||||
#define T_MX ns_t_mx
|
||||
#define T_TXT ns_t_txt
|
||||
#define T_RP ns_t_rp
|
||||
#define T_AFSDB ns_t_afsdb
|
||||
#define T_X25 ns_t_x25
|
||||
#define T_ISDN ns_t_isdn
|
||||
#define T_RT ns_t_rt
|
||||
#define T_NSAP ns_t_nsap
|
||||
#define T_NSAP_PTR ns_t_nsap_ptr
|
||||
#define T_SIG ns_t_sig
|
||||
#define T_KEY ns_t_key
|
||||
#define T_PX ns_t_px
|
||||
#define T_GPOS ns_t_gpos
|
||||
#define T_AAAA ns_t_aaaa
|
||||
#define T_LOC ns_t_loc
|
||||
#define T_NXT ns_t_nxt
|
||||
#define T_EID ns_t_eid
|
||||
#define T_NIMLOC ns_t_nimloc
|
||||
#define T_SRV ns_t_srv
|
||||
#define T_ATMA ns_t_atma
|
||||
#define T_NAPTR ns_t_naptr
|
||||
#define T_A6 ns_t_a6
|
||||
#define T_DNAME ns_t_dname
|
||||
#define T_TSIG ns_t_tsig
|
||||
#define T_IXFR ns_t_ixfr
|
||||
#define T_AXFR ns_t_axfr
|
||||
#define T_MAILB ns_t_mailb
|
||||
#define T_MAILA ns_t_maila
|
||||
#define T_ANY ns_t_any
|
||||
|
||||
#define C_IN ns_c_in
|
||||
#define C_CHAOS ns_c_chaos
|
||||
#define C_HS ns_c_hs
|
||||
/* BIND_UPDATE */
|
||||
#define C_NONE ns_c_none
|
||||
#define C_ANY ns_c_any
|
||||
|
||||
#define GETSHORT NS_GET16
|
||||
#define GETLONG NS_GET32
|
||||
#define PUTSHORT NS_PUT16
|
||||
#define PUTLONG NS_PUT32
|
||||
|
||||
#endif /* _ARPA_NAMESER_COMPAT_ */
|
||||
/*! \file */
|
||||
+11
-11
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -19,23 +20,22 @@
|
||||
#include "encoding.h"
|
||||
|
||||
int
|
||||
build_hostname(char *buf, size_t buflen,
|
||||
const char *data, const size_t datalen,
|
||||
build_hostname(char *buf, size_t buflen,
|
||||
const char *data, const size_t datalen,
|
||||
const char *topdomain, struct encoder *encoder, int maxlen)
|
||||
{
|
||||
int encsize;
|
||||
size_t space;
|
||||
char *b;
|
||||
|
||||
space = MIN(maxlen, buflen) - strlen(topdomain) - 8;
|
||||
space = MIN((size_t)maxlen, buflen) - strlen(topdomain) - 8;
|
||||
/* 8 = 5 max header length + 1 dot before topdomain + 2 safety */
|
||||
|
||||
if (!encoder->places_dots())
|
||||
space -= (space / 57); /* space for dots */
|
||||
|
||||
memset(buf, 0, buflen);
|
||||
|
||||
encsize = encoder->encode(buf, &space, data, datalen);
|
||||
|
||||
encoder->encode(buf, &space, data, datalen);
|
||||
|
||||
if (!encoder->places_dots())
|
||||
inline_dotify(buf, buflen);
|
||||
@@ -45,7 +45,7 @@ build_hostname(char *buf, size_t buflen,
|
||||
|
||||
/* move b back one step to see if the dot is there */
|
||||
b--;
|
||||
if (*b != '.')
|
||||
if (*b != '.')
|
||||
*++b = '.';
|
||||
b++;
|
||||
/* move b ahead of the string so we can copy to it */
|
||||
@@ -63,7 +63,7 @@ unpack_data(char *buf, size_t buflen, char *data, size_t datalen, struct encoder
|
||||
return enc->decode(buf, &buflen, data, datalen);
|
||||
}
|
||||
|
||||
int
|
||||
int
|
||||
inline_dotify(char *buf, size_t buflen)
|
||||
{
|
||||
unsigned dots;
|
||||
@@ -101,7 +101,7 @@ inline_dotify(char *buf, size_t buflen)
|
||||
return total;
|
||||
}
|
||||
|
||||
int
|
||||
int
|
||||
inline_undotify(char *buf, size_t len)
|
||||
{
|
||||
unsigned pos;
|
||||
@@ -124,7 +124,7 @@ inline_undotify(char *buf, size_t len)
|
||||
*writer++ = *reader++;
|
||||
pos++;
|
||||
}
|
||||
|
||||
|
||||
/* return new length of string */
|
||||
return len - dots;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2008-2014 Erik Ekman <yarrick@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -29,9 +29,9 @@ void fw_query_init()
|
||||
void fw_query_put(struct fw_query *fw_query)
|
||||
{
|
||||
memcpy(&(fwq[fwq_ix]), fw_query, sizeof(struct fw_query));
|
||||
|
||||
|
||||
++fwq_ix;
|
||||
if (fwq_ix >= FW_QUERY_CACHE_SIZE)
|
||||
if (fwq_ix >= FW_QUERY_CACHE_SIZE)
|
||||
fwq_ix = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2008-2014 Erik Ekman <yarrick@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -28,7 +28,7 @@
|
||||
#define FW_QUERY_CACHE_SIZE 16
|
||||
|
||||
struct fw_query {
|
||||
struct sockaddr addr;
|
||||
struct sockaddr_storage addr;
|
||||
int addrlen;
|
||||
unsigned short id;
|
||||
};
|
||||
|
||||
+70
-36
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -32,6 +33,7 @@
|
||||
#else
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
@@ -51,11 +53,17 @@ static char *__progname;
|
||||
#define PASSWORD_ENV_VAR "IODINE_PASS"
|
||||
|
||||
static void
|
||||
sighandler(int sig)
|
||||
sighandler(int sig)
|
||||
{
|
||||
client_stop();
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
/* mark as no return to help some compilers to avoid warnings
|
||||
* about use of uninitialized variables */
|
||||
static void usage() __attribute__((noreturn));
|
||||
#endif
|
||||
|
||||
static void
|
||||
usage() {
|
||||
extern char *__progname;
|
||||
@@ -75,7 +83,7 @@ help() {
|
||||
"[-P password] [-m maxfragsize] [-M maxlen] [-T type] [-O enc] [-L 0|1] [-I sec] "
|
||||
"[-z context] [-F pidfile] [nameserver] topdomain\n", __progname);
|
||||
fprintf(stderr, "Options to try if connection doesn't work:\n");
|
||||
fprintf(stderr, " -T force dns type: NULL, TXT, SRV, MX, CNAME, A (default: autodetect)\n");
|
||||
fprintf(stderr, " -T force dns type: NULL, PRIVATE, TXT, SRV, MX, CNAME, A (default: autodetect)\n");
|
||||
fprintf(stderr, " -O force downstream encoding for -T other than NULL: Base32, Base64, Base64u,\n");
|
||||
fprintf(stderr, " Base128, or (only for TXT:) Raw (default: autodetect)\n");
|
||||
fprintf(stderr, " -I max interval between requests (default 4 sec) to prevent DNS timeouts\n");
|
||||
@@ -101,8 +109,9 @@ help() {
|
||||
|
||||
static void
|
||||
version() {
|
||||
|
||||
fprintf(stderr, "iodine IP over DNS tunneling client\n");
|
||||
fprintf(stderr, "version: 0.6.0-rc1 from 2010-02-13\n");
|
||||
fprintf(stderr, "version: 0.7.0 from 2014-06-16\n");
|
||||
|
||||
exit(0);
|
||||
}
|
||||
@@ -110,8 +119,9 @@ version() {
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char *nameserv_addr;
|
||||
char *nameserv_host;
|
||||
char *topdomain;
|
||||
char *errormsg;
|
||||
#ifndef WINDOWS32
|
||||
struct passwd *pw;
|
||||
#endif
|
||||
@@ -132,9 +142,16 @@ main(int argc, char **argv)
|
||||
int lazymode;
|
||||
int selecttimeout;
|
||||
int hostname_maxlen;
|
||||
#ifdef OPENBSD
|
||||
int rtable = 0;
|
||||
#endif
|
||||
struct sockaddr_storage nameservaddr;
|
||||
int nameservaddr_len;
|
||||
int nameserv_family;
|
||||
|
||||
nameserv_addr = NULL;
|
||||
nameserv_host = NULL;
|
||||
topdomain = NULL;
|
||||
errormsg = NULL;
|
||||
#ifndef WINDOWS32
|
||||
pw = NULL;
|
||||
#endif
|
||||
@@ -154,6 +171,7 @@ main(int argc, char **argv)
|
||||
lazymode = 1;
|
||||
selecttimeout = 4;
|
||||
hostname_maxlen = 0xFF;
|
||||
nameserv_family = AF_UNSPEC;
|
||||
|
||||
#ifdef WINDOWS32
|
||||
WSAStartup(req_version, &wsa_data);
|
||||
@@ -161,7 +179,7 @@ main(int argc, char **argv)
|
||||
|
||||
srand((unsigned) time(NULL));
|
||||
client_init();
|
||||
|
||||
|
||||
#if !defined(BSD) && !defined(__GLIBC__)
|
||||
__progname = strrchr(argv[0], '/');
|
||||
if (__progname == NULL)
|
||||
@@ -170,8 +188,14 @@ main(int argc, char **argv)
|
||||
__progname++;
|
||||
#endif
|
||||
|
||||
while ((choice = getopt(argc, argv, "vfhru:t:d:P:m:M:F:T:O:L:I:")) != -1) {
|
||||
while ((choice = getopt(argc, argv, "46vfhru:t:d:R:P:m:M:F:T:O:L:I:")) != -1) {
|
||||
switch(choice) {
|
||||
case '4':
|
||||
nameserv_family = AF_INET;
|
||||
break;
|
||||
case '6':
|
||||
nameserv_family = AF_INET6;
|
||||
break;
|
||||
case 'v':
|
||||
version();
|
||||
/* NOTREACHED */
|
||||
@@ -185,6 +209,7 @@ main(int argc, char **argv)
|
||||
break;
|
||||
case 'r':
|
||||
raw_mode = 0;
|
||||
break;
|
||||
case 'u':
|
||||
username = optarg;
|
||||
break;
|
||||
@@ -194,12 +219,17 @@ main(int argc, char **argv)
|
||||
case 'd':
|
||||
device = optarg;
|
||||
break;
|
||||
#ifdef OPENBSD
|
||||
case 'R':
|
||||
rtable = atoi(optarg);
|
||||
break;
|
||||
#endif
|
||||
case 'P':
|
||||
strncpy(password, optarg, sizeof(password));
|
||||
password[sizeof(password)-1] = 0;
|
||||
|
||||
|
||||
/* XXX: find better way of cleaning up ps(1) */
|
||||
memset(optarg, 0, strlen(optarg));
|
||||
memset(optarg, 0, strlen(optarg));
|
||||
break;
|
||||
case 'm':
|
||||
autodetect_frag_size = 0;
|
||||
@@ -217,12 +247,13 @@ main(int argc, char **argv)
|
||||
break;
|
||||
case 'F':
|
||||
pidfile = optarg;
|
||||
break;
|
||||
break;
|
||||
case 'T':
|
||||
set_qtype(optarg);
|
||||
if (client_set_qtype(optarg))
|
||||
errx(5, "Invalid query type '%s'", optarg);
|
||||
break;
|
||||
case 'O': /* not -D, is Debug in server */
|
||||
set_downenc(optarg);
|
||||
client_set_downenc(optarg);
|
||||
break;
|
||||
case 'L':
|
||||
lazymode = atoi(optarg);
|
||||
@@ -243,7 +274,7 @@ main(int argc, char **argv)
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
check_superuser(usage);
|
||||
|
||||
argc -= optind;
|
||||
@@ -251,11 +282,11 @@ main(int argc, char **argv)
|
||||
|
||||
switch (argc) {
|
||||
case 1:
|
||||
nameserv_addr = get_resolvconf_addr();
|
||||
nameserv_host = get_resolvconf_addr();
|
||||
topdomain = strdup(argv[0]);
|
||||
break;
|
||||
case 2:
|
||||
nameserv_addr = argv[0];
|
||||
nameserv_host = argv[0];
|
||||
topdomain = strdup(argv[1]);
|
||||
break;
|
||||
default:
|
||||
@@ -269,22 +300,21 @@ main(int argc, char **argv)
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
if (nameserv_addr) {
|
||||
client_set_nameserver(nameserv_addr, DNS_PORT);
|
||||
if (nameserv_host) {
|
||||
nameservaddr_len = get_addr(nameserv_host, DNS_PORT, nameserv_family, 0, &nameservaddr);
|
||||
if (nameservaddr_len < 0) {
|
||||
errx(1, "Cannot lookup nameserver '%s': %s ",
|
||||
nameserv_host, gai_strerror(nameservaddr_len));
|
||||
}
|
||||
client_set_nameserver(&nameservaddr, nameservaddr_len);
|
||||
} else {
|
||||
warnx("No nameserver found - not connected to any network?\n");
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(topdomain) <= 128) {
|
||||
if(check_topdomain(topdomain)) {
|
||||
warnx("Topdomain contains invalid characters.\n");
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
} else {
|
||||
warnx("Use a topdomain max 128 chars long.\n");
|
||||
if(check_topdomain(topdomain, &errormsg)) {
|
||||
warnx("Invalid topdomain: %s", errormsg);
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
@@ -293,7 +323,7 @@ main(int argc, char **argv)
|
||||
client_set_lazymode(lazymode);
|
||||
client_set_topdomain(topdomain);
|
||||
client_set_hostname_maxlen(hostname_maxlen);
|
||||
|
||||
|
||||
if (username != NULL) {
|
||||
#ifndef WINDOWS32
|
||||
if ((pw = getpwnam(username)) == NULL) {
|
||||
@@ -303,51 +333,55 @@ main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
if (strlen(password) == 0) {
|
||||
if (NULL != getenv(PASSWORD_ENV_VAR))
|
||||
snprintf(password, sizeof(password), "%s", getenv(PASSWORD_ENV_VAR));
|
||||
else
|
||||
read_password(password, sizeof(password));
|
||||
}
|
||||
|
||||
|
||||
client_set_password(password);
|
||||
|
||||
if ((tun_fd = open_tun(device)) == -1) {
|
||||
retval = 1;
|
||||
goto cleanup1;
|
||||
}
|
||||
if ((dns_fd = open_dns(0, INADDR_ANY)) == -1) {
|
||||
if ((dns_fd = open_dns_from_host(NULL, 0, nameservaddr.ss_family, AI_PASSIVE)) < 0) {
|
||||
retval = 1;
|
||||
goto cleanup2;
|
||||
}
|
||||
#ifdef OPENBSD
|
||||
if (rtable > 0)
|
||||
socket_setrtable(dns_fd, rtable);
|
||||
#endif
|
||||
|
||||
signal(SIGINT, sighandler);
|
||||
signal(SIGTERM, sighandler);
|
||||
|
||||
fprintf(stderr, "Sending DNS queries for %s to %s\n",
|
||||
topdomain, nameserv_addr);
|
||||
topdomain, format_addr(&nameservaddr, nameservaddr_len));
|
||||
|
||||
if (client_handshake(dns_fd, raw_mode, autodetect_frag_size, max_downstream_frag_size)) {
|
||||
retval = 1;
|
||||
goto cleanup2;
|
||||
}
|
||||
|
||||
|
||||
if (client_get_conn() == CONN_RAW_UDP) {
|
||||
fprintf(stderr, "Sending raw traffic directly to %s\n", client_get_raw_addr());
|
||||
}
|
||||
|
||||
fprintf(stderr, "Connection setup complete, transmitting data.\n");
|
||||
|
||||
if (foreground == 0)
|
||||
if (foreground == 0)
|
||||
do_detach();
|
||||
|
||||
|
||||
if (pidfile != NULL)
|
||||
do_pidfile(pidfile);
|
||||
|
||||
if (newroot != NULL)
|
||||
do_chroot(newroot);
|
||||
|
||||
|
||||
if (username != NULL) {
|
||||
#ifndef WINDOWS32
|
||||
gid_t gids[1];
|
||||
|
||||
+304
-179
File diff suppressed because it is too large.
Load diff
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -20,16 +21,17 @@
|
||||
#ifdef WINDOWS32
|
||||
#include "windows.h"
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include "md5.h"
|
||||
|
||||
/*
|
||||
* Needs a 16byte array for output, and 32 bytes password
|
||||
/*
|
||||
* Needs a 16byte array for output, and 32 bytes password
|
||||
*/
|
||||
void
|
||||
login_calculate(char *buf, int buflen, const char *pass, int seed)
|
||||
void
|
||||
login_calculate(char *buf, int buflen, const char *pass, int seed)
|
||||
{
|
||||
unsigned char temp[32];
|
||||
md5_state_t ctx;
|
||||
@@ -37,7 +39,7 @@ login_calculate(char *buf, int buflen, const char *pass, int seed)
|
||||
int i;
|
||||
int k;
|
||||
|
||||
if (buflen < 16)
|
||||
if (buflen < 16)
|
||||
return;
|
||||
|
||||
memcpy(temp, pass, 32);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
||||
@@ -71,7 +71,7 @@ typedef struct md5_state_s {
|
||||
} md5_state_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
+11
-2
@@ -17,17 +17,26 @@ link)
|
||||
echo '-lws2_32 -liphlpapi';
|
||||
;;
|
||||
Linux)
|
||||
[ -e /usr/include/selinux/selinux.h ] && echo '-lselinux';
|
||||
FLAGS="";
|
||||
[ -e /usr/include/selinux/selinux.h ] && FLAGS="$FLAGS -lselinux";
|
||||
[ -e /usr/include/systemd/sd-daemon.h ] && FLAGS="$FLAGS -lsystemd-daemon";
|
||||
echo $FLAGS;
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
cflags)
|
||||
case $1 in
|
||||
windows32)
|
||||
echo '-DWINVER=0x0501';
|
||||
;;
|
||||
BeOS)
|
||||
echo '-Dsocklen_t=int';
|
||||
;;
|
||||
Linux)
|
||||
[ -e /usr/include/selinux/selinux.h ] && echo '-DHAVE_SETCON';
|
||||
FLAGS="-D_GNU_SOURCE"
|
||||
[ -e /usr/include/selinux/selinux.h ] && FLAGS="$FLAGS -DHAVE_SETCON";
|
||||
[ -e /usr/include/systemd/sd-daemon.h ] && FLAGS="$FLAGS -DHAVE_SYSTEMD";
|
||||
echo $FLAGS;
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
+10
-15
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -60,7 +61,7 @@ readname_loop(char *packet, int packetlen, char **src, char *dst, size_t length,
|
||||
|
||||
c--;
|
||||
}
|
||||
|
||||
|
||||
if (len >= length - 1) {
|
||||
break; /* We used up all space */
|
||||
}
|
||||
@@ -84,15 +85,15 @@ readname(char *packet, int packetlen, char **src, char *dst, size_t length)
|
||||
}
|
||||
|
||||
int
|
||||
readshort(char *packet, char **src, short *dst)
|
||||
readshort(char *packet, char **src, unsigned short *dst)
|
||||
{
|
||||
unsigned char *p;
|
||||
|
||||
p = (unsigned char *) *src;
|
||||
*dst = (p[0] << 8) | p[1];
|
||||
|
||||
(*src) += sizeof(short);
|
||||
return sizeof(short);
|
||||
(*src) += sizeof(unsigned short);
|
||||
return sizeof(unsigned short);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -103,8 +104,8 @@ readlong(char *packet, char **src, uint32_t *dst)
|
||||
|
||||
p = (unsigned char *) *src;
|
||||
|
||||
*dst = ((uint32_t)p[0] << 24)
|
||||
| ((uint32_t)p[1] << 16)
|
||||
*dst = ((uint32_t)p[0] << 24)
|
||||
| ((uint32_t)p[1] << 16)
|
||||
| ((uint32_t)p[2] << 8)
|
||||
| ((uint32_t)p[3]);
|
||||
|
||||
@@ -115,9 +116,6 @@ readlong(char *packet, char **src, uint32_t *dst)
|
||||
int
|
||||
readdata(char *packet, char **src, char *dst, size_t len)
|
||||
{
|
||||
if (len < 0)
|
||||
return 0;
|
||||
|
||||
memcpy(dst, *src, len);
|
||||
|
||||
(*src) += len;
|
||||
@@ -165,7 +163,7 @@ putname(char **buf, size_t buflen, const char *host)
|
||||
h = strdup(host);
|
||||
left = buflen;
|
||||
p = *buf;
|
||||
|
||||
|
||||
word = strtok(h, ".");
|
||||
while(word) {
|
||||
if (strlen(word) > 63 || strlen(word) > left) {
|
||||
@@ -232,11 +230,8 @@ putlong(char **dst, uint32_t value)
|
||||
int
|
||||
putdata(char **dst, char *data, size_t len)
|
||||
{
|
||||
if (len < 0)
|
||||
return 0;
|
||||
|
||||
memcpy(*dst, data, len);
|
||||
|
||||
|
||||
(*dst) += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -18,7 +19,7 @@
|
||||
#define _READ_H_
|
||||
|
||||
int readname(char *, int, char **, char *, size_t);
|
||||
int readshort(char *, char **, short *);
|
||||
int readshort(char *, char **, unsigned short *);
|
||||
int readlong(char *, char **, uint32_t *);
|
||||
int readdata(char *, char **, char *, size_t);
|
||||
int readtxtbin(char *, char **, size_t, char *, size_t);
|
||||
|
||||
+162
-127
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -24,13 +25,16 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef WINDOWS32
|
||||
#include <winsock2.h>
|
||||
#include <winioctl.h>
|
||||
#include "windows.h"
|
||||
#ifndef IFCONFIGPATH
|
||||
#define IFCONFIGPATH "PATH=/sbin:/bin "
|
||||
#endif
|
||||
|
||||
HANDLE dev_handle;
|
||||
struct tun_data data;
|
||||
#ifdef WINDOWS32
|
||||
#include "windows.h"
|
||||
#include <winioctl.h>
|
||||
|
||||
static HANDLE dev_handle;
|
||||
static struct tun_data data;
|
||||
|
||||
static void get_name(char *ifname, int namelen, char *dev_name);
|
||||
|
||||
@@ -47,8 +51,8 @@ static void get_name(char *ifname, int namelen, char *dev_name);
|
||||
#define NET_CFG_INST_ID "NetCfgInstanceId"
|
||||
#else
|
||||
#include <err.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#define TUN_MAX_TRY 50
|
||||
#endif
|
||||
@@ -56,22 +60,25 @@ static void get_name(char *ifname, int namelen, char *dev_name);
|
||||
#include "tun.h"
|
||||
#include "common.h"
|
||||
|
||||
char if_name[250];
|
||||
static char if_name[250];
|
||||
|
||||
#ifndef WINDOWS32
|
||||
#ifdef LINUX
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <linux/if_tun.h>
|
||||
|
||||
int
|
||||
open_tun(const char *tun_device)
|
||||
int
|
||||
open_tun(const char *tun_device)
|
||||
{
|
||||
int i;
|
||||
int tun_fd;
|
||||
struct ifreq ifreq;
|
||||
#ifdef ANDROID
|
||||
char *tunnel = "/dev/tun";
|
||||
#else
|
||||
char *tunnel = "/dev/net/tun";
|
||||
#endif
|
||||
|
||||
if ((tun_fd = open(tunnel, O_RDWR)) < 0) {
|
||||
warn("open_tun: %s: %s", tunnel, strerror(errno));
|
||||
@@ -80,7 +87,7 @@ open_tun(const char *tun_device)
|
||||
|
||||
memset(&ifreq, 0, sizeof(ifreq));
|
||||
|
||||
ifreq.ifr_flags = IFF_TUN;
|
||||
ifreq.ifr_flags = IFF_TUN;
|
||||
|
||||
if (tun_device != NULL) {
|
||||
strncpy(ifreq.ifr_name, tun_device, IFNAMSIZ);
|
||||
@@ -90,6 +97,7 @@ open_tun(const char *tun_device)
|
||||
|
||||
if (ioctl(tun_fd, TUNSETIFF, (void *) &ifreq) != -1) {
|
||||
fprintf(stderr, "Opened %s\n", ifreq.ifr_name);
|
||||
fd_set_close_on_exec(tun_fd);
|
||||
return tun_fd;
|
||||
}
|
||||
|
||||
@@ -104,6 +112,7 @@ open_tun(const char *tun_device)
|
||||
if (ioctl(tun_fd, TUNSETIFF, (void *) &ifreq) != -1) {
|
||||
fprintf(stderr, "Opened %s\n", ifreq.ifr_name);
|
||||
snprintf(if_name, sizeof(if_name), "dns%d", i);
|
||||
fd_set_close_on_exec(tun_fd);
|
||||
return tun_fd;
|
||||
}
|
||||
|
||||
@@ -119,49 +128,8 @@ open_tun(const char *tun_device)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#else /* BSD */
|
||||
#elif WINDOWS32
|
||||
|
||||
int
|
||||
open_tun(const char *tun_device)
|
||||
{
|
||||
int i;
|
||||
int tun_fd;
|
||||
char tun_name[50];
|
||||
|
||||
if (tun_device != NULL) {
|
||||
snprintf(tun_name, sizeof(tun_name), "/dev/%s", tun_device);
|
||||
strncpy(if_name, tun_device, sizeof(if_name));
|
||||
if_name[sizeof(if_name)-1] = '\0';
|
||||
|
||||
if ((tun_fd = open(tun_name, O_RDWR)) < 0) {
|
||||
warn("open_tun: %s: %s", tun_name, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Opened %s\n", tun_name);
|
||||
return tun_fd;
|
||||
} else {
|
||||
for (i = 0; i < TUN_MAX_TRY; i++) {
|
||||
snprintf(tun_name, sizeof(tun_name), "/dev/tun%d", i);
|
||||
|
||||
if ((tun_fd = open(tun_name, O_RDWR)) >= 0) {
|
||||
fprintf(stderr, "Opened %s\n", tun_name);
|
||||
snprintf(if_name, sizeof(if_name), "tun%d", i);
|
||||
return tun_fd;
|
||||
}
|
||||
|
||||
if (errno == ENOENT)
|
||||
break;
|
||||
}
|
||||
|
||||
warn("open_tun: Failed to open tunneling device");
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif /* !LINUX */
|
||||
#else /* WINDOWS32 */
|
||||
static void
|
||||
get_device(char *device, int device_len, const char *wanted_dev)
|
||||
{
|
||||
@@ -176,7 +144,7 @@ get_device(char *device, int device_len, const char *wanted_dev)
|
||||
warnx("Error opening registry key " TAP_ADAPTER_KEY );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
while (TRUE) {
|
||||
char name[256];
|
||||
char unit[256];
|
||||
@@ -214,7 +182,7 @@ get_device(char *device, int device_len, const char *wanted_dev)
|
||||
strncmp(TAP_VERSION_ID_0901, component, strlen(TAP_VERSION_ID_0901)) == 0) {
|
||||
/* We found a TAP32 device, get its NetCfgInstanceId */
|
||||
char iid_string[256] = NET_CFG_INST_ID;
|
||||
|
||||
|
||||
status = RegQueryValueEx(device_key, iid_string, NULL, &datatype, (LPBYTE) device, (DWORD *) &device_len);
|
||||
if (status != ERROR_SUCCESS || datatype != REG_SZ) {
|
||||
warnx("Error reading registry key %s\\%s on TAP device", unit, iid_string);
|
||||
@@ -280,7 +248,7 @@ DWORD WINAPI tun_reader(LPVOID arg)
|
||||
OVERLAPPED olpd;
|
||||
int sock;
|
||||
|
||||
sock = open_dns(0, INADDR_ANY);
|
||||
sock = open_dns_from_host("127.0.0.1", 0, AF_INET, 0);
|
||||
|
||||
olpd.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
|
||||
@@ -291,21 +259,22 @@ DWORD WINAPI tun_reader(LPVOID arg)
|
||||
if (!res) {
|
||||
WaitForSingleObject(olpd.hEvent, INFINITE);
|
||||
res = GetOverlappedResult(dev_handle, &olpd, (LPDWORD) &len, FALSE);
|
||||
res = sendto(sock, buf, len, 0, (struct sockaddr*) &(tun->addr),
|
||||
sizeof(struct sockaddr_in));
|
||||
res = sendto(sock, buf, len, 0, (struct sockaddr*) &(tun->addr),
|
||||
tun->addrlen);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
open_tun(const char *tun_device)
|
||||
int
|
||||
open_tun(const char *tun_device)
|
||||
{
|
||||
char adapter[256];
|
||||
char tapfile[512];
|
||||
int tunfd;
|
||||
in_addr_t local;
|
||||
struct sockaddr_storage localsock;
|
||||
int localsock_len;
|
||||
|
||||
memset(adapter, 0, sizeof(adapter));
|
||||
memset(if_name, 0, sizeof(if_name));
|
||||
@@ -319,7 +288,7 @@ open_tun(const char *tun_device)
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
fprintf(stderr, "Opening device %s\n", if_name);
|
||||
snprintf(tapfile, sizeof(tapfile), "%s%s.tap", TAP_DEVICE_SPACE, adapter);
|
||||
dev_handle = CreateFile(tapfile, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, NULL);
|
||||
@@ -330,34 +299,115 @@ open_tun(const char *tun_device)
|
||||
|
||||
/* Use a UDP connection to forward packets from tun,
|
||||
* so we can still use select() in main code.
|
||||
* A thread does blocking reads on tun device and
|
||||
* A thread does blocking reads on tun device and
|
||||
* sends data as udp to this socket */
|
||||
|
||||
local = htonl(0x7f000001); /* 127.0.0.1 */
|
||||
tunfd = open_dns(55353, local);
|
||||
|
||||
localsock_len = get_addr("127.0.0.1", 55353, AF_INET, 0, &localsock);
|
||||
tunfd = open_dns(&localsock, localsock_len);
|
||||
|
||||
data.tun = dev_handle;
|
||||
memset(&(data.addr), 0, sizeof(data.addr));
|
||||
data.addr.sin_family = AF_INET;
|
||||
data.addr.sin_port = htons(55353);
|
||||
data.addr.sin_addr.s_addr = local;
|
||||
memcpy(&(data.addr), &localsock, localsock_len);
|
||||
data.addrlen = localsock_len;
|
||||
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)tun_reader, &data, 0, NULL);
|
||||
|
||||
|
||||
return tunfd;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
close_tun(int tun_fd)
|
||||
#else /* BSD and friends */
|
||||
|
||||
int
|
||||
open_tun(const char *tun_device)
|
||||
{
|
||||
int i;
|
||||
int tun_fd;
|
||||
char tun_name[50];
|
||||
|
||||
if (tun_device != NULL) {
|
||||
snprintf(tun_name, sizeof(tun_name), "/dev/%s", tun_device);
|
||||
strncpy(if_name, tun_device, sizeof(if_name));
|
||||
if_name[sizeof(if_name)-1] = '\0';
|
||||
|
||||
if ((tun_fd = open(tun_name, O_RDWR)) < 0) {
|
||||
warn("open_tun: %s: %s", tun_name, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Opened %s\n", tun_name);
|
||||
fd_set_close_on_exec(tun_fd);
|
||||
return tun_fd;
|
||||
} else {
|
||||
for (i = 0; i < TUN_MAX_TRY; i++) {
|
||||
snprintf(tun_name, sizeof(tun_name), "/dev/tun%d", i);
|
||||
|
||||
if ((tun_fd = open(tun_name, O_RDWR)) >= 0) {
|
||||
fprintf(stderr, "Opened %s\n", tun_name);
|
||||
snprintf(if_name, sizeof(if_name), "tun%d", i);
|
||||
fd_set_close_on_exec(tun_fd);
|
||||
return tun_fd;
|
||||
}
|
||||
|
||||
if (errno == ENOENT)
|
||||
break;
|
||||
}
|
||||
|
||||
warn("open_tun: Failed to open tunneling device");
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
close_tun(int tun_fd)
|
||||
{
|
||||
if (tun_fd >= 0)
|
||||
close(tun_fd);
|
||||
}
|
||||
|
||||
int
|
||||
write_tun(int tun_fd, char *data, size_t len)
|
||||
#ifdef WINDOWS32
|
||||
int
|
||||
write_tun(int tun_fd, char *data, size_t len)
|
||||
{
|
||||
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD) || defined(WINDOWS32) || defined(__ANDROID__)
|
||||
DWORD written;
|
||||
DWORD res;
|
||||
OVERLAPPED olpd;
|
||||
|
||||
data += 4;
|
||||
len -= 4;
|
||||
|
||||
olpd.Offset = 0;
|
||||
olpd.OffsetHigh = 0;
|
||||
olpd.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
res = WriteFile(dev_handle, data, len, &written, &olpd);
|
||||
if (!res && GetLastError() == ERROR_IO_PENDING) {
|
||||
WaitForSingleObject(olpd.hEvent, INFINITE);
|
||||
res = GetOverlappedResult(dev_handle, &olpd, &written, FALSE);
|
||||
if (written != len) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
read_tun(int tun_fd, char *buf, size_t len)
|
||||
{
|
||||
int bytes;
|
||||
memset(buf, 0, 4);
|
||||
|
||||
bytes = recv(tun_fd, buf + 4, len - 4, 0);
|
||||
if (bytes < 0) {
|
||||
return bytes;
|
||||
} else {
|
||||
return bytes + 4;
|
||||
}
|
||||
}
|
||||
#else
|
||||
int
|
||||
write_tun(int tun_fd, char *data, size_t len)
|
||||
{
|
||||
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD) || defined(__ANDROID__)
|
||||
data += 4;
|
||||
len -= 4;
|
||||
#else /* !FREEBSD/DARWIN */
|
||||
@@ -374,47 +424,22 @@ write_tun(int tun_fd, char *data, size_t len)
|
||||
#endif /* !LINUX */
|
||||
#endif /* FREEBSD */
|
||||
|
||||
#ifndef WINDOWS32
|
||||
if (write(tun_fd, data, len) != len) {
|
||||
warn("write_tun");
|
||||
return 1;
|
||||
}
|
||||
#else /* WINDOWS32 */
|
||||
{
|
||||
DWORD written;
|
||||
DWORD res;
|
||||
OVERLAPPED olpd;
|
||||
|
||||
olpd.Offset = 0;
|
||||
olpd.OffsetHigh = 0;
|
||||
olpd.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
res = WriteFile(dev_handle, data, len, &written, &olpd);
|
||||
if (!res && GetLastError() == ERROR_IO_PENDING) {
|
||||
WaitForSingleObject(olpd.hEvent, INFINITE);
|
||||
res = GetOverlappedResult(dev_handle, &olpd, &written, FALSE);
|
||||
if (written != len) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
read_tun(int tun_fd, char *buf, size_t len)
|
||||
read_tun(int tun_fd, char *buf, size_t len)
|
||||
{
|
||||
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD) || defined(WINDOWS32) || defined(__ANDROID__)
|
||||
/* FreeBSD/Darwin/NetBSD/Android-VPN has no header */
|
||||
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD) || defined(__ANDROID__)
|
||||
/* FreeBSD/Darwin/NetBSD/Android-SDK has no header */
|
||||
int bytes;
|
||||
memset(buf, 0, 4);
|
||||
#ifdef WINDOWS32
|
||||
/* Windows needs recv() since it is local UDP socket */
|
||||
bytes = recv(tun_fd, buf + 4, len - 4, 0);
|
||||
#else
|
||||
/* The other need read() because fd is not a socket */
|
||||
|
||||
bytes = read(tun_fd, buf + 4, len - 4);
|
||||
#endif /*WINDOWS32*/
|
||||
if (bytes < 0) {
|
||||
return bytes;
|
||||
} else {
|
||||
@@ -424,9 +449,10 @@ read_tun(int tun_fd, char *buf, size_t len)
|
||||
return read(tun_fd, buf, len);
|
||||
#endif /* !FREEBSD */
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
tun_setip(const char *ip, const char *remoteip, int netbits)
|
||||
tun_setip(const char *ip, const char *other_ip, int netbits)
|
||||
{
|
||||
char cmdline[512];
|
||||
int netmask;
|
||||
@@ -440,6 +466,11 @@ tun_setip(const char *ip, const char *remoteip, int netbits)
|
||||
DWORD ipdata[3];
|
||||
struct in_addr addr;
|
||||
DWORD len;
|
||||
#else
|
||||
const char *display_ip;
|
||||
#ifndef LINUX
|
||||
struct in_addr netip;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
netmask = 0;
|
||||
@@ -461,32 +492,36 @@ tun_setip(const char *ip, const char *remoteip, int netbits)
|
||||
free(tun_config_android.remoteip);
|
||||
}
|
||||
tun_config_android.ip = strdup(ip);
|
||||
tun_config_android.remoteip = strdup(remoteip);
|
||||
tun_config_android.remoteip = strdup(other_ip);
|
||||
tun_config_android.netbits = netbits;
|
||||
return 0;
|
||||
#elif !defined(WINDOWS32)
|
||||
snprintf(cmdline, sizeof(cmdline),
|
||||
"/sbin/ifconfig %s %s %s netmask %s",
|
||||
# ifdef FREEBSD
|
||||
display_ip = other_ip; /* FreeBSD wants other IP as second IP */
|
||||
# else
|
||||
display_ip = ip;
|
||||
# endif
|
||||
snprintf(cmdline, sizeof(cmdline),
|
||||
IFCONFIGPATH "ifconfig %s %s %s netmask %s",
|
||||
if_name,
|
||||
ip,
|
||||
#ifdef FREEBSD
|
||||
remoteip, /* FreeBSD wants other IP as second IP */
|
||||
#else
|
||||
ip,
|
||||
#endif
|
||||
display_ip,
|
||||
inet_ntoa(net));
|
||||
|
||||
|
||||
fprintf(stderr, "Setting IP of %s to %s\n", if_name, ip);
|
||||
#ifndef LINUX
|
||||
netip.s_addr = inet_addr(ip);
|
||||
netip.s_addr = netip.s_addr & net.s_addr;
|
||||
r = system(cmdline);
|
||||
if(r != 0) {
|
||||
return r;
|
||||
} else {
|
||||
|
||||
snprintf(cmdline, sizeof(cmdline),
|
||||
"/sbin/route add %s/%d %s",
|
||||
ip, netbits, ip);
|
||||
inet_ntoa(netip), netbits, ip);
|
||||
}
|
||||
fprintf(stderr, "Adding route %s/%d to %s\n", ip, netbits, ip);
|
||||
fprintf(stderr, "Adding route %s/%d to %s\n", inet_ntoa(netip), netbits, ip);
|
||||
#endif
|
||||
return system(cmdline);
|
||||
#else /* WINDOWS32 */
|
||||
@@ -494,13 +529,13 @@ tun_setip(const char *ip, const char *remoteip, int netbits)
|
||||
/* Set device as connected */
|
||||
fprintf(stderr, "Enabling interface '%s'\n", if_name);
|
||||
status = 1;
|
||||
r = DeviceIoControl(dev_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status,
|
||||
r = DeviceIoControl(dev_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status,
|
||||
sizeof(status), &status, sizeof(status), &len, NULL);
|
||||
if (!r) {
|
||||
fprintf(stderr, "Failed to enable interface\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (inet_aton(ip, &addr)) {
|
||||
ipdata[0] = (DWORD) addr.s_addr; /* local ip addr */
|
||||
ipdata[1] = net.s_addr & ipdata[0]; /* network addr */
|
||||
@@ -510,7 +545,7 @@ tun_setip(const char *ip, const char *remoteip, int netbits)
|
||||
}
|
||||
|
||||
/* Tell ip/networkaddr/netmask to device for arp use */
|
||||
r = DeviceIoControl(dev_handle, TAP_IOCTL_CONFIG_TUN, &ipdata,
|
||||
r = DeviceIoControl(dev_handle, TAP_IOCTL_CONFIG_TUN, &ipdata,
|
||||
sizeof(ipdata), &ipdata, sizeof(ipdata), &len, NULL);
|
||||
if (!r) {
|
||||
fprintf(stderr, "Failed to set interface in TUN mode\n");
|
||||
@@ -525,7 +560,7 @@ tun_setip(const char *ip, const char *remoteip, int netbits)
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
int
|
||||
tun_setmtu(const unsigned mtu)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
@@ -535,11 +570,11 @@ tun_setmtu(const unsigned mtu)
|
||||
char cmdline[512];
|
||||
|
||||
if (mtu > 200 && mtu <= 1500) {
|
||||
snprintf(cmdline, sizeof(cmdline),
|
||||
"/sbin/ifconfig %s mtu %u",
|
||||
snprintf(cmdline, sizeof(cmdline),
|
||||
IFCONFIGPATH "ifconfig %s mtu %u",
|
||||
if_name,
|
||||
mtu);
|
||||
|
||||
|
||||
fprintf(stderr, "Setting MTU of %s to %u\n", if_name, mtu);
|
||||
return system(cmdline);
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
||||
+31
-28
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -33,7 +34,8 @@
|
||||
#include "encoding.h"
|
||||
#include "user.h"
|
||||
|
||||
struct user users[USERS];
|
||||
struct tun_user *users;
|
||||
unsigned usercount;
|
||||
|
||||
int
|
||||
init_users(in_addr_t my_ip, int netbits)
|
||||
@@ -41,7 +43,6 @@ init_users(in_addr_t my_ip, int netbits)
|
||||
int i;
|
||||
int skip = 0;
|
||||
char newip[16];
|
||||
int created_users = 0;
|
||||
|
||||
int maxusers;
|
||||
|
||||
@@ -57,9 +58,10 @@ init_users(in_addr_t my_ip, int netbits)
|
||||
ipstart.s_addr = my_ip & net.s_addr;
|
||||
|
||||
maxusers = (1 << (32-netbits)) - 3; /* 3: Net addr, broadcast addr, iodined addr */
|
||||
|
||||
memset(users, 0, USERS * sizeof(struct user));
|
||||
for (i = 0; i < USERS; i++) {
|
||||
usercount = MIN(maxusers, USERS);
|
||||
|
||||
users = calloc(usercount, sizeof(struct tun_user));
|
||||
for (i = 0; i < usercount; i++) {
|
||||
in_addr_t ip;
|
||||
users[i].id = i;
|
||||
snprintf(newip, sizeof(newip), "0.0.0.%d", i + skip + 1);
|
||||
@@ -72,17 +74,14 @@ init_users(in_addr_t my_ip, int netbits)
|
||||
}
|
||||
users[i].tun_ip = ip;
|
||||
net.s_addr = ip;
|
||||
if (maxusers-- < 1) {
|
||||
users[i].disabled = 1;
|
||||
} else {
|
||||
users[i].disabled = 0;
|
||||
created_users++;
|
||||
}
|
||||
users[i].disabled = 0;
|
||||
users[i].authenticated = 0;
|
||||
users[i].authenticated_raw = 0;
|
||||
users[i].active = 0;
|
||||
/* Rest is reset on login ('V' packet) */
|
||||
}
|
||||
|
||||
return created_users;
|
||||
return usercount;
|
||||
}
|
||||
|
||||
const char*
|
||||
@@ -90,7 +89,7 @@ users_get_first_ip()
|
||||
{
|
||||
struct in_addr ip;
|
||||
ip.s_addr = users[0].tun_ip;
|
||||
return inet_ntoa(ip);
|
||||
return strdup(inet_ntoa(ip));
|
||||
}
|
||||
|
||||
int
|
||||
@@ -100,14 +99,14 @@ users_waiting_on_reply()
|
||||
int i;
|
||||
|
||||
ret = 0;
|
||||
for (i = 0; i < USERS; i++) {
|
||||
if (users[i].active && !users[i].disabled &&
|
||||
for (i = 0; i < usercount; i++) {
|
||||
if (users[i].active && !users[i].disabled &&
|
||||
users[i].last_pkt + 60 > time(NULL) &&
|
||||
users[i].q.id != 0 && users[i].conn == CONN_DNS_NULL) {
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -118,8 +117,10 @@ find_user_by_ip(uint32_t ip)
|
||||
int i;
|
||||
|
||||
ret = -1;
|
||||
for (i = 0; i < USERS; i++) {
|
||||
if (users[i].active && !users[i].disabled &&
|
||||
for (i = 0; i < usercount; i++) {
|
||||
if (users[i].active &&
|
||||
users[i].authenticated &&
|
||||
!users[i].disabled &&
|
||||
users[i].last_pkt + 60 > time(NULL) &&
|
||||
ip == users[i].tun_ip) {
|
||||
ret = i;
|
||||
@@ -143,11 +144,11 @@ all_users_waiting_to_send()
|
||||
|
||||
ret = 1;
|
||||
now = time(NULL);
|
||||
for (i = 0; i < USERS; i++) {
|
||||
for (i = 0; i < usercount; i++) {
|
||||
if (users[i].active && !users[i].disabled &&
|
||||
users[i].last_pkt + 60 > now &&
|
||||
((users[i].conn == CONN_RAW_UDP) ||
|
||||
((users[i].conn == CONN_DNS_NULL)
|
||||
((users[i].conn == CONN_RAW_UDP) ||
|
||||
((users[i].conn == CONN_DNS_NULL)
|
||||
#ifdef OUTPACKETQ_LEN
|
||||
&& users[i].outpacketq_filled < 1
|
||||
#else
|
||||
@@ -167,10 +168,12 @@ find_available_user()
|
||||
{
|
||||
int ret = -1;
|
||||
int i;
|
||||
for (i = 0; i < USERS; i++) {
|
||||
for (i = 0; i < usercount; i++) {
|
||||
/* Not used at all or not used in one minute */
|
||||
if ((!users[i].active || users[i].last_pkt + 60 < time(NULL)) && !users[i].disabled) {
|
||||
users[i].active = 1;
|
||||
users[i].authenticated = 0;
|
||||
users[i].authenticated_raw = 0;
|
||||
users[i].last_pkt = time(NULL);
|
||||
users[i].fragsize = 4096;
|
||||
users[i].conn = CONN_DNS_NULL;
|
||||
@@ -184,21 +187,21 @@ find_available_user()
|
||||
void
|
||||
user_switch_codec(int userid, struct encoder *enc)
|
||||
{
|
||||
if (userid < 0 || userid >= USERS)
|
||||
if (userid < 0 || userid >= usercount)
|
||||
return;
|
||||
|
||||
|
||||
users[userid].encoder = enc;
|
||||
}
|
||||
|
||||
void
|
||||
user_set_conn_type(int userid, enum connection c)
|
||||
{
|
||||
if (userid < 0 || userid >= USERS)
|
||||
if (userid < 0 || userid >= usercount)
|
||||
return;
|
||||
|
||||
if (c < 0 || c >= CONN_MAX)
|
||||
return;
|
||||
|
||||
|
||||
users[userid].conn = c;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -33,9 +34,11 @@
|
||||
#define QMEMDATA_LEN 15
|
||||
/* Max advisable: 36/2 = 18. Total mem usage: QMEMDATA_LEN * USERS * 6 bytes */
|
||||
|
||||
struct user {
|
||||
struct tun_user {
|
||||
char id;
|
||||
int active;
|
||||
int authenticated;
|
||||
int authenticated_raw;
|
||||
int disabled;
|
||||
time_t last_pkt;
|
||||
int seed;
|
||||
@@ -73,7 +76,7 @@ struct user {
|
||||
#endif
|
||||
};
|
||||
|
||||
extern struct user users[USERS];
|
||||
extern struct tun_user *users;
|
||||
|
||||
int init_users(in_addr_t, int);
|
||||
const char* users_get_first_ip();
|
||||
|
||||
+29
-5
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -25,12 +26,22 @@ get_resolvconf_addr()
|
||||
#ifndef WINDOWS32
|
||||
char buf[80];
|
||||
FILE *fp;
|
||||
|
||||
#ifdef ANDROID
|
||||
fp = popen("getprop net.dns1", "r");
|
||||
if (fp == NULL)
|
||||
err(1, "getprop net.dns1 failed");
|
||||
if (fgets(buf, sizeof(buf), fp) == NULL)
|
||||
err(1, "read getprop net.dns1 failed");
|
||||
if (sscanf(buf, "%15s", addr) == 1)
|
||||
rv = addr;
|
||||
pclose(fp);
|
||||
#else
|
||||
|
||||
rv = NULL;
|
||||
|
||||
if ((fp = fopen("/etc/resolv.conf", "r")) == NULL)
|
||||
if ((fp = fopen("/etc/resolv.conf", "r")) == NULL)
|
||||
err(1, "/etc/resolv.conf");
|
||||
|
||||
|
||||
while (feof(fp) == 0) {
|
||||
fgets(buf, sizeof(buf), fp);
|
||||
|
||||
@@ -39,8 +50,9 @@ get_resolvconf_addr()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fclose(fp);
|
||||
#endif
|
||||
#else /* !WINDOWS32 */
|
||||
FIXED_INFO *fixed_info;
|
||||
ULONG buflen;
|
||||
@@ -67,3 +79,15 @@ get_resolvconf_addr()
|
||||
return rv;
|
||||
}
|
||||
|
||||
#ifdef OPENBSD
|
||||
void
|
||||
socket_setrtable(int fd, int rtable)
|
||||
{
|
||||
#ifdef SO_RTABLE
|
||||
if (setsockopt (fd, IPPROTO_IP, SO_RTABLE, &rtable, sizeof(rtable)) == -1)
|
||||
err(1, "Failed to set routing table %d", rtable);
|
||||
#else
|
||||
fprintf(stderr, "Routing domain support was not available at compile time.\n");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -2,5 +2,6 @@
|
||||
#define __UTIL_H__
|
||||
|
||||
char *get_resolvconf_addr();
|
||||
void socket_setrtable(int fd, int rtable);
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -19,9 +20,9 @@
|
||||
|
||||
typedef unsigned int in_addr_t;
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <windns.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <iphlpapi.h>
|
||||
|
||||
@@ -94,7 +95,8 @@ DWORD WINAPI tun_reader(LPVOID arg);
|
||||
struct tun_data {
|
||||
HANDLE tun;
|
||||
int sock;
|
||||
struct sockaddr_in addr;
|
||||
struct sockaddr_storage addr;
|
||||
int addrlen;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,26 +1,24 @@
|
||||
CC = gcc
|
||||
TEST = test
|
||||
OBJS = test.o base32.o base64.o read.o dns.o encoding.o login.o user.o fw_query.o
|
||||
SRCOBJS = ../src/base32.o ../src/base64.o ../src/read.o ../src/dns.o ../src/encoding.o ../src/login.o ../src/md5.o ../src/user.o ../src/fw_query.o
|
||||
OBJS = test.o base32.o base64.o common.o read.o dns.o encoding.o login.o user.o fw_query.o
|
||||
SRCOBJS = ../src/base32.o ../src/base64.o ../src/common.o ../src/read.o ../src/dns.o ../src/encoding.o ../src/login.o ../src/md5.o ../src/user.o ../src/fw_query.o
|
||||
|
||||
OS = `uname | tr "a-z" "A-Z"`
|
||||
|
||||
CHECK_PATH = /usr/local
|
||||
LDFLAGS = -L$(CHECK_PATH)/lib -lcheck `../src/osflags link`
|
||||
CFLAGS = -g -Wall -D$(OS) -I../src -I$(CHECK_PATH)/include -pedantic `../src/osflags cflags`
|
||||
LDFLAGS = -L$(CHECK_PATH)/lib `pkg-config check --libs` -lpthread `sh ../src/osflags $(TARGETOS) link`
|
||||
CFLAGS = -std=c99 -g -Wall -D$(OS) `pkg-config check --cflags` -I../src -I$(CHECK_PATH)/include -pedantic `sh ../src/osflags $(TARGETOS) cflags`
|
||||
|
||||
all: $(TEST)
|
||||
@LD_LIBRARY_PATH=${CHECK_PATH}/lib ./$(TEST)
|
||||
|
||||
$(TEST): $(OBJS) $(SRCOBJS)
|
||||
@echo LD $(TEST)
|
||||
@$(CC) -o $@ $(SRCOBJS) $(OBJS) $(LDFLAGS)
|
||||
@$(CC) -o $@ $(SRCOBJS) $(OBJS) $(LDFLAGS)
|
||||
|
||||
.c.o:
|
||||
.c.o:
|
||||
@echo CC $<
|
||||
@$(CC) $(CFLAGS) -c $<
|
||||
|
||||
|
||||
clean:
|
||||
@echo "Cleaning tests/"
|
||||
@rm -f *~ *.core $(TEST) $(OBJS)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -50,6 +51,7 @@ START_TEST(test_base32_encode)
|
||||
len = sizeof(buf);
|
||||
val = b32->encode(buf, &len, testpairs[_i].a, strlen(testpairs[_i].a));
|
||||
|
||||
fail_unless(val == strlen(testpairs[_i].b));
|
||||
fail_unless(strcmp(buf, testpairs[_i].b) == 0,
|
||||
"'%s' != '%s'", buf, testpairs[_i].b);
|
||||
}
|
||||
@@ -61,13 +63,13 @@ START_TEST(test_base32_decode)
|
||||
char buf[4096];
|
||||
struct encoder *b32;
|
||||
int val;
|
||||
|
||||
|
||||
b32 = get_base32_encoder();
|
||||
|
||||
len = sizeof(buf);
|
||||
val = b32->decode(buf, &len, testpairs[_i].b, strlen(testpairs[_i].b));
|
||||
|
||||
fail_unless(buf != NULL, "buf == NULL");
|
||||
fail_unless(val == strlen(testpairs[_i].a));
|
||||
fail_unless(strcmp(buf, testpairs[_i].a) == 0,
|
||||
"'%s' != '%s'", buf, testpairs[_i].a);
|
||||
}
|
||||
@@ -79,7 +81,7 @@ START_TEST(test_base32_5to8_8to5)
|
||||
int c;
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
c = b32_5to8(i);
|
||||
c = b32_5to8(i);
|
||||
fail_unless(b32_8to5(c) == i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -76,6 +77,7 @@ START_TEST(test_base64_encode)
|
||||
len = sizeof(buf);
|
||||
val = b64->encode(buf, &len, testpairs[_i].a, strlen(testpairs[_i].a));
|
||||
|
||||
fail_unless(val == strlen(testpairs[_i].b));
|
||||
fail_unless(strcmp(buf, testpairs[_i].b) == 0,
|
||||
"'%s' != '%s'", buf, testpairs[_i].b);
|
||||
}
|
||||
@@ -93,7 +95,7 @@ START_TEST(test_base64_decode)
|
||||
len = sizeof(buf);
|
||||
val = b64->decode(buf, &len, testpairs[_i].b, strlen(testpairs[_i].b));
|
||||
|
||||
fail_unless(buf != NULL, "buf == NULL");
|
||||
fail_unless(val == strlen(testpairs[_i].a));
|
||||
fail_unless(strcmp(buf, testpairs[_i].a) == 0,
|
||||
"'%s' != '%s'", buf, testpairs[_i].a);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
#include <check.h>
|
||||
#include <common.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
|
||||
START_TEST(test_topdomain_ok)
|
||||
{
|
||||
char *error;
|
||||
|
||||
fail_if(check_topdomain("foo.0123456789.qwertyuiop.asdfghjkl.zxcvbnm.com", &error));
|
||||
|
||||
/* Not allowed to start with dot */
|
||||
fail_unless(check_topdomain(".foo.0123456789.qwertyuiop.asdfghjkl.zxcvbnm.com", &error));
|
||||
fail_if(strcmp("Starts with a dot", error));
|
||||
|
||||
/* Test missing error msg ptr */
|
||||
fail_unless(check_topdomain(".foo", NULL));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_topdomain_length)
|
||||
{
|
||||
char *error;
|
||||
|
||||
/* Test empty and too short */
|
||||
fail_unless(check_topdomain("", &error));
|
||||
fail_if(strcmp("Too short (< 3)", error));
|
||||
fail_unless(check_topdomain("a", &error));
|
||||
fail_if(strcmp("Too short (< 3)", error));
|
||||
fail_unless(check_topdomain(".a", &error));
|
||||
fail_if(strcmp("Too short (< 3)", error));
|
||||
fail_unless(check_topdomain("a.", &error));
|
||||
fail_if(strcmp("Too short (< 3)", error));
|
||||
fail_unless(check_topdomain("ab", &error));
|
||||
fail_if(strcmp("Too short (< 3)", error));
|
||||
fail_if(check_topdomain("a.b", &error));
|
||||
fail_if(strcmp("Too short (< 3)", error));
|
||||
|
||||
/* Test too long (over 128, need rest of space for data) */
|
||||
fail_unless(check_topdomain(
|
||||
"abcd12345.abcd12345.abcd12345.abcd12345.abcd12345."
|
||||
"abcd12345.abcd12345.abcd12345.abcd12345.abcd12345."
|
||||
"abcd12345.abcd12345.foo129xxx", &error));
|
||||
fail_if(strcmp("Too long (> 128)", error));
|
||||
fail_if(check_topdomain(
|
||||
"abcd12345.abcd12345.abcd12345.abcd12345.abcd12345."
|
||||
"abcd12345.abcd12345.abcd12345.abcd12345.abcd12345."
|
||||
"abcd12345.abcd12345.foo128xx", &error));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_topdomain_chunks)
|
||||
{
|
||||
char *error;
|
||||
|
||||
/* Must have at least one dot */
|
||||
fail_if(check_topdomain("abcde.gh", &error));
|
||||
fail_unless(check_topdomain("abcdefgh", &error));
|
||||
fail_if(strcmp("No dots", error));
|
||||
|
||||
/* Not two consecutive dots */
|
||||
fail_unless(check_topdomain("abc..defgh", &error));
|
||||
fail_if(strcmp("Consecutive dots", error));
|
||||
|
||||
/* Not end with a dots */
|
||||
fail_unless(check_topdomain("abc.defgh.", &error));
|
||||
fail_if(strcmp("Ends with a dot", error));
|
||||
|
||||
/* No chunk longer than 63 chars */
|
||||
fail_if(check_topdomain("123456789012345678901234567890"
|
||||
"123456789012345678901234567890333.com", &error));
|
||||
fail_unless(check_topdomain("123456789012345678901234567890"
|
||||
"1234567890123456789012345678904444.com", &error));
|
||||
fail_if(strcmp("Too long domain part (> 63)", error));
|
||||
|
||||
fail_if(check_topdomain("abc.123456789012345678901234567890"
|
||||
"123456789012345678901234567890333.com", &error));
|
||||
fail_unless(check_topdomain("abc.123456789012345678901234567890"
|
||||
"1234567890123456789012345678904444.com", &error));
|
||||
fail_if(strcmp("Too long domain part (> 63)", error));
|
||||
|
||||
fail_if(check_topdomain("abc.123456789012345678901234567890"
|
||||
"123456789012345678901234567890333", &error));
|
||||
fail_unless(check_topdomain("abc.123456789012345678901234567890"
|
||||
"1234567890123456789012345678904444", &error));
|
||||
fail_if(strcmp("Too long domain part (> 63)", error));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_parse_format_ipv4)
|
||||
{
|
||||
char *host = "192.168.2.10";
|
||||
char *formatted;
|
||||
struct sockaddr_storage addr;
|
||||
struct sockaddr_in *v4addr;
|
||||
int addr_len;
|
||||
|
||||
addr_len = get_addr(host, 53, AF_INET, 0, &addr);
|
||||
fail_unless(addr_len == sizeof(struct sockaddr_in));
|
||||
|
||||
v4addr = (struct sockaddr_in *) &addr;
|
||||
fail_unless(v4addr->sin_addr.s_addr == htonl(0xc0a8020a));
|
||||
fail_unless(v4addr->sin_port == htons(53));
|
||||
|
||||
formatted = format_addr(&addr, addr_len);
|
||||
fail_if(strcmp(host, formatted));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_parse_format_ipv4_listen_all)
|
||||
{
|
||||
char *host = "0.0.0.0";
|
||||
char *formatted;
|
||||
struct sockaddr_storage addr;
|
||||
struct sockaddr_in *v4addr;
|
||||
int addr_len;
|
||||
|
||||
addr_len = get_addr(NULL, 53, AF_INET, AI_PASSIVE, &addr);
|
||||
fail_unless(addr_len == sizeof(struct sockaddr_in));
|
||||
|
||||
v4addr = (struct sockaddr_in *) &addr;
|
||||
fail_unless(v4addr->sin_addr.s_addr == htonl(0x00000000));
|
||||
fail_unless(v4addr->sin_port == htons(53));
|
||||
|
||||
formatted = format_addr(&addr, addr_len);
|
||||
fail_if(strcmp(host, formatted));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_parse_format_ipv6)
|
||||
{
|
||||
char *host = "2001:0db8:0505:0::123:0abc";
|
||||
char *compact = "2001:db8:505::123:abc";
|
||||
unsigned char v6_bits[] = {
|
||||
0x20, 0x01, 0x0d, 0xb8, 0x05, 0x05, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x23, 0x0a, 0xbc,
|
||||
};
|
||||
char *formatted;
|
||||
struct sockaddr_storage addr;
|
||||
struct sockaddr_in6 *v6addr;
|
||||
int addr_len;
|
||||
|
||||
addr_len = get_addr(host, 53, AF_UNSPEC, 0, &addr);
|
||||
fail_unless(addr_len == sizeof(struct sockaddr_in6));
|
||||
|
||||
v6addr = (struct sockaddr_in6 *) &addr;
|
||||
fail_if(memcmp(&v6addr->sin6_addr, v6_bits, sizeof(v6_bits)));
|
||||
fail_unless(v6addr->sin6_port == htons(53));
|
||||
|
||||
formatted = format_addr(&addr, addr_len);
|
||||
fail_if(strcmp(compact, formatted));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_parse_format_ipv4_mapped_ipv6)
|
||||
{
|
||||
char *v4mapped = "::FFFF:192.168.2.10";
|
||||
char *host = "192.168.2.10";
|
||||
unsigned char v6_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xff, 0xff, 0xc0, 0xa8, 0x02, 0x0a,
|
||||
};
|
||||
char *formatted;
|
||||
struct sockaddr_storage addr;
|
||||
struct sockaddr_in6 *v6addr;
|
||||
int addr_len;
|
||||
|
||||
addr_len = get_addr(v4mapped, 53, AF_INET6, 0, &addr);
|
||||
fail_unless(addr_len == sizeof(struct sockaddr_in6));
|
||||
|
||||
v6addr = (struct sockaddr_in6 *) &addr;
|
||||
fail_if(memcmp(&v6addr->sin6_addr, v6_bits, sizeof(v6_bits)));
|
||||
fail_unless(v6addr->sin6_port == htons(53));
|
||||
|
||||
/* Format as IPv4 address */
|
||||
formatted = format_addr(&addr, addr_len);
|
||||
fail_if(strcmp(host, formatted));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
TCase *
|
||||
test_common_create_tests()
|
||||
{
|
||||
TCase *tc;
|
||||
int sock;
|
||||
|
||||
tc = tcase_create("Common");
|
||||
tcase_add_test(tc, test_topdomain_ok);
|
||||
tcase_add_test(tc, test_topdomain_length);
|
||||
tcase_add_test(tc, test_topdomain_chunks);
|
||||
tcase_add_test(tc, test_parse_format_ipv4);
|
||||
tcase_add_test(tc, test_parse_format_ipv4_listen_all);
|
||||
|
||||
/* Tests require IPv6 support */
|
||||
sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (sock >= 0) {
|
||||
close(sock);
|
||||
tcase_add_test(tc, test_parse_format_ipv6);
|
||||
tcase_add_test(tc, test_parse_format_ipv4_mapped_ipv6);
|
||||
}
|
||||
return tc;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -24,6 +25,10 @@
|
||||
#include <netinet/in.h>
|
||||
#include <sys/stat.h>
|
||||
#include <arpa/nameser.h>
|
||||
#ifdef DARWIN
|
||||
#define BIND_8_COMPAT
|
||||
#include <arpa/nameser_compat.h>
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
#include "dns.h"
|
||||
@@ -159,8 +164,8 @@ START_TEST(test_decode_response)
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
|
||||
ret = dns_decode(buf, len, &q, QR_ANSWER, answer_packet, sizeof(answer_packet)-1);
|
||||
fail_unless(strncmp(msgData, buf, sizeof(msgData)) == 0, "Did not extract expected data");
|
||||
fail_unless(ret == strlen(msgData), "Bad data length: %d, expected %d", ret, strlen(msgData));
|
||||
fail_unless(strncmp(msgData, buf, strlen(msgData)) == 0, "Did not extract expected data");
|
||||
fail_unless(q.id == 0x0539);
|
||||
}
|
||||
END_TEST
|
||||
@@ -176,8 +181,8 @@ START_TEST(test_decode_response_with_high_trans_id)
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
|
||||
ret = dns_decode(buf, len, &q, QR_ANSWER, answer_packet_high_trans_id, sizeof(answer_packet_high_trans_id)-1);
|
||||
fail_unless(strncmp(msgData, buf, sizeof(msgData)) == 0, "Did not extract expected data");
|
||||
fail_unless(ret == strlen(msgData), "Bad data length: %d, expected %d", ret, strlen(msgData));
|
||||
fail_unless(strncmp(msgData, buf, strlen(msgData)) == 0, "Did not extract expected data");
|
||||
fail_unless(q.id == 0x8539, "q.id was %08X instead of %08X!", q.id, 0x8539);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -84,7 +85,7 @@ START_TEST(test_build_hostname)
|
||||
}
|
||||
|
||||
buflen = sizeof(buf);
|
||||
|
||||
|
||||
for (i = 1; i < sizeof(data); i++) {
|
||||
int len = build_hostname(buf, buflen, data, i, topdomain, get_base32_encoder(), sizeof(buf));
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2009-2014 Erik Ekman <yarrick@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -28,7 +28,7 @@ START_TEST(test_fw_query_simple)
|
||||
q.id = 0x848A;
|
||||
|
||||
fw_query_init();
|
||||
|
||||
|
||||
/* Test empty cache */
|
||||
fw_query_get(0x848A, &qp);
|
||||
fail_unless(qp == NULL);
|
||||
@@ -49,7 +49,7 @@ START_TEST(test_fw_query_edge)
|
||||
int i;
|
||||
|
||||
fw_query_init();
|
||||
|
||||
|
||||
q.addrlen = 33;
|
||||
q.id = 0x848A;
|
||||
fw_query_put(&q);
|
||||
@@ -64,7 +64,7 @@ START_TEST(test_fw_query_edge)
|
||||
fw_query_get(0x848A, &qp);
|
||||
fail_unless(qp->addrlen == 33);
|
||||
fail_unless(qp->id == 0x848A);
|
||||
|
||||
|
||||
q.addrlen++;
|
||||
q.id++;
|
||||
fw_query_put(&q);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
||||
+8
-12
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -20,7 +21,8 @@
|
||||
#include <sys/stat.h>
|
||||
#include <arpa/nameser.h>
|
||||
#ifdef DARWIN
|
||||
#include <arpa/nameser8_compat.h>
|
||||
#define BIND_8_COMPAT
|
||||
#include <arpa/nameser_compat.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
@@ -49,7 +51,7 @@ START_TEST(test_read_putshort)
|
||||
i, ntohs(k), i);
|
||||
|
||||
p = (char*)&k;
|
||||
readshort(NULL, &p, (short *) &l);
|
||||
readshort(NULL, &p, &l);
|
||||
fail_unless(l == i,
|
||||
"Bad value on readshort for %d: %d != %d",
|
||||
i, l, i);
|
||||
@@ -96,6 +98,7 @@ START_TEST(test_read_name_empty_loop)
|
||||
data = (char*) emptyloop + sizeof(HEADER);
|
||||
buf[1023] = 'A';
|
||||
rv = readname((char *) emptyloop, sizeof(emptyloop), &data, buf, 1023);
|
||||
fail_unless(rv == 0);
|
||||
fail_unless(buf[1023] == 'A');
|
||||
}
|
||||
END_TEST
|
||||
@@ -113,6 +116,7 @@ START_TEST(test_read_name_inf_loop)
|
||||
data = (char*) infloop + sizeof(HEADER);
|
||||
buf[4] = '\a';
|
||||
rv = readname((char*) infloop, sizeof(infloop), &data, buf, 4);
|
||||
fail_unless(rv == 3);
|
||||
fail_unless(buf[4] == '\a');
|
||||
}
|
||||
END_TEST
|
||||
@@ -136,6 +140,7 @@ START_TEST(test_read_name_longname)
|
||||
data = (char*) longname + sizeof(HEADER);
|
||||
buf[256] = '\a';
|
||||
rv = readname((char*) longname, sizeof(longname), &data, buf, 256);
|
||||
fail_unless(rv == 256);
|
||||
fail_unless(buf[256] == '\a');
|
||||
}
|
||||
END_TEST
|
||||
@@ -213,11 +218,8 @@ START_TEST(test_putname)
|
||||
char buf[256];
|
||||
char *domain = "BADGER.BADGER.KRYO.SE";
|
||||
char *b;
|
||||
int len;
|
||||
int ret;
|
||||
|
||||
len = 256;
|
||||
|
||||
memset(buf, 0, 256);
|
||||
b = buf;
|
||||
ret = putname(&b, 256, domain);
|
||||
@@ -234,11 +236,8 @@ START_TEST(test_putname_nodot)
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
char *b;
|
||||
int len;
|
||||
int ret;
|
||||
|
||||
len = 256;
|
||||
|
||||
memset(buf, 0, 256);
|
||||
b = buf;
|
||||
ret = putname(&b, 256, nodot);
|
||||
@@ -259,11 +258,8 @@ START_TEST(test_putname_toolong)
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ."
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ.";
|
||||
char *b;
|
||||
int len;
|
||||
int ret;
|
||||
|
||||
len = 256;
|
||||
|
||||
memset(buf, 0, 256);
|
||||
b = buf;
|
||||
ret = putname(&b, 256, toolong);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -38,6 +39,9 @@ main()
|
||||
test = test_base64_create_tests();
|
||||
suite_add_tcase(iodine, test);
|
||||
|
||||
test = test_common_create_tests();
|
||||
suite_add_tcase(iodine, test);
|
||||
|
||||
test = test_dns_create_tests();
|
||||
suite_add_tcase(iodine, test);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -19,6 +20,7 @@
|
||||
|
||||
TCase *test_base32_create_tests();
|
||||
TCase *test_base64_create_tests();
|
||||
TCase *test_common_create_tests();
|
||||
TCase *test_dns_create_tests();
|
||||
TCase *test_encoding_create_tests();
|
||||
TCase *test_read_create_tests();
|
||||
@@ -27,11 +29,11 @@ TCase *test_user_create_tests();
|
||||
TCase *test_fw_query_create_tests();
|
||||
|
||||
char *va_str(const char *, ...);
|
||||
|
||||
|
||||
#if (CHECK_MAJOR_VERSION == 0 && \
|
||||
((CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION < 2) || \
|
||||
(CHECK_MINOR_VERSION < 9)))
|
||||
#define tcase_set_timeout(...)
|
||||
#define tcase_set_timeout(...)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+30
-19
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
||||
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -19,8 +20,8 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "encoding.h"
|
||||
@@ -32,10 +33,11 @@ START_TEST(test_init_users)
|
||||
in_addr_t ip;
|
||||
char givenip[16];
|
||||
int i;
|
||||
int count;
|
||||
|
||||
ip = inet_addr("127.0.0.1");
|
||||
init_users(ip, 27);
|
||||
for (i = 0; i < USERS; i++) {
|
||||
count = init_users(ip, 27);
|
||||
for (i = 0; i < count; i++) {
|
||||
fail_unless(users[i].id == i);
|
||||
fail_unless(users[i].q.id == 0);
|
||||
fail_unless(users[i].inpacket.len == 0);
|
||||
@@ -60,12 +62,12 @@ START_TEST(test_users_waiting)
|
||||
fail_unless(users_waiting_on_reply() == 0);
|
||||
|
||||
users[3].last_pkt = time(NULL);
|
||||
|
||||
|
||||
fail_unless(users_waiting_on_reply() == 0);
|
||||
|
||||
|
||||
users[3].conn = CONN_DNS_NULL;
|
||||
users[3].q.id = 1;
|
||||
|
||||
|
||||
fail_unless(users_waiting_on_reply() == 1);
|
||||
}
|
||||
END_TEST
|
||||
@@ -81,17 +83,22 @@ START_TEST(test_find_user_by_ip)
|
||||
|
||||
testip = (unsigned int) inet_addr("10.0.0.1");
|
||||
fail_unless(find_user_by_ip(testip) == -1);
|
||||
|
||||
|
||||
testip = (unsigned int) inet_addr("127.0.0.2");
|
||||
fail_unless(find_user_by_ip(testip) == -1);
|
||||
|
||||
|
||||
users[0].active = 1;
|
||||
|
||||
|
||||
testip = (unsigned int) inet_addr("127.0.0.2");
|
||||
fail_unless(find_user_by_ip(testip) == -1);
|
||||
|
||||
|
||||
users[0].last_pkt = time(NULL);
|
||||
|
||||
|
||||
testip = (unsigned int) inet_addr("127.0.0.2");
|
||||
fail_unless(find_user_by_ip(testip) == -1);
|
||||
|
||||
users[0].authenticated = 1;
|
||||
|
||||
testip = (unsigned int) inet_addr("127.0.0.2");
|
||||
fail_unless(find_user_by_ip(testip) == 0);
|
||||
}
|
||||
@@ -105,15 +112,15 @@ START_TEST(test_all_users_waiting_to_send)
|
||||
init_users(ip, 27);
|
||||
|
||||
fail_unless(all_users_waiting_to_send() == 1);
|
||||
|
||||
|
||||
users[0].conn = CONN_DNS_NULL;
|
||||
users[0].active = 1;
|
||||
|
||||
|
||||
fail_unless(all_users_waiting_to_send() == 1);
|
||||
|
||||
|
||||
users[0].last_pkt = time(NULL);
|
||||
users[0].outpacket.len = 0;
|
||||
|
||||
|
||||
fail_unless(all_users_waiting_to_send() == 0);
|
||||
|
||||
#ifdef OUTPACKETQ_LEN
|
||||
@@ -121,7 +128,7 @@ START_TEST(test_all_users_waiting_to_send)
|
||||
#else
|
||||
users[0].outpacket.len = 44;
|
||||
#endif
|
||||
|
||||
|
||||
fail_unless(all_users_waiting_to_send() == 1);
|
||||
}
|
||||
END_TEST
|
||||
@@ -135,7 +142,11 @@ START_TEST(test_find_available_user)
|
||||
init_users(ip, 27);
|
||||
|
||||
for (i = 0; i < USERS; i++) {
|
||||
users[i].authenticated = 1;
|
||||
users[i].authenticated_raw = 1;
|
||||
fail_unless(find_available_user() == i);
|
||||
fail_if(users[i].authenticated);
|
||||
fail_if(users[i].authenticated_raw);
|
||||
}
|
||||
|
||||
for (i = 0; i < USERS; i++) {
|
||||
@@ -148,7 +159,7 @@ START_TEST(test_find_available_user)
|
||||
fail_unless(find_available_user() == -1);
|
||||
|
||||
users[3].last_pkt = 55;
|
||||
|
||||
|
||||
fail_unless(find_available_user() == 3);
|
||||
fail_unless(find_available_user() == -1);
|
||||
}
|
||||
@@ -176,7 +187,7 @@ START_TEST(test_find_available_user_small_net)
|
||||
fail_unless(find_available_user() == -1);
|
||||
|
||||
users[3].last_pkt = 55;
|
||||
|
||||
|
||||
fail_unless(find_available_user() == 3);
|
||||
fail_unless(find_available_user() == -1);
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 19 KiB |
@@ -37,7 +37,7 @@
|
||||
|
||||
<Button
|
||||
android:drawableLeft="@drawable/cancel"
|
||||
android:text="Cancel"
|
||||
android:text="Close"
|
||||
android:id="@+id/status_cancel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
|
||||
+192
-192
@@ -15,8 +15,11 @@
|
||||
width="1000"
|
||||
height="1000"
|
||||
id="svg2"
|
||||
inkscape:version="0.48.3.1 r9886"
|
||||
sodipodi:docname="logo.svg">
|
||||
inkscape:version="0.48.5 r10040"
|
||||
sodipodi:docname="logo.svg"
|
||||
inkscape:export-filename="/home/yvesf/vcs/andiodine-github/res/drawable/logo.png"
|
||||
inkscape:export-xdpi="11.52"
|
||||
inkscape:export-ydpi="11.52">
|
||||
<metadata
|
||||
id="metadata82">
|
||||
<rdf:RDF>
|
||||
@@ -25,6 +28,7 @@
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
@@ -37,17 +41,17 @@
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1916"
|
||||
inkscape:window-height="1180"
|
||||
inkscape:window-width="1436"
|
||||
inkscape:window-height="880"
|
||||
id="namedview80"
|
||||
showgrid="false"
|
||||
inkscape:zoom="0.236"
|
||||
inkscape:cx="-309.15823"
|
||||
inkscape:cy="-43.472837"
|
||||
inkscape:zoom="0.6675088"
|
||||
inkscape:cx="478.53622"
|
||||
inkscape:cy="487.65456"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="18"
|
||||
inkscape:window-maximized="0"
|
||||
inkscape:current-layer="g3243-6" />
|
||||
inkscape:current-layer="svg2" />
|
||||
<defs
|
||||
id="defs6">
|
||||
<circle
|
||||
@@ -59,145 +63,140 @@
|
||||
sodipodi:cy="0"
|
||||
sodipodi:rx="30"
|
||||
sodipodi:ry="30"
|
||||
style="fill:#b7c6cb;stroke:none" />
|
||||
style="fill:#fafafa;stroke:#2f2f2f" />
|
||||
</defs>
|
||||
<circle
|
||||
d="m 200,0 c 0,110.45695 -89.54305,200 -200,200 -110.45695,0 -200,-89.54305 -200,-200 0,-110.45695 89.54305,-200 200,-200 110.45695,0 200,89.54305 200,200 z"
|
||||
r="200"
|
||||
id="circle3227-5"
|
||||
cx="0"
|
||||
cy="0"
|
||||
sodipodi:cx="0"
|
||||
sodipodi:cy="0"
|
||||
sodipodi:rx="200"
|
||||
sodipodi:ry="200"
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#343434;stroke-width:2.26129237;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
transform="matrix(0.944522,0,0,0.94201149,-300,-300)" />
|
||||
<g
|
||||
style="display:inline"
|
||||
id="g3225-7"
|
||||
transform="matrix(0.89905744,0,0,0.94208582,-25.711286,-29.3741)">
|
||||
<circle
|
||||
transform="matrix(0.87892157,0,0,0.83654869,-305.08475,-287.26247)"
|
||||
style="fill:#f6ffec;stroke:#343434;stroke-width:10;fill-opacity:1"
|
||||
sodipodi:ry="200"
|
||||
sodipodi:rx="200"
|
||||
sodipodi:cy="0"
|
||||
sodipodi:cx="0"
|
||||
cy="0"
|
||||
cx="0"
|
||||
id="circle3227-5"
|
||||
r="200"
|
||||
d="m 200,0 c 0,110.45695 -89.54305,200 -200,200 -110.45695,0 -200,-89.54305 -200,-200 0,-110.45695 89.54305,-200 200,-200 110.45695,0 200,89.54305 200,200 z" />
|
||||
id="g3229-2"
|
||||
transform="matrix(0.93986331,0,0,0.98484463,-298.58417,-403.20625)">
|
||||
<g
|
||||
transform="matrix(0.86112107,0,0,0.86112107,-303.56771,-377.84524)"
|
||||
id="g3229-2">
|
||||
id="g3231-9"
|
||||
style="fill:#a4c639">
|
||||
<g
|
||||
style="fill:#a4c639"
|
||||
id="g3231-9">
|
||||
<g
|
||||
id="use3233-3"
|
||||
style="stroke:#ffffff;stroke-width:7.19999981"
|
||||
transform="scale(-1,1)">
|
||||
<rect
|
||||
id="rect3571"
|
||||
x="14"
|
||||
y="-86"
|
||||
width="13"
|
||||
height="86"
|
||||
transform="matrix(0.87461971,0.48480962,-0.48480962,0.87461971,0,0)"
|
||||
rx="6.5"
|
||||
style="stroke:none" />
|
||||
<rect
|
||||
x="-143"
|
||||
y="41"
|
||||
width="48"
|
||||
height="133"
|
||||
rx="24"
|
||||
id="rect3573"
|
||||
style="stroke:none" />
|
||||
<rect
|
||||
x="-58"
|
||||
y="138"
|
||||
width="48"
|
||||
height="133"
|
||||
rx="24"
|
||||
id="use3575"
|
||||
style="stroke:none" />
|
||||
</g>
|
||||
<g
|
||||
style="stroke:#ffffff;stroke-width:7.19999981"
|
||||
id="g3235-5">
|
||||
<rect
|
||||
style="stroke:none"
|
||||
rx="6.5"
|
||||
transform="matrix(0.87461971,0.48480962,-0.48480962,0.87461971,0,0)"
|
||||
height="86"
|
||||
width="13"
|
||||
y="-86"
|
||||
x="14"
|
||||
id="rect3237-7" />
|
||||
<rect
|
||||
style="stroke:none"
|
||||
id="rect3239-4"
|
||||
rx="24"
|
||||
height="133"
|
||||
width="48"
|
||||
y="41"
|
||||
x="-143" />
|
||||
<rect
|
||||
x="-58"
|
||||
y="138"
|
||||
width="48"
|
||||
height="133"
|
||||
rx="24"
|
||||
id="use3241-5"
|
||||
style="stroke:none" />
|
||||
</g>
|
||||
<g
|
||||
id="g3243-6">
|
||||
<ellipse
|
||||
d="m 91,41 c 0,46.391919 -40.742088,84 -91,84 -50.257912,0 -91,-37.608081 -91,-84 0,-46.391919 40.742088,-84 91,-84 50.257912,0 91,37.608081 91,84 z"
|
||||
sodipodi:ry="84"
|
||||
sodipodi:rx="91"
|
||||
sodipodi:cy="41"
|
||||
sodipodi:cx="0"
|
||||
cx="0"
|
||||
cy="41"
|
||||
rx="91"
|
||||
ry="84"
|
||||
id="ellipse3245-2"
|
||||
style="fill:#a4c639;fill-opacity:1;stroke:#a4c639;stroke-opacity:1" />
|
||||
<path
|
||||
style=""
|
||||
d="M 447.9375 430.875 C 439.93814 430.875 433.28525 436.60888 431.4375 444.375 L 571.28125 444.375 C 569.43246 436.61046 562.77955 430.875 554.78125 430.875 L 447.9375 430.875 z M 430.90625 451 L 430.90625 560.6875 C 430.90625 570.57501 438.50158 578.53125 447.9375 578.53125 L 554.78125 578.53125 C 564.21717 578.53125 571.8125 570.57501 571.8125 560.6875 L 571.8125 451 L 430.90625 451 z "
|
||||
transform="matrix(1.2916604,0,0,1.2326657,-647.5919,-511.14118)"
|
||||
id="rect3247-7" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
style="fill:#ffffff;stroke:#ffffff;stroke-width:7.04677343;display:inline"
|
||||
d="M -90.99955,40.88152 H 90.999549"
|
||||
id="path3251-2" />
|
||||
</g>
|
||||
<g
|
||||
style="fill:#ffffff;stroke:#ffffff;stroke-width:7.19999981;display:inline"
|
||||
id="g3249-3"
|
||||
transform="translate(-0.049281,4.3465664)">
|
||||
<circle
|
||||
d="m -38,0 c 0,2.209139 -1.790861,4 -4,4 -2.209139,0 -4,-1.790861 -4,-4 0,-2.209139 1.790861,-4 4,-4 2.209139,0 4,1.790861 4,4 z"
|
||||
sodipodi:ry="4"
|
||||
sodipodi:rx="4"
|
||||
sodipodi:cy="0"
|
||||
sodipodi:cx="-42"
|
||||
cy="0"
|
||||
cx="-42"
|
||||
r="4"
|
||||
id="circle3253-6" />
|
||||
<circle
|
||||
d="m 46,0 c 0,2.209139 -1.790861,4 -4,4 -2.209139,0 -4,-1.790861 -4,-4 0,-2.209139 1.790861,-4 4,-4 2.209139,0 4,1.790861 4,4 z"
|
||||
sodipodi:ry="4"
|
||||
sodipodi:rx="4"
|
||||
sodipodi:cy="0"
|
||||
sodipodi:cx="42"
|
||||
cy="0"
|
||||
cx="42"
|
||||
r="4"
|
||||
id="circle3255-6" />
|
||||
</g>
|
||||
transform="scale(-1,1)"
|
||||
style="stroke:#ffffff;stroke-width:7.19999981"
|
||||
id="use3233-3">
|
||||
<rect
|
||||
style="stroke:none"
|
||||
rx="6.5"
|
||||
transform="matrix(0.87461971,0.48480962,-0.48480962,0.87461971,0,0)"
|
||||
height="86"
|
||||
width="13"
|
||||
y="-86"
|
||||
x="14"
|
||||
id="rect3571" />
|
||||
<rect
|
||||
style="stroke:none"
|
||||
id="rect3573"
|
||||
rx="24"
|
||||
height="133"
|
||||
width="48"
|
||||
y="41"
|
||||
x="-143" />
|
||||
<rect
|
||||
style="stroke:none"
|
||||
id="use3575"
|
||||
rx="24"
|
||||
height="133"
|
||||
width="48"
|
||||
y="138"
|
||||
x="-58" />
|
||||
</g>
|
||||
<g
|
||||
id="g3235-5"
|
||||
style="stroke:#ffffff;stroke-width:7.19999981">
|
||||
<rect
|
||||
id="rect3237-7"
|
||||
x="14"
|
||||
y="-86"
|
||||
width="13"
|
||||
height="86"
|
||||
transform="matrix(0.87461971,0.48480962,-0.48480962,0.87461971,0,0)"
|
||||
rx="6.5"
|
||||
style="stroke:none" />
|
||||
<rect
|
||||
x="-143"
|
||||
y="41"
|
||||
width="48"
|
||||
height="133"
|
||||
rx="24"
|
||||
id="rect3239-4"
|
||||
style="stroke:none" />
|
||||
<rect
|
||||
style="stroke:none"
|
||||
id="use3241-5"
|
||||
rx="24"
|
||||
height="133"
|
||||
width="48"
|
||||
y="138"
|
||||
x="-58" />
|
||||
</g>
|
||||
<g
|
||||
id="g3243-6">
|
||||
<ellipse
|
||||
style="fill:#a4c639;fill-opacity:1;stroke:#a4c639;stroke-opacity:1"
|
||||
id="ellipse3245-2"
|
||||
ry="84"
|
||||
rx="91"
|
||||
cy="41"
|
||||
cx="0"
|
||||
sodipodi:cx="0"
|
||||
sodipodi:cy="41"
|
||||
sodipodi:rx="91"
|
||||
sodipodi:ry="84"
|
||||
d="m 91,41 c 0,46.391919 -40.742088,84 -91,84 -50.257912,0 -91,-37.608081 -91,-84 0,-46.391919 40.742088,-84 91,-84 50.257912,0 91,37.608081 91,84 z" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="rect3247-7"
|
||||
transform="matrix(1.2916604,0,0,1.2326657,-647.5919,-511.14118)"
|
||||
d="m 447.9375,430.875 c -7.99936,0 -14.65225,5.73388 -16.5,13.5 l 139.84375,0 c -1.84879,-7.76454 -8.5017,-13.5 -16.5,-13.5 l -106.84375,0 z M 430.90625,451 l 0,109.6875 c 0,9.88751 7.59533,17.84375 17.03125,17.84375 l 106.84375,0 c 9.43592,0 17.03125,-7.95624 17.03125,-17.84375 l 0,-109.6875 -140.90625,0 z" />
|
||||
<path
|
||||
id="path3251-2"
|
||||
d="M -90.99955,40.88152 H 90.999549"
|
||||
style="fill:#ffffff;stroke:#ffffff;stroke-width:7.04677343;display:inline"
|
||||
inkscape:connector-curvature="0" />
|
||||
</g>
|
||||
<g
|
||||
transform="translate(-0.049281,4.3465664)"
|
||||
id="g3249-3"
|
||||
style="fill:#ffffff;stroke:#ffffff;stroke-width:7.19999981;display:inline">
|
||||
<circle
|
||||
id="circle3253-6"
|
||||
r="4"
|
||||
cx="-42"
|
||||
cy="0"
|
||||
sodipodi:cx="-42"
|
||||
sodipodi:cy="0"
|
||||
sodipodi:rx="4"
|
||||
sodipodi:ry="4"
|
||||
d="m -38,0 c 0,2.209139 -1.790861,4 -4,4 -2.209139,0 -4,-1.790861 -4,-4 0,-2.209139 1.790861,-4 4,-4 2.209139,0 4,1.790861 4,4 z" />
|
||||
<circle
|
||||
id="circle3255-6"
|
||||
r="4"
|
||||
cx="42"
|
||||
cy="0"
|
||||
sodipodi:cx="42"
|
||||
sodipodi:cy="0"
|
||||
sodipodi:rx="4"
|
||||
sodipodi:ry="4"
|
||||
d="m 46,0 c 0,2.209139 -1.790861,4 -4,4 -2.209139,0 -4,-1.790861 -4,-4 0,-2.209139 1.790861,-4 4,-4 2.209139,0 4,1.790861 4,4 z" />
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<g
|
||||
id="g4283"
|
||||
transform="translate(0,-8.73212)">
|
||||
transform="matrix(1.0380709,0,0,1.0380709,11.421268,11.421265)">
|
||||
<circle
|
||||
transform="matrix(0.73071782,0,0,0.73071782,-300,-291.26788)"
|
||||
id="shell_1"
|
||||
@@ -218,7 +217,7 @@
|
||||
x="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_1_shell_1"
|
||||
xlink:href="#electron_0_shell_1"
|
||||
@@ -227,7 +226,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<circle
|
||||
transform="matrix(0.67170146,0,0,0.67170146,-300,-291.26788)"
|
||||
id="shell_2"
|
||||
@@ -248,7 +247,7 @@
|
||||
x="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_1_shell_2"
|
||||
xlink:href="#electron_0_shell_2"
|
||||
@@ -257,7 +256,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_2_shell_2"
|
||||
xlink:href="#electron_0_shell_2"
|
||||
@@ -266,7 +265,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_3_shell_2"
|
||||
xlink:href="#electron_0_shell_2"
|
||||
@@ -275,7 +274,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_4_shell_2"
|
||||
xlink:href="#electron_0_shell_2"
|
||||
@@ -284,7 +283,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_5_shell_2"
|
||||
xlink:href="#electron_0_shell_2"
|
||||
@@ -293,7 +292,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_6_shell_2"
|
||||
xlink:href="#electron_0_shell_2"
|
||||
@@ -302,7 +301,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_7_shell_2"
|
||||
xlink:href="#electron_0_shell_2"
|
||||
@@ -311,7 +310,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<circle
|
||||
transform="matrix(0.67170146,0,0,0.67170146,-300,-291.26788)"
|
||||
id="shell_3"
|
||||
@@ -332,7 +331,7 @@
|
||||
x="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_1_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -341,7 +340,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_2_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -350,7 +349,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_3_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -359,7 +358,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_4_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -368,7 +367,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_5_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -377,7 +376,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_6_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -386,7 +385,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_7_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -395,7 +394,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_8_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -404,7 +403,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_9_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -413,7 +412,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_10_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -422,7 +421,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_11_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -431,7 +430,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_12_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -440,7 +439,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_13_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -449,7 +448,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_14_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -458,7 +457,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_15_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -467,7 +466,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_16_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -476,7 +475,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#00d7d7;fill-opacity:1;stroke:#000000;stroke-width:8" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_17_shell_3"
|
||||
xlink:href="#electron_0_shell_3"
|
||||
@@ -485,7 +484,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<circle
|
||||
transform="matrix(0.67170146,0,0,0.67170146,-300,-291.26788)"
|
||||
id="shell_4"
|
||||
@@ -506,7 +505,7 @@
|
||||
x="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_1_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -515,7 +514,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_2_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -524,7 +523,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:9.6332534;stroke-miterlimit:4;stroke-dasharray:none" />
|
||||
<use
|
||||
id="electron_3_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -533,7 +532,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_4_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -542,7 +541,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_5_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -551,7 +550,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_6_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -560,7 +559,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_7_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -569,7 +568,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_8_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -578,7 +577,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_9_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -587,7 +586,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_10_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -596,7 +595,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_11_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -605,7 +604,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_12_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -614,7 +613,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_13_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -623,7 +622,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_14_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -632,7 +631,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_15_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -641,7 +640,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_16_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -650,7 +649,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_17_shell_4"
|
||||
xlink:href="#electron_0_shell_4"
|
||||
@@ -659,7 +658,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<circle
|
||||
transform="matrix(0.67170146,0,0,0.67170146,-300,-291.26788)"
|
||||
id="shell_5"
|
||||
@@ -673,9 +672,10 @@
|
||||
d="M 700,0 C 700,386.59932 386.59932,700 0,700 -386.59932,700 -700,386.59932 -700,0 c 0,-386.59932 313.40068,-700 700,-700 386.59932,0 700,313.40068 700,700 z"
|
||||
style="fill:none;stroke:#77868b;stroke-width:8" />
|
||||
<a
|
||||
id="a4147">
|
||||
id="a4147"
|
||||
style="fill:none;stroke:none;fill-opacity:1">
|
||||
<use
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1"
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8"
|
||||
height="1600"
|
||||
width="1600"
|
||||
x="0"
|
||||
@@ -692,7 +692,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_2_shell_5"
|
||||
xlink:href="#electron_0_shell_5"
|
||||
@@ -701,7 +701,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_3_shell_5"
|
||||
xlink:href="#electron_0_shell_5"
|
||||
@@ -710,7 +710,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_4_shell_5"
|
||||
xlink:href="#electron_0_shell_5"
|
||||
@@ -719,7 +719,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_5_shell_5"
|
||||
xlink:href="#electron_0_shell_5"
|
||||
@@ -728,7 +728,7 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
<use
|
||||
id="electron_6_shell_5"
|
||||
xlink:href="#electron_0_shell_5"
|
||||
@@ -737,6 +737,6 @@
|
||||
y="0"
|
||||
width="1600"
|
||||
height="1600"
|
||||
style="fill:#ff0000;stroke:#ff0000;stroke-width:8;fill-opacity:1" />
|
||||
style="fill:none;fill-opacity:1;stroke:none;stroke-width:8" />
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 24 KiB |
@@ -17,8 +17,6 @@ import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableString;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -21,19 +24,25 @@ public class FragmentStatus extends Fragment {
|
||||
private TextView mStatus;
|
||||
private TextView mLogmessages;
|
||||
private ScrollView mScrollview;
|
||||
private Button mCancel;
|
||||
private Button mClose;
|
||||
|
||||
private final BroadcastReceiver broadcastReceiverStatusUpdates = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d(TAG, "Got intent: " + intent);
|
||||
if (IodineVpnService.ACTION_STATUS_ERROR.equals(intent.getAction())) {
|
||||
new AlertDialog.Builder(FragmentStatus.this.getActivity())//
|
||||
.setIcon(R.drawable.error) //
|
||||
.setTitle(intent.getStringExtra(IodineVpnService.EXTRA_ERROR_MESSAGE)) //
|
||||
.setMessage(mLogmessages.getText()) //
|
||||
.create() //
|
||||
.show();
|
||||
final TextView message = new TextView(context);
|
||||
final String stringMessage = intent.getStringExtra(IodineVpnService.EXTRA_ERROR_MESSAGE);
|
||||
final SpannableString s = new SpannableString(stringMessage);
|
||||
Linkify.addLinks(s, Linkify.WEB_URLS);
|
||||
message.setText(s);
|
||||
message.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
new AlertDialog.Builder(FragmentStatus.this.getActivity())//
|
||||
.setIcon(R.drawable.error) //
|
||||
.setTitle("Error") //
|
||||
.setView(message)
|
||||
.create() //
|
||||
.show();
|
||||
} else if (IodineVpnService.ACTION_STATUS_CONNECT.equals(intent.getAction())) {
|
||||
mStatus.setText("Connect");
|
||||
} else if (IodineVpnService.ACTION_STATUS_CONNECTED.equals(intent.getAction())) {
|
||||
@@ -48,8 +57,10 @@ public class FragmentStatus extends Fragment {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (IodineClient.ACTION_LOG_MESSAGE.equals(intent.getAction())) {
|
||||
mLogmessages.append("\n");
|
||||
mLogmessages.append(intent.getStringExtra(IodineClient.EXTRA_MESSAGE));
|
||||
final String newLogEntry = intent.getStringExtra(IodineClient.EXTRA_MESSAGE);
|
||||
if (!".".equals(newLogEntry)) // Suppress newline for progress indicator'.'
|
||||
mLogmessages.append("\n");
|
||||
mLogmessages.append(newLogEntry);
|
||||
mScrollview.fullScroll(View.FOCUS_DOWN);
|
||||
}
|
||||
}
|
||||
@@ -61,8 +72,8 @@ public class FragmentStatus extends Fragment {
|
||||
mStatus = (TextView) getActivity().findViewById(R.id.status_message);
|
||||
mLogmessages = (TextView) getActivity().findViewById(R.id.status_logmessages);
|
||||
mScrollview = (ScrollView) getActivity().findViewById(R.id.status_scrollview);
|
||||
mCancel = (Button) getActivity().findViewById(R.id.status_cancel);
|
||||
mCancel.setOnClickListener(new View.OnClickListener() {
|
||||
mClose = (Button) getActivity().findViewById(R.id.status_cancel);
|
||||
mClose.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
requestDisconnect();
|
||||
|
||||
@@ -35,7 +35,6 @@ public class IodineClient {
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public static void log_callback(String message) {
|
||||
Log.d(TAG, "Message: " + message);
|
||||
Intent intent = new Intent(ACTION_LOG_MESSAGE);
|
||||
|
||||
intent.putExtra(EXTRA_MESSAGE, message);
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.util.Log;
|
||||
import org.xapek.andiodine.config.ConfigDatabase;
|
||||
import org.xapek.andiodine.config.IodineConfiguration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
@@ -151,7 +152,10 @@ public class IodineVpnService extends VpnService implements Runnable {
|
||||
}
|
||||
|
||||
private void shutdown() {
|
||||
setStatus(ACTION_STATUS_DISCONNECT, mConfiguration.getId(), null);
|
||||
if (mConfiguration != null)
|
||||
setStatus(ACTION_STATUS_DISCONNECT, mConfiguration.getId(), null);
|
||||
else
|
||||
setStatus(ACTION_STATUS_IDLE, null, null);
|
||||
|
||||
if (mThread != null) {
|
||||
mThread.interrupt();
|
||||
@@ -221,7 +225,7 @@ public class IodineVpnService extends VpnService implements Runnable {
|
||||
case 0:
|
||||
Log.d(TAG, "Handshake successful");
|
||||
setStatus(ACTION_STATUS_CONNECTED, currentConfigurationId, null);
|
||||
runTunnel();
|
||||
runTunnel(); // this blocks until connection is closed
|
||||
setStatus(ACTION_STATUS_IDLE, null, null);
|
||||
break;
|
||||
case 1:
|
||||
@@ -313,8 +317,19 @@ public class IodineVpnService extends VpnService implements Runnable {
|
||||
}
|
||||
b.setMtu(mtu);
|
||||
|
||||
Log.d(TAG, "Build tunnel interface");
|
||||
ParcelFileDescriptor parcelFD = b.establish();
|
||||
Log.d(TAG, "Build tunnel interface");
|
||||
ParcelFileDescriptor parcelFD;
|
||||
try {
|
||||
parcelFD = b.establish();
|
||||
} catch (Exception e) {
|
||||
if (e.getMessage().contains("fwmark") || e.getMessage().contains("iptables")) {
|
||||
throw new IodineVpnException(
|
||||
"Error while creating interface, please check issue #9 at https://github.com/yvesf/andiodine/issues/9");
|
||||
} else {
|
||||
throw new IodineVpnException("Error while creating interface: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protect(IodineClient.getDnsFd());
|
||||
|
||||
@@ -322,7 +337,13 @@ public class IodineVpnService extends VpnService implements Runnable {
|
||||
|
||||
setStatus(ACTION_STATUS_CONNECTED, mConfiguration.getId(), null);
|
||||
|
||||
Log.d(TAG, "Tunnel active");
|
||||
IodineClient.tunnel(tun_fd);
|
||||
}
|
||||
Log.d(TAG, "Tunnel active");
|
||||
IodineClient.tunnel(tun_fd);
|
||||
try {
|
||||
ParcelFileDescriptor.adoptFd(tun_fd).close();
|
||||
} catch (IOException e) {
|
||||
throw new IodineVpnException(
|
||||
"Failed to close fd after tunnel exited");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,6 @@ public class ConfigDatabase extends SQLiteOpenHelper {
|
||||
long id = writableDatabase.insertOrThrow(TABLE_NAME_CONF, null, config);
|
||||
writableDatabase.close();
|
||||
config.put(COLUMN_CONF_ID, id);
|
||||
|
||||
Log.d(TAG, "Insert id=" + id);
|
||||
}
|
||||
|
||||
@@ -77,7 +76,6 @@ public class ConfigDatabase extends SQLiteOpenHelper {
|
||||
int rows = writableDatabase.update(TABLE_NAME_CONF, config, COLUMN_CONF_ID + " = ?",
|
||||
new String[]{config.getAsString(COLUMN_CONF_ID)});
|
||||
writableDatabase.close();
|
||||
Log.d(TAG, config.toString());
|
||||
Log.d(TAG, "Update rows=" + rows);
|
||||
return rows;
|
||||
}
|
||||
@@ -96,11 +94,11 @@ public class ConfigDatabase extends SQLiteOpenHelper {
|
||||
SQLiteDatabase readableDatabase = getReadableDatabase();
|
||||
Cursor query = readableDatabase.query(TABLE_NAME_CONF, null, COLUMN_CONF_ID + " = ?",
|
||||
new String[]{id.toString()}, null, null, null);
|
||||
assert query.isLast();
|
||||
query.moveToFirst();
|
||||
DatabaseUtils.cursorRowToContentValues(query, v);
|
||||
Log.d(TAG, "Selected: " + v.toString());
|
||||
return new IodineConfiguration(v);
|
||||
IodineConfiguration iodineConfiguration = new IodineConfiguration(v);
|
||||
Log.d(TAG, "Selected: " + iodineConfiguration);
|
||||
return iodineConfiguration;
|
||||
}
|
||||
|
||||
public List<IodineConfiguration> selectAll() throws SQLException {
|
||||
|
||||
@@ -124,4 +124,9 @@ public class IodineConfiguration {
|
||||
public ContentValues getContentValues() {
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[IodineConfiguration name=" + getName() + "]";
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.HelloJni.tests"
|
||||
package="org.xapek.andiodine.tests"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
-->
|
||||
<instrumentation
|
||||
android:name="android.test.InstrumentationTestRunner"
|
||||
android:label="Tests for HelloJni"
|
||||
android:targetPackage="com.example.HelloJni" />
|
||||
android:label="Tests for Andiodine"
|
||||
android:targetPackage="org.xapek.andiodine" />
|
||||
|
||||
</manifest>
|
||||
Reference in new issue
Block a user