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;
|
||||||
|
|
||||||
if (filter.family == AF_UNSPEC)
|
|
||||||
filter.family = preferred_family;
|
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);
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -196,8 +197,13 @@ int rtnl_rtprot_a2n(__u32 *id, const char *arg)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *rtnl_rtscope_tab[256] = {
|
static char *rtnl_rtscope_tab[256] = {
|
||||||
"global",
|
[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,10 +211,6 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
@ -219,19 +221,22 @@ const char *rtnl_rtscope_n2a(int id, char *buf, int len)
|
||||||
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;
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -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,6 +355,30 @@ 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)
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -468,7 +499,9 @@ 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;
|
||||||
|
|
@ -528,10 +561,9 @@ const char *rtnl_group_n2a(int id, char *buf, int len)
|
||||||
|
|
||||||
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);
|
||||||
return buf;
|
return buf;
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
87
misc/ss.c
87
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,17 +874,27 @@ 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);
|
if (!fp)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!fgets(buf, sizeof(buf), fp)) {
|
||||||
|
pclose(fp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
||||||
unsigned int progn, port;
|
unsigned int progn, port;
|
||||||
char proto[128], prog[128];
|
char proto[128], prog[128] = "rpc.";
|
||||||
if (sscanf(buf, "%u %*d %s %u %s", &progn, proto,
|
struct scache *c;
|
||||||
&port, prog+4) == 4) {
|
|
||||||
struct scache *c = malloc(sizeof(*c));
|
if (sscanf(buf, "%u %*d %s %u %s",
|
||||||
if (c) {
|
&progn, proto, &port, prog+4) != 4)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!(c = malloc(sizeof(*c))))
|
||||||
|
continue;
|
||||||
|
|
||||||
c->port = port;
|
c->port = port;
|
||||||
memcpy(prog, "rpc.", 4);
|
|
||||||
c->name = strdup(prog);
|
c->name = strdup(prog);
|
||||||
if (strcmp(proto, TCP_PROTO) == 0)
|
if (strcmp(proto, TCP_PROTO) == 0)
|
||||||
c->proto = TCP_PROTO;
|
c->proto = TCP_PROTO;
|
||||||
|
|
@ -891,13 +905,8 @@ static void init_service_resolver(void)
|
||||||
c->next = rlist;
|
c->next = rlist;
|
||||||
rlist = c;
|
rlist = c;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
pclose(fp);
|
pclose(fp);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static int ip_local_port_min, ip_local_port_max;
|
|
||||||
|
|
||||||
/* 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