diff mbox series

[RFC,iproute2-next,04/11] ip: nexthop: parse resilient nexthop group attribute into structure

Message ID 20210929152848.1710552-5-razor@blackwall.org (mailing list archive)
State Superseded
Delegated to: David Ahern
Headers show
Series ip: nexthop: cache nexthops and print routes' nh info | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Nikolay Aleksandrov Sept. 29, 2021, 3:28 p.m. UTC
From: Nikolay Aleksandrov <nikolay@nvidia.com>

Add a structure which describes resilient nexthop groups and parse such
attributes into it.

Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com>
---
 ip/ipnexthop.c | 32 ++++++++++++++++++++++++++++++++
 ip/nh_common.h | 10 ++++++++++
 2 files changed, 42 insertions(+)

Comments

David Ahern Sept. 30, 2021, 3:35 a.m. UTC | #1
On 9/29/21 9:28 AM, Nikolay Aleksandrov wrote:
> diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
> index be8541476fa6..9340d8941277 100644
> --- a/ip/ipnexthop.c
> +++ b/ip/ipnexthop.c
> @@ -272,6 +272,33 @@ static void print_nh_group_type(FILE *fp, const struct rtattr *grp_type_attr)
>  	print_string(PRINT_ANY, "type", "type %s ", nh_group_type_name(type));
>  }
>  
> +static void parse_nh_res_group_rta(const struct rtattr *res_grp_attr,
> +				   struct nha_res_grp *res_grp)
> +{
> +	struct rtattr *tb[NHA_RES_GROUP_MAX + 1];
> +	struct rtattr *rta;
> +
> +	parse_rtattr_nested(tb, NHA_RES_GROUP_MAX, res_grp_attr);
> +
> +	if (tb[NHA_RES_GROUP_BUCKETS])
> +		res_grp->buckets = rta_getattr_u16(tb[NHA_RES_GROUP_BUCKETS]);
> +
> +	if (tb[NHA_RES_GROUP_IDLE_TIMER]) {
> +		rta = tb[NHA_RES_GROUP_IDLE_TIMER];
> +		res_grp->idle_timer = rta_getattr_u32(rta);
> +	}
> +
> +	if (tb[NHA_RES_GROUP_UNBALANCED_TIMER]) {
> +		rta = tb[NHA_RES_GROUP_UNBALANCED_TIMER];
> +		res_grp->unbalanced_timer = rta_getattr_u32(rta);
> +	}
> +
> +	if (tb[NHA_RES_GROUP_UNBALANCED_TIME]) {
> +		rta = tb[NHA_RES_GROUP_UNBALANCED_TIME];
> +		res_grp->unbalanced_time = rta_getattr_u64(rta);
> +	}
> +}
> +
>  static void print_nh_res_group(FILE *fp, const struct rtattr *res_grp_attr)
>  {
>  	struct rtattr *tb[NHA_RES_GROUP_MAX + 1];

similarly here - have print_nh_res_group use the one parse function and
print based on the outcome.
diff mbox series

Patch

diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
index be8541476fa6..9340d8941277 100644
--- a/ip/ipnexthop.c
+++ b/ip/ipnexthop.c
@@ -272,6 +272,33 @@  static void print_nh_group_type(FILE *fp, const struct rtattr *grp_type_attr)
 	print_string(PRINT_ANY, "type", "type %s ", nh_group_type_name(type));
 }
 
+static void parse_nh_res_group_rta(const struct rtattr *res_grp_attr,
+				   struct nha_res_grp *res_grp)
+{
+	struct rtattr *tb[NHA_RES_GROUP_MAX + 1];
+	struct rtattr *rta;
+
+	parse_rtattr_nested(tb, NHA_RES_GROUP_MAX, res_grp_attr);
+
+	if (tb[NHA_RES_GROUP_BUCKETS])
+		res_grp->buckets = rta_getattr_u16(tb[NHA_RES_GROUP_BUCKETS]);
+
+	if (tb[NHA_RES_GROUP_IDLE_TIMER]) {
+		rta = tb[NHA_RES_GROUP_IDLE_TIMER];
+		res_grp->idle_timer = rta_getattr_u32(rta);
+	}
+
+	if (tb[NHA_RES_GROUP_UNBALANCED_TIMER]) {
+		rta = tb[NHA_RES_GROUP_UNBALANCED_TIMER];
+		res_grp->unbalanced_timer = rta_getattr_u32(rta);
+	}
+
+	if (tb[NHA_RES_GROUP_UNBALANCED_TIME]) {
+		rta = tb[NHA_RES_GROUP_UNBALANCED_TIME];
+		res_grp->unbalanced_time = rta_getattr_u64(rta);
+	}
+}
+
 static void print_nh_res_group(FILE *fp, const struct rtattr *res_grp_attr)
 {
 	struct rtattr *tb[NHA_RES_GROUP_MAX + 1];
@@ -408,6 +435,11 @@  static int ipnh_parse_nhmsg(FILE *fp, const struct nhmsg *nhm, int len,
 		       RTA_PAYLOAD(tb[NHA_GROUP]));
 	}
 
+	if (tb[NHA_RES_GROUP]) {
+		parse_nh_res_group_rta(tb[NHA_RES_GROUP], &nhe->nh_res_grp);
+		nhe->nh_has_res_grp = true;
+	}
+
 	nhe->nh_blackhole = !!tb[NHA_BLACKHOLE];
 	nhe->nh_fdb = !!tb[NHA_FDB];
 
diff --git a/ip/nh_common.h b/ip/nh_common.h
index f2ff0e6532d3..8c96f9993562 100644
--- a/ip/nh_common.h
+++ b/ip/nh_common.h
@@ -2,6 +2,13 @@ 
 #ifndef __NH_COMMON_H__
 #define __NH_COMMON_H__ 1
 
+struct nha_res_grp {
+	__u16			buckets;
+	__u32			idle_timer;
+	__u32			unbalanced_timer;
+	__u64			unbalanced_time;
+};
+
 struct nh_entry {
 	__u32			nh_id;
 	__u32			nh_oif;
@@ -26,6 +33,9 @@  struct nh_entry {
 		__u8		_buf[RTA_LENGTH(sizeof(__u16))];
 	}			nh_encap_type;
 
+	bool			nh_has_res_grp;
+	struct nha_res_grp	nh_res_grp;
+
 	int			nh_groups_cnt;
 	struct nexthop_grp	*nh_groups;
 };