From 69d1c977b4770e651db6bc498fdca9c3061cef8c Mon Sep 17 00:00:00 2001 From: Jiri Pirko Date: Thu, 13 Jun 2013 16:10:50 +0200 Subject: add flag getters for prefix option Signed-off-by: Jiri Pirko --- include/ndp.h | 3 +++ libndp/libndp.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ utils/ndptool.c | 6 ++++++ 3 files changed, 69 insertions(+) diff --git a/include/ndp.h b/include/ndp.h index 423181d..08d6ad4 100644 --- a/include/ndp.h +++ b/include/ndp.h @@ -127,6 +127,9 @@ struct in6_addr *ndp_msg_opt_prefix(struct ndp_msg *msg, int offset); uint8_t ndp_msg_opt_prefix_len(struct ndp_msg *msg, int offset); uint32_t ndp_msg_opt_prefix_valid_time(struct ndp_msg *msg, int offset); uint32_t ndp_msg_opt_prefix_preferred_time(struct ndp_msg *msg, int offset); +bool ndp_msg_opt_prefix_flag_on_link(struct ndp_msg *msg, int offset); +bool ndp_msg_opt_prefix_flag_auto_addr_conf(struct ndp_msg *msg, int offset); +bool ndp_msg_opt_prefix_flag_router_addr(struct ndp_msg *msg, int offset); uint32_t ndp_msg_opt_mtu(struct ndp_msg *msg, int offset); diff --git a/libndp/libndp.c b/libndp/libndp.c index 20efe90..0600e59 100644 --- a/libndp/libndp.c +++ b/libndp/libndp.c @@ -1265,6 +1265,66 @@ uint32_t ndp_msg_opt_prefix_preferred_time(struct ndp_msg *msg, int offset) return ntohl(pi->nd_opt_pi_preferred_time); } +/** + * ndp_msg_opt_prefix_flag_on_link: + * @msg: message structure + * @offset: in-message offset + * + * Get on-link flag. + * User should use this function only inside ndp_msg_opt_for_each_offset() + * macro loop. + * + * Returns: on-link flag. + **/ +NDP_EXPORT +bool ndp_msg_opt_prefix_flag_on_link(struct ndp_msg *msg, int offset) +{ + struct nd_opt_prefix_info *pi = + ndp_msg_payload_opts_offset(msg, offset); + + return pi->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK; +} + +/** + * ndp_msg_opt_prefix_flag_auto_addr_conf: + * @msg: message structure + * @offset: in-message offset + * + * Get autonomous address-configuration flag. + * User should use this function only inside ndp_msg_opt_for_each_offset() + * macro loop. + * + * Returns: autonomous address-configuration flag. + **/ +NDP_EXPORT +bool ndp_msg_opt_prefix_flag_auto_addr_conf(struct ndp_msg *msg, int offset) +{ + struct nd_opt_prefix_info *pi = + ndp_msg_payload_opts_offset(msg, offset); + + return pi->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO; +} + +/** + * ndp_msg_opt_prefix_flag_router_addr: + * @msg: message structure + * @offset: in-message offset + * + * Get router address flag. + * User should use this function only inside ndp_msg_opt_for_each_offset() + * macro loop. + * + * Returns: router address flag. + **/ +NDP_EXPORT +bool ndp_msg_opt_prefix_flag_router_addr(struct ndp_msg *msg, int offset) +{ + struct nd_opt_prefix_info *pi = + ndp_msg_payload_opts_offset(msg, offset); + + return pi->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_RADDR; +} + /** * ndp_msg_opt_mtu: * @msg: message structure diff --git a/utils/ndptool.c b/utils/ndptool.c index 32b641f..d0764ce 100644 --- a/utils/ndptool.c +++ b/utils/ndptool.c @@ -257,6 +257,12 @@ static int msgrcv_handler_func(struct ndp *ndp, struct ndp_msg *msg, void *priv) pr_out("infinity"); else pr_out("%us", preferred_time); + pr_out(", on_link: %s", + ndp_msg_opt_prefix_flag_on_link(msg, offset) ? "yes" : "no"); + pr_out(", autonomous_addr_conf: %s", + ndp_msg_opt_prefix_flag_auto_addr_conf(msg, offset) ? "yes" : "no"); + pr_out(", router_addr: %s", + ndp_msg_opt_prefix_flag_router_addr(msg, offset) ? "yes" : "no"); pr_out("\n"); } ndp_msg_opt_for_each_offset(offset, msg, NDP_MSG_OPT_MTU) -- cgit v1.2.1