2007-04-10 00:27:25 +00:00
|
|
|
/*-
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
|
|
|
"$FreeBSD$";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if.h>
|
2007-04-17 00:35:11 +00:00
|
|
|
#include <net/if_lagg.h>
|
2014-10-05 02:37:01 +00:00
|
|
|
#include <net/ieee8023ad_lacp.h>
|
2007-04-10 00:27:25 +00:00
|
|
|
#include <net/route.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "ifconfig.h"
|
|
|
|
|
2007-07-05 09:18:57 +00:00
|
|
|
char lacpbuf[120]; /* LACP peer '[(a,a,a),(p,p,p)]' */
|
|
|
|
|
2007-04-10 00:27:25 +00:00
|
|
|
static void
|
2007-04-17 00:35:11 +00:00
|
|
|
setlaggport(const char *val, int d, int s, const struct afswtch *afp)
|
2007-04-10 00:27:25 +00:00
|
|
|
{
|
2007-04-17 00:35:11 +00:00
|
|
|
struct lagg_reqport rp;
|
2007-04-10 00:27:25 +00:00
|
|
|
|
|
|
|
bzero(&rp, sizeof(rp));
|
|
|
|
strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname));
|
|
|
|
strlcpy(rp.rp_portname, val, sizeof(rp.rp_portname));
|
|
|
|
|
2012-05-28 12:13:04 +00:00
|
|
|
/* Don't choke if the port is already in this lagg. */
|
|
|
|
if (ioctl(s, SIOCSLAGGPORT, &rp) && errno != EEXIST)
|
2007-04-17 00:35:11 +00:00
|
|
|
err(1, "SIOCSLAGGPORT");
|
2007-04-10 00:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-04-17 00:35:11 +00:00
|
|
|
unsetlaggport(const char *val, int d, int s, const struct afswtch *afp)
|
2007-04-10 00:27:25 +00:00
|
|
|
{
|
2007-04-17 00:35:11 +00:00
|
|
|
struct lagg_reqport rp;
|
2007-04-10 00:27:25 +00:00
|
|
|
|
|
|
|
bzero(&rp, sizeof(rp));
|
|
|
|
strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname));
|
|
|
|
strlcpy(rp.rp_portname, val, sizeof(rp.rp_portname));
|
|
|
|
|
2007-04-17 00:35:11 +00:00
|
|
|
if (ioctl(s, SIOCSLAGGDELPORT, &rp))
|
|
|
|
err(1, "SIOCSLAGGDELPORT");
|
2007-04-10 00:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-04-17 00:35:11 +00:00
|
|
|
setlaggproto(const char *val, int d, int s, const struct afswtch *afp)
|
2007-04-10 00:27:25 +00:00
|
|
|
{
|
2007-06-12 10:07:57 +00:00
|
|
|
struct lagg_protos lpr[] = LAGG_PROTOS;
|
2007-04-17 00:35:11 +00:00
|
|
|
struct lagg_reqall ra;
|
2007-04-10 00:27:25 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
bzero(&ra, sizeof(ra));
|
2007-04-17 00:35:11 +00:00
|
|
|
ra.ra_proto = LAGG_PROTO_MAX;
|
2007-04-10 00:27:25 +00:00
|
|
|
|
2014-10-01 21:37:32 +00:00
|
|
|
for (i = 0; i < nitems(lpr); i++) {
|
2007-06-12 10:07:57 +00:00
|
|
|
if (strcmp(val, lpr[i].lpr_name) == 0) {
|
|
|
|
ra.ra_proto = lpr[i].lpr_proto;
|
2007-04-10 00:27:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-04-17 00:35:11 +00:00
|
|
|
if (ra.ra_proto == LAGG_PROTO_MAX)
|
|
|
|
errx(1, "Invalid aggregation protocol: %s", val);
|
2007-04-10 00:27:25 +00:00
|
|
|
|
|
|
|
strlcpy(ra.ra_ifname, name, sizeof(ra.ra_ifname));
|
2007-04-17 00:35:11 +00:00
|
|
|
if (ioctl(s, SIOCSLAGG, &ra) != 0)
|
|
|
|
err(1, "SIOCSLAGG");
|
2007-04-10 00:27:25 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 21:37:32 +00:00
|
|
|
static void
|
|
|
|
setlaggflowidshift(const char *val, int d, int s, const struct afswtch *afp)
|
|
|
|
{
|
2014-10-02 20:01:13 +00:00
|
|
|
struct lagg_reqopts ro;
|
2014-10-01 21:37:32 +00:00
|
|
|
|
2014-10-02 20:01:13 +00:00
|
|
|
bzero(&ro, sizeof(ro));
|
|
|
|
ro.ro_opts = LAGG_OPT_FLOWIDSHIFT;
|
|
|
|
strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
|
|
|
|
ro.ro_flowid_shift = (int)strtol(val, NULL, 10);
|
|
|
|
if (ro.ro_flowid_shift & ~LAGG_OPT_FLOWIDSHIFT_MASK)
|
2014-10-01 21:37:32 +00:00
|
|
|
errx(1, "Invalid flowid_shift option: %s", val);
|
|
|
|
|
2014-10-02 20:01:13 +00:00
|
|
|
if (ioctl(s, SIOCSLAGGOPTS, &ro) != 0)
|
|
|
|
err(1, "SIOCSLAGGOPTS");
|
2014-10-01 21:37:32 +00:00
|
|
|
}
|
|
|
|
|
2016-01-23 04:18:44 +00:00
|
|
|
static void
|
|
|
|
setlaggrr_limit(const char *val, int d, int s, const struct afswtch *afp)
|
|
|
|
{
|
|
|
|
struct lagg_reqopts ro;
|
|
|
|
|
|
|
|
bzero(&ro, sizeof(ro));
|
|
|
|
strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
|
|
|
|
ro.ro_bkt = (int)strtol(val, NULL, 10);
|
|
|
|
|
|
|
|
if (ioctl(s, SIOCSLAGGOPTS, &ro) != 0)
|
|
|
|
err(1, "SIOCSLAGG");
|
|
|
|
}
|
|
|
|
|
2014-10-01 21:37:32 +00:00
|
|
|
static void
|
|
|
|
setlaggsetopt(const char *val, int d, int s, const struct afswtch *afp)
|
|
|
|
{
|
2014-10-02 20:01:13 +00:00
|
|
|
struct lagg_reqopts ro;
|
2014-10-01 21:37:32 +00:00
|
|
|
|
2014-10-02 20:01:13 +00:00
|
|
|
bzero(&ro, sizeof(ro));
|
|
|
|
ro.ro_opts = d;
|
|
|
|
switch (ro.ro_opts) {
|
2014-10-01 21:37:32 +00:00
|
|
|
case LAGG_OPT_USE_FLOWID:
|
|
|
|
case -LAGG_OPT_USE_FLOWID:
|
|
|
|
case LAGG_OPT_LACP_STRICT:
|
|
|
|
case -LAGG_OPT_LACP_STRICT:
|
|
|
|
case LAGG_OPT_LACP_TXTEST:
|
|
|
|
case -LAGG_OPT_LACP_TXTEST:
|
|
|
|
case LAGG_OPT_LACP_RXTEST:
|
|
|
|
case -LAGG_OPT_LACP_RXTEST:
|
2015-08-12 20:21:04 +00:00
|
|
|
case LAGG_OPT_LACP_TIMEOUT:
|
|
|
|
case -LAGG_OPT_LACP_TIMEOUT:
|
2014-10-01 21:37:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err(1, "Invalid lagg option");
|
|
|
|
}
|
2014-10-02 20:01:13 +00:00
|
|
|
strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
|
2014-10-01 21:37:32 +00:00
|
|
|
|
2014-10-02 20:01:13 +00:00
|
|
|
if (ioctl(s, SIOCSLAGGOPTS, &ro) != 0)
|
|
|
|
err(1, "SIOCSLAGGOPTS");
|
2014-10-01 21:37:32 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 22:58:13 +00:00
|
|
|
static void
|
|
|
|
setlagghash(const char *val, int d, int s, const struct afswtch *afp)
|
|
|
|
{
|
|
|
|
struct lagg_reqflags rf;
|
|
|
|
char *str, *tmp, *tok;
|
|
|
|
|
|
|
|
|
|
|
|
rf.rf_flags = 0;
|
|
|
|
str = tmp = strdup(val);
|
|
|
|
while ((tok = strsep(&tmp, ",")) != NULL) {
|
|
|
|
if (strcmp(tok, "l2") == 0)
|
|
|
|
rf.rf_flags |= LAGG_F_HASHL2;
|
|
|
|
else if (strcmp(tok, "l3") == 0)
|
|
|
|
rf.rf_flags |= LAGG_F_HASHL3;
|
|
|
|
else if (strcmp(tok, "l4") == 0)
|
|
|
|
rf.rf_flags |= LAGG_F_HASHL4;
|
2013-04-25 16:34:04 +00:00
|
|
|
else
|
2012-03-06 22:58:13 +00:00
|
|
|
errx(1, "Invalid lagghash option: %s", tok);
|
|
|
|
}
|
|
|
|
free(str);
|
|
|
|
if (rf.rf_flags == 0)
|
|
|
|
errx(1, "No lagghash options supplied");
|
|
|
|
|
|
|
|
strlcpy(rf.rf_ifname, name, sizeof(rf.rf_ifname));
|
|
|
|
if (ioctl(s, SIOCSLAGGHASH, &rf))
|
|
|
|
err(1, "SIOCSLAGGHASH");
|
|
|
|
}
|
|
|
|
|
2007-07-05 09:18:57 +00:00
|
|
|
static char *
|
|
|
|
lacp_format_mac(const uint8_t *mac, char *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
snprintf(buf, buflen, "%02X-%02X-%02X-%02X-%02X-%02X",
|
|
|
|
(int)mac[0], (int)mac[1], (int)mac[2], (int)mac[3],
|
|
|
|
(int)mac[4], (int)mac[5]);
|
|
|
|
|
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
lacp_format_peer(struct lacp_opreq *req, const char *sep)
|
|
|
|
{
|
|
|
|
char macbuf1[20];
|
|
|
|
char macbuf2[20];
|
|
|
|
|
|
|
|
snprintf(lacpbuf, sizeof(lacpbuf),
|
|
|
|
"[(%04X,%s,%04X,%04X,%04X),%s(%04X,%s,%04X,%04X,%04X)]",
|
|
|
|
req->actor_prio,
|
|
|
|
lacp_format_mac(req->actor_mac, macbuf1, sizeof(macbuf1)),
|
|
|
|
req->actor_key, req->actor_portprio, req->actor_portno, sep,
|
|
|
|
req->partner_prio,
|
|
|
|
lacp_format_mac(req->partner_mac, macbuf2, sizeof(macbuf2)),
|
|
|
|
req->partner_key, req->partner_portprio, req->partner_portno);
|
|
|
|
|
|
|
|
return(lacpbuf);
|
|
|
|
}
|
|
|
|
|
2007-04-10 00:27:25 +00:00
|
|
|
static void
|
2007-04-17 00:35:11 +00:00
|
|
|
lagg_status(int s)
|
2007-04-10 00:27:25 +00:00
|
|
|
{
|
2007-06-12 10:07:57 +00:00
|
|
|
struct lagg_protos lpr[] = LAGG_PROTOS;
|
2007-04-17 00:35:11 +00:00
|
|
|
struct lagg_reqport rp, rpbuf[LAGG_MAX_PORTS];
|
|
|
|
struct lagg_reqall ra;
|
2014-10-02 20:01:13 +00:00
|
|
|
struct lagg_reqopts ro;
|
2012-03-06 22:58:13 +00:00
|
|
|
struct lagg_reqflags rf;
|
2007-07-05 09:18:57 +00:00
|
|
|
struct lacp_opreq *lp;
|
2007-04-10 00:27:25 +00:00
|
|
|
const char *proto = "<unknown>";
|
|
|
|
int i, isport = 0;
|
|
|
|
|
|
|
|
bzero(&rp, sizeof(rp));
|
|
|
|
bzero(&ra, sizeof(ra));
|
2014-10-02 20:01:13 +00:00
|
|
|
bzero(&ro, sizeof(ro));
|
2007-04-10 00:27:25 +00:00
|
|
|
|
|
|
|
strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname));
|
|
|
|
strlcpy(rp.rp_portname, name, sizeof(rp.rp_portname));
|
|
|
|
|
2007-04-17 00:35:11 +00:00
|
|
|
if (ioctl(s, SIOCGLAGGPORT, &rp) == 0)
|
2007-04-10 00:27:25 +00:00
|
|
|
isport = 1;
|
|
|
|
|
|
|
|
strlcpy(ra.ra_ifname, name, sizeof(ra.ra_ifname));
|
|
|
|
ra.ra_size = sizeof(rpbuf);
|
|
|
|
ra.ra_port = rpbuf;
|
|
|
|
|
2014-10-02 20:01:13 +00:00
|
|
|
strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
|
|
|
|
ioctl(s, SIOCGLAGGOPTS, &ro);
|
|
|
|
|
2012-03-06 22:58:13 +00:00
|
|
|
strlcpy(rf.rf_ifname, name, sizeof(rf.rf_ifname));
|
|
|
|
if (ioctl(s, SIOCGLAGGFLAGS, &rf) != 0)
|
|
|
|
rf.rf_flags = 0;
|
|
|
|
|
2007-04-17 00:35:11 +00:00
|
|
|
if (ioctl(s, SIOCGLAGG, &ra) == 0) {
|
2007-07-05 09:18:57 +00:00
|
|
|
lp = (struct lacp_opreq *)&ra.ra_lacpreq;
|
|
|
|
|
2014-10-01 21:37:32 +00:00
|
|
|
for (i = 0; i < nitems(lpr); i++) {
|
2007-06-12 10:07:57 +00:00
|
|
|
if (ra.ra_proto == lpr[i].lpr_proto) {
|
|
|
|
proto = lpr[i].lpr_name;
|
2007-04-10 00:27:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-05 09:18:57 +00:00
|
|
|
printf("\tlaggproto %s", proto);
|
2012-03-06 22:58:13 +00:00
|
|
|
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 = ",";
|
|
|
|
}
|
|
|
|
}
|
2007-04-10 00:27:25 +00:00
|
|
|
if (isport)
|
2007-04-17 00:35:11 +00:00
|
|
|
printf(" laggdev %s", rp.rp_ifname);
|
2007-04-10 00:27:25 +00:00
|
|
|
putchar('\n');
|
2014-10-01 21:37:32 +00:00
|
|
|
if (verbose) {
|
|
|
|
printf("\tlagg options:\n");
|
2014-10-05 02:37:01 +00:00
|
|
|
printb("\t\tflags", ro.ro_opts, LAGG_OPT_BITS);
|
|
|
|
putchar('\n');
|
2014-10-02 20:01:13 +00:00
|
|
|
printf("\t\tflowid_shift: %d\n", ro.ro_flowid_shift);
|
2016-01-23 04:18:44 +00:00
|
|
|
if (ra.ra_proto == LAGG_PROTO_ROUNDROBIN)
|
|
|
|
printf("\t\trr_limit: %d\n", ro.ro_bkt);
|
2014-10-01 21:37:32 +00:00
|
|
|
printf("\tlagg statistics:\n");
|
2014-10-02 20:01:13 +00:00
|
|
|
printf("\t\tactive ports: %d\n", ro.ro_active);
|
|
|
|
printf("\t\tflapping: %u\n", ro.ro_flapping);
|
2014-10-01 21:37:32 +00:00
|
|
|
if (ra.ra_proto == LAGG_PROTO_LACP) {
|
|
|
|
printf("\tlag id: %s\n",
|
|
|
|
lacp_format_peer(lp, "\n\t\t "));
|
|
|
|
}
|
|
|
|
}
|
2007-04-10 00:27:25 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ra.ra_ports; i++) {
|
2007-07-05 09:18:57 +00:00
|
|
|
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)
|
2014-10-05 02:37:01 +00:00
|
|
|
printb(" state", lp->actor_state,
|
|
|
|
LACP_STATE_BITS);
|
2007-04-10 00:27:25 +00:00
|
|
|
putchar('\n');
|
2007-07-05 09:18:57 +00:00
|
|
|
if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
|
|
|
|
printf("\t\t%s\n",
|
|
|
|
lacp_format_peer(lp, "\n\t\t "));
|
2007-04-10 00:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (0 /* XXX */) {
|
2007-04-17 00:35:11 +00:00
|
|
|
printf("\tsupported aggregation protocols:\n");
|
2016-04-19 04:42:34 +00:00
|
|
|
for (i = 0; i < nitems(lpr); i++)
|
2007-06-12 10:07:57 +00:00
|
|
|
printf("\t\tlaggproto %s\n", lpr[i].lpr_name);
|
2007-04-10 00:27:25 +00:00
|
|
|
}
|
2009-04-30 14:31:52 +00:00
|
|
|
}
|
2007-04-10 00:27:25 +00:00
|
|
|
}
|
|
|
|
|
2007-04-17 00:35:11 +00:00
|
|
|
static struct cmd lagg_cmds[] = {
|
|
|
|
DEF_CMD_ARG("laggport", setlaggport),
|
|
|
|
DEF_CMD_ARG("-laggport", unsetlaggport),
|
|
|
|
DEF_CMD_ARG("laggproto", setlaggproto),
|
2012-03-06 22:58:13 +00:00
|
|
|
DEF_CMD_ARG("lagghash", setlagghash),
|
2014-10-01 21:37:32 +00:00
|
|
|
DEF_CMD("use_flowid", LAGG_OPT_USE_FLOWID, setlaggsetopt),
|
|
|
|
DEF_CMD("-use_flowid", -LAGG_OPT_USE_FLOWID, setlaggsetopt),
|
|
|
|
DEF_CMD("lacp_strict", LAGG_OPT_LACP_STRICT, setlaggsetopt),
|
|
|
|
DEF_CMD("-lacp_strict", -LAGG_OPT_LACP_STRICT, setlaggsetopt),
|
|
|
|
DEF_CMD("lacp_txtest", LAGG_OPT_LACP_TXTEST, setlaggsetopt),
|
|
|
|
DEF_CMD("-lacp_txtest", -LAGG_OPT_LACP_TXTEST, setlaggsetopt),
|
|
|
|
DEF_CMD("lacp_rxtest", LAGG_OPT_LACP_RXTEST, setlaggsetopt),
|
|
|
|
DEF_CMD("-lacp_rxtest", -LAGG_OPT_LACP_RXTEST, setlaggsetopt),
|
2015-08-12 20:21:04 +00:00
|
|
|
DEF_CMD("lacp_fast_timeout", LAGG_OPT_LACP_TIMEOUT, setlaggsetopt),
|
|
|
|
DEF_CMD("-lacp_fast_timeout", -LAGG_OPT_LACP_TIMEOUT, setlaggsetopt),
|
2014-10-01 21:37:32 +00:00
|
|
|
DEF_CMD_ARG("flowid_shift", setlaggflowidshift),
|
2016-01-23 04:18:44 +00:00
|
|
|
DEF_CMD_ARG("rr_limit", setlaggrr_limit),
|
2007-04-10 00:27:25 +00:00
|
|
|
};
|
2007-04-17 00:35:11 +00:00
|
|
|
static struct afswtch af_lagg = {
|
|
|
|
.af_name = "af_lagg",
|
2007-04-10 00:27:25 +00:00
|
|
|
.af_af = AF_UNSPEC,
|
2007-04-17 00:35:11 +00:00
|
|
|
.af_other_status = lagg_status,
|
2007-04-10 00:27:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static __constructor void
|
2007-04-17 00:35:11 +00:00
|
|
|
lagg_ctor(void)
|
2007-04-10 00:27:25 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2015-09-27 07:51:18 +00:00
|
|
|
for (i = 0; i < nitems(lagg_cmds); i++)
|
2007-04-17 00:35:11 +00:00
|
|
|
cmd_register(&lagg_cmds[i]);
|
|
|
|
af_register(&af_lagg);
|
2007-04-10 00:27:25 +00:00
|
|
|
}
|