made the service more resilient against out of order and simply incorrect messages
[oweals/gnunet.git] / src / tun / regex.c
index 5ec454637dd2697156317ebd357897ed905691f0..87e75b511135ae8a8d3ff85727bbc64da832af07 100644 (file)
@@ -40,13 +40,13 @@ 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--)
@@ -60,7 +60,7 @@ iptobinstr (const int af, const void *addr, char *str)
     case AF_INET6:
     {
       struct in6_addr b = *(const struct in6_addr *) addr;
-      
+
       str[128] = '\0';
             str += 127;
             for (i = 127; i >= 0; i--)
@@ -88,7 +88,7 @@ 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;
@@ -107,11 +107,11 @@ ipv4netmasktoprefixlen (const char *netmask)
  *              bytes long.
  */
 void
-GNUNET_TUN_ipv4toregex (const struct in_addr *ip, const char *netmask,
+GNUNET_TUN_ipv4toregexsearch (const struct in_addr *ip, const char *netmask,
                        char *rxstr)
 {
   unsigned int pfxlen;
-  
+
   pfxlen = ipv4netmasktoprefixlen (netmask);
   iptobinstr (AF_INET, ip, rxstr);
   rxstr[pfxlen] = '\0';
@@ -129,7 +129,7 @@ GNUNET_TUN_ipv4toregex (const struct in_addr *ip, const char *netmask,
  *              bytes long.
  */
 void
-GNUNET_TUN_ipv6toregex (const struct in6_addr *ipv6, unsigned int prefixlen,
+GNUNET_TUN_ipv6toregexsearch (const struct in6_addr *ipv6, unsigned int prefixlen,
                        char *rxstr)
 {
   iptobinstr (AF_INET6, ipv6, rxstr);
@@ -138,4 +138,39 @@ GNUNET_TUN_ipv6toregex (const struct in6_addr *ipv6, unsigned int prefixlen,
       strcat (rxstr, "(0|1)+");
 }
 
+
+/**
+ * Convert an exit policy to a regular expression.  The exit policy
+ * specifies a set of subnets this peer is willing to serve as an
+ * exit for; the resulting regular expression will match the
+ * IPv4 address strings as returned by 'GNUNET_TUN_ipv4toregexsearch'.
+ *
+ * @param policy exit policy specification
+ * @return regular expression, NULL on error
+ */
+char *
+GNUNET_TUN_ipv4policy2regex (const char *policy)
+{
+  // FIXME: do actual policy parsing here, see #2919
+  return GNUNET_strdup (policy);
+}
+
+
+/**
+ * Convert an exit policy to a regular expression.  The exit policy
+ * specifies a set of subnets this peer is willing to serve as an
+ * exit for; the resulting regular expression will match the
+ * IPv4 address strings as returned by 'GNUNET_TUN_ipv4toregexsearch'.
+ *
+ * @param policy exit policy specification
+ * @return regular expression, NULL on error
+ */
+char *
+GNUNET_TUN_ipv6policy2regex (const char *policy)
+{
+  // FIXME: do actual policy parsing here, see #2919
+  return GNUNET_strdup (policy);
+}
+
+
 /* end of regex.c */