2021-08-17 11:44:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007-2019 Alexandre Snarskii <snar@snar.spb.ru>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
2007-03-22 18:12:32 +00:00
|
|
|
|
2015-07-10 20:57:30 +03:00
|
|
|
#include <sys/queue.h>
|
2021-08-18 01:58:47 +00:00
|
|
|
#include <sys/tree.h>
|
2015-07-10 20:57:30 +03:00
|
|
|
|
2007-03-22 18:12:32 +00:00
|
|
|
#include "sx_prefix.h"
|
2021-08-18 01:58:47 +00:00
|
|
|
|
2021-08-19 20:21:25 +00:00
|
|
|
struct slentry {
|
2021-08-20 00:50:56 +00:00
|
|
|
STAILQ_ENTRY(slentry) entry;
|
2021-08-19 20:21:25 +00:00
|
|
|
char *text;
|
2021-08-18 01:58:47 +00:00
|
|
|
};
|
|
|
|
|
2021-08-19 20:21:25 +00:00
|
|
|
struct slentry *sx_slentry_new(char *text);
|
2021-08-18 01:58:47 +00:00
|
|
|
|
|
|
|
struct sx_tentry {
|
2021-08-20 00:50:56 +00:00
|
|
|
RB_ENTRY(sx_tentry) entry;
|
2021-08-19 20:21:25 +00:00
|
|
|
char *text;
|
2021-08-18 01:58:47 +00:00
|
|
|
};
|
|
|
|
|
2021-08-19 20:21:25 +00:00
|
|
|
struct sx_tentry *sx_tentry_new(char *text);
|
2007-03-22 18:12:32 +00:00
|
|
|
|
2021-08-20 00:50:56 +00:00
|
|
|
struct asn_entry {
|
|
|
|
RB_ENTRY(asn_entry) entry;
|
|
|
|
uint32_t asn;
|
|
|
|
};
|
|
|
|
|
2015-07-10 20:57:30 +03:00
|
|
|
typedef enum {
|
2007-03-22 18:12:32 +00:00
|
|
|
V_CISCO = 0,
|
2011-07-15 11:48:34 +00:00
|
|
|
V_JUNIPER,
|
2013-01-08 12:21:14 +00:00
|
|
|
V_CISCO_XR,
|
2014-06-04 18:10:59 +02:00
|
|
|
V_JSON,
|
2015-07-01 20:03:41 +03:00
|
|
|
V_BIRD,
|
2016-10-14 18:54:12 +03:00
|
|
|
V_OPENBGPD,
|
2017-03-01 10:02:04 +02:00
|
|
|
V_FORMAT,
|
2018-08-10 15:02:08 +03:00
|
|
|
V_NOKIA,
|
2018-11-11 19:50:44 +03:00
|
|
|
V_HUAWEI,
|
2019-12-14 14:48:01 +01:00
|
|
|
V_MIKROTIK,
|
2020-12-23 10:07:23 -05:00
|
|
|
V_NOKIA_MD,
|
|
|
|
V_ARISTA
|
2007-03-22 18:12:32 +00:00
|
|
|
} bgpq_vendor_t;
|
|
|
|
|
2015-07-10 20:57:30 +03:00
|
|
|
typedef enum {
|
2007-03-22 18:12:32 +00:00
|
|
|
T_NONE = 0,
|
|
|
|
T_ASPATH,
|
|
|
|
T_OASPATH,
|
2018-10-03 19:16:34 +03:00
|
|
|
T_ASSET,
|
2008-06-02 11:32:25 +00:00
|
|
|
T_PREFIXLIST,
|
2017-09-08 19:40:25 +03:00
|
|
|
T_EACL,
|
|
|
|
T_ROUTE_FILTER_LIST
|
2007-03-22 18:12:32 +00:00
|
|
|
} bgpq_gen_t;
|
|
|
|
|
2015-07-12 17:31:09 +03:00
|
|
|
struct bgpq_expander;
|
|
|
|
|
2021-08-19 20:21:25 +00:00
|
|
|
struct request {
|
|
|
|
STAILQ_ENTRY(request) next;
|
|
|
|
char *request;
|
|
|
|
int size, offset;
|
|
|
|
void *udata;
|
|
|
|
unsigned int depth;
|
|
|
|
int (*callback)(char *, struct bgpq_expander *,
|
|
|
|
struct request *);
|
2008-05-19 13:33:32 +00:00
|
|
|
};
|
|
|
|
|
2015-07-10 20:57:30 +03:00
|
|
|
struct bgpq_expander {
|
2021-08-19 20:21:25 +00:00
|
|
|
struct sx_radix_tree *tree;
|
|
|
|
int family;
|
|
|
|
char *sources;
|
|
|
|
uint32_t asnumber;
|
|
|
|
int aswidth;
|
|
|
|
char *name;
|
|
|
|
bgpq_vendor_t vendor;
|
|
|
|
bgpq_gen_t generation;
|
|
|
|
int identify;
|
|
|
|
int sequence;
|
|
|
|
unsigned int maxdepth;
|
|
|
|
unsigned int cdepth;
|
|
|
|
int validate_asns;
|
|
|
|
struct bgpq_prequest *firstpipe, *lastpipe;
|
|
|
|
int piped;
|
|
|
|
char *match;
|
|
|
|
char *server;
|
|
|
|
char *port;
|
|
|
|
char *format;
|
|
|
|
unsigned int maxlen;
|
|
|
|
int fd;
|
2021-08-20 00:50:56 +00:00
|
|
|
RB_HEAD(asn_tree, asn_entry) asnlist;
|
2021-08-19 20:21:25 +00:00
|
|
|
STAILQ_HEAD(requests, request) wq, rq;
|
|
|
|
STAILQ_HEAD(slentries, slentry) macroses, rsets;
|
|
|
|
RB_HEAD(tentree, sx_tentry) already, stoplist;
|
2007-03-22 18:12:32 +00:00
|
|
|
};
|
|
|
|
|
2021-08-20 00:50:56 +00:00
|
|
|
int asn_cmp(struct asn_entry *, struct asn_entry *);
|
|
|
|
RB_PROTOTYPE(asn_tree, asn_entry, entry, asn_cmp);
|
|
|
|
|
2021-08-17 23:51:18 +00:00
|
|
|
int bgpq_expander_init(struct bgpq_expander *b, int af);
|
|
|
|
int bgpq_expander_add_asset(struct bgpq_expander *b, char *set);
|
|
|
|
int bgpq_expander_add_rset(struct bgpq_expander *b, char *set);
|
|
|
|
int bgpq_expander_add_as(struct bgpq_expander *b, char *as);
|
|
|
|
int bgpq_expander_add_prefix(struct bgpq_expander *b, char *prefix);
|
|
|
|
int bgpq_expander_add_prefix_range(struct bgpq_expander *b, char *prefix);
|
|
|
|
int bgpq_expander_add_stop(struct bgpq_expander *b, char *object);
|
2007-03-22 18:12:32 +00:00
|
|
|
|
2021-08-17 23:51:18 +00:00
|
|
|
int bgpq_expand(struct bgpq_expander *b);
|
2007-03-23 12:47:28 +00:00
|
|
|
|
2021-08-20 00:50:56 +00:00
|
|
|
void bgpq4_print_prefixlist(FILE *f, struct bgpq_expander *b);
|
|
|
|
void bgpq4_print_eacl(FILE *f, struct bgpq_expander *b);
|
|
|
|
void bgpq4_print_aspath(FILE *f, struct bgpq_expander *b);
|
|
|
|
void bgpq4_print_asset(FILE *f, struct bgpq_expander *b);
|
|
|
|
void bgpq4_print_oaspath(FILE *f, struct bgpq_expander *b);
|
|
|
|
void bgpq4_print_route_filter_list(FILE *f, struct bgpq_expander *b);
|
2007-03-23 12:47:28 +00:00
|
|
|
|
2021-08-17 11:44:14 +00:00
|
|
|
void sx_radix_node_freeall(struct sx_radix_node *n);
|
|
|
|
void sx_radix_tree_freeall(struct sx_radix_tree *t);
|
|
|
|
void bgpq_prequest_freeall(struct bgpq_prequest *bpr);
|
|
|
|
void expander_freeall(struct bgpq_expander *expander);
|
|
|
|
|
|
|
|
/* s - number of opened socket, dir is either SO_SNDBUF or SO_RCVBUF */
|
|
|
|
int sx_maxsockbuf(int s, int dir);
|
|
|
|
|
2008-05-20 15:31:56 +00:00
|
|
|
#ifndef HAVE_STRLCPY
|
2021-08-19 20:21:25 +00:00
|
|
|
size_t strlcpy(char *dst, const char *src, size_t size);
|
2008-05-20 15:31:56 +00:00
|
|
|
#endif
|