1*b1d757bcSAlan Somers /*
2*b1d757bcSAlan Somers * Copyright (c) 1983, 1993
3*b1d757bcSAlan Somers * The Regents of the University of California. All rights reserved.
4*b1d757bcSAlan Somers *
5*b1d757bcSAlan Somers * Redistribution and use in source and binary forms, with or without
6*b1d757bcSAlan Somers * modification, are permitted provided that the following conditions
7*b1d757bcSAlan Somers * are met:
8*b1d757bcSAlan Somers * 1. Redistributions of source code must retain the above copyright
9*b1d757bcSAlan Somers * notice, this list of conditions and the following disclaimer.
10*b1d757bcSAlan Somers * 2. Redistributions in binary form must reproduce the above copyright
11*b1d757bcSAlan Somers * notice, this list of conditions and the following disclaimer in the
12*b1d757bcSAlan Somers * documentation and/or other materials provided with the distribution.
13*b1d757bcSAlan Somers * 3. Neither the name of the University nor the names of its contributors
14*b1d757bcSAlan Somers * may be used to endorse or promote products derived from this software
15*b1d757bcSAlan Somers * without specific prior written permission.
16*b1d757bcSAlan Somers *
17*b1d757bcSAlan Somers * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18*b1d757bcSAlan Somers * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*b1d757bcSAlan Somers * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*b1d757bcSAlan Somers * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21*b1d757bcSAlan Somers * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*b1d757bcSAlan Somers * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*b1d757bcSAlan Somers * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*b1d757bcSAlan Somers * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*b1d757bcSAlan Somers * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*b1d757bcSAlan Somers * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*b1d757bcSAlan Somers * SUCH DAMAGE.
28*b1d757bcSAlan Somers */
29*b1d757bcSAlan Somers #include <sys/param.h>
30*b1d757bcSAlan Somers #include <sys/ioctl.h>
31*b1d757bcSAlan Somers
32*b1d757bcSAlan Somers #include <net/ethernet.h>
33*b1d757bcSAlan Somers #include <net/if.h>
34*b1d757bcSAlan Somers #include <net/if_lagg.h>
35*b1d757bcSAlan Somers #include <net/ieee8023ad_lacp.h>
36*b1d757bcSAlan Somers
37*b1d757bcSAlan Somers #include <assert.h>
38*b1d757bcSAlan Somers #include <errno.h>
39*b1d757bcSAlan Somers #include <stdlib.h>
40*b1d757bcSAlan Somers #include <string.h>
41*b1d757bcSAlan Somers
42*b1d757bcSAlan Somers #include "libifconfig.h"
43*b1d757bcSAlan Somers #include "libifconfig_internal.h"
44*b1d757bcSAlan Somers
45*b1d757bcSAlan Somers /* Internal structure used for allocations and frees */
46*b1d757bcSAlan Somers struct _ifconfig_lagg_status {
47*b1d757bcSAlan Somers struct ifconfig_lagg_status l; /* Must be first */
48*b1d757bcSAlan Somers struct lagg_reqall ra;
49*b1d757bcSAlan Somers struct lagg_reqopts ro;
50*b1d757bcSAlan Somers struct lagg_reqflags rf;
51*b1d757bcSAlan Somers struct lagg_reqport rpbuf[LAGG_MAX_PORTS];
52*b1d757bcSAlan Somers };
53*b1d757bcSAlan Somers
54*b1d757bcSAlan Somers int
ifconfig_lagg_get_laggport_status(ifconfig_handle_t * h,const char * name,struct lagg_reqport * rp)55*b1d757bcSAlan Somers ifconfig_lagg_get_laggport_status(ifconfig_handle_t *h,
56*b1d757bcSAlan Somers const char *name, struct lagg_reqport *rp)
57*b1d757bcSAlan Somers {
58*b1d757bcSAlan Somers strlcpy(rp->rp_ifname, name, sizeof(rp->rp_portname));
59*b1d757bcSAlan Somers strlcpy(rp->rp_portname, name, sizeof(rp->rp_portname));
60*b1d757bcSAlan Somers
61*b1d757bcSAlan Somers return (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGLAGGPORT, rp));
62*b1d757bcSAlan Somers }
63*b1d757bcSAlan Somers
64*b1d757bcSAlan Somers int
ifconfig_lagg_get_lagg_status(ifconfig_handle_t * h,const char * name,struct ifconfig_lagg_status ** lagg_status)65*b1d757bcSAlan Somers ifconfig_lagg_get_lagg_status(ifconfig_handle_t *h,
66*b1d757bcSAlan Somers const char *name, struct ifconfig_lagg_status **lagg_status)
67*b1d757bcSAlan Somers {
68*b1d757bcSAlan Somers struct _ifconfig_lagg_status *ls;
69*b1d757bcSAlan Somers
70*b1d757bcSAlan Somers ls = calloc(1, sizeof(struct _ifconfig_lagg_status));
71*b1d757bcSAlan Somers if (ls == NULL) {
72*b1d757bcSAlan Somers h->error.errtype = OTHER;
73*b1d757bcSAlan Somers h->error.errcode = ENOMEM;
74*b1d757bcSAlan Somers return (-1);
75*b1d757bcSAlan Somers }
76*b1d757bcSAlan Somers ls->l.ra = &ls->ra;
77*b1d757bcSAlan Somers ls->l.ro = &ls->ro;
78*b1d757bcSAlan Somers ls->l.rf = &ls->rf;
79*b1d757bcSAlan Somers *lagg_status = &ls->l;
80*b1d757bcSAlan Somers
81*b1d757bcSAlan Somers ls->ra.ra_port = ls->rpbuf;
82*b1d757bcSAlan Somers ls->ra.ra_size = sizeof(ls->rpbuf);
83*b1d757bcSAlan Somers
84*b1d757bcSAlan Somers strlcpy(ls->ro.ro_ifname, name, sizeof(ls->ro.ro_ifname));
85*b1d757bcSAlan Somers ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGLAGGOPTS, &ls->ro);
86*b1d757bcSAlan Somers
87*b1d757bcSAlan Somers strlcpy(ls->rf.rf_ifname, name, sizeof(ls->rf.rf_ifname));
88*b1d757bcSAlan Somers if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGLAGGFLAGS, &ls->rf) != 0) {
89*b1d757bcSAlan Somers ls->rf.rf_flags = 0;
90*b1d757bcSAlan Somers }
91*b1d757bcSAlan Somers
92*b1d757bcSAlan Somers strlcpy(ls->ra.ra_ifname, name, sizeof(ls->ra.ra_ifname));
93*b1d757bcSAlan Somers if (ifconfig_ioctlwrap(h, AF_LOCAL, SIOCGLAGG, &ls->ra) != 0) {
94*b1d757bcSAlan Somers free(ls);
95*b1d757bcSAlan Somers return (-1);
96*b1d757bcSAlan Somers }
97*b1d757bcSAlan Somers
98*b1d757bcSAlan Somers return (0);
99*b1d757bcSAlan Somers }
100*b1d757bcSAlan Somers
101*b1d757bcSAlan Somers void
ifconfig_lagg_free_lagg_status(struct ifconfig_lagg_status * laggstat)102*b1d757bcSAlan Somers ifconfig_lagg_free_lagg_status(struct ifconfig_lagg_status *laggstat)
103*b1d757bcSAlan Somers {
104*b1d757bcSAlan Somers free(laggstat);
105*b1d757bcSAlan Somers }
106