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