mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2026-01-07 01:12:30 +00:00
netlink route attribute cleanup
Use the new helper functions rta_getattr_u* instead of direct cast of RTA_DATA(). Where RTA_DATA() is a structure, then remove the unnecessary cast since RTA_DATA() is void * Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
parent
e37d706b56
commit
9f1370c0e5
@ -172,7 +172,7 @@ static void print_queuelen(FILE *f, struct rtattr *tb[IFLA_MAX + 1])
|
||||
int qlen;
|
||||
|
||||
if (tb[IFLA_TXQLEN])
|
||||
qlen = *(int *)RTA_DATA(tb[IFLA_TXQLEN]);
|
||||
qlen = rta_getattr_u32(tb[IFLA_TXQLEN]);
|
||||
else {
|
||||
struct ifreq ifr = {};
|
||||
int s = socket(AF_INET, SOCK_STREAM, 0);
|
||||
@ -234,13 +234,12 @@ static void print_linktype(FILE *fp, struct rtattr *tb)
|
||||
struct link_util *lu;
|
||||
struct link_util *slave_lu;
|
||||
char slave[32];
|
||||
char *kind;
|
||||
char *slave_kind;
|
||||
|
||||
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);
|
||||
@ -263,7 +262,8 @@ static void print_linktype(FILE *fp, struct rtattr *tb)
|
||||
}
|
||||
|
||||
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);
|
||||
@ -474,18 +474,18 @@ static void print_vf_stats64(FILE *fp, struct rtattr *vfstats)
|
||||
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,
|
||||
@ -551,7 +551,7 @@ 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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -617,7 +617,7 @@ static void print_link_stats32(FILE *fp, const struct rtnl_link_stats *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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -660,7 +660,7 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
|
||||
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;
|
||||
|
||||
@ -677,8 +677,12 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
|
||||
return -1;
|
||||
|
||||
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);
|
||||
name = "<nil>";
|
||||
} else {
|
||||
name = rta_getattr_str(tb[IFLA_IFNAME]);
|
||||
}
|
||||
|
||||
if (filter.label &&
|
||||
(!filter.family || filter.family == AF_PACKET) &&
|
||||
@ -686,14 +690,14 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
|
||||
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)
|
||||
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;
|
||||
@ -709,11 +713,9 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
|
||||
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);
|
||||
@ -782,14 +784,14 @@ int print_linkinfo(const struct sockaddr_nl *who,
|
||||
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;
|
||||
@ -811,7 +813,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
|
||||
|
||||
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: ");
|
||||
@ -830,14 +832,14 @@ int print_linkinfo(const struct sockaddr_nl *who,
|
||||
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]);
|
||||
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));
|
||||
fprintf(fp, "master %s ", ll_idx_n2a(rta_getattr_u32(tb[IFLA_MASTER]), b1));
|
||||
}
|
||||
|
||||
if (tb[IFLA_OPERSTATE])
|
||||
@ -848,7 +850,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
|
||||
|
||||
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)));
|
||||
}
|
||||
@ -882,7 +884,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
|
||||
}
|
||||
|
||||
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);
|
||||
@ -898,7 +900,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
|
||||
if (show_details) {
|
||||
if (tb[IFLA_PROMISCUITY])
|
||||
fprintf(fp, " promiscuity %u ",
|
||||
*(int *)RTA_DATA(tb[IFLA_PROMISCUITY]));
|
||||
rta_getattr_u32(tb[IFLA_PROMISCUITY]));
|
||||
|
||||
if (tb[IFLA_LINKINFO])
|
||||
print_linktype(fp, tb[IFLA_LINKINFO]);
|
||||
|
||||
@ -263,10 +263,10 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
||||
}
|
||||
|
||||
if (tb[IFLA_CAN_STATE]) {
|
||||
int *state = RTA_DATA(tb[IFLA_CAN_STATE]);
|
||||
uint32_t state = rta_getattr_u32(tb[IFLA_CAN_STATE]);
|
||||
|
||||
fprintf(f, "state %s ", *state <= CAN_STATE_MAX ?
|
||||
can_state_names[*state] : "UNKNOWN");
|
||||
fprintf(f, "state %s ", state <= CAN_STATE_MAX ?
|
||||
can_state_names[state] : "UNKNOWN");
|
||||
}
|
||||
|
||||
if (tb[IFLA_CAN_BERR_COUNTER]) {
|
||||
|
||||
@ -89,7 +89,7 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
||||
return 0;
|
||||
|
||||
if (tb[RTA_IIF])
|
||||
iif = *(int *)RTA_DATA(tb[RTA_IIF]);
|
||||
iif = rta_getattr_u32(tb[RTA_IIF]);
|
||||
if (filter.iif && filter.iif != iif)
|
||||
return 0;
|
||||
|
||||
|
||||
@ -84,9 +84,8 @@ int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
||||
fprintf(fp, "autoconf ");
|
||||
|
||||
if (tb[PREFIX_CACHEINFO]) {
|
||||
struct prefix_cacheinfo *pc;
|
||||
|
||||
pc = (struct prefix_cacheinfo *)RTA_DATA(tb[PREFIX_CACHEINFO]);
|
||||
const struct prefix_cacheinfo *pc
|
||||
= RTA_DATA(tb[PREFIX_CACHEINFO]);
|
||||
|
||||
fprintf(fp, "valid %u ", pc->valid_time);
|
||||
fprintf(fp, "preferred %u ", pc->preferred_time);
|
||||
|
||||
17
ip/iproute.c
17
ip/iproute.c
@ -262,7 +262,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
|
||||
int iif = 0;
|
||||
|
||||
if (tb[RTA_IIF])
|
||||
iif = *(int *)RTA_DATA(tb[RTA_IIF]);
|
||||
iif = rta_getattr_u32(tb[RTA_IIF]);
|
||||
if ((iif^filter.iif)&filter.iifmask)
|
||||
return 0;
|
||||
}
|
||||
@ -270,7 +270,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
|
||||
int oif = 0;
|
||||
|
||||
if (tb[RTA_OIF])
|
||||
oif = *(int *)RTA_DATA(tb[RTA_OIF]);
|
||||
oif = rta_getattr_u32(tb[RTA_OIF]);
|
||||
if ((oif^filter.oif)&filter.oifmask)
|
||||
return 0;
|
||||
}
|
||||
@ -278,7 +278,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
|
||||
int mark = 0;
|
||||
|
||||
if (tb[RTA_MARK])
|
||||
mark = *(int *)RTA_DATA(tb[RTA_MARK]);
|
||||
mark = rta_getattr_u32(tb[RTA_MARK]);
|
||||
if ((mark ^ filter.mark) & filter.markmask)
|
||||
return 0;
|
||||
}
|
||||
@ -287,7 +287,7 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
|
||||
r->rtm_dst_len == 0 &&
|
||||
r->rtm_type == RTN_UNREACHABLE &&
|
||||
tb[RTA_PRIORITY] &&
|
||||
*(int *)RTA_DATA(tb[RTA_PRIORITY]) == -1)
|
||||
rta_getattr_u32(tb[RTA_PRIORITY]) == -1)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
@ -417,7 +417,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
||||
format_host(via->rtvia_family, len, via->rtvia_addr));
|
||||
}
|
||||
if (tb[RTA_OIF] && filter.oifmask != -1)
|
||||
fprintf(fp, "dev %s ", ll_index_to_name(*(int *)RTA_DATA(tb[RTA_OIF])));
|
||||
fprintf(fp, "dev %s ", ll_index_to_name(rta_getattr_u32(tb[RTA_OIF])));
|
||||
|
||||
if (table && (table != RT_TABLE_MAIN || show_details > 0) && !filter.tb)
|
||||
fprintf(fp, "table %s ", rtnl_rttable_n2a(table, b1, sizeof(b1)));
|
||||
@ -451,7 +451,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
||||
if (r->rtm_flags & RTNH_F_UNRESOLVED)
|
||||
fprintf(fp, "unresolved ");
|
||||
if (tb[RTA_MARK]) {
|
||||
unsigned int mark = *(unsigned int *)RTA_DATA(tb[RTA_MARK]);
|
||||
unsigned int mark = rta_getattr_u32(tb[RTA_MARK]);
|
||||
|
||||
if (mark) {
|
||||
if (mark >= 16)
|
||||
@ -563,7 +563,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
||||
parse_rtattr(mxrta, RTAX_MAX, RTA_DATA(tb[RTA_METRICS]),
|
||||
RTA_PAYLOAD(tb[RTA_METRICS]));
|
||||
if (mxrta[RTAX_LOCK])
|
||||
mxlock = *(unsigned *)RTA_DATA(mxrta[RTAX_LOCK]);
|
||||
mxlock = rta_getattr_u32(mxrta[RTAX_LOCK]);
|
||||
|
||||
for (i = 2; i <= RTAX_MAX; i++) {
|
||||
__u32 val = 0U;
|
||||
@ -613,7 +613,8 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
||||
}
|
||||
}
|
||||
if (tb[RTA_IIF] && filter.iifmask != -1) {
|
||||
fprintf(fp, " iif %s", ll_index_to_name(*(int *)RTA_DATA(tb[RTA_IIF])));
|
||||
fprintf(fp, " iif %s",
|
||||
ll_index_to_name(rta_getattr_u32(tb[RTA_IIF])));
|
||||
}
|
||||
if (tb[RTA_MULTIPATH]) {
|
||||
struct rtnexthop *nh = RTA_DATA(tb[RTA_MULTIPATH]);
|
||||
|
||||
@ -146,7 +146,7 @@ static void print_encap_ila(FILE *fp, struct rtattr *encap)
|
||||
if (tb[ILA_ATTR_LOCATOR]) {
|
||||
char abuf[ADDR64_BUF_SIZE];
|
||||
|
||||
addr64_n2a(*(__u64 *)RTA_DATA(tb[ILA_ATTR_LOCATOR]),
|
||||
addr64_n2a(rta_getattr_u64(tb[ILA_ATTR_LOCATOR]),
|
||||
abuf, sizeof(abuf));
|
||||
fprintf(fp, " %s ", abuf);
|
||||
}
|
||||
|
||||
19
ip/ipxfrm.c
19
ip/ipxfrm.c
@ -709,7 +709,7 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
|
||||
if (tb[XFRMA_ALG_AEAD]) {
|
||||
struct rtattr *rta = tb[XFRMA_ALG_AEAD];
|
||||
|
||||
xfrm_aead_print((struct xfrm_algo_aead *)RTA_DATA(rta),
|
||||
xfrm_aead_print(RTA_DATA(rta),
|
||||
RTA_PAYLOAD(rta), fp, prefix);
|
||||
}
|
||||
|
||||
@ -769,14 +769,13 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
|
||||
}
|
||||
|
||||
if (tb[XFRMA_COADDR]) {
|
||||
xfrm_address_t *coa;
|
||||
const xfrm_address_t *coa;
|
||||
|
||||
if (prefix)
|
||||
fputs(prefix, fp);
|
||||
fprintf(fp, "coa ");
|
||||
|
||||
coa = (xfrm_address_t *)RTA_DATA(tb[XFRMA_COADDR]);
|
||||
|
||||
coa = RTA_DATA(tb[XFRMA_COADDR]);
|
||||
if (RTA_PAYLOAD(tb[XFRMA_COADDR]) < sizeof(*coa)) {
|
||||
fprintf(fp, "(ERROR truncated)");
|
||||
fprintf(fp, "%s", _SL_);
|
||||
@ -820,7 +819,7 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
|
||||
return;
|
||||
}
|
||||
|
||||
replay = (struct xfrm_replay_state *)RTA_DATA(tb[XFRMA_REPLAY_VAL]);
|
||||
replay = RTA_DATA(tb[XFRMA_REPLAY_VAL]);
|
||||
fprintf(fp, "seq 0x%x, oseq 0x%x, bitmap 0x%08x",
|
||||
replay->seq, replay->oseq, replay->bitmap);
|
||||
fprintf(fp, "%s", _SL_);
|
||||
@ -841,7 +840,7 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
|
||||
}
|
||||
fprintf(fp, "%s", _SL_);
|
||||
|
||||
replay = (struct xfrm_replay_state_esn *)RTA_DATA(tb[XFRMA_REPLAY_ESN_VAL]);
|
||||
replay = RTA_DATA(tb[XFRMA_REPLAY_ESN_VAL]);
|
||||
if (prefix)
|
||||
fputs(prefix, fp);
|
||||
fprintf(fp, " seq-hi 0x%x, seq 0x%x, oseq-hi 0x%0x, oseq 0x%0x",
|
||||
@ -907,7 +906,7 @@ void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,
|
||||
fprintf(fp, "%x", flags);
|
||||
}
|
||||
if (show_stats > 0 && tb[XFRMA_SA_EXTRA_FLAGS]) {
|
||||
__u32 extra_flags = *(__u32 *)RTA_DATA(tb[XFRMA_SA_EXTRA_FLAGS]);
|
||||
__u32 extra_flags = rta_getattr_u32(tb[XFRMA_SA_EXTRA_FLAGS]);
|
||||
|
||||
fprintf(fp, "extra_flag ");
|
||||
XFRM_FLAG_PRINT(fp, extra_flags,
|
||||
@ -944,7 +943,7 @@ void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,
|
||||
if (RTA_PAYLOAD(tb[XFRMA_SEC_CTX]) < sizeof(*sctx))
|
||||
fprintf(fp, "(ERROR truncated)");
|
||||
|
||||
sctx = (struct xfrm_user_sec_ctx *)RTA_DATA(tb[XFRMA_SEC_CTX]);
|
||||
sctx = RTA_DATA(tb[XFRMA_SEC_CTX]);
|
||||
|
||||
fprintf(fp, "%s %s", (char *)(sctx + 1), _SL_);
|
||||
}
|
||||
@ -967,7 +966,7 @@ void xfrm_policy_info_print(struct xfrm_userpolicy_info *xpinfo,
|
||||
if (RTA_PAYLOAD(tb[XFRMA_SEC_CTX]) < sizeof(*sctx))
|
||||
fprintf(fp, "(ERROR truncated)");
|
||||
|
||||
sctx = (struct xfrm_user_sec_ctx *)RTA_DATA(tb[XFRMA_SEC_CTX]);
|
||||
sctx = RTA_DATA(tb[XFRMA_SEC_CTX]);
|
||||
|
||||
fprintf(fp, "%s ", (char *)(sctx + 1));
|
||||
fprintf(fp, "%s", _SL_);
|
||||
@ -1025,7 +1024,7 @@ void xfrm_policy_info_print(struct xfrm_userpolicy_info *xpinfo,
|
||||
if (RTA_PAYLOAD(tb[XFRMA_POLICY_TYPE]) < sizeof(*upt))
|
||||
fprintf(fp, "(ERROR truncated)");
|
||||
|
||||
upt = (struct xfrm_userpolicy_type *)RTA_DATA(tb[XFRMA_POLICY_TYPE]);
|
||||
upt = RTA_DATA(tb[XFRMA_POLICY_TYPE]);
|
||||
fprintf(fp, "%s ", strxf_ptype(upt->type));
|
||||
}
|
||||
|
||||
|
||||
@ -338,6 +338,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
|
||||
char s2[64];
|
||||
const char *local = "any";
|
||||
const char *remote = "any";
|
||||
__u16 prefixlen, type;
|
||||
|
||||
if (!tb)
|
||||
return;
|
||||
@ -398,8 +399,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
|
||||
}
|
||||
|
||||
if (tb[IFLA_IPTUN_6RD_PREFIXLEN] &&
|
||||
*(__u16 *)RTA_DATA(tb[IFLA_IPTUN_6RD_PREFIXLEN])) {
|
||||
__u16 prefixlen = rta_getattr_u16(tb[IFLA_IPTUN_6RD_PREFIXLEN]);
|
||||
(prefixlen = rta_getattr_u16(tb[IFLA_IPTUN_6RD_PREFIXLEN]))) {
|
||||
__u16 relayprefixlen =
|
||||
rta_getattr_u16(tb[IFLA_IPTUN_6RD_RELAY_PREFIXLEN]);
|
||||
__u32 relayprefix =
|
||||
@ -417,8 +417,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
|
||||
}
|
||||
|
||||
if (tb[IFLA_IPTUN_ENCAP_TYPE] &&
|
||||
*(__u16 *)RTA_DATA(tb[IFLA_IPTUN_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
|
||||
__u16 type = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]);
|
||||
(type = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE])) != TUNNEL_ENCAP_NONE) {
|
||||
__u16 flags = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_FLAGS]);
|
||||
__u16 sport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_SPORT]);
|
||||
__u16 dport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_DPORT]);
|
||||
|
||||
@ -95,19 +95,19 @@ get_failed:
|
||||
linkinfo[IFLA_INFO_DATA]);
|
||||
|
||||
if (vtiinfo[IFLA_VTI_IKEY])
|
||||
ikey = *(__u32 *)RTA_DATA(vtiinfo[IFLA_VTI_IKEY]);
|
||||
ikey = rta_getattr_u32(vtiinfo[IFLA_VTI_IKEY]);
|
||||
|
||||
if (vtiinfo[IFLA_VTI_OKEY])
|
||||
okey = *(__u32 *)RTA_DATA(vtiinfo[IFLA_VTI_OKEY]);
|
||||
okey = rta_getattr_u32(vtiinfo[IFLA_VTI_OKEY]);
|
||||
|
||||
if (vtiinfo[IFLA_VTI_LOCAL])
|
||||
saddr = *(__u32 *)RTA_DATA(vtiinfo[IFLA_VTI_LOCAL]);
|
||||
saddr = rta_getattr_u32(vtiinfo[IFLA_VTI_LOCAL]);
|
||||
|
||||
if (vtiinfo[IFLA_VTI_REMOTE])
|
||||
daddr = *(__u32 *)RTA_DATA(vtiinfo[IFLA_VTI_REMOTE]);
|
||||
daddr = rta_getattr_u32(vtiinfo[IFLA_VTI_REMOTE]);
|
||||
|
||||
if (vtiinfo[IFLA_VTI_LINK])
|
||||
link = *(__u8 *)RTA_DATA(vtiinfo[IFLA_VTI_LINK]);
|
||||
link = rta_getattr_u8(vtiinfo[IFLA_VTI_LINK]);
|
||||
}
|
||||
|
||||
while (argc > 0) {
|
||||
@ -196,15 +196,16 @@ get_failed:
|
||||
|
||||
static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
||||
{
|
||||
char s2[64];
|
||||
const char *local = "any";
|
||||
const char *remote = "any";
|
||||
unsigned int link;
|
||||
char s2[64];
|
||||
|
||||
if (!tb)
|
||||
return;
|
||||
|
||||
if (tb[IFLA_VTI_REMOTE]) {
|
||||
unsigned int addr = *(__u32 *)RTA_DATA(tb[IFLA_VTI_REMOTE]);
|
||||
unsigned int addr = rta_getattr_u32(tb[IFLA_VTI_REMOTE]);
|
||||
|
||||
if (addr)
|
||||
remote = format_host(AF_INET, 4, &addr);
|
||||
@ -213,7 +214,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
||||
fprintf(f, "remote %s ", remote);
|
||||
|
||||
if (tb[IFLA_VTI_LOCAL]) {
|
||||
unsigned int addr = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LOCAL]);
|
||||
unsigned int addr = rta_getattr_u32(tb[IFLA_VTI_LOCAL]);
|
||||
|
||||
if (addr)
|
||||
local = format_host(AF_INET, 4, &addr);
|
||||
@ -221,8 +222,8 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
||||
|
||||
fprintf(f, "local %s ", local);
|
||||
|
||||
if (tb[IFLA_VTI_LINK] && *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK])) {
|
||||
unsigned int link = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK]);
|
||||
if (tb[IFLA_VTI_LINK] &&
|
||||
(link = rta_getattr_u32(tb[IFLA_VTI_LINK]))) {
|
||||
const char *n = if_indextoname(link, s2);
|
||||
|
||||
if (n)
|
||||
|
||||
@ -195,11 +195,12 @@ get_failed:
|
||||
|
||||
static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
||||
{
|
||||
char s2[64];
|
||||
const char *local = "any";
|
||||
const char *remote = "any";
|
||||
struct in6_addr saddr;
|
||||
struct in6_addr daddr;
|
||||
unsigned int link;
|
||||
char s2[64];
|
||||
|
||||
if (!tb)
|
||||
return;
|
||||
@ -220,8 +221,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
||||
|
||||
fprintf(f, "local %s ", local);
|
||||
|
||||
if (tb[IFLA_VTI_LINK] && *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK])) {
|
||||
unsigned int link = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LINK]);
|
||||
if (tb[IFLA_VTI_LINK] && (link = rta_getattr_u32(tb[IFLA_VTI_LINK]))) {
|
||||
const char *n = if_indextoname(link, s2);
|
||||
|
||||
if (n)
|
||||
|
||||
@ -160,7 +160,7 @@ static int xfrm_policy_flush_print(const struct sockaddr_nl *who,
|
||||
if (RTA_PAYLOAD(tb[XFRMA_POLICY_TYPE]) < sizeof(*upt))
|
||||
fprintf(fp, "(ERROR truncated)");
|
||||
|
||||
upt = (struct xfrm_userpolicy_type *)RTA_DATA(tb[XFRMA_POLICY_TYPE]);
|
||||
upt = RTA_DATA(tb[XFRMA_POLICY_TYPE]);
|
||||
fprintf(fp, "%s ", strxf_ptype(upt->type));
|
||||
}
|
||||
|
||||
|
||||
@ -505,7 +505,7 @@ int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
|
||||
fprintf(stderr, "too short XFRMA_POLICY_TYPE len\n");
|
||||
return -1;
|
||||
}
|
||||
upt = (struct xfrm_userpolicy_type *)RTA_DATA(tb[XFRMA_POLICY_TYPE]);
|
||||
upt = RTA_DATA(tb[XFRMA_POLICY_TYPE]);
|
||||
ptype = upt->type;
|
||||
}
|
||||
|
||||
@ -529,7 +529,7 @@ int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
|
||||
fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: too short XFRMA_POLICY len\n");
|
||||
return -1;
|
||||
}
|
||||
xpinfo = (struct xfrm_userpolicy_info *)RTA_DATA(tb[XFRMA_POLICY]);
|
||||
xpinfo = RTA_DATA(tb[XFRMA_POLICY]);
|
||||
}
|
||||
|
||||
xfrm_policy_info_print(xpinfo, tb, fp, NULL, NULL);
|
||||
@ -725,7 +725,7 @@ static int xfrm_policy_keep(const struct sockaddr_nl *who,
|
||||
fprintf(stderr, "too short XFRMA_POLICY_TYPE len\n");
|
||||
return -1;
|
||||
}
|
||||
upt = (struct xfrm_userpolicy_type *)RTA_DATA(tb[XFRMA_POLICY_TYPE]);
|
||||
upt = RTA_DATA(tb[XFRMA_POLICY_TYPE]);
|
||||
ptype = upt->type;
|
||||
}
|
||||
|
||||
|
||||
@ -1216,8 +1216,6 @@ static int print_sadinfo(struct nlmsghdr *n, void *arg)
|
||||
__u32 *f = NLMSG_DATA(n);
|
||||
struct rtattr *tb[XFRMA_SAD_MAX+1];
|
||||
struct rtattr *rta;
|
||||
__u32 *cnt;
|
||||
|
||||
int len = n->nlmsg_len;
|
||||
|
||||
len -= NLMSG_LENGTH(sizeof(__u32));
|
||||
@ -1230,9 +1228,11 @@ static int print_sadinfo(struct nlmsghdr *n, void *arg)
|
||||
parse_rtattr(tb, XFRMA_SAD_MAX, rta, len);
|
||||
|
||||
if (tb[XFRMA_SAD_CNT]) {
|
||||
__u32 cnt;
|
||||
|
||||
fprintf(fp, "\t SAD");
|
||||
cnt = (__u32 *)RTA_DATA(tb[XFRMA_SAD_CNT]);
|
||||
fprintf(fp, " count %d", *cnt);
|
||||
cnt = rta_getattr_u32(tb[XFRMA_SAD_CNT]);
|
||||
fprintf(fp, " count %u", cnt);
|
||||
} else {
|
||||
fprintf(fp, "BAD SAD info returned\n");
|
||||
return -1;
|
||||
|
||||
16
misc/ss.c
16
misc/ss.c
@ -2361,9 +2361,9 @@ static void parse_diag_msg(struct nlmsghdr *nlh, struct sockstat *s)
|
||||
|
||||
s->mark = 0;
|
||||
if (tb[INET_DIAG_MARK])
|
||||
s->mark = *(__u32 *) RTA_DATA(tb[INET_DIAG_MARK]);
|
||||
s->mark = rta_getattr_u32(tb[INET_DIAG_MARK]);
|
||||
if (tb[INET_DIAG_PROTOCOL])
|
||||
s->raw_prot = *(__u8 *)RTA_DATA(tb[INET_DIAG_PROTOCOL]);
|
||||
s->raw_prot = rta_getattr_u8(tb[INET_DIAG_PROTOCOL]);
|
||||
else
|
||||
s->raw_prot = 0;
|
||||
|
||||
@ -2386,7 +2386,7 @@ static int inet_show_sock(struct nlmsghdr *nlh,
|
||||
nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
|
||||
|
||||
if (tb[INET_DIAG_PROTOCOL])
|
||||
s->type = *(__u8 *)RTA_DATA(tb[INET_DIAG_PROTOCOL]);
|
||||
s->type = rta_getattr_u8(tb[INET_DIAG_PROTOCOL]);
|
||||
|
||||
inet_stats_print(s);
|
||||
|
||||
@ -2407,13 +2407,13 @@ static int inet_show_sock(struct nlmsghdr *nlh,
|
||||
if (s->local.family == AF_INET6 && tb[INET_DIAG_SKV6ONLY]) {
|
||||
unsigned char v6only;
|
||||
|
||||
v6only = *(__u8 *)RTA_DATA(tb[INET_DIAG_SKV6ONLY]);
|
||||
v6only = rta_getattr_u8(tb[INET_DIAG_SKV6ONLY]);
|
||||
printf(" v6only:%u", v6only);
|
||||
}
|
||||
if (tb[INET_DIAG_SHUTDOWN]) {
|
||||
unsigned char mask;
|
||||
|
||||
mask = *(__u8 *)RTA_DATA(tb[INET_DIAG_SHUTDOWN]);
|
||||
mask = rta_getattr_u8(tb[INET_DIAG_SHUTDOWN]);
|
||||
printf(" %c-%c", mask & 1 ? '-' : '<', mask & 2 ? '-' : '>');
|
||||
}
|
||||
}
|
||||
@ -3039,7 +3039,7 @@ static int unix_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh,
|
||||
if (tb[UNIX_DIAG_SHUTDOWN]) {
|
||||
unsigned char mask;
|
||||
|
||||
mask = *(__u8 *)RTA_DATA(tb[UNIX_DIAG_SHUTDOWN]);
|
||||
mask = rta_getattr_u8(tb[UNIX_DIAG_SHUTDOWN]);
|
||||
printf(" %c-%c", mask & 1 ? '-' : '<', mask & 2 ? '-' : '>');
|
||||
}
|
||||
}
|
||||
@ -3298,7 +3298,7 @@ static int packet_show_sock(const struct sockaddr_nl *addr,
|
||||
}
|
||||
|
||||
if (tb[PACKET_DIAG_UID])
|
||||
stat.uid = *(__u32 *)RTA_DATA(tb[PACKET_DIAG_UID]);
|
||||
stat.uid = rta_getattr_u32(tb[PACKET_DIAG_UID]);
|
||||
|
||||
if (tb[PACKET_DIAG_RX_RING])
|
||||
ring_rx = RTA_DATA(tb[PACKET_DIAG_RX_RING]);
|
||||
@ -3308,7 +3308,7 @@ static int packet_show_sock(const struct sockaddr_nl *addr,
|
||||
|
||||
if (tb[PACKET_DIAG_FANOUT]) {
|
||||
has_fanout = true;
|
||||
fanout = *(uint32_t *)RTA_DATA(tb[PACKET_DIAG_FANOUT]);
|
||||
fanout = rta_getattr_u32(tb[PACKET_DIAG_FANOUT]);
|
||||
}
|
||||
|
||||
if (packet_stats_print(&stat, f))
|
||||
|
||||
@ -164,7 +164,7 @@ static int route_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt,
|
||||
if (tb[TCA_ROUTE4_FROM])
|
||||
fprintf(f, "from %s ", rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_FROM]), b1, sizeof(b1)));
|
||||
if (tb[TCA_ROUTE4_IIF])
|
||||
fprintf(f, "fromif %s", ll_index_to_name(*(int *)RTA_DATA(tb[TCA_ROUTE4_IIF])));
|
||||
fprintf(f, "fromif %s", ll_index_to_name(rta_getattr_u32(tb[TCA_ROUTE4_IIF])));
|
||||
if (tb[TCA_ROUTE4_POLICE])
|
||||
tc_print_police(f, tb[TCA_ROUTE4_POLICE]);
|
||||
if (tb[TCA_ROUTE4_ACT])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user