blob: 29287be696a2673a6edea49c71c1774e4f12970c [file] [log] [blame]
Harald Welte2e4e6a12006-01-12 13:30:04 -08001#ifndef _XT_SCTP_H_
2#define _XT_SCTP_H_
3
Arnd Bergmann60c195c2009-02-26 00:51:43 +01004#include <linux/types.h>
5
Harald Welte2e4e6a12006-01-12 13:30:04 -08006#define XT_SCTP_SRC_PORTS 0x01
7#define XT_SCTP_DEST_PORTS 0x02
8#define XT_SCTP_CHUNK_TYPES 0x04
9
10#define XT_SCTP_VALID_FLAGS 0x07
11
Harald Welte2e4e6a12006-01-12 13:30:04 -080012struct xt_sctp_flag_info {
Arnd Bergmann60c195c2009-02-26 00:51:43 +010013 __u8 chunktype;
14 __u8 flag;
15 __u8 flag_mask;
Harald Welte2e4e6a12006-01-12 13:30:04 -080016};
17
18#define XT_NUM_SCTP_FLAGS 4
19
20struct xt_sctp_info {
Arnd Bergmann60c195c2009-02-26 00:51:43 +010021 __u16 dpts[2]; /* Min, Max */
22 __u16 spts[2]; /* Min, Max */
Harald Welte2e4e6a12006-01-12 13:30:04 -080023
Arnd Bergmann60c195c2009-02-26 00:51:43 +010024 __u32 chunkmap[256 / sizeof (__u32)]; /* Bit mask of chunks to be matched according to RFC 2960 */
Harald Welte2e4e6a12006-01-12 13:30:04 -080025
26#define SCTP_CHUNK_MATCH_ANY 0x01 /* Match if any of the chunk types are present */
27#define SCTP_CHUNK_MATCH_ALL 0x02 /* Match if all of the chunk types are present */
28#define SCTP_CHUNK_MATCH_ONLY 0x04 /* Match if these are the only chunk types present */
29
Arnd Bergmann60c195c2009-02-26 00:51:43 +010030 __u32 chunk_match_type;
Harald Welte2e4e6a12006-01-12 13:30:04 -080031 struct xt_sctp_flag_info flag_info[XT_NUM_SCTP_FLAGS];
32 int flag_count;
33
Arnd Bergmann60c195c2009-02-26 00:51:43 +010034 __u32 flags;
35 __u32 invflags;
Harald Welte2e4e6a12006-01-12 13:30:04 -080036};
37
38#define bytes(type) (sizeof(type) * 8)
39
40#define SCTP_CHUNKMAP_SET(chunkmap, type) \
41 do { \
Arnd Bergmann60c195c2009-02-26 00:51:43 +010042 (chunkmap)[type / bytes(__u32)] |= \
43 1 << (type % bytes(__u32)); \
Harald Welte2e4e6a12006-01-12 13:30:04 -080044 } while (0)
45
46#define SCTP_CHUNKMAP_CLEAR(chunkmap, type) \
47 do { \
Arnd Bergmann60c195c2009-02-26 00:51:43 +010048 (chunkmap)[type / bytes(__u32)] &= \
49 ~(1 << (type % bytes(__u32))); \
Harald Welte2e4e6a12006-01-12 13:30:04 -080050 } while (0)
51
52#define SCTP_CHUNKMAP_IS_SET(chunkmap, type) \
53({ \
Arnd Bergmann60c195c2009-02-26 00:51:43 +010054 ((chunkmap)[type / bytes (__u32)] & \
55 (1 << (type % bytes (__u32)))) ? 1: 0; \
Harald Welte2e4e6a12006-01-12 13:30:04 -080056})
57
Jan Engelhardtb9f61b12008-04-14 09:56:04 +020058#define SCTP_CHUNKMAP_RESET(chunkmap) \
59 memset((chunkmap), 0, sizeof(chunkmap))
Harald Welte2e4e6a12006-01-12 13:30:04 -080060
Jan Engelhardtb9f61b12008-04-14 09:56:04 +020061#define SCTP_CHUNKMAP_SET_ALL(chunkmap) \
62 memset((chunkmap), ~0U, sizeof(chunkmap))
Harald Welte2e4e6a12006-01-12 13:30:04 -080063
Jan Engelhardtb9f61b12008-04-14 09:56:04 +020064#define SCTP_CHUNKMAP_COPY(destmap, srcmap) \
65 memcpy((destmap), (srcmap), sizeof(srcmap))
Harald Welte2e4e6a12006-01-12 13:30:04 -080066
Jan Engelhardtb9f61b12008-04-14 09:56:04 +020067#define SCTP_CHUNKMAP_IS_CLEAR(chunkmap) \
68 __sctp_chunkmap_is_clear((chunkmap), ARRAY_SIZE(chunkmap))
69static inline bool
Arnd Bergmann60c195c2009-02-26 00:51:43 +010070__sctp_chunkmap_is_clear(const __u32 *chunkmap, unsigned int n)
Jan Engelhardtb9f61b12008-04-14 09:56:04 +020071{
72 unsigned int i;
73 for (i = 0; i < n; ++i)
74 if (chunkmap[i])
75 return false;
76 return true;
77}
Harald Welte2e4e6a12006-01-12 13:30:04 -080078
Jan Engelhardtb9f61b12008-04-14 09:56:04 +020079#define SCTP_CHUNKMAP_IS_ALL_SET(chunkmap) \
80 __sctp_chunkmap_is_all_set((chunkmap), ARRAY_SIZE(chunkmap))
81static inline bool
Arnd Bergmann60c195c2009-02-26 00:51:43 +010082__sctp_chunkmap_is_all_set(const __u32 *chunkmap, unsigned int n)
Jan Engelhardtb9f61b12008-04-14 09:56:04 +020083{
84 unsigned int i;
85 for (i = 0; i < n; ++i)
86 if (chunkmap[i] != ~0U)
87 return false;
88 return true;
89}
Harald Welte2e4e6a12006-01-12 13:30:04 -080090
91#endif /* _XT_SCTP_H_ */
92