mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-10-05 19:02:41 +00:00

Every tool in the iproute2 package have one or more function to show an help message to the user. Some of these functions print the help line by line with a series of printf call, e.g. ip/xfrm_state.c does 60 fprintf calls. If we group all the calls to a single one and just concatenate strings, we save a lot of libc calls and thus object size. The size difference of the compiled binaries calculated with bloat-o-meter is: ip/ip: add/remove: 0/0 grow/shrink: 5/15 up/down: 103/-4796 (-4693) Total: Before=672591, After=667898, chg -0.70% ip/rtmon: add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-54 (-54) Total: Before=48879, After=48825, chg -0.11% tc/tc: add/remove: 0/2 grow/shrink: 31/10 up/down: 882/-6133 (-5251) Total: Before=351912, After=346661, chg -1.49% bridge/bridge: add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-459 (-459) Total: Before=70502, After=70043, chg -0.65% misc/lnstat: add/remove: 0/1 grow/shrink: 1/0 up/down: 48/-486 (-438) Total: Before=9960, After=9522, chg -4.40% tipc/tipc: add/remove: 0/0 grow/shrink: 1/1 up/down: 18/-62 (-44) Total: Before=79182, After=79138, chg -0.06% While at it, indent some strings which were starting at column 0, and use tabs where possible, to have a consistent style across helps. Signed-off-by: Matteo Croce <mcroce@redhat.com> Signed-off-by: David Ahern <dsahern@gmail.com>
201 lines
5.4 KiB
C
201 lines
5.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/* q_hhf.c Heavy-Hitter Filter (HHF)
|
|
*
|
|
* Copyright (C) 2013 Terry Lam <vtlam@google.com>
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <string.h>
|
|
|
|
#include "utils.h"
|
|
#include "tc_util.h"
|
|
|
|
static void explain(void)
|
|
{
|
|
fprintf(stderr,
|
|
"Usage: ... hhf [ limit PACKETS ] [ quantum BYTES]\n"
|
|
" [ hh_limit NUMBER ]\n"
|
|
" [ reset_timeout TIME ]\n"
|
|
" [ admit_bytes BYTES ]\n"
|
|
" [ evict_timeout TIME ]\n"
|
|
" [ non_hh_weight NUMBER ]\n");
|
|
}
|
|
|
|
static int hhf_parse_opt(struct qdisc_util *qu, int argc, char **argv,
|
|
struct nlmsghdr *n, const char *dev)
|
|
{
|
|
unsigned int limit = 0;
|
|
unsigned int quantum = 0;
|
|
unsigned int hh_limit = 0;
|
|
unsigned int reset_timeout = 0;
|
|
unsigned int admit_bytes = 0;
|
|
unsigned int evict_timeout = 0;
|
|
unsigned int non_hh_weight = 0;
|
|
struct rtattr *tail;
|
|
|
|
while (argc > 0) {
|
|
if (strcmp(*argv, "limit") == 0) {
|
|
NEXT_ARG();
|
|
if (get_unsigned(&limit, *argv, 0)) {
|
|
fprintf(stderr, "Illegal \"limit\"\n");
|
|
return -1;
|
|
}
|
|
} else if (strcmp(*argv, "quantum") == 0) {
|
|
NEXT_ARG();
|
|
if (get_unsigned(&quantum, *argv, 0)) {
|
|
fprintf(stderr, "Illegal \"quantum\"\n");
|
|
return -1;
|
|
}
|
|
} else if (strcmp(*argv, "hh_limit") == 0) {
|
|
NEXT_ARG();
|
|
if (get_unsigned(&hh_limit, *argv, 0)) {
|
|
fprintf(stderr, "Illegal \"hh_limit\"\n");
|
|
return -1;
|
|
}
|
|
} else if (strcmp(*argv, "reset_timeout") == 0) {
|
|
NEXT_ARG();
|
|
if (get_time(&reset_timeout, *argv)) {
|
|
fprintf(stderr, "Illegal \"reset_timeout\"\n");
|
|
return -1;
|
|
}
|
|
} else if (strcmp(*argv, "admit_bytes") == 0) {
|
|
NEXT_ARG();
|
|
if (get_unsigned(&admit_bytes, *argv, 0)) {
|
|
fprintf(stderr, "Illegal \"admit_bytes\"\n");
|
|
return -1;
|
|
}
|
|
} else if (strcmp(*argv, "evict_timeout") == 0) {
|
|
NEXT_ARG();
|
|
if (get_time(&evict_timeout, *argv)) {
|
|
fprintf(stderr, "Illegal \"evict_timeout\"\n");
|
|
return -1;
|
|
}
|
|
} else if (strcmp(*argv, "non_hh_weight") == 0) {
|
|
NEXT_ARG();
|
|
if (get_unsigned(&non_hh_weight, *argv, 0)) {
|
|
fprintf(stderr, "Illegal \"non_hh_weight\"\n");
|
|
return -1;
|
|
}
|
|
} else if (strcmp(*argv, "help") == 0) {
|
|
explain();
|
|
return -1;
|
|
} else {
|
|
fprintf(stderr, "What is \"%s\"?\n", *argv);
|
|
explain();
|
|
return -1;
|
|
}
|
|
argc--; argv++;
|
|
}
|
|
|
|
tail = addattr_nest(n, 1024, TCA_OPTIONS);
|
|
if (limit)
|
|
addattr_l(n, 1024, TCA_HHF_BACKLOG_LIMIT, &limit,
|
|
sizeof(limit));
|
|
if (quantum)
|
|
addattr_l(n, 1024, TCA_HHF_QUANTUM, &quantum, sizeof(quantum));
|
|
if (hh_limit)
|
|
addattr_l(n, 1024, TCA_HHF_HH_FLOWS_LIMIT, &hh_limit,
|
|
sizeof(hh_limit));
|
|
if (reset_timeout)
|
|
addattr_l(n, 1024, TCA_HHF_RESET_TIMEOUT, &reset_timeout,
|
|
sizeof(reset_timeout));
|
|
if (admit_bytes)
|
|
addattr_l(n, 1024, TCA_HHF_ADMIT_BYTES, &admit_bytes,
|
|
sizeof(admit_bytes));
|
|
if (evict_timeout)
|
|
addattr_l(n, 1024, TCA_HHF_EVICT_TIMEOUT, &evict_timeout,
|
|
sizeof(evict_timeout));
|
|
if (non_hh_weight)
|
|
addattr_l(n, 1024, TCA_HHF_NON_HH_WEIGHT, &non_hh_weight,
|
|
sizeof(non_hh_weight));
|
|
addattr_nest_end(n, tail);
|
|
return 0;
|
|
}
|
|
|
|
static int hhf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
|
|
{
|
|
struct rtattr *tb[TCA_HHF_MAX + 1];
|
|
unsigned int limit;
|
|
unsigned int quantum;
|
|
unsigned int hh_limit;
|
|
unsigned int reset_timeout;
|
|
unsigned int admit_bytes;
|
|
unsigned int evict_timeout;
|
|
unsigned int non_hh_weight;
|
|
|
|
SPRINT_BUF(b1);
|
|
|
|
if (opt == NULL)
|
|
return 0;
|
|
|
|
parse_rtattr_nested(tb, TCA_HHF_MAX, opt);
|
|
|
|
if (tb[TCA_HHF_BACKLOG_LIMIT] &&
|
|
RTA_PAYLOAD(tb[TCA_HHF_BACKLOG_LIMIT]) >= sizeof(__u32)) {
|
|
limit = rta_getattr_u32(tb[TCA_HHF_BACKLOG_LIMIT]);
|
|
fprintf(f, "limit %up ", limit);
|
|
}
|
|
if (tb[TCA_HHF_QUANTUM] &&
|
|
RTA_PAYLOAD(tb[TCA_HHF_QUANTUM]) >= sizeof(__u32)) {
|
|
quantum = rta_getattr_u32(tb[TCA_HHF_QUANTUM]);
|
|
fprintf(f, "quantum %u ", quantum);
|
|
}
|
|
if (tb[TCA_HHF_HH_FLOWS_LIMIT] &&
|
|
RTA_PAYLOAD(tb[TCA_HHF_HH_FLOWS_LIMIT]) >= sizeof(__u32)) {
|
|
hh_limit = rta_getattr_u32(tb[TCA_HHF_HH_FLOWS_LIMIT]);
|
|
fprintf(f, "hh_limit %u ", hh_limit);
|
|
}
|
|
if (tb[TCA_HHF_RESET_TIMEOUT] &&
|
|
RTA_PAYLOAD(tb[TCA_HHF_RESET_TIMEOUT]) >= sizeof(__u32)) {
|
|
reset_timeout = rta_getattr_u32(tb[TCA_HHF_RESET_TIMEOUT]);
|
|
fprintf(f, "reset_timeout %s ", sprint_time(reset_timeout, b1));
|
|
}
|
|
if (tb[TCA_HHF_ADMIT_BYTES] &&
|
|
RTA_PAYLOAD(tb[TCA_HHF_ADMIT_BYTES]) >= sizeof(__u32)) {
|
|
admit_bytes = rta_getattr_u32(tb[TCA_HHF_ADMIT_BYTES]);
|
|
fprintf(f, "admit_bytes %u ", admit_bytes);
|
|
}
|
|
if (tb[TCA_HHF_EVICT_TIMEOUT] &&
|
|
RTA_PAYLOAD(tb[TCA_HHF_EVICT_TIMEOUT]) >= sizeof(__u32)) {
|
|
evict_timeout = rta_getattr_u32(tb[TCA_HHF_EVICT_TIMEOUT]);
|
|
fprintf(f, "evict_timeout %s ", sprint_time(evict_timeout, b1));
|
|
}
|
|
if (tb[TCA_HHF_NON_HH_WEIGHT] &&
|
|
RTA_PAYLOAD(tb[TCA_HHF_NON_HH_WEIGHT]) >= sizeof(__u32)) {
|
|
non_hh_weight = rta_getattr_u32(tb[TCA_HHF_NON_HH_WEIGHT]);
|
|
fprintf(f, "non_hh_weight %u ", non_hh_weight);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int hhf_print_xstats(struct qdisc_util *qu, FILE *f,
|
|
struct rtattr *xstats)
|
|
{
|
|
struct tc_hhf_xstats *st;
|
|
|
|
if (xstats == NULL)
|
|
return 0;
|
|
|
|
if (RTA_PAYLOAD(xstats) < sizeof(*st))
|
|
return -1;
|
|
|
|
st = RTA_DATA(xstats);
|
|
|
|
fprintf(f, " drop_overlimit %u hh_overlimit %u tot_hh %u cur_hh %u",
|
|
st->drop_overlimit, st->hh_overlimit,
|
|
st->hh_tot_count, st->hh_cur_count);
|
|
return 0;
|
|
}
|
|
|
|
struct qdisc_util hhf_qdisc_util = {
|
|
.id = "hhf",
|
|
.parse_qopt = hhf_parse_opt,
|
|
.print_qopt = hhf_print_opt,
|
|
.print_xstats = hhf_print_xstats,
|
|
};
|