2 This file is part of GNUnet.
3 (C) 2009, 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file util/service.c
23 * @brief functions related to starting services
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_protocols.h"
29 #include "gnunet_constants.h"
30 #include "gnunet_resolver_service.h"
39 #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
41 #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall)
43 #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
46 /* ******************* access control ******************** */
49 * Check if the given IP address is in the list of IP addresses.
51 * @param list a list of networks
52 * @param add the IP to check (in network byte order)
53 * @return #GNUNET_NO if the IP is not in the list, #GNUNET_YES if it it is
56 check_ipv4_listed (const struct GNUNET_STRINGS_IPv4NetworkPolicy *list,
57 const struct in_addr *add)
64 while ((list[i].network.s_addr != 0) || (list[i].netmask.s_addr != 0))
66 if ((add->s_addr & list[i].netmask.s_addr) ==
67 (list[i].network.s_addr & list[i].netmask.s_addr))
76 * Check if the given IP address is in the list of IP addresses.
78 * @param list a list of networks
79 * @param ip the IP to check (in network byte order)
80 * @return #GNUNET_NO if the IP is not in the list, #GNUNET_YES if it it is
83 check_ipv6_listed (const struct GNUNET_STRINGS_IPv6NetworkPolicy *list,
84 const struct in6_addr *ip)
92 memset (&zero, 0, sizeof (struct in6_addr));
95 while (0 != memcmp (&zero, &list[i].network, sizeof (struct in6_addr)))
97 for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++)
98 if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) !=
99 (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j]))
110 /* ****************** service struct ****************** */
114 * Context for "service_task".
116 struct GNUNET_SERVICE_Context
121 const struct GNUNET_CONFIGURATION_Handle *cfg;
124 * Handle for the server.
126 struct GNUNET_SERVER_Handle *server;
129 * NULL-terminated array of addresses to bind to, NULL if we got pre-bound
132 struct sockaddr **addrs;
135 * Name of our service.
137 const char *service_name;
140 * Main service-specific task to run.
142 GNUNET_SERVICE_Main task;
150 * IPv4 addresses that are not allowed to connect.
152 struct GNUNET_STRINGS_IPv4NetworkPolicy *v4_denied;
155 * IPv6 addresses that are not allowed to connect.
157 struct GNUNET_STRINGS_IPv6NetworkPolicy *v6_denied;
160 * IPv4 addresses that are allowed to connect (if not
161 * set, all are allowed).
163 struct GNUNET_STRINGS_IPv4NetworkPolicy *v4_allowed;
166 * IPv6 addresses that are allowed to connect (if not
167 * set, all are allowed).
169 struct GNUNET_STRINGS_IPv6NetworkPolicy *v6_allowed;
172 * My (default) message handlers. Adjusted copy
175 struct GNUNET_SERVER_MessageHandler *my_handlers;
178 * Array of the lengths of the entries in addrs.
183 * NULL-terminated array of listen sockets we should take over.
185 struct GNUNET_NETWORK_Handle **lsocks;
188 * Task ID of the shutdown task.
190 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
193 * Idle timeout for server.
195 struct GNUNET_TIME_Relative timeout;
198 * Overall success/failure of the service start.
203 * If we are daemonizing, this FD is set to the
204 * pipe to the parent. Send '.' if we started
205 * ok, '!' if not. -1 if we are not daemonizing.
207 int ready_confirm_fd;
210 * Do we close connections if we receive messages
211 * for which we have no handler?
216 * Do we require a matching UID for UNIX domain socket connections?
217 * #GNUNET_NO means that the UID does not have to match (however,
218 * @e match_gid may still impose other access control checks).
223 * Do we require a matching GID for UNIX domain socket connections?
224 * Ignored if @e match_uid is #GNUNET_YES. Note that this is about
225 * checking that the client's UID is in our group OR that the
226 * client's GID is our GID. If both "match_gid" and @e match_uid are
227 * #GNUNET_NO, all users on the local system have access.
234 enum GNUNET_SERVICE_Options options;
239 /* ****************** message handlers ****************** */
242 * Send a 'TEST' message back to the client.
244 * @param cls the 'struct GNUNET_SERVER_Client' to send TEST to
245 * @param size number of bytes available in 'buf'
246 * @param buf where to copy the message
247 * @return number of bytes written to 'buf'
250 write_test (void *cls, size_t size, void *buf)
252 struct GNUNET_SERVER_Client *client = cls;
253 struct GNUNET_MessageHeader *msg;
255 if (size < sizeof (struct GNUNET_MessageHeader))
257 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
258 return 0; /* client disconnected */
260 msg = (struct GNUNET_MessageHeader *) buf;
261 msg->type = htons (GNUNET_MESSAGE_TYPE_TEST);
262 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
263 GNUNET_SERVER_receive_done (client, GNUNET_OK);
264 return sizeof (struct GNUNET_MessageHeader);
269 * Handler for TEST message.
271 * @param cls closure (refers to service)
272 * @param client identification of the client
273 * @param message the actual message
276 handle_test (void *cls, struct GNUNET_SERVER_Client *client,
277 const struct GNUNET_MessageHeader *message)
279 /* simply bounce message back to acknowledge */
281 GNUNET_SERVER_notify_transmit_ready (client,
282 sizeof (struct GNUNET_MessageHeader),
283 GNUNET_TIME_UNIT_FOREVER_REL,
284 &write_test, client))
285 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
290 * Default handlers for all services. Will be copied and the
291 * "callback_cls" fields will be replaced with the specific service
294 static const struct GNUNET_SERVER_MessageHandler defhandlers[] = {
295 {&handle_test, NULL, GNUNET_MESSAGE_TYPE_TEST,
296 sizeof (struct GNUNET_MessageHeader)},
301 /* ****************** service core routines ************** */
305 * Check if access to the service is allowed from the given address.
308 * @param uc credentials, if available, otherwise NULL
309 * @param addr address
310 * @param addrlen length of address
311 * @return #GNUNET_YES to allow, #GNUNET_NO to deny, #GNUNET_SYSERR
312 * for unknown address family (will be denied).
315 check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc,
316 const struct sockaddr *addr, socklen_t addrlen)
318 struct GNUNET_SERVICE_Context *sctx = cls;
319 const struct sockaddr_in *i4;
320 const struct sockaddr_in6 *i6;
323 switch (addr->sa_family)
326 GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
327 i4 = (const struct sockaddr_in *) addr;
328 ret = ((NULL == sctx->v4_allowed) ||
329 (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) &&
330 ((NULL == sctx->v4_denied) ||
331 (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr)));
334 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
335 i6 = (const struct sockaddr_in6 *) addr;
336 ret = ((NULL == sctx->v6_allowed) ||
337 (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) &&
338 ((NULL == sctx->v6_denied) ||
339 (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
343 ret = GNUNET_OK; /* controlled using file-system ACL now */
347 LOG (GNUNET_ERROR_TYPE_WARNING, _("Unknown address family %d\n"),
349 return GNUNET_SYSERR;
351 if (GNUNET_OK != ret)
353 LOG (GNUNET_ERROR_TYPE_WARNING,
354 _("Access from `%s' denied to service `%s'\n"),
355 GNUNET_a2s (addr, addrlen),
363 * Get the name of the file where we will
364 * write the PID of the service.
366 * @param sctx service context
367 * @return name of the file for the process ID
370 get_pid_file_name (struct GNUNET_SERVICE_Context *sctx)
375 GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->service_name,
383 * Parse an IPv4 access control list.
385 * @param ret location where to write the ACL (set)
386 * @param sctx service context to use to get the configuration
387 * @param option name of the ACL option to parse
388 * @return #GNUNET_SYSERR on parse error, #GNUNET_OK on success (including
392 process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret, struct GNUNET_SERVICE_Context *sctx,
397 if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option))
402 GNUNET_break (GNUNET_OK ==
403 GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
406 if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy (opt)))
408 LOG (GNUNET_ERROR_TYPE_WARNING,
409 _("Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
410 opt, sctx->service_name, option);
412 return GNUNET_SYSERR;
420 * Parse an IPv6 access control list.
422 * @param ret location where to write the ACL (set)
423 * @param sctx service context to use to get the configuration
424 * @param option name of the ACL option to parse
425 * @return #GNUNET_SYSERR on parse error, #GNUNET_OK on success (including
429 process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, struct GNUNET_SERVICE_Context *sctx,
434 if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option))
439 GNUNET_break (GNUNET_OK ==
440 GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
443 if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy (opt)))
445 LOG (GNUNET_ERROR_TYPE_WARNING,
446 _("Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
447 opt, sctx->service_name, option);
449 return GNUNET_SYSERR;
457 * Add the given UNIX domain path as an address to the
458 * list (as the first entry).
460 * @param saddrs array to update
461 * @param saddrlens where to store the address length
462 * @param unixpath path to add
463 * @param abstract GNUNET_YES to add an abstract UNIX domain socket. This
464 * parameter is ignore on systems other than LINUX
467 add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens,
468 const char *unixpath,
472 struct sockaddr_un *un;
474 un = GNUNET_new (struct sockaddr_un);
475 un->sun_family = AF_UNIX;
476 strncpy (un->sun_path, unixpath, sizeof (un->sun_path) - 1);
478 if (GNUNET_YES == abstract)
479 un->sun_path[0] = '\0';
481 #if HAVE_SOCKADDR_IN_SIN_LEN
482 un->sun_len = (u_char) sizeof (struct sockaddr_un);
484 *saddrs = (struct sockaddr *) un;
485 *saddrlens = sizeof (struct sockaddr_un);
487 /* this function should never be called
488 * unless AF_UNIX is defined! */
495 * Get the list of addresses that a server for the given service
498 * @param service_name name of the service
499 * @param cfg configuration (which specifies the addresses)
500 * @param addrs set (call by reference) to an array of pointers to the
501 * addresses the server should bind to and listen on; the
502 * array will be NULL-terminated (on success)
503 * @param addr_lens set (call by reference) to an array of the lengths
504 * of the respective `struct sockaddr` struct in the @a addrs
506 * @return number of addresses found on success,
507 * #GNUNET_SYSERR if the configuration
508 * did not specify reasonable finding information or
509 * if it specified a hostname that could not be resolved;
510 * #GNUNET_NO if the number of addresses configured is
511 * zero (in this case, `*addrs` and `*addr_lens` will be
515 GNUNET_SERVICE_get_server_addresses (const char *service_name,
516 const struct GNUNET_CONFIGURATION_Handle *cfg,
517 struct sockaddr ***addrs,
518 socklen_t ** addr_lens)
521 struct GNUNET_NETWORK_Handle *desc;
522 unsigned long long port;
524 struct addrinfo hints;
525 struct addrinfo *res;
526 struct addrinfo *pos;
527 struct addrinfo *next;
532 struct sockaddr **saddrs;
533 socklen_t *saddrlens;
539 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6"))
543 GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6")))
544 return GNUNET_SYSERR;
547 disablev6 = GNUNET_NO;
551 /* probe IPv6 support */
552 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
555 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
558 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
559 return GNUNET_SYSERR;
561 LOG (GNUNET_ERROR_TYPE_INFO,
563 ("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
564 service_name, STRERROR (errno));
565 disablev6 = GNUNET_YES;
569 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
575 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
578 GNUNET_CONFIGURATION_get_value_number (cfg, service_name,
581 LOG (GNUNET_ERROR_TYPE_ERROR,
582 _("Require valid port number for service `%s' in configuration!\n"),
587 LOG (GNUNET_ERROR_TYPE_ERROR,
588 _("Require valid port number for service `%s' in configuration!\n"),
590 return GNUNET_SYSERR;
594 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
596 GNUNET_break (GNUNET_OK ==
597 GNUNET_CONFIGURATION_get_value_string (cfg, service_name,
598 "BINDTO", &hostname));
604 abstract = GNUNET_NO;
607 GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
609 GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, "UNIXPATH",
611 (0 < strlen (unixpath)))
613 /* probe UNIX support */
614 struct sockaddr_un s_un;
616 if (strlen (unixpath) >= sizeof (s_un.sun_path))
618 LOG (GNUNET_ERROR_TYPE_WARNING,
619 _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath,
620 (unsigned long long) sizeof (s_un.sun_path));
621 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
622 LOG (GNUNET_ERROR_TYPE_INFO,
623 _("Using `%s' instead\n"), unixpath);
626 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
628 "USE_ABSTRACT_SOCKETS");
629 if (GNUNET_SYSERR == abstract)
630 abstract = GNUNET_NO;
632 if ((GNUNET_YES != abstract)
634 GNUNET_DISK_directory_create_for_file (unixpath)))
635 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
639 if (NULL != unixpath)
641 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
644 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
647 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
648 GNUNET_free_non_null (hostname);
649 GNUNET_free (unixpath);
650 return GNUNET_SYSERR;
652 LOG (GNUNET_ERROR_TYPE_INFO,
653 _("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
654 service_name, STRERROR (errno));
655 GNUNET_free (unixpath);
660 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
666 if ((0 == port) && (NULL == unixpath))
668 LOG (GNUNET_ERROR_TYPE_ERROR,
669 _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
671 GNUNET_free_non_null (hostname);
672 return GNUNET_SYSERR;
676 saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *));
677 saddrlens = GNUNET_malloc (2 * sizeof (socklen_t));
678 add_unixpath (saddrs, saddrlens, unixpath, abstract);
679 GNUNET_free_non_null (unixpath);
680 GNUNET_free_non_null (hostname);
682 *addr_lens = saddrlens;
686 if (NULL != hostname)
688 LOG (GNUNET_ERROR_TYPE_DEBUG,
689 "Resolving `%s' since that is where `%s' will bind to.\n",
692 memset (&hints, 0, sizeof (struct addrinfo));
694 hints.ai_family = AF_INET;
695 hints.ai_protocol = IPPROTO_TCP;
696 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
699 LOG (GNUNET_ERROR_TYPE_ERROR,
700 _("Failed to resolve `%s': %s\n"),
703 GNUNET_free (hostname);
704 GNUNET_free_non_null (unixpath);
705 return GNUNET_SYSERR;
709 while (NULL != (pos = next))
712 if ((disablev6) && (pos->ai_family == AF_INET6))
718 LOG (GNUNET_ERROR_TYPE_ERROR,
719 _("Failed to find %saddress for `%s'.\n"),
720 disablev6 ? "IPv4 " : "",
723 GNUNET_free (hostname);
724 GNUNET_free_non_null (unixpath);
725 return GNUNET_SYSERR;
728 if (NULL != unixpath)
730 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
731 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
733 if (NULL != unixpath)
735 add_unixpath (saddrs, saddrlens, unixpath, abstract);
739 while (NULL != (pos = next))
742 if ((disablev6) && (AF_INET6 == pos->ai_family))
744 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
745 continue; /* not TCP */
746 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
748 LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n",
749 service_name, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
750 if (AF_INET == pos->ai_family)
752 GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
753 saddrlens[i] = pos->ai_addrlen;
754 saddrs[i] = GNUNET_malloc (saddrlens[i]);
755 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
756 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
760 GNUNET_assert (AF_INET6 == pos->ai_family);
761 GNUNET_assert (sizeof (struct sockaddr_in6) == pos->ai_addrlen);
762 saddrlens[i] = pos->ai_addrlen;
763 saddrs[i] = GNUNET_malloc (saddrlens[i]);
764 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
765 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
769 GNUNET_free (hostname);
775 /* will bind against everything, just set port */
780 if (NULL != unixpath)
783 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
784 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
785 if (NULL != unixpath)
787 add_unixpath (saddrs, saddrlens, unixpath, abstract);
790 saddrlens[i] = sizeof (struct sockaddr_in);
791 saddrs[i] = GNUNET_malloc (saddrlens[i]);
792 #if HAVE_SOCKADDR_IN_SIN_LEN
793 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
795 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
796 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
802 if (NULL != unixpath)
804 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
805 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
807 if (NULL != unixpath)
809 add_unixpath (saddrs, saddrlens, unixpath, abstract);
812 saddrlens[i] = sizeof (struct sockaddr_in6);
813 saddrs[i] = GNUNET_malloc (saddrlens[i]);
814 #if HAVE_SOCKADDR_IN_SIN_LEN
815 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
817 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
818 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
820 saddrlens[i] = sizeof (struct sockaddr_in);
821 saddrs[i] = GNUNET_malloc (saddrlens[i]);
822 #if HAVE_SOCKADDR_IN_SIN_LEN
823 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
825 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
826 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
829 GNUNET_free_non_null (unixpath);
831 *addr_lens = saddrlens;
838 * Read listen sockets from the parent process (ARM).
840 * @param sctx service context to initialize
841 * @return #GNUNET_YES if ok, #GNUNET_NO if not ok (must bind yourself),
842 * and #GNUNET_SYSERR on error.
845 receive_sockets_from_parent (struct GNUNET_SERVICE_Context *sctx)
853 env_buf = getenv ("GNUNET_OS_READ_LSOCKS");
854 if ((NULL == env_buf) || (strlen (env_buf) <= 0))
856 /* Using W32 API directly here, because this pipe will
857 * never be used outside of this function, and it's just too much of a bother
858 * to create a GNUnet API that boxes a HANDLE (the way it is done with socks)
860 lsocks_pipe = (HANDLE) strtoul (env_buf, NULL, 10);
861 if ( (0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe))
870 ret = ReadFile (lsocks_pipe, &count, sizeof (count), &rd, NULL);
871 if ((0 == ret) || (sizeof (count) != rd) || (0 == count))
874 GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (count + 1));
877 for (i = 0; i < count; i++)
879 WSAPROTOCOL_INFOA pi;
883 ret = ReadFile (lsocks_pipe, &size, sizeof (size), &rd, NULL);
884 if ( (0 == ret) || (sizeof (size) != rd) || (sizeof (pi) != size) )
886 ret = ReadFile (lsocks_pipe, &pi, sizeof (pi), &rd, NULL);
887 if ( (0 == ret) || (sizeof (pi) != rd))
889 s = WSASocketA (pi.iAddressFamily, pi.iSocketType, pi.iProtocol, &pi, 0, WSA_FLAG_OVERLAPPED);
890 sctx->lsocks[i] = GNUNET_NETWORK_socket_box_native (s);
891 if (NULL == sctx->lsocks[i])
893 else if (i == count - 1)
898 sctx->lsocks[count] = NULL;
903 CloseHandle (lsocks_pipe);
907 LOG (GNUNET_ERROR_TYPE_ERROR,
908 _("Could not access a pre-bound socket, will try to bind myself\n"));
909 for (i = 0; (i < count) && (NULL != sctx->lsocks[i]); i++)
910 GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[i]));
911 GNUNET_free_non_null (sctx->lsocks);
921 * Setup addr, addrlen, idle_timeout
922 * based on configuration!
924 * Configuration may specify:
925 * - PORT (where to bind to for TCP)
926 * - UNIXPATH (where to bind to for UNIX domain sockets)
927 * - TIMEOUT (after how many ms does an inactive service timeout);
928 * - DISABLEV6 (disable support for IPv6, otherwise we use dual-stack)
929 * - BINDTO (hostname or IP address to bind to, otherwise we take everything)
930 * - ACCEPT_FROM (only allow connections from specified IPv4 subnets)
931 * - ACCEPT_FROM6 (only allow connections from specified IPv6 subnets)
932 * - REJECT_FROM (disallow allow connections from specified IPv4 subnets)
933 * - REJECT_FROM6 (disallow allow connections from specified IPv6 subnets)
935 * @param sctx service context to initialize
936 * @return #GNUNET_OK if configuration succeeded
939 setup_service (struct GNUNET_SERVICE_Context *sctx)
941 struct GNUNET_TIME_Relative idleout;
950 if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, "TIMEOUT"))
953 GNUNET_CONFIGURATION_get_value_time (sctx->cfg, sctx->service_name,
954 "TIMEOUT", &idleout))
956 LOG (GNUNET_ERROR_TYPE_ERROR,
957 _("Specified value for `%s' of service `%s' is invalid\n"),
958 "TIMEOUT", sctx->service_name);
959 return GNUNET_SYSERR;
961 sctx->timeout = idleout;
964 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
966 if (GNUNET_CONFIGURATION_have_value
967 (sctx->cfg, sctx->service_name, "TOLERANT"))
971 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name,
974 LOG (GNUNET_ERROR_TYPE_ERROR,
975 _("Specified value for `%s' of service `%s' is invalid\n"),
976 "TOLERANT", sctx->service_name);
977 return GNUNET_SYSERR;
981 tolerant = GNUNET_NO;
985 if ((NULL != (nfds = getenv ("LISTEN_FDS"))) &&
986 (1 == SSCANF (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) &&
987 (cnt + 4 < FD_SETSIZE))
990 GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1));
993 flags = fcntl (3 + cnt, F_GETFD);
994 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
996 (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
998 LOG (GNUNET_ERROR_TYPE_ERROR,
1000 ("Could not access pre-bound socket %u, will try to bind myself\n"),
1001 (unsigned int) 3 + cnt);
1003 while (sctx->lsocks[cnt] != NULL)
1004 GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[cnt++]));
1005 GNUNET_free (sctx->lsocks);
1006 sctx->lsocks = NULL;
1010 unsetenv ("LISTEN_FDS");
1013 if (getenv ("GNUNET_OS_READ_LSOCKS") != NULL)
1015 receive_sockets_from_parent (sctx);
1016 putenv ("GNUNET_OS_READ_LSOCKS=");
1020 if ((NULL == sctx->lsocks) &&
1022 GNUNET_SERVICE_get_server_addresses (sctx->service_name, sctx->cfg,
1023 &sctx->addrs, &sctx->addrlens)))
1024 return GNUNET_SYSERR;
1025 sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
1027 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name,
1030 GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name,
1032 process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM");
1033 process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM");
1034 process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6");
1035 process_acl6 (&sctx->v6_allowed, sctx, "ACCEPT_FROM6");
1042 * Get the name of the user that'll be used
1043 * to provide the service.
1045 * @param sctx service context
1046 * @return value of the 'USERNAME' option
1049 get_user_name (struct GNUNET_SERVICE_Context *sctx)
1054 GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->service_name,
1064 * @param sctx service context
1065 * @param pid PID to write (should be equal to 'getpid()'
1066 * @return #GNUNET_OK on success (including no work to be done)
1069 write_pid_file (struct GNUNET_SERVICE_Context *sctx, pid_t pid)
1077 if (NULL == (pif = get_pid_file_name (sctx)))
1078 return GNUNET_OK; /* no file desired */
1079 user = get_user_name (sctx);
1080 rdir = GNUNET_strdup (pif);
1081 len = strlen (rdir);
1082 while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
1085 if (0 != ACCESS (rdir, F_OK))
1087 /* we get to create a directory -- and claim it
1089 (void) GNUNET_DISK_directory_create (rdir);
1090 if ((NULL != user) && (0 < strlen (user)))
1091 GNUNET_DISK_file_change_owner (rdir, user);
1093 if (0 != ACCESS (rdir, W_OK | X_OK))
1095 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir);
1097 GNUNET_free_non_null (user);
1099 return GNUNET_SYSERR;
1102 pidfd = FOPEN (pif, "w");
1105 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif);
1107 GNUNET_free_non_null (user);
1108 return GNUNET_SYSERR;
1110 if (0 > FPRINTF (pidfd, "%u", pid))
1111 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif);
1112 GNUNET_break (0 == FCLOSE (pidfd));
1113 if ((NULL != user) && (0 < strlen (user)))
1114 GNUNET_DISK_file_change_owner (pif, user);
1115 GNUNET_free_non_null (user);
1122 * Task run during shutdown. Stops the server/service.
1124 * @param cls the `struct GNUNET_SERVICE_Context`
1128 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1130 struct GNUNET_SERVICE_Context *service = cls;
1131 struct GNUNET_SERVER_Handle *server = service->server;
1133 service->shutdown_task = GNUNET_SCHEDULER_NO_TASK;
1134 if (0 != (service->options & GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN))
1135 GNUNET_SERVER_stop_listening (server);
1137 GNUNET_SERVER_destroy (server);
1142 * Initial task for the service.
1144 * @param cls service context
1148 service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1150 struct GNUNET_SERVICE_Context *sctx = cls;
1153 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1155 (void) GNUNET_SPEEDUP_start_ (sctx->cfg);
1156 GNUNET_RESOLVER_connect (sctx->cfg);
1157 if (NULL != sctx->lsocks)
1159 = GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks,
1160 sctx->timeout, sctx->require_found);
1163 = GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens,
1164 sctx->timeout, sctx->require_found);
1165 if (NULL == sctx->server)
1167 if (NULL != sctx->addrs)
1168 for (i = 0; NULL != sctx->addrs[i]; i++)
1169 LOG (GNUNET_ERROR_TYPE_INFO,
1170 _("Failed to start `%s' at `%s'\n"),
1171 sctx->service_name, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
1172 sctx->ret = GNUNET_SYSERR;
1176 if (NULL != sctx->addrs)
1177 for (i = 0; NULL != sctx->addrs[i]; i++)
1178 if ((AF_UNIX == sctx->addrs[i]->sa_family)
1179 && ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0]))
1180 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path,
1186 if (0 == (sctx->options & GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN))
1188 /* install a task that will kill the server
1189 * process if the scheduler ever gets a shutdown signal */
1190 sctx->shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1194 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
1195 memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
1197 while (NULL != sctx->my_handlers[i].callback)
1198 sctx->my_handlers[i++].callback_cls = sctx;
1199 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers);
1200 if (-1 != sctx->ready_confirm_fd)
1202 GNUNET_break (1 == WRITE (sctx->ready_confirm_fd, ".", 1));
1203 GNUNET_break (0 == CLOSE (sctx->ready_confirm_fd));
1204 sctx->ready_confirm_fd = -1;
1205 write_pid_file (sctx, getpid ());
1207 if (NULL != sctx->addrs)
1210 while (NULL != sctx->addrs[i])
1212 LOG (GNUNET_ERROR_TYPE_INFO, _("Service `%s' runs at %s\n"),
1213 sctx->service_name, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
1217 sctx->task (sctx->task_cls, sctx->server, sctx->cfg);
1222 * Detach from terminal.
1224 * @param sctx service context
1225 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1228 detach_terminal (struct GNUNET_SERVICE_Context *sctx)
1235 if (0 != PIPE (filedes))
1237 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
1238 return GNUNET_SYSERR;
1243 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
1244 return GNUNET_SYSERR;
1251 GNUNET_break (0 == CLOSE (filedes[1]));
1253 if (1 != READ (filedes[0], &c, sizeof (char)))
1254 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read");
1261 LOG (GNUNET_ERROR_TYPE_INFO, _("Service process failed to initialize\n"));
1264 LOG (GNUNET_ERROR_TYPE_INFO,
1265 _("Service process could not initialize server function\n"));
1268 LOG (GNUNET_ERROR_TYPE_INFO,
1269 _("Service process failed to report status\n"));
1272 exit (1); /* child reported error */
1274 GNUNET_break (0 == CLOSE (0));
1275 GNUNET_break (0 == CLOSE (1));
1276 GNUNET_break (0 == CLOSE (filedes[0]));
1277 nullfd = OPEN ("/dev/null", O_RDWR | O_APPEND);
1279 return GNUNET_SYSERR;
1280 /* set stdin/stdout to /dev/null */
1281 if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
1283 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
1284 (void) CLOSE (nullfd);
1285 return GNUNET_SYSERR;
1287 (void) CLOSE (nullfd);
1288 /* Detach from controlling terminal */
1291 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "setsid");
1292 sctx->ready_confirm_fd = filedes[1];
1294 /* FIXME: we probably need to do something else
1295 * elsewhere in order to fork the process itself... */
1305 * @param sctx service context
1306 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1309 set_user_id (struct GNUNET_SERVICE_Context *sctx)
1313 if (NULL == (user = get_user_name (sctx)))
1314 return GNUNET_OK; /* keep */
1319 pws = getpwnam (user);
1322 LOG (GNUNET_ERROR_TYPE_ERROR,
1323 _("Cannot obtain information about user `%s': %s\n"), user,
1324 errno == 0 ? _("No such user") : STRERROR (errno));
1326 return GNUNET_SYSERR;
1328 if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) ||
1330 (0 != initgroups (user, pws->pw_gid)) ||
1332 (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid)))
1334 if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
1335 (0 != setreuid (pws->pw_uid, pws->pw_uid)))
1337 LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot change user/group to `%s': %s\n"),
1338 user, STRERROR (errno));
1340 return GNUNET_SYSERR;
1350 * Delete the PID file that was created by our parent.
1352 * @param sctx service context
1355 pid_file_delete (struct GNUNET_SERVICE_Context *sctx)
1357 char *pif = get_pid_file_name (sctx);
1360 return; /* no PID file */
1361 if (0 != UNLINK (pif))
1362 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif);
1368 * Run a standard GNUnet service startup sequence (initialize loggers
1369 * and configuration, parse options).
1371 * @param argc number of command line arguments
1372 * @param argv command line arguments
1373 * @param service_name our service name
1374 * @param options service options
1375 * @param task main task of the service
1376 * @param task_cls closure for @a task
1377 * @return #GNUNET_SYSERR on error, #GNUNET_OK
1378 * if we shutdown nicely
1381 GNUNET_SERVICE_run (int argc, char *const *argv,
1382 const char *service_name,
1383 enum GNUNET_SERVICE_Options options,
1384 GNUNET_SERVICE_Main task,
1387 #define HANDLE_ERROR do { GNUNET_break (0); goto shutdown; } while (0)
1397 unsigned long long skew_offset;
1398 unsigned long long skew_variance;
1399 long long clock_offset;
1400 struct GNUNET_SERVICE_Context sctx;
1401 struct GNUNET_CONFIGURATION_Handle *cfg;
1404 struct GNUNET_GETOPT_CommandLineOption service_options[] = {
1405 GNUNET_GETOPT_OPTION_CFG_FILE (&opt_cfg_fn),
1406 {'d', "daemonize", NULL,
1407 gettext_noop ("do daemonize (detach from terminal)"), 0,
1408 GNUNET_GETOPT_set_one, &do_daemonize},
1409 GNUNET_GETOPT_OPTION_HELP (NULL),
1410 GNUNET_GETOPT_OPTION_LOGLEVEL (&loglev),
1411 GNUNET_GETOPT_OPTION_LOGFILE (&logfile),
1412 GNUNET_GETOPT_OPTION_VERSION (PACKAGE_VERSION " " VCS_VERSION),
1413 GNUNET_GETOPT_OPTION_END
1420 xdg = getenv ("XDG_CONFIG_HOME");
1422 GNUNET_asprintf (&cfg_fn,
1428 cfg_fn = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE);
1429 memset (&sctx, 0, sizeof (sctx));
1430 sctx.options = options;
1431 sctx.ready_confirm_fd = -1;
1432 sctx.ret = GNUNET_OK;
1433 sctx.timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1435 sctx.task_cls = task_cls;
1436 sctx.service_name = service_name;
1437 sctx.cfg = cfg = GNUNET_CONFIGURATION_create ();
1439 /* setup subsystems */
1440 ret = GNUNET_GETOPT_run (service_name, service_options, argc, argv);
1441 if (GNUNET_SYSERR == ret)
1443 if (GNUNET_NO == ret)
1448 if (GNUNET_OK != GNUNET_log_setup (service_name, loglev, logfile))
1450 if (NULL == opt_cfg_fn)
1451 opt_cfg_fn = GNUNET_strdup (cfg_fn);
1452 if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_fn))
1454 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn))
1456 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1457 _("Malformed configuration file `%s', exit ...\n"),
1464 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL))
1466 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1467 _("Malformed configuration, exit ...\n"));
1470 if (0 != strcmp (opt_cfg_fn, cfg_fn))
1471 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1472 _("Could not access configuration file `%s'\n"),
1475 if (GNUNET_OK != setup_service (&sctx))
1477 if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal (&sctx)))
1479 if (GNUNET_OK != set_user_id (&sctx))
1481 LOG (GNUNET_ERROR_TYPE_DEBUG,
1482 "Service `%s' runs with configuration from `%s'\n",
1486 GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING",
1487 "SKEW_OFFSET", &skew_offset)) &&
1489 GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING",
1490 "SKEW_VARIANCE", &skew_variance)))
1492 clock_offset = skew_offset - skew_variance;
1493 GNUNET_TIME_set_offset (clock_offset);
1494 LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset);
1496 /* actually run service */
1498 GNUNET_SCHEDULER_run (&service_task, &sctx);
1500 if ((1 == do_daemonize) && (NULL != sctx.server))
1501 pid_file_delete (&sctx);
1502 GNUNET_free_non_null (sctx.my_handlers);
1505 if (-1 != sctx.ready_confirm_fd)
1507 if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1))
1508 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
1509 GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd));
1516 GNUNET_CONFIGURATION_have_value (sctx.cfg, service_name,
1519 GNUNET_CONFIGURATION_get_value_string (sctx.cfg, service_name,
1526 GAUGER (service_name, counter, mi.usmblks, "blocks");
1527 GNUNET_free (counter);
1531 GNUNET_SPEEDUP_stop_ ();
1532 GNUNET_CONFIGURATION_destroy (cfg);
1534 if (NULL != sctx.addrs)
1535 while (NULL != sctx.addrs[i])
1536 GNUNET_free (sctx.addrs[i++]);
1537 GNUNET_free_non_null (sctx.addrs);
1538 GNUNET_free_non_null (sctx.addrlens);
1539 GNUNET_free_non_null (logfile);
1540 GNUNET_free_non_null (loglev);
1541 GNUNET_free (cfg_fn);
1542 GNUNET_free_non_null (opt_cfg_fn);
1543 GNUNET_free_non_null (sctx.v4_denied);
1544 GNUNET_free_non_null (sctx.v6_denied);
1545 GNUNET_free_non_null (sctx.v4_allowed);
1546 GNUNET_free_non_null (sctx.v6_allowed);
1548 return err ? GNUNET_SYSERR : sctx.ret;
1553 * Run a service startup sequence within an existing
1554 * initialized system.
1556 * @param service_name our service name
1557 * @param cfg configuration to use
1558 * @param options service options
1559 * @return NULL on error, service handle
1561 struct GNUNET_SERVICE_Context *
1562 GNUNET_SERVICE_start (const char *service_name,
1563 const struct GNUNET_CONFIGURATION_Handle *cfg,
1564 enum GNUNET_SERVICE_Options options)
1567 struct GNUNET_SERVICE_Context *sctx;
1569 sctx = GNUNET_new (struct GNUNET_SERVICE_Context);
1570 sctx->ready_confirm_fd = -1; /* no daemonizing */
1571 sctx->ret = GNUNET_OK;
1572 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1573 sctx->service_name = service_name;
1575 sctx->options = options;
1577 /* setup subsystems */
1578 if (GNUNET_OK != setup_service (sctx))
1580 GNUNET_SERVICE_stop (sctx);
1583 if (NULL != sctx->lsocks)
1585 GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks,
1586 sctx->timeout, sctx->require_found);
1589 GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens,
1590 sctx->timeout, sctx->require_found);
1592 if (NULL == sctx->server)
1594 GNUNET_SERVICE_stop (sctx);
1598 if (NULL != sctx->addrs)
1599 for (i = 0; NULL != sctx->addrs[i]; i++)
1600 if ((AF_UNIX == sctx->addrs[i]->sa_family)
1601 && ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0]))
1602 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path,
1606 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
1607 memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
1609 while ((sctx->my_handlers[i].callback != NULL))
1610 sctx->my_handlers[i++].callback_cls = sctx;
1611 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers);
1617 * Obtain the server used by a service. Note that the server must NOT
1618 * be destroyed by the caller.
1620 * @param ctx the service context returned from the start function
1621 * @return handle to the server for this service, NULL if there is none
1623 struct GNUNET_SERVER_Handle *
1624 GNUNET_SERVICE_get_server (struct GNUNET_SERVICE_Context *ctx)
1631 * Stop a service that was started with "GNUNET_SERVICE_start".
1633 * @param sctx the service context returned from the start function
1636 GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx)
1645 GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name,
1648 GNUNET_CONFIGURATION_get_value_string (sctx->cfg, sctx->service_name,
1655 GAUGER (sctx->service_name, counter, mi.usmblks, "blocks");
1656 GNUNET_free (counter);
1660 if (GNUNET_SCHEDULER_NO_TASK != sctx->shutdown_task)
1662 GNUNET_SCHEDULER_cancel (sctx->shutdown_task);
1663 sctx->shutdown_task = GNUNET_SCHEDULER_NO_TASK;
1665 if (NULL != sctx->server)
1666 GNUNET_SERVER_destroy (sctx->server);
1667 GNUNET_free_non_null (sctx->my_handlers);
1668 if (NULL != sctx->addrs)
1671 while (NULL != sctx->addrs[i])
1672 GNUNET_free (sctx->addrs[i++]);
1673 GNUNET_free (sctx->addrs);
1675 GNUNET_free_non_null (sctx->addrlens);
1676 GNUNET_free_non_null (sctx->v4_denied);
1677 GNUNET_free_non_null (sctx->v6_denied);
1678 GNUNET_free_non_null (sctx->v4_allowed);
1679 GNUNET_free_non_null (sctx->v6_allowed);
1684 /* end of service.c */