2023-02-06 10:34:23 +08:00
|
|
|
#ifndef _UTILS_H
|
|
|
|
|
#define _UTILS_H
|
|
|
|
|
|
|
|
|
|
#ifdef __cpluscplus
|
|
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-02-17 17:15:53 +08:00
|
|
|
#define MIN(a, b) ((a) > (b) ? (b) : (a))
|
2023-02-06 10:34:23 +08:00
|
|
|
|
2023-03-14 16:10:44 +08:00
|
|
|
#define LOG_TAG_SCE "SCE"
|
|
|
|
|
#define LOG_TAG_POLICY "POLICY"
|
|
|
|
|
#define LOG_TAG_PKTIO "PACKET_IO"
|
2023-10-18 10:08:10 +08:00
|
|
|
#define LOG_TAG_RAWPKT "DATA_PACKET"
|
2023-03-14 16:10:44 +08:00
|
|
|
#define LOG_TAG_CTRLPKT "CTRL_PACKET"
|
2023-11-23 16:52:06 +08:00
|
|
|
#define LOG_TAG_SFMETRICS "SF_METRICS"
|
|
|
|
|
#define LOG_TAG_SFSTATUS "SF_STATUS"
|
2023-03-14 16:10:44 +08:00
|
|
|
#define LOG_TAG_UTILS "UTILS"
|
|
|
|
|
#define LOG_TAG_HEALTH_CHECK "HEALTH_CHECK"
|
|
|
|
|
#define LOG_TAG_TIMESTAMP "TIMESTAMP"
|
2023-03-27 14:37:18 +08:00
|
|
|
|
|
|
|
|
#define ATOMIC_INC(x) __atomic_fetch_add(x, 1, __ATOMIC_RELAXED)
|
|
|
|
|
#define ATOMIC_DEC(x) __atomic_fetch_sub(x, 1, __ATOMIC_RELAXED)
|
2023-10-13 12:00:39 +08:00
|
|
|
#define ATOMIC_READ(x) __atomic_load_n(x, __ATOMIC_RELAXED)
|
2023-03-27 14:37:18 +08:00
|
|
|
#define ATOMIC_ZERO(x) __atomic_fetch_and(x, 0, __ATOMIC_RELAXED)
|
|
|
|
|
#define ATOMIC_ADD(x, y) __atomic_fetch_add(x, y, __ATOMIC_RELAXED)
|
|
|
|
|
#define ATOMIC_SET(x, y) __atomic_store_n(x, y, __ATOMIC_RELAXED)
|
2023-02-10 14:22:40 +08:00
|
|
|
|
2023-05-04 17:56:12 +08:00
|
|
|
#define likely(expr) __builtin_expect((expr), 1)
|
|
|
|
|
#define unlikely(expr) __builtin_expect((expr), 0)
|
|
|
|
|
|
2023-10-12 11:59:42 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
2023-02-10 14:22:40 +08:00
|
|
|
/******************************************************************************
|
2023-10-18 10:08:10 +08:00
|
|
|
* mutable_array
|
2023-02-10 14:22:40 +08:00
|
|
|
******************************************************************************/
|
2023-02-06 10:34:23 +08:00
|
|
|
|
2023-10-18 10:08:10 +08:00
|
|
|
struct mutable_array
|
2023-02-06 10:34:23 +08:00
|
|
|
{
|
2023-04-07 14:09:20 +08:00
|
|
|
uint64_t elems[128];
|
2023-02-06 10:34:23 +08:00
|
|
|
int num;
|
|
|
|
|
int size;
|
|
|
|
|
};
|
|
|
|
|
|
2023-10-18 10:08:10 +08:00
|
|
|
void mutable_array_init(struct mutable_array *array);
|
|
|
|
|
void mutable_array_add_elem(struct mutable_array *array, uint64_t elem);
|
|
|
|
|
void mutable_array_del_elem(struct mutable_array *array, uint64_t elem);
|
|
|
|
|
int mutable_array_is_full(struct mutable_array *array);
|
|
|
|
|
int mutable_array_count_elem(struct mutable_array *array);
|
|
|
|
|
int mutable_array_exist_elem(struct mutable_array *array, uint64_t elem);
|
|
|
|
|
int mutable_array_index_elem(struct mutable_array *array, int index);
|
2023-02-06 10:34:23 +08:00
|
|
|
|
2023-02-10 14:22:40 +08:00
|
|
|
/******************************************************************************
|
|
|
|
|
* device
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
2023-10-12 11:59:42 +08:00
|
|
|
int get_ip_by_device_name(const char *dev_name, char *ip_str);
|
|
|
|
|
int get_mac_by_device_name(const char *dev_name, char *mac_str);
|
|
|
|
|
int str_to_mac(const char *mac_str, u_char mac[]);
|
2023-02-10 14:22:40 +08:00
|
|
|
|
2023-02-06 10:34:23 +08:00
|
|
|
#ifdef __cpluscplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|