]> git.proxmox.com Git - mirror_frr.git/blame - ripngd/ripng_zebra.c
ripd: fix unsetting of authentication password
[mirror_frr.git] / ripngd / ripng_zebra.c
CommitLineData
718e3744 1/*
2 * RIPngd and zebra interface.
3 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra 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 * GNU Zebra 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 *
896014f4
DL
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
718e3744 20 */
21
22#include <zebra.h>
23
24#include "command.h"
25#include "prefix.h"
fe08ba7e 26#include "agg_table.h"
718e3744 27#include "stream.h"
c880b636 28#include "memory.h"
718e3744 29#include "routemap.h"
30#include "zclient.h"
31#include "log.h"
32
33#include "ripngd/ripngd.h"
c880b636 34#include "ripngd/ripng_debug.h"
718e3744 35
36/* All information about zebra. */
37struct zclient *zclient = NULL;
38
c880b636 39/* Send ECMP routes to zebra. */
5c84b9a5
RW
40static void ripng_zebra_ipv6_send(struct ripng *ripng, struct agg_node *rp,
41 uint8_t cmd)
718e3744 42{
d62a17ae 43 struct list *list = (struct list *)rp->info;
c9fb3e23
RW
44 struct zapi_route api;
45 struct zapi_nexthop *api_nh;
d62a17ae 46 struct listnode *listnode = NULL;
47 struct ripng_info *rinfo = NULL;
48 int count = 0;
49
c9fb3e23 50 memset(&api, 0, sizeof(api));
dde7b15b 51 api.vrf_id = ripng->vrf->vrf_id;
d00061ea 52 api.type = ZEBRA_ROUTE_RIPNG;
d00061ea 53 api.safi = SAFI_UNICAST;
c9fb3e23 54 api.prefix = rp->p;
d62a17ae 55
d00061ea 56 SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
d00061ea 57 for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) {
a74e593b
RW
58 if (count >= MULTIPATH_NUM)
59 break;
c9fb3e23 60 api_nh = &api.nexthops[count];
dde7b15b 61 api_nh->vrf_id = ripng->vrf->vrf_id;
c9fb3e23
RW
62 api_nh->gate.ipv6 = rinfo->nexthop;
63 api_nh->ifindex = rinfo->ifindex;
64 api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX;
d00061ea 65 count++;
c9fb3e23 66 if (cmd == ZEBRA_ROUTE_ADD)
d00061ea
RW
67 SET_FLAG(rinfo->flags, RIPNG_RTF_FIB);
68 else
69 UNSET_FLAG(rinfo->flags, RIPNG_RTF_FIB);
70 }
d62a17ae 71
d00061ea 72 api.nexthop_num = count;
d62a17ae 73
d00061ea 74 rinfo = listgetdata(listhead(list));
d62a17ae 75
d00061ea
RW
76 SET_FLAG(api.message, ZAPI_MESSAGE_METRIC);
77 api.metric = rinfo->metric;
d62a17ae 78
d00061ea
RW
79 if (rinfo->tag) {
80 SET_FLAG(api.message, ZAPI_MESSAGE_TAG);
81 api.tag = rinfo->tag;
82 }
d62a17ae 83
c9fb3e23 84 zclient_route_send(cmd, zclient, &api);
d00061ea
RW
85
86 if (IS_RIPNG_DEBUG_ZEBRA) {
87 if (ripng->ecmp)
88 zlog_debug("%s: %s/%d nexthops %d",
c9fb3e23 89 (cmd == ZEBRA_ROUTE_ADD)
d00061ea
RW
90 ? "Install into zebra"
91 : "Delete from zebra",
92 inet6_ntoa(rp->p.u.prefix6), rp->p.prefixlen,
93 count);
94 else
c9fb3e23
RW
95 zlog_debug(
96 "%s: %s/%d",
97 (cmd == ZEBRA_ROUTE_ADD) ? "Install into zebra"
98 : "Delete from zebra",
99 inet6_ntoa(rp->p.u.prefix6), rp->p.prefixlen);
d62a17ae 100 }
718e3744 101}
102
c880b636 103/* Add/update ECMP routes to zebra. */
5c84b9a5 104void ripng_zebra_ipv6_add(struct ripng *ripng, struct agg_node *rp)
718e3744 105{
5c84b9a5 106 ripng_zebra_ipv6_send(ripng, rp, ZEBRA_ROUTE_ADD);
c880b636 107}
718e3744 108
c880b636 109/* Delete ECMP routes from zebra. */
5c84b9a5 110void ripng_zebra_ipv6_delete(struct ripng *ripng, struct agg_node *rp)
c880b636 111{
5c84b9a5 112 ripng_zebra_ipv6_send(ripng, rp, ZEBRA_ROUTE_DELETE);
718e3744 113}
114
115/* Zebra route add and delete treatment. */
74489921
RW
116static int ripng_zebra_read_route(int command, struct zclient *zclient,
117 zebra_size_t length, vrf_id_t vrf_id)
718e3744 118{
5c84b9a5 119 struct ripng *ripng;
74489921 120 struct zapi_route api;
d62a17ae 121 struct in6_addr nexthop;
74489921 122 unsigned long ifindex;
d62a17ae 123
5c84b9a5
RW
124 ripng = ripng_lookup_by_vrf_id(vrf_id);
125 if (!ripng)
126 return 0;
127
74489921
RW
128 if (zapi_route_decode(zclient->ibuf, &api) < 0)
129 return -1;
d62a17ae 130
74489921
RW
131 /* we completely ignore srcdest routes for now. */
132 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX))
133 return 0;
d62a17ae 134
74489921
RW
135 nexthop = api.nexthops[0].gate.ipv6;
136 ifindex = api.nexthops[0].ifindex;
d62a17ae 137
74489921 138 if (command == ZEBRA_REDISTRIBUTE_ROUTE_ADD)
5c84b9a5
RW
139 ripng_redistribute_add(ripng, api.type,
140 RIPNG_ROUTE_REDISTRIBUTE,
74489921 141 (struct prefix_ipv6 *)&api.prefix,
d62a17ae 142 ifindex, &nexthop, api.tag);
143 else
5c84b9a5
RW
144 ripng_redistribute_delete(
145 ripng, api.type, RIPNG_ROUTE_REDISTRIBUTE,
146 (struct prefix_ipv6 *)&api.prefix, ifindex);
d62a17ae 147
148 return 0;
718e3744 149}
150
5c84b9a5 151void ripng_redistribute_conf_update(struct ripng *ripng, int type)
718e3744 152{
db2038c7 153 zclient_redistribute(ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0,
dde7b15b 154 ripng->vrf->vrf_id);
db2038c7 155}
7076bb2f 156
5c84b9a5 157void ripng_redistribute_conf_delete(struct ripng *ripng, int type)
db2038c7 158{
d62a17ae 159 if (zclient->sock > 0)
160 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE, zclient,
dde7b15b 161 AFI_IP6, type, 0, ripng->vrf->vrf_id);
718e3744 162
5c84b9a5 163 ripng_redistribute_withdraw(ripng, type);
718e3744 164}
165
5c84b9a5 166int ripng_redistribute_check(struct ripng *ripng, int type)
a94434b6 167{
dde7b15b
RW
168 return vrf_bitmap_check(zclient->redist[AFI_IP6][type],
169 ripng->vrf->vrf_id);
a94434b6 170}
171
5c84b9a5 172void ripng_redistribute_clean(struct ripng *ripng)
a94434b6 173{
db2038c7 174 for (int i = 0; i < ZEBRA_ROUTE_MAX; i++) {
5c84b9a5 175 if (!vrf_bitmap_check(zclient->redist[AFI_IP6][i],
dde7b15b 176 ripng->vrf->vrf_id))
db2038c7 177 continue;
d62a17ae 178
db2038c7
RW
179 if (zclient->sock > 0)
180 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE,
181 zclient, AFI_IP6, i, 0,
dde7b15b 182 ripng->vrf->vrf_id);
d62a17ae 183
dde7b15b
RW
184 vrf_bitmap_unset(zclient->redist[AFI_IP6][i],
185 ripng->vrf->vrf_id);
d62a17ae 186 }
718e3744 187}
188
5c84b9a5 189void ripng_redistribute_write(struct vty *vty, struct ripng *ripng)
718e3744 190{
d62a17ae 191 int i;
192
d00061ea
RW
193 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
194 if (i == zclient->redist_default
195 || !vrf_bitmap_check(zclient->redist[AFI_IP6][i],
dde7b15b 196 ripng->vrf->vrf_id))
d00061ea
RW
197 continue;
198
db2038c7 199 vty_out(vty, " %s", zebra_route_string(i));
d00061ea 200 }
718e3744 201}
202
dde7b15b
RW
203void ripng_zebra_vrf_register(struct vrf *vrf)
204{
205 if (vrf->vrf_id == VRF_DEFAULT)
206 return;
207
208 if (IS_RIPNG_DEBUG_EVENT)
209 zlog_debug("%s: register VRF %s(%u) to zebra", __func__,
210 vrf->name, vrf->vrf_id);
211
212 zclient_send_reg_requests(zclient, vrf->vrf_id);
213}
214
215void ripng_zebra_vrf_deregister(struct vrf *vrf)
216{
217 if (vrf->vrf_id == VRF_DEFAULT)
218 return;
219
220 if (IS_RIPNG_DEBUG_EVENT)
221 zlog_debug("%s: deregister VRF %s(%u) from zebra.", __func__,
222 vrf->name, vrf->vrf_id);
223
224 zclient_send_dereg_requests(zclient, vrf->vrf_id);
225}
226
d62a17ae 227static void ripng_zebra_connected(struct zclient *zclient)
7076bb2f 228{
d62a17ae 229 zclient_send_reg_requests(zclient, VRF_DEFAULT);
7076bb2f
FL
230}
231
718e3744 232/* Initialize zebra structure and it's commands. */
d62a17ae 233void zebra_init(struct thread_master *master)
718e3744 234{
d62a17ae 235 /* Allocate zebra structure. */
26f63a1e 236 zclient = zclient_new(master, &zclient_options_default);
342213ea 237 zclient_init(zclient, ZEBRA_ROUTE_RIPNG, 0, &ripngd_privs);
d62a17ae 238
239 zclient->zebra_connected = ripng_zebra_connected;
240 zclient->interface_up = ripng_interface_up;
241 zclient->interface_down = ripng_interface_down;
242 zclient->interface_add = ripng_interface_add;
243 zclient->interface_delete = ripng_interface_delete;
244 zclient->interface_address_add = ripng_interface_address_add;
245 zclient->interface_address_delete = ripng_interface_address_delete;
dde7b15b 246 zclient->interface_vrf_update = ripng_interface_vrf_update;
74489921
RW
247 zclient->redistribute_route_add = ripng_zebra_read_route;
248 zclient->redistribute_route_del = ripng_zebra_read_route;
718e3744 249}
7feb9237 250
d62a17ae 251void ripng_zebra_stop(void)
7feb9237 252{
d62a17ae 253 zclient_stop(zclient);
254 zclient_free(zclient);
7feb9237 255}