mirror of
https://github.com/bgp/bgpq4
synced 2025-02-28 08:53:11 +00:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f8d82db21 | ||
|
|
a6792d2495 | ||
|
|
af202a821b | ||
|
|
ed8ee8368d | ||
|
|
bf5f10def9 | ||
|
|
1f7572c2f1 | ||
|
|
34cc813446 | ||
|
|
5c57bb2bb6 | ||
|
|
e6bf77058a | ||
|
|
139e0d972b | ||
|
|
99f036b186 | ||
|
|
cb98214f0c | ||
|
|
ed28cf6734 | ||
|
|
9ac2087d24 | ||
|
|
58adb550bd | ||
|
|
773849fc3a | ||
|
|
40656fbbbf | ||
|
|
4a8dc682fd | ||
|
|
450286a010 | ||
|
|
a055f6f2ee | ||
|
|
c4c5866fa3 | ||
|
|
6074f816e0 |
3
CHANGES
3
CHANGES
@@ -1,3 +1,6 @@
|
||||
0.0.9 (2021-08-18)
|
||||
- Fix various memory errors
|
||||
|
||||
0.0.8 (2021-08-17)
|
||||
- Reorganize automake files and includes
|
||||
- Normalize code to adhere to KNF
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*-
|
||||
* Copyright (c) 2007-2019 Alexandre Snarskii <snar@snar.spb.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -22,26 +22,5 @@
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SX_SLENTRY_H_
|
||||
#define SX_SLENTRY_H_
|
||||
|
||||
#include <sys/queue.h>
|
||||
#include <sys/tree.h>
|
||||
|
||||
struct sx_slentry {
|
||||
STAILQ_ENTRY(sx_slentry) next;
|
||||
char* text;
|
||||
};
|
||||
|
||||
struct sx_slentry* sx_slentry_new(char* text);
|
||||
|
||||
struct sx_tentry {
|
||||
RB_ENTRY(sx_tentry) entry;
|
||||
char* text;
|
||||
};
|
||||
|
||||
struct sx_tentry* sx_tentry_new(char* text);
|
||||
|
||||
#endif
|
||||
17
Makefile.am
17
Makefile.am
@@ -1,4 +1,4 @@
|
||||
SUBDIRS = include compat
|
||||
SUBDIRS = include
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include
|
||||
@@ -10,15 +10,20 @@ bin_PROGRAMS=bgpq4
|
||||
dist_man8_MANS=bgpq4.8
|
||||
|
||||
bgpq4_LDADD = $(PLATFORM_LDADD) $(PROG_LDADD)
|
||||
|
||||
if !HAVE_STRLCPY
|
||||
SUBDIRS += compat
|
||||
bgpq4_LDADD += $(top_builddir)/compat/libcompat.la
|
||||
endif
|
||||
|
||||
bgpq4_SOURCES=bgpq4.c extern.h bgpq4_printer.c bgpq_expander.c \
|
||||
expander_freeall.c sx_maxsockbuf.c \
|
||||
sx_prefix.c sx_prefix.h sx_report.c sx_report.h \
|
||||
sx_slentry.c sx_slentry.h
|
||||
bgpq4_SOURCES=main.c extern.h printer.c expander.c \
|
||||
sx_maxsockbuf.c \
|
||||
sx_prefix.c sx_prefix.h \
|
||||
sx_report.c sx_report.h \
|
||||
sx_slentry.c
|
||||
|
||||
|
||||
EXTRA_DIST=bootstrap README.md CHANGES bgpq4.spec
|
||||
EXTRA_DIST=bootstrap README.md CHANGES
|
||||
|
||||
MAINTAINERCLEANFILES=configure aclocal.m4 compile \
|
||||
install-sh missing Makefile.in depcomp \
|
||||
|
||||
14
README.md
14
README.md
@@ -3,6 +3,9 @@ NAME
|
||||
|
||||
`bgpq4` - bgp filtering automation tool
|
||||
|
||||
The `bgpq4` utility queries IRRd and then generates IRR and/or RPKI based
|
||||
filters formatted for a wide assortment of BGP implementations.
|
||||
|
||||
SYNOPSIS
|
||||
--------
|
||||
|
||||
@@ -329,11 +332,6 @@ Linux can be tuned in the following way:
|
||||
sysctl -w net.ipv4.tcp_rmem="4096 87380 2097152"
|
||||
sysctl -w net.ipv4.tcp_wmem="4096 65536 2097152"
|
||||
|
||||
Please note that generated prefix-lists may not fit your router's
|
||||
limitations. For example, JunOS supports only 85,325 prefixes in
|
||||
each prefix-list [4](http://www.juniper.net/techpubs/en_US/junos11.4/topics/reference/configuration-statement/prefix-list-edit-policy-options.html).
|
||||
|
||||
|
||||
BUILDING
|
||||
--------
|
||||
|
||||
@@ -378,6 +376,12 @@ On Arch Linux, BGPQ4 is [available in AUR](https://aur.archlinux.org/packages/bg
|
||||
yay -S bgpq4
|
||||
```
|
||||
|
||||
On OpenBSD:
|
||||
|
||||
```shell
|
||||
pkg_add bgpq4
|
||||
```
|
||||
|
||||
MAILING LIST
|
||||
------------
|
||||
|
||||
|
||||
88
bgpq4.spec
88
bgpq4.spec
@@ -1,88 +0,0 @@
|
||||
Name: bgpq4
|
||||
Version: 0.0.6
|
||||
Release: 0%{?dist}
|
||||
|
||||
Group: System/Utilities
|
||||
Summary: Generate BGP filters based on routing database information
|
||||
URL: https://github.com/bgp/bgpq4
|
||||
License: BSD
|
||||
Source0: https://github.com/bgp/bgpq4
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
||||
|
||||
%description
|
||||
You are running BGP in your network and want to automate filter generation for your routers? Well, with BGPQ4 it's easy.
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
%global debug_package %{nil}
|
||||
|
||||
%build
|
||||
./configure --prefix=$RPM_BUILD_ROOT%{_prefix} --mandir=%{_mandir}
|
||||
make
|
||||
|
||||
%install
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
mkdir -p $RPM_BUILD_ROOT/usr/bin
|
||||
make install
|
||||
|
||||
%files
|
||||
%defattr(-,root,root,-)
|
||||
/usr/bin/bgpq4
|
||||
/usr/man/man8/bgpq4.8.gz
|
||||
%doc COPYRIGHT CHANGES
|
||||
|
||||
%clean
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
%changelog
|
||||
* Thu Mar 12 2020 Job Snijders <job@ntt.net> 0.0.6:
|
||||
- bugfixes (Thanks Chris Caputo!)
|
||||
|
||||
* Wed Jan 01 2020 Job Snijders <job@ntt.net> 0.0.5:
|
||||
- bugfixes
|
||||
|
||||
* Tue Dec 31 2019 Job Snijders <job@ntt.net> 0.0.4
|
||||
- Remove '-3' command line option, assume all devices are 32-bit ASN safe
|
||||
|
||||
* Mon Dec 30 2019 Job Snijders <job@ntt.net> 0.0.3
|
||||
- Remove the '-2' command line option
|
||||
- Significant code reformating
|
||||
- Improve performance by using IRRd 4's A query when available
|
||||
|
||||
* Sat Dec 14 2019 Job Snijders <job@ntt.net> 0.0.2
|
||||
- Add Mikrotik support
|
||||
- Remove ASDDOT support
|
||||
|
||||
* Sat Dec 14 2019 Job Snijders <job@ntt.net> 0.0.1
|
||||
- Fork from bgpq3
|
||||
|
||||
* Tue Nov 30 2018 Alexandre Snarskii <snar@snar.spb.ru> 0.1.35
|
||||
- Version updated
|
||||
|
||||
* Fri Oct 14 2016 Alexandre Snarskii <snar@snar.spb.ru> 0.1.33
|
||||
- Version updated
|
||||
|
||||
* Tue Jun 23 Alexandre Snarskii <snar@snar.spb.ru> 0.1.31
|
||||
- Version updated
|
||||
|
||||
* Tue Mar 10 Alexandre Snarskii <snar@snar.spb.ru> 0.1.28
|
||||
- Version updated
|
||||
|
||||
* Wed Oct 29 Alexandre Snarskii <snar@snar.spb.ru> 0.1.25
|
||||
- Version updated
|
||||
|
||||
* Thu Jun 5 2014 Alexandre Snarskii <snar@snar.spb.ru> 0.1.21-0.snar
|
||||
- Version updated
|
||||
|
||||
* Thu May 9 2013 Alexandre Snarskii <snar@snar.spb.ru> 0.1.19-0.snar
|
||||
- Version updated
|
||||
|
||||
* Sun Feb 24 2013 Alexandre Snarskii <snar@snar.spb.ru> 0.1.18-3.snar
|
||||
- License corrected
|
||||
|
||||
* Wed Feb 20 2013 Arnoud Vermeer <arnoud@tumblr.com> 0.1.18-2.tumblr
|
||||
- Adding missing group info (arnoud@tumblr.com)
|
||||
|
||||
* Wed Feb 20 2013 Arnoud Vermeer <arnoud@tumblr.com> 0.1.18-1.tumblr
|
||||
- new package built with tito
|
||||
@@ -2,9 +2,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/include
|
||||
|
||||
noinst_LTLIBRARIES = libcompat.la
|
||||
|
||||
libcompat_la_SOURCES =
|
||||
libcompat_la_LIBADD = $(PLATFORM_LDADD)
|
||||
|
||||
if !HAVE_STRLCPY
|
||||
libcompat_la_SOURCES += strlcpy.c
|
||||
endif
|
||||
libcompat_la_SOURCES = strlcpy.c
|
||||
|
||||
@@ -107,6 +107,7 @@ AC_CHECK_LIB(nsl,getaddrinfo)
|
||||
|
||||
AC_CHECK_HEADERS([sys/cdefs.h sys/queue.h sys/tree.h sys/select.h])
|
||||
|
||||
AM_CONDITIONAL([HAVE_PLEDGE], [test "x$ac_cv_func_pledge" = xyes])
|
||||
AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2021 Job Snijders <job@sobornost.net>
|
||||
* Copyright (c) 2018 Peter Schoenmaker <pds@ntt.net>
|
||||
* Copyright (c) 2007-2019 Alexandre Snarskii <snar@snar.spb.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -30,17 +31,18 @@
|
||||
#include <sys/select.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <netdb.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
@@ -56,7 +58,7 @@ tentry_cmp(struct sx_tentry *a, struct sx_tentry *b)
|
||||
return strcasecmp(a->text, b->text);
|
||||
}
|
||||
|
||||
RB_GENERATE_STATIC(tentree, sx_tentry, entry, tentry_cmp);
|
||||
RB_GENERATE_STATIC(tentree, sx_tentry, entries, tentry_cmp);
|
||||
|
||||
int
|
||||
bgpq_expander_init(struct bgpq_expander *b, int af)
|
||||
@@ -121,7 +123,7 @@ bgpq_expander_add_asset(struct bgpq_expander *b, char *as)
|
||||
|
||||
le = sx_slentry_new(as);
|
||||
|
||||
STAILQ_INSERT_TAIL(&b->macroses, le, next);
|
||||
STAILQ_INSERT_TAIL(&b->macroses, le, entries);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -139,7 +141,7 @@ bgpq_expander_add_rset(struct bgpq_expander *b, char *rs)
|
||||
if (!le)
|
||||
return 0;
|
||||
|
||||
STAILQ_INSERT_TAIL(&b->rsets, le, next);
|
||||
STAILQ_INSERT_TAIL(&b->rsets, le, entries);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -267,11 +269,12 @@ bgpq_expanded_macro(char *as, struct bgpq_expander *ex,
|
||||
}
|
||||
|
||||
struct bgpq_request *bgpq_pipeline(struct bgpq_expander *b,
|
||||
int (*callback)(char*, struct bgpq_expander *b, struct bgpq_request *req),
|
||||
void *udata, char *fmt, ...);
|
||||
int (*callback)(char *, struct bgpq_expander *b, struct bgpq_request *req),
|
||||
void *udata, char *fmt, ...);
|
||||
|
||||
int bgpq_expand_irrd(struct bgpq_expander *b,
|
||||
int (*callback)(char*, struct bgpq_expander *b, struct bgpq_request *req),
|
||||
void *udata, char *fmt, ...);
|
||||
void *udata, char *fmt, ...);
|
||||
|
||||
static int
|
||||
bgpq_expanded_macro_limit(char *as, struct bgpq_expander *b,
|
||||
@@ -281,13 +284,13 @@ bgpq_expanded_macro_limit(char *as, struct bgpq_expander *b,
|
||||
struct sx_tentry tkey = { .text = as };
|
||||
|
||||
if (RB_FIND(tentree, &b->already, &tkey)) {
|
||||
SX_DEBUG(debug_expander>2, "%s is already expanding, "
|
||||
SX_DEBUG(debug_expander > 2, "%s is already expanding, "
|
||||
"ignore\n", as);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (RB_FIND(tentree, &b->stoplist, &tkey)) {
|
||||
SX_DEBUG(debug_expander>2, "%s is in the stoplist, "
|
||||
SX_DEBUG(debug_expander > 2, "%s is in the stoplist, "
|
||||
"ignore\n", as);
|
||||
return 0;
|
||||
}
|
||||
@@ -299,8 +302,8 @@ bgpq_expanded_macro_limit(char *as, struct bgpq_expander *b,
|
||||
if (pipelining) {
|
||||
struct bgpq_request *req1 = bgpq_pipeline(b,
|
||||
bgpq_expanded_macro_limit, NULL, "!i%s\n",
|
||||
as);
|
||||
req1->depth = req->depth+1;
|
||||
as);
|
||||
req1->depth = req->depth + 1;
|
||||
} else {
|
||||
b->cdepth++;
|
||||
bgpq_expand_irrd(b, bgpq_expanded_macro_limit,
|
||||
@@ -308,7 +311,7 @@ bgpq_expanded_macro_limit(char *as, struct bgpq_expander *b,
|
||||
b->cdepth--;
|
||||
}
|
||||
} else {
|
||||
SX_DEBUG(debug_expander>2, "ignoring %s at depth %i\n",
|
||||
SX_DEBUG(debug_expander > 2, "ignoring %s at depth %i\n",
|
||||
as,
|
||||
b->cdepth ? (b->cdepth + 1) : (req->depth + 1));
|
||||
}
|
||||
@@ -353,8 +356,8 @@ bgpq_expanded_prefix(char *as, struct bgpq_expander *ex,
|
||||
}
|
||||
|
||||
static int
|
||||
bgpq_expanded_v6prefix(char *prefix, struct bgpq_expander * ex,
|
||||
struct bgpq_request* req)
|
||||
bgpq_expanded_v6prefix(char *prefix, struct bgpq_expander *ex,
|
||||
struct bgpq_request *req)
|
||||
{
|
||||
char *d = strchr(prefix, '^');
|
||||
|
||||
@@ -368,11 +371,11 @@ bgpq_expanded_v6prefix(char *prefix, struct bgpq_expander * ex,
|
||||
|
||||
int bgpq_pipeline_dequeue(int fd, struct bgpq_expander *b);
|
||||
|
||||
static struct bgpq_request*
|
||||
bgpq_request_alloc(char *request, int (*callback)(char*, struct bgpq_expander*,
|
||||
struct bgpq_request*), void* udata)
|
||||
static struct bgpq_request *
|
||||
bgpq_request_alloc(char *request, int (*callback)(char *, struct bgpq_expander *,
|
||||
struct bgpq_request *), void *udata)
|
||||
{
|
||||
struct bgpq_request* bp = malloc(sizeof(struct bgpq_request));
|
||||
struct bgpq_request *bp = malloc(sizeof(struct bgpq_request));
|
||||
|
||||
if (!bp)
|
||||
return NULL;
|
||||
@@ -388,7 +391,7 @@ bgpq_request_alloc(char *request, int (*callback)(char*, struct bgpq_expander*,
|
||||
}
|
||||
|
||||
static void
|
||||
bgpq_request_free(struct bgpq_request* req)
|
||||
bgpq_request_free(struct bgpq_request *req)
|
||||
{
|
||||
if (req->request)
|
||||
free(req->request);
|
||||
@@ -396,15 +399,15 @@ bgpq_request_free(struct bgpq_request* req)
|
||||
free(req);
|
||||
}
|
||||
|
||||
struct bgpq_request*
|
||||
struct bgpq_request *
|
||||
bgpq_pipeline(struct bgpq_expander *b,
|
||||
int (*callback)(char*, struct bgpq_expander*, struct bgpq_request*),
|
||||
void* udata, char *fmt, ...)
|
||||
int (*callback)(char *, struct bgpq_expander *, struct bgpq_request *),
|
||||
void *udata, char *fmt, ...)
|
||||
{
|
||||
char request[128];
|
||||
int ret;
|
||||
struct bgpq_request* bp = NULL;
|
||||
va_list ap;
|
||||
char request[128];
|
||||
int ret;
|
||||
struct bgpq_request *bp = NULL;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(request, sizeof(request), fmt, ap);
|
||||
@@ -471,9 +474,9 @@ static void
|
||||
bgpq_write(struct bgpq_expander *b)
|
||||
{
|
||||
while(!STAILQ_EMPTY(&b->wq)) {
|
||||
struct bgpq_request* req = STAILQ_FIRST(&b->wq);
|
||||
struct bgpq_request *req = STAILQ_FIRST(&b->wq);
|
||||
|
||||
int ret = write(b->fd, req->request+req->offset,
|
||||
int ret = write(b->fd, req->request + req->offset,
|
||||
req->size-req->offset);
|
||||
|
||||
if (ret < 0) {
|
||||
@@ -537,11 +540,12 @@ bgpq_read(struct bgpq_expander *b)
|
||||
bgpq_write(b);
|
||||
|
||||
while(!STAILQ_EMPTY(&b->rq)) {
|
||||
struct bgpq_request* req = STAILQ_FIRST(&b->rq);
|
||||
int ret = 0;
|
||||
char *cres;
|
||||
struct bgpq_request *req = STAILQ_FIRST(&b->rq);
|
||||
|
||||
SX_DEBUG(debug_expander > 2, "waiting for answer to %s,"
|
||||
"init %i '%.*s'\n", req->request, off, off, response);
|
||||
int ret = 0;
|
||||
char *cres;
|
||||
|
||||
if ((cres=strchr(response, '\n')) != NULL)
|
||||
goto have;
|
||||
@@ -629,7 +633,7 @@ reread:
|
||||
recvbuffer + offset);
|
||||
offset += ret;
|
||||
if (offset < togot) {
|
||||
SX_DEBUG(debug_expander>5, "expected %lu, got "
|
||||
SX_DEBUG(debug_expander > 5, "expected %lu, got "
|
||||
"%lu expanding %s", togot,
|
||||
strlen(recvbuffer), req->request);
|
||||
goto reread;
|
||||
@@ -716,12 +720,12 @@ have3:
|
||||
|
||||
int
|
||||
bgpq_expand_irrd(struct bgpq_expander *b,
|
||||
int (*callback)(char*, struct bgpq_expander*, struct bgpq_request* ),
|
||||
void* udata, char *fmt, ...)
|
||||
int (*callback)(char *, struct bgpq_expander *, struct bgpq_request *),
|
||||
void *udata, char *fmt, ...)
|
||||
{
|
||||
char request[128], response[128];
|
||||
va_list ap;
|
||||
size_t ret;
|
||||
ssize_t ret;
|
||||
int off = 0;
|
||||
struct bgpq_request *req;
|
||||
|
||||
@@ -731,14 +735,11 @@ bgpq_expand_irrd(struct bgpq_expander *b,
|
||||
|
||||
req = bgpq_request_alloc(request, callback, udata);
|
||||
|
||||
SX_DEBUG(debug_expander, "expander: sending '%s'\n", request);
|
||||
SX_DEBUG(debug_expander, "expander sending: %s", request);
|
||||
|
||||
if ((ret = write(b->fd, request, strlen(request)) == 0) || ret == -1)
|
||||
err(1, "write");
|
||||
|
||||
ret=write(b->fd, request, strlen(request));
|
||||
if (ret != strlen(request)) {
|
||||
sx_report(SX_FATAL,"Partial write to IRRd, only %lu bytes "
|
||||
"written: %s\n", ret, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
memset(response, 0, sizeof(response));
|
||||
|
||||
repeat:
|
||||
@@ -825,7 +826,7 @@ have3:
|
||||
if (!strchr(response, '\n'))
|
||||
goto reread2;
|
||||
|
||||
SX_DEBUG(debug_expander>2,"expander: final reply of %lu bytes,"
|
||||
SX_DEBUG(debug_expander > 2,"expander: final reply of %lu bytes,"
|
||||
" %.*sreturn code %.*s",
|
||||
(unsigned long)strlen(recvbuffer), offset, recvbuffer, off,
|
||||
response);
|
||||
@@ -932,7 +933,7 @@ bgpq_expand(struct bgpq_expander *b)
|
||||
b->fd = fd;
|
||||
|
||||
SX_DEBUG(debug_expander, "Sending '!!' to server to request for the"
|
||||
"connection to remain open\n");
|
||||
" connection to remain open\n");
|
||||
if ((ret = write(fd, "!!\n", 3)) != 3) {
|
||||
sx_report(SX_ERROR, "Partial write of multiple command mode "
|
||||
"to IRRd: %i bytes, %s\n", ret, strerror(errno));
|
||||
@@ -1022,7 +1023,7 @@ bgpq_expand(struct bgpq_expander *b)
|
||||
if (pipelining)
|
||||
fcntl(fd, F_SETFL, O_NONBLOCK|(fcntl(fd, F_GETFL)));
|
||||
|
||||
STAILQ_FOREACH(mc, &b->macroses, next) {
|
||||
STAILQ_FOREACH(mc, &b->macroses, entries) {
|
||||
if (!b->maxdepth && RB_EMPTY(&b->stoplist)) {
|
||||
if (aquery)
|
||||
bgpq_expand_irrd(b, bgpq_expanded_prefix, b,
|
||||
@@ -1052,7 +1053,7 @@ bgpq_expand(struct bgpq_expander *b)
|
||||
|
||||
if (b->generation >= T_PREFIXLIST || b->validate_asns) {
|
||||
uint32_t i, j, k;
|
||||
STAILQ_FOREACH(mc, &b->rsets, next) {
|
||||
STAILQ_FOREACH(mc, &b->rsets, entries) {
|
||||
if (b->family == AF_INET)
|
||||
bgpq_expand_irrd(b, bgpq_expanded_prefix,
|
||||
NULL, "!i%s,1\n", mc->text);
|
||||
@@ -1060,7 +1061,7 @@ bgpq_expand(struct bgpq_expander *b)
|
||||
bgpq_expand_irrd(b, bgpq_expanded_v6prefix,
|
||||
NULL, "!i%s,1\n", mc->text);
|
||||
}
|
||||
for (k=0; k < sizeof(b->asn32s) / sizeof(unsigned char*); k++) {
|
||||
for (k=0; k < sizeof(b->asn32s) / sizeof(unsigned char *); k++) {
|
||||
if (!b->asn32s[k])
|
||||
continue;
|
||||
for (i=0; i<8192; i++) {
|
||||
@@ -1110,3 +1111,79 @@ bgpq_expand(struct bgpq_expander *b)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
sx_radix_node_freeall(struct sx_radix_node *n) {
|
||||
|
||||
if (n->l != NULL)
|
||||
sx_radix_node_freeall(n->l);
|
||||
|
||||
if (n->r != NULL)
|
||||
sx_radix_node_freeall(n->r);
|
||||
|
||||
if (n->son != NULL)
|
||||
sx_radix_node_freeall(n->son);
|
||||
|
||||
if (n->payload)
|
||||
free(n->payload);
|
||||
|
||||
sx_prefix_destroy(n->prefix);
|
||||
|
||||
free(n);
|
||||
}
|
||||
|
||||
void
|
||||
sx_radix_tree_freeall(struct sx_radix_tree *t) {
|
||||
|
||||
if (t->head != NULL)
|
||||
sx_radix_node_freeall(t->head);
|
||||
|
||||
free(t);
|
||||
}
|
||||
|
||||
void
|
||||
bgpq_prequest_freeall(struct bgpq_prequest *bpr) {
|
||||
}
|
||||
|
||||
void
|
||||
expander_freeall(struct bgpq_expander *expander) {
|
||||
struct sx_tentry *var, *nxt;
|
||||
|
||||
while (!STAILQ_EMPTY(&expander->macroses)) {
|
||||
struct sx_slentry *n1 = STAILQ_FIRST(&expander->macroses);
|
||||
STAILQ_REMOVE_HEAD(&expander->macroses, entries);
|
||||
free(n1->text);
|
||||
free(n1);
|
||||
}
|
||||
|
||||
while (!STAILQ_EMPTY(&expander->rsets)) {
|
||||
struct sx_slentry *n1 = STAILQ_FIRST(&expander->rsets);
|
||||
STAILQ_REMOVE_HEAD(&expander->rsets, entries);
|
||||
free(n1->text);
|
||||
free(n1);
|
||||
}
|
||||
|
||||
for (var = RB_MIN(tentree, &expander->already); var != NULL; var = nxt) {
|
||||
nxt = RB_NEXT(tentree, &expander->already, var);
|
||||
RB_REMOVE(tentree, &expander->already, var);
|
||||
free(var->text);
|
||||
free(var);
|
||||
}
|
||||
|
||||
for (var = RB_MIN(tentree, &expander->stoplist); var != NULL; var = nxt) {
|
||||
nxt = RB_NEXT(tentree, &expander->stoplist, var);
|
||||
RB_REMOVE(tentree, &expander->stoplist, var);
|
||||
free(var->text);
|
||||
free(var);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 65536; i++) {
|
||||
if (expander->asn32s[i] != NULL) {
|
||||
free(expander->asn32s[i]);
|
||||
}
|
||||
}
|
||||
|
||||
sx_radix_tree_freeall(expander->tree);
|
||||
|
||||
bgpq_prequest_freeall(expander->firstpipe);
|
||||
bgpq_prequest_freeall(expander->lastpipe);
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2020 Job Snijders <job@sobornost.net>
|
||||
* Copyright (c) 2018 Peter Schoenmaker <pds@ntt.net>
|
||||
* 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.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
void
|
||||
sx_radix_node_freeall(struct sx_radix_node *n) {
|
||||
|
||||
if (n->l != NULL)
|
||||
sx_radix_node_freeall(n->l);
|
||||
|
||||
if (n->r != NULL)
|
||||
sx_radix_node_freeall(n->r);
|
||||
|
||||
if (n->son != NULL)
|
||||
sx_radix_node_freeall(n->son);
|
||||
|
||||
if (n->payload)
|
||||
free(n->payload);
|
||||
|
||||
sx_prefix_destroy(n->prefix);
|
||||
|
||||
free(n);
|
||||
}
|
||||
|
||||
void
|
||||
sx_radix_tree_freeall(struct sx_radix_tree *t) {
|
||||
|
||||
if (t->head != NULL)
|
||||
sx_radix_node_freeall(t->head);
|
||||
|
||||
free(t);
|
||||
}
|
||||
|
||||
void
|
||||
bgpq_prequest_freeall(struct bgpq_prequest *bpr) {
|
||||
}
|
||||
|
||||
void
|
||||
expander_freeall(struct bgpq_expander *expander) {
|
||||
|
||||
// printf("starting to free all\n");
|
||||
// seg fault here
|
||||
// if (expander->sources != NULL) {
|
||||
// printf("freeing soruces\n");
|
||||
// free(expander->sources);
|
||||
//}
|
||||
// if (expander->name != NULL) {
|
||||
// printf("freeing name\n");
|
||||
// free(expander->name);
|
||||
//}
|
||||
// printf("freeing asn32s\n");
|
||||
|
||||
for (int i = 0; i < 65536; i++) {
|
||||
if (expander->asn32s[i] != NULL) {
|
||||
free(expander->asn32s[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// if (expander->match != NULL) {
|
||||
// printf("freeing match\n");
|
||||
// free(expander->match);
|
||||
//}
|
||||
//if (expander->server != NULL) {
|
||||
// printf("freeing server\n");
|
||||
// free(expander->server);
|
||||
//}
|
||||
//if (expander->port != NULL) {
|
||||
// printf("freeing port\n");
|
||||
// free(expander->port);
|
||||
//}
|
||||
//if (expander->format != NULL) {
|
||||
// printf("freeing format\n");
|
||||
// free(expander->format);
|
||||
//}
|
||||
|
||||
sx_radix_tree_freeall(expander->tree);
|
||||
|
||||
bgpq_prequest_freeall(expander->firstpipe);
|
||||
bgpq_prequest_freeall(expander->lastpipe);
|
||||
|
||||
// printf("finished freeing all\n");
|
||||
}
|
||||
47
extern.h
47
extern.h
@@ -25,9 +25,23 @@
|
||||
*/
|
||||
|
||||
#include <sys/queue.h>
|
||||
#include <sys/tree.h>
|
||||
|
||||
#include "sx_prefix.h"
|
||||
#include "sx_slentry.h"
|
||||
|
||||
struct sx_slentry {
|
||||
STAILQ_ENTRY(sx_slentry) entries;
|
||||
char* text;
|
||||
};
|
||||
|
||||
struct sx_slentry* sx_slentry_new(char* text);
|
||||
|
||||
struct sx_tentry {
|
||||
RB_ENTRY(sx_tentry) entries;
|
||||
char* text;
|
||||
};
|
||||
|
||||
struct sx_tentry* sx_tentry_new(char* text);
|
||||
|
||||
typedef enum {
|
||||
V_CISCO = 0,
|
||||
@@ -60,9 +74,10 @@ struct bgpq_request {
|
||||
STAILQ_ENTRY(bgpq_request) next;
|
||||
char *request;
|
||||
int size, offset;
|
||||
int (*callback)(char*, struct bgpq_expander*, struct bgpq_request*);
|
||||
void *udata;
|
||||
unsigned int depth;
|
||||
int (*callback)(char *, struct bgpq_expander *,
|
||||
struct bgpq_request *);
|
||||
};
|
||||
|
||||
struct bgpq_expander {
|
||||
@@ -93,22 +108,22 @@ struct bgpq_expander {
|
||||
int fd;
|
||||
};
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
int bgpq_expand(struct bgpq_expander* b);
|
||||
int bgpq_expand(struct bgpq_expander *b);
|
||||
|
||||
int bgpq4_print_prefixlist(FILE* f, struct bgpq_expander* b);
|
||||
int bgpq4_print_eacl(FILE* f, struct bgpq_expander* b);
|
||||
int bgpq4_print_aspath(FILE* f, struct bgpq_expander* b);
|
||||
int bgpq4_print_asset(FILE* f, struct bgpq_expander* b);
|
||||
int bgpq4_print_oaspath(FILE* f, struct bgpq_expander* b);
|
||||
int bgpq4_print_route_filter_list(FILE* f, struct bgpq_expander* b);
|
||||
int bgpq4_print_prefixlist(FILE *f, struct bgpq_expander *b);
|
||||
int bgpq4_print_eacl(FILE *f, struct bgpq_expander *b);
|
||||
int bgpq4_print_aspath(FILE *f, struct bgpq_expander *b);
|
||||
int bgpq4_print_asset(FILE *f, struct bgpq_expander *b);
|
||||
int bgpq4_print_oaspath(FILE *f, struct bgpq_expander *b);
|
||||
int bgpq4_print_route_filter_list(FILE *f, struct bgpq_expander *b);
|
||||
|
||||
void sx_radix_node_freeall(struct sx_radix_node *n);
|
||||
void sx_radix_tree_freeall(struct sx_radix_tree *t);
|
||||
|
||||
@@ -700,7 +700,8 @@ main(int argc, char* argv[])
|
||||
sx_report(SX_ERROR, "Unable to add prefix %s "
|
||||
"(bad prefix or address-family)\n", argv[0]);
|
||||
exit(1);
|
||||
} else if (ec && !bgpq_expander_add_prefix_range(&expander, argv[0])) {
|
||||
} else if (ec && !bgpq_expander_add_prefix_range(&expander,
|
||||
argv[0])) {
|
||||
sx_report(SX_ERROR, "Unable to add prefix-range "
|
||||
"%s (bad range or address-family)\n",
|
||||
argv[0]);
|
||||
@@ -40,18 +40,18 @@
|
||||
#include "sx_report.h"
|
||||
|
||||
#ifndef SX_MAXSOCKBUF_MAX
|
||||
#define SX_MAXSOCKBUF_MAX (2*1024*1024)
|
||||
#define SX_MAXSOCKBUF_MAX (2 * 1024 * 1024)
|
||||
#endif
|
||||
|
||||
int
|
||||
sx_maxsockbuf(int s, int dir)
|
||||
{
|
||||
int optval = 0, voptval;
|
||||
int hiconf = -1, loconf = -1;
|
||||
unsigned int voptlen;
|
||||
int phase = 0, iterations = 0;
|
||||
int optval = 0, voptval;
|
||||
int hiconf = -1, loconf = -1;
|
||||
unsigned int voptlen;
|
||||
int phase = 0, iterations = 0;
|
||||
|
||||
if (s<0) {
|
||||
if (s < 0) {
|
||||
sx_report(SX_FATAL,"Unable to maximize sockbuf on invalid "
|
||||
"socket %i\n", s);
|
||||
exit(1);
|
||||
|
||||
68
sx_prefix.h
68
sx_prefix.h
@@ -59,43 +59,43 @@ typedef struct sx_radix_tree {
|
||||
} sx_radix_tree_t;
|
||||
|
||||
/* most common operations with the tree is to: lookup/insert/unlink */
|
||||
struct sx_radix_node* sx_radix_tree_lookup(struct sx_radix_tree* tree,
|
||||
struct sx_prefix* prefix);
|
||||
struct sx_radix_node* sx_radix_tree_insert(struct sx_radix_tree* tree,
|
||||
struct sx_prefix* prefix);
|
||||
void sx_radix_tree_unlink(struct sx_radix_tree* t, struct sx_radix_node* n);
|
||||
struct sx_radix_node* sx_radix_tree_lookup_exact(struct sx_radix_tree* tree,
|
||||
struct sx_prefix* prefix);
|
||||
struct sx_radix_node *sx_radix_tree_lookup(struct sx_radix_tree *tree,
|
||||
struct sx_prefix *prefix);
|
||||
struct sx_radix_node *sx_radix_tree_insert(struct sx_radix_tree *tree,
|
||||
struct sx_prefix *prefix);
|
||||
void sx_radix_tree_unlink(struct sx_radix_tree *t, struct sx_radix_node *n);
|
||||
struct sx_radix_node *sx_radix_tree_lookup_exact(struct sx_radix_tree *tree,
|
||||
struct sx_prefix *prefix);
|
||||
|
||||
struct sx_prefix* sx_prefix_alloc(struct sx_prefix* p);
|
||||
void sx_prefix_destroy(struct sx_prefix* p);
|
||||
void sx_radix_node_destroy(struct sx_radix_node* p);
|
||||
void sx_prefix_adjust_masklen(struct sx_prefix* p);
|
||||
struct sx_prefix* sx_prefix_new(int af, char* text);
|
||||
int sx_prefix_parse(struct sx_prefix* p, int af, char* text);
|
||||
int sx_prefix_range_parse(struct sx_radix_tree* t, int af, unsigned int ml, char* text);
|
||||
int sx_prefix_fprint(FILE* f, struct sx_prefix* p);
|
||||
int sx_prefix_snprintf(struct sx_prefix* p, char* rbuffer, int srb);
|
||||
int sx_prefix_snprintf_sep(struct sx_prefix* p, char* rbuffer, int srb, char*);
|
||||
void sx_prefix_snprintf_fmt(struct sx_prefix* p, FILE* f,
|
||||
const char* name, const char* fmt,
|
||||
unsigned int aggregateLow, unsigned int aggregateHi);
|
||||
int sx_prefix_jsnprintf(struct sx_prefix* p, char* rbuffer, int srb);
|
||||
struct sx_radix_tree* sx_radix_tree_new(int af);
|
||||
struct sx_radix_node* sx_radix_node_new(struct sx_prefix* prefix);
|
||||
struct sx_prefix* sx_prefix_overlay(struct sx_prefix* p, int n);
|
||||
int sx_radix_tree_empty(struct sx_radix_tree* t);
|
||||
void sx_radix_node_fprintf(struct sx_radix_node* node, void* udata);
|
||||
int sx_radix_node_foreach(struct sx_radix_node* node,
|
||||
void (*func)(struct sx_radix_node*, void*), void* udata);
|
||||
int sx_radix_tree_foreach(struct sx_radix_tree* tree,
|
||||
void (*func)(struct sx_radix_node*, void*), void* udata);
|
||||
int sx_radix_tree_aggregate(struct sx_radix_tree* tree);
|
||||
int sx_radix_tree_refine(struct sx_radix_tree* tree, unsigned refine);
|
||||
int sx_radix_tree_refineLow(struct sx_radix_tree* tree, unsigned refineLow);
|
||||
struct sx_prefix *sx_prefix_alloc(struct sx_prefix *p);
|
||||
void sx_prefix_destroy(struct sx_prefix *p);
|
||||
void sx_radix_node_destroy(struct sx_radix_node *p);
|
||||
void sx_prefix_adjust_masklen(struct sx_prefix *p);
|
||||
struct sx_prefix *sx_prefix_new(int af, char *text);
|
||||
int sx_prefix_parse(struct sx_prefix *p, int af, char *text);
|
||||
int sx_prefix_range_parse(struct sx_radix_tree *t, int af, unsigned int ml, char *text);
|
||||
int sx_prefix_fprint(FILE *f, struct sx_prefix *p);
|
||||
int sx_prefix_snprintf(struct sx_prefix *p, char *rbuffer, int srb);
|
||||
int sx_prefix_snprintf_sep(struct sx_prefix *p, char *rbuffer, int srb, char *);
|
||||
void sx_prefix_snprintf_fmt(struct sx_prefix *p, FILE *f,
|
||||
const char *name, const char *fmt, unsigned int aggregateLow,
|
||||
unsigned int aggregateHi);
|
||||
int sx_prefix_jsnprintf(struct sx_prefix *p, char *rbuffer, int srb);
|
||||
struct sx_radix_tree *sx_radix_tree_new(int af);
|
||||
struct sx_radix_node *sx_radix_node_new(struct sx_prefix *prefix);
|
||||
struct sx_prefix *sx_prefix_overlay(struct sx_prefix *p, int n);
|
||||
int sx_radix_tree_empty(struct sx_radix_tree *t);
|
||||
void sx_radix_node_fprintf(struct sx_radix_node *node, void *udata);
|
||||
int sx_radix_node_foreach(struct sx_radix_node *node,
|
||||
void (*func)(struct sx_radix_node *, void *), void *udata);
|
||||
int sx_radix_tree_foreach(struct sx_radix_tree *tree,
|
||||
void (*func)(struct sx_radix_node *, void *), void *udata);
|
||||
int sx_radix_tree_aggregate(struct sx_radix_tree *tree);
|
||||
int sx_radix_tree_refine(struct sx_radix_tree *tree, unsigned refine);
|
||||
int sx_radix_tree_refineLow(struct sx_radix_tree *tree, unsigned refineLow);
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
size_t strlcpy(char* dst, const char* src, size_t size);
|
||||
size_t strlcpy(char *dst, const char *src, size_t size);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,11 +24,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include "sx_slentry.h"
|
||||
#include "extern.h"
|
||||
|
||||
struct sx_slentry *
|
||||
sx_slentry_new(char *t)
|
||||
@@ -40,8 +41,7 @@ sx_slentry_new(char *t)
|
||||
|
||||
memset(e, 0, sizeof(struct sx_slentry));
|
||||
|
||||
if (t)
|
||||
e->text = strdup(t);
|
||||
e->text = strdup(t);
|
||||
|
||||
return e;
|
||||
}
|
||||
@@ -55,6 +55,7 @@ sx_tentry_new(char *t)
|
||||
return NULL;
|
||||
|
||||
memset(te, 0, sizeof(struct sx_tentry));
|
||||
|
||||
te->text = strdup(t);
|
||||
|
||||
return te;
|
||||
|
||||
Reference in New Issue
Block a user