diff --git a/Makefile b/Makefile index b56c289ff..ae7b5f47b 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ clean: ${RM} -f tools/imghelper ${RM} -f tools/xo ${RM} -f tools/vale-ctl + ${RM} -f tools/nic_info ${RM} -f tools/bridge cbsd: @@ -58,6 +59,7 @@ cbsd: ${CC} tools/src/imghelper.c -o tools/imghelper && ${STRIP} tools/imghelper ${CC} tools/src/bridge.c -o tools/bridge && ${STRIP} tools/bridge ${CC} tools/src/vale-ctl.c -o tools/vale-ctl && ${STRIP} tools/vale-ctl + ${CC} tools/src/nic_info.c -o tools/nic_info && ${STRIP} tools/nic_info ${MAKE} -C bin/cbsdsh && ${STRIP} bin/cbsdsh/cbsd ${MAKE} -C share/bsdconfig/cbsd diff --git a/bhyve.subr b/bhyve.subr index 6d5e3b9ec..a1d761446 100644 --- a/bhyve.subr +++ b/bhyve.subr @@ -207,10 +207,12 @@ compile_nic_args() local sqldelimer=" " local mybridge local net_emul= + local _parent_mtu + local _ret= local errmsg= - eval $( cbsdsql ${jailsysdir}/${jname}/local.sqlite SELECT id,nic_order,nic_driver,nic_slot,nic_type,nic_parent,nic_hwaddr,nic_address FROM bhyvenic WHERE jname=\"${jname}\" |while read nic_id nic_order nic_driver nic_slot nic_type nic_parent nic_hwaddr nic_address; do + eval $( cbsdsql ${jailsysdir}/${jname}/local.sqlite SELECT id,nic_order,nic_driver,nic_slot,nic_type,nic_parent,nic_hwaddr,nic_address,nic_mtu FROM bhyvenic WHERE jname=\"${jname}\" |while read nic_id nic_order nic_driver nic_slot nic_type nic_parent nic_hwaddr nic_address nic_mtu; do if ! next_pci_id; then # no free pci bus @@ -305,6 +307,26 @@ compile_nic_args() echo "export nic${_id}=\"-s ${pcislot}:0,${net_emul},${mytap}\" ;" fi + # MTU management + [ -z "${nic_mtu}" ] && nic_mtu="0" # AUTO + if [ ${nic_mtu} -eq 0 ]; then + # Get parent MTU size + _parent_mtu=$( ${toolsdir}/nic_info --nic=${mybridge} --quiet 2>/dev/null ) + _ret=$? + if [ ${_ret} -eq 0 ]; then + [ -n "${_parent_mtu}" ] && _ret=$( /sbin/ifconfig ${mytap} mtu ${_parent_mtu} ) + fi + else + # Get parent MTU size + # compare MTU with parent + #_parent_mtu=$( ${toolsdir}/nic_info --nic=${mybridge} --quiet 2>/dev/null ) + #_ret=$? + #if [ ${_ret} -eq 0 ]; then + # [ ${nic_mtu} -gt ${_parent_mtu} ] + #fi + _ret=$( /sbin/ifconfig ${mytap} mtu ${nic_mtu} ) + fi + echo "export mytap${_id}=\"${mytap}\";" _id=$(( _id + 1 )) @@ -356,7 +378,7 @@ compile_lpc_args() # export arguments for bhyve pci_passthru_args compile_pci_passthru_args() { - local ppt + local ppt _i ppt=$( cbsdsql local SELECT ppt FROM bhyveppt WHERE jname=\"${jname}\" 2>/dev/null ) @@ -375,11 +397,15 @@ compile_pci_passthru_args() pci_passthru_args="${pci_passthru_args} -s ${bhyve_pci_index},passthru,${_i}" done - pci_passthru_args="${pci_passthru_args} -S" + pci_passthru_args="${pci_passthru_args}" - local _dmar_test=$( /usr/sbin/acpidump -t | /usr/bin/grep DMAR ) - [ -z "${_dmar_test}" ] && err 1 "${MAGENTA}I/O MMU / VT-d not enabled. Check you hardware or BIOS setting${NORMAL}" + . ${workdir}/virtual.subr + if check_dmar; then + err 1 "${MAGENTA}I/O MMU / VT-d not enabled. Check you hardware or BIOS setting${NORMAL}" + fi + + return 0 } diff --git a/bin/cbsdsh/about.h b/bin/cbsdsh/about.h index 874d1827b..59ae1ae9d 100644 --- a/bin/cbsdsh/about.h +++ b/bin/cbsdsh/about.h @@ -1 +1 @@ -#define VERSION "11.1.5" +#define VERSION "11.1.6" diff --git a/bsdconfig.subr b/bsdconfig.subr index d071df4d9..aa6494064 100644 --- a/bsdconfig.subr +++ b/bsdconfig.subr @@ -7,4 +7,3 @@ BSDCFG_LIBE="/usr/local/libexec/bsdconfig" APP_DIR="cbsd" ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" - diff --git a/cbsd.conf b/cbsd.conf index ae540d115..07f780dc7 100644 --- a/cbsd.conf +++ b/cbsd.conf @@ -3,7 +3,7 @@ unset oarch over ostable arch target_arch ver stable # defines product="CBSD" -myversion="11.1.5" +myversion="11.1.6" if [ -z "${workdir}" ]; then echo "no workdir" diff --git a/cbsd.lua b/cbsd.lua index 657693ae5..1b19fb43e 100644 --- a/cbsd.lua +++ b/cbsd.lua @@ -1,5 +1,5 @@ product="CBSD" -myversion="11.1.5" +myversion="11.1.6" if not workdir then print ( "no workdir" ) diff --git a/etc/defaults/vm-freebsd-BSDRP-x64-1.70.conf b/etc/defaults/vm-freebsd-BSDRP-x64-1.70.conf deleted file mode 100644 index 1946479d4..000000000 --- a/etc/defaults/vm-freebsd-BSDRP-x64-1.70.conf +++ /dev/null @@ -1,31 +0,0 @@ -# don't remove this line: -vm_profile="BSDRP-x64-1.70" -vm_os_type="freebsd" -# this is one-string additional info strings in dialogue menu -long_description="Embedded free and open source router distribution" - -# custom settings: -fetch=1 - -iso_site="https://netcologne.dl.sourceforge.net/project/bsdrp/BSD_Router_Project/1.70/amd64/ http://garr.dl.sourceforge.net/project/bsdrp/BSD_Router_Project/1.70/amd64/ http://cznic.dl.sourceforge.net/project/bsdrp/BSD_Router_Project/1.70/amd64/" - -iso_img="BSDRP-1.70-full-amd64-vga.img" -iso_img_dist="BSDRP-1.70-full-amd64-vga.img.xz" - -# register_iso as: -register_iso_name="cbsd-iso-${iso_img}" -register_iso_as="iso-BSDRP-x64-1.70" - -iso_extract="/usr/bin/xz -d " - -default_jailname="bsdrp" -vm_package="small1" - -active=0 - -# VNC -vm_vnc_port="0" -vm_efi="uefi" - -# VirtualBox Area -virtualbox_ostype="FreeBSD_64" diff --git a/etc/defaults/vm-freebsd-BSDRP-x64-1.80.conf b/etc/defaults/vm-freebsd-BSDRP-x64-1.80.conf new file mode 100644 index 000000000..524c7b94b --- /dev/null +++ b/etc/defaults/vm-freebsd-BSDRP-x64-1.80.conf @@ -0,0 +1,41 @@ +# don't remove this line: +vm_profile="BSDRP-x64-1.80" +vm_os_type="freebsd" +# this is one-string additional info strings in dialogue menu +long_description="Embedded free and open source router distribution" + +# custom settings: +fetch=1 + +iso_site="https://vorboss.dl.sourceforge.net/project/bsdrp/BSD_Router_Project/1.80/amd64/ \ +https://10gbps-io.dl.sourceforge.net/project/bsdrp/BSD_Router_Project/1.80/amd64/ \ +https://freefr.dl.sourceforge.net/project/bsdrp/BSD_Router_Project/1.80/amd64/ \ +https://gigenet.dl.sourceforge.net/project/bsdrp/BSD_Router_Project/1.80/amd64/ \ +https://netix.dl.sourceforge.net/project/bsdrp/BSD_Router_Project/1.80/amd64/ \ +https://ncu.dl.sourceforge.net/project/bsdrp/BSD_Router_Project/1.80/amd64/ \ +" + +iso_img="BSDRP-1.80-full-amd64-vga.img" +iso_img_dist="BSDRP-1.80-full-amd64-vga.img.xz" + +# register_iso as: +register_iso_name="cbsd-iso-${iso_img}" +register_iso_as="iso-BSDRP-x64-1.80" + +iso_extract="/usr/bin/xz -d " + +default_jailname="bsdrp" +vm_package="small1" + +# disable profile? +active=0 + +# Available in ClonOS? +clonos_active=0 + +# VNC +vm_vnc_port="0" +vm_efi="uefi" + +# VirtualBox Area +virtualbox_ostype="FreeBSD_64" diff --git a/etc/defaults/vm-freebsd-FreeBSD-x64-12.0-LATEST.conf b/etc/defaults/vm-freebsd-FreeBSD-x64-12.0-LATEST.conf index a61307f11..641c81fee 100644 --- a/etc/defaults/vm-freebsd-FreeBSD-x64-12.0-LATEST.conf +++ b/etc/defaults/vm-freebsd-FreeBSD-x64-12.0-LATEST.conf @@ -8,7 +8,7 @@ long_description="FreeBSD 12.0 Current" fetch=1 iso_site="https://download.freebsd.org/ftp/snapshots/amd64/amd64/ISO-IMAGES/12.0/" -iso_img="FreeBSD-12.0-CURRENT-amd64-20170814-r322508-disc1.iso" +iso_img="FreeBSD-12.0-CURRENT-amd64-20170912-r323499-disc1.iso" # register_iso as: register_iso_name="cbsd-iso-${iso_img}" diff --git a/etc/defaults/vm-freebsd-OPNsense-17-RELEASE-amd64.conf b/etc/defaults/vm-freebsd-OPNsense-17-RELEASE-amd64.conf index 7dc1b4198..5fc2dd692 100644 --- a/etc/defaults/vm-freebsd-OPNsense-17-RELEASE-amd64.conf +++ b/etc/defaults/vm-freebsd-OPNsense-17-RELEASE-amd64.conf @@ -15,6 +15,7 @@ http://mirror.cedia.org.ec/opnsense/releases/17.7/ \ http://mirrors.nycbug.org/pub/opnsense/releases/mirror/ \ http://mirror.wdc1.us.leaseweb.net/opnsense/releases/17.7/ \ https://opnsense.ieji.de/releases/17.7/ \ +https://mirror.dns-root.de/opnsense/releases/17.7/ \ " iso_img="OPNsense-17.7-OpenSSL-dvd-amd64.iso" diff --git a/etc/defaults/vm-linux-OracleLinux-7.conf b/etc/defaults/vm-linux-OracleLinux-7.conf index 828911124..76c37904c 100644 --- a/etc/defaults/vm-linux-OracleLinux-7.conf +++ b/etc/defaults/vm-linux-OracleLinux-7.conf @@ -3,7 +3,7 @@ vmlinuz_ver="3.10.0-123.el7.x86_64" vm_profile="OracleLinux-7" vm_os_type="linux" # this is one-string additional info strings in dialogue menu -long_description="Linux Oracle R7-U3" +long_description="Linux Oracle R7-U4" # custom settings: fetch=1 @@ -15,14 +15,14 @@ fetch=1 # grub-bhyve command to boot from ISO #grub_iso_cmd="echo -e \"linux /isolinux/vmlinuz text\ninitrd /isolinux/initrd.img\nboot\" | /usr/bin/lockf -s -t0 /tmp/bhyveload.${jname}.lock grub-bhyve -r cd0 -m "${_devicemap}" -M ${grubmem} "${jname}"" -iso_site="http://ftp5.gwdg.de/pub/linux/oracle/OL7/u3/x86_64/ \ -https://mirrors.dotsrc.org/oracle-linux/OL7/u3/x86_64/ \ -https://ftp.heanet.ie/mirrors/oracle-linux/OL7/u3/x86_64/ \ -http://ftp.icm.edu.pl/pub/Linux/dist/oracle-linux/OL7/u3/x86_64/ \ -http://mirror.aarnet.edu.au/pub/oraclelinux/OL7/u3/x86_64/ \ +iso_site="http://ftp5.gwdg.de/pub/linux/oracle/OL7/u4/x86_64/ \ +https://mirrors.dotsrc.org/oracle-linux/OL7/u4/x86_64/ \ +https://ftp.heanet.ie/mirrors/oracle-linux/OL7/u4/x86_64/ \ +http://ftp.icm.edu.pl/pub/Linux/dist/oracle-linux/OL7/u4/x86_64/ \ +http://mirror.aarnet.edu.au/pub/oraclelinux/OL7/u4/x86_64/ \ " -iso_img="OracleLinux-R7-U3-Server-x86_64-dvd.iso" +iso_img="OracleLinux-R7-U4-Server-x86_64-dvd.iso" # register_iso as: register_iso_name="cbsd-iso-${iso_img}" diff --git a/etc/defaults/vm-linux-TinyCore-x86-8.conf b/etc/defaults/vm-linux-TinyCore-x86-8.conf index 16f529e84..bc9a41098 100644 --- a/etc/defaults/vm-linux-TinyCore-x86-8.conf +++ b/etc/defaults/vm-linux-TinyCore-x86-8.conf @@ -21,7 +21,7 @@ http://mirrors.163.com/tinycorelinux/8.x/x86_64/release/ \ http://mirrors.dotsrc.org/tinycorelinux/8.x/x86_64/release/ \ http://ftp.nluug.nl/os/Linux/distr/tinycorelinux/8.x/x86_64/release/ \ " -iso_img="TinyCorePure64-8.0.iso" +iso_img="TinyCorePure64-8.1.1.iso" # register_iso as: register_iso_name="cbsd-iso-${iso_img}" diff --git a/jailctl/bset b/jailctl/bset index 35405257a..3c5186176 100755 --- a/jailctl/bset +++ b/jailctl/bset @@ -1,5 +1,5 @@ #!/usr/local/bin/cbsd -#v11.1.0 +#v11.1.4 MYARG="jname" CBSDMODULE="bhyve" @@ -17,6 +17,24 @@ ADDHELP="mode=force for modification on the running jail\n" . ${strings} init $* +emulator="bhyve" # for jname_is_multiple +jname_is_multiple + +if [ -n "${jail_list}" ]; then + new_arg= + + for i in $*; do + _is_jname=$( substr --pos=0 --len=5 --str=${i} ) + [ "${_is_jname}" = "jname" ] && continue + new_arg="${new_arg} ${i}" + done + + for jname in ${jail_list}; do + bset jname=${jname} ${new_arg} + done + exit 0 +fi + [ -z "${cbsd_queue_name}" ] && cbsd_queue_name="/clonos/bhyvevms/" update_jails() diff --git a/jailctl/bsetup-tui b/jailctl/bsetup-tui index 1a5e101d4..c0d874e14 100755 --- a/jailctl/bsetup-tui +++ b/jailctl/bsetup-tui @@ -1,5 +1,5 @@ #!/usr/local/bin/cbsd -#v10.0.4 +#v11.1.4 globalconf="${workdir}/cbsd.conf"; set -e @@ -39,22 +39,26 @@ commit() fi if [ "${i}" = "vm_ram" ]; then + # In SQLite3 we store vm_ram in bytes, convert it # test for human if is_number ${VAL}; then if conv2bytes ${VAL}; then VAL="${convval}" fi - fi - # test for human for original - if is_number ${OVAL}; then - if conv2bytes ${OVAL}; then - OVAL="${convval}" - fi + else + # Assume than user input in MB, so convert to bytes + VAL=$(( convval * 1024 * 1024 )) fi fi [ "${VAL}" = "${OVAL}" ] && continue - bset mode=quiet jname=${_oldjname} $i="${VAL}" + + if [ "${i}" = "vm_ram" ]; then + # In SQLite3 we store vm_ram in bytes, convert it + VAL=$(( VAL / 1024 / 1024 )) + fi + + bset mode=quiet jname=${_oldjname} ${i}="${VAL}" done [ "${_oldjname}" != "${_newjname}" -a -n "${_newjname}" ] && cbsd brename old=${_oldjname} new=${_newjname} @@ -140,11 +144,11 @@ dialog_menu_main() # test for human if ! is_number ${VAL}; then if conv2human "${VAL}"; then - VAL=$convval + VAL=${convval} vm_ram="${VAL}" - fi fi fi + fi if [ -z "${VAL}" ]; then menu_list="${menu_list} '${item_let} ${i}' ' ' 'Descr?'" diff --git a/jailctl/jset b/jailctl/jset index 271a432c8..b1285203a 100755 --- a/jailctl/jset +++ b/jailctl/jset @@ -1,5 +1,5 @@ #!/usr/local/bin/cbsd -#v11.0.9 +#v11.1.3 MYARG="jname" CBSDMODULE="jail" ADDHELP="jconf= - load and set settings from jconf\n" @@ -19,6 +19,24 @@ ADDHELP="mode=force for modification on the running jail\n" init $* +emulator="jail" # for jname_is_multiple +jname_is_multiple + +if [ -n "${jail_list}" ]; then + new_arg= + + for i in $*; do + _is_jname=$( substr --pos=0 --len=5 --str=${i} ) + [ "${_is_jname}" = "jname" ] && continue + new_arg="${new_arg} ${i}" + done + + for jname in ${jail_list}; do + jset jname=${jname} ${new_arg} + done + exit 0 +fi + [ -z "${cbsd_queue_name}" ] && cbsd_queue_name="/clonos/jailscontainers/" [ -z "${autorestart}" ] && autorestart=0 diff --git a/jcreate.subr b/jcreate.subr index 739f3eb5e..56989004b 100644 --- a/jcreate.subr +++ b/jcreate.subr @@ -168,7 +168,6 @@ external_exec_master_script() exec_master_prestop() { -# eval CMD=\${exec_master_prestop${i}} eval CMD=\${exec_master_prestop} [ -z "${CMD}" -o "${CMD}" = "0" ] && return 0 diff --git a/nc.subr b/nc.subr index 901f899ae..726f8afa7 100644 --- a/nc.subr +++ b/nc.subr @@ -6,9 +6,7 @@ _CBSD_NC_SUBR=1 if [ -n "${CBSD_RNODE}" ]; then rnode="${CBSD_RNODE}" unset CBSD_RNODE -# echo ">> Remote execution on ${rnode}" cmd=$( /usr/bin/basename $0 ) -# echo ">> cbsd rexe node=${rnode} /usr/local/bin/cbsd ${cmd} $@" exec /usr/local/bin/cbsd rexe node=${rnode} /usr/local/bin/cbsd ${cmd} $@ fi @@ -23,8 +21,6 @@ get_jid() { [ -z "$jname" -a -z "${path}" ] && return 0 -# _res=$( /usr/sbin/jls -h jid name |/usr/bin/tail +2| while read _jid _name; do - _res=$( cbsdjls | while read _jid _name; do [ "${_name}" = "${jname}" ] && echo ${_jid} done) diff --git a/rctl.subr b/rctl.subr index 1f18518ca..84fcbab46 100644 --- a/rctl.subr +++ b/rctl.subr @@ -26,7 +26,7 @@ init_rctlconf() eval ${i}=0 done - _ALLCOL=$( echo ${MYCOL}|tr " " "," ) + _ALLCOL=$( echo ${MYCOL}| /usr/bin/tr " " "," ) # empty string on remote node if cbsd version is mistmatch ( diff. jail schema ) _A=$( 2>/dev/null env sqldelimer="|" ${miscdir}/sqlcli ${_sqlfile} "SELECT ${_ALLCOL} FROM rctl WHERE jname=\"$1\"" ) diff --git a/settings-tui.subr b/settings-tui.subr index f21d7c381..b4b81999c 100644 --- a/settings-tui.subr +++ b/settings-tui.subr @@ -56,7 +56,7 @@ GET_IMGSIZE_MSG="Allocate X size of image free space: 100m, 1g" GET_SWAPSIZE_MSG="Configure swap partitional in X size (usual RAMx2), 0 - for disable, e.g: 4g" GET_CPUS_MSG="Number of CPUs: 1, max: 16" GET_VM_VNC_PORT_MSG="VNC port. 0 - for auto, 1 - disable" -GET_RAM_MSG="RAM size, eg: 512M" +GET_RAM_MSG="RAM in MB, eg: 512, 1024M, 2g" GET_VMPROFILE_MSG="Select profile for VMs" GET_JAILPROFILE_MSG="Profile for jcreate" GET_HOSTBRIDGE_MSG="Hostbridge for VMs, eg: hostbridge or amd_hostbridge" @@ -858,14 +858,30 @@ get_construct_vm_vnc_port() # form for $ram get_construct_vm_ram() { - local _input + local _input _tmp f_dialog_title " ram " f_dialog_input _input "${GET_RAM_MSG}" "${vm_ram}" \ "${_message}" || return $? - - vm_ram="${_input}" + + # test for human + if ! is_number "${_input}"; then + # is number. assume user's input value in MB, so convert to bytes + _input=$(( _input * 1024 * 1024 )) + if conv2human "${_input}"; then + _tmp="${convval}" + else + _tmp=$(( _input * 1024 * 1024 )) + if conv2human "${VAL}"; then + _tmp="${convval}" + fi + fi + else + _tmp="${_input}" + fi + + vm_ram="${_tmp}" } # form for $vm_iso_path @@ -2100,5 +2116,20 @@ get_construct_nic_hwaddr() [ -n "${_input}" ] && nic_hwaddr="${_input}" } +# form for $nic_mtu +get_construct_nic_mtu() +{ + local _input + + f_dialog_title " NIC MTU. 0 - auto, inherits parent MTU " + + [ -n "${nic_hwaddr}" ] && new_defhwaddr="${nic_hwaddr}" + + f_dialog_input _input "Input MTU size ( 0 - auto ), eg: 0, 1500, 9000" "${nic_mtu}" \ + "${_message}" || return $? + + [ -n "${_input}" ] && nic_mtu="${_input}" +} + ### fi diff --git a/share/bhyvenic.conf b/share/bhyvenic.conf index a05c5cbd3..c7e3ac58f 100644 --- a/share/bhyvenic.conf +++ b/share/bhyvenic.conf @@ -1,2 +1,2 @@ # Default SQL scheme for DB local::bhyvenic -MYCOL="id jname nic_order nic_driver nic_slot nic_type nic_parent nic_hwaddr nic_address" +MYCOL="id jname nic_order nic_driver nic_slot nic_type nic_parent nic_hwaddr nic_address nic_mtu" diff --git a/share/bhyverun.sh b/share/bhyverun.sh index 14f2311b9..62624dacd 100644 --- a/share/bhyverun.sh +++ b/share/bhyverun.sh @@ -89,7 +89,6 @@ while [ ! -f /tmp/bhyvestop.${jname}.lock ]; do for i in ${mytap}; do /sbin/ifconfig ${i} up - /sbin/ifconfig ${i} mtu 1500 done [ ${freebsdhostversion} -lt 1100120 ] && vm_vnc_port=1 # Disable xhci on FreeBSD < 11 @@ -113,7 +112,9 @@ while [ ! -f /tmp/bhyvestop.${jname}.lock ]; do add_bhyve_opts="-H" # Yield the virtual CPU thread when a HLT instruction is detected. [ "${bhyve_generate_acpi}" = "1" ] && add_bhyve_opts="${add_bhyve_opts} -A" - [ "$bhyve_wire_memory}" = "1" ] && add_bhyve_opts="${add_bhyve_opts} -S" + + [ "${bhyve_wire_memory}" = "1" -o -n "${pci_passthru_args}" ] && add_bhyve_opts="${add_bhyve_opts} -S" + [ "${bhyve_rts_keeps_utc}" = "1" ] && add_bhyve_opts="${add_bhyve_opts} -u" [ "${bhyve_force_msi_irq}" = "1" ] && add_bhyve_opts="${add_bhyve_opts} -W" [ "${bhyve_x2apic_mode}" = "1" ] && add_bhyve_opts="${add_bhyve_opts} -x" diff --git a/share/bsdconfig/cbsd/bhyvenic-cfgnic b/share/bsdconfig/cbsd/bhyvenic-cfgnic index cbcce6be9..c44419ce8 100755 --- a/share/bsdconfig/cbsd/bhyvenic-cfgnic +++ b/share/bsdconfig/cbsd/bhyvenic-cfgnic @@ -20,7 +20,7 @@ dialog_menu_main() local prompt="${_desc}" local sqldelimer=" " - eval $( cbsdsql ${jailsysdir}/${jname}/local.sqlite SELECT id,nic_driver,nic_slot,nic_type,nic_parent,nic_hwaddr,nic_address FROM bhyvenic WHERE id=\"${nic}\" AND jname=\"${jname}\" | while read nic_id nic_driver nic_slot nic_type nic_parent nic_hwaddr nic_address; do + eval $( cbsdsql ${jailsysdir}/${jname}/local.sqlite SELECT id,nic_driver,nic_slot,nic_type,nic_parent,nic_hwaddr,nic_address,nic_mtu FROM bhyvenic WHERE id=\"${nic}\" AND jname=\"${jname}\" | while read nic_id nic_driver nic_slot nic_type nic_parent nic_hwaddr nic_address nic_mtu; do echo "export nic_id=\"${nic_id}\"" echo "export nic_driver=\"${nic_driver}\"" echo "export nic_slot=\"${nic_slot}\"" @@ -28,6 +28,7 @@ dialog_menu_main() echo "export nic_parent=\"${nic_parent}\"" echo "export nic_hwaddr=\"${nic_hwaddr}\"" echo "export nic_address=\"${nic_address}\"" + echo "export nic_mtu=\"${nic_mtu}\"" done ) || err 1 "${MAGENTA}Error while create NIC map${NORMAL}" local menu_list=" @@ -36,6 +37,7 @@ dialog_menu_main() 'nic_hwaddr' '${nic_hwaddr}' 'NIC Mac address. 0 - auto' 'nic_type' '${nic_type}' 'Select NIC type' 'nic_address' '${nic_address}' 'Assign IPs on this nic (hoster side)' + 'nic_mtu' '${nic_mtu}' 'NIC MTU. 0 - auto' '-' '-' '' 'remove' 'remove' 'Detach and remove NIC' " # END-QUOTE @@ -159,6 +161,9 @@ while :; do "nic_hwaddr") get_construct_nic_hwaddr && update_nic_hwaddr ${nic_id} ;; + "nic_mtu") + get_construct_nic_mtu && update_nic_mtu ${nic_id} + ;; "nic_parent") case "${nic_driver}" in vtnet) diff --git a/share/bsdconfig/cbsd/include/bhyvenic.subr b/share/bsdconfig/cbsd/include/bhyvenic.subr index ad69a0e81..29406344b 100644 --- a/share/bsdconfig/cbsd/include/bhyvenic.subr +++ b/share/bsdconfig/cbsd/include/bhyvenic.subr @@ -182,6 +182,19 @@ update_nic_hwaddr() return 0 } +# update nic_mtu by nic id +# $nic_mtu must be set +update_nic_mtu() +{ + local nic="${1}"; shift + [ -z "${nic_mtu}" ] && return 0 + [ -z "${jname}" -o -z "${nic}" ] && return 0 + + cbsdsql ${jailsysdir}/${jname}/local.sqlite UPDATE bhyvenic SET nic_mtu=\"${nic_mtu}\" WHERE id=\"${nic}\" AND jname=\"${jname}\" + + return 0 +} + # update nic_parent by nic id # $nic_parent must be set update_nic_parent() diff --git a/share/local-bhyvenic.schema b/share/local-bhyvenic.schema index c97fd569f..9ff4fc74e 100644 --- a/share/local-bhyvenic.schema +++ b/share/local-bhyvenic.schema @@ -14,6 +14,7 @@ nic_type="text default 0" # 0 - mean auto nic_parent="text default \"auto\"" # upstream nic_hwaddr="text default 0" # MAC addr nic_address="text default 0" # IP ADDRESS from hoster side +nic_mtu="integer default 0" # MTU size CONSTRAINT=", FOREIGN KEY(jname) REFERENCES jails(jname)" diff --git a/sudoexec/bstart b/sudoexec/bstart index 2a92611ea..ff6c675c2 100755 --- a/sudoexec/bstart +++ b/sudoexec/bstart @@ -264,11 +264,10 @@ start_bhyve() boot_from_grub=0 ;; *) - if [ "${boot_from_grub}" = "1" ]; then - [ -z "${grub_boot_cmd}" ] && err 1 "${MAGENTA}No such grub_boot_cmd variable. Check ${GREEN}vm_os_profile${MAGENTA} of config for ${GREEN}vm-${vm_os_type}-${vm_os_profile}.conf${MAGENTA} in ${etcdir}${NORMAL}" - [ -z "${grub_iso_cmd}" -a "${vm_boot}" = "cd" ] && err 1 "${MAGENTA}No such grub_iso_cmd variable. Check ${GREEN}vm_os_profile${MANGETA} of config for ${GREEN}vm-${vm_os_type}-${vm_os_profile}.conf ${MAGENTA}in ${etcdir}${NORMAL}" - /bin/cat "${_devicemap}" - fi + boot_from_grub=1 + [ -z "${grub_boot_cmd}" ] && err 1 "${MAGENTA}No such grub_boot_cmd variable. Check ${GREEN}vm_os_profile${MAGENTA} of config for ${GREEN}vm-${vm_os_type}-${vm_os_profile}.conf${MAGENTA} in ${etcdir}${NORMAL}" + [ -z "${grub_iso_cmd}" -a "${vm_boot}" = "cd" ] && err 1 "${MAGENTA}No such grub_iso_cmd variable. Check ${GREEN}vm_os_profile${MANGETA} of config for ${GREEN}vm-${vm_os_type}-${vm_os_profile}.conf ${MAGENTA}in ${etcdir}${NORMAL}" + /bin/cat "${_devicemap}" ;; esac diff --git a/sudoexec/initenv b/sudoexec/initenv index 33b9e7875..1e32b4c4c 100755 --- a/sudoexec/initenv +++ b/sudoexec/initenv @@ -288,6 +288,10 @@ phase2() installne "-s -o ${cbsduser} -g ${cbsduser} -m 555" ${distdir}/tools/vale-ctl ${toolsdir}/vale-ctl [ -f ${toolsdir}/vale-ctl ] && /bin/rm -f ${toolsdir}/vale-ctl + [ ! -f "${distdir}/tools/nic_info" ] && ${CC_CMD} ${distdir}/tools/src/nic_info.c -o ${distdir}/tools/nic_info + installne "-s -o ${cbsduser} -g ${cbsduser} -m 555" ${distdir}/tools/nic_info ${toolsdir}/nic_info + [ -f ${toolsdir}/nic_info ] && /bin/rm -f ${toolsdir}/nic_info + [ ! -f "${distdir}/tools/bridge" ] && ${CC_CMD} ${distdir}/tools/src/bridge.c -o ${distdir}/tools/bridge installne "-s -o ${cbsduser} -g ${cbsduser} -m 555" ${distdir}/tools/bridge ${toolsdir}/bridge [ -f ${toolsdir}/bridge ] && /bin/rm -f ${toolsdir}/bridge diff --git a/tools/bhyve-ppt b/tools/bhyve-ppt index 61ae6f8d0..ff62d350b 100755 --- a/tools/bhyve-ppt +++ b/tools/bhyve-ppt @@ -15,9 +15,12 @@ ppt - ppt\n . ${strings} . ${tools} +. ${workdir}/virtual.subr + init $* -device=$( /sbin/sysctl -nq hw.vmm.ppt.devices ) +#device=$( /sbin/sysctl -nq hw.vmm.ppt.devices ) +device=$( /usr/sbin/pciconf -l | /usr/bin/egrep -E "^ppt[0-9]+@" | /usr/bin/wc -l |/usr/bin/awk '{printf $1}' ) [ -z "${device}" ] && err 1 "${MAGENTA}No such ppt devices${NORMAL}" @@ -79,8 +82,9 @@ init_ppt_action() [ -z "${jname}" ] && err 1 "${MAGENTA}Please set: ${GREEN}jname=${NORMAL}" # check for PCI passthrough - local _dmar_test=$( /usr/sbin/acpidump -t | /usr/bin/grep DMAR ) - [ -z "${_dmar_test}" ] && err 1 "${MAGENTA}I/O MMU / VT-d not enabled. Check you hardware or BIOS setting${NORMAL}" + if check_dmar; then + err 1 "${MAGENTA}I/O MMU / VT-d not enabled. Check you hardware or BIOS setting${NORMAL}" + fi . ${jrcconf} [ $? -eq 1 ] && err 1 "${MAGENTA}No such jail: ${GREEN}${jname}${NORMAL}" diff --git a/tools/src/nic_info.c b/tools/src/nic_info.c new file mode 100644 index 000000000..8eece41f6 --- /dev/null +++ b/tools/src/nic_info.c @@ -0,0 +1,99 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#define FALSE 0 +#define TRUE 1 + +/* List of all args */ +enum { + C_HELP, + C_MTU, + C_NIC, + C_QUIET, +}; + +static void +usage(void) +{ + printf("Obtain NIC information\n"); + printf("require: --nic\n"); + printf("optional: --quiet --mtu\n"); + printf("usage: nic_info --nic=em0 --mtu\n"); + exit(1); +} + +int main(int argc, char *argv[]) +{ + int s, af = AF_INET; + struct ifreq ifr; + char *nic = NULL; + int optcode = 0; + int option_index = 0; + + int show_mtu=0; + int quiet=0; + + static struct option long_options[] = { + {"help", no_argument, 0, C_HELP}, + {"mtu", no_argument, 0, C_MTU}, + {"nic", required_argument, 0, C_NIC}, + {"quiet", no_argument, 0, C_QUIET}, + /* End of options marker */ + {0, 0, 0, 0} + }; + + while (TRUE) { + optcode = getopt_long_only(argc, argv, "", long_options, &option_index); + if (optcode == -1) + break; + switch(optcode) { + case C_HELP: + usage(); + break; + case C_MTU: + show_mtu=1; + break; + case C_NIC: + nic = malloc(strlen(optarg) + 1); + memset(nic, 0, strlen(optarg) + 1); + strcpy(nic, optarg); + break; + case C_QUIET: + quiet=1; + break; + } + } + + if (!nic) { + usage(); + } + + if ((s = socket(af, SOCK_DGRAM, 0)) < 0) + err(1, "socket"); + + ifr.ifr_addr.sa_family = AF_INET; + strcpy(ifr.ifr_name, nic); + if (ioctl(s, SIOCGIFMTU, (caddr_t)&ifr) < 0) + err(1,"ioctl (get mtu)"); + + close(s); + + if ( quiet ) { + fprintf(stdout, "%d\n",ifr.ifr_mtu); + } else { + fprintf(stdout, "mtu:%d\n", ifr.ifr_mtu); + } + + return(0); +} diff --git a/upgrade/pre-patch-11.1.5.0 b/upgrade/pre-patch-11.1.5.0 new file mode 100755 index 000000000..38214488c --- /dev/null +++ b/upgrade/pre-patch-11.1.5.0 @@ -0,0 +1,33 @@ +#!/bin/sh +#v11.1.5 +# Update bhyvenic tables for nic_mtu column +: ${distdir="/usr/local/cbsd"} +unset workdir + +# MAIN +. /etc/rc.conf + +[ -z "${cbsd_workdir}" ] && exit + +workdir="${cbsd_workdir}" + +[ ! -f "${workdir}/cbsd.conf" ] && exit + +. ${distdir}/cbsd.conf +. ${distdir}/tools.subr +test_sql_stuff + +[ ! -h "${dbdir}/local.sqlite" ] && exit + +vms=$( ${miscdir}/sqlcli ${dbdir}/local.sqlite "SELECT jname FROM jails WHERE emulator = \"bhyve\"" ) + +for i in ${vms}; do + mydb="${jailsysdir}/${i}/local.sqlite" + [ ! -r "${mydb}" ] && continue + # alter nic_mtu if not exist + unset _test + _test=$( ${miscdir}/sqlcli ${mydb} "SELECT nic_mtu FROM bhyvenic LIMIT 1" ) + [ -n "${_test}" ] && continue + ${ECHO} " * ${MAGENTA}Update bhyvenic tables: nic_mtu for ${GREEN}${i}${NORMAL}" + ${miscdir}/sqlcli ${mydb} ALTER TABLE bhyvenic ADD COLUMN nic_mtu integer default 0 +done diff --git a/virtual.subr b/virtual.subr index eade0a8a3..c6c5cf877 100644 --- a/virtual.subr +++ b/virtual.subr @@ -200,5 +200,15 @@ get_next_rd_port() echo ${_rd_port} } +# check 1 when DMAR detected +# check 0 if not +check_dmar() +{ + local _dmar_test=$( /usr/sbin/acpidump -t | /usr/bin/grep DMAR ) + [ -z "${_dmar_test}" ] && return 0 + + return 1 +} + ### fi diff --git a/vnet.subr b/vnet.subr index 02290f84e..9c272bf00 100644 --- a/vnet.subr +++ b/vnet.subr @@ -251,11 +251,8 @@ ip2mac() { macpart=$(( macpart + 1 )) done ) -# echo "${MAC_PREFIX}:${mac_4}:${mac_5}:${mac_6}:${mac_7}" echo "${MAC_PREFIX}:${mac_5}:${mac_6}:${mac_7}" - } ### fi -