1
0
mirror of https://passt.top/passt synced 2024-06-30 15:02:40 +00:00

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>
This commit is contained in:
Stefano Brivio 2022-01-25 20:21:18 +01:00
parent 4c7304db85
commit caa22aa644
5 changed files with 16 additions and 7 deletions

View File

@ -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 */

2
tcp.c
View File

@ -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);

4
udp.c
View File

@ -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;

12
util.c
View File

@ -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);
}
/**

2
util.h
View File

@ -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 { \