]> git.proxmox.com Git - mirror_frr.git/blame - tests/bgpd/test_packet.c
bgpd: use new defaults system (v2)
[mirror_frr.git] / tests / bgpd / test_packet.c
CommitLineData
faf4cc64
DS
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"
c2d020ad 37#include "bgpd/bgp_network.h"
faf4cc64
DS
38
39/* need these to link in libbgp */
40struct zebra_privs_t *bgpd_privs = NULL;
41struct thread_master *master = NULL;
42
43static struct bgp *bgp;
44static as_t asn = 100;
45
46extern 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 */
53int 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);
c2d020ad 62 bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE);
ecbc5a37 63 vrf_init(NULL, NULL, NULL, NULL, NULL);
faf4cc64
DS
64 bgp_option_set(BGP_OPT_NO_LISTEN);
65
5d5393b9 66 if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT) < 0)
faf4cc64
DS
67 return -1;
68
69 peer = peer_create_accept(bgp);
70 peer->host = (char *)"foo";
71
72 for (i = AFI_IP; i < AFI_MAX; i++)
73 for (j = SAFI_UNICAST; j < SAFI_MAX; j++) {
74 peer->afc[i][j] = 1;
75 peer->afc_adv[i][j] = 1;
76 }
77
78 SET_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV);
79 peer->status = Established;
80
81 peer->fd = open(argv[1], O_RDONLY|O_NONBLOCK);
82 t.arg = peer;
83 peer->t_read = &t;
5561f523
QY
84
85 // printf("bgp_read_packet returns: %d\n", bgp_read(&t));
faf4cc64 86}