1 /* Copyright © 2012 Brandon L Black <blblack@gmail.com> 2 * 3 * This file is part of gdnsd. 4 * 5 * gdnsd-plugin-geoip is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * gdnsd-plugin-geoip is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with gdnsd. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 #ifndef NLIST_H 21 #define NLIST_H 22 23 #include "ntree.h" 24 25 #include <gdnsd/compiler.h> 26 27 #include <inttypes.h> 28 #include <stdbool.h> 29 30 typedef struct _nlist nlist_t; 31 32 // pre_norm flag indicates that the data to be added via _append() 33 // will already be in fully normalized form and order other than 34 // the possibility of dclist-based merges of adjacent subnets. 35 // This allows for significant optimizations in GeoIP input case, 36 // as GeoIP's data structure implies these gaurantees when walked 37 // in order for _append(). 38 F_NONNULL F_WUNUSED 39 nlist_t* nlist_new(const char* map_name, const bool pre_norm); 40 41 F_NONNULL 42 void nlist_destroy(nlist_t* nl); 43 44 F_NONNULL 45 void nlist_append(nlist_t* nl, const uint8_t* ipv6, const unsigned mask, const unsigned dclist); 46 47 // Call this when all nlist_append() are complete. For lists 48 // which are not "pre_norm", this does a bunch of normalization 49 // transformations on the data first (which can fail, hence 50 // the bool retval). "pre_norm" lists get their normalization 51 // state assert()'d expensively in debug builds. 52 // Regardless, storage is also realloc'd down to exact size. 53 F_NONNULL 54 void nlist_finish(nlist_t* nl); 55 56 // must pass through _finish() before *any* of the xlate/merge funcs below 57 F_NONNULL 58 ntree_t* nlist_xlate_tree(const nlist_t* nl_a); 59 F_NONNULL 60 ntree_t* nlist_merge2_tree(const nlist_t* nl_a, const nlist_t* nl_b); 61 F_NONNULL 62 ntree_t* nlist_merge3_tree(const nlist_t* nl_a, const nlist_t* nl_b, const nlist_t* nl_c); 63 64 // Just for debugging... 65 F_NONNULL 66 void nlist_debug_dump(const nlist_t* nl); 67 68 #endif // NLIST_H 69