]>
git.proxmox.com Git - mirror_iproute2.git/blob - bridge/link.c
6 #include <sys/socket.h>
8 #include <netinet/in.h>
10 #include <linux/if_bridge.h>
14 #include "br_common.h"
16 static const char *port_states
[] = {
17 [BR_STATE_DISABLED
] = "disabled",
18 [BR_STATE_LISTENING
] = "listening",
19 [BR_STATE_LEARNING
] = "learning",
20 [BR_STATE_FORWARDING
] = "forwarding",
21 [BR_STATE_BLOCKING
] = "blocking",
24 extern char *if_indextoname (unsigned int __ifindex
, char *__ifname
);
26 static void print_link_flags(FILE *fp
, unsigned flags
)
29 if (flags
& IFF_UP
&& !(flags
& IFF_RUNNING
))
30 fprintf(fp
, "NO-CARRIER%s", flags
? "," : "");
31 flags
&= ~IFF_RUNNING
;
32 #define _PF(f) if (flags&IFF_##f) { \
34 fprintf(fp, #f "%s", flags ? "," : ""); }
55 fprintf(fp
, "%x", flags
);
59 static const char *oper_states
[] = {
60 "UNKNOWN", "NOTPRESENT", "DOWN", "LOWERLAYERDOWN",
61 "TESTING", "DORMANT", "UP"
64 static void print_operstate(FILE *f
, __u8 state
)
66 if (state
>= sizeof(oper_states
)/sizeof(oper_states
[0]))
67 fprintf(f
, "state %#x ", state
);
69 fprintf(f
, "state %s ", oper_states
[state
]);
72 int print_linkinfo(const struct sockaddr_nl
*who
,
73 struct nlmsghdr
*n
, void *arg
)
76 int len
= n
->nlmsg_len
;
77 struct ifinfomsg
*ifi
= NLMSG_DATA(n
);
78 struct rtattr
* tb
[IFLA_MAX
+1];
81 len
-= NLMSG_LENGTH(sizeof(*ifi
));
83 fprintf(stderr
, "Message too short!\n");
87 if (!(ifi
->ifi_family
== AF_BRIDGE
|| ifi
->ifi_family
== AF_UNSPEC
))
90 parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
92 if (tb
[IFLA_IFNAME
] == NULL
) {
93 fprintf(stderr
, "BUG: nil ifname\n");
97 if (n
->nlmsg_type
== RTM_DELLINK
)
98 fprintf(fp
, "Deleted ");
100 fprintf(fp
, "%d: %s ", ifi
->ifi_index
,
101 tb
[IFLA_IFNAME
] ? (char*)RTA_DATA(tb
[IFLA_IFNAME
]) : "<nil>");
103 if (tb
[IFLA_OPERSTATE
])
104 print_operstate(fp
, *(__u8
*)RTA_DATA(tb
[IFLA_OPERSTATE
]));
108 int iflink
= *(int*)RTA_DATA(tb
[IFLA_LINK
]);
111 fprintf(fp
, "@NONE: ");
114 if_indextoname(iflink
, b1
));
120 print_link_flags(fp
, ifi
->ifi_flags
);
123 fprintf(fp
, "mtu %u ", *(int*)RTA_DATA(tb
[IFLA_MTU
]));
125 if (tb
[IFLA_MASTER
]) {
126 fprintf(fp
, "master %s ",
127 if_indextoname(*(int*)RTA_DATA(tb
[IFLA_MASTER
]), b1
));
130 if (tb
[IFLA_PROTINFO
]) {
131 uint8_t state
= *(uint8_t *)RTA_DATA(tb
[IFLA_PROTINFO
]);
132 if (state
<= BR_STATE_BLOCKING
)
133 fprintf(fp
, "state %s", port_states
[state
]);
135 fprintf(fp
, "state (%d)", state
);