]> git.proxmox.com Git - mirror_frr.git/blame - tests/bgpd/test_packet.c
Merge pull request #12837 from donaldsharp/unlikely_routemap
[mirror_frr.git] / tests / bgpd / test_packet.c
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
faf4cc64
DS
2/*
3 * Copyright (C) 2017 Cumulus Networks Inc.
4 * Donald Sharp
5 *
6 * This file is part of FRR
faf4cc64
DS
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"
c2d020ad 24#include "bgpd/bgp_network.h"
faf4cc64
DS
25
26/* need these to link in libbgp */
fcf6dce7 27struct zebra_privs_t bgpd_privs = {};
cd9d0537 28struct event_loop *master = NULL;
faf4cc64
DS
29
30static struct bgp *bgp;
31static as_t asn = 100;
32
33extern 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 */
40int main(int argc, char *argv[])
41{
42 struct peer *peer;
43 int i, j;
e6685141 44 struct event t;
faf4cc64
DS
45
46 qobj_init();
47 bgp_attr_init();
ce50d11c 48 master = event_master_create(NULL);
733367c0 49 bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new());
ac2cb9bf 50 vrf_init(NULL, NULL, NULL, NULL);
faf4cc64
DS
51 bgp_option_set(BGP_OPT_NO_LISTEN);
52
e55b0883
PG
53 if (bgp_get(&bgp, &asn, NULL, BGP_INSTANCE_TYPE_DEFAULT, NULL,
54 ASNOTATION_PLAIN) < 0)
faf4cc64
DS
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;
5561f523
QY
72
73 // printf("bgp_read_packet returns: %d\n", bgp_read(&t));
faf4cc64 74}