Skip to content

Commit

Permalink
pike: clang-format for coherent indentation and coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac committed May 18, 2023
1 parent 1560509 commit 448caab
Show file tree
Hide file tree
Showing 10 changed files with 388 additions and 413 deletions.
203 changes: 99 additions & 104 deletions src/modules/pike/ip_tree.c

Large diffs are not rendered by default.

68 changes: 36 additions & 32 deletions src/modules/pike/ip_tree.h
Expand Up @@ -28,38 +28,41 @@
#include "timer.h"


#define NEW_NODE (1<<0)
#define RED_NODE (1<<1)
#define NEWRED_NODE (1<<2)
#define NO_UPDATE (1<<3)
#define NEW_NODE (1 << 0)
#define RED_NODE (1 << 1)
#define NEWRED_NODE (1 << 2)
#define NO_UPDATE (1 << 3)

#define MAX_IP_BRANCHES 256

#define PREV_POS 0
#define CURR_POS 1


#define NODE_EXPIRED_FLAG (1<<0)
#define NODE_INTIMER_FLAG (1<<1)
#define NODE_IPLEAF_FLAG (1<<2)
#define NODE_ISRED_FLAG (1<<3)
#define NODE_EXPIRED_FLAG (1 << 0)
#define NODE_INTIMER_FLAG (1 << 1)
#define NODE_IPLEAF_FLAG (1 << 2)
#define NODE_ISRED_FLAG (1 << 3)

typedef struct pike_ip_node {
unsigned int expires;
unsigned short leaf_hits[2];
unsigned short hits[2];
unsigned char byte;
unsigned char branch;
typedef struct pike_ip_node
{
unsigned int expires;
unsigned short leaf_hits[2];
unsigned short hits[2];
unsigned char byte;
unsigned char branch;
volatile unsigned short flags;
pike_list_link_t timer_ll;
struct pike_ip_node *prev;
struct pike_ip_node *next;
struct pike_ip_node *kids;
pike_list_link_t timer_ll;
struct pike_ip_node *prev;
struct pike_ip_node *next;
struct pike_ip_node *kids;
} pike_ip_node_t;


typedef struct ip_tree {
struct entry {
typedef struct ip_tree
{
struct entry
{
pike_ip_node_t *node;
int lock_idx;
} entries[MAX_IP_BRANCHES];
Expand All @@ -68,27 +71,28 @@ typedef struct ip_tree {
} pike_ip_tree_t;


#define ll2ipnode(ptr) \
((pike_ip_node_t*)((char *)(ptr)-\
(unsigned long)(&((pike_ip_node_t*)0)->timer_ll)))
#define ll2ipnode(ptr) \
((pike_ip_node_t *)((char *)(ptr) \
- (unsigned long)(&((pike_ip_node_t *)0)->timer_ll)))


int init_ip_tree(int);
void destroy_ip_tree(void);
pike_ip_node_t* mark_node( unsigned char *ip, int ip_len,
pike_ip_node_t **father, unsigned char *flag);
pike_ip_node_t *mark_node(unsigned char *ip, int ip_len,
pike_ip_node_t **father, unsigned char *flag);
void remove_node(pike_ip_node_t *node);
int is_node_hot_leaf(pike_ip_node_t *node);

void lock_tree_branch(unsigned char b);
void unlock_tree_branch(unsigned char b);
pike_ip_node_t* get_tree_branch(unsigned char b);

typedef enum {
NODE_STATUS_OK = 0,
NODE_STATUS_WARM = 1,
NODE_STATUS_HOT = 2,
NODE_STATUS_ALL = 3 /** used for status matching */
pike_ip_node_t *get_tree_branch(unsigned char b);

typedef enum
{
NODE_STATUS_OK = 0,
NODE_STATUS_WARM = 1,
NODE_STATUS_HOT = 2,
NODE_STATUS_ALL = 3 /** used for status matching */
} pike_node_status_t;
pike_node_status_t node_status(pike_ip_node_t *node);
extern char *node_status_array[];
Expand Down
88 changes: 40 additions & 48 deletions src/modules/pike/pike.c
Expand Up @@ -46,94 +46,86 @@
MODULE_VERSION



static int pike_init(void);
void pike_exit(void);



/* parameters */
static int pike_time_unit = 2;
static int pike_max_reqs = 30;
int pike_timeout = 120;
static int pike_max_reqs = 30;
int pike_timeout = 120;
int pike_log_level = L_WARN;

/* global variables */
gen_lock_t *pike_timer_lock = 0;
gen_lock_t *pike_timer_lock = 0;
pike_list_link_t *pike_timer = 0;


static cmd_export_t cmds[]={
{"pike_check_req", (cmd_function)w_pike_check_req, 0,
0, 0, REQUEST_ROUTE|ONREPLY_ROUTE},
{"pike_check_ip", (cmd_function)w_pike_check_ip, 1,
fixup_spve_null, fixup_free_spve_null, REQUEST_ROUTE|ONREPLY_ROUTE},
{0,0,0,0,0,0}
};

static param_export_t params[]={
{"sampling_time_unit", INT_PARAM, &pike_time_unit},
{"reqs_density_per_unit", INT_PARAM, &pike_max_reqs},
{"remove_latency", INT_PARAM, &pike_timeout},
{"pike_log_level", INT_PARAM, &pike_log_level},
{0,0,0}
static cmd_export_t cmds[] = {{"pike_check_req", (cmd_function)w_pike_check_req,
0, 0, 0, REQUEST_ROUTE | ONREPLY_ROUTE},
{"pike_check_ip", (cmd_function)w_pike_check_ip, 1, fixup_spve_null,
fixup_free_spve_null, REQUEST_ROUTE | ONREPLY_ROUTE},
{0, 0, 0, 0, 0, 0}};

static param_export_t params[] = {
{"sampling_time_unit", INT_PARAM, &pike_time_unit},
{"reqs_density_per_unit", INT_PARAM, &pike_max_reqs},
{"remove_latency", INT_PARAM, &pike_timeout},
{"pike_log_level", INT_PARAM, &pike_log_level}, {0, 0, 0}};


struct module_exports exports = {
"pike", /* module name */
DEFAULT_DLFLAGS, /* dlopen flags */
cmds, /* cmd exports */
params, /* param exports */
0, /* RPC method exports */
0, /* exported pseudo-variables */
0, /* response handling function */
pike_init, /* module initialization function */
0, /* per-child init function */
pike_exit /* module exit function */
};


struct module_exports exports= {
"pike", /* module name */
DEFAULT_DLFLAGS, /* dlopen flags */
cmds, /* cmd exports */
params, /* param exports */
0, /* RPC method exports */
0, /* exported pseudo-variables */
0, /* response handling function */
pike_init, /* module initialization function */
0, /* per-child init function */
pike_exit /* module exit function */
};




static int pike_init(void)
{
LOG(L_INFO, "PIKE - initializing\n");

if (rpc_register_array(pike_rpc_methods)!=0) {
if(rpc_register_array(pike_rpc_methods) != 0) {
LM_ERR("failed to register RPC commands\n");
return -1;
}

/* alloc the timer lock */
pike_timer_lock=lock_alloc();
if (pike_timer_lock==0) {
pike_timer_lock = lock_alloc();
if(pike_timer_lock == 0) {
LM_ERR(" alloc locks failed!\n");
goto error1;
}
/* init the lock */
if (lock_init(pike_timer_lock)==0){
if(lock_init(pike_timer_lock) == 0) {
LM_ERR(" init lock failed\n");
goto error1;
}

/* init the IP tree */
if ( init_ip_tree(pike_max_reqs)!=0 ) {
if(init_ip_tree(pike_max_reqs) != 0) {
LM_ERR(" ip_tree creation failed!\n");
goto error2;
}

/* init timer list */
pike_timer = (pike_list_link_t*)shm_malloc(sizeof(pike_list_link_t));
if (pike_timer==0) {
pike_timer = (pike_list_link_t *)shm_malloc(sizeof(pike_list_link_t));
if(pike_timer == 0) {
SHM_MEM_ERROR_FMT("for timer!\n");
goto error3;
}
pike_timer->next = pike_timer->prev = pike_timer;

/* registering timing functions */
register_timer( clean_routine , 0, 1 );
register_timer( swap_routine , 0, pike_time_unit );
register_timer(clean_routine, 0, 1);
register_timer(swap_routine, 0, pike_time_unit);

/* Register counter */
pike_counter_init();
Expand All @@ -144,23 +136,23 @@ static int pike_init(void)
error2:
lock_destroy(pike_timer_lock);
error1:
if (pike_timer_lock) lock_dealloc(pike_timer_lock);
if(pike_timer_lock)
lock_dealloc(pike_timer_lock);
pike_timer_lock = 0;
return -1;
}



void pike_exit(void)
{
/* destroy semaphore */
if (pike_timer_lock) {
if(pike_timer_lock) {
lock_destroy(pike_timer_lock);
lock_dealloc(pike_timer_lock);
}

/* empty the timer list head */
if (pike_timer) {
if(pike_timer) {
shm_free(pike_timer);
pike_timer = 0;
}
Expand Down

0 comments on commit 448caab

Please sign in to comment.