-
Notifications
You must be signed in to change notification settings - Fork 5
/
quic_lb_types.h
73 lines (63 loc) · 2.06 KB
/
quic_lb_types.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Copyright (c) 2020 F5 Networks Inc.
* This source code is subject to the terms of the Apache License,
* version 2.0 (https://www.apache.org/licenses/LICENSE-2.0)
*/
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/evp.h>
#include <openssl/rand.h>
#ifndef _QUIC_LB_TYPES
#define _QUIC_LB_TYPES
typedef uint8_t UINT8;
typedef uint16_t UINT16;
typedef uint32_t UINT32;
typedef uint64_t UINT64;
typedef __uint128_t UINT128;
typedef enum {FALSE, TRUE} BOOL;
typedef enum {ERR_OK, ERR_REJECT} err_t;
/* BIGIP constants that don't matter here */
#define RND_PSEUDO 0
#define M_FILTER 0
#define UM_ZERO 0
static inline void *umalloc(size_t size, int ignored, int cleared)
{
void *ret = malloc(size);
if ((ret != NULL) && (cleared == UM_ZERO)) {
ret = memset(ret, 0, size);
}
return ret;
}
#define ufree(arg) free(arg)
#define CUT_ASSERT(expr) assert(expr)
#define ROUNDUPDIV(n, m) (((n) + ((m) - 1)) / (m))
#define rndset(ptr,type,len) RAND_bytes((unsigned char *)ptr,len)
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
/* Template to limit to a certain range for various types */
#define RND_RANGE(type,fnname,intmax) \
static inline type fnname(int rnd_type, \
type max) \
{ \
type value; \
rndset((unsigned char *)&value, rnd_type, sizeof(max)); \
return ((max < intmax) ? (value % (max + 1)) : value); \
}
RND_RANGE(UINT8, rnd8_range, UINT8_MAX)
RND_RANGE(UINT16, rnd16_range, UINT16_MAX)
static inline unsigned bit_count(UINT8 i)
{
UINT8 octet = i;
unsigned count = 0;
while (i > 0) {
if ((i & 0x1) == 1) {
count++;
}
i >>= 1;
}
return count;
}
#endif // _QUIC_LB_TYPES