Skip to content

Commit 6cfb066

Browse files
Yuxuan LuoCacheUseOnly
Yuxuan Luo
authored andcommitted
SCTP: Support I-FORWARD chunk
Add support for printing I-FORWARD chunk based on RFC8260 section 2.3. Remove REL_CTL (RFC3758) since it is obsolete and it uses the value '0xc2' of I-FORWARD for CNTL_ACK. Print stream IDs and message IDs with `-vv` set. Example: `-v`: [I-FORWARD-FSN] [TSN: 1584188225] `-vv`: [I-FORWARD-FSN] [TSN: 2195717635] [SID: 0] [MID: 2]
1 parent 1ebb798 commit 6cfb066

6 files changed

+1409
-2
lines changed

print-sctp.c

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
#define SCTP_I_DATA 0x40
115115
#define SCTP_FORWARD_CUM_TSN 0xc0
116116
#define SCTP_RELIABLE_CNTL 0xc1
117-
#define SCTP_RELIABLE_CNTL_ACK 0xc2
117+
#define SCTP_I_FORWARD_TSN 0xc2
118118

119119
static const struct tok sctp_chunkid_str[] = {
120120
{ SCTP_DATA, "DATA" },
@@ -135,7 +135,7 @@ static const struct tok sctp_chunkid_str[] = {
135135
{ SCTP_I_DATA, "I-DATA" },
136136
{ SCTP_FORWARD_CUM_TSN, "FOR CUM TSN" },
137137
{ SCTP_RELIABLE_CNTL, "REL CTRL" },
138-
{ SCTP_RELIABLE_CNTL_ACK, "REL CTRL ACK" },
138+
{ SCTP_I_FORWARD_TSN, "I-FORWARD-FSN" },
139139
{ 0, NULL }
140140
};
141141

@@ -148,6 +148,9 @@ static const struct tok sctp_chunkid_str[] = {
148148
#define SCTP_DATA_UNORDERED 0x04
149149
#define SCTP_DATA_SACK_IMM 0x08
150150

151+
/* I-Forward-TSN Specific Flag */
152+
#define SCTP_I_FORWARD_UNORDERED 0x01
153+
151154
#define SCTP_ADDRMAX 60
152155

153156
#define CHAN_HP 6704
@@ -361,6 +364,16 @@ struct sctpIData{
361364
nd_uint32_t PPID_FSN;
362365
};
363366

367+
struct sctpIForward{
368+
nd_uint32_t new_cum_TSN;
369+
};
370+
371+
struct sctpIForwardEntry{
372+
nd_uint16_t streamId;
373+
nd_uint16_t flag;
374+
nd_uint32_t MID;
375+
};
376+
364377
struct sctpUnifiedDatagram{
365378
struct sctpChunkDesc uh;
366379
struct sctpDataPart dp;
@@ -728,6 +741,40 @@ sctp_print(netdissect_options *ndo,
728741
chunkLengthRemaining -= payload_size;
729742
break;
730743
}
744+
case SCTP_I_FORWARD_TSN:
745+
{
746+
const struct sctpIForward *dataHdrPtr;
747+
const struct sctpIForwardEntry *entry;
748+
const size_t entry_len = sizeof(struct sctpIForwardEntry);
749+
750+
ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <, sizeof(*dataHdrPtr));
751+
dataHdrPtr=(const struct sctpIForward*)bp;
752+
ND_PRINT("[TSN: %u] ", GET_BE_U_4(dataHdrPtr->new_cum_TSN));
753+
754+
bp += sizeof(*dataHdrPtr);
755+
sctpPacketLengthRemaining -= sizeof(*dataHdrPtr);
756+
chunkLengthRemaining -= sizeof(*dataHdrPtr);
757+
758+
if (ndo->ndo_vflag >= 2) {
759+
while (entry_len <= chunkLengthRemaining) {
760+
entry = (const struct sctpIForwardEntry*)bp;
761+
762+
ND_PRINT("[SID: %u] ", GET_BE_U_2(entry->streamId));
763+
if ((GET_BE_U_2(entry->flag) & SCTP_I_FORWARD_UNORDERED))
764+
ND_PRINT("(U)"); /* if U bit is set */
765+
ND_PRINT("[MID: %u] ", GET_BE_U_4(entry->MID));
766+
767+
chunkLengthRemaining -= entry_len;
768+
sctpPacketLengthRemaining -= entry_len;
769+
bp += entry_len;
770+
}
771+
}
772+
773+
bp += chunkLengthRemaining;
774+
sctpPacketLengthRemaining -= chunkLengthRemaining;
775+
chunkLengthRemaining = 0;
776+
break;
777+
}
731778
case SCTP_INITIATION :
732779
{
733780
const struct sctpInitiation *init;

tests/TESTLIST

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ sctp-i-data sctp-i-data.pcap sctp-i-data.out
4949
sctp-i-data-v sctp-i-data.pcap sctp-i-data-v.out -v
5050
sctp-i-data-vv sctp-i-data.pcap sctp-i-data-vv.out -vv
5151

52+
# I-FORWARD tests
53+
sctp-i-forward sctp-i-forward.pcap sctp-i-forward.out
54+
sctp-i-forward-v sctp-i-forward.pcap sctp-i-forward-v.out -v
55+
sctp-i-forward-vv sctp-i-forward.pcap sctp-i-forward-vv.out -vv
56+
5257
# BGP tests
5358
bgp_vpn_attrset bgp_vpn_attrset.pcap bgp_vpn_attrset.out -v
5459
mpbgp-linklocal-nexthop mpbgp-linklocal-nexthop.pcap mpbgp-linklocal-nexthop.out -v

tests/sctp-i-forward-v.out

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
1 19:52:04.102869 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 92)
2+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [INIT] [init tag: 3308356620] [rwnd: 106496] [OS: 10] [MIS: 65535] [init TSN: 3700341333]
3+
2 19:52:04.102890 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 348)
4+
192.168.5.2.36297 > 192.168.5.1.46336: sctp (1) [INIT ACK] [init tag: 2742731420] [rwnd: 106496] [OS: 5] [MIS: 5] [init TSN: 2786592332]
5+
3 19:52:04.102901 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 296)
6+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [COOKIE ECHO]
7+
4 19:52:04.102914 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto SCTP (132), length 36)
8+
192.168.5.2.36297 > 192.168.5.1.46336: sctp (1) [COOKIE ACK]
9+
5 19:52:04.112376 IP (tos 0x2,ECT(0), ttl 64, id 1, offset 0, flags [DF], proto SCTP (132), length 1500)
10+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [I-DATA] (B) [TSN: 3700341333] [SID: 0] [MID: 0] [PPID 0x0]
11+
6 19:52:04.112403 IP (tos 0x2,ECT(0), ttl 64, id 2, offset 0, flags [DF], proto SCTP (132), length 1276)
12+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [I-DATA] (E) [TSN: 3700341334] [SID: 0] [MID: 0] [FSN: 0]
13+
7 19:52:04.112422 IP (tos 0x2,ECT(0), ttl 64, id 3, offset 0, flags [DF], proto SCTP (132), length 1500)
14+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [I-DATA] (B) [TSN: 3700341335] [SID: 0] [MID: 1] [PPID 0x0]
15+
8 19:52:04.112424 IP (tos 0x2,ECT(0), ttl 64, id 4, offset 0, flags [DF], proto SCTP (132), length 1276)
16+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [I-DATA] (E) [TSN: 3700341336] [SID: 0] [MID: 1] [FSN: 0]
17+
9 19:52:07.367974 IP (tos 0x2,ECT(0), ttl 64, id 5, offset 0, flags [DF], proto SCTP (132), length 1500)
18+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [I-DATA] (B) [TSN: 3700341333] [SID: 0] [MID: 0] [PPID 0x0]
19+
10 19:52:08.135725 IP (tos 0x2,ECT(0), ttl 64, id 5499, offset 0, flags [DF], proto SCTP (132), length 92)
20+
192.168.5.2.36297 > 192.168.5.3.46336: sctp (1) [HB REQ]
21+
11 19:52:08.135757 IP (tos 0x2,ECT(0), ttl 64, id 6, offset 0, flags [DF], proto SCTP (132), length 1336)
22+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [HB ACK] , (2) [I-DATA] (E) [TSN: 3700341334] [SID: 0] [MID: 0] [FSN: 0]
23+
12 19:52:08.391999 IP (tos 0x2,ECT(0), ttl 64, id 7, offset 0, flags [DF], proto SCTP (132), length 92)
24+
192.168.5.1.46336 > 192.168.5.4.36297: sctp (1) [HB REQ]
25+
13 19:52:08.392040 IP (tos 0x2,ECT(0), ttl 64, id 5500, offset 0, flags [DF], proto SCTP (132), length 92)
26+
192.168.5.2.36297 > 192.168.5.1.46336: sctp (1) [HB ACK]
27+
14 19:52:08.392061 IP (tos 0x2,ECT(0), ttl 64, id 8, offset 0, flags [DF], proto SCTP (132), length 2744)
28+
192.168.5.1.46336 > 192.168.5.4.36297: sctp (1) [I-DATA] (B) [TSN: 3700341335] [SID: 0] [MID: 1] [PPID 0x0] , (2) [I-DATA] (E) [TSN: 3700341336] [SID: 0] [MID: 1] [FSN: 0]
29+
15 19:52:08.392064 IP (tos 0x2,ECT(0), ttl 64, id 10, offset 0, flags [DF], proto SCTP (132), length 2744)
30+
192.168.5.1.46336 > 192.168.5.4.36297: sctp (1) [I-DATA] (B) [TSN: 3700341337] [SID: 0] [MID: 2] [PPID 0x0] , (2) [I-DATA] (E) [TSN: 3700341338] [SID: 0] [MID: 2] [FSN: 0]
31+
16 19:52:09.895573 IP (tos 0x2,ECT(0), ttl 64, id 5501, offset 0, flags [DF], proto SCTP (132), length 92)
32+
192.168.5.2.36297 > 192.168.5.3.46336: sctp (1) [HB REQ]
33+
17 19:52:09.895587 IP (tos 0x2,ECT(0), ttl 64, id 12, offset 0, flags [DF], proto SCTP (132), length 92)
34+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [HB ACK]
35+
18 19:52:13.511764 IP (tos 0x2,ECT(0), ttl 64, id 13, offset 0, flags [DF], proto SCTP (132), length 1500)
36+
192.168.5.1.46336 > 192.168.5.4.36297: sctp (1) [I-DATA] (B) [TSN: 3700341333] [SID: 0] [MID: 0] [PPID 0x0]
37+
19 19:52:15.531970 IP (tos 0x2,ECT(0), ttl 64, id 14, offset 0, flags [DF], proto SCTP (132), length 48)
38+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [I-FORWARD-FSN] [TSN: 3700341333]
39+
20 19:52:15.531974 IP (tos 0x2,ECT(0), ttl 64, id 15, offset 0, flags [DF], proto SCTP (132), length 1500)
40+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [I-DATA] (B) [TSN: 3700341335] [SID: 0] [MID: 1] [PPID 0x0]
41+
21 19:52:15.531991 IP (tos 0x2,ECT(0), ttl 64, id 5502, offset 0, flags [DF], proto SCTP (132), length 48)
42+
192.168.5.2.36297 > 192.168.5.1.46336: sctp (1) [SACK] [cum ack 3700341333] [a_rwnd 106496] [#gap acks 0] [#dup tsns 0]
43+
22 19:52:15.531997 IP (tos 0x2,ECT(0), ttl 64, id 16, offset 0, flags [DF], proto SCTP (132), length 48)
44+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [I-FORWARD-FSN] [TSN: 3700341335]
45+
23 19:52:15.531998 IP (tos 0x2,ECT(0), ttl 64, id 17, offset 0, flags [DF], proto SCTP (132), length 1500)
46+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [I-DATA] (B) [TSN: 3700341337] [SID: 0] [MID: 2] [PPID 0x0]
47+
24 19:52:15.531999 IP (tos 0x2,ECT(0), ttl 64, id 18, offset 0, flags [DF], proto SCTP (132), length 1276)
48+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [I-DATA] (E) [TSN: 3700341338] [SID: 0] [MID: 2] [FSN: 0]
49+
25 19:52:15.735956 IP (tos 0x2,ECT(0), ttl 64, id 5503, offset 0, flags [DF], proto SCTP (132), length 48)
50+
192.168.5.2.36297 > 192.168.5.1.46336: sctp (1) [SACK] [cum ack 3700341335] [a_rwnd 106496] [#gap acks 0] [#dup tsns 0]
51+
26 19:52:15.735987 IP (tos 0x2,ECT(0), ttl 64, id 19, offset 0, flags [DF], proto SCTP (132), length 48)
52+
192.168.5.1.46336 > 192.168.5.2.36297: sctp (1) [I-FORWARD-FSN] [TSN: 3700341336]
53+
27 19:52:15.939951 IP (tos 0x2,ECT(0), ttl 64, id 5504, offset 0, flags [DF], proto SCTP (132), length 48)
54+
192.168.5.2.36297 > 192.168.5.1.46336: sctp (1) [SACK] [cum ack 3700341336] [a_rwnd 106496] [#gap acks 0] [#dup tsns 0]

0 commit comments

Comments
 (0)