summaryrefslogtreecommitdiffstats
path: root/libdnet-stripped/include/dnet/sctp.h
blob: 9451abccd8bc32177adc76fc1aeac36b640c93ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
 * sctp.h
 *
 * Stream Control Transmission Protocol (RFC 4960).
 *
 * Copyright (c) 2008-2009 Daniel Roethlisberger <daniel@roe.ch>
 *
 * $Id: sctp.h 653 2009-07-05 21:00:00Z daniel@roe.ch $
 */

#ifndef DNET_SCTP_H
#define DNET_SCTP_H

#ifndef __GNUC__
# ifndef __attribute__
#  define __attribute__(x)
# endif
# pragma pack(1)
#endif

#define SCTP_HDR_LEN	12

struct sctp_hdr {
	uint16_t	sh_sport;	/* source port */
	uint16_t	sh_dport;	/* destination port */
	uint32_t	sh_vtag;	/* sctp verification tag */
	uint32_t	sh_sum;		/* sctp checksum */
} __attribute__((__packed__));

#define SCTP_PORT_MAX	65535

#define sctp_pack_hdr(hdr, sport, dport, vtag) do {			\
	struct sctp_hdr *sctp_pack_p = (struct sctp_hdr *)(hdr);	\
	sctp_pack_p->sh_sport = htons(sport);				\
	sctp_pack_p->sh_dport = htons(dport);				\
	sctp_pack_p->sh_vtag = htonl(vtag);				\
} while (0)

struct dnet_sctp_chunkhdr {
	uint8_t		sch_type;	/* chunk type */
	uint8_t		sch_flags;	/* chunk flags */
	uint16_t	sch_length;	/* chunk length */
} __attribute__((__packed__));

/* chunk types */
#define SCTP_DATA		0x00
#define SCTP_INIT		0x01
#define SCTP_INIT_ACK		0x02
#define SCTP_SACK		0x03
#define SCTP_HEARTBEAT		0x04
#define SCTP_HEARTBEAT_ACK	0x05
#define SCTP_ABORT		0x06
#define SCTP_SHUTDOWN		0x07
#define SCTP_SHUTDOWN_ACK	0x08
#define SCTP_ERROR		0x09
#define SCTP_COOKIE_ECHO	0x0a
#define SCTP_COOKIE_ACK		0x0b
#define SCTP_ECNE		0x0c
#define SCTP_CWR		0x0d
#define SCTP_SHUTDOWN_COMPLETE	0x0e
#define SCTP_AUTH		0x0f	/* RFC 4895 */
#define SCTP_ASCONF_ACK		0x80	/* RFC 5061 */
#define SCTP_PKTDROP		0x81	/* draft-stewart-sctp-pktdrprep-08 */
#define SCTP_PAD		0x84	/* RFC 4820 */
#define SCTP_FORWARD_TSN	0xc0	/* RFC 3758 */
#define SCTP_ASCONF		0xc1	/* RFC 5061 */

/* chunk types bitmask flags */
#define SCTP_TYPEFLAG_REPORT	1
#define SCTP_TYPEFLAG_SKIP	2

#define sctp_pack_chunkhdr(hdr, type, flags, length) do {		\
	struct dnet_sctp_chunkhdr *sctp_pack_chp = (struct dnet_sctp_chunkhdr *)(hdr);\
	sctp_pack_chp->sch_type = type;					\
	sctp_pack_chp->sch_flags = flags;				\
	sctp_pack_chp->sch_length = htons(length);			\
} while (0)

/*
 * INIT chunk
 */
struct sctp_chunkhdr_init {
	struct dnet_sctp_chunkhdr chunkhdr;

	uint32_t	schi_itag;	/* Initiate Tag */
	uint32_t	schi_arwnd;	/* Advertised Receiver Window Credit */
	uint16_t	schi_nos;	/* Number of Outbound Streams */
	uint16_t	schi_nis;	/* Number of Inbound Streams */
	uint32_t	schi_itsn;	/* Initial TSN */
} __attribute__((__packed__));

#define sctp_pack_chunkhdr_init(hdr, type, flags, length, itag,		\
				arwnd, nos, nis, itsn) do {		\
	struct sctp_chunkhdr_init *sctp_pack_chip =			\
			(struct sctp_chunkhdr_init *)(hdr);		\
	sctp_pack_chunkhdr(sctp_pack_chip, type, flags, length);	\
	sctp_pack_chip->schi_itag = htonl(itag);			\
	sctp_pack_chip->schi_arwnd = htonl(arwnd);			\
	sctp_pack_chip->schi_nos = htons(nos);				\
	sctp_pack_chip->schi_nis = htons(nis);				\
	sctp_pack_chip->schi_itsn = htonl(itsn);			\
} while (0)

/*
 * INIT ACK chunk
 */
struct sctp_chunkhdr_init_ack {
	struct dnet_sctp_chunkhdr chunkhdr;

	uint32_t	schia_itag;	/* Initiate Tag */
	uint32_t	schia_arwnd;	/* Advertised Receiver Window Credit */
	uint16_t	schia_nos;	/* Number of Outbound Streams */
	uint16_t	schia_nis;	/* Number of Inbound Streams */
	uint32_t	schia_itsn;	/* Initial TSN */
} __attribute__((__packed__));

#define sctp_pack_chunkhdr_init_ack(hdr, type, flags, length, itag,	\
				arwnd, nos, nis, itsn) do {		\
	struct sctp_chunkhdr_init_ack *sctp_pack_chip =			\
			(struct sctp_chunkhdr_init_ack *)(hdr);		\
	sctp_pack_chunkhdr(sctp_pack_chip, type, flags, length);	\
	sctp_pack_chip->schia_itag = htonl(itag);			\
	sctp_pack_chip->schia_arwnd = htonl(arwnd);			\
	sctp_pack_chip->schia_nos = htons(nos);				\
	sctp_pack_chip->schia_nis = htons(nis);				\
	sctp_pack_chip->schia_itsn = htonl(itsn);			\
} while (0)

/*
 * ABORT chunk
 */
struct sctp_chunkhdr_abort {
	struct dnet_sctp_chunkhdr chunkhdr;

	/* empty */
} __attribute__((__packed__));

#define sctp_pack_chunkhdr_abort(hdr, type, flags, length) do {		\
	struct sctp_chunkhdr_abort *sctp_pack_chip =			\
			(struct sctp_chunkhdr_abort *)(hdr);		\
	sctp_pack_chunkhdr(sctp_pack_chip, type, flags, length);	\
} while (0)

/*
 * SHUTDOWN ACK chunk
 */
struct sctp_chunkhdr_shutdown_ack {
	struct dnet_sctp_chunkhdr chunkhdr;

	/* empty */
} __attribute__((__packed__));

#define sctp_pack_chunkhdr_shutdown_ack(hdr, type, flags, length) do {	\
	struct sctp_chunkhdr_shutdown_ack *sctp_pack_chip =		\
			(struct sctp_chunkhdr_shutdown_ack *)(hdr);	\
	sctp_pack_chunkhdr(sctp_pack_chip, type, flags, length);	\
} while (0)

/*
 * COOKIE ECHO chunk
 */
struct sctp_chunkhdr_cookie_echo {
	struct dnet_sctp_chunkhdr chunkhdr;

	/* empty */
} __attribute__((__packed__));

#define sctp_pack_chunkhdr_cookie_echo(hdr, type, flags, length) do {	\
	struct sctp_chunkhdr_cookie_echo *sctp_pack_chip =		\
			(struct sctp_chunkhdr_cookie_echo *)(hdr);	\
	sctp_pack_chunkhdr(sctp_pack_chip, type, flags, length);	\
} while (0)

#ifndef __GNUC__
# pragma pack()
#endif

#endif /* DNET_SCTP_H */