[iproute2-next,1/2] macsec: report the offloading mode currently selected
diff mbox series

Message ID 20200120201823.887937-2-antoine.tenart@bootlin.com
State Changes Requested
Delegated to: David Ahern
Headers show
Series
  • macsec: add offloading support
Related show

Commit Message

Antoine Tenart Jan. 20, 2020, 8:18 p.m. UTC
This patch adds support to report the MACsec offloading mode currently
being enabled, which as of now can either be 'off' or 'phy'. This
information is reported through the `ip macsec show` command:

  # ip macsec show
  18: macsec0: protect on validate strict sc off sa off encrypt on send_sci on end_station off scb off replay off
      cipher suite: GCM-AES-128, using ICV length 16
      TXSC: 3e5035b67c860001 on SA 0
          0: PN 1, state on, key 00000000000000000000000000000000
      RXSC: b4969112700f0001, state on
          0: PN 1, state on, key 01000000000000000000000000000000
      offload: phy
  19: macsec1: protect on validate strict sc off sa off encrypt on send_sci on end_station off scb off replay off
      cipher suite: GCM-AES-128, using ICV length 16
      TXSC: 3e5035b67c880001 on SA 0
          1: PN 1, state on, key 00000000000000000000000000000000
      RXSC: b4969112700f0001, state on
          1: PN 1, state on, key 01000000000000000000000000000000
      offload: off

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

Comments

David Ahern Jan. 27, 2020, 4:41 p.m. UTC | #1
On 1/20/20 1:18 PM, Antoine Tenart wrote:
> @@ -997,6 +1002,19 @@ static int process(struct nlmsghdr *n, void *arg)
>  	if (attrs[MACSEC_ATTR_RXSC_LIST])
>  		print_rxsc_list(attrs[MACSEC_ATTR_RXSC_LIST]);
>  
> +	if (attrs[MACSEC_ATTR_OFFLOAD]) {
> +		struct rtattr *attrs_offload[MACSEC_OFFLOAD_ATTR_MAX + 1];
> +		__u8 offload;
> +
> +		parse_rtattr_nested(attrs_offload, MACSEC_OFFLOAD_ATTR_MAX,
> +				    attrs[MACSEC_ATTR_OFFLOAD]);
> +
> +		offload = rta_getattr_u8(attrs_offload[MACSEC_OFFLOAD_ATTR_TYPE]);
> +		print_string(PRINT_ANY, "offload",
> +			     "    offload: %s ", offload_str[offload]);

you should be an accessor around offload_str[offload] to handle a future
change adding a new type.
Antoine Tenart Jan. 29, 2020, 11:12 a.m. UTC | #2
Hello David,

On Mon, Jan 27, 2020 at 09:41:21AM -0700, David Ahern wrote:
> On 1/20/20 1:18 PM, Antoine Tenart wrote:
> > @@ -997,6 +1002,19 @@ static int process(struct nlmsghdr *n, void *arg)
> >  	if (attrs[MACSEC_ATTR_RXSC_LIST])
> >  		print_rxsc_list(attrs[MACSEC_ATTR_RXSC_LIST]);
> >  
> > +	if (attrs[MACSEC_ATTR_OFFLOAD]) {
> > +		struct rtattr *attrs_offload[MACSEC_OFFLOAD_ATTR_MAX + 1];
> > +		__u8 offload;
> > +
> > +		parse_rtattr_nested(attrs_offload, MACSEC_OFFLOAD_ATTR_MAX,
> > +				    attrs[MACSEC_ATTR_OFFLOAD]);
> > +
> > +		offload = rta_getattr_u8(attrs_offload[MACSEC_OFFLOAD_ATTR_TYPE]);
> > +		print_string(PRINT_ANY, "offload",
> > +			     "    offload: %s ", offload_str[offload]);
> 
> you should be an accessor around offload_str[offload] to handle a future
> change adding a new type.

Good idea, I'll do that.

Thanks!
Antoine

Patch
diff mbox series

diff --git a/ip/ipmacsec.c b/ip/ipmacsec.c
index ad6ad7d6b79f..db7202ceb0a7 100644
--- a/ip/ipmacsec.c
+++ b/ip/ipmacsec.c
@@ -31,6 +31,11 @@  static const char * const validate_str[] = {
 	[MACSEC_VALIDATE_STRICT] = "strict",
 };
 
+static const char * const offload_str[] = {
+	[MACSEC_OFFLOAD_OFF] = "off",
+	[MACSEC_OFFLOAD_PHY] = "phy",
+};
+
 struct sci {
 	__u64 sci;
 	__u16 port;
@@ -997,6 +1002,19 @@  static int process(struct nlmsghdr *n, void *arg)
 	if (attrs[MACSEC_ATTR_RXSC_LIST])
 		print_rxsc_list(attrs[MACSEC_ATTR_RXSC_LIST]);
 
+	if (attrs[MACSEC_ATTR_OFFLOAD]) {
+		struct rtattr *attrs_offload[MACSEC_OFFLOAD_ATTR_MAX + 1];
+		__u8 offload;
+
+		parse_rtattr_nested(attrs_offload, MACSEC_OFFLOAD_ATTR_MAX,
+				    attrs[MACSEC_ATTR_OFFLOAD]);
+
+		offload = rta_getattr_u8(attrs_offload[MACSEC_OFFLOAD_ATTR_TYPE]);
+		print_string(PRINT_ANY, "offload",
+			     "    offload: %s ", offload_str[offload]);
+		print_nl();
+	}
+
 	close_json_object();
 
 	return 0;