ifctrstat: Use new structure and recalculate binary size
This commit is contained in:
		
							parent
							
								
									7b45d3939d
								
							
						
					
					
						commit
						1a11bb768f
					
				
					 3 changed files with 27 additions and 31 deletions
				
			
		
							
								
								
									
										2
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
										
									
									
									
								
							| 
						 | 
					@ -62,7 +62,7 @@ MULTICALL_${CONFIG_IFQUERY}_OBJ += ${IFQUERY_SRC:.c=.o}
 | 
				
			||||||
CMDS_${CONFIG_IFQUERY} += ifquery
 | 
					CMDS_${CONFIG_IFQUERY} += ifquery
 | 
				
			||||||
CPPFLAGS_${CONFIG_IFQUERY} += -DCONFIG_IFQUERY
 | 
					CPPFLAGS_${CONFIG_IFQUERY} += -DCONFIG_IFQUERY
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# enable ifctrstat applet (+16 KB)
 | 
					# enable ifctrstat applet (+1 KB)
 | 
				
			||||||
CONFIG_IFCTRSTAT ?= Y
 | 
					CONFIG_IFCTRSTAT ?= Y
 | 
				
			||||||
IFCTRSTAT_SRC = cmd/ifctrstat.c cmd/ifctrstat-${LAYOUT}.c
 | 
					IFCTRSTAT_SRC = cmd/ifctrstat.c cmd/ifctrstat-${LAYOUT}.c
 | 
				
			||||||
MULTICALL_${CONFIG_IFCTRSTAT}_OBJ += ${IFCTRSTAT_SRC:.c=.o}
 | 
					MULTICALL_${CONFIG_IFCTRSTAT}_OBJ += ${IFCTRSTAT_SRC:.c=.o}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,19 +19,28 @@
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include "multicall.h"
 | 
					#include "multicall.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const char *avail_counters[] = {
 | 
					struct counter_desc {
 | 
				
			||||||
	"rx.octets",
 | 
						const char *name;
 | 
				
			||||||
	"rx.packets",
 | 
						const void *data;
 | 
				
			||||||
	"rx.discard",
 | 
					} avail_counters[] = {
 | 
				
			||||||
	"rx.errors",
 | 
						{"rx.discard", "rx_dropped"},
 | 
				
			||||||
	"tx.octets",
 | 
						{"rx.errors", "rx_errors"},
 | 
				
			||||||
	"tx.packets",
 | 
						{"rx.octets", "rx_bytes"},
 | 
				
			||||||
	"tx.discard",
 | 
						{"rx.packets", "rx_packets"},
 | 
				
			||||||
	"tx.errors"
 | 
						{"tx.discard", "tx_dropped"},
 | 
				
			||||||
 | 
						{"tx.errors", "tx_errors"},
 | 
				
			||||||
 | 
						{"tx.octets", "tx_bytes"},
 | 
				
			||||||
 | 
						{"tx.packets", "tx_packets"}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
size_t avail_counters_count = ARRAY_SIZE(avail_counters);
 | 
					size_t avail_counters_count = ARRAY_SIZE(avail_counters);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					counter_compare(const void *key, const void *candidate)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return strcasecmp((const char *)key, ((struct counter_desc *)candidate)->name);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char *
 | 
					char *
 | 
				
			||||||
read_counter(const char *interface, const char *counter)
 | 
					read_counter(const char *interface, const char *counter)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -40,26 +49,13 @@ read_counter(const char *interface, const char *counter)
 | 
				
			||||||
	char full_path[PATH_MAX];
 | 
						char full_path[PATH_MAX];
 | 
				
			||||||
	char buffer[1024];
 | 
						char buffer[1024];
 | 
				
			||||||
	size_t in_count;
 | 
						size_t in_count;
 | 
				
			||||||
 | 
						struct counter_desc *ctrdata;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	errno = 0;
 | 
						errno = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcasecmp(counter, "rx.octets") == 0)
 | 
						ctrdata = bsearch(counter, avail_counters, avail_counters_count, sizeof(struct counter_desc), counter_compare);
 | 
				
			||||||
	{
 | 
						if (ctrdata) {
 | 
				
			||||||
		path = "rx_bytes";
 | 
							path = (const char *)ctrdata->data;
 | 
				
			||||||
	} else if (strcasecmp(counter, "rx.packets") == 0) {
 | 
					 | 
				
			||||||
		path = "rx_packets";
 | 
					 | 
				
			||||||
	} else if (strcasecmp(counter, "rx.discard") == 0) {
 | 
					 | 
				
			||||||
		path = "rx_dropped";
 | 
					 | 
				
			||||||
	} else if (strcasecmp(counter, "rx.errors") == 0) {
 | 
					 | 
				
			||||||
		path = "rx_errors";
 | 
					 | 
				
			||||||
	} else if (strcasecmp(counter, "tx.octets") == 0) {
 | 
					 | 
				
			||||||
		path = "tx_bytes";
 | 
					 | 
				
			||||||
	} else if (strcasecmp(counter, "tx.packets") == 0) {
 | 
					 | 
				
			||||||
		path = "tx_packets";
 | 
					 | 
				
			||||||
	} else if (strcasecmp(counter, "tx.discard") == 0) {
 | 
					 | 
				
			||||||
		path = "tx_dropped";
 | 
					 | 
				
			||||||
	} else if (strcasecmp(counter, "tx.errors") == 0) {
 | 
					 | 
				
			||||||
		path = "tx_errors";
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		errno = ENOSYS;
 | 
							errno = ENOSYS;
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,7 +21,7 @@
 | 
				
			||||||
#include "libifupdown/libifupdown.h"
 | 
					#include "libifupdown/libifupdown.h"
 | 
				
			||||||
#include "cmd/multicall.h"
 | 
					#include "cmd/multicall.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern const char *avail_counters[];
 | 
					extern struct counter_desc { const char *name; const void *data; } avail_counters[];
 | 
				
			||||||
extern int avail_counters_count;
 | 
					extern int avail_counters_count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern const char *read_counter(const char *interface, const char *counter);
 | 
					extern const char *read_counter(const char *interface, const char *counter);
 | 
				
			||||||
| 
						 | 
					@ -33,7 +33,7 @@ counter_is_valid(const char *candidate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	for (int i = 0; i < avail_counters_count; i++)
 | 
						for (int i = 0; i < avail_counters_count; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (strcasecmp(avail_counters[i], candidate) == 0)
 | 
							if (strcasecmp(avail_counters[i].name, candidate) == 0)
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,7 +56,7 @@ print_all_counters(const char *iface)
 | 
				
			||||||
	const char *res;
 | 
						const char *res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (int i = 0; i < avail_counters_count; i++) {
 | 
						for (int i = 0; i < avail_counters_count; i++) {
 | 
				
			||||||
		const char *ctr = avail_counters[i];
 | 
							const char *ctr = avail_counters[i].name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		res = read_counter(iface, ctr);
 | 
							res = read_counter(iface, ctr);
 | 
				
			||||||
		if (!res)
 | 
							if (!res)
 | 
				
			||||||
| 
						 | 
					@ -81,7 +81,7 @@ ifctrstat_list_counters(int short_opt, const struct if_option *opt, const char *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (int i = 0; i < avail_counters_count; i++)
 | 
						for (int i = 0; i < avail_counters_count; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		fprintf(stdout, "%s\n", avail_counters[i]);
 | 
							fprintf(stdout, "%s\n", avail_counters[i].name);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	exit(EXIT_SUCCESS);
 | 
						exit(EXIT_SUCCESS);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue