ieee8023ad_lacp_debug.c revision 1.2 1 /* $NetBSD: ieee8023ad_lacp_debug.c,v 1.2 2005/06/01 11:25:01 yamt Exp $ */
2
3 /*-
4 * Copyright (c)2005 YAMAMOTO Takashi,
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
15 *
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
26 * SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: ieee8023ad_lacp_debug.c,v 1.2 2005/06/01 11:25:01 yamt Exp $");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34
35 #include <machine/stdarg.h>
36
37 #include <net/if.h>
38 #include <net/if_ether.h>
39
40 #include <net/agr/ieee8023_slowprotocols.h>
41 #include <net/agr/ieee8023_tlv.h>
42 #include <net/agr/ieee8023ad_lacp.h>
43 #include <net/agr/ieee8023ad_lacp_impl.h>
44 #include <net/agr/ieee8023ad_lacp_debug.h>
45
46 #if defined(LACP_DEBUG)
47 int lacpdebug = 0;
48 #endif /* defined(LACP_DEBUG) */
49
50 const char *
51 lacp_format_mac(const uint8_t *mac, char *buf, size_t buflen)
52 {
53
54 snprintf(buf, buflen, "%02X-%02X-%02X-%02X-%02X-%02X",
55 (int)mac[0],
56 (int)mac[1],
57 (int)mac[2],
58 (int)mac[3],
59 (int)mac[4],
60 (int)mac[5]);
61
62 return buf;
63 }
64
65 const char *
66 lacp_format_systemid(const struct lacp_systemid *sysid,
67 char *buf, size_t buflen)
68 {
69 char macbuf[LACP_MACSTR_MAX+1];
70
71 snprintf(buf, buflen, "%04X,%s",
72 be16toh(sysid->lsi_prio),
73 lacp_format_mac(sysid->lsi_mac, macbuf, sizeof(macbuf)));
74
75 return buf;
76 }
77
78 const char *
79 lacp_format_portid(const struct lacp_portid *portid, char *buf, size_t buflen)
80 {
81
82 snprintf(buf, buflen, "%04X,%04X",
83 be16toh(portid->lpi_prio),
84 be16toh(portid->lpi_portno));
85
86 return buf;
87 }
88
89 const char *
90 lacp_format_partner(const struct lacp_peerinfo *peer, char *buf, size_t buflen)
91 {
92 char sysid[LACP_SYSTEMIDSTR_MAX+1];
93 char portid[LACP_PORTIDSTR_MAX+1];
94
95 snprintf(buf, buflen, "(%s,%04X,%s)",
96 lacp_format_systemid(&peer->lip_systemid, sysid, sizeof(sysid)),
97 be16toh(peer->lip_key),
98 lacp_format_portid(&peer->lip_portid, portid, sizeof(portid)));
99
100 return buf;
101 }
102
103 const char *
104 lacp_format_lagid(const struct lacp_peerinfo *a,
105 const struct lacp_peerinfo *b, char *buf, size_t buflen)
106 {
107 char astr[LACP_PARTNERSTR_MAX+1];
108 char bstr[LACP_PARTNERSTR_MAX+1];
109
110 #if 0
111 /*
112 * there's a convention to display small numbered peer
113 * in the left.
114 */
115
116 if (lacp_compare_peerinfo(a, b) > 0) {
117 const struct lacp_peerinfo *t;
118
119 t = a;
120 a = b;
121 b = t;
122 }
123 #endif
124
125 snprintf(buf, buflen, "[%s,%s]",
126 lacp_format_partner(a, astr, sizeof(astr)),
127 lacp_format_partner(b, bstr, sizeof(bstr)));
128
129 return buf;
130 }
131
132 const char *
133 lacp_format_lagid_aggregator(const struct lacp_aggregator *la,
134 char *buf, size_t buflen)
135 {
136
137 if (la == NULL) {
138 return "(none)";
139 }
140
141 return lacp_format_lagid(&la->la_actor, &la->la_partner, buf, buflen);
142 }
143
144 const char *
145 lacp_format_state(uint8_t state, char *buf, size_t buflen)
146 {
147 static const char lacp_state_bits[] = LACP_STATE_BITS;
148
149 bitmask_snprintf(state, lacp_state_bits, buf, buflen);
150
151 return buf;
152 }
153
154 void
155 lacp_dump_lacpdu(const struct lacpdu *du)
156 {
157 char buf[LACP_PARTNERSTR_MAX+1];
158 char buf2[LACP_STATESTR_MAX+1];
159
160 printf("actor=%s\n",
161 lacp_format_partner(&du->ldu_actor, buf, sizeof(buf)));
162 printf("actor.state=%s\n",
163 lacp_format_state(du->ldu_actor.lip_state, buf2, sizeof(buf2)));
164 printf("partner=%s\n",
165 lacp_format_partner(&du->ldu_partner, buf, sizeof(buf)));
166 printf("partner.state=%s\n",
167 lacp_format_state(du->ldu_partner.lip_state, buf2, sizeof(buf2)));
168
169 printf("maxdelay=%d\n", be16toh(du->ldu_collector.lci_maxdelay));
170 }
171
172 #if defined(LACP_DEBUG)
173 #include <net/agr/if_agrvar_impl.h>
174
175 void
176 lacp_dprintf(const struct lacp_port *lp, const char *fmt, ...)
177 {
178 va_list va;
179
180 if (lacpdebug == 0) {
181 return;
182 }
183
184 if (lp) {
185 printf("%s: ", lp->lp_agrport->port_ifp->if_xname);
186 }
187
188 va_start(va, fmt);
189 vprintf(fmt, va);
190 va_end(va);
191 }
192 #endif
193