mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-08-13 18:44:04 +00:00
tc: implement color output
Implement the -color option; in this case -co is ambiguous since it was already used for -conf. For now this just means putting device name in color. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
parent
14f2124a34
commit
2d165c0811
@ -94,10 +94,11 @@ tc \- show / manipulate traffic control settings
|
||||
\fB\-s\fR[\fItatistics\fR] |
|
||||
\fB\-d\fR[\fIetails\fR] |
|
||||
\fB\-r\fR[\fIaw\fR] |
|
||||
\fB\-p\fR[\fIretty\fR] |
|
||||
\fB\-i\fR[\fIec\fR] |
|
||||
\fB\-g\fR[\fIraph\fR] |
|
||||
\fB\-j\fR[\fIjson\fR] }
|
||||
\fB\-j\fR[\fIjson\fR] |
|
||||
\fB\-p\fR[\fIretty\fR] |
|
||||
\fB\-col\fR[\fIor\fR] }
|
||||
|
||||
.SH DESCRIPTION
|
||||
.B Tc
|
||||
@ -685,6 +686,10 @@ option was specified. Classes can be filtered only by
|
||||
.BR "dev"
|
||||
option.
|
||||
|
||||
.TP
|
||||
.BR "\ -color"
|
||||
Use color output.
|
||||
|
||||
.TP
|
||||
.BR "\-j", " \-json"
|
||||
Display results in JSON format.
|
||||
|
15
tc/tc.c
15
tc/tc.c
@ -41,6 +41,7 @@ int use_iec;
|
||||
int force;
|
||||
bool use_names;
|
||||
int json;
|
||||
int color;
|
||||
|
||||
static char *conf_file;
|
||||
|
||||
@ -186,10 +187,11 @@ noexist:
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: tc [ OPTIONS ] OBJECT { COMMAND | help }\n"
|
||||
" tc [-force] -batch filename\n"
|
||||
"where OBJECT := { qdisc | class | filter | action | monitor | exec }\n"
|
||||
" OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] | -n[etns] name |\n"
|
||||
" -nm | -nam[es] | { -cf | -conf } path } | -j[son]\n");
|
||||
" tc [-force] -batch filename\n"
|
||||
"where OBJECT := { qdisc | class | filter | action | monitor | exec }\n"
|
||||
" OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -b[atch] [filename] | -n[etns] name |\n"
|
||||
" -nm | -nam[es] | { -cf | -conf } path } |\n"
|
||||
" -j[son] -p[retty] -c[olor]\n");
|
||||
}
|
||||
|
||||
static int do_cmd(int argc, char **argv, void *buf, size_t buflen)
|
||||
@ -476,6 +478,8 @@ int main(int argc, char **argv)
|
||||
matches(argv[1], "-conf") == 0) {
|
||||
NEXT_ARG();
|
||||
conf_file = argv[1];
|
||||
} else if (matches(argv[1], "-color") == 0) {
|
||||
++color;
|
||||
} else if (matches(argv[1], "-timestamp") == 0) {
|
||||
timestamp++;
|
||||
} else if (matches(argv[1], "-tshort") == 0) {
|
||||
@ -490,6 +494,9 @@ int main(int argc, char **argv)
|
||||
argc--; argv++;
|
||||
}
|
||||
|
||||
if (color & !json)
|
||||
enable_color();
|
||||
|
||||
if (batch_file)
|
||||
return batch(batch_file);
|
||||
|
||||
|
@ -303,8 +303,7 @@ int print_filter(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
||||
t->tcm_block_index);
|
||||
} else {
|
||||
if (!filter_ifindex || filter_ifindex != t->tcm_ifindex)
|
||||
print_string(PRINT_ANY, "dev", "dev %s ",
|
||||
ll_index_to_name(t->tcm_ifindex));
|
||||
print_devname(PRINT_ANY, t->tcm_ifindex);
|
||||
|
||||
if (!filter_parent || filter_parent != t->tcm_parent) {
|
||||
if (t->tcm_parent == TC_H_ROOT)
|
||||
|
@ -270,8 +270,7 @@ int print_qdisc(const struct sockaddr_nl *who,
|
||||
print_string(PRINT_FP, NULL, " ", NULL);
|
||||
|
||||
if (filter_ifindex == 0)
|
||||
print_string(PRINT_ANY, "dev", "dev %s ",
|
||||
ll_index_to_name(t->tcm_ifindex));
|
||||
print_devname(PRINT_ANY, t->tcm_ifindex);
|
||||
|
||||
if (t->tcm_parent == TC_H_ROOT)
|
||||
print_bool(PRINT_ANY, "root", "root ", true);
|
||||
|
11
tc/tc_util.c
11
tc/tc_util.c
@ -444,6 +444,17 @@ int get_size_and_cell(unsigned int *size, int *cell_log, char *str)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_devname(enum output_type type, int ifindex)
|
||||
{
|
||||
const char *ifname = ll_index_to_name(ifindex);
|
||||
|
||||
if (!is_json_context())
|
||||
printf("dev ");
|
||||
|
||||
print_color_string(type, COLOR_IFNAME,
|
||||
"dev", "%s ", ifname);
|
||||
}
|
||||
|
||||
void print_size(char *buf, int len, __u32 sz)
|
||||
{
|
||||
double tmp = sz;
|
||||
|
@ -89,6 +89,7 @@ void print_size(char *buf, int len, __u32 size);
|
||||
void print_qdisc_handle(char *buf, int len, __u32 h);
|
||||
void print_time(char *buf, int len, __u32 time);
|
||||
void print_linklayer(char *buf, int len, unsigned int linklayer);
|
||||
void print_devname(enum output_type type, int ifindex);
|
||||
|
||||
char *sprint_rate(__u64 rate, char *buf);
|
||||
char *sprint_size(__u32 size, char *buf);
|
||||
|
Loading…
Reference in New Issue
Block a user