Skip to content

Commit 169857f

Browse files
author
olevole
committed
CARP fixes: WIP
1 parent 35b8644 commit 169857f

File tree

6 files changed

+87
-26
lines changed

6 files changed

+87
-26
lines changed

jailctl/jls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ populate_output_data()
178178
if [ "${_val}" = "\-" ]; then
179179
_val="0"
180180
else
181-
_val=$( is_special_ip ${_val} )
181+
true
182+
#_val=$( is_special_ip "${_val}" )
182183
fi
183184
;;
184185
real_ip4)

jailctl/jset

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ validate_ipaddr()
8282
{
8383
[ -z "${ip4_addr}" ] && return 1
8484

85+
# load ip4_addr of all jails
86+
_i=0
87+
OIFS="${IFS}"
88+
IFS="|"
89+
eval $( cbsdsqlro local "SELECT jname,ip4_addr FROM jails WHERE ip4_addr!='0'" 2>/dev/null | while read _jname _ips; do
90+
IFS="${OIFS}"
91+
echo jname${_i}=\"$_jname\"
92+
echo ips${_i}=\"${_ips}\"
93+
_i=$(( _i + 1 ))
94+
IFS="|"
95+
done )
96+
IFS="${OIFS}"
97+
8598
# Yes, we wrote in the example that the valid separator between NIC and address
8699
# is '#' and not '|' as experienced jail.conf users can get used to.
87100
# But we will still try to convert the input with '|' to correct form
@@ -90,33 +103,37 @@ validate_ipaddr()
90103
[ ${_pos} -ne 0 ] && ip4_addr=$( echo ${ip4_addr} | ${TR_CMD} '|' '#' )
91104

92105
. ${subrdir}/vnet.subr # for is_nic_exist
106+
OIFS="${IFS}"
107+
IFS=","
93108
for _i in ${ip4_addr}; do
109+
IFS="${OIFS}"
94110
ipwmask ${_i}
95111
[ -z "${IWM}" -o "${_i}" = "0" ] && continue
96112

97-
iptype ${IWM}
98-
if [ $? -ne 0 ]; then
99-
if [ -n "${V_INTERFACE}" -a -n "${V_IP}" ]; then
100-
if ! is_nic_exist -n ${V_INTERFACE}; then
101-
log_err 1 "${N1_COLOR}jset for ${jname} error: interface not exist: ${N2_COLOR}${V_INTERFACE}${N0_COLOR}"
113+
special_ips=$( is_special_ip ${_i} )
114+
is_special=$?
115+
116+
if [ ${is_special} -eq 0 ]; then
117+
iptype ${IWM}
118+
if [ $? -ne 0 ]; then
119+
if [ -n "${V_INTERFACE}" -a -n "${V_IP}" ]; then
120+
if ! is_nic_exist -n ${V_INTERFACE}; then
121+
log_err 1 "${N1_COLOR}jset for ${jname} error: interface not exist: ${N2_COLOR}${V_INTERFACE}${N0_COLOR}"
122+
fi
123+
_myip="${_myip} ${V_IP}"
124+
else
125+
_myip="${_myip} ${IWM}"
102126
fi
103-
_myip="${_myip} ${V_IP}"
104-
else
105-
_myip="${_myip} ${IWM}"
106127
fi
128+
else
129+
#echo "SPECIAL"
130+
true
107131
fi
132+
IFS=","
108133
done
134+
IFS="${OIFS}"
109135

110-
# check for other jail
111-
IFS="|"
112-
_i=0
113-
eval $( cbsdsqlro local SELECT jname,ip4_addr FROM jails WHERE ip4_addr!="0" 2>/dev/null | while read _jname _ips; do
114-
echo jname${_i}=\"$_jname\"
115-
echo ips${_i}=\"${_ips}\"
116-
_i=$(( _i + 1 ))
117-
done )
118-
unset IFS
119-
136+
# check for other jails
120137
for _i in $( ${SEQ_CMD} 0 255 ); do
121138
_ok=1
122139
unset _existing_ipjail _existing_ip
@@ -164,7 +181,7 @@ modify_ipaddr()
164181
local _A _ip4_addr_old _pureip _inet _face _interface _IP4 _IP6 _MODIF _nIPs IFS _dhcp
165182
local _is_freebsd _elftest
166183

167-
_A=$( cbsdsqlro local "SELECT interface,ip4_addr,applytpl,vnet,baserw,data,host_hostname FROM jails WHERE jname=\"${jname}\"" )
184+
_A=$( cbsdsqlro local "SELECT interface,ip4_addr,applytpl,vnet,baserw,data,host_hostname FROM jails WHERE jname='${jname}'" )
168185
sqllist "${_A}" _interface _ip4_addr_old applytpl vnet baserw data host_hostname
169186

170187
_is_freebsd=1
@@ -378,7 +395,7 @@ modify_ipaddr()
378395
${JAIL_CMD} -m ${_nIPs} jid=${jid}
379396
fi
380397

381-
cbsdsqlrw local UPDATE jails SET ${i}=\"${ip4_addr}\" WHERE jname=\"${jname}\"
398+
cbsdsqlrw local "UPDATE jails SET ${i}='${ip4_addr}' WHERE jname='${jname}'"
382399
${ECHO} "${argpart}: ${N1_COLOR}${ip4_addr}${N0_COLOR}"
383400

384401
if [ "${mod_cbsd_queue_enabled}" = "YES" -a -z "${MOD_CBSD_QUEUE_DISABLED}" ]; then

subr/carp.subr

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,24 @@ get_construct_carp_vhid()
203203
return 0
204204
}
205205

206+
get_construct_carp_peer()
207+
{
208+
title=" IPv4 peer "
209+
prompt=" Enter valid IPv4 "
210+
defaultitem="${carp_peer}"
211+
cbsd_inputbox_simple && carp_peer="${mtag}"
212+
return 0
213+
}
214+
215+
get_construct_carp_peer6()
216+
{
217+
title=" IPv6 peer "
218+
prompt=" Enter valid IPv6 "
219+
defaultitem="${carp_peer6}"
220+
cbsd_inputbox_simple && carp_peer6="${mtag}"
221+
return 0
222+
}
223+
206224
get_construct_carp_advskew()
207225
{
208226
title=" advskew "

sudoexec/jcreate

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ The jail is created according to configuration file generated by jconstruct-tui.
2020
You can see this configuration file if you answer negatively to the
2121
'Do you want to create jail immediately?' question at the end of the dialogue.
2222

23+
To use CARP without VNET with jail ( in 'vhid_X#<IP_ADDR> form' for ip4_addr= ), please
24+
use 'cbsd vhidcfg-tui' first.
25+
2326
If the 'buildah' package is installed on the system, you can use the OCI images
2427
(including Linux) from the official docker registry - see the examples section
2528
with the [*] marker.
@@ -120,6 +123,8 @@ ${H3_COLOR}See also${N0_COLOR}:
120123
cbsd images --help
121124
cbsd jset --help
122125
cbsd makeresolv --help
126+
cbsd vhidcfg --help
127+
cbsd vhidcfg-tui --help
123128

124129
"
125130
CBSDMODULE="jail"

tools/vhidcfg-tui

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dialog_menu_main()
2121

2222
local mark
2323

24-
local menu_list=$( cbsdsqlro local SELECT id,vhid,advskew,pass,peer,peer6,interface,state FROM carp | while read id carp_vhid carp_advskew carp_pass carp_peer carp_peer6 interface carp_state; do
24+
local menu_list=$( cbsdsqlro local "SELECT id,vhid,advskew,pass,peer,peer6,interface,state FROM carp" | while read id carp_vhid carp_advskew carp_pass carp_peer carp_peer6 interface carp_state; do
2525
eval mark=\$vhid_selected_${id}
2626
if [ "${mark}" = "1" ]; then
2727
mark="X"
@@ -104,11 +104,11 @@ vhid_add()
104104

105105
menu_list="
106106
'vhid' '${carp_vhid}' 'vhid, must be integer, e.g.: 1'
107-
'advskew' '${carp_advskew}' 'advertisement skew, 1-240, e.g: 100'
107+
'advskew' '${carp_advskew}' 'advertisement skew, 1-240, e.g: 100'
108108
'pass' '${carp_pass}' 'password for vhid group'
109-
'peer' '${carp_peer}' 'peer ip address or default: 224.0.0.18'
110-
'peer6' '${carp_peer6}' 'peer ip6 address or default: ff02::12'
111-
'interface' '${interface}' 'configured for interface, e.g: auto (uplink)'
109+
'peer' '${carp_peer}' 'Unicast peer IPv4 address (or use 224.0.0.18 for Multicast'
110+
'peer6' '${carp_peer6}' 'Unicast peer IPv6 address (or use ff02::12 for Multicast'
111+
'interface' '${interface}' 'configured for interface, e.g: auto (uplink)'
112112
'state' '${carp_state}' 'default state on boot: master or backup'
113113
"
114114

upgrade/pre-patch-14.2.4.1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
#v13.2.4
3+
# Update carp tables for peer,peer6
4+
: ${distdir="/usr/local/cbsd"}
5+
[ ! -r "${distdir}/subr/cbsdbootstrap.subr" ] && exit 1
6+
. ${distdir}/subr/cbsdbootstrap.subr || exit 1
7+
test_sql_stuff
8+
9+
mydb="${dbdir}/local.sqlite"
10+
11+
[ ! -h "${mydb}" ] && exit
12+
13+
unset _test
14+
_test=$( ${miscdir}/sqlcli ${mydb} "SELECT COUNT(peer6) FROM carp LIMIT 1" 2>/dev/null )
15+
[ -n "${_test}" ] && exit 0
16+
${ECHO} " * ${N1_COLOR}Update carp tables: ${N2_COLOR}peer,peer6${N0_COLOR}"
17+
${miscdir}/sqlcli ${mydb} "ALTER TABLE carp ADD COLUMN peer TEXT DEFAULT '224.0.0.18'"
18+
${miscdir}/sqlcli ${mydb} "ALTER TABLE carp ADD COLUMN peer6 TEXT DEFAULT 'ff02::12'"
19+
20+
exit 0

0 commit comments

Comments
 (0)