]> git.proxmox.com Git - mirror_frr.git/blob - tests/bgpd/test_packet.c
bgpd: store the bgp as identifier in the configured as-notation
[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 #include "bgpd/bgp_network.h"
38
39 /* need these to link in libbgp */
40 struct zebra_privs_t bgpd_privs = {};
41 struct thread_master *master = NULL;
42
43 static struct bgp *bgp;
44 static as_t asn = 100;
45
46 extern int bgp_read_packet(struct peer *peer);
47
48 /*
49 * This file is intended to be used as input for some sort of
50 * fuzzer. Specifically I had afl in mind when I wrote
51 * this code.
52 */
53 int main(int argc, char *argv[])
54 {
55 struct peer *peer;
56 int i, j;
57 struct thread t;
58
59 qobj_init();
60 bgp_attr_init();
61 master = thread_master_create(NULL);
62 bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new());
63 vrf_init(NULL, NULL, NULL, NULL);
64 bgp_option_set(BGP_OPT_NO_LISTEN);
65
66 if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT,
67 NULL) < 0)
68 return -1;
69
70 peer = peer_create_accept(bgp);
71 peer->host = (char *)"foo";
72
73 for (i = AFI_IP; i < AFI_MAX; i++)
74 for (j = SAFI_UNICAST; j < SAFI_MAX; j++) {
75 peer->afc[i][j] = 1;
76 peer->afc_adv[i][j] = 1;
77 }
78
79 SET_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV);
80 peer->status = Established;
81
82 peer->fd = open(argv[1], O_RDONLY|O_NONBLOCK);
83 t.arg = peer;
84 peer->t_read = &t;
85
86 // printf("bgp_read_packet returns: %d\n", bgp_read(&t));
87 }