mirror_frr/tests/bgpd/test_packet.c
Donald Sharp 1f32eb30d9 bgpd: Start abstraction of struct peer_connection
BGP tracks connections based upon the peer.  But the problem
with this is that the doppelganger structure for it is being
created.  This has introduced a bunch of fragileness in that
the peer exists independently of the connections to it.

The whole point of the doppelganger structure was to allow
BGP to both accept and initiate tcp connections and then
when we get one to a `good` state we collapse into the
appropriate one.  The problem with this is that having
2 peer structures for this creates a situation where
we have to make sure we are configing the `right` one
and also make sure that we collapse the two independent
peer structures into 1 acting peer.  This makes no sense
let's abstract out the peer into having 2 connection
one for incoming connections and one for outgoing connections
then we can easily collapse down without having to do crazy
stuff.  In addition people adding new features don't need
to have to go touch a million places in the code.

This is the start of this abstraction.  In this commit
we'll just pull out the fd and input/output buffers
into a connection data structure.  Future commits
will abstract further.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-08-18 09:29:04 -04:00

75 lines
1.6 KiB
C

// SPDX-License-Identifier: GPL-2.0-or-later
/*
* 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"
#include "bgpd/bgp_network.h"
/* need these to link in libbgp */
struct zebra_privs_t bgpd_privs = {};
struct event_loop *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;
struct event t;
qobj_init();
bgp_attr_init();
master = event_master_create(NULL);
bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new());
vrf_init(NULL, NULL, NULL, NULL);
bgp_option_set(BGP_OPT_NO_LISTEN);
if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT, NULL,
ASNOTATION_PLAIN) < 0)
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->connection.fd = open(argv[1], O_RDONLY | O_NONBLOCK);
t.arg = peer;
peer->t_read = &t;
// printf("bgp_read_packet returns: %d\n", bgp_read(&t));
}