aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2012-11-02 16:41:25 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2012-11-02 16:41:25 +0000
commit211fd52268a5ae7856273dd8d8b3b3ed427beadb (patch)
treef30b55769ea49eecf36cdf9a87ab3f2115b81565 /src
parentc8f6b6ac48fea41f20b3721295d0fa064b2d129d (diff)
downloadgnunet-211fd52268a5ae7856273dd8d8b3b3ed427beadb.tar.gz
gnunet-211fd52268a5ae7856273dd8d8b3b3ed427beadb.zip
Using regex for exit/vpn
Diffstat (limited to 'src')
-rw-r--r--src/exit/Makefile.am1
-rw-r--r--src/exit/gnunet-daemon-exit.c45
-rw-r--r--src/include/gnunet_applications.h6
-rw-r--r--src/vpn/Makefile.am1
-rw-r--r--src/vpn/gnunet-service-vpn.c43
5 files changed, 84 insertions, 12 deletions
diff --git a/src/exit/Makefile.am b/src/exit/Makefile.am
index dd030e7a4..2da59f14a 100644
--- a/src/exit/Makefile.am
+++ b/src/exit/Makefile.am
@@ -41,4 +41,5 @@ gnunet_daemon_exit_LDADD = \
41 $(top_builddir)/src/tun/libgnunettun.la \ 41 $(top_builddir)/src/tun/libgnunettun.la \
42 $(top_builddir)/src/util/libgnunetutil.la \ 42 $(top_builddir)/src/util/libgnunetutil.la \
43 $(top_builddir)/src/mesh/libgnunetmesh.la \ 43 $(top_builddir)/src/mesh/libgnunetmesh.la \
44 $(top_builddir)/src/regex/libgnunetregex.la \
44 $(GN_LIBINTL) 45 $(GN_LIBINTL)
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c
index 30be57845..e03a9b55c 100644
--- a/src/exit/gnunet-daemon-exit.c
+++ b/src/exit/gnunet-daemon-exit.c
@@ -42,9 +42,23 @@
42#include "gnunet_statistics_service.h" 42#include "gnunet_statistics_service.h"
43#include "gnunet_constants.h" 43#include "gnunet_constants.h"
44#include "gnunet_tun_lib.h" 44#include "gnunet_tun_lib.h"
45#include "gnunet_regex_lib.h"
45#include "exit.h" 46#include "exit.h"
46 47
47/** 48/**
49 * Maximum path compression length for mesh regex announcing for IPv4 address
50 * based regex.
51 */
52#define REGEX_MAX_PATH_LEN_IPV4 4
53
54/**
55 * Maximum path compression length for mesh regex announcing for IPv6 address
56 * based regex.
57 */
58#define REGEX_MAX_PATH_LEN_IPV6 8
59
60
61/**
48 * Information about an address. 62 * Information about an address.
49 */ 63 */
50struct SocketAddress 64struct SocketAddress
@@ -3000,6 +3014,9 @@ run (void *cls, char *const *args GNUNET_UNUSED,
3000 char *ipv4addr; 3014 char *ipv4addr;
3001 char *ipv4mask; 3015 char *ipv4mask;
3002 char *binary; 3016 char *binary;
3017 char *regex;
3018 char ipv4regex[GNUNET_REGEX_IPV4_REGEXLEN];
3019 char ipv6regex[GNUNET_REGEX_IPV6_REGEXLEN];
3003 3020
3004 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-exit"); 3021 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-exit");
3005 if (GNUNET_YES != 3022 if (GNUNET_YES !=
@@ -3189,6 +3206,34 @@ run (void *cls, char *const *args GNUNET_UNUSED,
3189 GNUNET_SCHEDULER_shutdown (); 3206 GNUNET_SCHEDULER_shutdown ();
3190 return; 3207 return;
3191 } 3208 }
3209
3210 /* Mesh handle acquired, now announce regular expressions matching our exit */
3211 if (GNUNET_YES == ipv4_enabled && GNUNET_YES == ipv4_exit)
3212 {
3213 GNUNET_REGEX_ipv4toregex (&exit_ipv4addr, ipv4mask, ipv4regex);
3214 GNUNET_asprintf (&regex, "%s%s%s",
3215 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
3216 "4",
3217 ipv4regex);
3218
3219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing exit regex: %s\n", regex);
3220 GNUNET_MESH_announce_regex (mesh_handle, regex, REGEX_MAX_PATH_LEN_IPV4);
3221 GNUNET_free (regex);
3222 }
3223
3224 if (GNUNET_YES == ipv6_enabled && GNUNET_YES == ipv6_exit)
3225 {
3226 GNUNET_REGEX_ipv6toregex (&exit_ipv6addr, ipv6prefix, ipv6regex);
3227 GNUNET_asprintf (&regex, "%s%s%s",
3228 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
3229 "6",
3230 ipv6regex);
3231
3232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing exit regex: %s\n", regex);
3233 GNUNET_MESH_announce_regex (mesh_handle, regex, REGEX_MAX_PATH_LEN_IPV4);
3234 GNUNET_free (regex);
3235 }
3236
3192 helper_handle = GNUNET_HELPER_start (GNUNET_NO, 3237 helper_handle = GNUNET_HELPER_start (GNUNET_NO,
3193 "gnunet-helper-exit", 3238 "gnunet-helper-exit",
3194 exit_argv, 3239 exit_argv,
diff --git a/src/include/gnunet_applications.h b/src/include/gnunet_applications.h
index 5feaeec6b..1e9db3e72 100644
--- a/src/include/gnunet_applications.h
+++ b/src/include/gnunet_applications.h
@@ -61,6 +61,12 @@ extern "C"
61 */ 61 */
62#define GNUNET_APPLICATION_TYPE_IPV6_GATEWAY 17 62#define GNUNET_APPLICATION_TYPE_IPV6_GATEWAY 17
63 63
64/**
65 * Internet exit regex prefix. Consisting of application ID, followed by version
66 * and padding.
67 */
68#define GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX "GNEX0001PADPADPA"
69
64 70
65#if 0 /* keep Emacsens' auto-indent happy */ 71#if 0 /* keep Emacsens' auto-indent happy */
66{ 72{
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am
index 453b3b908..71601383e 100644
--- a/src/vpn/Makefile.am
+++ b/src/vpn/Makefile.am
@@ -47,6 +47,7 @@ gnunet_service_vpn_LDADD = \
47 $(top_builddir)/src/tun/libgnunettun.la \ 47 $(top_builddir)/src/tun/libgnunettun.la \
48 $(top_builddir)/src/util/libgnunetutil.la \ 48 $(top_builddir)/src/util/libgnunetutil.la \
49 $(top_builddir)/src/mesh/libgnunetmesh.la \ 49 $(top_builddir)/src/mesh/libgnunetmesh.la \
50 $(top_builddir)/src/regex/libgnunetregex.la \
50 $(GN_LIBINTL) 51 $(GN_LIBINTL)
51gnunet_service_vpn_CFLAGS = \ 52gnunet_service_vpn_CFLAGS = \
52 -I$(top_srcdir)/src/exit $(CFLAGS) 53 -I$(top_srcdir)/src/exit $(CFLAGS)
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index abdc16d79..5e1452bec 100644
--- a/src/vpn/gnunet-service-vpn.c
+++ b/src/vpn/gnunet-service-vpn.c
@@ -35,6 +35,7 @@
35#include "gnunet_statistics_service.h" 35#include "gnunet_statistics_service.h"
36#include "gnunet_constants.h" 36#include "gnunet_constants.h"
37#include "gnunet_tun_lib.h" 37#include "gnunet_tun_lib.h"
38#include "gnunet_regex_lib.h"
38#include "vpn.h" 39#include "vpn.h"
39#include "exit.h" 40#include "exit.h"
40 41
@@ -807,27 +808,45 @@ create_tunnel_to_destination (struct DestinationEntry *de,
807 } 808 }
808 else 809 else
809 { 810 {
811 char *policy;
812
810 switch (de->details.exit_destination.af) 813 switch (de->details.exit_destination.af)
811 { 814 {
812 case AF_INET: 815 case AF_INET:
813 GNUNET_MESH_peer_request_connect_by_type (ts->tunnel, 816 {
814 GNUNET_APPLICATION_TYPE_IPV4_GATEWAY); 817 char address[GNUNET_REGEX_IPV4_REGEXLEN];
815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 818 GNUNET_REGEX_ipv4toregex (&de->details.exit_destination.ip.v4,
816 "Creating tunnel to exit peer for %s\n", 819 "255.255.255.255", address);
817 "IPv4"); 820 GNUNET_asprintf (&policy, "%s%s%s",
818 break; 821 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
822 "4",
823 address);
824 break;
825 }
819 case AF_INET6: 826 case AF_INET6:
820 GNUNET_MESH_peer_request_connect_by_type (ts->tunnel, 827 {
821 GNUNET_APPLICATION_TYPE_IPV6_GATEWAY); 828 char address[GNUNET_REGEX_IPV6_REGEXLEN];
822 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 829 GNUNET_REGEX_ipv6toregex (&de->details.exit_destination.ip.v6,
823 "Creating tunnel to exit peer for %s\n", 830 128, address);
824 "IPv6"); 831 GNUNET_asprintf (&policy, "%s%s%s",
832 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
833 "6",
834 address);
825 break; 835 break;
836 }
826 default: 837 default:
827 GNUNET_assert (0); 838 GNUNET_assert (0);
828 break; 839 break;
829 } 840 }
830 } 841
842 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting connect by string: %s\n", policy);
843
844 GNUNET_MESH_peer_request_connect_by_string (ts->tunnel, policy);
845 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
846 "Creating tunnel to exit peer for policy `%s'\n",
847 policy);
848 GNUNET_free (policy);
849 }
831 return ts; 850 return ts;
832} 851}
833 852