Index: busybox-1.31.1/networking/interface.c =================================================================== --- busybox-1.31.1.orig/networking/interface.c 2019-06-10 18:50:53.000000000 +0800 +++ busybox-1.31.1/networking/interface.c 2021-03-09 20:59:21.582966502 +0800 @@ -294,6 +294,20 @@ unsigned long rx_dropped; /* no space in linux buffers */ unsigned long tx_dropped; /* no space available in linux */ unsigned long rx_multicast; /* multicast packets received */ + +#ifdef BRCM_CHANGE + /* BRCM change, JIRA 10503 - extended statistics */ + unsigned long tx_multicast_packets; /* multicast packets transmitted */ + unsigned long rx_multicast_bytes; /* multicast bytes recieved */ + unsigned long tx_multicast_bytes; /* multicast bytes transmitted */ + unsigned long rx_unicast_packets; /* unicast packets recieved */ + unsigned long tx_unicast_packets; /* unicast packets transmitted */ + unsigned long rx_broadcast_packets; /* broadcast packets recieved */ + unsigned long tx_broadcast_packets; /* broadcast packets transmitted */ + unsigned long rx_unknown_packets; /* unknown protocol packets recieved */ + /* End BRCM change, JIRA 10503 */ +#endif + unsigned long rx_compressed; unsigned long tx_compressed; unsigned long collisions; @@ -335,6 +349,12 @@ smallint has_ip; smallint statistics_valid; struct user_net_device_stats stats; /* statistics */ + +#ifdef BRCM_CHANGE + /* BRCM change, JIRA 10503 - add statistics formatting*/ + int procnetdev_vsn; /* Format of statistics */ +#endif + #if 0 /* UNUSED */ int keepalive; /* keepalive value for SLIP */ int outfill; /* outfill value for SLIP */ @@ -447,15 +467,33 @@ */ #if INT_MAX == LONG_MAX static const char *const ss_fmt[] = { +#ifdef BRCM_CHANGE + "%n%llu%u%u%u%u%n%n%n%llu%u%u%u%u%u", + "%llu%llu%u%u%u%u%n%n%llu%llu%u%u%u%u%u", + "%llu%llu%u%u%u%u%u%u%llu%llu%u%u%u%u%u%u", + + /* BRCM change, JIRA 10503 - add extended statistics format */ + "%llu%llu%u%u%u%u%u%u%llu%llu%u%u%u%u%u%u%u%u%u%u%u%u%u%u" +#else "%n%llu%u%u%u%u%n%n%n%llu%u%u%u%u%u", "%llu%llu%u%u%u%u%n%n%llu%llu%u%u%u%u%u", "%llu%llu%u%u%u%u%u%u%llu%llu%u%u%u%u%u%u" +#endif }; #else static const char *const ss_fmt[] = { +#ifdef BRCM_CHANGE + "%n%llu%lu%lu%lu%lu%n%n%n%llu%lu%lu%lu%lu%lu", + "%llu%llu%lu%lu%lu%lu%n%n%llu%llu%lu%lu%lu%lu%lu", + "%llu%llu%lu%lu%lu%lu%lu%lu%llu%llu%lu%lu%lu%lu%lu%lu", + +/* BRCM change, JIRA 10503 - add extended statstics format */ + "%llu%llu%lu%lu%lu%lu%lu%lu%llu%llu%lu%lu%lu%lu%lu%lu%lu%lu%lu%lu%lu%lu%lu%lu", +#else "%n%llu%lu%lu%lu%lu%n%n%n%llu%lu%lu%lu%lu%lu", "%llu%llu%lu%lu%lu%lu%n%n%llu%llu%lu%lu%lu%lu%lu", "%llu%llu%lu%lu%lu%lu%lu%lu%llu%llu%lu%lu%lu%lu%lu%lu" +#endif }; #endif @@ -463,6 +501,75 @@ { memset(&ife->stats, 0, sizeof(struct user_net_device_stats)); +#ifdef BRCM_CHANGE + /* BRCM change, JIRA 10503 */ + /* Record what format is being used (so we can print it out appropriately) */ + ife->procnetdev_vsn = procnetdev_vsn; + + /* Parse depending on the format of the file */ + if(procnetdev_vsn < 3) { + + sscanf(bp, ss_fmt[procnetdev_vsn], + &ife->stats.rx_bytes, /* missing for 0 */ + &ife->stats.rx_packets, + &ife->stats.rx_errors, + &ife->stats.rx_dropped, + &ife->stats.rx_fifo_errors, + &ife->stats.rx_frame_errors, + &ife->stats.rx_compressed, /* missing for <= 1 */ + &ife->stats.rx_multicast, /* missing for <= 1 */ + &ife->stats.tx_bytes, /* missing for 0 */ + &ife->stats.tx_packets, + &ife->stats.tx_errors, + &ife->stats.tx_dropped, + &ife->stats.tx_fifo_errors, + &ife->stats.collisions, + &ife->stats.tx_carrier_errors, + &ife->stats.tx_compressed /* missing for <= 1 */ + ); + + if (procnetdev_vsn <= 1) { + if (procnetdev_vsn == 0) { + ife->stats.rx_bytes = 0; + ife->stats.tx_bytes = 0; + } + ife->stats.rx_multicast = 0; + ife->stats.rx_compressed = 0; + ife->stats.tx_compressed = 0; + } + } + /* BRCM change, JIRA 10503 - extened format reading */ + else { + /* Read format from extended output, including multi/uni/broadcast data */ + sscanf(bp, ss_fmt[procnetdev_vsn], + /* Basic statistics, just like procnetdev_vsn == 2 */ + &ife->stats.rx_bytes, + &ife->stats.rx_packets, + &ife->stats.rx_errors, + &ife->stats.rx_dropped, + &ife->stats.rx_fifo_errors, + &ife->stats.rx_frame_errors, + &ife->stats.rx_compressed, + &ife->stats.rx_multicast, + &ife->stats.tx_bytes, + &ife->stats.tx_packets, + &ife->stats.tx_errors, + &ife->stats.tx_dropped, + &ife->stats.tx_fifo_errors, + &ife->stats.collisions, + &ife->stats.tx_carrier_errors, + &ife->stats.tx_compressed, + + /* extended statistics */ + &ife->stats.tx_multicast_packets, &ife->stats.rx_multicast_bytes, &ife->stats.tx_multicast_bytes, + &ife->stats.rx_unicast_packets, &ife->stats.tx_unicast_packets, &ife->stats.rx_broadcast_packets, &ife->stats.tx_broadcast_packets, + &ife->stats.rx_unknown_packets + ); + } + /* End BRCM change, JIRA 10503 */ + +#else + sscanf(bp, ss_fmt[procnetdev_vsn], &ife->stats.rx_bytes, /* missing for v0 */ &ife->stats.rx_packets, @@ -491,10 +598,16 @@ ife->stats.rx_compressed = 0; ife->stats.tx_compressed = 0; } +#endif } static int procnetdev_version(char *buf) { +#ifdef BRCM_CHANGE + /* Look for labels in the heading that indicate what format is being used */ + if (strstr(buf, "unicast")) + return 3; +#endif if (strstr(buf, "compressed")) return 2; if (strstr(buf, "bytes")) @@ -556,6 +669,14 @@ procnetdev_vsn = procnetdev_version(buf); +#ifdef BRCM_CHANGE + /* BRCM change, JIRA 10503 - support extended statsitics reading*/ + /* For some formats, there's a third line of header that needs to be ignored */ + if(procnetdev_vsn == 3) + fgets(buf, sizeof buf, fh); /* eat third line */ + /* End BRCM change, JIRA 10503 */ +#endif + ret = 0; while (fgets(buf, sizeof buf, fh)) { char *s, name[IFNAMSIZ]; @@ -801,7 +922,12 @@ static const char TRext[] ALIGN1 = "\0\0\0Ki\0Mi\0Gi\0Ti"; +#ifdef BRCM_CHANGE +/* BRCM change, JIRA 10503 - removed "end" pointer */ +static void print_bytes_scaled(unsigned long long ull) +#else static void print_bytes_scaled(unsigned long long ull, const char *end) +#endif { unsigned long long int_part; const char *ext; @@ -821,7 +947,13 @@ --i; } while (i); +#ifdef BRCM_CHANGE +/* BRCM change, JIRA 10503 - removed "end" pointer */ + printf("%llu (%llu.%u %sB)", ull, int_part, frac_part, ext); +/* End BRCM change, JIRA 10503 */ +#else printf("X bytes:%llu (%llu.%u %sB)%s", ull, int_part, frac_part, ext, end); +#endif } @@ -1018,6 +1150,118 @@ /* If needed, display the interface statistics. */ if (ptr->statistics_valid) { +#ifdef BRCM_CHANGE + /* BRCM change, JIRA 10503 - add extended formats, accomodate print_bytes_scaled() change */ + /* Depending on the format read in, output the statistics */ + if(ptr->procnetdev_vsn <= 2) { + /* Legacy formats */ + + /* XXX: statistics are currently only printed for the primary address, + * not for the aliases, although strictly speaking they're shared + * by all addresses. + */ + printf(" "); + + printf("RX packets:%llu errors:%lu dropped:%lu overruns:%lu frame:%lu\n", + ptr->stats.rx_packets, ptr->stats.rx_errors, + ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors, + ptr->stats.rx_frame_errors); + + printf("TX packets:%llu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n", + ptr->stats.tx_packets, ptr->stats.tx_errors, + ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors, + ptr->stats.tx_carrier_errors); + printf(" collisions:%lu ", ptr->stats.collisions); + if (can_compress) + printf("compressed:%lu ", ptr->stats.tx_compressed); + + if (ptr->tx_queue_len != -1) + { + printf(" "); + printf("txqueuelen:%d ", ptr->tx_queue_len); + } + + // Byte counts + printf(" "); + printf("RX bytes:"); + print_bytes_scaled(ptr->stats.rx_bytes); + printf(" TX bytes:"); + print_bytes_scaled(ptr->stats.tx_bytes); + printf("\n"); + } + else { + /* Extended formats, including multi/uni/broadcast data */ + + /* XXX: statistics are currently only printed for the primary address, + * not for the aliases, although strictly speaking they're shared + * by all addresses. + */ + + // RX packet counts + printf(" "); + printf("RX packets:%llu multicast:%lu unicast:%lu broadcast:%lu", + ptr->stats.rx_packets, ptr->stats.rx_multicast, + ptr->stats.rx_unicast_packets, ptr->stats.rx_broadcast_packets); + if (can_compress) + printf(" compressed:%lu\n", ptr->stats.rx_compressed); + else + printf("\n"); + + // RX error counts + printf(" "); + printf("RX errors:%lu dropped:%lu overruns:%lu frame:%lu\n", + ptr->stats.rx_errors, + ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors, + ptr->stats.rx_frame_errors); + + // printf("TX packets:%llu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n", + // ptr->stats.tx_packets, ptr->stats.tx_errors, + // ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors, + // ptr->stats.tx_carrier_errors); + // printf(" collisions:%lu ", ptr->stats.collisions); + // if (can_compress) + // printf("compressed:%lu ", ptr->stats.tx_compressed); + + // TX packet counts + printf(" "); + printf("TX packets:%llu multicast:%lu unicast:%lu broadcast:%lu", + ptr->stats.tx_packets, ptr->stats.tx_multicast_packets, + ptr->stats.tx_unicast_packets, ptr->stats.tx_broadcast_packets); + if (can_compress) + printf(" compressed:%lu\n", ptr->stats.tx_compressed); + else + printf("\n"); + + // TX error counts + printf(" "); + printf("TX errors:%lu dropped:%lu overruns:%lu carrier:%lu collisions:%lu\n", + ptr->stats.tx_errors, + ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors, + ptr->stats.tx_carrier_errors, ptr->stats.collisions); + + + + if (ptr->tx_queue_len != -1) + { + printf(" "); + printf("txqueuelen:%d\n", ptr->tx_queue_len); + } + + // Byte counts + printf(" "); + printf("RX bytes:"); + print_bytes_scaled(ptr->stats.rx_bytes); + printf(" TX bytes:"); + print_bytes_scaled(ptr->stats.tx_bytes); + printf("\n "); + printf("RX multicast bytes:"); + print_bytes_scaled(ptr->stats.rx_multicast_bytes); + printf(" TX multicast bytes:"); + print_bytes_scaled(ptr->stats.tx_multicast_bytes); + printf("\n"); + } +/* End BRCM change, JIRA 10503 */ +#else /* XXX: statistics are currently only printed for the primary address, * not for the aliases, although strictly speaking they're shared * by all addresses. @@ -1044,6 +1288,7 @@ printf("\n R"); print_bytes_scaled(ptr->stats.rx_bytes, " T"); print_bytes_scaled(ptr->stats.tx_bytes, "\n"); +#endif } if (ptr->map.irq || ptr->map.mem_start