#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
-#include <sys/ioctl.h>
+#include <sys/param.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "utils.h"
#include "ll_map.h"
#include "ip_common.h"
+#include "xdp.h"
#include "color.h"
enum {
IPADD_SAVE,
};
-static struct
-{
- int ifindex;
- int family;
- int oneline;
- int showqueue;
- inet_prefix pfx;
- int scope, scopemask;
- int flags, flagmask;
- int up;
- char *label;
- int flushed;
- char *flushb;
- int flushp;
- int flushe;
- int group;
- int master;
- char *kind;
-} filter;
-
+static struct link_filter filter;
static int do_link;
static void usage(void) __attribute__((noreturn));
fprintf(stderr, "Usage: ip address {add|change|replace} IFADDR dev IFNAME [ LIFETIME ]\n");
fprintf(stderr, " [ CONFFLAG-LIST ]\n");
fprintf(stderr, " ip address del IFADDR dev IFNAME [mngtmpaddr]\n");
- fprintf(stderr, " ip address {show|save|flush} [ dev IFNAME ] [ scope SCOPE-ID ]\n");
+ fprintf(stderr, " ip address {save|flush} [ dev IFNAME ] [ scope SCOPE-ID ]\n");
fprintf(stderr, " [ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up]\n");
+ fprintf(stderr, " ip address [ show [ dev IFNAME ] [ scope SCOPE-ID ] [ master DEVICE ]\n");
+ fprintf(stderr, " [ type TYPE ] [ to PREFIX ] [ FLAG-LIST ]\n");
+ fprintf(stderr, " [ label LABEL ] [up] [ vrf NAME ] ]\n");
fprintf(stderr, " ip address {showdump|restore}\n");
fprintf(stderr, "IFADDR := PREFIX | ADDR peer PREFIX\n");
fprintf(stderr, " [ broadcast ADDR ] [ anycast ADDR ]\n");
fprintf(stderr, "CONFFLAG := [ home | nodad | mngtmpaddr | noprefixroute | autojoin ]\n");
fprintf(stderr, "LIFETIME := [ valid_lft LFT ] [ preferred_lft LFT ]\n");
fprintf(stderr, "LFT := forever | SECONDS\n");
+ fprintf(stderr, "TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |\n");
+ fprintf(stderr, " bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan | lowpan |\n");
+ fprintf(stderr, " gre | gretap | ip6gre | ip6gretap | vti | nlmon | can |\n");
+ fprintf(stderr, " bond_slave | ipvlan | geneve | bridge_slave | vrf | hsr | macsec }\n");
exit(-1);
}
fprintf(f, "state %#x ", state);
} else if (brief) {
color_fprintf(f, oper_state_color(state),
- "%-14s ", oper_states[state]);
+ "%-14s ", oper_states[state]);
} else {
fprintf(f, "state ");
color_fprintf(f, oper_state_color(state),
- "%s ", oper_states[state]);
+ "%s ", oper_states[state]);
}
}
int qlen;
if (tb[IFLA_TXQLEN])
- qlen = *(int *)RTA_DATA(tb[IFLA_TXQLEN]);
+ qlen = rta_getattr_u32(tb[IFLA_TXQLEN]);
else {
- struct ifreq ifr;
+ struct ifreq ifr = {};
int s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0)
return;
- memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, rta_getattr_str(tb[IFLA_IFNAME]));
if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) {
fprintf(f, "ioctl(SIOCGIFTXQLEN) failed: %s\n", strerror(errno));
fprintf(f, "mode %s ", link_modes[mode]);
}
-static char *parse_link_kind(struct rtattr *tb)
+static char *parse_link_kind(struct rtattr *tb, bool slave)
{
struct rtattr *linkinfo[IFLA_INFO_MAX+1];
+ int attr = slave ? IFLA_INFO_SLAVE_KIND : IFLA_INFO_KIND;
parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb);
- if (linkinfo[IFLA_INFO_KIND])
- return RTA_DATA(linkinfo[IFLA_INFO_KIND]);
+ if (linkinfo[attr])
+ return RTA_DATA(linkinfo[attr]);
return "";
}
+static int match_link_kind(struct rtattr **tb, const char *kind, bool slave)
+{
+ if (!tb[IFLA_LINKINFO])
+ return -1;
+
+ return strcmp(parse_link_kind(tb[IFLA_LINKINFO], slave), kind);
+}
+
static void print_linktype(FILE *fp, struct rtattr *tb)
{
struct rtattr *linkinfo[IFLA_INFO_MAX+1];
struct link_util *lu;
struct link_util *slave_lu;
- char *kind;
- char *slave_kind;
+ char slave[32];
parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb);
if (linkinfo[IFLA_INFO_KIND]) {
- kind = RTA_DATA(linkinfo[IFLA_INFO_KIND]);
+ const char *kind
+ = rta_getattr_str(linkinfo[IFLA_INFO_KIND]);
fprintf(fp, "%s", _SL_);
fprintf(fp, " %s ", kind);
}
if (linkinfo[IFLA_INFO_SLAVE_KIND]) {
- slave_kind = RTA_DATA(linkinfo[IFLA_INFO_SLAVE_KIND]);
+ const char *slave_kind
+ = rta_getattr_str(linkinfo[IFLA_INFO_SLAVE_KIND]);
fprintf(fp, "%s", _SL_);
fprintf(fp, " %s_slave ", slave_kind);
+ snprintf(slave, sizeof(slave), "%s_slave", slave_kind);
- slave_lu = get_link_slave_kind(slave_kind);
+ slave_lu = get_link_kind(slave);
if (slave_lu && slave_lu->print_opt) {
struct rtattr *attr[slave_lu->maxattr+1], **data = NULL;
static void print_vfinfo(FILE *fp, struct rtattr *vfinfo)
{
struct ifla_vf_mac *vf_mac;
- struct ifla_vf_vlan *vf_vlan;
struct ifla_vf_tx_rate *vf_tx_rate;
- struct ifla_vf_spoofchk *vf_spoofchk;
- struct ifla_vf_link_state *vf_linkstate;
struct rtattr *vf[IFLA_VF_MAX + 1] = {};
- struct rtattr *tmp;
SPRINT_BUF(b1);
parse_rtattr_nested(vf, IFLA_VF_MAX, vfinfo);
vf_mac = RTA_DATA(vf[IFLA_VF_MAC]);
- vf_vlan = RTA_DATA(vf[IFLA_VF_VLAN]);
vf_tx_rate = RTA_DATA(vf[IFLA_VF_TX_RATE]);
- /* Check if the spoof checking vf info type is supported by
- * this kernel.
- */
- tmp = (struct rtattr *)((char *)vf[IFLA_VF_TX_RATE] +
- vf[IFLA_VF_TX_RATE]->rta_len);
-
- if (tmp->rta_type != IFLA_VF_SPOOFCHK)
- vf_spoofchk = NULL;
- else
- vf_spoofchk = RTA_DATA(vf[IFLA_VF_SPOOFCHK]);
-
- if (vf_spoofchk) {
- /* Check if the link state vf info type is supported by
- * this kernel.
- */
- tmp = (struct rtattr *)((char *)vf[IFLA_VF_SPOOFCHK] +
- vf[IFLA_VF_SPOOFCHK]->rta_len);
-
- if (tmp->rta_type != IFLA_VF_LINK_STATE)
- vf_linkstate = NULL;
- else
- vf_linkstate = RTA_DATA(vf[IFLA_VF_LINK_STATE]);
- } else
- vf_linkstate = NULL;
-
fprintf(fp, "%s vf %d MAC %s", _SL_, vf_mac->vf,
ll_addr_n2a((unsigned char *)&vf_mac->mac,
- ETH_ALEN, 0, b1, sizeof(b1)));
- if (vf_vlan->vlan)
- fprintf(fp, ", vlan %d", vf_vlan->vlan);
- if (vf_vlan->qos)
- fprintf(fp, ", qos %d", vf_vlan->qos);
+ ETH_ALEN, 0, b1, sizeof(b1)));
+ if (vf[IFLA_VF_VLAN_LIST]) {
+ struct rtattr *i, *vfvlanlist = vf[IFLA_VF_VLAN_LIST];
+ int rem = RTA_PAYLOAD(vfvlanlist);
+
+ for (i = RTA_DATA(vfvlanlist);
+ RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
+ struct ifla_vf_vlan_info *vf_vlan_info =
+ RTA_DATA(i);
+ SPRINT_BUF(b2);
+
+ if (vf_vlan_info->vlan)
+ fprintf(fp, ", vlan %d", vf_vlan_info->vlan);
+ if (vf_vlan_info->qos)
+ fprintf(fp, ", qos %d", vf_vlan_info->qos);
+ if (vf_vlan_info->vlan_proto &&
+ vf_vlan_info->vlan_proto != htons(ETH_P_8021Q))
+ fprintf(fp, ", vlan protocol %s",
+ ll_proto_n2a(vf_vlan_info->vlan_proto,
+ b2, sizeof(b2)));
+
+ }
+ } else {
+ struct ifla_vf_vlan *vf_vlan = RTA_DATA(vf[IFLA_VF_VLAN]);
+
+ if (vf_vlan->vlan)
+ fprintf(fp, ", vlan %d", vf_vlan->vlan);
+ if (vf_vlan->qos)
+ fprintf(fp, ", qos %d", vf_vlan->qos);
+ }
if (vf_tx_rate->rate)
fprintf(fp, ", tx rate %d (Mbps)", vf_tx_rate->rate);
if (vf_rate->min_tx_rate)
fprintf(fp, ", min_tx_rate %dMbps", vf_rate->min_tx_rate);
}
+ if (vf[IFLA_VF_SPOOFCHK]) {
+ struct ifla_vf_spoofchk *vf_spoofchk =
+ RTA_DATA(vf[IFLA_VF_SPOOFCHK]);
- if (vf_spoofchk && vf_spoofchk->setting != -1) {
- if (vf_spoofchk->setting)
- fprintf(fp, ", spoof checking on");
- else
- fprintf(fp, ", spoof checking off");
+ if (vf_spoofchk->setting != -1)
+ fprintf(fp, ", spoof checking %s",
+ vf_spoofchk->setting ? "on" : "off");
}
- if (vf_linkstate) {
+ if (vf[IFLA_VF_LINK_STATE]) {
+ struct ifla_vf_link_state *vf_linkstate =
+ RTA_DATA(vf[IFLA_VF_LINK_STATE]);
+
if (vf_linkstate->link_state == IFLA_VF_LINK_STATE_AUTO)
fprintf(fp, ", link-state auto");
else if (vf_linkstate->link_state == IFLA_VF_LINK_STATE_ENABLE)
else
fprintf(fp, ", link-state disable");
}
+ if (vf[IFLA_VF_TRUST]) {
+ struct ifla_vf_trust *vf_trust = RTA_DATA(vf[IFLA_VF_TRUST]);
+
+ if (vf_trust->setting != -1)
+ fprintf(fp, ", trust %s",
+ vf_trust->setting ? "on" : "off");
+ }
+ if (vf[IFLA_VF_RSS_QUERY_EN]) {
+ struct ifla_vf_rss_query_en *rss_query =
+ RTA_DATA(vf[IFLA_VF_RSS_QUERY_EN]);
+
+ if (rss_query->setting != -1)
+ fprintf(fp, ", query_rss %s",
+ rss_query->setting ? "on" : "off");
+ }
if (vf[IFLA_VF_STATS] && show_stats)
print_vf_stats64(fp, vf[IFLA_VF_STATS]);
}
-static void print_num(FILE *fp, unsigned int width, uint64_t count)
+void print_num(FILE *fp, unsigned int width, uint64_t count)
{
const char *prefix = "kMGTPE";
const unsigned int base = use_iec ? 1024 : 1000;
}
/* increase value by a factor of 1000/1024 and print
- * if result is something a human can read */
+ * if result is something a human can read
+ */
for (;;) {
powi *= base;
if (count / base < powi)
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) {
fprintf(stderr, "BUG: rta type is %d\n", vfstats->rta_type);
fprintf(fp, " RX: bytes packets mcast bcast %s", _SL_);
fprintf(fp, " ");
- print_num(fp, 10, *(__u64 *)RTA_DATA(vf[IFLA_VF_STATS_RX_BYTES]));
- print_num(fp, 8, *(__u64 *)RTA_DATA(vf[IFLA_VF_STATS_RX_PACKETS]));
- print_num(fp, 7, *(__u64 *)RTA_DATA(vf[IFLA_VF_STATS_MULTICAST]));
- print_num(fp, 7, *(__u64 *)RTA_DATA(vf[IFLA_VF_STATS_BROADCAST]));
+ print_num(fp, 10, rta_getattr_u64(vf[IFLA_VF_STATS_RX_BYTES]));
+ print_num(fp, 8, rta_getattr_u64(vf[IFLA_VF_STATS_RX_PACKETS]));
+ print_num(fp, 7, rta_getattr_u64(vf[IFLA_VF_STATS_MULTICAST]));
+ print_num(fp, 7, rta_getattr_u64(vf[IFLA_VF_STATS_BROADCAST]));
/* TX stats */
fprintf(fp, "%s", _SL_);
fprintf(fp, " TX: bytes packets %s", _SL_);
fprintf(fp, " ");
- print_num(fp, 10, *(__u64 *)RTA_DATA(vf[IFLA_VF_STATS_TX_BYTES]));
- print_num(fp, 8, *(__u64 *)RTA_DATA(vf[IFLA_VF_STATS_TX_PACKETS]));
+ print_num(fp, 10, rta_getattr_u64(vf[IFLA_VF_STATS_TX_BYTES]));
+ print_num(fp, 8, rta_getattr_u64(vf[IFLA_VF_STATS_TX_PACKETS]));
}
static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s,
print_num(fp, 7, s->tx_window_errors);
print_num(fp, 7, s->tx_heartbeat_errors);
if (carrier_changes)
- print_num(fp, 7, *(uint32_t *)RTA_DATA(carrier_changes));
+ print_num(fp, 7, rta_getattr_u32(carrier_changes));
}
}
print_num(fp, 7, s->tx_window_errors);
print_num(fp, 7, s->tx_heartbeat_errors);
if (carrier_changes)
- print_num(fp, 7, *(uint32_t *)RTA_DATA(carrier_changes));
+ print_num(fp, 7, rta_getattr_u32(carrier_changes));
}
}
}
int print_linkinfo_brief(const struct sockaddr_nl *who,
- struct nlmsghdr *n, void *arg)
+ struct nlmsghdr *n, void *arg,
+ struct link_filter *pfilter)
{
FILE *fp = (FILE *)arg;
struct ifinfomsg *ifi = NLMSG_DATA(n);
struct rtattr *tb[IFLA_MAX+1];
int len = n->nlmsg_len;
- char *name;
+ const char *name;
char buf[32] = { 0, };
unsigned int m_flag = 0;
if (len < 0)
return -1;
- if (filter.ifindex && ifi->ifi_index != filter.ifindex)
+ if (!pfilter)
+ pfilter = &filter;
+
+ if (pfilter->ifindex && ifi->ifi_index != pfilter->ifindex)
return -1;
- if (filter.up && !(ifi->ifi_flags&IFF_UP))
+ if (pfilter->up && !(ifi->ifi_flags&IFF_UP))
return -1;
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
if (tb[IFLA_IFNAME] == NULL) {
fprintf(stderr, "BUG: device with ifindex %d has nil ifname\n", ifi->ifi_index);
+ name = "<nil>";
+ } else {
+ name = rta_getattr_str(tb[IFLA_IFNAME]);
}
- if (filter.label &&
- (!filter.family || filter.family == AF_PACKET) &&
- fnmatch(filter.label, RTA_DATA(tb[IFLA_IFNAME]), 0))
+
+ if (pfilter->label &&
+ (!pfilter->family || pfilter->family == AF_PACKET) &&
+ fnmatch(pfilter->label, RTA_DATA(tb[IFLA_IFNAME]), 0))
return -1;
if (tb[IFLA_GROUP]) {
- int group = *(int *)RTA_DATA(tb[IFLA_GROUP]);
+ int group = rta_getattr_u32(tb[IFLA_GROUP]);
- if (filter.group != -1 && group != filter.group)
+ if (pfilter->group != -1 && group != pfilter->group)
return -1;
}
if (tb[IFLA_MASTER]) {
- int master = *(int *)RTA_DATA(tb[IFLA_MASTER]);
+ int master = rta_getattr_u32(tb[IFLA_MASTER]);
- if (filter.master > 0 && master != filter.master)
+ if (pfilter->master > 0 && master != pfilter->master)
return -1;
- } else if (filter.master > 0)
+ } else if (pfilter->master > 0)
return -1;
- if (filter.kind) {
- if (tb[IFLA_LINKINFO]) {
- char *kind = parse_link_kind(tb[IFLA_LINKINFO]);
+ if (pfilter->kind && match_link_kind(tb, pfilter->kind, 0))
+ return -1;
- if (strcmp(kind, filter.kind))
- return -1;
- } else {
- return -1;
- }
- }
+ if (pfilter->slave_kind && match_link_kind(tb, pfilter->slave_kind, 1))
+ return -1;
if (n->nlmsg_type == RTM_DELLINK)
fprintf(fp, "Deleted ");
- name = (char *)(tb[IFLA_IFNAME] ? rta_getattr_str(tb[IFLA_IFNAME]) : "<nil>");
-
if (tb[IFLA_LINK]) {
SPRINT_BUF(b1);
- int iflink = *(int *)RTA_DATA(tb[IFLA_LINK]);
+ int iflink = rta_getattr_u32(tb[IFLA_LINK]);
if (iflink == 0)
snprintf(buf, sizeof(buf), "%s@NONE", name);
if (tb[IFLA_OPERSTATE])
print_operstate(fp, rta_getattr_u8(tb[IFLA_OPERSTATE]));
- if (filter.family == AF_PACKET) {
+ if (pfilter->family == AF_PACKET) {
SPRINT_BUF(b1);
if (tb[IFLA_ADDRESS]) {
color_fprintf(fp, COLOR_MAC, "%s ",
}
}
- if (filter.family == AF_PACKET)
+ if (pfilter->family == AF_PACKET)
print_link_flags(fp, ifi->ifi_flags, m_flag);
- if (filter.family == AF_PACKET)
+ if (pfilter->family == AF_PACKET)
fprintf(fp, "\n");
fflush(fp);
return 0;
}
+static const char *link_events[] = {
+ [IFLA_EVENT_NONE] = "NONE",
+ [IFLA_EVENT_REBOOT] = "REBOOT",
+ [IFLA_EVENT_FEATURES] = "FEATURE CHANGE",
+ [IFLA_EVENT_BONDING_FAILOVER] = "BONDING FAILOVER",
+ [IFLA_EVENT_NOTIFY_PEERS] = "NOTIFY PEERS",
+ [IFLA_EVENT_IGMP_RESEND] = "RESEND IGMP",
+ [IFLA_EVENT_BONDING_OPTIONS] = "BONDING OPTION"
+};
+
+static void print_link_event(FILE *f, __u32 event)
+{
+ if (event >= ARRAY_SIZE(link_events))
+ fprintf(f, "event %d ", event);
+ else {
+ if (event)
+ fprintf(f, "event %s ", link_events[event]);
+ }
+}
+
int print_linkinfo(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg)
{
return 0;
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
- if (tb[IFLA_IFNAME] == NULL) {
+ if (tb[IFLA_IFNAME] == NULL)
fprintf(stderr, "BUG: device with ifindex %d has nil ifname\n", ifi->ifi_index);
- }
+
if (filter.label &&
(!filter.family || filter.family == AF_PACKET) &&
fnmatch(filter.label, RTA_DATA(tb[IFLA_IFNAME]), 0))
return 0;
if (tb[IFLA_GROUP]) {
- int group = *(int *)RTA_DATA(tb[IFLA_GROUP]);
+ int group = rta_getattr_u32(tb[IFLA_GROUP]);
if (filter.group != -1 && group != filter.group)
return -1;
}
if (tb[IFLA_MASTER]) {
- int master = *(int *)RTA_DATA(tb[IFLA_MASTER]);
+ int master = rta_getattr_u32(tb[IFLA_MASTER]);
if (filter.master > 0 && master != filter.master)
return -1;
} else if (filter.master > 0)
return -1;
- if (filter.kind) {
- if (tb[IFLA_LINKINFO]) {
- char *kind = parse_link_kind(tb[IFLA_LINKINFO]);
+ if (filter.kind && match_link_kind(tb, filter.kind, 0))
+ return -1;
- if (strcmp(kind, filter.kind))
- return -1;
- } else {
- return -1;
- }
- }
+ if (filter.slave_kind && match_link_kind(tb, filter.slave_kind, 1))
+ return -1;
if (n->nlmsg_type == RTM_DELLINK)
fprintf(fp, "Deleted ");
fprintf(fp, "%d: ", ifi->ifi_index);
color_fprintf(fp, COLOR_IFNAME, "%s",
- tb[IFLA_IFNAME] ? rta_getattr_str(tb[IFLA_IFNAME]) : "<nil>");
+ tb[IFLA_IFNAME] ? rta_getattr_str(tb[IFLA_IFNAME]) : "<nil>");
if (tb[IFLA_LINK]) {
SPRINT_BUF(b1);
- int iflink = *(int *)RTA_DATA(tb[IFLA_LINK]);
+ int iflink = rta_getattr_u32(tb[IFLA_LINK]);
if (iflink == 0)
fprintf(fp, "@NONE: ");
print_link_flags(fp, ifi->ifi_flags, m_flag);
if (tb[IFLA_MTU])
- fprintf(fp, "mtu %u ", *(int *)RTA_DATA(tb[IFLA_MTU]));
+ fprintf(fp, "mtu %u ", rta_getattr_u32(tb[IFLA_MTU]));
+ if (tb[IFLA_XDP])
+ xdp_dump(fp, tb[IFLA_XDP], do_link, false);
if (tb[IFLA_QDISC])
fprintf(fp, "qdisc %s ", rta_getattr_str(tb[IFLA_QDISC]));
if (tb[IFLA_MASTER]) {
SPRINT_BUF(b1);
- fprintf(fp, "master %s ", ll_idx_n2a(*(int *)RTA_DATA(tb[IFLA_MASTER]), b1));
- }
-
- if (tb[IFLA_PHYS_PORT_NAME])
- fprintf(fp, "portname %s ",
- rta_getattr_str(tb[IFLA_PHYS_PORT_NAME]));
-
- if (tb[IFLA_PHYS_PORT_ID]) {
- SPRINT_BUF(b1);
- fprintf(fp, "portid %s ",
- hexstring_n2a(RTA_DATA(tb[IFLA_PHYS_PORT_ID]),
- RTA_PAYLOAD(tb[IFLA_PHYS_PORT_ID]),
- b1, sizeof(b1)));
- }
-
- if (tb[IFLA_PHYS_SWITCH_ID]) {
- SPRINT_BUF(b1);
- fprintf(fp, "switchid %s ",
- hexstring_n2a(RTA_DATA(tb[IFLA_PHYS_SWITCH_ID]),
- RTA_PAYLOAD(tb[IFLA_PHYS_SWITCH_ID]),
- b1, sizeof(b1)));
+ fprintf(fp, "master %s ", ll_idx_n2a(rta_getattr_u32(tb[IFLA_MASTER]), b1));
}
if (tb[IFLA_OPERSTATE])
if (tb[IFLA_GROUP]) {
SPRINT_BUF(b1);
- int group = *(int *)RTA_DATA(tb[IFLA_GROUP]);
+ int group = rta_getattr_u32(tb[IFLA_GROUP]);
fprintf(fp, "group %s ", rtnl_group_n2a(group, b1, sizeof(b1)));
}
if (filter.showqueue)
print_queuelen(fp, tb);
+ if (tb[IFLA_EVENT])
+ print_link_event(fp, rta_getattr_u32(tb[IFLA_EVENT]));
+
if (!filter.family || filter.family == AF_PACKET || show_details) {
SPRINT_BUF(b1);
fprintf(fp, "%s", _SL_);
if (tb[IFLA_ADDRESS]) {
color_fprintf(fp, COLOR_MAC, "%s",
- ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]),
- RTA_PAYLOAD(tb[IFLA_ADDRESS]),
- ifi->ifi_type,
- b1, sizeof(b1)));
+ ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]),
+ RTA_PAYLOAD(tb[IFLA_ADDRESS]),
+ ifi->ifi_type,
+ b1, sizeof(b1)));
}
if (tb[IFLA_BROADCAST]) {
if (ifi->ifi_flags&IFF_POINTOPOINT)
else
fprintf(fp, " brd ");
color_fprintf(fp, COLOR_MAC, "%s",
- ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]),
- RTA_PAYLOAD(tb[IFLA_BROADCAST]),
- ifi->ifi_type,
- b1, sizeof(b1)));
+ ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]),
+ RTA_PAYLOAD(tb[IFLA_BROADCAST]),
+ ifi->ifi_type,
+ b1, sizeof(b1)));
}
}
if (tb[IFLA_LINK_NETNSID]) {
- int id = *(int *)RTA_DATA(tb[IFLA_LINK_NETNSID]);
+ int id = rta_getattr_u32(tb[IFLA_LINK_NETNSID]);
if (id >= 0)
fprintf(fp, " link-netnsid %d", id);
fprintf(fp, " protodown on ");
}
- if (tb[IFLA_PROMISCUITY] && show_details)
- fprintf(fp, " promiscuity %u ",
- *(int *)RTA_DATA(tb[IFLA_PROMISCUITY]));
+ if (show_details) {
+ if (tb[IFLA_PROMISCUITY])
+ fprintf(fp, " promiscuity %u ",
+ rta_getattr_u32(tb[IFLA_PROMISCUITY]));
+
+ if (tb[IFLA_LINKINFO])
+ print_linktype(fp, tb[IFLA_LINKINFO]);
+
+ if (do_link && tb[IFLA_AF_SPEC])
+ print_af_spec(fp, tb[IFLA_AF_SPEC]);
+
+ if (tb[IFLA_NUM_TX_QUEUES])
+ fprintf(fp, "numtxqueues %u ",
+ rta_getattr_u32(tb[IFLA_NUM_TX_QUEUES]));
- if (tb[IFLA_LINKINFO] && show_details)
- print_linktype(fp, tb[IFLA_LINKINFO]);
+ if (tb[IFLA_NUM_RX_QUEUES])
+ fprintf(fp, "numrxqueues %u ",
+ rta_getattr_u32(tb[IFLA_NUM_RX_QUEUES]));
- if (do_link && tb[IFLA_AF_SPEC] && show_details)
- print_af_spec(fp, tb[IFLA_AF_SPEC]);
+ if (tb[IFLA_GSO_MAX_SIZE])
+ fprintf(fp, "gso_max_size %u ",
+ rta_getattr_u32(tb[IFLA_GSO_MAX_SIZE]));
- if (tb[IFLA_NUM_TX_QUEUES] && show_details)
- fprintf(fp, "numtxqueues %u ", rta_getattr_u32(tb[IFLA_NUM_TX_QUEUES]));
+ if (tb[IFLA_GSO_MAX_SEGS])
+ fprintf(fp, "gso_max_segs %u ",
+ rta_getattr_u32(tb[IFLA_GSO_MAX_SEGS]));
- if (tb[IFLA_NUM_RX_QUEUES] && show_details)
- fprintf(fp, "numrxqueues %u ", rta_getattr_u32(tb[IFLA_NUM_RX_QUEUES]));
+ if (tb[IFLA_PHYS_PORT_NAME])
+ fprintf(fp, "portname %s ",
+ rta_getattr_str(tb[IFLA_PHYS_PORT_NAME]));
+
+ if (tb[IFLA_PHYS_PORT_ID]) {
+ SPRINT_BUF(b1);
+ fprintf(fp, "portid %s ",
+ hexstring_n2a(RTA_DATA(tb[IFLA_PHYS_PORT_ID]),
+ RTA_PAYLOAD(tb[IFLA_PHYS_PORT_ID]),
+ b1, sizeof(b1)));
+ }
+
+ if (tb[IFLA_PHYS_SWITCH_ID]) {
+ SPRINT_BUF(b1);
+ fprintf(fp, "switchid %s ",
+ hexstring_n2a(RTA_DATA(tb[IFLA_PHYS_SWITCH_ID]),
+ RTA_PAYLOAD(tb[IFLA_PHYS_SWITCH_ID]),
+ b1, sizeof(b1)));
+ }
+ }
if ((do_link || show_details) && tb[IFLA_IFALIAS]) {
fprintf(fp, "%s alias %s", _SL_,
rta_getattr_str(tb[IFLA_IFALIAS]));
}
+ if ((do_link || show_details) && tb[IFLA_XDP])
+ xdp_dump(fp, tb[IFLA_XDP], true, true);
+
if (do_link && show_stats) {
fprintf(fp, "%s", _SL_);
__print_link_stats(fp, tb);
ifa->ifa_flags;
}
+/* Mapping from argument to address flag mask */
+struct {
+ const char *name;
+ unsigned long value;
+} ifa_flag_names[] = {
+ { "secondary", IFA_F_SECONDARY },
+ { "temporary", IFA_F_SECONDARY },
+ { "nodad", IFA_F_NODAD },
+ { "optimistic", IFA_F_OPTIMISTIC },
+ { "dadfailed", IFA_F_DADFAILED },
+ { "home", IFA_F_HOMEADDRESS },
+ { "deprecated", IFA_F_DEPRECATED },
+ { "tentative", IFA_F_TENTATIVE },
+ { "permanent", IFA_F_PERMANENT },
+ { "mngtmpaddr", IFA_F_MANAGETEMPADDR },
+ { "noprefixroute", IFA_F_NOPREFIXROUTE },
+ { "autojoin", IFA_F_MCAUTOJOIN },
+ { "stable-privacy", IFA_F_STABLE_PRIVACY },
+};
+
+static void print_ifa_flags(FILE *fp, const struct ifaddrmsg *ifa,
+ unsigned int flags)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(ifa_flag_names); i++) {
+ unsigned long mask = ifa_flag_names[i].value;
+
+ if (mask == IFA_F_PERMANENT) {
+ if (!(flags & mask))
+ fprintf(fp, "dynamic ");
+ } else if (flags & mask) {
+ if (mask == IFA_F_SECONDARY &&
+ ifa->ifa_family == AF_INET6)
+ fprintf(fp, "temporary ");
+ else
+ fprintf(fp, "%s ", ifa_flag_names[i].name);
+ }
+
+ flags &= ~mask;
+ }
+
+ if (flags)
+ fprintf(fp, "flags %02x ", flags);
+
+}
+
+static int get_filter(const char *arg)
+{
+ unsigned int i;
+
+ /* Special cases */
+ if (strcmp(arg, "dynamic") == 0) {
+ filter.flags &= ~IFA_F_PERMANENT;
+ filter.flagmask |= IFA_F_PERMANENT;
+ } else if (strcmp(arg, "primary") == 0) {
+ filter.flags &= ~IFA_F_SECONDARY;
+ filter.flagmask |= IFA_F_SECONDARY;
+ } else if (*arg == '-') {
+ for (i = 0; i < ARRAY_SIZE(ifa_flag_names); i++) {
+ if (strcmp(arg + 1, ifa_flag_names[i].name))
+ continue;
+
+ filter.flags &= ifa_flag_names[i].value;
+ filter.flagmask |= ifa_flag_names[i].value;
+ return 0;
+ }
+
+ return -1;
+ } else {
+ for (i = 0; i < ARRAY_SIZE(ifa_flag_names); i++) {
+ if (strcmp(arg, ifa_flag_names[i].name))
+ continue;
+ filter.flags |= ifa_flag_names[i].value;
+ filter.flagmask |= ifa_flag_names[i].value;
+ return 0;
+ }
+ return -1;
+ }
+
+ return 0;
+}
+
int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
void *arg)
{
FILE *fp = arg;
struct ifaddrmsg *ifa = NLMSG_DATA(n);
int len = n->nlmsg_len;
- int deprecated = 0;
- /* Use local copy of ifa_flags to not interfere with filtering code */
unsigned int ifa_flags;
struct rtattr *rta_tb[IFA_MAX+1];
}
if (filter.pfx.family) {
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]));
if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen))
return 0;
if (rta_tb[IFA_LOCAL]) {
color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s",
- format_host_rta(ifa->ifa_family,
- rta_tb[IFA_LOCAL]));
+ format_host_rta(ifa->ifa_family,
+ rta_tb[IFA_LOCAL]));
if (rta_tb[IFA_ADDRESS] &&
memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]),
- RTA_DATA(rta_tb[IFA_LOCAL]),
- ifa->ifa_family == AF_INET ? 4 : 16)) {
+ RTA_DATA(rta_tb[IFA_LOCAL]),
+ ifa->ifa_family == AF_INET ? 4 : 16)) {
fprintf(fp, " peer ");
color_fprintf(fp, ifa_family_color(ifa->ifa_family),
- "%s", format_host_rta(ifa->ifa_family,
- rta_tb[IFA_ADDRESS]));
+ "%s", format_host_rta(ifa->ifa_family,
+ rta_tb[IFA_ADDRESS]));
}
fprintf(fp, "/%d ", ifa->ifa_prefixlen);
}
if (rta_tb[IFA_BROADCAST]) {
fprintf(fp, "brd ");
color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s ",
- format_host_rta(ifa->ifa_family,
- rta_tb[IFA_BROADCAST]));
+ format_host_rta(ifa->ifa_family,
+ rta_tb[IFA_BROADCAST]));
}
if (rta_tb[IFA_ANYCAST]) {
fprintf(fp, "any ");
color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s ",
- format_host_rta(ifa->ifa_family,
- rta_tb[IFA_ANYCAST]));
+ format_host_rta(ifa->ifa_family,
+ rta_tb[IFA_ANYCAST]));
}
fprintf(fp, "scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1, sizeof(b1)));
- if (ifa_flags & IFA_F_SECONDARY) {
- ifa_flags &= ~IFA_F_SECONDARY;
- if (ifa->ifa_family == AF_INET6)
- fprintf(fp, "temporary ");
- else
- fprintf(fp, "secondary ");
- }
- if (ifa_flags & IFA_F_TENTATIVE) {
- ifa_flags &= ~IFA_F_TENTATIVE;
- fprintf(fp, "tentative ");
- }
- if (ifa_flags & IFA_F_DEPRECATED) {
- ifa_flags &= ~IFA_F_DEPRECATED;
- deprecated = 1;
- fprintf(fp, "deprecated ");
- }
- if (ifa_flags & IFA_F_HOMEADDRESS) {
- ifa_flags &= ~IFA_F_HOMEADDRESS;
- fprintf(fp, "home ");
- }
- if (ifa_flags & IFA_F_NODAD) {
- ifa_flags &= ~IFA_F_NODAD;
- fprintf(fp, "nodad ");
- }
- if (ifa_flags & IFA_F_MANAGETEMPADDR) {
- ifa_flags &= ~IFA_F_MANAGETEMPADDR;
- fprintf(fp, "mngtmpaddr ");
- }
- if (ifa_flags & IFA_F_NOPREFIXROUTE) {
- ifa_flags &= ~IFA_F_NOPREFIXROUTE;
- fprintf(fp, "noprefixroute ");
- }
- if (ifa_flags & IFA_F_MCAUTOJOIN) {
- ifa_flags &= ~IFA_F_MCAUTOJOIN;
- fprintf(fp, "autojoin ");
- }
- if (!(ifa_flags & IFA_F_PERMANENT)) {
- fprintf(fp, "dynamic ");
- } else
- ifa_flags &= ~IFA_F_PERMANENT;
- if (ifa_flags & IFA_F_DADFAILED) {
- ifa_flags &= ~IFA_F_DADFAILED;
- fprintf(fp, "dadfailed ");
- }
- if (ifa_flags)
- fprintf(fp, "flags %02x ", ifa_flags);
+
+ print_ifa_flags(fp, ifa, ifa_flags);
+
if (rta_tb[IFA_LABEL])
fprintf(fp, "%s", rta_getattr_str(rta_tb[IFA_LABEL]));
if (rta_tb[IFA_CACHEINFO]) {
if (ci->ifa_prefered == INFINITY_LIFE_TIME)
fprintf(fp, "forever");
else {
- if (deprecated)
+ if (ifa_flags & IFA_F_DEPRECATED)
fprintf(fp, "%dsec", ci->ifa_prefered);
else
fprintf(fp, "%usec", ci->ifa_prefered);
return 0;
}
-struct nlmsg_list {
- struct nlmsg_list *next;
- struct nlmsghdr h;
-};
-
-struct nlmsg_chain {
- struct nlmsg_list *head;
- struct nlmsg_list *tail;
-};
-
static int print_selected_addrinfo(struct ifinfomsg *ifi,
struct nlmsg_list *ainfo, FILE *fp)
{
if (n->nlmsg_type != RTM_NEWADDR)
continue;
- if (n->nlmsg_len < NLMSG_LENGTH(sizeof(ifa)))
+ if (n->nlmsg_len < NLMSG_LENGTH(sizeof(*ifa)))
return -1;
if (ifa->ifa_index != ifi->ifi_index ||
exit(rtnl_from_file(stdin, &restore_handler, NULL));
}
-static void free_nlmsg_chain(struct nlmsg_chain *info)
+void free_nlmsg_chain(struct nlmsg_chain *info)
{
struct nlmsg_list *l, *n;
tb[IFA_LOCAL] = tb[IFA_ADDRESS];
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]));
if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen))
continue;
return 1;
}
+static int iplink_filter_req(struct nlmsghdr *nlh, int reqlen)
+{
+ int err;
+
+ err = addattr32(nlh, reqlen, IFLA_EXT_MASK, RTEXT_FILTER_VF);
+ if (err)
+ return err;
+
+ if (filter.master) {
+ err = addattr32(nlh, reqlen, IFLA_MASTER, filter.master);
+ if (err)
+ return err;
+ }
+
+ if (filter.kind) {
+ struct rtattr *linkinfo;
+
+ linkinfo = addattr_nest(nlh, reqlen, IFLA_LINKINFO);
+
+ err = addattr_l(nlh, reqlen, IFLA_INFO_KIND, filter.kind,
+ strlen(filter.kind));
+ if (err)
+ return err;
+
+ addattr_nest_end(nlh, linkinfo);
+ }
+
+ return 0;
+}
+
+/* fills in linfo with link data and optionally ainfo with address info
+ * caller can walk lists as desired and must call free_nlmsg_chain for
+ * both when done
+ */
+int ip_linkaddr_list(int family, req_filter_fn_t filter_fn,
+ struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo)
+{
+ if (rtnl_wilddump_req_filter_fn(&rth, preferred_family, RTM_GETLINK,
+ filter_fn) < 0) {
+ perror("Cannot send dump request");
+ return 1;
+ }
+
+ if (rtnl_dump_filter(&rth, store_nlmsg, linfo) < 0) {
+ fprintf(stderr, "Dump terminated\n");
+ return 1;
+ }
+
+ if (ainfo) {
+ if (rtnl_wilddump_request(&rth, family, RTM_GETADDR) < 0) {
+ perror("Cannot send dump request");
+ return 1;
+ }
+
+ if (rtnl_dump_filter(&rth, store_nlmsg, ainfo) < 0) {
+ fprintf(stderr, "Dump terminated\n");
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
{
struct nlmsg_chain linfo = { NULL, NULL};
- struct nlmsg_chain ainfo = { NULL, NULL};
+ struct nlmsg_chain _ainfo = { NULL, NULL}, *ainfo = NULL;
struct nlmsg_list *l;
char *filter_dev = NULL;
int no_link = 0;
filter.scope = scope;
} else if (strcmp(*argv, "up") == 0) {
filter.up = 1;
- } else if (strcmp(*argv, "dynamic") == 0) {
- filter.flags &= ~IFA_F_PERMANENT;
- filter.flagmask |= IFA_F_PERMANENT;
- } else if (strcmp(*argv, "permanent") == 0) {
- filter.flags |= IFA_F_PERMANENT;
- filter.flagmask |= IFA_F_PERMANENT;
- } else if (strcmp(*argv, "secondary") == 0 ||
- strcmp(*argv, "temporary") == 0) {
- filter.flags |= IFA_F_SECONDARY;
- filter.flagmask |= IFA_F_SECONDARY;
- } else if (strcmp(*argv, "primary") == 0) {
- filter.flags &= ~IFA_F_SECONDARY;
- filter.flagmask |= IFA_F_SECONDARY;
- } else if (strcmp(*argv, "tentative") == 0) {
- filter.flags |= IFA_F_TENTATIVE;
- filter.flagmask |= IFA_F_TENTATIVE;
- } else if (strcmp(*argv, "-tentative") == 0) {
- filter.flags &= ~IFA_F_TENTATIVE;
- filter.flagmask |= IFA_F_TENTATIVE;
- } else if (strcmp(*argv, "deprecated") == 0) {
- filter.flags |= IFA_F_DEPRECATED;
- filter.flagmask |= IFA_F_DEPRECATED;
- } else if (strcmp(*argv, "-deprecated") == 0) {
- filter.flags &= ~IFA_F_DEPRECATED;
- filter.flagmask |= IFA_F_DEPRECATED;
- } else if (strcmp(*argv, "home") == 0) {
- filter.flags |= IFA_F_HOMEADDRESS;
- filter.flagmask |= IFA_F_HOMEADDRESS;
- } else if (strcmp(*argv, "nodad") == 0) {
- filter.flags |= IFA_F_NODAD;
- filter.flagmask |= IFA_F_NODAD;
- } else if (strcmp(*argv, "mngtmpaddr") == 0) {
- filter.flags |= IFA_F_MANAGETEMPADDR;
- filter.flagmask |= IFA_F_MANAGETEMPADDR;
- } else if (strcmp(*argv, "noprefixroute") == 0) {
- filter.flags |= IFA_F_NOPREFIXROUTE;
- filter.flagmask |= IFA_F_NOPREFIXROUTE;
- } else if (strcmp(*argv, "autojoin") == 0) {
- filter.flags |= IFA_F_MCAUTOJOIN;
- filter.flagmask |= IFA_F_MCAUTOJOIN;
- } else if (strcmp(*argv, "dadfailed") == 0) {
- filter.flags |= IFA_F_DADFAILED;
- filter.flagmask |= IFA_F_DADFAILED;
- } else if (strcmp(*argv, "-dadfailed") == 0) {
- filter.flags &= ~IFA_F_DADFAILED;
- filter.flagmask |= IFA_F_DADFAILED;
+ } else if (get_filter(*argv) == 0) {
+
} else if (strcmp(*argv, "label") == 0) {
NEXT_ARG();
filter.label = *argv;
if (!ifindex)
invarg("Device does not exist\n", *argv);
filter.master = ifindex;
- } else if (do_link && strcmp(*argv, "type") == 0) {
+ } else if (strcmp(*argv, "vrf") == 0) {
+ int ifindex;
+
+ NEXT_ARG();
+ ifindex = ll_name_to_index(*argv);
+ if (!ifindex)
+ invarg("Not a valid VRF name\n", *argv);
+ if (!name_is_vrf(*argv))
+ invarg("Not a valid VRF name\n", *argv);
+ filter.master = ifindex;
+ } else if (strcmp(*argv, "type") == 0) {
+ int soff;
+
NEXT_ARG();
- filter.kind = *argv;
+ soff = strlen(*argv) - strlen("_slave");
+ if (!strcmp(*argv + soff, "_slave")) {
+ (*argv)[soff] = '\0';
+ filter.slave_kind = *argv;
+ } else {
+ filter.kind = *argv;
+ }
} else {
- if (strcmp(*argv, "dev") == 0) {
+ if (strcmp(*argv, "dev") == 0)
NEXT_ARG();
- } else if (matches(*argv, "help") == 0)
+ else if (matches(*argv, "help") == 0)
usage();
if (filter_dev)
duparg2("dev", *argv);
exit(0);
}
- if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETLINK) < 0) {
- perror("Cannot send dump request");
- exit(1);
- }
-
- if (rtnl_dump_filter(&rth, store_nlmsg, &linfo) < 0) {
- fprintf(stderr, "Dump terminated\n");
- exit(1);
- }
-
if (filter.family != AF_PACKET) {
+ ainfo = &_ainfo;
+
if (filter.oneline)
no_link = 1;
+ }
- if (rtnl_wilddump_request(&rth, filter.family, RTM_GETADDR) < 0) {
- perror("Cannot send dump request");
- exit(1);
- }
-
- if (rtnl_dump_filter(&rth, store_nlmsg, &ainfo) < 0) {
- fprintf(stderr, "Dump terminated\n");
- exit(1);
- }
+ if (ip_linkaddr_list(filter.family, iplink_filter_req,
+ &linfo, ainfo) != 0)
+ goto out;
- ipaddr_filter(&linfo, &ainfo);
- }
+ if (filter.family != AF_PACKET)
+ ipaddr_filter(&linfo, ainfo);
for (l = linfo.head; l; l = l->next) {
int res = 0;
struct ifinfomsg *ifi = NLMSG_DATA(&l->h);
if (brief) {
- if (print_linkinfo_brief(NULL, &l->h, stdout) == 0)
+ if (print_linkinfo_brief(NULL, &l->h,
+ stdout, NULL) == 0)
if (filter.family != AF_PACKET)
print_selected_addrinfo(ifi,
- ainfo.head,
+ ainfo->head,
stdout);
} else if (no_link ||
- (res = print_linkinfo(NULL, &l->h, stdout)) >= 0) {
+ (res = print_linkinfo(NULL, &l->h, stdout)) >= 0) {
if (filter.family != AF_PACKET)
print_selected_addrinfo(ifi,
- ainfo.head, stdout);
+ ainfo->head, stdout);
if (res > 0 && !do_link && show_stats)
print_link_stats(stdout, &l->h);
}
}
fflush(stdout);
- free_nlmsg_chain(&ainfo);
+out:
+ if (ainfo)
+ free_nlmsg_chain(ainfo);
free_nlmsg_chain(&linfo);
return 0;
struct nlmsghdr n;
struct ifaddrmsg ifa;
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 *l = NULL;
char *lcl_arg = NULL;
char *valid_lftp = NULL;
char *preferred_lftp = NULL;
- inet_prefix lcl;
+ inet_prefix lcl = {};
inet_prefix peer;
int local_len = 0;
int peer_len = 0;
int scoped = 0;
__u32 preferred_lft = INFINITY_LIFE_TIME;
__u32 valid_lft = INFINITY_LIFE_TIME;
- struct ifa_cacheinfo cinfo;
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) {
if (strcmp(*argv, "peer") == 0 ||
strcmp(*argv, "remote") == 0) {
} else if (strcmp(*argv, "autojoin") == 0) {
ifa_flags |= IFA_F_MCAUTOJOIN;
} else {
- if (strcmp(*argv, "local") == 0) {
+ if (strcmp(*argv, "local") == 0)
NEXT_ARG();
- }
if (matches(*argv, "help") == 0)
usage();
if (local_len)
if (peer_len == 0 && local_len) {
if (cmd == RTM_DELADDR && lcl.family == AF_INET && !(lcl.flags & PREFIXLEN_SPECIFIED)) {
fprintf(stderr,
- "Warning: Executing wildcard deletion to stay compatible with old scripts.\n" \
- " Explicitly specify the prefix length (%s/%d) to avoid this warning.\n" \
- " This special behaviour is likely to disappear in further releases,\n" \
+ "Warning: Executing wildcard deletion to stay compatible with old scripts.\n"
+ " Explicitly specify the prefix length (%s/%d) to avoid this warning.\n"
+ " This special behaviour is likely to disappear in further releases,\n"
" fix your scripts!\n", lcl_arg, local_len*8);
} else {
peer = lcl;
}
if (valid_lftp || preferred_lftp) {
+ struct ifa_cacheinfo cinfo = {};
+
if (!valid_lft) {
fprintf(stderr, "valid_lft is zero\n");
return -1;
return -1;
}
- memset(&cinfo, 0, sizeof(cinfo));
cinfo.ifa_prefered = preferred_lft;
cinfo.ifa_valid = valid_lft;
addattr_l(&req.n, sizeof(req), IFA_CACHEINFO, &cinfo,