Hi Matt Churchyard I made usable and working vale switch support in vm-bhyve project from FreeBSD 12 and above.
Now vale switches are near the same behaviour and view as standard and other supported types of switches. If you thinking my contributed code is ok to be part of yours project is free to merge, modify and using these patches to the vm-bhyve project. Best Regards Michael Pounov elwix.org
--- /usr/local/lib/vm-bhyve/vm-switch 2020-01-14 12:15:58.000000000 +0200 +++ vm-switch 2021-03-09 23:43:17.880167000 +0200 @@ -49,7 +49,7 @@ case "${_type}" in vxlan) switch::vxlan::init "${_switch}" ;; manual) switch::manual::init "${_switch}" ;; - vale) ;; + vale) switch::vale::init "${_switch}" ;; *) switch::standard::init "${_switch}" ;; esac done
--- /usr/local/lib/vm-bhyve/vm-switch-vale 2020-01-14 12:15:58.000000000 +0200 +++ vm-switch-vale 2021-03-09 23:43:17.886736000 +0200 @@ -32,26 +32,79 @@ switch::vale::show(){ local _name="$1" local _format="$2" - local _id + local _id _mtu + config::core::get "_ports" "ports_${_name}" + config::core::get "_bridge" "bridge_${_name}" + + [ -n "${_ports}" ] && _mtu=$(ifconfig ${_ports} | awk '($(NF - 1) == "mtu") { printf("%u", $NF); exit }') + switch::vale::id "_id" "${_name}" - printf "${_format}" "${_name}" "vale" "${_id}" "n/a" "n/a" "n/a" "n/a" "n/a" + printf "${_format}" "${_name}" "vale" "${_id}" "${_bridge:--}" "n/a" "${_mtu:--}" "n/a" "${_ports:--}" } +switch::vale::init(){ + local _name="$1" + + config::core::get "_ports" "ports_${_name}" + config::core::get "_bridge" "bridge_${_name}" + + switch::vale::id "_vale" "${_name}" + + if [ -n "${_ports}" ]; then + valectl -a ${_vale}:${_ports} + fi + + valectl -n ${_bridge} + valectl -a ${_vale}:${_bridge} +} + # create a vale switch # # @param string _switch the name of the switch # switch::vale::create(){ + local _br="${_bridge}" + switch::vale::id _vale ${_switch} + + if [ -n "${_if}" ]; then + valectl -a ${_vale}:${_if} || util::err "cannot create vale switch with interface ${_if}" + + [ -z "${_br}" ] && switch::vale::bridge _br ${_switch} + fi + + if [ -z "${_br}" ]; then + valectl -d ${_vale}:${_if} + util::err "cannot create vale switch without name for bridge" + fi + + valectl -n ${_br} || util::err "cannot create vale switch bridge interface ${_br}" + valectl -a ${_vale}:${_br} || util::err "cannot create vale switch with bridge ${_br}" + config::core::set "switch_list" "${_switch}" "1" config::core::set "type_${_switch}" "vale" + + config::core::set "bridge_${_switch}" "${_br}" + [ -n "${_if}" ] && config::core::set "ports_${_switch}" "${_if}" } # remove a vale switch # -switch::vale::remove(){ } +switch::vale::remove(){ + config::core::get "_if" "ports_${_switch}" + config::core::get "_br" "bridge_${_switch}" + switch::vale::id _vale ${_switch} + + valectl -d ${_vale}:${_br} + valectl -r ${_br} + + [ -n "${_if}" ] && valectl -d ${_vale}:${_if} + + return 0 +} + # add a new interface to this switch # at the moment we require the user to manually # set up any vale switches @@ -60,7 +113,14 @@ # @param string _if the interface to add # switch::vale::add_member(){ - util::err "physical interfaces must be added to the vale switch manually" + config::core::get "_chkif" "ports_${_switch}" + [ -n "${_chkif}" ] && util::err "we already have physical interface attached to the vale switch" + + switch::vale::id _vale ${_switch} + + valectl -a ${_vale}:${_if} || util::err "physical interfaces must be added to the vale switch manually" + + config::core::set "ports_${_switch}" "${_if}" } # remove an interface @@ -69,7 +129,14 @@ # @param string _if the interface to remove # switch::vale::remove_member(){ - util::err "physical interfaces must be removed from the vale switch manually" + config::core::get "_chkif" "ports_${_switch}" + [ "${_chkif}" != "${_if}" ] && util::err "we have not such physical interface attached to the vale switch" + + switch::vale::id _vale ${_switch} + + valectl -d ${_vale}:${_if} || util::err "physical interfaces must be removed from the vale switch manually" + + config::core::remove "ports_${_switch}" } # set vlan id @@ -106,4 +173,18 @@ else setvar "${_var}" "vale${_id_s}" fi +} + +switch::vale::bridge(){ + local _var="$1" + local _switch="$2" + local _br_s + + switch::vale::id _vale ${_switch} + + # get a switch bridge + _br_s=$(valectl 2>&1 | + awk -vvs=${_vale} '($NF ~ vs":" && $4 ~ "bridge:") { split($4, br, ":"); printf("vi%s\n", br[2]); exit; }') + + setvar "${_var}" "${_br_s}" }
_______________________________________________ freebsd-ports@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-ports To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"