5 static const char rcsid[] =
10 #include <sys/ioctl.h>
11 #include <sys/socket.h>
12 #include <sys/sockio.h>
17 #include <net/ethernet.h>
19 #include <net/if_lagg.h>
20 #include <net/route.h>
32 char lacpbuf[120]; /* LACP peer '[(a,a,a),(p,p,p)]' */
35 setlaggport(const char *val, int d, int s, const struct afswtch *afp)
37 struct lagg_reqport rp;
39 bzero(&rp, sizeof(rp));
40 strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname));
41 strlcpy(rp.rp_portname, val, sizeof(rp.rp_portname));
43 if (ioctl(s, SIOCSLAGGPORT, &rp))
44 err(1, "SIOCSLAGGPORT");
48 unsetlaggport(const char *val, int d, int s, const struct afswtch *afp)
50 struct lagg_reqport rp;
52 bzero(&rp, sizeof(rp));
53 strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname));
54 strlcpy(rp.rp_portname, val, sizeof(rp.rp_portname));
56 if (ioctl(s, SIOCSLAGGDELPORT, &rp))
57 err(1, "SIOCSLAGGDELPORT");
61 setlaggproto(const char *val, int d, int s, const struct afswtch *afp)
63 struct lagg_protos lpr[] = LAGG_PROTOS;
64 struct lagg_reqall ra;
67 bzero(&ra, sizeof(ra));
68 ra.ra_proto = LAGG_PROTO_MAX;
70 for (i = 0; i < (sizeof(lpr) / sizeof(lpr[0])); i++) {
71 if (strcmp(val, lpr[i].lpr_name) == 0) {
72 ra.ra_proto = lpr[i].lpr_proto;
76 if (ra.ra_proto == LAGG_PROTO_MAX)
77 errx(1, "Invalid aggregation protocol: %s", val);
79 strlcpy(ra.ra_ifname, name, sizeof(ra.ra_ifname));
80 if (ioctl(s, SIOCSLAGG, &ra) != 0)
85 lacp_format_mac(const uint8_t *mac, char *buf, size_t buflen)
87 snprintf(buf, buflen, "%02X-%02X-%02X-%02X-%02X-%02X",
88 (int)mac[0], (int)mac[1], (int)mac[2], (int)mac[3],
89 (int)mac[4], (int)mac[5]);
95 lacp_format_peer(struct lacp_opreq *req, const char *sep)
100 snprintf(lacpbuf, sizeof(lacpbuf),
101 "[(%04X,%s,%04X,%04X,%04X),%s(%04X,%s,%04X,%04X,%04X)]",
103 lacp_format_mac(req->actor_mac, macbuf1, sizeof(macbuf1)),
104 req->actor_key, req->actor_portprio, req->actor_portno, sep,
106 lacp_format_mac(req->partner_mac, macbuf2, sizeof(macbuf2)),
107 req->partner_key, req->partner_portprio, req->partner_portno);
115 struct lagg_protos lpr[] = LAGG_PROTOS;
116 struct lagg_reqport rp, rpbuf[LAGG_MAX_PORTS];
117 struct lagg_reqall ra;
118 struct lacp_opreq *lp;
119 const char *proto = "<unknown>";
122 bzero(&rp, sizeof(rp));
123 bzero(&ra, sizeof(ra));
125 strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname));
126 strlcpy(rp.rp_portname, name, sizeof(rp.rp_portname));
128 if (ioctl(s, SIOCGLAGGPORT, &rp) == 0)
131 strlcpy(ra.ra_ifname, name, sizeof(ra.ra_ifname));
132 ra.ra_size = sizeof(rpbuf);
135 if (ioctl(s, SIOCGLAGG, &ra) == 0) {
136 lp = (struct lacp_opreq *)&ra.ra_lacpreq;
138 for (i = 0; i < (sizeof(lpr) / sizeof(lpr[0])); i++) {
139 if (ra.ra_proto == lpr[i].lpr_proto) {
140 proto = lpr[i].lpr_name;
145 printf("\tlaggproto %s", proto);
147 printf(" laggdev %s", rp.rp_ifname);
149 if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
150 printf("\tlag id: %s\n",
151 lacp_format_peer(lp, "\n\t\t "));
153 for (i = 0; i < ra.ra_ports; i++) {
154 lp = (struct lacp_opreq *)&rpbuf[i].rp_lacpreq;
155 printf("\tlaggport: %s ", rpbuf[i].rp_portname);
156 printb("flags", rpbuf[i].rp_flags, LAGG_PORT_BITS);
157 if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
158 printf(" state=%X", lp->actor_state);
160 if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
162 lacp_format_peer(lp, "\n\t\t "));
166 printf("\tsupported aggregation protocols:\n");
167 for (i = 0; i < (sizeof(lpr) / sizeof(lpr[0])); i++)
168 printf("\t\tlaggproto %s\n", lpr[i].lpr_name);
173 static struct cmd lagg_cmds[] = {
174 DEF_CMD_ARG("laggport", setlaggport),
175 DEF_CMD_ARG("-laggport", unsetlaggport),
176 DEF_CMD_ARG("laggproto", setlaggproto),
178 static struct afswtch af_lagg = {
179 .af_name = "af_lagg",
181 .af_other_status = lagg_status,
184 static __constructor void
187 #define N(a) (sizeof(a) / sizeof(a[0]))
190 for (i = 0; i < N(lagg_cmds); i++)
191 cmd_register(&lagg_cmds[i]);
192 af_register(&af_lagg);