Merge branch 'master' into net-next
This commit is contained in:
commit
fece33c195
|
|
@ -0,0 +1,3 @@
|
||||||
|
Each file in this directory is an rt_tables configuration file. iproute2
|
||||||
|
commands scan this directory processing all files that end in '.conf'.
|
||||||
|
|
||||||
|
|
@ -60,11 +60,16 @@ struct rtnl_dump_filter_arg
|
||||||
{
|
{
|
||||||
rtnl_filter_t filter;
|
rtnl_filter_t filter;
|
||||||
void *arg1;
|
void *arg1;
|
||||||
|
__u16 nc_flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
int rtnl_dump_filter_l(struct rtnl_handle *rth,
|
int rtnl_dump_filter_l(struct rtnl_handle *rth,
|
||||||
const struct rtnl_dump_filter_arg *arg);
|
const struct rtnl_dump_filter_arg *arg);
|
||||||
int rtnl_dump_filter(struct rtnl_handle *rth, rtnl_filter_t filter, void *arg);
|
int rtnl_dump_filter_nc(struct rtnl_handle *rth,
|
||||||
|
rtnl_filter_t filter,
|
||||||
|
void *arg, __u16 nc_flags);
|
||||||
|
#define rtnl_dump_filter(rth, filter, arg) \
|
||||||
|
rtnl_dump_filter_nc(rth, filter, arg, 0)
|
||||||
int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
|
int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
|
||||||
struct nlmsghdr *answer, size_t len)
|
struct nlmsghdr *answer, size_t len)
|
||||||
__attribute__((warn_unused_result));
|
__attribute__((warn_unused_result));
|
||||||
|
|
|
||||||
|
|
@ -1148,28 +1148,6 @@ brief_exit:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int print_addrinfo_primary(const struct sockaddr_nl *who,
|
|
||||||
struct nlmsghdr *n, void *arg)
|
|
||||||
{
|
|
||||||
struct ifaddrmsg *ifa = NLMSG_DATA(n);
|
|
||||||
|
|
||||||
if (ifa->ifa_flags & IFA_F_SECONDARY)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return print_addrinfo(who, n, arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int print_addrinfo_secondary(const struct sockaddr_nl *who,
|
|
||||||
struct nlmsghdr *n, void *arg)
|
|
||||||
{
|
|
||||||
struct ifaddrmsg *ifa = NLMSG_DATA(n);
|
|
||||||
|
|
||||||
if (!(ifa->ifa_flags & IFA_F_SECONDARY))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return print_addrinfo(who, n, arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct nlmsg_list
|
struct nlmsg_list
|
||||||
{
|
{
|
||||||
struct nlmsg_list *next;
|
struct nlmsg_list *next;
|
||||||
|
|
@ -1420,26 +1398,13 @@ static int ipaddr_flush(void)
|
||||||
filter.flushe = sizeof(flushb);
|
filter.flushe = sizeof(flushb);
|
||||||
|
|
||||||
while ((max_flush_loops == 0) || (round < max_flush_loops)) {
|
while ((max_flush_loops == 0) || (round < max_flush_loops)) {
|
||||||
const struct rtnl_dump_filter_arg a[3] = {
|
|
||||||
{
|
|
||||||
.filter = print_addrinfo_secondary,
|
|
||||||
.arg1 = stdout,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.filter = print_addrinfo_primary,
|
|
||||||
.arg1 = stdout,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.filter = NULL,
|
|
||||||
.arg1 = NULL,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
if (rtnl_wilddump_request(&rth, filter.family, RTM_GETADDR) < 0) {
|
if (rtnl_wilddump_request(&rth, filter.family, RTM_GETADDR) < 0) {
|
||||||
perror("Cannot send dump request");
|
perror("Cannot send dump request");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
filter.flushed = 0;
|
filter.flushed = 0;
|
||||||
if (rtnl_dump_filter_l(&rth, a) < 0) {
|
if (rtnl_dump_filter_nc(&rth, print_addrinfo,
|
||||||
|
stdout, NLM_F_DUMP_INTR) < 0) {
|
||||||
fprintf(stderr, "Flush terminated\n");
|
fprintf(stderr, "Flush terminated\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
@ -1486,10 +1451,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
|
||||||
|
|
||||||
ipaddr_reset_filter(oneline, 0);
|
ipaddr_reset_filter(oneline, 0);
|
||||||
filter.showqueue = 1;
|
filter.showqueue = 1;
|
||||||
|
filter.family = preferred_family;
|
||||||
if (filter.family == AF_UNSPEC)
|
|
||||||
filter.family = preferred_family;
|
|
||||||
|
|
||||||
filter.group = -1;
|
filter.group = -1;
|
||||||
|
|
||||||
if (action == IPADD_FLUSH) {
|
if (action == IPADD_FLUSH) {
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ static void print_explain(FILE *f)
|
||||||
fprintf(f, " [ [no]l2miss ] [ [no]l3miss ]\n");
|
fprintf(f, " [ [no]l2miss ] [ [no]l3miss ]\n");
|
||||||
fprintf(f, " [ ageing SECONDS ] [ maxaddress NUMBER ]\n");
|
fprintf(f, " [ ageing SECONDS ] [ maxaddress NUMBER ]\n");
|
||||||
fprintf(f, " [ [no]udpcsum ] [ [no]udp6zerocsumtx ] [ [no]udp6zerocsumrx ]\n");
|
fprintf(f, " [ [no]udpcsum ] [ [no]udp6zerocsumtx ] [ [no]udp6zerocsumrx ]\n");
|
||||||
|
fprintf(f, " [ [no]remcsumtx ] [ [no]remcsumrx ]\n");
|
||||||
fprintf(f, " [ gbp ]\n");
|
fprintf(f, " [ gbp ]\n");
|
||||||
fprintf(f, "\n");
|
fprintf(f, "\n");
|
||||||
fprintf(f, "Where: VNI := 0-16777215\n");
|
fprintf(f, "Where: VNI := 0-16777215\n");
|
||||||
|
|
@ -69,6 +70,8 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
|
||||||
__u8 udpcsum = 0;
|
__u8 udpcsum = 0;
|
||||||
__u8 udp6zerocsumtx = 0;
|
__u8 udp6zerocsumtx = 0;
|
||||||
__u8 udp6zerocsumrx = 0;
|
__u8 udp6zerocsumrx = 0;
|
||||||
|
__u8 remcsumtx = 0;
|
||||||
|
__u8 remcsumrx = 0;
|
||||||
__u8 gbp = 0;
|
__u8 gbp = 0;
|
||||||
int dst_port_set = 0;
|
int dst_port_set = 0;
|
||||||
struct ifla_vxlan_port_range range = { 0, 0 };
|
struct ifla_vxlan_port_range range = { 0, 0 };
|
||||||
|
|
@ -199,6 +202,14 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
|
||||||
udp6zerocsumrx = 1;
|
udp6zerocsumrx = 1;
|
||||||
} else if (!matches(*argv, "noudp6zerocsumrx")) {
|
} else if (!matches(*argv, "noudp6zerocsumrx")) {
|
||||||
udp6zerocsumrx = 0;
|
udp6zerocsumrx = 0;
|
||||||
|
} else if (!matches(*argv, "remcsumtx")) {
|
||||||
|
remcsumtx = 1;
|
||||||
|
} else if (!matches(*argv, "noremcsumtx")) {
|
||||||
|
remcsumtx = 0;
|
||||||
|
} else if (!matches(*argv, "remcsumrx")) {
|
||||||
|
remcsumrx = 1;
|
||||||
|
} else if (!matches(*argv, "noremcsumrx")) {
|
||||||
|
remcsumrx = 0;
|
||||||
} else if (!matches(*argv, "gbp")) {
|
} else if (!matches(*argv, "gbp")) {
|
||||||
gbp = 1;
|
gbp = 1;
|
||||||
} else if (matches(*argv, "help") == 0) {
|
} else if (matches(*argv, "help") == 0) {
|
||||||
|
|
@ -259,6 +270,8 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
|
||||||
addattr8(n, 1024, IFLA_VXLAN_UDP_CSUM, udpcsum);
|
addattr8(n, 1024, IFLA_VXLAN_UDP_CSUM, udpcsum);
|
||||||
addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, udp6zerocsumtx);
|
addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, udp6zerocsumtx);
|
||||||
addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, udp6zerocsumrx);
|
addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, udp6zerocsumrx);
|
||||||
|
addattr8(n, 1024, IFLA_VXLAN_REMCSUM_TX, remcsumtx);
|
||||||
|
addattr8(n, 1024, IFLA_VXLAN_REMCSUM_RX, remcsumrx);
|
||||||
|
|
||||||
if (noage)
|
if (noage)
|
||||||
addattr32(n, 1024, IFLA_VXLAN_AGEING, 0);
|
addattr32(n, 1024, IFLA_VXLAN_AGEING, 0);
|
||||||
|
|
@ -407,6 +420,14 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
||||||
rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]))
|
rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]))
|
||||||
fputs("udp6zerocsumrx ", f);
|
fputs("udp6zerocsumrx ", f);
|
||||||
|
|
||||||
|
if (tb[IFLA_VXLAN_REMCSUM_TX] &&
|
||||||
|
rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_TX]))
|
||||||
|
fputs("remcsumtx ", f);
|
||||||
|
|
||||||
|
if (tb[IFLA_VXLAN_REMCSUM_RX] &&
|
||||||
|
rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_RX]))
|
||||||
|
fputs("remcsumrx ", f);
|
||||||
|
|
||||||
if (tb[IFLA_VXLAN_GBP])
|
if (tb[IFLA_VXLAN_GBP])
|
||||||
fputs("gbp ", f);
|
fputs("gbp ", f);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -931,7 +931,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
|
||||||
mxlock |= (1<<RTAX_HOPLIMIT);
|
mxlock |= (1<<RTAX_HOPLIMIT);
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
}
|
}
|
||||||
if (get_unsigned(&hoplimit, *argv, 0))
|
if (get_unsigned(&hoplimit, *argv, 0) || hoplimit > 255)
|
||||||
invarg("\"hoplimit\" value is invalid\n", *argv);
|
invarg("\"hoplimit\" value is invalid\n", *argv);
|
||||||
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_HOPLIMIT, hoplimit);
|
rta_addattr32(mxrta, sizeof(mxbuf), RTAX_HOPLIMIT, hoplimit);
|
||||||
} else if (strcmp(*argv, "advmss") == 0) {
|
} else if (strcmp(*argv, "advmss") == 0) {
|
||||||
|
|
|
||||||
|
|
@ -95,10 +95,6 @@ static int iptoken_list(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int af = AF_INET6;
|
int af = AF_INET6;
|
||||||
struct rtnl_dump_args da;
|
struct rtnl_dump_args da;
|
||||||
const struct rtnl_dump_filter_arg a[2] = {
|
|
||||||
{ .filter = print_token, .arg1 = &da, },
|
|
||||||
{ .filter = NULL, .arg1 = NULL, },
|
|
||||||
};
|
|
||||||
|
|
||||||
memset(&da, 0, sizeof(da));
|
memset(&da, 0, sizeof(da));
|
||||||
da.fp = stdout;
|
da.fp = stdout;
|
||||||
|
|
@ -118,7 +114,7 @@ static int iptoken_list(int argc, char **argv)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rtnl_dump_filter_l(&rth, a) < 0) {
|
if (rtnl_dump_filter(&rth, print_token, &da) < 0) {
|
||||||
fprintf(stderr, "Dump terminated\n");
|
fprintf(stderr, "Dump terminated\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -259,6 +259,8 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
|
||||||
while (NLMSG_OK(h, msglen)) {
|
while (NLMSG_OK(h, msglen)) {
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
h->nlmsg_flags &= ~a->nc_flags;
|
||||||
|
|
||||||
if (nladdr.nl_pid != 0 ||
|
if (nladdr.nl_pid != 0 ||
|
||||||
h->nlmsg_pid != rth->local.nl_pid ||
|
h->nlmsg_pid != rth->local.nl_pid ||
|
||||||
h->nlmsg_seq != rth->dump)
|
h->nlmsg_seq != rth->dump)
|
||||||
|
|
@ -317,13 +319,13 @@ skip_it:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int rtnl_dump_filter(struct rtnl_handle *rth,
|
int rtnl_dump_filter_nc(struct rtnl_handle *rth,
|
||||||
rtnl_filter_t filter,
|
rtnl_filter_t filter,
|
||||||
void *arg1)
|
void *arg1, __u16 nc_flags)
|
||||||
{
|
{
|
||||||
const struct rtnl_dump_filter_arg a[2] = {
|
const struct rtnl_dump_filter_arg a[2] = {
|
||||||
{ .filter = filter, .arg1 = arg1, },
|
{ .filter = filter, .arg1 = arg1, .nc_flags = nc_flags, },
|
||||||
{ .filter = NULL, .arg1 = NULL, },
|
{ .filter = NULL, .arg1 = NULL, .nc_flags = 0, },
|
||||||
};
|
};
|
||||||
|
|
||||||
return rtnl_dump_filter_l(rth, a);
|
return rtnl_dump_filter_l(rth, a);
|
||||||
|
|
|
||||||
136
lib/rt_names.c
136
lib/rt_names.c
|
|
@ -17,6 +17,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
#include <asm/types.h>
|
#include <asm/types.h>
|
||||||
#include <linux/rtnetlink.h>
|
#include <linux/rtnetlink.h>
|
||||||
|
|
@ -30,8 +31,8 @@
|
||||||
#define NAME_MAX_LEN 512
|
#define NAME_MAX_LEN 512
|
||||||
|
|
||||||
struct rtnl_hash_entry {
|
struct rtnl_hash_entry {
|
||||||
struct rtnl_hash_entry *next;
|
struct rtnl_hash_entry *next;
|
||||||
const char * name;
|
const char *name;
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -81,7 +82,7 @@ rtnl_hash_initialize(const char *file, struct rtnl_hash_entry **hash, int size)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id<0)
|
if (id < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
entry = malloc(sizeof(*entry));
|
entry = malloc(sizeof(*entry));
|
||||||
|
|
@ -111,7 +112,7 @@ static void rtnl_tab_initialize(const char *file, char **tab, int size)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (id<0 || id>size)
|
if (id < 0 || id > size)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
tab[id] = strdup(namebuf);
|
tab[id] = strdup(namebuf);
|
||||||
|
|
@ -119,23 +120,23 @@ static void rtnl_tab_initialize(const char *file, char **tab, int size)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char * rtnl_rtprot_tab[256] = {
|
static char *rtnl_rtprot_tab[256] = {
|
||||||
[RTPROT_UNSPEC] = "none",
|
[RTPROT_UNSPEC] = "none",
|
||||||
[RTPROT_REDIRECT] ="redirect",
|
[RTPROT_REDIRECT] = "redirect",
|
||||||
[RTPROT_KERNEL] = "kernel",
|
[RTPROT_KERNEL] = "kernel",
|
||||||
[RTPROT_BOOT] = "boot",
|
[RTPROT_BOOT] = "boot",
|
||||||
[RTPROT_STATIC] = "static",
|
[RTPROT_STATIC] = "static",
|
||||||
|
|
||||||
[RTPROT_GATED] = "gated",
|
[RTPROT_GATED] = "gated",
|
||||||
[RTPROT_RA] = "ra",
|
[RTPROT_RA] = "ra",
|
||||||
[RTPROT_MRT] = "mrt",
|
[RTPROT_MRT] = "mrt",
|
||||||
[RTPROT_ZEBRA] ="zebra",
|
[RTPROT_ZEBRA] = "zebra",
|
||||||
[RTPROT_BIRD] = "bird",
|
[RTPROT_BIRD] = "bird",
|
||||||
[RTPROT_BABEL] = "babel",
|
[RTPROT_BABEL] = "babel",
|
||||||
[RTPROT_DNROUTED] = "dnrouted",
|
[RTPROT_DNROUTED] = "dnrouted",
|
||||||
[RTPROT_XORP] = "xorp",
|
[RTPROT_XORP] = "xorp",
|
||||||
[RTPROT_NTK] = "ntk",
|
[RTPROT_NTK] = "ntk",
|
||||||
[RTPROT_DHCP] = "dhcp",
|
[RTPROT_DHCP] = "dhcp",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -148,9 +149,9 @@ static void rtnl_rtprot_initialize(void)
|
||||||
rtnl_rtprot_tab, 256);
|
rtnl_rtprot_tab, 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
snprintf(buf, len, "%u", id);
|
snprintf(buf, len, "%u", id);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
@ -166,7 +167,7 @@ const char * rtnl_rtprot_n2a(int id, char *buf, int len)
|
||||||
|
|
||||||
int rtnl_rtprot_a2n(__u32 *id, const char *arg)
|
int rtnl_rtprot_a2n(__u32 *id, const char *arg)
|
||||||
{
|
{
|
||||||
static char *cache = NULL;
|
static char *cache;
|
||||||
static unsigned long res;
|
static unsigned long res;
|
||||||
char *end;
|
char *end;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -179,7 +180,7 @@ int rtnl_rtprot_a2n(__u32 *id, const char *arg)
|
||||||
if (!rtnl_rtprot_init)
|
if (!rtnl_rtprot_init)
|
||||||
rtnl_rtprot_initialize();
|
rtnl_rtprot_initialize();
|
||||||
|
|
||||||
for (i=0; i<256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
if (rtnl_rtprot_tab[i] &&
|
if (rtnl_rtprot_tab[i] &&
|
||||||
strcmp(rtnl_rtprot_tab[i], arg) == 0) {
|
strcmp(rtnl_rtprot_tab[i], arg) == 0) {
|
||||||
cache = rtnl_rtprot_tab[i];
|
cache = rtnl_rtprot_tab[i];
|
||||||
|
|
@ -196,8 +197,13 @@ int rtnl_rtprot_a2n(__u32 *id, const char *arg)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char * rtnl_rtscope_tab[256] = {
|
|
||||||
"global",
|
static char *rtnl_rtscope_tab[256] = {
|
||||||
|
[RT_SCOPE_UNIVERSE] = "global",
|
||||||
|
[RT_SCOPE_NOWHERE] = "nowhere",
|
||||||
|
[RT_SCOPE_HOST] = "host",
|
||||||
|
[RT_SCOPE_LINK] = "link",
|
||||||
|
[RT_SCOPE_SITE] = "site",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int rtnl_rtscope_init;
|
static int rtnl_rtscope_init;
|
||||||
|
|
@ -205,33 +211,32 @@ static int rtnl_rtscope_init;
|
||||||
static void rtnl_rtscope_initialize(void)
|
static void rtnl_rtscope_initialize(void)
|
||||||
{
|
{
|
||||||
rtnl_rtscope_init = 1;
|
rtnl_rtscope_init = 1;
|
||||||
rtnl_rtscope_tab[RT_SCOPE_NOWHERE] = "nowhere";
|
|
||||||
rtnl_rtscope_tab[RT_SCOPE_HOST] = "host";
|
|
||||||
rtnl_rtscope_tab[RT_SCOPE_LINK] = "link";
|
|
||||||
rtnl_rtscope_tab[RT_SCOPE_SITE] = "site";
|
|
||||||
rtnl_tab_initialize(CONFDIR "/rt_scopes",
|
rtnl_tab_initialize(CONFDIR "/rt_scopes",
|
||||||
rtnl_rtscope_tab, 256);
|
rtnl_rtscope_tab, 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
snprintf(buf, len, "%d", id);
|
snprintf(buf, len, "%d", id);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rtnl_rtscope_tab[id]) {
|
if (!rtnl_rtscope_tab[id]) {
|
||||||
if (!rtnl_rtscope_init)
|
if (!rtnl_rtscope_init)
|
||||||
rtnl_rtscope_initialize();
|
rtnl_rtscope_initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rtnl_rtscope_tab[id])
|
if (rtnl_rtscope_tab[id])
|
||||||
return rtnl_rtscope_tab[id];
|
return rtnl_rtscope_tab[id];
|
||||||
|
|
||||||
snprintf(buf, len, "%d", id);
|
snprintf(buf, len, "%d", id);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rtnl_rtscope_a2n(__u32 *id, const char *arg)
|
int rtnl_rtscope_a2n(__u32 *id, const char *arg)
|
||||||
{
|
{
|
||||||
static const char *cache = NULL;
|
static const char *cache;
|
||||||
static unsigned long res;
|
static unsigned long res;
|
||||||
char *end;
|
char *end;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -244,7 +249,7 @@ int rtnl_rtscope_a2n(__u32 *id, const char *arg)
|
||||||
if (!rtnl_rtscope_init)
|
if (!rtnl_rtscope_init)
|
||||||
rtnl_rtscope_initialize();
|
rtnl_rtscope_initialize();
|
||||||
|
|
||||||
for (i=0; i<256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
if (rtnl_rtscope_tab[i] &&
|
if (rtnl_rtscope_tab[i] &&
|
||||||
strcmp(rtnl_rtscope_tab[i], arg) == 0) {
|
strcmp(rtnl_rtscope_tab[i], arg) == 0) {
|
||||||
cache = rtnl_rtscope_tab[i];
|
cache = rtnl_rtscope_tab[i];
|
||||||
|
|
@ -262,7 +267,7 @@ int rtnl_rtscope_a2n(__u32 *id, const char *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char * rtnl_rtrealm_tab[256] = {
|
static char *rtnl_rtrealm_tab[256] = {
|
||||||
"unknown",
|
"unknown",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -277,7 +282,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) {
|
||||||
snprintf(buf, len, "%d", id);
|
snprintf(buf, len, "%d", id);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
@ -294,7 +299,7 @@ const char *rtnl_rtrealm_n2a(int id, char *buf, int len)
|
||||||
|
|
||||||
int rtnl_rtrealm_a2n(__u32 *id, const char *arg)
|
int rtnl_rtrealm_a2n(__u32 *id, const char *arg)
|
||||||
{
|
{
|
||||||
static char *cache = NULL;
|
static char *cache;
|
||||||
static unsigned long res;
|
static unsigned long res;
|
||||||
char *end;
|
char *end;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -307,7 +312,7 @@ int rtnl_rtrealm_a2n(__u32 *id, const char *arg)
|
||||||
if (!rtnl_rtrealm_init)
|
if (!rtnl_rtrealm_init)
|
||||||
rtnl_rtrealm_initialize();
|
rtnl_rtrealm_initialize();
|
||||||
|
|
||||||
for (i=0; i<256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
if (rtnl_rtrealm_tab[i] &&
|
if (rtnl_rtrealm_tab[i] &&
|
||||||
strcmp(rtnl_rtrealm_tab[i], arg) == 0) {
|
strcmp(rtnl_rtrealm_tab[i], arg) == 0) {
|
||||||
cache = rtnl_rtrealm_tab[i];
|
cache = rtnl_rtrealm_tab[i];
|
||||||
|
|
@ -329,7 +334,7 @@ static struct rtnl_hash_entry dflt_table_entry = { .name = "default" };
|
||||||
static struct rtnl_hash_entry main_table_entry = { .name = "main" };
|
static struct rtnl_hash_entry main_table_entry = { .name = "main" };
|
||||||
static struct rtnl_hash_entry local_table_entry = { .name = "local" };
|
static struct rtnl_hash_entry local_table_entry = { .name = "local" };
|
||||||
|
|
||||||
static struct rtnl_hash_entry * rtnl_rttable_hash[256] = {
|
static struct rtnl_hash_entry *rtnl_rttable_hash[256] = {
|
||||||
[RT_TABLE_DEFAULT] = &dflt_table_entry,
|
[RT_TABLE_DEFAULT] = &dflt_table_entry,
|
||||||
[RT_TABLE_MAIN] = &main_table_entry,
|
[RT_TABLE_MAIN] = &main_table_entry,
|
||||||
[RT_TABLE_LOCAL] = &local_table_entry,
|
[RT_TABLE_LOCAL] = &local_table_entry,
|
||||||
|
|
@ -339,6 +344,8 @@ static int rtnl_rttable_init;
|
||||||
|
|
||||||
static void rtnl_rttable_initialize(void)
|
static void rtnl_rttable_initialize(void)
|
||||||
{
|
{
|
||||||
|
struct dirent *de;
|
||||||
|
DIR *d;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
rtnl_rttable_init = 1;
|
rtnl_rttable_init = 1;
|
||||||
|
|
@ -348,9 +355,33 @@ static void rtnl_rttable_initialize(void)
|
||||||
}
|
}
|
||||||
rtnl_hash_initialize(CONFDIR "/rt_tables",
|
rtnl_hash_initialize(CONFDIR "/rt_tables",
|
||||||
rtnl_rttable_hash, 256);
|
rtnl_rttable_hash, 256);
|
||||||
|
|
||||||
|
d = opendir(CONFDIR "/rt_tables.d");
|
||||||
|
if (!d)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while ((de = readdir(d)) != NULL) {
|
||||||
|
char path[PATH_MAX];
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if (*de->d_name == '.')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* only consider filenames ending in '.conf' */
|
||||||
|
len = strlen(de->d_name);
|
||||||
|
if (len <= 5)
|
||||||
|
continue;
|
||||||
|
if (strcmp(de->d_name + len - 5, ".conf"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
snprintf(path, sizeof(path),
|
||||||
|
CONFDIR "/rt_tables.d/%s", de->d_name);
|
||||||
|
rtnl_hash_initialize(path, rtnl_rttable_hash, 256);
|
||||||
|
}
|
||||||
|
closedir(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * rtnl_rttable_n2a(__u32 id, char *buf, int len)
|
const char *rtnl_rttable_n2a(__u32 id, char *buf, int len)
|
||||||
{
|
{
|
||||||
struct rtnl_hash_entry *entry;
|
struct rtnl_hash_entry *entry;
|
||||||
|
|
||||||
|
|
@ -371,7 +402,7 @@ const char * rtnl_rttable_n2a(__u32 id, char *buf, int len)
|
||||||
|
|
||||||
int rtnl_rttable_a2n(__u32 *id, const char *arg)
|
int rtnl_rttable_a2n(__u32 *id, const char *arg)
|
||||||
{
|
{
|
||||||
static const char *cache = NULL;
|
static const char *cache;
|
||||||
static unsigned long res;
|
static unsigned long res;
|
||||||
struct rtnl_hash_entry *entry;
|
struct rtnl_hash_entry *entry;
|
||||||
char *end;
|
char *end;
|
||||||
|
|
@ -385,7 +416,7 @@ int rtnl_rttable_a2n(__u32 *id, const char *arg)
|
||||||
if (!rtnl_rttable_init)
|
if (!rtnl_rttable_init)
|
||||||
rtnl_rttable_initialize();
|
rtnl_rttable_initialize();
|
||||||
|
|
||||||
for (i=0; i<256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
entry = rtnl_rttable_hash[i];
|
entry = rtnl_rttable_hash[i];
|
||||||
while (entry && strcmp(entry->name, arg))
|
while (entry && strcmp(entry->name, arg))
|
||||||
entry = entry->next;
|
entry = entry->next;
|
||||||
|
|
@ -405,7 +436,7 @@ int rtnl_rttable_a2n(__u32 *id, const char *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char * rtnl_rtdsfield_tab[256] = {
|
static char *rtnl_rtdsfield_tab[256] = {
|
||||||
"0",
|
"0",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -420,7 +451,7 @@ static void rtnl_rtdsfield_initialize(void)
|
||||||
|
|
||||||
const char *rtnl_dsfield_n2a(int id, char *buf, int len)
|
const char *rtnl_dsfield_n2a(int id, char *buf, int len)
|
||||||
{
|
{
|
||||||
if (id<0 || id>=256) {
|
if (id < 0 || id >= 256) {
|
||||||
snprintf(buf, len, "%d", id);
|
snprintf(buf, len, "%d", id);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
@ -437,7 +468,7 @@ const char *rtnl_dsfield_n2a(int id, char *buf, int len)
|
||||||
|
|
||||||
int rtnl_dsfield_a2n(__u32 *id, const char *arg)
|
int rtnl_dsfield_a2n(__u32 *id, const char *arg)
|
||||||
{
|
{
|
||||||
static char *cache = NULL;
|
static char *cache;
|
||||||
static unsigned long res;
|
static unsigned long res;
|
||||||
char *end;
|
char *end;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -450,7 +481,7 @@ int rtnl_dsfield_a2n(__u32 *id, const char *arg)
|
||||||
if (!rtnl_rtdsfield_init)
|
if (!rtnl_rtdsfield_init)
|
||||||
rtnl_rtdsfield_initialize();
|
rtnl_rtdsfield_initialize();
|
||||||
|
|
||||||
for (i=0; i<256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
if (rtnl_rtdsfield_tab[i] &&
|
if (rtnl_rtdsfield_tab[i] &&
|
||||||
strcmp(rtnl_rtdsfield_tab[i], arg) == 0) {
|
strcmp(rtnl_rtdsfield_tab[i], arg) == 0) {
|
||||||
cache = rtnl_rtdsfield_tab[i];
|
cache = rtnl_rtdsfield_tab[i];
|
||||||
|
|
@ -468,9 +499,11 @@ int rtnl_dsfield_a2n(__u32 *id, const char *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct rtnl_hash_entry dflt_group_entry = { .id = 0, .name = "default" };
|
static struct rtnl_hash_entry dflt_group_entry = {
|
||||||
|
.id = 0, .name = "default"
|
||||||
|
};
|
||||||
|
|
||||||
static struct rtnl_hash_entry * rtnl_group_hash[256] = {
|
static struct rtnl_hash_entry *rtnl_group_hash[256] = {
|
||||||
[0] = &dflt_group_entry,
|
[0] = &dflt_group_entry,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -485,7 +518,7 @@ static void rtnl_group_initialize(void)
|
||||||
|
|
||||||
int rtnl_group_a2n(int *id, const char *arg)
|
int rtnl_group_a2n(int *id, const char *arg)
|
||||||
{
|
{
|
||||||
static const char *cache = NULL;
|
static const char *cache;
|
||||||
static unsigned long res;
|
static unsigned long res;
|
||||||
struct rtnl_hash_entry *entry;
|
struct rtnl_hash_entry *entry;
|
||||||
char *end;
|
char *end;
|
||||||
|
|
@ -499,7 +532,7 @@ int rtnl_group_a2n(int *id, const char *arg)
|
||||||
if (!rtnl_group_init)
|
if (!rtnl_group_init)
|
||||||
rtnl_group_initialize();
|
rtnl_group_initialize();
|
||||||
|
|
||||||
for (i=0; i<256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
entry = rtnl_group_hash[i];
|
entry = rtnl_group_hash[i];
|
||||||
while (entry && strcmp(entry->name, arg))
|
while (entry && strcmp(entry->name, arg))
|
||||||
entry = entry->next;
|
entry = entry->next;
|
||||||
|
|
@ -526,11 +559,10 @@ 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; i < 256; i++) {
|
||||||
entry = rtnl_group_hash[i];
|
entry = rtnl_group_hash[i];
|
||||||
if (entry && entry->id == id) {
|
if (entry && entry->id == id)
|
||||||
return entry->name;
|
return entry->name;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf, len, "%d", id);
|
snprintf(buf, len, "%d", id);
|
||||||
|
|
@ -589,7 +621,7 @@ const char *nl_proto_n2a(int id, char *buf, int len)
|
||||||
|
|
||||||
int nl_proto_a2n(__u32 *id, const char *arg)
|
int nl_proto_a2n(__u32 *id, const char *arg)
|
||||||
{
|
{
|
||||||
static char *cache = NULL;
|
static char *cache;
|
||||||
static unsigned long res;
|
static unsigned long res;
|
||||||
char *end;
|
char *end;
|
||||||
int i;
|
int i;
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,14 @@ bridge \- show / manipulate bridge addresses and devices
|
||||||
|
|
||||||
.ti -8
|
.ti -8
|
||||||
.BR "bridge link set"
|
.BR "bridge link set"
|
||||||
.B dev
|
.B dev
|
||||||
.IR DEV
|
.IR DEV
|
||||||
.IR " [ "
|
.IR " [ "
|
||||||
.B cost
|
.B cost
|
||||||
.IR COST " ] [ "
|
.IR COST " ] [ "
|
||||||
.B priority
|
.B priority
|
||||||
.IR PRIO " ] [ "
|
.IR PRIO " ] [ "
|
||||||
.B state
|
.B state
|
||||||
.IR STATE "] ["
|
.IR STATE "] ["
|
||||||
.BR guard " { " on " | " off " } ] [ "
|
.BR guard " { " on " | " off " } ] [ "
|
||||||
.BR hairpin " { " on " | " off " } ] [ "
|
.BR hairpin " { " on " | " off " } ] [ "
|
||||||
|
|
@ -42,21 +42,21 @@ bridge \- show / manipulate bridge addresses and devices
|
||||||
.BR learning_sync " { " on " | " off " } ] [ "
|
.BR learning_sync " { " on " | " off " } ] [ "
|
||||||
.BR flood " { " on " | " off " } ] [ "
|
.BR flood " { " on " | " off " } ] [ "
|
||||||
.BR hwmode " { " vepa " | " veb " } ] [ "
|
.BR hwmode " { " vepa " | " veb " } ] [ "
|
||||||
.BR self " ] [ " master " ] "
|
.BR self " ] [ " master " ] "
|
||||||
|
|
||||||
.ti -8
|
.ti -8
|
||||||
.BR "bridge link" " [ " show " ] [ "
|
.BR "bridge link" " [ " show " ] [ "
|
||||||
.B dev
|
.B dev
|
||||||
.IR DEV " ]"
|
.IR DEV " ]"
|
||||||
|
|
||||||
.ti -8
|
.ti -8
|
||||||
.BR "bridge fdb" " { " add " | " append " | " del " | " replace " } "
|
.BR "bridge fdb" " { " add " | " append " | " del " | " replace " } "
|
||||||
.I LLADDR
|
.I LLADDR
|
||||||
.B dev
|
.B dev
|
||||||
.IR DEV " { "
|
.IR DEV " { "
|
||||||
.BR local " | " temp " } [ "
|
.BR local " | " temp " } [ "
|
||||||
.BR self " ] [ " master " ] [ " router " ] [ " use " ] [ "
|
.BR self " ] [ " master " ] [ " router " ] [ " use " ] [ "
|
||||||
.B dst
|
.B dst
|
||||||
.IR IPADDR " ] [ "
|
.IR IPADDR " ] [ "
|
||||||
.B vni
|
.B vni
|
||||||
.IR VNI " ] ["
|
.IR VNI " ] ["
|
||||||
|
|
@ -67,12 +67,12 @@ bridge \- show / manipulate bridge addresses and devices
|
||||||
|
|
||||||
.ti -8
|
.ti -8
|
||||||
.BR "bridge fdb" " [ " show " ] [ "
|
.BR "bridge fdb" " [ " show " ] [ "
|
||||||
.B dev
|
.B dev
|
||||||
.IR DEV " ]"
|
.IR DEV " ]"
|
||||||
|
|
||||||
.ti -8
|
.ti -8
|
||||||
.BR "bridge mdb" " { " add " | " del " } "
|
.BR "bridge mdb" " { " add " | " del " } "
|
||||||
.B dev
|
.B dev
|
||||||
.IR DEV
|
.IR DEV
|
||||||
.B port
|
.B port
|
||||||
.IR PORT
|
.IR PORT
|
||||||
|
|
@ -84,21 +84,21 @@ bridge \- show / manipulate bridge addresses and devices
|
||||||
|
|
||||||
.ti -8
|
.ti -8
|
||||||
.BR "bridge mdb show " [ "
|
.BR "bridge mdb show " [ "
|
||||||
.B dev
|
.B dev
|
||||||
.IR DEV " ]"
|
.IR DEV " ]"
|
||||||
|
|
||||||
.ti -8
|
.ti -8
|
||||||
.BR "bridge vlan" " { " add " | " del " } "
|
.BR "bridge vlan" " { " add " | " del " } "
|
||||||
.B dev
|
.B dev
|
||||||
.IR DEV
|
.IR DEV
|
||||||
.B vid
|
.B vid
|
||||||
.IR VID " [ "
|
.IR VID " [ "
|
||||||
.BR pvid " ] [ " untagged " ] [ "
|
.BR pvid " ] [ " untagged " ] [ "
|
||||||
.BR self " ] [ " master " ] "
|
.BR self " ] [ " master " ] "
|
||||||
|
|
||||||
.ti -8
|
.ti -8
|
||||||
.BR "bridge vlan" " [ " show " ] [ "
|
.BR "bridge vlan" " [ " show " ] [ "
|
||||||
.B dev
|
.B dev
|
||||||
.IR DEV " ]"
|
.IR DEV " ]"
|
||||||
|
|
||||||
.ti -8
|
.ti -8
|
||||||
|
|
@ -319,7 +319,7 @@ This command displays the current bridge port configuration and flags.
|
||||||
.SH bridge fdb - forwarding database management
|
.SH bridge fdb - forwarding database management
|
||||||
|
|
||||||
.B fdb
|
.B fdb
|
||||||
objects contain known Ethernet addresses on a link.
|
objects contain known Ethernet addresses on a link.
|
||||||
|
|
||||||
.P
|
.P
|
||||||
The corresponding commands display fdb entries, add new entries,
|
The corresponding commands display fdb entries, add new entries,
|
||||||
|
|
@ -398,21 +398,21 @@ sends a copy of the data packet to each entry found.
|
||||||
|
|
||||||
.PP
|
.PP
|
||||||
The arguments are the same as with
|
The arguments are the same as with
|
||||||
.BR "bridge fdb add" ,
|
.BR "bridge fdb add" .
|
||||||
|
|
||||||
.SS bridge fdb delete - delete a forwarding database entry
|
.SS bridge fdb delete - delete a forwarding database entry
|
||||||
This command removes an existing fdb entry.
|
This command removes an existing fdb entry.
|
||||||
|
|
||||||
.PP
|
.PP
|
||||||
The arguments are the same as with
|
The arguments are the same as with
|
||||||
.BR "bridge fdb add" ,
|
.BR "bridge fdb add" .
|
||||||
|
|
||||||
.SS bridge fdb replace - replace a forwarding database entry
|
.SS bridge fdb replace - replace a forwarding database entry
|
||||||
If no matching entry is found, a new one will be created instead.
|
If no matching entry is found, a new one will be created instead.
|
||||||
|
|
||||||
.PP
|
.PP
|
||||||
The arguments are the same as with
|
The arguments are the same as with
|
||||||
.BR "bridge fdb add" ,
|
.BR "bridge fdb add" .
|
||||||
|
|
||||||
.SS bridge fdb show - list forwarding entries.
|
.SS bridge fdb show - list forwarding entries.
|
||||||
|
|
||||||
|
|
@ -548,7 +548,7 @@ This command displays the current VLAN filter table.
|
||||||
|
|
||||||
The
|
The
|
||||||
.B bridge
|
.B bridge
|
||||||
utility can monitor the state of devices and addresses
|
utility can monitor the state of devices and addresses
|
||||||
continuously. This option has a slightly different format.
|
continuously. This option has a slightly different format.
|
||||||
Namely, the
|
Namely, the
|
||||||
.B monitor
|
.B monitor
|
||||||
|
|
@ -560,7 +560,7 @@ command is the first in the command line and then the object list follows:
|
||||||
.I OBJECT-LIST
|
.I OBJECT-LIST
|
||||||
is the list of object types that we want to monitor.
|
is the list of object types that we want to monitor.
|
||||||
It may contain
|
It may contain
|
||||||
.BR link ", " fdb ", and " mdb "."
|
.BR link ", " fdb ", and " mdb "."
|
||||||
If no
|
If no
|
||||||
.B file
|
.B file
|
||||||
argument is given,
|
argument is given,
|
||||||
|
|
|
||||||
|
|
@ -703,7 +703,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[sizeof(buf)-1] = 0;
|
buf[sizeof(buf)-1] = 0;
|
||||||
while (fgets(buf, sizeof(buf)-1, fp)) {
|
while (fgets(buf, sizeof(buf), fp)) {
|
||||||
__u8 b1[6];
|
__u8 b1[6];
|
||||||
char ipbuf[128];
|
char ipbuf[128];
|
||||||
char macbuf[128];
|
char macbuf[128];
|
||||||
|
|
|
||||||
|
|
@ -819,7 +819,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
if (uptime >= 0 && time(NULL) >= stb.st_mtime+uptime) {
|
if (uptime >= 0 && time(NULL) >= stb.st_mtime+uptime) {
|
||||||
fprintf(stderr, "ifstat: history is aged out, resetting\n");
|
fprintf(stderr, "ifstat: history is aged out, resetting\n");
|
||||||
ftruncate(fileno(hist_fp), 0);
|
if (ftruncate(fileno(hist_fp), 0))
|
||||||
|
perror("ifstat: ftruncate");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -862,7 +863,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!no_update) {
|
if (!no_update) {
|
||||||
ftruncate(fileno(hist_fp), 0);
|
if (ftruncate(fileno(hist_fp), 0))
|
||||||
|
perror("ifstat: ftruncate");
|
||||||
rewind(hist_fp);
|
rewind(hist_fp);
|
||||||
|
|
||||||
json_output = 0;
|
json_output = 0;
|
||||||
|
|
|
||||||
|
|
@ -38,18 +38,22 @@
|
||||||
/* Read (and summarize for SMP) the different stats vars. */
|
/* Read (and summarize for SMP) the different stats vars. */
|
||||||
static int scan_lines(struct lnstat_file *lf, int i)
|
static int scan_lines(struct lnstat_file *lf, int i)
|
||||||
{
|
{
|
||||||
|
char buf[FGETS_BUF_SIZE];
|
||||||
int j, num_lines = 0;
|
int j, num_lines = 0;
|
||||||
|
|
||||||
for (j = 0; j < lf->num_fields; j++)
|
for (j = 0; j < lf->num_fields; j++)
|
||||||
lf->fields[j].values[i] = 0;
|
lf->fields[j].values[i] = 0;
|
||||||
|
|
||||||
while(!feof(lf->fp)) {
|
rewind(lf->fp);
|
||||||
char buf[FGETS_BUF_SIZE];
|
/* skip first line */
|
||||||
|
if (!lf->compat && !fgets(buf, sizeof(buf)-1, lf->fp))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
while(!feof(lf->fp) && fgets(buf, sizeof(buf)-1, lf->fp)) {
|
||||||
char *ptr = buf;
|
char *ptr = buf;
|
||||||
|
|
||||||
num_lines++;
|
num_lines++;
|
||||||
|
|
||||||
fgets(buf, sizeof(buf)-1, lf->fp);
|
|
||||||
gettimeofday(&lf->last_read, NULL);
|
gettimeofday(&lf->last_read, NULL);
|
||||||
|
|
||||||
for (j = 0; j < lf->num_fields; j++) {
|
for (j = 0; j < lf->num_fields; j++) {
|
||||||
|
|
@ -81,7 +85,6 @@ static int time_after(struct timeval *last,
|
||||||
int lnstat_update(struct lnstat_file *lnstat_files)
|
int lnstat_update(struct lnstat_file *lnstat_files)
|
||||||
{
|
{
|
||||||
struct lnstat_file *lf;
|
struct lnstat_file *lf;
|
||||||
char buf[FGETS_BUF_SIZE];
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
|
|
@ -91,11 +94,6 @@ int lnstat_update(struct lnstat_file *lnstat_files)
|
||||||
int i;
|
int i;
|
||||||
struct lnstat_field *lfi;
|
struct lnstat_field *lfi;
|
||||||
|
|
||||||
rewind(lf->fp);
|
|
||||||
if (!lf->compat) {
|
|
||||||
/* skip first line */
|
|
||||||
fgets(buf, sizeof(buf)-1, lf->fp);
|
|
||||||
}
|
|
||||||
scan_lines(lf, 1);
|
scan_lines(lf, 1);
|
||||||
|
|
||||||
for (i = 0, lfi = &lf->fields[i];
|
for (i = 0, lfi = &lf->fields[i];
|
||||||
|
|
@ -107,8 +105,6 @@ int lnstat_update(struct lnstat_file *lnstat_files)
|
||||||
/ lf->interval.tv_sec;
|
/ lf->interval.tv_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
rewind(lf->fp);
|
|
||||||
fgets(buf, sizeof(buf)-1, lf->fp);
|
|
||||||
scan_lines(lf, 0);
|
scan_lines(lf, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +138,8 @@ static int lnstat_scan_fields(struct lnstat_file *lf)
|
||||||
char buf[FGETS_BUF_SIZE];
|
char buf[FGETS_BUF_SIZE];
|
||||||
|
|
||||||
rewind(lf->fp);
|
rewind(lf->fp);
|
||||||
fgets(buf, sizeof(buf)-1, lf->fp);
|
if (!fgets(buf, sizeof(buf)-1, lf->fp))
|
||||||
|
return -1;
|
||||||
|
|
||||||
return __lnstat_scan_fields(lf, buf);
|
return __lnstat_scan_fields(lf, buf);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -649,7 +649,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
if (uptime >= 0 && time(NULL) >= stb.st_mtime+uptime) {
|
if (uptime >= 0 && time(NULL) >= stb.st_mtime+uptime) {
|
||||||
fprintf(stderr, "nstat: history is aged out, resetting\n");
|
fprintf(stderr, "nstat: history is aged out, resetting\n");
|
||||||
ftruncate(fileno(hist_fp), 0);
|
if (ftruncate(fileno(hist_fp), 0) < 0)
|
||||||
|
perror("nstat: ftruncate");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -693,7 +694,8 @@ int main(int argc, char *argv[])
|
||||||
dump_incr_db(stdout);
|
dump_incr_db(stdout);
|
||||||
}
|
}
|
||||||
if (!no_update) {
|
if (!no_update) {
|
||||||
ftruncate(fileno(hist_fp), 0);
|
if (ftruncate(fileno(hist_fp), 0) < 0)
|
||||||
|
perror("nstat: ftruncate");
|
||||||
rewind(hist_fp);
|
rewind(hist_fp);
|
||||||
|
|
||||||
json_output = 0;
|
json_output = 0;
|
||||||
|
|
|
||||||
115
misc/ss.c
115
misc/ss.c
|
|
@ -528,7 +528,8 @@ static void user_ent_hash_build(void)
|
||||||
snprintf(tmp, sizeof(tmp), "%s/%d/stat",
|
snprintf(tmp, sizeof(tmp), "%s/%d/stat",
|
||||||
root, pid);
|
root, pid);
|
||||||
if ((fp = fopen(tmp, "r")) != NULL) {
|
if ((fp = fopen(tmp, "r")) != NULL) {
|
||||||
fscanf(fp, "%*d (%[^)])", p);
|
if (fscanf(fp, "%*d (%[^)])", p) < 1)
|
||||||
|
; /* ignore */
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -660,7 +661,10 @@ static int get_slabstat(struct slabstat *s)
|
||||||
|
|
||||||
cnt = sizeof(*s)/sizeof(int);
|
cnt = sizeof(*s)/sizeof(int);
|
||||||
|
|
||||||
fgets(buf, sizeof(buf), fp);
|
if (!fgets(buf, sizeof(buf), fp)) {
|
||||||
|
fclose(fp);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
while(fgets(buf, sizeof(buf), fp) != NULL) {
|
while(fgets(buf, sizeof(buf), fp) != NULL) {
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i<sizeof(slabstat_ids)/sizeof(slabstat_ids[0]); i++) {
|
for (i=0; i<sizeof(slabstat_ids)/sizeof(slabstat_ids[0]); i++) {
|
||||||
|
|
@ -870,34 +874,39 @@ static void init_service_resolver(void)
|
||||||
{
|
{
|
||||||
char buf[128];
|
char buf[128];
|
||||||
FILE *fp = popen("/usr/sbin/rpcinfo -p 2>/dev/null", "r");
|
FILE *fp = popen("/usr/sbin/rpcinfo -p 2>/dev/null", "r");
|
||||||
if (fp) {
|
|
||||||
fgets(buf, sizeof(buf), fp);
|
|
||||||
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
|
||||||
unsigned int progn, port;
|
|
||||||
char proto[128], prog[128];
|
|
||||||
if (sscanf(buf, "%u %*d %s %u %s", &progn, proto,
|
|
||||||
&port, prog+4) == 4) {
|
|
||||||
struct scache *c = malloc(sizeof(*c));
|
|
||||||
if (c) {
|
|
||||||
c->port = port;
|
|
||||||
memcpy(prog, "rpc.", 4);
|
|
||||||
c->name = strdup(prog);
|
|
||||||
if (strcmp(proto, TCP_PROTO) == 0)
|
|
||||||
c->proto = TCP_PROTO;
|
|
||||||
else if (strcmp(proto, UDP_PROTO) == 0)
|
|
||||||
c->proto = UDP_PROTO;
|
|
||||||
else
|
|
||||||
c->proto = NULL;
|
|
||||||
c->next = rlist;
|
|
||||||
rlist = c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pclose(fp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ip_local_port_min, ip_local_port_max;
|
if (!fp)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!fgets(buf, sizeof(buf), fp)) {
|
||||||
|
pclose(fp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
||||||
|
unsigned int progn, port;
|
||||||
|
char proto[128], prog[128] = "rpc.";
|
||||||
|
struct scache *c;
|
||||||
|
|
||||||
|
if (sscanf(buf, "%u %*d %s %u %s",
|
||||||
|
&progn, proto, &port, prog+4) != 4)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!(c = malloc(sizeof(*c))))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
c->port = port;
|
||||||
|
c->name = strdup(prog);
|
||||||
|
if (strcmp(proto, TCP_PROTO) == 0)
|
||||||
|
c->proto = TCP_PROTO;
|
||||||
|
else if (strcmp(proto, UDP_PROTO) == 0)
|
||||||
|
c->proto = UDP_PROTO;
|
||||||
|
else
|
||||||
|
c->proto = NULL;
|
||||||
|
c->next = rlist;
|
||||||
|
rlist = c;
|
||||||
|
}
|
||||||
|
pclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
/* Even do not try default linux ephemeral port ranges:
|
/* Even do not try default linux ephemeral port ranges:
|
||||||
* default /etc/services contains so much of useless crap
|
* default /etc/services contains so much of useless crap
|
||||||
|
|
@ -907,19 +916,18 @@ static int ip_local_port_min, ip_local_port_max;
|
||||||
*/
|
*/
|
||||||
static int is_ephemeral(int port)
|
static int is_ephemeral(int port)
|
||||||
{
|
{
|
||||||
if (!ip_local_port_min) {
|
static int min = 0, max = 0;
|
||||||
FILE *f = ephemeral_ports_open();
|
|
||||||
if (f) {
|
|
||||||
fscanf(f, "%d %d",
|
|
||||||
&ip_local_port_min, &ip_local_port_max);
|
|
||||||
fclose(f);
|
|
||||||
} else {
|
|
||||||
ip_local_port_min = 1024;
|
|
||||||
ip_local_port_max = 4999;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (port >= ip_local_port_min && port<= ip_local_port_max);
|
if (!min) {
|
||||||
|
FILE *f = ephemeral_ports_open();
|
||||||
|
if (!f || fscanf(f, "%d %d", &min, &max) < 2) {
|
||||||
|
min = 1024;
|
||||||
|
max = 4999;
|
||||||
|
}
|
||||||
|
if (f)
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
return port >= min && port <= max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1074,8 +1082,6 @@ static int run_ssfilter(struct ssfilter *f, struct sockstat *s)
|
||||||
switch (f->type) {
|
switch (f->type) {
|
||||||
case SSF_S_AUTO:
|
case SSF_S_AUTO:
|
||||||
{
|
{
|
||||||
static int low, high=65535;
|
|
||||||
|
|
||||||
if (s->local.family == AF_UNIX) {
|
if (s->local.family == AF_UNIX) {
|
||||||
char *p;
|
char *p;
|
||||||
memcpy(&p, s->local.data, sizeof(p));
|
memcpy(&p, s->local.data, sizeof(p));
|
||||||
|
|
@ -1087,14 +1093,7 @@ static int run_ssfilter(struct ssfilter *f, struct sockstat *s)
|
||||||
if (s->local.family == AF_NETLINK)
|
if (s->local.family == AF_NETLINK)
|
||||||
return s->lport < 0;
|
return s->lport < 0;
|
||||||
|
|
||||||
if (!low) {
|
return is_ephemeral(s->lport);
|
||||||
FILE *fp = ephemeral_ports_open();
|
|
||||||
if (fp) {
|
|
||||||
fscanf(fp, "%d%d", &low, &high);
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s->lport >= low && s->lport <= high;
|
|
||||||
}
|
}
|
||||||
case SSF_DCOND:
|
case SSF_DCOND:
|
||||||
{
|
{
|
||||||
|
|
@ -2730,13 +2729,16 @@ static int unix_show(struct filter *f)
|
||||||
|
|
||||||
if ((fp = net_unix_open()) == NULL)
|
if ((fp = net_unix_open()) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
fgets(buf, sizeof(buf)-1, fp);
|
if (!fgets(buf, sizeof(buf), fp)) {
|
||||||
|
fclose(fp);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (memcmp(buf, "Peer", 4) == 0)
|
if (memcmp(buf, "Peer", 4) == 0)
|
||||||
newformat = 1;
|
newformat = 1;
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf)-1, fp)) {
|
while (fgets(buf, sizeof(buf), fp)) {
|
||||||
struct sockstat *u, **insp;
|
struct sockstat *u, **insp;
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
|
|
@ -3215,9 +3217,12 @@ static int netlink_show(struct filter *f)
|
||||||
|
|
||||||
if ((fp = net_netlink_open()) == NULL)
|
if ((fp = net_netlink_open()) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
fgets(buf, sizeof(buf)-1, fp);
|
if (!fgets(buf, sizeof(buf), fp)) {
|
||||||
|
fclose(fp);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf)-1, fp)) {
|
while (fgets(buf, sizeof(buf), fp)) {
|
||||||
sscanf(buf, "%llx %d %d %x %d %d %llx %d",
|
sscanf(buf, "%llx %d %d %x %d %d %llx %d",
|
||||||
&sk,
|
&sk,
|
||||||
&prot, &pid, &groups, &rq, &wq, &cb, &rc);
|
&prot, &pid, &groups, &rq, &wq, &cb, &rc);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue