aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-06-20 08:32:50 +0000
committerChristian Grothoff <christian@grothoff.org>2013-06-20 08:32:50 +0000
commit21a2b4f95b4488645ba5a6254fcb8919c4915f73 (patch)
tree00c92cb7103cc14fba7e63e8dee99fe711856863 /src/vpn
parent5533b105943b4f6dd688c1758350cd83ebeab3b9 (diff)
downloadgnunet-21a2b4f95b4488645ba5a6254fcb8919c4915f73.tar.gz
gnunet-21a2b4f95b4488645ba5a6254fcb8919c4915f73.zip
continuing refactoring of regex library structure, disambiguating symbol names between old regex library which is now internal and the public API; moving IP-to-regex conversion functions to tun library, as only vpn is using those to begin with
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-service-vpn.c130
1 files changed, 4 insertions, 126 deletions
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index 2ab53047b..bc2327e96 100644
--- a/src/vpn/gnunet-service-vpn.c
+++ b/src/vpn/gnunet-service-vpn.c
@@ -49,16 +49,6 @@
49 */ 49 */
50#define MAX_MESSAGE_QUEUE_SIZE 4 50#define MAX_MESSAGE_QUEUE_SIZE 4
51 51
52/**
53 * Maximum regex string length for use with GNUNET_REGEX_ipv4toregex
54 */
55#define GNUNET_REGEX_IPV4_REGEXLEN 32 + 6
56
57/**
58 * Maximum regex string length for use with GNUNET_REGEX_ipv6toregex
59 */
60#define GNUNET_REGEX_IPV6_REGEXLEN 128 + 6
61
62 52
63/** 53/**
64 * State we keep for each of our tunnels. 54 * State we keep for each of our tunnels.
@@ -769,118 +759,6 @@ send_to_tunnel (struct TunnelMessageQueueEntry *tnq,
769 759
770 760
771/** 761/**
772 * Create a string with binary IP notation for the given 'addr' in 'str'.
773 *
774 * @param af address family of the given 'addr'.
775 * @param addr address that should be converted to a string.
776 * struct in_addr * for IPv4 and struct in6_addr * for IPv6.
777 * @param str string that will contain binary notation of 'addr'. Expected
778 * to be at least 33 bytes long for IPv4 and 129 bytes long for IPv6.
779 */
780static void
781iptobinstr (const int af, const void *addr, char *str)
782{
783 int i;
784
785 switch (af)
786 {
787 case AF_INET:
788 {
789 uint32_t b = htonl (((struct in_addr *) addr)->s_addr);
790
791 str[32] = '\0';
792 str += 31;
793 for (i = 31; i >= 0; i--)
794 {
795 *str = (b & 1) + '0';
796 str--;
797 b >>= 1;
798 }
799 break;
800 }
801 case AF_INET6:
802 {
803 struct in6_addr b = *(const struct in6_addr *) addr;
804
805 str[128] = '\0';
806 str += 127;
807 for (i = 127; i >= 0; i--)
808 {
809 *str = (b.s6_addr[i / 8] & 1) + '0';
810 str--;
811 b.s6_addr[i / 8] >>= 1;
812 }
813 break;
814 }
815 }
816}
817
818
819/**
820 * Get the ipv4 network prefix from the given 'netmask'.
821 *
822 * @param netmask netmask for which to get the prefix len.
823 *
824 * @return length of ipv4 prefix for 'netmask'.
825 */
826static unsigned int
827ipv4netmasktoprefixlen (const char *netmask)
828{
829 struct in_addr a;
830 unsigned int len;
831 uint32_t t;
832
833 if (1 != inet_pton (AF_INET, netmask, &a))
834 return 0;
835 len = 32;
836 for (t = htonl (~a.s_addr); 0 != t; t >>= 1)
837 len--;
838 return len;
839}
840
841
842/**
843 * Create a regex in 'rxstr' from the given 'ip' and 'netmask'.
844 *
845 * @param ip IPv4 representation.
846 * @param netmask netmask for the ip.
847 * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV4_REGEXLEN
848 * bytes long.
849 */
850static void
851ipv4toregex (const struct in_addr *ip, const char *netmask,
852 char *rxstr)
853{
854 unsigned int pfxlen;
855
856 pfxlen = ipv4netmasktoprefixlen (netmask);
857 iptobinstr (AF_INET, ip, rxstr);
858 rxstr[pfxlen] = '\0';
859 if (pfxlen < 32)
860 strcat (rxstr, "(0|1)+");
861}
862
863
864/**
865 * Create a regex in 'rxstr' from the given 'ipv6' and 'prefixlen'.
866 *
867 * @param ipv6 IPv6 representation.
868 * @param prefixlen length of the ipv6 prefix.
869 * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV6_REGEXLEN
870 * bytes long.
871 */
872static void
873ipv6toregex (const struct in6_addr *ipv6, unsigned int prefixlen,
874 char *rxstr)
875{
876 iptobinstr (AF_INET6, ipv6, rxstr);
877 rxstr[prefixlen] = '\0';
878 if (prefixlen < 128)
879 strcat (rxstr, "(0|1)+");
880}
881
882
883/**
884 * Regex has found a potential exit peer for us; consider using it. 762 * Regex has found a potential exit peer for us; consider using it.
885 * 763 *
886 * @param cls the 'struct TunnelState' 764 * @param cls the 'struct TunnelState'
@@ -973,9 +851,9 @@ create_tunnel_to_destination (struct DestinationEntry *de,
973 { 851 {
974 case AF_INET: 852 case AF_INET:
975 { 853 {
976 char address[GNUNET_REGEX_IPV4_REGEXLEN]; 854 char address[GNUNET_TUN_IPV4_REGEXLEN];
977 855
978 ipv4toregex (&de->details.exit_destination.ip.v4, 856 GNUNET_TUN_ipv4toregex (&de->details.exit_destination.ip.v4,
979 "255.255.255.255", address); 857 "255.255.255.255", address);
980 GNUNET_asprintf (&policy, "%s%s%s", 858 GNUNET_asprintf (&policy, "%s%s%s",
981 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, 859 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
@@ -985,9 +863,9 @@ create_tunnel_to_destination (struct DestinationEntry *de,
985 } 863 }
986 case AF_INET6: 864 case AF_INET6:
987 { 865 {
988 char address[GNUNET_REGEX_IPV6_REGEXLEN]; 866 char address[GNUNET_TUN_IPV6_REGEXLEN];
989 867
990 ipv6toregex (&de->details.exit_destination.ip.v6, 868 GNUNET_TUN_ipv6toregex (&de->details.exit_destination.ip.v6,
991 128, address); 869 128, address);
992 GNUNET_asprintf (&policy, "%s%s%s", 870 GNUNET_asprintf (&policy, "%s%s%s",
993 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, 871 GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,