Skip to content

Commit 27019c4

Browse files
committed
create,clone: add -S option to specify a different network stack
network: add _get_pot_network_stack, to allow per-pot stack option network: netowrw_stack is now a parameter start: adopt the per-pot stack option network-stack: option wider adoption zsh: adjust autocompletion test: network1 fixed and extended tests: fix tests
1 parent 7c93219 commit 27019c4

File tree

11 files changed

+357
-151
lines changed

11 files changed

+357
-151
lines changed

share/pot/clone.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ clone-help()
1212
echo ' -N network-type : new network type of the cloned pot'
1313
echo ' -i ipaddr : an ip address or the keyword auto (if applicable)'
1414
echo ' -B bridge-name : the name of the bridge to be used (private-bridge only)'
15+
echo ' -S network-stack : the network stack (ipv4, ipv6 or dual)'
1516
echo ' -F : automatically take snapshots of dataset that has no one'
1617
}
1718

@@ -155,15 +156,17 @@ _cj_zfs()
155156
# $3 network type
156157
# $4 ip
157158
# $5 bridge name
159+
# $6 network stack
158160
_cj_conf()
159161
{
160162
# shellcheck disable=SC2039
161-
local _pname _potbase _ptype _ip _network_type _bridge_name
163+
local _pname _potbase _ptype _ip _network_type _bridge_name _stack
162164
_pname=$1
163165
_potbase=$2
164166
_network_type=$3
165167
_ip=$4
166168
_bridge_name=$5
169+
_stack=$6
167170
_pdir=${POT_FS_ROOT}/jails/$_pname
168171
_pbdir=${POT_FS_ROOT}/jails/$_potbase
169172
if [ ! -d "$_pdir/conf" ]; then
@@ -172,6 +175,7 @@ _cj_conf()
172175
grep -v ^host.hostname "$_pbdir/conf/pot.conf" | \
173176
grep -v ^ip | grep -v ^vnet | grep -v ^network_type > "$_pdir/conf/pot.conf"
174177
echo "host.hostname=\"${_pname}.$( hostname )\"" >> "$_pdir/conf/pot.conf"
178+
echo "pot.stack=$_stack" >> "$_pdir/conf/pot.conf"
175179
echo "network_type=$_network_type" >> "$_pdir/conf/pot.conf"
176180
case "$_network_type" in
177181
"inherit")
@@ -218,15 +222,16 @@ _cj_conf()
218222
# shellcheck disable=SC2039
219223
pot-clone()
220224
{
221-
local _pname _ipaddr _potbase _pblvl _autosnap _pb_type _pb_network_type _network_type _bridge_name
225+
local _pname _ipaddr _potbase _pblvl _autosnap _pb_type _pb_network_type _network_type _bridge_name _network_stack
222226
_pname=
223227
_ipaddr=
224228
_potbase=
225229
_pblvl=0
226230
_autosnap="NO"
227231
_bridge_name=
232+
_network_stack=
228233
OPTIND=1
229-
while getopts "hvp:i:P:FN:B:" _o ; do
234+
while getopts "hvp:i:P:FN:B:S:" _o ; do
230235
case "$_o" in
231236
h)
232237
clone-help
@@ -259,6 +264,14 @@ pot-clone()
259264
B)
260265
_bridge_name=$OPTARG
261266
;;
267+
S)
268+
if ! is_in_list "$OPTARG" "ipv4" "ipv6" "dual" ; then
269+
_error "Network stack $OPTARG not valid"
270+
create-help
271+
${EXIT} 1
272+
fi
273+
_network_stack="$OPTARG"
274+
;;
262275
F)
263276
_autosnap="YES"
264277
;;
@@ -298,7 +311,10 @@ pot-clone()
298311
fi
299312
_network_type="$_pb_network_type"
300313
fi
301-
if ! _ipaddr="$( _validate_network_param "$_network_type" "$_ipaddr" "$_bridge_name" )" ; then
314+
if [ -z "$_network_stack" ]; then
315+
_network_stack="$( _get_pot_network_stack "$_potbase" )"
316+
fi
317+
if ! _ipaddr="$( _validate_network_param "$_network_type" "$_ipaddr" "$_bridge_name" "$_network_stack" )" ; then
302318
echo "$_ipaddr"
303319
clone-help
304320
${EXIT} 1
@@ -316,7 +332,7 @@ pot-clone()
316332
if ! _cj_zfs "$_pname" "$_potbase" $_autosnap ; then
317333
${EXIT} 1
318334
fi
319-
if ! _cj_conf "$_pname" "$_potbase" "$_network_type" "$_ipaddr" "$_bridge_name" ; then
335+
if ! _cj_conf "$_pname" "$_potbase" "$_network_type" "$_ipaddr" "$_bridge_name" "$_network_stack" ; then
320336
${EXIT} 1
321337
fi
322338
}

share/pot/create.sh

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ create-help()
3030
echo ' auto: usable with public-bridge and private-bridge (default)'
3131
echo ' ipaddr: mandatory with alias, usable with public-bridge and private-bridge'
3232
echo ' -B bridge-name : the name of the bridge to be used (private-bridge only)'
33+
echo ' -S network-stack : the network stack (ipv4, ipv6 or dual)'
3334
}
3435

3536
_cj_undo_create()
@@ -221,12 +222,13 @@ _cj_zfs()
221222
# $7 type
222223
# $8 private bridge (if network tpye is private_bridge"
223224
# $9 pot-base name
225+
# $10 network-stack
224226
_cj_conf()
225227
{
226228
# shellcheck disable=SC2039
227229
local _pname _base _ip _network_type _lvl _jdir _bdir _potbase _dns _type _pblvl _pbpb
228230
# shellcheck disable=SC2039
229-
local _jdset _bdset _pbdset _baseos _bridge_name
231+
local _jdset _bdset _pbdset _baseos _bridge_name _stack
230232
_pname=$1
231233
_base=$2
232234
_network_type=$3
@@ -236,6 +238,8 @@ _cj_conf()
236238
_type=$7
237239
_bridge_name=$8
238240
_potbase=$9
241+
_stack=${10}
242+
239243
_jdir=${POT_FS_ROOT}/jails/$_pname
240244
_bdir=${POT_FS_ROOT}/bases/$_base
241245

@@ -301,6 +305,7 @@ _cj_conf()
301305
echo "pot.attr.start-at-boot=NO"
302306
echo "pot.attr.procfs=NO"
303307
echo "pot.attr.prunable=NO"
308+
echo "pot.stack=$_stack"
304309
echo "network_type=$_network_type"
305310
case $_network_type in
306311
"inherit")
@@ -347,6 +352,7 @@ _cj_conf()
347352
# $4 ip
348353
_cj_internal_conf()
349354
{
355+
# shellcheck disable=SC2039
350356
local _pname _type _lvl _ip _jdir
351357
_pname=$1
352358
_type=$2
@@ -489,7 +495,7 @@ _cj_single_install()
489495
pot-create()
490496
{
491497
# shellcheck disable=SC2039
492-
local _pname _ipaddr _lvl _base _flv _potbase _dns _type _new_lvl _network_type _private_bridge
498+
local _pname _ipaddr _lvl _base _flv _potbase _dns _type _new_lvl _network_type _private_bridge _network_stack
493499
OPTIND=1
494500
_type="multi"
495501
_network_type="inherit"
@@ -502,8 +508,9 @@ pot-create()
502508
_potbase=
503509
_dns=inherit
504510
_private_bridge=
511+
_network_stack="$( _get_network_stack )"
505512
_cleanup_keep="NO"
506-
while getopts "hvp:t:N:i:l:b:f:P:d:B:k" _o ; do
513+
while getopts "hvp:t:N:i:l:b:f:P:d:B:S:k" _o ; do
507514
case "$_o" in
508515
h)
509516
create-help
@@ -538,6 +545,14 @@ pot-create()
538545
B)
539546
_private_bridge="$OPTARG"
540547
;;
548+
S)
549+
if ! _is_in_list "$OPTARG" "ipv4" "ipv6" "dual" ; then
550+
_error "Network stack $OPTARG not valid"
551+
create-help
552+
${EXIT} 1
553+
fi
554+
_network_stack="$OPTARG"
555+
;;
541556
i)
542557
if [ -z "$_ipaddr" ]; then
543558
_ipaddr="$OPTARG"
@@ -745,7 +760,7 @@ pot-create()
745760
if ! _is_uid0 ; then
746761
${EXIT} 1
747762
fi
748-
if ! _ipaddr="$( _validate_network_param "$_network_type" "$_ipaddr" "$_private_bridge" )" ; then
763+
if ! _ipaddr="$( _validate_network_param "$_network_type" "$_ipaddr" "$_private_bridge" "$_network_stack" )" ; then
749764
echo "$_ipaddr"
750765
${EXIT} 1
751766
fi
@@ -760,22 +775,23 @@ pot-create()
760775
fi
761776
fi
762777
_info "Creating a new pot"
763-
_info "pot name : $_pname"
764-
_info "type : $_type"
765-
_info "base : $_base"
766-
_info "pot_base : $_potbase"
767-
_info "level : $_lvl"
768-
_info "network-type: $_network_type"
769-
_info "ip : $_ipaddr"
770-
_info "bridge : $_private_bridge"
771-
_info "dns : $_dns"
772-
_info "flavours : $_flv"
778+
_info "pot name : $_pname"
779+
_info "type : $_type"
780+
_info "base : $_base"
781+
_info "pot_base : $_potbase"
782+
_info "level : $_lvl"
783+
_info "network-type : $_network_type"
784+
_info "network-stack: $_network_stack"
785+
_info "ip : $_ipaddr"
786+
_info "bridge : $_private_bridge"
787+
_info "dns : $_dns"
788+
_info "flavours : $_flv"
773789
export _cleanup_pname="$_pname" # for the cleanup function
774790
export _cleanup_keep
775791
if ! _cj_zfs "$_pname" "$_type" "$_lvl" "$_base" "$_potbase" ; then
776792
${EXIT} 1
777793
fi
778-
if ! _cj_conf "$_pname" "$_base" "$_network_type" "$_ipaddr" "$_lvl" "$_dns" "$_type" "$_private_bridge" "$_potbase" ; then
794+
if ! _cj_conf "$_pname" "$_base" "$_network_type" "$_ipaddr" "$_lvl" "$_dns" "$_type" "$_private_bridge" "$_potbase" "$_network_stack" ; then
779795
${EXIT} 1
780796
fi
781797
if [ "$_type" = "single" ]; then

share/pot/export-ports.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pot-export-ports()
8686
[ "$(_get_pot_network_type "$_pname")" != "private-bridge" ] ; then
8787
_info "Only public-bridge and private-bridge network type can export ports - this setting will be ignored during start"
8888
fi
89-
if [ "$( _get_network_stack )" = "ipv6" ]; then
89+
if [ "$( _get_pot_network_stack "$_pname" )" = "ipv6" ]; then
9090
_info "Only ipv4 can export ports, on ipv6 the pot has already a unique address - this setting will be ignored during start"
9191
fi
9292
_debug "Exporting the following ports: $_ports"

share/pot/info.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,14 @@ info-help()
1717
_info_pot_env()
1818
{
1919
# shellcheck disable=SC2039
20-
local _pname _ips _idx
20+
local _pname _ips _idx _all_ips
2121
_pname=$1
2222
echo "export _POT_NAME=$_pname"
2323
if [ "$( _get_pot_network_type "$_pname" )" != "alias" ]; then
2424
echo "export _POT_IP=$( _get_ip_var "$_pname" )"
2525
else
26-
_ips=""
27-
if [ "$( _get_network_stack )" != "ipv6" ]; then
28-
_ips="$( _get_alias_ipv4 "$_pname" )"
29-
fi
30-
if [ "$( _get_network_stack )" != "ipv4" ]; then
31-
_ips="$_ips $( _get_alias_ipv6 "$_pname" )"
32-
fi
26+
_all_ips="$( _get_ip_var "$_pname" ) "
27+
_ips="$( _get_alias_ipv4 "$_pname" "$_all_ips" ) $( _get_alias_ipv6 "$_pname" "$_all_ips" )"
3328
_idx=0
3429
_ipvar_list=""
3530
_nicvar_list=""

0 commit comments

Comments
 (0)