/* seq_nr_after(a, b) - return true if a is after (higher in sequence than) b, *falseotherwise.
*/ staticbool seq_nr_after(u16 a, u16 b)
{ /* Remove inconsistency where *seq_nr_after(a,b)==seq_nr_before(a,b)
*/ if ((int)b - a == 32768) returnfalse;
return (((s16)(b - a)) < 0);
}
#define seq_nr_before(a, b) seq_nr_after((b), (a)) #define seq_nr_before_or_eq(a, b) (!seq_nr_after((a), (b))) #define PRP_DROP_WINDOW_LEN 32768
rcu_read_lock();
sn = rcu_dereference(hsr->self_node); if (!sn) {
WARN_ONCE(1, "HSR: No self node\n"); goto out;
}
if (ether_addr_equal(addr, sn->macaddress_A) ||
ether_addr_equal(addr, sn->macaddress_B))
ret = true;
out:
rcu_read_unlock(); return ret;
}
/* Search for mac entry. Caller must hold rcu read lock.
*/ staticstruct hsr_node *find_node_by_addr_A(struct list_head *node_db, constunsignedchar addr[ETH_ALEN])
{ struct hsr_node *node;
list_for_each_entry_rcu(node, node_db, mac_list) { if (ether_addr_equal(node->macaddress_A, addr)) return node;
}
return NULL;
}
/* Check if node for a given MAC address is already present in data base
*/ bool hsr_is_node_in_db(struct list_head *node_db, constunsignedchar addr[ETH_ALEN])
{ return !!find_node_by_addr_A(node_db, addr);
}
/* Helper for device init; the self_node is used in hsr_rcv() to recognize *framesfromselfthat'sbeenloopedovertheHSRring.
*/ int hsr_create_self_node(struct hsr_priv *hsr, constunsignedchar addr_a[ETH_ALEN], constunsignedchar addr_b[ETH_ALEN])
{ struct hsr_self_node *sn, *old;
sn = kmalloc(sizeof(*sn), GFP_KERNEL); if (!sn) return -ENOMEM;
void prp_handle_san_frame(bool san, enum hsr_port_type port, struct hsr_node *node)
{ /* Mark if the SAN node is over LAN_A or LAN_B */ if (port == HSR_PT_SLAVE_A) {
node->san_a = true; return;
}
if (port == HSR_PT_SLAVE_B)
node->san_b = true;
}
/* Allocate an hsr_node and add it to node_db. 'addr' is the node's address_A; *seq_outisusedtoinitializefilteringofoutgoingduplicateframes *originatingfromthenewlyaddednode.
*/ staticstruct hsr_node *hsr_add_node(struct hsr_priv *hsr, struct list_head *node_db, unsignedchar addr[],
u16 seq_out, bool san, enum hsr_port_type rx_port)
{ struct hsr_node *new_node, *node; unsignedlong now; int i;
new_node = kzalloc(sizeof(*new_node), GFP_ATOMIC); if (!new_node) return NULL;
/* We are only interested in time diffs here, so use current jiffies *asinitialization.(0couldtriggeranspuriousringerrorwarning).
*/
now = jiffies; for (i = 0; i < HSR_PT_PORTS; i++) {
new_node->time_in[i] = now;
new_node->time_out[i] = now;
} for (i = 0; i < HSR_PT_PORTS; i++) {
new_node->seq_out[i] = seq_out;
new_node->seq_expected[i] = seq_out + 1;
new_node->seq_start[i] = seq_out + 1;
}
if (san && hsr->proto_ops->handle_san_frame)
hsr->proto_ops->handle_san_frame(san, rx_port, new_node);
void prp_update_san_info(struct hsr_node *node, bool is_sup)
{ if (!is_sup) return;
node->san_a = false;
node->san_b = false;
}
/* Get the hsr_node from which 'skb' was sent.
*/ struct hsr_node *hsr_get_node(struct hsr_port *port, struct list_head *node_db, struct sk_buff *skb, bool is_sup, enum hsr_port_type rx_port)
{ struct hsr_priv *hsr = port->hsr; struct hsr_node *node; struct ethhdr *ethhdr; struct prp_rct *rct; bool san = false;
u16 seq_out;
if (!skb_mac_header_was_set(skb)) return NULL;
ethhdr = (struct ethhdr *)skb_mac_header(skb);
list_for_each_entry_rcu(node, node_db, mac_list) { if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) { if (hsr->proto_ops->update_san_info)
hsr->proto_ops->update_san_info(node, is_sup); return node;
} if (ether_addr_equal(node->macaddress_B, ethhdr->h_source)) { if (hsr->proto_ops->update_san_info)
hsr->proto_ops->update_san_info(node, is_sup); return node;
}
}
/* Check if required node is not in proxy nodes table */
list_for_each_entry_rcu(node, &hsr->proxy_node_db, mac_list) { if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) { if (hsr->proto_ops->update_san_info)
hsr->proto_ops->update_san_info(node, is_sup); return node;
}
}
/* Everyone may create a node entry, connected node to a HSR/PRP *device.
*/ if (ethhdr->h_proto == htons(ETH_P_PRP) ||
ethhdr->h_proto == htons(ETH_P_HSR)) { /* Check if skb contains hsr_ethhdr */ if (skb->mac_len < sizeof(struct hsr_ethhdr)) return NULL;
/* Use the existing sequence_nr from the tag as starting point *forfilteringduplicateframes.
*/
seq_out = hsr_get_skb_sequence_nr(skb) - 1;
} else {
rct = skb_get_PRP_rct(skb); if (rct && prp_check_lsdu_size(skb, rct, is_sup)) {
seq_out = prp_get_skb_sequence_nr(rct);
} else { if (rx_port != HSR_PT_MASTER)
san = true;
seq_out = HSR_SEQNR_START;
}
}
/* Use the Supervision frame's info about an eventual macaddress_B for merging *nodesthathaspreviouslyhadtheirmacaddress_Bregisteredasaseparate *node.
*/ void hsr_handle_sup_frame(struct hsr_frame_info *frame)
{ struct hsr_node *node_curr = frame->node_src; struct hsr_port *port_rcv = frame->port_rcv; struct hsr_priv *hsr = port_rcv->hsr; struct hsr_sup_payload *hsr_sp; struct hsr_sup_tlv *hsr_sup_tlv; struct hsr_node *node_real; struct sk_buff *skb = NULL; struct list_head *node_db; struct ethhdr *ethhdr; int i; unsignedint pull_size = 0; unsignedint total_pull_size = 0;
/* Here either frame->skb_hsr or frame->skb_prp should be *validassupervisionframealwayswillhaveprotocol *headerinfo.
*/ if (frame->skb_hsr)
skb = frame->skb_hsr; elseif (frame->skb_prp)
skb = frame->skb_prp; elseif (frame->skb_std)
skb = frame->skb_std; if (!skb) return;
/* Merge node_curr (registered on macaddress_B) into node_real */
node_db = &port_rcv->hsr->node_db;
node_real = find_node_by_addr_A(node_db, hsr_sp->macaddress_A); if (!node_real) /* No frame received from AddrA of this node yet */
node_real = hsr_add_node(hsr, node_db, hsr_sp->macaddress_A,
HSR_SEQNR_START - 1, true,
port_rcv->type); if (!node_real) goto done; /* No mem */ if (node_real == node_curr) /* Node has already been merged */ goto done;
/* Leave the first HSR sup payload. */
pull_size = sizeof(struct hsr_sup_payload);
skb_pull(skb, pull_size);
total_pull_size += pull_size;
/* Get second supervision tlv */
hsr_sup_tlv = (struct hsr_sup_tlv *)skb->data; /* And check if it is a redbox mac TLV */ if (hsr_sup_tlv->HSR_TLV_type == PRP_TLV_REDBOX_MAC) { /* We could stop here after pushing hsr_sup_payload, *orproceedandallowmacaddress_Bandforredboxes.
*/ /* Sanity check length */ if (hsr_sup_tlv->HSR_TLV_length != 6) goto done;
/* Leave the second HSR sup tlv. */
pull_size = sizeof(struct hsr_sup_tlv);
skb_pull(skb, pull_size);
total_pull_size += pull_size;
/* Get redbox mac address. */
hsr_sp = (struct hsr_sup_payload *)skb->data;
/* Check if redbox mac and node mac are equal. */ if (!ether_addr_equal(node_real->macaddress_A, hsr_sp->macaddress_A)) { /* This is a redbox supervision frame for a VDAN! */ goto done;
}
}
ether_addr_copy(node_real->macaddress_B, ethhdr->h_source);
spin_lock_bh(&node_real->seq_out_lock); for (i = 0; i < HSR_PT_PORTS; i++) { if (!node_curr->time_in_stale[i] &&
time_after(node_curr->time_in[i], node_real->time_in[i])) {
node_real->time_in[i] = node_curr->time_in[i];
node_real->time_in_stale[i] =
node_curr->time_in_stale[i];
} if (seq_nr_after(node_curr->seq_out[i], node_real->seq_out[i]))
node_real->seq_out[i] = node_curr->seq_out[i];
}
spin_unlock_bh(&node_real->seq_out_lock);
node_real->addr_B_port = port_rcv->type;
done: /* Push back here */
skb_push(skb, total_pull_size);
}
/* 'skb' is a frame meant for this host, that is to be passed to upper layers. * *Iftheframewassentbyanode'sBinterface,replacethesource *addresswiththatnode's"official"address(macaddress_A)sothatupper *layersrecognizewhereitcamefrom.
*/ void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb)
{ if (!skb_mac_header_was_set(skb)) {
WARN_ONCE(1, "%s: Mac header not set\n", __func__); return;
}
/* out-going frames are always in order *andcanbecheckedthesamewayasforHSR
*/ if (frame->port_rcv->type == HSR_PT_MASTER) return hsr_register_frame_out(port, frame);
/* for PRP we should only forward frames from the slave ports *tothemasterport
*/ if (port->type != HSR_PT_MASTER) return1;
spin_lock_bh(&node->seq_out_lock); if (time_is_before_jiffies(node->time_out[port->type] +
msecs_to_jiffies(HSR_ENTRY_FORGET_TIME)) ||
(node->seq_start[rcv_port] == node->seq_expected[rcv_port] &&
node->seq_start[other_port] == node->seq_expected[other_port])) { /* the node hasn't been sending for a while *orbothdropwindowsareempty,forwardtheframe
*/
node->seq_start[rcv_port] = sequence_nr;
} elseif (seq_nr_before(sequence_nr, node->seq_expected[other_port]) &&
seq_nr_before_or_eq(node->seq_start[other_port], sequence_nr)) { /* drop the frame, update the drop window for the other port *andresetourdropwindow
*/
node->seq_start[other_port] = sequence_exp;
node->seq_expected[rcv_port] = sequence_exp;
node->seq_start[rcv_port] = node->seq_expected[rcv_port];
spin_unlock_bh(&node->seq_out_lock); return1;
}
/* update the drop window for the port where this frame was received *andclearthedropwindowfortheotherport
*/
node->seq_start[other_port] = node->seq_expected[other_port];
node->seq_expected[rcv_port] = sequence_exp;
sequence_diff = sequence_exp - node->seq_start[rcv_port]; if (sequence_diff > PRP_DROP_WINDOW_LEN)
node->seq_start[rcv_port] = sequence_exp - PRP_DROP_WINDOW_LEN;
/* Check for timestamps old enough to risk wrap-around */ if (time_after(jiffies, time_a + MAX_JIFFY_OFFSET / 2))
node->time_in_stale[HSR_PT_SLAVE_A] = true; if (time_after(jiffies, time_b + MAX_JIFFY_OFFSET / 2))
node->time_in_stale[HSR_PT_SLAVE_B] = true;
/* Get age of newest frame from node. *Atleastonetime_inisOKhere;nodesgetprunedlong *beforebothtime_inscangetstale
*/
timestamp = time_a; if (node->time_in_stale[HSR_PT_SLAVE_A] ||
(!node->time_in_stale[HSR_PT_SLAVE_B] &&
time_after(time_b, time_a)))
timestamp = time_b;
/* Warn of ring error only as long as we get frames at all */ if (time_is_after_jiffies(timestamp +
msecs_to_jiffies(1.5 * MAX_SLAVE_DIFF))) {
rcu_read_lock();
port = get_late_port(hsr, node); if (port)
hsr_nl_ringerror(hsr, node->macaddress_A, port);
rcu_read_unlock();
}
/* Prune old entries */ if (time_is_before_jiffies(timestamp +
msecs_to_jiffies(HSR_NODE_FORGET_TIME))) {
hsr_nl_nodedown(hsr, node->macaddress_A); if (!node->removed) {
list_del_rcu(&node->mac_list);
node->removed = true; /* Note that we need to free this entry later: */
kfree_rcu(node, rcu_head);
}
}
}
spin_unlock_bh(&hsr->list_lock);
/* Prune old entries */ if (time_is_before_jiffies(timestamp +
msecs_to_jiffies(HSR_PROXY_NODE_FORGET_TIME))) {
hsr_nl_nodedown(hsr, node->macaddress_A); if (!node->removed) {
list_del_rcu(&node->mac_list);
node->removed = true; /* Note that we need to free this entry later: */
kfree_rcu(node, rcu_head);
}
}
}
/* Present sequence numbers as if they were incoming on interface */
*if1_seq = node->seq_out[HSR_PT_SLAVE_B];
*if2_seq = node->seq_out[HSR_PT_SLAVE_A];
if (node->addr_B_port != HSR_PT_NONE) {
port = hsr_port_get_hsr(hsr, node->addr_B_port);
*addr_b_ifindex = port->dev->ifindex;
} else {
*addr_b_ifindex = -1;
}
return0;
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.38Bemerkung:
(vorverarbeitet am 2026-09-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.