netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Antoine Tenart <antoine.tenart@bootlin.com>
To: dsahern@gmail.com, sd@queasysnail.net
Cc: Antoine Tenart <antoine.tenart@bootlin.com>, netdev@vger.kernel.org
Subject: [PATCH iproute2-next v2 4/4] macsec: add an accessor for validate_str
Date: Tue,  3 Mar 2020 11:36:19 +0100	[thread overview]
Message-ID: <20200303103619.818985-5-antoine.tenart@bootlin.com> (raw)
In-Reply-To: <20200303103619.818985-1-antoine.tenart@bootlin.com>

This patch adds an accessor for the validate_str array, to handle future
changes adding a member.

Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com>
---
 ip/ipmacsec.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/ip/ipmacsec.c b/ip/ipmacsec.c
index 6104a3a5523d..4e500e4e4825 100644
--- a/ip/ipmacsec.c
+++ b/ip/ipmacsec.c
@@ -653,6 +653,14 @@ static const char *cs_id_to_name(__u64 cid)
 	}
 }
 
+static const char *validate_to_str(__u8 validate)
+{
+	if (validate >= ARRAY_SIZE(validate_str))
+		return "(unknown)";
+
+	return validate_str[validate];
+}
+
 static const char *offload_to_str(__u8 offload)
 {
 	if (offload >= ARRAY_SIZE(offload_str))
@@ -669,7 +677,7 @@ static void print_attrs(struct rtattr *attrs[])
 		__u8 val = rta_getattr_u8(attrs[MACSEC_SECY_ATTR_VALIDATE]);
 
 		print_string(PRINT_ANY, "validate",
-			     "validate %s ", validate_str[val]);
+			     "validate %s ", validate_to_str(val));
 	}
 
 	print_flag(attrs, "sc", MACSEC_RXSC_ATTR_ACTIVE);
@@ -1208,7 +1216,7 @@ static void macsec_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 		print_string(PRINT_ANY,
 			     "validation",
 			     "validate %s ",
-			     validate_str[val]);
+			     validate_to_str(val));
 	}
 
 	const char *inc_sci, *es, *replay;
-- 
2.24.1


  parent reply	other threads:[~2020-03-03 10:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-03 10:36 [PATCH iproute2-next v2 0/4] macsec: add offloading support Antoine Tenart
2020-03-03 10:36 ` [PATCH iproute2-next v2 1/4] macsec: report the offloading mode currently selected Antoine Tenart
2020-03-03 10:36 ` [PATCH iproute2-next v2 2/4] macsec: add support for changing the offloading mode Antoine Tenart
2020-03-03 10:36 ` [PATCH iproute2-next v2 3/4] man: document the ip macsec offload command Antoine Tenart
2020-03-03 10:36 ` Antoine Tenart [this message]
2020-03-04 20:00 ` [PATCH iproute2-next v2 0/4] macsec: add offloading support David Ahern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200303103619.818985-5-antoine.tenart@bootlin.com \
    --to=antoine.tenart@bootlin.com \
    --cc=dsahern@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=sd@queasysnail.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).