From owner-dev-commits-src-branches@freebsd.org Sun Mar 14 09:09:53 2021 Return-Path: Delivered-To: dev-commits-src-branches@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 4CFB45788D2; Sun, 14 Mar 2021 09:09:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Dytzg1rThz3Fnp; Sun, 14 Mar 2021 09:09:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1C9B91AAF5; Sun, 14 Mar 2021 09:09:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 12E99m93078377; Sun, 14 Mar 2021 09:09:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 12E99mDW078376; Sun, 14 Mar 2021 09:09:48 GMT (envelope-from git) Date: Sun, 14 Mar 2021 09:09:48 GMT Message-Id: <202103140909.12E99mDW078376@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ryan Moeller Subject: git: 3dfbda3401ab - stable/13 - sbin/ifconfig: Get bridge status with libifconfig MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: freqlabs X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3dfbda3401abea84da9fd637c1b950fd954f2514 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Mar 2021 09:09:53 -0000 The branch stable/13 has been updated by freqlabs: URL: https://cgit.FreeBSD.org/src/commit/?id=3dfbda3401abea84da9fd637c1b950fd954f2514 commit 3dfbda3401abea84da9fd637c1b950fd954f2514 Author: Ryan Moeller AuthorDate: 2021-02-26 23:04:38 +0000 Commit: Ryan Moeller CommitDate: 2021-03-14 08:08:13 +0000 sbin/ifconfig: Get bridge status with libifconfig Reviewed by: kp Differential Revision: https://reviews.freebsd.org/D28954 (cherry picked from commit 6f497e47e925f6886f444a8e31e2e939fca264f2) --- sbin/ifconfig/ifbridge.c | 169 +++++++++++++++++++---------------------------- 1 file changed, 69 insertions(+), 100 deletions(-) diff --git a/sbin/ifconfig/ifbridge.c b/sbin/ifconfig/ifbridge.c index f4c51632bc98..cc1520a2e3f0 100644 --- a/sbin/ifconfig/ifbridge.c +++ b/sbin/ifconfig/ifbridge.c @@ -61,6 +61,8 @@ static const char rcsid[] = #include #include +#include + #include "ifconfig.h" static const char *stpstates[] = { STP_STATES }; @@ -116,74 +118,6 @@ do_bridgeflag(int sock, const char *ifs, int flag, int set) err(1, "unable to set bridge flags"); } -static void -bridge_interfaces(int s, const char *prefix) -{ - struct ifbifconf bifc; - struct ifbreq *req; - char *inbuf = NULL, *ninbuf; - char *p, *pad; - int i, len = 8192; - - pad = strdup(prefix); - if (pad == NULL) - err(1, "strdup"); - /* replace the prefix with whitespace */ - for (p = pad; *p != '\0'; p++) { - if(isprint(*p)) - *p = ' '; - } - - for (;;) { - ninbuf = realloc(inbuf, len); - if (ninbuf == NULL) - err(1, "unable to allocate interface buffer"); - bifc.ifbic_len = len; - bifc.ifbic_buf = inbuf = ninbuf; - if (do_cmd(s, BRDGGIFS, &bifc, sizeof(bifc), 0) < 0) - err(1, "unable to get interface list"); - if ((bifc.ifbic_len + sizeof(*req)) < len) - break; - len *= 2; - } - - for (i = 0; i < bifc.ifbic_len / sizeof(*req); i++) { - req = bifc.ifbic_req + i; - printf("%s%s ", prefix, req->ifbr_ifsname); - printb("flags", req->ifbr_ifsflags, IFBIFBITS); - printf("\n"); - - printf("%s", pad); - printf("ifmaxaddr %u", req->ifbr_addrmax); - printf(" port %u priority %u", req->ifbr_portno, - req->ifbr_priority); - printf(" path cost %u", req->ifbr_path_cost); - - if (req->ifbr_ifsflags & IFBIF_STP) { - if (req->ifbr_proto < nitems(stpproto)) - printf(" proto %s", stpproto[req->ifbr_proto]); - else - printf(" ", - req->ifbr_proto); - - printf("\n%s", pad); - if (req->ifbr_role < nitems(stproles)) - printf("role %s", stproles[req->ifbr_role]); - else - printf("", - req->ifbr_role); - if (req->ifbr_state < nitems(stpstates)) - printf(" state %s", stpstates[req->ifbr_state]); - else - printf(" ", - req->ifbr_state); - } - printf("\n"); - } - free(pad); - free(inbuf); -} - static void bridge_addresses(int s, const char *prefix) { @@ -222,44 +156,79 @@ bridge_addresses(int s, const char *prefix) static void bridge_status(int s) { - struct ifbropreq ifbp; - struct ifbrparam param; - u_int16_t pri; - u_int8_t ht, fd, ma, hc, pro; - u_int8_t lladdr[ETHER_ADDR_LEN]; - u_int16_t bprio; - u_int32_t csize, ctime; + ifconfig_handle_t *lifh; + struct ifconfig_bridge_status *bridge; + struct ifbropreq *params; + const char *pad, *prefix; + uint8_t lladdr[ETHER_ADDR_LEN]; + uint16_t bprio; - if (do_cmd(s, BRDGGCACHE, ¶m, sizeof(param), 0) < 0) - return; - csize = param.ifbrp_csize; - if (do_cmd(s, BRDGGTO, ¶m, sizeof(param), 0) < 0) - return; - ctime = param.ifbrp_ctime; - if (do_cmd(s, BRDGPARAM, &ifbp, sizeof(ifbp), 0) < 0) + lifh = ifconfig_open(); + if (lifh == NULL) return; - pri = ifbp.ifbop_priority; - pro = ifbp.ifbop_protocol; - ht = ifbp.ifbop_hellotime; - fd = ifbp.ifbop_fwddelay; - hc = ifbp.ifbop_holdcount; - ma = ifbp.ifbop_maxage; - - PV2ID(ifbp.ifbop_bridgeid, bprio, lladdr); - printf("\tid %s priority %u hellotime %u fwddelay %u\n", - ether_ntoa((struct ether_addr *)lladdr), pri, ht, fd); - printf("\tmaxage %u holdcnt %u proto %s maxaddr %u timeout %u\n", - ma, hc, stpproto[pro], csize, ctime); - PV2ID(ifbp.ifbop_designated_root, bprio, lladdr); - printf("\troot id %s priority %d ifcost %u port %u\n", - ether_ntoa((struct ether_addr *)lladdr), bprio, - ifbp.ifbop_root_path_cost, ifbp.ifbop_root_port & 0xfff); + if (ifconfig_bridge_get_bridge_status(lifh, name, &bridge) == -1) + goto close; - bridge_interfaces(s, "\tmember: "); + params = bridge->params; - return; + PV2ID(params->ifbop_bridgeid, bprio, lladdr); + printf("\tid %s priority %u hellotime %u fwddelay %u\n", + ether_ntoa((struct ether_addr *)lladdr), + params->ifbop_priority, + params->ifbop_hellotime, + params->ifbop_fwddelay); + printf("\tmaxage %u holdcnt %u proto %s maxaddr %u timeout %u\n", + params->ifbop_maxage, + params->ifbop_holdcount, + stpproto[params->ifbop_protocol], + bridge->cache_size, + bridge->cache_lifetime); + PV2ID(params->ifbop_designated_root, bprio, lladdr); + printf("\troot id %s priority %d ifcost %u port %u\n", + ether_ntoa((struct ether_addr *)lladdr), + bprio, + params->ifbop_root_path_cost, + params->ifbop_root_port & 0xfff); + + prefix = "\tmember: "; + pad = "\t "; + for (size_t i = 0; i < bridge->members_count; ++i) { + struct ifbreq *member = &bridge->members[i]; + + printf("%s%s ", prefix, member->ifbr_ifsname); + printb("flags", member->ifbr_ifsflags, IFBIFBITS); + printf("\n%s", pad); + printf("ifmaxaddr %u port %u priority %u path cost %u", + member->ifbr_addrmax, + member->ifbr_portno, + member->ifbr_priority, + member->ifbr_path_cost); + if (member->ifbr_ifsflags & IFBIF_STP) { + uint8_t proto = member->ifbr_proto; + uint8_t role = member->ifbr_role; + uint8_t state = member->ifbr_state; + + if (proto < nitems(stpproto)) + printf(" proto %s", stpproto[proto]); + else + printf(" ", proto); + printf("\n%s", pad); + if (role < nitems(stproles)) + printf("role %s", stproles[role]); + else + printf("", role); + if (state < nitems(stpstates)) + printf(" state %s", stpstates[state]); + else + printf(" ", state); + } + printf("\n"); + } + ifconfig_bridge_free_bridge_status(bridge); +close: + ifconfig_close(lifh); } static void