Commit b9f61b16 authored by Jan Engelhardt's avatar Jan Engelhardt Committed by Patrick McHardy

[NETFILTER]: xt_sctp: simplify xt_sctp.h

The use of xt_sctp.h flagged up -Wshadow warnings in userspace, which
prompted me to look at it and clean it up. Basic operations have been
directly replaced by library calls (memcpy, memset is both available
in the kernel and userspace, and usually faster than a self-made
loop). The is_set and is_clear functions now use a processing time
shortcut, too.
Signed-off-by: default avatarJan Engelhardt <jengelh@computergmbh.de>
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
parent fdccecd0
...@@ -37,68 +37,54 @@ struct xt_sctp_info { ...@@ -37,68 +37,54 @@ struct xt_sctp_info {
#define SCTP_CHUNKMAP_SET(chunkmap, type) \ #define SCTP_CHUNKMAP_SET(chunkmap, type) \
do { \ do { \
chunkmap[type / bytes(u_int32_t)] |= \ (chunkmap)[type / bytes(u_int32_t)] |= \
1 << (type % bytes(u_int32_t)); \ 1 << (type % bytes(u_int32_t)); \
} while (0) } while (0)
#define SCTP_CHUNKMAP_CLEAR(chunkmap, type) \ #define SCTP_CHUNKMAP_CLEAR(chunkmap, type) \
do { \ do { \
chunkmap[type / bytes(u_int32_t)] &= \ (chunkmap)[type / bytes(u_int32_t)] &= \
~(1 << (type % bytes(u_int32_t))); \ ~(1 << (type % bytes(u_int32_t))); \
} while (0) } while (0)
#define SCTP_CHUNKMAP_IS_SET(chunkmap, type) \ #define SCTP_CHUNKMAP_IS_SET(chunkmap, type) \
({ \ ({ \
(chunkmap[type / bytes (u_int32_t)] & \ ((chunkmap)[type / bytes (u_int32_t)] & \
(1 << (type % bytes (u_int32_t)))) ? 1: 0; \ (1 << (type % bytes (u_int32_t)))) ? 1: 0; \
}) })
#define SCTP_CHUNKMAP_RESET(chunkmap) \ #define SCTP_CHUNKMAP_RESET(chunkmap) \
do { \ memset((chunkmap), 0, sizeof(chunkmap))
int i; \
for (i = 0; i < ARRAY_SIZE(chunkmap); i++) \
chunkmap[i] = 0; \
} while (0)
#define SCTP_CHUNKMAP_SET_ALL(chunkmap) \ #define SCTP_CHUNKMAP_SET_ALL(chunkmap) \
do { \ memset((chunkmap), ~0U, sizeof(chunkmap))
int i; \
for (i = 0; i < ARRAY_SIZE(chunkmap); i++) \
chunkmap[i] = ~0; \
} while (0)
#define SCTP_CHUNKMAP_COPY(destmap, srcmap) \ #define SCTP_CHUNKMAP_COPY(destmap, srcmap) \
do { \ memcpy((destmap), (srcmap), sizeof(srcmap))
int i; \
for (i = 0; i < ARRAY_SIZE(srcmap); i++) \
destmap[i] = srcmap[i]; \
} while (0)
#define SCTP_CHUNKMAP_IS_CLEAR(chunkmap) \ #define SCTP_CHUNKMAP_IS_CLEAR(chunkmap) \
({ \ __sctp_chunkmap_is_clear((chunkmap), ARRAY_SIZE(chunkmap))
int i; \ static inline bool
int flag = 1; \ __sctp_chunkmap_is_clear(const u_int32_t *chunkmap, unsigned int n)
for (i = 0; i < ARRAY_SIZE(chunkmap); i++) { \ {
if (chunkmap[i]) { \ unsigned int i;
flag = 0; \ for (i = 0; i < n; ++i)
break; \ if (chunkmap[i])
} \ return false;
} \ return true;
flag; \ }
})
#define SCTP_CHUNKMAP_IS_ALL_SET(chunkmap) \ #define SCTP_CHUNKMAP_IS_ALL_SET(chunkmap) \
({ \ __sctp_chunkmap_is_all_set((chunkmap), ARRAY_SIZE(chunkmap))
int i; \ static inline bool
int flag = 1; \ __sctp_chunkmap_is_all_set(const u_int32_t *chunkmap, unsigned int n)
for (i = 0; i < ARRAY_SIZE(chunkmap); i++) { \ {
if (chunkmap[i] != ~0) { \ unsigned int i;
flag = 0; \ for (i = 0; i < n; ++i)
break; \ if (chunkmap[i] != ~0U)
} \ return false;
} \ return true;
flag; \ }
})
#endif /* _XT_SCTP_H_ */ #endif /* _XT_SCTP_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment