Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../usr/include/bind9/isc
File: radix.h
/*
[0] Fix | Delete
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
[1] Fix | Delete
*
[2] Fix | Delete
* This Source Code Form is subject to the terms of the Mozilla Public
[3] Fix | Delete
* License, v. 2.0. If a copy of the MPL was not distributed with this
[4] Fix | Delete
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
[5] Fix | Delete
*
[6] Fix | Delete
* See the COPYRIGHT file distributed with this work for additional
[7] Fix | Delete
* information regarding copyright ownership.
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
#include <stdbool.h>
[11] Fix | Delete
[12] Fix | Delete
#include <isc/magic.h>
[13] Fix | Delete
#include <isc/types.h>
[14] Fix | Delete
#include <isc/mutex.h>
[15] Fix | Delete
#include <isc/net.h>
[16] Fix | Delete
#include <isc/refcount.h>
[17] Fix | Delete
[18] Fix | Delete
#include <string.h>
[19] Fix | Delete
[20] Fix | Delete
#ifndef _RADIX_H
[21] Fix | Delete
#define _RADIX_H
[22] Fix | Delete
[23] Fix | Delete
#define NETADDR_TO_PREFIX_T(na,pt,bits,is_ecs) \
[24] Fix | Delete
do { \
[25] Fix | Delete
const void *p = na; \
[26] Fix | Delete
memset(&(pt), 0, sizeof(pt)); \
[27] Fix | Delete
if (p != NULL) { \
[28] Fix | Delete
(pt).family = (na)->family; \
[29] Fix | Delete
(pt).bitlen = (bits); \
[30] Fix | Delete
if ((pt).family == AF_INET6) { \
[31] Fix | Delete
memmove(&(pt).add.sin6, &(na)->type.in6, \
[32] Fix | Delete
((bits)+7)/8); \
[33] Fix | Delete
} else \
[34] Fix | Delete
memmove(&(pt).add.sin, &(na)->type.in, \
[35] Fix | Delete
((bits)+7)/8); \
[36] Fix | Delete
} else { \
[37] Fix | Delete
(pt).family = AF_UNSPEC; \
[38] Fix | Delete
(pt).bitlen = 0; \
[39] Fix | Delete
} \
[40] Fix | Delete
(pt).ecs = is_ecs; \
[41] Fix | Delete
isc_refcount_init(&(pt).refcount, 0); \
[42] Fix | Delete
} while(0)
[43] Fix | Delete
[44] Fix | Delete
typedef struct isc_prefix {
[45] Fix | Delete
isc_mem_t *mctx;
[46] Fix | Delete
unsigned int family; /* AF_INET | AF_INET6, or AF_UNSPEC for "any" */
[47] Fix | Delete
unsigned int bitlen; /* 0 for "any" */
[48] Fix | Delete
bool ecs; /* true for an EDNS client subnet address */
[49] Fix | Delete
isc_refcount_t refcount;
[50] Fix | Delete
union {
[51] Fix | Delete
struct in_addr sin;
[52] Fix | Delete
struct in6_addr sin6;
[53] Fix | Delete
} add;
[54] Fix | Delete
} isc_prefix_t;
[55] Fix | Delete
[56] Fix | Delete
typedef void (*isc_radix_destroyfunc_t)(void *);
[57] Fix | Delete
typedef void (*isc_radix_processfunc_t)(isc_prefix_t *, void **);
[58] Fix | Delete
[59] Fix | Delete
#define isc_prefix_tochar(prefix) ((char *)&(prefix)->add.sin)
[60] Fix | Delete
#define isc_prefix_touchar(prefix) ((u_char *)&(prefix)->add.sin)
[61] Fix | Delete
[62] Fix | Delete
/*
[63] Fix | Delete
* We need "first match" when we search the radix tree to preserve
[64] Fix | Delete
* compatibility with the existing ACL implementation. Radix trees
[65] Fix | Delete
* naturally lend themselves to "best match". In order to get "first match"
[66] Fix | Delete
* behavior, we keep track of the order in which entries are added to the
[67] Fix | Delete
* tree--and when a search is made, we find all matching entries, and
[68] Fix | Delete
* return the one that was added first.
[69] Fix | Delete
*
[70] Fix | Delete
* An IPv4 prefix and an IPv6 prefix may share a radix tree node if they
[71] Fix | Delete
* have the same length and bit pattern (e.g., 127/8 and 7f::/8). Also,
[72] Fix | Delete
* a node that matches a client address may also match an EDNS client
[73] Fix | Delete
* subnet address. To disambiguate between these, node_num and data
[74] Fix | Delete
* are four-element arrays;
[75] Fix | Delete
*
[76] Fix | Delete
* - node_num[0] and data[0] are used for IPv4 client addresses
[77] Fix | Delete
* - node_num[1] and data[1] for IPv4 client subnet addresses
[78] Fix | Delete
* - node_num[2] and data[2] are used for IPv6 client addresses
[79] Fix | Delete
* - node_num[3] and data[3] for IPv6 client subnet addresses
[80] Fix | Delete
*
[81] Fix | Delete
* A prefix of 0/0 (aka "any" or "none"), is always stored as IPv4,
[82] Fix | Delete
* but matches IPv6 addresses too, as well as all client subnet
[83] Fix | Delete
* addresses.
[84] Fix | Delete
*/
[85] Fix | Delete
[86] Fix | Delete
#define RADIX_NOECS 0
[87] Fix | Delete
#define RADIX_ECS 2
[88] Fix | Delete
#define RADIX_V4 0
[89] Fix | Delete
#define RADIX_V6 1
[90] Fix | Delete
#define RADIX_V4_ECS 2
[91] Fix | Delete
#define RADIX_V6_ECS 3
[92] Fix | Delete
#define RADIX_FAMILIES 4
[93] Fix | Delete
[94] Fix | Delete
#define ISC_RADIX_FAMILY(p) \
[95] Fix | Delete
((((p)->family == AF_INET6) ? RADIX_V6 : RADIX_V4) + \
[96] Fix | Delete
((p)->ecs ? RADIX_ECS : RADIX_NOECS))
[97] Fix | Delete
[98] Fix | Delete
typedef struct isc_radix_node {
[99] Fix | Delete
isc_mem_t *mctx;
[100] Fix | Delete
uint32_t bit; /* bit length of the prefix */
[101] Fix | Delete
isc_prefix_t *prefix; /* who we are in radix tree */
[102] Fix | Delete
struct isc_radix_node *l, *r; /* left and right children */
[103] Fix | Delete
struct isc_radix_node *parent; /* may be used */
[104] Fix | Delete
void *data[RADIX_FAMILIES]; /* pointers to IPv4 and IPV6 data */
[105] Fix | Delete
int node_num[RADIX_FAMILIES]; /* which node this was in the tree,
[106] Fix | Delete
or -1 for glue nodes */
[107] Fix | Delete
} isc_radix_node_t;
[108] Fix | Delete
[109] Fix | Delete
#define RADIX_TREE_MAGIC ISC_MAGIC('R','d','x','T');
[110] Fix | Delete
#define RADIX_TREE_VALID(a) ISC_MAGIC_VALID(a, RADIX_TREE_MAGIC);
[111] Fix | Delete
[112] Fix | Delete
typedef struct isc_radix_tree {
[113] Fix | Delete
unsigned int magic;
[114] Fix | Delete
isc_mem_t *mctx;
[115] Fix | Delete
isc_radix_node_t *head;
[116] Fix | Delete
uint32_t maxbits; /* for IP, 32 bit addresses */
[117] Fix | Delete
int num_active_node; /* for debugging purposes */
[118] Fix | Delete
int num_added_node; /* total number of nodes */
[119] Fix | Delete
} isc_radix_tree_t;
[120] Fix | Delete
[121] Fix | Delete
isc_result_t
[122] Fix | Delete
isc_radix_search(isc_radix_tree_t *radix, isc_radix_node_t **target,
[123] Fix | Delete
isc_prefix_t *prefix);
[124] Fix | Delete
/*%<
[125] Fix | Delete
* Search 'radix' for the best match to 'prefix'.
[126] Fix | Delete
* Return the node found in '*target'.
[127] Fix | Delete
*
[128] Fix | Delete
* Requires:
[129] Fix | Delete
* \li 'radix' to be valid.
[130] Fix | Delete
* \li 'target' is not NULL and "*target" is NULL.
[131] Fix | Delete
* \li 'prefix' to be valid.
[132] Fix | Delete
*
[133] Fix | Delete
* Returns:
[134] Fix | Delete
* \li ISC_R_NOTFOUND
[135] Fix | Delete
* \li ISC_R_SUCCESS
[136] Fix | Delete
*/
[137] Fix | Delete
[138] Fix | Delete
isc_result_t
[139] Fix | Delete
isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target,
[140] Fix | Delete
isc_radix_node_t *source, isc_prefix_t *prefix);
[141] Fix | Delete
/*%<
[142] Fix | Delete
* Insert 'source' or 'prefix' into the radix tree 'radix'.
[143] Fix | Delete
* Return the node added in 'target'.
[144] Fix | Delete
*
[145] Fix | Delete
* Requires:
[146] Fix | Delete
* \li 'radix' to be valid.
[147] Fix | Delete
* \li 'target' is not NULL and "*target" is NULL.
[148] Fix | Delete
* \li 'prefix' to be valid or 'source' to be non NULL and contain
[149] Fix | Delete
* a valid prefix.
[150] Fix | Delete
*
[151] Fix | Delete
* Returns:
[152] Fix | Delete
* \li ISC_R_NOMEMORY
[153] Fix | Delete
* \li ISC_R_SUCCESS
[154] Fix | Delete
*/
[155] Fix | Delete
[156] Fix | Delete
void
[157] Fix | Delete
isc_radix_remove(isc_radix_tree_t *radix, isc_radix_node_t *node);
[158] Fix | Delete
/*%<
[159] Fix | Delete
* Remove the node 'node' from the radix tree 'radix'.
[160] Fix | Delete
*
[161] Fix | Delete
* Requires:
[162] Fix | Delete
* \li 'radix' to be valid.
[163] Fix | Delete
* \li 'node' to be valid.
[164] Fix | Delete
*/
[165] Fix | Delete
[166] Fix | Delete
isc_result_t
[167] Fix | Delete
isc_radix_create(isc_mem_t *mctx, isc_radix_tree_t **target, int maxbits);
[168] Fix | Delete
/*%<
[169] Fix | Delete
* Create a radix tree with a maximum depth of 'maxbits';
[170] Fix | Delete
*
[171] Fix | Delete
* Requires:
[172] Fix | Delete
* \li 'mctx' to be valid.
[173] Fix | Delete
* \li 'target' to be non NULL and '*target' to be NULL.
[174] Fix | Delete
* \li 'maxbits' to be less than or equal to RADIX_MAXBITS.
[175] Fix | Delete
*
[176] Fix | Delete
* Returns:
[177] Fix | Delete
* \li ISC_R_NOMEMORY
[178] Fix | Delete
* \li ISC_R_SUCCESS
[179] Fix | Delete
*/
[180] Fix | Delete
[181] Fix | Delete
void
[182] Fix | Delete
isc_radix_destroy(isc_radix_tree_t *radix, isc_radix_destroyfunc_t func);
[183] Fix | Delete
/*%<
[184] Fix | Delete
* Destroy a radix tree optionally calling 'func' to clean up node data.
[185] Fix | Delete
*
[186] Fix | Delete
* Requires:
[187] Fix | Delete
* \li 'radix' to be valid.
[188] Fix | Delete
*/
[189] Fix | Delete
[190] Fix | Delete
void
[191] Fix | Delete
isc_radix_process(isc_radix_tree_t *radix, isc_radix_processfunc_t func);
[192] Fix | Delete
/*%<
[193] Fix | Delete
* Walk a radix tree calling 'func' to process node data.
[194] Fix | Delete
*
[195] Fix | Delete
* Requires:
[196] Fix | Delete
* \li 'radix' to be valid.
[197] Fix | Delete
* \li 'func' to point to a function.
[198] Fix | Delete
*/
[199] Fix | Delete
[200] Fix | Delete
#define RADIX_MAXBITS 128
[201] Fix | Delete
#define RADIX_NBIT(x) (0x80 >> ((x) & 0x7f))
[202] Fix | Delete
#define RADIX_NBYTE(x) ((x) >> 3)
[203] Fix | Delete
[204] Fix | Delete
#define RADIX_WALK(Xhead, Xnode) \
[205] Fix | Delete
do { \
[206] Fix | Delete
isc_radix_node_t *Xstack[RADIX_MAXBITS+1]; \
[207] Fix | Delete
isc_radix_node_t **Xsp = Xstack; \
[208] Fix | Delete
isc_radix_node_t *Xrn = (Xhead); \
[209] Fix | Delete
while ((Xnode = Xrn)) { \
[210] Fix | Delete
if (Xnode->prefix)
[211] Fix | Delete
[212] Fix | Delete
#define RADIX_WALK_END \
[213] Fix | Delete
if (Xrn->l) { \
[214] Fix | Delete
if (Xrn->r) { \
[215] Fix | Delete
*Xsp++ = Xrn->r; \
[216] Fix | Delete
} \
[217] Fix | Delete
Xrn = Xrn->l; \
[218] Fix | Delete
} else if (Xrn->r) { \
[219] Fix | Delete
Xrn = Xrn->r; \
[220] Fix | Delete
} else if (Xsp != Xstack) { \
[221] Fix | Delete
Xrn = *(--Xsp); \
[222] Fix | Delete
} else { \
[223] Fix | Delete
Xrn = (isc_radix_node_t *) 0; \
[224] Fix | Delete
} \
[225] Fix | Delete
} \
[226] Fix | Delete
} while (0)
[227] Fix | Delete
[228] Fix | Delete
#endif /* _RADIX_H */
[229] Fix | Delete
[230] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function