2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2012 The FreeBSD Foundation
6 * This software was developed by Edward Tomasz Napierala under sponsorship
7 * from the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <sys/types.h>
37 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <arpa/inet.h>
57 static bool timed_out(void);
58 #ifdef ICL_KERNEL_PROXY
59 static void pdu_receive_proxy(struct pdu *pdu);
60 static void pdu_send_proxy(struct pdu *pdu);
61 #endif /* ICL_KERNEL_PROXY */
62 static void pdu_fail(const struct connection *conn, const char *reason);
64 bool proxy_mode = false;
66 static volatile bool sighup_received = false;
67 static volatile bool sigterm_received = false;
68 static volatile bool sigalrm_received = false;
70 static int nchildren = 0;
71 static uint16_t last_portal_group_tag = 0xff;
73 static struct connection_ops conn_ops = {
74 .timed_out = timed_out,
75 #ifdef ICL_KERNEL_PROXY
76 .pdu_receive_proxy = pdu_receive_proxy,
77 .pdu_send_proxy = pdu_send_proxy,
86 fprintf(stderr, "usage: ctld [-d][-u][-f config-file]\n");
87 fprintf(stderr, " ctld -t [-u][-f config-file]\n");
96 conf = calloc(1, sizeof(*conf));
99 TAILQ_INIT(&conf->conf_luns);
100 TAILQ_INIT(&conf->conf_targets);
101 TAILQ_INIT(&conf->conf_auth_groups);
102 TAILQ_INIT(&conf->conf_ports);
103 TAILQ_INIT(&conf->conf_portal_groups);
104 TAILQ_INIT(&conf->conf_pports);
105 TAILQ_INIT(&conf->conf_isns);
107 conf->conf_isns_period = 900;
108 conf->conf_isns_timeout = 5;
109 conf->conf_debug = 0;
110 conf->conf_timeout = 60;
111 conf->conf_maxproc = 30;
117 conf_delete(struct conf *conf)
119 struct lun *lun, *ltmp;
120 struct target *targ, *tmp;
121 struct auth_group *ag, *cagtmp;
122 struct portal_group *pg, *cpgtmp;
123 struct pport *pp, *pptmp;
124 struct isns *is, *istmp;
126 assert(conf->conf_pidfh == NULL);
128 TAILQ_FOREACH_SAFE(lun, &conf->conf_luns, l_next, ltmp)
130 TAILQ_FOREACH_SAFE(targ, &conf->conf_targets, t_next, tmp)
132 TAILQ_FOREACH_SAFE(ag, &conf->conf_auth_groups, ag_next, cagtmp)
133 auth_group_delete(ag);
134 TAILQ_FOREACH_SAFE(pg, &conf->conf_portal_groups, pg_next, cpgtmp)
135 portal_group_delete(pg);
136 TAILQ_FOREACH_SAFE(pp, &conf->conf_pports, pp_next, pptmp)
138 TAILQ_FOREACH_SAFE(is, &conf->conf_isns, i_next, istmp)
140 assert(TAILQ_EMPTY(&conf->conf_ports));
141 free(conf->conf_pidfile_path);
146 auth_new(struct auth_group *ag)
150 auth = calloc(1, sizeof(*auth));
152 log_err(1, "calloc");
153 auth->a_auth_group = ag;
154 TAILQ_INSERT_TAIL(&ag->ag_auths, auth, a_next);
159 auth_delete(struct auth *auth)
161 TAILQ_REMOVE(&auth->a_auth_group->ag_auths, auth, a_next);
164 free(auth->a_secret);
165 free(auth->a_mutual_user);
166 free(auth->a_mutual_secret);
171 auth_find(const struct auth_group *ag, const char *user)
173 const struct auth *auth;
175 TAILQ_FOREACH(auth, &ag->ag_auths, a_next) {
176 if (strcmp(auth->a_user, user) == 0)
184 auth_check_secret_length(struct auth *auth)
188 len = strlen(auth->a_secret);
190 if (auth->a_auth_group->ag_name != NULL)
191 log_warnx("secret for user \"%s\", auth-group \"%s\", "
192 "is too long; it should be at most 16 characters "
193 "long", auth->a_user, auth->a_auth_group->ag_name);
195 log_warnx("secret for user \"%s\", target \"%s\", "
196 "is too long; it should be at most 16 characters "
197 "long", auth->a_user,
198 auth->a_auth_group->ag_target->t_name);
201 if (auth->a_auth_group->ag_name != NULL)
202 log_warnx("secret for user \"%s\", auth-group \"%s\", "
203 "is too short; it should be at least 12 characters "
204 "long", auth->a_user,
205 auth->a_auth_group->ag_name);
207 log_warnx("secret for user \"%s\", target \"%s\", "
208 "is too short; it should be at least 12 characters "
209 "long", auth->a_user,
210 auth->a_auth_group->ag_target->t_name);
213 if (auth->a_mutual_secret != NULL) {
214 len = strlen(auth->a_mutual_secret);
216 if (auth->a_auth_group->ag_name != NULL)
217 log_warnx("mutual secret for user \"%s\", "
218 "auth-group \"%s\", is too long; it should "
219 "be at most 16 characters long",
220 auth->a_user, auth->a_auth_group->ag_name);
222 log_warnx("mutual secret for user \"%s\", "
223 "target \"%s\", is too long; it should "
224 "be at most 16 characters long",
226 auth->a_auth_group->ag_target->t_name);
229 if (auth->a_auth_group->ag_name != NULL)
230 log_warnx("mutual secret for user \"%s\", "
231 "auth-group \"%s\", is too short; it "
232 "should be at least 12 characters long",
233 auth->a_user, auth->a_auth_group->ag_name);
235 log_warnx("mutual secret for user \"%s\", "
236 "target \"%s\", is too short; it should be "
237 "at least 12 characters long",
239 auth->a_auth_group->ag_target->t_name);
245 auth_new_chap(struct auth_group *ag, const char *user,
250 if (ag->ag_type == AG_TYPE_UNKNOWN)
251 ag->ag_type = AG_TYPE_CHAP;
252 if (ag->ag_type != AG_TYPE_CHAP) {
253 if (ag->ag_name != NULL)
254 log_warnx("cannot mix \"chap\" authentication with "
255 "other types for auth-group \"%s\"", ag->ag_name);
257 log_warnx("cannot mix \"chap\" authentication with "
258 "other types for target \"%s\"",
259 ag->ag_target->t_name);
264 auth->a_user = checked_strdup(user);
265 auth->a_secret = checked_strdup(secret);
267 auth_check_secret_length(auth);
273 auth_new_chap_mutual(struct auth_group *ag, const char *user,
274 const char *secret, const char *user2, const char *secret2)
278 if (ag->ag_type == AG_TYPE_UNKNOWN)
279 ag->ag_type = AG_TYPE_CHAP_MUTUAL;
280 if (ag->ag_type != AG_TYPE_CHAP_MUTUAL) {
281 if (ag->ag_name != NULL)
282 log_warnx("cannot mix \"chap-mutual\" authentication "
283 "with other types for auth-group \"%s\"",
286 log_warnx("cannot mix \"chap-mutual\" authentication "
287 "with other types for target \"%s\"",
288 ag->ag_target->t_name);
293 auth->a_user = checked_strdup(user);
294 auth->a_secret = checked_strdup(secret);
295 auth->a_mutual_user = checked_strdup(user2);
296 auth->a_mutual_secret = checked_strdup(secret2);
298 auth_check_secret_length(auth);
303 const struct auth_name *
304 auth_name_new(struct auth_group *ag, const char *name)
306 struct auth_name *an;
308 an = calloc(1, sizeof(*an));
310 log_err(1, "calloc");
311 an->an_auth_group = ag;
312 an->an_initiator_name = checked_strdup(name);
313 TAILQ_INSERT_TAIL(&ag->ag_names, an, an_next);
318 auth_name_delete(struct auth_name *an)
320 TAILQ_REMOVE(&an->an_auth_group->ag_names, an, an_next);
322 free(an->an_initiator_name);
327 auth_name_defined(const struct auth_group *ag)
329 if (TAILQ_EMPTY(&ag->ag_names))
334 const struct auth_name *
335 auth_name_find(const struct auth_group *ag, const char *name)
337 const struct auth_name *auth_name;
339 TAILQ_FOREACH(auth_name, &ag->ag_names, an_next) {
340 if (strcmp(auth_name->an_initiator_name, name) == 0)
348 auth_name_check(const struct auth_group *ag, const char *initiator_name)
350 if (!auth_name_defined(ag))
353 if (auth_name_find(ag, initiator_name) == NULL)
359 const struct auth_portal *
360 auth_portal_new(struct auth_group *ag, const char *portal)
362 struct auth_portal *ap;
363 char *net, *mask, *str, *tmp;
366 ap = calloc(1, sizeof(*ap));
368 log_err(1, "calloc");
369 ap->ap_auth_group = ag;
370 ap->ap_initiator_portal = checked_strdup(portal);
371 mask = str = checked_strdup(portal);
372 net = strsep(&mask, "/");
378 if (net[len - 1] == ']')
380 if (strchr(net, ':') != NULL) {
381 struct sockaddr_in6 *sin6 =
382 (struct sockaddr_in6 *)&ap->ap_sa;
384 sin6->sin6_len = sizeof(*sin6);
385 sin6->sin6_family = AF_INET6;
386 if (inet_pton(AF_INET6, net, &sin6->sin6_addr) <= 0)
390 struct sockaddr_in *sin =
391 (struct sockaddr_in *)&ap->ap_sa;
393 sin->sin_len = sizeof(*sin);
394 sin->sin_family = AF_INET;
395 if (inet_pton(AF_INET, net, &sin->sin_addr) <= 0)
400 m = strtol(mask, &tmp, 0);
401 if (m < 0 || m > dm || tmp[0] != 0)
407 TAILQ_INSERT_TAIL(&ag->ag_portals, ap, ap_next);
413 log_warnx("incorrect initiator portal \"%s\"", portal);
418 auth_portal_delete(struct auth_portal *ap)
420 TAILQ_REMOVE(&ap->ap_auth_group->ag_portals, ap, ap_next);
422 free(ap->ap_initiator_portal);
427 auth_portal_defined(const struct auth_group *ag)
429 if (TAILQ_EMPTY(&ag->ag_portals))
434 const struct auth_portal *
435 auth_portal_find(const struct auth_group *ag, const struct sockaddr_storage *ss)
437 const struct auth_portal *ap;
438 const uint8_t *a, *b;
442 TAILQ_FOREACH(ap, &ag->ag_portals, ap_next) {
443 if (ap->ap_sa.ss_family != ss->ss_family)
445 if (ss->ss_family == AF_INET) {
446 a = (const uint8_t *)
447 &((const struct sockaddr_in *)ss)->sin_addr;
448 b = (const uint8_t *)
449 &((const struct sockaddr_in *)&ap->ap_sa)->sin_addr;
451 a = (const uint8_t *)
452 &((const struct sockaddr_in6 *)ss)->sin6_addr;
453 b = (const uint8_t *)
454 &((const struct sockaddr_in6 *)&ap->ap_sa)->sin6_addr;
456 for (i = 0; i < ap->ap_mask / 8; i++) {
460 if (ap->ap_mask % 8) {
461 bmask = 0xff << (8 - (ap->ap_mask % 8));
462 if ((a[i] & bmask) != (b[i] & bmask))
474 auth_portal_check(const struct auth_group *ag, const struct sockaddr_storage *sa)
477 if (!auth_portal_defined(ag))
480 if (auth_portal_find(ag, sa) == NULL)
487 auth_group_new(struct conf *conf, const char *name)
489 struct auth_group *ag;
492 ag = auth_group_find(conf, name);
494 log_warnx("duplicated auth-group \"%s\"", name);
499 ag = calloc(1, sizeof(*ag));
501 log_err(1, "calloc");
503 ag->ag_name = checked_strdup(name);
504 TAILQ_INIT(&ag->ag_auths);
505 TAILQ_INIT(&ag->ag_names);
506 TAILQ_INIT(&ag->ag_portals);
508 TAILQ_INSERT_TAIL(&conf->conf_auth_groups, ag, ag_next);
514 auth_group_delete(struct auth_group *ag)
516 struct auth *auth, *auth_tmp;
517 struct auth_name *auth_name, *auth_name_tmp;
518 struct auth_portal *auth_portal, *auth_portal_tmp;
520 TAILQ_REMOVE(&ag->ag_conf->conf_auth_groups, ag, ag_next);
522 TAILQ_FOREACH_SAFE(auth, &ag->ag_auths, a_next, auth_tmp)
524 TAILQ_FOREACH_SAFE(auth_name, &ag->ag_names, an_next, auth_name_tmp)
525 auth_name_delete(auth_name);
526 TAILQ_FOREACH_SAFE(auth_portal, &ag->ag_portals, ap_next,
528 auth_portal_delete(auth_portal);
534 auth_group_find(const struct conf *conf, const char *name)
536 struct auth_group *ag;
538 TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) {
539 if (ag->ag_name != NULL && strcmp(ag->ag_name, name) == 0)
547 auth_group_set_type(struct auth_group *ag, const char *str)
551 if (strcmp(str, "none") == 0) {
552 type = AG_TYPE_NO_AUTHENTICATION;
553 } else if (strcmp(str, "deny") == 0) {
555 } else if (strcmp(str, "chap") == 0) {
557 } else if (strcmp(str, "chap-mutual") == 0) {
558 type = AG_TYPE_CHAP_MUTUAL;
560 if (ag->ag_name != NULL)
561 log_warnx("invalid auth-type \"%s\" for auth-group "
562 "\"%s\"", str, ag->ag_name);
564 log_warnx("invalid auth-type \"%s\" for target "
565 "\"%s\"", str, ag->ag_target->t_name);
569 if (ag->ag_type != AG_TYPE_UNKNOWN && ag->ag_type != type) {
570 if (ag->ag_name != NULL) {
571 log_warnx("cannot set auth-type to \"%s\" for "
572 "auth-group \"%s\"; already has a different "
573 "type", str, ag->ag_name);
575 log_warnx("cannot set auth-type to \"%s\" for target "
576 "\"%s\"; already has a different type",
577 str, ag->ag_target->t_name);
587 static struct portal *
588 portal_new(struct portal_group *pg)
590 struct portal *portal;
592 portal = calloc(1, sizeof(*portal));
594 log_err(1, "calloc");
595 TAILQ_INIT(&portal->p_targets);
596 portal->p_portal_group = pg;
597 TAILQ_INSERT_TAIL(&pg->pg_portals, portal, p_next);
602 portal_delete(struct portal *portal)
605 TAILQ_REMOVE(&portal->p_portal_group->pg_portals, portal, p_next);
606 if (portal->p_ai != NULL)
607 freeaddrinfo(portal->p_ai);
608 free(portal->p_listen);
612 struct portal_group *
613 portal_group_new(struct conf *conf, const char *name)
615 struct portal_group *pg;
617 pg = portal_group_find(conf, name);
619 log_warnx("duplicated portal-group \"%s\"", name);
623 pg = calloc(1, sizeof(*pg));
625 log_err(1, "calloc");
626 pg->pg_name = checked_strdup(name);
627 TAILQ_INIT(&pg->pg_options);
628 TAILQ_INIT(&pg->pg_portals);
629 TAILQ_INIT(&pg->pg_ports);
631 pg->pg_tag = 0; /* Assigned later in conf_apply(). */
634 TAILQ_INSERT_TAIL(&conf->conf_portal_groups, pg, pg_next);
640 portal_group_delete(struct portal_group *pg)
642 struct portal *portal, *tmp;
643 struct port *port, *tport;
644 struct option *o, *otmp;
646 TAILQ_FOREACH_SAFE(port, &pg->pg_ports, p_pgs, tport)
648 TAILQ_REMOVE(&pg->pg_conf->conf_portal_groups, pg, pg_next);
650 TAILQ_FOREACH_SAFE(portal, &pg->pg_portals, p_next, tmp)
651 portal_delete(portal);
652 TAILQ_FOREACH_SAFE(o, &pg->pg_options, o_next, otmp)
653 option_delete(&pg->pg_options, o);
655 free(pg->pg_offload);
656 free(pg->pg_redirection);
660 struct portal_group *
661 portal_group_find(const struct conf *conf, const char *name)
663 struct portal_group *pg;
665 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
666 if (strcmp(pg->pg_name, name) == 0)
674 parse_addr_port(char *arg, const char *def_port, struct addrinfo **ai)
676 struct addrinfo hints;
677 char *str, *addr, *ch;
679 int error, colons = 0;
681 str = arg = strdup(arg);
684 * IPv6 address in square brackets, perhaps with port.
687 addr = strsep(&arg, "]");
692 if (arg[0] == '\0') {
694 } else if (arg[0] == ':') {
702 * Either IPv6 address without brackets - and without
703 * a port - or IPv4 address. Just count the colons.
705 for (ch = arg; *ch != '\0'; ch++) {
713 addr = strsep(&arg, ":");
721 memset(&hints, 0, sizeof(hints));
722 hints.ai_family = PF_UNSPEC;
723 hints.ai_socktype = SOCK_STREAM;
724 hints.ai_flags = AI_PASSIVE;
725 error = getaddrinfo(addr, port, &hints, ai);
727 return ((error != 0) ? 1 : 0);
731 portal_group_add_listen(struct portal_group *pg, const char *value, bool iser)
733 struct portal *portal;
735 portal = portal_new(pg);
736 portal->p_listen = checked_strdup(value);
737 portal->p_iser = iser;
739 if (parse_addr_port(portal->p_listen, "3260", &portal->p_ai)) {
740 log_warnx("invalid listen address %s", portal->p_listen);
741 portal_delete(portal);
746 * XXX: getaddrinfo(3) may return multiple addresses; we should turn
747 * those into multiple portals.
754 isns_new(struct conf *conf, const char *addr)
758 isns = calloc(1, sizeof(*isns));
760 log_err(1, "calloc");
762 TAILQ_INSERT_TAIL(&conf->conf_isns, isns, i_next);
763 isns->i_addr = checked_strdup(addr);
765 if (parse_addr_port(isns->i_addr, "3205", &isns->i_ai)) {
766 log_warnx("invalid iSNS address %s", isns->i_addr);
772 * XXX: getaddrinfo(3) may return multiple addresses; we should turn
773 * those into multiple servers.
780 isns_delete(struct isns *isns)
783 TAILQ_REMOVE(&isns->i_conf->conf_isns, isns, i_next);
785 if (isns->i_ai != NULL)
786 freeaddrinfo(isns->i_ai);
791 isns_do_connect(struct isns *isns)
795 s = socket(isns->i_ai->ai_family, isns->i_ai->ai_socktype,
796 isns->i_ai->ai_protocol);
798 log_warn("socket(2) failed for %s", isns->i_addr);
801 if (connect(s, isns->i_ai->ai_addr, isns->i_ai->ai_addrlen)) {
802 log_warn("connect(2) failed for %s", isns->i_addr);
810 isns_do_register(struct isns *isns, int s, const char *hostname)
812 struct conf *conf = isns->i_conf;
813 struct target *target;
814 struct portal *portal;
815 struct portal_group *pg;
817 struct isns_req *req;
821 req = isns_req_create(ISNS_FUNC_DEVATTRREG, ISNS_FLAG_CLIENT);
822 isns_req_add_str(req, 32, TAILQ_FIRST(&conf->conf_targets)->t_name);
823 isns_req_add_delim(req);
824 isns_req_add_str(req, 1, hostname);
825 isns_req_add_32(req, 2, 2); /* 2 -- iSCSI */
826 isns_req_add_32(req, 6, conf->conf_isns_period);
827 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
828 if (pg->pg_unassigned)
830 TAILQ_FOREACH(portal, &pg->pg_portals, p_next) {
831 isns_req_add_addr(req, 16, portal->p_ai);
832 isns_req_add_port(req, 17, portal->p_ai);
835 TAILQ_FOREACH(target, &conf->conf_targets, t_next) {
836 isns_req_add_str(req, 32, target->t_name);
837 isns_req_add_32(req, 33, 1); /* 1 -- Target*/
838 if (target->t_alias != NULL)
839 isns_req_add_str(req, 34, target->t_alias);
840 TAILQ_FOREACH(port, &target->t_ports, p_ts) {
841 if ((pg = port->p_portal_group) == NULL)
843 isns_req_add_32(req, 51, pg->pg_tag);
844 TAILQ_FOREACH(portal, &pg->pg_portals, p_next) {
845 isns_req_add_addr(req, 49, portal->p_ai);
846 isns_req_add_port(req, 50, portal->p_ai);
850 res = isns_req_send(s, req);
852 log_warn("send(2) failed for %s", isns->i_addr);
855 res = isns_req_receive(s, req);
857 log_warn("receive(2) failed for %s", isns->i_addr);
860 error = isns_req_get_status(req);
862 log_warnx("iSNS register error %d for %s", error, isns->i_addr);
871 isns_do_check(struct isns *isns, int s, const char *hostname)
873 struct conf *conf = isns->i_conf;
874 struct isns_req *req;
878 req = isns_req_create(ISNS_FUNC_DEVATTRQRY, ISNS_FLAG_CLIENT);
879 isns_req_add_str(req, 32, TAILQ_FIRST(&conf->conf_targets)->t_name);
880 isns_req_add_str(req, 1, hostname);
881 isns_req_add_delim(req);
882 isns_req_add(req, 2, 0, NULL);
883 res = isns_req_send(s, req);
885 log_warn("send(2) failed for %s", isns->i_addr);
888 res = isns_req_receive(s, req);
890 log_warn("receive(2) failed for %s", isns->i_addr);
893 error = isns_req_get_status(req);
895 log_warnx("iSNS check error %d for %s", error, isns->i_addr);
904 isns_do_deregister(struct isns *isns, int s, const char *hostname)
906 struct conf *conf = isns->i_conf;
907 struct isns_req *req;
911 req = isns_req_create(ISNS_FUNC_DEVDEREG, ISNS_FLAG_CLIENT);
912 isns_req_add_str(req, 32, TAILQ_FIRST(&conf->conf_targets)->t_name);
913 isns_req_add_delim(req);
914 isns_req_add_str(req, 1, hostname);
915 res = isns_req_send(s, req);
917 log_warn("send(2) failed for %s", isns->i_addr);
920 res = isns_req_receive(s, req);
922 log_warn("receive(2) failed for %s", isns->i_addr);
925 error = isns_req_get_status(req);
927 log_warnx("iSNS deregister error %d for %s", error, isns->i_addr);
936 isns_register(struct isns *isns, struct isns *oldisns)
938 struct conf *conf = isns->i_conf;
942 if (TAILQ_EMPTY(&conf->conf_targets) ||
943 TAILQ_EMPTY(&conf->conf_portal_groups))
945 set_timeout(conf->conf_isns_timeout, false);
946 s = isns_do_connect(isns);
948 set_timeout(0, false);
951 error = gethostname(hostname, sizeof(hostname));
953 log_err(1, "gethostname");
955 if (oldisns == NULL || TAILQ_EMPTY(&oldisns->i_conf->conf_targets))
957 isns_do_deregister(oldisns, s, hostname);
958 isns_do_register(isns, s, hostname);
960 set_timeout(0, false);
964 isns_check(struct isns *isns)
966 struct conf *conf = isns->i_conf;
970 if (TAILQ_EMPTY(&conf->conf_targets) ||
971 TAILQ_EMPTY(&conf->conf_portal_groups))
973 set_timeout(conf->conf_isns_timeout, false);
974 s = isns_do_connect(isns);
976 set_timeout(0, false);
979 error = gethostname(hostname, sizeof(hostname));
981 log_err(1, "gethostname");
983 res = isns_do_check(isns, s, hostname);
985 isns_do_deregister(isns, s, hostname);
986 isns_do_register(isns, s, hostname);
989 set_timeout(0, false);
993 isns_deregister(struct isns *isns)
995 struct conf *conf = isns->i_conf;
999 if (TAILQ_EMPTY(&conf->conf_targets) ||
1000 TAILQ_EMPTY(&conf->conf_portal_groups))
1002 set_timeout(conf->conf_isns_timeout, false);
1003 s = isns_do_connect(isns);
1006 error = gethostname(hostname, sizeof(hostname));
1008 log_err(1, "gethostname");
1010 isns_do_deregister(isns, s, hostname);
1012 set_timeout(0, false);
1016 portal_group_set_filter(struct portal_group *pg, const char *str)
1020 if (strcmp(str, "none") == 0) {
1021 filter = PG_FILTER_NONE;
1022 } else if (strcmp(str, "portal") == 0) {
1023 filter = PG_FILTER_PORTAL;
1024 } else if (strcmp(str, "portal-name") == 0) {
1025 filter = PG_FILTER_PORTAL_NAME;
1026 } else if (strcmp(str, "portal-name-auth") == 0) {
1027 filter = PG_FILTER_PORTAL_NAME_AUTH;
1029 log_warnx("invalid discovery-filter \"%s\" for portal-group "
1030 "\"%s\"; valid values are \"none\", \"portal\", "
1031 "\"portal-name\", and \"portal-name-auth\"",
1036 if (pg->pg_discovery_filter != PG_FILTER_UNKNOWN &&
1037 pg->pg_discovery_filter != filter) {
1038 log_warnx("cannot set discovery-filter to \"%s\" for "
1039 "portal-group \"%s\"; already has a different "
1040 "value", str, pg->pg_name);
1044 pg->pg_discovery_filter = filter;
1050 portal_group_set_offload(struct portal_group *pg, const char *offload)
1053 if (pg->pg_offload != NULL) {
1054 log_warnx("cannot set offload to \"%s\" for "
1055 "portal-group \"%s\"; already defined",
1056 offload, pg->pg_name);
1060 pg->pg_offload = checked_strdup(offload);
1066 portal_group_set_redirection(struct portal_group *pg, const char *addr)
1069 if (pg->pg_redirection != NULL) {
1070 log_warnx("cannot set redirection to \"%s\" for "
1071 "portal-group \"%s\"; already defined",
1076 pg->pg_redirection = checked_strdup(addr);
1082 valid_hex(const char ch)
1114 valid_iscsi_name(const char *name)
1118 if (strlen(name) >= MAX_NAME_LEN) {
1119 log_warnx("overlong name for target \"%s\"; max length allowed "
1120 "by iSCSI specification is %d characters",
1121 name, MAX_NAME_LEN);
1126 * In the cases below, we don't return an error, just in case the admin
1127 * was right, and we're wrong.
1129 if (strncasecmp(name, "iqn.", strlen("iqn.")) == 0) {
1130 for (i = strlen("iqn."); name[i] != '\0'; i++) {
1132 * XXX: We should verify UTF-8 normalisation, as defined
1133 * by 3.2.6.2: iSCSI Name Encoding.
1135 if (isalnum(name[i]))
1137 if (name[i] == '-' || name[i] == '.' || name[i] == ':')
1139 log_warnx("invalid character \"%c\" in target name "
1140 "\"%s\"; allowed characters are letters, digits, "
1141 "'-', '.', and ':'", name[i], name);
1145 * XXX: Check more stuff: valid date and a valid reversed domain.
1147 } else if (strncasecmp(name, "eui.", strlen("eui.")) == 0) {
1148 if (strlen(name) != strlen("eui.") + 16)
1149 log_warnx("invalid target name \"%s\"; the \"eui.\" "
1150 "should be followed by exactly 16 hexadecimal "
1152 for (i = strlen("eui."); name[i] != '\0'; i++) {
1153 if (!valid_hex(name[i])) {
1154 log_warnx("invalid character \"%c\" in target "
1155 "name \"%s\"; allowed characters are 1-9 "
1156 "and A-F", name[i], name);
1160 } else if (strncasecmp(name, "naa.", strlen("naa.")) == 0) {
1161 if (strlen(name) > strlen("naa.") + 32)
1162 log_warnx("invalid target name \"%s\"; the \"naa.\" "
1163 "should be followed by at most 32 hexadecimal "
1165 for (i = strlen("naa."); name[i] != '\0'; i++) {
1166 if (!valid_hex(name[i])) {
1167 log_warnx("invalid character \"%c\" in target "
1168 "name \"%s\"; allowed characters are 1-9 "
1169 "and A-F", name[i], name);
1174 log_warnx("invalid target name \"%s\"; should start with "
1175 "either \"iqn.\", \"eui.\", or \"naa.\"",
1182 pport_new(struct conf *conf, const char *name, uint32_t ctl_port)
1186 pp = calloc(1, sizeof(*pp));
1188 log_err(1, "calloc");
1190 pp->pp_name = checked_strdup(name);
1191 pp->pp_ctl_port = ctl_port;
1192 TAILQ_INIT(&pp->pp_ports);
1193 TAILQ_INSERT_TAIL(&conf->conf_pports, pp, pp_next);
1198 pport_find(const struct conf *conf, const char *name)
1202 TAILQ_FOREACH(pp, &conf->conf_pports, pp_next) {
1203 if (strcasecmp(pp->pp_name, name) == 0)
1210 pport_copy(struct pport *pp, struct conf *conf)
1212 struct pport *ppnew;
1214 ppnew = pport_new(conf, pp->pp_name, pp->pp_ctl_port);
1219 pport_delete(struct pport *pp)
1221 struct port *port, *tport;
1223 TAILQ_FOREACH_SAFE(port, &pp->pp_ports, p_ts, tport)
1225 TAILQ_REMOVE(&pp->pp_conf->conf_pports, pp, pp_next);
1231 port_new(struct conf *conf, struct target *target, struct portal_group *pg)
1237 ret = asprintf(&name, "%s-%s", pg->pg_name, target->t_name);
1239 log_err(1, "asprintf");
1240 if (port_find(conf, name) != NULL) {
1241 log_warnx("duplicate port \"%s\"", name);
1245 port = calloc(1, sizeof(*port));
1247 log_err(1, "calloc");
1248 port->p_conf = conf;
1249 port->p_name = name;
1250 port->p_ioctl_port = 0;
1251 TAILQ_INSERT_TAIL(&conf->conf_ports, port, p_next);
1252 TAILQ_INSERT_TAIL(&target->t_ports, port, p_ts);
1253 port->p_target = target;
1254 TAILQ_INSERT_TAIL(&pg->pg_ports, port, p_pgs);
1255 port->p_portal_group = pg;
1260 port_new_ioctl(struct conf *conf, struct target *target, int pp, int vp)
1262 struct pport *pport;
1268 ret = asprintf(&pname, "ioctl/%d/%d", pp, vp);
1270 log_err(1, "asprintf");
1274 pport = pport_find(conf, pname);
1275 if (pport != NULL) {
1277 return (port_new_pp(conf, target, pport));
1280 ret = asprintf(&name, "%s-%s", pname, target->t_name);
1284 log_err(1, "asprintf");
1285 if (port_find(conf, name) != NULL) {
1286 log_warnx("duplicate port \"%s\"", name);
1290 port = calloc(1, sizeof(*port));
1292 log_err(1, "calloc");
1293 port->p_conf = conf;
1294 port->p_name = name;
1295 port->p_ioctl_port = 1;
1296 port->p_ioctl_pp = pp;
1297 port->p_ioctl_vp = vp;
1298 TAILQ_INSERT_TAIL(&conf->conf_ports, port, p_next);
1299 TAILQ_INSERT_TAIL(&target->t_ports, port, p_ts);
1300 port->p_target = target;
1305 port_new_pp(struct conf *conf, struct target *target, struct pport *pp)
1311 ret = asprintf(&name, "%s-%s", pp->pp_name, target->t_name);
1313 log_err(1, "asprintf");
1314 if (port_find(conf, name) != NULL) {
1315 log_warnx("duplicate port \"%s\"", name);
1319 port = calloc(1, sizeof(*port));
1321 log_err(1, "calloc");
1322 port->p_conf = conf;
1323 port->p_name = name;
1324 TAILQ_INSERT_TAIL(&conf->conf_ports, port, p_next);
1325 TAILQ_INSERT_TAIL(&target->t_ports, port, p_ts);
1326 port->p_target = target;
1327 TAILQ_INSERT_TAIL(&pp->pp_ports, port, p_pps);
1333 port_find(const struct conf *conf, const char *name)
1337 TAILQ_FOREACH(port, &conf->conf_ports, p_next) {
1338 if (strcasecmp(port->p_name, name) == 0)
1346 port_find_in_pg(const struct portal_group *pg, const char *target)
1350 TAILQ_FOREACH(port, &pg->pg_ports, p_pgs) {
1351 if (strcasecmp(port->p_target->t_name, target) == 0)
1359 port_delete(struct port *port)
1362 if (port->p_portal_group)
1363 TAILQ_REMOVE(&port->p_portal_group->pg_ports, port, p_pgs);
1365 TAILQ_REMOVE(&port->p_pport->pp_ports, port, p_pps);
1367 TAILQ_REMOVE(&port->p_target->t_ports, port, p_ts);
1368 TAILQ_REMOVE(&port->p_conf->conf_ports, port, p_next);
1374 port_is_dummy(struct port *port)
1377 if (port->p_portal_group) {
1378 if (port->p_portal_group->pg_foreign)
1380 if (TAILQ_EMPTY(&port->p_portal_group->pg_portals))
1387 target_new(struct conf *conf, const char *name)
1389 struct target *targ;
1392 targ = target_find(conf, name);
1394 log_warnx("duplicated target \"%s\"", name);
1397 if (valid_iscsi_name(name) == false) {
1398 log_warnx("target name \"%s\" is invalid", name);
1401 targ = calloc(1, sizeof(*targ));
1403 log_err(1, "calloc");
1404 targ->t_name = checked_strdup(name);
1407 * RFC 3722 requires us to normalize the name to lowercase.
1410 for (i = 0; i < len; i++)
1411 targ->t_name[i] = tolower(targ->t_name[i]);
1413 targ->t_conf = conf;
1414 TAILQ_INIT(&targ->t_ports);
1415 TAILQ_INSERT_TAIL(&conf->conf_targets, targ, t_next);
1421 target_delete(struct target *targ)
1423 struct port *port, *tport;
1425 TAILQ_FOREACH_SAFE(port, &targ->t_ports, p_ts, tport)
1427 TAILQ_REMOVE(&targ->t_conf->conf_targets, targ, t_next);
1430 free(targ->t_redirection);
1435 target_find(struct conf *conf, const char *name)
1437 struct target *targ;
1439 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
1440 if (strcasecmp(targ->t_name, name) == 0)
1448 target_set_redirection(struct target *target, const char *addr)
1451 if (target->t_redirection != NULL) {
1452 log_warnx("cannot set redirection to \"%s\" for "
1453 "target \"%s\"; already defined",
1454 addr, target->t_name);
1458 target->t_redirection = checked_strdup(addr);
1464 lun_new(struct conf *conf, const char *name)
1468 lun = lun_find(conf, name);
1470 log_warnx("duplicated lun \"%s\"", name);
1474 lun = calloc(1, sizeof(*lun));
1476 log_err(1, "calloc");
1478 lun->l_name = checked_strdup(name);
1479 TAILQ_INIT(&lun->l_options);
1480 TAILQ_INSERT_TAIL(&conf->conf_luns, lun, l_next);
1481 lun->l_ctl_lun = -1;
1487 lun_delete(struct lun *lun)
1489 struct target *targ;
1490 struct option *o, *tmp;
1493 TAILQ_FOREACH(targ, &lun->l_conf->conf_targets, t_next) {
1494 for (i = 0; i < MAX_LUNS; i++) {
1495 if (targ->t_luns[i] == lun)
1496 targ->t_luns[i] = NULL;
1499 TAILQ_REMOVE(&lun->l_conf->conf_luns, lun, l_next);
1501 TAILQ_FOREACH_SAFE(o, &lun->l_options, o_next, tmp)
1502 option_delete(&lun->l_options, o);
1504 free(lun->l_backend);
1505 free(lun->l_device_id);
1507 free(lun->l_scsiname);
1508 free(lun->l_serial);
1513 lun_find(const struct conf *conf, const char *name)
1517 TAILQ_FOREACH(lun, &conf->conf_luns, l_next) {
1518 if (strcmp(lun->l_name, name) == 0)
1526 lun_set_backend(struct lun *lun, const char *value)
1528 free(lun->l_backend);
1529 lun->l_backend = checked_strdup(value);
1533 lun_set_blocksize(struct lun *lun, size_t value)
1536 lun->l_blocksize = value;
1540 lun_set_device_type(struct lun *lun, uint8_t value)
1543 lun->l_device_type = value;
1547 lun_set_device_id(struct lun *lun, const char *value)
1549 free(lun->l_device_id);
1550 lun->l_device_id = checked_strdup(value);
1554 lun_set_path(struct lun *lun, const char *value)
1557 lun->l_path = checked_strdup(value);
1561 lun_set_scsiname(struct lun *lun, const char *value)
1563 free(lun->l_scsiname);
1564 lun->l_scsiname = checked_strdup(value);
1568 lun_set_serial(struct lun *lun, const char *value)
1570 free(lun->l_serial);
1571 lun->l_serial = checked_strdup(value);
1575 lun_set_size(struct lun *lun, size_t value)
1578 lun->l_size = value;
1582 lun_set_ctl_lun(struct lun *lun, uint32_t value)
1585 lun->l_ctl_lun = value;
1589 option_new(struct options *options, const char *name, const char *value)
1593 o = option_find(options, name);
1595 log_warnx("duplicated option \"%s\"", name);
1599 o = calloc(1, sizeof(*o));
1601 log_err(1, "calloc");
1602 o->o_name = checked_strdup(name);
1603 o->o_value = checked_strdup(value);
1604 TAILQ_INSERT_TAIL(options, o, o_next);
1610 option_delete(struct options *options, struct option *o)
1613 TAILQ_REMOVE(options, o, o_next);
1620 option_find(const struct options *options, const char *name)
1624 TAILQ_FOREACH(o, options, o_next) {
1625 if (strcmp(o->o_name, name) == 0)
1633 option_set(struct option *o, const char *value)
1637 o->o_value = checked_strdup(value);
1640 #ifdef ICL_KERNEL_PROXY
1643 pdu_receive_proxy(struct pdu *pdu)
1645 struct connection *conn;
1649 conn = pdu->pdu_connection;
1651 kernel_receive(pdu);
1653 len = pdu_ahs_length(pdu);
1655 log_errx(1, "protocol error: non-empty AHS");
1657 len = pdu_data_segment_length(pdu);
1658 assert(len <= (size_t)conn->conn_max_recv_data_segment_length);
1659 pdu->pdu_data_len = len;
1663 pdu_send_proxy(struct pdu *pdu)
1668 pdu_set_data_segment_length(pdu, pdu->pdu_data_len);
1672 #endif /* ICL_KERNEL_PROXY */
1675 pdu_fail(const struct connection *conn __unused, const char *reason __unused)
1679 static struct ctld_connection *
1680 connection_new(struct portal *portal, int fd, const char *host,
1681 const struct sockaddr *client_sa)
1683 struct ctld_connection *conn;
1685 conn = calloc(1, sizeof(*conn));
1687 log_err(1, "calloc");
1688 connection_init(&conn->conn, &conn_ops, proxy_mode);
1689 conn->conn.conn_socket = fd;
1690 conn->conn_portal = portal;
1691 conn->conn_initiator_addr = checked_strdup(host);
1692 memcpy(&conn->conn_initiator_sa, client_sa, client_sa->sa_len);
1699 conf_print(struct conf *conf)
1701 struct auth_group *ag;
1703 struct auth_name *auth_name;
1704 struct auth_portal *auth_portal;
1705 struct portal_group *pg;
1706 struct portal *portal;
1707 struct target *targ;
1711 TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) {
1712 fprintf(stderr, "auth-group %s {\n", ag->ag_name);
1713 TAILQ_FOREACH(auth, &ag->ag_auths, a_next)
1714 fprintf(stderr, "\t chap-mutual %s %s %s %s\n",
1715 auth->a_user, auth->a_secret,
1716 auth->a_mutual_user, auth->a_mutual_secret);
1717 TAILQ_FOREACH(auth_name, &ag->ag_names, an_next)
1718 fprintf(stderr, "\t initiator-name %s\n",
1719 auth_name->an_initiator_name);
1720 TAILQ_FOREACH(auth_portal, &ag->ag_portals, ap_next)
1721 fprintf(stderr, "\t initiator-portal %s\n",
1722 auth_portal->ap_initiator_portal);
1723 fprintf(stderr, "}\n");
1725 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
1726 fprintf(stderr, "portal-group %s {\n", pg->pg_name);
1727 TAILQ_FOREACH(portal, &pg->pg_portals, p_next)
1728 fprintf(stderr, "\t listen %s\n", portal->p_listen);
1729 fprintf(stderr, "}\n");
1731 TAILQ_FOREACH(lun, &conf->conf_luns, l_next) {
1732 fprintf(stderr, "\tlun %s {\n", lun->l_name);
1733 fprintf(stderr, "\t\tpath %s\n", lun->l_path);
1734 TAILQ_FOREACH(o, &lun->l_options, o_next)
1735 fprintf(stderr, "\t\toption %s %s\n",
1736 o->o_name, o->o_value);
1737 fprintf(stderr, "\t}\n");
1739 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
1740 fprintf(stderr, "target %s {\n", targ->t_name);
1741 if (targ->t_alias != NULL)
1742 fprintf(stderr, "\t alias %s\n", targ->t_alias);
1743 fprintf(stderr, "}\n");
1749 conf_verify_lun(struct lun *lun)
1751 const struct lun *lun2;
1753 if (lun->l_backend == NULL)
1754 lun_set_backend(lun, "block");
1755 if (strcmp(lun->l_backend, "block") == 0) {
1756 if (lun->l_path == NULL) {
1757 log_warnx("missing path for lun \"%s\"",
1761 } else if (strcmp(lun->l_backend, "ramdisk") == 0) {
1762 if (lun->l_size == 0) {
1763 log_warnx("missing size for ramdisk-backed lun \"%s\"",
1767 if (lun->l_path != NULL) {
1768 log_warnx("path must not be specified "
1769 "for ramdisk-backed lun \"%s\"",
1774 if (lun->l_blocksize == 0) {
1775 if (lun->l_device_type == 5)
1776 lun_set_blocksize(lun, DEFAULT_CD_BLOCKSIZE);
1778 lun_set_blocksize(lun, DEFAULT_BLOCKSIZE);
1779 } else if (lun->l_blocksize < 0) {
1780 log_warnx("invalid blocksize for lun \"%s\"; "
1781 "must be larger than 0", lun->l_name);
1784 if (lun->l_size != 0 && lun->l_size % lun->l_blocksize != 0) {
1785 log_warnx("invalid size for lun \"%s\"; "
1786 "must be multiple of blocksize", lun->l_name);
1789 TAILQ_FOREACH(lun2, &lun->l_conf->conf_luns, l_next) {
1792 if (lun->l_path != NULL && lun2->l_path != NULL &&
1793 strcmp(lun->l_path, lun2->l_path) == 0) {
1794 log_debugx("WARNING: path \"%s\" duplicated "
1795 "between lun \"%s\", and "
1796 "lun \"%s\"", lun->l_path,
1797 lun->l_name, lun2->l_name);
1805 conf_verify(struct conf *conf)
1807 struct auth_group *ag;
1808 struct portal_group *pg;
1810 struct target *targ;
1815 if (conf->conf_pidfile_path == NULL)
1816 conf->conf_pidfile_path = checked_strdup(DEFAULT_PIDFILE);
1818 TAILQ_FOREACH(lun, &conf->conf_luns, l_next) {
1819 error = conf_verify_lun(lun);
1823 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
1824 if (targ->t_auth_group == NULL) {
1825 targ->t_auth_group = auth_group_find(conf,
1827 assert(targ->t_auth_group != NULL);
1829 if (TAILQ_EMPTY(&targ->t_ports)) {
1830 pg = portal_group_find(conf, "default");
1832 port_new(conf, targ, pg);
1835 for (i = 0; i < MAX_LUNS; i++) {
1836 if (targ->t_luns[i] != NULL)
1839 if (!found && targ->t_redirection == NULL) {
1840 log_warnx("no LUNs defined for target \"%s\"",
1843 if (found && targ->t_redirection != NULL) {
1844 log_debugx("target \"%s\" contains luns, "
1845 " but configured for redirection",
1849 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
1850 assert(pg->pg_name != NULL);
1851 if (pg->pg_discovery_auth_group == NULL) {
1852 pg->pg_discovery_auth_group =
1853 auth_group_find(conf, "default");
1854 assert(pg->pg_discovery_auth_group != NULL);
1857 if (pg->pg_discovery_filter == PG_FILTER_UNKNOWN)
1858 pg->pg_discovery_filter = PG_FILTER_NONE;
1860 if (pg->pg_redirection != NULL) {
1861 if (!TAILQ_EMPTY(&pg->pg_ports)) {
1862 log_debugx("portal-group \"%s\" assigned "
1863 "to target, but configured "
1867 pg->pg_unassigned = false;
1868 } else if (!TAILQ_EMPTY(&pg->pg_ports)) {
1869 pg->pg_unassigned = false;
1871 if (strcmp(pg->pg_name, "default") != 0)
1872 log_warnx("portal-group \"%s\" not assigned "
1873 "to any target", pg->pg_name);
1874 pg->pg_unassigned = true;
1877 TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) {
1878 if (ag->ag_name == NULL)
1879 assert(ag->ag_target != NULL);
1881 assert(ag->ag_target == NULL);
1884 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
1885 if (targ->t_auth_group == ag) {
1890 TAILQ_FOREACH(port, &conf->conf_ports, p_next) {
1891 if (port->p_auth_group == ag) {
1896 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
1897 if (pg->pg_discovery_auth_group == ag) {
1902 if (!found && ag->ag_name != NULL &&
1903 strcmp(ag->ag_name, "default") != 0 &&
1904 strcmp(ag->ag_name, "no-authentication") != 0 &&
1905 strcmp(ag->ag_name, "no-access") != 0) {
1906 log_warnx("auth-group \"%s\" not assigned "
1907 "to any target", ag->ag_name);
1915 conf_apply(struct conf *oldconf, struct conf *newconf)
1917 struct lun *oldlun, *newlun, *tmplun;
1918 struct portal_group *oldpg, *newpg;
1919 struct portal *oldp, *newp;
1920 struct port *oldport, *newport, *tmpport;
1921 struct isns *oldns, *newns;
1923 int changed, cumulated_error = 0, error, sockbuf;
1926 if (oldconf->conf_debug != newconf->conf_debug) {
1927 log_debugx("changing debug level to %d", newconf->conf_debug);
1928 log_init(newconf->conf_debug);
1931 if (oldconf->conf_pidfh != NULL) {
1932 assert(oldconf->conf_pidfile_path != NULL);
1933 if (newconf->conf_pidfile_path != NULL &&
1934 strcmp(oldconf->conf_pidfile_path,
1935 newconf->conf_pidfile_path) == 0) {
1936 newconf->conf_pidfh = oldconf->conf_pidfh;
1937 oldconf->conf_pidfh = NULL;
1939 log_debugx("removing pidfile %s",
1940 oldconf->conf_pidfile_path);
1941 pidfile_remove(oldconf->conf_pidfh);
1942 oldconf->conf_pidfh = NULL;
1946 if (newconf->conf_pidfh == NULL && newconf->conf_pidfile_path != NULL) {
1947 log_debugx("opening pidfile %s", newconf->conf_pidfile_path);
1948 newconf->conf_pidfh =
1949 pidfile_open(newconf->conf_pidfile_path, 0600, &otherpid);
1950 if (newconf->conf_pidfh == NULL) {
1951 if (errno == EEXIST)
1952 log_errx(1, "daemon already running, pid: %jd.",
1953 (intmax_t)otherpid);
1954 log_err(1, "cannot open or create pidfile \"%s\"",
1955 newconf->conf_pidfile_path);
1960 * Go through the new portal groups, assigning tags or preserving old.
1962 TAILQ_FOREACH(newpg, &newconf->conf_portal_groups, pg_next) {
1963 if (newpg->pg_tag != 0)
1965 oldpg = portal_group_find(oldconf, newpg->pg_name);
1967 newpg->pg_tag = oldpg->pg_tag;
1969 newpg->pg_tag = ++last_portal_group_tag;
1972 /* Deregister on removed iSNS servers. */
1973 TAILQ_FOREACH(oldns, &oldconf->conf_isns, i_next) {
1974 TAILQ_FOREACH(newns, &newconf->conf_isns, i_next) {
1975 if (strcmp(oldns->i_addr, newns->i_addr) == 0)
1979 isns_deregister(oldns);
1983 * XXX: If target or lun removal fails, we should somehow "move"
1984 * the old lun or target into newconf, so that subsequent
1985 * conf_apply() would try to remove them again. That would
1986 * be somewhat hairy, though, and lun deletion failures don't
1987 * really happen, so leave it as it is for now.
1990 * First, remove any ports present in the old configuration
1991 * and missing in the new one.
1993 TAILQ_FOREACH_SAFE(oldport, &oldconf->conf_ports, p_next, tmpport) {
1994 if (port_is_dummy(oldport))
1996 newport = port_find(newconf, oldport->p_name);
1997 if (newport != NULL && !port_is_dummy(newport))
1999 log_debugx("removing port \"%s\"", oldport->p_name);
2000 error = kernel_port_remove(oldport);
2002 log_warnx("failed to remove port %s",
2005 * XXX: Uncomment after fixing the root cause.
2007 * cumulated_error++;
2013 * Second, remove any LUNs present in the old configuration
2014 * and missing in the new one.
2016 TAILQ_FOREACH_SAFE(oldlun, &oldconf->conf_luns, l_next, tmplun) {
2017 newlun = lun_find(newconf, oldlun->l_name);
2018 if (newlun == NULL) {
2019 log_debugx("lun \"%s\", CTL lun %d "
2020 "not found in new configuration; "
2021 "removing", oldlun->l_name, oldlun->l_ctl_lun);
2022 error = kernel_lun_remove(oldlun);
2024 log_warnx("failed to remove lun \"%s\", "
2026 oldlun->l_name, oldlun->l_ctl_lun);
2033 * Also remove the LUNs changed by more than size.
2036 assert(oldlun->l_backend != NULL);
2037 assert(newlun->l_backend != NULL);
2038 if (strcmp(newlun->l_backend, oldlun->l_backend) != 0) {
2039 log_debugx("backend for lun \"%s\", "
2040 "CTL lun %d changed; removing",
2041 oldlun->l_name, oldlun->l_ctl_lun);
2044 if (oldlun->l_blocksize != newlun->l_blocksize) {
2045 log_debugx("blocksize for lun \"%s\", "
2046 "CTL lun %d changed; removing",
2047 oldlun->l_name, oldlun->l_ctl_lun);
2050 if (newlun->l_device_id != NULL &&
2051 (oldlun->l_device_id == NULL ||
2052 strcmp(oldlun->l_device_id, newlun->l_device_id) !=
2054 log_debugx("device-id for lun \"%s\", "
2055 "CTL lun %d changed; removing",
2056 oldlun->l_name, oldlun->l_ctl_lun);
2059 if (newlun->l_path != NULL &&
2060 (oldlun->l_path == NULL ||
2061 strcmp(oldlun->l_path, newlun->l_path) != 0)) {
2062 log_debugx("path for lun \"%s\", "
2063 "CTL lun %d, changed; removing",
2064 oldlun->l_name, oldlun->l_ctl_lun);
2067 if (newlun->l_serial != NULL &&
2068 (oldlun->l_serial == NULL ||
2069 strcmp(oldlun->l_serial, newlun->l_serial) != 0)) {
2070 log_debugx("serial for lun \"%s\", "
2071 "CTL lun %d changed; removing",
2072 oldlun->l_name, oldlun->l_ctl_lun);
2076 error = kernel_lun_remove(oldlun);
2078 log_warnx("failed to remove lun \"%s\", "
2080 oldlun->l_name, oldlun->l_ctl_lun);
2087 lun_set_ctl_lun(newlun, oldlun->l_ctl_lun);
2090 TAILQ_FOREACH_SAFE(newlun, &newconf->conf_luns, l_next, tmplun) {
2091 oldlun = lun_find(oldconf, newlun->l_name);
2092 if (oldlun != NULL) {
2093 log_debugx("modifying lun \"%s\", CTL lun %d",
2094 newlun->l_name, newlun->l_ctl_lun);
2095 error = kernel_lun_modify(newlun);
2097 log_warnx("failed to "
2098 "modify lun \"%s\", CTL lun %d",
2099 newlun->l_name, newlun->l_ctl_lun);
2104 log_debugx("adding lun \"%s\"", newlun->l_name);
2105 error = kernel_lun_add(newlun);
2107 log_warnx("failed to add lun \"%s\"", newlun->l_name);
2114 * Now add new ports or modify existing ones.
2116 TAILQ_FOREACH(newport, &newconf->conf_ports, p_next) {
2117 if (port_is_dummy(newport))
2119 oldport = port_find(oldconf, newport->p_name);
2121 if (oldport == NULL || port_is_dummy(oldport)) {
2122 log_debugx("adding port \"%s\"", newport->p_name);
2123 error = kernel_port_add(newport);
2125 log_debugx("updating port \"%s\"", newport->p_name);
2126 newport->p_ctl_port = oldport->p_ctl_port;
2127 error = kernel_port_update(newport, oldport);
2130 log_warnx("failed to %s port %s",
2131 (oldport == NULL) ? "add" : "update",
2134 * XXX: Uncomment after fixing the root cause.
2136 * cumulated_error++;
2142 * Go through the new portals, opening the sockets as necessary.
2144 TAILQ_FOREACH(newpg, &newconf->conf_portal_groups, pg_next) {
2145 if (newpg->pg_foreign)
2147 if (newpg->pg_unassigned) {
2148 log_debugx("not listening on portal-group \"%s\", "
2149 "not assigned to any target",
2153 TAILQ_FOREACH(newp, &newpg->pg_portals, p_next) {
2155 * Try to find already open portal and reuse
2156 * the listening socket. We don't care about
2157 * what portal or portal group that was, what
2158 * matters is the listening address.
2160 TAILQ_FOREACH(oldpg, &oldconf->conf_portal_groups,
2162 TAILQ_FOREACH(oldp, &oldpg->pg_portals,
2164 if (strcmp(newp->p_listen,
2165 oldp->p_listen) == 0 &&
2166 oldp->p_socket > 0) {
2174 if (newp->p_socket > 0) {
2176 * We're done with this portal.
2181 #ifdef ICL_KERNEL_PROXY
2183 newpg->pg_conf->conf_portal_id++;
2184 newp->p_id = newpg->pg_conf->conf_portal_id;
2185 log_debugx("listening on %s, portal-group "
2186 "\"%s\", portal id %d, using ICL proxy",
2187 newp->p_listen, newpg->pg_name, newp->p_id);
2188 kernel_listen(newp->p_ai, newp->p_iser,
2193 assert(proxy_mode == false);
2194 assert(newp->p_iser == false);
2196 log_debugx("listening on %s, portal-group \"%s\"",
2197 newp->p_listen, newpg->pg_name);
2198 newp->p_socket = socket(newp->p_ai->ai_family,
2199 newp->p_ai->ai_socktype,
2200 newp->p_ai->ai_protocol);
2201 if (newp->p_socket < 0) {
2202 log_warn("socket(2) failed for %s",
2207 sockbuf = SOCKBUF_SIZE;
2208 if (setsockopt(newp->p_socket, SOL_SOCKET, SO_RCVBUF,
2209 &sockbuf, sizeof(sockbuf)) == -1)
2210 log_warn("setsockopt(SO_RCVBUF) failed "
2211 "for %s", newp->p_listen);
2212 sockbuf = SOCKBUF_SIZE;
2213 if (setsockopt(newp->p_socket, SOL_SOCKET, SO_SNDBUF,
2214 &sockbuf, sizeof(sockbuf)) == -1)
2215 log_warn("setsockopt(SO_SNDBUF) failed "
2216 "for %s", newp->p_listen);
2217 if (setsockopt(newp->p_socket, SOL_SOCKET, SO_NO_DDP,
2218 &one, sizeof(one)) == -1)
2219 log_warn("setsockopt(SO_NO_DDP) failed "
2220 "for %s", newp->p_listen);
2221 error = setsockopt(newp->p_socket, SOL_SOCKET,
2222 SO_REUSEADDR, &one, sizeof(one));
2224 log_warn("setsockopt(SO_REUSEADDR) failed "
2225 "for %s", newp->p_listen);
2226 close(newp->p_socket);
2231 if (newpg->pg_dscp != -1) {
2233 int len = sizeof(sa);
2234 getsockname(newp->p_socket, &sa, &len);
2236 * Only allow the 6-bit DSCP
2237 * field to be modified
2239 int tos = newpg->pg_dscp << 2;
2240 if (sa.sa_family == AF_INET) {
2241 if (setsockopt(newp->p_socket,
2243 &tos, sizeof(tos)) == -1)
2244 log_warn("setsockopt(IP_TOS) "
2248 if (sa.sa_family == AF_INET6) {
2249 if (setsockopt(newp->p_socket,
2250 IPPROTO_IPV6, IPV6_TCLASS,
2251 &tos, sizeof(tos)) == -1)
2252 log_warn("setsockopt(IPV6_TCLASS) "
2257 if (newpg->pg_pcp != -1) {
2259 int len = sizeof(sa);
2260 getsockname(newp->p_socket, &sa, &len);
2262 * Only allow the 6-bit DSCP
2263 * field to be modified
2265 int pcp = newpg->pg_pcp;
2266 if (sa.sa_family == AF_INET) {
2267 if (setsockopt(newp->p_socket,
2268 IPPROTO_IP, IP_VLAN_PCP,
2269 &pcp, sizeof(pcp)) == -1)
2270 log_warn("setsockopt(IP_VLAN_PCP) "
2274 if (sa.sa_family == AF_INET6) {
2275 if (setsockopt(newp->p_socket,
2276 IPPROTO_IPV6, IPV6_VLAN_PCP,
2277 &pcp, sizeof(pcp)) == -1)
2278 log_warn("setsockopt(IPV6_VLAN_PCP) "
2283 error = bind(newp->p_socket, newp->p_ai->ai_addr,
2284 newp->p_ai->ai_addrlen);
2286 log_warn("bind(2) failed for %s",
2288 close(newp->p_socket);
2293 error = listen(newp->p_socket, -1);
2295 log_warn("listen(2) failed for %s",
2297 close(newp->p_socket);
2306 * Go through the no longer used sockets, closing them.
2308 TAILQ_FOREACH(oldpg, &oldconf->conf_portal_groups, pg_next) {
2309 TAILQ_FOREACH(oldp, &oldpg->pg_portals, p_next) {
2310 if (oldp->p_socket <= 0)
2312 log_debugx("closing socket for %s, portal-group \"%s\"",
2313 oldp->p_listen, oldpg->pg_name);
2314 close(oldp->p_socket);
2319 /* (Re-)Register on remaining/new iSNS servers. */
2320 TAILQ_FOREACH(newns, &newconf->conf_isns, i_next) {
2321 TAILQ_FOREACH(oldns, &oldconf->conf_isns, i_next) {
2322 if (strcmp(oldns->i_addr, newns->i_addr) == 0)
2325 isns_register(newns, oldns);
2328 /* Schedule iSNS update */
2329 if (!TAILQ_EMPTY(&newconf->conf_isns))
2330 set_timeout((newconf->conf_isns_period + 2) / 3, false);
2332 return (cumulated_error);
2339 return (sigalrm_received);
2343 sigalrm_handler_fatal(int dummy __unused)
2346 * It would be easiest to just log an error and exit. We can't
2347 * do this, though, because log_errx() is not signal safe, since
2348 * it calls syslog(3). Instead, set a flag checked by pdu_send()
2349 * and pdu_receive(), to call log_errx() there. Should they fail
2350 * to notice, we'll exit here one second later.
2352 if (sigalrm_received) {
2354 * Oh well. Just give up and quit.
2359 sigalrm_received = true;
2363 sigalrm_handler(int dummy __unused)
2366 sigalrm_received = true;
2370 set_timeout(int timeout, int fatal)
2372 struct sigaction sa;
2373 struct itimerval itv;
2377 log_debugx("session timeout disabled");
2378 bzero(&itv, sizeof(itv));
2379 error = setitimer(ITIMER_REAL, &itv, NULL);
2381 log_err(1, "setitimer");
2382 sigalrm_received = false;
2386 sigalrm_received = false;
2387 bzero(&sa, sizeof(sa));
2389 sa.sa_handler = sigalrm_handler_fatal;
2391 sa.sa_handler = sigalrm_handler;
2392 sigfillset(&sa.sa_mask);
2393 error = sigaction(SIGALRM, &sa, NULL);
2395 log_err(1, "sigaction");
2398 * First SIGALRM will arive after conf_timeout seconds.
2399 * If we do nothing, another one will arrive a second later.
2401 log_debugx("setting session timeout to %d seconds", timeout);
2402 bzero(&itv, sizeof(itv));
2403 itv.it_interval.tv_sec = 1;
2404 itv.it_value.tv_sec = timeout;
2405 error = setitimer(ITIMER_REAL, &itv, NULL);
2407 log_err(1, "setitimer");
2411 wait_for_children(bool block)
2419 * If "block" is true, wait for at least one process.
2421 if (block && num == 0)
2422 pid = wait4(-1, &status, 0, NULL);
2424 pid = wait4(-1, &status, WNOHANG, NULL);
2427 if (WIFSIGNALED(status)) {
2428 log_warnx("child process %d terminated with signal %d",
2429 pid, WTERMSIG(status));
2430 } else if (WEXITSTATUS(status) != 0) {
2431 log_warnx("child process %d terminated with exit status %d",
2432 pid, WEXITSTATUS(status));
2434 log_debugx("child process %d terminated gracefully", pid);
2443 handle_connection(struct portal *portal, int fd,
2444 const struct sockaddr *client_sa, bool dont_fork)
2446 struct ctld_connection *conn;
2449 char host[NI_MAXHOST + 1];
2452 conf = portal->p_portal_group->pg_conf;
2455 log_debugx("incoming connection; not forking due to -d flag");
2457 nchildren -= wait_for_children(false);
2458 assert(nchildren >= 0);
2460 while (conf->conf_maxproc > 0 && nchildren >= conf->conf_maxproc) {
2461 log_debugx("maxproc limit of %d child processes hit; "
2462 "waiting for child process to exit", conf->conf_maxproc);
2463 nchildren -= wait_for_children(true);
2464 assert(nchildren >= 0);
2466 log_debugx("incoming connection; forking child process #%d",
2477 pidfile_close(conf->conf_pidfh);
2479 error = getnameinfo(client_sa, client_sa->sa_len,
2480 host, sizeof(host), NULL, 0, NI_NUMERICHOST);
2482 log_errx(1, "getnameinfo: %s", gai_strerror(error));
2484 log_debugx("accepted connection from %s; portal group \"%s\"",
2485 host, portal->p_portal_group->pg_name);
2486 log_set_peer_addr(host);
2487 setproctitle("%s", host);
2489 conn = connection_new(portal, fd, host, client_sa);
2490 set_timeout(conf->conf_timeout, true);
2493 if (conn->conn_session_type == CONN_SESSION_TYPE_NORMAL) {
2494 kernel_handoff(conn);
2495 log_debugx("connection handed off to the kernel");
2497 assert(conn->conn_session_type == CONN_SESSION_TYPE_DISCOVERY);
2500 log_debugx("nothing more to do; exiting");
2505 fd_add(int fd, fd_set *fdset, int nfds)
2509 * Skip sockets which we failed to bind.
2521 main_loop(struct conf *conf, bool dont_fork)
2523 struct portal_group *pg;
2524 struct portal *portal;
2525 struct sockaddr_storage client_sa;
2526 socklen_t client_salen;
2527 #ifdef ICL_KERNEL_PROXY
2532 int error, nfds, client_fd;
2534 pidfile_write(conf->conf_pidfh);
2537 if (sighup_received || sigterm_received || timed_out())
2540 #ifdef ICL_KERNEL_PROXY
2542 client_salen = sizeof(client_sa);
2543 kernel_accept(&connection_id, &portal_id,
2544 (struct sockaddr *)&client_sa, &client_salen);
2545 assert(client_salen >= client_sa.ss_len);
2547 log_debugx("incoming connection, id %d, portal id %d",
2548 connection_id, portal_id);
2549 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
2550 TAILQ_FOREACH(portal, &pg->pg_portals, p_next) {
2551 if (portal->p_id == portal_id) {
2557 log_errx(1, "kernel returned invalid portal_id %d",
2561 handle_connection(portal, connection_id,
2562 (struct sockaddr *)&client_sa, dont_fork);
2565 assert(proxy_mode == false);
2569 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
2570 TAILQ_FOREACH(portal, &pg->pg_portals, p_next)
2571 nfds = fd_add(portal->p_socket, &fdset, nfds);
2573 error = select(nfds + 1, &fdset, NULL, NULL, NULL);
2577 log_err(1, "select");
2579 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
2580 TAILQ_FOREACH(portal, &pg->pg_portals, p_next) {
2581 if (!FD_ISSET(portal->p_socket, &fdset))
2583 client_salen = sizeof(client_sa);
2584 client_fd = accept(portal->p_socket,
2585 (struct sockaddr *)&client_sa,
2587 if (client_fd < 0) {
2588 if (errno == ECONNABORTED)
2590 log_err(1, "accept");
2592 assert(client_salen >= client_sa.ss_len);
2594 handle_connection(portal, client_fd,
2595 (struct sockaddr *)&client_sa,
2600 #ifdef ICL_KERNEL_PROXY
2607 sighup_handler(int dummy __unused)
2610 sighup_received = true;
2614 sigterm_handler(int dummy __unused)
2617 sigterm_received = true;
2621 sigchld_handler(int dummy __unused)
2625 * The only purpose of this handler is to make SIGCHLD
2626 * interrupt the ISCSIDWAIT ioctl(2), so we can call
2627 * wait_for_children().
2632 register_signals(void)
2634 struct sigaction sa;
2637 bzero(&sa, sizeof(sa));
2638 sa.sa_handler = sighup_handler;
2639 sigfillset(&sa.sa_mask);
2640 error = sigaction(SIGHUP, &sa, NULL);
2642 log_err(1, "sigaction");
2644 sa.sa_handler = sigterm_handler;
2645 error = sigaction(SIGTERM, &sa, NULL);
2647 log_err(1, "sigaction");
2649 sa.sa_handler = sigterm_handler;
2650 error = sigaction(SIGINT, &sa, NULL);
2652 log_err(1, "sigaction");
2654 sa.sa_handler = sigchld_handler;
2655 error = sigaction(SIGCHLD, &sa, NULL);
2657 log_err(1, "sigaction");
2661 check_perms(const char *path)
2666 error = stat(path, &sb);
2671 if (sb.st_mode & S_IWOTH) {
2672 log_warnx("%s is world-writable", path);
2673 } else if (sb.st_mode & S_IROTH) {
2674 log_warnx("%s is world-readable", path);
2675 } else if (sb.st_mode & S_IXOTH) {
2677 * Ok, this one doesn't matter, but still do it,
2678 * just for consistency.
2680 log_warnx("%s is world-executable", path);
2684 * XXX: Should we also check for owner != 0?
2688 static struct conf *
2689 conf_new_from_file(const char *path, struct conf *oldconf, bool ucl)
2692 struct auth_group *ag;
2693 struct portal_group *pg;
2697 log_debugx("obtaining configuration from %s", path);
2701 TAILQ_FOREACH(pp, &oldconf->conf_pports, pp_next)
2702 pport_copy(pp, conf);
2704 ag = auth_group_new(conf, "default");
2707 ag = auth_group_new(conf, "no-authentication");
2709 ag->ag_type = AG_TYPE_NO_AUTHENTICATION;
2711 ag = auth_group_new(conf, "no-access");
2713 ag->ag_type = AG_TYPE_DENY;
2715 pg = portal_group_new(conf, "default");
2719 error = uclparse_conf(conf, path);
2721 error = parse_conf(conf, path);
2730 if (conf->conf_default_ag_defined == false) {
2731 log_debugx("auth-group \"default\" not defined; "
2732 "going with defaults");
2733 ag = auth_group_find(conf, "default");
2735 ag->ag_type = AG_TYPE_DENY;
2738 if (conf->conf_default_pg_defined == false) {
2739 log_debugx("portal-group \"default\" not defined; "
2740 "going with defaults");
2741 pg = portal_group_find(conf, "default");
2743 portal_group_add_listen(pg, "0.0.0.0:3260", false);
2744 portal_group_add_listen(pg, "[::]:3260", false);
2747 conf->conf_kernel_port_on = true;
2749 error = conf_verify(conf);
2759 main(int argc, char **argv)
2761 struct conf *oldconf, *newconf, *tmpconf;
2763 const char *config_path = DEFAULT_CONFIG_PATH;
2764 int debug = 0, ch, error;
2765 bool dont_daemonize = false;
2766 bool test_config = false;
2767 bool use_ucl = false;
2769 while ((ch = getopt(argc, argv, "dtuf:R")) != -1) {
2772 dont_daemonize = true;
2782 config_path = optarg;
2785 #ifndef ICL_KERNEL_PROXY
2786 log_errx(1, "ctld(8) compiled without ICL_KERNEL_PROXY "
2787 "does not support iSER protocol");
2803 oldconf = conf_new_from_kernel();
2804 newconf = conf_new_from_file(config_path, oldconf, use_ucl);
2806 if (newconf == NULL)
2807 log_errx(1, "configuration error; exiting");
2813 oldconf->conf_debug = debug;
2814 newconf->conf_debug = debug;
2817 error = conf_apply(oldconf, newconf);
2819 log_errx(1, "failed to apply configuration; exiting");
2821 conf_delete(oldconf);
2826 if (dont_daemonize == false) {
2827 log_debugx("daemonizing");
2828 if (daemon(0, 0) == -1) {
2829 log_warn("cannot daemonize");
2830 pidfile_remove(newconf->conf_pidfh);
2835 /* Schedule iSNS update */
2836 if (!TAILQ_EMPTY(&newconf->conf_isns))
2837 set_timeout((newconf->conf_isns_period + 2) / 3, false);
2840 main_loop(newconf, dont_daemonize);
2841 if (sighup_received) {
2842 sighup_received = false;
2843 log_debugx("received SIGHUP, reloading configuration");
2844 tmpconf = conf_new_from_file(config_path, newconf,
2847 if (tmpconf == NULL) {
2848 log_warnx("configuration error, "
2849 "continuing with old configuration");
2852 tmpconf->conf_debug = debug;
2855 error = conf_apply(oldconf, newconf);
2857 log_warnx("failed to reload "
2859 conf_delete(oldconf);
2862 } else if (sigterm_received) {
2863 log_debugx("exiting on signal; "
2864 "reloading empty configuration");
2866 log_debugx("removing CTL iSCSI ports "
2867 "and terminating all connections");
2870 newconf = conf_new();
2872 newconf->conf_debug = debug;
2873 error = conf_apply(oldconf, newconf);
2875 log_warnx("failed to apply configuration");
2876 conf_delete(oldconf);
2879 log_warnx("exiting on signal");
2882 nchildren -= wait_for_children(false);
2883 assert(nchildren >= 0);
2885 set_timeout(0, false);
2886 TAILQ_FOREACH(newns, &newconf->conf_isns, i_next)
2888 /* Schedule iSNS update */
2889 if (!TAILQ_EMPTY(&newconf->conf_isns)) {
2890 set_timeout((newconf->conf_isns_period