]> git.proxmox.com Git - mirror_frr.git/blob - tests/bgpd/test_packet.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / tests / bgpd / test_packet.c
1 /*
2 * Copyright (C) 2017 Cumulus Networks Inc.
3 * Donald Sharp
4 *
5 * This file is part of FRR
6 *
7 * FRR is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * FRR is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <zebra.h>
23
24 #include "qobj.h"
25 #include "vty.h"
26 #include "stream.h"
27 #include "privs.h"
28 #include "memory.h"
29 #include "queue.h"
30 #include "filter.h"
31
32 #include "bgpd/bgpd.h"
33 #include "bgpd/bgp_open.h"
34 #include "bgpd/bgp_debug.h"
35 #include "bgpd/bgp_packet.h"
36 #include "bgpd/bgp_aspath.h"
37
38 /* need these to link in libbgp */
39 struct zebra_privs_t *bgpd_privs = NULL;
40 struct thread_master *master = NULL;
41
42 static struct bgp *bgp;
43 static as_t asn = 100;
44
45 extern int bgp_read_packet(struct peer *peer);
46
47 /*
48 * This file is intended to be used as input for some sort of
49 * fuzzer. Specifically I had afl in mind when I wrote
50 * this code.
51 */
52 int main(int argc, char *argv[])
53 {
54 struct peer *peer;
55 int i, j;
56 struct thread t;
57
58 qobj_init();
59 bgp_attr_init();
60 master = thread_master_create(NULL);
61 bgp_master_init(master);
62 vrf_init(NULL, NULL, NULL, NULL, NULL);
63 bgp_option_set(BGP_OPT_NO_LISTEN);
64
65 if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT))
66 return -1;
67
68 peer = peer_create_accept(bgp);
69 peer->host = (char *)"foo";
70
71 for (i = AFI_IP; i < AFI_MAX; i++)
72 for (j = SAFI_UNICAST; j < SAFI_MAX; j++) {
73 peer->afc[i][j] = 1;
74 peer->afc_adv[i][j] = 1;
75 }
76
77 SET_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV);
78 peer->status = Established;
79
80 peer->fd = open(argv[1], O_RDONLY|O_NONBLOCK);
81 t.arg = peer;
82 peer->t_read = &t;
83
84 // printf("bgp_read_packet returns: %d\n", bgp_read(&t));
85 }