This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
2024-09-27 19:11:47 +08:00

73 lines
2.2 KiB
C

#ifndef _UTILS_H
#define _UTILS_H
#ifdef __cplusplus
extern "C"
{
#endif
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define LOG_TAG_SCE "SCE"
#define LOG_TAG_POLICY "POLICY"
#define LOG_TAG_PKTIO "PACKET_IO"
#define LOG_TAG_RAWPKT "DATA_PACKET"
#define LOG_TAG_CTRLPKT "CTRL_PACKET"
#define LOG_TAG_SFMETRICS "SF_METRICS"
#define LOG_TAG_SFSTATUS "SF_STATUS"
#define LOG_TAG_UTILS "UTILS"
#define LOG_TAG_HEALTH_CHECK "HEALTH_CHECK"
#define LOG_TAG_TIMESTAMP "TIMESTAMP"
#define LOG_TAG_KAFKA "KAFKA"
#define ATOMIC_INC(x) __atomic_fetch_add(x, 1, __ATOMIC_RELAXED)
#define ATOMIC_DEC(x) __atomic_fetch_sub(x, 1, __ATOMIC_RELAXED)
#define ATOMIC_READ(x) __atomic_load_n(x, __ATOMIC_RELAXED)
#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)
#define likely(expr) __builtin_expect((expr), 1)
#define unlikely(expr) __builtin_expect((expr), 0)
#include <stdint.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <uuid/uuid.h>
/******************************************************************************
* uuid_array
******************************************************************************/
#define UUID_STRING_SIZE 37
#define MAX_RULE_NUM 128
struct uuid_array
{
uuid_t uuids[MAX_RULE_NUM];
int num;
int size;
};
void uuid_array_init(struct uuid_array *array);
void uuid_array_append(struct uuid_array *array, uuid_t uuid);
void uuid_array_remove(struct uuid_array *array, uuid_t uuid);
int uuid_array_contains(struct uuid_array *array, uuid_t uuid);
int uuid_array_is_full(struct uuid_array *array);
int uuid_array_get_count(struct uuid_array *array);
uuid_t *uuid_array_get_at(struct uuid_array *array, int index);
/******************************************************************************
* device
******************************************************************************/
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[]);
#ifdef __cplusplus
}
#endif
#endif