diff options
-rw-r--r-- | src/exit/gnunet-daemon-exit.c | 59 | ||||
-rw-r--r-- | src/include/gnunet_tun_lib.h | 25 | ||||
-rw-r--r-- | src/tun/regex.c | 33 |
3 files changed, 95 insertions, 22 deletions
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c index dcaa90be0..358e07434 100644 --- a/src/exit/gnunet-daemon-exit.c +++ b/src/exit/gnunet-daemon-exit.c | |||
@@ -3331,6 +3331,7 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
3331 | unsigned int app_idx; | 3331 | unsigned int app_idx; |
3332 | char *exit_ifname; | 3332 | char *exit_ifname; |
3333 | char *tun_ifname; | 3333 | char *tun_ifname; |
3334 | char *policy; | ||
3334 | char *ipv6addr; | 3335 | char *ipv6addr; |
3335 | char *ipv6prefix_s; | 3336 | char *ipv6prefix_s; |
3336 | char *ipv4addr; | 3337 | char *ipv4addr; |
@@ -3565,40 +3566,54 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
3565 | /* Mesh handle acquired, now announce regular expressions matching our exit */ | 3566 | /* Mesh handle acquired, now announce regular expressions matching our exit */ |
3566 | if ( (GNUNET_YES == ipv4_enabled) && (GNUNET_YES == ipv4_exit) ) | 3567 | if ( (GNUNET_YES == ipv4_enabled) && (GNUNET_YES == ipv4_exit) ) |
3567 | { | 3568 | { |
3569 | policy = NULL; | ||
3568 | if (GNUNET_OK != | 3570 | if (GNUNET_OK != |
3569 | GNUNET_CONFIGURATION_get_value_string (cfg, | 3571 | GNUNET_CONFIGURATION_get_value_string (cfg, |
3570 | "exit", | 3572 | "exit", |
3571 | "EXIT_RANGE_IPV4_REGEX", | 3573 | "EXIT_RANGE_IPV4_REGEX", |
3572 | ®ex)) | 3574 | &policy)) |
3573 | regex = GNUNET_strdup ("(0|1)*"); | 3575 | regex = NULL; |
3574 | (void) GNUNET_asprintf (&prefixed_regex, "%s%s%s", | 3576 | else |
3575 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, | 3577 | regex = GNUNET_TUN_ipv4policy2regex (policy); |
3576 | "4", regex); | 3578 | GNUNET_free_non_null (policy); |
3577 | regex4 = GNUNET_REGEX_announce (cfg, | 3579 | if (NULL != regex) |
3578 | prefixed_regex, | 3580 | { |
3579 | REGEX_REFRESH_FREQUENCY, | 3581 | (void) GNUNET_asprintf (&prefixed_regex, "%s%s%s", |
3580 | REGEX_MAX_PATH_LEN_IPV4); | 3582 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, |
3581 | GNUNET_free (regex); | 3583 | "4", regex); |
3582 | GNUNET_free (prefixed_regex); | 3584 | regex4 = GNUNET_REGEX_announce (cfg, |
3585 | prefixed_regex, | ||
3586 | REGEX_REFRESH_FREQUENCY, | ||
3587 | REGEX_MAX_PATH_LEN_IPV4); | ||
3588 | GNUNET_free (regex); | ||
3589 | GNUNET_free (prefixed_regex); | ||
3590 | } | ||
3583 | } | 3591 | } |
3584 | 3592 | ||
3585 | if (GNUNET_YES == ipv6_enabled && GNUNET_YES == ipv6_exit) | 3593 | if (GNUNET_YES == ipv6_enabled && GNUNET_YES == ipv6_exit) |
3586 | { | 3594 | { |
3595 | policy = NULL; | ||
3587 | if (GNUNET_OK != | 3596 | if (GNUNET_OK != |
3588 | GNUNET_CONFIGURATION_get_value_string (cfg, | 3597 | GNUNET_CONFIGURATION_get_value_string (cfg, |
3589 | "exit", | 3598 | "exit", |
3590 | "EXIT_RANGE_IPV6_REGEX", | 3599 | "EXIT_RANGE_IPV6_REGEX", |
3591 | ®ex)) | 3600 | &policy)) |
3592 | regex = GNUNET_strdup ("(0|1)*"); | 3601 | regex = NULL; |
3593 | (void) GNUNET_asprintf (&prefixed_regex, "%s%s%s", | 3602 | else |
3594 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, | 3603 | regex = GNUNET_TUN_ipv6policy2regex (policy); |
3595 | "6", regex); | 3604 | GNUNET_free_non_null (policy); |
3596 | regex6 = GNUNET_REGEX_announce (cfg, | 3605 | if (NULL != regex) |
3597 | prefixed_regex, | 3606 | { |
3598 | REGEX_REFRESH_FREQUENCY, | 3607 | (void) GNUNET_asprintf (&prefixed_regex, "%s%s%s", |
3599 | REGEX_MAX_PATH_LEN_IPV6); | 3608 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, |
3600 | GNUNET_free (regex); | 3609 | "6", regex); |
3601 | GNUNET_free (prefixed_regex); | 3610 | regex6 = GNUNET_REGEX_announce (cfg, |
3611 | prefixed_regex, | ||
3612 | REGEX_REFRESH_FREQUENCY, | ||
3613 | REGEX_MAX_PATH_LEN_IPV6); | ||
3614 | GNUNET_free (regex); | ||
3615 | GNUNET_free (prefixed_regex); | ||
3616 | } | ||
3602 | } | 3617 | } |
3603 | if ((ipv4_exit) || (ipv6_exit)) | 3618 | if ((ipv4_exit) || (ipv6_exit)) |
3604 | helper_handle = GNUNET_HELPER_start (GNUNET_NO, | 3619 | helper_handle = GNUNET_HELPER_start (GNUNET_NO, |
diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h index c670a19fb..90487265b 100644 --- a/src/include/gnunet_tun_lib.h +++ b/src/include/gnunet_tun_lib.h | |||
@@ -455,5 +455,30 @@ GNUNET_TUN_ipv6toregex (const struct in6_addr *ipv6, | |||
455 | unsigned int prefixlen, char *rxstr); | 455 | unsigned int prefixlen, char *rxstr); |
456 | 456 | ||
457 | 457 | ||
458 | /** | ||
459 | * Convert an exit policy to a regular expression. The exit policy | ||
460 | * specifies a set of subnets this peer is willing to serve as an | ||
461 | * exit for; the resulting regular expression will match the | ||
462 | * IPv6 address strings as returned by 'GNUNET_TUN_ipv6toregex'. | ||
463 | * | ||
464 | * @param policy exit policy specification | ||
465 | * @return regular expression, NULL on error | ||
466 | */ | ||
467 | char * | ||
468 | GNUNET_TUN_ipv6policy2regex (const char *policy); | ||
469 | |||
470 | |||
471 | /** | ||
472 | * Convert an exit policy to a regular expression. The exit policy | ||
473 | * specifies a set of subnets this peer is willing to serve as an | ||
474 | * exit for; the resulting regular expression will match the | ||
475 | * IPv4 address strings as returned by 'GNUNET_TUN_ipv4toregex'. | ||
476 | * | ||
477 | * @param policy exit policy specification | ||
478 | * @return regular expression, NULL on error | ||
479 | */ | ||
480 | char * | ||
481 | GNUNET_TUN_ipv4policy2regex (const char *policy); | ||
482 | |||
458 | 483 | ||
459 | #endif | 484 | #endif |
diff --git a/src/tun/regex.c b/src/tun/regex.c index 5ec454637..0d259a8d5 100644 --- a/src/tun/regex.c +++ b/src/tun/regex.c | |||
@@ -138,4 +138,37 @@ GNUNET_TUN_ipv6toregex (const struct in6_addr *ipv6, unsigned int prefixlen, | |||
138 | strcat (rxstr, "(0|1)+"); | 138 | strcat (rxstr, "(0|1)+"); |
139 | } | 139 | } |
140 | 140 | ||
141 | |||
142 | /** | ||
143 | * Convert an exit policy to a regular expression. The exit policy | ||
144 | * specifies a set of subnets this peer is willing to serve as an | ||
145 | * exit for; the resulting regular expression will match the | ||
146 | * IPv4 address strings as returned by 'GNUNET_TUN_ipv4toregex'. | ||
147 | * | ||
148 | * @param policy exit policy specification | ||
149 | * @return regular expression, NULL on error | ||
150 | */ | ||
151 | char * | ||
152 | GNUNET_TUN_ipv4policy2regex (const char *policy) | ||
153 | { | ||
154 | return GNUNET_strdup (policy); | ||
155 | } | ||
156 | |||
157 | |||
158 | /** | ||
159 | * Convert an exit policy to a regular expression. The exit policy | ||
160 | * specifies a set of subnets this peer is willing to serve as an | ||
161 | * exit for; the resulting regular expression will match the | ||
162 | * IPv4 address strings as returned by 'GNUNET_TUN_ipv4toregex'. | ||
163 | * | ||
164 | * @param policy exit policy specification | ||
165 | * @return regular expression, NULL on error | ||
166 | */ | ||
167 | char * | ||
168 | GNUNET_TUN_ipv6policy2regex (const char *policy) | ||
169 | { | ||
170 | return GNUNET_strdup (policy); | ||
171 | } | ||
172 | |||
173 | |||
141 | /* end of regex.c */ | 174 | /* end of regex.c */ |