From owner-freebsd-ports@freebsd.org Tue Mar 9 22:00:43 2021 Return-Path: Delivered-To: freebsd-ports@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 79BBF572FAB for ; Tue, 9 Mar 2021 22:00:43 +0000 (UTC) (envelope-from misho@elwix.org) Received: from mailman.nyi.freebsd.org (mailman.nyi.freebsd.org [IPv6:2610:1c1:1:606c::50:13]) by mx1.freebsd.org (Postfix) with ESMTP id 4Dw8KR272vz3LlM for ; Tue, 9 Mar 2021 22:00:43 +0000 (UTC) (envelope-from misho@elwix.org) Received: by mailman.nyi.freebsd.org (Postfix) id 48E53572EED; Tue, 9 Mar 2021 22:00:43 +0000 (UTC) Delivered-To: ports@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 48AFF572EEC for ; Tue, 9 Mar 2021 22:00:43 +0000 (UTC) (envelope-from misho@elwix.org) Received: from mail.elwix.net (ns.aitbg.com [84.242.154.175]) by mx1.freebsd.org (Postfix) with ESMTP id 4Dw8KP6vbpz3Lnk for ; Tue, 9 Mar 2021 22:00:41 +0000 (UTC) (envelope-from misho@elwix.org) Received: from terran.aitnet.org (unknown [87.246.28.119]) by mail.elwix.net (Postfix) with ESMTPSA id BDCD94A29AD5; Wed, 10 Mar 2021 00:00:33 +0200 (EET) Date: Wed, 10 Mar 2021 00:00:32 +0200 From: Michael Pounov To: churchers@gmail.com Cc: ports@freebsd.org Subject: vm-bhyve vale support Message-Id: <20210310000032.88cee39c2f148ad990297c92@elwix.org> Organization: ELWIX X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; amd64-portbld-freebsd11.2) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Wed__10_Mar_2021_00_00_32_+0200_CrcZznn8j.3h7ic8" X-Rspamd-Queue-Id: 4Dw8KP6vbpz3Lnk X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of misho@elwix.org has no SPF policy when checking 84.242.154.175) smtp.mailfrom=misho@elwix.org X-Spamd-Result: default: False [-1.50 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; MV_CASE(0.50)[]; HAS_ATTACHMENT(0.00)[]; TO_DN_NONE(0.00)[]; HAS_ORG_HEADER(0.00)[]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCPT_COUNT_TWO(0.00)[2]; FREEMAIL_TO(0.00)[gmail.com]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:+,3:+]; RBL_DBL_DONT_QUERY_IPS(0.00)[84.242.154.175:from]; ASN(0.00)[asn:29580, ipnet:84.242.152.0/21, country:BG]; MID_RHS_MATCH_FROM(0.00)[]; RECEIVED_SPAMHAUS_PBL(0.00)[87.246.28.119:received]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[multipart/mixed,text/plain,text/x-diff]; R_DKIM_NA(0.00)[]; AUTH_NA(1.00)[]; DMARC_NA(0.00)[elwix.org]; SPAMHAUS_ZRD(0.00)[84.242.154.175:from:127.0.2.255]; TO_MATCH_ENVRCPT_SOME(0.00)[]; R_SPF_NA(0.00)[no SPF record]; RCVD_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[ports] X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Mar 2021 22:00:43 -0000 This is a multi-part message in MIME format. --Multipart=_Wed__10_Mar_2021_00_00_32_+0200_CrcZznn8j.3h7ic8 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 --Multipart=_Wed__10_Mar_2021_00_00_32_+0200_CrcZznn8j.3h7ic8 Content-Type: text/x-diff; name="vm-switch.patch" Content-Disposition: attachment; filename="vm-switch.patch" Content-Transfer-Encoding: 7bit --- /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 --Multipart=_Wed__10_Mar_2021_00_00_32_+0200_CrcZznn8j.3h7ic8 Content-Type: text/x-diff; name="vm-switch-vale.patch" Content-Disposition: attachment; filename="vm-switch-vale.patch" Content-Transfer-Encoding: 7bit --- /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}" } --Multipart=_Wed__10_Mar_2021_00_00_32_+0200_CrcZznn8j.3h7ic8--