mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-10-05 09:21:05 +00:00
ip: add a new parameter -Numeric
Add a new parameter '-Numeric' to show the number of protocol, scope, dsfield, etc directly instead of converting it to human readable name. Do the same on tc and ss. This patch is based on David Ahern's previous patch. Suggested-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
parent
e92d221022
commit
ca697cee4c
@ -34,6 +34,7 @@ extern int timestamp_short;
|
|||||||
extern const char * _SL_;
|
extern const char * _SL_;
|
||||||
extern int max_flush_loops;
|
extern int max_flush_loops;
|
||||||
extern int batch_mode;
|
extern int batch_mode;
|
||||||
|
extern int numeric;
|
||||||
extern bool do_all;
|
extern bool do_all;
|
||||||
|
|
||||||
#ifndef CONFDIR
|
#ifndef CONFDIR
|
||||||
|
6
ip/ip.c
6
ip/ip.c
@ -36,6 +36,7 @@ int timestamp;
|
|||||||
int force;
|
int force;
|
||||||
int max_flush_loops = 10;
|
int max_flush_loops = 10;
|
||||||
int batch_mode;
|
int batch_mode;
|
||||||
|
int numeric;
|
||||||
bool do_all;
|
bool do_all;
|
||||||
|
|
||||||
struct rtnl_handle rth = { .fd = -1 };
|
struct rtnl_handle rth = { .fd = -1 };
|
||||||
@ -57,7 +58,8 @@ static void usage(void)
|
|||||||
" -4 | -6 | -I | -D | -M | -B | -0 |\n"
|
" -4 | -6 | -I | -D | -M | -B | -0 |\n"
|
||||||
" -l[oops] { maximum-addr-flush-attempts } | -br[ief] |\n"
|
" -l[oops] { maximum-addr-flush-attempts } | -br[ief] |\n"
|
||||||
" -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |\n"
|
" -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |\n"
|
||||||
" -rc[vbuf] [size] | -n[etns] name | -a[ll] | -c[olor]}\n");
|
" -rc[vbuf] [size] | -n[etns] name | -N[umeric] | -a[ll] |\n"
|
||||||
|
" -c[olor]}\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,6 +291,8 @@ int main(int argc, char **argv)
|
|||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
if (netns_switch(argv[1]))
|
if (netns_switch(argv[1]))
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
} else if (matches(opt, "-Numeric") == 0) {
|
||||||
|
++numeric;
|
||||||
} else if (matches(opt, "-all") == 0) {
|
} else if (matches(opt, "-all") == 0) {
|
||||||
do_all = true;
|
do_all = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,6 +23,12 @@
|
|||||||
|
|
||||||
char *rtnl_rtntype_n2a(int id, char *buf, int len)
|
char *rtnl_rtntype_n2a(int id, char *buf, int len)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (numeric) {
|
||||||
|
snprintf(buf, len, "%d", id);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case RTN_UNSPEC:
|
case RTN_UNSPEC:
|
||||||
return "none";
|
return "none";
|
||||||
|
@ -32,7 +32,7 @@ const char *inet_proto_n2a(int proto, char *buf, int len)
|
|||||||
return ncache;
|
return ncache;
|
||||||
|
|
||||||
pe = getprotobynumber(proto);
|
pe = getprotobynumber(proto);
|
||||||
if (pe) {
|
if (pe && !numeric) {
|
||||||
if (icache != -1)
|
if (icache != -1)
|
||||||
free(ncache);
|
free(ncache);
|
||||||
icache = proto;
|
icache = proto;
|
||||||
|
@ -92,7 +92,7 @@ const char * ll_proto_n2a(unsigned short id, char *buf, int len)
|
|||||||
|
|
||||||
id = ntohs(id);
|
id = ntohs(id);
|
||||||
|
|
||||||
for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
|
for (i=0; !numeric && i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
|
||||||
if (llproto_names[i].id == id)
|
if (llproto_names[i].id == id)
|
||||||
return llproto_names[i].name;
|
return llproto_names[i].name;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <linux/sockios.h>
|
#include <linux/sockios.h>
|
||||||
|
|
||||||
#include "rt_names.h"
|
#include "rt_names.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
const char * ll_type_n2a(int type, char *buf, int len)
|
const char * ll_type_n2a(int type, char *buf, int len)
|
||||||
{
|
{
|
||||||
@ -112,7 +113,7 @@ __PF(VOID,void)
|
|||||||
#undef __PF
|
#undef __PF
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i<sizeof(arphrd_names)/sizeof(arphrd_names[0]); i++) {
|
for (i=0; !numeric && i<sizeof(arphrd_names)/sizeof(arphrd_names[0]); i++) {
|
||||||
if (arphrd_names[i].type == type)
|
if (arphrd_names[i].type == type)
|
||||||
return arphrd_names[i].name;
|
return arphrd_names[i].name;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#define NAME_MAX_LEN 512
|
#define NAME_MAX_LEN 512
|
||||||
|
|
||||||
|
int numeric;
|
||||||
|
|
||||||
struct rtnl_hash_entry {
|
struct rtnl_hash_entry {
|
||||||
struct rtnl_hash_entry *next;
|
struct rtnl_hash_entry *next;
|
||||||
const char *name;
|
const char *name;
|
||||||
@ -180,7 +182,7 @@ static void rtnl_rtprot_initialize(void)
|
|||||||
|
|
||||||
const char *rtnl_rtprot_n2a(int id, char *buf, int len)
|
const char *rtnl_rtprot_n2a(int id, char *buf, int len)
|
||||||
{
|
{
|
||||||
if (id < 0 || id >= 256) {
|
if (id < 0 || id >= 256 || numeric) {
|
||||||
snprintf(buf, len, "%u", id);
|
snprintf(buf, len, "%u", id);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
@ -246,7 +248,7 @@ static void rtnl_rtscope_initialize(void)
|
|||||||
|
|
||||||
const char *rtnl_rtscope_n2a(int id, char *buf, int len)
|
const char *rtnl_rtscope_n2a(int id, char *buf, int len)
|
||||||
{
|
{
|
||||||
if (id < 0 || id >= 256) {
|
if (id < 0 || id >= 256 || numeric) {
|
||||||
snprintf(buf, len, "%d", id);
|
snprintf(buf, len, "%d", id);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
@ -311,7 +313,7 @@ static void rtnl_rtrealm_initialize(void)
|
|||||||
|
|
||||||
const char *rtnl_rtrealm_n2a(int id, char *buf, int len)
|
const char *rtnl_rtrealm_n2a(int id, char *buf, int len)
|
||||||
{
|
{
|
||||||
if (id < 0 || id >= 256) {
|
if (id < 0 || id >= 256 || numeric) {
|
||||||
snprintf(buf, len, "%d", id);
|
snprintf(buf, len, "%d", id);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
@ -419,7 +421,7 @@ const char *rtnl_rttable_n2a(__u32 id, char *buf, int len)
|
|||||||
entry = rtnl_rttable_hash[id & 255];
|
entry = rtnl_rttable_hash[id & 255];
|
||||||
while (entry && entry->id != id)
|
while (entry && entry->id != id)
|
||||||
entry = entry->next;
|
entry = entry->next;
|
||||||
if (entry)
|
if (!numeric && entry)
|
||||||
return entry->name;
|
return entry->name;
|
||||||
snprintf(buf, len, "%u", id);
|
snprintf(buf, len, "%u", id);
|
||||||
return buf;
|
return buf;
|
||||||
@ -484,7 +486,7 @@ const char *rtnl_dsfield_n2a(int id, char *buf, int len)
|
|||||||
if (!rtnl_rtdsfield_init)
|
if (!rtnl_rtdsfield_init)
|
||||||
rtnl_rtdsfield_initialize();
|
rtnl_rtdsfield_initialize();
|
||||||
}
|
}
|
||||||
if (rtnl_rtdsfield_tab[id])
|
if (!numeric && rtnl_rtdsfield_tab[id])
|
||||||
return rtnl_rtdsfield_tab[id];
|
return rtnl_rtdsfield_tab[id];
|
||||||
snprintf(buf, len, "0x%02x", id);
|
snprintf(buf, len, "0x%02x", id);
|
||||||
return buf;
|
return buf;
|
||||||
@ -584,7 +586,7 @@ const char *rtnl_group_n2a(int id, char *buf, int len)
|
|||||||
if (!rtnl_group_init)
|
if (!rtnl_group_init)
|
||||||
rtnl_group_initialize();
|
rtnl_group_initialize();
|
||||||
|
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; !numeric && i < 256; i++) {
|
||||||
entry = rtnl_group_hash[i];
|
entry = rtnl_group_hash[i];
|
||||||
|
|
||||||
while (entry) {
|
while (entry) {
|
||||||
@ -633,8 +635,8 @@ static void nl_proto_initialize(void)
|
|||||||
|
|
||||||
const char *nl_proto_n2a(int id, char *buf, int len)
|
const char *nl_proto_n2a(int id, char *buf, int len)
|
||||||
{
|
{
|
||||||
if (id < 0 || id >= 256) {
|
if (id < 0 || id >= 256 || numeric) {
|
||||||
snprintf(buf, len, "%u", id);
|
snprintf(buf, len, "%d", id);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ ip \- show / manipulate routing, network devices, interfaces and tunnels
|
|||||||
\fB\-t\fR[\fIimestamp\fR] |
|
\fB\-t\fR[\fIimestamp\fR] |
|
||||||
\fB\-ts\fR[\fIhort\fR] |
|
\fB\-ts\fR[\fIhort\fR] |
|
||||||
\fB\-n\fR[\fIetns\fR] name |
|
\fB\-n\fR[\fIetns\fR] name |
|
||||||
|
\fB\-N\fR[\fIumeric\fR] |
|
||||||
\fB\-a\fR[\fIll\fR] |
|
\fB\-a\fR[\fIll\fR] |
|
||||||
\fB\-c\fR[\fIolor\fR] |
|
\fB\-c\fR[\fIolor\fR] |
|
||||||
\fB\-br\fR[\fIief\fR] |
|
\fB\-br\fR[\fIief\fR] |
|
||||||
@ -174,6 +175,11 @@ to
|
|||||||
.RI "-n[etns] " NETNS " [ " OPTIONS " ] " OBJECT " { " COMMAND " | "
|
.RI "-n[etns] " NETNS " [ " OPTIONS " ] " OBJECT " { " COMMAND " | "
|
||||||
.BR help " }"
|
.BR help " }"
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BR "\-N" , " \-Numeric"
|
||||||
|
Print the number of protocol, scope, dsfield, etc directly instead of
|
||||||
|
converting it to human readable name.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BR "\-a" , " \-all"
|
.BR "\-a" , " \-all"
|
||||||
executes specified command over all objects, it depends if command
|
executes specified command over all objects, it depends if command
|
||||||
|
@ -119,6 +119,7 @@ tc \- show / manipulate traffic control settings
|
|||||||
.IR OPTIONS " := {"
|
.IR OPTIONS " := {"
|
||||||
\fB[ -force ] -b\fR[\fIatch\fR] \fB[ filename ] \fR|
|
\fB[ -force ] -b\fR[\fIatch\fR] \fB[ filename ] \fR|
|
||||||
\fB[ \fB-n\fR[\fIetns\fR] name \fB] \fR|
|
\fB[ \fB-n\fR[\fIetns\fR] name \fB] \fR|
|
||||||
|
\fB[ \fB-N\fR[\fIumeric\fR] \fB] \fR|
|
||||||
\fB[ \fB-nm \fR| \fB-nam\fR[\fIes\fR] \fB] \fR|
|
\fB[ \fB-nm \fR| \fB-nam\fR[\fIes\fR] \fB] \fR|
|
||||||
\fB[ \fR{ \fB-cf \fR| \fB-c\fR[\fIonf\fR] \fR} \fB[ filename ] \fB] \fR
|
\fB[ \fR{ \fB-cf \fR| \fB-c\fR[\fIonf\fR] \fR} \fB[ filename ] \fB] \fR
|
||||||
\fB[ -t\fR[imestamp\fR] \fB\] \fR| \fB[ -t\fR[short\fR] \fR| \fB[
|
\fB[ -t\fR[imestamp\fR] \fB\] \fR| \fB[ -t\fR[short\fR] \fR| \fB[
|
||||||
@ -707,6 +708,11 @@ to
|
|||||||
.RI "-n[etns] " NETNS " [ " OPTIONS " ] " OBJECT " { " COMMAND " | "
|
.RI "-n[etns] " NETNS " [ " OPTIONS " ] " OBJECT " { " COMMAND " | "
|
||||||
.BR help " }"
|
.BR help " }"
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BR "\-N" , " \-Numeric"
|
||||||
|
Print the number of protocol, scope, dsfield, etc directly instead of
|
||||||
|
converting it to human readable name.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BR "\-cf" , " \-conf " <FILENAME>
|
.BR "\-cf" , " \-conf " <FILENAME>
|
||||||
specifies path to the config file. This option is used in conjunction with other options (e.g.
|
specifies path to the config file. This option is used in conjunction with other options (e.g.
|
||||||
|
13
misc/ss.c
13
misc/ss.c
@ -106,7 +106,6 @@ static int security_get_initial_context(char *name, char **context)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int resolve_services = 1;
|
|
||||||
int preferred_family = AF_UNSPEC;
|
int preferred_family = AF_UNSPEC;
|
||||||
static int show_options;
|
static int show_options;
|
||||||
int show_details;
|
int show_details;
|
||||||
@ -121,6 +120,7 @@ static int follow_events;
|
|||||||
static int sctp_ino;
|
static int sctp_ino;
|
||||||
static int show_tipcinfo;
|
static int show_tipcinfo;
|
||||||
static int show_tos;
|
static int show_tos;
|
||||||
|
int numeric;
|
||||||
int oneline;
|
int oneline;
|
||||||
|
|
||||||
enum col_id {
|
enum col_id {
|
||||||
@ -1553,7 +1553,7 @@ static const char *resolve_service(int port)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!resolve_services)
|
if (numeric)
|
||||||
goto do_numeric;
|
goto do_numeric;
|
||||||
|
|
||||||
if (dg_proto == RAW_PROTO)
|
if (dg_proto == RAW_PROTO)
|
||||||
@ -4296,14 +4296,11 @@ static int netlink_show_one(struct filter *f,
|
|||||||
|
|
||||||
sock_state_print(&st);
|
sock_state_print(&st);
|
||||||
|
|
||||||
if (resolve_services)
|
|
||||||
prot_name = nl_proto_n2a(prot, prot_buf, sizeof(prot_buf));
|
prot_name = nl_proto_n2a(prot, prot_buf, sizeof(prot_buf));
|
||||||
else
|
|
||||||
prot_name = int_to_str(prot, prot_buf);
|
|
||||||
|
|
||||||
if (pid == -1) {
|
if (pid == -1) {
|
||||||
procname[0] = '*';
|
procname[0] = '*';
|
||||||
} else if (resolve_services) {
|
} else if (!numeric) {
|
||||||
int done = 0;
|
int done = 0;
|
||||||
|
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
@ -5050,7 +5047,7 @@ int main(int argc, char *argv[])
|
|||||||
long_opts, NULL)) != EOF) {
|
long_opts, NULL)) != EOF) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'n':
|
case 'n':
|
||||||
resolve_services = 0;
|
numeric = 1;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
resolve_hosts = 1;
|
resolve_hosts = 1;
|
||||||
@ -5268,7 +5265,7 @@ int main(int argc, char *argv[])
|
|||||||
filter_states_set(¤t_filter, state_filter);
|
filter_states_set(¤t_filter, state_filter);
|
||||||
filter_merge_defaults(¤t_filter);
|
filter_merge_defaults(¤t_filter);
|
||||||
|
|
||||||
if (resolve_services && resolve_hosts &&
|
if (!numeric && resolve_hosts &&
|
||||||
(current_filter.dbs & (UNIX_DBM|INET_L4_DBM)))
|
(current_filter.dbs & (UNIX_DBM|INET_L4_DBM)))
|
||||||
init_service_resolver();
|
init_service_resolver();
|
||||||
|
|
||||||
|
5
tc/tc.c
5
tc/tc.c
@ -43,6 +43,7 @@ bool use_names;
|
|||||||
int json;
|
int json;
|
||||||
int color;
|
int color;
|
||||||
int oneline;
|
int oneline;
|
||||||
|
int numeric;
|
||||||
|
|
||||||
static char *conf_file;
|
static char *conf_file;
|
||||||
|
|
||||||
@ -200,7 +201,7 @@ static void usage(void)
|
|||||||
" action | monitor | exec }\n"
|
" action | monitor | exec }\n"
|
||||||
" OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[aw] |\n"
|
" OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[aw] |\n"
|
||||||
" -o[neline] | -j[son] | -p[retty] | -c[olor]\n"
|
" -o[neline] | -j[son] | -p[retty] | -c[olor]\n"
|
||||||
" -b[atch] [filename] | -n[etns] name |\n"
|
" -b[atch] [filename] | -n[etns] name | -N[umeric] |\n"
|
||||||
" -nm | -nam[es] | { -cf | -conf } path }\n");
|
" -nm | -nam[es] | { -cf | -conf } path }\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,6 +487,8 @@ int main(int argc, char **argv)
|
|||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
if (netns_switch(argv[1]))
|
if (netns_switch(argv[1]))
|
||||||
return -1;
|
return -1;
|
||||||
|
} else if (matches(argv[1], "-Numeric") == 0) {
|
||||||
|
++numeric;
|
||||||
} else if (matches(argv[1], "-names") == 0 ||
|
} else if (matches(argv[1], "-names") == 0 ||
|
||||||
matches(argv[1], "-nm") == 0) {
|
matches(argv[1], "-nm") == 0) {
|
||||||
use_names = true;
|
use_names = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user