Merge branch 'master' into net-next

This commit is contained in:
Stephen Hemminger 2016-07-20 12:21:42 -07:00
commit ac75d5cd36
95 changed files with 1227 additions and 1143 deletions

View File

@ -34,8 +34,8 @@ ADDLIB+=ipx_ntop.o ipx_pton.o
#options for mpls #options for mpls
ADDLIB+=mpls_ntop.o mpls_pton.o ADDLIB+=mpls_ntop.o mpls_pton.o
CC = gcc CC := gcc
HOSTCC = gcc HOSTCC ?= $(CC)
DEFINES += -D_GNU_SOURCE DEFINES += -D_GNU_SOURCE
# Turn on transparent support for LFS # Turn on transparent support for LFS
DEFINES += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE DEFINES += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE

View File

@ -23,4 +23,5 @@ extern int show_stats;
extern int show_details; extern int show_details;
extern int timestamp; extern int timestamp;
extern int compress_vlans; extern int compress_vlans;
extern int json_output;
extern struct rtnl_handle rth; extern struct rtnl_handle rth;

View File

@ -23,6 +23,7 @@ int oneline;
int show_stats; int show_stats;
int show_details; int show_details;
int compress_vlans; int compress_vlans;
int json_output;
int timestamp; int timestamp;
char *batch_file; char *batch_file;
int force; int force;
@ -38,7 +39,7 @@ static void usage(void)
"where OBJECT := { link | fdb | mdb | vlan | monitor }\n" "where OBJECT := { link | fdb | mdb | vlan | monitor }\n"
" OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] |\n" " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] |\n"
" -o[neline] | -t[imestamp] | -n[etns] name |\n" " -o[neline] | -t[imestamp] | -n[etns] name |\n"
" -c[ompressvlans] }\n"); " -c[ompressvlans] -j{son} }\n");
exit(-1); exit(-1);
} }
@ -173,6 +174,8 @@ main(int argc, char **argv)
++compress_vlans; ++compress_vlans;
} else if (matches(opt, "-force") == 0) { } else if (matches(opt, "-force") == 0) {
++force; ++force;
} else if (matches(opt, "-json") == 0) {
++json_output;
} else if (matches(opt, "-batch") == 0) { } else if (matches(opt, "-batch") == 0) {
argc--; argc--;
argv++; argv++;

View File

@ -21,6 +21,8 @@
#include <linux/neighbour.h> #include <linux/neighbour.h>
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <json_writer.h>
#include <stdbool.h>
#include "libnetlink.h" #include "libnetlink.h"
#include "br_common.h" #include "br_common.h"
@ -29,6 +31,8 @@
static unsigned int filter_index, filter_vlan; static unsigned int filter_index, filter_vlan;
json_writer_t *jw_global;
static void usage(void) static void usage(void)
{ {
fprintf(stderr, "Usage: bridge fdb { add | append | del | replace } ADDR dev DEV\n" fprintf(stderr, "Usage: bridge fdb { add | append | del | replace } ADDR dev DEV\n"
@ -59,6 +63,15 @@ static const char *state_n2a(unsigned int s)
return buf; return buf;
} }
static void start_json_fdb_flags_array(bool *fdb_flags)
{
if (*fdb_flags)
return;
jsonw_name(jw_global, "flags");
jsonw_start_array(jw_global);
*fdb_flags = true;
}
int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{ {
FILE *fp = arg; FILE *fp = arg;
@ -66,11 +79,12 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr *tb[NDA_MAX+1]; struct rtattr *tb[NDA_MAX+1];
__u16 vid = 0; __u16 vid = 0;
bool fdb_flags = false;
const char *state_s;
if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH) { if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH) {
fprintf(stderr, "Not RTM_NEWNEIGH: %08x %08x %08x\n", fprintf(stderr, "Not RTM_NEWNEIGH: %08x %08x %08x\n",
n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
return 0; return 0;
} }
@ -86,6 +100,11 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (filter_index && filter_index != r->ndm_ifindex) if (filter_index && filter_index != r->ndm_ifindex)
return 0; return 0;
if (jw_global) {
jsonw_pretty(jw_global, 1);
jsonw_start_object(jw_global);
}
parse_rtattr(tb, NDA_MAX, NDA_RTA(r), parse_rtattr(tb, NDA_MAX, NDA_RTA(r),
n->nlmsg_len - NLMSG_LENGTH(sizeof(*r))); n->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
@ -95,40 +114,75 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (filter_vlan && filter_vlan != vid) if (filter_vlan && filter_vlan != vid)
return 0; return 0;
if (n->nlmsg_type == RTM_DELNEIGH) if (n->nlmsg_type == RTM_DELNEIGH) {
fprintf(fp, "Deleted "); if (jw_global)
jsonw_string_field(jw_global, "opCode", "deleted");
else
fprintf(fp, "Deleted ");
}
if (tb[NDA_LLADDR]) { if (tb[NDA_LLADDR]) {
SPRINT_BUF(b1); SPRINT_BUF(b1);
fprintf(fp, "%s ", ll_addr_n2a(RTA_DATA(tb[NDA_LLADDR]),
ll_addr_n2a(RTA_DATA(tb[NDA_LLADDR]), RTA_PAYLOAD(tb[NDA_LLADDR]),
RTA_PAYLOAD(tb[NDA_LLADDR]), ll_index_to_type(r->ndm_ifindex),
ll_index_to_type(r->ndm_ifindex), b1, sizeof(b1));
b1, sizeof(b1))); if (jw_global)
jsonw_string_field(jw_global, "mac", b1);
else
fprintf(fp, "%s ", b1);
} }
if (!filter_index && r->ndm_ifindex) if (!filter_index && r->ndm_ifindex) {
fprintf(fp, "dev %s ", ll_index_to_name(r->ndm_ifindex)); if (jw_global)
jsonw_string_field(jw_global, "dev",
ll_index_to_name(r->ndm_ifindex));
else
fprintf(fp, "dev %s ",
ll_index_to_name(r->ndm_ifindex));
}
if (tb[NDA_DST]) { if (tb[NDA_DST]) {
int family = AF_INET; int family = AF_INET;
const char *abuf_s;
if (RTA_PAYLOAD(tb[NDA_DST]) == sizeof(struct in6_addr)) if (RTA_PAYLOAD(tb[NDA_DST]) == sizeof(struct in6_addr))
family = AF_INET6; family = AF_INET6;
fprintf(fp, "dst %s ", abuf_s = format_host(family,
format_host(family, RTA_PAYLOAD(tb[NDA_DST]),
RTA_PAYLOAD(tb[NDA_DST]), RTA_DATA(tb[NDA_DST]));
RTA_DATA(tb[NDA_DST]))); if (jw_global)
jsonw_string_field(jw_global, "dst", abuf_s);
else
fprintf(fp, "dst %s ", abuf_s);
} }
if (vid) if (vid) {
fprintf(fp, "vlan %hu ", vid); if (jw_global)
jsonw_uint_field(jw_global, "vlan", vid);
else
fprintf(fp, "vlan %hu ", vid);
}
if (tb[NDA_PORT]) {
if (jw_global)
jsonw_uint_field(jw_global, "port",
ntohs(rta_getattr_u16(tb[NDA_PORT])));
else
fprintf(fp, "port %d ",
ntohs(rta_getattr_u16(tb[NDA_PORT])));
}
if (tb[NDA_VNI]) {
if (jw_global)
jsonw_uint_field(jw_global, "vni",
rta_getattr_u32(tb[NDA_VNI]));
else
fprintf(fp, "vni %d ",
rta_getattr_u32(tb[NDA_VNI]));
}
if (tb[NDA_PORT])
fprintf(fp, "port %d ", ntohs(rta_getattr_u16(tb[NDA_PORT])));
if (tb[NDA_VNI])
fprintf(fp, "vni %d ", rta_getattr_u32(tb[NDA_VNI]));
if (tb[NDA_IFINDEX]) { if (tb[NDA_IFINDEX]) {
unsigned int ifindex = rta_getattr_u32(tb[NDA_IFINDEX]); unsigned int ifindex = rta_getattr_u32(tb[NDA_IFINDEX]);
@ -136,37 +190,95 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
char ifname[IF_NAMESIZE]; char ifname[IF_NAMESIZE];
if (!tb[NDA_LINK_NETNSID] && if (!tb[NDA_LINK_NETNSID] &&
if_indextoname(ifindex, ifname)) if_indextoname(ifindex, ifname)) {
fprintf(fp, "via %s ", ifname); if (jw_global)
else jsonw_string_field(jw_global, "viaIf",
fprintf(fp, "via ifindex %u ", ifindex); ifname);
else
fprintf(fp, "via %s ", ifname);
} else {
if (jw_global)
jsonw_uint_field(jw_global, "viaIfIndex",
ifindex);
else
fprintf(fp, "via ifindex %u ", ifindex);
}
} }
} }
if (tb[NDA_LINK_NETNSID])
fprintf(fp, "link-netnsid %d ", if (tb[NDA_LINK_NETNSID]) {
rta_getattr_u32(tb[NDA_LINK_NETNSID])); if (jw_global)
jsonw_uint_field(jw_global, "linkNetNsId",
rta_getattr_u32(tb[NDA_LINK_NETNSID]));
else
fprintf(fp, "link-netnsid %d ",
rta_getattr_u32(tb[NDA_LINK_NETNSID]));
}
if (show_stats && tb[NDA_CACHEINFO]) { if (show_stats && tb[NDA_CACHEINFO]) {
struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]); struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]);
int hz = get_user_hz(); int hz = get_user_hz();
fprintf(fp, "used %d/%d ", ci->ndm_used/hz, if (jw_global) {
ci->ndm_updated/hz); jsonw_uint_field(jw_global, "used",
ci->ndm_used/hz);
jsonw_uint_field(jw_global, "updated",
ci->ndm_updated/hz);
} else {
fprintf(fp, "used %d/%d ", ci->ndm_used/hz,
ci->ndm_updated/hz);
}
} }
if (r->ndm_flags & NTF_SELF)
fprintf(fp, "self ");
if (tb[NDA_MASTER])
fprintf(fp, "master %s ",
ll_index_to_name(rta_getattr_u32(tb[NDA_MASTER])));
else if (r->ndm_flags & NTF_MASTER)
fprintf(fp, "master ");
if (r->ndm_flags & NTF_ROUTER)
fprintf(fp, "router ");
if (r->ndm_flags & NTF_EXT_LEARNED)
fprintf(fp, "offload ");
fprintf(fp, "%s\n", state_n2a(r->ndm_state)); if (jw_global) {
fflush(fp); if (r->ndm_flags & NTF_SELF) {
start_json_fdb_flags_array(&fdb_flags);
jsonw_string(jw_global, "self");
}
if (r->ndm_flags & NTF_ROUTER) {
start_json_fdb_flags_array(&fdb_flags);
jsonw_string(jw_global, "router");
}
if (r->ndm_flags & NTF_EXT_LEARNED) {
start_json_fdb_flags_array(&fdb_flags);
jsonw_string(jw_global, "offload");
}
if (r->ndm_flags & NTF_MASTER)
jsonw_string(jw_global, "master");
if (fdb_flags)
jsonw_end_array(jw_global);
if (tb[NDA_MASTER])
jsonw_string_field(jw_global,
"master",
ll_index_to_name(rta_getattr_u32(tb[NDA_MASTER])));
} else {
if (r->ndm_flags & NTF_SELF)
fprintf(fp, "self ");
if (r->ndm_flags & NTF_ROUTER)
fprintf(fp, "router ");
if (r->ndm_flags & NTF_EXT_LEARNED)
fprintf(fp, "offload ");
if (tb[NDA_MASTER]) {
fprintf(fp, "master %s ",
ll_index_to_name(rta_getattr_u32(tb[NDA_MASTER])));
} else if (r->ndm_flags & NTF_MASTER) {
fprintf(fp, "master ");
}
}
state_s = state_n2a(r->ndm_state);
if (jw_global) {
if (state_s[0])
jsonw_string_field(jw_global, "state", state_s);
jsonw_end_object(jw_global);
} else {
fprintf(fp, "%s\n", state_s);
fflush(fp);
}
return 0; return 0;
} }
@ -177,16 +289,15 @@ static int fdb_show(int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg ifm; struct ifinfomsg ifm;
char buf[256]; char buf[256];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
.ifm.ifi_family = PF_BRIDGE,
};
char *filter_dev = NULL; char *filter_dev = NULL;
char *br = NULL; char *br = NULL;
int msg_size = sizeof(struct ifinfomsg); int msg_size = sizeof(struct ifinfomsg);
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
req.ifm.ifi_family = PF_BRIDGE;
while (argc > 0) { while (argc > 0) {
if ((strcmp(*argv, "brport") == 0) || strcmp(*argv, "dev") == 0) { if ((strcmp(*argv, "brport") == 0) || strcmp(*argv, "dev") == 0) {
NEXT_ARG(); NEXT_ARG();
@ -233,10 +344,22 @@ static int fdb_show(int argc, char **argv)
exit(1); exit(1);
} }
if (json_output) {
jw_global = jsonw_new(stdout);
if (!jw_global) {
fprintf(stderr, "Error allocation json object\n");
exit(1);
}
jsonw_start_array(jw_global);
}
if (rtnl_dump_filter(&rth, print_fdb, stdout) < 0) { if (rtnl_dump_filter(&rth, print_fdb, stdout) < 0) {
fprintf(stderr, "Dump terminated\n"); fprintf(stderr, "Dump terminated\n");
exit(1); exit(1);
} }
if (jw_global) {
jsonw_end_array(jw_global);
jsonw_destroy(&jw_global);
}
return 0; return 0;
} }
@ -247,7 +370,13 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct ndmsg ndm; struct ndmsg ndm;
char buf[256]; char buf[256];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)),
.n.nlmsg_flags = NLM_F_REQUEST | flags,
.n.nlmsg_type = cmd,
.ndm.ndm_family = PF_BRIDGE,
.ndm.ndm_state = NUD_NOARP,
};
char *addr = NULL; char *addr = NULL;
char *d = NULL; char *d = NULL;
char abuf[ETH_ALEN]; char abuf[ETH_ALEN];
@ -259,14 +388,6 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
char *endptr; char *endptr;
short vid = -1; short vid = -1;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
req.ndm.ndm_family = PF_BRIDGE;
req.ndm.ndm_state = NUD_NOARP;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "dev") == 0) { if (strcmp(*argv, "dev") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -255,7 +255,12 @@ static int brlink_modify(int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg ifm; struct ifinfomsg ifm;
char buf[512]; char buf[512];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = RTM_SETLINK,
.ifm.ifi_family = PF_BRIDGE,
};
char *d = NULL; char *d = NULL;
__s8 learning = -1; __s8 learning = -1;
__s8 learning_sync = -1; __s8 learning_sync = -1;
@ -271,13 +276,6 @@ static int brlink_modify(int argc, char **argv)
__u16 flags = 0; __u16 flags = 0;
struct rtattr *nest; struct rtattr *nest;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = RTM_SETLINK;
req.ifm.ifi_family = PF_BRIDGE;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "dev") == 0) { if (strcmp(*argv, "dev") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -234,19 +234,16 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct br_port_msg bpm; struct br_port_msg bpm;
char buf[1024]; char buf[1024];
} req; } req = {
struct br_mdb_entry entry; .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct br_port_msg)),
.n.nlmsg_flags = NLM_F_REQUEST | flags,
.n.nlmsg_type = cmd,
.bpm.family = PF_BRIDGE,
};
struct br_mdb_entry entry = {};
char *d = NULL, *p = NULL, *grp = NULL; char *d = NULL, *p = NULL, *grp = NULL;
short vid = 0; short vid = 0;
memset(&req, 0, sizeof(req));
memset(&entry, 0, sizeof(entry));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct br_port_msg));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
req.bpm.family = PF_BRIDGE;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "dev") == 0) { if (strcmp(*argv, "dev") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -7,6 +7,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <linux/if_bridge.h> #include <linux/if_bridge.h>
#include <linux/if_ether.h> #include <linux/if_ether.h>
#include <json_writer.h>
#include <string.h> #include <string.h>
#include "libnetlink.h" #include "libnetlink.h"
@ -15,6 +16,8 @@
static unsigned int filter_index, filter_vlan; static unsigned int filter_index, filter_vlan;
json_writer_t *jw_global = NULL;
static void usage(void) static void usage(void)
{ {
fprintf(stderr, "Usage: bridge vlan { add | del } vid VLAN_ID dev DEV [ pvid] [ untagged ]\n"); fprintf(stderr, "Usage: bridge vlan { add | del } vid VLAN_ID dev DEV [ pvid] [ untagged ]\n");
@ -29,22 +32,19 @@ static int vlan_modify(int cmd, int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg ifm; struct ifinfomsg ifm;
char buf[1024]; char buf[1024];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = cmd,
.ifm.ifi_family = PF_BRIDGE,
};
char *d = NULL; char *d = NULL;
short vid = -1; short vid = -1;
short vid_end = -1; short vid_end = -1;
struct rtattr *afspec; struct rtattr *afspec;
struct bridge_vlan_info vinfo; struct bridge_vlan_info vinfo = {};
unsigned short flags = 0; unsigned short flags = 0;
memset(&vinfo, 0, sizeof(vinfo));
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = cmd;
req.ifm.ifi_family = PF_BRIDGE;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "dev") == 0) { if (strcmp(*argv, "dev") == 0) {
NEXT_ARG(); NEXT_ARG();
@ -158,6 +158,28 @@ static int filter_vlan_check(struct bridge_vlan_info *vinfo)
return 1; return 1;
} }
static void print_vlan_port(FILE *fp, int ifi_index)
{
if (jw_global) {
jsonw_pretty(jw_global, 1);
jsonw_name(jw_global,
ll_index_to_name(ifi_index));
jsonw_start_array(jw_global);
} else {
fprintf(fp, "%s",
ll_index_to_name(ifi_index));
}
}
static void start_json_vlan_flags_array(bool *vlan_flags)
{
if (*vlan_flags)
return;
jsonw_name(jw_global, "flags");
jsonw_start_array(jw_global);
*vlan_flags = true;
}
static int print_vlan(const struct sockaddr_nl *who, static int print_vlan(const struct sockaddr_nl *who,
struct nlmsghdr *n, struct nlmsghdr *n,
void *arg) void *arg)
@ -166,6 +188,7 @@ static int print_vlan(const struct sockaddr_nl *who,
struct ifinfomsg *ifm = NLMSG_DATA(n); struct ifinfomsg *ifm = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr *tb[IFLA_MAX+1]; struct rtattr *tb[IFLA_MAX+1];
bool vlan_flags;
if (n->nlmsg_type != RTM_NEWLINK) { if (n->nlmsg_type != RTM_NEWLINK) {
fprintf(stderr, "Not RTM_NEWLINK: %08x %08x %08x\n", fprintf(stderr, "Not RTM_NEWLINK: %08x %08x %08x\n",
@ -199,7 +222,8 @@ static int print_vlan(const struct sockaddr_nl *who,
__u16 last_vid_start = 0; __u16 last_vid_start = 0;
if (!filter_vlan) if (!filter_vlan)
fprintf(fp, "%s", ll_index_to_name(ifm->ifi_index)); print_vlan_port(fp, ifm->ifi_index);
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
struct bridge_vlan_info *vinfo; struct bridge_vlan_info *vinfo;
int vcheck_ret; int vcheck_ret;
@ -218,20 +242,58 @@ static int print_vlan(const struct sockaddr_nl *who,
continue; continue;
if (filter_vlan) if (filter_vlan)
fprintf(fp, "%s", print_vlan_port(fp, ifm->ifi_index);
ll_index_to_name(ifm->ifi_index)); if (jw_global) {
fprintf(fp, "\t %hu", last_vid_start); jsonw_start_object(jw_global);
if (last_vid_start != vinfo->vid) jsonw_uint_field(jw_global, "vlan",
fprintf(fp, "-%hu", vinfo->vid); last_vid_start);
if (vinfo->flags & BRIDGE_VLAN_INFO_PVID) if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN)
fprintf(fp, " PVID"); continue;
if (vinfo->flags & BRIDGE_VLAN_INFO_UNTAGGED) } else {
fprintf(fp, " Egress Untagged"); fprintf(fp, "\t %hu", last_vid_start);
fprintf(fp, "\n"); }
if (last_vid_start != vinfo->vid) {
if (jw_global)
jsonw_uint_field(jw_global, "vlanEnd",
vinfo->vid);
else
fprintf(fp, "-%hu", vinfo->vid);
}
if (vinfo->flags & BRIDGE_VLAN_INFO_PVID) {
if (jw_global) {
start_json_vlan_flags_array(&vlan_flags);
jsonw_string(jw_global, "PVID");
} else {
fprintf(fp, " PVID");
}
}
if (vinfo->flags & BRIDGE_VLAN_INFO_UNTAGGED) {
if (jw_global) {
start_json_vlan_flags_array(&vlan_flags);
jsonw_string(jw_global,
"Egress Untagged");
} else {
fprintf(fp, " Egress Untagged");
}
}
if (vlan_flags) {
jsonw_end_array(jw_global);
vlan_flags = false;
}
if (jw_global)
jsonw_end_object(jw_global);
else
fprintf(fp, "\n");
} }
} }
if (!filter_vlan) if (!filter_vlan) {
fprintf(fp, "\n"); if (jw_global)
jsonw_end_array(jw_global);
else
fprintf(fp, "\n");
}
fflush(fp); fflush(fp);
return 0; return 0;
} }
@ -271,12 +333,27 @@ static int vlan_show(int argc, char **argv)
exit(1); exit(1);
} }
printf("port\tvlan ids\n"); if (json_output) {
jw_global = jsonw_new(stdout);
if (!jw_global) {
fprintf(stderr, "Error allocation json object\n");
exit(1);
}
jsonw_start_object(jw_global);
} else {
printf("port\tvlan ids\n");
}
if (rtnl_dump_filter(&rth, print_vlan, stdout) < 0) { if (rtnl_dump_filter(&rth, print_vlan, stdout) < 0) {
fprintf(stderr, "Dump ternminated\n"); fprintf(stderr, "Dump ternminated\n");
exit(1); exit(1);
} }
if (jw_global) {
jsonw_end_object(jw_global);
jsonw_destroy(&jw_global);
}
return 0; return 0;
} }

View File

@ -42,23 +42,19 @@ static int usage(void)
int genl_ctrl_resolve_family(const char *family) int genl_ctrl_resolve_family(const char *family)
{ {
struct rtnl_handle rth; struct rtnl_handle rth;
struct nlmsghdr *nlh;
struct genlmsghdr *ghdr;
int ret = 0; int ret = 0;
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct genlmsghdr g;
char buf[4096]; char buf[4096];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN),
memset(&req, 0, sizeof(req)); .n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
.n.nlmsg_type = GENL_ID_CTRL,
nlh = &req.n; .g.cmd = CTRL_CMD_GETFAMILY,
nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); };
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; struct nlmsghdr *nlh = &req.n;
nlh->nlmsg_type = GENL_ID_CTRL; struct genlmsghdr *ghdr = &req.g;
ghdr = NLMSG_DATA(&req.n);
ghdr->cmd = CTRL_CMD_GETFAMILY;
if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC) < 0) { if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC) < 0) {
fprintf(stderr, "Cannot open generic netlink socket\n"); fprintf(stderr, "Cannot open generic netlink socket\n");
@ -74,7 +70,6 @@ int genl_ctrl_resolve_family(const char *family)
{ {
struct rtattr *tb[CTRL_ATTR_MAX + 1]; struct rtattr *tb[CTRL_ATTR_MAX + 1];
struct genlmsghdr *ghdr = NLMSG_DATA(nlh);
int len = nlh->nlmsg_len; int len = nlh->nlmsg_len;
struct rtattr *attrs; struct rtattr *attrs;
@ -291,24 +286,19 @@ static int print_ctrl2(const struct sockaddr_nl *who,
static int ctrl_list(int cmd, int argc, char **argv) static int ctrl_list(int cmd, int argc, char **argv)
{ {
struct rtnl_handle rth; struct rtnl_handle rth;
struct nlmsghdr *nlh;
struct genlmsghdr *ghdr;
int ret = -1; int ret = -1;
char d[GENL_NAMSIZ]; char d[GENL_NAMSIZ];
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct genlmsghdr g;
char buf[4096]; char buf[4096];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN),
memset(&req, 0, sizeof(req)); .n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
.n.nlmsg_type = GENL_ID_CTRL,
nlh = &req.n; .g.cmd = CTRL_CMD_GETFAMILY,
nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); };
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; struct nlmsghdr *nlh = &req.n;
nlh->nlmsg_type = GENL_ID_CTRL;
ghdr = NLMSG_DATA(&req.n);
ghdr->cmd = CTRL_CMD_GETFAMILY;
if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC) < 0) { if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC) < 0) {
fprintf(stderr, "Cannot open generic netlink socket\n"); fprintf(stderr, "Cannot open generic netlink socket\n");

View File

@ -86,9 +86,8 @@ reg:
return f; return f;
noexist: noexist:
f = malloc(sizeof(*f)); f = calloc(1, sizeof(*f));
if (f) { if (f) {
memset(f, 0, sizeof(*f));
strncpy(f->name, str, 15); strncpy(f->name, str, 15);
f->parse_genlopt = parse_nofopt; f->parse_genlopt = parse_nofopt;
f->print_genlopt = print_nofopt; f->print_genlopt = print_nofopt;

View File

@ -135,9 +135,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p)
static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p) static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
{ {
int count = 0; int count = 0;
char medium[IFNAMSIZ]; char medium[IFNAMSIZ] = {};
memset(medium, 0, sizeof(medium));
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "mode") == 0) { if (strcmp(*argv, "mode") == 0) {
@ -276,9 +274,8 @@ static int parse_args(int argc, char **argv, int cmd, struct ip6_tnl_parm2 *p)
duparg2("name", *argv); duparg2("name", *argv);
strncpy(p->name, *argv, IFNAMSIZ - 1); strncpy(p->name, *argv, IFNAMSIZ - 1);
if (cmd == SIOCCHGTUNNEL && count == 0) { if (cmd == SIOCCHGTUNNEL && count == 0) {
struct ip6_tnl_parm2 old_p; struct ip6_tnl_parm2 old_p = {};
memset(&old_p, 0, sizeof(old_p));
if (tnl_get_ioctl(*argv, &old_p)) if (tnl_get_ioctl(*argv, &old_p))
return -1; return -1;
*p = old_p; *p = old_p;
@ -351,7 +348,7 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
while (fgets(buf, sizeof(buf), fp) != NULL) { while (fgets(buf, sizeof(buf), fp) != NULL) {
char name[IFNAMSIZ]; char name[IFNAMSIZ];
int index, type; int index, type;
struct ip6_tnl_parm2 p1; struct ip6_tnl_parm2 p1 = {};
char *ptr; char *ptr;
buf[sizeof(buf) - 1] = '\0'; buf[sizeof(buf) - 1] = '\0';
@ -372,7 +369,6 @@ static int do_tunnels_list(struct ip6_tnl_parm2 *p)
} }
if (type != ARPHRD_TUNNEL6 && type != ARPHRD_IP6GRE) if (type != ARPHRD_TUNNEL6 && type != ARPHRD_IP6GRE)
continue; continue;
memset(&p1, 0, sizeof(p1));
ip6_tnl_parm_init(&p1, 0); ip6_tnl_parm_init(&p1, 0);
if (type == ARPHRD_IP6GRE) if (type == ARPHRD_IP6GRE)
p1.proto = IPPROTO_GRE; p1.proto = IPPROTO_GRE;

View File

@ -173,13 +173,12 @@ static void print_queuelen(FILE *f, struct rtattr *tb[IFLA_MAX + 1])
if (tb[IFLA_TXQLEN]) if (tb[IFLA_TXQLEN])
qlen = *(int *)RTA_DATA(tb[IFLA_TXQLEN]); qlen = *(int *)RTA_DATA(tb[IFLA_TXQLEN]);
else { else {
struct ifreq ifr; struct ifreq ifr = {};
int s = socket(AF_INET, SOCK_STREAM, 0); int s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0) if (s < 0)
return; return;
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, rta_getattr_str(tb[IFLA_IFNAME])); strcpy(ifr.ifr_name, rta_getattr_str(tb[IFLA_IFNAME]));
if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) { if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) {
fprintf(f, "ioctl(SIOCGIFTXQLEN) failed: %s\n", strerror(errno)); fprintf(f, "ioctl(SIOCGIFTXQLEN) failed: %s\n", strerror(errno));
@ -450,7 +449,7 @@ static void print_num(FILE *fp, unsigned int width, uint64_t count)
static void print_vf_stats64(FILE *fp, struct rtattr *vfstats) static void print_vf_stats64(FILE *fp, struct rtattr *vfstats)
{ {
struct rtattr *vf[IFLA_VF_STATS_MAX + 1] = {}; struct rtattr *vf[IFLA_VF_STATS_MAX + 1];
if (vfstats->rta_type != IFLA_VF_STATS) { if (vfstats->rta_type != IFLA_VF_STATS) {
fprintf(stderr, "BUG: rta type is %d\n", vfstats->rta_type); fprintf(stderr, "BUG: rta type is %d\n", vfstats->rta_type);
@ -1037,10 +1036,8 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
} }
if (filter.pfx.family) { if (filter.pfx.family) {
if (rta_tb[IFA_LOCAL]) { if (rta_tb[IFA_LOCAL]) {
inet_prefix dst; inet_prefix dst = { .family = ifa->ifa_family };
memset(&dst, 0, sizeof(dst));
dst.family = ifa->ifa_family;
memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]), RTA_PAYLOAD(rta_tb[IFA_LOCAL])); memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]), RTA_PAYLOAD(rta_tb[IFA_LOCAL]));
if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen)) if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen))
return 0; return 0;
@ -1396,10 +1393,10 @@ static void ipaddr_filter(struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo)
tb[IFA_LOCAL] = tb[IFA_ADDRESS]; tb[IFA_LOCAL] = tb[IFA_ADDRESS];
if (filter.pfx.family && tb[IFA_LOCAL]) { if (filter.pfx.family && tb[IFA_LOCAL]) {
inet_prefix dst; inet_prefix dst = {
.family = ifa->ifa_family
};
memset(&dst, 0, sizeof(dst));
dst.family = ifa->ifa_family;
memcpy(&dst.data, RTA_DATA(tb[IFA_LOCAL]), RTA_PAYLOAD(tb[IFA_LOCAL])); memcpy(&dst.data, RTA_DATA(tb[IFA_LOCAL]), RTA_PAYLOAD(tb[IFA_LOCAL]));
if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen)) if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen))
continue; continue;
@ -1845,7 +1842,12 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct ifaddrmsg ifa; struct ifaddrmsg ifa;
char buf[256]; char buf[256];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)),
.n.nlmsg_flags = NLM_F_REQUEST | flags,
.n.nlmsg_type = cmd,
.ifa.ifa_family = preferred_family,
};
char *d = NULL; char *d = NULL;
char *l = NULL; char *l = NULL;
char *lcl_arg = NULL; char *lcl_arg = NULL;
@ -1860,16 +1862,8 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
int scoped = 0; int scoped = 0;
__u32 preferred_lft = INFINITY_LIFE_TIME; __u32 preferred_lft = INFINITY_LIFE_TIME;
__u32 valid_lft = INFINITY_LIFE_TIME; __u32 valid_lft = INFINITY_LIFE_TIME;
struct ifa_cacheinfo cinfo;
unsigned int ifa_flags = 0; unsigned int ifa_flags = 0;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
req.n.nlmsg_flags = NLM_F_REQUEST | flags;
req.n.nlmsg_type = cmd;
req.ifa.ifa_family = preferred_family;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "peer") == 0 || if (strcmp(*argv, "peer") == 0 ||
strcmp(*argv, "remote") == 0) { strcmp(*argv, "remote") == 0) {
@ -2026,6 +2020,8 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
} }
if (valid_lftp || preferred_lftp) { if (valid_lftp || preferred_lftp) {
struct ifa_cacheinfo cinfo = {};
if (!valid_lft) { if (!valid_lft) {
fprintf(stderr, "valid_lft is zero\n"); fprintf(stderr, "valid_lft is zero\n");
return -1; return -1;
@ -2035,7 +2031,6 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
return -1; return -1;
} }
memset(&cinfo, 0, sizeof(cinfo));
cinfo.ifa_prefered = preferred_lft; cinfo.ifa_prefered = preferred_lft;
cinfo.ifa_valid = valid_lft; cinfo.ifa_valid = valid_lft;
addattr_l(&req.n, sizeof(req), IFA_CACHEINFO, &cinfo, addattr_l(&req.n, sizeof(req), IFA_CACHEINFO, &cinfo,

View File

@ -127,23 +127,18 @@ static int ipaddrlabel_modify(int cmd, int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct ifaddrlblmsg ifal; struct ifaddrlblmsg ifal;
char buf[1024]; char buf[1024];
} req; } req = {
.n.nlmsg_type = cmd,
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrlblmsg)),
.n.nlmsg_flags = NLM_F_REQUEST,
.ifal.ifal_family = preferred_family,
};
inet_prefix prefix; inet_prefix prefix = {};
uint32_t label = 0xffffffffUL; uint32_t label = 0xffffffffUL;
char *p = NULL; char *p = NULL;
char *l = NULL; char *l = NULL;
memset(&req, 0, sizeof(req));
memset(&prefix, 0, sizeof(prefix));
req.n.nlmsg_type = cmd;
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrlblmsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.ifal.ifal_family = preferred_family;
req.ifal.ifal_prefixlen = 0;
req.ifal.ifal_index = 0;
if (cmd == RTM_NEWADDRLABEL) { if (cmd == RTM_NEWADDRLABEL) {
req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL; req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;
} }

View File

@ -55,7 +55,9 @@ void iplink_usage(void)
fprintf(stderr, " type TYPE [ ARGS ]\n"); fprintf(stderr, " type TYPE [ ARGS ]\n");
fprintf(stderr, " ip link delete { DEVICE | dev DEVICE | group DEVGROUP } type TYPE [ ARGS ]\n"); fprintf(stderr, " ip link delete { DEVICE | dev DEVICE | group DEVGROUP } type TYPE [ ARGS ]\n");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fprintf(stderr, " ip link set { DEVICE | dev DEVICE | group DEVGROUP } [ { up | down } ]\n"); fprintf(stderr, " ip link set { DEVICE | dev DEVICE | group DEVGROUP }\n");
fprintf(stderr, " [ { up | down } ]\n");
fprintf(stderr, " [ type TYPE ARGS ]\n");
} else } else
fprintf(stderr, "Usage: ip link set DEVICE [ { up | down } ]\n"); fprintf(stderr, "Usage: ip link set DEVICE [ { up | down } ]\n");
@ -206,16 +208,14 @@ static int iplink_have_newlink(void)
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg i; struct ifinfomsg i;
char buf[1024]; char buf[1024];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
.n.nlmsg_type = RTM_NEWLINK,
.i.ifi_family = AF_UNSPEC,
};
if (have_rtnl_newlink < 0) { if (have_rtnl_newlink < 0) {
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
req.n.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK;
req.n.nlmsg_type = RTM_NEWLINK;
req.i.ifi_family = AF_UNSPEC;
if (rtnl_send(&rth, &req.n, req.n.nlmsg_len) < 0) { if (rtnl_send(&rth, &req.n, req.n.nlmsg_len) < 0) {
perror("request send failed"); perror("request send failed");
exit(1); exit(1);
@ -781,16 +781,14 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
int index = -1; int index = -1;
int group; int group;
struct link_util *lu = NULL; struct link_util *lu = NULL;
struct iplink_req req; struct iplink_req req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
.n.nlmsg_flags = NLM_F_REQUEST | flags,
.n.nlmsg_type = cmd,
.i.ifi_family = preferred_family,
};
int ret; int ret;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
req.i.ifi_family = preferred_family;
ret = iplink_parse(argc, argv, ret = iplink_parse(argc, argv,
&req, &name, &type, &link, &dev, &group, &index); &req, &name, &type, &link, &dev, &group, &index);
if (ret < 0) if (ret < 0)
@ -923,19 +921,17 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
int iplink_get(unsigned int flags, char *name, __u32 filt_mask) int iplink_get(unsigned int flags, char *name, __u32 filt_mask)
{ {
int len; int len;
struct iplink_req req; struct iplink_req req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
.n.nlmsg_flags = NLM_F_REQUEST | flags,
.n.nlmsg_type = RTM_GETLINK,
.i.ifi_family = preferred_family,
};
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
char buf[16384]; char buf[16384];
} answer; } answer;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = RTM_GETLINK;
req.i.ifi_family = preferred_family;
if (name) { if (name) {
len = strlen(name) + 1; len = strlen(name) + 1;
if (len == 1) if (len == 1)
@ -1029,16 +1025,14 @@ static int do_changename(const char *dev, const char *newdev)
static int set_qlen(const char *dev, int qlen) static int set_qlen(const char *dev, int qlen)
{ {
struct ifreq ifr; struct ifreq ifr = { .ifr_qlen = qlen };
int s; int s;
s = get_ctl_fd(); s = get_ctl_fd();
if (s < 0) if (s < 0)
return -1; return -1;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, dev, IFNAMSIZ); strncpy(ifr.ifr_name, dev, IFNAMSIZ);
ifr.ifr_qlen = qlen;
if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) { if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) {
perror("SIOCSIFXQLEN"); perror("SIOCSIFXQLEN");
close(s); close(s);
@ -1051,16 +1045,14 @@ static int set_qlen(const char *dev, int qlen)
static int set_mtu(const char *dev, int mtu) static int set_mtu(const char *dev, int mtu)
{ {
struct ifreq ifr; struct ifreq ifr = { .ifr_mtu = mtu };
int s; int s;
s = get_ctl_fd(); s = get_ctl_fd();
if (s < 0) if (s < 0)
return -1; return -1;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, dev, IFNAMSIZ); strncpy(ifr.ifr_name, dev, IFNAMSIZ);
ifr.ifr_mtu = mtu;
if (ioctl(s, SIOCSIFMTU, &ifr) < 0) { if (ioctl(s, SIOCSIFMTU, &ifr) < 0) {
perror("SIOCSIFMTU"); perror("SIOCSIFMTU");
close(s); close(s);
@ -1073,8 +1065,11 @@ static int set_mtu(const char *dev, int mtu)
static int get_address(const char *dev, int *htype) static int get_address(const char *dev, int *htype)
{ {
struct ifreq ifr; struct ifreq ifr = {};
struct sockaddr_ll me; struct sockaddr_ll me = {
.sll_family = AF_PACKET,
.sll_protocol = htons(ETH_P_LOOP),
};
socklen_t alen; socklen_t alen;
int s; int s;
@ -1084,7 +1079,6 @@ static int get_address(const char *dev, int *htype)
return -1; return -1;
} }
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, dev, IFNAMSIZ); strncpy(ifr.ifr_name, dev, IFNAMSIZ);
if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) { if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
perror("SIOCGIFINDEX"); perror("SIOCGIFINDEX");
@ -1092,10 +1086,7 @@ static int get_address(const char *dev, int *htype)
return -1; return -1;
} }
memset(&me, 0, sizeof(me));
me.sll_family = AF_PACKET;
me.sll_ifindex = ifr.ifr_ifindex; me.sll_ifindex = ifr.ifr_ifindex;
me.sll_protocol = htons(ETH_P_LOOP);
if (bind(s, (struct sockaddr *)&me, sizeof(me)) == -1) { if (bind(s, (struct sockaddr *)&me, sizeof(me)) == -1) {
perror("bind"); perror("bind");
close(s); close(s);

View File

@ -17,6 +17,16 @@
#include "utils.h" #include "utils.h"
#include "ip_common.h" #include "ip_common.h"
static void print_explain(FILE *f)
{
fprintf(f, "Usage: ... bond_slave [ queue_id ID ]\n");
}
static void explain(void)
{
print_explain(stderr);
}
static const char *slave_states[] = { static const char *slave_states[] = {
[BOND_STATE_ACTIVE] = "ACTIVE", [BOND_STATE_ACTIVE] = "ACTIVE",
[BOND_STATE_BACKUP] = "BACKUP", [BOND_STATE_BACKUP] = "BACKUP",
@ -99,6 +109,13 @@ static int bond_slave_parse_opt(struct link_util *lu, int argc, char **argv,
if (get_u16(&queue_id, *argv, 0)) if (get_u16(&queue_id, *argv, 0))
invarg("queue_id is invalid", *argv); invarg("queue_id is invalid", *argv);
addattr16(n, 1024, IFLA_BOND_SLAVE_QUEUE_ID, queue_id); addattr16(n, 1024, IFLA_BOND_SLAVE_QUEUE_ID, queue_id);
} else {
if (matches(*argv, "help") != 0)
fprintf(stderr,
"bond_slave: unknown option \"%s\"?\n",
*argv);
explain();
return -1;
} }
argc--, argv++; argc--, argv++;
} }
@ -106,10 +123,17 @@ static int bond_slave_parse_opt(struct link_util *lu, int argc, char **argv,
return 0; return 0;
} }
static void bond_slave_print_help(struct link_util *lu, int argc, char **argv,
FILE *f)
{
print_explain(f);
}
struct link_util bond_slave_link_util = { struct link_util bond_slave_link_util = {
.id = "bond", .id = "bond",
.maxattr = IFLA_BOND_SLAVE_MAX, .maxattr = IFLA_BOND_SLAVE_MAX,
.print_opt = bond_slave_print_opt, .print_opt = bond_slave_print_opt,
.parse_opt = bond_slave_parse_opt, .parse_opt = bond_slave_parse_opt,
.print_help = bond_slave_print_help,
.slave = true, .slave = true,
}; };

View File

@ -110,11 +110,9 @@ static void print_ctrlmode(FILE *f, __u32 cm)
static int can_parse_opt(struct link_util *lu, int argc, char **argv, static int can_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct can_bittiming bt, dbt; struct can_bittiming bt = {}, dbt = {};
struct can_ctrlmode cm = {0, 0}; struct can_ctrlmode cm = {0, 0};
memset(&bt, 0, sizeof(bt));
memset(&dbt, 0, sizeof(dbt));
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "bitrate") == 0) { if (matches(*argv, "bitrate") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -93,18 +93,15 @@ static void read_dev_mcast(struct ma_info **result_p)
while (fgets(buf, sizeof(buf), fp)) { while (fgets(buf, sizeof(buf), fp)) {
char hexa[256]; char hexa[256];
struct ma_info m; struct ma_info m = { .addr.family = AF_PACKET };
int len; int len;
int st; int st;
memset(&m, 0, sizeof(m));
sscanf(buf, "%d%s%d%d%s", &m.index, m.name, &m.users, &st, sscanf(buf, "%d%s%d%d%s", &m.index, m.name, &m.users, &st,
hexa); hexa);
if (filter.dev && strcmp(filter.dev, m.name)) if (filter.dev && strcmp(filter.dev, m.name))
continue; continue;
m.addr.family = AF_PACKET;
len = parse_hex(hexa, (unsigned char *)&m.addr.data, sizeof(m.addr.data)); len = parse_hex(hexa, (unsigned char *)&m.addr.data, sizeof(m.addr.data));
if (len >= 0) { if (len >= 0) {
struct ma_info *ma = malloc(sizeof(m)); struct ma_info *ma = malloc(sizeof(m));
@ -122,22 +119,21 @@ static void read_dev_mcast(struct ma_info **result_p)
static void read_igmp(struct ma_info **result_p) static void read_igmp(struct ma_info **result_p)
{ {
struct ma_info m; struct ma_info m = {
.addr.family = AF_INET,
.addr.bitlen = 32,
.addr.bytelen = 4,
};
char buf[256]; char buf[256];
FILE *fp = fopen("/proc/net/igmp", "r"); FILE *fp = fopen("/proc/net/igmp", "r");
if (!fp) if (!fp)
return; return;
memset(&m, 0, sizeof(m));
if (!fgets(buf, sizeof(buf), fp)) { if (!fgets(buf, sizeof(buf), fp)) {
fclose(fp); fclose(fp);
return; return;
} }
m.addr.family = AF_INET;
m.addr.bitlen = 32;
m.addr.bytelen = 4;
while (fgets(buf, sizeof(buf), fp)) { while (fgets(buf, sizeof(buf), fp)) {
struct ma_info *ma; struct ma_info *ma;
@ -169,17 +165,14 @@ static void read_igmp6(struct ma_info **result_p)
while (fgets(buf, sizeof(buf), fp)) { while (fgets(buf, sizeof(buf), fp)) {
char hexa[256]; char hexa[256];
struct ma_info m; struct ma_info m = { .addr.family = AF_INET6 };
int len; int len;
memset(&m, 0, sizeof(m));
sscanf(buf, "%d%s%s%d", &m.index, m.name, hexa, &m.users); sscanf(buf, "%d%s%s%d", &m.index, m.name, hexa, &m.users);
if (filter.dev && strcmp(filter.dev, m.name)) if (filter.dev && strcmp(filter.dev, m.name))
continue; continue;
m.addr.family = AF_INET6;
len = parse_hex(hexa, (unsigned char *)&m.addr.data, sizeof(m.addr.data)); len = parse_hex(hexa, (unsigned char *)&m.addr.data, sizeof(m.addr.data));
if (len >= 0) { if (len >= 0) {
struct ma_info *ma = malloc(sizeof(m)); struct ma_info *ma = malloc(sizeof(m));
@ -274,11 +267,9 @@ static int multiaddr_list(int argc, char **argv)
static int multiaddr_modify(int cmd, int argc, char **argv) static int multiaddr_modify(int cmd, int argc, char **argv)
{ {
struct ifreq ifr; struct ifreq ifr = {};
int fd; int fd;
memset(&ifr, 0, sizeof(ifr));
if (cmd == RTM_NEWADDR) if (cmd == RTM_NEWADDR)
cmd = SIOCADDMULTI; cmd = SIOCADDMULTI;
else else

View File

@ -97,20 +97,16 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
return 0; return 0;
if (tb[RTA_DST] && filter.mdst.bitlen > 0) { if (tb[RTA_DST] && filter.mdst.bitlen > 0) {
inet_prefix dst; inet_prefix dst = { .family = r->rtm_family };
memset(&dst, 0, sizeof(dst));
dst.family = r->rtm_family;
memcpy(&dst.data, RTA_DATA(tb[RTA_DST]), RTA_PAYLOAD(tb[RTA_DST])); memcpy(&dst.data, RTA_DATA(tb[RTA_DST]), RTA_PAYLOAD(tb[RTA_DST]));
if (inet_addr_match(&dst, &filter.mdst, filter.mdst.bitlen)) if (inet_addr_match(&dst, &filter.mdst, filter.mdst.bitlen))
return 0; return 0;
} }
if (tb[RTA_SRC] && filter.msrc.bitlen > 0) { if (tb[RTA_SRC] && filter.msrc.bitlen > 0) {
inet_prefix src; inet_prefix src = { .family = r->rtm_family };
memset(&src, 0, sizeof(src));
src.family = r->rtm_family;
memcpy(&src.data, RTA_DATA(tb[RTA_SRC]), RTA_PAYLOAD(tb[RTA_SRC])); memcpy(&src.data, RTA_DATA(tb[RTA_SRC]), RTA_PAYLOAD(tb[RTA_SRC]));
if (inet_addr_match(&src, &filter.msrc, filter.msrc.bitlen)) if (inet_addr_match(&src, &filter.msrc, filter.msrc.bitlen))
return 0; return 0;

View File

@ -101,7 +101,13 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct ndmsg ndm; struct ndmsg ndm;
char buf[256]; char buf[256];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)),
.n.nlmsg_flags = NLM_F_REQUEST | flags,
.n.nlmsg_type = cmd,
.ndm.ndm_family = preferred_family,
.ndm.ndm_state = NUD_PERMANENT,
};
char *dev = NULL; char *dev = NULL;
int dst_ok = 0; int dst_ok = 0;
int dev_ok = 0; int dev_ok = 0;
@ -109,14 +115,6 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
char *lla = NULL; char *lla = NULL;
inet_prefix dst; inet_prefix dst;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
req.ndm.ndm_family = preferred_family;
req.ndm.ndm_state = NUD_PERMANENT;
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "lladdr") == 0) { if (matches(*argv, "lladdr") == 0) {
NEXT_ARG(); NEXT_ARG();
@ -239,10 +237,8 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[NDA_DST]) { if (tb[NDA_DST]) {
if (filter.pfx.family) { if (filter.pfx.family) {
inet_prefix dst; inet_prefix dst = { .family = r->ndm_family };
memset(&dst, 0, sizeof(dst));
dst.family = r->ndm_family;
memcpy(&dst.data, RTA_DATA(tb[NDA_DST]), RTA_PAYLOAD(tb[NDA_DST])); memcpy(&dst.data, RTA_DATA(tb[NDA_DST]), RTA_PAYLOAD(tb[NDA_DST]));
if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen)) if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen))
return 0; return 0;
@ -348,15 +344,13 @@ static int do_show_or_flush(int argc, char **argv, int flush)
struct nlmsghdr n; struct nlmsghdr n;
struct ndmsg ndm; struct ndmsg ndm;
char buf[256]; char buf[256];
} req; } req = {
.n.nlmsg_type = RTM_GETNEIGH,
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)),
};
char *filter_dev = NULL; char *filter_dev = NULL;
int state_given = 0; int state_given = 0;
memset(&req, 0, sizeof(req));
req.n.nlmsg_type = RTM_GETNEIGH;
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
ipneigh_reset_filter(0); ipneigh_reset_filter(0);
if (!filter.family) if (!filter.family)

View File

@ -154,7 +154,11 @@ static int do_show(int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct netconfmsg ncm; struct netconfmsg ncm;
char buf[1024]; char buf[1024];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct netconfmsg)),
.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
.n.nlmsg_type = RTM_GETNETCONF,
};
ipnetconf_reset_filter(0); ipnetconf_reset_filter(0);
filter.family = preferred_family; filter.family = preferred_family;
@ -176,10 +180,6 @@ static int do_show(int argc, char **argv)
ll_init_map(&rth); ll_init_map(&rth);
if (filter.ifindex) { if (filter.ifindex) {
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct netconfmsg));
req.n.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK;
req.n.nlmsg_type = RTM_GETNETCONF;
req.ncm.ncm_family = filter.family; req.ncm.ncm_family = filter.family;
if (filter.ifindex) if (filter.ifindex)
addattr_l(&req.n, sizeof(req), NETCONFA_IFINDEX, addattr_l(&req.n, sizeof(req), NETCONFA_IFINDEX,

View File

@ -61,16 +61,15 @@ static int ipnetns_have_nsid(void)
struct nlmsghdr n; struct nlmsghdr n;
struct rtgenmsg g; struct rtgenmsg g;
char buf[1024]; char buf[1024];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = RTM_GETNSID,
.g.rtgen_family = AF_UNSPEC,
};
int fd; int fd;
if (have_rtnl_getnsid < 0) { if (have_rtnl_getnsid < 0) {
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = RTM_GETNSID;
req.g.rtgen_family = AF_UNSPEC;
fd = open("/proc/self/ns/net", O_RDONLY); fd = open("/proc/self/ns/net", O_RDONLY);
if (fd < 0) { if (fd < 0) {
perror("open(\"/proc/self/ns/net\")"); perror("open(\"/proc/self/ns/net\")");
@ -96,17 +95,16 @@ static int get_netnsid_from_name(const char *name)
struct nlmsghdr n; struct nlmsghdr n;
struct rtgenmsg g; struct rtgenmsg g;
char buf[1024]; char buf[1024];
} req, answer; } answer, req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = RTM_GETNSID,
.g.rtgen_family = AF_UNSPEC,
};
struct rtattr *tb[NETNSA_MAX + 1]; struct rtattr *tb[NETNSA_MAX + 1];
struct rtgenmsg *rthdr; struct rtgenmsg *rthdr;
int len, fd; int len, fd;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = RTM_GETNSID;
req.g.rtgen_family = AF_UNSPEC;
fd = netns_get_fd(name); fd = netns_get_fd(name);
if (fd < 0) if (fd < 0)
return fd; return fd;
@ -685,15 +683,14 @@ static int set_netnsid_from_name(const char *name, int nsid)
struct nlmsghdr n; struct nlmsghdr n;
struct rtgenmsg g; struct rtgenmsg g;
char buf[1024]; char buf[1024];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = RTM_NEWNSID,
.g.rtgen_family = AF_UNSPEC,
};
int fd, err = 0; int fd, err = 0;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = RTM_NEWNSID;
req.g.rtgen_family = AF_UNSPEC;
fd = netns_get_fd(name); fd = netns_get_fd(name);
if (fd < 0) if (fd < 0)
return fd; return fd;

View File

@ -66,26 +66,19 @@ static int ipntable_modify(int cmd, int flags, int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct ndtmsg ndtm; struct ndtmsg ndtm;
char buf[1024]; char buf[1024];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndtmsg)),
.n.nlmsg_flags = NLM_F_REQUEST | flags,
.n.nlmsg_type = cmd,
.ndtm.ndtm_family = preferred_family,
};
char *namep = NULL; char *namep = NULL;
char *threshsp = NULL; char *threshsp = NULL;
char *gc_intp = NULL; char *gc_intp = NULL;
char parms_buf[1024]; char parms_buf[1024] = {};
struct rtattr *parms_rta = (struct rtattr *)parms_buf; struct rtattr *parms_rta = (struct rtattr *)parms_buf;
int parms_change = 0; int parms_change = 0;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndtmsg));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
req.ndtm.ndtm_family = preferred_family;
req.ndtm.ndtm_pad1 = 0;
req.ndtm.ndtm_pad2 = 0;
memset(&parms_buf, 0, sizeof(parms_buf));
parms_rta->rta_type = NDTA_PARMS; parms_rta->rta_type = NDTA_PARMS;
parms_rta->rta_len = RTA_LENGTH(0); parms_rta->rta_len = RTA_LENGTH(0);
@ -322,15 +315,13 @@ static int ipntable_modify(int cmd, int flags, int argc, char **argv)
static const char *ntable_strtime_delta(__u32 msec) static const char *ntable_strtime_delta(__u32 msec)
{ {
static char str[32]; static char str[32];
struct timeval now; struct timeval now = {};
time_t t; time_t t;
struct tm *tp; struct tm *tp;
if (msec == 0) if (msec == 0)
goto error; goto error;
memset(&now, 0, sizeof(now));
if (gettimeofday(&now, NULL) < 0) { if (gettimeofday(&now, NULL) < 0) {
perror("gettimeofday"); perror("gettimeofday");
goto error; goto error;

View File

@ -140,10 +140,10 @@ static int flush_update(void)
static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len) static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
{ {
struct rtmsg *r = NLMSG_DATA(n); struct rtmsg *r = NLMSG_DATA(n);
inet_prefix dst; inet_prefix dst = { .family = r->rtm_family };
inet_prefix src; inet_prefix src = { .family = r->rtm_family };
inet_prefix via; inet_prefix via = { .family = r->rtm_family };
inet_prefix prefsrc; inet_prefix prefsrc = { .family = r->rtm_family };
__u32 table; __u32 table;
static int ip6_multiple_tables; static int ip6_multiple_tables;
@ -211,19 +211,13 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
if (filter.rprefsrc.family && r->rtm_family != filter.rprefsrc.family) if (filter.rprefsrc.family && r->rtm_family != filter.rprefsrc.family)
return 0; return 0;
memset(&dst, 0, sizeof(dst));
dst.family = r->rtm_family;
if (tb[RTA_DST]) if (tb[RTA_DST])
memcpy(&dst.data, RTA_DATA(tb[RTA_DST]), (r->rtm_dst_len+7)/8); memcpy(&dst.data, RTA_DATA(tb[RTA_DST]), (r->rtm_dst_len+7)/8);
if (filter.rsrc.family || filter.msrc.family) { if (filter.rsrc.family || filter.msrc.family) {
memset(&src, 0, sizeof(src));
src.family = r->rtm_family;
if (tb[RTA_SRC]) if (tb[RTA_SRC])
memcpy(&src.data, RTA_DATA(tb[RTA_SRC]), (r->rtm_src_len+7)/8); memcpy(&src.data, RTA_DATA(tb[RTA_SRC]), (r->rtm_src_len+7)/8);
} }
if (filter.rvia.bitlen > 0) { if (filter.rvia.bitlen > 0) {
memset(&via, 0, sizeof(via));
via.family = r->rtm_family;
if (tb[RTA_GATEWAY]) if (tb[RTA_GATEWAY])
memcpy(&via.data, RTA_DATA(tb[RTA_GATEWAY]), host_len/8); memcpy(&via.data, RTA_DATA(tb[RTA_GATEWAY]), host_len/8);
if (tb[RTA_VIA]) { if (tb[RTA_VIA]) {
@ -235,8 +229,6 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
} }
} }
if (filter.rprefsrc.bitlen > 0) { if (filter.rprefsrc.bitlen > 0) {
memset(&prefsrc, 0, sizeof(prefsrc));
prefsrc.family = r->rtm_family;
if (tb[RTA_PREFSRC]) if (tb[RTA_PREFSRC])
memcpy(&prefsrc.data, RTA_DATA(tb[RTA_PREFSRC]), host_len/8); memcpy(&prefsrc.data, RTA_DATA(tb[RTA_PREFSRC]), host_len/8);
} }
@ -829,7 +821,14 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct rtmsg r; struct rtmsg r;
char buf[1024]; char buf[1024];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)),
.n.nlmsg_flags = NLM_F_REQUEST | flags,
.n.nlmsg_type = cmd,
.r.rtm_family = preferred_family,
.r.rtm_table = RT_TABLE_MAIN,
.r.rtm_scope = RT_SCOPE_NOWHERE,
};
char mxbuf[256]; char mxbuf[256];
struct rtattr *mxrta = (void *)mxbuf; struct rtattr *mxrta = (void *)mxbuf;
unsigned int mxlock = 0; unsigned int mxlock = 0;
@ -842,15 +841,6 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
int raw = 0; int raw = 0;
int type_ok = 0; int type_ok = 0;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
req.r.rtm_family = preferred_family;
req.r.rtm_table = RT_TABLE_MAIN;
req.r.rtm_scope = RT_SCOPE_NOWHERE;
if (cmd != RTM_DELROUTE) { if (cmd != RTM_DELROUTE) {
req.r.rtm_protocol = RTPROT_BOOT; req.r.rtm_protocol = RTPROT_BOOT;
req.r.rtm_scope = RT_SCOPE_UNIVERSE; req.r.rtm_scope = RT_SCOPE_UNIVERSE;
@ -1277,20 +1267,15 @@ static int rtnl_rtcache_request(struct rtnl_handle *rth, int family)
struct { struct {
struct nlmsghdr nlh; struct nlmsghdr nlh;
struct rtmsg rtm; struct rtmsg rtm;
} req; } req = {
struct sockaddr_nl nladdr; .nlh.nlmsg_len = sizeof(req),
.nlh.nlmsg_type = RTM_GETROUTE,
memset(&nladdr, 0, sizeof(nladdr)); .nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_REQUEST,
memset(&req, 0, sizeof(req)); .nlh.nlmsg_seq = rth->dump = ++rth->seq,
nladdr.nl_family = AF_NETLINK; .rtm.rtm_family = family,
.rtm.rtm_flags = RTM_F_CLONED,
req.nlh.nlmsg_len = sizeof(req); };
req.nlh.nlmsg_type = RTM_GETROUTE; struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_REQUEST;
req.nlh.nlmsg_pid = 0;
req.nlh.nlmsg_seq = rth->dump = ++rth->seq;
req.rtm.rtm_family = family;
req.rtm.rtm_flags |= RTM_F_CLONED;
return sendto(rth->fd, (void *)&req, sizeof(req), 0, (struct sockaddr *)&nladdr, sizeof(nladdr)); return sendto(rth->fd, (void *)&req, sizeof(req), 0, (struct sockaddr *)&nladdr, sizeof(nladdr));
} }
@ -1641,30 +1626,21 @@ static int iproute_get(int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct rtmsg r; struct rtmsg r;
char buf[1024]; char buf[1024];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = RTM_GETROUTE,
.r.rtm_family = preferred_family,
};
char *idev = NULL; char *idev = NULL;
char *odev = NULL; char *odev = NULL;
int connected = 0; int connected = 0;
int from_ok = 0; int from_ok = 0;
unsigned int mark = 0; unsigned int mark = 0;
memset(&req, 0, sizeof(req));
iproute_reset_filter(0); iproute_reset_filter(0);
filter.cloned = 2; filter.cloned = 2;
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = RTM_GETROUTE;
req.r.rtm_family = preferred_family;
req.r.rtm_table = 0;
req.r.rtm_protocol = 0;
req.r.rtm_scope = 0;
req.r.rtm_type = 0;
req.r.rtm_src_len = 0;
req.r.rtm_dst_len = 0;
req.r.rtm_tos = 0;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "tos") == 0 || if (strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) { matches(*argv, "dsfield") == 0) {

View File

@ -331,19 +331,15 @@ static int iprule_modify(int cmd, int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct rtmsg r; struct rtmsg r;
char buf[1024]; char buf[1024];
} req; } req = {
.n.nlmsg_type = cmd,
memset(&req, 0, sizeof(req)); .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)),
.n.nlmsg_flags = NLM_F_REQUEST,
req.n.nlmsg_type = cmd; .r.rtm_family = preferred_family,
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); .r.rtm_protocol = RTPROT_BOOT,
req.n.nlmsg_flags = NLM_F_REQUEST; .r.rtm_scope = RT_SCOPE_UNIVERSE,
req.r.rtm_family = preferred_family; .r.rtm_type = RTN_UNSPEC,
req.r.rtm_protocol = RTPROT_BOOT; };
req.r.rtm_scope = RT_SCOPE_UNIVERSE;
req.r.rtm_table = 0;
req.r.rtm_type = RTN_UNSPEC;
req.r.rtm_flags = 0;
if (cmd == RTM_NEWRULE) { if (cmd == RTM_NEWRULE) {
req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL; req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;

View File

@ -89,10 +89,7 @@ static int print_token(const struct sockaddr_nl *who, struct nlmsghdr *n, void *
static int iptoken_list(int argc, char **argv) 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 = { .fp = stdout };
memset(&da, 0, sizeof(da));
da.fp = stdout;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "dev") == 0) { if (strcmp(*argv, "dev") == 0) {
@ -123,18 +120,16 @@ static int iptoken_set(int argc, char **argv, bool delete)
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg ifi; struct ifinfomsg ifi;
char buf[512]; char buf[512];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = RTM_SETLINK,
.ifi.ifi_family = AF_INET6,
};
struct rtattr *afs, *afs6; struct rtattr *afs, *afs6;
bool have_token = delete, have_dev = false; bool have_token = delete, have_dev = false;
inet_prefix addr = { .bytelen = 16, }; inet_prefix addr = { .bytelen = 16, };
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = RTM_SETLINK;
req.ifi.ifi_family = AF_INET6;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "dev") == 0) { if (strcmp(*argv, "dev") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -60,12 +60,10 @@ static void set_tunnel_proto(struct ip_tunnel_parm *p, int proto)
static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p) static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
{ {
int count = 0; int count = 0;
char medium[IFNAMSIZ]; char medium[IFNAMSIZ] = {};
int isatap = 0; int isatap = 0;
memset(p, 0, sizeof(*p)); memset(p, 0, sizeof(*p));
memset(&medium, 0, sizeof(medium));
p->iph.version = 4; p->iph.version = 4;
p->iph.ihl = 5; p->iph.ihl = 5;
#ifndef IP_DF #ifndef IP_DF
@ -182,9 +180,8 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
duparg2("name", *argv); duparg2("name", *argv);
strncpy(p->name, *argv, IFNAMSIZ - 1); strncpy(p->name, *argv, IFNAMSIZ - 1);
if (cmd == SIOCCHGTUNNEL && count == 0) { if (cmd == SIOCCHGTUNNEL && count == 0) {
struct ip_tunnel_parm old_p; struct ip_tunnel_parm old_p = {};
memset(&old_p, 0, sizeof(old_p));
if (tnl_get_ioctl(*argv, &old_p)) if (tnl_get_ioctl(*argv, &old_p))
return -1; return -1;
*p = old_p; *p = old_p;
@ -296,12 +293,10 @@ static int do_del(int argc, char **argv)
static void print_tunnel(struct ip_tunnel_parm *p) static void print_tunnel(struct ip_tunnel_parm *p)
{ {
struct ip_tunnel_6rd ip6rd; struct ip_tunnel_6rd ip6rd = {};
char s1[1024]; char s1[1024];
char s2[1024]; char s2[1024];
memset(&ip6rd, 0, sizeof(ip6rd));
/* Do not use format_host() for local addr, /* Do not use format_host() for local addr,
* symbolic name will not be useful. * symbolic name will not be useful.
*/ */
@ -312,10 +307,9 @@ static void print_tunnel(struct ip_tunnel_parm *p)
p->iph.saddr ? rt_addr_n2a_r(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2)) : "any"); p->iph.saddr ? rt_addr_n2a_r(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2)) : "any");
if (p->iph.protocol == IPPROTO_IPV6 && (p->i_flags & SIT_ISATAP)) { if (p->iph.protocol == IPPROTO_IPV6 && (p->i_flags & SIT_ISATAP)) {
struct ip_tunnel_prl prl[16]; struct ip_tunnel_prl prl[16] = {};
int i; int i;
memset(prl, 0, sizeof(prl));
prl[0].datalen = sizeof(prl) - sizeof(prl[0]); prl[0].datalen = sizeof(prl) - sizeof(prl[0]);
prl[0].addr = htonl(INADDR_ANY); prl[0].addr = htonl(INADDR_ANY);
@ -405,7 +399,7 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
while (fgets(buf, sizeof(buf), fp) != NULL) { while (fgets(buf, sizeof(buf), fp) != NULL) {
char name[IFNAMSIZ]; char name[IFNAMSIZ];
int index, type; int index, type;
struct ip_tunnel_parm p1; struct ip_tunnel_parm p1 = {};
char *ptr; char *ptr;
buf[sizeof(buf) - 1] = 0; buf[sizeof(buf) - 1] = 0;
@ -427,7 +421,6 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
} }
if (type != ARPHRD_TUNNEL && type != ARPHRD_IPGRE && type != ARPHRD_SIT) if (type != ARPHRD_TUNNEL && type != ARPHRD_IPGRE && type != ARPHRD_SIT)
continue; continue;
memset(&p1, 0, sizeof(p1));
if (tnl_get_ioctl(name, &p1)) if (tnl_get_ioctl(name, &p1))
continue; continue;
if ((p->link && p1.link != p->link) || if ((p->link && p1.link != p->link) ||
@ -470,14 +463,11 @@ static int do_show(int argc, char **argv)
static int do_prl(int argc, char **argv) static int do_prl(int argc, char **argv)
{ {
struct ip_tunnel_prl p; struct ip_tunnel_prl p = {};
int count = 0; int count = 0;
int devname = 0; int devname = 0;
int cmd = 0; int cmd = 0;
char medium[IFNAMSIZ]; char medium[IFNAMSIZ] = {};
memset(&p, 0, sizeof(p));
memset(&medium, 0, sizeof(medium));
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "prl-default") == 0) { if (strcmp(*argv, "prl-default") == 0) {
@ -522,15 +512,12 @@ static int do_prl(int argc, char **argv)
static int do_6rd(int argc, char **argv) static int do_6rd(int argc, char **argv)
{ {
struct ip_tunnel_6rd ip6rd; struct ip_tunnel_6rd ip6rd = {};
int devname = 0; int devname = 0;
int cmd = 0; int cmd = 0;
char medium[IFNAMSIZ]; char medium[IFNAMSIZ] = {};
inet_prefix prefix; inet_prefix prefix;
memset(&ip6rd, 0, sizeof(ip6rd));
memset(&medium, 0, sizeof(medium));
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "6rd-prefix") == 0) { if (strcmp(*argv, "6rd-prefix") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -867,9 +867,7 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
static int xfrm_selector_iszero(struct xfrm_selector *s) static int xfrm_selector_iszero(struct xfrm_selector *s)
{ {
struct xfrm_selector s0; struct xfrm_selector s0 = {};
memset(&s0, 0, sizeof(s0));
return (memcmp(&s0, s, sizeof(s0)) == 0); return (memcmp(&s0, s, sizeof(s0)) == 0);
} }
@ -878,11 +876,9 @@ void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,
struct rtattr *tb[], FILE *fp, const char *prefix, struct rtattr *tb[], FILE *fp, const char *prefix,
const char *title) const char *title)
{ {
char buf[STRBUF_SIZE]; char buf[STRBUF_SIZE] = {};
int force_spi = xfrm_xfrmproto_is_ipsec(xsinfo->id.proto); int force_spi = xfrm_xfrmproto_is_ipsec(xsinfo->id.proto);
memset(buf, '\0', sizeof(buf));
xfrm_id_info_print(&xsinfo->saddr, &xsinfo->id, xsinfo->mode, xfrm_id_info_print(&xsinfo->saddr, &xsinfo->id, xsinfo->mode,
xsinfo->reqid, xsinfo->family, force_spi, fp, xsinfo->reqid, xsinfo->family, force_spi, fp,
prefix, title); prefix, title);
@ -959,9 +955,7 @@ void xfrm_policy_info_print(struct xfrm_userpolicy_info *xpinfo,
struct rtattr *tb[], FILE *fp, const char *prefix, struct rtattr *tb[], FILE *fp, const char *prefix,
const char *title) const char *title)
{ {
char buf[STRBUF_SIZE]; char buf[STRBUF_SIZE] = {};
memset(buf, '\0', sizeof(buf));
xfrm_selector_print(&xpinfo->sel, preferred_family, fp, title); xfrm_selector_print(&xpinfo->sel, preferred_family, fp, title);
@ -1062,11 +1056,8 @@ int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family,
{ {
int argc = *argcp; int argc = *argcp;
char **argv = *argvp; char **argv = *argvp;
inet_prefix dst; inet_prefix dst = {};
inet_prefix src; inet_prefix src = {};
memset(&dst, 0, sizeof(dst));
memset(&src, 0, sizeof(src));
while (1) { while (1) {
if (strcmp(*argv, "src") == 0) { if (strcmp(*argv, "src") == 0) {
@ -1371,13 +1362,10 @@ int xfrm_selector_parse(struct xfrm_selector *sel, int *argcp, char ***argvp)
{ {
int argc = *argcp; int argc = *argcp;
char **argv = *argvp; char **argv = *argvp;
inet_prefix dst; inet_prefix dst = {};
inet_prefix src; inet_prefix src = {};
char *upspecp = NULL; char *upspecp = NULL;
memset(&dst, 0, sizeof(dst));
memset(&src, 0, sizeof(src));
while (1) { while (1) {
if (strcmp(*argv, "src") == 0) { if (strcmp(*argv, "src") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -50,12 +50,18 @@ static void usage(void)
static int gre_parse_opt(struct link_util *lu, int argc, char **argv, static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg i; struct ifinfomsg i;
char buf[16384]; char buf[16384];
} req; } req = {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1); .n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = RTM_GETLINK,
.i.ifi_family = preferred_family,
.i.ifi_index = ifi->ifi_index,
};
struct rtattr *tb[IFLA_MAX + 1]; struct rtattr *tb[IFLA_MAX + 1];
struct rtattr *linkinfo[IFLA_INFO_MAX+1]; struct rtattr *linkinfo[IFLA_INFO_MAX+1];
struct rtattr *greinfo[IFLA_GRE_MAX + 1]; struct rtattr *greinfo[IFLA_GRE_MAX + 1];
@ -77,14 +83,6 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
__u8 metadata = 0; __u8 metadata = 0;
if (!(n->nlmsg_flags & NLM_F_CREATE)) { if (!(n->nlmsg_flags & NLM_F_CREATE)) {
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = RTM_GETLINK;
req.i.ifi_family = preferred_family;
req.i.ifi_index = ifi->ifi_index;
if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) { if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
get_failed: get_failed:
fprintf(stderr, fprintf(stderr,

View File

@ -60,12 +60,18 @@ static void usage(void)
static int gre_parse_opt(struct link_util *lu, int argc, char **argv, static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg i; struct ifinfomsg i;
char buf[1024]; char buf[1024];
} req; } req = {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1); .n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = RTM_GETLINK,
.i.ifi_family = preferred_family,
.i.ifi_index = ifi->ifi_index,
};
struct rtattr *tb[IFLA_MAX + 1]; struct rtattr *tb[IFLA_MAX + 1];
struct rtattr *linkinfo[IFLA_INFO_MAX+1]; struct rtattr *linkinfo[IFLA_INFO_MAX+1];
struct rtattr *greinfo[IFLA_GRE_MAX + 1]; struct rtattr *greinfo[IFLA_GRE_MAX + 1];
@ -83,14 +89,6 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
int len; int len;
if (!(n->nlmsg_flags & NLM_F_CREATE)) { if (!(n->nlmsg_flags & NLM_F_CREATE)) {
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = RTM_GETLINK;
req.i.ifi_family = preferred_family;
req.i.ifi_index = ifi->ifi_index;
if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) { if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
get_failed: get_failed:
fprintf(stderr, fprintf(stderr,

View File

@ -58,18 +58,24 @@ static void usage(void)
static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv, static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg i; struct ifinfomsg i;
char buf[2048]; char buf[2048];
} req; } req = {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1); .n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = RTM_GETLINK,
.i.ifi_family = preferred_family,
.i.ifi_index = ifi->ifi_index,
};
struct rtattr *tb[IFLA_MAX + 1]; struct rtattr *tb[IFLA_MAX + 1];
struct rtattr *linkinfo[IFLA_INFO_MAX+1]; struct rtattr *linkinfo[IFLA_INFO_MAX+1];
struct rtattr *iptuninfo[IFLA_IPTUN_MAX + 1]; struct rtattr *iptuninfo[IFLA_IPTUN_MAX + 1];
int len; int len;
struct in6_addr laddr; struct in6_addr laddr = {};
struct in6_addr raddr; struct in6_addr raddr = {};
__u8 hop_limit = DEFAULT_TNL_HOP_LIMIT; __u8 hop_limit = DEFAULT_TNL_HOP_LIMIT;
__u8 encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT; __u8 encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT;
__u32 flowinfo = 0; __u32 flowinfo = 0;
@ -77,18 +83,7 @@ static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,
__u32 link = 0; __u32 link = 0;
__u8 proto = 0; __u8 proto = 0;
memset(&laddr, 0, sizeof(laddr));
memset(&raddr, 0, sizeof(raddr));
if (!(n->nlmsg_flags & NLM_F_CREATE)) { if (!(n->nlmsg_flags & NLM_F_CREATE)) {
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = RTM_GETLINK;
req.i.ifi_family = preferred_family;
req.i.ifi_index = ifi->ifi_index;
if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) { if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
get_failed: get_failed:
fprintf(stderr, fprintf(stderr,

View File

@ -53,12 +53,18 @@ static void usage(int sit)
static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv, static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg i; struct ifinfomsg i;
char buf[2048]; char buf[2048];
} req; } req = {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1); .n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = RTM_GETLINK,
.i.ifi_family = preferred_family,
.i.ifi_index = ifi->ifi_index,
};
struct rtattr *tb[IFLA_MAX + 1]; struct rtattr *tb[IFLA_MAX + 1];
struct rtattr *linkinfo[IFLA_INFO_MAX+1]; struct rtattr *linkinfo[IFLA_INFO_MAX+1];
struct rtattr *iptuninfo[IFLA_IPTUN_MAX + 1]; struct rtattr *iptuninfo[IFLA_IPTUN_MAX + 1];
@ -71,7 +77,7 @@ static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv,
__u8 pmtudisc = 1; __u8 pmtudisc = 1;
__u16 iflags = 0; __u16 iflags = 0;
__u8 proto = 0; __u8 proto = 0;
struct in6_addr ip6rdprefix; struct in6_addr ip6rdprefix = {};
__u16 ip6rdprefixlen = 0; __u16 ip6rdprefixlen = 0;
__u32 ip6rdrelayprefix = 0; __u32 ip6rdrelayprefix = 0;
__u16 ip6rdrelayprefixlen = 0; __u16 ip6rdrelayprefixlen = 0;
@ -80,17 +86,7 @@ static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv,
__u16 encapsport = 0; __u16 encapsport = 0;
__u16 encapdport = 0; __u16 encapdport = 0;
memset(&ip6rdprefix, 0, sizeof(ip6rdprefix));
if (!(n->nlmsg_flags & NLM_F_CREATE)) { if (!(n->nlmsg_flags & NLM_F_CREATE)) {
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = RTM_GETLINK;
req.i.ifi_family = preferred_family;
req.i.ifi_index = ifi->ifi_index;
if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) { if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
get_failed: get_failed:
fprintf(stderr, fprintf(stderr,

View File

@ -46,12 +46,18 @@ static void usage(void)
static int vti_parse_opt(struct link_util *lu, int argc, char **argv, static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg i; struct ifinfomsg i;
char buf[1024]; char buf[1024];
} req; } req = {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1); .n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = RTM_GETLINK,
.i.ifi_family = preferred_family,
.i.ifi_index = ifi->ifi_index,
};
struct rtattr *tb[IFLA_MAX + 1]; struct rtattr *tb[IFLA_MAX + 1];
struct rtattr *linkinfo[IFLA_INFO_MAX+1]; struct rtattr *linkinfo[IFLA_INFO_MAX+1];
struct rtattr *vtiinfo[IFLA_VTI_MAX + 1]; struct rtattr *vtiinfo[IFLA_VTI_MAX + 1];
@ -63,14 +69,6 @@ static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
int len; int len;
if (!(n->nlmsg_flags & NLM_F_CREATE)) { if (!(n->nlmsg_flags & NLM_F_CREATE)) {
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = RTM_GETLINK;
req.i.ifi_family = preferred_family;
req.i.ifi_index = ifi->ifi_index;
if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) { if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
get_failed: get_failed:
fprintf(stderr, fprintf(stderr,

View File

@ -42,12 +42,18 @@ static void usage(void)
static int vti6_parse_opt(struct link_util *lu, int argc, char **argv, static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct ifinfomsg i; struct ifinfomsg i;
char buf[1024]; char buf[1024];
} req; } req = {
struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1); .n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = RTM_GETLINK,
.i.ifi_family = preferred_family,
.i.ifi_index = ifi->ifi_index,
};
struct rtattr *tb[IFLA_MAX + 1]; struct rtattr *tb[IFLA_MAX + 1];
struct rtattr *linkinfo[IFLA_INFO_MAX+1]; struct rtattr *linkinfo[IFLA_INFO_MAX+1];
struct rtattr *vtiinfo[IFLA_VTI_MAX + 1]; struct rtattr *vtiinfo[IFLA_VTI_MAX + 1];
@ -59,14 +65,6 @@ static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
int len; int len;
if (!(n->nlmsg_flags & NLM_F_CREATE)) { if (!(n->nlmsg_flags & NLM_F_CREATE)) {
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = RTM_GETLINK;
req.i.ifi_family = preferred_family;
req.i.ifi_index = ifi->ifi_index;
if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) { if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
get_failed: get_failed:
fprintf(stderr, fprintf(stderr,

View File

@ -248,34 +248,28 @@ static int xfrm_policy_modify(int cmd, unsigned int flags, int argc, char **argv
struct nlmsghdr n; struct nlmsghdr n;
struct xfrm_userpolicy_info xpinfo; struct xfrm_userpolicy_info xpinfo;
char buf[RTA_BUF_SIZE]; char buf[RTA_BUF_SIZE];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xpinfo)),
.n.nlmsg_flags = NLM_F_REQUEST | flags,
.n.nlmsg_type = cmd,
.xpinfo.sel.family = preferred_family,
.xpinfo.lft.soft_byte_limit = XFRM_INF,
.xpinfo.lft.hard_byte_limit = XFRM_INF,
.xpinfo.lft.soft_packet_limit = XFRM_INF,
.xpinfo.lft.hard_packet_limit = XFRM_INF,
};
char *dirp = NULL; char *dirp = NULL;
char *selp = NULL; char *selp = NULL;
char *ptypep = NULL; char *ptypep = NULL;
char *sctxp = NULL; char *sctxp = NULL;
struct xfrm_userpolicy_type upt; struct xfrm_userpolicy_type upt = {};
char tmpls_buf[XFRM_TMPLS_BUF_SIZE]; char tmpls_buf[XFRM_TMPLS_BUF_SIZE] = {};
int tmpls_len = 0; int tmpls_len = 0;
struct xfrm_mark mark = {0, 0}; struct xfrm_mark mark = {0, 0};
struct { struct {
struct xfrm_user_sec_ctx sctx; struct xfrm_user_sec_ctx sctx;
char str[CTX_BUF_SIZE]; char str[CTX_BUF_SIZE];
} ctx; } ctx = {};
memset(&req, 0, sizeof(req));
memset(&upt, 0, sizeof(upt));
memset(&tmpls_buf, 0, sizeof(tmpls_buf));
memset(&ctx, 0, sizeof(ctx));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xpinfo));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
req.xpinfo.sel.family = preferred_family;
req.xpinfo.lft.soft_byte_limit = XFRM_INF;
req.xpinfo.lft.hard_byte_limit = XFRM_INF;
req.xpinfo.lft.soft_packet_limit = XFRM_INF;
req.xpinfo.lft.hard_packet_limit = XFRM_INF;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "dir") == 0) { if (strcmp(*argv, "dir") == 0) {
@ -561,27 +555,23 @@ static int xfrm_policy_get_or_delete(int argc, char **argv, int delete,
struct nlmsghdr n; struct nlmsghdr n;
struct xfrm_userpolicy_id xpid; struct xfrm_userpolicy_id xpid;
char buf[RTA_BUF_SIZE]; char buf[RTA_BUF_SIZE];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xpid)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = delete ? XFRM_MSG_DELPOLICY
: XFRM_MSG_GETPOLICY,
};
char *dirp = NULL; char *dirp = NULL;
char *selp = NULL; char *selp = NULL;
char *indexp = NULL; char *indexp = NULL;
char *ptypep = NULL; char *ptypep = NULL;
char *sctxp = NULL; char *sctxp = NULL;
struct xfrm_userpolicy_type upt; struct xfrm_userpolicy_type upt = {};
struct xfrm_mark mark = {0, 0}; struct xfrm_mark mark = {0, 0};
struct { struct {
struct xfrm_user_sec_ctx sctx; struct xfrm_user_sec_ctx sctx;
char str[CTX_BUF_SIZE]; char str[CTX_BUF_SIZE];
} ctx; } ctx = {};
memset(&req, 0, sizeof(req));
memset(&upt, 0, sizeof(upt));
memset(&ctx, 0, sizeof(ctx));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xpid));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = delete ? XFRM_MSG_DELPOLICY : XFRM_MSG_GETPOLICY;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "dir") == 0) { if (strcmp(*argv, "dir") == 0) {
@ -684,11 +674,9 @@ static int xfrm_policy_delete(int argc, char **argv)
static int xfrm_policy_get(int argc, char **argv) static int xfrm_policy_get(int argc, char **argv)
{ {
char buf[NLMSG_BUF_SIZE]; char buf[NLMSG_BUF_SIZE] = {};
struct nlmsghdr *n = (struct nlmsghdr *)buf; struct nlmsghdr *n = (struct nlmsghdr *)buf;
memset(buf, 0, sizeof(buf));
xfrm_policy_get_or_delete(argc, argv, 0, n, sizeof(buf)); xfrm_policy_get_or_delete(argc, argv, 0, n, sizeof(buf));
if (xfrm_policy_print(NULL, n, (void *)stdout) < 0) { if (xfrm_policy_print(NULL, n, (void *)stdout) < 0) {
@ -1012,18 +1000,16 @@ static int xfrm_spd_setinfo(int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
__u32 flags; __u32 flags;
char buf[RTA_BUF_SIZE]; char buf[RTA_BUF_SIZE];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(__u32)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = XFRM_MSG_NEWSPDINFO,
.flags = 0XFFFFFFFF,
};
char *thr4 = NULL; char *thr4 = NULL;
char *thr6 = NULL; char *thr6 = NULL;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(__u32));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = XFRM_MSG_NEWSPDINFO;
req.flags = 0XFFFFFFFF;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "hthresh4") == 0) { if (strcmp(*argv, "hthresh4") == 0) {
struct xfrmu_spdhthresh thr; struct xfrmu_spdhthresh thr;
@ -1080,14 +1066,12 @@ static int xfrm_spd_getinfo(int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
__u32 flags; __u32 flags;
char ans[128]; char ans[128];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(__u32)),
memset(&req, 0, sizeof(req)); .n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = XFRM_MSG_GETSPDINFO,
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(__u32)); .flags = 0XFFFFFFFF,
req.n.nlmsg_flags = NLM_F_REQUEST; };
req.n.nlmsg_type = XFRM_MSG_GETSPDINFO;
req.flags = 0XFFFFFFFF;
if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
exit(1); exit(1);
@ -1108,16 +1092,13 @@ static int xfrm_policy_flush(int argc, char **argv)
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
char buf[RTA_BUF_SIZE]; char buf[RTA_BUF_SIZE];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(0), /* nlmsg data is nothing */
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = XFRM_MSG_FLUSHPOLICY,
};
char *ptypep = NULL; char *ptypep = NULL;
struct xfrm_userpolicy_type upt; struct xfrm_userpolicy_type upt = {};
memset(&req, 0, sizeof(req));
memset(&upt, 0, sizeof(upt));
req.n.nlmsg_len = NLMSG_LENGTH(0); /* nlmsg data is nothing */
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = XFRM_MSG_FLUSHPOLICY;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "ptype") == 0) { if (strcmp(*argv, "ptype") == 0) {

View File

@ -271,9 +271,18 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct xfrm_usersa_info xsinfo; struct xfrm_usersa_info xsinfo;
char buf[RTA_BUF_SIZE]; char buf[RTA_BUF_SIZE];
} req; } req = {
struct xfrm_replay_state replay; .n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xsinfo)),
struct xfrm_replay_state_esn replay_esn; .n.nlmsg_flags = NLM_F_REQUEST | flags,
.n.nlmsg_type = cmd,
.xsinfo.family = preferred_family,
.xsinfo.lft.soft_byte_limit = XFRM_INF,
.xsinfo.lft.hard_byte_limit = XFRM_INF,
.xsinfo.lft.soft_packet_limit = XFRM_INF,
.xsinfo.lft.hard_packet_limit = XFRM_INF,
};
struct xfrm_replay_state replay = {};
struct xfrm_replay_state_esn replay_esn = {};
__u32 replay_window = 0; __u32 replay_window = 0;
__u32 seq = 0, oseq = 0, seq_hi = 0, oseq_hi = 0; __u32 seq = 0, oseq = 0, seq_hi = 0, oseq_hi = 0;
char *idp = NULL; char *idp = NULL;
@ -288,22 +297,7 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
struct { struct {
struct xfrm_user_sec_ctx sctx; struct xfrm_user_sec_ctx sctx;
char str[CTX_BUF_SIZE]; char str[CTX_BUF_SIZE];
} ctx; } ctx = {};
memset(&req, 0, sizeof(req));
memset(&replay, 0, sizeof(replay));
memset(&replay_esn, 0, sizeof(replay_esn));
memset(&ctx, 0, sizeof(ctx));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xsinfo));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
req.xsinfo.family = preferred_family;
req.xsinfo.lft.soft_byte_limit = XFRM_INF;
req.xsinfo.lft.hard_byte_limit = XFRM_INF;
req.xsinfo.lft.soft_packet_limit = XFRM_INF;
req.xsinfo.lft.hard_packet_limit = XFRM_INF;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "mode") == 0) { if (strcmp(*argv, "mode") == 0) {
@ -369,7 +363,7 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
(void *)&encap, sizeof(encap)); (void *)&encap, sizeof(encap));
} else if (strcmp(*argv, "coa") == 0) { } else if (strcmp(*argv, "coa") == 0) {
inet_prefix coa; inet_prefix coa;
xfrm_address_t xcoa; xfrm_address_t xcoa = {};
if (coap) if (coap)
duparg("coa", *argv); duparg("coa", *argv);
@ -383,7 +377,6 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
if (coa.bytelen > sizeof(xcoa)) if (coa.bytelen > sizeof(xcoa))
invarg("value after \"coa\" is too large", *argv); invarg("value after \"coa\" is too large", *argv);
memset(&xcoa, 0, sizeof(xcoa));
memcpy(&xcoa, &coa.data, coa.bytelen); memcpy(&xcoa, &coa.data, coa.bytelen);
addattr_l(&req.n, sizeof(req.buf), XFRMA_COADDR, addattr_l(&req.n, sizeof(req.buf), XFRMA_COADDR,
@ -699,30 +692,25 @@ static int xfrm_state_allocspi(int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct xfrm_userspi_info xspi; struct xfrm_userspi_info xspi;
char buf[RTA_BUF_SIZE]; char buf[RTA_BUF_SIZE];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xspi)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = XFRM_MSG_ALLOCSPI,
.xspi.info.family = preferred_family,
#if 0
.xspi.lft.soft_byte_limit = XFRM_INF,
.xspi.lft.hard_byte_limit = XFRM_INF,
.xspi.lft.soft_packet_limit = XFRM_INF,
.xspi.lft.hard_packet_limit = XFRM_INF,
#endif
};
char *idp = NULL; char *idp = NULL;
char *minp = NULL; char *minp = NULL;
char *maxp = NULL; char *maxp = NULL;
struct xfrm_mark mark = {0, 0}; struct xfrm_mark mark = {0, 0};
char res_buf[NLMSG_BUF_SIZE]; char res_buf[NLMSG_BUF_SIZE] = {};
struct nlmsghdr *res_n = (struct nlmsghdr *)res_buf; struct nlmsghdr *res_n = (struct nlmsghdr *)res_buf;
memset(res_buf, 0, sizeof(res_buf));
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xspi));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = XFRM_MSG_ALLOCSPI;
req.xspi.info.family = preferred_family;
#if 0
req.xsinfo.lft.soft_byte_limit = XFRM_INF;
req.xsinfo.lft.hard_byte_limit = XFRM_INF;
req.xsinfo.lft.soft_packet_limit = XFRM_INF;
req.xsinfo.lft.hard_packet_limit = XFRM_INF;
#endif
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "mode") == 0) { if (strcmp(*argv, "mode") == 0) {
NEXT_ARG(); NEXT_ARG();
@ -956,18 +944,16 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete)
struct nlmsghdr n; struct nlmsghdr n;
struct xfrm_usersa_id xsid; struct xfrm_usersa_id xsid;
char buf[RTA_BUF_SIZE]; char buf[RTA_BUF_SIZE];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xsid)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = delete ? XFRM_MSG_DELSA : XFRM_MSG_GETSA,
.xsid.family = preferred_family,
};
struct xfrm_id id; struct xfrm_id id;
char *idp = NULL; char *idp = NULL;
struct xfrm_mark mark = {0, 0}; struct xfrm_mark mark = {0, 0};
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xsid));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = delete ? XFRM_MSG_DELSA : XFRM_MSG_GETSA;
req.xsid.family = preferred_family;
while (argc > 0) { while (argc > 0) {
xfrm_address_t saddr; xfrm_address_t saddr;
@ -1014,11 +1000,9 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete)
if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
exit(2); exit(2);
} else { } else {
char buf[NLMSG_BUF_SIZE]; char buf[NLMSG_BUF_SIZE] = {};
struct nlmsghdr *res_n = (struct nlmsghdr *)buf; struct nlmsghdr *res_n = (struct nlmsghdr *)buf;
memset(buf, 0, sizeof(buf));
if (rtnl_talk(&rth, &req.n, res_n, sizeof(req)) < 0) if (rtnl_talk(&rth, &req.n, res_n, sizeof(req)) < 0)
exit(2); exit(2);
@ -1282,13 +1266,12 @@ static int xfrm_sad_getinfo(int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
__u32 flags; __u32 flags;
char ans[64]; char ans[64];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.flags)),
memset(&req, 0, sizeof(req)); .n.nlmsg_flags = NLM_F_REQUEST,
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.flags)); .n.nlmsg_type = XFRM_MSG_GETSADINFO,
req.n.nlmsg_flags = NLM_F_REQUEST; .flags = 0XFFFFFFFF,
req.n.nlmsg_type = XFRM_MSG_GETSADINFO; };
req.flags = 0XFFFFFFFF;
if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
exit(1); exit(1);
@ -1309,16 +1292,13 @@ static int xfrm_state_flush(int argc, char **argv)
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct xfrm_usersa_flush xsf; struct xfrm_usersa_flush xsf;
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xsf)),
.n.nlmsg_flags = NLM_F_REQUEST,
.n.nlmsg_type = XFRM_MSG_FLUSHSA,
};
char *protop = NULL; char *protop = NULL;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.xsf));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = XFRM_MSG_FLUSHSA;
req.xsf.proto = 0;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "proto") == 0) { if (strcmp(*argv, "proto") == 0) {
int ret; int ret;

View File

@ -33,7 +33,7 @@ struct json_writer {
static void jsonw_indent(json_writer_t *self) static void jsonw_indent(json_writer_t *self)
{ {
unsigned i; unsigned i;
for (i = 0; i <= self->depth; ++i) for (i = 0; i < self->depth; ++i)
fputs(" ", self->out); fputs(" ", self->out);
} }
@ -102,7 +102,6 @@ json_writer_t *jsonw_new(FILE *f)
self->depth = 0; self->depth = 0;
self->pretty = false; self->pretty = false;
self->sep = '\0'; self->sep = '\0';
putc('{', self->out);
} }
return self; return self;
} }
@ -113,8 +112,7 @@ void jsonw_destroy(json_writer_t **self_p)
json_writer_t *self = *self_p; json_writer_t *self = *self_p;
assert(self->depth == 0); assert(self->depth == 0);
jsonw_eol(self); fputs("\n", self->out);
fputs("}\n", self->out);
fflush(self->out); fflush(self->out);
free(self); free(self);
*self_p = NULL; *self_p = NULL;
@ -269,6 +267,7 @@ int main(int argc, char **argv)
{ {
json_writer_t *wr = jsonw_new(stdout); json_writer_t *wr = jsonw_new(stdout);
jsonw_start_object(wr);
jsonw_pretty(wr, true); jsonw_pretty(wr, true);
jsonw_name(wr, "Vyatta"); jsonw_name(wr, "Vyatta");
jsonw_start_object(wr); jsonw_start_object(wr);
@ -305,6 +304,7 @@ int main(int argc, char **argv)
jsonw_end_object(wr); jsonw_end_object(wr);
jsonw_end_object(wr);
jsonw_destroy(&wr); jsonw_destroy(&wr);
return 0; return 0;
} }

View File

@ -112,19 +112,16 @@ int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int family, int type,
/* attribute has to be NLMSG aligned */ /* attribute has to be NLMSG aligned */
struct rtattr ext_req __attribute__ ((aligned(NLMSG_ALIGNTO))); struct rtattr ext_req __attribute__ ((aligned(NLMSG_ALIGNTO)));
__u32 ext_filter_mask; __u32 ext_filter_mask;
} req; } req = {
.nlh.nlmsg_len = sizeof(req),
memset(&req, 0, sizeof(req)); .nlh.nlmsg_type = type,
req.nlh.nlmsg_len = sizeof(req); .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
req.nlh.nlmsg_type = type; .nlh.nlmsg_seq = rth->dump = ++rth->seq,
req.nlh.nlmsg_flags = NLM_F_DUMP|NLM_F_REQUEST; .ifm.ifi_family = family,
req.nlh.nlmsg_pid = 0; .ext_req.rta_type = IFLA_EXT_MASK,
req.nlh.nlmsg_seq = rth->dump = ++rth->seq; .ext_req.rta_len = RTA_LENGTH(sizeof(__u32)),
req.ifm.ifi_family = family; .ext_filter_mask = filt_mask,
};
req.ext_req.rta_type = IFLA_EXT_MASK;
req.ext_req.rta_len = RTA_LENGTH(sizeof(__u32));
req.ext_filter_mask = filt_mask;
return send(rth->fd, (void*)&req, sizeof(req), 0); return send(rth->fd, (void*)&req, sizeof(req), 0);
} }
@ -136,20 +133,18 @@ int rtnl_wilddump_req_filter_fn(struct rtnl_handle *rth, int family, int type,
struct nlmsghdr nlh; struct nlmsghdr nlh;
struct ifinfomsg ifm; struct ifinfomsg ifm;
char buf[1024]; char buf[1024];
} req; } req = {
.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
.nlh.nlmsg_type = type,
.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
.nlh.nlmsg_seq = rth->dump = ++rth->seq,
.ifm.ifi_family = family,
};
int err; int err;
if (!filter_fn) if (!filter_fn)
return -EINVAL; return -EINVAL;
memset(&req, 0, sizeof(req));
req.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
req.nlh.nlmsg_type = type;
req.nlh.nlmsg_flags = NLM_F_DUMP|NLM_F_REQUEST;
req.nlh.nlmsg_pid = 0;
req.nlh.nlmsg_seq = rth->dump = ++rth->seq;
req.ifm.ifi_family = family;
err = filter_fn(&req.nlh, sizeof(req)); err = filter_fn(&req.nlh, sizeof(req));
if (err) if (err)
return err; return err;
@ -197,7 +192,12 @@ int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int len)
int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
{ {
struct nlmsghdr nlh; struct nlmsghdr nlh = {
.nlmsg_len = NLMSG_LENGTH(len),
.nlmsg_type = type,
.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
.nlmsg_seq = rth->dump = ++rth->seq,
};
struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK }; struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
struct iovec iov[2] = { struct iovec iov[2] = {
{ .iov_base = &nlh, .iov_len = sizeof(nlh) }, { .iov_base = &nlh, .iov_len = sizeof(nlh) },
@ -205,17 +205,11 @@ int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
}; };
struct msghdr msg = { struct msghdr msg = {
.msg_name = &nladdr, .msg_name = &nladdr,
.msg_namelen = sizeof(nladdr), .msg_namelen = sizeof(nladdr),
.msg_iov = iov, .msg_iov = iov,
.msg_iovlen = 2, .msg_iovlen = 2,
}; };
nlh.nlmsg_len = NLMSG_LENGTH(len);
nlh.nlmsg_type = type;
nlh.nlmsg_flags = NLM_F_DUMP|NLM_F_REQUEST;
nlh.nlmsg_pid = 0;
nlh.nlmsg_seq = rth->dump = ++rth->seq;
return sendmsg(rth->fd, &msg, 0); return sendmsg(rth->fd, &msg, 0);
} }
@ -365,7 +359,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
int status; int status;
unsigned seq; unsigned seq;
struct nlmsghdr *h; struct nlmsghdr *h;
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
struct iovec iov = { struct iovec iov = {
.iov_base = (void*) n, .iov_base = (void*) n,
.iov_len = n->nlmsg_len .iov_len = n->nlmsg_len
@ -376,10 +370,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
.msg_iov = &iov, .msg_iov = &iov,
.msg_iovlen = 1, .msg_iovlen = 1,
}; };
char buf[32768]; char buf[32768] = {};
memset(&nladdr, 0, sizeof(nladdr));
nladdr.nl_family = AF_NETLINK;
n->nlmsg_seq = seq = ++rtnl->seq; n->nlmsg_seq = seq = ++rtnl->seq;
@ -392,8 +383,6 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
return -1; return -1;
} }
memset(buf,0,sizeof(buf));
iov.iov_base = buf; iov.iov_base = buf;
while (1) { while (1) {
iov.iov_len = sizeof(buf); iov.iov_len = sizeof(buf);
@ -498,7 +487,7 @@ int rtnl_listen(struct rtnl_handle *rtnl,
{ {
int status; int status;
struct nlmsghdr *h; struct nlmsghdr *h;
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
struct iovec iov; struct iovec iov;
struct msghdr msg = { struct msghdr msg = {
.msg_name = &nladdr, .msg_name = &nladdr,
@ -514,11 +503,6 @@ int rtnl_listen(struct rtnl_handle *rtnl,
msg.msg_controllen = sizeof(cmsgbuf); msg.msg_controllen = sizeof(cmsgbuf);
} }
memset(&nladdr, 0, sizeof(nladdr));
nladdr.nl_family = AF_NETLINK;
nladdr.nl_pid = 0;
nladdr.nl_groups = 0;
iov.iov_base = buf; iov.iov_base = buf;
while (1) { while (1) {
struct rtnl_ctrl_data ctrl; struct rtnl_ctrl_data ctrl;
@ -595,15 +579,10 @@ int rtnl_from_file(FILE *rtnl, rtnl_listen_filter_t handler,
void *jarg) void *jarg)
{ {
int status; int status;
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
char buf[16384]; char buf[16384];
struct nlmsghdr *h = (void*)buf; struct nlmsghdr *h = (void*)buf;
memset(&nladdr, 0, sizeof(nladdr));
nladdr.nl_family = AF_NETLINK;
nladdr.nl_pid = 0;
nladdr.nl_groups = 0;
while (1) { while (1) {
int err, len; int err, len;
int l; int l;

View File

@ -103,7 +103,6 @@ int ll_remember_index(const struct sockaddr_nl *who,
return 0; return 0;
} }
memset(tb, 0, sizeof(tb));
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), IFLA_PAYLOAD(n)); parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), IFLA_PAYLOAD(n));
ifname = rta_getattr_str(tb[IFLA_IFNAME]); ifname = rta_getattr_str(tb[IFLA_IFNAME]);
if (ifname == NULL) if (ifname == NULL)

View File

@ -54,15 +54,12 @@ struct db_names *db_names_alloc(void)
{ {
struct db_names *db; struct db_names *db;
db = malloc(sizeof(*db)); db = calloc(1, sizeof(*db));
if (!db) if (!db)
return NULL; return NULL;
memset(db, 0, sizeof(*db));
db->size = MAX_ENTRIES; db->size = MAX_ENTRIES;
db->hash = malloc(sizeof(struct db_entry *) * db->size); db->hash = calloc(db->size, sizeof(struct db_entry *));
memset(db->hash, 0, sizeof(struct db_entry *) * db->size);
return db; return db;
} }

View File

@ -20,8 +20,9 @@ bridge \- show / manipulate bridge addresses and devices
.IR OPTIONS " := { " .IR OPTIONS " := { "
\fB\-V\fR[\fIersion\fR] | \fB\-V\fR[\fIersion\fR] |
\fB\-s\fR[\fItatistics\fR] | \fB\-s\fR[\fItatistics\fR] |
\fB\-n\fR[\fIetns\fR] name } \fB\-n\fR[\fIetns\fR] name |
\fB\-b\fR[\fIatch\fR] filename } \fB\-b\fR[\fIatch\fR] filename |
\fB\-j\fR[\fIson\fR] }
.ti -8 .ti -8
.BR "bridge link set" .BR "bridge link set"
@ -153,6 +154,10 @@ Don't terminate bridge command on errors in batch mode.
If there were any errors during execution of the commands, the application If there were any errors during execution of the commands, the application
return code will be non zero. return code will be non zero.
.TP
.BR "\-json"
Display results in JSON format. Currently available for vlan and fdb.
.SH BRIDGE - COMMAND SYNTAX .SH BRIDGE - COMMAND SYNTAX
.SS .SS

View File

@ -77,14 +77,15 @@ ip-address \- protocol address management
.IR FLAG " := " .IR FLAG " := "
.RB "[ " permanent " | " dynamic " | " secondary " | " primary " |" .RB "[ " permanent " | " dynamic " | " secondary " | " primary " |"
.RB [ - ] tentative " | [" - ] deprecated " | [" - ] dadfailed " |" .RB [ - ] tentative " | [" - ] deprecated " | [" - ] dadfailed " |"
.BR temporary " | " CONFFLAG-LIST " ]" .BR temporary " |"
.IR CONFFLAG-LIST " ]"
.ti -8 .ti -8
.IR CONFFLAG-LIST " := [ " CONFFLAG-LIST " ] " CONFFLAG .IR CONFFLAG-LIST " := [ " CONFFLAG-LIST " ] " CONFFLAG
.ti -8 .ti -8
.IR CONFFLAG " := " .IR CONFFLAG " := "
.RB "[ " home " | " mngtmpaddr " | " nodad " | " noprefixroute " ]" .RB "[ " home " | " mngtmpaddr " | " nodad " | " noprefixroute " | " autojoin " ]"
.ti -8 .ti -8
.IR LIFETIME " := [ " .IR LIFETIME " := [ "
@ -249,6 +250,26 @@ address, and don't search for one to delete when removing the address. Changing
an address to add this flag will remove the automatically added prefix route, an address to add this flag will remove the automatically added prefix route,
changing it to remove this flag will create the prefix route automatically. changing it to remove this flag will create the prefix route automatically.
.TP
.B autojoin
Joining multicast groups on Ethernet level via
.B "ip maddr"
command does not work if connected to an Ethernet switch that does IGMP
snooping since the switch would not replicate multicast packets on ports that
did not have IGMP reports for the multicast addresses.
Linux VXLAN interfaces created via
.B "ip link add vxlan"
have the
.B group
option that enables them to do the required join.
Using the
.B autojoin
flag when adding a multicast address enables similar functionality for
Openvswitch VXLAN interfaces as well as other tunneling mechanisms that need to
receive multicast traffic.
.SS ip address delete - delete protocol address .SS ip address delete - delete protocol address
.B Arguments: .B Arguments:
coincide with the arguments of coincide with the arguments of

View File

@ -39,35 +39,6 @@ ip-link \- network device configuration
.BI type " TYPE" .BI type " TYPE"
.RI "[ " ARGS " ]" .RI "[ " ARGS " ]"
.ti -8
.IR TYPE " := [ "
.BR bridge " | "
.BR bond " | "
.BR can " | "
.BR dummy " | "
.BR hsr " | "
.BR ifb " | "
.BR ipoib " |"
.BR macvlan " | "
.BR macvtap " | "
.BR vcan " | "
.BR veth " | "
.BR vlan " | "
.BR vxlan " |"
.BR ip6tnl " |"
.BR ipip " |"
.BR sit " |"
.BR gre " |"
.BR gretap " |"
.BR ip6gre " |"
.BR ip6gretap " |"
.BR vti " |"
.BR nlmon " |"
.BR ipvlan " |"
.BR lowpan " |"
.BR geneve " |"
.BR vrf " ]"
.ti -8 .ti -8
.BR "ip link delete " { .BR "ip link delete " {
.IR DEVICE " | " .IR DEVICE " | "
@ -80,7 +51,12 @@ ip-link \- network device configuration
.BR "ip link set " { .BR "ip link set " {
.IR DEVICE " | " .IR DEVICE " | "
.BI "group " GROUP .BI "group " GROUP
.RB "} [ { " up " | " down " } ]" }
.br
.RB "[ { " up " | " down " } ]"
.br
.RB "[ " type
.IR "ETYPE TYPE_ARGS" " ]"
.br .br
.RB "[ " arp " { " on " | " off " } ]" .RB "[ " arp " { " on " | " off " } ]"
.br .br
@ -173,7 +149,7 @@ ip-link \- network device configuration
.B master .B master
.IR DEVICE " ] [" .IR DEVICE " ] ["
.B type .B type
.IR TYPE " ]" .IR ETYPE " ]"
.B vrf .B vrf
.IR NAME " ]" .IR NAME " ]"
@ -181,6 +157,39 @@ ip-link \- network device configuration
.B ip link help .B ip link help
.RI "[ " TYPE " ]" .RI "[ " TYPE " ]"
.ti -8
.IR TYPE " := [ "
.BR bridge " | "
.BR bond " | "
.BR can " | "
.BR dummy " | "
.BR hsr " | "
.BR ifb " | "
.BR ipoib " |"
.BR macvlan " | "
.BR macvtap " | "
.BR vcan " | "
.BR veth " | "
.BR vlan " | "
.BR vxlan " |"
.BR ip6tnl " |"
.BR ipip " |"
.BR sit " |"
.BR gre " |"
.BR gretap " |"
.BR ip6gre " |"
.BR ip6gretap " |"
.BR vti " |"
.BR nlmon " |"
.BR ipvlan " |"
.BR lowpan " |"
.BR geneve " |"
.BR vrf " ]"
.ti -8
.IR ETYPE " := [ " TYPE " |"
.BR bridge_slave " | " bond_slave " ]"
.SH "DESCRIPTION" .SH "DESCRIPTION"
.SS ip link add - add virtual link .SS ip link add - add virtual link
@ -299,7 +308,7 @@ the following additional arguments are supported:
.BI "ip link add .BI "ip link add
.BI link " DEVICE " .BI link " DEVICE "
.BI name " NAME " .BI name " NAME "
.BI type " vlan " .B "type vlan"
[ [
.BI protocol " VLAN_PROTO " .BI protocol " VLAN_PROTO "
] ]
@ -401,7 +410,7 @@ For a link of type
the following additional arguments are supported: the following additional arguments are supported:
.BI "ip link add " DEVICE .BI "ip link add " DEVICE
.BI type " vxlan " id " ID" .BI type " vxlan " id " VNI"
[ [
.BI dev " PHYS_DEV " .BI dev " PHYS_DEV "
.RB " ] [ { " group " | " remote " } " .RB " ] [ { " group " | " remote " } "
@ -420,27 +429,27 @@ the following additional arguments are supported:
] [ ] [
.BI srcport " MIN MAX " .BI srcport " MIN MAX "
] [ ] [
.I "[no]learning " .RB [ no ] learning
] [ ] [
.I "[no]proxy " .RB [ no ] proxy
] [ ] [
.I "[no]rsc " .RB [ no ] rsc
] [ ] [
.I "[no]l2miss " .RB [ no ] l2miss
] [ ] [
.I "[no]l3miss " .RB [ no ] l3miss
] [ ] [
.I "[no]udpcsum " .RB [ no ] udpcsum
] [ ] [
.I "[no]udp6zerocsumtx " .RB [ no ] udp6zerocsumtx
] [ ] [
.I "[no]udp6zerocsumrx " .RB [ no ] udp6zerocsumrx
] [ ] [
.BI ageing " SECONDS " .BI ageing " SECONDS "
] [ ] [
.BI maxaddress " NUMBER " .BI maxaddress " NUMBER "
] [ ] [
.RI "[no]external " .RB [ no ] external
] [ ] [
.B gbp .B gbp
] [ ] [
@ -497,36 +506,36 @@ parameter.
source ports to communicate to the remote VXLAN tunnel endpoint. source ports to communicate to the remote VXLAN tunnel endpoint.
.sp .sp
.I [no]learning .RB [ no ] learning
- specifies if unknown source link layer addresses and IP addresses - specifies if unknown source link layer addresses and IP addresses
are entered into the VXLAN device forwarding database. are entered into the VXLAN device forwarding database.
.sp .sp
.I [no]rsc .RB [ no ] rsc
- specifies if route short circuit is turned on. - specifies if route short circuit is turned on.
.sp .sp
.I [no]proxy .RB [ no ] proxy
- specifies ARP proxy is turned on. - specifies ARP proxy is turned on.
.sp .sp
.I [no]l2miss .RB [ no ] l2miss
- specifies if netlink LLADDR miss notifications are generated. - specifies if netlink LLADDR miss notifications are generated.
.sp .sp
.I [no]l3miss .RB [ no ] l3miss
- specifies if netlink IP ADDR miss notifications are generated. - specifies if netlink IP ADDR miss notifications are generated.
.sp .sp
.I [no]udpcsum .RB [ no ] udpcsum
- specifies if UDP checksum is calculated for transmitted packets over IPv4. - specifies if UDP checksum is calculated for transmitted packets over IPv4.
.sp .sp
.I [no]udp6zerocsumtx .RB [ no ] udp6zerocsumtx
- skip UDP checksum calculation for transmitted packets over IPv6. - skip UDP checksum calculation for transmitted packets over IPv6.
.sp .sp
.I [no]udp6zerocsumrx .RB [ no ] udp6zerocsumrx
- allow incoming UDP packets over IPv6 with zero checksum field. - allow incoming UDP packets over IPv6 with zero checksum field.
.sp .sp
@ -538,7 +547,7 @@ are entered into the VXLAN device forwarding database.
- specifies the maximum number of FDB entries. - specifies the maximum number of FDB entries.
.sp .sp
.I [no]external .RB [ no ] external
- specifies whether an external control plane - specifies whether an external control plane
.RB "(e.g. " "ip route encap" ) .RB "(e.g. " "ip route encap" )
or the internal FDB should be used. or the internal FDB should be used.
@ -602,18 +611,18 @@ For a link of types
the following additional arguments are supported: the following additional arguments are supported:
.BI "ip link add " DEVICE .BI "ip link add " DEVICE
.BR type " { gre | ipip | sit } " .BR type " { " gre " | " ipip " | " sit " }"
.BI " remote " ADDR " local " ADDR .BI " remote " ADDR " local " ADDR
[ [
.BR encap " { fou | gue | none } " .BR encap " { " fou " | " gue " | " none " }"
] [ ] [
.BI "encap-sport { " PORT " | auto } " .BR encap-sport " { " \fIPORT " | " auto " }"
] [ ] [
.BI "encap-dport " PORT .BI "encap-dport " PORT
] [ ] [
.I " [no]encap-csum " .RB [ no ] encap-csum
] [ ] [
.I " [no]encap-remcsum " .RB [ no ] encap-remcsum
] ]
.in +8 .in +8
@ -627,12 +636,12 @@ the following additional arguments are supported:
It must be an address on another interface on this host. It must be an address on another interface on this host.
.sp .sp
.BR encap " { fou | gue | none } " .BR encap " { " fou " | " gue " | " none " }"
- specifies type of secondary UDP encapsulation. "fou" indicates - specifies type of secondary UDP encapsulation. "fou" indicates
Foo-Over-UDP, "gue" indicates Generic UDP Encapsulation. Foo-Over-UDP, "gue" indicates Generic UDP Encapsulation.
.sp .sp
.BI "encap-sport { " PORT " | auto } " .BR encap-sport " { " \fIPORT " | " auto " }"
- specifies the source port in UDP encapsulation. - specifies the source port in UDP encapsulation.
.IR PORT .IR PORT
indicates the port by number, "auto" indicates the port by number, "auto"
@ -641,12 +650,12 @@ indicates that the port number should be chosen automatically
encapsulated packet). encapsulated packet).
.sp .sp
.I [no]encap-csum .RB [ no ] encap-csum
- specifies if UDP checksums are enabled in the secondary - specifies if UDP checksums are enabled in the secondary
encapsulation. encapsulation.
.sp .sp
.I [no]encap-remcsum .RB [ no ] encap-remcsum
- specifies if Remote Checksum Offload is enabled. This is only - specifies if Remote Checksum Offload is enabled. This is only
applicable for Generic UDP Encapsulation. applicable for Generic UDP Encapsulation.
@ -659,13 +668,15 @@ For a link of type
the following additional arguments are supported: the following additional arguments are supported:
.BI "ip link add " DEVICE .BI "ip link add " DEVICE
.BI type " { ip6gre | ip6gretap } " remote " ADDR " local " ADDR .BR type " { " ip6gre " | " ip6gretap " }"
.BI remote " ADDR " local " ADDR"
[ [
.I "[i|o]seq]" .RB [ i | o ] seq
] [ ] [
.I "[i|o]key" KEY .RB [ i | o ] key
.I KEY
] [ ] [
.I " [i|o]csum " .RB [ i | o ] csum
] [ ] [
.BI hoplimit " TTL " .BI hoplimit " TTL "
] [ ] [
@ -691,7 +702,7 @@ the following additional arguments are supported:
It must be an address on another interface on this host. It must be an address on another interface on this host.
.sp .sp
.BI [i|o]seq .RB [ i | o ] seq
- serialize packets. - serialize packets.
The The
.B oseq .B oseq
@ -701,7 +712,7 @@ The
flag requires that all input packets are serialized. flag requires that all input packets are serialized.
.sp .sp
.BI [i|o]key " KEY" .RB [ i | o ] key " \fIKEY"
- use keyed GRE with key - use keyed GRE with key
.IR KEY ". "KEY .IR KEY ". "KEY
is either a number or an IPv4 address-like dotted quad. is either a number or an IPv4 address-like dotted quad.
@ -713,7 +724,7 @@ The
parameters specify different keys for input and output. parameters specify different keys for input and output.
.sp .sp
.BI [i|o]csum .RB [ i | o ] csum
- generate/require checksums for tunneled packets. - generate/require checksums for tunneled packets.
The The
.B ocsum .B ocsum
@ -765,7 +776,7 @@ For a link of type
the following additional arguments are supported: the following additional arguments are supported:
.BI "ip link add " DEVICE " name " NAME .BI "ip link add " DEVICE " name " NAME
.BI type " ipoib [ " pkey " PKEY ] [" mode " MODE " ] .BR "type ipoib " [ " pkey \fIPKEY" " ] [ " mode " \fIMODE \fR]"
.in +8 .in +8
.sp .sp
@ -782,7 +793,7 @@ For a link of type
the following additional arguments are supported: the following additional arguments are supported:
.BI "ip link add " DEVICE .BI "ip link add " DEVICE
.BI type " geneve " id " ID " remote " IPADDR" .BI type " geneve " id " VNI " remote " IPADDR"
[ [
.BI ttl " TTL " .BI ttl " TTL "
] [ ] [
@ -825,7 +836,7 @@ the following additional arguments are supported:
.BI "ip link add link " DEVICE " name " NAME .BI "ip link add link " DEVICE " name " NAME
.BR type " { " macvlan " | " macvtap " } " .BR type " { " macvlan " | " macvtap " } "
.BR mode " { " private " | " vepa " | " bridge " | " passthru .BR mode " { " private " | " vepa " | " bridge " | " passthru
.BR " [ " nopromisc " ] } " .RB " [ " nopromisc " ] } "
.in +8 .in +8
.sp .sp
@ -870,11 +881,11 @@ For a link of type
.I HSR .I HSR
the following additional arguments are supported: the following additional arguments are supported:
.BI "ip link add link " DEVICE " name " NAME .BI "ip link add link " DEVICE " name " NAME " type hsr"
.BI type " hsr "
.BI slave1 " SLAVE1-IF " slave2 " SLAVE2-IF " .BI slave1 " SLAVE1-IF " slave2 " SLAVE2-IF "
.BR " [ supervision " ADDR-BYTE " ] " .RB [ " supervision"
.BR " [ version { " 0 " | " 1 " } ] " .IR ADDR-BYTE " ] ["
.BR version " { " 0 " | " 1 " } ]"
.in +8 .in +8
.sp .sp
@ -887,11 +898,11 @@ the following additional arguments are supported:
.BI slave2 " SLAVE2-IF " .BI slave2 " SLAVE2-IF "
- Specifies the physical device used for the second of the two ring ports. - Specifies the physical device used for the second of the two ring ports.
.BR "supervision ADDR-BYTE " .BI supervision " ADDR-BYTE"
- The last byte of the multicast address used for HSR supervision frames. - The last byte of the multicast address used for HSR supervision frames.
Default option is "0", possible values 0-255. Default option is "0", possible values 0-255.
.BR "version { 0 | 1 }" .BR version " { " 0 " | " 1 " }"
- Selects the protocol version of the interface. Default option is "0", which - Selects the protocol version of the interface. Default option is "0", which
corresponds to the 2010 version of the HSR standard. Option "1" activates the corresponds to the 2010 version of the HSR standard. Option "1" activates the
2012 version. 2012 version.
@ -1010,6 +1021,18 @@ specifies the type of the device.
.SS ip link set - change device attributes .SS ip link set - change device attributes
.PP
.B Warning:
If multiple parameter changes are requested,
.B ip
aborts immediately after any of the changes have failed.
This is the only case when
.B ip
can move the system to an unpredictable state. The solution
is to avoid changing several parameters with one
.B ip link set
call.
.TP .TP
.BI dev " DEVICE " .BI dev " DEVICE "
.I DEVICE .I DEVICE
@ -1236,17 +1259,134 @@ set the IPv6 address generation mode
.BR "link-netnsid " .BR "link-netnsid "
set peer netnsid for a cross-netns interface set peer netnsid for a cross-netns interface
.PP .TP
.B Warning: .BI type " ETYPE TYPE_ARGS"
If multiple parameter changes are requested, Change type-specific settings. For a list of supported types and arguments refer
.B ip to the description of
aborts immediately after any of the changes have failed. .B "ip link add"
This is the only case when above. In addition to that, it is possible to manipulate settings to slave
.B ip devices:
can move the system to an unpredictable state. The solution
is to avoid changing several parameters with one .TP
.B ip link set Bridge Slave Support
call. For a link with master
.B bridge
the following additional arguments are supported:
.B "ip link set type bridge_slave"
[
.BI state " STATE"
] [
.BI priority " PRIO"
] [
.BI cost " COST"
] [
.BR guard " { " on " | " off " }"
] [
.BR hairpin " { " on " | " off " }"
] [
.BR fastleave " { " on " | " off " }"
] [
.BR root_block " { " on " | " off " }"
] [
.BR learning " { " on " | " off " }"
] [
.BR flood " { " on " | " off " }"
] [
.BR proxy_arp " { " on " | " off " }"
] [
.BR proxy_arp_wifi " { " on " | " off " }"
] [
.BI mcast_router " MULTICAST_ROUTER"
] [
.BR mcast_fast_leave " { " on " | " off "} ]"
.in +8
.sp
.BI state " STATE"
- Set port state.
.I STATE
is a number representing the following states:
.BR 0 " (disabled),"
.BR 1 " (listening),"
.BR 2 " (learning),"
.BR 3 " (forwarding),"
.BR 4 " (blocking)."
.BI priority " PRIO"
- set port priority (a 16bit unsigned value).
.BI cost " COST"
- set port cost (a 32bit unsigned value).
.BR guard " { " on " | " off " }"
- block incoming BPDU packets on this port.
.BR hairpin " { " on " | " off " }"
- enable hairpin mode on this port. This will allow incoming packets on this
port to be reflected back.
.BR fastleave " { " on " | " off " }"
- enable multicast fast leave on this port.
.BR root_block " { " on " | " off " }"
- block this port from becoming the bridge's root port.
.BR learning " { " on " | " off " }"
- allow MAC address learning on this port.
.BR flood " { " on " | " off " }"
- open the flood gates on this port, i.e. forward all unicast frames to this
port also. Requires
.BR proxy_arp " and " proxy_arp_wifi
to be turned off.
.BR proxy_arp " { " on " | " off " }"
- enable proxy ARP on this port.
.BR proxy_arp_wifi " { " on " | " off " }"
- enable proxy ARP on this port which meets extended requirements by IEEE
802.11 and Hotspot 2.0 specifications.
.BI mcast_router " MULTICAST_ROUTER"
- configure this port for having multicast routers attached. A port with a
multicast router will receive all multicast traffic.
.I MULTICAST_ROUTER
may be either
.B 0
to disable multicast routers on this port,
.B 1
to let the system detect the presence of of routers (this is the default),
.B 2
to permanently enable multicast traffic forwarding on this port or
.B 3
to enable multicast routers temporarily on this port, not depending on incoming
queries.
.BR mcast_fast_leave " { " on " | " off " }"
- this is a synonym to the
.B fastleave
option above.
.in -8
.TP
Bonding Slave Support
For a link with master
.B bond
the following additional arguments are supported:
.B "ip link set type bond_slave"
[
.BI queue_id " ID"
]
.in +8
.sp
.BI queue_id " ID"
- set the slave's queue ID (a 16bit unsigned value).
.in -8
.SS ip link show - display device attributes .SS ip link show - display device attributes

View File

@ -21,6 +21,9 @@ Show summary of options.
.B \-V, \-\-version .B \-V, \-\-version
Output version information. Output version information.
.TP .TP
.B \-H, \-\-no-header
Suppress header line.
.TP
.B \-n, \-\-numeric .B \-n, \-\-numeric
Do not try to resolve service names. Do not try to resolve service names.
.TP .TP

View File

@ -179,16 +179,22 @@ static void undo_sysctl_adjustments(void)
static int send_probe(int ifindex, __u32 addr) static int send_probe(int ifindex, __u32 addr)
{ {
struct ifreq ifr; struct ifreq ifr = { .ifr_ifindex = ifindex };
struct sockaddr_in dst; struct sockaddr_in dst = {
.sin_family = AF_INET,
.sin_port = htons(1025),
.sin_addr.s_addr = addr,
};
socklen_t len; socklen_t len;
unsigned char buf[256]; unsigned char buf[256];
struct arphdr *ah = (struct arphdr *)buf; struct arphdr *ah = (struct arphdr *)buf;
unsigned char *p = (unsigned char *)(ah+1); unsigned char *p = (unsigned char *)(ah+1);
struct sockaddr_ll sll; struct sockaddr_ll sll = {
.sll_family = AF_PACKET,
.sll_ifindex = ifindex,
.sll_protocol = htons(ETH_P_ARP),
};
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_ifindex = ifindex;
if (ioctl(udp_sock, SIOCGIFNAME, &ifr)) if (ioctl(udp_sock, SIOCGIFNAME, &ifr))
return -1; return -1;
if (ioctl(udp_sock, SIOCGIFHWADDR, &ifr)) if (ioctl(udp_sock, SIOCGIFHWADDR, &ifr))
@ -198,9 +204,6 @@ static int send_probe(int ifindex, __u32 addr)
if (setsockopt(udp_sock, SOL_SOCKET, SO_BINDTODEVICE, ifr.ifr_name, strlen(ifr.ifr_name)+1) < 0) if (setsockopt(udp_sock, SOL_SOCKET, SO_BINDTODEVICE, ifr.ifr_name, strlen(ifr.ifr_name)+1) < 0)
return -1; return -1;
dst.sin_family = AF_INET;
dst.sin_port = htons(1025);
dst.sin_addr.s_addr = addr;
if (connect(udp_sock, (struct sockaddr *)&dst, sizeof(dst)) < 0) if (connect(udp_sock, (struct sockaddr *)&dst, sizeof(dst)) < 0)
return -1; return -1;
len = sizeof(dst); len = sizeof(dst);
@ -219,10 +222,7 @@ static int send_probe(int ifindex, __u32 addr)
memcpy(p, &dst.sin_addr, 4); memcpy(p, &dst.sin_addr, 4);
p += 4; p += 4;
sll.sll_family = AF_PACKET;
memset(sll.sll_addr, 0xFF, sizeof(sll.sll_addr)); memset(sll.sll_addr, 0xFF, sizeof(sll.sll_addr));
sll.sll_ifindex = ifindex;
sll.sll_protocol = htons(ETH_P_ARP);
memcpy(p, &sll.sll_addr, ah->ar_hln); memcpy(p, &sll.sll_addr, ah->ar_hln);
p += ah->ar_hln; p += ah->ar_hln;
@ -268,18 +268,15 @@ static int respond_to_kernel(int ifindex, __u32 addr, char *lla, int llalen)
struct nlmsghdr n; struct nlmsghdr n;
struct ndmsg ndm; struct ndmsg ndm;
char buf[256]; char buf[256];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)),
memset(&req.n, 0, sizeof(req.n)); .n.nlmsg_flags = NLM_F_REQUEST,
memset(&req.ndm, 0, sizeof(req.ndm)); .n.nlmsg_type = RTM_NEWNEIGH,
.ndm.ndm_family = AF_INET,
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)); .ndm.ndm_state = NUD_STALE,
req.n.nlmsg_flags = NLM_F_REQUEST; .ndm.ndm_ifindex = ifindex,
req.n.nlmsg_type = RTM_NEWNEIGH; .ndm.ndm_type = RTN_UNICAST,
req.ndm.ndm_family = AF_INET; };
req.ndm.ndm_state = NUD_STALE;
req.ndm.ndm_ifindex = ifindex;
req.ndm.ndm_type = RTN_UNICAST;
addattr_l(&req.n, sizeof(req), NDA_DST, &addr, 4); addattr_l(&req.n, sizeof(req), NDA_DST, &addr, 4);
addattr_l(&req.n, sizeof(req), NDA_LLADDR, lla, llalen); addattr_l(&req.n, sizeof(req), NDA_LLADDR, lla, llalen);
@ -440,7 +437,7 @@ static void get_kern_msg(void)
{ {
int status; int status;
struct nlmsghdr *h; struct nlmsghdr *h;
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr = {};
struct iovec iov; struct iovec iov;
char buf[8192]; char buf[8192];
struct msghdr msg = { struct msghdr msg = {
@ -450,8 +447,6 @@ static void get_kern_msg(void)
0 0
}; };
memset(&nladdr, 0, sizeof(nladdr));
iov.iov_base = buf; iov.iov_base = buf;
iov.iov_len = sizeof(buf); iov.iov_len = sizeof(buf);
@ -539,10 +534,8 @@ static void get_arp_pkt(void)
static void catch_signal(int sig, void (*handler)(int)) static void catch_signal(int sig, void (*handler)(int))
{ {
struct sigaction sa; struct sigaction sa = { .sa_handler = handler };
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handler;
#ifdef SA_INTERRUPT #ifdef SA_INTERRUPT
sa.sa_flags = SA_INTERRUPT; sa.sa_flags = SA_INTERRUPT;
#endif #endif
@ -668,9 +661,8 @@ int main(int argc, char **argv)
if (ifnum) { if (ifnum) {
int i; int i;
struct ifreq ifr; struct ifreq ifr = {};
memset(&ifr, 0, sizeof(ifr));
for (i = 0; i < ifnum; i++) { for (i = 0; i < ifnum; i++) {
strncpy(ifr.ifr_name, ifnames[i], IFNAMSIZ); strncpy(ifr.ifr_name, ifnames[i], IFNAMSIZ);
if (ioctl(udp_sock, SIOCGIFINDEX, &ifr)) { if (ioctl(udp_sock, SIOCGIFINDEX, &ifr)) {
@ -772,12 +764,12 @@ int main(int argc, char **argv)
} }
if (1) { if (1) {
struct sockaddr_ll sll; struct sockaddr_ll sll = {
.sll_family = AF_PACKET,
.sll_protocol = htons(ETH_P_ARP),
.sll_ifindex = (ifnum == 1 ? ifvec[0] : 0),
};
memset(&sll, 0, sizeof(sll));
sll.sll_family = AF_PACKET;
sll.sll_protocol = htons(ETH_P_ARP);
sll.sll_ifindex = (ifnum == 1 ? ifvec[0] : 0);
if (bind(pset[0].fd, (struct sockaddr *)&sll, sizeof(sll)) < 0) { if (bind(pset[0].fd, (struct sockaddr *)&sll, sizeof(sll)) < 0) {
perror("bind"); perror("bind");
goto do_abort; goto do_abort;

View File

@ -245,6 +245,7 @@ static void dump_raw_db(FILE *fp, int to_hist)
h = hist_db; h = hist_db;
if (jw) { if (jw) {
jsonw_start_object(jw);
jsonw_pretty(jw, pretty); jsonw_pretty(jw, pretty);
jsonw_name(jw, info_source); jsonw_name(jw, info_source);
jsonw_start_object(jw); jsonw_start_object(jw);
@ -287,6 +288,8 @@ static void dump_raw_db(FILE *fp, int to_hist)
} }
} }
if (jw) { if (jw) {
jsonw_end_object(jw);
jsonw_end_object(jw); jsonw_end_object(jw);
jsonw_destroy(&jw); jsonw_destroy(&jw);
} }
@ -451,6 +454,7 @@ static void dump_kern_db(FILE *fp)
struct ifstat_ent *n; struct ifstat_ent *n;
if (jw) { if (jw) {
jsonw_start_object(jw);
jsonw_pretty(jw, pretty); jsonw_pretty(jw, pretty);
jsonw_name(jw, info_source); jsonw_name(jw, info_source);
jsonw_start_object(jw); jsonw_start_object(jw);
@ -477,6 +481,7 @@ static void dump_incr_db(FILE *fp)
h = hist_db; h = hist_db;
if (jw) { if (jw) {
jsonw_start_object(jw);
jsonw_pretty(jw, pretty); jsonw_pretty(jw, pretty);
jsonw_name(jw, info_source); jsonw_name(jw, info_source);
jsonw_start_object(jw); jsonw_start_object(jw);
@ -508,6 +513,8 @@ static void dump_incr_db(FILE *fp)
} }
if (jw) { if (jw) {
jsonw_end_object(jw);
jsonw_end_object(jw); jsonw_end_object(jw);
jsonw_destroy(&jw); jsonw_destroy(&jw);
} }

View File

@ -182,10 +182,8 @@ static struct table_hdr *build_hdr_string(struct lnstat_file *lnstat_files,
static struct table_hdr th; static struct table_hdr th;
int ofs = 0; int ofs = 0;
for (i = 0; i < HDR_LINES; i++) { for (i = 0; i < HDR_LINES; i++)
th.hdr[i] = malloc(HDR_LINE_LENGTH); th.hdr[i] = calloc(1, HDR_LINE_LENGTH);
memset(th.hdr[i], 0, HDR_LINE_LENGTH);
}
for (i = 0; i < fps->num; i++) { for (i = 0; i < fps->num; i++) {
char *cname, *fname = fps->params[i].lf->name; char *cname, *fname = fps->params[i].lf->name;

View File

@ -173,15 +173,13 @@ static struct lnstat_file *alloc_and_open(const char *path, const char *file)
struct lnstat_file *lf; struct lnstat_file *lf;
/* allocate */ /* allocate */
lf = malloc(sizeof(*lf)); lf = calloc(1, sizeof(*lf));
if (!lf) { if (!lf) {
fprintf(stderr, "out of memory\n"); fprintf(stderr, "out of memory\n");
return NULL; return NULL;
} }
/* initialize */ /* initialize */
memset(lf, 0, sizeof(*lf));
/* de->d_name is guaranteed to be <= NAME_MAX */ /* de->d_name is guaranteed to be <= NAME_MAX */
strcpy(lf->basename, file); strcpy(lf->basename, file);
strcpy(lf->path, path); strcpy(lf->path, path);

View File

@ -285,6 +285,7 @@ static void dump_kern_db(FILE *fp, int to_hist)
h = hist_db; h = hist_db;
if (jw) { if (jw) {
jsonw_start_object(jw);
jsonw_pretty(jw, pretty); jsonw_pretty(jw, pretty);
jsonw_name(jw, info_source); jsonw_name(jw, info_source);
jsonw_start_object(jw); jsonw_start_object(jw);
@ -317,6 +318,8 @@ static void dump_kern_db(FILE *fp, int to_hist)
} }
if (jw) { if (jw) {
jsonw_end_object(jw);
jsonw_end_object(jw); jsonw_end_object(jw);
jsonw_destroy(&jw); jsonw_destroy(&jw);
} }
@ -329,6 +332,7 @@ static void dump_incr_db(FILE *fp)
h = hist_db; h = hist_db;
if (jw) { if (jw) {
jsonw_start_object(jw);
jsonw_pretty(jw, pretty); jsonw_pretty(jw, pretty);
jsonw_name(jw, info_source); jsonw_name(jw, info_source);
jsonw_start_object(jw); jsonw_start_object(jw);
@ -364,6 +368,8 @@ static void dump_incr_db(FILE *fp)
} }
if (jw) { if (jw) {
jsonw_end_object(jw);
jsonw_end_object(jw); jsonw_end_object(jw);
jsonw_destroy(&jw); jsonw_destroy(&jw);
} }

View File

@ -97,6 +97,7 @@ int show_tcpinfo;
int show_bpf; int show_bpf;
int show_proc_ctx; int show_proc_ctx;
int show_sock_ctx; int show_sock_ctx;
int show_header = 1;
/* If show_users & show_proc_ctx only do user_ent_hash_build() once */ /* If show_users & show_proc_ctx only do user_ent_hash_build() once */
int user_ent_hash_build_init; int user_ent_hash_build_init;
int follow_events; int follow_events;
@ -1435,11 +1436,13 @@ void *parse_devcond(char *name)
a.iface = xll_name_to_index(name); a.iface = xll_name_to_index(name);
if (a.iface == 0) { if (a.iface == 0) {
char *end; char *end;
unsigned long res; unsigned long n;
res = strtoul(name, &end, 0); n = strtoul(name, &end, 0);
if (!end || end == name || *end || res > UINT_MAX) if (!end || end == name || *end || n > UINT_MAX)
return NULL; return NULL;
a.iface = n;
} }
res = malloc(sizeof(*res)); res = malloc(sizeof(*res));
@ -2163,11 +2166,17 @@ static int inet_show_sock(struct nlmsghdr *nlh,
static int tcpdiag_send(int fd, int protocol, struct filter *f) static int tcpdiag_send(int fd, int protocol, struct filter *f)
{ {
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
struct { struct {
struct nlmsghdr nlh; struct nlmsghdr nlh;
struct inet_diag_req r; struct inet_diag_req r;
} req; } req = {
.nlh.nlmsg_len = sizeof(req),
.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST,
.nlh.nlmsg_seq = MAGIC_SEQ,
.r.idiag_family = AF_INET,
.r.idiag_states = f->states,
};
char *bc = NULL; char *bc = NULL;
int bclen; int bclen;
struct msghdr msg; struct msghdr msg;
@ -2178,20 +2187,10 @@ static int tcpdiag_send(int fd, int protocol, struct filter *f)
if (protocol == IPPROTO_UDP) if (protocol == IPPROTO_UDP)
return -1; return -1;
memset(&nladdr, 0, sizeof(nladdr));
nladdr.nl_family = AF_NETLINK;
req.nlh.nlmsg_len = sizeof(req);
if (protocol == IPPROTO_TCP) if (protocol == IPPROTO_TCP)
req.nlh.nlmsg_type = TCPDIAG_GETSOCK; req.nlh.nlmsg_type = TCPDIAG_GETSOCK;
else else
req.nlh.nlmsg_type = DCCPDIAG_GETSOCK; req.nlh.nlmsg_type = DCCPDIAG_GETSOCK;
req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
req.nlh.nlmsg_pid = 0;
req.nlh.nlmsg_seq = MAGIC_SEQ;
memset(&req.r, 0, sizeof(req.r));
req.r.idiag_family = AF_INET;
req.r.idiag_states = f->states;
if (show_mem) { if (show_mem) {
req.r.idiag_ext |= (1<<(INET_DIAG_MEMINFO-1)); req.r.idiag_ext |= (1<<(INET_DIAG_MEMINFO-1));
req.r.idiag_ext |= (1<<(INET_DIAG_SKMEMINFO-1)); req.r.idiag_ext |= (1<<(INET_DIAG_SKMEMINFO-1));
@ -2236,8 +2235,7 @@ static int tcpdiag_send(int fd, int protocol, struct filter *f)
static int sockdiag_send(int family, int fd, int protocol, struct filter *f) static int sockdiag_send(int family, int fd, int protocol, struct filter *f)
{ {
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
DIAG_REQUEST(req, struct inet_diag_req_v2 r); DIAG_REQUEST(req, struct inet_diag_req_v2 r);
char *bc = NULL; char *bc = NULL;
int bclen; int bclen;
@ -2249,9 +2247,6 @@ static int sockdiag_send(int family, int fd, int protocol, struct filter *f)
if (family == PF_UNSPEC) if (family == PF_UNSPEC)
return tcpdiag_send(fd, protocol, f); return tcpdiag_send(fd, protocol, f);
memset(&nladdr, 0, sizeof(nladdr));
nladdr.nl_family = AF_NETLINK;
memset(&req.r, 0, sizeof(req.r)); memset(&req.r, 0, sizeof(req.r));
req.r.sdiag_family = family; req.r.sdiag_family = family;
req.r.sdiag_protocol = protocol; req.r.sdiag_protocol = protocol;
@ -2747,14 +2742,13 @@ static void unix_stats_print(struct sockstat *list, struct filter *f)
} }
if (use_proc && f->f) { if (use_proc && f->f) {
struct sockstat st; struct sockstat st = {
.local.family = AF_UNIX,
.remote.family = AF_UNIX,
};
st.local.family = AF_UNIX;
st.remote.family = AF_UNIX;
memcpy(st.local.data, &s->name, sizeof(s->name)); memcpy(st.local.data, &s->name, sizeof(s->name));
if (strcmp(peer, "*") == 0) if (strcmp(peer, "*"))
memset(st.remote.data, 0, sizeof(peer));
else
memcpy(st.remote.data, &peer, sizeof(peer)); memcpy(st.remote.data, &peer, sizeof(peer));
if (run_ssfilter(f->f, &st) == 0) if (run_ssfilter(f->f, &st) == 0)
continue; continue;
@ -3667,6 +3661,7 @@ static void _usage(FILE *dest)
" FAMILY := {inet|inet6|link|unix|netlink|help}\n" " FAMILY := {inet|inet6|link|unix|netlink|help}\n"
"\n" "\n"
" -K, --kill forcibly close sockets, display what was closed\n" " -K, --kill forcibly close sockets, display what was closed\n"
" -H, --no-header Suppress header line\n"
"\n" "\n"
" -A, --query=QUERY, --socket=QUERY\n" " -A, --query=QUERY, --socket=QUERY\n"
" QUERY := {all|inet|tcp|udp|raw|unix|unix_dgram|unix_stream|unix_seqpacket|packet|netlink}[,QUERY]\n" " QUERY := {all|inet|tcp|udp|raw|unix|unix_dgram|unix_stream|unix_seqpacket|packet|netlink}[,QUERY]\n"
@ -3760,6 +3755,7 @@ static const struct option long_opts[] = {
{ "contexts", 0, 0, 'z' }, { "contexts", 0, 0, 'z' },
{ "net", 1, 0, 'N' }, { "net", 1, 0, 'N' },
{ "kill", 0, 0, 'K' }, { "kill", 0, 0, 'K' },
{ "no-header", 0, 0, 'H' },
{ 0 } { 0 }
}; };
@ -3774,7 +3770,7 @@ int main(int argc, char *argv[])
int ch; int ch;
int state_filter = 0; int state_filter = 0;
while ((ch = getopt_long(argc, argv, "dhaletuwxnro460spbEf:miA:D:F:vVzZN:K", while ((ch = getopt_long(argc, argv, "dhaletuwxnro460spbEf:miA:D:F:vVzZN:KH",
long_opts, NULL)) != EOF) { long_opts, NULL)) != EOF) {
switch (ch) { switch (ch) {
case 'n': case 'n':
@ -3959,6 +3955,9 @@ int main(int argc, char *argv[])
case 'K': case 'K':
current_filter.kill = 1; current_filter.kill = 1;
break; break;
case 'H':
show_header = 0;
break;
case 'h': case 'h':
help(); help();
case '?': case '?':
@ -4084,19 +4083,23 @@ int main(int argc, char *argv[])
addr_width = addrp_width - serv_width - 1; addr_width = addrp_width - serv_width - 1;
if (netid_width) if (show_header) {
printf("%-*s ", netid_width, "Netid"); if (netid_width)
if (state_width) printf("%-*s ", netid_width, "Netid");
printf("%-*s ", state_width, "State"); if (state_width)
printf("%-6s %-6s ", "Recv-Q", "Send-Q"); printf("%-*s ", state_width, "State");
printf("%-6s %-6s ", "Recv-Q", "Send-Q");
}
/* Make enough space for the local/remote port field */ /* Make enough space for the local/remote port field */
addr_width -= 13; addr_width -= 13;
serv_width += 13; serv_width += 13;
printf("%*s:%-*s %*s:%-*s\n", if (show_header) {
addr_width, "Local Address", serv_width, "Port", printf("%*s:%-*s %*s:%-*s\n",
addr_width, "Peer Address", serv_width, "Port"); addr_width, "Local Address", serv_width, "Port",
addr_width, "Peer Address", serv_width, "Port");
}
fflush(stdout); fflush(stdout);

View File

@ -0,0 +1,62 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "bridge fdb show",
"type": "array",
"items": {
"type": "object",
"properties": {
"dev": {
"type": "string"
},
"dst": {
"description" : "host name or ip address",
"type": "string"
},
"flags": {
"type": "array",
"items": {
"enum": ["self", "master", "router", "offload"]
},
"uniqueItems": true
},
"linkNetNsId": {
"type": "integer"
},
"mac": {
"type": "string"
},
"master": {
"type": "string"
},
"opCode": {
"description" : "used to indicate fdb entry del",
"enum": ["deleted"]
},
"port": {
"type": "integer"
},
"state": {
"description" : "permanent, static, stale, state=#x",
"type": "string"
},
"updated": {
"type": "integer"
},
"used": {
"type": "integer"
},
"viaIf": {
"type": "string"
},
"viaIfIndex": {
"type": "integer"
},
"vlan": {
"type": "integer"
},
"vni": {
"type": "integer"
}
}
}
}

View File

@ -56,8 +56,8 @@ static int parse_bpf(struct exec_util *eu, int argc, char **argv)
char **argv_run = argv_default, **envp_run, *tmp; char **argv_run = argv_default, **envp_run, *tmp;
int ret, i, env_old, env_num, env_map; int ret, i, env_old, env_num, env_map;
const char *bpf_uds_name = NULL; const char *bpf_uds_name = NULL;
int fds[BPF_SCM_MAX_FDS]; int fds[BPF_SCM_MAX_FDS] = {};
struct bpf_map_aux aux; struct bpf_map_aux aux = {};
if (argc == 0) if (argc == 0)
return 0; return 0;
@ -115,9 +115,6 @@ static int parse_bpf(struct exec_util *eu, int argc, char **argv)
return -1; return -1;
} }
memset(fds, 0, sizeof(fds));
memset(&aux, 0, sizeof(aux));
ret = bpf_recv_map_fds(bpf_uds_name, fds, &aux, ARRAY_SIZE(fds)); ret = bpf_recv_map_fds(bpf_uds_name, fds, &aux, ARRAY_SIZE(fds));
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "bpf: Could not receive fds!\n"); fprintf(stderr, "bpf: Could not receive fds!\n");

View File

@ -106,8 +106,8 @@ static int canid_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
if (args == NULL) if (args == NULL)
return PARSE_ERR(args, "canid: missing arguments"); return PARSE_ERR(args, "canid: missing arguments");
rules.rules_raw = malloc(sizeof(struct can_filter) * rules.rules_capacity); rules.rules_raw = calloc(rules.rules_capacity,
memset(rules.rules_raw, 0, sizeof(struct can_filter) * rules.rules_capacity); sizeof(struct can_filter));
do { do {
if (!bstrcmp(args, "sff")) { if (!bstrcmp(args, "sff")) {

View File

@ -44,9 +44,7 @@ static int cmp_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
int align, opnd = 0; int align, opnd = 0;
unsigned long offset = 0, layer = TCF_LAYER_NETWORK, mask = 0, value = 0; unsigned long offset = 0, layer = TCF_LAYER_NETWORK, mask = 0, value = 0;
int offset_present = 0, value_present = 0; int offset_present = 0, value_present = 0;
struct tcf_em_cmp cmp; struct tcf_em_cmp cmp = {};
memset(&cmp, 0, sizeof(cmp));
#define PARSE_ERR(CARG, FMT, ARGS...) \ #define PARSE_ERR(CARG, FMT, ARGS...) \
em_parse_error(EINVAL, args, CARG, &cmp_ematch_util, FMT, ##ARGS) em_parse_error(EINVAL, args, CARG, &cmp_ematch_util, FMT, ##ARGS)

View File

@ -198,11 +198,9 @@ static void ipset_print_usage(FILE *fd)
static int ipset_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr, static int ipset_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
struct bstr *args) struct bstr *args)
{ {
struct xt_set_info set_info; struct xt_set_info set_info = {};
int ret; int ret;
memset(&set_info, 0, sizeof(set_info));
#define PARSE_ERR(CARG, FMT, ARGS...) \ #define PARSE_ERR(CARG, FMT, ARGS...) \
em_parse_error(EINVAL, args, CARG, &ipset_ematch_util, FMT, ##ARGS) em_parse_error(EINVAL, args, CARG, &ipset_ematch_util, FMT, ##ARGS)

View File

@ -361,11 +361,9 @@ static int meta_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
{ {
int opnd; int opnd;
struct bstr *a; struct bstr *a;
struct tcf_meta_hdr meta_hdr; struct tcf_meta_hdr meta_hdr = {};
unsigned long lvalue = 0, rvalue = 0; unsigned long lvalue = 0, rvalue = 0;
memset(&meta_hdr, 0, sizeof(meta_hdr));
if (args == NULL) if (args == NULL)
return PARSE_ERR(args, "meta: missing arguments"); return PARSE_ERR(args, "meta: missing arguments");
@ -485,8 +483,9 @@ static int print_object(FILE *fd, struct tcf_meta_val *obj, struct rtattr *rta)
if (RTA_PAYLOAD(rta) < sizeof(__u32)) if (RTA_PAYLOAD(rta) < sizeof(__u32))
goto size_mismatch; goto size_mismatch;
fprintf(fd, " mask 0x%08x", if (rta_getattr_u32(rta))
rta_getattr_u32(rta)); fprintf(fd, " mask 0x%08x",
rta_getattr_u32(rta));
} }
break; break;
} }

View File

@ -44,9 +44,7 @@ static int nbyte_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
struct bstr *needle = args; struct bstr *needle = args;
unsigned long offset = 0, layer = TCF_LAYER_NETWORK; unsigned long offset = 0, layer = TCF_LAYER_NETWORK;
int offset_present = 0; int offset_present = 0;
struct tcf_em_nbyte nb; struct tcf_em_nbyte nb = {};
memset(&nb, 0, sizeof(nb));
#define PARSE_ERR(CARG, FMT, ARGS...) \ #define PARSE_ERR(CARG, FMT, ARGS...) \
em_parse_error(EINVAL, args, CARG, &nbyte_ematch_util, FMT, ##ARGS) em_parse_error(EINVAL, args, CARG, &nbyte_ematch_util, FMT, ##ARGS)

View File

@ -39,9 +39,7 @@ static int u32_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
struct bstr *a; struct bstr *a;
int align, nh_len; int align, nh_len;
unsigned long key, mask, offmask = 0, offset; unsigned long key, mask, offmask = 0, offset;
struct tc_u32_key u_key; struct tc_u32_key u_key = {};
memset(&u_key, 0, sizeof(u_key));
#define PARSE_ERR(CARG, FMT, ARGS...) \ #define PARSE_ERR(CARG, FMT, ARGS...) \
em_parse_error(EINVAL, args, CARG, &u32_ematch_util, FMT, ##ARGS) em_parse_error(EINVAL, args, CARG, &u32_ematch_util, FMT, ##ARGS)

View File

@ -133,7 +133,6 @@ out:
static int flow_parse_opt(struct filter_util *fu, char *handle, static int flow_parse_opt(struct filter_util *fu, char *handle,
int argc, char **argv, struct nlmsghdr *n) int argc, char **argv, struct nlmsghdr *n)
{ {
struct tc_police tp;
struct tcmsg *t = NLMSG_DATA(n); struct tcmsg *t = NLMSG_DATA(n);
struct rtattr *tail; struct rtattr *tail;
__u32 mask = ~0U, xor = 0; __u32 mask = ~0U, xor = 0;
@ -141,8 +140,6 @@ static int flow_parse_opt(struct filter_util *fu, char *handle,
__u32 mode = FLOW_MODE_MAP; __u32 mode = FLOW_MODE_MAP;
__u32 tmp; __u32 tmp;
memset(&tp, 0, sizeof(tp));
if (handle) { if (handle) {
if (get_u32(&t->tcm_handle, handle, 0)) { if (get_u32(&t->tcm_handle, handle, 0)) {
fprintf(stderr, "Illegal \"handle\"\n"); fprintf(stderr, "Illegal \"handle\"\n");

View File

@ -203,10 +203,9 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
} else if (matches(*argv, "skip_sw") == 0) { } else if (matches(*argv, "skip_sw") == 0) {
flags |= TCA_CLS_FLAGS_SKIP_SW; flags |= TCA_CLS_FLAGS_SKIP_SW;
} else if (matches(*argv, "indev") == 0) { } else if (matches(*argv, "indev") == 0) {
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ] = {};
NEXT_ARG(); NEXT_ARG();
memset(ifname, 0, sizeof(ifname));
strncpy(ifname, *argv, sizeof(ifname) - 1); strncpy(ifname, *argv, sizeof(ifname) - 1);
addattrstrz(n, MAX_MSG, TCA_FLOWER_INDEV, ifname); addattrstrz(n, MAX_MSG, TCA_FLOWER_INDEV, ifname);
} else if (matches(*argv, "dst_mac") == 0) { } else if (matches(*argv, "dst_mac") == 0) {

View File

@ -33,14 +33,11 @@ static void explain(void)
static int fw_parse_opt(struct filter_util *qu, char *handle, int argc, char **argv, struct nlmsghdr *n) static int fw_parse_opt(struct filter_util *qu, char *handle, int argc, char **argv, struct nlmsghdr *n)
{ {
struct tc_police tp;
struct tcmsg *t = NLMSG_DATA(n); struct tcmsg *t = NLMSG_DATA(n);
struct rtattr *tail; struct rtattr *tail;
__u32 mask = 0; __u32 mask = 0;
int mask_set = 0; int mask_set = 0;
memset(&tp, 0, sizeof(tp));
if (handle) { if (handle) {
char *slash; char *slash;
@ -94,9 +91,8 @@ static int fw_parse_opt(struct filter_util *qu, char *handle, int argc, char **a
} }
continue; continue;
} else if (strcmp(*argv, "indev") == 0) { } else if (strcmp(*argv, "indev") == 0) {
char d[IFNAMSIZ+1]; char d[IFNAMSIZ+1] = {};
memset(d, 0, sizeof(d));
argc--; argc--;
argv++; argv++;
if (argc < 1) { if (argc < 1) {

View File

@ -36,14 +36,11 @@ static void explain(void)
static int route_parse_opt(struct filter_util *qu, char *handle, int argc, char **argv, struct nlmsghdr *n) static int route_parse_opt(struct filter_util *qu, char *handle, int argc, char **argv, struct nlmsghdr *n)
{ {
struct tc_police tp;
struct tcmsg *t = NLMSG_DATA(n); struct tcmsg *t = NLMSG_DATA(n);
struct rtattr *tail; struct rtattr *tail;
__u32 fh = 0xFFFF8000; __u32 fh = 0xFFFF8000;
__u32 order = 0; __u32 order = 0;
memset(&tp, 0, sizeof(tp));
if (handle) { if (handle) {
if (get_u32(&t->tcm_handle, handle, 0)) { if (get_u32(&t->tcm_handle, handle, 0)) {
fprintf(stderr, "Illegal \"handle\"\n"); fprintf(stderr, "Illegal \"handle\"\n");

View File

@ -173,15 +173,11 @@ done:
static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char **argv, struct nlmsghdr *n) static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char **argv, struct nlmsghdr *n)
{ {
int family = strcmp(qu->id, "rsvp") == 0 ? AF_INET : AF_INET6; int family = strcmp(qu->id, "rsvp") == 0 ? AF_INET : AF_INET6;
struct tc_rsvp_pinfo pinfo; struct tc_rsvp_pinfo pinfo = {};
struct tc_police tp;
struct tcmsg *t = NLMSG_DATA(n); struct tcmsg *t = NLMSG_DATA(n);
int pinfo_ok = 0; int pinfo_ok = 0;
struct rtattr *tail; struct rtattr *tail;
memset(&pinfo, 0, sizeof(pinfo));
memset(&tp, 0, sizeof(tp));
if (handle) { if (handle) {
if (get_u32(&t->tcm_handle, handle, 0)) { if (get_u32(&t->tcm_handle, handle, 0)) {
fprintf(stderr, "Illegal \"handle\"\n"); fprintf(stderr, "Illegal \"handle\"\n");

View File

@ -988,7 +988,7 @@ static int u32_parse_opt(struct filter_util *qu, char *handle,
struct { struct {
struct tc_u32_sel sel; struct tc_u32_sel sel;
struct tc_u32_key keys[128]; struct tc_u32_key keys[128];
} sel; } sel = {};
struct tcmsg *t = NLMSG_DATA(n); struct tcmsg *t = NLMSG_DATA(n);
struct rtattr *tail; struct rtattr *tail;
int sel_ok = 0, terminal_ok = 0; int sel_ok = 0, terminal_ok = 0;
@ -997,8 +997,6 @@ static int u32_parse_opt(struct filter_util *qu, char *handle,
__u32 order = 0; __u32 order = 0;
__u32 flags = 0; __u32 flags = 0;
memset(&sel, 0, sizeof(sel));
if (handle && get_u32_handle(&t->tcm_handle, handle)) { if (handle && get_u32_handle(&t->tcm_handle, handle)) {
fprintf(stderr, "Illegal filter ID\n"); fprintf(stderr, "Illegal filter ID\n");
return -1; return -1;
@ -1093,12 +1091,11 @@ static int u32_parse_opt(struct filter_util *qu, char *handle,
} else if (strcmp(*argv, "sample") == 0) { } else if (strcmp(*argv, "sample") == 0) {
__u32 hash; __u32 hash;
unsigned int divisor = 0x100; unsigned int divisor = 0x100;
struct { struct {
struct tc_u32_sel sel; struct tc_u32_sel sel;
struct tc_u32_key keys[4]; struct tc_u32_key keys[4];
} sel2; } sel2 = {};
memset(&sel2, 0, sizeof(sel2));
NEXT_ARG(); NEXT_ARG();
if (parse_selector(&argc, &argv, &sel2.sel, n)) { if (parse_selector(&argc, &argv, &sel2.sel, n)) {
fprintf(stderr, "Illegal \"sample\"\n"); fprintf(stderr, "Illegal \"sample\"\n");
@ -1125,9 +1122,8 @@ static int u32_parse_opt(struct filter_util *qu, char *handle,
sample_ok = 1; sample_ok = 1;
continue; continue;
} else if (strcmp(*argv, "indev") == 0) { } else if (strcmp(*argv, "indev") == 0) {
char ind[IFNAMSIZ + 1]; char ind[IFNAMSIZ + 1] = {};
memset(ind, 0, sizeof(ind));
argc--; argc--;
argv++; argv++;
if (argc < 1) { if (argc < 1) {

View File

@ -126,9 +126,8 @@ noexist:
goto restart_s; goto restart_s;
} }
#endif #endif
a = malloc(sizeof(*a)); a = calloc(1, sizeof(*a));
if (a) { if (a) {
memset(a, 0, sizeof(*a));
strncpy(a->id, "noact", 15); strncpy(a->id, "noact", 15);
a->parse_aopt = parse_noaopt; a->parse_aopt = parse_noaopt;
a->print_aopt = print_noaopt; a->print_aopt = print_noaopt;
@ -395,13 +394,10 @@ static int tc_action_gd(int cmd, unsigned int flags, int *argc_p, char ***argv_p
struct tcamsg t; struct tcamsg t;
char buf[MAX_MSG]; char buf[MAX_MSG];
} req = { } req = {
.n = { .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)),
.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)), .n.nlmsg_flags = NLM_F_REQUEST | flags,
.nlmsg_flags = NLM_F_REQUEST | flags, .n.nlmsg_type = cmd,
.nlmsg_type = cmd,
},
.t.tca_family = AF_UNSPEC, .t.tca_family = AF_UNSPEC,
.buf = { 0 }
}; };
argc -= 1; argc -= 1;
@ -491,23 +487,18 @@ static int tc_action_modify(int cmd, unsigned int flags, int *argc_p, char ***ar
int argc = *argc_p; int argc = *argc_p;
char **argv = *argv_p; char **argv = *argv_p;
int ret = 0; int ret = 0;
struct rtattr *tail;
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct tcamsg t; struct tcamsg t;
char buf[MAX_MSG]; char buf[MAX_MSG];
} req = { } req = {
.n = { .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)),
.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)), .n.nlmsg_flags = NLM_F_REQUEST | flags,
.nlmsg_flags = NLM_F_REQUEST | flags, .n.nlmsg_type = cmd,
.nlmsg_type = cmd,
},
.t.tca_family = AF_UNSPEC, .t.tca_family = AF_UNSPEC,
.buf = { 0 }
}; };
struct rtattr *tail = NLMSG_TAIL(&req.n);
tail = NLMSG_TAIL(&req.n);
argc -= 1; argc -= 1;
argv += 1; argv += 1;
if (parse_action(&argc, &argv, TCA_ACT_TAB, &req.n)) { if (parse_action(&argc, &argv, TCA_ACT_TAB, &req.n)) {
@ -540,7 +531,6 @@ static int tc_act_list_or_flush(int argc, char **argv, int event)
} req = { } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)), .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)),
.t.tca_family = AF_UNSPEC, .t.tca_family = AF_UNSPEC,
.buf = { 0 }
}; };
tail = NLMSG_TAIL(&req.n); tail = NLMSG_TAIL(&req.n);

View File

@ -63,7 +63,7 @@ static int bpf_parse_opt(struct action_util *a, int *ptr_argc, char ***ptr_argv,
int tca_id, struct nlmsghdr *n) int tca_id, struct nlmsghdr *n)
{ {
const char *bpf_obj = NULL, *bpf_uds_name = NULL; const char *bpf_obj = NULL, *bpf_uds_name = NULL;
struct tc_act_bpf parm; struct tc_act_bpf parm = { .action = TC_ACT_PIPE };
bool seen_run = false; bool seen_run = false;
struct rtattr *tail; struct rtattr *tail;
int argc, ret = 0; int argc, ret = 0;
@ -104,9 +104,6 @@ opt_bpf:
NEXT_ARG_FWD(); NEXT_ARG_FWD();
} }
memset(&parm, 0, sizeof(parm));
parm.action = TC_ACT_PIPE;
if (argc) { if (argc) {
if (matches(*argv, "reclassify") == 0) { if (matches(*argv, "reclassify") == 0) {
parm.action = TC_ACT_RECLASSIFY; parm.action = TC_ACT_RECLASSIFY;

View File

@ -85,15 +85,13 @@ static int
parse_csum(struct action_util *a, int *argc_p, parse_csum(struct action_util *a, int *argc_p,
char ***argv_p, int tca_id, struct nlmsghdr *n) char ***argv_p, int tca_id, struct nlmsghdr *n)
{ {
struct tc_csum sel; struct tc_csum sel = {};
int argc = *argc_p; int argc = *argc_p;
char **argv = *argv_p; char **argv = *argv_p;
int ok = 0; int ok = 0;
struct rtattr *tail; struct rtattr *tail;
memset(&sel, 0, sizeof(sel));
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "csum") == 0) { if (matches(*argv, "csum") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -177,9 +177,7 @@ static int parse_tree(struct nlmsghdr *n, struct ematch *tree)
for (t = tree; t; t = t->next) { for (t = tree; t; t = t->next) {
struct rtattr *tail = NLMSG_TAIL(n); struct rtattr *tail = NLMSG_TAIL(n);
struct tcf_ematch_hdr hdr = { struct tcf_ematch_hdr hdr = { .flags = t->relation };
.flags = t->relation
};
if (t->inverted) if (t->inverted)
hdr.flags |= TCF_EM_INVERT; hdr.flags |= TCF_EM_INVERT;

View File

@ -97,16 +97,13 @@ parse_gact(struct action_util *a, int *argc_p, char ***argv_p,
char **argv = *argv_p; char **argv = *argv_p;
int ok = 0; int ok = 0;
int action = TC_POLICE_RECLASSIFY; int action = TC_POLICE_RECLASSIFY;
struct tc_gact p; struct tc_gact p = { .action = TC_POLICE_RECLASSIFY };
#ifdef CONFIG_GACT_PROB #ifdef CONFIG_GACT_PROB
int rd = 0; int rd = 0;
struct tc_gact_p pp; struct tc_gact_p pp;
#endif #endif
struct rtattr *tail; struct rtattr *tail;
memset(&p, 0, sizeof(p));
p.action = TC_POLICE_RECLASSIFY;
if (argc < 0) if (argc < 0)
return -1; return -1;

View File

@ -56,7 +56,7 @@ static int parse_ife(struct action_util *a, int *argc_p, char ***argv_p,
int argc = *argc_p; int argc = *argc_p;
char **argv = *argv_p; char **argv = *argv_p;
int ok = 0; int ok = 0;
struct tc_ife p; struct tc_ife p = { .action = TC_ACT_PIPE }; /* good default */
struct rtattr *tail; struct rtattr *tail;
struct rtattr *tail2; struct rtattr *tail2;
char dbuf[ETH_ALEN]; char dbuf[ETH_ALEN];
@ -69,9 +69,6 @@ static int parse_ife(struct action_util *a, int *argc_p, char ***argv_p,
char *daddr = NULL; char *daddr = NULL;
char *saddr = NULL; char *saddr = NULL;
memset(&p, 0, sizeof(p));
p.action = TC_ACT_PIPE; /* good default */
if (argc <= 0) if (argc <= 0)
return -1; return -1;

View File

@ -164,16 +164,11 @@ get_target_name(const char *name)
return NULL; return NULL;
#endif #endif
new_name = malloc(strlen(name) + 1); new_name = calloc(1, strlen(name) + 1);
lname = malloc(strlen(name) + 1); lname = calloc(1, strlen(name) + 1);
if (new_name) if (!new_name)
memset(new_name, '\0', strlen(name) + 1);
else
exit_error(PARAMETER_PROBLEM, "get_target_name"); exit_error(PARAMETER_PROBLEM, "get_target_name");
if (!lname)
if (lname)
memset(lname, '\0', strlen(name) + 1);
else
exit_error(PARAMETER_PROBLEM, "get_target_name"); exit_error(PARAMETER_PROBLEM, "get_target_name");
strcpy(new_name, name); strcpy(new_name, name);

View File

@ -69,12 +69,9 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p,
int argc = *argc_p; int argc = *argc_p;
char **argv = *argv_p; char **argv = *argv_p;
int ok = 0, iok = 0, mirror = 0, redir = 0; int ok = 0, iok = 0, mirror = 0, redir = 0;
struct tc_mirred p; struct tc_mirred p = {};
struct rtattr *tail; struct rtattr *tail;
char d[16]; char d[16] = {};
memset(d, 0, sizeof(d)-1);
memset(&p, 0, sizeof(struct tc_mirred));
while (argc > 0) { while (argc > 0) {

View File

@ -84,15 +84,13 @@ bad_val:
static int static int
parse_nat(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n) parse_nat(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
{ {
struct tc_nat sel; struct tc_nat sel = {};
int argc = *argc_p; int argc = *argc_p;
char **argv = *argv_p; char **argv = *argv_p;
int ok = 0; int ok = 0;
struct rtattr *tail; struct rtattr *tail;
memset(&sel, 0, sizeof(sel));
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "nat") == 0) { if (matches(*argv, "nat") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -107,9 +107,8 @@ reg:
return p; return p;
noexist: noexist:
p = malloc(sizeof(*p)); p = calloc(1, sizeof(*p));
if (p) { if (p) {
memset(p, 0, sizeof(*p));
strncpy(p->id, str, sizeof(p->id) - 1); strncpy(p->id, str, sizeof(p->id) - 1);
p->parse_peopt = pedit_parse_nopopt; p->parse_peopt = pedit_parse_nopopt;
goto reg; goto reg;
@ -392,7 +391,7 @@ done:
static int parse_munge(int *argc_p, char ***argv_p, struct tc_pedit_sel *sel) static int parse_munge(int *argc_p, char ***argv_p, struct tc_pedit_sel *sel)
{ {
struct tc_pedit_key tkey; struct tc_pedit_key tkey = {};
int argc = *argc_p; int argc = *argc_p;
char **argv = *argv_p; char **argv = *argv_p;
int res = -1; int res = -1;
@ -400,8 +399,6 @@ static int parse_munge(int *argc_p, char ***argv_p, struct tc_pedit_sel *sel)
if (argc <= 0) if (argc <= 0)
return -1; return -1;
memset(&tkey, 0, sizeof(tkey));
if (matches(*argv, "offset") == 0) { if (matches(*argv, "offset") == 0) {
NEXT_ARG(); NEXT_ARG();
res = parse_offset(&argc, &argv, sel, &tkey); res = parse_offset(&argc, &argv, sel, &tkey);
@ -442,15 +439,13 @@ int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
struct { struct {
struct tc_pedit_sel sel; struct tc_pedit_sel sel;
struct tc_pedit_key keys[MAX_OFFS]; struct tc_pedit_key keys[MAX_OFFS];
} sel; } sel = {};
int argc = *argc_p; int argc = *argc_p;
char **argv = *argv_p; char **argv = *argv_p;
int ok = 0, iok = 0; int ok = 0, iok = 0;
struct rtattr *tail; struct rtattr *tail;
memset(&sel, 0, sizeof(sel));
while (argc > 0) { while (argc > 0) {
if (pedit_debug > 1) if (pedit_debug > 1)
fprintf(stderr, "while pedit (%d:%s)\n", argc, *argv); fprintf(stderr, "while pedit (%d:%s)\n", argc, *argv);

View File

@ -127,7 +127,7 @@ int act_parse_police(struct action_util *a, int *argc_p, char ***argv_p,
char **argv = *argv_p; char **argv = *argv_p;
int res = -1; int res = -1;
int ok = 0; int ok = 0;
struct tc_police p; struct tc_police p = { .action = TC_POLICE_RECLASSIFY };
__u32 rtab[256]; __u32 rtab[256];
__u32 ptab[256]; __u32 ptab[256];
__u32 avrate = 0; __u32 avrate = 0;
@ -138,9 +138,6 @@ int act_parse_police(struct action_util *a, int *argc_p, char ***argv_p,
int Rcell_log = -1, Pcell_log = -1; int Rcell_log = -1, Pcell_log = -1;
struct rtattr *tail; struct rtattr *tail;
memset(&p, 0, sizeof(p));
p.action = TC_POLICE_RECLASSIFY;
if (a) /* new way of doing things */ if (a) /* new way of doing things */
NEXT_ARG(); NEXT_ARG();

View File

@ -47,7 +47,7 @@ static void explain(void)
static int atm_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, static int atm_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct sockaddr_atmsvc addr; struct sockaddr_atmsvc addr = {};
struct atm_qos qos; struct atm_qos qos;
struct atm_sap sap; struct atm_sap sap;
unsigned char hdr[MAX_HDR_LEN]; unsigned char hdr[MAX_HDR_LEN];
@ -58,7 +58,6 @@ static int atm_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
int set_clip = 0; int set_clip = 0;
int s; int s;
memset(&addr, 0, sizeof(addr));
(void) text2qos("aal5,ubr:sdu=9180,rx:none", &qos, 0); (void) text2qos("aal5,ubr:sdu=9180,rx:none", &qos, 0);
(void) text2sap("blli:l2=iso8802", &sap, 0); (void) text2sap("blli:l2=iso8802", &sap, 0);
while (argc > 0) { while (argc > 0) {

View File

@ -49,8 +49,8 @@ static void explain1(char *arg)
static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{ {
struct tc_ratespec r; struct tc_ratespec r = {};
struct tc_cbq_lssopt lss; struct tc_cbq_lssopt lss = {};
__u32 rtab[256]; __u32 rtab[256];
unsigned mpu = 0, avpkt = 0, allot = 0; unsigned mpu = 0, avpkt = 0, allot = 0;
unsigned short overhead = 0; unsigned short overhead = 0;
@ -59,9 +59,6 @@ static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
int ewma_log = -1; int ewma_log = -1;
struct rtattr *tail; struct rtattr *tail;
memset(&lss, 0, sizeof(lss));
memset(&r, 0, sizeof(r));
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "bandwidth") == 0 || if (matches(*argv, "bandwidth") == 0 ||
matches(*argv, "rate") == 0) { matches(*argv, "rate") == 0) {
@ -183,11 +180,10 @@ static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{ {
int wrr_ok = 0, fopt_ok = 0; int wrr_ok = 0, fopt_ok = 0;
struct tc_ratespec r; struct tc_ratespec r = {};
struct tc_cbq_lssopt lss; struct tc_cbq_lssopt lss = {};
struct tc_cbq_wrropt wrr; struct tc_cbq_wrropt wrr = {};
struct tc_cbq_fopt fopt; struct tc_cbq_fopt fopt = {};
struct tc_cbq_ovl ovl;
__u32 rtab[256]; __u32 rtab[256];
unsigned mpu = 0; unsigned mpu = 0;
int cell_log = -1; int cell_log = -1;
@ -198,12 +194,6 @@ static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, str
unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */ unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */
struct rtattr *tail; struct rtattr *tail;
memset(&r, 0, sizeof(r));
memset(&lss, 0, sizeof(lss));
memset(&wrr, 0, sizeof(wrr));
memset(&fopt, 0, sizeof(fopt));
memset(&ovl, 0, sizeof(ovl));
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "rate") == 0) { if (matches(*argv, "rate") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -34,7 +34,7 @@ static void explain(void)
static int choke_parse_opt(struct qdisc_util *qu, int argc, char **argv, static int choke_parse_opt(struct qdisc_util *qu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct tc_red_qopt opt; struct tc_red_qopt opt = {};
unsigned int burst = 0; unsigned int burst = 0;
unsigned int avpkt = 1000; unsigned int avpkt = 1000;
double probability = 0.02; double probability = 0.02;
@ -45,8 +45,6 @@ static int choke_parse_opt(struct qdisc_util *qu, int argc, char **argv,
__u32 max_P; __u32 max_P;
struct rtattr *tail; struct rtattr *tail;
memset(&opt, 0, sizeof(opt));
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "limit") == 0) { if (strcmp(*argv, "limit") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -175,7 +175,7 @@ static int codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
static int codel_print_xstats(struct qdisc_util *qu, FILE *f, static int codel_print_xstats(struct qdisc_util *qu, FILE *f,
struct rtattr *xstats) struct rtattr *xstats)
{ {
struct tc_codel_xstats _st, *st; struct tc_codel_xstats _st = {}, *st;
SPRINT_BUF(b1); SPRINT_BUF(b1);
@ -184,7 +184,6 @@ static int codel_print_xstats(struct qdisc_util *qu, FILE *f,
st = RTA_DATA(xstats); st = RTA_DATA(xstats);
if (RTA_PAYLOAD(xstats) < sizeof(*st)) { if (RTA_PAYLOAD(xstats) < sizeof(*st)) {
memset(&_st, 0, sizeof(_st));
memcpy(&_st, st, RTA_PAYLOAD(xstats)); memcpy(&_st, st, RTA_PAYLOAD(xstats));
st = &_st; st = &_st;
} }

View File

@ -128,7 +128,6 @@ static int dsmark_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
struct rtattr *tb[TCA_DSMARK_MAX+1]; struct rtattr *tb[TCA_DSMARK_MAX+1];
if (!opt) return 0; if (!opt) return 0;
memset(tb, 0, sizeof(tb));
parse_rtattr(tb, TCA_DSMARK_MAX, RTA_DATA(opt), RTA_PAYLOAD(opt)); parse_rtattr(tb, TCA_DSMARK_MAX, RTA_DATA(opt), RTA_PAYLOAD(opt));
if (tb[TCA_DSMARK_MASK]) { if (tb[TCA_DSMARK_MASK]) {
if (!RTA_PAYLOAD(tb[TCA_DSMARK_MASK])) if (!RTA_PAYLOAD(tb[TCA_DSMARK_MASK]))

View File

@ -31,9 +31,7 @@ static void explain(void)
static int fifo_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) static int fifo_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{ {
int ok = 0; int ok = 0;
struct tc_fifo_qopt opt; struct tc_fifo_qopt opt = {};
memset(&opt, 0, sizeof(opt));
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "limit") == 0) { if (strcmp(*argv, "limit") == 0) {

View File

@ -220,7 +220,7 @@ static int fq_codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt
static int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f, static int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f,
struct rtattr *xstats) struct rtattr *xstats)
{ {
struct tc_fq_codel_xstats _st, *st; struct tc_fq_codel_xstats _st = {}, *st;
SPRINT_BUF(b1); SPRINT_BUF(b1);
@ -229,7 +229,6 @@ static int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f,
st = RTA_DATA(xstats); st = RTA_DATA(xstats);
if (RTA_PAYLOAD(xstats) < sizeof(*st)) { if (RTA_PAYLOAD(xstats) < sizeof(*st)) {
memset(&_st, 0, sizeof(_st));
memcpy(&_st, st, RTA_PAYLOAD(xstats)); memcpy(&_st, st, RTA_PAYLOAD(xstats));
st = &_st; st = &_st;
} }

View File

@ -73,9 +73,7 @@ explain1(char *arg)
static int static int
hfsc_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) hfsc_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{ {
struct tc_hfsc_qopt qopt; struct tc_hfsc_qopt qopt = {};
memset(&qopt, 0, sizeof(qopt));
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "default") == 0) { if (matches(*argv, "default") == 0) {
@ -146,15 +144,10 @@ static int
hfsc_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, hfsc_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct tc_service_curve rsc, fsc, usc; struct tc_service_curve rsc = {}, fsc = {}, usc = {};
int rsc_ok, fsc_ok, usc_ok; int rsc_ok = 0, fsc_ok = 0, usc_ok = 0;
struct rtattr *tail; struct rtattr *tail;
memset(&rsc, 0, sizeof(rsc));
memset(&fsc, 0, sizeof(fsc));
memset(&usc, 0, sizeof(usc));
rsc_ok = fsc_ok = usc_ok = 0;
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "rt") == 0) { if (matches(*argv, "rt") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -63,14 +63,13 @@ static void explain1(char *arg)
static int htb_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) static int htb_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{ {
unsigned int direct_qlen = ~0U; unsigned int direct_qlen = ~0U;
struct tc_htb_glob opt; struct tc_htb_glob opt = {
.rate2quantum = 10,
.version = 3,
};
struct rtattr *tail; struct rtattr *tail;
unsigned int i; char *p; unsigned int i; char *p;
memset(&opt, 0, sizeof(opt));
opt.rate2quantum = 10;
opt.version = 3;
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "r2q") == 0) { if (matches(*argv, "r2q") == 0) {
NEXT_ARG(); NEXT_ARG();
@ -113,19 +112,17 @@ static int htb_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
static int htb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) static int htb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{ {
int ok = 0; int ok = 0;
struct tc_htb_opt opt; struct tc_htb_opt opt = {};
__u32 rtab[256], ctab[256]; __u32 rtab[256], ctab[256];
unsigned buffer = 0, cbuffer = 0; unsigned buffer = 0, cbuffer = 0;
int cell_log = -1, ccell_log = -1; int cell_log = -1, ccell_log = -1;
unsigned int mtu; unsigned int mtu = 1600; /* eth packet len */
unsigned short mpu = 0; unsigned short mpu = 0;
unsigned short overhead = 0; unsigned short overhead = 0;
unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */ unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */
struct rtattr *tail; struct rtattr *tail;
__u64 ceil64 = 0, rate64 = 0; __u64 ceil64 = 0, rate64 = 0;
memset(&opt, 0, sizeof(opt)); mtu = 1600; /* eth packet len */
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "prio") == 0) { if (matches(*argv, "prio") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -175,23 +175,17 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
int dist_size = 0; int dist_size = 0;
struct rtattr *tail; struct rtattr *tail;
struct tc_netem_qopt opt = { .limit = 1000 }; struct tc_netem_qopt opt = { .limit = 1000 };
struct tc_netem_corr cor; struct tc_netem_corr cor = {};
struct tc_netem_reorder reorder; struct tc_netem_reorder reorder = {};
struct tc_netem_corrupt corrupt; struct tc_netem_corrupt corrupt = {};
struct tc_netem_gimodel gimodel; struct tc_netem_gimodel gimodel;
struct tc_netem_gemodel gemodel; struct tc_netem_gemodel gemodel;
struct tc_netem_rate rate; struct tc_netem_rate rate = {};
__s16 *dist_data = NULL; __s16 *dist_data = NULL;
__u16 loss_type = NETEM_LOSS_UNSPEC; __u16 loss_type = NETEM_LOSS_UNSPEC;
int present[__TCA_NETEM_MAX]; int present[__TCA_NETEM_MAX] = {};
__u64 rate64 = 0; __u64 rate64 = 0;
memset(&cor, 0, sizeof(cor));
memset(&reorder, 0, sizeof(reorder));
memset(&corrupt, 0, sizeof(corrupt));
memset(&rate, 0, sizeof(rate));
memset(present, 0, sizeof(present));
for ( ; argc > 0; --argc, ++argv) { for ( ; argc > 0; --argc, ++argv) {
if (matches(*argv, "limit") == 0) { if (matches(*argv, "limit") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -35,7 +35,7 @@ static void explain(void)
static int red_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) static int red_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{ {
struct tc_red_qopt opt; struct tc_red_qopt opt = {};
unsigned int burst = 0; unsigned int burst = 0;
unsigned int avpkt = 0; unsigned int avpkt = 0;
double probability = 0.02; double probability = 0.02;
@ -45,8 +45,6 @@ static int red_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
__u32 max_P; __u32 max_P;
struct rtattr *tail; struct rtattr *tail;
memset(&opt, 0, sizeof(opt));
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "limit") == 0) { if (strcmp(*argv, "limit") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -51,17 +51,16 @@ static int get_prob(__u32 *val, const char *arg)
static int sfb_parse_opt(struct qdisc_util *qu, int argc, char **argv, static int sfb_parse_opt(struct qdisc_util *qu, int argc, char **argv,
struct nlmsghdr *n) struct nlmsghdr *n)
{ {
struct tc_sfb_qopt opt; struct tc_sfb_qopt opt = {
.rehash_interval = 600*1000,
.warmup_time = 60*1000,
.penalty_rate = 10,
.penalty_burst = 20,
.increment = (SFB_MAX_PROB + 1000) / 2000,
.decrement = (SFB_MAX_PROB + 10000) / 20000,
};
struct rtattr *tail; struct rtattr *tail;
memset(&opt, 0, sizeof(opt));
opt.rehash_interval = 600*1000;
opt.warmup_time = 60*1000;
opt.penalty_rate = 10;
opt.penalty_burst = 20;
opt.increment = (SFB_MAX_PROB + 1000) / 2000;
opt.decrement = (SFB_MAX_PROB + 10000) / 20000;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "rehash") == 0) { if (strcmp(*argv, "rehash") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -38,14 +38,12 @@ static void explain(void)
static int sfq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) static int sfq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{ {
int ok = 0, red = 0; int ok = 0, red = 0;
struct tc_sfq_qopt_v1 opt; struct tc_sfq_qopt_v1 opt = {};
unsigned int burst = 0; unsigned int burst = 0;
int wlog; int wlog;
unsigned int avpkt = 1000; unsigned int avpkt = 1000;
double probability = 0.02; double probability = 0.02;
memset(&opt, 0, sizeof(opt));
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "quantum") == 0) { if (strcmp(*argv, "quantum") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -39,7 +39,7 @@ static void explain1(const char *arg, const char *val)
static int tbf_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) static int tbf_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{ {
int ok = 0; int ok = 0;
struct tc_tbf_qopt opt; struct tc_tbf_qopt opt = {};
__u32 rtab[256]; __u32 rtab[256];
__u32 ptab[256]; __u32 ptab[256];
unsigned buffer = 0, mtu = 0, mpu = 0, latency = 0; unsigned buffer = 0, mtu = 0, mpu = 0, latency = 0;
@ -49,8 +49,6 @@ static int tbf_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
struct rtattr *tail; struct rtattr *tail;
__u64 rate64 = 0, prate64 = 0; __u64 rate64 = 0, prate64 = 0;
memset(&opt, 0, sizeof(opt));
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "limit") == 0) { if (matches(*argv, "limit") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -133,11 +133,9 @@ reg:
return q; return q;
noexist: noexist:
q = malloc(sizeof(*q)); q = calloc(1, sizeof(*q));
if (q) { if (q) {
q->id = strdup(str);
memset(q, 0, sizeof(*q));
q->id = strcpy(malloc(strlen(str)+1), str);
q->parse_qopt = parse_noqopt; q->parse_qopt = parse_noqopt;
q->print_qopt = print_noqopt; q->print_qopt = print_noqopt;
goto reg; goto reg;
@ -177,9 +175,8 @@ reg:
filter_list = q; filter_list = q;
return q; return q;
noexist: noexist:
q = malloc(sizeof(*q)); q = calloc(1, sizeof(*q));
if (q) { if (q) {
memset(q, 0, sizeof(*q));
strncpy(q->id, str, 15); strncpy(q->id, str, 15);
q->parse_fopt = parse_nofopt; q->parse_fopt = parse_nofopt;
q->print_fopt = print_nofopt; q->print_fopt = print_nofopt;

View File

@ -54,6 +54,10 @@
#define AF_ALG 38 #define AF_ALG 38
#endif #endif
#ifndef EM_BPF
#define EM_BPF 247
#endif
#ifdef HAVE_ELF #ifdef HAVE_ELF
static int bpf_obj_open(const char *path, enum bpf_prog_type type, static int bpf_obj_open(const char *path, enum bpf_prog_type type,
const char *sec, bool verbose); const char *sec, bool verbose);
@ -86,9 +90,8 @@ static int bpf(int cmd, union bpf_attr *attr, unsigned int size)
static int bpf_map_update(int fd, const void *key, const void *value, static int bpf_map_update(int fd, const void *key, const void *value,
uint64_t flags) uint64_t flags)
{ {
union bpf_attr attr; union bpf_attr attr = {};
memset(&attr, 0, sizeof(attr));
attr.map_fd = fd; attr.map_fd = fd;
attr.key = bpf_ptr_to_u64(key); attr.key = bpf_ptr_to_u64(key);
attr.value = bpf_ptr_to_u64(value); attr.value = bpf_ptr_to_u64(value);
@ -109,12 +112,10 @@ static int bpf_parse_string(char *arg, bool from_file, __u16 *bpf_len,
FILE *fp; FILE *fp;
tmp_len = sizeof("4096,") + BPF_MAXINSNS * op_len; tmp_len = sizeof("4096,") + BPF_MAXINSNS * op_len;
tmp_string = malloc(tmp_len); tmp_string = calloc(1, tmp_len);
if (tmp_string == NULL) if (tmp_string == NULL)
return -ENOMEM; return -ENOMEM;
memset(tmp_string, 0, tmp_len);
fp = fopen(arg, "r"); fp = fopen(arg, "r");
if (fp == NULL) { if (fp == NULL) {
perror("Cannot fopen"); perror("Cannot fopen");
@ -243,7 +244,7 @@ static int bpf_map_selfcheck_pinned(int fd, const struct bpf_elf_map *map,
int length) int length)
{ {
char file[PATH_MAX], buff[4096]; char file[PATH_MAX], buff[4096];
struct bpf_elf_map tmp, zero; struct bpf_elf_map tmp = {}, zero = {};
unsigned int val; unsigned int val;
FILE *fp; FILE *fp;
@ -255,7 +256,6 @@ static int bpf_map_selfcheck_pinned(int fd, const struct bpf_elf_map *map,
return -EIO; return -EIO;
} }
memset(&tmp, 0, sizeof(tmp));
while (fgets(buff, sizeof(buff), fp)) { while (fgets(buff, sizeof(buff), fp)) {
if (sscanf(buff, "map_type:\t%u", &val) == 1) if (sscanf(buff, "map_type:\t%u", &val) == 1)
tmp.type = val; tmp.type = val;
@ -274,7 +274,6 @@ static int bpf_map_selfcheck_pinned(int fd, const struct bpf_elf_map *map,
if (!memcmp(&tmp, map, length)) { if (!memcmp(&tmp, map, length)) {
return 0; return 0;
} else { } else {
memset(&zero, 0, sizeof(zero));
/* If kernel doesn't have eBPF-related fdinfo, we cannot do much, /* If kernel doesn't have eBPF-related fdinfo, we cannot do much,
* so just accept it. We know we do have an eBPF fd and in this * so just accept it. We know we do have an eBPF fd and in this
* case, everything is 0. It is guaranteed that no such map exists * case, everything is 0. It is guaranteed that no such map exists
@ -465,7 +464,7 @@ done:
static int bpf_obj_get(const char *pathname) static int bpf_obj_get(const char *pathname)
{ {
union bpf_attr attr; union bpf_attr attr = {};
char tmp[PATH_MAX]; char tmp[PATH_MAX];
if (strlen(pathname) > 2 && pathname[0] == 'm' && if (strlen(pathname) > 2 && pathname[0] == 'm' &&
@ -475,7 +474,6 @@ static int bpf_obj_get(const char *pathname)
pathname = tmp; pathname = tmp;
} }
memset(&attr, 0, sizeof(attr));
attr.pathname = bpf_ptr_to_u64(pathname); attr.pathname = bpf_ptr_to_u64(pathname);
return bpf(BPF_OBJ_GET, &attr, sizeof(attr)); return bpf(BPF_OBJ_GET, &attr, sizeof(attr));
@ -806,9 +804,8 @@ static int bpf_map_create(enum bpf_map_type type, uint32_t size_key,
uint32_t size_value, uint32_t max_elem, uint32_t size_value, uint32_t max_elem,
uint32_t flags) uint32_t flags)
{ {
union bpf_attr attr; union bpf_attr attr = {};
memset(&attr, 0, sizeof(attr));
attr.map_type = type; attr.map_type = type;
attr.key_size = size_key; attr.key_size = size_key;
attr.value_size = size_value; attr.value_size = size_value;
@ -822,9 +819,8 @@ static int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns,
size_t size_insns, const char *license, char *log, size_t size_insns, const char *license, char *log,
size_t size_log) size_t size_log)
{ {
union bpf_attr attr; union bpf_attr attr = {};
memset(&attr, 0, sizeof(attr));
attr.prog_type = type; attr.prog_type = type;
attr.insns = bpf_ptr_to_u64(insns); attr.insns = bpf_ptr_to_u64(insns);
attr.insn_cnt = size_insns / sizeof(struct bpf_insn); attr.insn_cnt = size_insns / sizeof(struct bpf_insn);
@ -841,9 +837,8 @@ static int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns,
static int bpf_obj_pin(int fd, const char *pathname) static int bpf_obj_pin(int fd, const char *pathname)
{ {
union bpf_attr attr; union bpf_attr attr = {};
memset(&attr, 0, sizeof(attr));
attr.pathname = bpf_ptr_to_u64(pathname); attr.pathname = bpf_ptr_to_u64(pathname);
attr.bpf_fd = fd; attr.bpf_fd = fd;
@ -1628,7 +1623,7 @@ static bool bpf_pinning_reserved(uint32_t pinning)
static void bpf_hash_init(struct bpf_elf_ctx *ctx, const char *db_file) static void bpf_hash_init(struct bpf_elf_ctx *ctx, const char *db_file)
{ {
struct bpf_hash_entry *entry; struct bpf_hash_entry *entry;
char subpath[PATH_MAX]; char subpath[PATH_MAX] = {};
uint32_t pinning; uint32_t pinning;
FILE *fp; FILE *fp;
int ret; int ret;
@ -1637,7 +1632,6 @@ static void bpf_hash_init(struct bpf_elf_ctx *ctx, const char *db_file)
if (!fp) if (!fp)
return; return;
memset(subpath, 0, sizeof(subpath));
while ((ret = bpf_read_pin_mapping(fp, &pinning, subpath))) { while ((ret = bpf_read_pin_mapping(fp, &pinning, subpath))) {
if (ret == -1) { if (ret == -1) {
fprintf(stderr, "Database %s is corrupted at: %s\n", fprintf(stderr, "Database %s is corrupted at: %s\n",
@ -1690,7 +1684,8 @@ static void bpf_hash_destroy(struct bpf_elf_ctx *ctx)
static int bpf_elf_check_ehdr(const struct bpf_elf_ctx *ctx) static int bpf_elf_check_ehdr(const struct bpf_elf_ctx *ctx)
{ {
if (ctx->elf_hdr.e_type != ET_REL || if (ctx->elf_hdr.e_type != ET_REL ||
ctx->elf_hdr.e_machine != 0 || (ctx->elf_hdr.e_machine != EM_NONE &&
ctx->elf_hdr.e_machine != EM_BPF) ||
ctx->elf_hdr.e_version != EV_CURRENT) { ctx->elf_hdr.e_version != EV_CURRENT) {
fprintf(stderr, "ELF format error, ELF file not for eBPF?\n"); fprintf(stderr, "ELF format error, ELF file not for eBPF?\n");
return -EINVAL; return -EINVAL;
@ -1864,16 +1859,14 @@ static int
bpf_map_set_send(int fd, struct sockaddr_un *addr, unsigned int addr_len, bpf_map_set_send(int fd, struct sockaddr_un *addr, unsigned int addr_len,
const struct bpf_map_data *aux, unsigned int entries) const struct bpf_map_data *aux, unsigned int entries)
{ {
struct bpf_map_set_msg msg; struct bpf_map_set_msg msg = {
.aux.uds_ver = BPF_SCM_AUX_VER,
.aux.num_ent = entries,
};
int *cmsg_buf, min_fd; int *cmsg_buf, min_fd;
char *amsg_buf; char *amsg_buf;
int i; int i;
memset(&msg, 0, sizeof(msg));
msg.aux.uds_ver = BPF_SCM_AUX_VER;
msg.aux.num_ent = entries;
strncpy(msg.aux.obj_name, aux->obj, sizeof(msg.aux.obj_name)); strncpy(msg.aux.obj_name, aux->obj, sizeof(msg.aux.obj_name));
memcpy(&msg.aux.obj_st, aux->st, sizeof(msg.aux.obj_st)); memcpy(&msg.aux.obj_st, aux->st, sizeof(msg.aux.obj_st));
@ -1947,8 +1940,13 @@ bpf_map_set_recv(int fd, int *fds, struct bpf_map_aux *aux,
int bpf_send_map_fds(const char *path, const char *obj) int bpf_send_map_fds(const char *path, const char *obj)
{ {
struct bpf_elf_ctx *ctx = &__ctx; struct bpf_elf_ctx *ctx = &__ctx;
struct sockaddr_un addr; struct sockaddr_un addr = { .sun_family = AF_UNIX };
struct bpf_map_data bpf_aux; struct bpf_map_data bpf_aux = {
.fds = ctx->map_fds,
.ent = ctx->maps,
.st = &ctx->stat,
.obj = obj,
};
int fd, ret; int fd, ret;
fd = socket(AF_UNIX, SOCK_DGRAM, 0); fd = socket(AF_UNIX, SOCK_DGRAM, 0);
@ -1958,8 +1956,6 @@ int bpf_send_map_fds(const char *path, const char *obj)
return -1; return -1;
} }
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, path, sizeof(addr.sun_path)); strncpy(addr.sun_path, path, sizeof(addr.sun_path));
ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr)); ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
@ -1969,13 +1965,6 @@ int bpf_send_map_fds(const char *path, const char *obj)
return -1; return -1;
} }
memset(&bpf_aux, 0, sizeof(bpf_aux));
bpf_aux.fds = ctx->map_fds;
bpf_aux.ent = ctx->maps;
bpf_aux.st = &ctx->stat;
bpf_aux.obj = obj;
ret = bpf_map_set_send(fd, &addr, sizeof(addr), &bpf_aux, ret = bpf_map_set_send(fd, &addr, sizeof(addr), &bpf_aux,
bpf_maps_count(ctx)); bpf_maps_count(ctx));
if (ret < 0) if (ret < 0)
@ -1990,7 +1979,7 @@ int bpf_send_map_fds(const char *path, const char *obj)
int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux, int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux,
unsigned int entries) unsigned int entries)
{ {
struct sockaddr_un addr; struct sockaddr_un addr = { .sun_family = AF_UNIX };
int fd, ret; int fd, ret;
fd = socket(AF_UNIX, SOCK_DGRAM, 0); fd = socket(AF_UNIX, SOCK_DGRAM, 0);
@ -2000,8 +1989,6 @@ int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux,
return -1; return -1;
} }
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, path, sizeof(addr.sun_path)); strncpy(addr.sun_path, path, sizeof(addr.sun_path));
ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr));

View File

@ -61,21 +61,16 @@ static int tc_class_modify(int cmd, unsigned int flags, int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct tcmsg t; struct tcmsg t;
char buf[4096]; char buf[4096];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)),
.n.nlmsg_flags = NLM_F_REQUEST | flags,
.n.nlmsg_type = cmd,
.t.tcm_family = AF_UNSPEC,
};
struct qdisc_util *q = NULL; struct qdisc_util *q = NULL;
struct tc_estimator est; struct tc_estimator est = {};
char d[16]; char d[16] = {};
char k[16]; char k[16] = {};
memset(&req, 0, sizeof(req));
memset(&est, 0, sizeof(est));
memset(d, 0, sizeof(d));
memset(k, 0, sizeof(k));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
req.t.tcm_family = AF_UNSPEC;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "dev") == 0) { if (strcmp(*argv, "dev") == 0) {
@ -168,9 +163,8 @@ __u32 filter_classid;
static void graph_node_add(__u32 parent_id, __u32 id, void *data, static void graph_node_add(__u32 parent_id, __u32 id, void *data,
int len) int len)
{ {
struct graph_node *node = malloc(sizeof(struct graph_node)); struct graph_node *node = calloc(1, sizeof(struct graph_node));
memset(node, 0, sizeof(*node));
node->id = id; node->id = id;
node->parent_id = parent_id; node->parent_id = parent_id;
@ -225,7 +219,7 @@ static void graph_cls_show(FILE *fp, char *buf, struct hlist_head *root_list,
{ {
struct hlist_node *n, *tmp_cls; struct hlist_node *n, *tmp_cls;
char cls_id_str[256] = {}; char cls_id_str[256] = {};
struct rtattr *tb[TCA_MAX + 1] = {}; struct rtattr *tb[TCA_MAX + 1];
struct qdisc_util *q; struct qdisc_util *q;
char str[100] = {}; char str[100] = {};
@ -310,7 +304,7 @@ int print_class(const struct sockaddr_nl *who,
FILE *fp = (FILE *)arg; FILE *fp = (FILE *)arg;
struct tcmsg *t = NLMSG_DATA(n); struct tcmsg *t = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr *tb[TCA_MAX + 1] = {}; struct rtattr *tb[TCA_MAX + 1];
struct qdisc_util *q; struct qdisc_util *q;
char abuf[256]; char abuf[256];
@ -395,14 +389,10 @@ int print_class(const struct sockaddr_nl *who,
static int tc_class_list(int argc, char **argv) static int tc_class_list(int argc, char **argv)
{ {
struct tcmsg t; struct tcmsg t = { .tcm_family = AF_UNSPEC };
char d[16]; char d[16] = {};
char buf[1024] = {0}; char buf[1024] = {0};
memset(&t, 0, sizeof(t));
t.tcm_family = AF_UNSPEC;
memset(d, 0, sizeof(d));
filter_qdisc = 0; filter_qdisc = 0;
filter_classid = 0; filter_classid = 0;

View File

@ -71,9 +71,8 @@ reg:
return eu; return eu;
noexist: noexist:
eu = malloc(sizeof(*eu)); eu = calloc(1, sizeof(*eu));
if (eu) { if (eu) {
memset(eu, 0, sizeof(*eu));
strncpy(eu->id, name, sizeof(eu->id) - 1); strncpy(eu->id, name, sizeof(eu->id) - 1);
eu->parse_eopt = parse_noeopt; eu->parse_eopt = parse_noeopt;
goto reg; goto reg;
@ -85,7 +84,7 @@ noexist:
int do_exec(int argc, char **argv) int do_exec(int argc, char **argv)
{ {
struct exec_util *eu; struct exec_util *eu;
char kind[16]; char kind[16] = {};
if (argc < 1) { if (argc < 1) {
fprintf(stderr, "No command given, try \"tc exec help\".\n"); fprintf(stderr, "No command given, try \"tc exec help\".\n");
@ -97,7 +96,6 @@ int do_exec(int argc, char **argv)
return 0; return 0;
} }
memset(kind, 0, sizeof(kind));
strncpy(kind, *argv, sizeof(kind) - 1); strncpy(kind, *argv, sizeof(kind) - 1);
eu = get_exec_kind(kind); eu = get_exec_kind(kind);

View File

@ -47,26 +47,20 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv)
struct nlmsghdr n; struct nlmsghdr n;
struct tcmsg t; struct tcmsg t;
char buf[MAX_MSG]; char buf[MAX_MSG];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)),
.n.nlmsg_flags = NLM_F_REQUEST | flags,
.n.nlmsg_type = cmd,
.t.tcm_family = AF_UNSPEC,
};
struct filter_util *q = NULL; struct filter_util *q = NULL;
__u32 prio = 0; __u32 prio = 0;
__u32 protocol = 0; __u32 protocol = 0;
int protocol_set = 0; int protocol_set = 0;
char *fhandle = NULL; char *fhandle = NULL;
char d[16]; char d[16] = {};
char k[16]; char k[16] = {};
struct tc_estimator est; struct tc_estimator est = {};
memset(&req, 0, sizeof(req));
memset(&est, 0, sizeof(est));
memset(d, 0, sizeof(d));
memset(k, 0, sizeof(k));
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
req.t.tcm_family = AF_UNSPEC;
if (cmd == RTM_NEWTFILTER && flags & NLM_F_CREATE) if (cmd == RTM_NEWTFILTER && flags & NLM_F_CREATE)
protocol = htons(ETH_P_ALL); protocol = htons(ETH_P_ALL);
@ -213,7 +207,6 @@ int print_filter(const struct sockaddr_nl *who,
return -1; return -1;
} }
memset(tb, 0, sizeof(tb));
parse_rtattr(tb, TCA_MAX, TCA_RTA(t), len); parse_rtattr(tb, TCA_MAX, TCA_RTA(t), len);
if (tb[TCA_KIND] == NULL) { if (tb[TCA_KIND] == NULL) {
@ -278,16 +271,12 @@ int print_filter(const struct sockaddr_nl *who,
static int tc_filter_list(int argc, char **argv) static int tc_filter_list(int argc, char **argv)
{ {
struct tcmsg t; struct tcmsg t = { .tcm_family = AF_UNSPEC };
char d[16]; char d[16] = {};
__u32 prio = 0; __u32 prio = 0;
__u32 protocol = 0; __u32 protocol = 0;
char *fhandle = NULL; char *fhandle = NULL;
memset(&t, 0, sizeof(t));
t.tcm_family = AF_UNSPEC;
memset(d, 0, sizeof(d));
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "dev") == 0) { if (strcmp(*argv, "dev") == 0) {
NEXT_ARG(); NEXT_ARG();

View File

@ -49,25 +49,19 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)
struct { struct {
struct tc_sizespec szopts; struct tc_sizespec szopts;
__u16 *data; __u16 *data;
} stab; } stab = {};
char d[16]; char d[16] = {};
char k[16]; char k[16] = {};
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct tcmsg t; struct tcmsg t;
char buf[TCA_BUF_MAX]; char buf[TCA_BUF_MAX];
} req; } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)),
memset(&req, 0, sizeof(req)); .n.nlmsg_flags = NLM_F_REQUEST | flags,
memset(&stab, 0, sizeof(stab)); .n.nlmsg_type = cmd,
memset(&est, 0, sizeof(est)); .t.tcm_family = AF_UNSPEC,
memset(&d, 0, sizeof(d)); };
memset(&k, 0, sizeof(k));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
req.t.tcm_family = AF_UNSPEC;
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "dev") == 0) { if (strcmp(*argv, "dev") == 0) {
@ -227,7 +221,6 @@ int print_qdisc(const struct sockaddr_nl *who,
if (filter_ifindex && filter_ifindex != t->tcm_ifindex) if (filter_ifindex && filter_ifindex != t->tcm_ifindex)
return 0; return 0;
memset(tb, 0, sizeof(tb));
parse_rtattr(tb, TCA_MAX, TCA_RTA(t), len); parse_rtattr(tb, TCA_MAX, TCA_RTA(t), len);
if (tb[TCA_KIND] == NULL) { if (tb[TCA_KIND] == NULL) {
@ -287,12 +280,8 @@ int print_qdisc(const struct sockaddr_nl *who,
static int tc_qdisc_list(int argc, char **argv) static int tc_qdisc_list(int argc, char **argv)
{ {
struct tcmsg t; struct tcmsg t = { .tcm_family = AF_UNSPEC };
char d[16]; char d[16] = {};
memset(&t, 0, sizeof(t));
t.tcm_family = AF_UNSPEC;
memset(&d, 0, sizeof(d));
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "dev") == 0) { if (strcmp(*argv, "dev") == 0) {

View File

@ -53,9 +53,7 @@ int parse_size_table(int *argcp, char ***argvp, struct tc_sizespec *sp)
{ {
char **argv = *argvp; char **argv = *argvp;
int argc = *argcp; int argc = *argcp;
struct tc_sizespec s; struct tc_sizespec s = {};
memset(&s, 0, sizeof(s));
NEXT_ARG(); NEXT_ARG();
if (matches(*argv, "help") == 0) { if (matches(*argv, "help") == 0) {

View File

@ -580,10 +580,9 @@ void print_tcstats_attr(FILE *fp, struct rtattr *tb[], char *prefix, struct rtat
} }
/* backward compatibility */ /* backward compatibility */
if (tb[TCA_STATS]) { if (tb[TCA_STATS]) {
struct tc_stats st; struct tc_stats st = {};
/* handle case where kernel returns more/less than we know about */ /* handle case where kernel returns more/less than we know about */
memset(&st, 0, sizeof(st));
memcpy(&st, RTA_DATA(tb[TCA_STATS]), MIN(RTA_PAYLOAD(tb[TCA_STATS]), sizeof(st))); memcpy(&st, RTA_DATA(tb[TCA_STATS]), MIN(RTA_PAYLOAD(tb[TCA_STATS]), sizeof(st)));
fprintf(fp, "%sSent %llu bytes %u pkts (dropped %u, overlimits %u) ", fprintf(fp, "%sSent %llu bytes %u pkts (dropped %u, overlimits %u) ",