|
| 1 | +/* |
| 2 | + * Redistribution and use in source and binary forms, with or without |
| 3 | + * modification, are permitted provided that: (1) source code |
| 4 | + * distributions retain the above copyright notice and this paragraph |
| 5 | + * in its entirety, and (2) distributions including binary code include |
| 6 | + * the above copyright notice and this paragraph in its entirety in |
| 7 | + * the documentation or other materials provided with the distribution. |
| 8 | + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND |
| 9 | + * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT |
| 10 | + * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 11 | + * FOR A PARTICULAR PURPOSE. |
| 12 | + */ |
| 13 | + |
| 14 | +/* \summary: High-availability Seamless Redundancy (HSR) and |
| 15 | + * Parallel Redundancy Protocol (PRP) printer */ |
| 16 | + |
| 17 | +/* specification: https://webstore.iec.ch/publication/64423 */ |
| 18 | + |
| 19 | +#ifdef HAVE_CONFIG_H |
| 20 | +#include <config.h> |
| 21 | +#endif |
| 22 | + |
| 23 | +#include "netdissect-stdinc.h" |
| 24 | +#include "netdissect.h" |
| 25 | +#include "extract.h" |
| 26 | +#include "addrtoname.h" |
| 27 | + |
| 28 | +/* |
| 29 | + * HSR header |
| 30 | + * 0 1 2 3 |
| 31 | + * 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 |
| 32 | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 33 | + * |NetID|L| LSDUsize | Sequence number | |
| 34 | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 35 | + * 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 |
| 36 | + * 0 1 2 3 |
| 37 | + * |
| 38 | + * L = LanID |
| 39 | + * LSDUsize = Link Service Data Unit size = size of the packet excluding MAC |
| 40 | + * header, tags before the HSR tag (e.g. VLAN), and the HSR ethertype field. |
| 41 | + * For PRP it includes the PRP suffix. |
| 42 | + */ |
| 43 | + |
| 44 | +#define HSR_HDR_LEN 6 |
| 45 | + |
| 46 | +void hsr_print(netdissect_options *ndo, const u_char *bp, u_int length) |
| 47 | +{ |
| 48 | + int lanid, netid; |
| 49 | + uint16_t lsdu_size; |
| 50 | + uint16_t hdr; |
| 51 | + uint32_t seq_nr; |
| 52 | + |
| 53 | + ND_ICHECK_U(length, <, HSR_HDR_LEN); |
| 54 | + |
| 55 | + hdr = GET_BE_U_2(bp); |
| 56 | + lsdu_size = hdr & 0xFFF; |
| 57 | + lanid = (hdr >> 12) & 0x1; |
| 58 | + netid = hdr >> 13; |
| 59 | + |
| 60 | + length -= 2; |
| 61 | + bp += 2; |
| 62 | + seq_nr = GET_BE_U_2(bp); |
| 63 | + |
| 64 | + ND_PRINT("LSDUsize %u, SeqNr %u, LanId %s, NetId %u, ", |
| 65 | + lsdu_size, seq_nr, lanid ? "A" : "B", netid); |
| 66 | + |
| 67 | + return; |
| 68 | + |
| 69 | +invalid: |
| 70 | + nd_print_invalid(ndo); |
| 71 | +} |
| 72 | + |
0 commit comments