Lines Matching +full:frame +full:- +full:master
1 /* Copyright 2011-2014 Autronica Fire and Security AS
9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
40 * --
41 * Or not - resetting the counter and bridging the frame would create a
45 * frame is received from a particular node, we know something is wrong.
61 if (!ether_addr_equal(ethHdr->h_dest, in is_supervision_frame()
62 hsr->sup_multicast_addr)) in is_supervision_frame()
66 if (!(ethHdr->h_proto == htons(ETH_P_PRP) in is_supervision_frame()
67 || ethHdr->h_proto == htons(ETH_P_HSR))) in is_supervision_frame()
71 if (ethHdr->h_proto == htons(ETH_P_HSR)) { /* Okay HSRv1. */ in is_supervision_frame()
73 if (hsrV1Hdr->hsr.encap_proto != htons(ETH_P_PRP)) in is_supervision_frame()
76 hsrSupTag = &hsrV1Hdr->hsr_sup; in is_supervision_frame()
78 hsrSupTag = &((struct hsrv0_ethhdr_sp *) skb_mac_header(skb))->hsr_sup; in is_supervision_frame()
81 if ((hsrSupTag->HSR_TLV_Type != HSR_TLV_ANNOUNCE) && in is_supervision_frame()
82 (hsrSupTag->HSR_TLV_Type != HSR_TLV_LIFE_CHECK)) in is_supervision_frame()
84 if ((hsrSupTag->HSR_TLV_Length != 12) && in is_supervision_frame()
85 (hsrSupTag->HSR_TLV_Length != in is_supervision_frame()
94 struct hsr_frame_info *frame) in create_stripped_skb() argument
101 skb = __pskb_copy(skb_in, skb_headroom(skb_in) - HSR_HLEN, GFP_ATOMIC); in create_stripped_skb()
108 if (skb->ip_summed == CHECKSUM_PARTIAL) in create_stripped_skb()
109 skb->csum_start -= HSR_HLEN; in create_stripped_skb()
112 if (frame->is_vlan) in create_stripped_skb()
118 skb->protocol = eth_hdr(skb)->h_proto; in create_stripped_skb()
122 static struct sk_buff *frame_get_stripped_skb(struct hsr_frame_info *frame, in frame_get_stripped_skb() argument
125 if (!frame->skb_std) in frame_get_stripped_skb()
126 frame->skb_std = create_stripped_skb(frame->skb_hsr, frame); in frame_get_stripped_skb()
127 return skb_clone(frame->skb_std, GFP_ATOMIC); in frame_get_stripped_skb()
131 static void hsr_fill_tag(struct sk_buff *skb, struct hsr_frame_info *frame, in hsr_fill_tag() argument
138 if (port->type == HSR_PT_SLAVE_A) in hsr_fill_tag()
143 lsdu_size = skb->len - 14; in hsr_fill_tag()
144 if (frame->is_vlan) in hsr_fill_tag()
145 lsdu_size -= 4; in hsr_fill_tag()
149 set_hsr_tag_path(&hsr_ethhdr->hsr_tag, lane_id); in hsr_fill_tag()
150 set_hsr_tag_LSDU_size(&hsr_ethhdr->hsr_tag, lsdu_size); in hsr_fill_tag()
151 hsr_ethhdr->hsr_tag.sequence_nr = htons(frame->sequence_nr); in hsr_fill_tag()
152 hsr_ethhdr->hsr_tag.encap_proto = hsr_ethhdr->ethhdr.h_proto; in hsr_fill_tag()
153 hsr_ethhdr->ethhdr.h_proto = htons(protoVersion ? in hsr_fill_tag()
158 struct hsr_frame_info *frame, in create_tagged_skb() argument
171 if (skb->ip_summed == CHECKSUM_PARTIAL) in create_tagged_skb()
172 skb->csum_start += HSR_HLEN; in create_tagged_skb()
175 if (frame->is_vlan) in create_tagged_skb()
183 hsr_fill_tag(skb, frame, port, port->hsr->protVersion); in create_tagged_skb()
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'.
191 static struct sk_buff *frame_get_tagged_skb(struct hsr_frame_info *frame, in frame_get_tagged_skb() argument
194 if (frame->skb_hsr) in frame_get_tagged_skb()
195 return skb_clone(frame->skb_hsr, GFP_ATOMIC); in frame_get_tagged_skb()
197 if ((port->type != HSR_PT_SLAVE_A) && (port->type != HSR_PT_SLAVE_B)) { in frame_get_tagged_skb()
198 WARN_ONCE(1, "HSR: Bug: trying to create a tagged frame for a non-ring port"); in frame_get_tagged_skb()
202 return create_tagged_skb(frame->skb_std, frame, port); in frame_get_tagged_skb()
212 was_multicast_frame = (skb->pkt_type == PACKET_MULTICAST); in hsr_deliver_master()
217 dev->stats.rx_dropped++; in hsr_deliver_master()
219 dev->stats.rx_packets++; in hsr_deliver_master()
220 dev->stats.rx_bytes += skb->len; in hsr_deliver_master()
222 dev->stats.multicast++; in hsr_deliver_master()
227 struct hsr_frame_info *frame) in hsr_xmit() argument
229 if (frame->port_rcv->type == HSR_PT_MASTER) { in hsr_xmit()
230 hsr_addr_subst_dest(frame->node_src, skb, port); in hsr_xmit()
232 /* Address substitution (IEC62439-3 pp 26, 50): replace mac in hsr_xmit()
233 * address of outgoing frame with that of the outgoing slave's. in hsr_xmit()
235 ether_addr_copy(eth_hdr(skb)->h_source, port->dev->dev_addr); in hsr_xmit()
241 /* Forward the frame through all devices except:
242 * - Back through the receiving device
243 * - If it's a HSR frame: through a device where it has passed before
244 * - To the local HSR master only if the frame is directly addressed to it, or
245 * a non-supervision multicast or broadcast frame.
247 * HSR slave devices should insert a HSR tag into the frame, or forward the
248 * frame unchanged if it's already tagged. Interlink devices should strip HSR
249 * tags if they're of the non-HSR type (but only after duplicate discard). The
250 * master device always strips HSR tags.
252 static void hsr_forward_do(struct hsr_frame_info *frame) in hsr_forward_do() argument
257 hsr_for_each_port(frame->port_rcv->hsr, port) { in hsr_forward_do()
258 /* Don't send frame back the way it came */ in hsr_forward_do()
259 if (port == frame->port_rcv) in hsr_forward_do()
263 if ((port->type == HSR_PT_MASTER) && !frame->is_local_dest) in hsr_forward_do()
266 /* Deliver frames directly addressed to us to master only */ in hsr_forward_do()
267 if ((port->type != HSR_PT_MASTER) && frame->is_local_exclusive) in hsr_forward_do()
270 /* Don't send frame over port where it has been sent before */ in hsr_forward_do()
271 if (hsr_register_frame_out(port, frame->node_src, in hsr_forward_do()
272 frame->sequence_nr)) in hsr_forward_do()
275 if (frame->is_supervision && (port->type == HSR_PT_MASTER)) { in hsr_forward_do()
276 hsr_handle_sup_frame(frame->skb_hsr, in hsr_forward_do()
277 frame->node_src, in hsr_forward_do()
278 frame->port_rcv); in hsr_forward_do()
282 if (port->type != HSR_PT_MASTER) in hsr_forward_do()
283 skb = frame_get_tagged_skb(frame, port); in hsr_forward_do()
285 skb = frame_get_stripped_skb(frame, port); in hsr_forward_do()
287 /* FIXME: Record the dropped frame? */ in hsr_forward_do()
291 skb->dev = port->dev; in hsr_forward_do()
292 if (port->type == HSR_PT_MASTER) in hsr_forward_do()
293 hsr_deliver_master(skb, port->dev, frame->node_src); in hsr_forward_do()
295 hsr_xmit(skb, port, frame); in hsr_forward_do()
301 struct hsr_frame_info *frame) in check_local_dest() argument
303 if (hsr_addr_is_self(hsr, eth_hdr(skb)->h_dest)) { in check_local_dest()
304 frame->is_local_exclusive = true; in check_local_dest()
305 skb->pkt_type = PACKET_HOST; in check_local_dest()
307 frame->is_local_exclusive = false; in check_local_dest()
310 if ((skb->pkt_type == PACKET_HOST) || in check_local_dest()
311 (skb->pkt_type == PACKET_MULTICAST) || in check_local_dest()
312 (skb->pkt_type == PACKET_BROADCAST)) { in check_local_dest()
313 frame->is_local_dest = true; in check_local_dest()
315 frame->is_local_dest = false; in check_local_dest()
320 static int hsr_fill_frame_info(struct hsr_frame_info *frame, in hsr_fill_frame_info() argument
326 frame->is_supervision = is_supervision_frame(port->hsr, skb); in hsr_fill_frame_info()
327 frame->node_src = hsr_get_node(port, skb, frame->is_supervision); in hsr_fill_frame_info()
328 if (frame->node_src == NULL) in hsr_fill_frame_info()
329 return -1; /* Unknown node and !is_supervision, or no mem */ in hsr_fill_frame_info()
332 frame->is_vlan = false; in hsr_fill_frame_info()
333 if (ethhdr->h_proto == htons(ETH_P_8021Q)) { in hsr_fill_frame_info()
334 frame->is_vlan = true; in hsr_fill_frame_info()
338 if (ethhdr->h_proto == htons(ETH_P_PRP) in hsr_fill_frame_info()
339 || ethhdr->h_proto == htons(ETH_P_HSR)) { in hsr_fill_frame_info()
340 frame->skb_std = NULL; in hsr_fill_frame_info()
341 frame->skb_hsr = skb; in hsr_fill_frame_info()
342 frame->sequence_nr = hsr_get_skb_sequence_nr(skb); in hsr_fill_frame_info()
344 frame->skb_std = skb; in hsr_fill_frame_info()
345 frame->skb_hsr = NULL; in hsr_fill_frame_info()
346 /* Sequence nr for the master node */ in hsr_fill_frame_info()
347 spin_lock_irqsave(&port->hsr->seqnr_lock, irqflags); in hsr_fill_frame_info()
348 frame->sequence_nr = port->hsr->sequence_nr; in hsr_fill_frame_info()
349 port->hsr->sequence_nr++; in hsr_fill_frame_info()
350 spin_unlock_irqrestore(&port->hsr->seqnr_lock, irqflags); in hsr_fill_frame_info()
353 frame->port_rcv = port; in hsr_fill_frame_info()
354 check_local_dest(port->hsr, skb, frame); in hsr_fill_frame_info()
362 struct hsr_frame_info frame; in hsr_forward_skb() local
364 if (skb_mac_header(skb) != skb->data) { in hsr_forward_skb()
365 WARN_ONCE(1, "%s:%d: Malformed frame (port_src %s)\n", in hsr_forward_skb()
366 __FILE__, __LINE__, port->dev->name); in hsr_forward_skb()
370 if (hsr_fill_frame_info(&frame, skb, port) < 0) in hsr_forward_skb()
372 hsr_register_frame_in(frame.node_src, port, frame.sequence_nr); in hsr_forward_skb()
373 hsr_forward_do(&frame); in hsr_forward_skb()
375 if (frame.skb_hsr != NULL) in hsr_forward_skb()
376 kfree_skb(frame.skb_hsr); in hsr_forward_skb()
377 if (frame.skb_std != NULL) in hsr_forward_skb()
378 kfree_skb(frame.skb_std); in hsr_forward_skb()
382 port->dev->stats.tx_dropped++; in hsr_forward_skb()