linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2 0/2] fix and move definitions of MRP data structures
@ 2021-01-21 20:40 Rasmus Villemoes
  2021-01-21 20:40 ` [PATCH net v2 1/2] net: mrp: fix definitions of MRP test packets Rasmus Villemoes
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Rasmus Villemoes @ 2021-01-21 20:40 UTC (permalink / raw)
  To: netdev
  Cc: Horatiu Vultur, Andrew Lunn, Jakub Kicinski, David S . Miller,
	linux-kernel, Rasmus Villemoes

v2: update commit log of the patch to include comments on 32 bit
alignment; include second patch moving the structs out of uapi.

Rasmus Villemoes (2):
  net: mrp: fix definitions of MRP test packets
  net: mrp: move struct definitions out of uapi

 include/uapi/linux/mrp_bridge.h | 86 ---------------------------------
 net/bridge/br_private_mrp.h     | 29 +++++++++++
 2 files changed, 29 insertions(+), 86 deletions(-)

-- 
2.23.0


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

* [PATCH net v2 1/2] net: mrp: fix definitions of MRP test packets
  2021-01-21 20:40 [PATCH net v2 0/2] fix and move definitions of MRP data structures Rasmus Villemoes
@ 2021-01-21 20:40 ` Rasmus Villemoes
  2021-01-21 21:23   ` Horatiu Vultur
  2021-01-21 20:40 ` [PATCH net v2 2/2] net: mrp: move struct definitions out of uapi Rasmus Villemoes
  2021-01-23 20:40 ` [PATCH net v2 0/2] fix and move definitions of MRP data structures Jakub Kicinski
  2 siblings, 1 reply; 6+ messages in thread
From: Rasmus Villemoes @ 2021-01-21 20:40 UTC (permalink / raw)
  To: netdev
  Cc: Horatiu Vultur, Andrew Lunn, Jakub Kicinski, David S . Miller,
	linux-kernel, Rasmus Villemoes

Wireshark says that the MRP test packets cannot be decoded - and the
reason for that is that there's a two-byte hole filled with garbage
between the "transitions" and "timestamp" members.

So Wireshark decodes the two garbage bytes and the top two bytes of
the timestamp written by the kernel as the timestamp value (which thus
fluctuates wildly), and interprets the lower two bytes of the
timestamp as a new (type, length) pair, which is of course broken.

Even though this makes the timestamp field in the struct unaligned, it
actually makes it end up on a 32 bit boundary in the frame as mandated
by the standard, since it is preceded by a two byte TLV header.

The struct definitions live under include/uapi/, but they are not
really part of any kernel<->userspace API/ABI, so fixing the
definitions by adding the packed attribute should not cause any
compatibility issues.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 include/uapi/linux/mrp_bridge.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/mrp_bridge.h b/include/uapi/linux/mrp_bridge.h
index 6aeb13ef0b1e..d1d0cf65916d 100644
--- a/include/uapi/linux/mrp_bridge.h
+++ b/include/uapi/linux/mrp_bridge.h
@@ -96,7 +96,7 @@ struct br_mrp_ring_test_hdr {
 	__be16 state;
 	__be16 transitions;
 	__be32 timestamp;
-};
+} __attribute__((__packed__));
 
 struct br_mrp_ring_topo_hdr {
 	__be16 prio;
@@ -141,7 +141,7 @@ struct br_mrp_in_test_hdr {
 	__be16 state;
 	__be16 transitions;
 	__be32 timestamp;
-};
+} __attribute__((__packed__));
 
 struct br_mrp_in_topo_hdr {
 	__u8 sa[ETH_ALEN];
-- 
2.23.0


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

* [PATCH net v2 2/2] net: mrp: move struct definitions out of uapi
  2021-01-21 20:40 [PATCH net v2 0/2] fix and move definitions of MRP data structures Rasmus Villemoes
  2021-01-21 20:40 ` [PATCH net v2 1/2] net: mrp: fix definitions of MRP test packets Rasmus Villemoes
@ 2021-01-21 20:40 ` Rasmus Villemoes
  2021-01-23 20:40 ` [PATCH net v2 0/2] fix and move definitions of MRP data structures Jakub Kicinski
  2 siblings, 0 replies; 6+ messages in thread
From: Rasmus Villemoes @ 2021-01-21 20:40 UTC (permalink / raw)
  To: netdev
  Cc: Horatiu Vultur, Andrew Lunn, Jakub Kicinski, David S . Miller,
	linux-kernel, Rasmus Villemoes

None of these are actually used in the kernel/userspace interface -
there's a userspace component of implementing MRP, and userspace will
need to construct certain frames to put on the wire, but there's no
reason the kernel should provide the relevant definitions in a UAPI
header.

In fact, most of these structs are unused in the kernel, so only keep
the few that are actually referenced in the kernel code, and move them
to the br_private_mrp.h header.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 include/uapi/linux/mrp_bridge.h | 86 ---------------------------------
 net/bridge/br_private_mrp.h     | 29 +++++++++++
 2 files changed, 29 insertions(+), 86 deletions(-)

diff --git a/include/uapi/linux/mrp_bridge.h b/include/uapi/linux/mrp_bridge.h
index d1d0cf65916d..f090acd4f6c4 100644
--- a/include/uapi/linux/mrp_bridge.h
+++ b/include/uapi/linux/mrp_bridge.h
@@ -70,90 +70,4 @@ enum br_mrp_sub_tlv_header_type {
 	BR_MRP_SUB_TLV_HEADER_TEST_AUTO_MGR = 0x3,
 };
 
-struct br_mrp_tlv_hdr {
-	__u8 type;
-	__u8 length;
-};
-
-struct br_mrp_sub_tlv_hdr {
-	__u8 type;
-	__u8 length;
-};
-
-struct br_mrp_end_hdr {
-	struct br_mrp_tlv_hdr hdr;
-};
-
-struct br_mrp_common_hdr {
-	__be16 seq_id;
-	__u8 domain[MRP_DOMAIN_UUID_LENGTH];
-};
-
-struct br_mrp_ring_test_hdr {
-	__be16 prio;
-	__u8 sa[ETH_ALEN];
-	__be16 port_role;
-	__be16 state;
-	__be16 transitions;
-	__be32 timestamp;
-} __attribute__((__packed__));
-
-struct br_mrp_ring_topo_hdr {
-	__be16 prio;
-	__u8 sa[ETH_ALEN];
-	__be16 interval;
-};
-
-struct br_mrp_ring_link_hdr {
-	__u8 sa[ETH_ALEN];
-	__be16 port_role;
-	__be16 interval;
-	__be16 blocked;
-};
-
-struct br_mrp_sub_opt_hdr {
-	__u8 type;
-	__u8 manufacture_data[MRP_MANUFACTURE_DATA_LENGTH];
-};
-
-struct br_mrp_test_mgr_nack_hdr {
-	__be16 prio;
-	__u8 sa[ETH_ALEN];
-	__be16 other_prio;
-	__u8 other_sa[ETH_ALEN];
-};
-
-struct br_mrp_test_prop_hdr {
-	__be16 prio;
-	__u8 sa[ETH_ALEN];
-	__be16 other_prio;
-	__u8 other_sa[ETH_ALEN];
-};
-
-struct br_mrp_oui_hdr {
-	__u8 oui[MRP_OUI_LENGTH];
-};
-
-struct br_mrp_in_test_hdr {
-	__be16 id;
-	__u8 sa[ETH_ALEN];
-	__be16 port_role;
-	__be16 state;
-	__be16 transitions;
-	__be32 timestamp;
-} __attribute__((__packed__));
-
-struct br_mrp_in_topo_hdr {
-	__u8 sa[ETH_ALEN];
-	__be16 id;
-	__be16 interval;
-};
-
-struct br_mrp_in_link_hdr {
-	__u8 sa[ETH_ALEN];
-	__be16 port_role;
-	__be16 id;
-	__be16 interval;
-};
-
 #endif
diff --git a/net/bridge/br_private_mrp.h b/net/bridge/br_private_mrp.h
index af0e9eff6549..3f80a0a79a32 100644
--- a/net/bridge/br_private_mrp.h
+++ b/net/bridge/br_private_mrp.h
@@ -88,4 +88,33 @@ int br_mrp_switchdev_send_in_test(struct net_bridge *br, struct br_mrp *mrp,
 int br_mrp_ring_port_open(struct net_device *dev, u8 loc);
 int br_mrp_in_port_open(struct net_device *dev, u8 loc);
 
+/* MRP protocol data units */
+struct br_mrp_tlv_hdr {
+	__u8 type;
+	__u8 length;
+};
+
+struct br_mrp_common_hdr {
+	__be16 seq_id;
+	__u8 domain[MRP_DOMAIN_UUID_LENGTH];
+};
+
+struct br_mrp_ring_test_hdr {
+	__be16 prio;
+	__u8 sa[ETH_ALEN];
+	__be16 port_role;
+	__be16 state;
+	__be16 transitions;
+	__be32 timestamp;
+} __attribute__((__packed__));
+
+struct br_mrp_in_test_hdr {
+	__be16 id;
+	__u8 sa[ETH_ALEN];
+	__be16 port_role;
+	__be16 state;
+	__be16 transitions;
+	__be32 timestamp;
+} __attribute__((__packed__));
+
 #endif /* _BR_PRIVATE_MRP_H */
-- 
2.23.0


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

* Re: [PATCH net v2 1/2] net: mrp: fix definitions of MRP test packets
  2021-01-21 20:40 ` [PATCH net v2 1/2] net: mrp: fix definitions of MRP test packets Rasmus Villemoes
@ 2021-01-21 21:23   ` Horatiu Vultur
  2021-01-21 21:28     ` Rasmus Villemoes
  0 siblings, 1 reply; 6+ messages in thread
From: Horatiu Vultur @ 2021-01-21 21:23 UTC (permalink / raw)
  To: Rasmus Villemoes
  Cc: netdev, Andrew Lunn, Jakub Kicinski, David S . Miller, linux-kernel

The 01/21/2021 21:40, Rasmus Villemoes wrote:

It seems that is missing a Fixes tag, other than that it looks fine.

Reviewed-by: Horatiu Vultur <horatiu.vultur@microchip.com>

> 
> Wireshark says that the MRP test packets cannot be decoded - and the
> reason for that is that there's a two-byte hole filled with garbage
> between the "transitions" and "timestamp" members.
> 
> So Wireshark decodes the two garbage bytes and the top two bytes of
> the timestamp written by the kernel as the timestamp value (which thus
> fluctuates wildly), and interprets the lower two bytes of the
> timestamp as a new (type, length) pair, which is of course broken.
> 
> Even though this makes the timestamp field in the struct unaligned, it
> actually makes it end up on a 32 bit boundary in the frame as mandated
> by the standard, since it is preceded by a two byte TLV header.
> 
> The struct definitions live under include/uapi/, but they are not
> really part of any kernel<->userspace API/ABI, so fixing the
> definitions by adding the packed attribute should not cause any
> compatibility issues.
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> ---
>  include/uapi/linux/mrp_bridge.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/include/uapi/linux/mrp_bridge.h b/include/uapi/linux/mrp_bridge.h
> index 6aeb13ef0b1e..d1d0cf65916d 100644
> --- a/include/uapi/linux/mrp_bridge.h
> +++ b/include/uapi/linux/mrp_bridge.h
> @@ -96,7 +96,7 @@ struct br_mrp_ring_test_hdr {
>         __be16 state;
>         __be16 transitions;
>         __be32 timestamp;
> -};
> +} __attribute__((__packed__));
> 
>  struct br_mrp_ring_topo_hdr {
>         __be16 prio;
> @@ -141,7 +141,7 @@ struct br_mrp_in_test_hdr {
>         __be16 state;
>         __be16 transitions;
>         __be32 timestamp;
> -};
> +} __attribute__((__packed__));
> 
>  struct br_mrp_in_topo_hdr {
>         __u8 sa[ETH_ALEN];
> --
> 2.23.0
> 

-- 
/Horatiu

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

* Re: [PATCH net v2 1/2] net: mrp: fix definitions of MRP test packets
  2021-01-21 21:23   ` Horatiu Vultur
@ 2021-01-21 21:28     ` Rasmus Villemoes
  0 siblings, 0 replies; 6+ messages in thread
From: Rasmus Villemoes @ 2021-01-21 21:28 UTC (permalink / raw)
  To: Horatiu Vultur
  Cc: netdev, Andrew Lunn, Jakub Kicinski, David S . Miller, linux-kernel

On 21/01/2021 22.23, Horatiu Vultur wrote:
> The 01/21/2021 21:40, Rasmus Villemoes wrote:
> 
> It seems that is missing a Fixes tag, other than that it looks fine.

That would be these two I guess:

Fixes: 2801758391ba ("bridge: uapi: mrp: Extend MRP attributes for MRP
interconnect")
Fixes: 4714d13791f8 ("bridge: uapi: mrp: Add mrp attributes.")

> Reviewed-by: Horatiu Vultur <horatiu.vultur@microchip.com>

Thanks,
Rasmus

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

* Re: [PATCH net v2 0/2] fix and move definitions of MRP data structures
  2021-01-21 20:40 [PATCH net v2 0/2] fix and move definitions of MRP data structures Rasmus Villemoes
  2021-01-21 20:40 ` [PATCH net v2 1/2] net: mrp: fix definitions of MRP test packets Rasmus Villemoes
  2021-01-21 20:40 ` [PATCH net v2 2/2] net: mrp: move struct definitions out of uapi Rasmus Villemoes
@ 2021-01-23 20:40 ` Jakub Kicinski
  2 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2021-01-23 20:40 UTC (permalink / raw)
  To: Rasmus Villemoes
  Cc: netdev, Horatiu Vultur, Andrew Lunn, David S . Miller, linux-kernel

On Thu, 21 Jan 2021 21:40:35 +0100 Rasmus Villemoes wrote:
> v2: update commit log of the patch to include comments on 32 bit
> alignment; include second patch moving the structs out of uapi.

Applied, thanks!

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

end of thread, other threads:[~2021-01-23 20:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-21 20:40 [PATCH net v2 0/2] fix and move definitions of MRP data structures Rasmus Villemoes
2021-01-21 20:40 ` [PATCH net v2 1/2] net: mrp: fix definitions of MRP test packets Rasmus Villemoes
2021-01-21 21:23   ` Horatiu Vultur
2021-01-21 21:28     ` Rasmus Villemoes
2021-01-21 20:40 ` [PATCH net v2 2/2] net: mrp: move struct definitions out of uapi Rasmus Villemoes
2021-01-23 20:40 ` [PATCH net v2 0/2] fix and move definitions of MRP data structures Jakub Kicinski

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