ieee8023ad_lacp_debug.c revision 1.1.6.2 1 1.1.6.2 kent /* $NetBSD: ieee8023ad_lacp_debug.c,v 1.1.6.2 2005/04/29 11:29:32 kent Exp $ */
2 1.1.6.2 kent
3 1.1.6.2 kent /*-
4 1.1.6.2 kent * Copyright (c)2005 YAMAMOTO Takashi,
5 1.1.6.2 kent * All rights reserved.
6 1.1.6.2 kent *
7 1.1.6.2 kent * Redistribution and use in source and binary forms, with or without
8 1.1.6.2 kent * modification, are permitted provided that the following conditions
9 1.1.6.2 kent * are met:
10 1.1.6.2 kent * 1. Redistributions of source code must retain the above copyright
11 1.1.6.2 kent * notice, this list of conditions and the following disclaimer.
12 1.1.6.2 kent * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.6.2 kent * notice, this list of conditions and the following disclaimer in the
14 1.1.6.2 kent * documentation and/or other materials provided with the distribution.
15 1.1.6.2 kent *
16 1.1.6.2 kent * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.1.6.2 kent * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1.6.2 kent * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1.6.2 kent * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.1.6.2 kent * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1.6.2 kent * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1.6.2 kent * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1.6.2 kent * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1.6.2 kent * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1.6.2 kent * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1.6.2 kent * SUCH DAMAGE.
27 1.1.6.2 kent */
28 1.1.6.2 kent
29 1.1.6.2 kent #include <sys/cdefs.h>
30 1.1.6.2 kent __KERNEL_RCSID(0, "$NetBSD: ieee8023ad_lacp_debug.c,v 1.1.6.2 2005/04/29 11:29:32 kent Exp $");
31 1.1.6.2 kent
32 1.1.6.2 kent #include <sys/param.h>
33 1.1.6.2 kent #include <sys/systm.h>
34 1.1.6.2 kent
35 1.1.6.2 kent #include <machine/stdarg.h>
36 1.1.6.2 kent
37 1.1.6.2 kent #include <net/if.h>
38 1.1.6.2 kent #include <net/if_ether.h>
39 1.1.6.2 kent
40 1.1.6.2 kent #include <net/agr/ieee8023_slowprotocols.h>
41 1.1.6.2 kent #include <net/agr/ieee8023_tlv.h>
42 1.1.6.2 kent #include <net/agr/ieee8023ad_lacp.h>
43 1.1.6.2 kent #include <net/agr/ieee8023ad_lacp_impl.h>
44 1.1.6.2 kent #include <net/agr/ieee8023ad_lacp_debug.h>
45 1.1.6.2 kent
46 1.1.6.2 kent #if defined(LACP_DEBUG)
47 1.1.6.2 kent int lacpdebug = 0;
48 1.1.6.2 kent #endif /* defined(LACP_DEBUG) */
49 1.1.6.2 kent
50 1.1.6.2 kent char *
51 1.1.6.2 kent lacp_format_mac(const uint8_t *mac, char *buf, size_t buflen)
52 1.1.6.2 kent {
53 1.1.6.2 kent
54 1.1.6.2 kent snprintf(buf, buflen, "%02X-%02X-%02X-%02X-%02X-%02X",
55 1.1.6.2 kent (int)mac[0],
56 1.1.6.2 kent (int)mac[1],
57 1.1.6.2 kent (int)mac[2],
58 1.1.6.2 kent (int)mac[3],
59 1.1.6.2 kent (int)mac[4],
60 1.1.6.2 kent (int)mac[5]);
61 1.1.6.2 kent
62 1.1.6.2 kent return buf;
63 1.1.6.2 kent }
64 1.1.6.2 kent
65 1.1.6.2 kent char *
66 1.1.6.2 kent lacp_format_systemid(const struct lacp_systemid *sysid,
67 1.1.6.2 kent char *buf, size_t buflen)
68 1.1.6.2 kent {
69 1.1.6.2 kent char macbuf[LACP_MACSTR_MAX+1];
70 1.1.6.2 kent
71 1.1.6.2 kent snprintf(buf, buflen, "%04X,%s",
72 1.1.6.2 kent be16toh(sysid->lsi_prio),
73 1.1.6.2 kent lacp_format_mac(sysid->lsi_mac, macbuf, sizeof(macbuf)));
74 1.1.6.2 kent
75 1.1.6.2 kent return buf;
76 1.1.6.2 kent }
77 1.1.6.2 kent
78 1.1.6.2 kent char *
79 1.1.6.2 kent lacp_format_portid(const struct lacp_portid *portid, char *buf, size_t buflen)
80 1.1.6.2 kent {
81 1.1.6.2 kent
82 1.1.6.2 kent snprintf(buf, buflen, "%04X,%04X",
83 1.1.6.2 kent be16toh(portid->lpi_prio),
84 1.1.6.2 kent be16toh(portid->lpi_portno));
85 1.1.6.2 kent
86 1.1.6.2 kent return buf;
87 1.1.6.2 kent }
88 1.1.6.2 kent
89 1.1.6.2 kent char *
90 1.1.6.2 kent lacp_format_partner(const struct lacp_peerinfo *peer, char *buf, size_t buflen)
91 1.1.6.2 kent {
92 1.1.6.2 kent char sysid[LACP_SYSTEMIDSTR_MAX+1];
93 1.1.6.2 kent char portid[LACP_PORTIDSTR_MAX+1];
94 1.1.6.2 kent
95 1.1.6.2 kent snprintf(buf, buflen, "(%s,%04X,%s)",
96 1.1.6.2 kent lacp_format_systemid(&peer->lip_systemid, sysid, sizeof(sysid)),
97 1.1.6.2 kent be16toh(peer->lip_key),
98 1.1.6.2 kent lacp_format_portid(&peer->lip_portid, portid, sizeof(portid)));
99 1.1.6.2 kent
100 1.1.6.2 kent return buf;
101 1.1.6.2 kent }
102 1.1.6.2 kent
103 1.1.6.2 kent char *
104 1.1.6.2 kent lacp_format_lagid(const struct lacp_peerinfo *a,
105 1.1.6.2 kent const struct lacp_peerinfo *b, char *buf, size_t buflen)
106 1.1.6.2 kent {
107 1.1.6.2 kent char astr[LACP_PARTNERSTR_MAX+1];
108 1.1.6.2 kent char bstr[LACP_PARTNERSTR_MAX+1];
109 1.1.6.2 kent
110 1.1.6.2 kent #if 0
111 1.1.6.2 kent /*
112 1.1.6.2 kent * there's a convention to display small numbered peer
113 1.1.6.2 kent * in the left.
114 1.1.6.2 kent */
115 1.1.6.2 kent
116 1.1.6.2 kent if (lacp_compare_peerinfo(a, b) > 0) {
117 1.1.6.2 kent const struct lacp_peerinfo *t;
118 1.1.6.2 kent
119 1.1.6.2 kent t = a;
120 1.1.6.2 kent a = b;
121 1.1.6.2 kent b = t;
122 1.1.6.2 kent }
123 1.1.6.2 kent #endif
124 1.1.6.2 kent
125 1.1.6.2 kent snprintf(buf, buflen, "[%s,%s]",
126 1.1.6.2 kent lacp_format_partner(a, astr, sizeof(astr)),
127 1.1.6.2 kent lacp_format_partner(b, bstr, sizeof(bstr)));
128 1.1.6.2 kent
129 1.1.6.2 kent return buf;
130 1.1.6.2 kent }
131 1.1.6.2 kent
132 1.1.6.2 kent char *
133 1.1.6.2 kent lacp_format_lagid_aggregator(const struct lacp_aggregator *la,
134 1.1.6.2 kent char *buf, size_t buflen)
135 1.1.6.2 kent {
136 1.1.6.2 kent
137 1.1.6.2 kent if (la == NULL) {
138 1.1.6.2 kent return "(none)";
139 1.1.6.2 kent }
140 1.1.6.2 kent
141 1.1.6.2 kent return lacp_format_lagid(&la->la_actor, &la->la_partner, buf, buflen);
142 1.1.6.2 kent }
143 1.1.6.2 kent
144 1.1.6.2 kent char *
145 1.1.6.2 kent lacp_format_state(uint8_t state, char *buf, size_t buflen)
146 1.1.6.2 kent {
147 1.1.6.2 kent static const char lacp_state_bits[] = LACP_STATE_BITS;
148 1.1.6.2 kent
149 1.1.6.2 kent bitmask_snprintf(state, lacp_state_bits, buf, buflen);
150 1.1.6.2 kent
151 1.1.6.2 kent return buf;
152 1.1.6.2 kent }
153 1.1.6.2 kent
154 1.1.6.2 kent void
155 1.1.6.2 kent lacp_dump_lacpdu(const struct lacpdu *du)
156 1.1.6.2 kent {
157 1.1.6.2 kent char buf[LACP_PARTNERSTR_MAX+1];
158 1.1.6.2 kent char buf2[LACP_STATESTR_MAX+1];
159 1.1.6.2 kent
160 1.1.6.2 kent printf("actor=%s\n",
161 1.1.6.2 kent lacp_format_partner(&du->ldu_actor, buf, sizeof(buf)));
162 1.1.6.2 kent printf("actor.state=%s\n",
163 1.1.6.2 kent lacp_format_state(du->ldu_actor.lip_state, buf2, sizeof(buf2)));
164 1.1.6.2 kent printf("partner=%s\n",
165 1.1.6.2 kent lacp_format_partner(&du->ldu_partner, buf, sizeof(buf)));
166 1.1.6.2 kent printf("partner.state=%s\n",
167 1.1.6.2 kent lacp_format_state(du->ldu_partner.lip_state, buf2, sizeof(buf2)));
168 1.1.6.2 kent
169 1.1.6.2 kent printf("maxdelay=%d\n", be16toh(du->ldu_collector.lci_maxdelay));
170 1.1.6.2 kent }
171 1.1.6.2 kent
172 1.1.6.2 kent #if defined(LACP_DEBUG)
173 1.1.6.2 kent #include <net/agr/if_agrvar_impl.h>
174 1.1.6.2 kent
175 1.1.6.2 kent void
176 1.1.6.2 kent lacp_dprintf(const struct lacp_port *lp, const char *fmt, ...)
177 1.1.6.2 kent {
178 1.1.6.2 kent va_list va;
179 1.1.6.2 kent
180 1.1.6.2 kent if (lacpdebug == 0) {
181 1.1.6.2 kent return;
182 1.1.6.2 kent }
183 1.1.6.2 kent
184 1.1.6.2 kent if (lp) {
185 1.1.6.2 kent printf("%s: ", lp->lp_agrport->port_ifp->if_xname);
186 1.1.6.2 kent }
187 1.1.6.2 kent
188 1.1.6.2 kent va_start(va, fmt);
189 1.1.6.2 kent vprintf(fmt, va);
190 1.1.6.2 kent va_end(va);
191 1.1.6.2 kent }
192 1.1.6.2 kent #endif
193