diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-02-23 00:06:03 +0100 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-02-23 00:06:03 +0100 |
commit | e73b829feec7ca6af5116b5ffb566c79d6aa1bbd (patch) | |
tree | 6cd24578e725801853300ced105fa624568fbe23 /src/util/gnunet-service-resolver.c | |
parent | dda10ff31f6e4eba45b581f8497cb20ebc0aa7b0 (diff) | |
download | gnunet-e73b829feec7ca6af5116b5ffb566c79d6aa1bbd.tar.gz gnunet-e73b829feec7ca6af5116b5ffb566c79d6aa1bbd.zip |
attempt fix #5578
Diffstat (limited to 'src/util/gnunet-service-resolver.c')
-rw-r--r-- | src/util/gnunet-service-resolver.c | 387 |
1 files changed, 175 insertions, 212 deletions
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c index a1d4d0b45..0df213588 100644 --- a/src/util/gnunet-service-resolver.c +++ b/src/util/gnunet-service-resolver.c | |||
@@ -773,6 +773,41 @@ pack (const char *hostname, | |||
773 | return GNUNET_OK; | 773 | return GNUNET_OK; |
774 | } | 774 | } |
775 | 775 | ||
776 | static void | ||
777 | cache_answers(const char* name, | ||
778 | struct GNUNET_DNSPARSER_Record *records, | ||
779 | unsigned int num_records) | ||
780 | { | ||
781 | struct ResolveCache *rc; | ||
782 | struct GNUNET_DNSPARSER_Record *record; | ||
783 | struct RecordListEntry *rle; | ||
784 | |||
785 | for (unsigned int i = 0; i != num_records; i++) | ||
786 | { | ||
787 | record = &records[i]; | ||
788 | |||
789 | for (rc = cache_head; NULL != rc; rc = rc->next) | ||
790 | if (0 == strcasecmp (rc->hostname, | ||
791 | name)) | ||
792 | break; | ||
793 | if (NULL == rc) | ||
794 | { | ||
795 | rc = GNUNET_new (struct ResolveCache); | ||
796 | rc->hostname = GNUNET_strdup (name); | ||
797 | GNUNET_CONTAINER_DLL_insert (cache_head, | ||
798 | cache_tail, | ||
799 | rc); | ||
800 | cache_size++; | ||
801 | } | ||
802 | /* TODO: ought to check first if we have this exact record | ||
803 | already in the cache! */ | ||
804 | rle = GNUNET_new (struct RecordListEntry); | ||
805 | rle->record = GNUNET_DNSPARSER_duplicate_record (record); | ||
806 | GNUNET_CONTAINER_DLL_insert (rc->records_head, | ||
807 | rc->records_tail, | ||
808 | rle); | ||
809 | } | ||
810 | } | ||
776 | 811 | ||
777 | /** | 812 | /** |
778 | * We got a result from DNS. Add it to the cache and | 813 | * We got a result from DNS. Add it to the cache and |
@@ -784,43 +819,42 @@ pack (const char *hostname, | |||
784 | */ | 819 | */ |
785 | static void | 820 | static void |
786 | handle_resolve_result (void *cls, | 821 | handle_resolve_result (void *cls, |
787 | const struct GNUNET_TUN_DnsHeader *dns, | 822 | const struct GNUNET_TUN_DnsHeader *dns, |
788 | size_t dns_len) | 823 | size_t dns_len) |
789 | { | 824 | { |
790 | struct ActiveLookup *al = cls; | 825 | struct ActiveLookup *al = cls; |
791 | struct GNUNET_DNSPARSER_Packet *parsed; | 826 | struct GNUNET_DNSPARSER_Packet *parsed; |
792 | struct ResolveCache *rc; | ||
793 | 827 | ||
794 | parsed = GNUNET_DNSPARSER_parse ((const char *)dns, | 828 | parsed = GNUNET_DNSPARSER_parse ((const char *)dns, |
795 | dns_len); | 829 | dns_len); |
796 | if (NULL == parsed) | 830 | if (NULL == parsed) |
797 | { | 831 | { |
798 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 832 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
799 | "Failed to parse DNS reply (hostname %s, request ID %u)\n", | 833 | "Failed to parse DNS reply (hostname %s, request ID %u)\n", |
800 | al->hostname, | 834 | al->hostname, |
801 | al->dns_id); | 835 | al->dns_id); |
802 | return; | 836 | return; |
803 | } | 837 | } |
804 | if (al->dns_id != ntohs (parsed->id)) | 838 | if (al->dns_id != ntohs (parsed->id)) |
805 | { | 839 | { |
806 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 840 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
807 | "Request ID in DNS reply does not match\n"); | 841 | "Request ID in DNS reply does not match\n"); |
808 | GNUNET_DNSPARSER_free_packet (parsed); | 842 | GNUNET_DNSPARSER_free_packet (parsed); |
809 | return; | 843 | return; |
810 | } | 844 | } |
811 | if (0 == parsed->num_answers + parsed->num_authority_records + parsed->num_additional_records) | 845 | if (0 == parsed->num_answers + parsed->num_authority_records + parsed->num_additional_records) |
812 | { | 846 | { |
813 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 847 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
814 | "DNS reply (hostname %s, request ID %u) contains no answers\n", | 848 | "DNS reply (hostname %s, request ID %u) contains no answers\n", |
815 | al->hostname, | 849 | al->hostname, |
816 | (unsigned int) al->client_request_id); | 850 | (unsigned int) al->client_request_id); |
817 | /* resume by trying again from cache */ | 851 | /* resume by trying again from cache */ |
818 | if (GNUNET_NO == | 852 | if (GNUNET_NO == |
819 | try_cache (al->hostname, | 853 | try_cache (al->hostname, |
820 | al->record_type, | 854 | al->record_type, |
821 | al->client_request_id, | 855 | al->client_request_id, |
822 | al->client)) | 856 | al->client)) |
823 | /* cache failed, tell client we could not get an answer */ | 857 | /* cache failed, tell client we could not get an answer */ |
824 | { | 858 | { |
825 | send_end_msg (al->client_request_id, | 859 | send_end_msg (al->client_request_id, |
826 | al->client); | 860 | al->client); |
@@ -838,84 +872,13 @@ handle_resolve_result (void *cls, | |||
838 | al->hostname, | 872 | al->hostname, |
839 | (unsigned int) al->client_request_id); | 873 | (unsigned int) al->client_request_id); |
840 | /* add to cache */ | 874 | /* add to cache */ |
841 | for (unsigned int i = 0; i != parsed->num_answers; i++) | 875 | cache_answers(al->hostname, |
842 | { | 876 | parsed->answers, parsed->num_answers); |
843 | struct GNUNET_DNSPARSER_Record *record = &parsed->answers[i]; | 877 | cache_answers(al->hostname, |
844 | struct RecordListEntry *rle; | 878 | parsed->authority_records, parsed->num_authority_records); |
879 | cache_answers(al->hostname, | ||
880 | parsed->additional_records, parsed->num_additional_records); | ||
845 | 881 | ||
846 | for (rc = cache_head; NULL != rc; rc = rc->next) | ||
847 | if (0 == strcasecmp (rc->hostname, | ||
848 | record->name)) | ||
849 | break; | ||
850 | if (NULL == rc) | ||
851 | { | ||
852 | rc = GNUNET_new (struct ResolveCache); | ||
853 | rc->hostname = GNUNET_strdup (record->name); | ||
854 | GNUNET_CONTAINER_DLL_insert (cache_head, | ||
855 | cache_tail, | ||
856 | rc); | ||
857 | cache_size++; | ||
858 | } | ||
859 | /* TODO: ought to check first if we have this exact record | ||
860 | already in the cache! */ | ||
861 | rle = GNUNET_new (struct RecordListEntry); | ||
862 | rle->record = GNUNET_DNSPARSER_duplicate_record (record); | ||
863 | GNUNET_CONTAINER_DLL_insert (rc->records_head, | ||
864 | rc->records_tail, | ||
865 | rle); | ||
866 | } | ||
867 | for (unsigned int i = 0; i != parsed->num_authority_records; i++) | ||
868 | { | ||
869 | struct GNUNET_DNSPARSER_Record *record = &parsed->authority_records[i]; | ||
870 | struct RecordListEntry *rle; | ||
871 | |||
872 | for (rc = cache_head; NULL != rc; rc = rc->next) | ||
873 | if (0 == strcasecmp (rc->hostname, | ||
874 | record->name)) | ||
875 | break; | ||
876 | if (NULL == rc) | ||
877 | { | ||
878 | rc = GNUNET_new (struct ResolveCache); | ||
879 | rc->hostname = GNUNET_strdup (record->name); | ||
880 | GNUNET_CONTAINER_DLL_insert (cache_head, | ||
881 | cache_tail, | ||
882 | rc); | ||
883 | cache_size++; | ||
884 | } | ||
885 | /* TODO: ought to check first if we have this exact record | ||
886 | already in the cache! */ | ||
887 | rle = GNUNET_new (struct RecordListEntry); | ||
888 | rle->record = GNUNET_DNSPARSER_duplicate_record (record); | ||
889 | GNUNET_CONTAINER_DLL_insert (rc->records_head, | ||
890 | rc->records_tail, | ||
891 | rle); | ||
892 | } | ||
893 | for (unsigned int i = 0; i != parsed->num_additional_records; i++) | ||
894 | { | ||
895 | struct GNUNET_DNSPARSER_Record *record = &parsed->additional_records[i]; | ||
896 | struct RecordListEntry *rle; | ||
897 | |||
898 | for (rc = cache_head; NULL != rc; rc = rc->next) | ||
899 | if (0 == strcasecmp (rc->hostname, | ||
900 | record->name)) | ||
901 | break; | ||
902 | if (NULL == rc) | ||
903 | { | ||
904 | rc = GNUNET_new (struct ResolveCache); | ||
905 | rc->hostname = GNUNET_strdup (record->name); | ||
906 | GNUNET_CONTAINER_DLL_insert (cache_head, | ||
907 | cache_tail, | ||
908 | rc); | ||
909 | cache_size++; | ||
910 | } | ||
911 | /* TODO: ought to check first if we have this exact record | ||
912 | already in the cache! */ | ||
913 | rle = GNUNET_new (struct RecordListEntry); | ||
914 | rle->record = GNUNET_DNSPARSER_duplicate_record (record); | ||
915 | GNUNET_CONTAINER_DLL_insert (rc->records_head, | ||
916 | rc->records_tail, | ||
917 | rle); | ||
918 | } | ||
919 | /* see if we need to do the 2nd request for AAAA records */ | 882 | /* see if we need to do the 2nd request for AAAA records */ |
920 | if ( (GNUNET_DNSPARSER_TYPE_ALL == al->record_type) && | 883 | if ( (GNUNET_DNSPARSER_TYPE_ALL == al->record_type) && |
921 | (GNUNET_NO == al->did_aaaa) ) | 884 | (GNUNET_NO == al->did_aaaa) ) |
@@ -977,7 +940,7 @@ handle_resolve_timeout (void *cls) | |||
977 | 940 | ||
978 | al->timeout_task = NULL; | 941 | al->timeout_task = NULL; |
979 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 942 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
980 | "DNS lookup timeout!\n"); | 943 | "DNS lookup timeout!\n"); |
981 | send_end_msg (al->client_request_id, | 944 | send_end_msg (al->client_request_id, |
982 | al->client); | 945 | al->client); |
983 | free_active_lookup (al); | 946 | free_active_lookup (al); |
@@ -996,9 +959,9 @@ handle_resolve_timeout (void *cls) | |||
996 | */ | 959 | */ |
997 | static int | 960 | static int |
998 | resolve_and_cache (const char* hostname, | 961 | resolve_and_cache (const char* hostname, |
999 | uint16_t record_type, | 962 | uint16_t record_type, |
1000 | uint32_t client_request_id, | 963 | uint32_t client_request_id, |
1001 | struct GNUNET_SERVICE_Client *client) | 964 | struct GNUNET_SERVICE_Client *client) |
1002 | { | 965 | { |
1003 | char *packet_buf; | 966 | char *packet_buf; |
1004 | size_t packet_size; | 967 | size_t packet_size; |
@@ -1007,8 +970,8 @@ resolve_and_cache (const char* hostname, | |||
1007 | uint16_t type; | 970 | uint16_t type; |
1008 | 971 | ||
1009 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 972 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1010 | "resolve_and_cache `%s'\n", | 973 | "resolve_and_cache `%s'\n", |
1011 | hostname); | 974 | hostname); |
1012 | dns_id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 975 | dns_id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
1013 | UINT16_MAX); | 976 | UINT16_MAX); |
1014 | 977 | ||
@@ -1024,7 +987,7 @@ resolve_and_cache (const char* hostname, | |||
1024 | &packet_size)) | 987 | &packet_size)) |
1025 | { | 988 | { |
1026 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 989 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1027 | "Failed to pack query for hostname `%s'\n", | 990 | "Failed to pack query for hostname `%s'\n", |
1028 | hostname); | 991 | hostname); |
1029 | return GNUNET_SYSERR; | 992 | return GNUNET_SYSERR; |
1030 | } | 993 | } |
@@ -1040,19 +1003,19 @@ resolve_and_cache (const char* hostname, | |||
1040 | al); | 1003 | al); |
1041 | al->resolve_handle = | 1004 | al->resolve_handle = |
1042 | GNUNET_DNSSTUB_resolve (dnsstub_ctx, | 1005 | GNUNET_DNSSTUB_resolve (dnsstub_ctx, |
1043 | packet_buf, | 1006 | packet_buf, |
1044 | packet_size, | 1007 | packet_size, |
1045 | &handle_resolve_result, | 1008 | &handle_resolve_result, |
1046 | al); | 1009 | al); |
1047 | GNUNET_free (packet_buf); | 1010 | GNUNET_free (packet_buf); |
1048 | GNUNET_CONTAINER_DLL_insert (lookup_head, | 1011 | GNUNET_CONTAINER_DLL_insert (lookup_head, |
1049 | lookup_tail, | 1012 | lookup_tail, |
1050 | al); | 1013 | al); |
1051 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1014 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1052 | "Resolving %s, client_request_id = %u, dns_id = %u\n", | 1015 | "Resolving %s, client_request_id = %u, dns_id = %u\n", |
1053 | hostname, | 1016 | hostname, |
1054 | (unsigned int) client_request_id, | 1017 | (unsigned int) client_request_id, |
1055 | (unsigned int) dns_id); | 1018 | (unsigned int) dns_id); |
1056 | return GNUNET_OK; | 1019 | return GNUNET_OK; |
1057 | } | 1020 | } |
1058 | 1021 | ||
@@ -1068,29 +1031,29 @@ resolve_and_cache (const char* hostname, | |||
1068 | */ | 1031 | */ |
1069 | static void | 1032 | static void |
1070 | process_get (const char *hostname, | 1033 | process_get (const char *hostname, |
1071 | uint16_t record_type, | 1034 | uint16_t record_type, |
1072 | uint32_t client_request_id, | 1035 | uint32_t client_request_id, |
1073 | struct GNUNET_SERVICE_Client *client) | 1036 | struct GNUNET_SERVICE_Client *client) |
1074 | { | 1037 | { |
1075 | char fqdn[255]; | 1038 | char fqdn[255]; |
1076 | 1039 | ||
1077 | if ( (NULL != my_domain) && | 1040 | if ( (NULL != my_domain) && |
1078 | (NULL == strchr (hostname, | 1041 | (NULL == strchr (hostname, |
1079 | (unsigned char) '.')) && | 1042 | (unsigned char) '.')) && |
1080 | (strlen (hostname) + strlen (my_domain) <= 253) ) | 1043 | (strlen (hostname) + strlen (my_domain) <= 253) ) |
1081 | { | 1044 | { |
1082 | GNUNET_snprintf (fqdn, | 1045 | GNUNET_snprintf (fqdn, |
1083 | sizeof (fqdn), | 1046 | sizeof (fqdn), |
1084 | "%s.%s", | 1047 | "%s.%s", |
1085 | hostname, | 1048 | hostname, |
1086 | my_domain); | 1049 | my_domain); |
1087 | } | 1050 | } |
1088 | else if (strlen (hostname) < 255) | 1051 | else if (strlen (hostname) < 255) |
1089 | { | 1052 | { |
1090 | GNUNET_snprintf (fqdn, | 1053 | GNUNET_snprintf (fqdn, |
1091 | sizeof (fqdn), | 1054 | sizeof (fqdn), |
1092 | "%s", | 1055 | "%s", |
1093 | hostname); | 1056 | hostname); |
1094 | } | 1057 | } |
1095 | else | 1058 | else |
1096 | { | 1059 | { |
@@ -1126,7 +1089,7 @@ process_get (const char *hostname, | |||
1126 | */ | 1089 | */ |
1127 | static int | 1090 | static int |
1128 | check_get (void *cls, | 1091 | check_get (void *cls, |
1129 | const struct GNUNET_RESOLVER_GetMessage *get) | 1092 | const struct GNUNET_RESOLVER_GetMessage *get) |
1130 | { | 1093 | { |
1131 | uint16_t size; | 1094 | uint16_t size; |
1132 | int direction; | 1095 | int direction; |
@@ -1143,23 +1106,23 @@ check_get (void *cls, | |||
1143 | af = ntohl (get->af); | 1106 | af = ntohl (get->af); |
1144 | switch (af) | 1107 | switch (af) |
1145 | { | 1108 | { |
1146 | case AF_INET: | 1109 | case AF_INET: |
1147 | if (size != sizeof (struct in_addr)) | 1110 | if (size != sizeof (struct in_addr)) |
1148 | { | 1111 | { |
1149 | GNUNET_break (0); | 1112 | GNUNET_break (0); |
1150 | return GNUNET_SYSERR; | 1113 | return GNUNET_SYSERR; |
1151 | } | 1114 | } |
1152 | break; | 1115 | break; |
1153 | case AF_INET6: | 1116 | case AF_INET6: |
1154 | if (size != sizeof (struct in6_addr)) | 1117 | if (size != sizeof (struct in6_addr)) |
1155 | { | 1118 | { |
1119 | GNUNET_break (0); | ||
1120 | return GNUNET_SYSERR; | ||
1121 | } | ||
1122 | break; | ||
1123 | default: | ||
1156 | GNUNET_break (0); | 1124 | GNUNET_break (0); |
1157 | return GNUNET_SYSERR; | 1125 | return GNUNET_SYSERR; |
1158 | } | ||
1159 | break; | ||
1160 | default: | ||
1161 | GNUNET_break (0); | ||
1162 | return GNUNET_SYSERR; | ||
1163 | } | 1126 | } |
1164 | return GNUNET_OK; | 1127 | return GNUNET_OK; |
1165 | } | 1128 | } |
@@ -1173,7 +1136,7 @@ check_get (void *cls, | |||
1173 | */ | 1136 | */ |
1174 | static void | 1137 | static void |
1175 | handle_get (void *cls, | 1138 | handle_get (void *cls, |
1176 | const struct GNUNET_RESOLVER_GetMessage *msg) | 1139 | const struct GNUNET_RESOLVER_GetMessage *msg) |
1177 | { | 1140 | { |
1178 | struct GNUNET_SERVICE_Client *client = cls; | 1141 | struct GNUNET_SERVICE_Client *client = cls; |
1179 | int direction; | 1142 | int direction; |
@@ -1192,36 +1155,36 @@ handle_get (void *cls, | |||
1192 | switch (af) | 1155 | switch (af) |
1193 | { | 1156 | { |
1194 | case AF_UNSPEC: | 1157 | case AF_UNSPEC: |
1195 | { | 1158 | { |
1196 | process_get (hostname, | 1159 | process_get (hostname, |
1197 | GNUNET_DNSPARSER_TYPE_ALL, | 1160 | GNUNET_DNSPARSER_TYPE_ALL, |
1198 | client_request_id, | 1161 | client_request_id, |
1199 | client); | 1162 | client); |
1200 | break; | 1163 | break; |
1201 | } | 1164 | } |
1202 | case AF_INET: | 1165 | case AF_INET: |
1203 | { | 1166 | { |
1204 | process_get (hostname, | 1167 | process_get (hostname, |
1205 | GNUNET_DNSPARSER_TYPE_A, | 1168 | GNUNET_DNSPARSER_TYPE_A, |
1206 | client_request_id, | 1169 | client_request_id, |
1207 | client); | 1170 | client); |
1208 | break; | 1171 | break; |
1209 | } | 1172 | } |
1210 | case AF_INET6: | 1173 | case AF_INET6: |
1211 | { | 1174 | { |
1212 | process_get (hostname, | 1175 | process_get (hostname, |
1213 | GNUNET_DNSPARSER_TYPE_AAAA, | 1176 | GNUNET_DNSPARSER_TYPE_AAAA, |
1214 | client_request_id, | 1177 | client_request_id, |
1215 | client); | 1178 | client); |
1216 | break; | 1179 | break; |
1217 | } | 1180 | } |
1218 | default: | 1181 | default: |
1219 | { | 1182 | { |
1220 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1221 | "got invalid af: %d\n", | 1184 | "got invalid af: %d\n", |
1222 | af); | 1185 | af); |
1223 | GNUNET_assert (0); | 1186 | GNUNET_assert (0); |
1224 | } | 1187 | } |
1225 | } | 1188 | } |
1226 | } | 1189 | } |
1227 | else | 1190 | else |
@@ -1270,9 +1233,9 @@ shutdown_task (void *cls) | |||
1270 | */ | 1233 | */ |
1271 | static void | 1234 | static void |
1272 | add_host (const char *hostname, | 1235 | add_host (const char *hostname, |
1273 | uint16_t rec_type, | 1236 | uint16_t rec_type, |
1274 | const void *data, | 1237 | const void *data, |
1275 | size_t data_size) | 1238 | size_t data_size) |
1276 | { | 1239 | { |
1277 | struct ResolveCache *rc; | 1240 | struct ResolveCache *rc; |
1278 | struct RecordListEntry *rle; | 1241 | struct RecordListEntry *rle; |
@@ -1284,18 +1247,18 @@ add_host (const char *hostname, | |||
1284 | rec->dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; | 1247 | rec->dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; |
1285 | rec->name = GNUNET_strdup (hostname); | 1248 | rec->name = GNUNET_strdup (hostname); |
1286 | rec->data.raw.data = GNUNET_memdup (data, | 1249 | rec->data.raw.data = GNUNET_memdup (data, |
1287 | data_size); | 1250 | data_size); |
1288 | rec->data.raw.data_len = data_size; | 1251 | rec->data.raw.data_len = data_size; |
1289 | rle = GNUNET_new (struct RecordListEntry); | 1252 | rle = GNUNET_new (struct RecordListEntry); |
1290 | rle->record = rec; | 1253 | rle->record = rec; |
1291 | rc = GNUNET_new (struct ResolveCache); | 1254 | rc = GNUNET_new (struct ResolveCache); |
1292 | rc->hostname = GNUNET_strdup (hostname); | 1255 | rc->hostname = GNUNET_strdup (hostname); |
1293 | GNUNET_CONTAINER_DLL_insert (rc->records_head, | 1256 | GNUNET_CONTAINER_DLL_insert (rc->records_head, |
1294 | rc->records_tail, | 1257 | rc->records_tail, |
1295 | rle); | 1258 | rle); |
1296 | GNUNET_CONTAINER_DLL_insert (hosts_head, | 1259 | GNUNET_CONTAINER_DLL_insert (hosts_head, |
1297 | hosts_tail, | 1260 | hosts_tail, |
1298 | rc); | 1261 | rc); |
1299 | } | 1262 | } |
1300 | 1263 | ||
1301 | 1264 | ||
@@ -1307,7 +1270,7 @@ add_host (const char *hostname, | |||
1307 | */ | 1270 | */ |
1308 | static void | 1271 | static void |
1309 | extract_hosts (const char *line, | 1272 | extract_hosts (const char *line, |
1310 | size_t line_len) | 1273 | size_t line_len) |
1311 | { | 1274 | { |
1312 | const char *c; | 1275 | const char *c; |
1313 | struct in_addr v4; | 1276 | struct in_addr v4; |
@@ -1317,19 +1280,19 @@ extract_hosts (const char *line, | |||
1317 | 1280 | ||
1318 | /* ignore everything after '#' */ | 1281 | /* ignore everything after '#' */ |
1319 | c = memrchr (line, | 1282 | c = memrchr (line, |
1320 | (unsigned char) '#', | 1283 | (unsigned char) '#', |
1321 | line_len); | 1284 | line_len); |
1322 | if (NULL != c) | 1285 | if (NULL != c) |
1323 | line_len = c - line; | 1286 | line_len = c - line; |
1324 | /* ignore leading whitespace */ | 1287 | /* ignore leading whitespace */ |
1325 | while ( (0 < line_len) && | 1288 | while ( (0 < line_len) && |
1326 | isspace ((unsigned char) *line) ) | 1289 | isspace ((unsigned char) *line) ) |
1327 | { | 1290 | { |
1328 | line++; | 1291 | line++; |
1329 | line_len--; | 1292 | line_len--; |
1330 | } | 1293 | } |
1331 | tbuf = GNUNET_strndup (line, | 1294 | tbuf = GNUNET_strndup (line, |
1332 | line_len); | 1295 | line_len); |
1333 | tok = strtok (tbuf, " \t"); | 1296 | tok = strtok (tbuf, " \t"); |
1334 | if (NULL == tok) | 1297 | if (NULL == tok) |
1335 | { | 1298 | { |
@@ -1337,24 +1300,24 @@ extract_hosts (const char *line, | |||
1337 | return; | 1300 | return; |
1338 | } | 1301 | } |
1339 | if (1 == inet_pton (AF_INET, | 1302 | if (1 == inet_pton (AF_INET, |
1340 | tok, | 1303 | tok, |
1341 | &v4)) | 1304 | &v4)) |
1342 | { | 1305 | { |
1343 | while (NULL != (tok = strtok (NULL, " \t"))) | 1306 | while (NULL != (tok = strtok (NULL, " \t"))) |
1344 | add_host (tok, | 1307 | add_host (tok, |
1345 | GNUNET_DNSPARSER_TYPE_A, | 1308 | GNUNET_DNSPARSER_TYPE_A, |
1346 | &v4, | 1309 | &v4, |
1347 | sizeof (struct in_addr)); | 1310 | sizeof (struct in_addr)); |
1348 | } | 1311 | } |
1349 | else if (1 == inet_pton (AF_INET6, | 1312 | else if (1 == inet_pton (AF_INET6, |
1350 | tok, | 1313 | tok, |
1351 | &v6)) | 1314 | &v6)) |
1352 | { | 1315 | { |
1353 | while (NULL != (tok = strtok (NULL, " \t"))) | 1316 | while (NULL != (tok = strtok (NULL, " \t"))) |
1354 | add_host (tok, | 1317 | add_host (tok, |
1355 | GNUNET_DNSPARSER_TYPE_AAAA, | 1318 | GNUNET_DNSPARSER_TYPE_AAAA, |
1356 | &v6, | 1319 | &v6, |
1357 | sizeof (struct in6_addr)); | 1320 | sizeof (struct in6_addr)); |
1358 | } | 1321 | } |
1359 | GNUNET_free (tbuf); | 1322 | GNUNET_free (tbuf); |
1360 | } | 1323 | } |
@@ -1373,36 +1336,36 @@ load_etc_hosts (void) | |||
1373 | size_t read_offset; | 1336 | size_t read_offset; |
1374 | 1337 | ||
1375 | fh = GNUNET_DISK_file_open ("/etc/hosts", | 1338 | fh = GNUNET_DISK_file_open ("/etc/hosts", |
1376 | GNUNET_DISK_OPEN_READ, | 1339 | GNUNET_DISK_OPEN_READ, |
1377 | GNUNET_DISK_PERM_NONE); | 1340 | GNUNET_DISK_PERM_NONE); |
1378 | if (NULL == fh) | 1341 | if (NULL == fh) |
1379 | { | 1342 | { |
1380 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1343 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1381 | "Failed to open /etc/hosts"); | 1344 | "Failed to open /etc/hosts"); |
1382 | return; | 1345 | return; |
1383 | } | 1346 | } |
1384 | if (GNUNET_OK != | 1347 | if (GNUNET_OK != |
1385 | GNUNET_DISK_file_handle_size (fh, | 1348 | GNUNET_DISK_file_handle_size (fh, |
1386 | &bytes_read)) | 1349 | &bytes_read)) |
1387 | { | 1350 | { |
1388 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1351 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1389 | "Could not determin size of /etc/hosts. " | 1352 | "Could not determin size of /etc/hosts. " |
1390 | "DNS resolution will not be possible.\n"); | 1353 | "DNS resolution will not be possible.\n"); |
1391 | GNUNET_DISK_file_close (fh); | 1354 | GNUNET_DISK_file_close (fh); |
1392 | return; | 1355 | return; |
1393 | } | 1356 | } |
1394 | if ((size_t) bytes_read > SIZE_MAX) | 1357 | if ((size_t) bytes_read > SIZE_MAX) |
1395 | { | 1358 | { |
1396 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1359 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1397 | "/etc/hosts file too large to mmap. " | 1360 | "/etc/hosts file too large to mmap. " |
1398 | "DNS resolution will not be possible.\n"); | 1361 | "DNS resolution will not be possible.\n"); |
1399 | GNUNET_DISK_file_close (fh); | 1362 | GNUNET_DISK_file_close (fh); |
1400 | return; | 1363 | return; |
1401 | } | 1364 | } |
1402 | buf = GNUNET_DISK_file_map (fh, | 1365 | buf = GNUNET_DISK_file_map (fh, |
1403 | &mh, | 1366 | &mh, |
1404 | GNUNET_DISK_MAP_TYPE_READ, | 1367 | GNUNET_DISK_MAP_TYPE_READ, |
1405 | (size_t) bytes_read); | 1368 | (size_t) bytes_read); |
1406 | read_offset = 0; | 1369 | read_offset = 0; |
1407 | while (read_offset < (size_t) bytes_read) | 1370 | while (read_offset < (size_t) bytes_read) |
1408 | { | 1371 | { |
@@ -1415,7 +1378,7 @@ load_etc_hosts (void) | |||
1415 | break; | 1378 | break; |
1416 | line_len = newline - buf - read_offset; | 1379 | line_len = newline - buf - read_offset; |
1417 | extract_hosts (buf + read_offset, | 1380 | extract_hosts (buf + read_offset, |
1418 | line_len); | 1381 | line_len); |
1419 | read_offset += line_len + 1; | 1382 | read_offset += line_len + 1; |
1420 | } | 1383 | } |
1421 | GNUNET_DISK_file_unmap (mh); | 1384 | GNUNET_DISK_file_unmap (mh); |
@@ -1432,8 +1395,8 @@ load_etc_hosts (void) | |||
1432 | */ | 1395 | */ |
1433 | static void | 1396 | static void |
1434 | init_cb (void *cls, | 1397 | init_cb (void *cls, |
1435 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1398 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1436 | struct GNUNET_SERVICE_Handle *sh) | 1399 | struct GNUNET_SERVICE_Handle *sh) |
1437 | { | 1400 | { |
1438 | char **dns_servers; | 1401 | char **dns_servers; |
1439 | int num_dns_servers; | 1402 | int num_dns_servers; |
@@ -1442,23 +1405,23 @@ init_cb (void *cls, | |||
1442 | (void) sh; | 1405 | (void) sh; |
1443 | load_etc_hosts (); | 1406 | load_etc_hosts (); |
1444 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 1407 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
1445 | cls); | 1408 | cls); |
1446 | dnsstub_ctx = GNUNET_DNSSTUB_start (128); | 1409 | dnsstub_ctx = GNUNET_DNSSTUB_start (128); |
1447 | dns_servers = NULL; | 1410 | dns_servers = NULL; |
1448 | num_dns_servers = lookup_dns_servers (&dns_servers); | 1411 | num_dns_servers = lookup_dns_servers (&dns_servers); |
1449 | if (0 >= num_dns_servers) | 1412 | if (0 >= num_dns_servers) |
1450 | { | 1413 | { |
1451 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1414 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1452 | _("No DNS server available. DNS resolution will not be possible.\n")); | 1415 | _("No DNS server available. DNS resolution will not be possible.\n")); |
1453 | return; | 1416 | return; |
1454 | } | 1417 | } |
1455 | for (int i = 0; i < num_dns_servers; i++) | 1418 | for (int i = 0; i < num_dns_servers; i++) |
1456 | { | 1419 | { |
1457 | int result = GNUNET_DNSSTUB_add_dns_ip (dnsstub_ctx, dns_servers[i]); | 1420 | int result = GNUNET_DNSSTUB_add_dns_ip (dnsstub_ctx, dns_servers[i]); |
1458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1421 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1459 | "Adding DNS server '%s': %s\n", | 1422 | "Adding DNS server '%s': %s\n", |
1460 | dns_servers[i], | 1423 | dns_servers[i], |
1461 | GNUNET_OK == result ? "success" : "failure"); | 1424 | GNUNET_OK == result ? "success" : "failure"); |
1462 | GNUNET_free (dns_servers[i]); | 1425 | GNUNET_free (dns_servers[i]); |
1463 | } | 1426 | } |
1464 | GNUNET_free_non_null (dns_servers); | 1427 | GNUNET_free_non_null (dns_servers); |
@@ -1475,8 +1438,8 @@ init_cb (void *cls, | |||
1475 | */ | 1438 | */ |
1476 | static void * | 1439 | static void * |
1477 | connect_cb (void *cls, | 1440 | connect_cb (void *cls, |
1478 | struct GNUNET_SERVICE_Client *c, | 1441 | struct GNUNET_SERVICE_Client *c, |
1479 | struct GNUNET_MQ_Handle *mq) | 1442 | struct GNUNET_MQ_Handle *mq) |
1480 | { | 1443 | { |
1481 | (void) cls; | 1444 | (void) cls; |
1482 | (void) mq; | 1445 | (void) mq; |
@@ -1494,8 +1457,8 @@ connect_cb (void *cls, | |||
1494 | */ | 1457 | */ |
1495 | static void | 1458 | static void |
1496 | disconnect_cb (void *cls, | 1459 | disconnect_cb (void *cls, |
1497 | struct GNUNET_SERVICE_Client *c, | 1460 | struct GNUNET_SERVICE_Client *c, |
1498 | void *internal_cls) | 1461 | void *internal_cls) |
1499 | { | 1462 | { |
1500 | struct ActiveLookup *n; | 1463 | struct ActiveLookup *n; |
1501 | (void) cls; | 1464 | (void) cls; |
@@ -1524,9 +1487,9 @@ GNUNET_SERVICE_MAIN | |||
1524 | &disconnect_cb, | 1487 | &disconnect_cb, |
1525 | NULL, | 1488 | NULL, |
1526 | GNUNET_MQ_hd_var_size (get, | 1489 | GNUNET_MQ_hd_var_size (get, |
1527 | GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST, | 1490 | GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST, |
1528 | struct GNUNET_RESOLVER_GetMessage, | 1491 | struct GNUNET_RESOLVER_GetMessage, |
1529 | NULL), | 1492 | NULL), |
1530 | GNUNET_MQ_handler_end ()); | 1493 | GNUNET_MQ_handler_end ()); |
1531 | 1494 | ||
1532 | 1495 | ||