From: Stephen Hemminger Date: Fri, 14 Mar 2008 22:30:03 +0000 (-0700) Subject: IP link state show enhancements X-Git-Tag: v2.6.25~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d866ba2650d424faca3ea1c3fc89ba519019998;p=thirdparty%2Fiproute2.git IP link state show enhancements Show operational state (carrier), as well as fixing functions to be static and use similar API. --- diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 0a34ace21..59c71c83c 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -114,7 +115,20 @@ void print_link_flags(FILE *fp, unsigned flags, unsigned mdown) fprintf(fp, "> "); } -void print_queuelen(char *name) +static const char *oper_states[] = { + "UNKNOWN", "NOTPRESENT", "DOWN", "LOWERLAYERDOWN", + "TESTING", "DORMANT", "UP" +}; + +static void print_operstate(FILE *f, __u8 state) +{ + if (state >= sizeof(oper_states)/sizeof(oper_states[0])) + fprintf(f, "state %#x ", state); + else + fprintf(f, "state %s ", oper_states[state]); +} + +static void print_queuelen(FILE *f, const char *name) { struct ifreq ifr; int s; @@ -126,14 +140,14 @@ void print_queuelen(char *name) memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, name); if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) { - perror("SIOCGIFXQLEN"); + fprintf(f, "ioctl(SIOCGIFXQLEN) failed: %s\n", strerror(errno)); close(s); return; } close(s); if (ifr.ifr_qlen) - printf("qlen %d", ifr.ifr_qlen); + fprintf(f, "qlen %d", ifr.ifr_qlen); } static void print_linktype(FILE *fp, struct rtattr *tb) @@ -233,8 +247,11 @@ int print_linkinfo(const struct sockaddr_nl *who, fprintf(fp, "master %s ", ll_idx_n2a(*(int*)RTA_DATA(tb[IFLA_MASTER]), b1)); } #endif + if (tb[IFLA_OPERSTATE]) + print_operstate(fp, *(__u8 *)RTA_DATA(tb[IFLA_OPERSTATE])); + if (filter.showqueue) - print_queuelen((char*)RTA_DATA(tb[IFLA_IFNAME])); + print_queuelen(fp, (char*)RTA_DATA(tb[IFLA_IFNAME])); if (!filter.family || filter.family == AF_PACKET) { SPRINT_BUF(b1); @@ -514,7 +531,7 @@ struct nlmsg_list struct nlmsghdr h; }; -int print_selected_addrinfo(int ifindex, struct nlmsg_list *ainfo, FILE *fp) +static int print_selected_addrinfo(int ifindex, struct nlmsg_list *ainfo, FILE *fp) { for ( ;ainfo ; ainfo = ainfo->next) { struct nlmsghdr *n = &ainfo->h; @@ -557,7 +574,7 @@ static int store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, return 0; } -int ipaddr_list_or_flush(int argc, char **argv, int flush) +static int ipaddr_list_or_flush(int argc, char **argv, int flush) { struct nlmsg_list *linfo = NULL; struct nlmsg_list *ainfo = NULL; @@ -795,7 +812,7 @@ void ipaddr_reset_filter(int oneline) filter.oneline = oneline; } -int default_scope(inet_prefix *lcl) +static int default_scope(inet_prefix *lcl) { if (lcl->family == AF_INET) { if (lcl->bytelen >= 1 && *(__u8*)&lcl->data == 127) @@ -804,7 +821,7 @@ int default_scope(inet_prefix *lcl) return 0; } -int ipaddr_modify(int cmd, int flags, int argc, char **argv) +static int ipaddr_modify(int cmd, int flags, int argc, char **argv) { struct { struct nlmsghdr n;