hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/net/hsr/hsr_forward.c
....@@ -1,12 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /* 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.
73 *
84 * Author(s):
95 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
6
+ *
7
+ * Frame router for HSR and PRP.
108 */
119
1210 #include "hsr_forward.h"
....@@ -17,21 +15,7 @@
1715 #include "hsr_main.h"
1816 #include "hsr_framereg.h"
1917
20
-
2118 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
-
3519
3620 /* The uses I can see for these HSR supervision frames are:
3721 * 1) Use the frames that are sent after node initialization ("HSR_TLV.Type =
....@@ -50,48 +34,49 @@
5034 */
5135 static bool is_supervision_frame(struct hsr_priv *hsr, struct sk_buff *skb)
5236 {
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;
5640
5741 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);
5943
6044 /* Correct addr? */
61
- if (!ether_addr_equal(ethHdr->h_dest,
45
+ if (!ether_addr_equal(eth_hdr->h_dest,
6246 hsr->sup_multicast_addr))
6347 return false;
6448
6549 /* 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)))
6852 return false;
6953
7054 /* 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))
7458 return false;
7559
76
- hsrSupTag = &hsrV1Hdr->hsr_sup;
60
+ hsr_sup_tag = &hsr_V1_hdr->hsr_sup;
7761 } 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;
7964 }
8065
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)
8370 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))
8773 return false;
8874
8975 return true;
9076 }
9177
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)
9580 {
9681 struct sk_buff *skb;
9782 int copylen;
....@@ -100,7 +85,7 @@
10085 skb_pull(skb_in, HSR_HLEN);
10186 skb = __pskb_copy(skb_in, skb_headroom(skb_in) - HSR_HLEN, GFP_ATOMIC);
10287 skb_push(skb_in, HSR_HLEN);
103
- if (skb == NULL)
88
+ if (!skb)
10489 return NULL;
10590
10691 skb_reset_mac_header(skb);
....@@ -108,7 +93,7 @@
10893 if (skb->ip_summed == CHECKSUM_PARTIAL)
10994 skb->csum_start -= HSR_HLEN;
11095
111
- copylen = 2*ETH_ALEN;
96
+ copylen = 2 * ETH_ALEN;
11297 if (frame->is_vlan)
11398 copylen += VLAN_HLEN;
11499 src = skb_mac_header(skb_in);
....@@ -119,52 +104,157 @@
119104 return skb;
120105 }
121106
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)
124109 {
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
+
127122 return skb_clone(frame->skb_std, GFP_ATOMIC);
128123 }
129124
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)
133127 {
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
+{
135151 int lane_id;
136
- int lsdu_size;
137152
138153 if (port->type == HSR_PT_SLAVE_A)
139154 lane_id = 0;
140155 else
141156 lane_id = 1;
142157
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
+ skb->protocol = eth_hdr(skb)->h_proto;
190
+
191
+ return skb;
192
+}
193
+
194
+static void hsr_set_path_id(struct hsr_ethhdr *hsr_ethhdr,
195
+ struct hsr_port *port)
196
+{
197
+ int path_id;
198
+
199
+ if (port->type == HSR_PT_SLAVE_A)
200
+ path_id = 0;
201
+ else
202
+ path_id = 1;
203
+
204
+ set_hsr_tag_path(&hsr_ethhdr->hsr_tag, path_id);
205
+}
206
+
207
+static struct sk_buff *hsr_fill_tag(struct sk_buff *skb,
208
+ struct hsr_frame_info *frame,
209
+ struct hsr_port *port, u8 proto_version)
210
+{
211
+ struct hsr_ethhdr *hsr_ethhdr;
212
+ int lsdu_size;
213
+
214
+ /* pad to minimum packet size which is 60 + 6 (HSR tag) */
215
+ if (skb_put_padto(skb, ETH_ZLEN + HSR_HLEN))
216
+ return NULL;
217
+
143218 lsdu_size = skb->len - 14;
144219 if (frame->is_vlan)
145220 lsdu_size -= 4;
146221
147
- hsr_ethhdr = (struct hsr_ethhdr *) skb_mac_header(skb);
222
+ hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb);
148223
149
- set_hsr_tag_path(&hsr_ethhdr->hsr_tag, lane_id);
224
+ hsr_set_path_id(hsr_ethhdr, port);
150225 set_hsr_tag_LSDU_size(&hsr_ethhdr->hsr_tag, lsdu_size);
151226 hsr_ethhdr->hsr_tag.sequence_nr = htons(frame->sequence_nr);
152227 hsr_ethhdr->hsr_tag.encap_proto = hsr_ethhdr->ethhdr.h_proto;
153
- hsr_ethhdr->ethhdr.h_proto = htons(protoVersion ?
228
+ hsr_ethhdr->ethhdr.h_proto = htons(proto_version ?
154229 ETH_P_HSR : ETH_P_PRP);
230
+ skb->protocol = hsr_ethhdr->ethhdr.h_proto;
231
+
232
+ return skb;
155233 }
156234
157
-static struct sk_buff *create_tagged_skb(struct sk_buff *skb_o,
158
- struct hsr_frame_info *frame,
159
- struct hsr_port *port)
235
+/* If the original frame was an HSR tagged frame, just clone it to be sent
236
+ * unchanged. Otherwise, create a private frame especially tagged for 'port'.
237
+ */
238
+struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
239
+ struct hsr_port *port)
160240 {
161
- int movelen;
162241 unsigned char *dst, *src;
163242 struct sk_buff *skb;
243
+ int movelen;
244
+
245
+ if (frame->skb_hsr) {
246
+ struct hsr_ethhdr *hsr_ethhdr =
247
+ (struct hsr_ethhdr *)skb_mac_header(frame->skb_hsr);
248
+
249
+ /* set the lane id properly */
250
+ hsr_set_path_id(hsr_ethhdr, port);
251
+ return skb_clone(frame->skb_hsr, GFP_ATOMIC);
252
+ }
164253
165254 /* 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)
255
+ skb = __pskb_copy(frame->skb_std,
256
+ skb_headroom(frame->skb_std) + HSR_HLEN, GFP_ATOMIC);
257
+ if (!skb)
168258 return NULL;
169259 skb_reset_mac_header(skb);
170260
....@@ -180,44 +270,53 @@
180270 memmove(dst, src, movelen);
181271 skb_reset_mac_header(skb);
182272
183
- hsr_fill_tag(skb, frame, port, port->hsr->protVersion);
273
+ /* skb_put_padto free skb on error and hsr_fill_tag returns NULL in
274
+ * that case
275
+ */
276
+ return hsr_fill_tag(skb, frame, port, port->hsr->prot_version);
277
+}
278
+
279
+struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,
280
+ struct hsr_port *port)
281
+{
282
+ struct sk_buff *skb;
283
+
284
+ if (frame->skb_prp) {
285
+ struct prp_rct *trailer = skb_get_PRP_rct(frame->skb_prp);
286
+
287
+ if (trailer) {
288
+ prp_set_lan_id(trailer, port);
289
+ } else {
290
+ WARN_ONCE(!trailer, "errored PRP skb");
291
+ return NULL;
292
+ }
293
+ return skb_clone(frame->skb_prp, GFP_ATOMIC);
294
+ }
295
+
296
+ skb = skb_copy_expand(frame->skb_std, 0,
297
+ skb_tailroom(frame->skb_std) + HSR_HLEN,
298
+ GFP_ATOMIC);
299
+ prp_fill_rct(skb, frame, port);
184300
185301 return skb;
186302 }
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
-
205303
206304 static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev,
207305 struct hsr_node *node_src)
208306 {
209307 bool was_multicast_frame;
210
- int res;
308
+ int res, recv_len;
211309
212310 was_multicast_frame = (skb->pkt_type == PACKET_MULTICAST);
213311 hsr_addr_subst_source(node_src, skb);
214312 skb_pull(skb, ETH_HLEN);
313
+ recv_len = skb->len;
215314 res = netif_rx(skb);
216315 if (res == NET_RX_DROP) {
217316 dev->stats.rx_dropped++;
218317 } else {
219318 dev->stats.rx_packets++;
220
- dev->stats.rx_bytes += skb->len;
319
+ dev->stats.rx_bytes += recv_len;
221320 if (was_multicast_frame)
222321 dev->stats.multicast++;
223322 }
....@@ -237,10 +336,18 @@
237336 return dev_queue_xmit(skb);
238337 }
239338
339
+bool prp_drop_frame(struct hsr_frame_info *frame, struct hsr_port *port)
340
+{
341
+ return ((frame->port_rcv->type == HSR_PT_SLAVE_A &&
342
+ port->type == HSR_PT_SLAVE_B) ||
343
+ (frame->port_rcv->type == HSR_PT_SLAVE_B &&
344
+ port->type == HSR_PT_SLAVE_A));
345
+}
240346
241347 /* Forward the frame through all devices except:
242348 * - Back through the receiving device
243349 * - If it's a HSR frame: through a device where it has passed before
350
+ * - if it's a PRP frame: through another PRP slave device (no bridge)
244351 * - To the local HSR master only if the frame is directly addressed to it, or
245352 * a non-supervision multicast or broadcast frame.
246353 *
....@@ -255,36 +362,46 @@
255362 struct sk_buff *skb;
256363
257364 hsr_for_each_port(frame->port_rcv->hsr, port) {
365
+ struct hsr_priv *hsr = port->hsr;
258366 /* Don't send frame back the way it came */
259367 if (port == frame->port_rcv)
260368 continue;
261369
262370 /* Don't deliver locally unless we should */
263
- if ((port->type == HSR_PT_MASTER) && !frame->is_local_dest)
371
+ if (port->type == HSR_PT_MASTER && !frame->is_local_dest)
264372 continue;
265373
266374 /* Deliver frames directly addressed to us to master only */
267
- if ((port->type != HSR_PT_MASTER) && frame->is_local_exclusive)
375
+ if (port->type != HSR_PT_MASTER && frame->is_local_exclusive)
268376 continue;
269377
270
- /* Don't send frame over port where it has been sent before */
271
- if (hsr_register_frame_out(port, frame->node_src,
378
+ /* Don't send frame over port where it has been sent before.
379
+ * Also fro SAN, this shouldn't be done.
380
+ */
381
+ if (!frame->is_from_san &&
382
+ hsr_register_frame_out(port, frame->node_src,
272383 frame->sequence_nr))
273384 continue;
274385
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);
386
+ if (frame->is_supervision && port->type == HSR_PT_MASTER) {
387
+ hsr_handle_sup_frame(frame);
279388 continue;
280389 }
281390
391
+ /* Check if frame is to be dropped. Eg. for PRP no forward
392
+ * between ports.
393
+ */
394
+ if (hsr->proto_ops->drop_frame &&
395
+ hsr->proto_ops->drop_frame(frame, port))
396
+ continue;
397
+
282398 if (port->type != HSR_PT_MASTER)
283
- skb = frame_get_tagged_skb(frame, port);
399
+ skb = hsr->proto_ops->create_tagged_frame(frame, port);
284400 else
285
- skb = frame_get_stripped_skb(frame, port);
286
- if (skb == NULL) {
287
- /* FIXME: Record the dropped frame? */
401
+ skb = hsr->proto_ops->get_untagged_frame(frame, port);
402
+
403
+ if (!skb) {
404
+ frame->port_rcv->dev->stats.rx_dropped++;
288405 continue;
289406 }
290407
....@@ -296,7 +413,6 @@
296413 }
297414 }
298415
299
-
300416 static void check_local_dest(struct hsr_priv *hsr, struct sk_buff *skb,
301417 struct hsr_frame_info *frame)
302418 {
....@@ -307,50 +423,123 @@
307423 frame->is_local_exclusive = false;
308424 }
309425
310
- if ((skb->pkt_type == PACKET_HOST) ||
311
- (skb->pkt_type == PACKET_MULTICAST) ||
312
- (skb->pkt_type == PACKET_BROADCAST)) {
426
+ if (skb->pkt_type == PACKET_HOST ||
427
+ skb->pkt_type == PACKET_MULTICAST ||
428
+ skb->pkt_type == PACKET_BROADCAST) {
313429 frame->is_local_dest = true;
314430 } else {
315431 frame->is_local_dest = false;
316432 }
317433 }
318434
319
-
320
-static int hsr_fill_frame_info(struct hsr_frame_info *frame,
321
- struct sk_buff *skb, struct hsr_port *port)
435
+static void handle_std_frame(struct sk_buff *skb,
436
+ struct hsr_frame_info *frame)
322437 {
323
- struct ethhdr *ethhdr;
324
- unsigned long irqflags;
438
+ struct hsr_port *port = frame->port_rcv;
439
+ struct hsr_priv *hsr = port->hsr;
325440
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 */
441
+ frame->skb_hsr = NULL;
442
+ frame->skb_prp = NULL;
443
+ frame->skb_std = skb;
330444
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");
445
+ if (port->type != HSR_PT_MASTER) {
446
+ frame->is_from_san = true;
447
+ } else {
448
+ /* Sequence nr for the master node */
449
+ lockdep_assert_held(&hsr->seqnr_lock);
450
+ frame->sequence_nr = hsr->sequence_nr;
451
+ hsr->sequence_nr++;
337452 }
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
+ struct hsr_port *port = frame->port_rcv;
459
+ struct hsr_priv *hsr = port->hsr;
460
+
461
+ /* HSRv0 supervisory frames double as a tag so treat them as tagged. */
462
+ if ((!hsr->prot_version && proto == htons(ETH_P_PRP)) ||
463
+ proto == htons(ETH_P_HSR)) {
464
+ /* Check if skb contains hsr_ethhdr */
465
+ if (skb->mac_len < sizeof(struct hsr_ethhdr))
466
+ return -EINVAL;
467
+
468
+ /* HSR tagged frame :- Data or Supervision */
340469 frame->skb_std = NULL;
470
+ frame->skb_prp = NULL;
341471 frame->skb_hsr = skb;
342472 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);
473
+ return 0;
351474 }
352475
476
+ /* Standard frame or PRP from master port */
477
+ handle_std_frame(skb, frame);
478
+
479
+ return 0;
480
+}
481
+
482
+int prp_fill_frame_info(__be16 proto, struct sk_buff *skb,
483
+ struct hsr_frame_info *frame)
484
+{
485
+ /* Supervision frame */
486
+ struct prp_rct *rct = skb_get_PRP_rct(skb);
487
+
488
+ if (rct &&
489
+ prp_check_lsdu_size(skb, rct, frame->is_supervision)) {
490
+ frame->skb_hsr = NULL;
491
+ frame->skb_std = NULL;
492
+ frame->skb_prp = skb;
493
+ frame->sequence_nr = prp_get_skb_sequence_nr(rct);
494
+ return 0;
495
+ }
496
+ handle_std_frame(skb, frame);
497
+
498
+ return 0;
499
+}
500
+
501
+static int fill_frame_info(struct hsr_frame_info *frame,
502
+ struct sk_buff *skb, struct hsr_port *port)
503
+{
504
+ struct hsr_priv *hsr = port->hsr;
505
+ struct hsr_vlan_ethhdr *vlan_hdr;
506
+ struct ethhdr *ethhdr;
507
+ __be16 proto;
508
+ int ret;
509
+
510
+ /* Check if skb contains ethhdr */
511
+ if (skb->mac_len < sizeof(struct ethhdr))
512
+ return -EINVAL;
513
+
514
+ memset(frame, 0, sizeof(*frame));
515
+ frame->is_supervision = is_supervision_frame(port->hsr, skb);
516
+ frame->node_src = hsr_get_node(port, &hsr->node_db, skb,
517
+ frame->is_supervision,
518
+ port->type);
519
+ if (!frame->node_src)
520
+ return -1; /* Unknown node and !is_supervision, or no mem */
521
+
522
+ ethhdr = (struct ethhdr *)skb_mac_header(skb);
523
+ frame->is_vlan = false;
524
+ proto = ethhdr->h_proto;
525
+
526
+ if (proto == htons(ETH_P_8021Q))
527
+ frame->is_vlan = true;
528
+
529
+ if (frame->is_vlan) {
530
+ vlan_hdr = (struct hsr_vlan_ethhdr *)ethhdr;
531
+ proto = vlan_hdr->vlanhdr.h_vlan_encapsulated_proto;
532
+ /* FIXME: */
533
+ netdev_warn_once(skb->dev, "VLAN not yet supported");
534
+ return -EINVAL;
535
+ }
536
+
537
+ frame->is_from_san = false;
353538 frame->port_rcv = port;
539
+ ret = hsr->proto_ops->fill_frame_info(proto, skb, frame);
540
+ if (ret)
541
+ return ret;
542
+
354543 check_local_dest(port->hsr, skb, frame);
355544
356545 return 0;
....@@ -361,24 +550,28 @@
361550 {
362551 struct hsr_frame_info frame;
363552
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);
553
+ rcu_read_lock();
554
+ if (fill_frame_info(&frame, skb, port) < 0)
367555 goto out_drop;
368
- }
369556
370
- if (hsr_fill_frame_info(&frame, skb, port) < 0)
371
- goto out_drop;
372557 hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
373558 hsr_forward_do(&frame);
559
+ rcu_read_unlock();
560
+ /* Gets called for ingress frames as well as egress from master port.
561
+ * So check and increment stats for master port only here.
562
+ */
563
+ if (port->type == HSR_PT_MASTER) {
564
+ port->dev->stats.tx_packets++;
565
+ port->dev->stats.tx_bytes += skb->len;
566
+ }
374567
375
- if (frame.skb_hsr != NULL)
376
- kfree_skb(frame.skb_hsr);
377
- if (frame.skb_std != NULL)
378
- kfree_skb(frame.skb_std);
568
+ kfree_skb(frame.skb_hsr);
569
+ kfree_skb(frame.skb_prp);
570
+ kfree_skb(frame.skb_std);
379571 return;
380572
381573 out_drop:
574
+ rcu_read_unlock();
382575 port->dev->stats.tx_dropped++;
383576 kfree_skb(skb);
384577 }