aboutsummaryrefslogtreecommitdiffstats
path: root/ip
diff options
context:
space:
mode:
Diffstat (limited to 'ip')
-rw-r--r--ip/Android.mk2
-rw-r--r--ip/ip_common.h3
-rw-r--r--ip/ipaddress.c22
-rw-r--r--ip/ipl2tp.c5
-rw-r--r--ip/iplink.c16
-rw-r--r--ip/iplink_macvlan.c2
-rw-r--r--ip/iplink_macvtap.c2
-rw-r--r--ip/iplink_vlan.c2
-rw-r--r--ip/ipneigh.c2
-rw-r--r--ip/ipntable.c44
-rw-r--r--ip/iproute.c8
-rw-r--r--ip/iprule.c12
-rw-r--r--ip/ipxfrm.c2
-rw-r--r--ip/link_gre.c42
14 files changed, 93 insertions, 71 deletions
diff --git a/ip/Android.mk b/ip/Android.mk
index 1cc6f9b..3307c55 100644
--- a/ip/Android.mk
+++ b/ip/Android.mk
@@ -17,7 +17,7 @@ LOCAL_SHARED_LIBRARIES += libiprouteutil libnetlink
LOCAL_C_INCLUDES := $(KERNEL_HEADERS) external/iproute2/include
-LOCAL_CFLAGS := -O2 -g -W -Wall
+LOCAL_CFLAGS := -O2 -g -Wall -Wstrict-prototypes
include $(BUILD_EXECUTABLE)
diff --git a/ip/ip_common.h b/ip/ip_common.h
index b45c5ee..5fa2cc0 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -1,3 +1,4 @@
+extern int get_operstate(const char *name);
extern int print_linkinfo(const struct sockaddr_nl *who,
struct nlmsghdr *n,
void *arg);
@@ -46,7 +47,7 @@ static inline int rtm_get_table(struct rtmsg *r, struct rtattr **tb)
{
__u32 table = r->rtm_table;
if (tb[RTA_TABLE])
- table = *(__u32*) RTA_DATA(tb[RTA_TABLE]);
+ table = rta_getattr_u32(tb[RTA_TABLE]);
return table;
}
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 8453d1f..c28a986 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -136,6 +136,16 @@ static void print_operstate(FILE *f, __u8 state)
fprintf(f, "state %s ", oper_states[state]);
}
+int get_operstate(const char *name)
+{
+ int i;
+
+ for (i = 0; i < sizeof(oper_states)/sizeof(oper_states[0]); i++)
+ if (strcasecmp(name, oper_states[i]) == 0)
+ return i;
+ return -1;
+}
+
static void print_queuelen(FILE *f, struct rtattr *tb[IFLA_MAX + 1])
{
int qlen;
@@ -150,7 +160,7 @@ static void print_queuelen(FILE *f, struct rtattr *tb[IFLA_MAX + 1])
return;
memset(&ifr, 0, sizeof(ifr));
- strcpy(ifr.ifr_name, (char *)RTA_DATA(tb[IFLA_IFNAME]));
+ strcpy(ifr.ifr_name, rta_getattr_str(tb[IFLA_IFNAME]));
if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) {
fprintf(f, "ioctl(SIOCGIFXQLEN) failed: %s\n", strerror(errno));
close(s);
@@ -392,7 +402,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
fprintf(fp, "Deleted ");
fprintf(fp, "%d: %s", ifi->ifi_index,
- tb[IFLA_IFNAME] ? (char*)RTA_DATA(tb[IFLA_IFNAME]) : "<nil>");
+ tb[IFLA_IFNAME] ? rta_getattr_str(tb[IFLA_IFNAME]) : "<nil>");
if (tb[IFLA_LINK]) {
SPRINT_BUF(b1);
@@ -412,14 +422,14 @@ int print_linkinfo(const struct sockaddr_nl *who,
if (tb[IFLA_MTU])
fprintf(fp, "mtu %u ", *(int*)RTA_DATA(tb[IFLA_MTU]));
if (tb[IFLA_QDISC])
- fprintf(fp, "qdisc %s ", (char*)RTA_DATA(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_OPERSTATE])
- print_operstate(fp, *(__u8 *)RTA_DATA(tb[IFLA_OPERSTATE]));
+ print_operstate(fp, rta_getattr_u8(tb[IFLA_OPERSTATE]));
if (do_link && tb[IFLA_LINKMODE])
print_linkmode(fp, tb[IFLA_LINKMODE]);
@@ -455,7 +465,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
if (do_link && tb[IFLA_IFALIAS])
fprintf(fp,"\n alias %s",
- (const char *) RTA_DATA(tb[IFLA_IFALIAS]));
+ rta_getattr_str(tb[IFLA_IFALIAS]));
if (do_link && show_stats) {
if (tb[IFLA_STATS64])
@@ -660,7 +670,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (ifa_flags)
fprintf(fp, "flags %02x ", ifa_flags);
if (rta_tb[IFA_LABEL])
- fprintf(fp, "%s", (char*)RTA_DATA(rta_tb[IFA_LABEL]));
+ fprintf(fp, "%s", rta_getattr_str(rta_tb[IFA_LABEL]));
if (rta_tb[IFA_CACHEINFO]) {
struct ifa_cacheinfo *ci = RTA_DATA(rta_tb[IFA_CACHEINFO]);
fprintf(fp, "%s", _SL_);
diff --git a/ip/ipl2tp.c b/ip/ipl2tp.c
index 97f98b6..c5683f5 100644
--- a/ip/ipl2tp.c
+++ b/ip/ipl2tp.c
@@ -488,7 +488,7 @@ static void usage(void)
fprintf(stderr, " tunnel_id ID peer_tunnel_id ID\n");
fprintf(stderr, " [ encap { ip | udp } ]\n");
fprintf(stderr, " [ udp_sport PORT ] [ udp_dport PORT ]\n");
- fprintf(stderr, "Usage: ip l2tp add session\n");
+ fprintf(stderr, "Usage: ip l2tp add session [ name NAME ]\n");
fprintf(stderr, " tunnel_id ID\n");
fprintf(stderr, " session_id ID peer_session_id ID\n");
fprintf(stderr, " [ cookie HEXSTR ] [ peer_cookie HEXSTR ]\n");
@@ -524,6 +524,9 @@ static int parse_args(int argc, char **argv, int cmd, struct l2tp_parm *p)
fprintf(stderr, "Unknown tunnel encapsulation.\n");
exit(-1);
}
+ } else if (strcmp(*argv, "name") == 0) {
+ NEXT_ARG();
+ p->ifname = *argv;
} else if (strcmp(*argv, "remote") == 0) {
NEXT_ARG();
p->peer_ip.s_addr = get_addr32(*argv);
diff --git a/ip/iplink.c b/ip/iplink.c
index 8dc089a..447ae3d 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -38,7 +38,7 @@
#define IPLINK_IOCTL_COMPAT 1
#ifndef LIBDIR
-#define LIBDIR "/usr/lib/"
+#define LIBDIR "/usr/lib"
#endif
static void usage(void) __attribute__((noreturn));
@@ -138,9 +138,9 @@ struct link_util *get_link_kind(const char *id)
int get_link_mode(const char *mode)
{
- if (strcmp(mode, "default") == 0)
+ if (strcasecmp(mode, "default") == 0)
return IF_LINK_MODE_DEFAULT;
- if (strcmp(mode, "dormant") == 0)
+ if (strcasecmp(mode, "dormant") == 0)
return IF_LINK_MODE_DORMANT;
return -1;
}
@@ -437,10 +437,18 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
} else if (strcmp(*argv, "mode") == 0) {
int mode;
NEXT_ARG();
- mode = get_link_mode(*argv);
+ mode = get_link_mode(*argv);
if (mode < 0)
invarg("Invalid link mode\n", *argv);
addattr8(&req->n, sizeof(*req), IFLA_LINKMODE, mode);
+ } else if (strcmp(*argv, "state") == 0) {
+ int state;
+ NEXT_ARG();
+ state = get_operstate(*argv);
+ if (state < 0)
+ invarg("Invalid operstate\n", *argv);
+
+ addattr8(&req->n, sizeof(*req), IFLA_OPERSTATE, state);
} else {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
diff --git a/ip/iplink_macvlan.c b/ip/iplink_macvlan.c
index 15022aa..ed0e34b 100644
--- a/ip/iplink_macvlan.c
+++ b/ip/iplink_macvlan.c
@@ -79,7 +79,7 @@ static void macvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]
RTA_PAYLOAD(tb[IFLA_MACVLAN_MODE]) < sizeof(__u32))
return;
- mode = *(__u32 *)RTA_DATA(tb[IFLA_VLAN_ID]);
+ mode = rta_getattr_u32(tb[IFLA_VLAN_ID]);
fprintf(f, " mode %s ",
mode == MACVLAN_MODE_PRIVATE ? "private"
: mode == MACVLAN_MODE_VEPA ? "vepa"
diff --git a/ip/iplink_macvtap.c b/ip/iplink_macvtap.c
index 07aed4e..6c7fe1f 100644
--- a/ip/iplink_macvtap.c
+++ b/ip/iplink_macvtap.c
@@ -76,7 +76,7 @@ static void macvtap_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]
RTA_PAYLOAD(tb[IFLA_MACVLAN_MODE]) < sizeof(__u32))
return;
- mode = *(__u32 *)RTA_DATA(tb[IFLA_VLAN_ID]);
+ mode = rta_getattr_u32(tb[IFLA_VLAN_ID]);
fprintf(f, " mode %s ",
mode == MACVLAN_MODE_PRIVATE ? "private"
: mode == MACVLAN_MODE_VEPA ? "vepa"
diff --git a/ip/iplink_vlan.c b/ip/iplink_vlan.c
index 223feb3..97af8d6 100644
--- a/ip/iplink_vlan.c
+++ b/ip/iplink_vlan.c
@@ -183,7 +183,7 @@ static void vlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
RTA_PAYLOAD(tb[IFLA_VLAN_ID]) < sizeof(__u16))
return;
- fprintf(f, "id %u ", *(__u16 *)RTA_DATA(tb[IFLA_VLAN_ID]));
+ fprintf(f, "id %u ", rta_getattr_u16(tb[IFLA_VLAN_ID]));
if (tb[IFLA_VLAN_FLAGS]) {
if (RTA_PAYLOAD(tb[IFLA_VLAN_FLAGS]) < sizeof(*flags))
diff --git a/ip/ipneigh.c b/ip/ipneigh.c
index 313cc63..93cfba2 100644
--- a/ip/ipneigh.c
+++ b/ip/ipneigh.c
@@ -282,7 +282,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
}
if (tb[NDA_PROBES] && show_stats) {
- __u32 p = *(__u32 *) RTA_DATA(tb[NDA_PROBES]);
+ __u32 p = rta_getattr_u32(tb[NDA_PROBES]);
fprintf(fp, " probes %u", p);
}
diff --git a/ip/ipntable.c b/ip/ipntable.c
index b00d3dc..639f512 100644
--- a/ip/ipntable.c
+++ b/ip/ipntable.c
@@ -376,7 +376,7 @@ int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
n->nlmsg_len - NLMSG_LENGTH(sizeof(*ndtm)));
if (tb[NDTA_NAME]) {
- char *name = RTA_DATA(tb[NDTA_NAME]);
+ const char *name = rta_getattr_str(tb[NDTA_NAME]);
if (strlen(filter.name) > 0 && strcmp(filter.name, name))
return 0;
@@ -386,7 +386,7 @@ int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
RTA_PAYLOAD(tb[NDTA_PARMS]));
if (tpb[NDTPA_IFINDEX]) {
- __u32 ifindex = *(__u32 *)RTA_DATA(tpb[NDTPA_IFINDEX]);
+ __u32 ifindex = rta_getattr_u32(tpb[NDTPA_IFINDEX]);
if (filter.index && filter.index != ifindex)
return 0;
@@ -406,7 +406,7 @@ int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "(%d) ", ndtm->ndtm_family);
if (tb[NDTA_NAME]) {
- char *name = RTA_DATA(tb[NDTA_NAME]);
+ const char *name = rta_getattr_str(tb[NDTA_NAME]);
fprintf(fp, "%s ", name);
}
@@ -418,19 +418,19 @@ int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, " ");
if (tb[NDTA_THRESH1]) {
- __u32 thresh1 = *(__u32 *)RTA_DATA(tb[NDTA_THRESH1]);
+ __u32 thresh1 = rta_getattr_u32(tb[NDTA_THRESH1]);
fprintf(fp, "thresh1 %u ", thresh1);
}
if (tb[NDTA_THRESH2]) {
- __u32 thresh2 = *(__u32 *)RTA_DATA(tb[NDTA_THRESH2]);
+ __u32 thresh2 = rta_getattr_u32(tb[NDTA_THRESH2]);
fprintf(fp, "thresh2 %u ", thresh2);
}
if (tb[NDTA_THRESH3]) {
- __u32 thresh3 = *(__u32 *)RTA_DATA(tb[NDTA_THRESH3]);
+ __u32 thresh3 = rta_getattr_u32(tb[NDTA_THRESH3]);
fprintf(fp, "thresh3 %u ", thresh3);
}
if (tb[NDTA_GC_INTERVAL]) {
- __u64 gc_int = *(__u64 *)RTA_DATA(tb[NDTA_GC_INTERVAL]);
+ __u64 gc_int = rta_getattr_u64(tb[NDTA_GC_INTERVAL]);
fprintf(fp, "gc_int %llu ", gc_int);
}
@@ -469,7 +469,7 @@ int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[NDTA_PARMS]) {
if (tpb[NDTPA_IFINDEX]) {
- __u32 ifindex = *(__u32 *)RTA_DATA(tpb[NDTPA_IFINDEX]);
+ __u32 ifindex = rta_getattr_u32(tpb[NDTPA_IFINDEX]);
fprintf(fp, " ");
fprintf(fp, "dev %s ", ll_index_to_name(ifindex));
@@ -479,19 +479,19 @@ int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, " ");
if (tpb[NDTPA_REFCNT]) {
- __u32 refcnt = *(__u32 *)RTA_DATA(tpb[NDTPA_REFCNT]);
+ __u32 refcnt = rta_getattr_u32(tpb[NDTPA_REFCNT]);
fprintf(fp, "refcnt %u ", refcnt);
}
if (tpb[NDTPA_REACHABLE_TIME]) {
- __u64 reachable = *(__u64 *)RTA_DATA(tpb[NDTPA_REACHABLE_TIME]);
+ __u64 reachable = rta_getattr_u64(tpb[NDTPA_REACHABLE_TIME]);
fprintf(fp, "reachable %llu ", reachable);
}
if (tpb[NDTPA_BASE_REACHABLE_TIME]) {
- __u64 breachable = *(__u64 *)RTA_DATA(tpb[NDTPA_BASE_REACHABLE_TIME]);
+ __u64 breachable = rta_getattr_u64(tpb[NDTPA_BASE_REACHABLE_TIME]);
fprintf(fp, "base_reachable %llu ", breachable);
}
if (tpb[NDTPA_RETRANS_TIME]) {
- __u64 retrans = *(__u64 *)RTA_DATA(tpb[NDTPA_RETRANS_TIME]);
+ __u64 retrans = rta_getattr_u64(tpb[NDTPA_RETRANS_TIME]);
fprintf(fp, "retrans %llu ", retrans);
}
@@ -500,15 +500,15 @@ int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, " ");
if (tpb[NDTPA_GC_STALETIME]) {
- __u64 gc_stale = *(__u64 *)RTA_DATA(tpb[NDTPA_GC_STALETIME]);
+ __u64 gc_stale = rta_getattr_u64(tpb[NDTPA_GC_STALETIME]);
fprintf(fp, "gc_stale %llu ", gc_stale);
}
if (tpb[NDTPA_DELAY_PROBE_TIME]) {
- __u64 delay_probe = *(__u64 *)RTA_DATA(tpb[NDTPA_DELAY_PROBE_TIME]);
+ __u64 delay_probe = rta_getattr_u64(tpb[NDTPA_DELAY_PROBE_TIME]);
fprintf(fp, "delay_probe %llu ", delay_probe);
}
if (tpb[NDTPA_QUEUE_LEN]) {
- __u32 queue = *(__u32 *)RTA_DATA(tpb[NDTPA_QUEUE_LEN]);
+ __u32 queue = rta_getattr_u32(tpb[NDTPA_QUEUE_LEN]);
fprintf(fp, "queue %u ", queue);
}
@@ -517,15 +517,15 @@ int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, " ");
if (tpb[NDTPA_APP_PROBES]) {
- __u32 aprobe = *(__u32 *)RTA_DATA(tpb[NDTPA_APP_PROBES]);
+ __u32 aprobe = rta_getattr_u32(tpb[NDTPA_APP_PROBES]);
fprintf(fp, "app_probes %u ", aprobe);
}
if (tpb[NDTPA_UCAST_PROBES]) {
- __u32 uprobe = *(__u32 *)RTA_DATA(tpb[NDTPA_UCAST_PROBES]);
+ __u32 uprobe = rta_getattr_u32(tpb[NDTPA_UCAST_PROBES]);
fprintf(fp, "ucast_probes %u ", uprobe);
}
if (tpb[NDTPA_MCAST_PROBES]) {
- __u32 mprobe = *(__u32 *)RTA_DATA(tpb[NDTPA_MCAST_PROBES]);
+ __u32 mprobe = rta_getattr_u32(tpb[NDTPA_MCAST_PROBES]);
fprintf(fp, "mcast_probes %u ", mprobe);
}
@@ -534,19 +534,19 @@ int print_ntable(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, " ");
if (tpb[NDTPA_ANYCAST_DELAY]) {
- __u64 anycast_delay = *(__u64 *)RTA_DATA(tpb[NDTPA_ANYCAST_DELAY]);
+ __u64 anycast_delay = rta_getattr_u64(tpb[NDTPA_ANYCAST_DELAY]);
fprintf(fp, "anycast_delay %llu ", anycast_delay);
}
if (tpb[NDTPA_PROXY_DELAY]) {
- __u64 proxy_delay = *(__u64 *)RTA_DATA(tpb[NDTPA_PROXY_DELAY]);
+ __u64 proxy_delay = rta_getattr_u64(tpb[NDTPA_PROXY_DELAY]);
fprintf(fp, "proxy_delay %llu ", proxy_delay);
}
if (tpb[NDTPA_PROXY_QLEN]) {
- __u32 pqueue = *(__u32 *)RTA_DATA(tpb[NDTPA_PROXY_QLEN]);
+ __u32 pqueue = rta_getattr_u32(tpb[NDTPA_PROXY_QLEN]);
fprintf(fp, "proxy_queue %u ", pqueue);
}
if (tpb[NDTPA_LOCKTIME]) {
- __u64 locktime = *(__u64 *)RTA_DATA(tpb[NDTPA_LOCKTIME]);
+ __u64 locktime = rta_getattr_u64(tpb[NDTPA_LOCKTIME]);
fprintf(fp, "locktime %llu ", locktime);
}
diff --git a/ip/iproute.c b/ip/iproute.c
index c97f979..5cd313e 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -227,7 +227,7 @@ int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
if (filter.realmmask) {
__u32 realms = 0;
if (tb[RTA_FLOW])
- realms = *(__u32*)RTA_DATA(tb[RTA_FLOW]);
+ realms = rta_getattr_u32(tb[RTA_FLOW]);
if ((realms^filter.realm)&filter.realmmask)
return 0;
}
@@ -404,7 +404,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
abuf, sizeof(abuf)));
}
if (tb[RTA_PRIORITY])
- fprintf(fp, " metric %d ", *(__u32*)RTA_DATA(tb[RTA_PRIORITY]));
+ fprintf(fp, " metric %u ", rta_getattr_u32(tb[RTA_PRIORITY]));
if (r->rtm_flags & RTNH_F_DEAD)
fprintf(fp, "dead ");
if (r->rtm_flags & RTNH_F_ONLINK)
@@ -424,7 +424,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
}
if (tb[RTA_FLOW] && filter.realmmask != ~0U) {
- __u32 to = *(__u32*)RTA_DATA(tb[RTA_FLOW]);
+ __u32 to = rta_getattr_u32(tb[RTA_FLOW]);
__u32 from = to>>16;
to &= 0xFFFF;
fprintf(fp, "realm%s ", from ? "s" : "");
@@ -589,7 +589,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
abuf, sizeof(abuf)));
}
if (tb[RTA_FLOW]) {
- __u32 to = *(__u32*)RTA_DATA(tb[RTA_FLOW]);
+ __u32 to = rta_getattr_u32(tb[RTA_FLOW]);
__u32 from = to>>16;
to &= 0xFFFF;
fprintf(fp, " realm%s ", from ? "s" : "");
diff --git a/ip/iprule.c b/ip/iprule.c
index f983731..a5fcd43 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -131,23 +131,23 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
__u32 mark = 0, mask = 0;
if (tb[FRA_FWMARK])
- mark = *(__u32*)RTA_DATA(tb[FRA_FWMARK]);
+ mark = rta_getattr_u32(tb[FRA_FWMARK]);
if (tb[FRA_FWMASK] &&
- (mask = *(__u32*)RTA_DATA(tb[FRA_FWMASK])) != 0xFFFFFFFF)
+ (mask = rta_getattr_u32(tb[FRA_FWMASK])) != 0xFFFFFFFF)
fprintf(fp, "fwmark 0x%x/0x%x ", mark, mask);
else
fprintf(fp, "fwmark 0x%x ", mark);
}
if (tb[FRA_IFNAME]) {
- fprintf(fp, "iif %s ", (char*)RTA_DATA(tb[FRA_IFNAME]));
+ fprintf(fp, "iif %s ", rta_getattr_str(tb[FRA_IFNAME]));
if (r->rtm_flags & FIB_RULE_IIF_DETACHED)
fprintf(fp, "[detached] ");
}
if (tb[FRA_OIFNAME]) {
- fprintf(fp, "oif %s ", (char*)RTA_DATA(tb[FRA_OIFNAME]));
+ fprintf(fp, "oif %s ", rta_getattr_str(tb[FRA_OIFNAME]));
if (r->rtm_flags & FIB_RULE_OIF_DETACHED)
fprintf(fp, "[detached] ");
}
@@ -157,7 +157,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "lookup %s ", rtnl_rttable_n2a(table, b1, sizeof(b1)));
if (tb[FRA_FLOW]) {
- __u32 to = *(__u32*)RTA_DATA(tb[FRA_FLOW]);
+ __u32 to = rta_getattr_u32(tb[FRA_FLOW]);
__u32 from = to>>16;
to &= 0xFFFF;
if (from) {
@@ -180,7 +180,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
} else if (r->rtm_type == FR_ACT_GOTO) {
fprintf(fp, "goto ");
if (tb[FRA_GOTO])
- fprintf(fp, "%u", *(__u32 *) RTA_DATA(tb[FRA_GOTO]));
+ fprintf(fp, "%u", rta_getattr_u32(tb[FRA_GOTO]));
else
fprintf(fp, "none");
if (r->rtm_flags & FIB_RULE_UNRESOLVED)
diff --git a/ip/ipxfrm.c b/ip/ipxfrm.c
index adeac60..6be62e0 100644
--- a/ip/ipxfrm.c
+++ b/ip/ipxfrm.c
@@ -809,7 +809,7 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
return;
}
- lastused = *(__u64 *)RTA_DATA(tb[XFRMA_LASTUSED]);
+ lastused = rta_getattr_u64(tb[XFRMA_LASTUSED]);
fprintf(fp, "%s", strxf_time(lastused));
fprintf(fp, "%s", _SL_);
diff --git a/ip/link_gre.c b/ip/link_gre.c
index 5002095..839fb29 100644
--- a/ip/link_gre.c
+++ b/ip/link_gre.c
@@ -98,35 +98,35 @@ get_failed:
linkinfo[IFLA_INFO_DATA]);
if (greinfo[IFLA_GRE_IKEY])
- ikey = *(__u32 *)RTA_DATA(greinfo[IFLA_GRE_IKEY]);
+ ikey = rta_getattr_u32(greinfo[IFLA_GRE_IKEY]);
if (greinfo[IFLA_GRE_OKEY])
- okey = *(__u32 *)RTA_DATA(greinfo[IFLA_GRE_OKEY]);
+ okey = rta_getattr_u32(greinfo[IFLA_GRE_OKEY]);
if (greinfo[IFLA_GRE_IFLAGS])
- iflags = *(__u16 *)RTA_DATA(greinfo[IFLA_GRE_IFLAGS]);
+ iflags = rta_getattr_u16(greinfo[IFLA_GRE_IFLAGS]);
if (greinfo[IFLA_GRE_OFLAGS])
- oflags = *(__u16 *)RTA_DATA(greinfo[IFLA_GRE_OFLAGS]);
+ oflags = rta_getattr_u16(greinfo[IFLA_GRE_OFLAGS]);
if (greinfo[IFLA_GRE_LOCAL])
- saddr = *(__u32 *)RTA_DATA(greinfo[IFLA_GRE_LOCAL]);
+ saddr = rta_getattr_u32(greinfo[IFLA_GRE_LOCAL]);
if (greinfo[IFLA_GRE_REMOTE])
- daddr = *(__u32 *)RTA_DATA(greinfo[IFLA_GRE_REMOTE]);
+ daddr = rta_getattr_u32(greinfo[IFLA_GRE_REMOTE]);
if (greinfo[IFLA_GRE_PMTUDISC])
- pmtudisc = *(__u8 *)RTA_DATA(
+ pmtudisc = rta_getattr_u8(
greinfo[IFLA_GRE_PMTUDISC]);
if (greinfo[IFLA_GRE_TTL])
- ttl = *(__u8 *)RTA_DATA(greinfo[IFLA_GRE_TTL]);
+ ttl = rta_getattr_u8(greinfo[IFLA_GRE_TTL]);
if (greinfo[IFLA_GRE_TOS])
- tos = *(__u8 *)RTA_DATA(greinfo[IFLA_GRE_TOS]);
+ tos = rta_getattr_u8(greinfo[IFLA_GRE_TOS]);
if (greinfo[IFLA_GRE_LINK])
- link = *(__u8 *)RTA_DATA(greinfo[IFLA_GRE_LINK]);
+ link = rta_getattr_u8(greinfo[IFLA_GRE_LINK]);
}
while (argc > 0) {
@@ -279,7 +279,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
return;
if (tb[IFLA_GRE_REMOTE]) {
- unsigned addr = *(__u32 *)RTA_DATA(tb[IFLA_GRE_REMOTE]);
+ unsigned addr = rta_getattr_u32(tb[IFLA_GRE_REMOTE]);
if (addr)
remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
@@ -288,7 +288,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf(f, "remote %s ", remote);
if (tb[IFLA_GRE_LOCAL]) {
- unsigned addr = *(__u32 *)RTA_DATA(tb[IFLA_GRE_LOCAL]);
+ unsigned addr = rta_getattr_u32(tb[IFLA_GRE_LOCAL]);
if (addr)
local = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
@@ -296,8 +296,8 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf(f, "local %s ", local);
- if (tb[IFLA_GRE_LINK] && *(__u32 *)RTA_DATA(tb[IFLA_GRE_LINK])) {
- unsigned link = *(__u32 *)RTA_DATA(tb[IFLA_GRE_LINK]);
+ if (tb[IFLA_GRE_LINK] && rta_getattr_u32(tb[IFLA_GRE_LINK])) {
+ unsigned link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
const char *n = if_indextoname(link, s2);
if (n)
@@ -306,13 +306,13 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
fprintf(f, "dev %u ", link);
}
- if (tb[IFLA_GRE_TTL] && *(__u8 *)RTA_DATA(tb[IFLA_GRE_TTL]))
- fprintf(f, "ttl %d ", *(__u8 *)RTA_DATA(tb[IFLA_GRE_TTL]));
+ if (tb[IFLA_GRE_TTL] && rta_getattr_u8(tb[IFLA_GRE_TTL]))
+ fprintf(f, "ttl %d ", rta_getattr_u8(tb[IFLA_GRE_TTL]));
else
fprintf(f, "ttl inherit ");
- if (tb[IFLA_GRE_TOS] && *(__u8 *)RTA_DATA(tb[IFLA_GRE_TOS])) {
- int tos = *(__u8 *)RTA_DATA(tb[IFLA_GRE_TOS]);
+ if (tb[IFLA_GRE_TOS] && rta_getattr_u8(tb[IFLA_GRE_TOS])) {
+ int tos = rta_getattr_u8(tb[IFLA_GRE_TOS]);
fputs("tos ", f);
if (tos == 1)
@@ -322,14 +322,14 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
}
if (tb[IFLA_GRE_PMTUDISC] &&
- !*(__u8 *)RTA_DATA(tb[IFLA_GRE_PMTUDISC]))
+ !rta_getattr_u8(tb[IFLA_GRE_PMTUDISC]))
fputs("nopmtudisc ", f);
if (tb[IFLA_GRE_IFLAGS])
- iflags = *(__u16 *)RTA_DATA(tb[IFLA_GRE_IFLAGS]);
+ iflags = rta_getattr_u16(tb[IFLA_GRE_IFLAGS]);
if (tb[IFLA_GRE_OFLAGS])
- oflags = *(__u16 *)RTA_DATA(tb[IFLA_GRE_OFLAGS]);
+ oflags = rta_getattr_u16(tb[IFLA_GRE_OFLAGS]);
if ((iflags & GRE_KEY) && tb[IFLA_GRE_IKEY]) {
inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_IKEY]), s2, sizeof(s2));