]> git.proxmox.com Git - mirror_frr.git/blob - tests/bgpd/test_packet.c
*: Rename `struct thread` to `struct event`
[mirror_frr.git] / tests / bgpd / test_packet.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2017 Cumulus Networks Inc.
4 * Donald Sharp
5 *
6 * This file is part of FRR
7 */
8
9 #include <zebra.h>
10
11 #include "qobj.h"
12 #include "vty.h"
13 #include "stream.h"
14 #include "privs.h"
15 #include "memory.h"
16 #include "queue.h"
17 #include "filter.h"
18
19 #include "bgpd/bgpd.h"
20 #include "bgpd/bgp_open.h"
21 #include "bgpd/bgp_debug.h"
22 #include "bgpd/bgp_packet.h"
23 #include "bgpd/bgp_aspath.h"
24 #include "bgpd/bgp_network.h"
25
26 /* need these to link in libbgp */
27 struct zebra_privs_t bgpd_privs = {};
28 struct thread_master *master = NULL;
29
30 static struct bgp *bgp;
31 static as_t asn = 100;
32
33 extern int bgp_read_packet(struct peer *peer);
34
35 /*
36 * This file is intended to be used as input for some sort of
37 * fuzzer. Specifically I had afl in mind when I wrote
38 * this code.
39 */
40 int main(int argc, char *argv[])
41 {
42 struct peer *peer;
43 int i, j;
44 struct event t;
45
46 qobj_init();
47 bgp_attr_init();
48 master = thread_master_create(NULL);
49 bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new());
50 vrf_init(NULL, NULL, NULL, NULL);
51 bgp_option_set(BGP_OPT_NO_LISTEN);
52
53 if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT, NULL,
54 ASNOTATION_PLAIN) < 0)
55 return -1;
56
57 peer = peer_create_accept(bgp);
58 peer->host = (char *)"foo";
59
60 for (i = AFI_IP; i < AFI_MAX; i++)
61 for (j = SAFI_UNICAST; j < SAFI_MAX; j++) {
62 peer->afc[i][j] = 1;
63 peer->afc_adv[i][j] = 1;
64 }
65
66 SET_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV);
67 peer->status = Established;
68
69 peer->fd = open(argv[1], O_RDONLY|O_NONBLOCK);
70 t.arg = peer;
71 peer->t_read = &t;
72
73 // printf("bgp_read_packet returns: %d\n", bgp_read(&t));
74 }