Fix definitions of SOCKET_MAX, TCP_MAX_CONNS

...and, given that I keep getting this wrong, add a convenience
macro, MAX_FROM_BITS().

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Stefano Brivio 2023-02-27 03:30:01 +01:00
parent 4f523c3276
commit 26a0e4d6ee
4 changed files with 7 additions and 5 deletions

View file

@ -42,7 +42,7 @@ union epoll_ref;
/** /**
* union epoll_ref - Breakdown of reference for epoll socket bookkeeping * union epoll_ref - Breakdown of reference for epoll socket bookkeeping
* @proto: IP protocol number * @proto: IP protocol number
* @s: Socket number (implies 2^24 limit on number of descriptors) * @s: Socket number (implies 2^24-1 limit on number of descriptors)
* @tcp: TCP-specific reference part * @tcp: TCP-specific reference part
* @udp: UDP-specific reference part * @udp: UDP-specific reference part
* @icmp: ICMP-specific reference part * @icmp: ICMP-specific reference part
@ -53,7 +53,7 @@ union epoll_ref {
struct { struct {
int32_t proto:8, int32_t proto:8,
#define SOCKET_REF_BITS 24 #define SOCKET_REF_BITS 24
#define SOCKET_MAX (1 << SOCKET_REF_BITS) #define SOCKET_MAX MAX_FROM_BITS(SOCKET_REF_BITS)
s:SOCKET_REF_BITS; s:SOCKET_REF_BITS;
union { union {
union tcp_epoll_ref tcp; union tcp_epoll_ref tcp;

4
tcp.h
View file

@ -8,8 +8,8 @@
#define TCP_TIMER_INTERVAL 1000 /* ms */ #define TCP_TIMER_INTERVAL 1000 /* ms */
#define TCP_CONN_INDEX_BITS 17 /* 128k */ #define TCP_CONN_INDEX_BITS 17 /* 128k - 1 */
#define TCP_MAX_CONNS (1 << TCP_CONN_INDEX_BITS) #define TCP_MAX_CONNS MAX_FROM_BITS(TCP_CONN_INDEX_BITS)
struct ctx; struct ctx;

View file

@ -54,7 +54,7 @@ struct tcp_tap_conn {
#define TCP_RETRANS_BITS 3 #define TCP_RETRANS_BITS 3
unsigned int retrans :TCP_RETRANS_BITS; unsigned int retrans :TCP_RETRANS_BITS;
#define TCP_MAX_RETRANS ((1U << TCP_RETRANS_BITS) - 1) #define TCP_MAX_RETRANS MAX_FROM_BITS(TCP_RETRANS_BITS)
#define TCP_WS_BITS 4 /* RFC 7323 */ #define TCP_WS_BITS 4 /* RFC 7323 */
#define TCP_WS_MAX 14 #define TCP_WS_MAX 14

2
util.h
View file

@ -40,6 +40,8 @@
#define ROUND_DOWN(x, y) ((x) & ~((y) - 1)) #define ROUND_DOWN(x, y) ((x) & ~((y) - 1))
#define ROUND_UP(x, y) (((x) + (y) - 1) & ~((y) - 1)) #define ROUND_UP(x, y) (((x) + (y) - 1) & ~((y) - 1))
#define MAX_FROM_BITS(n) ((int)((1U << (n)) - 1))
#define BIT(n) (1UL << (n)) #define BIT(n) (1UL << (n))
#define BITMAP_BIT(n) (BIT((n) % (sizeof(long) * 8))) #define BITMAP_BIT(n) (BIT((n) % (sizeof(long) * 8)))
#define BITMAP_WORD(n) (n / (sizeof(long) * 8)) #define BITMAP_WORD(n) (n / (sizeof(long) * 8))