From d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb Mon Sep 17 00:00:00 2001 From: ng0 Date: Sun, 8 Sep 2019 12:33:09 +0000 Subject: uncrustify as demanded. --- src/dns/dns.h | 17 +- src/dns/dns_api.c | 225 ++++--- src/dns/gnunet-dns-monitor.c | 380 +++++------ src/dns/gnunet-dns-redirector.c | 234 +++---- src/dns/gnunet-helper-dns.c | 1336 +++++++++++++++++++-------------------- src/dns/gnunet-service-dns.c | 1251 ++++++++++++++++++------------------ src/dns/gnunet-zonewalk.c | 593 ++++++++--------- src/dns/plugin_block_dns.c | 191 +++--- 8 files changed, 2131 insertions(+), 2096 deletions(-) (limited to 'src/dns') diff --git a/src/dns/dns.h b/src/dns/dns.h index af86bbaed..12d8f6025 100644 --- a/src/dns/dns.h +++ b/src/dns/dns.h @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -32,10 +32,9 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Message from client to DNS service to register itself. */ -struct GNUNET_DNS_Register -{ +struct GNUNET_DNS_Register { /** - * Header of type #GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT + * Header of type #GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT */ struct GNUNET_MessageHeader header; @@ -49,10 +48,9 @@ struct GNUNET_DNS_Register /** * Message from DNS service to client: please handle a request. */ -struct GNUNET_DNS_Request -{ +struct GNUNET_DNS_Request { /** - * Header of type #GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST + * Header of type #GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST */ struct GNUNET_MessageHeader header; @@ -67,15 +65,13 @@ struct GNUNET_DNS_Request uint64_t request_id GNUNET_PACKED; /* followed by original DNS request (without UDP header) */ - }; /** * Message from client to DNS service: here is my reply. */ -struct GNUNET_DNS_Response -{ +struct GNUNET_DNS_Response { /** * Header of type #GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE */ @@ -92,7 +88,6 @@ struct GNUNET_DNS_Response uint64_t request_id GNUNET_PACKED; /* followed by original DNS request (without UDP header) */ - }; diff --git a/src/dns/dns_api.c b/src/dns/dns_api.c index e34f02ef0..4dc8e00dd 100644 --- a/src/dns/dns_api.c +++ b/src/dns/dns_api.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -31,9 +31,7 @@ /** * Handle to identify an individual DNS request. */ -struct GNUNET_DNS_RequestHandle -{ - +struct GNUNET_DNS_RequestHandle { /** * Handle to DNS API. */ @@ -48,16 +46,13 @@ struct GNUNET_DNS_RequestHandle * Re-connect counter, to make sure we did not reconnect in the meantime. */ uint32_t generation; - }; /** * DNS handle */ -struct GNUNET_DNS_Handle -{ - +struct GNUNET_DNS_Handle { /** * Connection to DNS service, or NULL. */ @@ -108,7 +103,7 @@ struct GNUNET_DNS_Handle * @param tc scheduler context (unused) */ static void -reconnect (void *cls); +reconnect(void *cls); /** @@ -117,17 +112,17 @@ reconnect (void *cls); * @param dh handle with the connection */ static void -force_reconnect (struct GNUNET_DNS_Handle *dh) +force_reconnect(struct GNUNET_DNS_Handle *dh) { if (NULL != dh->mq) - { - GNUNET_MQ_destroy (dh->mq); - dh->mq = NULL; - } + { + GNUNET_MQ_destroy(dh->mq); + dh->mq = NULL; + } dh->reconnect_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &reconnect, - dh); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, + &reconnect, + dh); } @@ -140,12 +135,12 @@ force_reconnect (struct GNUNET_DNS_Handle *dh) * @param error error code */ static void -mq_error_handler (void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler(void *cls, + enum GNUNET_MQ_Error error) { struct GNUNET_DNS_Handle *dh = cls; - force_reconnect (dh); + force_reconnect(dh); } @@ -158,14 +153,14 @@ mq_error_handler (void *cls, * @param req message from the service (request) */ static int -check_request (void *cls, - const struct GNUNET_DNS_Request *req) +check_request(void *cls, + const struct GNUNET_DNS_Request *req) { - if (0 != ntohl (req->reserved)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + if (0 != ntohl(req->reserved)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -178,22 +173,22 @@ check_request (void *cls, * @param msg message from the service (request) */ static void -handle_request (void *cls, - const struct GNUNET_DNS_Request *req) +handle_request(void *cls, + const struct GNUNET_DNS_Request *req) { struct GNUNET_DNS_Handle *dh = cls; - size_t payload_length = ntohs (req->header.size) - sizeof (*req); + size_t payload_length = ntohs(req->header.size) - sizeof(*req); struct GNUNET_DNS_RequestHandle *rh; - rh = GNUNET_new (struct GNUNET_DNS_RequestHandle); - rh->dh =dh; + rh = GNUNET_new(struct GNUNET_DNS_RequestHandle); + rh->dh = dh; rh->request_id = req->request_id; rh->generation = dh->generation; dh->pending_requests++; - dh->rh (dh->rh_cls, - rh, - payload_length, - (const char*) &req[1]); + dh->rh(dh->rh_cls, + rh, + payload_length, + (const char*)&req[1]); } @@ -203,33 +198,33 @@ handle_request (void *cls, * @param cls handle with the connection to connect */ static void -reconnect (void *cls) +reconnect(void *cls) { struct GNUNET_DNS_Handle *dh = cls; struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size (request, - GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST, - struct GNUNET_DNS_Request, - dh), - GNUNET_MQ_handler_end () + GNUNET_MQ_hd_var_size(request, + GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST, + struct GNUNET_DNS_Request, + dh), + GNUNET_MQ_handler_end() }; struct GNUNET_MQ_Envelope *env; struct GNUNET_DNS_Register *msg; dh->reconnect_task = NULL; - dh->mq = GNUNET_CLIENT_connect (dh->cfg, - "dns", - handlers, - &mq_error_handler, - dh); + dh->mq = GNUNET_CLIENT_connect(dh->cfg, + "dns", + handlers, + &mq_error_handler, + dh); if (NULL == dh->mq) return; dh->generation++; - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT); - msg->flags = htonl (dh->flags); - GNUNET_MQ_send (dh->mq, - env); + env = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT); + msg->flags = htonl(dh->flags); + GNUNET_MQ_send(dh->mq, + env); } @@ -244,24 +239,24 @@ reconnect (void *cls) * @param rh request that should now be forwarded */ void -GNUNET_DNS_request_forward (struct GNUNET_DNS_RequestHandle *rh) +GNUNET_DNS_request_forward(struct GNUNET_DNS_RequestHandle *rh) { struct GNUNET_MQ_Envelope *env; struct GNUNET_DNS_Response *resp; - GNUNET_assert (0 < rh->dh->pending_requests--); + GNUNET_assert(0 < rh->dh->pending_requests--); if (rh->generation != rh->dh->generation) - { - GNUNET_free (rh); - return; - } - env = GNUNET_MQ_msg (resp, - GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); - resp->drop_flag = htonl (1); + { + GNUNET_free(rh); + return; + } + env = GNUNET_MQ_msg(resp, + GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); + resp->drop_flag = htonl(1); resp->request_id = rh->request_id; - GNUNET_MQ_send (rh->dh->mq, - env); - GNUNET_free (rh); + GNUNET_MQ_send(rh->dh->mq, + env); + GNUNET_free(rh); } @@ -272,24 +267,24 @@ GNUNET_DNS_request_forward (struct GNUNET_DNS_RequestHandle *rh) * @param rh request that should now be dropped */ void -GNUNET_DNS_request_drop (struct GNUNET_DNS_RequestHandle *rh) +GNUNET_DNS_request_drop(struct GNUNET_DNS_RequestHandle *rh) { struct GNUNET_MQ_Envelope *env; struct GNUNET_DNS_Response *resp; - GNUNET_assert (0 < rh->dh->pending_requests--); + GNUNET_assert(0 < rh->dh->pending_requests--); if (rh->generation != rh->dh->generation) - { - GNUNET_free (rh); + { + GNUNET_free(rh); return; - } - env = GNUNET_MQ_msg (resp, - GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); + } + env = GNUNET_MQ_msg(resp, + GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); resp->request_id = rh->request_id; - resp->drop_flag = htonl (0); - GNUNET_MQ_send (rh->dh->mq, - env); - GNUNET_free (rh); + resp->drop_flag = htonl(0); + GNUNET_MQ_send(rh->dh->mq, + env); + GNUNET_free(rh); } @@ -303,37 +298,37 @@ GNUNET_DNS_request_drop (struct GNUNET_DNS_RequestHandle *rh) * @param reply reply data */ void -GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh, - uint16_t reply_length, - const char *reply) +GNUNET_DNS_request_answer(struct GNUNET_DNS_RequestHandle *rh, + uint16_t reply_length, + const char *reply) { struct GNUNET_MQ_Envelope *env; struct GNUNET_DNS_Response *resp; - GNUNET_assert (0 < rh->dh->pending_requests--); + GNUNET_assert(0 < rh->dh->pending_requests--); if (rh->generation != rh->dh->generation) - { - GNUNET_free (rh); + { + GNUNET_free(rh); return; - } - if (reply_length + sizeof (struct GNUNET_DNS_Response) + } + if (reply_length + sizeof(struct GNUNET_DNS_Response) >= GNUNET_MAX_MESSAGE_SIZE) - { - GNUNET_break (0); - GNUNET_free (rh); - return; - } - env = GNUNET_MQ_msg_extra (resp, - reply_length, - GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); - resp->drop_flag = htonl (2); + { + GNUNET_break(0); + GNUNET_free(rh); + return; + } + env = GNUNET_MQ_msg_extra(resp, + reply_length, + GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE); + resp->drop_flag = htonl(2); resp->request_id = rh->request_id; - GNUNET_memcpy (&resp[1], - reply, - reply_length); - GNUNET_MQ_send (rh->dh->mq, - env); - GNUNET_free (rh); + GNUNET_memcpy(&resp[1], + reply, + reply_length); + GNUNET_MQ_send(rh->dh->mq, + env); + GNUNET_free(rh); } @@ -347,19 +342,19 @@ GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh, * @return DNS handle */ struct GNUNET_DNS_Handle * -GNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, - enum GNUNET_DNS_Flags flags, - GNUNET_DNS_RequestHandler rh, - void *rh_cls) +GNUNET_DNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, + enum GNUNET_DNS_Flags flags, + GNUNET_DNS_RequestHandler rh, + void *rh_cls) { struct GNUNET_DNS_Handle *dh; - dh = GNUNET_new (struct GNUNET_DNS_Handle); + dh = GNUNET_new(struct GNUNET_DNS_Handle); dh->cfg = cfg; dh->flags = flags; dh->rh = rh; dh->rh_cls = rh_cls; - dh->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, dh); + dh->reconnect_task = GNUNET_SCHEDULER_add_now(&reconnect, dh); return dh; } @@ -370,21 +365,21 @@ GNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, * @param dh DNS handle */ void -GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *dh) +GNUNET_DNS_disconnect(struct GNUNET_DNS_Handle *dh) { if (NULL != dh->mq) - { - GNUNET_MQ_destroy (dh->mq); - dh->mq = NULL; - } + { + GNUNET_MQ_destroy(dh->mq); + dh->mq = NULL; + } if (NULL != dh->reconnect_task) - { - GNUNET_SCHEDULER_cancel (dh->reconnect_task); - dh->reconnect_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(dh->reconnect_task); + dh->reconnect_task = NULL; + } /* make sure client has no pending requests left over! */ - GNUNET_break (0 == dh->pending_requests); - GNUNET_free (dh); + GNUNET_break(0 == dh->pending_requests); + GNUNET_free(dh); } /* end of dns_api.c */ diff --git a/src/dns/gnunet-dns-monitor.c b/src/dns/gnunet-dns-monitor.c index e822b3211..819cb025d 100644 --- a/src/dns/gnunet-dns-monitor.c +++ b/src/dns/gnunet-dns-monitor.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file src/dns/gnunet-dns-monitor.c @@ -62,22 +62,31 @@ static unsigned int verbosity; * @return type as string, only valid until the next call to this function */ static const char * -get_type (uint16_t type) +get_type(uint16_t type) { static char buf[6]; + switch (type) - { - case GNUNET_DNSPARSER_TYPE_A: return "A"; - case GNUNET_DNSPARSER_TYPE_NS: return "NS"; - case GNUNET_DNSPARSER_TYPE_CNAME: return "CNAME"; - case GNUNET_DNSPARSER_TYPE_SOA: return "SOA"; - case GNUNET_DNSPARSER_TYPE_PTR: return "PTR"; - case GNUNET_DNSPARSER_TYPE_MX: return "MX"; - case GNUNET_DNSPARSER_TYPE_TXT: return "TXT"; - case GNUNET_DNSPARSER_TYPE_AAAA: return "AAAA"; - case GNUNET_DNSPARSER_TYPE_SRV: return "SRV"; - } - GNUNET_snprintf (buf, sizeof (buf), "%u", (unsigned int) type); + { + case GNUNET_DNSPARSER_TYPE_A: return "A"; + + case GNUNET_DNSPARSER_TYPE_NS: return "NS"; + + case GNUNET_DNSPARSER_TYPE_CNAME: return "CNAME"; + + case GNUNET_DNSPARSER_TYPE_SOA: return "SOA"; + + case GNUNET_DNSPARSER_TYPE_PTR: return "PTR"; + + case GNUNET_DNSPARSER_TYPE_MX: return "MX"; + + case GNUNET_DNSPARSER_TYPE_TXT: return "TXT"; + + case GNUNET_DNSPARSER_TYPE_AAAA: return "AAAA"; + + case GNUNET_DNSPARSER_TYPE_SRV: return "SRV"; + } + GNUNET_snprintf(buf, sizeof(buf), "%u", (unsigned int)type); return buf; } @@ -89,16 +98,19 @@ get_type (uint16_t type) * @return class as string, only valid until the next call to this function */ static const char * -get_class (uint16_t class) +get_class(uint16_t class) { static char buf[6]; + switch (class) - { - case GNUNET_TUN_DNS_CLASS_INTERNET: return "IN"; - case GNUNET_TUN_DNS_CLASS_CHAOS: return "CHAOS"; - case GNUNET_TUN_DNS_CLASS_HESIOD: return "HESIOD"; - } - GNUNET_snprintf (buf, sizeof (buf), "%u", (unsigned int) class); + { + case GNUNET_TUN_DNS_CLASS_INTERNET: return "IN"; + + case GNUNET_TUN_DNS_CLASS_CHAOS: return "CHAOS"; + + case GNUNET_TUN_DNS_CLASS_HESIOD: return "HESIOD"; + } + GNUNET_snprintf(buf, sizeof(buf), "%u", (unsigned int)class); return buf; } @@ -109,13 +121,13 @@ get_class (uint16_t class) * @param query query to display. */ static void -display_query (const struct GNUNET_DNSPARSER_Query *query) +display_query(const struct GNUNET_DNSPARSER_Query *query) { - fprintf (stdout, - "\t\t%s %s: %s\n", - get_class (query->dns_traffic_class), - get_type (query->type), - query->name); + fprintf(stdout, + "\t\t%s %s: %s\n", + get_class(query->dns_traffic_class), + get_type(query->type), + query->name); } @@ -125,7 +137,7 @@ display_query (const struct GNUNET_DNSPARSER_Query *query) * @param record record to display. */ static void -display_record (const struct GNUNET_DNSPARSER_Record *record) +display_record(const struct GNUNET_DNSPARSER_Record *record) { const char *format; char buf[INET6_ADDRSTRLEN]; @@ -133,86 +145,93 @@ display_record (const struct GNUNET_DNSPARSER_Record *record) tmp = NULL; switch (record->type) - { - case GNUNET_DNSPARSER_TYPE_A: - if (record->data.raw.data_len != sizeof (struct in_addr)) - format = ""; - else - format = inet_ntop (AF_INET, record->data.raw.data, buf, sizeof (buf)); - break; - case GNUNET_DNSPARSER_TYPE_AAAA: - if (record->data.raw.data_len != sizeof (struct in6_addr)) - format = ""; - else - format = inet_ntop (AF_INET6, record->data.raw.data, buf, sizeof (buf)); - break; - case GNUNET_DNSPARSER_TYPE_NS: - case GNUNET_DNSPARSER_TYPE_CNAME: - case GNUNET_DNSPARSER_TYPE_PTR: - format = record->data.hostname; - break; - case GNUNET_DNSPARSER_TYPE_SOA: - if (NULL == record->data.soa) - format = ""; - else { - GNUNET_asprintf (&tmp, - "origin: %s, mail: %s, serial = %u, refresh = %u s, retry = %u s, expire = %u s, minimum = %u s", - record->data.soa->mname, - record->data.soa->rname, - (unsigned int) record->data.soa->serial, - (unsigned int) record->data.soa->refresh, - (unsigned int) record->data.soa->retry, - (unsigned int) record->data.soa->expire, - (unsigned int) record->data.soa->minimum_ttl); - format = tmp; - } - break; - case GNUNET_DNSPARSER_TYPE_MX: - if (record->data.mx == NULL) - format = ""; - else - { - GNUNET_asprintf (&tmp, - "%u: %s", - record->data.mx->preference, - record->data.mx->mxhost); - format = tmp; - } - break; - case GNUNET_DNSPARSER_TYPE_SRV: - if (NULL == record->data.srv) - format = ""; - else - { - GNUNET_asprintf (&tmp, - "priority %u, weight = %s, port = %u, target = %s", - (unsigned int) record->data.srv->priority, - (unsigned int) record->data.srv->weight, - (unsigned int) record->data.srv->port, - record->data.srv->target); + case GNUNET_DNSPARSER_TYPE_A: + if (record->data.raw.data_len != sizeof(struct in_addr)) + format = ""; + else + format = inet_ntop(AF_INET, record->data.raw.data, buf, sizeof(buf)); + break; + + case GNUNET_DNSPARSER_TYPE_AAAA: + if (record->data.raw.data_len != sizeof(struct in6_addr)) + format = ""; + else + format = inet_ntop(AF_INET6, record->data.raw.data, buf, sizeof(buf)); + break; + + case GNUNET_DNSPARSER_TYPE_NS: + case GNUNET_DNSPARSER_TYPE_CNAME: + case GNUNET_DNSPARSER_TYPE_PTR: + format = record->data.hostname; + break; + + case GNUNET_DNSPARSER_TYPE_SOA: + if (NULL == record->data.soa) + format = ""; + else + { + GNUNET_asprintf(&tmp, + "origin: %s, mail: %s, serial = %u, refresh = %u s, retry = %u s, expire = %u s, minimum = %u s", + record->data.soa->mname, + record->data.soa->rname, + (unsigned int)record->data.soa->serial, + (unsigned int)record->data.soa->refresh, + (unsigned int)record->data.soa->retry, + (unsigned int)record->data.soa->expire, + (unsigned int)record->data.soa->minimum_ttl); + format = tmp; + } + break; + + case GNUNET_DNSPARSER_TYPE_MX: + if (record->data.mx == NULL) + format = ""; + else + { + GNUNET_asprintf(&tmp, + "%u: %s", + record->data.mx->preference, + record->data.mx->mxhost); + format = tmp; + } + break; + + case GNUNET_DNSPARSER_TYPE_SRV: + if (NULL == record->data.srv) + format = ""; + else + { + GNUNET_asprintf(&tmp, + "priority %u, weight = %s, port = %u, target = %s", + (unsigned int)record->data.srv->priority, + (unsigned int)record->data.srv->weight, + (unsigned int)record->data.srv->port, + record->data.srv->target); + format = tmp; + } + break; + + case GNUNET_DNSPARSER_TYPE_TXT: + GNUNET_asprintf(&tmp, + "%.*s", + (unsigned int)record->data.raw.data_len, + record->data.raw.data); format = tmp; + break; + + default: + format = ""; + break; } - break; - case GNUNET_DNSPARSER_TYPE_TXT: - GNUNET_asprintf (&tmp, - "%.*s", - (unsigned int) record->data.raw.data_len, - record->data.raw.data); - format = tmp; - break; - default: - format = ""; - break; - } - fprintf (stdout, - "\t\t%s %s: %s = %s (%u s)\n", - get_class (record->dns_traffic_class), - get_type (record->type), - record->name, - format, - (unsigned int) (GNUNET_TIME_absolute_get_remaining (record->expiration_time).rel_value_us / 1000LL / 1000LL)); - GNUNET_free_non_null (tmp); + fprintf(stdout, + "\t\t%s %s: %s = %s (%u s)\n", + get_class(record->dns_traffic_class), + get_type(record->type), + record->name, + format, + (unsigned int)(GNUNET_TIME_absolute_get_remaining(record->expiration_time).rel_value_us / 1000LL / 1000LL)); + GNUNET_free_non_null(tmp); } @@ -240,62 +259,62 @@ display_record (const struct GNUNET_DNSPARSER_Record *record) * @param request udp payload of the DNS request */ static void -display_request (void *cls, - struct GNUNET_DNS_RequestHandle *rh, - size_t request_length, - const char *request) +display_request(void *cls, + struct GNUNET_DNS_RequestHandle *rh, + size_t request_length, + const char *request) { static const char *return_codes[] = - { - "No error", "Format error", "Server failure", "Name error", - "Not implemented", "Refused", "YXDomain", "YXRRset", - "NXRRset", "NOT AUTH", "NOT ZONE", "", - "", "", "", "" - }; + { + "No error", "Format error", "Server failure", "Name error", + "Not implemented", "Refused", "YXDomain", "YXRRset", + "NXRRset", "NOT AUTH", "NOT ZONE", "", + "", "", "", "" + }; static const char *op_codes[] = - { - "Query", "Inverse query", "Status", "", - "", "", "", "", - "", "", "", "", - "", "", "", "" - }; + { + "Query", "Inverse query", "Status", "", + "", "", "", "", + "", "", "", "", + "", "", "", "" + }; struct GNUNET_DNSPARSER_Packet *p; unsigned int i; - p = GNUNET_DNSPARSER_parse (request, request_length); + p = GNUNET_DNSPARSER_parse(request, request_length); if (NULL == p) - { - fprintf (stderr, "Received malformed DNS packet!\n"); - // FIXME: drop instead? - GNUNET_DNS_request_forward (rh); - return; - } - fprintf (stdout, - "%s with ID: %5u Flags: %s%s%s%s%s%s, Return Code: %s, Opcode: %s\n", - p->flags.query_or_response ? "Response" : "Query", - p->id, - p->flags.recursion_desired ? "RD " : "", - p->flags.message_truncated ? "MT " : "", - p->flags.authoritative_answer ? "AA " : "", - p->flags.checking_disabled ? "CD " : "", - p->flags.authenticated_data ? "AD " : "", - p->flags.recursion_available ? "RA " : "", - return_codes[p->flags.return_code & 15], - op_codes[p->flags.opcode & 15]); + { + fprintf(stderr, "Received malformed DNS packet!\n"); + // FIXME: drop instead? + GNUNET_DNS_request_forward(rh); + return; + } + fprintf(stdout, + "%s with ID: %5u Flags: %s%s%s%s%s%s, Return Code: %s, Opcode: %s\n", + p->flags.query_or_response ? "Response" : "Query", + p->id, + p->flags.recursion_desired ? "RD " : "", + p->flags.message_truncated ? "MT " : "", + p->flags.authoritative_answer ? "AA " : "", + p->flags.checking_disabled ? "CD " : "", + p->flags.authenticated_data ? "AD " : "", + p->flags.recursion_available ? "RA " : "", + return_codes[p->flags.return_code & 15], + op_codes[p->flags.opcode & 15]); if (p->num_queries > 0) - fprintf (stdout, - "\tQueries:\n"); - for (i=0;inum_queries;i++) - display_query (&p->queries[i]); + fprintf(stdout, + "\tQueries:\n"); + for (i = 0; i < p->num_queries; i++) + display_query(&p->queries[i]); if (p->num_answers > 0) - fprintf (stdout, - "\tAnswers:\n"); - for (i=0;inum_answers;i++) - display_record (&p->answers[i]); - fprintf (stdout, "\n"); - GNUNET_DNSPARSER_free_packet (p); - GNUNET_DNS_request_forward (rh); + fprintf(stdout, + "\tAnswers:\n"); + for (i = 0; i < p->num_answers; i++) + display_record(&p->answers[i]); + fprintf(stdout, "\n"); + GNUNET_DNSPARSER_free_packet(p); + GNUNET_DNS_request_forward(rh); } @@ -303,13 +322,13 @@ display_request (void *cls, * Shutdown. */ static void -do_disconnect (void *cls) +do_disconnect(void *cls) { if (NULL != handle) - { - GNUNET_DNS_disconnect (handle); - handle = NULL; - } + { + GNUNET_DNS_disconnect(handle); + handle = NULL; + } } @@ -322,8 +341,8 @@ do_disconnect (void *cls) * @param cfg configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { enum GNUNET_DNS_Flags flags; @@ -335,41 +354,40 @@ run (void *cls, char *const *args, const char *cfgfile, if (outbound_only) flags |= GNUNET_DNS_FLAG_RESPONSE_MONITOR; handle = - GNUNET_DNS_connect (cfg, - flags, - &display_request, - NULL); - GNUNET_SCHEDULER_add_shutdown (&do_disconnect, NULL); + GNUNET_DNS_connect(cfg, + flags, + &display_request, + NULL); + GNUNET_SCHEDULER_add_shutdown(&do_disconnect, NULL); } int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_option_flag('i', + "inbound-only", + gettext_noop("only monitor DNS queries"), + &inbound_only), - GNUNET_GETOPT_option_flag ('i', - "inbound-only", - gettext_noop ("only monitor DNS queries"), - &inbound_only), - - GNUNET_GETOPT_option_flag ('o', - "outbound-only", - gettext_noop ("only monitor DNS queries"), - &outbound_only), + GNUNET_GETOPT_option_flag('o', + "outbound-only", + gettext_noop("only monitor DNS queries"), + &outbound_only), - GNUNET_GETOPT_option_verbose (&verbosity), + GNUNET_GETOPT_option_verbose(&verbosity), GNUNET_GETOPT_OPTION_END }; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "gnunet-dns-monitor", - gettext_noop - ("Monitor DNS queries."), options, - &run, NULL)) ? ret : 1; - GNUNET_free ((void*) argv); + GNUNET_PROGRAM_run(argc, argv, "gnunet-dns-monitor", + gettext_noop + ("Monitor DNS queries."), options, + &run, NULL)) ? ret : 1; + GNUNET_free((void*)argv); return ret; } diff --git a/src/dns/gnunet-dns-redirector.c b/src/dns/gnunet-dns-redirector.c index 608540e12..f1978ce92 100644 --- a/src/dns/gnunet-dns-redirector.c +++ b/src/dns/gnunet-dns-redirector.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file src/dns/gnunet-dns-redirector.c @@ -61,48 +61,51 @@ static unsigned int verbosity; * @param record record to modify */ static void -modify_record (const struct GNUNET_DNSPARSER_Record *record) +modify_record(const struct GNUNET_DNSPARSER_Record *record) { char buf[INET6_ADDRSTRLEN]; switch (record->type) - { - case GNUNET_DNSPARSER_TYPE_A: - if (record->data.raw.data_len != sizeof (struct in_addr)) - return; - if (NULL != n4) { - if (verbosity > 1) - fprintf (stderr, - "Changing A record from `%s' to `%s'\n", - inet_ntop (AF_INET, record->data.raw.data, buf, sizeof (buf)), - n4); - GNUNET_assert (1 == inet_pton (AF_INET, n4, record->data.raw.data)); - } - break; - case GNUNET_DNSPARSER_TYPE_AAAA: - if (record->data.raw.data_len != sizeof (struct in6_addr)) - return; - if (NULL != n6) - { - if (verbosity > 1) - fprintf (stderr, - "Changing AAAA record from `%s' to `%s'\n", - inet_ntop (AF_INET6, record->data.raw.data, buf, sizeof (buf)), - n6); - GNUNET_assert (1 == inet_pton (AF_INET6, n6, record->data.raw.data)); + case GNUNET_DNSPARSER_TYPE_A: + if (record->data.raw.data_len != sizeof(struct in_addr)) + return; + if (NULL != n4) + { + if (verbosity > 1) + fprintf(stderr, + "Changing A record from `%s' to `%s'\n", + inet_ntop(AF_INET, record->data.raw.data, buf, sizeof(buf)), + n4); + GNUNET_assert(1 == inet_pton(AF_INET, n4, record->data.raw.data)); + } + break; + + case GNUNET_DNSPARSER_TYPE_AAAA: + if (record->data.raw.data_len != sizeof(struct in6_addr)) + return; + if (NULL != n6) + { + if (verbosity > 1) + fprintf(stderr, + "Changing AAAA record from `%s' to `%s'\n", + inet_ntop(AF_INET6, record->data.raw.data, buf, sizeof(buf)), + n6); + GNUNET_assert(1 == inet_pton(AF_INET6, n6, record->data.raw.data)); + } + break; + + case GNUNET_DNSPARSER_TYPE_NS: + case GNUNET_DNSPARSER_TYPE_CNAME: + case GNUNET_DNSPARSER_TYPE_PTR: + case GNUNET_DNSPARSER_TYPE_SOA: + case GNUNET_DNSPARSER_TYPE_MX: + case GNUNET_DNSPARSER_TYPE_TXT: + break; + + default: + break; } - break; - case GNUNET_DNSPARSER_TYPE_NS: - case GNUNET_DNSPARSER_TYPE_CNAME: - case GNUNET_DNSPARSER_TYPE_PTR: - case GNUNET_DNSPARSER_TYPE_SOA: - case GNUNET_DNSPARSER_TYPE_MX: - case GNUNET_DNSPARSER_TYPE_TXT: - break; - default: - break; - } } @@ -130,10 +133,10 @@ modify_record (const struct GNUNET_DNSPARSER_Record *record) * @param request udp payload of the DNS request */ static void -modify_request (void *cls, - struct GNUNET_DNS_RequestHandle *rh, - size_t request_length, - const char *request) +modify_request(void *cls, + struct GNUNET_DNS_RequestHandle *rh, + size_t request_length, + const char *request) { struct GNUNET_DNSPARSER_Packet *p; unsigned int i; @@ -141,35 +144,35 @@ modify_request (void *cls, size_t len; int ret; - p = GNUNET_DNSPARSER_parse (request, request_length); + p = GNUNET_DNSPARSER_parse(request, request_length); if (NULL == p) - { - fprintf (stderr, "Received malformed DNS packet, leaving it untouched\n"); - GNUNET_DNS_request_forward (rh); - return; - } - for (i=0;inum_answers;i++) - modify_record (&p->answers[i]); + { + fprintf(stderr, "Received malformed DNS packet, leaving it untouched\n"); + GNUNET_DNS_request_forward(rh); + return; + } + for (i = 0; i < p->num_answers; i++) + modify_record(&p->answers[i]); buf = NULL; - ret = GNUNET_DNSPARSER_pack (p, 1024, &buf, &len); - GNUNET_DNSPARSER_free_packet (p); + ret = GNUNET_DNSPARSER_pack(p, 1024, &buf, &len); + GNUNET_DNSPARSER_free_packet(p); if (GNUNET_OK != ret) - { - if (GNUNET_NO == ret) - fprintf (stderr, - "Modified DNS response did not fit, keeping old response\n"); - else - GNUNET_break (0); /* our modifications should have been sane! */ - GNUNET_DNS_request_forward (rh); - } + { + if (GNUNET_NO == ret) + fprintf(stderr, + "Modified DNS response did not fit, keeping old response\n"); + else + GNUNET_break(0); /* our modifications should have been sane! */ + GNUNET_DNS_request_forward(rh); + } else - { - if (verbosity > 0) - fprintf (stdout, - "Injecting modified DNS response\n"); - GNUNET_DNS_request_answer (rh, len, buf); - } - GNUNET_free_non_null (buf); + { + if (verbosity > 0) + fprintf(stdout, + "Injecting modified DNS response\n"); + GNUNET_DNS_request_answer(rh, len, buf); + } + GNUNET_free_non_null(buf); } @@ -177,13 +180,13 @@ modify_request (void *cls, * Shutdown. */ static void -do_disconnect (void *cls) +do_disconnect(void *cls) { if (NULL != handle) - { - GNUNET_DNS_disconnect (handle); - handle = NULL; - } + { + GNUNET_DNS_disconnect(handle); + handle = NULL; + } } @@ -196,66 +199,67 @@ do_disconnect (void *cls) * @param cfg configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run(void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct in_addr i4; struct in6_addr i6; - if ( (n4 != NULL) && - (1 != inet_pton (AF_INET, n4, &i4)) ) - { - fprintf (stderr, - "`%s' is nto a valid IPv4 address!\n", - n4); - return; - } - if ( (n6 != NULL) && - (1 != inet_pton (AF_INET6, n6, &i6)) ) - { - fprintf (stderr, - "`%s' is nto a valid IPv6 address!\n", - n6); - return; - } + + if ((n4 != NULL) && + (1 != inet_pton(AF_INET, n4, &i4))) + { + fprintf(stderr, + "`%s' is nto a valid IPv4 address!\n", + n4); + return; + } + if ((n6 != NULL) && + (1 != inet_pton(AF_INET6, n6, &i6))) + { + fprintf(stderr, + "`%s' is nto a valid IPv6 address!\n", + n6); + return; + } handle = - GNUNET_DNS_connect (cfg, - GNUNET_DNS_FLAG_POST_RESOLUTION, - &modify_request, - NULL); - GNUNET_SCHEDULER_add_shutdown (&do_disconnect, NULL); + GNUNET_DNS_connect(cfg, + GNUNET_DNS_FLAG_POST_RESOLUTION, + &modify_request, + NULL); + GNUNET_SCHEDULER_add_shutdown(&do_disconnect, NULL); } int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_string ('4', - "ipv4", - "IPV4", - gettext_noop ("set A records"), - &n4), - - GNUNET_GETOPT_option_string ('6', - "ipv4", - "IPV6", - gettext_noop ("set AAAA records"), - &n6), - - GNUNET_GETOPT_option_verbose (&verbosity), + GNUNET_GETOPT_option_string('4', + "ipv4", + "IPV4", + gettext_noop("set A records"), + &n4), + + GNUNET_GETOPT_option_string('6', + "ipv4", + "IPV6", + gettext_noop("set AAAA records"), + &n6), + + GNUNET_GETOPT_option_verbose(&verbosity), GNUNET_GETOPT_OPTION_END }; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "gnunet-dns-redirector", - gettext_noop - ("Change DNS replies to point elsewhere."), options, - &run, NULL)) ? ret : 1; - GNUNET_free ((void*) argv); + GNUNET_PROGRAM_run(argc, argv, "gnunet-dns-redirector", + gettext_noop + ("Change DNS replies to point elsewhere."), options, + &run, NULL)) ? ret : 1; + GNUNET_free((void*)argv); return ret; } diff --git a/src/dns/gnunet-helper-dns.c b/src/dns/gnunet-helper-dns.c index 554727094..85c72579d 100644 --- a/src/dns/gnunet-helper-dns.c +++ b/src/dns/gnunet-helper-dns.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file dns/gnunet-helper-dns.c @@ -87,8 +87,7 @@ /** * This is in linux/include/net/ipv6.h, but not always exported... */ -struct in6_ifreq -{ +struct in6_ifreq { struct in6_addr ifr6_addr; uint32_t ifr6_prefixlen; unsigned int ifr6_ifindex; @@ -152,11 +151,11 @@ static int cpipe[2]; * @param signal signal number of the signal (not used) */ static void -signal_handler (int signal) +signal_handler(int signal) { /* ignore return value, as the signal handler could theoretically be called many times before the shutdown can actually happen */ - (void) write (cpipe[1], "K", 1); + (void)write(cpipe[1], "K", 1); } @@ -168,22 +167,22 @@ signal_handler (int signal) * @param flags open flags (O_RDONLY, O_WRONLY) */ static void -open_dev_null (int target_fd, - int flags) +open_dev_null(int target_fd, + int flags) { int fd; - fd = open ("/dev/null", flags); + fd = open("/dev/null", flags); if (-1 == fd) - abort (); + abort(); if (fd == target_fd) return; - if (-1 == dup2 (fd, target_fd)) - { - (void) close (fd); - abort (); - } - (void) close (fd); + if (-1 == dup2(fd, target_fd)) + { + (void)close(fd); + abort(); + } + (void)close(fd); } @@ -195,49 +194,50 @@ open_dev_null (int target_fd, * @return 0 on success, 1 on any error */ static int -fork_and_exec (const char *file, - char *const cmd[]) +fork_and_exec(const char *file, + char *const cmd[]) { int status; pid_t pid; pid_t ret; - pid = fork (); + pid = fork(); if (-1 == pid) - { - fprintf (stderr, - "fork failed: %s\n", - strerror (errno)); - return 1; - } + { + fprintf(stderr, + "fork failed: %s\n", + strerror(errno)); + return 1; + } if (0 == pid) - { - /* we are the child process */ - /* close stdin/stdout to not cause interference - with the helper's main protocol! */ - (void) close (0); - open_dev_null (0, O_RDONLY); - (void) close (1); - open_dev_null (1, O_WRONLY); - (void) execv (file, cmd); - /* can only get here on error */ - fprintf (stderr, - "exec `%s' failed: %s\n", - file, - strerror (errno)); - _exit (1); - } + { + /* we are the child process */ + /* close stdin/stdout to not cause interference + with the helper's main protocol! */ + (void)close(0); + open_dev_null(0, O_RDONLY); + (void)close(1); + open_dev_null(1, O_WRONLY); + (void)execv(file, cmd); + /* can only get here on error */ + fprintf(stderr, + "exec `%s' failed: %s\n", + file, + strerror(errno)); + _exit(1); + } /* keep running waitpid as long as the only error we get is 'EINTR' */ - while ( (-1 == (ret = waitpid (pid, &status, 0))) && - (errno == EINTR) ); + while ((-1 == (ret = waitpid(pid, &status, 0))) && + (errno == EINTR)) + ; if (-1 == ret) - { - fprintf (stderr, - "waitpid failed: %s\n", - strerror (errno)); - return 1; - } - if (! (WIFEXITED (status) && (0 == WEXITSTATUS (status)))) + { + fprintf(stderr, + "waitpid failed: %s\n", + strerror(errno)); + return 1; + } + if (!(WIFEXITED(status) && (0 == WEXITSTATUS(status)))) return 1; /* child process completed and returned success, we're happy */ return 0; @@ -252,45 +252,45 @@ fork_and_exec (const char *file, * @return the fd to the tun or -1 on error */ static int -init_tun (char *dev) +init_tun(char *dev) { struct ifreq ifr; int fd; if (NULL == dev) - { - errno = EINVAL; - return -1; - } + { + errno = EINVAL; + return -1; + } - if (-1 == (fd = open ("/dev/net/tun", O_RDWR))) - { - fprintf (stderr, "Error opening `%s': %s\n", "/dev/net/tun", - strerror (errno)); - return -1; - } + if (-1 == (fd = open("/dev/net/tun", O_RDWR))) + { + fprintf(stderr, "Error opening `%s': %s\n", "/dev/net/tun", + strerror(errno)); + return -1; + } if (fd >= FD_SETSIZE) - { - fprintf (stderr, "File descriptor to large: %d", fd); - (void) close (fd); - return -1; - } + { + fprintf(stderr, "File descriptor to large: %d", fd); + (void)close(fd); + return -1; + } - memset (&ifr, 0, sizeof (ifr)); + memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TUN; if ('\0' != *dev) - strncpy (ifr.ifr_name, dev, IFNAMSIZ); + strncpy(ifr.ifr_name, dev, IFNAMSIZ); - if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr)) - { - fprintf (stderr, "Error with ioctl on `%s': %s\n", "/dev/net/tun", - strerror (errno)); - (void) close (fd); - return -1; - } - strcpy (dev, ifr.ifr_name); + if (-1 == ioctl(fd, TUNSETIFF, (void *)&ifr)) + { + fprintf(stderr, "Error with ioctl on `%s': %s\n", "/dev/net/tun", + strerror(errno)); + (void)close(fd); + return -1; + } + strcpy(dev, ifr.ifr_name); return fd; } @@ -303,7 +303,7 @@ init_tun (char *dev) * @param prefix_len the length of the network-prefix */ static void -set_address6 (const char *dev, const char *address, unsigned long prefix_len) +set_address6(const char *dev, const char *address, unsigned long prefix_len) { struct ifreq ifr; struct in6_ifreq ifr6; @@ -313,39 +313,39 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len) /* * parse the new address */ - memset (&sa6, 0, sizeof (struct sockaddr_in6)); + memset(&sa6, 0, sizeof(struct sockaddr_in6)); sa6.sin6_family = AF_INET6; - if (1 != inet_pton (AF_INET6, address, sa6.sin6_addr.s6_addr)) - { - fprintf (stderr, - "Failed to parse IPv6 address `%s': %s\n", - address, - strerror (errno)); - exit (1); - } + if (1 != inet_pton(AF_INET6, address, sa6.sin6_addr.s6_addr)) + { + fprintf(stderr, + "Failed to parse IPv6 address `%s': %s\n", + address, + strerror(errno)); + exit(1); + } - if (-1 == (fd = socket (PF_INET6, SOCK_DGRAM, 0))) - { - fprintf (stderr, - "Error creating IPv6 socket: %s (ignored)\n", - strerror (errno)); - /* ignore error, maybe only IPv4 works on this system! */ - return; - } + if (-1 == (fd = socket(PF_INET6, SOCK_DGRAM, 0))) + { + fprintf(stderr, + "Error creating IPv6 socket: %s (ignored)\n", + strerror(errno)); + /* ignore error, maybe only IPv4 works on this system! */ + return; + } - memset (&ifr, 0, sizeof (struct ifreq)); + memset(&ifr, 0, sizeof(struct ifreq)); /* * Get the index of the if */ - strncpy (ifr.ifr_name, dev, IFNAMSIZ); - if (-1 == ioctl (fd, SIOGIFINDEX, &ifr)) - { - fprintf (stderr, "ioctl failed at %d: %s\n", __LINE__, strerror (errno)); - (void) close (fd); - exit (1); - } + strncpy(ifr.ifr_name, dev, IFNAMSIZ); + if (-1 == ioctl(fd, SIOGIFINDEX, &ifr)) + { + fprintf(stderr, "ioctl failed at %d: %s\n", __LINE__, strerror(errno)); + (void)close(fd); + exit(1); + } - memset (&ifr6, 0, sizeof (struct in6_ifreq)); + memset(&ifr6, 0, sizeof(struct in6_ifreq)); ifr6.ifr6_addr = sa6.sin6_addr; ifr6.ifr6_ifindex = ifr.ifr_ifindex; ifr6.ifr6_prefixlen = prefix_len; @@ -353,42 +353,42 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len) /* * Set the address */ - if (-1 == ioctl (fd, SIOCSIFADDR, &ifr6)) - { - fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, - strerror (errno)); - (void) close (fd); - exit (1); - } + if (-1 == ioctl(fd, SIOCSIFADDR, &ifr6)) + { + fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, + strerror(errno)); + (void)close(fd); + exit(1); + } /* * Get the flags */ - if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr)) - { - fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, - strerror (errno)); - (void) close (fd); - exit (1); - } + if (-1 == ioctl(fd, SIOCGIFFLAGS, &ifr)) + { + fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, + strerror(errno)); + (void)close(fd); + exit(1); + } /* * Add the UP and RUNNING flags */ ifr.ifr_flags |= IFF_UP | IFF_RUNNING; - if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr)) - { - fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, - strerror (errno)); - (void) close (fd); - exit (1); - } + if (-1 == ioctl(fd, SIOCSIFFLAGS, &ifr)) + { + fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, + strerror(errno)); + (void)close(fd); + exit(1); + } - if (0 != close (fd)) - { - fprintf (stderr, "close failed: %s\n", strerror (errno)); - exit (1); - } + if (0 != close(fd)) + { + fprintf(stderr, "close failed: %s\n", strerror(errno)); + exit(1); + } } @@ -400,100 +400,100 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len) * @param mask the netmask */ static void -set_address4 (const char *dev, const char *address, const char *mask) +set_address4(const char *dev, const char *address, const char *mask) { int fd; struct sockaddr_in *addr; struct ifreq ifr; - memset (&ifr, 0, sizeof (struct ifreq)); - addr = (struct sockaddr_in *) &(ifr.ifr_addr); + memset(&ifr, 0, sizeof(struct ifreq)); + addr = (struct sockaddr_in *)&(ifr.ifr_addr); addr->sin_family = AF_INET; /* * Parse the address */ - if (1 != inet_pton (AF_INET, address, &addr->sin_addr.s_addr)) - { - fprintf (stderr, - "Failed to parse IPv4 address `%s': %s\n", - address, - strerror (errno)); - exit (1); - } + if (1 != inet_pton(AF_INET, address, &addr->sin_addr.s_addr)) + { + fprintf(stderr, + "Failed to parse IPv4 address `%s': %s\n", + address, + strerror(errno)); + exit(1); + } - if (-1 == (fd = socket (PF_INET, SOCK_DGRAM, 0))) - { - fprintf (stderr, - "Error creating IPv4 socket: %s\n", - strerror (errno)); - exit (1); - } + if (-1 == (fd = socket(PF_INET, SOCK_DGRAM, 0))) + { + fprintf(stderr, + "Error creating IPv4 socket: %s\n", + strerror(errno)); + exit(1); + } - strncpy (ifr.ifr_name, dev, IFNAMSIZ); + strncpy(ifr.ifr_name, dev, IFNAMSIZ); /* * Set the address */ - if (-1 == ioctl (fd, SIOCSIFADDR, &ifr)) - { - fprintf (stderr, "ioctl failed at %d: %s\n", __LINE__, strerror (errno)); - (void) close (fd); - exit (1); - } + if (-1 == ioctl(fd, SIOCSIFADDR, &ifr)) + { + fprintf(stderr, "ioctl failed at %d: %s\n", __LINE__, strerror(errno)); + (void)close(fd); + exit(1); + } /* * Parse the netmask */ - addr = (struct sockaddr_in *) &(ifr.ifr_netmask); - if (1 != inet_pton (AF_INET, mask, &addr->sin_addr.s_addr)) - { - fprintf (stderr, "Failed to parse address `%s': %s\n", mask, - strerror (errno)); - (void) close (fd); - exit (1); - } + addr = (struct sockaddr_in *)&(ifr.ifr_netmask); + if (1 != inet_pton(AF_INET, mask, &addr->sin_addr.s_addr)) + { + fprintf(stderr, "Failed to parse address `%s': %s\n", mask, + strerror(errno)); + (void)close(fd); + exit(1); + } /* * Set the netmask */ - if (-1 == ioctl (fd, SIOCSIFNETMASK, &ifr)) - { - fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, - strerror (errno)); - (void) close (fd); - exit (1); - } + if (-1 == ioctl(fd, SIOCSIFNETMASK, &ifr)) + { + fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, + strerror(errno)); + (void)close(fd); + exit(1); + } /* * Get the flags */ - if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr)) - { - fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, - strerror (errno)); - (void) close (fd); - exit (1); - } + if (-1 == ioctl(fd, SIOCGIFFLAGS, &ifr)) + { + fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, + strerror(errno)); + (void)close(fd); + exit(1); + } /* * Add the UP and RUNNING flags */ ifr.ifr_flags |= IFF_UP | IFF_RUNNING; - if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr)) - { - fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, - strerror (errno)); - (void) close (fd); - exit (1); - } + if (-1 == ioctl(fd, SIOCSIFFLAGS, &ifr)) + { + fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, + strerror(errno)); + (void)close(fd); + exit(1); + } - if (0 != close (fd)) - { - fprintf (stderr, "close failed: %s\n", strerror (errno)); - (void) close (fd); - exit (1); - } + if (0 != close(fd)) + { + fprintf(stderr, "close failed: %s\n", strerror(errno)); + (void)close(fd); + exit(1); + } } @@ -505,7 +505,7 @@ set_address4 (const char *dev, const char *address, const char *mask) * @param fd_tun tunnel FD */ static void -run (int fd_tun) +run(int fd_tun) { /* * The buffer filled by reading from fd_tun @@ -526,176 +526,176 @@ run (int fd_tun) int max; while (1) - { - FD_ZERO (&fds_w); - FD_ZERO (&fds_r); - - /* - * We are supposed to read and the buffer is empty - * -> select on read from tun - */ - if (0 == buftun_size) - FD_SET (fd_tun, &fds_r); - - /* - * We are supposed to read and the buffer is not empty - * -> select on write to stdout - */ - if (0 < buftun_size) - FD_SET (1, &fds_w); - - /* - * We are supposed to write and the buffer is empty - * -> select on read from stdin - */ - if (NULL == bufin_read) - FD_SET (0, &fds_r); - - /* - * We are supposed to write and the buffer is not empty - * -> select on write to tun - */ - if (NULL != bufin_read) - FD_SET (fd_tun, &fds_w); - - FD_SET (cpipe[0], &fds_r); - max = (fd_tun > cpipe[0]) ? fd_tun : cpipe[0]; - - int r = select (max + 1, &fds_r, &fds_w, NULL, NULL); - - if (-1 == r) - { - if (EINTR == errno) - continue; - fprintf (stderr, "select failed: %s\n", strerror (errno)); - return; - } - - if (r > 0) { - if (FD_ISSET (cpipe[0], &fds_r)) - return; /* aborted by signal */ - - if (FD_ISSET (fd_tun, &fds_r)) - { - buftun_size = - read (fd_tun, buftun + sizeof (struct GNUNET_MessageHeader), - MAX_SIZE - sizeof (struct GNUNET_MessageHeader)); - if (-1 == buftun_size) + FD_ZERO(&fds_w); + FD_ZERO(&fds_r); + + /* + * We are supposed to read and the buffer is empty + * -> select on read from tun + */ + if (0 == buftun_size) + FD_SET(fd_tun, &fds_r); + + /* + * We are supposed to read and the buffer is not empty + * -> select on write to stdout + */ + if (0 < buftun_size) + FD_SET(1, &fds_w); + + /* + * We are supposed to write and the buffer is empty + * -> select on read from stdin + */ + if (NULL == bufin_read) + FD_SET(0, &fds_r); + + /* + * We are supposed to write and the buffer is not empty + * -> select on write to tun + */ + if (NULL != bufin_read) + FD_SET(fd_tun, &fds_w); + + FD_SET(cpipe[0], &fds_r); + max = (fd_tun > cpipe[0]) ? fd_tun : cpipe[0]; + + int r = select(max + 1, &fds_r, &fds_w, NULL, NULL); + + if (-1 == r) { - if ( (errno == EINTR) || - (errno == EAGAIN) ) - { - buftun_size = 0; - continue; - } - fprintf (stderr, "read-error: %s\n", strerror (errno)); - return; - } - if (0 == buftun_size) - { - fprintf (stderr, "EOF on tun\n"); - return; - } - buftun_read = buftun; - { - struct GNUNET_MessageHeader *hdr = - (struct GNUNET_MessageHeader *) buftun; - buftun_size += sizeof (struct GNUNET_MessageHeader); - hdr->type = htons (GNUNET_MESSAGE_TYPE_DNS_HELPER); - hdr->size = htons (buftun_size); - } - } - else if (FD_ISSET (1, &fds_w)) - { - ssize_t written = write (1, buftun_read, buftun_size); - - if (-1 == written) - { - if ( (errno == EINTR) || - (errno == EAGAIN) ) - continue; - fprintf (stderr, "write-error to stdout: %s\n", strerror (errno)); - return; - } - if (0 == written) - { - fprintf (stderr, "write returned 0\n"); + if (EINTR == errno) + continue; + fprintf(stderr, "select failed: %s\n", strerror(errno)); return; } - buftun_size -= written; - buftun_read += written; - } - if (FD_ISSET (0, &fds_r)) - { - bufin_size = read (0, bufin + bufin_rpos, MAX_SIZE - bufin_rpos); - if (-1 == bufin_size) + if (r > 0) { - bufin_read = NULL; - if ( (errno == EINTR) || - (errno == EAGAIN) ) - continue; - fprintf (stderr, "read-error: %s\n", strerror (errno)); - return; - } - if (0 == bufin_size) - { - bufin_read = NULL; - fprintf (stderr, "EOF on stdin\n"); - return; - } - { - struct GNUNET_MessageHeader *hdr; + if (FD_ISSET(cpipe[0], &fds_r)) + return; /* aborted by signal */ + + if (FD_ISSET(fd_tun, &fds_r)) + { + buftun_size = + read(fd_tun, buftun + sizeof(struct GNUNET_MessageHeader), + MAX_SIZE - sizeof(struct GNUNET_MessageHeader)); + if (-1 == buftun_size) + { + if ((errno == EINTR) || + (errno == EAGAIN)) + { + buftun_size = 0; + continue; + } + fprintf(stderr, "read-error: %s\n", strerror(errno)); + return; + } + if (0 == buftun_size) + { + fprintf(stderr, "EOF on tun\n"); + return; + } + buftun_read = buftun; + { + struct GNUNET_MessageHeader *hdr = + (struct GNUNET_MessageHeader *)buftun; + buftun_size += sizeof(struct GNUNET_MessageHeader); + hdr->type = htons(GNUNET_MESSAGE_TYPE_DNS_HELPER); + hdr->size = htons(buftun_size); + } + } + else if (FD_ISSET(1, &fds_w)) + { + ssize_t written = write(1, buftun_read, buftun_size); + + if (-1 == written) + { + if ((errno == EINTR) || + (errno == EAGAIN)) + continue; + fprintf(stderr, "write-error to stdout: %s\n", strerror(errno)); + return; + } + if (0 == written) + { + fprintf(stderr, "write returned 0\n"); + return; + } + buftun_size -= written; + buftun_read += written; + } + + if (FD_ISSET(0, &fds_r)) + { + bufin_size = read(0, bufin + bufin_rpos, MAX_SIZE - bufin_rpos); + if (-1 == bufin_size) + { + bufin_read = NULL; + if ((errno == EINTR) || + (errno == EAGAIN)) + continue; + fprintf(stderr, "read-error: %s\n", strerror(errno)); + return; + } + if (0 == bufin_size) + { + bufin_read = NULL; + fprintf(stderr, "EOF on stdin\n"); + return; + } + { + struct GNUNET_MessageHeader *hdr; PROCESS_BUFFER: - bufin_rpos += bufin_size; - if (bufin_rpos < sizeof (struct GNUNET_MessageHeader)) - continue; - hdr = (struct GNUNET_MessageHeader *) bufin; - if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_DNS_HELPER) - { - fprintf (stderr, "protocol violation!\n"); - return; - } - if (ntohs (hdr->size) > bufin_rpos) - continue; - bufin_read = bufin + sizeof (struct GNUNET_MessageHeader); - bufin_size = ntohs (hdr->size) - sizeof (struct GNUNET_MessageHeader); - bufin_rpos -= bufin_size + sizeof (struct GNUNET_MessageHeader); - } - } - else if (FD_ISSET (fd_tun, &fds_w)) - { - ssize_t written = write (fd_tun, bufin_read, bufin_size); - - if (-1 == written) - { - if ( (errno == EINTR) || - (errno == EAGAIN) ) - continue; - fprintf (stderr, "write-error to tun: %s\n", strerror (errno)); - return; - } - if (0 == written) - { - fprintf (stderr, "write returned 0\n"); - return; + bufin_rpos += bufin_size; + if (bufin_rpos < sizeof(struct GNUNET_MessageHeader)) + continue; + hdr = (struct GNUNET_MessageHeader *)bufin; + if (ntohs(hdr->type) != GNUNET_MESSAGE_TYPE_DNS_HELPER) + { + fprintf(stderr, "protocol violation!\n"); + return; + } + if (ntohs(hdr->size) > bufin_rpos) + continue; + bufin_read = bufin + sizeof(struct GNUNET_MessageHeader); + bufin_size = ntohs(hdr->size) - sizeof(struct GNUNET_MessageHeader); + bufin_rpos -= bufin_size + sizeof(struct GNUNET_MessageHeader); + } + } + else if (FD_ISSET(fd_tun, &fds_w)) + { + ssize_t written = write(fd_tun, bufin_read, bufin_size); + + if (-1 == written) + { + if ((errno == EINTR) || + (errno == EAGAIN)) + continue; + fprintf(stderr, "write-error to tun: %s\n", strerror(errno)); + return; + } + if (0 == written) + { + fprintf(stderr, "write returned 0\n"); + return; + } + { + bufin_size -= written; + bufin_read += written; + if (0 == bufin_size) + { + memmove(bufin, bufin_read, bufin_rpos); + bufin_read = NULL; /* start reading again */ + bufin_size = 0; + goto PROCESS_BUFFER; + } + } + } } - { - bufin_size -= written; - bufin_read += written; - if (0 == bufin_size) - { - memmove (bufin, bufin_read, bufin_rpos); - bufin_read = NULL; /* start reading again */ - bufin_size = 0; - goto PROCESS_BUFFER; - } - } - } } - } } @@ -732,7 +732,7 @@ PROCESS_BUFFER: * 255 failed to handle kill signal properly */ int -main (int argc, char *const*argv) +main(int argc, char *const*argv) { int r; char dev[IFNAMSIZ]; @@ -742,224 +742,224 @@ main (int argc, char *const*argv) int nortsetup = 0; if (7 != argc) - { - fprintf (stderr, "Fatal: must supply 6 arguments!\n"); - return 1; - } + { + fprintf(stderr, "Fatal: must supply 6 arguments!\n"); + return 1; + } /* assert privs so we can modify the firewall rules! */ - uid = getuid (); + uid = getuid(); #ifdef HAVE_SETRESUID - if (0 != setresuid (uid, 0, 0)) - { - fprintf (stderr, "Failed to setresuid to root: %s\n", strerror (errno)); - return 254; - } + if (0 != setresuid(uid, 0, 0)) + { + fprintf(stderr, "Failed to setresuid to root: %s\n", strerror(errno)); + return 254; + } #else - if (0 != seteuid (0)) - { - fprintf (stderr, "Failed to seteuid back to root: %s\n", strerror (errno)); - return 254; - } + if (0 != seteuid(0)) + { + fprintf(stderr, "Failed to seteuid back to root: %s\n", strerror(errno)); + return 254; + } #endif - if (0 == strncmp (argv[6], "1", 2)) + if (0 == strncmp(argv[6], "1", 2)) nortsetup = 1; if (0 == nortsetup) - { - /* verify that the binaries we care about are executable */ + { + /* verify that the binaries we care about are executable */ #ifdef IPTABLES - if (0 == access (IPTABLES, X_OK)) - sbin_iptables = IPTABLES; - else + if (0 == access(IPTABLES, X_OK)) + sbin_iptables = IPTABLES; + else #endif - if (0 == access ("/sbin/iptables", X_OK)) - sbin_iptables = "/sbin/iptables"; - else if (0 == access ("/usr/sbin/iptables", X_OK)) - sbin_iptables = "/usr/sbin/iptables"; - else - { - fprintf (stderr, - "Fatal: executable iptables not found in approved directories: %s\n", - strerror (errno)); - return 3; - } + if (0 == access("/sbin/iptables", X_OK)) + sbin_iptables = "/sbin/iptables"; + else if (0 == access("/usr/sbin/iptables", X_OK)) + sbin_iptables = "/usr/sbin/iptables"; + else + { + fprintf(stderr, + "Fatal: executable iptables not found in approved directories: %s\n", + strerror(errno)); + return 3; + } #ifdef IP6TABLES - if (0 == access (IP6TABLES, X_OK)) - sbin_ip6tables = IP6TABLES; - else + if (0 == access(IP6TABLES, X_OK)) + sbin_ip6tables = IP6TABLES; + else #endif - if (0 == access ("/sbin/ip6tables", X_OK)) - sbin_ip6tables = "/sbin/ip6tables"; - else if (0 == access ("/usr/sbin/ip6tables", X_OK)) - sbin_ip6tables = "/usr/sbin/ip6tables"; - else - { - fprintf (stderr, - "Fatal: executable ip6tables not found in approved directories: %s\n", - strerror (errno)); - return 3; - } + if (0 == access("/sbin/ip6tables", X_OK)) + sbin_ip6tables = "/sbin/ip6tables"; + else if (0 == access("/usr/sbin/ip6tables", X_OK)) + sbin_ip6tables = "/usr/sbin/ip6tables"; + else + { + fprintf(stderr, + "Fatal: executable ip6tables not found in approved directories: %s\n", + strerror(errno)); + return 3; + } #ifdef PATH_TO_IP - if (0 == access (PATH_TO_IP, X_OK)) - sbin_ip = PATH_TO_IP; - else + if (0 == access(PATH_TO_IP, X_OK)) + sbin_ip = PATH_TO_IP; + else #endif - if (0 == access ("/sbin/ip", X_OK)) - sbin_ip = "/sbin/ip"; - else if (0 == access ("/usr/sbin/ip", X_OK)) - sbin_ip = "/usr/sbin/ip"; - else if (0 == access ("/bin/ip", X_OK)) /* gentoo has it there */ - sbin_ip = "/bin/ip"; - else - { - fprintf (stderr, - "Fatal: executable ip not found in approved directories: %s\n", - strerror (errno)); - return 4; - } + if (0 == access("/sbin/ip", X_OK)) + sbin_ip = "/sbin/ip"; + else if (0 == access("/usr/sbin/ip", X_OK)) + sbin_ip = "/usr/sbin/ip"; + else if (0 == access("/bin/ip", X_OK)) /* gentoo has it there */ + sbin_ip = "/bin/ip"; + else + { + fprintf(stderr, + "Fatal: executable ip not found in approved directories: %s\n", + strerror(errno)); + return 4; + } #ifdef SYSCTL - if (0 == access (SYSCTL, X_OK)) - sbin_sysctl = SYSCTL; - else + if (0 == access(SYSCTL, X_OK)) + sbin_sysctl = SYSCTL; + else #endif - if (0 == access ("/sbin/sysctl", X_OK)) - sbin_sysctl = "/sbin/sysctl"; - else if (0 == access ("/usr/sbin/sysctl", X_OK)) - sbin_sysctl = "/usr/sbin/sysctl"; - else - { - fprintf (stderr, - "Fatal: executable sysctl not found in approved directories: %s\n", - strerror (errno)); - return 5; + if (0 == access("/sbin/sysctl", X_OK)) + sbin_sysctl = "/sbin/sysctl"; + else if (0 == access("/usr/sbin/sysctl", X_OK)) + sbin_sysctl = "/usr/sbin/sysctl"; + else + { + fprintf(stderr, + "Fatal: executable sysctl not found in approved directories: %s\n", + strerror(errno)); + return 5; + } } - } /* setup 'mygid' string */ - snprintf (mygid, sizeof (mygid), "%d", (int) getegid()); + snprintf(mygid, sizeof(mygid), "%d", (int)getegid()); /* do not die on SIGPIPE */ - if (SIG_ERR == signal (SIGPIPE, SIG_IGN)) - { - fprintf (stderr, "Failed to protect against SIGPIPE: %s\n", - strerror (errno)); - return 7; - } + if (SIG_ERR == signal(SIGPIPE, SIG_IGN)) + { + fprintf(stderr, "Failed to protect against SIGPIPE: %s\n", + strerror(errno)); + return 7; + } /* setup pipe to shutdown nicely on SIGINT */ - if (0 != pipe (cpipe)) - { - fprintf (stderr, - "Fatal: could not setup control pipe: %s\n", - strerror (errno)); - return 6; - } - if (cpipe[0] >= FD_SETSIZE) - { - fprintf (stderr, "Pipe file descriptor to large: %d", cpipe[0]); - (void) close (cpipe[0]); - (void) close (cpipe[1]); - return 6; - } - { - /* make pipe non-blocking, as we theoretically could otherwise block - in the signal handler */ - int flags = fcntl (cpipe[1], F_GETFL); - if (-1 == flags) + if (0 != pipe(cpipe)) { - fprintf (stderr, "Failed to read flags for pipe: %s", strerror (errno)); - (void) close (cpipe[0]); - (void) close (cpipe[1]); + fprintf(stderr, + "Fatal: could not setup control pipe: %s\n", + strerror(errno)); return 6; } - flags |= O_NONBLOCK; - if (0 != fcntl (cpipe[1], F_SETFL, flags)) + if (cpipe[0] >= FD_SETSIZE) { - fprintf (stderr, "Failed to make pipe non-blocking: %s", strerror (errno)); - (void) close (cpipe[0]); - (void) close (cpipe[1]); + fprintf(stderr, "Pipe file descriptor to large: %d", cpipe[0]); + (void)close(cpipe[0]); + (void)close(cpipe[1]); return 6; } + { + /* make pipe non-blocking, as we theoretically could otherwise block + in the signal handler */ + int flags = fcntl(cpipe[1], F_GETFL); + if (-1 == flags) + { + fprintf(stderr, "Failed to read flags for pipe: %s", strerror(errno)); + (void)close(cpipe[0]); + (void)close(cpipe[1]); + return 6; + } + flags |= O_NONBLOCK; + if (0 != fcntl(cpipe[1], F_SETFL, flags)) + { + fprintf(stderr, "Failed to make pipe non-blocking: %s", strerror(errno)); + (void)close(cpipe[0]); + (void)close(cpipe[1]); + return 6; + } } - if ( (SIG_ERR == signal (SIGTERM, &signal_handler)) || + if ((SIG_ERR == signal(SIGTERM, &signal_handler)) || #if (SIGTERM != GNUNET_TERM_SIG) - (SIG_ERR == signal (GNUNET_TERM_SIG, &signal_handler)) || + (SIG_ERR == signal(GNUNET_TERM_SIG, &signal_handler)) || #endif - (SIG_ERR == signal (SIGINT, &signal_handler)) || - (SIG_ERR == signal (SIGHUP, &signal_handler)) ) - { - fprintf (stderr, - "Fatal: could not initialize signal handler: %s\n", - strerror (errno)); - (void) close (cpipe[0]); - (void) close (cpipe[1]); - return 7; - } + (SIG_ERR == signal(SIGINT, &signal_handler)) || + (SIG_ERR == signal(SIGHUP, &signal_handler))) + { + fprintf(stderr, + "Fatal: could not initialize signal handler: %s\n", + strerror(errno)); + (void)close(cpipe[0]); + (void)close(cpipe[1]); + return 7; + } /* get interface name */ - strncpy (dev, argv[1], IFNAMSIZ); + strncpy(dev, argv[1], IFNAMSIZ); dev[IFNAMSIZ - 1] = '\0'; /* Disable rp filtering */ if (0 == nortsetup) - { - char *const sysctl_args[] = {"sysctl", "-w", - "net.ipv4.conf.all.rp_filter=0", NULL}; - char *const sysctl_args2[] = {"sysctl", "-w", - "net.ipv4.conf.default.rp_filter=0", NULL}; - if ((0 != fork_and_exec (sbin_sysctl, sysctl_args)) || - (0 != fork_and_exec (sbin_sysctl, sysctl_args2))) { - fprintf (stderr, - "Failed to disable rp filtering.\n"); - return 5; + char *const sysctl_args[] = { "sysctl", "-w", + "net.ipv4.conf.all.rp_filter=0", NULL }; + char *const sysctl_args2[] = { "sysctl", "-w", + "net.ipv4.conf.default.rp_filter=0", NULL }; + if ((0 != fork_and_exec(sbin_sysctl, sysctl_args)) || + (0 != fork_and_exec(sbin_sysctl, sysctl_args2))) + { + fprintf(stderr, + "Failed to disable rp filtering.\n"); + return 5; + } } - } /* now open virtual interface (first part that requires root) */ - if (-1 == (fd_tun = init_tun (dev))) - { - fprintf (stderr, "Fatal: could not initialize tun-interface\n"); - (void) signal (SIGTERM, SIG_IGN); + if (-1 == (fd_tun = init_tun(dev))) + { + fprintf(stderr, "Fatal: could not initialize tun-interface\n"); + (void)signal(SIGTERM, SIG_IGN); #if (SIGTERM != GNUNET_TERM_SIG) - (void) signal (GNUNET_TERM_SIG, SIG_IGN); + (void)signal(GNUNET_TERM_SIG, SIG_IGN); #endif - (void) signal (SIGINT, SIG_IGN); - (void) signal (SIGHUP, SIG_IGN); - (void) close (cpipe[0]); - (void) close (cpipe[1]); - return 5; - } + (void)signal(SIGINT, SIG_IGN); + (void)signal(SIGHUP, SIG_IGN); + (void)close(cpipe[0]); + (void)close(cpipe[1]); + return 5; + } /* now set interface addresses */ { const char *address = argv[2]; - long prefix_len = atol (argv[3]); + long prefix_len = atol(argv[3]); if ((prefix_len < 1) || (prefix_len > 127)) - { - fprintf (stderr, "Fatal: prefix_len out of range\n"); - (void) signal (SIGTERM, SIG_IGN); + { + fprintf(stderr, "Fatal: prefix_len out of range\n"); + (void)signal(SIGTERM, SIG_IGN); #if (SIGTERM != GNUNET_TERM_SIG) - (void) signal (GNUNET_TERM_SIG, SIG_IGN); + (void)signal(GNUNET_TERM_SIG, SIG_IGN); #endif - (void) signal (SIGINT, SIG_IGN); - (void) signal (SIGHUP, SIG_IGN); - (void) close (cpipe[0]); - (void) close (cpipe[1]); - return 2; - } - set_address6 (dev, address, prefix_len); + (void)signal(SIGINT, SIG_IGN); + (void)signal(SIGHUP, SIG_IGN); + (void)close(cpipe[0]); + (void)close(cpipe[1]); + return 2; + } + set_address6(dev, address, prefix_len); } { const char *address = argv[4]; const char *mask = argv[5]; - set_address4 (dev, address, mask); + set_address4(dev, address, mask); } @@ -968,237 +968,237 @@ main (int argc, char *const*argv) by the 'gnunet-service-dns') and with destination to port 53 on UDP, without hijacking */ if (0 == nortsetup) - { - r = 8; /* failed to fully setup routing table */ { - char *const mangle_args[] = + r = 8; /* failed to fully setup routing table */ + { + char *const mangle_args[] = { - "iptables", "-m", "owner", "-t", "mangle", "-I", "OUTPUT", "1", "-p", - "udp", "--gid-owner", mygid, "--dport", DNS_PORT, "-j", - "ACCEPT", NULL + "iptables", "-m", "owner", "-t", "mangle", "-I", "OUTPUT", "1", "-p", + "udp", "--gid-owner", mygid, "--dport", DNS_PORT, "-j", + "ACCEPT", NULL }; - if (0 != fork_and_exec (sbin_iptables, mangle_args)) - goto cleanup_rest; - } - { - char *const mangle_args[] = + if (0 != fork_and_exec(sbin_iptables, mangle_args)) + goto cleanup_rest; + } + { + char *const mangle_args[] = { - "ip6tables", "-m", "owner", "-t", "mangle", "-I", "OUTPUT", "1", "-p", - "udp", "--gid-owner", mygid, "--dport", DNS_PORT, "-j", - "ACCEPT", NULL + "ip6tables", "-m", "owner", "-t", "mangle", "-I", "OUTPUT", "1", "-p", + "udp", "--gid-owner", mygid, "--dport", DNS_PORT, "-j", + "ACCEPT", NULL }; - if (0 != fork_and_exec (sbin_ip6tables, mangle_args)) - goto cleanup_mangle_1b; - } - /* Mark all of the other DNS traffic using our mark DNS_MARK, - unless it is on a link-local IPv6 address, which we cannot support. */ - { - char *const mark_args[] = + if (0 != fork_and_exec(sbin_ip6tables, mangle_args)) + goto cleanup_mangle_1b; + } + /* Mark all of the other DNS traffic using our mark DNS_MARK, + unless it is on a link-local IPv6 address, which we cannot support. */ + { + char *const mark_args[] = { - "iptables", "-t", "mangle", "-I", "OUTPUT", "2", "-p", - "udp", "--dport", DNS_PORT, - "-j", "MARK", "--set-mark", DNS_MARK, - NULL + "iptables", "-t", "mangle", "-I", "OUTPUT", "2", "-p", + "udp", "--dport", DNS_PORT, + "-j", "MARK", "--set-mark", DNS_MARK, + NULL }; - if (0 != fork_and_exec (sbin_iptables, mark_args)) - goto cleanup_mangle_1; - } - { - char *const mark_args[] = + if (0 != fork_and_exec(sbin_iptables, mark_args)) + goto cleanup_mangle_1; + } + { + char *const mark_args[] = { - "ip6tables", "-t", "mangle", "-I", "OUTPUT", "2", "-p", - "udp", "--dport", DNS_PORT, - "!", "-s", "fe80::/10", /* this line excludes link-local traffic */ - "-j", "MARK", "--set-mark", DNS_MARK, - NULL + "ip6tables", "-t", "mangle", "-I", "OUTPUT", "2", "-p", + "udp", "--dport", DNS_PORT, + "!", "-s", "fe80::/10", /* this line excludes link-local traffic */ + "-j", "MARK", "--set-mark", DNS_MARK, + NULL }; - if (0 != fork_and_exec (sbin_ip6tables, mark_args)) - goto cleanup_mark_2b; - } - /* Forward all marked DNS traffic to our DNS_TABLE */ - { - char *const forward_args[] = + if (0 != fork_and_exec(sbin_ip6tables, mark_args)) + goto cleanup_mark_2b; + } + /* Forward all marked DNS traffic to our DNS_TABLE */ + { + char *const forward_args[] = { - "ip", "rule", "add", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL + "ip", "rule", "add", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL }; - if (0 != fork_and_exec (sbin_ip, forward_args)) - goto cleanup_mark_2; - } - { - char *const forward_args[] = + if (0 != fork_and_exec(sbin_ip, forward_args)) + goto cleanup_mark_2; + } + { + char *const forward_args[] = { "ip", "-6", "rule", "add", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL }; - if (0 != fork_and_exec (sbin_ip, forward_args)) - goto cleanup_forward_3b; - } - /* Finally, add rule in our forwarding table to pass to our virtual interface */ - { - char *const route_args[] = + if (0 != fork_and_exec(sbin_ip, forward_args)) + goto cleanup_forward_3b; + } + /* Finally, add rule in our forwarding table to pass to our virtual interface */ + { + char *const route_args[] = { - "ip", "route", "add", "default", "dev", dev, - "table", DNS_TABLE, NULL + "ip", "route", "add", "default", "dev", dev, + "table", DNS_TABLE, NULL }; - if (0 != fork_and_exec (sbin_ip, route_args)) - goto cleanup_forward_3; - } - { - char *const route_args[] = + if (0 != fork_and_exec(sbin_ip, route_args)) + goto cleanup_forward_3; + } + { + char *const route_args[] = { "ip", "-6", "route", "add", "default", "dev", dev, "table", DNS_TABLE, NULL }; - if (0 != fork_and_exec (sbin_ip, route_args)) - goto cleanup_route_4b; + if (0 != fork_and_exec(sbin_ip, route_args)) + goto cleanup_route_4b; + } } - } /* drop privs *except* for the saved UID; this is not perfect, but better than doing nothing */ #ifdef HAVE_SETRESUID - if (0 != setresuid (uid, uid, 0)) - { - fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); - r = 24; - goto cleanup_route_4; - } + if (0 != setresuid(uid, uid, 0)) + { + fprintf(stderr, "Failed to setresuid: %s\n", strerror(errno)); + r = 24; + goto cleanup_route_4; + } #else /* Note: no 'setuid' here as we must keep our saved UID as root */ - if (0 != seteuid (uid)) - { - fprintf (stderr, "Failed to seteuid: %s\n", strerror (errno)); - r = 24; - goto cleanup_route_4; - } + if (0 != seteuid(uid)) + { + fprintf(stderr, "Failed to seteuid: %s\n", strerror(errno)); + r = 24; + goto cleanup_route_4; + } #endif r = 0; /* did fully setup routing table (if nothing else happens, we were successful!) */ /* now forward until we hit a problem */ - run (fd_tun); + run(fd_tun); /* now need to regain privs so we can remove the firewall rules we added! */ #ifdef HAVE_SETRESUID - if (0 != setresuid (uid, 0, 0)) - { - fprintf (stderr, "Failed to setresuid back to root: %s\n", strerror (errno)); - r = 40; - goto cleanup_route_4; - } + if (0 != setresuid(uid, 0, 0)) + { + fprintf(stderr, "Failed to setresuid back to root: %s\n", strerror(errno)); + r = 40; + goto cleanup_route_4; + } #else - if (0 != seteuid (0)) - { - fprintf (stderr, "Failed to seteuid back to root: %s\n", strerror (errno)); - r = 40; - goto cleanup_route_4; - } + if (0 != seteuid(0)) + { + fprintf(stderr, "Failed to seteuid back to root: %s\n", strerror(errno)); + r = 40; + goto cleanup_route_4; + } #endif /* update routing tables again -- this is why we could not fully drop privs */ /* now undo updating of routing tables; normal exit or clean-up-on-error case */ - cleanup_route_4: +cleanup_route_4: if (0 == nortsetup) - { - char *const route_clean_args[] = + { + char *const route_clean_args[] = { - "ip", "-6", "route", "del", "default", "dev", dev, - "table", DNS_TABLE, NULL + "ip", "-6", "route", "del", "default", "dev", dev, + "table", DNS_TABLE, NULL }; - if (0 != fork_and_exec (sbin_ip, route_clean_args)) - r += 1; - } - cleanup_route_4b: + if (0 != fork_and_exec(sbin_ip, route_clean_args)) + r += 1; + } +cleanup_route_4b: if (0 == nortsetup) - { - char *const route_clean_args[] = + { + char *const route_clean_args[] = { - "ip", "route", "del", "default", "dev", dev, - "table", DNS_TABLE, NULL + "ip", "route", "del", "default", "dev", dev, + "table", DNS_TABLE, NULL }; - if (0 != fork_and_exec (sbin_ip, route_clean_args)) - r += 1; - } - cleanup_forward_3: + if (0 != fork_and_exec(sbin_ip, route_clean_args)) + r += 1; + } +cleanup_forward_3: if (0 == nortsetup) - { - char *const forward_clean_args[] = + { + char *const forward_clean_args[] = { - "ip", "-6", "rule", "del", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL + "ip", "-6", "rule", "del", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL }; - if (0 != fork_and_exec (sbin_ip, forward_clean_args)) - r += 2; - } - cleanup_forward_3b: + if (0 != fork_and_exec(sbin_ip, forward_clean_args)) + r += 2; + } +cleanup_forward_3b: if (0 == nortsetup) - { - char *const forward_clean_args[] = + { + char *const forward_clean_args[] = { - "ip", "rule", "del", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL + "ip", "rule", "del", "fwmark", DNS_MARK, "table", DNS_TABLE, NULL }; - if (0 != fork_and_exec (sbin_ip, forward_clean_args)) - r += 2; - } - cleanup_mark_2: + if (0 != fork_and_exec(sbin_ip, forward_clean_args)) + r += 2; + } +cleanup_mark_2: if (0 == nortsetup) - { - char *const mark_clean_args[] = + { + char *const mark_clean_args[] = { - "ip6tables", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", - "--dport", DNS_PORT, + "ip6tables", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", + "--dport", DNS_PORT, "!", "-s", "fe80::/10", /* this line excludes link-local traffic */ "-j", "MARK", "--set-mark", DNS_MARK, NULL }; - if (0 != fork_and_exec (sbin_ip6tables, mark_clean_args)) - r += 4; - } - cleanup_mark_2b: + if (0 != fork_and_exec(sbin_ip6tables, mark_clean_args)) + r += 4; + } +cleanup_mark_2b: if (0 == nortsetup) - { - char *const mark_clean_args[] = + { + char *const mark_clean_args[] = { - "iptables", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", - "--dport", DNS_PORT, "-j", "MARK", "--set-mark", DNS_MARK, NULL + "iptables", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", + "--dport", DNS_PORT, "-j", "MARK", "--set-mark", DNS_MARK, NULL }; - if (0 != fork_and_exec (sbin_iptables, mark_clean_args)) - r += 4; - } - cleanup_mangle_1: + if (0 != fork_and_exec(sbin_iptables, mark_clean_args)) + r += 4; + } +cleanup_mangle_1: if (0 == nortsetup) - { - char *const mangle_clean_args[] = + { + char *const mangle_clean_args[] = { - "ip6tables", "-m", "owner", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", - "--gid-owner", mygid, "--dport", DNS_PORT, "-j", "ACCEPT", - NULL + "ip6tables", "-m", "owner", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", + "--gid-owner", mygid, "--dport", DNS_PORT, "-j", "ACCEPT", + NULL }; - if (0 != fork_and_exec (sbin_ip6tables, mangle_clean_args)) - r += 8; - } - cleanup_mangle_1b: + if (0 != fork_and_exec(sbin_ip6tables, mangle_clean_args)) + r += 8; + } +cleanup_mangle_1b: if (0 == nortsetup) - { - char *const mangle_clean_args[] = + { + char *const mangle_clean_args[] = { - "iptables", "-m", "owner", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", - "--gid-owner", mygid, "--dport", DNS_PORT, "-j", "ACCEPT", - NULL + "iptables", "-m", "owner", "-t", "mangle", "-D", "OUTPUT", "-p", "udp", + "--gid-owner", mygid, "--dport", DNS_PORT, "-j", "ACCEPT", + NULL }; - if (0 != fork_and_exec (sbin_iptables, mangle_clean_args)) - r += 8; - } + if (0 != fork_and_exec(sbin_iptables, mangle_clean_args)) + r += 8; + } - cleanup_rest: +cleanup_rest: /* close virtual interface */ - (void) close (fd_tun); + (void)close(fd_tun); /* remove signal handler so we can close the pipes */ - (void) signal (SIGTERM, SIG_IGN); + (void)signal(SIGTERM, SIG_IGN); #if (SIGTERM != GNUNET_TERM_SIG) - (void) signal (GNUNET_TERM_SIG, SIG_IGN); + (void)signal(GNUNET_TERM_SIG, SIG_IGN); #endif - (void) signal (SIGINT, SIG_IGN); - (void) signal (SIGHUP, SIG_IGN); - (void) close (cpipe[0]); - (void) close (cpipe[1]); + (void)signal(SIGINT, SIG_IGN); + (void)signal(SIGHUP, SIG_IGN); + (void)close(cpipe[0]); + (void)close(cpipe[1]); return r; } diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c index 9c4f1f490..9a2293b2d 100644 --- a/src/dns/gnunet-service-dns.c +++ b/src/dns/gnunet-service-dns.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file dns/gnunet-service-dns.c @@ -59,14 +59,13 @@ * Generic logging shorthand */ #define LOG(kind, ...) \ - GNUNET_log_from (kind, "dns", __VA_ARGS__); + GNUNET_log_from(kind, "dns", __VA_ARGS__); /** * Phases each request goes through. */ -enum RequestPhase -{ +enum RequestPhase { /** * Request has just been received. */ @@ -112,16 +111,15 @@ enum RequestPhase /** * Entry we keep for each client. */ -struct ClientRecord -{ +struct ClientRecord { /** * Kept in doubly-linked list. */ struct ClientRecord *next; - /** + /** * Kept in doubly-linked list. - */ + */ struct ClientRecord *prev; /** @@ -138,16 +136,13 @@ struct ClientRecord * Flags for the client. */ enum GNUNET_DNS_Flags flags; - }; /** * Entry we keep for each active request. */ -struct RequestRecord -{ - +struct RequestRecord { /** * List of clients that still need to see this request (each entry * is set to NULL when the client is done). @@ -197,7 +192,6 @@ struct RequestRecord * In which phase this this request? */ enum RequestPhase phase; - }; @@ -258,14 +252,14 @@ static struct GNUNET_DNSSTUB_Context *dnsstub; * @param rr request to clean up */ static void -cleanup_rr (struct RequestRecord *rr) +cleanup_rr(struct RequestRecord *rr) { - GNUNET_free_non_null (rr->payload); + GNUNET_free_non_null(rr->payload); rr->payload = NULL; rr->payload_length = 0; - GNUNET_array_grow (rr->client_wait_list, - rr->client_wait_list_length, - 0); + GNUNET_array_grow(rr->client_wait_list, + rr->client_wait_list_length, + 0); } @@ -275,28 +269,28 @@ cleanup_rr (struct RequestRecord *rr) * @param cls unused */ static void -cleanup_task (void *cls GNUNET_UNUSED) +cleanup_task(void *cls GNUNET_UNUSED) { if (NULL != hijacker) - { - GNUNET_HELPER_stop (hijacker, GNUNET_NO); - hijacker = NULL; - } - for (unsigned int i=0;i<8;i++) - GNUNET_free_non_null (helper_argv[i]); - for (unsigned int i=0;i<=UINT16_MAX;i++) - cleanup_rr (&requests[i]); + { + GNUNET_HELPER_stop(hijacker, GNUNET_NO); + hijacker = NULL; + } + for (unsigned int i = 0; i < 8; i++) + GNUNET_free_non_null(helper_argv[i]); + for (unsigned int i = 0; i <= UINT16_MAX; i++) + cleanup_rr(&requests[i]); if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, - GNUNET_NO); - stats = NULL; - } + { + GNUNET_STATISTICS_destroy(stats, + GNUNET_NO); + stats = NULL; + } if (NULL != dnsstub) - { - GNUNET_DNSSTUB_stop (dnsstub); - dnsstub = NULL; - } + { + GNUNET_DNSSTUB_stop(dnsstub); + dnsstub = NULL; + } } @@ -306,54 +300,56 @@ cleanup_task (void *cls GNUNET_UNUSED) * @param rr request send to the network or just clean up. */ static void -request_done (struct RequestRecord *rr) +request_done(struct RequestRecord *rr) { struct GNUNET_MessageHeader *hdr; size_t reply_len; uint16_t source_port; uint16_t destination_port; - GNUNET_array_grow (rr->client_wait_list, - rr->client_wait_list_length, - 0); + GNUNET_array_grow(rr->client_wait_list, + rr->client_wait_list_length, + 0); if (RP_RESPONSE_MONITOR != rr->phase) - { - /* no response, drop */ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Got no response for request %llu, dropping\n", - (unsigned long long) rr->request_id); - cleanup_rr (rr); - return; - } + { + /* no response, drop */ + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Got no response for request %llu, dropping\n", + (unsigned long long)rr->request_id); + cleanup_rr(rr); + return; + } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transmitting response for request %llu\n", - (unsigned long long) rr->request_id); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Transmitting response for request %llu\n", + (unsigned long long)rr->request_id); /* send response via hijacker */ - reply_len = sizeof (struct GNUNET_MessageHeader); - reply_len += sizeof (struct GNUNET_TUN_Layer2PacketHeader); + reply_len = sizeof(struct GNUNET_MessageHeader); + reply_len += sizeof(struct GNUNET_TUN_Layer2PacketHeader); switch (rr->src_addr.ss_family) - { - case AF_INET: - reply_len += sizeof (struct GNUNET_TUN_IPv4Header); - break; - case AF_INET6: - reply_len += sizeof (struct GNUNET_TUN_IPv6Header); - break; - default: - GNUNET_break (0); - cleanup_rr (rr); - return; - } - reply_len += sizeof (struct GNUNET_TUN_UdpHeader); + { + case AF_INET: + reply_len += sizeof(struct GNUNET_TUN_IPv4Header); + break; + + case AF_INET6: + reply_len += sizeof(struct GNUNET_TUN_IPv6Header); + break; + + default: + GNUNET_break(0); + cleanup_rr(rr); + return; + } + reply_len += sizeof(struct GNUNET_TUN_UdpHeader); reply_len += rr->payload_length; if (reply_len >= GNUNET_MAX_MESSAGE_SIZE) - { - /* response too big, drop */ - GNUNET_break (0); /* how can this be? */ - cleanup_rr(rr); - return; - } + { + /* response too big, drop */ + GNUNET_break(0); /* how can this be? */ + cleanup_rr(rr); + return; + } { char buf[reply_len] GNUNET_ALIGN; size_t off; @@ -361,68 +357,70 @@ request_done (struct RequestRecord *rr) struct GNUNET_TUN_IPv6Header ip6; /* first, GNUnet message header */ - hdr = (struct GNUNET_MessageHeader*) buf; - hdr->type = htons (GNUNET_MESSAGE_TYPE_DNS_HELPER); - hdr->size = htons ((uint16_t) reply_len); - off = sizeof (struct GNUNET_MessageHeader); + hdr = (struct GNUNET_MessageHeader*)buf; + hdr->type = htons(GNUNET_MESSAGE_TYPE_DNS_HELPER); + hdr->size = htons((uint16_t)reply_len); + off = sizeof(struct GNUNET_MessageHeader); /* first, TUN header */ { struct GNUNET_TUN_Layer2PacketHeader tun; - tun.flags = htons (0); + tun.flags = htons(0); if (rr->src_addr.ss_family == AF_INET) - tun.proto = htons (ETH_P_IPV4); + tun.proto = htons(ETH_P_IPV4); else - tun.proto = htons (ETH_P_IPV6); - GNUNET_memcpy (&buf[off], - &tun, - sizeof (struct GNUNET_TUN_Layer2PacketHeader)); - off += sizeof (struct GNUNET_TUN_Layer2PacketHeader); + tun.proto = htons(ETH_P_IPV6); + GNUNET_memcpy(&buf[off], + &tun, + sizeof(struct GNUNET_TUN_Layer2PacketHeader)); + off += sizeof(struct GNUNET_TUN_Layer2PacketHeader); } /* now IP header */ switch (rr->src_addr.ss_family) - { - case AF_INET: { - struct sockaddr_in *src = (struct sockaddr_in *) &rr->src_addr; - struct sockaddr_in *dst = (struct sockaddr_in *) &rr->dst_addr; - - source_port = dst->sin_port; - destination_port = src->sin_port; - GNUNET_TUN_initialize_ipv4_header (&ip4, - IPPROTO_UDP, - reply_len - off - sizeof (struct GNUNET_TUN_IPv4Header), - &dst->sin_addr, - &src->sin_addr); - GNUNET_memcpy (&buf[off], - &ip4, - sizeof (ip4)); - off += sizeof (ip4); + case AF_INET: + { + struct sockaddr_in *src = (struct sockaddr_in *)&rr->src_addr; + struct sockaddr_in *dst = (struct sockaddr_in *)&rr->dst_addr; + + source_port = dst->sin_port; + destination_port = src->sin_port; + GNUNET_TUN_initialize_ipv4_header(&ip4, + IPPROTO_UDP, + reply_len - off - sizeof(struct GNUNET_TUN_IPv4Header), + &dst->sin_addr, + &src->sin_addr); + GNUNET_memcpy(&buf[off], + &ip4, + sizeof(ip4)); + off += sizeof(ip4); } break; - case AF_INET6: + + case AF_INET6: { - struct sockaddr_in6 *src = (struct sockaddr_in6 *) &rr->src_addr; - struct sockaddr_in6 *dst = (struct sockaddr_in6 *) &rr->dst_addr; - - source_port = dst->sin6_port; - destination_port = src->sin6_port; - GNUNET_TUN_initialize_ipv6_header (&ip6, - IPPROTO_UDP, - reply_len - off - sizeof (struct GNUNET_TUN_IPv6Header), - &dst->sin6_addr, - &src->sin6_addr); - GNUNET_memcpy (&buf[off], - &ip6, - sizeof (ip6)); - off += sizeof (ip6); + struct sockaddr_in6 *src = (struct sockaddr_in6 *)&rr->src_addr; + struct sockaddr_in6 *dst = (struct sockaddr_in6 *)&rr->dst_addr; + + source_port = dst->sin6_port; + destination_port = src->sin6_port; + GNUNET_TUN_initialize_ipv6_header(&ip6, + IPPROTO_UDP, + reply_len - off - sizeof(struct GNUNET_TUN_IPv6Header), + &dst->sin6_addr, + &src->sin6_addr); + GNUNET_memcpy(&buf[off], + &ip6, + sizeof(ip6)); + off += sizeof(ip6); } break; - default: - GNUNET_assert (0); - } + + default: + GNUNET_assert(0); + } /* now UDP header */ { @@ -430,40 +428,40 @@ request_done (struct RequestRecord *rr) udp.source_port = source_port; udp.destination_port = destination_port; - udp.len = htons (reply_len - off); + udp.len = htons(reply_len - off); if (AF_INET == rr->src_addr.ss_family) - GNUNET_TUN_calculate_udp4_checksum (&ip4, - &udp, - rr->payload, - rr->payload_length); + GNUNET_TUN_calculate_udp4_checksum(&ip4, + &udp, + rr->payload, + rr->payload_length); else - GNUNET_TUN_calculate_udp6_checksum (&ip6, - &udp, - rr->payload, - rr->payload_length); - GNUNET_memcpy (&buf[off], - &udp, - sizeof (udp)); - off += sizeof (udp); + GNUNET_TUN_calculate_udp6_checksum(&ip6, + &udp, + rr->payload, + rr->payload_length); + GNUNET_memcpy(&buf[off], + &udp, + sizeof(udp)); + off += sizeof(udp); } /* now DNS payload */ { - GNUNET_memcpy (&buf[off], rr->payload, rr->payload_length); + GNUNET_memcpy(&buf[off], rr->payload, rr->payload_length); off += rr->payload_length; } /* final checks & sending */ - GNUNET_assert (off == reply_len); - (void) GNUNET_HELPER_send (hijacker, - hdr, - GNUNET_YES, - NULL, NULL); - GNUNET_STATISTICS_update (stats, - gettext_noop ("# DNS requests answered via TUN interface"), - 1, GNUNET_NO); + GNUNET_assert(off == reply_len); + (void)GNUNET_HELPER_send(hijacker, + hdr, + GNUNET_YES, + NULL, NULL); + GNUNET_STATISTICS_update(stats, + gettext_noop("# DNS requests answered via TUN interface"), + 1, GNUNET_NO); } /* clean up, we're done */ - cleanup_rr (rr); + cleanup_rr(rr); } @@ -475,31 +473,31 @@ request_done (struct RequestRecord *rr) * @param cr client to send the response to */ static void -send_request_to_client (struct RequestRecord *rr, - struct ClientRecord *cr) +send_request_to_client(struct RequestRecord *rr, + struct ClientRecord *cr) { struct GNUNET_MQ_Envelope *env; struct GNUNET_DNS_Request *req; - if (sizeof (struct GNUNET_DNS_Request) + rr->payload_length >= GNUNET_MAX_MESSAGE_SIZE) - { - GNUNET_break (0); - cleanup_rr (rr); - return; - } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Sending information about request %llu to local client\n", - (unsigned long long) rr->request_id); - env = GNUNET_MQ_msg_extra (req, - rr->payload_length, - GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST); - req->reserved = htonl (0); + if (sizeof(struct GNUNET_DNS_Request) + rr->payload_length >= GNUNET_MAX_MESSAGE_SIZE) + { + GNUNET_break(0); + cleanup_rr(rr); + return; + } + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Sending information about request %llu to local client\n", + (unsigned long long)rr->request_id); + env = GNUNET_MQ_msg_extra(req, + rr->payload_length, + GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST); + req->reserved = htonl(0); req->request_id = rr->request_id; - GNUNET_memcpy (&req[1], - rr->payload, - rr->payload_length); - GNUNET_MQ_send (cr->mq, - env); + GNUNET_memcpy(&req[1], + rr->payload, + rr->payload_length); + GNUNET_MQ_send(cr->mq, + env); } @@ -512,9 +510,9 @@ send_request_to_client (struct RequestRecord *rr, * @param r number of bytes in dns */ static void -process_dns_result (void *cls, - const struct GNUNET_TUN_DnsHeader *dns, - size_t r); +process_dns_result(void *cls, + const struct GNUNET_TUN_DnsHeader *dns, + size_t r); /** @@ -524,129 +522,138 @@ process_dns_result (void *cls, * @param rr request to process further */ static void -next_phase (struct RequestRecord *rr) +next_phase(struct RequestRecord *rr) { struct ClientRecord *cr; int nz; if (rr->phase == RP_DROP) - { - cleanup_rr (rr); - return; - } + { + cleanup_rr(rr); + return; + } nz = -1; - for (unsigned int j=0;jclient_wait_list_length;j++) - { - if (NULL != rr->client_wait_list[j]) + for (unsigned int j = 0; j < rr->client_wait_list_length; j++) { - nz = (int) j; - break; + if (NULL != rr->client_wait_list[j]) + { + nz = (int)j; + break; + } } - } if (-1 != nz) - { - send_request_to_client (rr, - rr->client_wait_list[nz]); - return; - } - /* done with current phase, advance! */ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Request %llu now in phase %d\n", - rr->request_id, - rr->phase); - switch (rr->phase) - { - case RP_INIT: - rr->phase = RP_REQUEST_MONITOR; - for (cr = clients_head; NULL != cr; cr = cr->next) { - if (0 != (cr->flags & GNUNET_DNS_FLAG_REQUEST_MONITOR)) - GNUNET_array_append (rr->client_wait_list, - rr->client_wait_list_length, - cr); + send_request_to_client(rr, + rr->client_wait_list[nz]); + return; } - next_phase (rr); - return; - case RP_REQUEST_MONITOR: - rr->phase = RP_QUERY; - for (cr = clients_head; NULL != cr; cr = cr->next) + /* done with current phase, advance! */ + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Request %llu now in phase %d\n", + rr->request_id, + rr->phase); + switch (rr->phase) { - if (0 != (cr->flags & GNUNET_DNS_FLAG_PRE_RESOLUTION)) - GNUNET_array_append (rr->client_wait_list, - rr->client_wait_list_length, - cr); - } - next_phase (rr); - return; - case RP_QUERY: + case RP_INIT: + rr->phase = RP_REQUEST_MONITOR; + for (cr = clients_head; NULL != cr; cr = cr->next) + { + if (0 != (cr->flags & GNUNET_DNS_FLAG_REQUEST_MONITOR)) + GNUNET_array_append(rr->client_wait_list, + rr->client_wait_list_length, + cr); + } + next_phase(rr); + return; + + case RP_REQUEST_MONITOR: + rr->phase = RP_QUERY; + for (cr = clients_head; NULL != cr; cr = cr->next) + { + if (0 != (cr->flags & GNUNET_DNS_FLAG_PRE_RESOLUTION)) + GNUNET_array_append(rr->client_wait_list, + rr->client_wait_list_length, + cr); + } + next_phase(rr); + return; + + case RP_QUERY: #if 0 - /* TODO: optionally, use this to forward DNS requests to the - *original* DNS server instead of the one we have configured... - (but then we need to create a fresh dnsstub for each request - *and* manage the timeout) */ - switch (rr->dst_addr.ss_family) - { - case AF_INET: - salen = sizeof (struct sockaddr_in); - sa = (const struct sockaddr *) &rr->dst_addr; + /* TODO: optionally, use this to forward DNS requests to the + * original* DNS server instead of the one we have configured... + (but then we need to create a fresh dnsstub for each request + * and* manage the timeout) */ + switch (rr->dst_addr.ss_family) + { + case AF_INET: + salen = sizeof(struct sockaddr_in); + sa = (const struct sockaddr *)&rr->dst_addr; + break; + + case AF_INET6: + salen = sizeof(struct sockaddr_in6); + sa = (const struct sockaddr *)&rr->dst_addr; + break; + + default: + GNUNET_assert(0); + } +#endif + rr->phase = RP_INTERNET_DNS; + rr->rs = GNUNET_DNSSTUB_resolve(dnsstub, + rr->payload, + rr->payload_length, + &process_dns_result, + NULL); + if (NULL == rr->rs) + { + GNUNET_STATISTICS_update(stats, + gettext_noop("# DNS exit failed (failed to open socket)"), + 1, + GNUNET_NO); + cleanup_rr(rr); + return; + } + return; + + case RP_INTERNET_DNS: + rr->phase = RP_MODIFY; + for (cr = clients_head; NULL != cr; cr = cr->next) + { + if (0 != (cr->flags & GNUNET_DNS_FLAG_POST_RESOLUTION)) + GNUNET_array_append(rr->client_wait_list, + rr->client_wait_list_length, + cr); + } + next_phase(rr); + return; + + case RP_MODIFY: + rr->phase = RP_RESPONSE_MONITOR; + for (cr = clients_head; NULL != cr; cr = cr->next) + { + if (0 != (cr->flags & GNUNET_DNS_FLAG_RESPONSE_MONITOR)) + GNUNET_array_append(rr->client_wait_list, + rr->client_wait_list_length, + cr); + } + next_phase(rr); + return; + + case RP_RESPONSE_MONITOR: + request_done(rr); break; - case AF_INET6: - salen = sizeof (struct sockaddr_in6); - sa = (const struct sockaddr *) &rr->dst_addr; + + case RP_DROP: + cleanup_rr(rr); break; + default: - GNUNET_assert (0); - } -#endif - rr->phase = RP_INTERNET_DNS; - rr->rs = GNUNET_DNSSTUB_resolve (dnsstub, - rr->payload, - rr->payload_length, - &process_dns_result, - NULL); - if (NULL == rr->rs) - { - GNUNET_STATISTICS_update (stats, - gettext_noop ("# DNS exit failed (failed to open socket)"), - 1, - GNUNET_NO); - cleanup_rr (rr); - return; - } - return; - case RP_INTERNET_DNS: - rr->phase = RP_MODIFY; - for (cr = clients_head; NULL != cr; cr = cr->next) - { - if (0 != (cr->flags & GNUNET_DNS_FLAG_POST_RESOLUTION)) - GNUNET_array_append (rr->client_wait_list, - rr->client_wait_list_length, - cr); - } - next_phase (rr); - return; - case RP_MODIFY: - rr->phase = RP_RESPONSE_MONITOR; - for (cr = clients_head; NULL != cr; cr = cr->next) - { - if (0 != (cr->flags & GNUNET_DNS_FLAG_RESPONSE_MONITOR)) - GNUNET_array_append (rr->client_wait_list, - rr->client_wait_list_length, - cr); + GNUNET_break(0); + cleanup_rr(rr); + break; } - next_phase (rr); - return; - case RP_RESPONSE_MONITOR: - request_done (rr); - break; - case RP_DROP: - cleanup_rr (rr); - break; - default: - GNUNET_break (0); - cleanup_rr (rr); - break; - } } @@ -659,18 +666,18 @@ next_phase (struct RequestRecord *rr) * @return our `struct ClientRecord` */ static void * -client_connect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - struct GNUNET_MQ_Handle *mq) +client_connect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { struct ClientRecord *cr = cls; - cr = GNUNET_new (struct ClientRecord); + cr = GNUNET_new(struct ClientRecord); cr->client = client; cr->mq = mq; - GNUNET_CONTAINER_DLL_insert (clients_head, - clients_tail, - cr); + GNUNET_CONTAINER_DLL_insert(clients_head, + clients_tail, + cr); return cr; } @@ -683,31 +690,31 @@ client_connect_cb (void *cls, * @param app_ctx our `struct ClientRecord` */ static void -client_disconnect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - void *app_ctx) +client_disconnect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + void *app_ctx) { struct ClientRecord *cr = app_ctx; struct RequestRecord *rr; - GNUNET_CONTAINER_DLL_remove (clients_head, - clients_tail, - cr); - for (unsigned int i=0;iclient_wait_list_length) - continue; /* not in use */ - for (unsigned int j=0;jclient_wait_list_length;j++) + GNUNET_CONTAINER_DLL_remove(clients_head, + clients_tail, + cr); + for (unsigned int i = 0; i < UINT16_MAX; i++) { - if (rr->client_wait_list[j] == cr) - { - rr->client_wait_list[j] = NULL; - next_phase (rr); - } + rr = &requests[i]; + if (0 == rr->client_wait_list_length) + continue; /* not in use */ + for (unsigned int j = 0; j < rr->client_wait_list_length; j++) + { + if (rr->client_wait_list[j] == cr) + { + rr->client_wait_list[j] = NULL; + next_phase(rr); + } + } } - } - GNUNET_free (cr); + GNUNET_free(cr); } @@ -720,39 +727,39 @@ client_disconnect_cb (void *cls, * @param r number of bytes in dns */ static void -process_dns_result (void *cls, - const struct GNUNET_TUN_DnsHeader *dns, - size_t r) +process_dns_result(void *cls, + const struct GNUNET_TUN_DnsHeader *dns, + size_t r) { struct RequestRecord *rr; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Processing DNS result from stub resolver\n"); - GNUNET_assert (NULL == cls); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Processing DNS result from stub resolver\n"); + GNUNET_assert(NULL == cls); if (NULL == dns) return; /* ignore */ rr = &requests[dns->id]; if (rr->phase != RP_INTERNET_DNS) - { - /* unexpected / bogus reply */ - GNUNET_STATISTICS_update (stats, - gettext_noop ("# External DNS response discarded (no matching request)"), - 1, GNUNET_NO); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received DNS reply that does not match any pending request. Dropping.\n"); - return; - } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Got a response from the stub resolver for DNS request %llu intercepted locally!\n", - (unsigned long long) rr->request_id); - GNUNET_free_non_null (rr->payload); - rr->payload = GNUNET_malloc (r); - GNUNET_memcpy (rr->payload, - dns, - r); + { + /* unexpected / bogus reply */ + GNUNET_STATISTICS_update(stats, + gettext_noop("# External DNS response discarded (no matching request)"), + 1, GNUNET_NO); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received DNS reply that does not match any pending request. Dropping.\n"); + return; + } + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Got a response from the stub resolver for DNS request %llu intercepted locally!\n", + (unsigned long long)rr->request_id); + GNUNET_free_non_null(rr->payload); + rr->payload = GNUNET_malloc(r); + GNUNET_memcpy(rr->payload, + dns, + r); rr->payload_length = r; - next_phase (rr); + next_phase(rr); } @@ -763,13 +770,13 @@ process_dns_result (void *cls, * @param reg the init message */ static void -handle_client_init (void *cls, - const struct GNUNET_DNS_Register *reg) +handle_client_init(void *cls, + const struct GNUNET_DNS_Register *reg) { struct ClientRecord *cr = cls; - cr->flags = (enum GNUNET_DNS_Flags) ntohl (reg->flags); - GNUNET_SERVICE_client_continue (cr->client); + cr->flags = (enum GNUNET_DNS_Flags)ntohl(reg->flags); + GNUNET_SERVICE_client_continue(cr->client); } @@ -781,8 +788,8 @@ handle_client_init (void *cls, * @return #GNUNET_OK (always fine) */ static int -check_client_response (void *cls, - const struct GNUNET_DNS_Response *resp) +check_client_response(void *cls, + const struct GNUNET_DNS_Response *resp) { return GNUNET_OK; /* any payload is acceptable */ } @@ -795,87 +802,89 @@ check_client_response (void *cls, * @param resp the response */ static void -handle_client_response (void *cls, - const struct GNUNET_DNS_Response *resp) +handle_client_response(void *cls, + const struct GNUNET_DNS_Response *resp) { struct ClientRecord *cr = cls; struct RequestRecord *rr; uint16_t msize; uint16_t off; - msize = ntohs (resp->header.size); - off = (uint16_t) resp->request_id; + msize = ntohs(resp->header.size); + off = (uint16_t)resp->request_id; rr = &requests[off]; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received DNS response with ID %llu from local client!\n", - (unsigned long long) resp->request_id); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Received DNS response with ID %llu from local client!\n", + (unsigned long long)resp->request_id); if (rr->request_id != resp->request_id) - { - GNUNET_STATISTICS_update (stats, - gettext_noop ("# Client response discarded (no matching request)"), - 1, - GNUNET_NO); - GNUNET_SERVICE_client_continue (cr->client); - return; - } - for (unsigned int i=0;iclient_wait_list_length;i++) - { - if (NULL == rr->client_wait_list[i]) - continue; - if (rr->client_wait_list[i] != cr) - continue; - rr->client_wait_list[i] = NULL; - switch (ntohl (resp->drop_flag)) { - case 0: /* drop */ - rr->phase = RP_DROP; - break; - case 1: /* no change */ - break; - case 2: /* update */ - msize -= sizeof (struct GNUNET_DNS_Response); - if ( (sizeof (struct GNUNET_TUN_DnsHeader) > msize) || - (RP_REQUEST_MONITOR == rr->phase) || - (RP_RESPONSE_MONITOR == rr->phase) ) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cr->client); - next_phase (rr); - return; - } - GNUNET_free_non_null (rr->payload); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Changing DNS reply according to client specifications\n"); - rr->payload = GNUNET_malloc (msize); - rr->payload_length = msize; - GNUNET_memcpy (rr->payload, &resp[1], msize); - if (rr->phase == RP_QUERY) - { - /* clear wait list, we're moving to MODIFY phase next */ - GNUNET_array_grow (rr->client_wait_list, - rr->client_wait_list_length, - 0); - } - /* if query changed to answer, move past DNS resolution phase... */ - if ( (RP_QUERY == rr->phase) && - (rr->payload_length > sizeof (struct GNUNET_TUN_DnsHeader)) && - ((struct GNUNET_TUN_DnsFlags*)&(((struct GNUNET_TUN_DnsHeader*) rr->payload)->flags))->query_or_response == 1) - { - rr->phase = RP_INTERNET_DNS; - GNUNET_array_grow (rr->client_wait_list, - rr->client_wait_list_length, - 0); - } - break; + GNUNET_STATISTICS_update(stats, + gettext_noop("# Client response discarded (no matching request)"), + 1, + GNUNET_NO); + GNUNET_SERVICE_client_continue(cr->client); + return; + } + for (unsigned int i = 0; i < rr->client_wait_list_length; i++) + { + if (NULL == rr->client_wait_list[i]) + continue; + if (rr->client_wait_list[i] != cr) + continue; + rr->client_wait_list[i] = NULL; + switch (ntohl(resp->drop_flag)) + { + case 0: /* drop */ + rr->phase = RP_DROP; + break; + + case 1: /* no change */ + break; + + case 2: /* update */ + msize -= sizeof(struct GNUNET_DNS_Response); + if ((sizeof(struct GNUNET_TUN_DnsHeader) > msize) || + (RP_REQUEST_MONITOR == rr->phase) || + (RP_RESPONSE_MONITOR == rr->phase)) + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cr->client); + next_phase(rr); + return; + } + GNUNET_free_non_null(rr->payload); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Changing DNS reply according to client specifications\n"); + rr->payload = GNUNET_malloc(msize); + rr->payload_length = msize; + GNUNET_memcpy(rr->payload, &resp[1], msize); + if (rr->phase == RP_QUERY) + { + /* clear wait list, we're moving to MODIFY phase next */ + GNUNET_array_grow(rr->client_wait_list, + rr->client_wait_list_length, + 0); + } + /* if query changed to answer, move past DNS resolution phase... */ + if ((RP_QUERY == rr->phase) && + (rr->payload_length > sizeof(struct GNUNET_TUN_DnsHeader)) && + ((struct GNUNET_TUN_DnsFlags*)&(((struct GNUNET_TUN_DnsHeader*)rr->payload)->flags))->query_or_response == 1) + { + rr->phase = RP_INTERNET_DNS; + GNUNET_array_grow(rr->client_wait_list, + rr->client_wait_list_length, + 0); + } + break; + } + next_phase(rr); + GNUNET_SERVICE_client_continue(cr->client); + return; } - next_phase (rr); - GNUNET_SERVICE_client_continue (cr->client); - return; - } /* odd, client was not on our list for the request, that ought to be an error */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (cr->client); + GNUNET_break(0); + GNUNET_SERVICE_client_drop(cr->client); } @@ -887,8 +896,8 @@ handle_client_response (void *cls, * @param message the actual message, a DNS request we should handle */ static int -process_helper_messages (void *cls, - const struct GNUNET_MessageHeader *message) +process_helper_messages(void *cls, + const struct GNUNET_MessageHeader *message) { uint16_t msize; const struct GNUNET_TUN_Layer2PacketHeader *tun; @@ -902,93 +911,95 @@ process_helper_messages (void *cls, struct sockaddr_in *dsta4; struct sockaddr_in6 *dsta6; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Intercepted message via DNS hijacker\n"); - msize = ntohs (message->size); - if (msize < sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader) + sizeof (struct GNUNET_TUN_IPv4Header)) - { - /* non-IP packet received on TUN!? */ - GNUNET_break (0); - return GNUNET_OK; - } - msize -= sizeof (struct GNUNET_MessageHeader); - tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1]; - msize -= sizeof (struct GNUNET_TUN_Layer2PacketHeader); - switch (ntohs (tun->proto)) - { - case ETH_P_IPV4: - ip4 = (const struct GNUNET_TUN_IPv4Header *) &tun[1]; - ip6 = NULL; /* make compiler happy */ - if ( (msize < sizeof (struct GNUNET_TUN_IPv4Header)) || - (ip4->version != 4) || - (ip4->header_length != sizeof (struct GNUNET_TUN_IPv4Header) / 4) || - (ntohs(ip4->total_length) != msize) || - (ip4->protocol != IPPROTO_UDP) ) + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Intercepted message via DNS hijacker\n"); + msize = ntohs(message->size); + if (msize < sizeof(struct GNUNET_MessageHeader) + sizeof(struct GNUNET_TUN_Layer2PacketHeader) + sizeof(struct GNUNET_TUN_IPv4Header)) { - /* non-IP/UDP packet received on TUN (or with options) */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Received malformed IPv4-UDP packet on TUN interface.\n")); + /* non-IP packet received on TUN!? */ + GNUNET_break(0); return GNUNET_OK; } - udp = (const struct GNUNET_TUN_UdpHeader*) &ip4[1]; - msize -= sizeof (struct GNUNET_TUN_IPv4Header); - break; - case ETH_P_IPV6: - ip4 = NULL; /* make compiler happy */ - ip6 = (const struct GNUNET_TUN_IPv6Header *) &tun[1]; - if ( (msize < sizeof (struct GNUNET_TUN_IPv6Header)) || - (ip6->version != 6) || - (ntohs (ip6->payload_length) != msize - sizeof (struct GNUNET_TUN_IPv6Header)) || - (ip6->next_header != IPPROTO_UDP) ) + msize -= sizeof(struct GNUNET_MessageHeader); + tun = (const struct GNUNET_TUN_Layer2PacketHeader *)&message[1]; + msize -= sizeof(struct GNUNET_TUN_Layer2PacketHeader); + switch (ntohs(tun->proto)) { - /* non-IP/UDP packet received on TUN (or with extensions) */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Received malformed IPv6-UDP packet on TUN interface.\n")); + case ETH_P_IPV4: + ip4 = (const struct GNUNET_TUN_IPv4Header *)&tun[1]; + ip6 = NULL; /* make compiler happy */ + if ((msize < sizeof(struct GNUNET_TUN_IPv4Header)) || + (ip4->version != 4) || + (ip4->header_length != sizeof(struct GNUNET_TUN_IPv4Header) / 4) || + (ntohs(ip4->total_length) != msize) || + (ip4->protocol != IPPROTO_UDP)) + { + /* non-IP/UDP packet received on TUN (or with options) */ + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + _("Received malformed IPv4-UDP packet on TUN interface.\n")); + return GNUNET_OK; + } + udp = (const struct GNUNET_TUN_UdpHeader*)&ip4[1]; + msize -= sizeof(struct GNUNET_TUN_IPv4Header); + break; + + case ETH_P_IPV6: + ip4 = NULL; /* make compiler happy */ + ip6 = (const struct GNUNET_TUN_IPv6Header *)&tun[1]; + if ((msize < sizeof(struct GNUNET_TUN_IPv6Header)) || + (ip6->version != 6) || + (ntohs(ip6->payload_length) != msize - sizeof(struct GNUNET_TUN_IPv6Header)) || + (ip6->next_header != IPPROTO_UDP)) + { + /* non-IP/UDP packet received on TUN (or with extensions) */ + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + _("Received malformed IPv6-UDP packet on TUN interface.\n")); + return GNUNET_OK; + } + udp = (const struct GNUNET_TUN_UdpHeader *)&ip6[1]; + msize -= sizeof(struct GNUNET_TUN_IPv6Header); + break; + + default: + /* non-IP packet received on TUN!? */ + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + _("Got non-IP packet with %u bytes and protocol %u from TUN\n"), + (unsigned int)msize, + ntohs(tun->proto)); return GNUNET_OK; } - udp = (const struct GNUNET_TUN_UdpHeader *) &ip6[1]; - msize -= sizeof (struct GNUNET_TUN_IPv6Header); - break; - default: - /* non-IP packet received on TUN!? */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Got non-IP packet with %u bytes and protocol %u from TUN\n"), - (unsigned int) msize, - ntohs (tun->proto)); - return GNUNET_OK; - } - if ( (msize <= sizeof (struct GNUNET_TUN_UdpHeader) + sizeof (struct GNUNET_TUN_DnsHeader)) || - (DNS_PORT != ntohs (udp->destination_port)) ) - { - /* non-DNS packet received on TUN, ignore */ - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("DNS interceptor got non-DNS packet (dropped)\n")); - GNUNET_STATISTICS_update (stats, - gettext_noop ("# Non-DNS UDP packet received via TUN interface"), - 1, GNUNET_NO); - return GNUNET_OK; - } - msize -= sizeof (struct GNUNET_TUN_UdpHeader); - dns = (const struct GNUNET_TUN_DnsHeader*) &udp[1]; + if ((msize <= sizeof(struct GNUNET_TUN_UdpHeader) + sizeof(struct GNUNET_TUN_DnsHeader)) || + (DNS_PORT != ntohs(udp->destination_port))) + { + /* non-DNS packet received on TUN, ignore */ + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("DNS interceptor got non-DNS packet (dropped)\n")); + GNUNET_STATISTICS_update(stats, + gettext_noop("# Non-DNS UDP packet received via TUN interface"), + 1, GNUNET_NO); + return GNUNET_OK; + } + msize -= sizeof(struct GNUNET_TUN_UdpHeader); + dns = (const struct GNUNET_TUN_DnsHeader*)&udp[1]; rr = &requests[dns->id]; /* clean up from previous request */ - GNUNET_free_non_null (rr->payload); + GNUNET_free_non_null(rr->payload); rr->payload = NULL; - GNUNET_array_grow (rr->client_wait_list, - rr->client_wait_list_length, - 0); + GNUNET_array_grow(rr->client_wait_list, + rr->client_wait_list_length, + 0); /* setup new request */ rr->phase = RP_INIT; - switch (ntohs (tun->proto)) - { - case ETH_P_IPV4: + switch (ntohs(tun->proto)) { - srca4 = (struct sockaddr_in*) &rr->src_addr; - dsta4 = (struct sockaddr_in*) &rr->dst_addr; - memset (srca4, 0, sizeof (struct sockaddr_in)); - memset (dsta4, 0, sizeof (struct sockaddr_in)); + case ETH_P_IPV4: + { + srca4 = (struct sockaddr_in*)&rr->src_addr; + dsta4 = (struct sockaddr_in*)&rr->dst_addr; + memset(srca4, 0, sizeof(struct sockaddr_in)); + memset(dsta4, 0, sizeof(struct sockaddr_in)); srca4->sin_family = AF_INET; dsta4->sin_family = AF_INET; srca4->sin_addr = ip4->source_address; @@ -996,17 +1007,18 @@ process_helper_messages (void *cls, srca4->sin_port = udp->source_port; dsta4->sin_port = udp->destination_port; #if HAVE_SOCKADDR_IN_SIN_LEN - srca4->sin_len = sizeof (struct sockaddr_in); - dsta4->sin_len = sizeof (struct sockaddr_in); + srca4->sin_len = sizeof(struct sockaddr_in); + dsta4->sin_len = sizeof(struct sockaddr_in); #endif } break; - case ETH_P_IPV6: + + case ETH_P_IPV6: { - srca6 = (struct sockaddr_in6*) &rr->src_addr; - dsta6 = (struct sockaddr_in6*) &rr->dst_addr; - memset (srca6, 0, sizeof (struct sockaddr_in6)); - memset (dsta6, 0, sizeof (struct sockaddr_in6)); + srca6 = (struct sockaddr_in6*)&rr->src_addr; + dsta6 = (struct sockaddr_in6*)&rr->dst_addr; + memset(srca6, 0, sizeof(struct sockaddr_in6)); + memset(dsta6, 0, sizeof(struct sockaddr_in6)); srca6->sin6_family = AF_INET6; dsta6->sin6_family = AF_INET6; srca6->sin6_addr = ip6->source_address; @@ -1014,27 +1026,28 @@ process_helper_messages (void *cls, srca6->sin6_port = udp->source_port; dsta6->sin6_port = udp->destination_port; #if HAVE_SOCKADDR_IN_SIN_LEN - srca6->sin6_len = sizeof (struct sockaddr_in6); - dsta6->sin6_len = sizeof (struct sockaddr_in6); + srca6->sin6_len = sizeof(struct sockaddr_in6); + dsta6->sin6_len = sizeof(struct sockaddr_in6); #endif } - break; - default: - GNUNET_assert (0); - } - rr->payload = GNUNET_malloc (msize); + break; + + default: + GNUNET_assert(0); + } + rr->payload = GNUNET_malloc(msize); rr->payload_length = msize; - GNUNET_memcpy (rr->payload, dns, msize); + GNUNET_memcpy(rr->payload, dns, msize); rr->request_id = dns->id | (request_id_gen << 16); request_id_gen++; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Creating new DNS request %llu\n", - (unsigned long long) rr->request_id); - GNUNET_STATISTICS_update (stats, - gettext_noop ("# DNS requests received via TUN interface"), - 1, GNUNET_NO); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Creating new DNS request %llu\n", + (unsigned long long)rr->request_id); + GNUNET_STATISTICS_update(stats, + gettext_noop("# DNS requests received via TUN interface"), + 1, GNUNET_NO); /* start request processing state machine */ - next_phase (rr); + next_phase(rr); return GNUNET_OK; } @@ -1045,9 +1058,9 @@ process_helper_messages (void *cls, * @param service the initialized service */ static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg_, - struct GNUNET_SERVICE_Handle *service) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg_, + struct GNUNET_SERVICE_Handle *service) { char *ifc_name; char *ipv4addr; @@ -1059,126 +1072,126 @@ run (void *cls, int nortsetup; cfg = cfg_; - stats = GNUNET_STATISTICS_create ("dns", cfg); - GNUNET_SCHEDULER_add_shutdown (&cleanup_task, - cls); - dnsstub = GNUNET_DNSSTUB_start (128); + stats = GNUNET_STATISTICS_create("dns", cfg); + GNUNET_SCHEDULER_add_shutdown(&cleanup_task, + cls); + dnsstub = GNUNET_DNSSTUB_start(128); /* TODO: support multiple DNS_EXIT servers being configured */ /* TODO: see above TODO on using DNS server from original packet. Not sure which is best... */ dns_exit = NULL; - if ( (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - "dns", - "DNS_EXIT", - &dns_exit)) || - (GNUNET_OK != - GNUNET_DNSSTUB_add_dns_ip (dnsstub, - dns_exit)) ) - { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, - "dns", - "DNS_EXIT", - _("need a valid IPv4 or IPv6 address\n")); - GNUNET_free_non_null (dns_exit); - } - binary = GNUNET_OS_get_suid_binary_path (cfg, "gnunet-helper-dns"); + if ((GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string(cfg, + "dns", + "DNS_EXIT", + &dns_exit)) || + (GNUNET_OK != + GNUNET_DNSSTUB_add_dns_ip(dnsstub, + dns_exit))) + { + GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, + "dns", + "DNS_EXIT", + _("need a valid IPv4 or IPv6 address\n")); + GNUNET_free_non_null(dns_exit); + } + binary = GNUNET_OS_get_suid_binary_path(cfg, "gnunet-helper-dns"); if (GNUNET_YES != - GNUNET_OS_check_helper_binary (binary, - GNUNET_YES, - NULL)) // TODO: once we have a windows-testcase, add test parameters here - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("`%s' is not SUID or the path is invalid, " - "will not run DNS interceptor\n"), - binary); - global_ret = 1; - GNUNET_free (binary); - return; - } - GNUNET_free (binary); + GNUNET_OS_check_helper_binary(binary, + GNUNET_YES, + NULL)) // TODO: once we have a windows-testcase, add test parameters here + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("`%s' is not SUID or the path is invalid, " + "will not run DNS interceptor\n"), + binary); + global_ret = 1; + GNUNET_free(binary); + return; + } + GNUNET_free(binary); - helper_argv[0] = GNUNET_strdup ("gnunet-dns"); + helper_argv[0] = GNUNET_strdup("gnunet-dns"); if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (cfg, - "dns", - "IFNAME", - &ifc_name)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No entry 'IFNAME' in configuration!\n"); - GNUNET_free (binary); - GNUNET_SCHEDULER_shutdown (); - return; - } + GNUNET_CONFIGURATION_get_value_string(cfg, + "dns", + "IFNAME", + &ifc_name)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "No entry 'IFNAME' in configuration!\n"); + GNUNET_free(binary); + GNUNET_SCHEDULER_shutdown(); + return; + } helper_argv[1] = ifc_name; - if ( (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (cfg, - "dns", - "IPV6ADDR", - &ipv6addr)) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No entry 'IPV6ADDR' in configuration!\n"); - GNUNET_free (binary); - GNUNET_SCHEDULER_shutdown (); - return; - } + if ((GNUNET_SYSERR == + GNUNET_CONFIGURATION_get_value_string(cfg, + "dns", + "IPV6ADDR", + &ipv6addr))) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "No entry 'IPV6ADDR' in configuration!\n"); + GNUNET_free(binary); + GNUNET_SCHEDULER_shutdown(); + return; + } helper_argv[2] = ipv6addr; if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (cfg, - "dns", - "IPV6PREFIX", - &ipv6prefix)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No entry 'IPV6PREFIX' in configuration!\n"); - GNUNET_free (binary); - GNUNET_SCHEDULER_shutdown (); - return; - } + GNUNET_CONFIGURATION_get_value_string(cfg, + "dns", + "IPV6PREFIX", + &ipv6prefix)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "No entry 'IPV6PREFIX' in configuration!\n"); + GNUNET_free(binary); + GNUNET_SCHEDULER_shutdown(); + return; + } helper_argv[3] = ipv6prefix; if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (cfg, - "dns", - "IPV4ADDR", - &ipv4addr)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No entry 'IPV4ADDR' in configuration!\n"); - GNUNET_free (binary); - GNUNET_SCHEDULER_shutdown (); - return; - } + GNUNET_CONFIGURATION_get_value_string(cfg, + "dns", + "IPV4ADDR", + &ipv4addr)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "No entry 'IPV4ADDR' in configuration!\n"); + GNUNET_free(binary); + GNUNET_SCHEDULER_shutdown(); + return; + } helper_argv[4] = ipv4addr; if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (cfg, "dns", "IPV4MASK", - &ipv4mask)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No entry 'IPV4MASK' in configuration!\n"); - GNUNET_free (binary); - GNUNET_SCHEDULER_shutdown (); - return; - } + GNUNET_CONFIGURATION_get_value_string(cfg, "dns", "IPV4MASK", + &ipv4mask)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "No entry 'IPV4MASK' in configuration!\n"); + GNUNET_free(binary); + GNUNET_SCHEDULER_shutdown(); + return; + } helper_argv[5] = ipv4mask; - nortsetup = GNUNET_CONFIGURATION_get_value_yesno (cfg, "dns", - "SKIP_ROUTING_SETUP"); + nortsetup = GNUNET_CONFIGURATION_get_value_yesno(cfg, "dns", + "SKIP_ROUTING_SETUP"); if (GNUNET_YES == nortsetup) helper_argv[6] = GNUNET_strdup("1"); else helper_argv[6] = GNUNET_strdup("0"); helper_argv[7] = NULL; - hijacker = GNUNET_HELPER_start (GNUNET_NO, - binary, - helper_argv, - &process_helper_messages, - NULL, NULL); - GNUNET_free (binary); + hijacker = GNUNET_HELPER_start(GNUNET_NO, + binary, + helper_argv, + &process_helper_messages, + NULL, NULL); + GNUNET_free(binary); } @@ -1186,21 +1199,21 @@ run (void *cls, * Define "main" method using service macro. */ GNUNET_SERVICE_MAIN -("dns", - GNUNET_SERVICE_OPTION_NONE, - &run, - &client_connect_cb, - &client_disconnect_cb, - NULL, - GNUNET_MQ_hd_fixed_size (client_init, - GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT, - struct GNUNET_DNS_Register, - NULL), - GNUNET_MQ_hd_var_size (client_response, + ("dns", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_hd_fixed_size(client_init, + GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT, + struct GNUNET_DNS_Register, + NULL), + GNUNET_MQ_hd_var_size(client_response, GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE, struct GNUNET_DNS_Response, NULL), - GNUNET_MQ_handler_end ()); + GNUNET_MQ_handler_end()); /* FIXME: this might need a port on systems without 'getresgid' */ @@ -1209,28 +1222,28 @@ GNUNET_SERVICE_MAIN * Enable use of SGID capabilities on POSIX */ void __attribute__ ((constructor)) -GNUNET_DNS_init () +GNUNET_DNS_init() { gid_t rgid; gid_t egid; gid_t sgid; - if (-1 == getresgid (&rgid, - &egid, - &sgid)) - { - fprintf (stderr, - "getresgid failed: %s\n", - strerror (errno)); - } + if (-1 == getresgid(&rgid, + &egid, + &sgid)) + { + fprintf(stderr, + "getresgid failed: %s\n", + strerror(errno)); + } else if (sgid != rgid) - { - if (-1 == setregid (sgid, - sgid)) - fprintf (stderr, - "setregid failed: %s\n", - strerror (errno)); - } + { + if (-1 == setregid(sgid, + sgid)) + fprintf(stderr, + "setregid failed: %s\n", + strerror(errno)); + } } #endif diff --git a/src/dns/gnunet-zonewalk.c b/src/dns/gnunet-zonewalk.c index 19fc5b78d..2968d0209 100644 --- a/src/dns/gnunet-zonewalk.c +++ b/src/dns/gnunet-zonewalk.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file src/dns/gnunet-zoneimport.c @@ -31,8 +31,7 @@ /** * Request we should make. */ -struct Request -{ +struct Request { /** * Requests are kept in a DLL. */ @@ -144,145 +143,155 @@ static struct GNUNET_SCHEDULER_Task *t; * @param rec response */ static void -process_record (struct Request *req, - struct GNUNET_DNSPARSER_Record *rec) +process_record(struct Request *req, + struct GNUNET_DNSPARSER_Record *rec) { char buf[INET6_ADDRSTRLEN]; records++; switch (rec->type) - { - case GNUNET_DNSPARSER_TYPE_A: - fprintf (stdout, - "%s A %s\n", - req->hostname, - inet_ntop (AF_INET, + { + case GNUNET_DNSPARSER_TYPE_A: + fprintf(stdout, + "%s A %s\n", + req->hostname, + inet_ntop(AF_INET, rec->data.raw.data, buf, - sizeof (buf))); - break; - case GNUNET_DNSPARSER_TYPE_AAAA: - fprintf (stdout, - "%s AAAA %s\n", - req->hostname, - inet_ntop (AF_INET6, + sizeof(buf))); + break; + + case GNUNET_DNSPARSER_TYPE_AAAA: + fprintf(stdout, + "%s AAAA %s\n", + req->hostname, + inet_ntop(AF_INET6, rec->data.raw.data, buf, - sizeof (buf))); - break; - case GNUNET_DNSPARSER_TYPE_NS: - fprintf (stdout, - "%s NS %s\n", - req->hostname, - rec->data.hostname); - break; - case GNUNET_DNSPARSER_TYPE_CNAME: - fprintf (stdout, - "%s CNAME %s\n", - req->hostname, - rec->data.hostname); - break; - case GNUNET_DNSPARSER_TYPE_MX: - fprintf (stdout, - "%s MX %u %s\n", - req->hostname, - (unsigned int) rec->data.mx->preference, - rec->data.mx->mxhost); - break; - case GNUNET_DNSPARSER_TYPE_SOA: - fprintf (stdout, - "%s SOA %s %s %u %u %u %u %u\n", - req->hostname, - rec->data.soa->mname, - rec->data.soa->rname, - (unsigned int) rec->data.soa->serial, - (unsigned int) rec->data.soa->refresh, - (unsigned int) rec->data.soa->retry, - (unsigned int) rec->data.soa->expire, - (unsigned int) rec->data.soa->minimum_ttl); - break; - case GNUNET_DNSPARSER_TYPE_SRV: - fprintf (stdout, - "%s SRV %s %u %u %u\n", - req->hostname, - rec->data.srv->target, - rec->data.srv->priority, - rec->data.srv->weight, - rec->data.srv->port); - break; - case GNUNET_DNSPARSER_TYPE_PTR: - fprintf (stdout, - "%s PTR %s\n", - req->hostname, - rec->data.hostname); - break; - case GNUNET_DNSPARSER_TYPE_TXT: - fprintf (stdout, - "%s TXT %.*s\n", - req->hostname, - (int) rec->data.raw.data_len, - (char *) rec->data.raw.data); - break; - case GNUNET_DNSPARSER_TYPE_DNAME: - fprintf (stdout, - "%s DNAME %s\n", - req->hostname, - rec->data.hostname); - break; + sizeof(buf))); + break; + + case GNUNET_DNSPARSER_TYPE_NS: + fprintf(stdout, + "%s NS %s\n", + req->hostname, + rec->data.hostname); + break; + + case GNUNET_DNSPARSER_TYPE_CNAME: + fprintf(stdout, + "%s CNAME %s\n", + req->hostname, + rec->data.hostname); + break; + + case GNUNET_DNSPARSER_TYPE_MX: + fprintf(stdout, + "%s MX %u %s\n", + req->hostname, + (unsigned int)rec->data.mx->preference, + rec->data.mx->mxhost); + break; + + case GNUNET_DNSPARSER_TYPE_SOA: + fprintf(stdout, + "%s SOA %s %s %u %u %u %u %u\n", + req->hostname, + rec->data.soa->mname, + rec->data.soa->rname, + (unsigned int)rec->data.soa->serial, + (unsigned int)rec->data.soa->refresh, + (unsigned int)rec->data.soa->retry, + (unsigned int)rec->data.soa->expire, + (unsigned int)rec->data.soa->minimum_ttl); + break; + + case GNUNET_DNSPARSER_TYPE_SRV: + fprintf(stdout, + "%s SRV %s %u %u %u\n", + req->hostname, + rec->data.srv->target, + rec->data.srv->priority, + rec->data.srv->weight, + rec->data.srv->port); + break; + + case GNUNET_DNSPARSER_TYPE_PTR: + fprintf(stdout, + "%s PTR %s\n", + req->hostname, + rec->data.hostname); + break; + + case GNUNET_DNSPARSER_TYPE_TXT: + fprintf(stdout, + "%s TXT %.*s\n", + req->hostname, + (int)rec->data.raw.data_len, + (char *)rec->data.raw.data); + break; + + case GNUNET_DNSPARSER_TYPE_DNAME: + fprintf(stdout, + "%s DNAME %s\n", + req->hostname, + rec->data.hostname); + break; /* obscure records */ - case GNUNET_DNSPARSER_TYPE_AFSDB: - case GNUNET_DNSPARSER_TYPE_NAPTR: - case GNUNET_DNSPARSER_TYPE_APL: - case GNUNET_DNSPARSER_TYPE_DHCID: - case GNUNET_DNSPARSER_TYPE_HIP: - case GNUNET_DNSPARSER_TYPE_LOC: - case GNUNET_DNSPARSER_TYPE_RP: - case GNUNET_DNSPARSER_TYPE_TKEY: - case GNUNET_DNSPARSER_TYPE_TSIG: - case GNUNET_DNSPARSER_TYPE_URI: - case GNUNET_DNSPARSER_TYPE_TA: + case GNUNET_DNSPARSER_TYPE_AFSDB: + case GNUNET_DNSPARSER_TYPE_NAPTR: + case GNUNET_DNSPARSER_TYPE_APL: + case GNUNET_DNSPARSER_TYPE_DHCID: + case GNUNET_DNSPARSER_TYPE_HIP: + case GNUNET_DNSPARSER_TYPE_LOC: + case GNUNET_DNSPARSER_TYPE_RP: + case GNUNET_DNSPARSER_TYPE_TKEY: + case GNUNET_DNSPARSER_TYPE_TSIG: + case GNUNET_DNSPARSER_TYPE_URI: + case GNUNET_DNSPARSER_TYPE_TA: /* DNSSEC */ - case GNUNET_DNSPARSER_TYPE_DS: - case GNUNET_DNSPARSER_TYPE_RRSIG: - case GNUNET_DNSPARSER_TYPE_NSEC: - case GNUNET_DNSPARSER_TYPE_DNSKEY: - case GNUNET_DNSPARSER_TYPE_NSEC3: - case GNUNET_DNSPARSER_TYPE_NSEC3PARAM: - case GNUNET_DNSPARSER_TYPE_CDS: - case GNUNET_DNSPARSER_TYPE_CDNSKEY: + case GNUNET_DNSPARSER_TYPE_DS: + case GNUNET_DNSPARSER_TYPE_RRSIG: + case GNUNET_DNSPARSER_TYPE_NSEC: + case GNUNET_DNSPARSER_TYPE_DNSKEY: + case GNUNET_DNSPARSER_TYPE_NSEC3: + case GNUNET_DNSPARSER_TYPE_NSEC3PARAM: + case GNUNET_DNSPARSER_TYPE_CDS: + case GNUNET_DNSPARSER_TYPE_CDNSKEY: /* DNSSEC payload */ - case GNUNET_DNSPARSER_TYPE_CERT: - case GNUNET_DNSPARSER_TYPE_SSHFP: - case GNUNET_DNSPARSER_TYPE_IPSECKEY: - case GNUNET_DNSPARSER_TYPE_TLSA: - case GNUNET_DNSPARSER_TYPE_OPENPGPKEY: + case GNUNET_DNSPARSER_TYPE_CERT: + case GNUNET_DNSPARSER_TYPE_SSHFP: + case GNUNET_DNSPARSER_TYPE_IPSECKEY: + case GNUNET_DNSPARSER_TYPE_TLSA: + case GNUNET_DNSPARSER_TYPE_OPENPGPKEY: /* obsolete records */ - case GNUNET_DNSPARSER_TYPE_SIG: - case GNUNET_DNSPARSER_TYPE_KEY: - case GNUNET_DNSPARSER_TYPE_KX: + case GNUNET_DNSPARSER_TYPE_SIG: + case GNUNET_DNSPARSER_TYPE_KEY: + case GNUNET_DNSPARSER_TYPE_KX: { char *base32; - base32 = GNUNET_STRINGS_data_to_string_alloc (rec->data.raw.data, - rec->data.raw.data_len); - fprintf (stdout, - "%s (%u) %s\n", - req->hostname, - rec->type, - base32); - GNUNET_free (base32); + base32 = GNUNET_STRINGS_data_to_string_alloc(rec->data.raw.data, + rec->data.raw.data_len); + fprintf(stdout, + "%s (%u) %s\n", + req->hostname, + rec->type, + base32); + GNUNET_free(base32); } break; - default: - fprintf (stderr, - "Unsupported type %u\n", - (unsigned int) rec->type); - break; - } + + default: + fprintf(stderr, + "Unsupported type %u\n", + (unsigned int)rec->type); + break; + } } @@ -294,90 +303,90 @@ process_record (struct Request *req, * @param dns_len number of bytes in @a dns */ static void -process_result (void *cls, - const struct GNUNET_TUN_DnsHeader *dns, - size_t dns_len) +process_result(void *cls, + const struct GNUNET_TUN_DnsHeader *dns, + size_t dns_len) { struct Request *req = cls; struct GNUNET_DNSPARSER_Packet *p; if (NULL == dns) - { - /* stub gave up */ - pending--; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Stub gave up on DNS reply for `%s'\n", - req->hostname); - GNUNET_CONTAINER_DLL_remove (req_head, - req_tail, - req); - if (req->issue_num > MAX_RETRIES) { - failures++; - GNUNET_free (req->hostname); - GNUNET_free (req->raw); - GNUNET_free (req); + /* stub gave up */ + pending--; + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Stub gave up on DNS reply for `%s'\n", + req->hostname); + GNUNET_CONTAINER_DLL_remove(req_head, + req_tail, + req); + if (req->issue_num > MAX_RETRIES) + { + failures++; + GNUNET_free(req->hostname); + GNUNET_free(req->raw); + GNUNET_free(req); + return; + } + GNUNET_CONTAINER_DLL_insert_tail(req_head, + req_tail, + req); + req->rs = NULL; return; } - GNUNET_CONTAINER_DLL_insert_tail (req_head, - req_tail, - req); - req->rs = NULL; - return; - } if (req->id != dns->id) return; pending--; - GNUNET_DNSSTUB_resolve_cancel (req->rs); + GNUNET_DNSSTUB_resolve_cancel(req->rs); req->rs = NULL; - GNUNET_CONTAINER_DLL_remove (req_head, - req_tail, - req); - p = GNUNET_DNSPARSER_parse ((const char *) dns, - dns_len); + GNUNET_CONTAINER_DLL_remove(req_head, + req_tail, + req); + p = GNUNET_DNSPARSER_parse((const char *)dns, + dns_len); if (NULL == p) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to parse DNS reply for `%s'\n", - req->hostname); - if (req->issue_num > MAX_RETRIES) { - failures++; - GNUNET_free (req->hostname); - GNUNET_free (req->raw); - GNUNET_free (req); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to parse DNS reply for `%s'\n", + req->hostname); + if (req->issue_num > MAX_RETRIES) + { + failures++; + GNUNET_free(req->hostname); + GNUNET_free(req->raw); + GNUNET_free(req); + return; + } + GNUNET_CONTAINER_DLL_insert_tail(req_head, + req_tail, + req); return; } - GNUNET_CONTAINER_DLL_insert_tail (req_head, - req_tail, - req); - return; - } - for (unsigned int i=0;inum_answers;i++) - { - struct GNUNET_DNSPARSER_Record *rs = &p->answers[i]; - - process_record (req, - rs); - } - for (unsigned int i=0;inum_authority_records;i++) - { - struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i]; - - process_record (req, - rs); - } - for (unsigned int i=0;inum_additional_records;i++) - { - struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i]; - - process_record (req, - rs); - } - GNUNET_DNSPARSER_free_packet (p); - GNUNET_free (req->hostname); - GNUNET_free (req->raw); - GNUNET_free (req); + for (unsigned int i = 0; i < p->num_answers; i++) + { + struct GNUNET_DNSPARSER_Record *rs = &p->answers[i]; + + process_record(req, + rs); + } + for (unsigned int i = 0; i < p->num_authority_records; i++) + { + struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i]; + + process_record(req, + rs); + } + for (unsigned int i = 0; i < p->num_additional_records; i++) + { + struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i]; + + process_record(req, + rs); + } + GNUNET_DNSPARSER_free_packet(p); + GNUNET_free(req->hostname); + GNUNET_free(req->raw); + GNUNET_free(req); } @@ -391,31 +400,31 @@ process_result (void *cls, * #GNUNET_SYSERR if we are at the rate limit */ static int -submit_req (struct Request *req) +submit_req(struct Request *req) { static struct timeval last_request; struct timeval now; if (NULL != req->rs) return GNUNET_NO; /* already submitted */ - gettimeofday (&now, - NULL); - if ( ( ( (now.tv_sec - last_request.tv_sec) == 0) && - ( (now.tv_usec - last_request.tv_usec) < TIME_THRESH) ) || - (pending >= THRESH) ) + gettimeofday(&now, + NULL); + if ((((now.tv_sec - last_request.tv_sec) == 0) && + ((now.tv_usec - last_request.tv_usec) < TIME_THRESH)) || + (pending >= THRESH)) return GNUNET_SYSERR; - GNUNET_assert (NULL == req->rs); - req->rs = GNUNET_DNSSTUB_resolve (ctx, - req->raw, - req->raw_len, - &process_result, - req); - GNUNET_assert (NULL != req->rs); + GNUNET_assert(NULL == req->rs); + req->rs = GNUNET_DNSSTUB_resolve(ctx, + req->raw, + req->raw_len, + &process_result, + req); + GNUNET_assert(NULL != req->rs); req->issue_num++; last_request = now; lookups++; pending++; - req->time = time (NULL); + req->time = time(NULL); return GNUNET_OK; } @@ -428,21 +437,21 @@ submit_req (struct Request *req) static void process_queue(void *cls) { - (void) cls; + (void)cls; t = NULL; for (struct Request *req = req_head; NULL != req; req = req->next) - { - if (GNUNET_SYSERR == submit_req (req)) - break; - } + { + if (GNUNET_SYSERR == submit_req(req)) + break; + } if (NULL != req_head) - t = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, - &process_queue, - NULL); + t = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MILLISECONDS, + &process_queue, + NULL); else - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); } @@ -452,15 +461,15 @@ process_queue(void *cls) * @param cls NULL */ static void -do_shutdown (void *cls) +do_shutdown(void *cls) { - (void) cls; + (void)cls; if (NULL != t) - { - GNUNET_SCHEDULER_cancel (t); - t = NULL; - } - GNUNET_DNSSTUB_stop (ctx); + { + GNUNET_SCHEDULER_cancel(t); + t = NULL; + } + GNUNET_DNSSTUB_stop(ctx); ctx = NULL; } @@ -472,14 +481,14 @@ do_shutdown (void *cls) * @param cls NULL */ static void -run (void *cls) +run(void *cls) { - (void) cls; + (void)cls; - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, - NULL); - t = GNUNET_SCHEDULER_add_now (&process_queue, + GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); + t = GNUNET_SCHEDULER_add_now(&process_queue, + NULL); } @@ -489,7 +498,7 @@ run (void *cls) * @param hostname name to resolve */ static void -queue (const char *hostname) +queue(const char *hostname) { struct GNUNET_DNSPARSER_Packet p; struct GNUNET_DNSPARSER_Query q; @@ -499,46 +508,46 @@ queue (const char *hostname) int ret; if (GNUNET_OK != - GNUNET_DNSPARSER_check_name (hostname)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Refusing invalid hostname `%s'\n", - hostname); - return; - } - q.name = (char *) hostname; + GNUNET_DNSPARSER_check_name(hostname)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Refusing invalid hostname `%s'\n", + hostname); + return; + } + q.name = (char *)hostname; q.type = GNUNET_DNSPARSER_TYPE_NS; q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; - memset (&p, - 0, - sizeof (p)); + memset(&p, + 0, + sizeof(p)); p.num_queries = 1; p.queries = &q; - p.id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, - UINT16_MAX); - ret = GNUNET_DNSPARSER_pack (&p, - UINT16_MAX, - &raw, - &raw_size); + p.id = (uint16_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, + UINT16_MAX); + ret = GNUNET_DNSPARSER_pack(&p, + UINT16_MAX, + &raw, + &raw_size); if (GNUNET_OK != ret) - { - if (GNUNET_NO == ret) - GNUNET_free (raw); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to pack query for hostname `%s'\n", - hostname); - return; - } + { + if (GNUNET_NO == ret) + GNUNET_free(raw); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to pack query for hostname `%s'\n", + hostname); + return; + } - req = GNUNET_new (struct Request); - req->hostname = strdup (hostname); + req = GNUNET_new(struct Request); + req->hostname = strdup(hostname); req->raw = raw; req->raw_len = raw_size; req->id = p.id; - GNUNET_CONTAINER_DLL_insert_tail (req_head, - req_tail, - req); + GNUNET_CONTAINER_DLL_insert_tail(req_head, + req_tail, + req); } @@ -550,50 +559,50 @@ queue (const char *hostname) * @return 0 on success */ int -main (int argc, - char **argv) +main(int argc, + char **argv) { char hn[256]; if (2 != argc) - { - fprintf (stderr, - "Missing required configuration argument\n"); - return -1; - } - ctx = GNUNET_DNSSTUB_start (256); + { + fprintf(stderr, + "Missing required configuration argument\n"); + return -1; + } + ctx = GNUNET_DNSSTUB_start(256); if (NULL == ctx) - { - fprintf (stderr, - "Failed to initialize GNUnet DNS STUB\n"); - return 1; - } + { + fprintf(stderr, + "Failed to initialize GNUnet DNS STUB\n"); + return 1; + } if (GNUNET_OK != - GNUNET_DNSSTUB_add_dns_ip (ctx, - argv[1])) - { - fprintf (stderr, - "Failed to use `%s' for DNS resolver\n", - argv[1]); - return 1; - } + GNUNET_DNSSTUB_add_dns_ip(ctx, + argv[1])) + { + fprintf(stderr, + "Failed to use `%s' for DNS resolver\n", + argv[1]); + return 1; + } while (NULL != - fgets (hn, - sizeof (hn), - stdin)) - { - if (strlen(hn) > 0) - hn[strlen(hn)-1] = '\0'; /* eat newline */ - queue (hn); - } - GNUNET_SCHEDULER_run (&run, - NULL); - fprintf (stderr, - "Did %u lookups, found %u records, %u lookups failed, %u pending on shutdown\n", - lookups, - records, - failures, - pending); + fgets(hn, + sizeof(hn), + stdin)) + { + if (strlen(hn) > 0) + hn[strlen(hn) - 1] = '\0'; /* eat newline */ + queue(hn); + } + GNUNET_SCHEDULER_run(&run, + NULL); + fprintf(stderr, + "Did %u lookups, found %u records, %u lookups failed, %u pending on shutdown\n", + lookups, + records, + failures, + pending); return 0; } diff --git a/src/dns/plugin_block_dns.c b/src/dns/plugin_block_dns.c index ed75ce2f3..fd4d844c5 100644 --- a/src/dns/plugin_block_dns.c +++ b/src/dns/plugin_block_dns.c @@ -11,12 +11,12 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file dns/plugin_block_dns.c @@ -54,37 +54,37 @@ * by this @a type of block (this is not an error) */ static struct GNUNET_BLOCK_Group * -block_plugin_dns_create_group (void *cls, - enum GNUNET_BLOCK_Type type, - uint32_t nonce, - const void *raw_data, - size_t raw_data_size, - va_list va) +block_plugin_dns_create_group(void *cls, + enum GNUNET_BLOCK_Type type, + uint32_t nonce, + const void *raw_data, + size_t raw_data_size, + va_list va) { unsigned int bf_size; const char *guard; - guard = va_arg (va, const char *); - if (0 == strcmp (guard, - "seen-set-size")) - bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), - BLOOMFILTER_K); - else if (0 == strcmp (guard, - "filter-size")) - bf_size = va_arg (va, unsigned int); + guard = va_arg(va, const char *); + if (0 == strcmp(guard, + "seen-set-size")) + bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int), + BLOOMFILTER_K); + else if (0 == strcmp(guard, + "filter-size")) + bf_size = va_arg(va, unsigned int); else - { - GNUNET_break (0); - bf_size = 8; - } - GNUNET_break (NULL == va_arg (va, const char *)); - return GNUNET_BLOCK_GROUP_bf_create (cls, - bf_size, - BLOOMFILTER_K, - type, - nonce, - raw_data, - raw_data_size); + { + GNUNET_break(0); + bf_size = 8; + } + GNUNET_break(NULL == va_arg(va, const char *)); + return GNUNET_BLOCK_GROUP_bf_create(cls, + bf_size, + BLOOMFILTER_K, + type, + nonce, + raw_data, + raw_data_size); } @@ -105,71 +105,72 @@ block_plugin_dns_create_group (void *cls, * @return characterization of result */ static enum GNUNET_BLOCK_EvaluationResult -block_plugin_dns_evaluate (void *cls, - struct GNUNET_BLOCK_Context *ctx, - enum GNUNET_BLOCK_Type type, - struct GNUNET_BLOCK_Group *bg, - enum GNUNET_BLOCK_EvaluationOptions eo, - const struct GNUNET_HashCode * query, - const void *xquery, - size_t xquery_size, - const void *reply_block, - size_t reply_block_size) +block_plugin_dns_evaluate(void *cls, + struct GNUNET_BLOCK_Context *ctx, + enum GNUNET_BLOCK_Type type, + struct GNUNET_BLOCK_Group *bg, + enum GNUNET_BLOCK_EvaluationOptions eo, + const struct GNUNET_HashCode * query, + const void *xquery, + size_t xquery_size, + const void *reply_block, + size_t reply_block_size) { const struct GNUNET_DNS_Advertisement *ad; struct GNUNET_HashCode phash; switch (type) - { - case GNUNET_BLOCK_TYPE_DNS: - if (0 != xquery_size) - return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; - - if (NULL == reply_block) - return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; - - if (sizeof (struct GNUNET_DNS_Advertisement) != reply_block_size) - { - GNUNET_break_op (0); - return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; - } - ad = reply_block; - - if (ntohl (ad->purpose.size) != - sizeof (struct GNUNET_DNS_Advertisement) - - sizeof (struct GNUNET_CRYPTO_EddsaSignature)) - { - GNUNET_break_op (0); - return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; - } - if (0 == - GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh - (ad->expiration_time)).rel_value_us) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "DNS advertisement has expired\n"); - return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; - } - if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD, - &ad->purpose, - &ad->signature, - &ad->peer.public_key)) { - GNUNET_break_op (0); - return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + case GNUNET_BLOCK_TYPE_DNS: + if (0 != xquery_size) + return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; + + if (NULL == reply_block) + return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; + + if (sizeof(struct GNUNET_DNS_Advertisement) != reply_block_size) + { + GNUNET_break_op(0); + return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + } + ad = reply_block; + + if (ntohl(ad->purpose.size) != + sizeof(struct GNUNET_DNS_Advertisement) - + sizeof(struct GNUNET_CRYPTO_EddsaSignature)) + { + GNUNET_break_op(0); + return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + } + if (0 == + GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_ntoh + (ad->expiration_time)).rel_value_us) + { + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "DNS advertisement has expired\n"); + return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + } + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_DNS_RECORD, + &ad->purpose, + &ad->signature, + &ad->peer.public_key)) + { + GNUNET_break_op(0); + return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; + } + GNUNET_CRYPTO_hash(reply_block, + reply_block_size, + &phash); + if (GNUNET_YES == + GNUNET_BLOCK_GROUP_bf_test_and_set(bg, + &phash)) + return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; + return GNUNET_BLOCK_EVALUATION_OK_MORE; + + default: + return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; } - GNUNET_CRYPTO_hash (reply_block, - reply_block_size, - &phash); - if (GNUNET_YES == - GNUNET_BLOCK_GROUP_bf_test_and_set (bg, - &phash)) - return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; - return GNUNET_BLOCK_EVALUATION_OK_MORE; - default: - return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; - } } @@ -185,11 +186,11 @@ block_plugin_dns_evaluate (void *cls, * (or if extracting a key from a block of this type does not work) */ static int -block_plugin_dns_get_key (void *cls, - enum GNUNET_BLOCK_Type type, - const void *block, - size_t block_size, - struct GNUNET_HashCode *key) +block_plugin_dns_get_key(void *cls, + enum GNUNET_BLOCK_Type type, + const void *block, + size_t block_size, + struct GNUNET_HashCode *key) { /* we cannot extract a key from a block of this type */ return GNUNET_SYSERR; @@ -200,7 +201,7 @@ block_plugin_dns_get_key (void *cls, * Entry point for the plugin. */ void * -libgnunet_plugin_block_dns_init (void *cls) +libgnunet_plugin_block_dns_init(void *cls) { static enum GNUNET_BLOCK_Type types[] = { @@ -209,7 +210,7 @@ libgnunet_plugin_block_dns_init (void *cls) }; struct GNUNET_BLOCK_PluginFunctions *api; - api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); + api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); api->evaluate = &block_plugin_dns_evaluate; api->get_key = &block_plugin_dns_get_key; api->create_group = &block_plugin_dns_create_group; @@ -222,11 +223,11 @@ libgnunet_plugin_block_dns_init (void *cls) * Exit point from the plugin. */ void * -libgnunet_plugin_block_dns_done (void *cls) +libgnunet_plugin_block_dns_done(void *cls) { struct GNUNET_BLOCK_PluginFunctions *api = cls; - GNUNET_free (api); + GNUNET_free(api); return NULL; } -- cgit v1.2.3