1/*
2 * $Id: brctl_disp.c,v 1.1.1.1 2008/10/15 03:28:31 james26_jang Exp $
3 *
4 * Copyright (C) 2000 Lennert Buytenhek
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <sys/time.h>
24#include "libbridge.h"
25#include "brctl.h"
26
27void br_dump_bridge_id(unsigned char *x)
28{
29	printf("%.2x%.2x.%.2x%.2x%.2x%.2x%.2x%.2x", x[0], x[1], x[2], x[3],
30	       x[4], x[5], x[6], x[7]);
31}
32
33void br_show_timer(struct timeval *tv)
34{
35	printf("%4i.%.2i", (int)tv->tv_sec, (int)tv->tv_usec/10000);
36}
37
38void br_dump_port_info(struct port *p)
39{
40	char ifname[IFNAMSIZ];
41	struct port_info *pi;
42
43	pi = &p->info;
44
45	printf("%s (%i)\n", if_indextoname(p->ifindex, ifname), p->index);
46	printf(" port id\t\t%.4x\t\t\t", pi->port_id);
47	printf("state\t\t\t%s\n", br_get_state_name(pi->state));
48	printf(" designated root\t");
49	br_dump_bridge_id((unsigned char *)&pi->designated_root);
50	printf("\tpath cost\t\t%4i\n", pi->path_cost);
51
52	printf(" designated bridge\t");
53	br_dump_bridge_id((unsigned char *)&pi->designated_bridge);
54	printf("\tmessage age timer\t");
55	br_show_timer(&pi->message_age_timer_value);
56	printf("\n designated port\t%.4x", pi->designated_port);
57	printf("\t\t\tforward delay timer\t");
58	br_show_timer(&pi->forward_delay_timer_value);
59	printf("\n designated cost\t%4i", pi->designated_cost);
60	printf("\t\t\thold timer\t\t");
61	br_show_timer(&pi->hold_timer_value);
62	printf("\n flags\t\t\t");
63	if (pi->config_pending)
64		printf("CONFIG_PENDING ");
65	if (pi->top_change_ack)
66		printf("TOPOLOGY_CHANGE_ACK ");
67	printf("\n");
68	printf("\n");
69}
70
71void br_dump_info(struct bridge *br)
72{
73	struct bridge_info *bri;
74	struct port *p;
75
76	bri = &br->info;
77
78	printf("%s\n", br->ifname);
79	if (!bri->stp_enabled) {
80		printf("\tSTP disabled\n");
81		return;
82	}
83
84	printf(" bridge id\t\t");
85	br_dump_bridge_id((unsigned char *)&bri->bridge_id);
86	printf("\n designated root\t");
87	br_dump_bridge_id((unsigned char *)&bri->designated_root);
88	printf("\n root port\t\t%4i\t\t\t", bri->root_port);
89	printf("path cost\t\t%4i\n", bri->root_path_cost);
90	printf(" max age\t\t");
91	br_show_timer(&bri->max_age);
92	printf("\t\t\tbridge max age\t\t");
93	br_show_timer(&bri->bridge_max_age);
94	printf("\n hello time\t\t");
95	br_show_timer(&bri->hello_time);
96	printf("\t\t\tbridge hello time\t");
97	br_show_timer(&bri->bridge_hello_time);
98	printf("\n forward delay\t\t");
99	br_show_timer(&bri->forward_delay);
100	printf("\t\t\tbridge forward delay\t");
101	br_show_timer(&bri->bridge_forward_delay);
102	printf("\n ageing time\t\t");
103	br_show_timer(&bri->ageing_time);
104	printf("\t\t\tgc interval\t\t");
105	br_show_timer(&bri->gc_interval);
106	printf("\n hello timer\t\t");
107	br_show_timer(&bri->hello_timer_value);
108	printf("\t\t\ttcn timer\t\t");
109	br_show_timer(&bri->tcn_timer_value);
110	printf("\n topology change timer\t");
111	br_show_timer(&bri->topology_change_timer_value);
112	printf("\t\t\tgc timer\t\t");
113	br_show_timer(&bri->gc_timer_value);
114	printf("\n flags\t\t\t");
115	if (bri->topology_change)
116		printf("TOPOLOGY_CHANGE ");
117	if (bri->topology_change_detected)
118		printf("TOPOLOGY_CHANGE_DETECTED ");
119	printf("\n");
120	printf("\n");
121	printf("\n");
122
123	p = br->firstport;
124	while (p != NULL) {
125		br_dump_port_info(p);
126		p = p->next;
127	}
128}
129