netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] macsec: Support 32bit PN netlink attribute for XPN links
@ 2020-06-15 15:41 Era Mayflower
  2020-06-16  1:23 ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Era Mayflower @ 2020-06-15 15:41 UTC (permalink / raw)
  To: davem, kuba; +Cc: netdev, linux-kernel, Era Mayflower

Allow using 32bit netlink attribute for packet number when creating or
updating SA in an XPN link.
Now utilities like iproute2's `ip` do not have to know the link type
(XPN or not) when setting the packet number field of an SA.

Signed-off-by: Era Mayflower <mayflowerera@gmail.com>
---
 drivers/net/macsec.c | 95 ++++++++++++++++++++++++++++++++------------
 1 file changed, 69 insertions(+), 26 deletions(-)

diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index e56547bfdac9..7d3c3a38ea81 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -1691,8 +1691,7 @@ static bool validate_add_rxsa(struct nlattr **attrs)
 	if (nla_get_u8(attrs[MACSEC_SA_ATTR_AN]) >= MACSEC_NUM_AN)
 		return false;
 
-	if (attrs[MACSEC_SA_ATTR_PN] &&
-	    *(u64 *)nla_data(attrs[MACSEC_SA_ATTR_PN]) == 0)
+	if (attrs[MACSEC_SA_ATTR_PN] && nla_get_u64(attrs[MACSEC_SA_ATTR_PN]) == 0)
 		return false;
 
 	if (attrs[MACSEC_SA_ATTR_ACTIVE]) {
@@ -1714,7 +1713,6 @@ static int macsec_add_rxsa(struct sk_buff *skb, struct genl_info *info)
 	struct macsec_rx_sc *rx_sc;
 	struct macsec_rx_sa *rx_sa;
 	unsigned char assoc_num;
-	int pn_len;
 	struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
 	struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1];
 	int err;
@@ -1747,12 +1745,26 @@ static int macsec_add_rxsa(struct sk_buff *skb, struct genl_info *info)
 		return -EINVAL;
 	}
 
-	pn_len = secy->xpn ? MACSEC_XPN_PN_LEN : MACSEC_DEFAULT_PN_LEN;
-	if (nla_len(tb_sa[MACSEC_SA_ATTR_PN]) != pn_len) {
-		pr_notice("macsec: nl: add_rxsa: bad pn length: %d != %d\n",
-			  nla_len(tb_sa[MACSEC_SA_ATTR_PN]), pn_len);
-		rtnl_unlock();
-		return -EINVAL;
+	if (tb_sa[MACSEC_SA_ATTR_PN]) {
+		switch (nla_len(tb_sa[MACSEC_SA_ATTR_PN])) {
+		case MACSEC_DEFAULT_PN_LEN:
+			break;
+
+		case MACSEC_XPN_PN_LEN:
+			if (secy->xpn)
+				break;
+
+			pr_notice("macsec: nl: add_rxsa: pn length on non-xpn links must be %d\n",
+				  MACSEC_DEFAULT_PN_LEN);
+			rtnl_unlock();
+			return -EINVAL;
+
+		default:
+			pr_notice("macsec: nl: add_rxsa: pn length must be %d or %d\n",
+				  MACSEC_DEFAULT_PN_LEN, MACSEC_XPN_PN_LEN);
+			rtnl_unlock();
+			return -EINVAL;
+		}
 	}
 
 	if (secy->xpn) {
@@ -1934,7 +1946,7 @@ static bool validate_add_txsa(struct nlattr **attrs)
 	if (nla_get_u8(attrs[MACSEC_SA_ATTR_AN]) >= MACSEC_NUM_AN)
 		return false;
 
-	if (nla_get_u32(attrs[MACSEC_SA_ATTR_PN]) == 0)
+	if (nla_get_u64(attrs[MACSEC_SA_ATTR_PN]) == 0)
 		return false;
 
 	if (attrs[MACSEC_SA_ATTR_ACTIVE]) {
@@ -1956,7 +1968,6 @@ static int macsec_add_txsa(struct sk_buff *skb, struct genl_info *info)
 	struct macsec_tx_sc *tx_sc;
 	struct macsec_tx_sa *tx_sa;
 	unsigned char assoc_num;
-	int pn_len;
 	struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1];
 	bool was_operational;
 	int err;
@@ -1989,10 +2000,22 @@ static int macsec_add_txsa(struct sk_buff *skb, struct genl_info *info)
 		return -EINVAL;
 	}
 
-	pn_len = secy->xpn ? MACSEC_XPN_PN_LEN : MACSEC_DEFAULT_PN_LEN;
-	if (nla_len(tb_sa[MACSEC_SA_ATTR_PN]) != pn_len) {
-		pr_notice("macsec: nl: add_txsa: bad pn length: %d != %d\n",
-			  nla_len(tb_sa[MACSEC_SA_ATTR_PN]), pn_len);
+	switch (nla_len(tb_sa[MACSEC_SA_ATTR_PN])) {
+	case MACSEC_DEFAULT_PN_LEN:
+		break;
+
+	case MACSEC_XPN_PN_LEN:
+		if (secy->xpn)
+			break;
+
+		pr_notice("macsec: nl: add_txsa: pn length on non-xpn links must be %d\n",
+			  MACSEC_DEFAULT_PN_LEN);
+		rtnl_unlock();
+		return -EINVAL;
+
+	default:
+		pr_notice("macsec: nl: add_txsa: pn length must be %d or %d\n",
+			  MACSEC_DEFAULT_PN_LEN, MACSEC_XPN_PN_LEN);
 		rtnl_unlock();
 		return -EINVAL;
 	}
@@ -2288,7 +2311,7 @@ static bool validate_upd_sa(struct nlattr **attrs)
 	if (nla_get_u8(attrs[MACSEC_SA_ATTR_AN]) >= MACSEC_NUM_AN)
 		return false;
 
-	if (attrs[MACSEC_SA_ATTR_PN] && nla_get_u32(attrs[MACSEC_SA_ATTR_PN]) == 0)
+	if (attrs[MACSEC_SA_ATTR_PN] && nla_get_u64(attrs[MACSEC_SA_ATTR_PN]) == 0)
 		return false;
 
 	if (attrs[MACSEC_SA_ATTR_ACTIVE]) {
@@ -2332,12 +2355,22 @@ static int macsec_upd_txsa(struct sk_buff *skb, struct genl_info *info)
 	}
 
 	if (tb_sa[MACSEC_SA_ATTR_PN]) {
-		int pn_len;
+		switch (nla_len(tb_sa[MACSEC_SA_ATTR_PN])) {
+		case MACSEC_DEFAULT_PN_LEN:
+			break;
+
+		case MACSEC_XPN_PN_LEN:
+			if (secy->xpn)
+				break;
+
+			pr_notice("macsec: nl: upd_txsa: pn length on non-xpn links must be %d\n",
+				  MACSEC_DEFAULT_PN_LEN);
+			rtnl_unlock();
+			return -EINVAL;
 
-		pn_len = secy->xpn ? MACSEC_XPN_PN_LEN : MACSEC_DEFAULT_PN_LEN;
-		if (nla_len(tb_sa[MACSEC_SA_ATTR_PN]) != pn_len) {
-			pr_notice("macsec: nl: upd_txsa: bad pn length: %d != %d\n",
-				  nla_len(tb_sa[MACSEC_SA_ATTR_PN]), pn_len);
+		default:
+			pr_notice("macsec: nl: upd_txsa: pn length must be %d or %d\n",
+				  MACSEC_DEFAULT_PN_LEN, MACSEC_XPN_PN_LEN);
 			rtnl_unlock();
 			return -EINVAL;
 		}
@@ -2429,12 +2462,22 @@ static int macsec_upd_rxsa(struct sk_buff *skb, struct genl_info *info)
 	}
 
 	if (tb_sa[MACSEC_SA_ATTR_PN]) {
-		int pn_len;
+		switch (nla_len(tb_sa[MACSEC_SA_ATTR_PN])) {
+		case MACSEC_DEFAULT_PN_LEN:
+			break;
+
+		case MACSEC_XPN_PN_LEN:
+			if (secy->xpn)
+				break;
 
-		pn_len = secy->xpn ? MACSEC_XPN_PN_LEN : MACSEC_DEFAULT_PN_LEN;
-		if (nla_len(tb_sa[MACSEC_SA_ATTR_PN]) != pn_len) {
-			pr_notice("macsec: nl: upd_rxsa: bad pn length: %d != %d\n",
-				  nla_len(tb_sa[MACSEC_SA_ATTR_PN]), pn_len);
+			pr_notice("macsec: nl: upd_rxsa: pn length on non-xpn links must be %d\n",
+				  MACSEC_DEFAULT_PN_LEN);
+			rtnl_unlock();
+			return -EINVAL;
+
+		default:
+			pr_notice("macsec: nl: upd_rxsa: pn length must be %d or %d\n",
+				  MACSEC_DEFAULT_PN_LEN, MACSEC_XPN_PN_LEN);
 			rtnl_unlock();
 			return -EINVAL;
 		}

base-commit: bc7d17d55762421b98089f5f7496e48cab89de50
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] macsec: Support 32bit PN netlink attribute for XPN links
  2020-06-15 15:41 [PATCH] macsec: Support 32bit PN netlink attribute for XPN links Era Mayflower
@ 2020-06-16  1:23 ` David Miller
  2020-06-17  1:02   ` Era Mayflower
  0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2020-06-16  1:23 UTC (permalink / raw)
  To: mayflowerera; +Cc: kuba, netdev, linux-kernel

From: Era Mayflower <mayflowerera@gmail.com>
Date: Tue, 16 Jun 2020 00:41:14 +0900

> +	if (tb_sa[MACSEC_SA_ATTR_PN]) {

validate_add_rxsa() requires that MACSET_SA_ATTR_PN be non-NULL, so
you don't need to add this check here.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] macsec: Support 32bit PN netlink attribute for XPN links
  2020-06-17  1:02   ` Era Mayflower
@ 2020-06-16 16:32     ` Era Mayflower
  2020-06-24 10:23       ` Era Mayflower
  0 siblings, 1 reply; 6+ messages in thread
From: Era Mayflower @ 2020-06-16 16:32 UTC (permalink / raw)
  To: David Miller; +Cc: kuba, netdev, linux-kernel

On Wed, Jun 17, 2020 at 10:02 AM Era Mayflower <mayflowerera@gmail.com> wrote:
>
> On Tue, Jun 16, 2020 at 1:23 AM David Miller <davem@davemloft.net> wrote:
> >
> > From: Era Mayflower <mayflowerera@gmail.com>
> > Date: Tue, 16 Jun 2020 00:41:14 +0900
> >
> > > +     if (tb_sa[MACSEC_SA_ATTR_PN]) {
> >
> > validate_add_rxsa() requires that MACSET_SA_ATTR_PN be non-NULL, so
> > you don't need to add this check here.
> >
>
> validate_add_rxsa() did not originally contain that requirement.
> It does exist in validate_add_txsa(), which means that providing a PN
> is necessary only when creating TXSA.
> When creating an RXSA without providing a PN it will be set to 1
> (init_rx_sa+15).
> This is the original behavior which of course can be changed.
>
> - Era.

Sorry for the time issues, just noticed I sent the previous mail with
future time.
Fixed it permanently on my computer.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] macsec: Support 32bit PN netlink attribute for XPN links
  2020-06-16  1:23 ` David Miller
@ 2020-06-17  1:02   ` Era Mayflower
  2020-06-16 16:32     ` Era Mayflower
  0 siblings, 1 reply; 6+ messages in thread
From: Era Mayflower @ 2020-06-17  1:02 UTC (permalink / raw)
  To: David Miller; +Cc: kuba, netdev, linux-kernel

On Tue, Jun 16, 2020 at 1:23 AM David Miller <davem@davemloft.net> wrote:
>
> From: Era Mayflower <mayflowerera@gmail.com>
> Date: Tue, 16 Jun 2020 00:41:14 +0900
>
> > +     if (tb_sa[MACSEC_SA_ATTR_PN]) {
>
> validate_add_rxsa() requires that MACSET_SA_ATTR_PN be non-NULL, so
> you don't need to add this check here.
>

validate_add_rxsa() did not originally contain that requirement.
It does exist in validate_add_txsa(), which means that providing a PN
is necessary only when creating TXSA.
When creating an RXSA without providing a PN it will be set to 1
(init_rx_sa+15).
This is the original behavior which of course can be changed.

- Era.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] macsec: Support 32bit PN netlink attribute for XPN links
  2020-06-16 16:32     ` Era Mayflower
@ 2020-06-24 10:23       ` Era Mayflower
  2020-08-19 13:03         ` Era Mayflower
  0 siblings, 1 reply; 6+ messages in thread
From: Era Mayflower @ 2020-06-24 10:23 UTC (permalink / raw)
  To: David Miller; +Cc: kuba, netdev, linux-kernel

On Wed, Jun 17, 2020 at 1:32 AM Era Mayflower <mayflowerera@gmail.com> wrote:
>
> On Wed, Jun 17, 2020 at 10:02 AM Era Mayflower <mayflowerera@gmail.com> wrote:
> >
> > On Tue, Jun 16, 2020 at 1:23 AM David Miller <davem@davemloft.net> wrote:
> > >
> > > From: Era Mayflower <mayflowerera@gmail.com>
> > > Date: Tue, 16 Jun 2020 00:41:14 +0900
> > >
> > > > +     if (tb_sa[MACSEC_SA_ATTR_PN]) {
> > >
> > > validate_add_rxsa() requires that MACSET_SA_ATTR_PN be non-NULL, so
> > > you don't need to add this check here.
> > >
> >
> > validate_add_rxsa() did not originally contain that requirement.
> > It does exist in validate_add_txsa(), which means that providing a PN
> > is necessary only when creating TXSA.
> > When creating an RXSA without providing a PN it will be set to 1
> > (init_rx_sa+15).
> > This is the original behavior which of course can be changed.
> >
> > - Era.
>
> Sorry for the time issues, just noticed I sent the previous mail with
> future time.
> Fixed it permanently on my computer.

Hello, is there any news?

- Era.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] macsec: Support 32bit PN netlink attribute for XPN links
  2020-06-24 10:23       ` Era Mayflower
@ 2020-08-19 13:03         ` Era Mayflower
  0 siblings, 0 replies; 6+ messages in thread
From: Era Mayflower @ 2020-08-19 13:03 UTC (permalink / raw)
  To: David Miller; +Cc: kuba, netdev, linux-kernel

On Wed, Jun 24, 2020 at 10:23 AM Era Mayflower <mayflowerera@gmail.com> wrote:
>
> On Wed, Jun 17, 2020 at 1:32 AM Era Mayflower <mayflowerera@gmail.com> wrote:
> >
> > On Wed, Jun 17, 2020 at 10:02 AM Era Mayflower <mayflowerera@gmail.com> wrote:
> > >
> > > On Tue, Jun 16, 2020 at 1:23 AM David Miller <davem@davemloft.net> wrote:
> > > >
> > > > From: Era Mayflower <mayflowerera@gmail.com>
> > > > Date: Tue, 16 Jun 2020 00:41:14 +0900
> > > >
> > > > > +     if (tb_sa[MACSEC_SA_ATTR_PN]) {
> > > >
> > > > validate_add_rxsa() requires that MACSET_SA_ATTR_PN be non-NULL, so
> > > > you don't need to add this check here.
> > > >
> > >
> > > validate_add_rxsa() did not originally contain that requirement.
> > > It does exist in validate_add_txsa(), which means that providing a PN
> > > is necessary only when creating TXSA.
> > > When creating an RXSA without providing a PN it will be set to 1
> > > (init_rx_sa+15).
> > > This is the original behavior which of course can be changed.
> > >
> > > - Era.
> >
> > Sorry for the time issues, just noticed I sent the previous mail with
> > future time.
> > Fixed it permanently on my computer.
>
> Hello, is there any news?
>
> - Era.

This patch is important to help projects like iproute2 use XPN macsec links.
Please let me know if there is anything I need to fix.

- Era.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-08-19 13:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15 15:41 [PATCH] macsec: Support 32bit PN netlink attribute for XPN links Era Mayflower
2020-06-16  1:23 ` David Miller
2020-06-17  1:02   ` Era Mayflower
2020-06-16 16:32     ` Era Mayflower
2020-06-24 10:23       ` Era Mayflower
2020-08-19 13:03         ` Era Mayflower

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).