#include <string.h>
#include <errno.h>
-#include "SNAPSHOT.h"
+#include "version.h"
#include "utils.h"
#include "tc_util.h"
#include "tc_common.h"
#include "namespace.h"
+#include "rt_names.h"
int show_stats;
int show_details;
int show_raw;
-int show_pretty;
int show_graph;
int timestamp;
int use_iec;
int force;
bool use_names;
+int json;
+int color;
+int oneline;
static char *conf_file;
return 0;
}
-static int parse_noqopt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
+static int parse_noqopt(struct qdisc_util *qu, int argc, char **argv,
+ struct nlmsghdr *n, const char *dev)
{
if (argc) {
- fprintf(stderr, "Unknown qdisc \"%s\", hence option \"%s\" is unparsable\n", qu->id, *argv);
+ fprintf(stderr,
+ "Unknown qdisc \"%s\", hence option \"%s\" is unparsable\n",
+ qu->id, *argv);
return -1;
}
return 0;
return 0;
}
-static int parse_nofopt(struct filter_util *qu, char *fhandle, int argc, char **argv, struct nlmsghdr *n)
+static int parse_nofopt(struct filter_util *qu, char *fhandle,
+ int argc, char **argv, struct nlmsghdr *n)
{
__u32 handle;
if (argc) {
- fprintf(stderr, "Unknown filter \"%s\", hence option \"%s\" is unparsable\n", qu->id, *argv);
+ fprintf(stderr,
+ "Unknown filter \"%s\", hence option \"%s\" is unparsable\n",
+ qu->id, *argv);
return -1;
}
if (fhandle) {
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 }\n");
+ fprintf(stderr,
+ "Usage: tc [ OPTIONS ] OBJECT { COMMAND | help }\n"
+ " tc [-force] -batch filename\n"
+ "where OBJECT := { qdisc | class | filter | chain |\n"
+ " action | monitor | exec }\n"
+ " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[aw] |\n"
+ " -o[neline] | -j[son] | -p[retty] | -c[olor]\n"
+ " -b[atch] [filename] | -n[etns] name | -N[umeric] |\n"
+ " -nm | -nam[es] | { -cf | -conf } path }\n");
}
static int do_cmd(int argc, char **argv)
return do_class(argc-1, argv+1);
if (matches(*argv, "filter") == 0)
return do_filter(argc-1, argv+1);
+ if (matches(*argv, "chain") == 0)
+ return do_chain(argc-1, argv+1);
if (matches(*argv, "actions") == 0)
return do_action(argc-1, argv+1);
if (matches(*argv, "monitor") == 0)
batch_mode = 1;
if (name && strcmp(name, "-") != 0) {
if (freopen(name, "r", stdin) == NULL) {
- fprintf(stderr, "Cannot open file \"%s\" for reading: %s\n",
+ fprintf(stderr,
+ "Cannot open file \"%s\" for reading: %s\n",
name, strerror(errno));
return -1;
}
continue; /* blank line */
if (do_cmd(largc, largv)) {
- fprintf(stderr, "Command failed %s:%d\n", name, cmdlineno);
+ fprintf(stderr, "Command failed %s:%d\n",
+ name, cmdlineno);
ret = 1;
if (!force)
break;
}
+ fflush(stdout);
}
- if (line)
- free(line);
+ free(line);
rtnl_close(&rth);
return ret;
}
} else if (matches(argv[1], "-raw") == 0) {
++show_raw;
} else if (matches(argv[1], "-pretty") == 0) {
- ++show_pretty;
+ ++pretty;
} else if (matches(argv[1], "-graph") == 0) {
show_graph = 1;
} else if (matches(argv[1], "-Version") == 0) {
- printf("tc utility, iproute2-ss%s\n", SNAPSHOT);
+ printf("tc utility, iproute2-%s\n", version);
return 0;
} else if (matches(argv[1], "-iec") == 0) {
++use_iec;
NEXT_ARG();
if (netns_switch(argv[1]))
return -1;
+ } else if (matches(argv[1], "-Numeric") == 0) {
+ ++numeric;
} else if (matches(argv[1], "-names") == 0 ||
matches(argv[1], "-nm") == 0) {
use_names = true;
matches(argv[1], "-conf") == 0) {
NEXT_ARG();
conf_file = argv[1];
+ } else if (matches_color(argv[1], &color)) {
} else if (matches(argv[1], "-timestamp") == 0) {
timestamp++;
} else if (matches(argv[1], "-tshort") == 0) {
++timestamp;
++timestamp_short;
+ } else if (matches(argv[1], "-json") == 0) {
+ ++json;
+ } else if (matches(argv[1], "-oneline") == 0) {
+ ++oneline;
} else {
- fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
+ fprintf(stderr,
+ "Option \"%s\" is unknown, try \"tc -help\".\n",
+ argv[1]);
return -1;
}
argc--; argv++;
}
+ _SL_ = oneline ? "\\" : "\n";
+
+ check_enable_color(color, json);
+
if (batch_file)
return batch(batch_file);