diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2022-01-25 20:21:18 +0100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2022-01-26 16:30:59 +0100 |
commit | caa22aa644cb56e6fda77ff80c62d038653f3cf9 (patch) | |
tree | 07616ecc3704c24d235591e1efce6fb1031f49b2 | |
parent | 4c7304db85bd4e8ae641ab946a5b3832f24b6eca (diff) | |
download | passt-caa22aa644cb56e6fda77ff80c62d038653f3cf9.tar passt-caa22aa644cb56e6fda77ff80c62d038653f3cf9.tar.gz passt-caa22aa644cb56e6fda77ff80c62d038653f3cf9.tar.bz2 passt-caa22aa644cb56e6fda77ff80c62d038653f3cf9.tar.lz passt-caa22aa644cb56e6fda77ff80c62d038653f3cf9.tar.xz passt-caa22aa644cb56e6fda77ff80c62d038653f3cf9.tar.zst passt-caa22aa644cb56e6fda77ff80c62d038653f3cf9.zip |
tcp, udp, util: Fixes for bitmap handling on big-endian, casts
Bitmap manipulating functions would otherwise refer to inconsistent
sets of bits on big-endian architectures. While at it, fix up a
couple of casts.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r-- | passt.h | 3 | ||||
-rw-r--r-- | tcp.c | 2 | ||||
-rw-r--r-- | udp.c | 4 | ||||
-rw-r--r-- | util.c | 12 | ||||
-rw-r--r-- | util.h | 2 |
5 files changed, 16 insertions, 7 deletions
@@ -67,7 +67,8 @@ extern char pkt_buf [PKT_BUF_BYTES]; extern char *ip_proto_str[]; #define IP_PROTO_STR(n) \ - (((n) <= IPPROTO_SCTP && ip_proto_str[(n)]) ? ip_proto_str[(n)] : "?") + (((uint8_t)(n) <= IPPROTO_SCTP && ip_proto_str[(n)]) ? \ + ip_proto_str[(n)] : "?") #include <resolv.h> /* For MAXNS below */ @@ -2518,7 +2518,7 @@ eintr: } - if (n < (seq_from_tap - conn->seq_from_tap)) { + if (n < (int)(seq_from_tap - conn->seq_from_tap)) { partial_send = 1; conn->seq_from_tap += n; tcp_send_to_tap(c, conn, 0, now); @@ -684,7 +684,7 @@ void udp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events, cur_mh->msg_iov = &udp6_l2_iov_tap[0]; msg_i = msglen = iov_in_msg = 0; - for (i = 0; i < n; i++) { + for (i = 0; i < (unsigned)n; i++) { struct udp6_l2_buf_t *b = &udp6_l2_buf[i]; size_t ip_len, iov_len; @@ -770,7 +770,7 @@ void udp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events, cur_mh->msg_iov = &udp4_l2_iov_tap[0]; msg_i = msglen = iov_in_msg = 0; - for (i = 0; i < n; i++) { + for (i = 0; i < (unsigned)n; i++) { struct udp4_l2_buf_t *b = &udp4_l2_buf[i]; size_t ip_len, iov_len; in_addr_t s_addr; @@ -342,7 +342,9 @@ int timespec_diff_ms(struct timespec *a, struct timespec *b) */ void bitmap_set(uint8_t *map, int bit) { - map[bit / 8] |= 1 << (bit % 8); + unsigned long *word = (unsigned long *)map + BITMAP_WORD(bit); + + *word |= BITMAP_BIT(bit); } /** @@ -352,7 +354,9 @@ void bitmap_set(uint8_t *map, int bit) */ void bitmap_clear(uint8_t *map, int bit) { - map[bit / 8] &= ~(1 << (bit % 8)); + unsigned long *word = (unsigned long *)map + BITMAP_WORD(bit); + + *word &= ~BITMAP_BIT(bit); } /** @@ -364,7 +368,9 @@ void bitmap_clear(uint8_t *map, int bit) */ int bitmap_isset(const uint8_t *map, int bit) { - return map[bit / 8] & (1 << bit % 8); + unsigned long *word = (unsigned long *)map + BITMAP_WORD(bit); + + return *word & BITMAP_BIT(bit); } /** @@ -43,6 +43,8 @@ void debug(const char *format, ...); #define ROUND_DOWN(x, y) ((x) & ~((y) - 1)) #define ROUND_UP(x, y) (((x) + (y) - 1) & ~((y) - 1)) +#define BITMAP_BIT(n) (1UL << (n) % (sizeof(long) * 8)) +#define BITMAP_WORD(n) (n / (sizeof(long) * 8)) #define SWAP(a, b) \ do { \ |