aboutsummaryrefslogblamecommitdiffstats
path: root/radix-trie.h
blob: 9e210af731fd2114134fc82d6648bbf9a00ea10f (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                         

                                                                














                                                                          
/* SPDX-License-Identifier: MIT
 *
 * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
 */

#ifndef __RADIX_TRIE_H__
#define __RADIX_TRIE_H__

#include <arpa/inet.h>
#include <stdbool.h>
#include <stdint.h>

struct radix_trie {
	struct radix_node *ip4_root, *ip6_root;
};

void radix_init(struct radix_trie *trie);
void radix_free(struct radix_trie *trie);
void *radix_find_v4(struct radix_trie *trie, const void *be_ip);
void *radix_find_v6(struct radix_trie *trie, const void *be_ip);
int radix_insert_v4(struct radix_trie *root, const struct in_addr *ip,
		    uint8_t cidr, void *data);
int radix_insert_v6(struct radix_trie *root, const struct in6_addr *ip,
		    uint8_t cidr, void *data);
int radix_tryinsert_v4(struct radix_trie *root, const struct in_addr *ip,
		       uint8_t cidr, void *data);
int radix_tryinsert_v6(struct radix_trie *root, const struct in6_addr *ip,
		       uint8_t cidr, void *data);

#ifdef DEBUG
void node_to_str(struct radix_node *node, char *buf);
void debug_print_trie(struct radix_node *root);
#endif

#endif