| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* Copyright 2011-2014 Autronica Fire and Security AS |
|---|
| 2 | | - * |
|---|
| 3 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 4 | | - * under the terms of the GNU General Public License as published by the Free |
|---|
| 5 | | - * Software Foundation; either version 2 of the License, or (at your option) |
|---|
| 6 | | - * any later version. |
|---|
| 7 | 3 | * |
|---|
| 8 | 4 | * Author(s): |
|---|
| 9 | 5 | * 2011-2014 Arvid Brodin, arvid.brodin@alten.se |
|---|
| 6 | + * |
|---|
| 7 | + * Frame router for HSR and PRP. |
|---|
| 10 | 8 | */ |
|---|
| 11 | 9 | |
|---|
| 12 | 10 | #include "hsr_forward.h" |
|---|
| .. | .. |
|---|
| 17 | 15 | #include "hsr_main.h" |
|---|
| 18 | 16 | #include "hsr_framereg.h" |
|---|
| 19 | 17 | |
|---|
| 20 | | - |
|---|
| 21 | 18 | struct hsr_node; |
|---|
| 22 | | - |
|---|
| 23 | | -struct hsr_frame_info { |
|---|
| 24 | | - struct sk_buff *skb_std; |
|---|
| 25 | | - struct sk_buff *skb_hsr; |
|---|
| 26 | | - struct hsr_port *port_rcv; |
|---|
| 27 | | - struct hsr_node *node_src; |
|---|
| 28 | | - u16 sequence_nr; |
|---|
| 29 | | - bool is_supervision; |
|---|
| 30 | | - bool is_vlan; |
|---|
| 31 | | - bool is_local_dest; |
|---|
| 32 | | - bool is_local_exclusive; |
|---|
| 33 | | -}; |
|---|
| 34 | | - |
|---|
| 35 | 19 | |
|---|
| 36 | 20 | /* The uses I can see for these HSR supervision frames are: |
|---|
| 37 | 21 | * 1) Use the frames that are sent after node initialization ("HSR_TLV.Type = |
|---|
| .. | .. |
|---|
| 50 | 34 | */ |
|---|
| 51 | 35 | static bool is_supervision_frame(struct hsr_priv *hsr, struct sk_buff *skb) |
|---|
| 52 | 36 | { |
|---|
| 53 | | - struct ethhdr *ethHdr; |
|---|
| 54 | | - struct hsr_sup_tag *hsrSupTag; |
|---|
| 55 | | - struct hsrv1_ethhdr_sp *hsrV1Hdr; |
|---|
| 37 | + struct ethhdr *eth_hdr; |
|---|
| 38 | + struct hsr_sup_tag *hsr_sup_tag; |
|---|
| 39 | + struct hsrv1_ethhdr_sp *hsr_V1_hdr; |
|---|
| 56 | 40 | |
|---|
| 57 | 41 | WARN_ON_ONCE(!skb_mac_header_was_set(skb)); |
|---|
| 58 | | - ethHdr = (struct ethhdr *) skb_mac_header(skb); |
|---|
| 42 | + eth_hdr = (struct ethhdr *)skb_mac_header(skb); |
|---|
| 59 | 43 | |
|---|
| 60 | 44 | /* Correct addr? */ |
|---|
| 61 | | - if (!ether_addr_equal(ethHdr->h_dest, |
|---|
| 45 | + if (!ether_addr_equal(eth_hdr->h_dest, |
|---|
| 62 | 46 | hsr->sup_multicast_addr)) |
|---|
| 63 | 47 | return false; |
|---|
| 64 | 48 | |
|---|
| 65 | 49 | /* Correct ether type?. */ |
|---|
| 66 | | - if (!(ethHdr->h_proto == htons(ETH_P_PRP) |
|---|
| 67 | | - || ethHdr->h_proto == htons(ETH_P_HSR))) |
|---|
| 50 | + if (!(eth_hdr->h_proto == htons(ETH_P_PRP) || |
|---|
| 51 | + eth_hdr->h_proto == htons(ETH_P_HSR))) |
|---|
| 68 | 52 | return false; |
|---|
| 69 | 53 | |
|---|
| 70 | 54 | /* Get the supervision header from correct location. */ |
|---|
| 71 | | - if (ethHdr->h_proto == htons(ETH_P_HSR)) { /* Okay HSRv1. */ |
|---|
| 72 | | - hsrV1Hdr = (struct hsrv1_ethhdr_sp *) skb_mac_header(skb); |
|---|
| 73 | | - if (hsrV1Hdr->hsr.encap_proto != htons(ETH_P_PRP)) |
|---|
| 55 | + if (eth_hdr->h_proto == htons(ETH_P_HSR)) { /* Okay HSRv1. */ |
|---|
| 56 | + hsr_V1_hdr = (struct hsrv1_ethhdr_sp *)skb_mac_header(skb); |
|---|
| 57 | + if (hsr_V1_hdr->hsr.encap_proto != htons(ETH_P_PRP)) |
|---|
| 74 | 58 | return false; |
|---|
| 75 | 59 | |
|---|
| 76 | | - hsrSupTag = &hsrV1Hdr->hsr_sup; |
|---|
| 60 | + hsr_sup_tag = &hsr_V1_hdr->hsr_sup; |
|---|
| 77 | 61 | } else { |
|---|
| 78 | | - hsrSupTag = &((struct hsrv0_ethhdr_sp *) skb_mac_header(skb))->hsr_sup; |
|---|
| 62 | + hsr_sup_tag = |
|---|
| 63 | + &((struct hsrv0_ethhdr_sp *)skb_mac_header(skb))->hsr_sup; |
|---|
| 79 | 64 | } |
|---|
| 80 | 65 | |
|---|
| 81 | | - if ((hsrSupTag->HSR_TLV_Type != HSR_TLV_ANNOUNCE) && |
|---|
| 82 | | - (hsrSupTag->HSR_TLV_Type != HSR_TLV_LIFE_CHECK)) |
|---|
| 66 | + if (hsr_sup_tag->HSR_TLV_type != HSR_TLV_ANNOUNCE && |
|---|
| 67 | + hsr_sup_tag->HSR_TLV_type != HSR_TLV_LIFE_CHECK && |
|---|
| 68 | + hsr_sup_tag->HSR_TLV_type != PRP_TLV_LIFE_CHECK_DD && |
|---|
| 69 | + hsr_sup_tag->HSR_TLV_type != PRP_TLV_LIFE_CHECK_DA) |
|---|
| 83 | 70 | return false; |
|---|
| 84 | | - if ((hsrSupTag->HSR_TLV_Length != 12) && |
|---|
| 85 | | - (hsrSupTag->HSR_TLV_Length != |
|---|
| 86 | | - sizeof(struct hsr_sup_payload))) |
|---|
| 71 | + if (hsr_sup_tag->HSR_TLV_length != 12 && |
|---|
| 72 | + hsr_sup_tag->HSR_TLV_length != sizeof(struct hsr_sup_payload)) |
|---|
| 87 | 73 | return false; |
|---|
| 88 | 74 | |
|---|
| 89 | 75 | return true; |
|---|
| 90 | 76 | } |
|---|
| 91 | 77 | |
|---|
| 92 | | - |
|---|
| 93 | | -static struct sk_buff *create_stripped_skb(struct sk_buff *skb_in, |
|---|
| 94 | | - struct hsr_frame_info *frame) |
|---|
| 78 | +static struct sk_buff *create_stripped_skb_hsr(struct sk_buff *skb_in, |
|---|
| 79 | + struct hsr_frame_info *frame) |
|---|
| 95 | 80 | { |
|---|
| 96 | 81 | struct sk_buff *skb; |
|---|
| 97 | 82 | int copylen; |
|---|
| .. | .. |
|---|
| 100 | 85 | skb_pull(skb_in, HSR_HLEN); |
|---|
| 101 | 86 | skb = __pskb_copy(skb_in, skb_headroom(skb_in) - HSR_HLEN, GFP_ATOMIC); |
|---|
| 102 | 87 | skb_push(skb_in, HSR_HLEN); |
|---|
| 103 | | - if (skb == NULL) |
|---|
| 88 | + if (!skb) |
|---|
| 104 | 89 | return NULL; |
|---|
| 105 | 90 | |
|---|
| 106 | 91 | skb_reset_mac_header(skb); |
|---|
| .. | .. |
|---|
| 108 | 93 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
|---|
| 109 | 94 | skb->csum_start -= HSR_HLEN; |
|---|
| 110 | 95 | |
|---|
| 111 | | - copylen = 2*ETH_ALEN; |
|---|
| 96 | + copylen = 2 * ETH_ALEN; |
|---|
| 112 | 97 | if (frame->is_vlan) |
|---|
| 113 | 98 | copylen += VLAN_HLEN; |
|---|
| 114 | 99 | src = skb_mac_header(skb_in); |
|---|
| .. | .. |
|---|
| 119 | 104 | return skb; |
|---|
| 120 | 105 | } |
|---|
| 121 | 106 | |
|---|
| 122 | | -static struct sk_buff *frame_get_stripped_skb(struct hsr_frame_info *frame, |
|---|
| 123 | | - struct hsr_port *port) |
|---|
| 107 | +struct sk_buff *hsr_get_untagged_frame(struct hsr_frame_info *frame, |
|---|
| 108 | + struct hsr_port *port) |
|---|
| 124 | 109 | { |
|---|
| 125 | | - if (!frame->skb_std) |
|---|
| 126 | | - frame->skb_std = create_stripped_skb(frame->skb_hsr, frame); |
|---|
| 110 | + if (!frame->skb_std) { |
|---|
| 111 | + if (frame->skb_hsr) |
|---|
| 112 | + frame->skb_std = |
|---|
| 113 | + create_stripped_skb_hsr(frame->skb_hsr, frame); |
|---|
| 114 | + else |
|---|
| 115 | + netdev_warn_once(port->dev, |
|---|
| 116 | + "Unexpected frame received in hsr_get_untagged_frame()\n"); |
|---|
| 117 | + |
|---|
| 118 | + if (!frame->skb_std) |
|---|
| 119 | + return NULL; |
|---|
| 120 | + } |
|---|
| 121 | + |
|---|
| 127 | 122 | return skb_clone(frame->skb_std, GFP_ATOMIC); |
|---|
| 128 | 123 | } |
|---|
| 129 | 124 | |
|---|
| 130 | | - |
|---|
| 131 | | -static void hsr_fill_tag(struct sk_buff *skb, struct hsr_frame_info *frame, |
|---|
| 132 | | - struct hsr_port *port, u8 protoVersion) |
|---|
| 125 | +struct sk_buff *prp_get_untagged_frame(struct hsr_frame_info *frame, |
|---|
| 126 | + struct hsr_port *port) |
|---|
| 133 | 127 | { |
|---|
| 134 | | - struct hsr_ethhdr *hsr_ethhdr; |
|---|
| 128 | + if (!frame->skb_std) { |
|---|
| 129 | + if (frame->skb_prp) { |
|---|
| 130 | + /* trim the skb by len - HSR_HLEN to exclude RCT */ |
|---|
| 131 | + skb_trim(frame->skb_prp, |
|---|
| 132 | + frame->skb_prp->len - HSR_HLEN); |
|---|
| 133 | + frame->skb_std = |
|---|
| 134 | + __pskb_copy(frame->skb_prp, |
|---|
| 135 | + skb_headroom(frame->skb_prp), |
|---|
| 136 | + GFP_ATOMIC); |
|---|
| 137 | + } else { |
|---|
| 138 | + /* Unexpected */ |
|---|
| 139 | + WARN_ONCE(1, "%s:%d: Unexpected frame received (port_src %s)\n", |
|---|
| 140 | + __FILE__, __LINE__, port->dev->name); |
|---|
| 141 | + return NULL; |
|---|
| 142 | + } |
|---|
| 143 | + } |
|---|
| 144 | + |
|---|
| 145 | + return skb_clone(frame->skb_std, GFP_ATOMIC); |
|---|
| 146 | +} |
|---|
| 147 | + |
|---|
| 148 | +static void prp_set_lan_id(struct prp_rct *trailer, |
|---|
| 149 | + struct hsr_port *port) |
|---|
| 150 | +{ |
|---|
| 135 | 151 | int lane_id; |
|---|
| 136 | | - int lsdu_size; |
|---|
| 137 | 152 | |
|---|
| 138 | 153 | if (port->type == HSR_PT_SLAVE_A) |
|---|
| 139 | 154 | lane_id = 0; |
|---|
| 140 | 155 | else |
|---|
| 141 | 156 | lane_id = 1; |
|---|
| 142 | 157 | |
|---|
| 158 | + /* Add net_id in the upper 3 bits of lane_id */ |
|---|
| 159 | + lane_id |= port->hsr->net_id; |
|---|
| 160 | + set_prp_lan_id(trailer, lane_id); |
|---|
| 161 | +} |
|---|
| 162 | + |
|---|
| 163 | +/* Tailroom for PRP rct should have been created before calling this */ |
|---|
| 164 | +static struct sk_buff *prp_fill_rct(struct sk_buff *skb, |
|---|
| 165 | + struct hsr_frame_info *frame, |
|---|
| 166 | + struct hsr_port *port) |
|---|
| 167 | +{ |
|---|
| 168 | + struct prp_rct *trailer; |
|---|
| 169 | + int min_size = ETH_ZLEN; |
|---|
| 170 | + int lsdu_size; |
|---|
| 171 | + |
|---|
| 172 | + if (!skb) |
|---|
| 173 | + return skb; |
|---|
| 174 | + |
|---|
| 175 | + if (frame->is_vlan) |
|---|
| 176 | + min_size = VLAN_ETH_ZLEN; |
|---|
| 177 | + |
|---|
| 178 | + if (skb_put_padto(skb, min_size)) |
|---|
| 179 | + return NULL; |
|---|
| 180 | + |
|---|
| 181 | + trailer = (struct prp_rct *)skb_put(skb, HSR_HLEN); |
|---|
| 182 | + lsdu_size = skb->len - 14; |
|---|
| 183 | + if (frame->is_vlan) |
|---|
| 184 | + lsdu_size -= 4; |
|---|
| 185 | + prp_set_lan_id(trailer, port); |
|---|
| 186 | + set_prp_LSDU_size(trailer, lsdu_size); |
|---|
| 187 | + trailer->sequence_nr = htons(frame->sequence_nr); |
|---|
| 188 | + trailer->PRP_suffix = htons(ETH_P_PRP); |
|---|
| 189 | + |
|---|
| 190 | + return skb; |
|---|
| 191 | +} |
|---|
| 192 | + |
|---|
| 193 | +static void hsr_set_path_id(struct hsr_ethhdr *hsr_ethhdr, |
|---|
| 194 | + struct hsr_port *port) |
|---|
| 195 | +{ |
|---|
| 196 | + int path_id; |
|---|
| 197 | + |
|---|
| 198 | + if (port->type == HSR_PT_SLAVE_A) |
|---|
| 199 | + path_id = 0; |
|---|
| 200 | + else |
|---|
| 201 | + path_id = 1; |
|---|
| 202 | + |
|---|
| 203 | + set_hsr_tag_path(&hsr_ethhdr->hsr_tag, path_id); |
|---|
| 204 | +} |
|---|
| 205 | + |
|---|
| 206 | +static struct sk_buff *hsr_fill_tag(struct sk_buff *skb, |
|---|
| 207 | + struct hsr_frame_info *frame, |
|---|
| 208 | + struct hsr_port *port, u8 proto_version) |
|---|
| 209 | +{ |
|---|
| 210 | + struct hsr_ethhdr *hsr_ethhdr; |
|---|
| 211 | + int lsdu_size; |
|---|
| 212 | + |
|---|
| 213 | + /* pad to minimum packet size which is 60 + 6 (HSR tag) */ |
|---|
| 214 | + if (skb_put_padto(skb, ETH_ZLEN + HSR_HLEN)) |
|---|
| 215 | + return NULL; |
|---|
| 216 | + |
|---|
| 143 | 217 | lsdu_size = skb->len - 14; |
|---|
| 144 | 218 | if (frame->is_vlan) |
|---|
| 145 | 219 | lsdu_size -= 4; |
|---|
| 146 | 220 | |
|---|
| 147 | | - hsr_ethhdr = (struct hsr_ethhdr *) skb_mac_header(skb); |
|---|
| 221 | + hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb); |
|---|
| 148 | 222 | |
|---|
| 149 | | - set_hsr_tag_path(&hsr_ethhdr->hsr_tag, lane_id); |
|---|
| 223 | + hsr_set_path_id(hsr_ethhdr, port); |
|---|
| 150 | 224 | set_hsr_tag_LSDU_size(&hsr_ethhdr->hsr_tag, lsdu_size); |
|---|
| 151 | 225 | hsr_ethhdr->hsr_tag.sequence_nr = htons(frame->sequence_nr); |
|---|
| 152 | 226 | hsr_ethhdr->hsr_tag.encap_proto = hsr_ethhdr->ethhdr.h_proto; |
|---|
| 153 | | - hsr_ethhdr->ethhdr.h_proto = htons(protoVersion ? |
|---|
| 227 | + hsr_ethhdr->ethhdr.h_proto = htons(proto_version ? |
|---|
| 154 | 228 | ETH_P_HSR : ETH_P_PRP); |
|---|
| 229 | + |
|---|
| 230 | + return skb; |
|---|
| 155 | 231 | } |
|---|
| 156 | 232 | |
|---|
| 157 | | -static struct sk_buff *create_tagged_skb(struct sk_buff *skb_o, |
|---|
| 158 | | - struct hsr_frame_info *frame, |
|---|
| 159 | | - struct hsr_port *port) |
|---|
| 233 | +/* If the original frame was an HSR tagged frame, just clone it to be sent |
|---|
| 234 | + * unchanged. Otherwise, create a private frame especially tagged for 'port'. |
|---|
| 235 | + */ |
|---|
| 236 | +struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame, |
|---|
| 237 | + struct hsr_port *port) |
|---|
| 160 | 238 | { |
|---|
| 161 | | - int movelen; |
|---|
| 162 | 239 | unsigned char *dst, *src; |
|---|
| 163 | 240 | struct sk_buff *skb; |
|---|
| 241 | + int movelen; |
|---|
| 242 | + |
|---|
| 243 | + if (frame->skb_hsr) { |
|---|
| 244 | + struct hsr_ethhdr *hsr_ethhdr = |
|---|
| 245 | + (struct hsr_ethhdr *)skb_mac_header(frame->skb_hsr); |
|---|
| 246 | + |
|---|
| 247 | + /* set the lane id properly */ |
|---|
| 248 | + hsr_set_path_id(hsr_ethhdr, port); |
|---|
| 249 | + return skb_clone(frame->skb_hsr, GFP_ATOMIC); |
|---|
| 250 | + } |
|---|
| 164 | 251 | |
|---|
| 165 | 252 | /* Create the new skb with enough headroom to fit the HSR tag */ |
|---|
| 166 | | - skb = __pskb_copy(skb_o, skb_headroom(skb_o) + HSR_HLEN, GFP_ATOMIC); |
|---|
| 167 | | - if (skb == NULL) |
|---|
| 253 | + skb = __pskb_copy(frame->skb_std, |
|---|
| 254 | + skb_headroom(frame->skb_std) + HSR_HLEN, GFP_ATOMIC); |
|---|
| 255 | + if (!skb) |
|---|
| 168 | 256 | return NULL; |
|---|
| 169 | 257 | skb_reset_mac_header(skb); |
|---|
| 170 | 258 | |
|---|
| .. | .. |
|---|
| 180 | 268 | memmove(dst, src, movelen); |
|---|
| 181 | 269 | skb_reset_mac_header(skb); |
|---|
| 182 | 270 | |
|---|
| 183 | | - hsr_fill_tag(skb, frame, port, port->hsr->protVersion); |
|---|
| 271 | + /* skb_put_padto free skb on error and hsr_fill_tag returns NULL in |
|---|
| 272 | + * that case |
|---|
| 273 | + */ |
|---|
| 274 | + return hsr_fill_tag(skb, frame, port, port->hsr->prot_version); |
|---|
| 275 | +} |
|---|
| 276 | + |
|---|
| 277 | +struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame, |
|---|
| 278 | + struct hsr_port *port) |
|---|
| 279 | +{ |
|---|
| 280 | + struct sk_buff *skb; |
|---|
| 281 | + |
|---|
| 282 | + if (frame->skb_prp) { |
|---|
| 283 | + struct prp_rct *trailer = skb_get_PRP_rct(frame->skb_prp); |
|---|
| 284 | + |
|---|
| 285 | + if (trailer) { |
|---|
| 286 | + prp_set_lan_id(trailer, port); |
|---|
| 287 | + } else { |
|---|
| 288 | + WARN_ONCE(!trailer, "errored PRP skb"); |
|---|
| 289 | + return NULL; |
|---|
| 290 | + } |
|---|
| 291 | + return skb_clone(frame->skb_prp, GFP_ATOMIC); |
|---|
| 292 | + } |
|---|
| 293 | + |
|---|
| 294 | + skb = skb_copy_expand(frame->skb_std, 0, |
|---|
| 295 | + skb_tailroom(frame->skb_std) + HSR_HLEN, |
|---|
| 296 | + GFP_ATOMIC); |
|---|
| 297 | + prp_fill_rct(skb, frame, port); |
|---|
| 184 | 298 | |
|---|
| 185 | 299 | return skb; |
|---|
| 186 | 300 | } |
|---|
| 187 | | - |
|---|
| 188 | | -/* If the original frame was an HSR tagged frame, just clone it to be sent |
|---|
| 189 | | - * unchanged. Otherwise, create a private frame especially tagged for 'port'. |
|---|
| 190 | | - */ |
|---|
| 191 | | -static struct sk_buff *frame_get_tagged_skb(struct hsr_frame_info *frame, |
|---|
| 192 | | - struct hsr_port *port) |
|---|
| 193 | | -{ |
|---|
| 194 | | - if (frame->skb_hsr) |
|---|
| 195 | | - return skb_clone(frame->skb_hsr, GFP_ATOMIC); |
|---|
| 196 | | - |
|---|
| 197 | | - if ((port->type != HSR_PT_SLAVE_A) && (port->type != HSR_PT_SLAVE_B)) { |
|---|
| 198 | | - WARN_ONCE(1, "HSR: Bug: trying to create a tagged frame for a non-ring port"); |
|---|
| 199 | | - return NULL; |
|---|
| 200 | | - } |
|---|
| 201 | | - |
|---|
| 202 | | - return create_tagged_skb(frame->skb_std, frame, port); |
|---|
| 203 | | -} |
|---|
| 204 | | - |
|---|
| 205 | 301 | |
|---|
| 206 | 302 | static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev, |
|---|
| 207 | 303 | struct hsr_node *node_src) |
|---|
| 208 | 304 | { |
|---|
| 209 | 305 | bool was_multicast_frame; |
|---|
| 210 | | - int res; |
|---|
| 306 | + int res, recv_len; |
|---|
| 211 | 307 | |
|---|
| 212 | 308 | was_multicast_frame = (skb->pkt_type == PACKET_MULTICAST); |
|---|
| 213 | 309 | hsr_addr_subst_source(node_src, skb); |
|---|
| 214 | 310 | skb_pull(skb, ETH_HLEN); |
|---|
| 311 | + recv_len = skb->len; |
|---|
| 215 | 312 | res = netif_rx(skb); |
|---|
| 216 | 313 | if (res == NET_RX_DROP) { |
|---|
| 217 | 314 | dev->stats.rx_dropped++; |
|---|
| 218 | 315 | } else { |
|---|
| 219 | 316 | dev->stats.rx_packets++; |
|---|
| 220 | | - dev->stats.rx_bytes += skb->len; |
|---|
| 317 | + dev->stats.rx_bytes += recv_len; |
|---|
| 221 | 318 | if (was_multicast_frame) |
|---|
| 222 | 319 | dev->stats.multicast++; |
|---|
| 223 | 320 | } |
|---|
| .. | .. |
|---|
| 237 | 334 | return dev_queue_xmit(skb); |
|---|
| 238 | 335 | } |
|---|
| 239 | 336 | |
|---|
| 337 | +bool prp_drop_frame(struct hsr_frame_info *frame, struct hsr_port *port) |
|---|
| 338 | +{ |
|---|
| 339 | + return ((frame->port_rcv->type == HSR_PT_SLAVE_A && |
|---|
| 340 | + port->type == HSR_PT_SLAVE_B) || |
|---|
| 341 | + (frame->port_rcv->type == HSR_PT_SLAVE_B && |
|---|
| 342 | + port->type == HSR_PT_SLAVE_A)); |
|---|
| 343 | +} |
|---|
| 240 | 344 | |
|---|
| 241 | 345 | /* Forward the frame through all devices except: |
|---|
| 242 | 346 | * - Back through the receiving device |
|---|
| 243 | 347 | * - If it's a HSR frame: through a device where it has passed before |
|---|
| 348 | + * - if it's a PRP frame: through another PRP slave device (no bridge) |
|---|
| 244 | 349 | * - To the local HSR master only if the frame is directly addressed to it, or |
|---|
| 245 | 350 | * a non-supervision multicast or broadcast frame. |
|---|
| 246 | 351 | * |
|---|
| .. | .. |
|---|
| 255 | 360 | struct sk_buff *skb; |
|---|
| 256 | 361 | |
|---|
| 257 | 362 | hsr_for_each_port(frame->port_rcv->hsr, port) { |
|---|
| 363 | + struct hsr_priv *hsr = port->hsr; |
|---|
| 258 | 364 | /* Don't send frame back the way it came */ |
|---|
| 259 | 365 | if (port == frame->port_rcv) |
|---|
| 260 | 366 | continue; |
|---|
| 261 | 367 | |
|---|
| 262 | 368 | /* Don't deliver locally unless we should */ |
|---|
| 263 | | - if ((port->type == HSR_PT_MASTER) && !frame->is_local_dest) |
|---|
| 369 | + if (port->type == HSR_PT_MASTER && !frame->is_local_dest) |
|---|
| 264 | 370 | continue; |
|---|
| 265 | 371 | |
|---|
| 266 | 372 | /* Deliver frames directly addressed to us to master only */ |
|---|
| 267 | | - if ((port->type != HSR_PT_MASTER) && frame->is_local_exclusive) |
|---|
| 373 | + if (port->type != HSR_PT_MASTER && frame->is_local_exclusive) |
|---|
| 268 | 374 | continue; |
|---|
| 269 | 375 | |
|---|
| 270 | | - /* Don't send frame over port where it has been sent before */ |
|---|
| 271 | | - if (hsr_register_frame_out(port, frame->node_src, |
|---|
| 376 | + /* Don't send frame over port where it has been sent before. |
|---|
| 377 | + * Also fro SAN, this shouldn't be done. |
|---|
| 378 | + */ |
|---|
| 379 | + if (!frame->is_from_san && |
|---|
| 380 | + hsr_register_frame_out(port, frame->node_src, |
|---|
| 272 | 381 | frame->sequence_nr)) |
|---|
| 273 | 382 | continue; |
|---|
| 274 | 383 | |
|---|
| 275 | | - if (frame->is_supervision && (port->type == HSR_PT_MASTER)) { |
|---|
| 276 | | - hsr_handle_sup_frame(frame->skb_hsr, |
|---|
| 277 | | - frame->node_src, |
|---|
| 278 | | - frame->port_rcv); |
|---|
| 384 | + if (frame->is_supervision && port->type == HSR_PT_MASTER) { |
|---|
| 385 | + hsr_handle_sup_frame(frame); |
|---|
| 279 | 386 | continue; |
|---|
| 280 | 387 | } |
|---|
| 281 | 388 | |
|---|
| 389 | + /* Check if frame is to be dropped. Eg. for PRP no forward |
|---|
| 390 | + * between ports. |
|---|
| 391 | + */ |
|---|
| 392 | + if (hsr->proto_ops->drop_frame && |
|---|
| 393 | + hsr->proto_ops->drop_frame(frame, port)) |
|---|
| 394 | + continue; |
|---|
| 395 | + |
|---|
| 282 | 396 | if (port->type != HSR_PT_MASTER) |
|---|
| 283 | | - skb = frame_get_tagged_skb(frame, port); |
|---|
| 397 | + skb = hsr->proto_ops->create_tagged_frame(frame, port); |
|---|
| 284 | 398 | else |
|---|
| 285 | | - skb = frame_get_stripped_skb(frame, port); |
|---|
| 286 | | - if (skb == NULL) { |
|---|
| 287 | | - /* FIXME: Record the dropped frame? */ |
|---|
| 399 | + skb = hsr->proto_ops->get_untagged_frame(frame, port); |
|---|
| 400 | + |
|---|
| 401 | + if (!skb) { |
|---|
| 402 | + frame->port_rcv->dev->stats.rx_dropped++; |
|---|
| 288 | 403 | continue; |
|---|
| 289 | 404 | } |
|---|
| 290 | 405 | |
|---|
| .. | .. |
|---|
| 296 | 411 | } |
|---|
| 297 | 412 | } |
|---|
| 298 | 413 | |
|---|
| 299 | | - |
|---|
| 300 | 414 | static void check_local_dest(struct hsr_priv *hsr, struct sk_buff *skb, |
|---|
| 301 | 415 | struct hsr_frame_info *frame) |
|---|
| 302 | 416 | { |
|---|
| .. | .. |
|---|
| 307 | 421 | frame->is_local_exclusive = false; |
|---|
| 308 | 422 | } |
|---|
| 309 | 423 | |
|---|
| 310 | | - if ((skb->pkt_type == PACKET_HOST) || |
|---|
| 311 | | - (skb->pkt_type == PACKET_MULTICAST) || |
|---|
| 312 | | - (skb->pkt_type == PACKET_BROADCAST)) { |
|---|
| 424 | + if (skb->pkt_type == PACKET_HOST || |
|---|
| 425 | + skb->pkt_type == PACKET_MULTICAST || |
|---|
| 426 | + skb->pkt_type == PACKET_BROADCAST) { |
|---|
| 313 | 427 | frame->is_local_dest = true; |
|---|
| 314 | 428 | } else { |
|---|
| 315 | 429 | frame->is_local_dest = false; |
|---|
| 316 | 430 | } |
|---|
| 317 | 431 | } |
|---|
| 318 | 432 | |
|---|
| 319 | | - |
|---|
| 320 | | -static int hsr_fill_frame_info(struct hsr_frame_info *frame, |
|---|
| 321 | | - struct sk_buff *skb, struct hsr_port *port) |
|---|
| 433 | +static void handle_std_frame(struct sk_buff *skb, |
|---|
| 434 | + struct hsr_frame_info *frame) |
|---|
| 322 | 435 | { |
|---|
| 323 | | - struct ethhdr *ethhdr; |
|---|
| 436 | + struct hsr_port *port = frame->port_rcv; |
|---|
| 437 | + struct hsr_priv *hsr = port->hsr; |
|---|
| 324 | 438 | unsigned long irqflags; |
|---|
| 325 | 439 | |
|---|
| 326 | | - frame->is_supervision = is_supervision_frame(port->hsr, skb); |
|---|
| 327 | | - frame->node_src = hsr_get_node(port, skb, frame->is_supervision); |
|---|
| 328 | | - if (frame->node_src == NULL) |
|---|
| 329 | | - return -1; /* Unknown node and !is_supervision, or no mem */ |
|---|
| 440 | + frame->skb_hsr = NULL; |
|---|
| 441 | + frame->skb_prp = NULL; |
|---|
| 442 | + frame->skb_std = skb; |
|---|
| 330 | 443 | |
|---|
| 331 | | - ethhdr = (struct ethhdr *) skb_mac_header(skb); |
|---|
| 332 | | - frame->is_vlan = false; |
|---|
| 333 | | - if (ethhdr->h_proto == htons(ETH_P_8021Q)) { |
|---|
| 334 | | - frame->is_vlan = true; |
|---|
| 335 | | - /* FIXME: */ |
|---|
| 336 | | - WARN_ONCE(1, "HSR: VLAN not yet supported"); |
|---|
| 444 | + if (port->type != HSR_PT_MASTER) { |
|---|
| 445 | + frame->is_from_san = true; |
|---|
| 446 | + } else { |
|---|
| 447 | + /* Sequence nr for the master node */ |
|---|
| 448 | + spin_lock_irqsave(&hsr->seqnr_lock, irqflags); |
|---|
| 449 | + frame->sequence_nr = hsr->sequence_nr; |
|---|
| 450 | + hsr->sequence_nr++; |
|---|
| 451 | + spin_unlock_irqrestore(&hsr->seqnr_lock, irqflags); |
|---|
| 337 | 452 | } |
|---|
| 338 | | - if (ethhdr->h_proto == htons(ETH_P_PRP) |
|---|
| 339 | | - || ethhdr->h_proto == htons(ETH_P_HSR)) { |
|---|
| 453 | +} |
|---|
| 454 | + |
|---|
| 455 | +int hsr_fill_frame_info(__be16 proto, struct sk_buff *skb, |
|---|
| 456 | + struct hsr_frame_info *frame) |
|---|
| 457 | +{ |
|---|
| 458 | + if (proto == htons(ETH_P_PRP) || |
|---|
| 459 | + proto == htons(ETH_P_HSR)) { |
|---|
| 460 | + /* Check if skb contains hsr_ethhdr */ |
|---|
| 461 | + if (skb->mac_len < sizeof(struct hsr_ethhdr)) |
|---|
| 462 | + return -EINVAL; |
|---|
| 463 | + |
|---|
| 464 | + /* HSR tagged frame :- Data or Supervision */ |
|---|
| 340 | 465 | frame->skb_std = NULL; |
|---|
| 466 | + frame->skb_prp = NULL; |
|---|
| 341 | 467 | frame->skb_hsr = skb; |
|---|
| 342 | 468 | frame->sequence_nr = hsr_get_skb_sequence_nr(skb); |
|---|
| 343 | | - } else { |
|---|
| 344 | | - frame->skb_std = skb; |
|---|
| 345 | | - frame->skb_hsr = NULL; |
|---|
| 346 | | - /* Sequence nr for the master node */ |
|---|
| 347 | | - spin_lock_irqsave(&port->hsr->seqnr_lock, irqflags); |
|---|
| 348 | | - frame->sequence_nr = port->hsr->sequence_nr; |
|---|
| 349 | | - port->hsr->sequence_nr++; |
|---|
| 350 | | - spin_unlock_irqrestore(&port->hsr->seqnr_lock, irqflags); |
|---|
| 469 | + return 0; |
|---|
| 351 | 470 | } |
|---|
| 352 | 471 | |
|---|
| 472 | + /* Standard frame or PRP from master port */ |
|---|
| 473 | + handle_std_frame(skb, frame); |
|---|
| 474 | + |
|---|
| 475 | + return 0; |
|---|
| 476 | +} |
|---|
| 477 | + |
|---|
| 478 | +int prp_fill_frame_info(__be16 proto, struct sk_buff *skb, |
|---|
| 479 | + struct hsr_frame_info *frame) |
|---|
| 480 | +{ |
|---|
| 481 | + /* Supervision frame */ |
|---|
| 482 | + struct prp_rct *rct = skb_get_PRP_rct(skb); |
|---|
| 483 | + |
|---|
| 484 | + if (rct && |
|---|
| 485 | + prp_check_lsdu_size(skb, rct, frame->is_supervision)) { |
|---|
| 486 | + frame->skb_hsr = NULL; |
|---|
| 487 | + frame->skb_std = NULL; |
|---|
| 488 | + frame->skb_prp = skb; |
|---|
| 489 | + frame->sequence_nr = prp_get_skb_sequence_nr(rct); |
|---|
| 490 | + return 0; |
|---|
| 491 | + } |
|---|
| 492 | + handle_std_frame(skb, frame); |
|---|
| 493 | + |
|---|
| 494 | + return 0; |
|---|
| 495 | +} |
|---|
| 496 | + |
|---|
| 497 | +static int fill_frame_info(struct hsr_frame_info *frame, |
|---|
| 498 | + struct sk_buff *skb, struct hsr_port *port) |
|---|
| 499 | +{ |
|---|
| 500 | + struct hsr_priv *hsr = port->hsr; |
|---|
| 501 | + struct hsr_vlan_ethhdr *vlan_hdr; |
|---|
| 502 | + struct ethhdr *ethhdr; |
|---|
| 503 | + __be16 proto; |
|---|
| 504 | + int ret; |
|---|
| 505 | + |
|---|
| 506 | + /* Check if skb contains ethhdr */ |
|---|
| 507 | + if (skb->mac_len < sizeof(struct ethhdr)) |
|---|
| 508 | + return -EINVAL; |
|---|
| 509 | + |
|---|
| 510 | + memset(frame, 0, sizeof(*frame)); |
|---|
| 511 | + frame->is_supervision = is_supervision_frame(port->hsr, skb); |
|---|
| 512 | + frame->node_src = hsr_get_node(port, &hsr->node_db, skb, |
|---|
| 513 | + frame->is_supervision, |
|---|
| 514 | + port->type); |
|---|
| 515 | + if (!frame->node_src) |
|---|
| 516 | + return -1; /* Unknown node and !is_supervision, or no mem */ |
|---|
| 517 | + |
|---|
| 518 | + ethhdr = (struct ethhdr *)skb_mac_header(skb); |
|---|
| 519 | + frame->is_vlan = false; |
|---|
| 520 | + proto = ethhdr->h_proto; |
|---|
| 521 | + |
|---|
| 522 | + if (proto == htons(ETH_P_8021Q)) |
|---|
| 523 | + frame->is_vlan = true; |
|---|
| 524 | + |
|---|
| 525 | + if (frame->is_vlan) { |
|---|
| 526 | + vlan_hdr = (struct hsr_vlan_ethhdr *)ethhdr; |
|---|
| 527 | + proto = vlan_hdr->vlanhdr.h_vlan_encapsulated_proto; |
|---|
| 528 | + /* FIXME: */ |
|---|
| 529 | + netdev_warn_once(skb->dev, "VLAN not yet supported"); |
|---|
| 530 | + } |
|---|
| 531 | + |
|---|
| 532 | + frame->is_from_san = false; |
|---|
| 353 | 533 | frame->port_rcv = port; |
|---|
| 534 | + ret = hsr->proto_ops->fill_frame_info(proto, skb, frame); |
|---|
| 535 | + if (ret) |
|---|
| 536 | + return ret; |
|---|
| 537 | + |
|---|
| 354 | 538 | check_local_dest(port->hsr, skb, frame); |
|---|
| 355 | 539 | |
|---|
| 356 | 540 | return 0; |
|---|
| .. | .. |
|---|
| 361 | 545 | { |
|---|
| 362 | 546 | struct hsr_frame_info frame; |
|---|
| 363 | 547 | |
|---|
| 364 | | - if (skb_mac_header(skb) != skb->data) { |
|---|
| 365 | | - WARN_ONCE(1, "%s:%d: Malformed frame (port_src %s)\n", |
|---|
| 366 | | - __FILE__, __LINE__, port->dev->name); |
|---|
| 548 | + if (fill_frame_info(&frame, skb, port) < 0) |
|---|
| 367 | 549 | goto out_drop; |
|---|
| 368 | | - } |
|---|
| 369 | 550 | |
|---|
| 370 | | - if (hsr_fill_frame_info(&frame, skb, port) < 0) |
|---|
| 371 | | - goto out_drop; |
|---|
| 372 | 551 | hsr_register_frame_in(frame.node_src, port, frame.sequence_nr); |
|---|
| 373 | 552 | hsr_forward_do(&frame); |
|---|
| 553 | + /* Gets called for ingress frames as well as egress from master port. |
|---|
| 554 | + * So check and increment stats for master port only here. |
|---|
| 555 | + */ |
|---|
| 556 | + if (port->type == HSR_PT_MASTER) { |
|---|
| 557 | + port->dev->stats.tx_packets++; |
|---|
| 558 | + port->dev->stats.tx_bytes += skb->len; |
|---|
| 559 | + } |
|---|
| 374 | 560 | |
|---|
| 375 | | - if (frame.skb_hsr != NULL) |
|---|
| 376 | | - kfree_skb(frame.skb_hsr); |
|---|
| 377 | | - if (frame.skb_std != NULL) |
|---|
| 378 | | - kfree_skb(frame.skb_std); |
|---|
| 561 | + kfree_skb(frame.skb_hsr); |
|---|
| 562 | + kfree_skb(frame.skb_prp); |
|---|
| 563 | + kfree_skb(frame.skb_std); |
|---|
| 379 | 564 | return; |
|---|
| 380 | 565 | |
|---|
| 381 | 566 | out_drop: |
|---|