changing trunk/trunk to trunk
[iptables.git] / include / linux / netfilter / xt_sctp.h
1 #ifndef _XT_SCTP_H_
2 #define _XT_SCTP_H_
3
4 #define XT_SCTP_SRC_PORTS               0x01
5 #define XT_SCTP_DEST_PORTS              0x02
6 #define XT_SCTP_CHUNK_TYPES             0x04
7
8 #define XT_SCTP_VALID_FLAGS             0x07
9
10 /* temporary */
11 #define SCTP_ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
12
13
14 struct xt_sctp_flag_info {
15         u_int8_t chunktype;
16         u_int8_t flag;
17         u_int8_t flag_mask;
18 };
19
20 #define XT_NUM_SCTP_FLAGS       4
21
22 struct xt_sctp_info {
23         u_int16_t dpts[2];  /* Min, Max */
24         u_int16_t spts[2];  /* Min, Max */
25
26         u_int32_t chunkmap[256 / sizeof (u_int32_t)];  /* Bit mask of chunks to be matched according to RFC 2960 */
27
28 #define SCTP_CHUNK_MATCH_ANY   0x01  /* Match if any of the chunk types are present */
29 #define SCTP_CHUNK_MATCH_ALL   0x02  /* Match if all of the chunk types are present */
30 #define SCTP_CHUNK_MATCH_ONLY  0x04  /* Match if these are the only chunk types present */
31
32         u_int32_t chunk_match_type;
33         struct xt_sctp_flag_info flag_info[XT_NUM_SCTP_FLAGS];
34         int flag_count;
35
36         u_int32_t flags;
37         u_int32_t invflags;
38 };
39
40 #define bytes(type) (sizeof(type) * 8)
41
42 #define SCTP_CHUNKMAP_SET(chunkmap, type)               \
43         do {                                            \
44                 (chunkmap)[type / bytes(u_int32_t)] |=  \
45                         1 << (type % bytes(u_int32_t)); \
46         } while (0)
47
48 #define SCTP_CHUNKMAP_CLEAR(chunkmap, type)                     \
49         do {                                                    \
50                 (chunkmap)[type / bytes(u_int32_t)] &=          \
51                         ~(1 << (type % bytes(u_int32_t)));      \
52         } while (0)
53
54 #define SCTP_CHUNKMAP_IS_SET(chunkmap, type)                    \
55 ({                                                              \
56         ((chunkmap)[type / bytes (u_int32_t)] &                 \
57                 (1 << (type % bytes (u_int32_t)))) ? 1: 0;      \
58 })
59
60 #define SCTP_CHUNKMAP_RESET(chunkmap) \
61         memset((chunkmap), 0, sizeof(chunkmap))
62
63 #define SCTP_CHUNKMAP_SET_ALL(chunkmap) \
64         memset((chunkmap), ~0U, sizeof(chunkmap))
65
66 #define SCTP_CHUNKMAP_COPY(destmap, srcmap) \
67         memcpy((destmap), (srcmap), sizeof(srcmap))
68
69 #define SCTP_CHUNKMAP_IS_CLEAR(chunkmap) \
70         __sctp_chunkmap_is_clear((chunkmap), SCTP_ARRAY_SIZE(chunkmap))
71 static inline bool
72 __sctp_chunkmap_is_clear(const u_int32_t *chunkmap, unsigned int n)
73 {
74         unsigned int i;
75         for (i = 0; i < n; ++i)
76                 if (chunkmap[i])
77                         return false;
78         return true;
79 }
80
81 #define SCTP_CHUNKMAP_IS_ALL_SET(chunkmap) \
82         __sctp_chunkmap_is_all_set((chunkmap), ARRAY_SIZE(chunkmap))
83 static inline bool
84 __sctp_chunkmap_is_all_set(const u_int32_t *chunkmap, unsigned int n)
85 {
86         unsigned int i;
87         for (i = 0; i < n; ++i)
88                 if (chunkmap[i] != ~0U)
89                         return false;
90         return true;
91 }
92
93 #endif /* _XT_SCTP_H_ */
94