*/
#define MAX_MESSAGE_QUEUE_SIZE 4
-/**
- * Maximum regex string length for use with GNUNET_REGEX_ipv4toregex
- */
-#define GNUNET_REGEX_IPV4_REGEXLEN 32 + 6
-
-/**
- * Maximum regex string length for use with GNUNET_REGEX_ipv6toregex
- */
-#define GNUNET_REGEX_IPV6_REGEXLEN 128 + 6
-
/**
* State we keep for each of our tunnels.
}
-/**
- * Create a string with binary IP notation for the given 'addr' in 'str'.
- *
- * @param af address family of the given 'addr'.
- * @param addr address that should be converted to a string.
- * struct in_addr * for IPv4 and struct in6_addr * for IPv6.
- * @param str string that will contain binary notation of 'addr'. Expected
- * to be at least 33 bytes long for IPv4 and 129 bytes long for IPv6.
- */
-static void
-iptobinstr (const int af, const void *addr, char *str)
-{
- int i;
-
- switch (af)
- {
- case AF_INET:
- {
- uint32_t b = htonl (((struct in_addr *) addr)->s_addr);
-
- str[32] = '\0';
- str += 31;
- for (i = 31; i >= 0; i--)
- {
- *str = (b & 1) + '0';
- str--;
- b >>= 1;
- }
- break;
- }
- case AF_INET6:
- {
- struct in6_addr b = *(const struct in6_addr *) addr;
-
- str[128] = '\0';
- str += 127;
- for (i = 127; i >= 0; i--)
- {
- *str = (b.s6_addr[i / 8] & 1) + '0';
- str--;
- b.s6_addr[i / 8] >>= 1;
- }
- break;
- }
- }
-}
-
-
-/**
- * Get the ipv4 network prefix from the given 'netmask'.
- *
- * @param netmask netmask for which to get the prefix len.
- *
- * @return length of ipv4 prefix for 'netmask'.
- */
-static unsigned int
-ipv4netmasktoprefixlen (const char *netmask)
-{
- struct in_addr a;
- unsigned int len;
- uint32_t t;
-
- if (1 != inet_pton (AF_INET, netmask, &a))
- return 0;
- len = 32;
- for (t = htonl (~a.s_addr); 0 != t; t >>= 1)
- len--;
- return len;
-}
-
-
-/**
- * Create a regex in 'rxstr' from the given 'ip' and 'netmask'.
- *
- * @param ip IPv4 representation.
- * @param netmask netmask for the ip.
- * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV4_REGEXLEN
- * bytes long.
- */
-static void
-ipv4toregex (const struct in_addr *ip, const char *netmask,
- char *rxstr)
-{
- unsigned int pfxlen;
-
- pfxlen = ipv4netmasktoprefixlen (netmask);
- iptobinstr (AF_INET, ip, rxstr);
- rxstr[pfxlen] = '\0';
- if (pfxlen < 32)
- strcat (rxstr, "(0|1)+");
-}
-
-
-/**
- * Create a regex in 'rxstr' from the given 'ipv6' and 'prefixlen'.
- *
- * @param ipv6 IPv6 representation.
- * @param prefixlen length of the ipv6 prefix.
- * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV6_REGEXLEN
- * bytes long.
- */
-static void
-ipv6toregex (const struct in6_addr *ipv6, unsigned int prefixlen,
- char *rxstr)
-{
- iptobinstr (AF_INET6, ipv6, rxstr);
- rxstr[prefixlen] = '\0';
- if (prefixlen < 128)
- strcat (rxstr, "(0|1)+");
-}
-
-
/**
* Regex has found a potential exit peer for us; consider using it.
*
{
case AF_INET:
{
- char address[GNUNET_REGEX_IPV4_REGEXLEN];
+ char address[GNUNET_TUN_IPV4_REGEXLEN];
- ipv4toregex (&de->details.exit_destination.ip.v4,
+ GNUNET_TUN_ipv4toregex (&de->details.exit_destination.ip.v4,
"255.255.255.255", address);
GNUNET_asprintf (&policy, "%s%s%s",
GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
}
case AF_INET6:
{
- char address[GNUNET_REGEX_IPV6_REGEXLEN];
+ char address[GNUNET_TUN_IPV6_REGEXLEN];
- ipv6toregex (&de->details.exit_destination.ip.v6,
+ GNUNET_TUN_ipv6toregex (&de->details.exit_destination.ip.v6,
128, address);
GNUNET_asprintf (&policy, "%s%s%s",
GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,