forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
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,155 @@
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
+
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
+
143217 lsdu_size = skb->len - 14;
144218 if (frame->is_vlan)
145219 lsdu_size -= 4;
146220
147
- hsr_ethhdr = (struct hsr_ethhdr *) skb_mac_header(skb);
221
+ hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb);
148222
149
- set_hsr_tag_path(&hsr_ethhdr->hsr_tag, lane_id);
223
+ hsr_set_path_id(hsr_ethhdr, port);
150224 set_hsr_tag_LSDU_size(&hsr_ethhdr->hsr_tag, lsdu_size);
151225 hsr_ethhdr->hsr_tag.sequence_nr = htons(frame->sequence_nr);
152226 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 ?
154228 ETH_P_HSR : ETH_P_PRP);
229
+
230
+ return skb;
155231 }
156232
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)
160238 {
161
- int movelen;
162239 unsigned char *dst, *src;
163240 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
+ }
164251
165252 /* 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)
168256 return NULL;
169257 skb_reset_mac_header(skb);
170258
....@@ -180,44 +268,53 @@
180268 memmove(dst, src, movelen);
181269 skb_reset_mac_header(skb);
182270
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);
184298
185299 return skb;
186300 }
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
-
205301
206302 static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev,
207303 struct hsr_node *node_src)
208304 {
209305 bool was_multicast_frame;
210
- int res;
306
+ int res, recv_len;
211307
212308 was_multicast_frame = (skb->pkt_type == PACKET_MULTICAST);
213309 hsr_addr_subst_source(node_src, skb);
214310 skb_pull(skb, ETH_HLEN);
311
+ recv_len = skb->len;
215312 res = netif_rx(skb);
216313 if (res == NET_RX_DROP) {
217314 dev->stats.rx_dropped++;
218315 } else {
219316 dev->stats.rx_packets++;
220
- dev->stats.rx_bytes += skb->len;
317
+ dev->stats.rx_bytes += recv_len;
221318 if (was_multicast_frame)
222319 dev->stats.multicast++;
223320 }
....@@ -237,10 +334,18 @@
237334 return dev_queue_xmit(skb);
238335 }
239336
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
+}
240344
241345 /* Forward the frame through all devices except:
242346 * - Back through the receiving device
243347 * - 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)
244349 * - To the local HSR master only if the frame is directly addressed to it, or
245350 * a non-supervision multicast or broadcast frame.
246351 *
....@@ -255,36 +360,46 @@
255360 struct sk_buff *skb;
256361
257362 hsr_for_each_port(frame->port_rcv->hsr, port) {
363
+ struct hsr_priv *hsr = port->hsr;
258364 /* Don't send frame back the way it came */
259365 if (port == frame->port_rcv)
260366 continue;
261367
262368 /* 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)
264370 continue;
265371
266372 /* 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)
268374 continue;
269375
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,
272381 frame->sequence_nr))
273382 continue;
274383
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);
279386 continue;
280387 }
281388
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
+
282396 if (port->type != HSR_PT_MASTER)
283
- skb = frame_get_tagged_skb(frame, port);
397
+ skb = hsr->proto_ops->create_tagged_frame(frame, port);
284398 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++;
288403 continue;
289404 }
290405
....@@ -296,7 +411,6 @@
296411 }
297412 }
298413
299
-
300414 static void check_local_dest(struct hsr_priv *hsr, struct sk_buff *skb,
301415 struct hsr_frame_info *frame)
302416 {
....@@ -307,50 +421,120 @@
307421 frame->is_local_exclusive = false;
308422 }
309423
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) {
313427 frame->is_local_dest = true;
314428 } else {
315429 frame->is_local_dest = false;
316430 }
317431 }
318432
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)
322435 {
323
- struct ethhdr *ethhdr;
436
+ struct hsr_port *port = frame->port_rcv;
437
+ struct hsr_priv *hsr = port->hsr;
324438 unsigned long irqflags;
325439
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;
330443
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);
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
+ 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 */
340465 frame->skb_std = NULL;
466
+ frame->skb_prp = NULL;
341467 frame->skb_hsr = skb;
342468 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;
351470 }
352471
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;
353533 frame->port_rcv = port;
534
+ ret = hsr->proto_ops->fill_frame_info(proto, skb, frame);
535
+ if (ret)
536
+ return ret;
537
+
354538 check_local_dest(port->hsr, skb, frame);
355539
356540 return 0;
....@@ -361,21 +545,22 @@
361545 {
362546 struct hsr_frame_info frame;
363547
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)
367549 goto out_drop;
368
- }
369550
370
- if (hsr_fill_frame_info(&frame, skb, port) < 0)
371
- goto out_drop;
372551 hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
373552 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
+ }
374560
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);
379564 return;
380565
381566 out_drop: