2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-11-06 16:53:01 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Cumulus Networks Inc.
|
|
|
|
* Donald Sharp
|
|
|
|
*
|
|
|
|
* This file is part of FRR
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zebra.h>
|
|
|
|
|
|
|
|
#include "qobj.h"
|
|
|
|
#include "vty.h"
|
|
|
|
#include "stream.h"
|
|
|
|
#include "privs.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "queue.h"
|
|
|
|
#include "filter.h"
|
|
|
|
|
|
|
|
#include "bgpd/bgpd.h"
|
|
|
|
#include "bgpd/bgp_open.h"
|
|
|
|
#include "bgpd/bgp_debug.h"
|
|
|
|
#include "bgpd/bgp_packet.h"
|
|
|
|
#include "bgpd/bgp_aspath.h"
|
2019-10-04 20:33:01 +02:00
|
|
|
#include "bgpd/bgp_network.h"
|
2017-11-06 16:53:01 +01:00
|
|
|
|
|
|
|
/* need these to link in libbgp */
|
2022-04-27 14:16:50 +02:00
|
|
|
struct zebra_privs_t bgpd_privs = {};
|
2017-11-06 16:53:01 +01:00
|
|
|
struct thread_master *master = NULL;
|
|
|
|
|
|
|
|
static struct bgp *bgp;
|
|
|
|
static as_t asn = 100;
|
|
|
|
|
|
|
|
extern int bgp_read_packet(struct peer *peer);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is intended to be used as input for some sort of
|
|
|
|
* fuzzer. Specifically I had afl in mind when I wrote
|
|
|
|
* this code.
|
|
|
|
*/
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct peer *peer;
|
|
|
|
int i, j;
|
2022-03-01 22:18:12 +01:00
|
|
|
struct event t;
|
2017-11-06 16:53:01 +01:00
|
|
|
|
|
|
|
qobj_init();
|
|
|
|
bgp_attr_init();
|
|
|
|
master = thread_master_create(NULL);
|
2021-01-03 06:02:29 +01:00
|
|
|
bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new());
|
*: rework renaming the default VRF
Currently, it is possible to rename the default VRF either by passing
`-o` option to zebra or by creating a file in `/var/run/netns` and
binding it to `/proc/self/ns/net`.
In both cases, only zebra knows about the rename and other daemons learn
about it only after they connect to zebra. This is a problem, because
daemons may read their config before they connect to zebra. To handle
this rename after the config is read, we have some special code in every
single daemon, which is not very bad but not desirable in my opinion.
But things are getting worse when we need to handle this in northbound
layer as we have to manually rewrite the config nodes. This approach is
already hacky, but still works as every daemon handles its own NB
structures. But it is completely incompatible with the central
management daemon architecture we are aiming for, as mgmtd doesn't even
have a connection with zebra to learn from it. And it shouldn't have it,
because operational state changes should never affect configuration.
To solve the problem and simplify the code, I propose to expand the `-o`
option to all daemons. By using the startup option, we let daemons know
about the rename before they read their configs so we don't need any
special code to deal with it. There's an easy way to pass the option to
all daemons by using `frr_global_options` variable.
Unfortunately, the second way of renaming by creating a file in
`/var/run/netns` is incompatible with the new mgmtd architecture.
Theoretically, we could force daemons to read their configs only after
they connect to zebra, but it means adding even more code to handle a
very specific use-case. And anyway this won't work for mgmtd as it
doesn't have a connection with zebra. So I had to remove this option.
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-12-03 23:22:55 +01:00
|
|
|
vrf_init(NULL, NULL, NULL, NULL);
|
2017-11-06 16:53:01 +01:00
|
|
|
bgp_option_set(BGP_OPT_NO_LISTEN);
|
|
|
|
|
bgpd: add as-notation keyword to 'router bgp' vty command
A new keyword permits changing the BGP as-notation output:
- [no] router bgp <> [vrf BLABLA] [as-notation [<dot|plain|dot+>]]
At the BGP instance creation, the output will inherit the way the
BGP instance is declared. For instance, the 'router bgp 1.1'
command will configure the output in the dot format. However, if
the client wants to choose an alternate output, he will have to
add the extra command: 'router bgp 1.1 as-notation dot+'.
Also, if the user wants to have plain format, even if the BGP
instance is declared in dot format, the keyword can also be used
for that.
The as-notation output is only taken into account at the BGP
instance creation. In the case where VPN instances are used,
a separate instance may be dynamically created. In that case,
the real as-notation format will be taken into acccount at the
first configuration.
Linking the as-notation format with the BGP instance makes sense,
as the operators want to keep consistency of what they configure.
One technical reason why to link the as-notation output with the
BGP instance creation is that the as-path segment lists stored
in the BGP updates use a string representation to handle aspath
operations (by using regexp for instance). Changing on the fly
the output needs to regenerate this string representation to the
correct format. Linking the configuration to the BGP instance
creation avoids refreshing the BGP updates. A similar mechanism
is put in place in junos too.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2022-11-03 21:17:57 +01:00
|
|
|
if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT, NULL,
|
|
|
|
ASNOTATION_PLAIN) < 0)
|
2017-11-06 16:53:01 +01:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
peer = peer_create_accept(bgp);
|
|
|
|
peer->host = (char *)"foo";
|
|
|
|
|
|
|
|
for (i = AFI_IP; i < AFI_MAX; i++)
|
|
|
|
for (j = SAFI_UNICAST; j < SAFI_MAX; j++) {
|
|
|
|
peer->afc[i][j] = 1;
|
|
|
|
peer->afc_adv[i][j] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SET_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV);
|
|
|
|
peer->status = Established;
|
|
|
|
|
|
|
|
peer->fd = open(argv[1], O_RDONLY|O_NONBLOCK);
|
|
|
|
t.arg = peer;
|
|
|
|
peer->t_read = &t;
|
2017-11-30 21:07:29 +01:00
|
|
|
|
|
|
|
// printf("bgp_read_packet returns: %d\n", bgp_read(&t));
|
2017-11-06 16:53:01 +01:00
|
|
|
}
|