Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / net / agr / ieee8023ad_lacp_debug.c
blob9af8114ac56bf597fcb65b6d39c5ae1cb6362f9d
1 /* $NetBSD: ieee8023ad_lacp_debug.c,v 1.4 2005/12/11 12:24:54 christos Exp $ */
3 /*-
4 * Copyright (c)2005 YAMAMOTO Takashi,
5 * All rights reserved.
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.
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.
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>
38 #include <net/if.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)
48 int lacpdebug = 0;
49 #endif /* defined(LACP_DEBUG) */
51 const char *
52 lacp_format_mac(const uint8_t *mac, char *buf, size_t buflen)
55 snprintf(buf, buflen, "%02X-%02X-%02X-%02X-%02X-%02X",
56 (int)mac[0],
57 (int)mac[1],
58 (int)mac[2],
59 (int)mac[3],
60 (int)mac[4],
61 (int)mac[5]);
63 return buf;
66 const char *
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)));
76 return buf;
79 const char *
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));
87 return buf;
90 const char *
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)));
101 return buf;
104 const char *
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];
111 #if 0
113 * there's a convention to display small numbered peer
114 * in the left.
117 if (lacp_compare_peerinfo(a, b) > 0) {
118 const struct lacp_peerinfo *t;
120 t = a;
121 a = b;
122 b = t;
124 #endif
126 snprintf(buf, buflen, "[%s,%s]",
127 lacp_format_partner(a, astr, sizeof(astr)),
128 lacp_format_partner(b, bstr, sizeof(bstr)));
130 return buf;
133 const char *
134 lacp_format_lagid_aggregator(const struct lacp_aggregator *la,
135 char *buf, size_t buflen)
138 if (la == NULL) {
139 return "(none)";
142 return lacp_format_lagid(&la->la_actor, &la->la_partner, buf, buflen);
145 const char *
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);
152 return buf;
155 void
156 lacp_dump_lacpdu(const struct lacpdu *du)
158 char buf[LACP_PARTNERSTR_MAX+1];
159 char buf2[LACP_STATESTR_MAX+1];
161 printf("actor=%s\n",
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>
176 void
177 lacp_dprintf(const struct lacp_port *lp, const char *fmt, ...)
179 va_list va;
181 if (lacpdebug == 0) {
182 return;
185 if (lp) {
186 printf("%s: ", lp->lp_agrport->port_ifp->if_xname);
189 va_start(va, fmt);
190 vprintf(fmt, va);
191 va_end(va);
193 #endif