RE: [PATCH] net: hsr : Provide fix for HSRv1 supervisor frames decoding

From: Tristram.Ha
Date: Fri Aug 25 2023 - 14:11:22 EST


> - /* And leave the HSR tag. */
> + * And leave the HSR tag.
> + *
> + * The HSRv1 supervisory frame encapsulates the v0 frame
> + * with EtherType of 0x88FB
> + */
> if (ethhdr->h_proto == htons(ETH_P_HSR)) {
> - pull_size = sizeof(struct ethhdr);
> + if (hsr->prot_version == HSR_V1)
> + /* In the above step the DA, SA and EtherType
> + * (0x892F - HSRv1) bytes has been removed.
> + *
> + * As the HSRv1 has the HSR header added, one need
> + * to remove path_and_LSDU_size and sequence_nr fields.
> + *
> + */
> + pull_size = 4;
> + else
> + pull_size = sizeof(struct hsr_tag);
> +
> skb_pull(skb, pull_size);
> total_pull_size += pull_size;
> }
> @@ -313,6 +328,19 @@ void hsr_handle_sup_frame(struct hsr_frame_info *frame)
> total_pull_size += pull_size;
>
> /* get HSR sup payload */
> + if (hsr->prot_version == HSR_V1) {
> + /* In the HSRv1 supervisor frame, when
> + * one with EtherType = 0x88FB is extracted, the Node A
> + * MAC address is preceded with type and length elements of TLV
> + * data field.
> + *
> + * It needs to be removed to get the remote peer MAC address.
> + */
> + pull_size = sizeof(struct hsr_sup_tlv);
> + skb_pull(skb, pull_size);
> + total_pull_size += pull_size;
> + }
> +
> hsr_sp = (struct hsr_sup_payload *)skb->data;

I thought the fix is simply this:

if (ethhdr->h_proto == htons(ETH_P_HSR)) {
- pull_size = sizeof(struct ethhdr);
+ pull_size = sizeof(struct hsr_tag);
skb_pull(skb, pull_size);
total_pull_size += pull_size;
}

- pull_size = sizeof(struct hsr_tag);
+ pull_size = sizeof(struct hsr_sup_tag);

Note the sizes of hsr_tag and hsr_sup_tag are the same: 6 bytes.
The code in 5.15 before this refactored code uses those structures.
When using v0 the EtherType uses the PRP tag instead of the HSR tag so
the HSR related code is not executed.