2 * Copyright (c) 2012 The FreeBSD Foundation
5 * This software was developed by Edward Tomasz Napierala under sponsorship
6 * from the FreeBSD Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/types.h>
36 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <arpa/inet.h>
54 bool proxy_mode = false;
56 static volatile bool sighup_received = false;
57 static volatile bool sigterm_received = false;
58 static volatile bool sigalrm_received = false;
60 static int nchildren = 0;
66 fprintf(stderr, "usage: ctld [-d][-f config-file]\n");
71 checked_strdup(const char *s)
86 conf = calloc(1, sizeof(*conf));
89 TAILQ_INIT(&conf->conf_targets);
90 TAILQ_INIT(&conf->conf_auth_groups);
91 TAILQ_INIT(&conf->conf_portal_groups);
94 conf->conf_timeout = 60;
95 conf->conf_maxproc = 30;
101 conf_delete(struct conf *conf)
103 struct target *targ, *tmp;
104 struct auth_group *ag, *cagtmp;
105 struct portal_group *pg, *cpgtmp;
107 assert(conf->conf_pidfh == NULL);
109 TAILQ_FOREACH_SAFE(targ, &conf->conf_targets, t_next, tmp)
111 TAILQ_FOREACH_SAFE(ag, &conf->conf_auth_groups, ag_next, cagtmp)
112 auth_group_delete(ag);
113 TAILQ_FOREACH_SAFE(pg, &conf->conf_portal_groups, pg_next, cpgtmp)
114 portal_group_delete(pg);
115 free(conf->conf_pidfile_path);
120 auth_new(struct auth_group *ag)
124 auth = calloc(1, sizeof(*auth));
126 log_err(1, "calloc");
127 auth->a_auth_group = ag;
128 TAILQ_INSERT_TAIL(&ag->ag_auths, auth, a_next);
133 auth_delete(struct auth *auth)
135 TAILQ_REMOVE(&auth->a_auth_group->ag_auths, auth, a_next);
138 free(auth->a_secret);
139 free(auth->a_mutual_user);
140 free(auth->a_mutual_secret);
145 auth_find(const struct auth_group *ag, const char *user)
147 const struct auth *auth;
149 TAILQ_FOREACH(auth, &ag->ag_auths, a_next) {
150 if (strcmp(auth->a_user, user) == 0)
158 auth_check_secret_length(struct auth *auth)
162 len = strlen(auth->a_secret);
164 if (auth->a_auth_group->ag_name != NULL)
165 log_warnx("secret for user \"%s\", auth-group \"%s\", "
166 "is too long; it should be at most 16 characters "
167 "long", auth->a_user, auth->a_auth_group->ag_name);
169 log_warnx("secret for user \"%s\", target \"%s\", "
170 "is too long; it should be at most 16 characters "
171 "long", auth->a_user,
172 auth->a_auth_group->ag_target->t_name);
175 if (auth->a_auth_group->ag_name != NULL)
176 log_warnx("secret for user \"%s\", auth-group \"%s\", "
177 "is too short; it should be at least 12 characters "
178 "long", auth->a_user,
179 auth->a_auth_group->ag_name);
181 log_warnx("secret for user \"%s\", target \"%s\", "
182 "is too short; it should be at least 16 characters "
183 "long", auth->a_user,
184 auth->a_auth_group->ag_target->t_name);
187 if (auth->a_mutual_secret != NULL) {
188 len = strlen(auth->a_secret);
190 if (auth->a_auth_group->ag_name != NULL)
191 log_warnx("mutual secret for user \"%s\", "
192 "auth-group \"%s\", is too long; it should "
193 "be at most 16 characters long",
194 auth->a_user, auth->a_auth_group->ag_name);
196 log_warnx("mutual secret for user \"%s\", "
197 "target \"%s\", is too long; it should "
198 "be at most 16 characters long",
200 auth->a_auth_group->ag_target->t_name);
203 if (auth->a_auth_group->ag_name != NULL)
204 log_warnx("mutual secret for user \"%s\", "
205 "auth-group \"%s\", is too short; it "
206 "should be at least 12 characters long",
207 auth->a_user, auth->a_auth_group->ag_name);
209 log_warnx("mutual secret for user \"%s\", "
210 "target \"%s\", is too short; it should be "
211 "at least 16 characters long",
213 auth->a_auth_group->ag_target->t_name);
219 auth_new_chap(struct auth_group *ag, const char *user,
224 if (ag->ag_type == AG_TYPE_UNKNOWN)
225 ag->ag_type = AG_TYPE_CHAP;
226 if (ag->ag_type != AG_TYPE_CHAP) {
227 if (ag->ag_name != NULL)
228 log_warnx("cannot mix \"chap\" authentication with "
229 "other types for auth-group \"%s\"", ag->ag_name);
231 log_warnx("cannot mix \"chap\" authentication with "
232 "other types for target \"%s\"",
233 ag->ag_target->t_name);
238 auth->a_user = checked_strdup(user);
239 auth->a_secret = checked_strdup(secret);
241 auth_check_secret_length(auth);
247 auth_new_chap_mutual(struct auth_group *ag, const char *user,
248 const char *secret, const char *user2, const char *secret2)
252 if (ag->ag_type == AG_TYPE_UNKNOWN)
253 ag->ag_type = AG_TYPE_CHAP_MUTUAL;
254 if (ag->ag_type != AG_TYPE_CHAP_MUTUAL) {
255 if (ag->ag_name != NULL)
256 log_warnx("cannot mix \"chap-mutual\" authentication "
257 "with other types for auth-group \"%s\"",
260 log_warnx("cannot mix \"chap-mutual\" authentication "
261 "with other types for target \"%s\"",
262 ag->ag_target->t_name);
267 auth->a_user = checked_strdup(user);
268 auth->a_secret = checked_strdup(secret);
269 auth->a_mutual_user = checked_strdup(user2);
270 auth->a_mutual_secret = checked_strdup(secret2);
272 auth_check_secret_length(auth);
277 const struct auth_name *
278 auth_name_new(struct auth_group *ag, const char *name)
280 struct auth_name *an;
282 an = calloc(1, sizeof(*an));
284 log_err(1, "calloc");
285 an->an_auth_group = ag;
286 an->an_initator_name = checked_strdup(name);
287 TAILQ_INSERT_TAIL(&ag->ag_names, an, an_next);
292 auth_name_delete(struct auth_name *an)
294 TAILQ_REMOVE(&an->an_auth_group->ag_names, an, an_next);
296 free(an->an_initator_name);
301 auth_name_defined(const struct auth_group *ag)
303 if (TAILQ_EMPTY(&ag->ag_names))
308 const struct auth_name *
309 auth_name_find(const struct auth_group *ag, const char *name)
311 const struct auth_name *auth_name;
313 TAILQ_FOREACH(auth_name, &ag->ag_names, an_next) {
314 if (strcmp(auth_name->an_initator_name, name) == 0)
321 const struct auth_portal *
322 auth_portal_new(struct auth_group *ag, const char *portal)
324 struct auth_portal *ap;
325 char *net, *mask, *str, *tmp;
328 ap = calloc(1, sizeof(*ap));
330 log_err(1, "calloc");
331 ap->ap_auth_group = ag;
332 ap->ap_initator_portal = checked_strdup(portal);
333 mask = str = checked_strdup(portal);
334 net = strsep(&mask, "/");
340 if (net[len - 1] == ']')
342 if (strchr(net, ':') != NULL) {
343 struct sockaddr_in6 *sin6 =
344 (struct sockaddr_in6 *)&ap->ap_sa;
346 sin6->sin6_len = sizeof(*sin6);
347 sin6->sin6_family = AF_INET6;
348 if (inet_pton(AF_INET6, net, &sin6->sin6_addr) <= 0)
352 struct sockaddr_in *sin =
353 (struct sockaddr_in *)&ap->ap_sa;
355 sin->sin_len = sizeof(*sin);
356 sin->sin_family = AF_INET;
357 if (inet_pton(AF_INET, net, &sin->sin_addr) <= 0)
362 m = strtol(mask, &tmp, 0);
363 if (m < 0 || m > dm || tmp[0] != 0)
369 TAILQ_INSERT_TAIL(&ag->ag_portals, ap, ap_next);
373 log_errx(1, "Incorrect initiator portal '%s'", portal);
378 auth_portal_delete(struct auth_portal *ap)
380 TAILQ_REMOVE(&ap->ap_auth_group->ag_portals, ap, ap_next);
382 free(ap->ap_initator_portal);
387 auth_portal_defined(const struct auth_group *ag)
389 if (TAILQ_EMPTY(&ag->ag_portals))
394 const struct auth_portal *
395 auth_portal_find(const struct auth_group *ag, const struct sockaddr_storage *ss)
397 const struct auth_portal *ap;
398 const uint8_t *a, *b;
402 TAILQ_FOREACH(ap, &ag->ag_portals, ap_next) {
403 if (ap->ap_sa.ss_family != ss->ss_family)
405 if (ss->ss_family == AF_INET) {
406 a = (const uint8_t *)
407 &((const struct sockaddr_in *)ss)->sin_addr;
408 b = (const uint8_t *)
409 &((const struct sockaddr_in *)&ap->ap_sa)->sin_addr;
411 a = (const uint8_t *)
412 &((const struct sockaddr_in6 *)ss)->sin6_addr;
413 b = (const uint8_t *)
414 &((const struct sockaddr_in6 *)&ap->ap_sa)->sin6_addr;
416 for (i = 0; i < ap->ap_mask / 8; i++) {
420 if (ap->ap_mask % 8) {
421 bmask = 0xff << (8 - (ap->ap_mask % 8));
422 if ((a[i] & bmask) != (b[i] & bmask))
434 auth_group_new(struct conf *conf, const char *name)
436 struct auth_group *ag;
439 ag = auth_group_find(conf, name);
441 log_warnx("duplicated auth-group \"%s\"", name);
446 ag = calloc(1, sizeof(*ag));
448 log_err(1, "calloc");
450 ag->ag_name = checked_strdup(name);
451 TAILQ_INIT(&ag->ag_auths);
452 TAILQ_INIT(&ag->ag_names);
453 TAILQ_INIT(&ag->ag_portals);
455 TAILQ_INSERT_TAIL(&conf->conf_auth_groups, ag, ag_next);
461 auth_group_delete(struct auth_group *ag)
463 struct auth *auth, *auth_tmp;
464 struct auth_name *auth_name, *auth_name_tmp;
465 struct auth_portal *auth_portal, *auth_portal_tmp;
467 TAILQ_REMOVE(&ag->ag_conf->conf_auth_groups, ag, ag_next);
469 TAILQ_FOREACH_SAFE(auth, &ag->ag_auths, a_next, auth_tmp)
471 TAILQ_FOREACH_SAFE(auth_name, &ag->ag_names, an_next, auth_name_tmp)
472 auth_name_delete(auth_name);
473 TAILQ_FOREACH_SAFE(auth_portal, &ag->ag_portals, ap_next,
475 auth_portal_delete(auth_portal);
481 auth_group_find(const struct conf *conf, const char *name)
483 struct auth_group *ag;
485 TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) {
486 if (ag->ag_name != NULL && strcmp(ag->ag_name, name) == 0)
494 auth_group_set_type(struct auth_group *ag, int type)
497 if (ag->ag_type == AG_TYPE_UNKNOWN) {
502 if (ag->ag_type == type)
509 auth_group_set_type_str(struct auth_group *ag, const char *str)
513 if (strcmp(str, "none") == 0) {
514 type = AG_TYPE_NO_AUTHENTICATION;
515 } else if (strcmp(str, "deny") == 0) {
517 } else if (strcmp(str, "chap") == 0) {
519 } else if (strcmp(str, "chap-mutual") == 0) {
520 type = AG_TYPE_CHAP_MUTUAL;
522 if (ag->ag_name != NULL)
523 log_warnx("invalid auth-type \"%s\" for auth-group "
524 "\"%s\"", str, ag->ag_name);
526 log_warnx("invalid auth-type \"%s\" for target "
527 "\"%s\"", str, ag->ag_target->t_name);
531 error = auth_group_set_type(ag, type);
533 if (ag->ag_name != NULL)
534 log_warnx("cannot set auth-type to \"%s\" for "
535 "auth-group \"%s\"; already has a different "
536 "type", str, ag->ag_name);
538 log_warnx("cannot set auth-type to \"%s\" for target "
539 "\"%s\"; already has a different type",
540 str, ag->ag_target->t_name);
547 static struct portal *
548 portal_new(struct portal_group *pg)
550 struct portal *portal;
552 portal = calloc(1, sizeof(*portal));
554 log_err(1, "calloc");
555 TAILQ_INIT(&portal->p_targets);
556 portal->p_portal_group = pg;
557 TAILQ_INSERT_TAIL(&pg->pg_portals, portal, p_next);
562 portal_delete(struct portal *portal)
564 TAILQ_REMOVE(&portal->p_portal_group->pg_portals, portal, p_next);
565 freeaddrinfo(portal->p_ai);
566 free(portal->p_listen);
570 struct portal_group *
571 portal_group_new(struct conf *conf, const char *name)
573 struct portal_group *pg;
575 pg = portal_group_find(conf, name);
577 log_warnx("duplicated portal-group \"%s\"", name);
581 pg = calloc(1, sizeof(*pg));
583 log_err(1, "calloc");
584 pg->pg_name = checked_strdup(name);
585 TAILQ_INIT(&pg->pg_portals);
587 conf->conf_last_portal_group_tag++;
588 pg->pg_tag = conf->conf_last_portal_group_tag;
589 TAILQ_INSERT_TAIL(&conf->conf_portal_groups, pg, pg_next);
595 portal_group_delete(struct portal_group *pg)
597 struct portal *portal, *tmp;
599 TAILQ_REMOVE(&pg->pg_conf->conf_portal_groups, pg, pg_next);
601 TAILQ_FOREACH_SAFE(portal, &pg->pg_portals, p_next, tmp)
602 portal_delete(portal);
607 struct portal_group *
608 portal_group_find(const struct conf *conf, const char *name)
610 struct portal_group *pg;
612 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
613 if (strcmp(pg->pg_name, name) == 0)
621 portal_group_add_listen(struct portal_group *pg, const char *value, bool iser)
623 struct addrinfo hints;
624 struct portal *portal;
625 char *addr, *ch, *arg;
627 int error, colons = 0;
629 portal = portal_new(pg);
630 portal->p_listen = checked_strdup(value);
631 portal->p_iser = iser;
633 arg = portal->p_listen;
634 if (arg[0] == '\0') {
635 log_warnx("empty listen address");
636 free(portal->p_listen);
642 * IPv6 address in square brackets, perhaps with port.
645 addr = strsep(&arg, "]");
647 log_warnx("invalid listen address %s",
649 free(portal->p_listen);
653 if (arg[0] == '\0') {
655 } else if (arg[0] == ':') {
658 log_warnx("invalid listen address %s",
660 free(portal->p_listen);
666 * Either IPv6 address without brackets - and without
667 * a port - or IPv4 address. Just count the colons.
669 for (ch = arg; *ch != '\0'; ch++) {
677 addr = strsep(&arg, ":");
685 memset(&hints, 0, sizeof(hints));
686 hints.ai_family = PF_UNSPEC;
687 hints.ai_socktype = SOCK_STREAM;
688 hints.ai_flags = AI_PASSIVE;
690 error = getaddrinfo(addr, port, &hints, &portal->p_ai);
692 log_warnx("getaddrinfo for %s failed: %s",
693 portal->p_listen, gai_strerror(error));
694 free(portal->p_listen);
700 * XXX: getaddrinfo(3) may return multiple addresses; we should turn
701 * those into multiple portals.
708 valid_hex(const char ch)
740 valid_iscsi_name(const char *name)
744 if (strlen(name) >= MAX_NAME_LEN) {
745 log_warnx("overlong name for target \"%s\"; max length allowed "
746 "by iSCSI specification is %d characters",
752 * In the cases below, we don't return an error, just in case the admin
753 * was right, and we're wrong.
755 if (strncasecmp(name, "iqn.", strlen("iqn.")) == 0) {
756 for (i = strlen("iqn."); name[i] != '\0'; i++) {
758 * XXX: We should verify UTF-8 normalisation, as defined
759 * by 3.2.6.2: iSCSI Name Encoding.
761 if (isalnum(name[i]))
763 if (name[i] == '-' || name[i] == '.' || name[i] == ':')
765 log_warnx("invalid character \"%c\" in target name "
766 "\"%s\"; allowed characters are letters, digits, "
767 "'-', '.', and ':'", name[i], name);
771 * XXX: Check more stuff: valid date and a valid reversed domain.
773 } else if (strncasecmp(name, "eui.", strlen("eui.")) == 0) {
774 if (strlen(name) != strlen("eui.") + 16)
775 log_warnx("invalid target name \"%s\"; the \"eui.\" "
776 "should be followed by exactly 16 hexadecimal "
778 for (i = strlen("eui."); name[i] != '\0'; i++) {
779 if (!valid_hex(name[i])) {
780 log_warnx("invalid character \"%c\" in target "
781 "name \"%s\"; allowed characters are 1-9 "
782 "and A-F", name[i], name);
786 } else if (strncasecmp(name, "naa.", strlen("naa.")) == 0) {
787 if (strlen(name) > strlen("naa.") + 32)
788 log_warnx("invalid target name \"%s\"; the \"naa.\" "
789 "should be followed by at most 32 hexadecimal "
791 for (i = strlen("naa."); name[i] != '\0'; i++) {
792 if (!valid_hex(name[i])) {
793 log_warnx("invalid character \"%c\" in target "
794 "name \"%s\"; allowed characters are 1-9 "
795 "and A-F", name[i], name);
800 log_warnx("invalid target name \"%s\"; should start with "
801 "either \".iqn\", \"eui.\", or \"naa.\"",
808 target_new(struct conf *conf, const char *name)
813 targ = target_find(conf, name);
815 log_warnx("duplicated target \"%s\"", name);
818 if (valid_iscsi_name(name) == false) {
819 log_warnx("target name \"%s\" is invalid", name);
822 targ = calloc(1, sizeof(*targ));
824 log_err(1, "calloc");
825 targ->t_name = checked_strdup(name);
828 * RFC 3722 requires us to normalize the name to lowercase.
831 for (i = 0; i < len; i++)
832 targ->t_name[i] = tolower(targ->t_name[i]);
834 TAILQ_INIT(&targ->t_luns);
836 TAILQ_INSERT_TAIL(&conf->conf_targets, targ, t_next);
842 target_delete(struct target *targ)
844 struct lun *lun, *tmp;
846 TAILQ_REMOVE(&targ->t_conf->conf_targets, targ, t_next);
848 TAILQ_FOREACH_SAFE(lun, &targ->t_luns, l_next, tmp)
855 target_find(struct conf *conf, const char *name)
859 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
860 if (strcasecmp(targ->t_name, name) == 0)
868 lun_new(struct target *targ, int lun_id)
872 lun = lun_find(targ, lun_id);
874 log_warnx("duplicated lun %d for target \"%s\"",
875 lun_id, targ->t_name);
879 lun = calloc(1, sizeof(*lun));
881 log_err(1, "calloc");
883 TAILQ_INIT(&lun->l_options);
884 lun->l_target = targ;
885 TAILQ_INSERT_TAIL(&targ->t_luns, lun, l_next);
891 lun_delete(struct lun *lun)
893 struct lun_option *lo, *tmp;
895 TAILQ_REMOVE(&lun->l_target->t_luns, lun, l_next);
897 TAILQ_FOREACH_SAFE(lo, &lun->l_options, lo_next, tmp)
898 lun_option_delete(lo);
899 free(lun->l_backend);
900 free(lun->l_device_id);
907 lun_find(const struct target *targ, int lun_id)
911 TAILQ_FOREACH(lun, &targ->t_luns, l_next) {
912 if (lun->l_lun == lun_id)
920 lun_set_backend(struct lun *lun, const char *value)
922 free(lun->l_backend);
923 lun->l_backend = checked_strdup(value);
927 lun_set_blocksize(struct lun *lun, size_t value)
930 lun->l_blocksize = value;
934 lun_set_device_id(struct lun *lun, const char *value)
936 free(lun->l_device_id);
937 lun->l_device_id = checked_strdup(value);
941 lun_set_path(struct lun *lun, const char *value)
944 lun->l_path = checked_strdup(value);
948 lun_set_serial(struct lun *lun, const char *value)
951 lun->l_serial = checked_strdup(value);
955 lun_set_size(struct lun *lun, size_t value)
962 lun_set_ctl_lun(struct lun *lun, uint32_t value)
965 lun->l_ctl_lun = value;
969 lun_option_new(struct lun *lun, const char *name, const char *value)
971 struct lun_option *lo;
973 lo = lun_option_find(lun, name);
975 log_warnx("duplicated lun option %s for lun %d, target \"%s\"",
976 name, lun->l_lun, lun->l_target->t_name);
980 lo = calloc(1, sizeof(*lo));
982 log_err(1, "calloc");
983 lo->lo_name = checked_strdup(name);
984 lo->lo_value = checked_strdup(value);
986 TAILQ_INSERT_TAIL(&lun->l_options, lo, lo_next);
992 lun_option_delete(struct lun_option *lo)
995 TAILQ_REMOVE(&lo->lo_lun->l_options, lo, lo_next);
1003 lun_option_find(const struct lun *lun, const char *name)
1005 struct lun_option *lo;
1007 TAILQ_FOREACH(lo, &lun->l_options, lo_next) {
1008 if (strcmp(lo->lo_name, name) == 0)
1016 lun_option_set(struct lun_option *lo, const char *value)
1020 lo->lo_value = checked_strdup(value);
1023 static struct connection *
1024 connection_new(struct portal *portal, int fd, const char *host,
1025 const struct sockaddr *client_sa)
1027 struct connection *conn;
1029 conn = calloc(1, sizeof(*conn));
1031 log_err(1, "calloc");
1032 conn->conn_portal = portal;
1033 conn->conn_socket = fd;
1034 conn->conn_initiator_addr = checked_strdup(host);
1035 memcpy(&conn->conn_initiator_sa, client_sa, client_sa->sa_len);
1038 * Default values, from RFC 3720, section 12.
1040 conn->conn_max_data_segment_length = 8192;
1041 conn->conn_max_burst_length = 262144;
1042 conn->conn_immediate_data = true;
1049 conf_print(struct conf *conf)
1051 struct auth_group *ag;
1053 struct auth_name *auth_name;
1054 struct auth_portal *auth_portal;
1055 struct portal_group *pg;
1056 struct portal *portal;
1057 struct target *targ;
1059 struct lun_option *lo;
1061 TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) {
1062 fprintf(stderr, "auth-group %s {\n", ag->ag_name);
1063 TAILQ_FOREACH(auth, &ag->ag_auths, a_next)
1064 fprintf(stderr, "\t chap-mutual %s %s %s %s\n",
1065 auth->a_user, auth->a_secret,
1066 auth->a_mutual_user, auth->a_mutual_secret);
1067 TAILQ_FOREACH(auth_name, &ag->ag_names, an_next)
1068 fprintf(stderr, "\t initiator-name %s\n",
1069 auth_name->an_initator_name);
1070 TAILQ_FOREACH(auth_portal, &ag->ag_portals, an_next)
1071 fprintf(stderr, "\t initiator-portal %s\n",
1072 auth_portal->an_initator_portal);
1073 fprintf(stderr, "}\n");
1075 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
1076 fprintf(stderr, "portal-group %s {\n", pg->pg_name);
1077 TAILQ_FOREACH(portal, &pg->pg_portals, p_next)
1078 fprintf(stderr, "\t listen %s\n", portal->p_listen);
1079 fprintf(stderr, "}\n");
1081 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
1082 fprintf(stderr, "target %s {\n", targ->t_name);
1083 if (targ->t_alias != NULL)
1084 fprintf(stderr, "\t alias %s\n", targ->t_alias);
1085 TAILQ_FOREACH(lun, &targ->t_luns, l_next) {
1086 fprintf(stderr, "\tlun %d {\n", lun->l_lun);
1087 fprintf(stderr, "\t\tpath %s\n", lun->l_path);
1088 TAILQ_FOREACH(lo, &lun->l_options, lo_next)
1089 fprintf(stderr, "\t\toption %s %s\n",
1090 lo->lo_name, lo->lo_value);
1091 fprintf(stderr, "\t}\n");
1093 fprintf(stderr, "}\n");
1099 conf_verify_lun(struct lun *lun)
1101 const struct lun *lun2;
1102 const struct target *targ2;
1104 if (lun->l_backend == NULL)
1105 lun_set_backend(lun, "block");
1106 if (strcmp(lun->l_backend, "block") == 0) {
1107 if (lun->l_path == NULL) {
1108 log_warnx("missing path for lun %d, target \"%s\"",
1109 lun->l_lun, lun->l_target->t_name);
1112 } else if (strcmp(lun->l_backend, "ramdisk") == 0) {
1113 if (lun->l_size == 0) {
1114 log_warnx("missing size for ramdisk-backed lun %d, "
1115 "target \"%s\"", lun->l_lun, lun->l_target->t_name);
1118 if (lun->l_path != NULL) {
1119 log_warnx("path must not be specified "
1120 "for ramdisk-backed lun %d, target \"%s\"",
1121 lun->l_lun, lun->l_target->t_name);
1125 if (lun->l_lun < 0 || lun->l_lun > 255) {
1126 log_warnx("invalid lun number for lun %d, target \"%s\"; "
1127 "must be between 0 and 255", lun->l_lun,
1128 lun->l_target->t_name);
1131 if (lun->l_blocksize == 0) {
1132 lun_set_blocksize(lun, DEFAULT_BLOCKSIZE);
1133 } else if (lun->l_blocksize < 0) {
1134 log_warnx("invalid blocksize for lun %d, target \"%s\"; "
1135 "must be larger than 0", lun->l_lun, lun->l_target->t_name);
1138 if (lun->l_size != 0 && lun->l_size % lun->l_blocksize != 0) {
1139 log_warnx("invalid size for lun %d, target \"%s\"; "
1140 "must be multiple of blocksize", lun->l_lun,
1141 lun->l_target->t_name);
1144 TAILQ_FOREACH(targ2, &lun->l_target->t_conf->conf_targets, t_next) {
1145 TAILQ_FOREACH(lun2, &targ2->t_luns, l_next) {
1148 if (lun->l_path != NULL && lun2->l_path != NULL &&
1149 strcmp(lun->l_path, lun2->l_path) == 0) {
1150 log_debugx("WARNING: path \"%s\" duplicated "
1151 "between lun %d, target \"%s\", and "
1152 "lun %d, target \"%s\"", lun->l_path,
1153 lun->l_lun, lun->l_target->t_name,
1154 lun2->l_lun, lun2->l_target->t_name);
1163 conf_verify(struct conf *conf)
1165 struct auth_group *ag;
1166 struct portal_group *pg;
1167 struct target *targ;
1172 if (conf->conf_pidfile_path == NULL)
1173 conf->conf_pidfile_path = checked_strdup(DEFAULT_PIDFILE);
1175 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
1176 if (targ->t_auth_group == NULL) {
1177 targ->t_auth_group = auth_group_find(conf,
1179 assert(targ->t_auth_group != NULL);
1181 if (targ->t_portal_group == NULL) {
1182 targ->t_portal_group = portal_group_find(conf,
1184 assert(targ->t_portal_group != NULL);
1187 TAILQ_FOREACH(lun, &targ->t_luns, l_next) {
1188 error = conf_verify_lun(lun);
1194 log_warnx("no LUNs defined for target \"%s\"",
1198 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
1199 assert(pg->pg_name != NULL);
1200 if (pg->pg_discovery_auth_group == NULL) {
1201 pg->pg_discovery_auth_group =
1202 auth_group_find(conf, "default");
1203 assert(pg->pg_discovery_auth_group != NULL);
1206 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
1207 if (targ->t_portal_group == pg)
1211 if (strcmp(pg->pg_name, "default") != 0)
1212 log_warnx("portal-group \"%s\" not assigned "
1213 "to any target", pg->pg_name);
1214 pg->pg_unassigned = true;
1216 pg->pg_unassigned = false;
1218 TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) {
1219 if (ag->ag_name == NULL)
1220 assert(ag->ag_target != NULL);
1222 assert(ag->ag_target == NULL);
1224 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
1225 if (targ->t_auth_group == ag)
1228 if (targ == NULL && ag->ag_name != NULL &&
1229 strcmp(ag->ag_name, "default") != 0 &&
1230 strcmp(ag->ag_name, "no-authentication") != 0 &&
1231 strcmp(ag->ag_name, "no-access") != 0) {
1232 log_warnx("auth-group \"%s\" not assigned "
1233 "to any target", ag->ag_name);
1241 conf_apply(struct conf *oldconf, struct conf *newconf)
1243 struct target *oldtarg, *newtarg, *tmptarg;
1244 struct lun *oldlun, *newlun, *tmplun;
1245 struct portal_group *oldpg, *newpg;
1246 struct portal *oldp, *newp;
1248 int changed, cumulated_error = 0, error;
1251 if (oldconf->conf_debug != newconf->conf_debug) {
1252 log_debugx("changing debug level to %d", newconf->conf_debug);
1253 log_init(newconf->conf_debug);
1256 if (oldconf->conf_pidfh != NULL) {
1257 assert(oldconf->conf_pidfile_path != NULL);
1258 if (newconf->conf_pidfile_path != NULL &&
1259 strcmp(oldconf->conf_pidfile_path,
1260 newconf->conf_pidfile_path) == 0) {
1261 newconf->conf_pidfh = oldconf->conf_pidfh;
1262 oldconf->conf_pidfh = NULL;
1264 log_debugx("removing pidfile %s",
1265 oldconf->conf_pidfile_path);
1266 pidfile_remove(oldconf->conf_pidfh);
1267 oldconf->conf_pidfh = NULL;
1271 if (newconf->conf_pidfh == NULL && newconf->conf_pidfile_path != NULL) {
1272 log_debugx("opening pidfile %s", newconf->conf_pidfile_path);
1273 newconf->conf_pidfh =
1274 pidfile_open(newconf->conf_pidfile_path, 0600, &otherpid);
1275 if (newconf->conf_pidfh == NULL) {
1276 if (errno == EEXIST)
1277 log_errx(1, "daemon already running, pid: %jd.",
1278 (intmax_t)otherpid);
1279 log_err(1, "cannot open or create pidfile \"%s\"",
1280 newconf->conf_pidfile_path);
1285 * XXX: If target or lun removal fails, we should somehow "move"
1286 * the old lun or target into newconf, so that subsequent
1287 * conf_apply() would try to remove them again. That would
1288 * be somewhat hairy, though, and lun deletion failures don't
1289 * really happen, so leave it as it is for now.
1291 TAILQ_FOREACH_SAFE(oldtarg, &oldconf->conf_targets, t_next, tmptarg) {
1293 * First, remove any targets present in the old configuration
1294 * and missing in the new one.
1296 newtarg = target_find(newconf, oldtarg->t_name);
1297 if (newtarg == NULL) {
1298 TAILQ_FOREACH_SAFE(oldlun, &oldtarg->t_luns, l_next,
1300 log_debugx("target %s not found in new "
1301 "configuration; removing its lun %d, "
1302 "backed by CTL lun %d",
1303 oldtarg->t_name, oldlun->l_lun,
1305 error = kernel_lun_remove(oldlun);
1307 log_warnx("failed to remove lun %d, "
1308 "target %s, CTL lun %d",
1309 oldlun->l_lun, oldtarg->t_name,
1315 kernel_port_remove(oldtarg);
1316 target_delete(oldtarg);
1321 * Second, remove any LUNs present in the old target
1322 * and missing in the new one.
1324 TAILQ_FOREACH_SAFE(oldlun, &oldtarg->t_luns, l_next, tmplun) {
1325 newlun = lun_find(newtarg, oldlun->l_lun);
1326 if (newlun == NULL) {
1327 log_debugx("lun %d, target %s, CTL lun %d "
1328 "not found in new configuration; "
1329 "removing", oldlun->l_lun, oldtarg->t_name,
1331 error = kernel_lun_remove(oldlun);
1333 log_warnx("failed to remove lun %d, "
1334 "target %s, CTL lun %d",
1335 oldlun->l_lun, oldtarg->t_name,
1344 * Also remove the LUNs changed by more than size.
1347 assert(oldlun->l_backend != NULL);
1348 assert(newlun->l_backend != NULL);
1349 if (strcmp(newlun->l_backend, oldlun->l_backend) != 0) {
1350 log_debugx("backend for lun %d, target %s, "
1351 "CTL lun %d changed; removing",
1352 oldlun->l_lun, oldtarg->t_name,
1356 if (oldlun->l_blocksize != newlun->l_blocksize) {
1357 log_debugx("blocksize for lun %d, target %s, "
1358 "CTL lun %d changed; removing",
1359 oldlun->l_lun, oldtarg->t_name,
1363 if (newlun->l_device_id != NULL &&
1364 (oldlun->l_device_id == NULL ||
1365 strcmp(oldlun->l_device_id, newlun->l_device_id) !=
1367 log_debugx("device-id for lun %d, target %s, "
1368 "CTL lun %d changed; removing",
1369 oldlun->l_lun, oldtarg->t_name,
1373 if (newlun->l_path != NULL &&
1374 (oldlun->l_path == NULL ||
1375 strcmp(oldlun->l_path, newlun->l_path) != 0)) {
1376 log_debugx("path for lun %d, target %s, "
1377 "CTL lun %d, changed; removing",
1378 oldlun->l_lun, oldtarg->t_name,
1382 if (newlun->l_serial != NULL &&
1383 (oldlun->l_serial == NULL ||
1384 strcmp(oldlun->l_serial, newlun->l_serial) != 0)) {
1385 log_debugx("serial for lun %d, target %s, "
1386 "CTL lun %d changed; removing",
1387 oldlun->l_lun, oldtarg->t_name,
1392 error = kernel_lun_remove(oldlun);
1394 log_warnx("failed to remove lun %d, "
1395 "target %s, CTL lun %d",
1396 oldlun->l_lun, oldtarg->t_name,
1404 lun_set_ctl_lun(newlun, oldlun->l_ctl_lun);
1409 * Now add new targets or modify existing ones.
1411 TAILQ_FOREACH(newtarg, &newconf->conf_targets, t_next) {
1412 oldtarg = target_find(oldconf, newtarg->t_name);
1414 TAILQ_FOREACH_SAFE(newlun, &newtarg->t_luns, l_next, tmplun) {
1415 if (oldtarg != NULL) {
1416 oldlun = lun_find(oldtarg, newlun->l_lun);
1417 if (oldlun != NULL) {
1418 if (newlun->l_size != oldlun->l_size) {
1419 log_debugx("resizing lun %d, "
1420 "target %s, CTL lun %d",
1425 kernel_lun_resize(newlun);
1427 log_warnx("failed to "
1440 log_debugx("adding lun %d, target %s",
1441 newlun->l_lun, newtarg->t_name);
1442 error = kernel_lun_add(newlun);
1444 log_warnx("failed to add lun %d, target %s",
1445 newlun->l_lun, newtarg->t_name);
1450 if (oldtarg == NULL)
1451 kernel_port_add(newtarg);
1455 * Go through the new portals, opening the sockets as neccessary.
1457 TAILQ_FOREACH(newpg, &newconf->conf_portal_groups, pg_next) {
1458 if (newpg->pg_unassigned) {
1459 log_debugx("not listening on portal-group \"%s\", "
1460 "not assigned to any target",
1464 TAILQ_FOREACH(newp, &newpg->pg_portals, p_next) {
1466 * Try to find already open portal and reuse
1467 * the listening socket. We don't care about
1468 * what portal or portal group that was, what
1469 * matters is the listening address.
1471 TAILQ_FOREACH(oldpg, &oldconf->conf_portal_groups,
1473 TAILQ_FOREACH(oldp, &oldpg->pg_portals,
1475 if (strcmp(newp->p_listen,
1476 oldp->p_listen) == 0 &&
1477 oldp->p_socket > 0) {
1485 if (newp->p_socket > 0) {
1487 * We're done with this portal.
1492 #ifdef ICL_KERNEL_PROXY
1494 newpg->pg_conf->conf_portal_id++;
1495 newp->p_id = newpg->pg_conf->conf_portal_id;
1496 log_debugx("listening on %s, portal-group "
1497 "\"%s\", portal id %d, using ICL proxy",
1498 newp->p_listen, newpg->pg_name, newp->p_id);
1499 kernel_listen(newp->p_ai, newp->p_iser,
1504 assert(proxy_mode == false);
1505 assert(newp->p_iser == false);
1507 log_debugx("listening on %s, portal-group \"%s\"",
1508 newp->p_listen, newpg->pg_name);
1509 newp->p_socket = socket(newp->p_ai->ai_family,
1510 newp->p_ai->ai_socktype,
1511 newp->p_ai->ai_protocol);
1512 if (newp->p_socket < 0) {
1513 log_warn("socket(2) failed for %s",
1518 error = setsockopt(newp->p_socket, SOL_SOCKET,
1519 SO_REUSEADDR, &one, sizeof(one));
1521 log_warn("setsockopt(SO_REUSEADDR) failed "
1522 "for %s", newp->p_listen);
1523 close(newp->p_socket);
1528 error = bind(newp->p_socket, newp->p_ai->ai_addr,
1529 newp->p_ai->ai_addrlen);
1531 log_warn("bind(2) failed for %s",
1533 close(newp->p_socket);
1538 error = listen(newp->p_socket, -1);
1540 log_warn("listen(2) failed for %s",
1542 close(newp->p_socket);
1551 * Go through the no longer used sockets, closing them.
1553 TAILQ_FOREACH(oldpg, &oldconf->conf_portal_groups, pg_next) {
1554 TAILQ_FOREACH(oldp, &oldpg->pg_portals, p_next) {
1555 if (oldp->p_socket <= 0)
1557 log_debugx("closing socket for %s, portal-group \"%s\"",
1558 oldp->p_listen, oldpg->pg_name);
1559 close(oldp->p_socket);
1564 return (cumulated_error);
1571 return (sigalrm_received);
1575 sigalrm_handler(int dummy __unused)
1578 * It would be easiest to just log an error and exit. We can't
1579 * do this, though, because log_errx() is not signal safe, since
1580 * it calls syslog(3). Instead, set a flag checked by pdu_send()
1581 * and pdu_receive(), to call log_errx() there. Should they fail
1582 * to notice, we'll exit here one second later.
1584 if (sigalrm_received) {
1586 * Oh well. Just give up and quit.
1591 sigalrm_received = true;
1595 set_timeout(const struct conf *conf)
1597 struct sigaction sa;
1598 struct itimerval itv;
1601 if (conf->conf_timeout <= 0) {
1602 log_debugx("session timeout disabled");
1606 bzero(&sa, sizeof(sa));
1607 sa.sa_handler = sigalrm_handler;
1608 sigfillset(&sa.sa_mask);
1609 error = sigaction(SIGALRM, &sa, NULL);
1611 log_err(1, "sigaction");
1614 * First SIGALRM will arive after conf_timeout seconds.
1615 * If we do nothing, another one will arrive a second later.
1617 bzero(&itv, sizeof(itv));
1618 itv.it_interval.tv_sec = 1;
1619 itv.it_value.tv_sec = conf->conf_timeout;
1621 log_debugx("setting session timeout to %d seconds",
1622 conf->conf_timeout);
1623 error = setitimer(ITIMER_REAL, &itv, NULL);
1625 log_err(1, "setitimer");
1629 wait_for_children(bool block)
1637 * If "block" is true, wait for at least one process.
1639 if (block && num == 0)
1640 pid = wait4(-1, &status, 0, NULL);
1642 pid = wait4(-1, &status, WNOHANG, NULL);
1645 if (WIFSIGNALED(status)) {
1646 log_warnx("child process %d terminated with signal %d",
1647 pid, WTERMSIG(status));
1648 } else if (WEXITSTATUS(status) != 0) {
1649 log_warnx("child process %d terminated with exit status %d",
1650 pid, WEXITSTATUS(status));
1652 log_debugx("child process %d terminated gracefully", pid);
1661 handle_connection(struct portal *portal, int fd,
1662 const struct sockaddr *client_sa, bool dont_fork)
1664 struct connection *conn;
1667 char host[NI_MAXHOST + 1];
1670 conf = portal->p_portal_group->pg_conf;
1673 log_debugx("incoming connection; not forking due to -d flag");
1675 nchildren -= wait_for_children(false);
1676 assert(nchildren >= 0);
1678 while (conf->conf_maxproc > 0 && nchildren >= conf->conf_maxproc) {
1679 log_debugx("maxproc limit of %d child processes hit; "
1680 "waiting for child process to exit", conf->conf_maxproc);
1681 nchildren -= wait_for_children(true);
1682 assert(nchildren >= 0);
1684 log_debugx("incoming connection; forking child process #%d",
1695 pidfile_close(conf->conf_pidfh);
1697 error = getnameinfo(client_sa, client_sa->sa_len,
1698 host, sizeof(host), NULL, 0, NI_NUMERICHOST);
1700 log_errx(1, "getnameinfo: %s", gai_strerror(error));
1702 log_debugx("accepted connection from %s; portal group \"%s\"",
1703 host, portal->p_portal_group->pg_name);
1704 log_set_peer_addr(host);
1705 setproctitle("%s", host);
1707 conn = connection_new(portal, fd, host, client_sa);
1711 if (conn->conn_session_type == CONN_SESSION_TYPE_NORMAL) {
1712 kernel_handoff(conn);
1713 log_debugx("connection handed off to the kernel");
1715 assert(conn->conn_session_type == CONN_SESSION_TYPE_DISCOVERY);
1718 log_debugx("nothing more to do; exiting");
1723 fd_add(int fd, fd_set *fdset, int nfds)
1727 * Skip sockets which we failed to bind.
1739 main_loop(struct conf *conf, bool dont_fork)
1741 struct portal_group *pg;
1742 struct portal *portal;
1743 struct sockaddr_storage client_sa;
1744 socklen_t client_salen;
1745 #ifdef ICL_KERNEL_PROXY
1750 int error, nfds, client_fd;
1752 pidfile_write(conf->conf_pidfh);
1755 if (sighup_received || sigterm_received)
1758 #ifdef ICL_KERNEL_PROXY
1760 client_salen = sizeof(client_sa);
1761 kernel_accept(&connection_id, &portal_id,
1762 (struct sockaddr *)&client_sa, &client_salen);
1763 assert(client_salen >= client_sa.ss_len);
1765 log_debugx("incoming connection, id %d, portal id %d",
1766 connection_id, portal_id);
1767 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
1768 TAILQ_FOREACH(portal, &pg->pg_portals, p_next) {
1769 if (portal->p_id == portal_id) {
1775 log_errx(1, "kernel returned invalid portal_id %d",
1779 handle_connection(portal, connection_id,
1780 (struct sockaddr *)&client_sa, dont_fork);
1783 assert(proxy_mode == false);
1787 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
1788 TAILQ_FOREACH(portal, &pg->pg_portals, p_next)
1789 nfds = fd_add(portal->p_socket, &fdset, nfds);
1791 error = select(nfds + 1, &fdset, NULL, NULL, NULL);
1795 log_err(1, "select");
1797 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
1798 TAILQ_FOREACH(portal, &pg->pg_portals, p_next) {
1799 if (!FD_ISSET(portal->p_socket, &fdset))
1801 client_salen = sizeof(client_sa);
1802 client_fd = accept(portal->p_socket,
1803 (struct sockaddr *)&client_sa,
1806 log_err(1, "accept");
1807 assert(client_salen >= client_sa.ss_len);
1809 handle_connection(portal, client_fd,
1810 (struct sockaddr *)&client_sa,
1815 #ifdef ICL_KERNEL_PROXY
1822 sighup_handler(int dummy __unused)
1825 sighup_received = true;
1829 sigterm_handler(int dummy __unused)
1832 sigterm_received = true;
1836 sigchld_handler(int dummy __unused)
1840 * The only purpose of this handler is to make SIGCHLD
1841 * interrupt the ISCSIDWAIT ioctl(2), so we can call
1842 * wait_for_children().
1847 register_signals(void)
1849 struct sigaction sa;
1852 bzero(&sa, sizeof(sa));
1853 sa.sa_handler = sighup_handler;
1854 sigfillset(&sa.sa_mask);
1855 error = sigaction(SIGHUP, &sa, NULL);
1857 log_err(1, "sigaction");
1859 sa.sa_handler = sigterm_handler;
1860 error = sigaction(SIGTERM, &sa, NULL);
1862 log_err(1, "sigaction");
1864 sa.sa_handler = sigterm_handler;
1865 error = sigaction(SIGINT, &sa, NULL);
1867 log_err(1, "sigaction");
1869 sa.sa_handler = sigchld_handler;
1870 error = sigaction(SIGCHLD, &sa, NULL);
1872 log_err(1, "sigaction");
1876 main(int argc, char **argv)
1878 struct conf *oldconf, *newconf, *tmpconf;
1879 const char *config_path = DEFAULT_CONFIG_PATH;
1880 int debug = 0, ch, error;
1881 bool dont_daemonize = false;
1883 while ((ch = getopt(argc, argv, "df:R")) != -1) {
1886 dont_daemonize = true;
1890 config_path = optarg;
1893 #ifndef ICL_KERNEL_PROXY
1894 log_errx(1, "ctld(8) compiled without ICL_KERNEL_PROXY "
1895 "does not support iSER protocol");
1911 oldconf = conf_new_from_kernel();
1912 newconf = conf_new_from_file(config_path);
1913 if (newconf == NULL)
1914 log_errx(1, "configuration error; exiting");
1916 oldconf->conf_debug = debug;
1917 newconf->conf_debug = debug;
1920 error = conf_apply(oldconf, newconf);
1922 log_errx(1, "failed to apply configuration; exiting");
1924 conf_delete(oldconf);
1929 if (dont_daemonize == false) {
1930 log_debugx("daemonizing");
1931 if (daemon(0, 0) == -1) {
1932 log_warn("cannot daemonize");
1933 pidfile_remove(newconf->conf_pidfh);
1939 main_loop(newconf, dont_daemonize);
1940 if (sighup_received) {
1941 sighup_received = false;
1942 log_debugx("received SIGHUP, reloading configuration");
1943 tmpconf = conf_new_from_file(config_path);
1944 if (tmpconf == NULL) {
1945 log_warnx("configuration error, "
1946 "continuing with old configuration");
1949 tmpconf->conf_debug = debug;
1952 error = conf_apply(oldconf, newconf);
1954 log_warnx("failed to reload "
1956 conf_delete(oldconf);
1959 } else if (sigterm_received) {
1960 log_debugx("exiting on signal; "
1961 "reloading empty configuration");
1963 log_debugx("disabling CTL iSCSI port "
1964 "and terminating all connections");
1967 newconf = conf_new();
1969 newconf->conf_debug = debug;
1970 error = conf_apply(oldconf, newconf);
1972 log_warnx("failed to apply configuration");
1974 log_warnx("exiting on signal");
1977 nchildren -= wait_for_children(false);
1978 assert(nchildren >= 0);