2024-06-07 16:57:34 +02:00
|
|
|
#ifndef RADIX_HEADER_736213980973149671328765
|
|
|
|
#define RADIX_HEADER_736213980973149671328765
|
|
|
|
|
|
|
|
#include "stdio.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
#include "string.h"
|
|
|
|
|
|
|
|
#define VALID_RULE 1
|
|
|
|
#define INVALID_RULE 0
|
|
|
|
#define RULE_NOT_FOUND -1
|
|
|
|
|
2024-06-08 12:51:50 +02:00
|
|
|
struct routing_record {
|
|
|
|
unsigned long long _ip;
|
|
|
|
unsigned short _rule;
|
|
|
|
unsigned _ip_end_bit:7;
|
|
|
|
unsigned _rule_valid:1;
|
2024-06-07 16:57:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct radix_node {
|
|
|
|
struct radix_node* _l;
|
|
|
|
struct radix_node* _r;
|
2024-06-08 12:51:50 +02:00
|
|
|
struct routing_record _data;
|
2024-06-07 16:57:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct radix_holder {
|
|
|
|
struct radix_node* _root;
|
|
|
|
size_t _size;
|
|
|
|
};
|
|
|
|
|
2024-06-08 12:51:50 +02:00
|
|
|
typedef struct radix_node* radix_node_t;
|
|
|
|
typedef struct radix_holder* radix_holder_t;
|
|
|
|
typedef struct routing_record* record_t;
|
2024-06-07 16:57:34 +02:00
|
|
|
|
|
|
|
struct radix_holder* create_holder();
|
2024-06-08 12:51:50 +02:00
|
|
|
struct radix_node* create_node(record_t record);
|
|
|
|
static struct radix_node* clone_node(radix_node_t n);
|
2024-06-07 16:57:34 +02:00
|
|
|
static void split_node(struct radix_node* n, unsigned bit);
|
|
|
|
|
|
|
|
int destory_holder(struct radix_holder*);
|
|
|
|
int destory_node(struct radix_node*);
|
|
|
|
|
2024-06-08 12:51:50 +02:00
|
|
|
int radix_insert(radix_holder_t, record_t);
|
|
|
|
int radix_search(radix_holder_t, record_t);
|
2024-06-07 16:57:34 +02:00
|
|
|
|
|
|
|
#endif
|