]> git.proxmox.com Git - mirror_frr.git/blame - zebra/zebra_ptm_redistribute.c
Merge pull request #531 from qlyoung/fix-stack-ref
[mirror_frr.git] / zebra / zebra_ptm_redistribute.c
CommitLineData
c43ed2e4
DS
1/**
2 * @copyright Copyright (C) 2015 Cumulus Networks, Inc.
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22#include <zebra.h>
23#include "prefix.h"
24#include "vty.h"
25#include "stream.h"
26#include "zebra/zserv.h"
88177fe3 27#include "zebra/zebra_ptm_redistribute.h"
4a1ab8e4 28#include "zebra/zebra_memory.h"
c43ed2e4 29
88177fe3 30static int
c43ed2e4
DS
31zsend_interface_bfd_update (int cmd, struct zserv *client,
32 struct interface *ifp, struct prefix *dp,
d553294e 33 struct prefix *sp, int status, vrf_id_t vrf_id)
c43ed2e4
DS
34{
35 int blen;
36 struct stream *s;
37
38 /* Check this client need interface information. */
39 if (! client->ifinfo)
40 return 0;
41
42 s = client->obuf;
43 stream_reset (s);
44
d553294e 45 zserv_create_header (s, cmd, vrf_id);
c43ed2e4
DS
46 if (ifp)
47 stream_putl (s, ifp->ifindex);
48 else
49 stream_putl (s, 0);
50
51 /* BFD destination prefix information. */
52 stream_putc (s, dp->family);
53 blen = prefix_blen (dp);
54 stream_put (s, &dp->u.prefix, blen);
55 stream_putc (s, dp->prefixlen);
56
68fe91d6 57 /* BFD status */
58 stream_putl(s, status);
59
c43ed2e4
DS
60 /* BFD source prefix information. */
61 stream_putc (s, sp->family);
62 blen = prefix_blen (sp);
63 stream_put (s, &sp->u.prefix, blen);
64 stream_putc (s, sp->prefixlen);
65
66 /* Write packet size. */
67 stream_putw_at (s, 0, stream_get_endp (s));
68
69 client->if_bfd_cnt++;
70 return zebra_server_send_message(client);
71}
72
73void
74zebra_interface_bfd_update (struct interface *ifp, struct prefix *dp,
d553294e 75 struct prefix *sp, int status, vrf_id_t vrf_id)
c43ed2e4
DS
76{
77 struct listnode *node, *nnode;
78 struct zserv *client;
79
80 for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client))
81 {
82 /* Supporting for OSPF and BGP */
7f342629
DS
83 if (client->proto != ZEBRA_ROUTE_OSPF && client->proto != ZEBRA_ROUTE_BGP
84 && client->proto != ZEBRA_ROUTE_OSPF6)
c43ed2e4
DS
85 continue;
86
87 /* Notify to the protocol daemons. */
68fe91d6 88 zsend_interface_bfd_update (ZEBRA_INTERFACE_BFD_DEST_UPDATE, client, ifp,
d553294e 89 dp, sp, status, vrf_id);
c43ed2e4
DS
90 }
91}
92
88177fe3 93static int
c43ed2e4
DS
94zsend_bfd_peer_replay (int cmd, struct zserv *client)
95{
96 struct stream *s;
97
98 s = client->obuf;
99 stream_reset (s);
100
12f6fb97 101 zserv_create_header (s, cmd, VRF_DEFAULT); //Pending: adjust when multi-vrf bfd work
c43ed2e4
DS
102
103 /* Write packet size. */
104 stream_putw_at (s, 0, stream_get_endp (s));
105
106 client->bfd_peer_replay_cnt++;
107 return zebra_server_send_message(client);
108}
109
110void
111zebra_bfd_peer_replay_req (void)
112{
113 struct listnode *node, *nnode;
114 struct zserv *client;
115
116 for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client))
117 {
118 /* Supporting for BGP */
7f342629
DS
119 if ((client->proto != ZEBRA_ROUTE_BGP) &&
120 (client->proto != ZEBRA_ROUTE_OSPF) &&
121 (client->proto != ZEBRA_ROUTE_OSPF6))
c43ed2e4
DS
122 continue;
123
124 /* Notify to the protocol daemons. */
125 zsend_bfd_peer_replay (ZEBRA_BFD_DEST_REPLAY, client);
126 }
127}