2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2015 iXsystems Inc.
7 * This software was developed by Jakub Klama <jceel@FreeBSD.org>
8 * under sponsorship from iXsystems Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/queue.h>
33 #include <sys/types.h>
40 #include <netinet/in.h>
41 #include <netinet/ip.h>
45 static struct conf *conf = NULL;
47 static int uclparse_toplevel(const ucl_object_t *);
48 static int uclparse_chap(struct auth_group *, const ucl_object_t *);
49 static int uclparse_chap_mutual(struct auth_group *, const ucl_object_t *);
50 static int uclparse_lun(const char *, const ucl_object_t *);
51 static int uclparse_auth_group(const char *, const ucl_object_t *);
52 static int uclparse_portal_group(const char *, const ucl_object_t *);
53 static int uclparse_target(const char *, const ucl_object_t *);
54 static int uclparse_target_portal_group(struct target *, const ucl_object_t *);
55 static int uclparse_target_lun(struct target *, const ucl_object_t *);
58 uclparse_chap(struct auth_group *auth_group, const ucl_object_t *obj)
60 const struct auth *ca;
61 const ucl_object_t *user, *secret;
63 assert(auth_group != NULL);
64 user = ucl_object_find_key(obj, "user");
65 if (!user || user->type != UCL_STRING) {
66 log_warnx("chap section in auth-group \"%s\" is missing "
67 "\"user\" string key", auth_group->ag_name);
71 secret = ucl_object_find_key(obj, "secret");
72 if (!secret || secret->type != UCL_STRING) {
73 log_warnx("chap section in auth-group \"%s\" is missing "
74 "\"secret\" string key", auth_group->ag_name);
77 ca = auth_new_chap(auth_group,
78 ucl_object_tostring(user),
79 ucl_object_tostring(secret));
88 uclparse_chap_mutual(struct auth_group *auth_group, const ucl_object_t *obj)
90 const struct auth *ca;
91 const ucl_object_t *user, *secret, *mutual_user;
92 const ucl_object_t *mutual_secret;
94 assert(auth_group != NULL);
95 user = ucl_object_find_key(obj, "user");
96 if (!user || user->type != UCL_STRING) {
97 log_warnx("chap-mutual section in auth-group \"%s\" is missing "
98 "\"user\" string key", auth_group->ag_name);
102 secret = ucl_object_find_key(obj, "secret");
103 if (!secret || secret->type != UCL_STRING) {
104 log_warnx("chap-mutual section in auth-group \"%s\" is missing "
105 "\"secret\" string key", auth_group->ag_name);
109 mutual_user = ucl_object_find_key(obj, "mutual-user");
110 if (!user || user->type != UCL_STRING) {
111 log_warnx("chap-mutual section in auth-group \"%s\" is missing "
112 "\"mutual-user\" string key", auth_group->ag_name);
116 mutual_secret = ucl_object_find_key(obj, "mutual-secret");
117 if (!secret || secret->type != UCL_STRING) {
118 log_warnx("chap-mutual section in auth-group \"%s\" is missing "
119 "\"mutual-secret\" string key", auth_group->ag_name);
123 ca = auth_new_chap_mutual(auth_group,
124 ucl_object_tostring(user),
125 ucl_object_tostring(secret),
126 ucl_object_tostring(mutual_user),
127 ucl_object_tostring(mutual_secret));
136 uclparse_target_portal_group(struct target *target, const ucl_object_t *obj)
138 struct portal_group *tpg;
139 struct auth_group *tag = NULL;
141 const ucl_object_t *portal_group, *auth_group;
143 portal_group = ucl_object_find_key(obj, "name");
144 if (!portal_group || portal_group->type != UCL_STRING) {
145 log_warnx("portal-group section in target \"%s\" is missing "
146 "\"name\" string key", target->t_name);
150 auth_group = ucl_object_find_key(obj, "auth-group-name");
151 if (auth_group && auth_group->type != UCL_STRING) {
152 log_warnx("portal-group section in target \"%s\" is missing "
153 "\"auth-group-name\" string key", target->t_name);
158 tpg = portal_group_find(conf, ucl_object_tostring(portal_group));
160 log_warnx("unknown portal-group \"%s\" for target "
161 "\"%s\"", ucl_object_tostring(portal_group), target->t_name);
166 tag = auth_group_find(conf, ucl_object_tostring(auth_group));
168 log_warnx("unknown auth-group \"%s\" for target "
169 "\"%s\"", ucl_object_tostring(auth_group),
175 tp = port_new(conf, target, tpg);
177 log_warnx("can't link portal-group \"%s\" to target "
178 "\"%s\"", ucl_object_tostring(portal_group), target->t_name);
181 tp->p_auth_group = tag;
187 uclparse_target_lun(struct target *target, const ucl_object_t *obj)
192 if (obj->type == UCL_INT) {
195 tmp = ucl_object_toint(obj);
196 if (tmp >= MAX_LUNS) {
197 log_warnx("LU number %ju in target \"%s\" is too big",
198 tmp, target->t_name);
202 asprintf(&name, "%s,lun,%ju", target->t_name, tmp);
203 lun = lun_new(conf, name);
207 lun_set_scsiname(lun, name);
208 target->t_luns[tmp] = lun;
212 if (obj->type == UCL_OBJECT) {
213 const ucl_object_t *num = ucl_object_find_key(obj, "number");
214 const ucl_object_t *name = ucl_object_find_key(obj, "name");
216 if (num == NULL || num->type != UCL_INT) {
217 log_warnx("lun section in target \"%s\" is missing "
218 "\"number\" integer property", target->t_name);
221 tmp = ucl_object_toint(num);
222 if (tmp >= MAX_LUNS) {
223 log_warnx("LU number %ju in target \"%s\" is too big",
224 tmp, target->t_name);
228 if (name == NULL || name->type != UCL_STRING) {
229 log_warnx("lun section in target \"%s\" is missing "
230 "\"name\" string property", target->t_name);
234 lun = lun_find(conf, ucl_object_tostring(name));
238 target->t_luns[tmp] = lun;
245 uclparse_toplevel(const ucl_object_t *top)
247 ucl_object_iter_t it = NULL, iter = NULL;
248 const ucl_object_t *obj = NULL, *child = NULL;
251 /* Pass 1 - everything except targets */
252 while ((obj = ucl_iterate_object(top, &it, true))) {
253 const char *key = ucl_object_key(obj);
255 if (!strcmp(key, "debug")) {
256 if (obj->type == UCL_INT)
257 conf->conf_debug = ucl_object_toint(obj);
259 log_warnx("\"debug\" property value is not integer");
264 if (!strcmp(key, "timeout")) {
265 if (obj->type == UCL_INT)
266 conf->conf_timeout = ucl_object_toint(obj);
268 log_warnx("\"timeout\" property value is not integer");
273 if (!strcmp(key, "maxproc")) {
274 if (obj->type == UCL_INT)
275 conf->conf_maxproc = ucl_object_toint(obj);
277 log_warnx("\"maxproc\" property value is not integer");
282 if (!strcmp(key, "pidfile")) {
283 if (obj->type == UCL_STRING)
284 conf->conf_pidfile_path = strdup(
285 ucl_object_tostring(obj));
287 log_warnx("\"pidfile\" property value is not string");
292 if (!strcmp(key, "isns-server")) {
293 if (obj->type == UCL_ARRAY) {
295 while ((child = ucl_iterate_object(obj, &iter,
297 if (child->type != UCL_STRING)
301 ucl_object_tostring(child));
307 log_warnx("\"isns-server\" property value is "
313 if (!strcmp(key, "isns-period")) {
314 if (obj->type == UCL_INT)
315 conf->conf_timeout = ucl_object_toint(obj);
317 log_warnx("\"isns-period\" property value is not integer");
322 if (!strcmp(key, "isns-timeout")) {
323 if (obj->type == UCL_INT)
324 conf->conf_timeout = ucl_object_toint(obj);
326 log_warnx("\"isns-timeout\" property value is not integer");
331 if (!strcmp(key, "auth-group")) {
332 if (obj->type == UCL_OBJECT) {
334 while ((child = ucl_iterate_object(obj, &iter, true))) {
335 uclparse_auth_group(ucl_object_key(child), child);
338 log_warnx("\"auth-group\" section is not an object");
343 if (!strcmp(key, "portal-group")) {
344 if (obj->type == UCL_OBJECT) {
346 while ((child = ucl_iterate_object(obj, &iter, true))) {
347 uclparse_portal_group(ucl_object_key(child), child);
350 log_warnx("\"portal-group\" section is not an object");
355 if (!strcmp(key, "lun")) {
356 if (obj->type == UCL_OBJECT) {
358 while ((child = ucl_iterate_object(obj, &iter, true))) {
359 uclparse_lun(ucl_object_key(child), child);
362 log_warnx("\"lun\" section is not an object");
368 /* Pass 2 - targets */
370 while ((obj = ucl_iterate_object(top, &it, true))) {
371 const char *key = ucl_object_key(obj);
373 if (!strcmp(key, "target")) {
374 if (obj->type == UCL_OBJECT) {
376 while ((child = ucl_iterate_object(obj, &iter,
378 uclparse_target(ucl_object_key(child),
382 log_warnx("\"target\" section is not an object");
392 uclparse_auth_group(const char *name, const ucl_object_t *top)
394 struct auth_group *auth_group;
395 const struct auth_name *an;
396 const struct auth_portal *ap;
397 ucl_object_iter_t it = NULL, it2 = NULL;
398 const ucl_object_t *obj = NULL, *tmp = NULL;
402 if (!strcmp(name, "default") &&
403 conf->conf_default_ag_defined == false) {
404 auth_group = auth_group_find(conf, name);
405 conf->conf_default_ag_defined = true;
407 auth_group = auth_group_new(conf, name);
410 if (auth_group == NULL)
413 while ((obj = ucl_iterate_object(top, &it, true))) {
414 key = ucl_object_key(obj);
416 if (!strcmp(key, "auth-type")) {
417 const char *value = ucl_object_tostring(obj);
419 err = auth_group_set_type(auth_group, value);
424 if (!strcmp(key, "chap")) {
425 if (obj->type != UCL_ARRAY) {
426 log_warnx("\"chap\" property of "
427 "auth-group \"%s\" is not an array",
433 while ((tmp = ucl_iterate_object(obj, &it2, true))) {
434 if (uclparse_chap(auth_group, tmp) != 0)
439 if (!strcmp(key, "chap-mutual")) {
440 if (obj->type != UCL_ARRAY) {
441 log_warnx("\"chap-mutual\" property of "
442 "auth-group \"%s\" is not an array",
448 while ((tmp = ucl_iterate_object(obj, &it2, true))) {
449 if (uclparse_chap_mutual(auth_group, tmp) != 0)
454 if (!strcmp(key, "initiator-name")) {
455 if (obj->type != UCL_ARRAY) {
456 log_warnx("\"initiator-name\" property of "
457 "auth-group \"%s\" is not an array",
463 while ((tmp = ucl_iterate_object(obj, &it2, true))) {
464 const char *value = ucl_object_tostring(tmp);
466 an = auth_name_new(auth_group, value);
472 if (!strcmp(key, "initiator-portal")) {
473 if (obj->type != UCL_ARRAY) {
474 log_warnx("\"initiator-portal\" property of "
475 "auth-group \"%s\" is not an array",
481 while ((tmp = ucl_iterate_object(obj, &it2, true))) {
482 const char *value = ucl_object_tostring(tmp);
484 ap = auth_portal_new(auth_group, value);
495 uclparse_portal_group(const char *name, const ucl_object_t *top)
497 struct portal_group *portal_group;
498 ucl_object_iter_t it = NULL, it2 = NULL;
499 const ucl_object_t *obj = NULL, *tmp = NULL;
502 if (strcmp(name, "default") == 0 &&
503 conf->conf_default_pg_defined == false) {
504 portal_group = portal_group_find(conf, name);
505 conf->conf_default_pg_defined = true;
507 portal_group = portal_group_new(conf, name);
510 if (portal_group == NULL)
513 while ((obj = ucl_iterate_object(top, &it, true))) {
514 key = ucl_object_key(obj);
516 if (!strcmp(key, "discovery-auth-group")) {
517 portal_group->pg_discovery_auth_group =
518 auth_group_find(conf, ucl_object_tostring(obj));
519 if (portal_group->pg_discovery_auth_group == NULL) {
520 log_warnx("unknown discovery-auth-group \"%s\" "
521 "for portal-group \"%s\"",
522 ucl_object_tostring(obj),
523 portal_group->pg_name);
528 if (!strcmp(key, "discovery-filter")) {
529 if (obj->type != UCL_STRING) {
530 log_warnx("\"discovery-filter\" property of "
531 "portal-group \"%s\" is not a string",
532 portal_group->pg_name);
536 if (portal_group_set_filter(portal_group,
537 ucl_object_tostring(obj)) != 0)
541 if (!strcmp(key, "listen")) {
542 if (obj->type == UCL_STRING) {
543 if (portal_group_add_listen(portal_group,
544 ucl_object_tostring(obj), false) != 0)
546 } else if (obj->type == UCL_ARRAY) {
547 while ((tmp = ucl_iterate_object(obj, &it2,
549 if (portal_group_add_listen(
551 ucl_object_tostring(tmp),
556 log_warnx("\"listen\" property of "
557 "portal-group \"%s\" is not a string",
558 portal_group->pg_name);
563 if (!strcmp(key, "listen-iser")) {
564 if (obj->type == UCL_STRING) {
565 if (portal_group_add_listen(portal_group,
566 ucl_object_tostring(obj), true) != 0)
568 } else if (obj->type == UCL_ARRAY) {
569 while ((tmp = ucl_iterate_object(obj, &it2,
571 if (portal_group_add_listen(
573 ucl_object_tostring(tmp),
578 log_warnx("\"listen\" property of "
579 "portal-group \"%s\" is not a string",
580 portal_group->pg_name);
585 if (!strcmp(key, "redirect")) {
586 if (obj->type != UCL_STRING) {
587 log_warnx("\"listen\" property of "
588 "portal-group \"%s\" is not a string",
589 portal_group->pg_name);
593 if (portal_group_set_redirection(portal_group,
594 ucl_object_tostring(obj)) != 0)
598 if (!strcmp(key, "options")) {
599 if (obj->type != UCL_OBJECT) {
600 log_warnx("\"options\" property of portal group "
601 "\"%s\" is not an object", portal_group->pg_name);
605 while ((tmp = ucl_iterate_object(obj, &it2,
607 option_new(&portal_group->pg_options,
609 ucl_object_tostring_forced(tmp));
613 if (!strcmp(key, "dscp")) {
614 if ((obj->type != UCL_STRING) && (obj->type != UCL_INT)) {
615 log_warnx("\"dscp\" property of portal group "
616 "\"%s\" is not a string or integer", portal_group->pg_name);
619 if (obj->type == UCL_INT)
620 portal_group->pg_dscp = ucl_object_toint(obj);
622 key = ucl_object_tostring(obj);
623 if (strcmp(key, "0x") == 0)
624 portal_group->pg_dscp = strtol(key + 2, NULL, 16);
625 else if (strcmp(key, "be") || strcmp(key, "cs0"))
626 portal_group->pg_dscp = IPTOS_DSCP_CS0 >> 2;
627 else if (strcmp(key, "ef"))
628 portal_group->pg_dscp = IPTOS_DSCP_EF >> 2;
629 else if (strcmp(key, "cs0"))
630 portal_group->pg_dscp = IPTOS_DSCP_CS0 >> 2;
631 else if (strcmp(key, "cs1"))
632 portal_group->pg_dscp = IPTOS_DSCP_CS1 >> 2;
633 else if (strcmp(key, "cs2"))
634 portal_group->pg_dscp = IPTOS_DSCP_CS2 >> 2;
635 else if (strcmp(key, "cs3"))
636 portal_group->pg_dscp = IPTOS_DSCP_CS3 >> 2;
637 else if (strcmp(key, "cs4"))
638 portal_group->pg_dscp = IPTOS_DSCP_CS4 >> 2;
639 else if (strcmp(key, "cs5"))
640 portal_group->pg_dscp = IPTOS_DSCP_CS5 >> 2;
641 else if (strcmp(key, "cs6"))
642 portal_group->pg_dscp = IPTOS_DSCP_CS6 >> 2;
643 else if (strcmp(key, "cs7"))
644 portal_group->pg_dscp = IPTOS_DSCP_CS7 >> 2;
645 else if (strcmp(key, "af11"))
646 portal_group->pg_dscp = IPTOS_DSCP_AF11 >> 2;
647 else if (strcmp(key, "af12"))
648 portal_group->pg_dscp = IPTOS_DSCP_AF12 >> 2;
649 else if (strcmp(key, "af13"))
650 portal_group->pg_dscp = IPTOS_DSCP_AF13 >> 2;
651 else if (strcmp(key, "af21"))
652 portal_group->pg_dscp = IPTOS_DSCP_AF21 >> 2;
653 else if (strcmp(key, "af22"))
654 portal_group->pg_dscp = IPTOS_DSCP_AF22 >> 2;
655 else if (strcmp(key, "af23"))
656 portal_group->pg_dscp = IPTOS_DSCP_AF23 >> 2;
657 else if (strcmp(key, "af31"))
658 portal_group->pg_dscp = IPTOS_DSCP_AF31 >> 2;
659 else if (strcmp(key, "af32"))
660 portal_group->pg_dscp = IPTOS_DSCP_AF32 >> 2;
661 else if (strcmp(key, "af33"))
662 portal_group->pg_dscp = IPTOS_DSCP_AF33 >> 2;
663 else if (strcmp(key, "af41"))
664 portal_group->pg_dscp = IPTOS_DSCP_AF41 >> 2;
665 else if (strcmp(key, "af42"))
666 portal_group->pg_dscp = IPTOS_DSCP_AF42 >> 2;
667 else if (strcmp(key, "af43"))
668 portal_group->pg_dscp = IPTOS_DSCP_AF43 >> 2;
670 log_warnx("\"dscp\" property value is not a supported textual value");
676 if (!strcmp(key, "pcp")) {
677 if (obj->type != UCL_INT) {
678 log_warnx("\"pcp\" property of portal group "
679 "\"%s\" is not an integer", portal_group->pg_name);
682 portal_group->pg_pcp = ucl_object_toint(obj);
683 if (!((portal_group->pg_pcp >= 0) && (portal_group->pg_pcp <= 7))) {
684 log_warnx("invalid \"pcp\" value %d, using default", portal_group->pg_pcp);
685 portal_group->pg_pcp = -1;
694 uclparse_target(const char *name, const ucl_object_t *top)
696 struct target *target;
697 ucl_object_iter_t it = NULL, it2 = NULL;
698 const ucl_object_t *obj = NULL, *tmp = NULL;
701 target = target_new(conf, name);
705 while ((obj = ucl_iterate_object(top, &it, true))) {
706 key = ucl_object_key(obj);
708 if (!strcmp(key, "alias")) {
709 if (obj->type != UCL_STRING) {
710 log_warnx("\"alias\" property of target "
711 "\"%s\" is not a string", target->t_name);
715 target->t_alias = strdup(ucl_object_tostring(obj));
718 if (!strcmp(key, "auth-group")) {
721 if (target->t_auth_group != NULL) {
722 if (target->t_auth_group->ag_name != NULL)
723 log_warnx("auth-group for target \"%s\" "
724 "specified more than once",
727 log_warnx("cannot use both auth-group "
728 "and explicit authorisations for "
729 "target \"%s\"", target->t_name);
732 ag = ucl_object_tostring(obj);
734 log_warnx("auth-group must be a string");
737 target->t_auth_group = auth_group_find(conf, ag);
738 if (target->t_auth_group == NULL) {
739 log_warnx("unknown auth-group \"%s\" for target "
740 "\"%s\"", ucl_object_tostring(obj),
746 if (!strcmp(key, "auth-type")) {
749 if (target->t_auth_group != NULL) {
750 if (target->t_auth_group->ag_name != NULL) {
751 log_warnx("cannot use both auth-group and "
752 "auth-type for target \"%s\"",
757 target->t_auth_group = auth_group_new(conf, NULL);
758 if (target->t_auth_group == NULL)
761 target->t_auth_group->ag_target = target;
763 error = auth_group_set_type(target->t_auth_group,
764 ucl_object_tostring(obj));
769 if (!strcmp(key, "chap")) {
770 if (target->t_auth_group != NULL) {
771 if (target->t_auth_group->ag_name != NULL) {
772 log_warnx("cannot use both auth-group "
773 "and chap for target \"%s\"",
778 target->t_auth_group = auth_group_new(conf, NULL);
779 if (target->t_auth_group == NULL) {
782 target->t_auth_group->ag_target = target;
784 if (uclparse_chap(target->t_auth_group, obj) != 0)
788 if (!strcmp(key, "chap-mutual")) {
789 if (uclparse_chap_mutual(target->t_auth_group, obj) != 0)
793 if (!strcmp(key, "initiator-name")) {
794 const struct auth_name *an;
796 if (target->t_auth_group != NULL) {
797 if (target->t_auth_group->ag_name != NULL) {
798 log_warnx("cannot use both auth-group and "
799 "initiator-name for target \"%s\"",
804 target->t_auth_group = auth_group_new(conf, NULL);
805 if (target->t_auth_group == NULL)
808 target->t_auth_group->ag_target = target;
810 an = auth_name_new(target->t_auth_group,
811 ucl_object_tostring(obj));
816 if (!strcmp(key, "initiator-portal")) {
817 const struct auth_portal *ap;
819 if (target->t_auth_group != NULL) {
820 if (target->t_auth_group->ag_name != NULL) {
821 log_warnx("cannot use both auth-group and "
822 "initiator-portal for target \"%s\"",
827 target->t_auth_group = auth_group_new(conf, NULL);
828 if (target->t_auth_group == NULL)
831 target->t_auth_group->ag_target = target;
833 ap = auth_portal_new(target->t_auth_group,
834 ucl_object_tostring(obj));
839 if (!strcmp(key, "portal-group")) {
840 if (obj->type == UCL_OBJECT) {
841 if (uclparse_target_portal_group(target, obj) != 0)
845 if (obj->type == UCL_ARRAY) {
846 while ((tmp = ucl_iterate_object(obj, &it2,
848 if (uclparse_target_portal_group(target,
855 if (!strcmp(key, "port")) {
858 const char *value = ucl_object_tostring(obj);
859 int ret, i_pp, i_vp = 0;
861 ret = sscanf(value, "ioctl/%d/%d", &i_pp, &i_vp);
863 tp = port_new_ioctl(conf, target, i_pp, i_vp);
865 log_warnx("can't create new ioctl port "
866 "for target \"%s\"", target->t_name);
873 pp = pport_find(conf, value);
875 log_warnx("unknown port \"%s\" for target \"%s\"",
876 value, target->t_name);
879 if (!TAILQ_EMPTY(&pp->pp_ports)) {
880 log_warnx("can't link port \"%s\" to target \"%s\", "
881 "port already linked to some target",
882 value, target->t_name);
885 tp = port_new_pp(conf, target, pp);
887 log_warnx("can't link port \"%s\" to target \"%s\"",
888 value, target->t_name);
893 if (!strcmp(key, "redirect")) {
894 if (obj->type != UCL_STRING) {
895 log_warnx("\"redirect\" property of target "
896 "\"%s\" is not a string", target->t_name);
900 if (target_set_redirection(target,
901 ucl_object_tostring(obj)) != 0)
905 if (!strcmp(key, "lun")) {
906 while ((tmp = ucl_iterate_object(obj, &it2, true))) {
907 if (uclparse_target_lun(target, tmp) != 0)
917 uclparse_lun(const char *name, const ucl_object_t *top)
920 ucl_object_iter_t it = NULL, child_it = NULL;
921 const ucl_object_t *obj = NULL, *child = NULL;
924 lun = lun_new(conf, name);
928 while ((obj = ucl_iterate_object(top, &it, true))) {
929 key = ucl_object_key(obj);
931 if (!strcmp(key, "backend")) {
932 if (obj->type != UCL_STRING) {
933 log_warnx("\"backend\" property of lun "
934 "\"%s\" is not a string",
939 lun_set_backend(lun, ucl_object_tostring(obj));
942 if (!strcmp(key, "blocksize")) {
943 if (obj->type != UCL_INT) {
944 log_warnx("\"blocksize\" property of lun "
945 "\"%s\" is not an integer", lun->l_name);
949 lun_set_blocksize(lun, ucl_object_toint(obj));
952 if (!strcmp(key, "device-id")) {
953 if (obj->type != UCL_STRING) {
954 log_warnx("\"device-id\" property of lun "
955 "\"%s\" is not an integer", lun->l_name);
959 lun_set_device_id(lun, ucl_object_tostring(obj));
962 if (!strcmp(key, "options")) {
963 if (obj->type != UCL_OBJECT) {
964 log_warnx("\"options\" property of lun "
965 "\"%s\" is not an object", lun->l_name);
969 while ((child = ucl_iterate_object(obj, &child_it,
971 option_new(&lun->l_options,
972 ucl_object_key(child),
973 ucl_object_tostring_forced(child));
977 if (!strcmp(key, "path")) {
978 if (obj->type != UCL_STRING) {
979 log_warnx("\"path\" property of lun "
980 "\"%s\" is not a string", lun->l_name);
984 lun_set_path(lun, ucl_object_tostring(obj));
987 if (!strcmp(key, "serial")) {
988 if (obj->type != UCL_STRING) {
989 log_warnx("\"serial\" property of lun "
990 "\"%s\" is not a string", lun->l_name);
994 lun_set_serial(lun, ucl_object_tostring(obj));
997 if (!strcmp(key, "size")) {
998 if (obj->type != UCL_INT) {
999 log_warnx("\"size\" property of lun "
1000 "\"%s\" is not an integer", lun->l_name);
1004 lun_set_size(lun, ucl_object_toint(obj));
1012 uclparse_conf(struct conf *newconf, const char *path)
1014 struct ucl_parser *parser;
1019 parser = ucl_parser_new(0);
1021 if (!ucl_parser_add_file(parser, path)) {
1022 log_warn("unable to parse configuration file %s: %s", path,
1023 ucl_parser_get_error(parser));
1024 ucl_parser_free(parser);
1028 top = ucl_parser_get_object(parser);
1029 error = uclparse_toplevel(top);
1030 ucl_object_unref(top);
1031 ucl_parser_free(parser);