2 * SPDX-License-Identifier: BSD-2-Clause
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/types.h>
34 #include <sys/socket.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
54 static bool timed_out(void);
55 #ifdef ICL_KERNEL_PROXY
56 static void pdu_receive_proxy(struct pdu *pdu);
57 static void pdu_send_proxy(struct pdu *pdu);
58 #endif /* ICL_KERNEL_PROXY */
59 static void pdu_fail(const struct connection *conn, const char *reason);
61 bool proxy_mode = false;
63 static volatile bool sighup_received = false;
64 static volatile bool sigterm_received = false;
65 static volatile bool sigalrm_received = false;
67 static int nchildren = 0;
68 static uint16_t last_portal_group_tag = 0xff;
70 static struct connection_ops conn_ops = {
71 .timed_out = timed_out,
72 #ifdef ICL_KERNEL_PROXY
73 .pdu_receive_proxy = pdu_receive_proxy,
74 .pdu_send_proxy = pdu_send_proxy,
83 fprintf(stderr, "usage: ctld [-d][-u][-f config-file]\n");
84 fprintf(stderr, " ctld -t [-u][-f config-file]\n");
93 conf = calloc(1, sizeof(*conf));
96 TAILQ_INIT(&conf->conf_luns);
97 TAILQ_INIT(&conf->conf_targets);
98 TAILQ_INIT(&conf->conf_auth_groups);
99 TAILQ_INIT(&conf->conf_ports);
100 TAILQ_INIT(&conf->conf_portal_groups);
101 TAILQ_INIT(&conf->conf_pports);
102 TAILQ_INIT(&conf->conf_isns);
104 conf->conf_isns_period = 900;
105 conf->conf_isns_timeout = 5;
106 conf->conf_debug = 0;
107 conf->conf_timeout = 60;
108 conf->conf_maxproc = 30;
114 conf_delete(struct conf *conf)
116 struct lun *lun, *ltmp;
117 struct target *targ, *tmp;
118 struct auth_group *ag, *cagtmp;
119 struct portal_group *pg, *cpgtmp;
120 struct pport *pp, *pptmp;
121 struct isns *is, *istmp;
123 assert(conf->conf_pidfh == NULL);
125 TAILQ_FOREACH_SAFE(lun, &conf->conf_luns, l_next, ltmp)
127 TAILQ_FOREACH_SAFE(targ, &conf->conf_targets, t_next, tmp)
129 TAILQ_FOREACH_SAFE(ag, &conf->conf_auth_groups, ag_next, cagtmp)
130 auth_group_delete(ag);
131 TAILQ_FOREACH_SAFE(pg, &conf->conf_portal_groups, pg_next, cpgtmp)
132 portal_group_delete(pg);
133 TAILQ_FOREACH_SAFE(pp, &conf->conf_pports, pp_next, pptmp)
135 TAILQ_FOREACH_SAFE(is, &conf->conf_isns, i_next, istmp)
137 assert(TAILQ_EMPTY(&conf->conf_ports));
138 free(conf->conf_pidfile_path);
143 auth_new(struct auth_group *ag)
147 auth = calloc(1, sizeof(*auth));
149 log_err(1, "calloc");
150 auth->a_auth_group = ag;
151 TAILQ_INSERT_TAIL(&ag->ag_auths, auth, a_next);
156 auth_delete(struct auth *auth)
158 TAILQ_REMOVE(&auth->a_auth_group->ag_auths, auth, a_next);
161 free(auth->a_secret);
162 free(auth->a_mutual_user);
163 free(auth->a_mutual_secret);
168 auth_find(const struct auth_group *ag, const char *user)
170 const struct auth *auth;
172 TAILQ_FOREACH(auth, &ag->ag_auths, a_next) {
173 if (strcmp(auth->a_user, user) == 0)
181 auth_check_secret_length(struct auth *auth)
185 len = strlen(auth->a_secret);
187 if (auth->a_auth_group->ag_name != NULL)
188 log_warnx("secret for user \"%s\", auth-group \"%s\", "
189 "is too long; it should be at most 16 characters "
190 "long", auth->a_user, auth->a_auth_group->ag_name);
192 log_warnx("secret for user \"%s\", target \"%s\", "
193 "is too long; it should be at most 16 characters "
194 "long", auth->a_user,
195 auth->a_auth_group->ag_target->t_name);
198 if (auth->a_auth_group->ag_name != NULL)
199 log_warnx("secret for user \"%s\", auth-group \"%s\", "
200 "is too short; it should be at least 12 characters "
201 "long", auth->a_user,
202 auth->a_auth_group->ag_name);
204 log_warnx("secret for user \"%s\", target \"%s\", "
205 "is too short; it should be at least 12 characters "
206 "long", auth->a_user,
207 auth->a_auth_group->ag_target->t_name);
210 if (auth->a_mutual_secret != NULL) {
211 len = strlen(auth->a_mutual_secret);
213 if (auth->a_auth_group->ag_name != NULL)
214 log_warnx("mutual secret for user \"%s\", "
215 "auth-group \"%s\", is too long; it should "
216 "be at most 16 characters long",
217 auth->a_user, auth->a_auth_group->ag_name);
219 log_warnx("mutual secret for user \"%s\", "
220 "target \"%s\", is too long; it should "
221 "be at most 16 characters long",
223 auth->a_auth_group->ag_target->t_name);
226 if (auth->a_auth_group->ag_name != NULL)
227 log_warnx("mutual secret for user \"%s\", "
228 "auth-group \"%s\", is too short; it "
229 "should be at least 12 characters long",
230 auth->a_user, auth->a_auth_group->ag_name);
232 log_warnx("mutual secret for user \"%s\", "
233 "target \"%s\", is too short; it should be "
234 "at least 12 characters long",
236 auth->a_auth_group->ag_target->t_name);
242 auth_new_chap(struct auth_group *ag, const char *user,
247 if (ag->ag_type == AG_TYPE_UNKNOWN)
248 ag->ag_type = AG_TYPE_CHAP;
249 if (ag->ag_type != AG_TYPE_CHAP) {
250 if (ag->ag_name != NULL)
251 log_warnx("cannot mix \"chap\" authentication with "
252 "other types for auth-group \"%s\"", ag->ag_name);
254 log_warnx("cannot mix \"chap\" authentication with "
255 "other types for target \"%s\"",
256 ag->ag_target->t_name);
261 auth->a_user = checked_strdup(user);
262 auth->a_secret = checked_strdup(secret);
264 auth_check_secret_length(auth);
270 auth_new_chap_mutual(struct auth_group *ag, const char *user,
271 const char *secret, const char *user2, const char *secret2)
275 if (ag->ag_type == AG_TYPE_UNKNOWN)
276 ag->ag_type = AG_TYPE_CHAP_MUTUAL;
277 if (ag->ag_type != AG_TYPE_CHAP_MUTUAL) {
278 if (ag->ag_name != NULL)
279 log_warnx("cannot mix \"chap-mutual\" authentication "
280 "with other types for auth-group \"%s\"",
283 log_warnx("cannot mix \"chap-mutual\" authentication "
284 "with other types for target \"%s\"",
285 ag->ag_target->t_name);
290 auth->a_user = checked_strdup(user);
291 auth->a_secret = checked_strdup(secret);
292 auth->a_mutual_user = checked_strdup(user2);
293 auth->a_mutual_secret = checked_strdup(secret2);
295 auth_check_secret_length(auth);
300 const struct auth_name *
301 auth_name_new(struct auth_group *ag, const char *name)
303 struct auth_name *an;
305 an = calloc(1, sizeof(*an));
307 log_err(1, "calloc");
308 an->an_auth_group = ag;
309 an->an_initiator_name = checked_strdup(name);
310 TAILQ_INSERT_TAIL(&ag->ag_names, an, an_next);
315 auth_name_delete(struct auth_name *an)
317 TAILQ_REMOVE(&an->an_auth_group->ag_names, an, an_next);
319 free(an->an_initiator_name);
324 auth_name_defined(const struct auth_group *ag)
326 if (TAILQ_EMPTY(&ag->ag_names))
331 const struct auth_name *
332 auth_name_find(const struct auth_group *ag, const char *name)
334 const struct auth_name *auth_name;
336 TAILQ_FOREACH(auth_name, &ag->ag_names, an_next) {
337 if (strcmp(auth_name->an_initiator_name, name) == 0)
345 auth_name_check(const struct auth_group *ag, const char *initiator_name)
347 if (!auth_name_defined(ag))
350 if (auth_name_find(ag, initiator_name) == NULL)
356 const struct auth_portal *
357 auth_portal_new(struct auth_group *ag, const char *portal)
359 struct auth_portal *ap;
360 char *net, *mask, *str, *tmp;
363 ap = calloc(1, sizeof(*ap));
365 log_err(1, "calloc");
366 ap->ap_auth_group = ag;
367 ap->ap_initiator_portal = checked_strdup(portal);
368 mask = str = checked_strdup(portal);
369 net = strsep(&mask, "/");
375 if (net[len - 1] == ']')
377 if (strchr(net, ':') != NULL) {
378 struct sockaddr_in6 *sin6 =
379 (struct sockaddr_in6 *)&ap->ap_sa;
381 sin6->sin6_len = sizeof(*sin6);
382 sin6->sin6_family = AF_INET6;
383 if (inet_pton(AF_INET6, net, &sin6->sin6_addr) <= 0)
387 struct sockaddr_in *sin =
388 (struct sockaddr_in *)&ap->ap_sa;
390 sin->sin_len = sizeof(*sin);
391 sin->sin_family = AF_INET;
392 if (inet_pton(AF_INET, net, &sin->sin_addr) <= 0)
397 m = strtol(mask, &tmp, 0);
398 if (m < 0 || m > dm || tmp[0] != 0)
404 TAILQ_INSERT_TAIL(&ag->ag_portals, ap, ap_next);
410 log_warnx("incorrect initiator portal \"%s\"", portal);
415 auth_portal_delete(struct auth_portal *ap)
417 TAILQ_REMOVE(&ap->ap_auth_group->ag_portals, ap, ap_next);
419 free(ap->ap_initiator_portal);
424 auth_portal_defined(const struct auth_group *ag)
426 if (TAILQ_EMPTY(&ag->ag_portals))
431 const struct auth_portal *
432 auth_portal_find(const struct auth_group *ag, const struct sockaddr_storage *ss)
434 const struct auth_portal *ap;
435 const uint8_t *a, *b;
439 TAILQ_FOREACH(ap, &ag->ag_portals, ap_next) {
440 if (ap->ap_sa.ss_family != ss->ss_family)
442 if (ss->ss_family == AF_INET) {
443 a = (const uint8_t *)
444 &((const struct sockaddr_in *)ss)->sin_addr;
445 b = (const uint8_t *)
446 &((const struct sockaddr_in *)&ap->ap_sa)->sin_addr;
448 a = (const uint8_t *)
449 &((const struct sockaddr_in6 *)ss)->sin6_addr;
450 b = (const uint8_t *)
451 &((const struct sockaddr_in6 *)&ap->ap_sa)->sin6_addr;
453 for (i = 0; i < ap->ap_mask / 8; i++) {
457 if (ap->ap_mask % 8) {
458 bmask = 0xff << (8 - (ap->ap_mask % 8));
459 if ((a[i] & bmask) != (b[i] & bmask))
471 auth_portal_check(const struct auth_group *ag, const struct sockaddr_storage *sa)
474 if (!auth_portal_defined(ag))
477 if (auth_portal_find(ag, sa) == NULL)
484 auth_group_new(struct conf *conf, const char *name)
486 struct auth_group *ag;
489 ag = auth_group_find(conf, name);
491 log_warnx("duplicated auth-group \"%s\"", name);
496 ag = calloc(1, sizeof(*ag));
498 log_err(1, "calloc");
500 ag->ag_name = checked_strdup(name);
501 TAILQ_INIT(&ag->ag_auths);
502 TAILQ_INIT(&ag->ag_names);
503 TAILQ_INIT(&ag->ag_portals);
505 TAILQ_INSERT_TAIL(&conf->conf_auth_groups, ag, ag_next);
511 auth_group_delete(struct auth_group *ag)
513 struct auth *auth, *auth_tmp;
514 struct auth_name *auth_name, *auth_name_tmp;
515 struct auth_portal *auth_portal, *auth_portal_tmp;
517 TAILQ_REMOVE(&ag->ag_conf->conf_auth_groups, ag, ag_next);
519 TAILQ_FOREACH_SAFE(auth, &ag->ag_auths, a_next, auth_tmp)
521 TAILQ_FOREACH_SAFE(auth_name, &ag->ag_names, an_next, auth_name_tmp)
522 auth_name_delete(auth_name);
523 TAILQ_FOREACH_SAFE(auth_portal, &ag->ag_portals, ap_next,
525 auth_portal_delete(auth_portal);
531 auth_group_find(const struct conf *conf, const char *name)
533 struct auth_group *ag;
535 TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) {
536 if (ag->ag_name != NULL && strcmp(ag->ag_name, name) == 0)
544 auth_group_set_type(struct auth_group *ag, const char *str)
548 if (strcmp(str, "none") == 0) {
549 type = AG_TYPE_NO_AUTHENTICATION;
550 } else if (strcmp(str, "deny") == 0) {
552 } else if (strcmp(str, "chap") == 0) {
554 } else if (strcmp(str, "chap-mutual") == 0) {
555 type = AG_TYPE_CHAP_MUTUAL;
557 if (ag->ag_name != NULL)
558 log_warnx("invalid auth-type \"%s\" for auth-group "
559 "\"%s\"", str, ag->ag_name);
561 log_warnx("invalid auth-type \"%s\" for target "
562 "\"%s\"", str, ag->ag_target->t_name);
566 if (ag->ag_type != AG_TYPE_UNKNOWN && ag->ag_type != type) {
567 if (ag->ag_name != NULL) {
568 log_warnx("cannot set auth-type to \"%s\" for "
569 "auth-group \"%s\"; already has a different "
570 "type", str, ag->ag_name);
572 log_warnx("cannot set auth-type to \"%s\" for target "
573 "\"%s\"; already has a different type",
574 str, ag->ag_target->t_name);
584 static struct portal *
585 portal_new(struct portal_group *pg)
587 struct portal *portal;
589 portal = calloc(1, sizeof(*portal));
591 log_err(1, "calloc");
592 TAILQ_INIT(&portal->p_targets);
593 portal->p_portal_group = pg;
594 TAILQ_INSERT_TAIL(&pg->pg_portals, portal, p_next);
599 portal_delete(struct portal *portal)
602 TAILQ_REMOVE(&portal->p_portal_group->pg_portals, portal, p_next);
603 if (portal->p_ai != NULL)
604 freeaddrinfo(portal->p_ai);
605 free(portal->p_listen);
609 struct portal_group *
610 portal_group_new(struct conf *conf, const char *name)
612 struct portal_group *pg;
614 pg = portal_group_find(conf, name);
616 log_warnx("duplicated portal-group \"%s\"", name);
620 pg = calloc(1, sizeof(*pg));
622 log_err(1, "calloc");
623 pg->pg_name = checked_strdup(name);
624 TAILQ_INIT(&pg->pg_options);
625 TAILQ_INIT(&pg->pg_portals);
626 TAILQ_INIT(&pg->pg_ports);
628 pg->pg_tag = 0; /* Assigned later in conf_apply(). */
631 TAILQ_INSERT_TAIL(&conf->conf_portal_groups, pg, pg_next);
637 portal_group_delete(struct portal_group *pg)
639 struct portal *portal, *tmp;
640 struct port *port, *tport;
641 struct option *o, *otmp;
643 TAILQ_FOREACH_SAFE(port, &pg->pg_ports, p_pgs, tport)
645 TAILQ_REMOVE(&pg->pg_conf->conf_portal_groups, pg, pg_next);
647 TAILQ_FOREACH_SAFE(portal, &pg->pg_portals, p_next, tmp)
648 portal_delete(portal);
649 TAILQ_FOREACH_SAFE(o, &pg->pg_options, o_next, otmp)
650 option_delete(&pg->pg_options, o);
652 free(pg->pg_offload);
653 free(pg->pg_redirection);
657 struct portal_group *
658 portal_group_find(const struct conf *conf, const char *name)
660 struct portal_group *pg;
662 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
663 if (strcmp(pg->pg_name, name) == 0)
671 parse_addr_port(char *arg, const char *def_port, struct addrinfo **ai)
673 struct addrinfo hints;
674 char *str, *addr, *ch;
676 int error, colons = 0;
678 str = arg = strdup(arg);
681 * IPv6 address in square brackets, perhaps with port.
684 addr = strsep(&arg, "]");
689 if (arg[0] == '\0') {
691 } else if (arg[0] == ':') {
699 * Either IPv6 address without brackets - and without
700 * a port - or IPv4 address. Just count the colons.
702 for (ch = arg; *ch != '\0'; ch++) {
710 addr = strsep(&arg, ":");
718 memset(&hints, 0, sizeof(hints));
719 hints.ai_family = PF_UNSPEC;
720 hints.ai_socktype = SOCK_STREAM;
721 hints.ai_flags = AI_PASSIVE;
722 error = getaddrinfo(addr, port, &hints, ai);
724 return ((error != 0) ? 1 : 0);
728 portal_group_add_listen(struct portal_group *pg, const char *value, bool iser)
730 struct portal *portal;
732 portal = portal_new(pg);
733 portal->p_listen = checked_strdup(value);
734 portal->p_iser = iser;
736 if (parse_addr_port(portal->p_listen, "3260", &portal->p_ai)) {
737 log_warnx("invalid listen address %s", portal->p_listen);
738 portal_delete(portal);
743 * XXX: getaddrinfo(3) may return multiple addresses; we should turn
744 * those into multiple portals.
751 isns_new(struct conf *conf, const char *addr)
755 isns = calloc(1, sizeof(*isns));
757 log_err(1, "calloc");
759 TAILQ_INSERT_TAIL(&conf->conf_isns, isns, i_next);
760 isns->i_addr = checked_strdup(addr);
762 if (parse_addr_port(isns->i_addr, "3205", &isns->i_ai)) {
763 log_warnx("invalid iSNS address %s", isns->i_addr);
769 * XXX: getaddrinfo(3) may return multiple addresses; we should turn
770 * those into multiple servers.
777 isns_delete(struct isns *isns)
780 TAILQ_REMOVE(&isns->i_conf->conf_isns, isns, i_next);
782 if (isns->i_ai != NULL)
783 freeaddrinfo(isns->i_ai);
788 isns_do_connect(struct isns *isns)
792 s = socket(isns->i_ai->ai_family, isns->i_ai->ai_socktype,
793 isns->i_ai->ai_protocol);
795 log_warn("socket(2) failed for %s", isns->i_addr);
798 if (connect(s, isns->i_ai->ai_addr, isns->i_ai->ai_addrlen)) {
799 log_warn("connect(2) failed for %s", isns->i_addr);
807 isns_do_register(struct isns *isns, int s, const char *hostname)
809 struct conf *conf = isns->i_conf;
810 struct target *target;
811 struct portal *portal;
812 struct portal_group *pg;
814 struct isns_req *req;
818 req = isns_req_create(ISNS_FUNC_DEVATTRREG, ISNS_FLAG_CLIENT);
819 isns_req_add_str(req, 32, TAILQ_FIRST(&conf->conf_targets)->t_name);
820 isns_req_add_delim(req);
821 isns_req_add_str(req, 1, hostname);
822 isns_req_add_32(req, 2, 2); /* 2 -- iSCSI */
823 isns_req_add_32(req, 6, conf->conf_isns_period);
824 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
825 if (pg->pg_unassigned)
827 TAILQ_FOREACH(portal, &pg->pg_portals, p_next) {
828 isns_req_add_addr(req, 16, portal->p_ai);
829 isns_req_add_port(req, 17, portal->p_ai);
832 TAILQ_FOREACH(target, &conf->conf_targets, t_next) {
833 isns_req_add_str(req, 32, target->t_name);
834 isns_req_add_32(req, 33, 1); /* 1 -- Target*/
835 if (target->t_alias != NULL)
836 isns_req_add_str(req, 34, target->t_alias);
837 TAILQ_FOREACH(port, &target->t_ports, p_ts) {
838 if ((pg = port->p_portal_group) == NULL)
840 isns_req_add_32(req, 51, pg->pg_tag);
841 TAILQ_FOREACH(portal, &pg->pg_portals, p_next) {
842 isns_req_add_addr(req, 49, portal->p_ai);
843 isns_req_add_port(req, 50, portal->p_ai);
847 res = isns_req_send(s, req);
849 log_warn("send(2) failed for %s", isns->i_addr);
852 res = isns_req_receive(s, req);
854 log_warn("receive(2) failed for %s", isns->i_addr);
857 error = isns_req_get_status(req);
859 log_warnx("iSNS register error %d for %s", error, isns->i_addr);
868 isns_do_check(struct isns *isns, int s, const char *hostname)
870 struct conf *conf = isns->i_conf;
871 struct isns_req *req;
875 req = isns_req_create(ISNS_FUNC_DEVATTRQRY, ISNS_FLAG_CLIENT);
876 isns_req_add_str(req, 32, TAILQ_FIRST(&conf->conf_targets)->t_name);
877 isns_req_add_str(req, 1, hostname);
878 isns_req_add_delim(req);
879 isns_req_add(req, 2, 0, NULL);
880 res = isns_req_send(s, req);
882 log_warn("send(2) failed for %s", isns->i_addr);
885 res = isns_req_receive(s, req);
887 log_warn("receive(2) failed for %s", isns->i_addr);
890 error = isns_req_get_status(req);
892 log_warnx("iSNS check error %d for %s", error, isns->i_addr);
901 isns_do_deregister(struct isns *isns, int s, const char *hostname)
903 struct conf *conf = isns->i_conf;
904 struct isns_req *req;
908 req = isns_req_create(ISNS_FUNC_DEVDEREG, ISNS_FLAG_CLIENT);
909 isns_req_add_str(req, 32, TAILQ_FIRST(&conf->conf_targets)->t_name);
910 isns_req_add_delim(req);
911 isns_req_add_str(req, 1, hostname);
912 res = isns_req_send(s, req);
914 log_warn("send(2) failed for %s", isns->i_addr);
917 res = isns_req_receive(s, req);
919 log_warn("receive(2) failed for %s", isns->i_addr);
922 error = isns_req_get_status(req);
924 log_warnx("iSNS deregister error %d for %s", error, isns->i_addr);
933 isns_register(struct isns *isns, struct isns *oldisns)
935 struct conf *conf = isns->i_conf;
939 if (TAILQ_EMPTY(&conf->conf_targets) ||
940 TAILQ_EMPTY(&conf->conf_portal_groups))
942 set_timeout(conf->conf_isns_timeout, false);
943 s = isns_do_connect(isns);
945 set_timeout(0, false);
948 error = gethostname(hostname, sizeof(hostname));
950 log_err(1, "gethostname");
952 if (oldisns == NULL || TAILQ_EMPTY(&oldisns->i_conf->conf_targets))
954 isns_do_deregister(oldisns, s, hostname);
955 isns_do_register(isns, s, hostname);
957 set_timeout(0, false);
961 isns_check(struct isns *isns)
963 struct conf *conf = isns->i_conf;
967 if (TAILQ_EMPTY(&conf->conf_targets) ||
968 TAILQ_EMPTY(&conf->conf_portal_groups))
970 set_timeout(conf->conf_isns_timeout, false);
971 s = isns_do_connect(isns);
973 set_timeout(0, false);
976 error = gethostname(hostname, sizeof(hostname));
978 log_err(1, "gethostname");
980 res = isns_do_check(isns, s, hostname);
982 isns_do_deregister(isns, s, hostname);
983 isns_do_register(isns, s, hostname);
986 set_timeout(0, false);
990 isns_deregister(struct isns *isns)
992 struct conf *conf = isns->i_conf;
996 if (TAILQ_EMPTY(&conf->conf_targets) ||
997 TAILQ_EMPTY(&conf->conf_portal_groups))
999 set_timeout(conf->conf_isns_timeout, false);
1000 s = isns_do_connect(isns);
1003 error = gethostname(hostname, sizeof(hostname));
1005 log_err(1, "gethostname");
1007 isns_do_deregister(isns, s, hostname);
1009 set_timeout(0, false);
1013 portal_group_set_filter(struct portal_group *pg, const char *str)
1017 if (strcmp(str, "none") == 0) {
1018 filter = PG_FILTER_NONE;
1019 } else if (strcmp(str, "portal") == 0) {
1020 filter = PG_FILTER_PORTAL;
1021 } else if (strcmp(str, "portal-name") == 0) {
1022 filter = PG_FILTER_PORTAL_NAME;
1023 } else if (strcmp(str, "portal-name-auth") == 0) {
1024 filter = PG_FILTER_PORTAL_NAME_AUTH;
1026 log_warnx("invalid discovery-filter \"%s\" for portal-group "
1027 "\"%s\"; valid values are \"none\", \"portal\", "
1028 "\"portal-name\", and \"portal-name-auth\"",
1033 if (pg->pg_discovery_filter != PG_FILTER_UNKNOWN &&
1034 pg->pg_discovery_filter != filter) {
1035 log_warnx("cannot set discovery-filter to \"%s\" for "
1036 "portal-group \"%s\"; already has a different "
1037 "value", str, pg->pg_name);
1041 pg->pg_discovery_filter = filter;
1047 portal_group_set_offload(struct portal_group *pg, const char *offload)
1050 if (pg->pg_offload != NULL) {
1051 log_warnx("cannot set offload to \"%s\" for "
1052 "portal-group \"%s\"; already defined",
1053 offload, pg->pg_name);
1057 pg->pg_offload = checked_strdup(offload);
1063 portal_group_set_redirection(struct portal_group *pg, const char *addr)
1066 if (pg->pg_redirection != NULL) {
1067 log_warnx("cannot set redirection to \"%s\" for "
1068 "portal-group \"%s\"; already defined",
1073 pg->pg_redirection = checked_strdup(addr);
1079 valid_hex(const char ch)
1111 valid_iscsi_name(const char *name)
1115 if (strlen(name) >= MAX_NAME_LEN) {
1116 log_warnx("overlong name for target \"%s\"; max length allowed "
1117 "by iSCSI specification is %d characters",
1118 name, MAX_NAME_LEN);
1123 * In the cases below, we don't return an error, just in case the admin
1124 * was right, and we're wrong.
1126 if (strncasecmp(name, "iqn.", strlen("iqn.")) == 0) {
1127 for (i = strlen("iqn."); name[i] != '\0'; i++) {
1129 * XXX: We should verify UTF-8 normalisation, as defined
1130 * by 3.2.6.2: iSCSI Name Encoding.
1132 if (isalnum(name[i]))
1134 if (name[i] == '-' || name[i] == '.' || name[i] == ':')
1136 log_warnx("invalid character \"%c\" in target name "
1137 "\"%s\"; allowed characters are letters, digits, "
1138 "'-', '.', and ':'", name[i], name);
1142 * XXX: Check more stuff: valid date and a valid reversed domain.
1144 } else if (strncasecmp(name, "eui.", strlen("eui.")) == 0) {
1145 if (strlen(name) != strlen("eui.") + 16)
1146 log_warnx("invalid target name \"%s\"; the \"eui.\" "
1147 "should be followed by exactly 16 hexadecimal "
1149 for (i = strlen("eui."); name[i] != '\0'; i++) {
1150 if (!valid_hex(name[i])) {
1151 log_warnx("invalid character \"%c\" in target "
1152 "name \"%s\"; allowed characters are 1-9 "
1153 "and A-F", name[i], name);
1157 } else if (strncasecmp(name, "naa.", strlen("naa.")) == 0) {
1158 if (strlen(name) > strlen("naa.") + 32)
1159 log_warnx("invalid target name \"%s\"; the \"naa.\" "
1160 "should be followed by at most 32 hexadecimal "
1162 for (i = strlen("naa."); name[i] != '\0'; i++) {
1163 if (!valid_hex(name[i])) {
1164 log_warnx("invalid character \"%c\" in target "
1165 "name \"%s\"; allowed characters are 1-9 "
1166 "and A-F", name[i], name);
1171 log_warnx("invalid target name \"%s\"; should start with "
1172 "either \"iqn.\", \"eui.\", or \"naa.\"",
1179 pport_new(struct conf *conf, const char *name, uint32_t ctl_port)
1183 pp = calloc(1, sizeof(*pp));
1185 log_err(1, "calloc");
1187 pp->pp_name = checked_strdup(name);
1188 pp->pp_ctl_port = ctl_port;
1189 TAILQ_INIT(&pp->pp_ports);
1190 TAILQ_INSERT_TAIL(&conf->conf_pports, pp, pp_next);
1195 pport_find(const struct conf *conf, const char *name)
1199 TAILQ_FOREACH(pp, &conf->conf_pports, pp_next) {
1200 if (strcasecmp(pp->pp_name, name) == 0)
1207 pport_copy(struct pport *pp, struct conf *conf)
1209 struct pport *ppnew;
1211 ppnew = pport_new(conf, pp->pp_name, pp->pp_ctl_port);
1216 pport_delete(struct pport *pp)
1218 struct port *port, *tport;
1220 TAILQ_FOREACH_SAFE(port, &pp->pp_ports, p_ts, tport)
1222 TAILQ_REMOVE(&pp->pp_conf->conf_pports, pp, pp_next);
1228 port_new(struct conf *conf, struct target *target, struct portal_group *pg)
1234 ret = asprintf(&name, "%s-%s", pg->pg_name, target->t_name);
1236 log_err(1, "asprintf");
1237 if (port_find(conf, name) != NULL) {
1238 log_warnx("duplicate port \"%s\"", name);
1242 port = calloc(1, sizeof(*port));
1244 log_err(1, "calloc");
1245 port->p_conf = conf;
1246 port->p_name = name;
1247 port->p_ioctl_port = 0;
1248 TAILQ_INSERT_TAIL(&conf->conf_ports, port, p_next);
1249 TAILQ_INSERT_TAIL(&target->t_ports, port, p_ts);
1250 port->p_target = target;
1251 TAILQ_INSERT_TAIL(&pg->pg_ports, port, p_pgs);
1252 port->p_portal_group = pg;
1257 port_new_ioctl(struct conf *conf, struct target *target, int pp, int vp)
1259 struct pport *pport;
1265 ret = asprintf(&pname, "ioctl/%d/%d", pp, vp);
1267 log_err(1, "asprintf");
1271 pport = pport_find(conf, pname);
1272 if (pport != NULL) {
1274 return (port_new_pp(conf, target, pport));
1277 ret = asprintf(&name, "%s-%s", pname, target->t_name);
1281 log_err(1, "asprintf");
1282 if (port_find(conf, name) != NULL) {
1283 log_warnx("duplicate port \"%s\"", name);
1287 port = calloc(1, sizeof(*port));
1289 log_err(1, "calloc");
1290 port->p_conf = conf;
1291 port->p_name = name;
1292 port->p_ioctl_port = 1;
1293 port->p_ioctl_pp = pp;
1294 port->p_ioctl_vp = vp;
1295 TAILQ_INSERT_TAIL(&conf->conf_ports, port, p_next);
1296 TAILQ_INSERT_TAIL(&target->t_ports, port, p_ts);
1297 port->p_target = target;
1302 port_new_pp(struct conf *conf, struct target *target, struct pport *pp)
1308 ret = asprintf(&name, "%s-%s", pp->pp_name, target->t_name);
1310 log_err(1, "asprintf");
1311 if (port_find(conf, name) != NULL) {
1312 log_warnx("duplicate port \"%s\"", name);
1316 port = calloc(1, sizeof(*port));
1318 log_err(1, "calloc");
1319 port->p_conf = conf;
1320 port->p_name = name;
1321 TAILQ_INSERT_TAIL(&conf->conf_ports, port, p_next);
1322 TAILQ_INSERT_TAIL(&target->t_ports, port, p_ts);
1323 port->p_target = target;
1324 TAILQ_INSERT_TAIL(&pp->pp_ports, port, p_pps);
1330 port_find(const struct conf *conf, const char *name)
1334 TAILQ_FOREACH(port, &conf->conf_ports, p_next) {
1335 if (strcasecmp(port->p_name, name) == 0)
1343 port_find_in_pg(const struct portal_group *pg, const char *target)
1347 TAILQ_FOREACH(port, &pg->pg_ports, p_pgs) {
1348 if (strcasecmp(port->p_target->t_name, target) == 0)
1356 port_delete(struct port *port)
1359 if (port->p_portal_group)
1360 TAILQ_REMOVE(&port->p_portal_group->pg_ports, port, p_pgs);
1362 TAILQ_REMOVE(&port->p_pport->pp_ports, port, p_pps);
1364 TAILQ_REMOVE(&port->p_target->t_ports, port, p_ts);
1365 TAILQ_REMOVE(&port->p_conf->conf_ports, port, p_next);
1371 port_is_dummy(struct port *port)
1374 if (port->p_portal_group) {
1375 if (port->p_portal_group->pg_foreign)
1377 if (TAILQ_EMPTY(&port->p_portal_group->pg_portals))
1384 target_new(struct conf *conf, const char *name)
1386 struct target *targ;
1389 targ = target_find(conf, name);
1391 log_warnx("duplicated target \"%s\"", name);
1394 if (valid_iscsi_name(name) == false) {
1395 log_warnx("target name \"%s\" is invalid", name);
1398 targ = calloc(1, sizeof(*targ));
1400 log_err(1, "calloc");
1401 targ->t_name = checked_strdup(name);
1404 * RFC 3722 requires us to normalize the name to lowercase.
1407 for (i = 0; i < len; i++)
1408 targ->t_name[i] = tolower(targ->t_name[i]);
1410 targ->t_conf = conf;
1411 TAILQ_INIT(&targ->t_ports);
1412 TAILQ_INSERT_TAIL(&conf->conf_targets, targ, t_next);
1418 target_delete(struct target *targ)
1420 struct port *port, *tport;
1422 TAILQ_FOREACH_SAFE(port, &targ->t_ports, p_ts, tport)
1424 TAILQ_REMOVE(&targ->t_conf->conf_targets, targ, t_next);
1427 free(targ->t_redirection);
1432 target_find(struct conf *conf, const char *name)
1434 struct target *targ;
1436 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
1437 if (strcasecmp(targ->t_name, name) == 0)
1445 target_set_redirection(struct target *target, const char *addr)
1448 if (target->t_redirection != NULL) {
1449 log_warnx("cannot set redirection to \"%s\" for "
1450 "target \"%s\"; already defined",
1451 addr, target->t_name);
1455 target->t_redirection = checked_strdup(addr);
1461 lun_new(struct conf *conf, const char *name)
1465 lun = lun_find(conf, name);
1467 log_warnx("duplicated lun \"%s\"", name);
1471 lun = calloc(1, sizeof(*lun));
1473 log_err(1, "calloc");
1475 lun->l_name = checked_strdup(name);
1476 TAILQ_INIT(&lun->l_options);
1477 TAILQ_INSERT_TAIL(&conf->conf_luns, lun, l_next);
1478 lun->l_ctl_lun = -1;
1484 lun_delete(struct lun *lun)
1486 struct target *targ;
1487 struct option *o, *tmp;
1490 TAILQ_FOREACH(targ, &lun->l_conf->conf_targets, t_next) {
1491 for (i = 0; i < MAX_LUNS; i++) {
1492 if (targ->t_luns[i] == lun)
1493 targ->t_luns[i] = NULL;
1496 TAILQ_REMOVE(&lun->l_conf->conf_luns, lun, l_next);
1498 TAILQ_FOREACH_SAFE(o, &lun->l_options, o_next, tmp)
1499 option_delete(&lun->l_options, o);
1501 free(lun->l_backend);
1502 free(lun->l_device_id);
1504 free(lun->l_scsiname);
1505 free(lun->l_serial);
1510 lun_find(const struct conf *conf, const char *name)
1514 TAILQ_FOREACH(lun, &conf->conf_luns, l_next) {
1515 if (strcmp(lun->l_name, name) == 0)
1523 lun_set_backend(struct lun *lun, const char *value)
1525 free(lun->l_backend);
1526 lun->l_backend = checked_strdup(value);
1530 lun_set_blocksize(struct lun *lun, size_t value)
1533 lun->l_blocksize = value;
1537 lun_set_device_type(struct lun *lun, uint8_t value)
1540 lun->l_device_type = value;
1544 lun_set_device_id(struct lun *lun, const char *value)
1546 free(lun->l_device_id);
1547 lun->l_device_id = checked_strdup(value);
1551 lun_set_path(struct lun *lun, const char *value)
1554 lun->l_path = checked_strdup(value);
1558 lun_set_scsiname(struct lun *lun, const char *value)
1560 free(lun->l_scsiname);
1561 lun->l_scsiname = checked_strdup(value);
1565 lun_set_serial(struct lun *lun, const char *value)
1567 free(lun->l_serial);
1568 lun->l_serial = checked_strdup(value);
1572 lun_set_size(struct lun *lun, size_t value)
1575 lun->l_size = value;
1579 lun_set_ctl_lun(struct lun *lun, uint32_t value)
1582 lun->l_ctl_lun = value;
1586 option_new(struct options *options, const char *name, const char *value)
1590 o = option_find(options, name);
1592 log_warnx("duplicated option \"%s\"", name);
1596 o = calloc(1, sizeof(*o));
1598 log_err(1, "calloc");
1599 o->o_name = checked_strdup(name);
1600 o->o_value = checked_strdup(value);
1601 TAILQ_INSERT_TAIL(options, o, o_next);
1607 option_delete(struct options *options, struct option *o)
1610 TAILQ_REMOVE(options, o, o_next);
1617 option_find(const struct options *options, const char *name)
1621 TAILQ_FOREACH(o, options, o_next) {
1622 if (strcmp(o->o_name, name) == 0)
1630 option_set(struct option *o, const char *value)
1634 o->o_value = checked_strdup(value);
1637 #ifdef ICL_KERNEL_PROXY
1640 pdu_receive_proxy(struct pdu *pdu)
1642 struct connection *conn;
1646 conn = pdu->pdu_connection;
1648 kernel_receive(pdu);
1650 len = pdu_ahs_length(pdu);
1652 log_errx(1, "protocol error: non-empty AHS");
1654 len = pdu_data_segment_length(pdu);
1655 assert(len <= (size_t)conn->conn_max_recv_data_segment_length);
1656 pdu->pdu_data_len = len;
1660 pdu_send_proxy(struct pdu *pdu)
1665 pdu_set_data_segment_length(pdu, pdu->pdu_data_len);
1669 #endif /* ICL_KERNEL_PROXY */
1672 pdu_fail(const struct connection *conn __unused, const char *reason __unused)
1676 static struct ctld_connection *
1677 connection_new(struct portal *portal, int fd, const char *host,
1678 const struct sockaddr *client_sa)
1680 struct ctld_connection *conn;
1682 conn = calloc(1, sizeof(*conn));
1684 log_err(1, "calloc");
1685 connection_init(&conn->conn, &conn_ops, proxy_mode);
1686 conn->conn.conn_socket = fd;
1687 conn->conn_portal = portal;
1688 conn->conn_initiator_addr = checked_strdup(host);
1689 memcpy(&conn->conn_initiator_sa, client_sa, client_sa->sa_len);
1696 conf_print(struct conf *conf)
1698 struct auth_group *ag;
1700 struct auth_name *auth_name;
1701 struct auth_portal *auth_portal;
1702 struct portal_group *pg;
1703 struct portal *portal;
1704 struct target *targ;
1708 TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) {
1709 fprintf(stderr, "auth-group %s {\n", ag->ag_name);
1710 TAILQ_FOREACH(auth, &ag->ag_auths, a_next)
1711 fprintf(stderr, "\t chap-mutual %s %s %s %s\n",
1712 auth->a_user, auth->a_secret,
1713 auth->a_mutual_user, auth->a_mutual_secret);
1714 TAILQ_FOREACH(auth_name, &ag->ag_names, an_next)
1715 fprintf(stderr, "\t initiator-name %s\n",
1716 auth_name->an_initiator_name);
1717 TAILQ_FOREACH(auth_portal, &ag->ag_portals, ap_next)
1718 fprintf(stderr, "\t initiator-portal %s\n",
1719 auth_portal->ap_initiator_portal);
1720 fprintf(stderr, "}\n");
1722 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
1723 fprintf(stderr, "portal-group %s {\n", pg->pg_name);
1724 TAILQ_FOREACH(portal, &pg->pg_portals, p_next)
1725 fprintf(stderr, "\t listen %s\n", portal->p_listen);
1726 fprintf(stderr, "}\n");
1728 TAILQ_FOREACH(lun, &conf->conf_luns, l_next) {
1729 fprintf(stderr, "\tlun %s {\n", lun->l_name);
1730 fprintf(stderr, "\t\tpath %s\n", lun->l_path);
1731 TAILQ_FOREACH(o, &lun->l_options, o_next)
1732 fprintf(stderr, "\t\toption %s %s\n",
1733 o->o_name, o->o_value);
1734 fprintf(stderr, "\t}\n");
1736 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
1737 fprintf(stderr, "target %s {\n", targ->t_name);
1738 if (targ->t_alias != NULL)
1739 fprintf(stderr, "\t alias %s\n", targ->t_alias);
1740 fprintf(stderr, "}\n");
1746 conf_verify_lun(struct lun *lun)
1748 const struct lun *lun2;
1750 if (lun->l_backend == NULL)
1751 lun_set_backend(lun, "block");
1752 if (strcmp(lun->l_backend, "block") == 0) {
1753 if (lun->l_path == NULL) {
1754 log_warnx("missing path for lun \"%s\"",
1758 } else if (strcmp(lun->l_backend, "ramdisk") == 0) {
1759 if (lun->l_size == 0) {
1760 log_warnx("missing size for ramdisk-backed lun \"%s\"",
1764 if (lun->l_path != NULL) {
1765 log_warnx("path must not be specified "
1766 "for ramdisk-backed lun \"%s\"",
1771 if (lun->l_blocksize == 0) {
1772 if (lun->l_device_type == 5)
1773 lun_set_blocksize(lun, DEFAULT_CD_BLOCKSIZE);
1775 lun_set_blocksize(lun, DEFAULT_BLOCKSIZE);
1776 } else if (lun->l_blocksize < 0) {
1777 log_warnx("invalid blocksize for lun \"%s\"; "
1778 "must be larger than 0", lun->l_name);
1781 if (lun->l_size != 0 && lun->l_size % lun->l_blocksize != 0) {
1782 log_warnx("invalid size for lun \"%s\"; "
1783 "must be multiple of blocksize", lun->l_name);
1786 TAILQ_FOREACH(lun2, &lun->l_conf->conf_luns, l_next) {
1789 if (lun->l_path != NULL && lun2->l_path != NULL &&
1790 strcmp(lun->l_path, lun2->l_path) == 0) {
1791 log_debugx("WARNING: path \"%s\" duplicated "
1792 "between lun \"%s\", and "
1793 "lun \"%s\"", lun->l_path,
1794 lun->l_name, lun2->l_name);
1802 conf_verify(struct conf *conf)
1804 struct auth_group *ag;
1805 struct portal_group *pg;
1807 struct target *targ;
1812 if (conf->conf_pidfile_path == NULL)
1813 conf->conf_pidfile_path = checked_strdup(DEFAULT_PIDFILE);
1815 TAILQ_FOREACH(lun, &conf->conf_luns, l_next) {
1816 error = conf_verify_lun(lun);
1820 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
1821 if (targ->t_auth_group == NULL) {
1822 targ->t_auth_group = auth_group_find(conf,
1824 assert(targ->t_auth_group != NULL);
1826 if (TAILQ_EMPTY(&targ->t_ports)) {
1827 pg = portal_group_find(conf, "default");
1829 port_new(conf, targ, pg);
1832 for (i = 0; i < MAX_LUNS; i++) {
1833 if (targ->t_luns[i] != NULL)
1836 if (!found && targ->t_redirection == NULL) {
1837 log_warnx("no LUNs defined for target \"%s\"",
1840 if (found && targ->t_redirection != NULL) {
1841 log_debugx("target \"%s\" contains luns, "
1842 " but configured for redirection",
1846 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
1847 assert(pg->pg_name != NULL);
1848 if (pg->pg_discovery_auth_group == NULL) {
1849 pg->pg_discovery_auth_group =
1850 auth_group_find(conf, "default");
1851 assert(pg->pg_discovery_auth_group != NULL);
1854 if (pg->pg_discovery_filter == PG_FILTER_UNKNOWN)
1855 pg->pg_discovery_filter = PG_FILTER_NONE;
1857 if (pg->pg_redirection != NULL) {
1858 if (!TAILQ_EMPTY(&pg->pg_ports)) {
1859 log_debugx("portal-group \"%s\" assigned "
1860 "to target, but configured "
1864 pg->pg_unassigned = false;
1865 } else if (!TAILQ_EMPTY(&pg->pg_ports)) {
1866 pg->pg_unassigned = false;
1868 if (strcmp(pg->pg_name, "default") != 0)
1869 log_warnx("portal-group \"%s\" not assigned "
1870 "to any target", pg->pg_name);
1871 pg->pg_unassigned = true;
1874 TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) {
1875 if (ag->ag_name == NULL)
1876 assert(ag->ag_target != NULL);
1878 assert(ag->ag_target == NULL);
1881 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
1882 if (targ->t_auth_group == ag) {
1887 TAILQ_FOREACH(port, &conf->conf_ports, p_next) {
1888 if (port->p_auth_group == ag) {
1893 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
1894 if (pg->pg_discovery_auth_group == ag) {
1899 if (!found && ag->ag_name != NULL &&
1900 strcmp(ag->ag_name, "default") != 0 &&
1901 strcmp(ag->ag_name, "no-authentication") != 0 &&
1902 strcmp(ag->ag_name, "no-access") != 0) {
1903 log_warnx("auth-group \"%s\" not assigned "
1904 "to any target", ag->ag_name);
1912 conf_apply(struct conf *oldconf, struct conf *newconf)
1914 struct lun *oldlun, *newlun, *tmplun;
1915 struct portal_group *oldpg, *newpg;
1916 struct portal *oldp, *newp;
1917 struct port *oldport, *newport, *tmpport;
1918 struct isns *oldns, *newns;
1920 int changed, cumulated_error = 0, error, sockbuf;
1923 if (oldconf->conf_debug != newconf->conf_debug) {
1924 log_debugx("changing debug level to %d", newconf->conf_debug);
1925 log_init(newconf->conf_debug);
1928 if (oldconf->conf_pidfh != NULL) {
1929 assert(oldconf->conf_pidfile_path != NULL);
1930 if (newconf->conf_pidfile_path != NULL &&
1931 strcmp(oldconf->conf_pidfile_path,
1932 newconf->conf_pidfile_path) == 0) {
1933 newconf->conf_pidfh = oldconf->conf_pidfh;
1934 oldconf->conf_pidfh = NULL;
1936 log_debugx("removing pidfile %s",
1937 oldconf->conf_pidfile_path);
1938 pidfile_remove(oldconf->conf_pidfh);
1939 oldconf->conf_pidfh = NULL;
1943 if (newconf->conf_pidfh == NULL && newconf->conf_pidfile_path != NULL) {
1944 log_debugx("opening pidfile %s", newconf->conf_pidfile_path);
1945 newconf->conf_pidfh =
1946 pidfile_open(newconf->conf_pidfile_path, 0600, &otherpid);
1947 if (newconf->conf_pidfh == NULL) {
1948 if (errno == EEXIST)
1949 log_errx(1, "daemon already running, pid: %jd.",
1950 (intmax_t)otherpid);
1951 log_err(1, "cannot open or create pidfile \"%s\"",
1952 newconf->conf_pidfile_path);
1957 * Go through the new portal groups, assigning tags or preserving old.
1959 TAILQ_FOREACH(newpg, &newconf->conf_portal_groups, pg_next) {
1960 if (newpg->pg_tag != 0)
1962 oldpg = portal_group_find(oldconf, newpg->pg_name);
1964 newpg->pg_tag = oldpg->pg_tag;
1966 newpg->pg_tag = ++last_portal_group_tag;
1969 /* Deregister on removed iSNS servers. */
1970 TAILQ_FOREACH(oldns, &oldconf->conf_isns, i_next) {
1971 TAILQ_FOREACH(newns, &newconf->conf_isns, i_next) {
1972 if (strcmp(oldns->i_addr, newns->i_addr) == 0)
1976 isns_deregister(oldns);
1980 * XXX: If target or lun removal fails, we should somehow "move"
1981 * the old lun or target into newconf, so that subsequent
1982 * conf_apply() would try to remove them again. That would
1983 * be somewhat hairy, though, and lun deletion failures don't
1984 * really happen, so leave it as it is for now.
1987 * First, remove any ports present in the old configuration
1988 * and missing in the new one.
1990 TAILQ_FOREACH_SAFE(oldport, &oldconf->conf_ports, p_next, tmpport) {
1991 if (port_is_dummy(oldport))
1993 newport = port_find(newconf, oldport->p_name);
1994 if (newport != NULL && !port_is_dummy(newport))
1996 log_debugx("removing port \"%s\"", oldport->p_name);
1997 error = kernel_port_remove(oldport);
1999 log_warnx("failed to remove port %s",
2002 * XXX: Uncomment after fixing the root cause.
2004 * cumulated_error++;
2010 * Second, remove any LUNs present in the old configuration
2011 * and missing in the new one.
2013 TAILQ_FOREACH_SAFE(oldlun, &oldconf->conf_luns, l_next, tmplun) {
2014 newlun = lun_find(newconf, oldlun->l_name);
2015 if (newlun == NULL) {
2016 log_debugx("lun \"%s\", CTL lun %d "
2017 "not found in new configuration; "
2018 "removing", oldlun->l_name, oldlun->l_ctl_lun);
2019 error = kernel_lun_remove(oldlun);
2021 log_warnx("failed to remove lun \"%s\", "
2023 oldlun->l_name, oldlun->l_ctl_lun);
2030 * Also remove the LUNs changed by more than size.
2033 assert(oldlun->l_backend != NULL);
2034 assert(newlun->l_backend != NULL);
2035 if (strcmp(newlun->l_backend, oldlun->l_backend) != 0) {
2036 log_debugx("backend for lun \"%s\", "
2037 "CTL lun %d changed; removing",
2038 oldlun->l_name, oldlun->l_ctl_lun);
2041 if (oldlun->l_blocksize != newlun->l_blocksize) {
2042 log_debugx("blocksize for lun \"%s\", "
2043 "CTL lun %d changed; removing",
2044 oldlun->l_name, oldlun->l_ctl_lun);
2047 if (newlun->l_device_id != NULL &&
2048 (oldlun->l_device_id == NULL ||
2049 strcmp(oldlun->l_device_id, newlun->l_device_id) !=
2051 log_debugx("device-id for lun \"%s\", "
2052 "CTL lun %d changed; removing",
2053 oldlun->l_name, oldlun->l_ctl_lun);
2056 if (newlun->l_path != NULL &&
2057 (oldlun->l_path == NULL ||
2058 strcmp(oldlun->l_path, newlun->l_path) != 0)) {
2059 log_debugx("path for lun \"%s\", "
2060 "CTL lun %d, changed; removing",
2061 oldlun->l_name, oldlun->l_ctl_lun);
2064 if (newlun->l_serial != NULL &&
2065 (oldlun->l_serial == NULL ||
2066 strcmp(oldlun->l_serial, newlun->l_serial) != 0)) {
2067 log_debugx("serial for lun \"%s\", "
2068 "CTL lun %d changed; removing",
2069 oldlun->l_name, oldlun->l_ctl_lun);
2073 error = kernel_lun_remove(oldlun);
2075 log_warnx("failed to remove lun \"%s\", "
2077 oldlun->l_name, oldlun->l_ctl_lun);
2084 lun_set_ctl_lun(newlun, oldlun->l_ctl_lun);
2087 TAILQ_FOREACH_SAFE(newlun, &newconf->conf_luns, l_next, tmplun) {
2088 oldlun = lun_find(oldconf, newlun->l_name);
2089 if (oldlun != NULL) {
2090 log_debugx("modifying lun \"%s\", CTL lun %d",
2091 newlun->l_name, newlun->l_ctl_lun);
2092 error = kernel_lun_modify(newlun);
2094 log_warnx("failed to "
2095 "modify lun \"%s\", CTL lun %d",
2096 newlun->l_name, newlun->l_ctl_lun);
2101 log_debugx("adding lun \"%s\"", newlun->l_name);
2102 error = kernel_lun_add(newlun);
2104 log_warnx("failed to add lun \"%s\"", newlun->l_name);
2111 * Now add new ports or modify existing ones.
2113 TAILQ_FOREACH_SAFE(newport, &newconf->conf_ports, p_next, tmpport) {
2114 if (port_is_dummy(newport))
2116 oldport = port_find(oldconf, newport->p_name);
2118 if (oldport == NULL || port_is_dummy(oldport)) {
2119 log_debugx("adding port \"%s\"", newport->p_name);
2120 error = kernel_port_add(newport);
2122 log_debugx("updating port \"%s\"", newport->p_name);
2123 newport->p_ctl_port = oldport->p_ctl_port;
2124 error = kernel_port_update(newport, oldport);
2127 log_warnx("failed to %s port %s",
2128 (oldport == NULL) ? "add" : "update",
2130 if (oldport == NULL || port_is_dummy(oldport))
2131 port_delete(newport);
2133 * XXX: Uncomment after fixing the root cause.
2135 * cumulated_error++;
2141 * Go through the new portals, opening the sockets as necessary.
2143 TAILQ_FOREACH(newpg, &newconf->conf_portal_groups, pg_next) {
2144 if (newpg->pg_foreign)
2146 if (newpg->pg_unassigned) {
2147 log_debugx("not listening on portal-group \"%s\", "
2148 "not assigned to any target",
2152 TAILQ_FOREACH(newp, &newpg->pg_portals, p_next) {
2154 * Try to find already open portal and reuse
2155 * the listening socket. We don't care about
2156 * what portal or portal group that was, what
2157 * matters is the listening address.
2159 TAILQ_FOREACH(oldpg, &oldconf->conf_portal_groups,
2161 TAILQ_FOREACH(oldp, &oldpg->pg_portals,
2163 if (strcmp(newp->p_listen,
2164 oldp->p_listen) == 0 &&
2165 oldp->p_socket > 0) {
2173 if (newp->p_socket > 0) {
2175 * We're done with this portal.
2180 #ifdef ICL_KERNEL_PROXY
2182 newpg->pg_conf->conf_portal_id++;
2183 newp->p_id = newpg->pg_conf->conf_portal_id;
2184 log_debugx("listening on %s, portal-group "
2185 "\"%s\", portal id %d, using ICL proxy",
2186 newp->p_listen, newpg->pg_name, newp->p_id);
2187 kernel_listen(newp->p_ai, newp->p_iser,
2192 assert(proxy_mode == false);
2193 assert(newp->p_iser == false);
2195 log_debugx("listening on %s, portal-group \"%s\"",
2196 newp->p_listen, newpg->pg_name);
2197 newp->p_socket = socket(newp->p_ai->ai_family,
2198 newp->p_ai->ai_socktype,
2199 newp->p_ai->ai_protocol);
2200 if (newp->p_socket < 0) {
2201 log_warn("socket(2) failed for %s",
2206 sockbuf = SOCKBUF_SIZE;
2207 if (setsockopt(newp->p_socket, SOL_SOCKET, SO_RCVBUF,
2208 &sockbuf, sizeof(sockbuf)) == -1)
2209 log_warn("setsockopt(SO_RCVBUF) failed "
2210 "for %s", newp->p_listen);
2211 sockbuf = SOCKBUF_SIZE;
2212 if (setsockopt(newp->p_socket, SOL_SOCKET, SO_SNDBUF,
2213 &sockbuf, sizeof(sockbuf)) == -1)
2214 log_warn("setsockopt(SO_SNDBUF) failed "
2215 "for %s", newp->p_listen);
2216 if (setsockopt(newp->p_socket, SOL_SOCKET, SO_NO_DDP,
2217 &one, sizeof(one)) == -1)
2218 log_warn("setsockopt(SO_NO_DDP) failed "
2219 "for %s", newp->p_listen);
2220 error = setsockopt(newp->p_socket, SOL_SOCKET,
2221 SO_REUSEADDR, &one, sizeof(one));
2223 log_warn("setsockopt(SO_REUSEADDR) failed "
2224 "for %s", newp->p_listen);
2225 close(newp->p_socket);
2230 if (newpg->pg_dscp != -1) {
2232 int len = sizeof(sa);
2233 getsockname(newp->p_socket, &sa, &len);
2235 * Only allow the 6-bit DSCP
2236 * field to be modified
2238 int tos = newpg->pg_dscp << 2;
2239 if (sa.sa_family == AF_INET) {
2240 if (setsockopt(newp->p_socket,
2242 &tos, sizeof(tos)) == -1)
2243 log_warn("setsockopt(IP_TOS) "
2247 if (sa.sa_family == AF_INET6) {
2248 if (setsockopt(newp->p_socket,
2249 IPPROTO_IPV6, IPV6_TCLASS,
2250 &tos, sizeof(tos)) == -1)
2251 log_warn("setsockopt(IPV6_TCLASS) "
2256 if (newpg->pg_pcp != -1) {
2258 int len = sizeof(sa);
2259 getsockname(newp->p_socket, &sa, &len);
2261 * Only allow the 6-bit DSCP
2262 * field to be modified
2264 int pcp = newpg->pg_pcp;
2265 if (sa.sa_family == AF_INET) {
2266 if (setsockopt(newp->p_socket,
2267 IPPROTO_IP, IP_VLAN_PCP,
2268 &pcp, sizeof(pcp)) == -1)
2269 log_warn("setsockopt(IP_VLAN_PCP) "
2273 if (sa.sa_family == AF_INET6) {
2274 if (setsockopt(newp->p_socket,
2275 IPPROTO_IPV6, IPV6_VLAN_PCP,
2276 &pcp, sizeof(pcp)) == -1)
2277 log_warn("setsockopt(IPV6_VLAN_PCP) "
2282 error = bind(newp->p_socket, newp->p_ai->ai_addr,
2283 newp->p_ai->ai_addrlen);
2285 log_warn("bind(2) failed for %s",
2287 close(newp->p_socket);
2292 error = listen(newp->p_socket, -1);
2294 log_warn("listen(2) failed for %s",
2296 close(newp->p_socket);
2305 * Go through the no longer used sockets, closing them.
2307 TAILQ_FOREACH(oldpg, &oldconf->conf_portal_groups, pg_next) {
2308 TAILQ_FOREACH(oldp, &oldpg->pg_portals, p_next) {
2309 if (oldp->p_socket <= 0)
2311 log_debugx("closing socket for %s, portal-group \"%s\"",
2312 oldp->p_listen, oldpg->pg_name);
2313 close(oldp->p_socket);
2318 /* (Re-)Register on remaining/new iSNS servers. */
2319 TAILQ_FOREACH(newns, &newconf->conf_isns, i_next) {
2320 TAILQ_FOREACH(oldns, &oldconf->conf_isns, i_next) {
2321 if (strcmp(oldns->i_addr, newns->i_addr) == 0)
2324 isns_register(newns, oldns);
2327 /* Schedule iSNS update */
2328 if (!TAILQ_EMPTY(&newconf->conf_isns))
2329 set_timeout((newconf->conf_isns_period + 2) / 3, false);
2331 return (cumulated_error);
2338 return (sigalrm_received);
2342 sigalrm_handler_fatal(int dummy __unused)
2345 * It would be easiest to just log an error and exit. We can't
2346 * do this, though, because log_errx() is not signal safe, since
2347 * it calls syslog(3). Instead, set a flag checked by pdu_send()
2348 * and pdu_receive(), to call log_errx() there. Should they fail
2349 * to notice, we'll exit here one second later.
2351 if (sigalrm_received) {
2353 * Oh well. Just give up and quit.
2358 sigalrm_received = true;
2362 sigalrm_handler(int dummy __unused)
2365 sigalrm_received = true;
2369 set_timeout(int timeout, int fatal)
2371 struct sigaction sa;
2372 struct itimerval itv;
2376 log_debugx("session timeout disabled");
2377 bzero(&itv, sizeof(itv));
2378 error = setitimer(ITIMER_REAL, &itv, NULL);
2380 log_err(1, "setitimer");
2381 sigalrm_received = false;
2385 sigalrm_received = false;
2386 bzero(&sa, sizeof(sa));
2388 sa.sa_handler = sigalrm_handler_fatal;
2390 sa.sa_handler = sigalrm_handler;
2391 sigfillset(&sa.sa_mask);
2392 error = sigaction(SIGALRM, &sa, NULL);
2394 log_err(1, "sigaction");
2397 * First SIGALRM will arive after conf_timeout seconds.
2398 * If we do nothing, another one will arrive a second later.
2400 log_debugx("setting session timeout to %d seconds", timeout);
2401 bzero(&itv, sizeof(itv));
2402 itv.it_interval.tv_sec = 1;
2403 itv.it_value.tv_sec = timeout;
2404 error = setitimer(ITIMER_REAL, &itv, NULL);
2406 log_err(1, "setitimer");
2410 wait_for_children(bool block)
2418 * If "block" is true, wait for at least one process.
2420 if (block && num == 0)
2421 pid = wait4(-1, &status, 0, NULL);
2423 pid = wait4(-1, &status, WNOHANG, NULL);
2426 if (WIFSIGNALED(status)) {
2427 log_warnx("child process %d terminated with signal %d",
2428 pid, WTERMSIG(status));
2429 } else if (WEXITSTATUS(status) != 0) {
2430 log_warnx("child process %d terminated with exit status %d",
2431 pid, WEXITSTATUS(status));
2433 log_debugx("child process %d terminated gracefully", pid);
2442 handle_connection(struct portal *portal, int fd,
2443 const struct sockaddr *client_sa, bool dont_fork)
2445 struct ctld_connection *conn;
2448 char host[NI_MAXHOST + 1];
2451 conf = portal->p_portal_group->pg_conf;
2454 log_debugx("incoming connection; not forking due to -d flag");
2456 nchildren -= wait_for_children(false);
2457 assert(nchildren >= 0);
2459 while (conf->conf_maxproc > 0 && nchildren >= conf->conf_maxproc) {
2460 log_debugx("maxproc limit of %d child processes hit; "
2461 "waiting for child process to exit", conf->conf_maxproc);
2462 nchildren -= wait_for_children(true);
2463 assert(nchildren >= 0);
2465 log_debugx("incoming connection; forking child process #%d",
2476 pidfile_close(conf->conf_pidfh);
2478 error = getnameinfo(client_sa, client_sa->sa_len,
2479 host, sizeof(host), NULL, 0, NI_NUMERICHOST);
2481 log_errx(1, "getnameinfo: %s", gai_strerror(error));
2483 log_debugx("accepted connection from %s; portal group \"%s\"",
2484 host, portal->p_portal_group->pg_name);
2485 log_set_peer_addr(host);
2486 setproctitle("%s", host);
2488 conn = connection_new(portal, fd, host, client_sa);
2489 set_timeout(conf->conf_timeout, true);
2492 if (conn->conn_session_type == CONN_SESSION_TYPE_NORMAL) {
2493 kernel_handoff(conn);
2494 log_debugx("connection handed off to the kernel");
2496 assert(conn->conn_session_type == CONN_SESSION_TYPE_DISCOVERY);
2499 log_debugx("nothing more to do; exiting");
2504 fd_add(int fd, fd_set *fdset, int nfds)
2508 * Skip sockets which we failed to bind.
2520 main_loop(struct conf *conf, bool dont_fork)
2522 struct portal_group *pg;
2523 struct portal *portal;
2524 struct sockaddr_storage client_sa;
2525 socklen_t client_salen;
2526 #ifdef ICL_KERNEL_PROXY
2531 int error, nfds, client_fd;
2533 pidfile_write(conf->conf_pidfh);
2536 if (sighup_received || sigterm_received || timed_out())
2539 #ifdef ICL_KERNEL_PROXY
2541 client_salen = sizeof(client_sa);
2542 kernel_accept(&connection_id, &portal_id,
2543 (struct sockaddr *)&client_sa, &client_salen);
2544 assert(client_salen >= client_sa.ss_len);
2546 log_debugx("incoming connection, id %d, portal id %d",
2547 connection_id, portal_id);
2548 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
2549 TAILQ_FOREACH(portal, &pg->pg_portals, p_next) {
2550 if (portal->p_id == portal_id) {
2556 log_errx(1, "kernel returned invalid portal_id %d",
2560 handle_connection(portal, connection_id,
2561 (struct sockaddr *)&client_sa, dont_fork);
2564 assert(proxy_mode == false);
2568 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
2569 TAILQ_FOREACH(portal, &pg->pg_portals, p_next)
2570 nfds = fd_add(portal->p_socket, &fdset, nfds);
2572 error = select(nfds + 1, &fdset, NULL, NULL, NULL);
2576 log_err(1, "select");
2578 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
2579 TAILQ_FOREACH(portal, &pg->pg_portals, p_next) {
2580 if (!FD_ISSET(portal->p_socket, &fdset))
2582 client_salen = sizeof(client_sa);
2583 client_fd = accept(portal->p_socket,
2584 (struct sockaddr *)&client_sa,
2586 if (client_fd < 0) {
2587 if (errno == ECONNABORTED)
2589 log_err(1, "accept");
2591 assert(client_salen >= client_sa.ss_len);
2593 handle_connection(portal, client_fd,
2594 (struct sockaddr *)&client_sa,
2599 #ifdef ICL_KERNEL_PROXY
2606 sighup_handler(int dummy __unused)
2609 sighup_received = true;
2613 sigterm_handler(int dummy __unused)
2616 sigterm_received = true;
2620 sigchld_handler(int dummy __unused)
2624 * The only purpose of this handler is to make SIGCHLD
2625 * interrupt the ISCSIDWAIT ioctl(2), so we can call
2626 * wait_for_children().
2631 register_signals(void)
2633 struct sigaction sa;
2636 bzero(&sa, sizeof(sa));
2637 sa.sa_handler = sighup_handler;
2638 sigfillset(&sa.sa_mask);
2639 error = sigaction(SIGHUP, &sa, NULL);
2641 log_err(1, "sigaction");
2643 sa.sa_handler = sigterm_handler;
2644 error = sigaction(SIGTERM, &sa, NULL);
2646 log_err(1, "sigaction");
2648 sa.sa_handler = sigterm_handler;
2649 error = sigaction(SIGINT, &sa, NULL);
2651 log_err(1, "sigaction");
2653 sa.sa_handler = sigchld_handler;
2654 error = sigaction(SIGCHLD, &sa, NULL);
2656 log_err(1, "sigaction");
2660 check_perms(const char *path)
2665 error = stat(path, &sb);
2670 if (sb.st_mode & S_IWOTH) {
2671 log_warnx("%s is world-writable", path);
2672 } else if (sb.st_mode & S_IROTH) {
2673 log_warnx("%s is world-readable", path);
2674 } else if (sb.st_mode & S_IXOTH) {
2676 * Ok, this one doesn't matter, but still do it,
2677 * just for consistency.
2679 log_warnx("%s is world-executable", path);
2683 * XXX: Should we also check for owner != 0?
2687 static struct conf *
2688 conf_new_from_file(const char *path, struct conf *oldconf, bool ucl)
2691 struct auth_group *ag;
2692 struct portal_group *pg;
2696 log_debugx("obtaining configuration from %s", path);
2700 TAILQ_FOREACH(pp, &oldconf->conf_pports, pp_next)
2701 pport_copy(pp, conf);
2703 ag = auth_group_new(conf, "default");
2706 ag = auth_group_new(conf, "no-authentication");
2708 ag->ag_type = AG_TYPE_NO_AUTHENTICATION;
2710 ag = auth_group_new(conf, "no-access");
2712 ag->ag_type = AG_TYPE_DENY;
2714 pg = portal_group_new(conf, "default");
2718 error = uclparse_conf(conf, path);
2720 error = parse_conf(conf, path);
2729 if (conf->conf_default_ag_defined == false) {
2730 log_debugx("auth-group \"default\" not defined; "
2731 "going with defaults");
2732 ag = auth_group_find(conf, "default");
2734 ag->ag_type = AG_TYPE_DENY;
2737 if (conf->conf_default_pg_defined == false) {
2738 log_debugx("portal-group \"default\" not defined; "
2739 "going with defaults");
2740 pg = portal_group_find(conf, "default");
2742 portal_group_add_listen(pg, "0.0.0.0:3260", false);
2743 portal_group_add_listen(pg, "[::]:3260", false);
2746 conf->conf_kernel_port_on = true;
2748 error = conf_verify(conf);
2758 main(int argc, char **argv)
2760 struct conf *oldconf, *newconf, *tmpconf;
2762 const char *config_path = DEFAULT_CONFIG_PATH;
2763 int debug = 0, ch, error;
2764 bool dont_daemonize = false;
2765 bool test_config = false;
2766 bool use_ucl = false;
2768 while ((ch = getopt(argc, argv, "dtuf:R")) != -1) {
2771 dont_daemonize = true;
2781 config_path = optarg;
2784 #ifndef ICL_KERNEL_PROXY
2785 log_errx(1, "ctld(8) compiled without ICL_KERNEL_PROXY "
2786 "does not support iSER protocol");
2802 oldconf = conf_new_from_kernel();
2803 newconf = conf_new_from_file(config_path, oldconf, use_ucl);
2805 if (newconf == NULL)
2806 log_errx(1, "configuration error; exiting");
2812 oldconf->conf_debug = debug;
2813 newconf->conf_debug = debug;
2816 error = conf_apply(oldconf, newconf);
2818 log_errx(1, "failed to apply configuration; exiting");
2820 conf_delete(oldconf);
2825 if (dont_daemonize == false) {
2826 log_debugx("daemonizing");
2827 if (daemon(0, 0) == -1) {
2828 log_warn("cannot daemonize");
2829 pidfile_remove(newconf->conf_pidfh);
2834 /* Schedule iSNS update */
2835 if (!TAILQ_EMPTY(&newconf->conf_isns))
2836 set_timeout((newconf->conf_isns_period + 2) / 3, false);
2839 main_loop(newconf, dont_daemonize);
2840 if (sighup_received) {
2841 sighup_received = false;
2842 log_debugx("received SIGHUP, reloading configuration");
2843 tmpconf = conf_new_from_file(config_path, newconf,
2846 if (tmpconf == NULL) {
2847 log_warnx("configuration error, "
2848 "continuing with old configuration");
2851 tmpconf->conf_debug = debug;
2854 error = conf_apply(oldconf, newconf);
2856 log_warnx("failed to reload "
2858 conf_delete(oldconf);
2861 } else if (sigterm_received) {
2862 log_debugx("exiting on signal; "
2863 "reloading empty configuration");
2865 log_debugx("removing CTL iSCSI ports "
2866 "and terminating all connections");
2869 newconf = conf_new();
2871 newconf->conf_debug = debug;
2872 error = conf_apply(oldconf, newconf);
2874 log_warnx("failed to apply configuration");
2875 conf_delete(oldconf);
2878 log_warnx("exiting on signal");
2881 nchildren -= wait_for_children(false);
2882 assert(nchildren >= 0);
2884 set_timeout(0, false);
2885 TAILQ_FOREACH(newns, &newconf->conf_isns, i_next)
2887 /* Schedule iSNS update */
2888 if (!TAILQ_EMPTY(&newconf->conf_isns)) {
2889 set_timeout((newconf->conf_isns_period