sbin/ifconfig: Get lagg status with libifconfig

Also trimmed an unused block of code that never prints out LAGG_PROTOS.
Reviewed by:	kp (earlier version)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D28961
This commit is contained in:
Ryan Moeller 2021-02-27 03:05:31 +00:00
parent da393346ac
commit a0ebb91504

View File

@ -28,6 +28,8 @@ static const char rcsid[] =
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <libifconfig.h>
#include "ifconfig.h" #include "ifconfig.h"
static struct iflaggparam params = { static struct iflaggparam params = {
@ -216,93 +218,87 @@ lacp_format_peer(struct lacp_opreq *req, const char *sep)
static void static void
lagg_status(int s) lagg_status(int s)
{ {
struct lagg_protos lpr[] = LAGG_PROTOS; struct lagg_protos protos[] = LAGG_PROTOS;
struct lagg_reqport rpbuf[LAGG_MAX_PORTS]; ifconfig_handle_t *lifh;
struct lagg_reqall ra; struct ifconfig_lagg_status *lagg;
struct lagg_reqopts ro; struct lagg_reqall *ra;
struct lagg_reqflags rf; struct lagg_reqflags *rf;
struct lagg_reqopts *ro;
struct lagg_reqport *ports;
struct lacp_opreq *lp; struct lacp_opreq *lp;
const char *proto = "<unknown>"; const char *proto;
int i;
bzero(&ra, sizeof(ra)); lifh = ifconfig_open();
bzero(&ro, sizeof(ro)); if (lifh == NULL)
return;
strlcpy(ra.ra_ifname, name, sizeof(ra.ra_ifname)); if (ifconfig_lagg_get_lagg_status(lifh, name, &lagg) == -1)
ra.ra_size = sizeof(rpbuf); goto close;
ra.ra_port = rpbuf;
strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname)); ra = lagg->ra;
ioctl(s, SIOCGLAGGOPTS, &ro); rf = lagg->rf;
ro = lagg->ro;
ports = ra->ra_port;
strlcpy(rf.rf_ifname, name, sizeof(rf.rf_ifname)); proto = "<unknown>";
if (ioctl(s, SIOCGLAGGFLAGS, &rf) != 0) for (size_t i = 0; i < nitems(protos); ++i) {
rf.rf_flags = 0; if (ra->ra_proto == protos[i].lpr_proto) {
proto = protos[i].lpr_name;
if (ioctl(s, SIOCGLAGG, &ra) == 0) { break;
lp = (struct lacp_opreq *)&ra.ra_lacpreq;
for (i = 0; i < nitems(lpr); i++) {
if (ra.ra_proto == lpr[i].lpr_proto) {
proto = lpr[i].lpr_name;
break;
}
}
printf("\tlaggproto %s", proto);
if (rf.rf_flags & LAGG_F_HASHMASK) {
const char *sep = "";
printf(" lagghash ");
if (rf.rf_flags & LAGG_F_HASHL2) {
printf("%sl2", sep);
sep = ",";
}
if (rf.rf_flags & LAGG_F_HASHL3) {
printf("%sl3", sep);
sep = ",";
}
if (rf.rf_flags & LAGG_F_HASHL4) {
printf("%sl4", sep);
sep = ",";
}
}
putchar('\n');
if (verbose) {
printf("\tlagg options:\n");
printb("\t\tflags", ro.ro_opts, LAGG_OPT_BITS);
putchar('\n');
printf("\t\tflowid_shift: %d\n", ro.ro_flowid_shift);
if (ra.ra_proto == LAGG_PROTO_ROUNDROBIN)
printf("\t\trr_limit: %d\n", ro.ro_bkt);
printf("\tlagg statistics:\n");
printf("\t\tactive ports: %d\n", ro.ro_active);
printf("\t\tflapping: %u\n", ro.ro_flapping);
if (ra.ra_proto == LAGG_PROTO_LACP) {
printf("\tlag id: %s\n",
lacp_format_peer(lp, "\n\t\t "));
}
}
for (i = 0; i < ra.ra_ports; i++) {
lp = (struct lacp_opreq *)&rpbuf[i].rp_lacpreq;
printf("\tlaggport: %s ", rpbuf[i].rp_portname);
printb("flags", rpbuf[i].rp_flags, LAGG_PORT_BITS);
if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
printb(" state", lp->actor_state,
LACP_STATE_BITS);
putchar('\n');
if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
printf("\t\t%s\n",
lacp_format_peer(lp, "\n\t\t "));
}
if (0 /* XXX */) {
printf("\tsupported aggregation protocols:\n");
for (i = 0; i < nitems(lpr); i++)
printf("\t\tlaggproto %s\n", lpr[i].lpr_name);
} }
} }
printf("\tlaggproto %s", proto);
if (rf->rf_flags & LAGG_F_HASHMASK) {
const char *sep = "";
printf(" lagghash ");
if (rf->rf_flags & LAGG_F_HASHL2) {
printf("%sl2", sep);
sep = ",";
}
if (rf->rf_flags & LAGG_F_HASHL3) {
printf("%sl3", sep);
sep = ",";
}
if (rf->rf_flags & LAGG_F_HASHL4) {
printf("%sl4", sep);
sep = ",";
}
}
putchar('\n');
if (verbose) {
printf("\tlagg options:\n");
printb("\t\tflags", ro->ro_opts, LAGG_OPT_BITS);
putchar('\n');
printf("\t\tflowid_shift: %d\n", ro->ro_flowid_shift);
if (ra->ra_proto == LAGG_PROTO_ROUNDROBIN)
printf("\t\trr_limit: %d\n", ro->ro_bkt);
printf("\tlagg statistics:\n");
printf("\t\tactive ports: %d\n", ro->ro_active);
printf("\t\tflapping: %u\n", ro->ro_flapping);
if (ra->ra_proto == LAGG_PROTO_LACP) {
lp = &ra->ra_lacpreq;
printf("\tlag id: %s\n",
lacp_format_peer(lp, "\n\t\t "));
}
}
for (size_t i = 0; i < ra->ra_ports; ++i) {
lp = &ports[i].rp_lacpreq;
printf("\tlaggport: %s ", ports[i].rp_portname);
printb("flags", ports[i].rp_flags, LAGG_PORT_BITS);
if (verbose && ra->ra_proto == LAGG_PROTO_LACP)
printb(" state", lp->actor_state, LACP_STATE_BITS);
putchar('\n');
if (verbose && ra->ra_proto == LAGG_PROTO_LACP)
printf("\t\t%s\n",
lacp_format_peer(lp, "\n\t\t "));
}
ifconfig_lagg_free_lagg_status(lagg);
close:
ifconfig_close(lifh);
} }
static static