1
0
mirror of https://github.com/bgp/bgpq4.git synced 2024-05-11 05:55:05 +00:00
Files
bgp-bgpq4/extern.h

147 lines
4.2 KiB
C
Raw Normal View History

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 {
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 {
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
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,
V_JSON,
V_BIRD,
2016-10-14 18:54:12 +03:00
V_OPENBGPD,
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,
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,
T_ASSET,
2008-06-02 11:32:25 +00:00
T_PREFIXLIST,
T_EACL,
T_ROUTE_FILTER_LIST
2007-03-22 18:12:32 +00:00
} bgpq_gen_t;
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;
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
};
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);
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);
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);
#ifndef HAVE_STRLCPY
2021-08-19 20:21:25 +00:00
size_t strlcpy(char *dst, const char *src, size_t size);
#endif