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