1 /* $NetBSD: ieee8023ad_lacp_debug.c,v 1.4 2005/12/11 12:24:54 christos Exp $ */
4 * Copyright (c)2005 YAMAMOTO Takashi,
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: ieee8023ad_lacp_debug.c,v 1.4 2005/12/11 12:24:54 christos Exp $");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/callout.h>
36 #include <machine/stdarg.h>
39 #include <net/if_ether.h>
41 #include <net/agr/ieee8023_slowprotocols.h>
42 #include <net/agr/ieee8023_tlv.h>
43 #include <net/agr/ieee8023ad_lacp.h>
44 #include <net/agr/ieee8023ad_lacp_impl.h>
45 #include <net/agr/ieee8023ad_lacp_debug.h>
47 #if defined(LACP_DEBUG)
49 #endif /* defined(LACP_DEBUG) */
52 lacp_format_mac(const uint8_t *mac
, char *buf
, size_t buflen
)
55 snprintf(buf
, buflen
, "%02X-%02X-%02X-%02X-%02X-%02X",
67 lacp_format_systemid(const struct lacp_systemid
*sysid
,
68 char *buf
, size_t buflen
)
70 char macbuf
[LACP_MACSTR_MAX
+1];
72 snprintf(buf
, buflen
, "%04X,%s",
73 be16toh(sysid
->lsi_prio
),
74 lacp_format_mac(sysid
->lsi_mac
, macbuf
, sizeof(macbuf
)));
80 lacp_format_portid(const struct lacp_portid
*portid
, char *buf
, size_t buflen
)
83 snprintf(buf
, buflen
, "%04X,%04X",
84 be16toh(portid
->lpi_prio
),
85 be16toh(portid
->lpi_portno
));
91 lacp_format_partner(const struct lacp_peerinfo
*peer
, char *buf
, size_t buflen
)
93 char sysid
[LACP_SYSTEMIDSTR_MAX
+1];
94 char portid
[LACP_PORTIDSTR_MAX
+1];
96 snprintf(buf
, buflen
, "(%s,%04X,%s)",
97 lacp_format_systemid(&peer
->lip_systemid
, sysid
, sizeof(sysid
)),
98 be16toh(peer
->lip_key
),
99 lacp_format_portid(&peer
->lip_portid
, portid
, sizeof(portid
)));
105 lacp_format_lagid(const struct lacp_peerinfo
*a
,
106 const struct lacp_peerinfo
*b
, char *buf
, size_t buflen
)
108 char astr
[LACP_PARTNERSTR_MAX
+1];
109 char bstr
[LACP_PARTNERSTR_MAX
+1];
113 * there's a convention to display small numbered peer
117 if (lacp_compare_peerinfo(a
, b
) > 0) {
118 const struct lacp_peerinfo
*t
;
126 snprintf(buf
, buflen
, "[%s,%s]",
127 lacp_format_partner(a
, astr
, sizeof(astr
)),
128 lacp_format_partner(b
, bstr
, sizeof(bstr
)));
134 lacp_format_lagid_aggregator(const struct lacp_aggregator
*la
,
135 char *buf
, size_t buflen
)
142 return lacp_format_lagid(&la
->la_actor
, &la
->la_partner
, buf
, buflen
);
146 lacp_format_state(uint8_t state
, char *buf
, size_t buflen
)
148 static const char lacp_state_bits
[] = LACP_STATE_BITS
;
150 snprintb(buf
, buflen
, lacp_state_bits
, state
);
156 lacp_dump_lacpdu(const struct lacpdu
*du
)
158 char buf
[LACP_PARTNERSTR_MAX
+1];
159 char buf2
[LACP_STATESTR_MAX
+1];
162 lacp_format_partner(&du
->ldu_actor
, buf
, sizeof(buf
)));
163 printf("actor.state=%s\n",
164 lacp_format_state(du
->ldu_actor
.lip_state
, buf2
, sizeof(buf2
)));
165 printf("partner=%s\n",
166 lacp_format_partner(&du
->ldu_partner
, buf
, sizeof(buf
)));
167 printf("partner.state=%s\n",
168 lacp_format_state(du
->ldu_partner
.lip_state
, buf2
, sizeof(buf2
)));
170 printf("maxdelay=%d\n", be16toh(du
->ldu_collector
.lci_maxdelay
));
173 #if defined(LACP_DEBUG)
174 #include <net/agr/if_agrvar_impl.h>
177 lacp_dprintf(const struct lacp_port
*lp
, const char *fmt
, ...)
181 if (lacpdebug
== 0) {
186 printf("%s: ", lp
->lp_agrport
->port_ifp
->if_xname
);