From 1f6e0725f43d9c065bf9b83db5a29db1ea681537 Mon Sep 17 00:00:00 2001 From: tschettervictor Date: Thu, 2 Oct 2025 17:43:40 -0600 Subject: [PATCH] epair-name: final revision --- usr/local/share/bastille/clone.sh | 18 +++++------------ usr/local/share/bastille/common.sh | 2 +- usr/local/share/bastille/create.sh | 2 -- usr/local/share/bastille/network.sh | 31 +++++++++++++++-------------- 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/usr/local/share/bastille/clone.sh b/usr/local/share/bastille/clone.sh index 273882e0..b7a4cf8e 100644 --- a/usr/local/share/bastille/clone.sh +++ b/usr/local/share/bastille/clone.sh @@ -263,8 +263,8 @@ update_jailconf_vnet() { while echo "${BASTILLE_EPAIR_LIST}" | grep -oq "bastille${epair_num}"; do epair_num=$((epair_num + 1)) done - local host_epair="e0a_bastille${epair_num}" - local jail_epair="e0b_bastille${epair_num}" + local _new_host_epair="e0a_bastille${epair_num}" + local _new_jail_epair="e0b_bastille${epair_num}" fi local _new_if_prefix="$(echo ${_new_host_epair} | awk -F'_' '{print $1}')" @@ -375,16 +375,8 @@ update_jailconf_vnet() { local _ngif_num="$(echo "${_old_if_prefix}" | grep -Eo "[0-9]+")" local _old_ngif="${_if}" - - if [ "$(echo -n "ng${_ngif_num}_${NEWNAME}" | awk '{print length}')" -lt 16 ]; then - # Generate new netgraph interface name - local _new_ngif="ng${_ngif_num}_${NEWNAME}" - else - name_prefix="$(echo ${NEWNAME} | cut -c1-7)" - name_suffix="$(echo ${NEWNAME} | rev | cut -c1-2 | rev)" - local _new_ngif="ng${_ngif_num}_${name_prefix}xx${name_suffix}" - fi - + # Generate new netgraph interface name + local _new_ngif="ng${_ngif_num}_${NEWNAME}" local _new_if_prefix="$(echo ${_if} | awk -F'_' '{print $1}')" local _new_if_suffix="$(echo ${_if} | awk -F'_' '{print $2}')" @@ -560,4 +552,4 @@ info "\nAttempting to clone '${TARGET}' to '${NEWNAME}'..." clone_validate_jail_name -clone_jail +clone_jail \ No newline at end of file diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index ef9933e3..b4388465 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -124,7 +124,7 @@ check_target_is_stopped() { get_bastille_epair_count() { for _config in /usr/local/etc/bastille/*.conf; do local bastille_jailsdir="$(sysrc -f "${_config}" -n bastille_jailsdir)" - BASTILLE_EPAIR_LIST="$(printf '%s\n%s' "$( (grep -Ehos '(epair[0-9]+|bastille[0-9]+)' ${bastille_jailsdir}/*/jail.conf; ifconfig -g epair | grep -Eos "_bastille[0-9]+$"; ifconfig -g epair | grep -vs 'bastille' | grep -Eos 'e[0-9]+a_') | grep -Eos '[0-9]+')" "${_epair_list}")" + BASTILLE_EPAIR_LIST="$(printf '%s\n%s' "$( (grep -Ehos "bastille[0-9]+" ${bastille_jailsdir}/*/jail.conf; ifconfig -g epair | grep -Eos "e[0-9]+a_bastille[0-9]+$" | grep -Eos 'bastille[0-9]+') | sort -u)" "${_epair_list}")" done BASTILLE_EPAIR_COUNT=$(printf '%s' "${BASTILLE_EPAIR_LIST}" | sort -u | wc -l | awk '{print $1}') export BASTILLE_EPAIR_LIST diff --git a/usr/local/share/bastille/create.sh b/usr/local/share/bastille/create.sh index 88a87eb8..3cfe0ec4 100644 --- a/usr/local/share/bastille/create.sh +++ b/usr/local/share/bastille/create.sh @@ -1173,5 +1173,3 @@ if check_target_exists "${NAME}"; then fi create_jail "${NAME}" "${RELEASE}" "${IP}" "${INTERFACE}" - -echo diff --git a/usr/local/share/bastille/network.sh b/usr/local/share/bastille/network.sh index c0d9ba87..b2dcd06a 100644 --- a/usr/local/share/bastille/network.sh +++ b/usr/local/share/bastille/network.sh @@ -247,7 +247,7 @@ add_interface() { if [ "${bastille_network_vnet_type}" = "if_bridge" ]; then local _if_list="$(grep -Eo 'e[0-9]+a_[^;" ]+' ${_jail_config} | sort -u)" local _epair_count="$(echo "${_if_list}" | grep -Eo "[0-9]+" | wc -l)" - local _epair_num_range=$((_epair_count + 1)) + local _epair_num_range=$((_epair_count + 1)) elif [ "${bastille_network_vnet_type}" = "netgraph" ]; then local _if_list="$(grep -Eo 'ng[0-9]+_[^;" ]+' ${_jail_config} | sort -u)" local _ngif_count="$(echo "${_if_list}" | grep -Eo "[0-9]+" | wc -l)" @@ -261,10 +261,13 @@ add_interface() { local host_epair=e${_epair_num}a_${_jailname} local jail_epair=e${_epair_num}b_${_jailname} else - name_prefix="$(echo ${_jailname} | cut -c1-7)" - name_suffix="$(echo ${_jailname} | rev | cut -c1-2 | rev)" - local host_epair="e${_epair_num}a_${name_prefix}xx${name_suffix}" - local jail_epair="e${_epair_num}b_${name_prefix}xx${name_suffix}" + get_bastille_epair_count + local global_epair_num=1 + while echo "${BASTILLE_EPAIR_LIST}" | grep -oq "bastille${global_epair_num}"; do + global_epair_num=$((global_epair_num + 1)) + done + local host_epair="e0a_bastille${global_epair_num}" + local jail_epair="e0b_bastille${global_epair_num}" fi # Remove ending brace (it is added again with the netblock) sed -i '' '/^}$/d' "${_jail_config}" @@ -326,11 +329,14 @@ EOF local jail_epair=e${_epair_num}b_${_jailname} local jib_epair=${_jailname} else - name_prefix="$(echo ${_jailname} | cut -c1-7)" - name_suffix="$(echo ${_jailname} | rev | cut -c1-2 | rev)" - local host_epair="e${_epair_num}a_${name_prefix}xx${name_suffix}" - local jail_epair="e${_epair_num}b_${name_prefix}xx${name_suffix}" - local jib_epair="${name_prefix}xx${name_suffix}" + get_bastille_epair_count + local global_epair_num=1 + while echo "${BASTILLE_EPAIR_LIST}" | grep -oq "bastille${global_epair_num}"; do + global_epair_num=$((global_epair_num + 1)) + done + local host_epair="e0a_bastille${global_epair_num}" + local jail_epair="e0b_bastille${global_epair_num}" + local jib_epair="bastille${global_epair_num}" fi # Remove ending brace (it is added again with the netblock) sed -i '' '/^}$/d' "${_jail_config}" @@ -387,11 +393,6 @@ EOF # Generate new netgraph interface name local _ngif="ng${_ngif_num}_${_jailname}" local jng_if="${_jailname}" - else - name_prefix="$(echo ${_jailname} | cut -c1-7)" - name_suffix="$(echo ${_jailname} | rev | cut -c1-2 | rev)" - local _ngif="ng${_ngif_num}_${name_prefix}xx${name_suffix}" - local jng_if="${name_prefix}xx${name_suffix}" fi # Remove ending brace (it is added again with the netblock) sed -i '' '/^}$/d' "${_jail_config}"