provide the bandwidth limit through d-bus

This commit is contained in:
Nikos Mavrogiannopoulos
2014-03-02 13:24:44 +01:00
parent 949fbacf32
commit e72414459a
4 changed files with 58 additions and 4 deletions
+19 -1
View File
@@ -72,7 +72,7 @@ typedef struct {
{name, sizeof(name)-1, iface, sizeof(iface)-1, desc, sizeof(desc)-1, func} {name, sizeof(name)-1, iface, sizeof(iface)-1, desc, sizeof(desc)-1, func}
#define LIST_USERS_SIG "(ussssssssusssss)" #define LIST_USERS_SIG "(ussssssssusssss)"
#define LIST_SINGLE_USER_SIG "(ussssssssusssssasasasas)" #define LIST_SINGLE_USER_SIG "(ussssssssusssssuuasasasas)"
#define DESC_LIST \ #define DESC_LIST \
" <method name=\"list\">\n" \ " <method name=\"list\">\n" \
@@ -563,6 +563,24 @@ static int append_user_info(main_server_st * s, DBusMessageIter * subs,
} }
if (single > 0) { if (single > 0) {
if (ctmp->config.rx_per_sec > 0)
tmp = ctmp->config.rx_per_sec;
else
tmp = s->config->rx_per_sec;
tmp *= 1000;
if (dbus_message_iter_append_basic(subs, DBUS_TYPE_UINT32, &tmp) == 0) {
return -1;
}
if (ctmp->config.tx_per_sec > 0)
tmp = ctmp->config.tx_per_sec;
else
tmp = s->config->tx_per_sec;
tmp *= 1000;
if (dbus_message_iter_append_basic(subs, DBUS_TYPE_UINT32, &tmp) == 0) {
return -1;
}
if (ctmp->config.dns_size > 0) { if (ctmp->config.dns_size > 0) {
list = ctmp->config.dns; list = ctmp->config.dns;
list_size = ctmp->config.dns_size; list_size = ctmp->config.dns_size;
+1 -1
View File
@@ -68,7 +68,7 @@ error:
return -1; return -1;
} }
static void void
bytes2human(unsigned long bytes, char* output, unsigned output_size, const char* suffix) bytes2human(unsigned long bytes, char* output, unsigned output_size, const char* suffix)
{ {
double data; double data;
+35 -2
View File
@@ -768,7 +768,7 @@ int print_list_entries(FILE* out, const char* name, DBusMessageIter * subs)
int common_info_cmd(DBusMessageIter * args) int common_info_cmd(DBusMessageIter * args)
{ {
DBusMessageIter suba, subs; DBusMessageIter suba, subs;
dbus_uint32_t id = 0; dbus_uint32_t id = 0, rx = 0, tx = 0;
char *username = ""; char *username = "";
dbus_uint32_t since = 0; dbus_uint32_t since = 0;
char *groupname = "", *ip = ""; char *groupname = "", *ip = "";
@@ -908,6 +908,20 @@ int common_info_cmd(DBusMessageIter * args)
goto error_parse; goto error_parse;
dbus_message_iter_get_basic(&subs, &dtls_ciphersuite); dbus_message_iter_get_basic(&subs, &dtls_ciphersuite);
if (!dbus_message_iter_next(&subs))
goto error_recv;
if (dbus_message_iter_get_arg_type(&subs) != DBUS_TYPE_UINT32)
goto error_parse;
dbus_message_iter_get_basic(&subs, &rx);
if (!dbus_message_iter_next(&subs))
goto error_recv;
if (dbus_message_iter_get_arg_type(&subs) != DBUS_TYPE_UINT32)
goto error_parse;
dbus_message_iter_get_basic(&subs, &tx);
if (!dbus_message_iter_next(&subs)) if (!dbus_message_iter_next(&subs))
goto error_recv; goto error_recv;
@@ -940,6 +954,25 @@ int common_info_cmd(DBusMessageIter * args)
else else
fprintf(out, "\n"); fprintf(out, "\n");
if (rx > 0 || tx > 0) {
/* print limits */
char buf[32];
if (rx > 0 && tx > 0) {
bytes2human(rx, buf, sizeof(buf), NULL);
fprintf(out, "\tLimit RX: %s/sec ", buf);
bytes2human(tx, buf, sizeof(buf), NULL);
fprintf(out, "TX: %s/sec\n", buf);
} else if (tx > 0) {
bytes2human(tx, buf, sizeof(buf), NULL);
fprintf(out, "\tLimit TX: %s/sec\n", buf);
} else if (rx > 0) {
bytes2human(rx, buf, sizeof(buf), NULL);
fprintf(out, "\tLimit RX: %s/sec\n", buf);
}
}
print_iface_stats(device, since, out); print_iface_stats(device, since, out);
if (hostname != NULL && hostname[0] != 0) if (hostname != NULL && hostname[0] != 0)
@@ -979,10 +1012,10 @@ int common_info_cmd(DBusMessageIter * args)
if (print_list_entries(out, "\tiRoutes:", &subs) < 0) if (print_list_entries(out, "\tiRoutes:", &subs) < 0)
goto error_parse; goto error_parse;
at_least_one = 1; at_least_one = 1;
if (!dbus_message_iter_next(&suba)) if (!dbus_message_iter_next(&suba))
break; break;
} }
ret = 0; ret = 0;
+3
View File
@@ -9,6 +9,9 @@ void pager_stop(FILE* fp);
void print_time_ival7(time_t t, FILE * fout); void print_time_ival7(time_t t, FILE * fout);
void print_iface_stats(const char *iface, time_t since, FILE * out); void print_iface_stats(const char *iface, time_t since, FILE * out);
void
bytes2human(unsigned long bytes, char* output, unsigned output_size, const char* suffix);
char* search_for_id(unsigned idx, const char* match, int match_size); char* search_for_id(unsigned idx, const char* match, int match_size);
char* search_for_user(unsigned idx, const char* match, int match_size); char* search_for_user(unsigned idx, const char* match, int match_size);
void entries_add(const char* user, unsigned user_size, unsigned id); void entries_add(const char* user, unsigned user_size, unsigned id);