diff options
Diffstat (limited to 'examples/rtnl/rtnl-route-dump.c')
-rw-r--r-- | examples/rtnl/rtnl-route-dump.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/examples/rtnl/rtnl-route-dump.c b/examples/rtnl/rtnl-route-dump.c index a798515..17da80b 100644 --- a/examples/rtnl/rtnl-route-dump.c +++ b/examples/rtnl/rtnl-route-dump.c @@ -13,6 +13,8 @@ static int data_attr_cb2(const struct nlattr *attr, void *data) { + const struct nlattr **tb = data; + /* skip unsupported attribute in user-space */ if (mnl_attr_type_valid(attr, RTAX_MAX) < 0) return MNL_CB_OK; @@ -21,6 +23,8 @@ static int data_attr_cb2(const struct nlattr *attr, void *data) perror("mnl_attr_validate"); return MNL_CB_ERROR; } + + tb[mnl_attr_get_type(attr)] = attr; return MNL_CB_OK; } @@ -51,6 +55,9 @@ static void attributes_show_ipv4(struct nlattr *tb[]) struct in_addr *addr = mnl_attr_get_payload(tb[RTA_GATEWAY]); printf("gw=%s ", inet_ntoa(*addr)); } + if (tb[RTA_PRIORITY]) { + printf("prio=%u ", mnl_attr_get_u32(tb[RTA_PRIORITY])); + } if (tb[RTA_METRICS]) { int i; struct nlattr *tbx[RTAX_MAX+1] = {}; @@ -64,7 +71,6 @@ static void attributes_show_ipv4(struct nlattr *tb[]) } } } - printf("\n"); } /* like inet_ntoa(), not reentrant */ @@ -102,6 +108,9 @@ static void attributes_show_ipv6(struct nlattr *tb[]) struct in6_addr *addr = mnl_attr_get_payload(tb[RTA_GATEWAY]); printf("gw=%s ", inet6_ntoa(*addr)); } + if (tb[RTA_PRIORITY]) { + printf("prio=%u ", mnl_attr_get_u32(tb[RTA_PRIORITY])); + } if (tb[RTA_METRICS]) { int i; struct nlattr *tbx[RTAX_MAX+1] = {}; @@ -115,7 +124,6 @@ static void attributes_show_ipv6(struct nlattr *tb[]) } } } - printf("\n"); } static int data_ipv4_attr_cb(const struct nlattr *attr, void *data) @@ -135,6 +143,7 @@ static int data_ipv4_attr_cb(const struct nlattr *attr, void *data) case RTA_FLOW: case RTA_PREFSRC: case RTA_GATEWAY: + case RTA_PRIORITY: if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) { perror("mnl_attr_validate"); return MNL_CB_ERROR; @@ -164,6 +173,7 @@ static int data_ipv6_attr_cb(const struct nlattr *attr, void *data) case RTA_TABLE: case RTA_OIF: case RTA_FLOW: + case RTA_PRIORITY: if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) { perror("mnl_attr_validate"); return MNL_CB_ERROR; @@ -175,7 +185,7 @@ static int data_ipv6_attr_cb(const struct nlattr *attr, void *data) case RTA_GATEWAY: if (mnl_attr_validate2(attr, MNL_TYPE_BINARY, sizeof(struct in6_addr)) < 0) { - perror("mnl_attr_validate"); + perror("mnl_attr_validate2"); return MNL_CB_ERROR; } break; @@ -269,7 +279,7 @@ static int data_cb(const struct nlmsghdr *nlh, void *data) * RTM_F_EQUALIZE = 0x400: Multipath equalizer: NI * RTM_F_PREFIX = 0x800: Prefix addresses */ - printf("flags=%x\n", rm->rtm_flags); + printf("flags=%x ", rm->rtm_flags); switch(rm->rtm_family) { case AF_INET: @@ -282,6 +292,7 @@ static int data_cb(const struct nlmsghdr *nlh, void *data) break; } + printf("\n"); return MNL_CB_OK; } @@ -323,7 +334,7 @@ int main(int argc, char *argv[]) portid = mnl_socket_get_portid(nl); if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { - perror("mnl_socket_send"); + perror("mnl_socket_sendto"); exit(EXIT_FAILURE); } |