Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add printing for HSR/PRP protocols #1126

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
HSR/PRP: Add printing for HSR header
HSR is a redundancy protocol that duplicates traffic and sends it two
ways in a ring with an HSR header that includes a sequence number. Other
devices in the ring will forward the first occurrence of a packet, and
discard the duplicate (based on SMAC + sequence number). This enables
zero packet loss when a link goes down.

Signed-off-by: Casper Andersson <casper.casan@gmail.com>
  • Loading branch information
cappe987 committed Feb 1, 2024
commit d6195affa919b1f24beea6b1a054ac8e9b00be4f
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,7 @@ set(NETDISSECT_SOURCE_LIST_C
print-geonet.c
print-gre.c
print-hncp.c
print-hsr-prp.c
print-hsrp.c
print-http.c
print-icmp.c
Expand Down
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ LIBNETDISSECT_SRC=\
print-geonet.c \
print-gre.c \
print-hncp.c \
print-hsr-prp.c \
print-hsrp.c \
print-http.c \
print-icmp.c \
Expand Down
3 changes: 3 additions & 0 deletions ethertype.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@
#ifndef ETHERTYPE_PTP
#define ETHERTYPE_PTP 0x88f7
#endif
#ifndef ETHERTYPE_HSR
#define ETHERTYPE_HSR 0x892f
#endif
#ifndef ETHERTYPE_LOOPBACK
#define ETHERTYPE_LOOPBACK 0x9000
#endif
Expand Down
1 change: 1 addition & 0 deletions netdissect.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ extern void hex_and_ascii_print(netdissect_options *, const char *, const u_char
extern void hex_print(netdissect_options *, const char *indent, const u_char *cp, u_int);
extern void hex_print_with_offset(netdissect_options *, const char *indent, const u_char *cp, u_int, u_int);
extern void hncp_print(netdissect_options *, const u_char *, u_int);
extern void hsr_print(netdissect_options *, const u_char *, u_int);
extern void hsrp_print(netdissect_options *, const u_char *, u_int);
extern void http_print(netdissect_options *, const u_char *, u_int);
extern void icmp6_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
Expand Down
19 changes: 19 additions & 0 deletions print-ether.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const struct tok ethertype_values[] = {
{ ETHERTYPE_CALM_FAST, "CALM FAST"},
{ ETHERTYPE_AOE, "AoE" },
{ ETHERTYPE_PTP, "PTP" },
{ ETHERTYPE_HSR, "HSR" },
{ ETHERTYPE_ARISTA, "Arista Vendor Specific Protocol" },
{ 0, NULL}
};
Expand Down Expand Up @@ -287,6 +288,24 @@ ether_common_print(netdissect_options *ndo, const u_char *p, u_int length,
hdrlen += 4;
}

if (length_type == ETHERTYPE_HSR) {
if (ndo->ndo_eflag) {
ether_type_print(ndo, length_type);
if (!printed_length) {
ND_PRINT(", length %u: ", orig_length);
printed_length = 1;
} else
ND_PRINT(", ");
hsr_print(ndo, p, length);
}

length_type = GET_BE_U_2(p + 4);
p += 6;
length -= 6;
caplen -= 6;
hdrlen += 6;
}

/*
* We now have the final length/type field.
*/
Expand Down
72 changes: 72 additions & 0 deletions print-hsr-prp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code
* distributions retain the above copyright notice and this paragraph
* in its entirety, and (2) distributions including binary code include
* the above copyright notice and this paragraph in its entirety in
* the documentation or other materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND
* WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*/

/* \summary: High-availability Seamless Redundancy (HSR) and
* Parallel Redundancy Protocol (PRP) printer */

/* specification: https://webstore.iec.ch/publication/64423 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "extract.h"
#include "addrtoname.h"

/*
* HSR header
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |NetID|L| LSDUsize | Sequence number |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* 0 1 2 3
*
* L = LanID
* LSDUsize = Link Service Data Unit size = size of the packet excluding MAC
* header, tags before the HSR tag (e.g. VLAN), and the HSR ethertype field.
* For PRP it includes the PRP suffix.
*/

#define HSR_HDR_LEN 6

void hsr_print(netdissect_options *ndo, const u_char *bp, u_int length)
{
int lanid, netid;
uint16_t lsdu_size;
uint16_t hdr;
uint32_t seq_nr;

ND_ICHECK_U(length, <, HSR_HDR_LEN);

hdr = GET_BE_U_2(bp);
lsdu_size = hdr & 0xFFF;
lanid = (hdr >> 12) & 0x1;
netid = hdr >> 13;

length -= 2;
bp += 2;
seq_nr = GET_BE_U_2(bp);

ND_PRINT("LSDUsize %u, SeqNr %u, LanId %s, NetId %u, ",
lsdu_size, seq_nr, lanid ? "A" : "B", netid);

return;

invalid:
nd_print_invalid(ndo);
}