Debian Codegraph @

paramtype.go

raw
1 // SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
2 // SPDX-License-Identifier: MIT
3
4 package sctp
5
6 import (
7 "encoding/binary"
8 "errors"
9 "fmt"
10 )
11
12 // paramType represents a SCTP INIT/INITACK parameter.
13 type paramType uint16
14
15 const (
16 heartbeatInfo paramType = 1 // Heartbeat Info [RFC9260]
17 ipV4Addr paramType = 5 // IPv4 IP [RFC9260]
18 ipV6Addr paramType = 6 // IPv6 IP [RFC9260]
19 stateCookie paramType = 7 // State Cookie [RFC9260]
20 unrecognizedParam paramType = 8 // Unrecognized Parameters [RFC9260]
21 cookiePreservative paramType = 9 // Cookie Preservative [RFC9260]
22 hostNameAddr paramType = 11 // Host Name Address [RFC9260]
23 supportedAddrTypes paramType = 12 // Supported IP Types [RFC9260]
24 outSSNResetReq paramType = 13 // Outgoing SSN Reset Request Parameter [RFC6525]
25 incSSNResetReq paramType = 14 // Incoming SSN Reset Request Parameter [RFC6525]
26 ssnTSNResetReq paramType = 15 // SSN/TSN Reset Request Parameter [RFC6525]
27 reconfigResp paramType = 16 // Re-configuration Response Parameter [RFC6525]
28 addOutStreamsReq paramType = 17 // Add Outgoing Streams Request Parameter [RFC6525]
29 addIncStreamsReq paramType = 18 // Add Incoming Streams Request Parameter [RFC6525]
30 ecnCapable paramType = 32768 // ECN Capable (0x8000) [RFC2960]
31 zeroChecksumAcceptable paramType = 32769 // Zero Checksum Acceptable [draft-ietf-tsvwg-sctp-zero-checksum-00]
32 random paramType = 32770 // Random (0x8002) [RFC4895]
33 chunkList paramType = 32771 // Chunk List (0x8003) [RFC4895]
34 reqHMACAlgo paramType = 32772 // Requested HMAC Algorithm Parameter (0x8004) [RFC4895]
35 padding paramType = 32773 // Padding (0x8005)
36 supportedExt paramType = 32776 // Supported Extensions (0x8008) [RFC5061]
37 forwardTSNSupp paramType = 49152 // Forward TSN supported (0xC000) [RFC3758]
38 addIPAddr paramType = 49153 // Add IP Address (0xC001) [RFC5061]
39 delIPAddr paramType = 49154 // Delete IP Address (0xC002) [RFC5061]
40 errClauseInd paramType = 49155 // Error Cause Indication (0xC003) [RFC5061]
41 setPriAddr paramType = 49156 // Set Primary IP (0xC004) [RFC5061]
42 successInd paramType = 49157 // Success Indication (0xC005) [RFC5061]
43 adaptLayerInd paramType = 49158 // Adaptation Layer Indication (0xC006) [RFC5061]
44 )
45
46 // Parameter packet errors.
47 var (
48 ErrParamPacketTooShort = errors.New("packet too short")
49 )
50
51 func parseParamType(raw []byte) (paramType, error) {
52 if len(raw) < 2 {
53 return paramType(0), ErrParamPacketTooShort
54 }
55
56 return paramType(binary.BigEndian.Uint16(raw)), nil
57 }
58
59 func (p paramType) String() string { //nolint:cyclop
60 switch p {
61 case heartbeatInfo:
62 return "Heartbeat Info"
63 case ipV4Addr:
64 return "IPv4 IP"
65 case ipV6Addr:
66 return "IPv6 IP"
67 case stateCookie:
68 return "State Cookie"
69 case unrecognizedParam:
70 return "Unrecognized Parameters"
71 case cookiePreservative:
72 return "Cookie Preservative"
73 case hostNameAddr:
74 return "Host Name Address"
75 case supportedAddrTypes:
76 return "Supported IP Types"
77 case outSSNResetReq:
78 return "Outgoing SSN Reset Request Parameter"
79 case incSSNResetReq:
80 return "Incoming SSN Reset Request Parameter"
81 case ssnTSNResetReq:
82 return "SSN/TSN Reset Request Parameter"
83 case reconfigResp:
84 return "Re-configuration Response Parameter"
85 case addOutStreamsReq:
86 return "Add Outgoing Streams Request Parameter"
87 case addIncStreamsReq:
88 return "Add Incoming Streams Request Parameter"
89 case ecnCapable:
90 return "ECN Capable"
91 case zeroChecksumAcceptable:
92 return "Zero Checksum Acceptable"
93 case random:
94 return "Random"
95 case chunkList:
96 return "Chunk List"
97 case reqHMACAlgo:
98 return "Requested HMAC Algorithm Parameter"
99 case padding:
100 return "Padding"
101 case supportedExt:
102 return "Supported Extensions"
103 case forwardTSNSupp:
104 return "Forward TSN supported"
105 case addIPAddr:
106 return "Add IP Address"
107 case delIPAddr:
108 return "Delete IP Address"
109 case errClauseInd:
110 return "Error Cause Indication"
111 case setPriAddr:
112 return "Set Primary IP"
113 case successInd:
114 return "Success Indication"
115 case adaptLayerInd:
116 return "Adaptation Layer Indication"
117 default:
118 return fmt.Sprintf("Unknown ParamType: %d", p)
119 }
120 }