]> git.ipfire.org Git - people/stevee/network.git/blame - src/functions/functions.zone
wireless-ap: Bring up hostapd, too when device is plugged in
[people/stevee/network.git] / src / functions / functions.zone
CommitLineData
1848564d
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2010 Michael Tremer & Christian Schmidt #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21
22function zone_dir() {
23 local zone=${1}
24
d2a21d01 25 echo "${NETWORK_ZONE_DIR}/zones/${zone}"
1848564d
MT
26}
27
28function zone_exists() {
29 local zone=${1}
711ffac1
MT
30 assert isset zone
31
1848564d
MT
32 [ -d "$(zone_dir ${zone})" ]
33}
34
35function zone_match() {
36 local match
37
38 local i
39 for i in ${VALID_ZONES}; do
40 match="${match}|${i}[0-9]{1,5}"
41 done
42
43 echo "${match:1:${#match}}"
44}
45
46function zone_name_is_valid() {
47 local zone=${1}
4fedddef
MT
48
49 # Don't accept empty strings.
50 [ -z "${zone}" ] && return ${EXIT_FALSE}
711ffac1 51
1848564d
MT
52 [[ ${zone} =~ $(zone_match) ]]
53}
54
55function zone_is_local() {
56 local zone=${1}
57
7de0637a 58 [[ "${zone:0:${#ZONE_LOCAL}}" = "${ZONE_LOCAL}" ]]
5e42d659
MT
59}
60
61function zone_is_nonlocal() {
62 local zone=${1}
63
7de0637a 64 [[ "${zone:0:${#ZONE_NONLOCAL}}" = "${ZONE_NONLOCAL}" ]]
1848564d
MT
65}
66
67function zone_get_hook() {
68 local zone=${1}
711ffac1
MT
69 assert isset zone
70
1848564d
MT
71 config_get_hook $(zone_dir ${zone})/settings
72}
73
5bb2429a
MT
74function zone_start() {
75 # This function will bring up the zone
76 # 'asynchronously' with help of systemd.
77
78 local zone=${1}
79 assert zone_exists ${zone}
80
1d08b9b3 81 service_start "network@${zone}.service"
5bb2429a
MT
82}
83
84function zone_stop() {
85 # This function will bring down the zone
86 # 'asynchronously' with help of systemd.
87
88 local zone=${1}
89 assert zone_exists ${zone}
90
1d08b9b3 91 service_stop "network@${zone}.service"
5bb2429a
MT
92}
93
e6fd23fd
MT
94function zone_reload() {
95 local zone="${1}"
96 assert zone_exists "${zone}"
97
98 service_reload "network@${zone}.service"
99}
100
fb8c7c92
MT
101function zone_hotplug_event() {
102 local zone="${1}"
103 assert zone_exists "${zone}"
104
105 # If the zone has already been started, we
106 # will reload it so the current configuration
107 # is re-applied.
108 if zone_is_active "${zone}"; then
109 zone_reload "${zone}"
110 return ${?}
111
112 # If the zone is still down, but in auto-start mode,
113 # we will start it.
114 elif zone_is_enabled "${zone}"; then
115 zone_start "${zone}"
116 return ${?}
117 fi
118
119 # Otherwise, nothing will be done.
120 return ${EXIT_OK}
121}
122
5c5b8e36
SS
123function zone_enable() {
124 # This function will enable the zone
125 # with help of systemd.
126
127 local zone="${1}"
128 assert zone_exists "${zone}"
129
130 # Enable service for the zone
131 service_enable "network@${zone}.service"
132 local ret=$?
133
134 if [ ${ret} -eq ${EXIT_OK} ]; then
135 log INFO "Auto-start enabled for zone ${zone}"
136 return ${EXIT_OK}
137 fi
138
139 log ERROR "Could not enable zone ${zone}: ${ret}"
140 return ${ret}
141}
142
143function zone_disable() {
144 # This function will disable the zone
145 # with help of systemd.
146
147 local zone="${1}"
148 assert zone_exists "${zone}"
149
150 # Disable service for the zone
151 service_disable "network@${zone}.service"
152 local ret=$?
153
154 if [ ${ret} -eq ${EXIT_OK} ]; then
155 log INFO "Auto-start disabled for zone ${zone}"
156 return ${EXIT_OK}
157 fi
158
159 log ERROR "Could not disable zone ${zone}: ${ret}"
160 return ${ret}
161}
162
163function zone_is_enabled() {
164 local zone="${1}"
165 assert isset zone
166
167 # Ask systemd if the zone is enabled.
168 if service_is_enabled "network@${zone}.service"; then
169 return ${EXIT_TRUE}
170 fi
171
172 return ${EXIT_FALSE}
173}
174
e6fd23fd
MT
175function zone_is_active() {
176 local zone="${1}"
177 assert isset zone
178
179 if service_is_active "network@${zone}.service"; then
180 return ${EXIT_TRUE}
181 fi
182
183 return ${EXIT_FALSE}
184}
185
1848564d
MT
186function zone_create() {
187 local zone=${1}
188 local hook=${2}
189 shift 2
190
191 if ! zone_name_is_valid ${zone}; then
192 error "Zone name '${zone}' is not valid."
193 return ${EXIT_ERROR}
194 fi
195
196 if zone_exists ${zone}; then
197 error "Zone '${zone}' does already exist."
198 return ${EXIT_ERROR}
199 fi
200
d61a01d4 201 if ! hook_zone_exists ${hook}; then
1848564d
MT
202 error "Hook '${hook}' does not exist."
203 return ${EXIT_ERROR}
204 fi
205
206 mkdir -p $(zone_dir ${zone})
207
a5ebb169
MT
208 # Create directories for configs and ports
209 mkdir -p $(zone_dir ${zone})/{configs,ports}
943e3f7e 210
d61a01d4 211 hook_zone_exec ${hook} create ${zone} $@
1848564d
MT
212 local ret=$?
213
214 # Maybe the zone create hook did not exit correctly.
215 # If this is the case we remove the created zone immediately.
216 if [ "${ret}" = "${EXIT_ERROR}" ]; then
69ace22b 217 zone_remove_now ${zone}
5c5b8e36 218 return ${EXIT_ERROR}
1848564d 219 fi
5c5b8e36
SS
220
221 # Automatically enable zone.
222 zone_enable "${zone}"
1848564d
MT
223}
224
225function zone_edit() {
226 local zone=${1}
227 shift
228
229 if ! zone_exists ${zone}; then
230 error "Zone '${zone}' does not exist."
231 return ${EXIT_ERROR}
232 fi
233
69ace22b
MT
234 # Check if the zone is tagged for removal.
235 if zone_has_remove_tag ${zone}; then
236 error "You cannot edit a zone that is tagged for removal."
237 return ${EXIT_ERROR}
238 fi
239
1848564d
MT
240 local hook=$(config_get_hook $(zone_dir ${zone})/settings)
241
242 if [ -z "${hook}" ]; then
243 error "Config file did not provide any hook."
244 return ${EXIT_ERROR}
245 fi
246
d61a01d4 247 if ! hook_zone_exists ${hook}; then
1848564d
MT
248 error "Hook '${hook}' does not exist."
249 return ${EXIT_ERROR}
250 fi
251
d61a01d4 252 hook_zone_exec ${hook} edit ${zone} $@
1848564d
MT
253}
254
69ace22b 255
1848564d
MT
256function zone_remove() {
257 local zone=${1}
69ace22b 258 assert zone_exists ${zone}
1848564d 259
69ace22b
MT
260 # Make the zone for removal.
261 touch $(zone_dir ${zone})/.remove
262
263 log INFO "Zone '${zone}' has been tagged for removal."
264}
265
266function zone_has_remove_tag() {
267 local zone=${1}
268 assert zone_exists ${zone}
269
270 [ -e "$(zone_dir ${zone})/.remove" ]
271}
272
273# This function will remove the given zone
274# RIGHT NOW. Use zone_remove to remove it
275# at the next status change.
276function zone_remove_now() {
277 local zone=${1}
278 assert zone_exists ${zone}
279
280 log INFO "Removing zone '${zone}' right now."
1848564d 281
69ace22b
MT
282 # Force the zone down.
283 zone_is_up ${zone} && zone_set_down ${zone}
1848564d 284
5c5b8e36
SS
285 # Disable zone.
286 zone_disable "${zone}"
287
1848564d
MT
288 rm -rf $(zone_dir ${zone})
289}
290
291function zone_up() {
292 local zone=${1}
293 shift
294
295 if ! zone_exists ${zone}; then
296 error "Zone '${zone}' does not exist."
297 return ${EXIT_ERROR}
298 fi
299
69ace22b
MT
300 # Check if a zone has got the remove tag.
301 if zone_has_remove_tag ${zone}; then
302 error "Cannot bring up any zone which is to be removed."
303 return ${EXIT_ERROR}
304 fi
305
1848564d
MT
306 local hook=$(config_get_hook $(zone_dir ${zone})/settings)
307
308 if [ -z "${hook}" ]; then
309 error "Config file did not provide any hook."
310 return ${EXIT_ERROR}
311 fi
312
d61a01d4 313 if ! hook_zone_exists ${hook}; then
1848564d
MT
314 error "Hook '${hook}' does not exist."
315 return ${EXIT_ERROR}
316 fi
317
059469a8
MT
318 zone_db ${zone} starting
319
d61a01d4
MT
320 hook_zone_exec ${hook} up ${zone} $@
321
059469a8 322 zone_db ${zone} started
1848564d
MT
323}
324
325function zone_down() {
326 local zone=${1}
327 shift
328
329 if ! zone_exists ${zone}; then
330 error "Zone '${zone}' does not exist."
331 return ${EXIT_ERROR}
332 fi
333
334 local hook=$(config_get_hook $(zone_dir ${zone})/settings)
335
336 if [ -z "${hook}" ]; then
337 error "Config file did not provide any hook."
338 return ${EXIT_ERROR}
339 fi
340
d61a01d4 341 if ! hook_zone_exists ${hook}; then
1848564d
MT
342 error "Hook '${hook}' does not exist."
343 return ${EXIT_ERROR}
344 fi
345
059469a8
MT
346 zone_db ${zone} stopping
347
d61a01d4 348 hook_zone_exec ${hook} down ${zone} $@
059469a8
MT
349
350 zone_db ${zone} stopped
69ace22b
MT
351
352 # Remove the zone, if it has got a remove tag.
353 if zone_has_remove_tag ${zone}; then
354 zone_remove_now ${zone}
355 fi
1848564d
MT
356}
357
358function zone_status() {
359 local zone=${1}
360 shift
361
362 if ! zone_exists ${zone}; then
363 error "Zone '${zone}' does not exist."
364 return ${EXIT_ERROR}
365 fi
366
367 local hook=$(config_get_hook $(zone_dir ${zone})/settings)
368
369 if [ -z "${hook}" ]; then
370 error "Config file did not provide any hook."
371 return ${EXIT_ERROR}
372 fi
373
d61a01d4 374 if ! hook_zone_exists ${hook}; then
1848564d
MT
375 error "Hook '${hook}' does not exist."
376 return ${EXIT_ERROR}
377 fi
378
d61a01d4 379 hook_zone_exec ${hook} status ${zone} $@
69ace22b
MT
380
381 # Show that the zone it to be removed soon.
382 if zone_has_remove_tag ${zone}; then
383 warning "This zone is tagged for removal."
384 fi
1848564d
MT
385}
386
711ffac1
MT
387function zone_port() {
388 local zone=${1}
389 local action=${2}
390 shift 2
391
392 assert isset zone
393 assert isset action
394 assert zone_exists ${zone}
395
396 case "${action}" in
828eb94a 397 add|edit|remove)
943e3f7e
MT
398 zone_port_${action} ${zone} $@
399 ;;
400 *)
401 error "Unrecognized argument: ${action}"
402 cli_usage root-zone-port-subcommands
403 exit ${EXIT_ERROR}
404 ;;
405 esac
711ffac1
MT
406}
407
408function zone_port_add() {
828eb94a 409 local zone="${1}"
711ffac1
MT
410 assert isset zone
411
828eb94a
MT
412 local port="${2}"
413 assert isset port
414
415 shift 2
711ffac1 416
828eb94a
MT
417 # Check if the port actually exists.
418 if ! port_exists "${port}"; then
419 error "Cannot add port '${port}' which does not exist"
420 return ${EXIT_ERROR}
421 fi
422
423 # Check if the port is already connected to this or any other zone.
424 local z
425 for z in $(zones_get_all); do
426 if zone_has_port "${z}" "${port}"; then
427 error "Port '${port}' is already assigned to zone '${z}'"
428 return ${EXIT_ERROR}
429 fi
430 done
431
432 local hook=$(zone_get_hook "${zone}")
711ffac1
MT
433 assert isset hook
434
828eb94a 435 hook_zone_exec "${hook}" "port_add" "${zone}" "${port}" "$@"
711ffac1
MT
436}
437
438function zone_port_edit() {
828eb94a
MT
439 local zone="${1}"
440 assert isset zone
711ffac1 441
828eb94a
MT
442 local port="${2}"
443 assert isset port
711ffac1 444
828eb94a 445 shift 2
711ffac1 446
828eb94a
MT
447 # Check if the port actually exists.
448 if ! port_exists "${port}"; then
449 error "Port '${port}' does not exist"
450 return ${EXIT_ERROR}
451 fi
711ffac1 452
828eb94a
MT
453 # Check if the zone actually has this port.
454 if ! zone_has_port "${zone}" "${port}"; then
455 error "Port '${port}' is not attached to zone '${zone}'"
456 return ${EXIT_ERROR}
457 fi
711ffac1 458
828eb94a
MT
459 local hook=$(zone_get_hook "${zone}")
460 assert isset hook
711ffac1 461
828eb94a 462 hook_zone_exec "${hook}" "port_edit" "${zone}" "${port}" "$@"
711ffac1
MT
463}
464
828eb94a
MT
465function zone_port_remove() {
466 local zone="${1}"
467 assert isset zone
468
469 local port="${2}"
470 assert isset port
471
472 shift 2
473
474 # Check if the zone actually has this port.
475 if ! zone_has_port "${zone}" "${port}"; then
476 error "Port '${port}' is not attached to zone '${zone}'"
477 return ${EXIT_ERROR}
478 fi
479
480 local hook=$(zone_get_hook "${zone}")
481 assert isset hook
711ffac1 482
828eb94a 483 hook_zone_exec "${hook}" "port_remove" "${zone}" "${port}" "$@"
711ffac1
MT
484}
485
486function zone_get_ports() {
487 local zone=${1}
488
489 assert isset zone
490
491 local port
943e3f7e 492 for port in $(zone_dir ${zone})/ports/*; do
711ffac1 493 port=$(basename ${port})
711ffac1
MT
494
495 if port_exists ${port}; then
496 echo "${port}"
497 fi
498 done
499}
500
529141df
MT
501function zone_get_ports_num() {
502 local zone="${1}"
503 assert isset zone
504
505 local counter=0
506 local port
507 for port in $(zone_dir "${zone}")/ports/*; do
508 port="$(basename "${port}")"
509
510 if port_exists "${port}"; then
511 counter=$(( ${counter} + 1 ))
512 fi
513 done
514
515 echo "${counter}"
516 return ${EXIT_OK}
517}
518
3a7fef62
MT
519function zone_has_port() {
520 # Check, if the given port is configured
521 # in this zone.
522
523 local zone=${1}
524 local port=${2}
525 shift 2
526
527 assert isset zone
528 assert isset port
529
530 [ -e "$(zone_dir ${zone})/ports/${port}" ]
531}
532
a5ebb169 533# XXX overwritten some lines below
1848564d
MT
534function zone_config() {
535 local zone=${1}
536 shift
537
538 if ! zone_exists ${zone}; then
539 error "Zone '${zone}' does not exist."
540 return ${EXIT_ERROR}
541 fi
542
543 local hook=$(config_get_hook $(zone_dir ${zone})/settings)
544
545 if [ -z "${hook}" ]; then
546 error "Config file did not provide any hook."
547 return ${EXIT_ERROR}
548 fi
549
d61a01d4 550 if ! hook_zone_exists ${hook}; then
1848564d
MT
551 error "Hook '${hook}' does not exist."
552 return ${EXIT_ERROR}
553 fi
554
d61a01d4 555 hook_zone_exec ${hook} config ${zone} $@
1848564d
MT
556}
557
a5ebb169
MT
558function zone_config() {
559 local zone=${1}
560 local action=${2}
561 shift 2
562
563 assert isset zone
564 assert isset action
565 assert zone_exists ${zone}
566
567 # Aliases
568 case "${action}" in
569 del|delete|remove)
570 action="rem"
571 ;;
572 esac
573
574 case "${action}" in
575 create|edit|rem)
576 zone_config_${action} ${zone} $@
577 ;;
578 *)
579 error "Unrecognized argument: ${action}"
580 cli_usage root-zone-config-subcommands
581 exit ${EXIT_ERROR}
582 ;;
583 esac
584}
585
586function zone_config_create() {
e9df08ad 587 local zone="${1}"
a5ebb169 588 assert isset zone
e9df08ad 589 shift
a5ebb169 590
e9df08ad 591 local hook=$(zone_get_hook "${zone}")
a5ebb169
MT
592 assert isset hook
593
e9df08ad 594 hook_zone_exec "${hook}" "config_create" "${zone}" "$@"
a5ebb169
MT
595}
596
1848564d
MT
597function zone_show() {
598 local zone=${1}
599
600 echo "${zone}"
601 echo " Type: $(zone_get_hook ${zone})"
602 echo
603}
604
605function zones_show() {
606 local zone
607
608 for zone in $(zones_get $@); do
609 zone_show ${zone}
610 done
611}
612
613function zones_get_all() {
614 local zone
d61a01d4 615 for zone in $(zone_dir)/*; do
1848564d
MT
616 zone=$(basename ${zone})
617 zone_exists ${zone} || continue
618
619 echo "${zone}"
03170817 620 done
1848564d
MT
621}
622
623function zones_get_local() {
624 local zone
625 for zone in $(zones_get_all); do
626 zone_is_local ${zone} && echo "${zone}"
627 done
628}
629
630function zones_get_nonlocal() {
631 local zone
632 for zone in $(zones_get_all); do
5e42d659 633 zone_is_nonlocal ${zone} && echo "${zone}"
1848564d
MT
634 done
635}
636
637function zones_get() {
638 local local=1
639 local remote=1
640
641 local zones
642
643 while [ $# -gt 0 ]; do
644 case "${1}" in
645 --local-only)
646 local=1
647 remote=0
648 ;;
649 --remote-only)
650 local=0
651 remote=1
652 ;;
653 --all)
654 local=1
655 remote=1
656 ;;
657 *)
658 if zone_name_is_valid ${1}; then
659 zones="${zones} ${1}"
660 else
661 warning "Unrecognized argument '${1}'"
662 fi
663 ;;
664 esac
665 shift
666 done
667
668 if [ -n "${zones}" ]; then
669 local zone
670 for zone in ${zones}; do
671 zone_exists ${zone} && echo "${zone}"
672 done
673 exit ${EXIT_OK}
674 fi
675
676 if [ ${local} -eq 1 ] && [ ${remote} -eq 1 ]; then
677 zones_get_all
678 elif [ ${local} -eq 1 ]; then
679 zones_get_local
680 elif [ ${remote} -eq 1 ]; then
681 zones_get_nonlocal
682 fi
683}
684
685function zone_ports_list() {
686 local zone=${1}
687
688 local port
a5ebb169 689 for port in $(zone_dir ${zone})/ports/*; do
1848564d
MT
690 [ -e "${port}" ] || continue
691
692 echo $(basename ${port})
03170817 693 done
1848564d
MT
694}
695
696function zone_ports_cmd() {
697 local cmd=${1}
698 local zone=${2}
699 shift 2
700
711ffac1
MT
701 assert isset cmd
702 assert isset zone
1848564d 703
711ffac1 704 assert zone_exists ${zone}
1848564d 705
711ffac1
MT
706 local hook=$(zone_get_hook ${zone})
707
708 local port
709 for port in $(zone_get_ports ${zone}); do
711ffac1 710 hook_zone_exec ${hook} ${cmd} ${zone} ${port} $@
1848564d
MT
711 done
712}
713
714function zone_ports_up() {
711ffac1 715 zone_ports_cmd port_up $@
1848564d
MT
716}
717
718function zone_ports_down() {
711ffac1
MT
719 zone_ports_cmd port_down $@
720}
721
722function zone_ports_status() {
723 zone_ports_cmd port_status $@
1848564d
MT
724}
725
726function zone_configs_list() {
727 local zone=${1}
728
729 local config
a5ebb169 730 for config in $(zone_dir ${zone})/configs/*; do
1848564d
MT
731 [ -e "${config}" ] || continue
732
f41fa3d7 733 basename ${config}
03170817 734 done
1848564d
MT
735}
736
737function zone_configs_cmd() {
738 local cmd=${1}
739 local zone=${2}
740 shift 2
741
742 local hook_zone=$(config_get_hook $(zone_dir ${zone})/settings)
743
744 local hook_config
745 local config
746 for config in $(zone_configs_list ${zone}); do
a5ebb169 747 hook_config=$(config_get_hook $(zone_dir ${zone})/configs/${config})
1848564d 748
d61a01d4 749 hook_zone_config_exec ${hook_zone} ${hook_config} ${cmd} ${zone} ${config} $@
1848564d
MT
750 done
751}
752
753function zone_configs_up() {
754 zone_configs_cmd up $@
755}
756
757function zone_configs_down() {
758 zone_configs_cmd down $@
759}
760
a5ebb169
MT
761function zone_configs_status() {
762 zone_configs_cmd config_status $@
763}
764
38f61548
MT
765function zone_has_ip() {
766 device_has_ip $@
4231f419
MT
767}
768
059469a8
MT
769function zone_db() {
770 local zone=${1}
771 local action=${2}
772 shift 2
773
774 case "${action}" in
775 starting|started|stopping|stopped)
776 db_connection_update ${zone} ${action}
777 ;;
778 esac
779}
5e42d659
MT
780
781function zone_is_up() {
782 local zone=${1}
783
784 device_is_up ${zone}
785}
786
787function zone_is_down() {
788 ! zone_is_up $@
789}
711ffac1 790
a5ebb169 791function zone_get_supported_port_hooks() {
711ffac1
MT
792 local zone=${1}
793
794 local hook=$(zone_get_hook ${zone})
795
796 hook_zone_ports_get_all ${hook}
797}
798
a5ebb169
MT
799function zone_get_supported_config_hooks() {
800 local zone=${1}
801
802 local hook=$(zone_get_hook ${zone})
803
804 hook_zone_configs_get_all ${hook}
805}
806
711ffac1
MT
807function zone_file() {
808 local zone=${1}
809
810 assert isset zone
811
812 echo "$(zone_dir ${zone})/settings"
813}
814
e9df08ad 815function zone_settings_read() {
711ffac1
MT
816 local zone=${1}
817
818 assert isset zone
819
bfd6c282
MT
820 # Save the HOOK variable.
821 local hook="${HOOK}"
822
e9df08ad 823 settings_read $(zone_file ${zone})
bfd6c282
MT
824
825 # Restore hook.
826 HOOK="${hook}"
711ffac1
MT
827}
828
e9df08ad 829function zone_settings_write() {
711ffac1
MT
830 local zone=${1}
831
832 assert isset zone
833
e9df08ad 834 settings_write $(zone_file ${zone}) ${HOOK_SETTINGS}
711ffac1
MT
835}
836
e9df08ad 837function zone_settings_set() {
711ffac1
MT
838 local zone=${1}
839 shift
840 local args="$@"
841
842 assert isset zone
843
844 (
e9df08ad 845 zone_settings_read ${zone}
711ffac1
MT
846
847 for arg in ${args}; do
848 eval "${arg}"
849 done
850
e9df08ad 851 zone_settings_write ${zone}
711ffac1
MT
852 )
853}
6b3f9c85 854
e9df08ad 855function zone_settings_get() {
6b3f9c85
MT
856 local zone=${1}
857 local key=${2}
858
859 assert isset zone
860 assert isset key
861
862 (
e9df08ad 863 zone_settings_read ${zone}
6b3f9c85
MT
864
865 echo "${!key}"
866 )
867}
e9df08ad
MT
868
869function zone_config_settings_read() {
870 assert [ $# -gt 2 ]
871
872 local zone="${1}"
873 local config="${2}"
874 shift 2
875
876 local path="$(zone_dir "${zone}")/configs/${config}"
877 settings_read "${path}" "$@"
878}
879
880function zone_config_settings_write() {
881 assert [ $# -gt 2 ]
882
883 local zone="${1}"
884 local config="${2}"
885 shift 2
886
887 local path="$(zone_dir "${zone}")/configs/${config}"
888 settings_write "${path}" "$@"
889}
890
891function zone_port_settings_read() {
892 assert [ $# -gt 2 ]
893
894 local zone="${1}"
895 local port="${2}"
896 shift 2
897
898 local path="$(zone_dir "${zone}")/ports/${port}"
899 settings_read "${path}" "$@"
900}
901
902function zone_port_settings_write() {
903 assert [ $# -gt 2 ]
904
905 local zone="${1}"
906 local port="${2}"
907 shift 2
908
909 local path="$(zone_dir "${zone}")/ports/${port}"
910 settings_write "${path}" "$@"
911}
912
913function zone_port_settings_remove() {
914 assert [ $# -eq 2 ]
915
916 local zone="${1}"
917 local port="${2}"
918
919 local path="$(zone_dir "${zone}")/ports/${port}"
920 settings_remove "${path}"
921}