]>
Commit | Line | Data |
---|---|---|
12e41d03 | 1 | /* |
896014f4 DL |
2 | * PIM for Quagga |
3 | * Copyright (C) 2008 Everton da Silva Marques | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; see the file COPYING; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | */ | |
12e41d03 DL |
19 | |
20 | #include <zebra.h> | |
12e41d03 DL |
21 | |
22 | #include "log.h" | |
23 | #include "prefix.h" | |
24 | #include "zclient.h" | |
25 | #include "stream.h" | |
26 | #include "network.h" | |
27 | #include "thread.h" | |
e3be0432 | 28 | #include "prefix.h" |
05b0d0d0 | 29 | #include "vty.h" |
3613d898 | 30 | #include "lib_errors.h" |
12e41d03 DL |
31 | |
32 | #include "pimd.h" | |
e3be0432 | 33 | #include "pim_iface.h" |
e34e07e6 | 34 | #include "pim_neighbor.h" |
12e41d03 DL |
35 | #include "pim_pim.h" |
36 | #include "pim_str.h" | |
e3be0432 | 37 | #include "pim_oil.h" |
12e41d03 | 38 | #include "pim_zlookup.h" |
90ab4458 | 39 | #include "pim_addr.h" |
12e41d03 | 40 | |
05b0d0d0 | 41 | static struct zclient *zlookup = NULL; |
0da02f3a | 42 | struct thread *zlookup_read; |
05b0d0d0 | 43 | |
12e41d03 | 44 | static void zclient_lookup_sched(struct zclient *zlookup, int delay); |
cc9f21da | 45 | static void zclient_lookup_read_pipe(struct thread *thread); |
12e41d03 DL |
46 | |
47 | /* Connect to zebra for nexthop lookup. */ | |
cc9f21da | 48 | static void zclient_lookup_connect(struct thread *t) |
12e41d03 | 49 | { |
d62a17ae | 50 | struct zclient *zlookup; |
51 | ||
52 | zlookup = THREAD_ARG(t); | |
53 | ||
54 | if (zlookup->sock >= 0) { | |
cc9f21da | 55 | return; |
d62a17ae | 56 | } |
57 | ||
58 | if (zclient_socket_connect(zlookup) < 0) { | |
59 | ++zlookup->fail; | |
60 | zlog_warn("%s: failure connecting zclient socket: failures=%d", | |
15569c58 | 61 | __func__, zlookup->fail); |
d62a17ae | 62 | } else { |
63 | zlookup->fail = 0; /* reset counter on connection */ | |
64 | } | |
65 | ||
7cfdb485 | 66 | if (zclient_send_hello(zlookup) == ZCLIENT_SEND_FAILURE) { |
17da84a4 KS |
67 | if (close(zlookup->sock)) { |
68 | zlog_warn("%s: closing fd=%d: errno=%d %s", __func__, | |
69 | zlookup->sock, errno, safe_strerror(errno)); | |
70 | } | |
71 | zlookup->sock = -1; | |
72 | } | |
73 | ||
d62a17ae | 74 | if (zlookup->sock < 0) { |
75 | /* Since last connect failed, retry within 10 secs */ | |
76 | zclient_lookup_sched(zlookup, 10); | |
cc9f21da | 77 | return; |
d62a17ae | 78 | } |
79 | ||
0da02f3a DS |
80 | thread_add_timer(router->master, zclient_lookup_read_pipe, zlookup, 60, |
81 | &zlookup_read); | |
12e41d03 DL |
82 | } |
83 | ||
84 | /* Schedule connection with delay. */ | |
85 | static void zclient_lookup_sched(struct zclient *zlookup, int delay) | |
86 | { | |
36417fcc | 87 | thread_add_timer(router->master, zclient_lookup_connect, zlookup, delay, |
d62a17ae | 88 | &zlookup->t_connect); |
12e41d03 | 89 | |
d62a17ae | 90 | zlog_notice("%s: zclient lookup connection scheduled for %d seconds", |
15569c58 | 91 | __func__, delay); |
12e41d03 DL |
92 | } |
93 | ||
94 | /* Schedule connection for now. */ | |
95 | static void zclient_lookup_sched_now(struct zclient *zlookup) | |
96 | { | |
36417fcc | 97 | thread_add_event(router->master, zclient_lookup_connect, zlookup, 0, |
d62a17ae | 98 | &zlookup->t_connect); |
12e41d03 | 99 | |
d62a17ae | 100 | zlog_notice("%s: zclient lookup immediate connection scheduled", |
15569c58 | 101 | __func__); |
12e41d03 DL |
102 | } |
103 | ||
104 | /* Schedule reconnection, if needed. */ | |
105 | static void zclient_lookup_reconnect(struct zclient *zlookup) | |
106 | { | |
d62a17ae | 107 | if (zlookup->t_connect) { |
108 | return; | |
109 | } | |
12e41d03 | 110 | |
d62a17ae | 111 | zclient_lookup_sched_now(zlookup); |
12e41d03 DL |
112 | } |
113 | ||
114 | static void zclient_lookup_failed(struct zclient *zlookup) | |
115 | { | |
d62a17ae | 116 | if (zlookup->sock >= 0) { |
117 | if (close(zlookup->sock)) { | |
118 | zlog_warn("%s: closing fd=%d: errno=%d %s", __func__, | |
119 | zlookup->sock, errno, safe_strerror(errno)); | |
120 | } | |
121 | zlookup->sock = -1; | |
122 | } | |
123 | ||
124 | zclient_lookup_reconnect(zlookup); | |
12e41d03 DL |
125 | } |
126 | ||
d62a17ae | 127 | void zclient_lookup_free(void) |
0b6817c5 | 128 | { |
c58a47ea | 129 | THREAD_OFF(zlookup_read); |
d62a17ae | 130 | zclient_stop(zlookup); |
131 | zclient_free(zlookup); | |
132 | zlookup = NULL; | |
0b6817c5 DS |
133 | } |
134 | ||
d62a17ae | 135 | void zclient_lookup_new(void) |
12e41d03 | 136 | { |
17da84a4 KS |
137 | struct zclient_options options = zclient_options_default; |
138 | options.synchronous = true; | |
139 | ||
a243d1db | 140 | zlookup = zclient_new(router->master, &options, NULL, 0); |
d62a17ae | 141 | if (!zlookup) { |
450971aa | 142 | flog_err(EC_LIB_ZAPI_SOCKET, "%s: zclient_new() failure", |
15569c58 | 143 | __func__); |
d62a17ae | 144 | return; |
145 | } | |
12e41d03 | 146 | |
d62a17ae | 147 | zlookup->sock = -1; |
148 | zlookup->t_connect = NULL; | |
342213ea | 149 | zlookup->privs = &pimd_privs; |
12e41d03 | 150 | |
d62a17ae | 151 | zclient_lookup_sched_now(zlookup); |
12e41d03 | 152 | |
15569c58 | 153 | zlog_notice("%s: zclient lookup socket initialized", __func__); |
12e41d03 DL |
154 | } |
155 | ||
71edad0f DS |
156 | static int zclient_read_nexthop(struct pim_instance *pim, |
157 | struct zclient *zlookup, | |
12e41d03 | 158 | struct pim_zlookup_nexthop nexthop_tab[], |
eed74896 | 159 | const int tab_size, pim_addr addr) |
12e41d03 | 160 | { |
d62a17ae | 161 | int num_ifindex = 0; |
162 | struct stream *s; | |
d62a17ae | 163 | uint16_t length; |
d7c0a89a QY |
164 | uint8_t marker; |
165 | uint8_t version; | |
d62a17ae | 166 | vrf_id_t vrf_id; |
167 | uint16_t command = 0; | |
34ee41c6 | 168 | struct ipaddr raddr; |
d62a17ae | 169 | uint8_t distance; |
170 | uint32_t metric; | |
171 | int nexthop_num; | |
172 | int i, err; | |
173 | ||
eed74896 | 174 | if (PIM_DEBUG_PIM_NHT_DETAIL) |
175 | zlog_debug("%s: addr=%pPAs(%s)", __func__, &addr, | |
5cef40fc | 176 | pim->vrf->name); |
d62a17ae | 177 | |
178 | s = zlookup->ibuf; | |
179 | ||
34ee41c6 | 180 | while (command != ZEBRA_NEXTHOP_LOOKUP_MRIB) { |
d62a17ae | 181 | stream_reset(s); |
182 | err = zclient_read_header(s, zlookup->sock, &length, &marker, | |
183 | &version, &vrf_id, &command); | |
184 | if (err < 0) { | |
450971aa | 185 | flog_err(EC_LIB_ZAPI_MISSMATCH, |
15569c58 | 186 | "%s: zclient_read_header() failed", __func__); |
d62a17ae | 187 | zclient_lookup_failed(zlookup); |
188 | return -1; | |
189 | } | |
7713e71a SW |
190 | |
191 | if (command == ZEBRA_ERROR) { | |
192 | enum zebra_error_types error; | |
193 | ||
194 | zapi_error_decode(s, &error); | |
195 | /* Do nothing with it for now */ | |
196 | return -1; | |
197 | } | |
d62a17ae | 198 | } |
199 | ||
34ee41c6 DL |
200 | stream_get_ipaddr(s, &raddr); |
201 | ||
dea337dc DL |
202 | if (raddr.ipa_type != PIM_IPADDR || |
203 | pim_addr_cmp(raddr.ipaddr_pim, addr)) { | |
34ee41c6 | 204 | zlog_warn("%s: address mismatch: addr=%pPA(%s) raddr=%pIA", |
eed74896 | 205 | __func__, &addr, pim->vrf->name, &raddr); |
dea337dc DL |
206 | /* warning only */ |
207 | } | |
d62a17ae | 208 | |
209 | distance = stream_getc(s); | |
210 | metric = stream_getl(s); | |
211 | nexthop_num = stream_getc(s); | |
212 | ||
213 | if (nexthop_num < 1) { | |
209a5679 DS |
214 | if (PIM_DEBUG_PIM_NHT_DETAIL) |
215 | zlog_debug("%s: socket %d bad nexthop_num=%d", __func__, | |
216 | zlookup->sock, nexthop_num); | |
d62a17ae | 217 | return -6; |
218 | } | |
219 | ||
220 | for (i = 0; i < nexthop_num; ++i) { | |
a756969d | 221 | vrf_id_t nexthop_vrf_id; |
d62a17ae | 222 | enum nexthop_types_t nexthop_type; |
6f4ce28a DL |
223 | struct in_addr nh_ip4; |
224 | struct in6_addr nh_ip6; | |
225 | ifindex_t nh_ifi; | |
d62a17ae | 226 | |
a756969d | 227 | nexthop_vrf_id = stream_getl(s); |
d62a17ae | 228 | nexthop_type = stream_getc(s); |
229 | if (num_ifindex >= tab_size) { | |
d62a17ae | 230 | zlog_warn( |
eed74896 | 231 | "%s: found too many nexthop ifindexes (%d > %d) for address %pPAs(%s)", |
232 | __func__, (num_ifindex + 1), tab_size, &addr, | |
15569c58 | 233 | pim->vrf->name); |
d62a17ae | 234 | return num_ifindex; |
235 | } | |
56c1568b MB |
236 | nexthop_tab[num_ifindex].protocol_distance = distance; |
237 | nexthop_tab[num_ifindex].route_metric = metric; | |
a756969d | 238 | nexthop_tab[num_ifindex].vrf_id = nexthop_vrf_id; |
d62a17ae | 239 | switch (nexthop_type) { |
240 | case NEXTHOP_TYPE_IFINDEX: | |
66f5152f MB |
241 | nexthop_tab[num_ifindex].ifindex = stream_getl(s); |
242 | /* | |
243 | * Connected route (i.e. no nexthop), use | |
244 | * address passed in as PIM nexthop. This will | |
245 | * allow us to work in cases where we are | |
246 | * trying to find a route for this box. | |
247 | */ | |
eed74896 | 248 | nexthop_tab[num_ifindex].nexthop_addr = addr; |
66f5152f MB |
249 | ++num_ifindex; |
250 | break; | |
d62a17ae | 251 | case NEXTHOP_TYPE_IPV4_IFINDEX: |
252 | case NEXTHOP_TYPE_IPV4: | |
6f4ce28a DL |
253 | nh_ip4.s_addr = stream_get_ipv4(s); |
254 | nh_ifi = stream_getl(s); | |
255 | #if PIM_IPV == 4 | |
256 | nexthop_tab[num_ifindex].nexthop_addr = nh_ip4; | |
257 | nexthop_tab[num_ifindex].ifindex = nh_ifi; | |
d62a17ae | 258 | ++num_ifindex; |
6f4ce28a DL |
259 | #else |
260 | zlog_warn("cannot use IPv4 nexthop %pI4 for IPv6 %pPA", | |
261 | &nh_ip4, &addr); | |
262 | #endif | |
d62a17ae | 263 | break; |
264 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
6f4ce28a DL |
265 | stream_get(&nh_ip6, s, sizeof(nh_ip6)); |
266 | nh_ifi = stream_getl(s); | |
d62a17ae | 267 | |
6f4ce28a DL |
268 | #if PIM_IPV == 6 |
269 | nexthop_tab[num_ifindex].nexthop_addr = nh_ip6; | |
270 | nexthop_tab[num_ifindex].ifindex = nh_ifi; | |
271 | ++num_ifindex; | |
272 | #else | |
273 | /* RFC 5549 v4-over-v6 nexthop handling */ | |
d62a17ae | 274 | |
275 | /* | |
276 | * If we are sending v6 secondary assume we receive v6 | |
277 | * secondary | |
278 | */ | |
85948e7b DS |
279 | struct interface *ifp = if_lookup_by_index( |
280 | nexthop_tab[num_ifindex].ifindex, | |
281 | nexthop_vrf_id); | |
282 | ||
283 | if (!ifp) | |
6f4ce28a DL |
284 | break; |
285 | ||
286 | struct pim_neighbor *nbr; | |
287 | ||
288 | if (pim->send_v6_secondary) { | |
289 | struct prefix p; | |
290 | ||
291 | p.family = AF_INET6; | |
292 | p.prefixlen = IPV6_MAX_BITLEN; | |
293 | p.u.prefix6 = nh_ip6; | |
294 | ||
85948e7b | 295 | nbr = pim_neighbor_find_by_secondary(ifp, &p); |
6f4ce28a | 296 | } else |
85948e7b DS |
297 | nbr = pim_neighbor_find_if(ifp); |
298 | ||
6f4ce28a DL |
299 | if (!nbr) |
300 | break; | |
301 | ||
302 | nexthop_tab[num_ifindex].nexthop_addr = | |
303 | nbr->source_addr; | |
304 | nexthop_tab[num_ifindex].ifindex = nh_ifi; | |
d62a17ae | 305 | ++num_ifindex; |
6f4ce28a | 306 | #endif |
d62a17ae | 307 | break; |
56c1568b MB |
308 | default: |
309 | /* do nothing */ | |
6f4ce28a DL |
310 | zlog_warn( |
311 | "%s: found non-ifindex nexthop type=%d for address %pPAs(%s)", | |
312 | __func__, nexthop_type, &addr, pim->vrf->name); | |
56c1568b | 313 | break; |
d62a17ae | 314 | } |
315 | } | |
316 | ||
317 | return num_ifindex; | |
12e41d03 DL |
318 | } |
319 | ||
71edad0f DS |
320 | static int zclient_lookup_nexthop_once(struct pim_instance *pim, |
321 | struct pim_zlookup_nexthop nexthop_tab[], | |
ebbecd21 | 322 | const int tab_size, pim_addr addr) |
12e41d03 | 323 | { |
d62a17ae | 324 | struct stream *s; |
325 | int ret; | |
34ee41c6 | 326 | struct ipaddr ipaddr; |
d62a17ae | 327 | |
ebbecd21 | 328 | if (PIM_DEBUG_PIM_NHT_DETAIL) |
329 | zlog_debug("%s: addr=%pPAs(%s)", __func__, &addr, | |
5cef40fc | 330 | pim->vrf->name); |
d62a17ae | 331 | |
332 | /* Check socket. */ | |
333 | if (zlookup->sock < 0) { | |
450971aa | 334 | flog_err(EC_LIB_ZAPI_SOCKET, |
1c50c1c0 | 335 | "%s: zclient lookup socket is not connected", |
15569c58 | 336 | __func__); |
d62a17ae | 337 | zclient_lookup_failed(zlookup); |
338 | return -1; | |
339 | } | |
340 | ||
3af2452c | 341 | if (pim->vrf->vrf_id == VRF_UNKNOWN) { |
d9ff4302 | 342 | zlog_notice( |
3af2452c | 343 | "%s: VRF: %s does not fully exist yet, delaying lookup", |
15569c58 | 344 | __func__, pim->vrf->name); |
3af2452c DS |
345 | return -1; |
346 | } | |
347 | ||
dea337dc DL |
348 | ipaddr.ipa_type = PIM_IPADDR; |
349 | ipaddr.ipaddr_pim = addr; | |
34ee41c6 | 350 | |
d62a17ae | 351 | s = zlookup->obuf; |
352 | stream_reset(s); | |
34ee41c6 DL |
353 | zclient_create_header(s, ZEBRA_NEXTHOP_LOOKUP_MRIB, pim->vrf->vrf_id); |
354 | stream_put_ipaddr(s, &ipaddr); | |
d62a17ae | 355 | stream_putw_at(s, 0, stream_get_endp(s)); |
356 | ||
357 | ret = writen(zlookup->sock, s->data, stream_get_endp(s)); | |
358 | if (ret < 0) { | |
af4c2728 | 359 | flog_err( |
450971aa | 360 | EC_LIB_SOCKET, |
5cef40fc | 361 | "%s: writen() failure: %d writing to zclient lookup socket", |
15569c58 | 362 | __func__, errno); |
d62a17ae | 363 | zclient_lookup_failed(zlookup); |
364 | return -2; | |
365 | } | |
366 | if (ret == 0) { | |
450971aa | 367 | flog_err_sys(EC_LIB_SOCKET, |
09c866e3 | 368 | "%s: connection closed on zclient lookup socket", |
15569c58 | 369 | __func__); |
d62a17ae | 370 | zclient_lookup_failed(zlookup); |
371 | return -3; | |
372 | } | |
373 | ||
71edad0f | 374 | return zclient_read_nexthop(pim, zlookup, nexthop_tab, tab_size, addr); |
12e41d03 DL |
375 | } |
376 | ||
cc9f21da | 377 | void zclient_lookup_read_pipe(struct thread *thread) |
0da02f3a DS |
378 | { |
379 | struct zclient *zlookup = THREAD_ARG(thread); | |
380 | struct pim_instance *pim = pim_get_pim_instance(VRF_DEFAULT); | |
381 | struct pim_zlookup_nexthop nexthop_tab[10]; | |
265dec6a | 382 | pim_addr l = PIMADDR_ANY; |
0da02f3a | 383 | |
75a5ac75 | 384 | if (!pim) { |
385 | if (PIM_DEBUG_PIM_NHT_DETAIL) | |
386 | zlog_debug("%s: Unable to find pim instance", __func__); | |
387 | return; | |
388 | } | |
389 | ||
0da02f3a DS |
390 | zclient_lookup_nexthop_once(pim, nexthop_tab, 10, l); |
391 | thread_add_timer(router->master, zclient_lookup_read_pipe, zlookup, 60, | |
392 | &zlookup_read); | |
0da02f3a DS |
393 | } |
394 | ||
71edad0f DS |
395 | int zclient_lookup_nexthop(struct pim_instance *pim, |
396 | struct pim_zlookup_nexthop nexthop_tab[], | |
00b1f412 | 397 | const int tab_size, pim_addr addr, |
d62a17ae | 398 | int max_lookup) |
12e41d03 | 399 | { |
d62a17ae | 400 | int lookup; |
401 | uint32_t route_metric = 0xFFFFFFFF; | |
402 | uint8_t protocol_distance = 0xFF; | |
403 | ||
bfc92019 | 404 | pim->nexthop_lookups++; |
d62a17ae | 405 | |
406 | for (lookup = 0; lookup < max_lookup; ++lookup) { | |
407 | int num_ifindex; | |
408 | int first_ifindex; | |
eed4433d | 409 | pim_addr nexthop_addr; |
d62a17ae | 410 | |
71edad0f DS |
411 | num_ifindex = zclient_lookup_nexthop_once(pim, nexthop_tab, |
412 | tab_size, addr); | |
d62a17ae | 413 | if (num_ifindex < 1) { |
6d733f0d | 414 | if (PIM_DEBUG_PIM_NHT_DETAIL) |
d62a17ae | 415 | zlog_debug( |
90ab4458 | 416 | "%s: lookup=%d/%d: could not find nexthop ifindex for address %pPA(%s)", |
417 | __func__, lookup, max_lookup, &addr, | |
15569c58 | 418 | pim->vrf->name); |
d62a17ae | 419 | return -1; |
420 | } | |
421 | ||
422 | if (lookup < 1) { | |
423 | /* this is the non-recursive lookup - save original | |
424 | * metric/distance */ | |
425 | route_metric = nexthop_tab[0].route_metric; | |
426 | protocol_distance = nexthop_tab[0].protocol_distance; | |
427 | } | |
428 | ||
429 | /* | |
430 | * FIXME: Non-recursive nexthop ensured only for first ifindex. | |
431 | * However, recursive route lookup should really be fixed in | |
432 | * zebra daemon. | |
433 | * See also TODO T24. | |
434 | * | |
435 | * So Zebra for NEXTHOP_TYPE_IPV4 returns the ifindex now since | |
436 | * it was being stored. This Doesn't solve all cases of | |
437 | * recursive lookup but for the most common types it does. | |
438 | */ | |
439 | first_ifindex = nexthop_tab[0].ifindex; | |
440 | nexthop_addr = nexthop_tab[0].nexthop_addr; | |
441 | if (first_ifindex > 0) { | |
442 | /* found: first ifindex is non-recursive nexthop */ | |
443 | ||
444 | if (lookup > 0) { | |
445 | /* Report non-recursive success after first | |
446 | * lookup */ | |
90ab4458 | 447 | if (PIM_DEBUG_PIM_NHT) |
d62a17ae | 448 | zlog_debug( |
90ab4458 | 449 | "%s: lookup=%d/%d: found non-recursive ifindex=%d for address %pPA(%s) dist=%d met=%d", |
15569c58 | 450 | __func__, lookup, max_lookup, |
90ab4458 | 451 | first_ifindex, &addr, |
15569c58 | 452 | pim->vrf->name, |
d62a17ae | 453 | nexthop_tab[0] |
454 | .protocol_distance, | |
455 | nexthop_tab[0].route_metric); | |
d62a17ae | 456 | |
457 | /* use last address as nexthop address */ | |
eed4433d | 458 | nexthop_tab[0].nexthop_addr = addr; |
d62a17ae | 459 | |
460 | /* report original route metric/distance */ | |
461 | nexthop_tab[0].route_metric = route_metric; | |
462 | nexthop_tab[0].protocol_distance = | |
463 | protocol_distance; | |
464 | } | |
465 | ||
466 | return num_ifindex; | |
467 | } | |
468 | ||
eed4433d | 469 | if (PIM_DEBUG_PIM_NHT) |
d62a17ae | 470 | zlog_debug( |
eed4433d | 471 | "%s: lookup=%d/%d: zebra returned recursive nexthop %pPAs for address %pPA(%s) dist=%d met=%d", |
472 | __func__, lookup, max_lookup, &nexthop_addr, | |
90ab4458 | 473 | &addr, pim->vrf->name, |
d62a17ae | 474 | nexthop_tab[0].protocol_distance, |
475 | nexthop_tab[0].route_metric); | |
d62a17ae | 476 | |
eed4433d | 477 | addr = nexthop_addr; /* use nexthop |
478 | addr for recursive lookup */ | |
d62a17ae | 479 | |
480 | } /* for (max_lookup) */ | |
481 | ||
90ab4458 | 482 | if (PIM_DEBUG_PIM_NHT) |
d62a17ae | 483 | zlog_warn( |
90ab4458 | 484 | "%s: lookup=%d/%d: failure searching recursive nexthop ifindex for address %pPA(%s)", |
485 | __func__, lookup, max_lookup, &addr, pim->vrf->name); | |
12e41d03 | 486 | |
d62a17ae | 487 | return -2; |
12e41d03 | 488 | } |
05b0d0d0 | 489 | |
d62a17ae | 490 | void pim_zlookup_show_ip_multicast(struct vty *vty) |
05b0d0d0 | 491 | { |
d62a17ae | 492 | vty_out(vty, "Zclient lookup socket: "); |
493 | if (zlookup) { | |
494 | vty_out(vty, "%d failures=%d\n", zlookup->sock, zlookup->fail); | |
495 | } else { | |
496 | vty_out(vty, "<null zclient>\n"); | |
497 | } | |
05b0d0d0 | 498 | } |
e3be0432 | 499 | |
d62a17ae | 500 | int pim_zlookup_sg_statistics(struct channel_oil *c_oil) |
e3be0432 | 501 | { |
d62a17ae | 502 | struct stream *s = zlookup->obuf; |
503 | uint16_t command = 0; | |
504 | unsigned long long lastused; | |
6fff2cc6 | 505 | pim_sgaddr sg; |
d62a17ae | 506 | int count = 0; |
507 | int ret; | |
51f4fd98 | 508 | pim_sgaddr more = {}; |
d62a17ae | 509 | struct interface *ifp = |
51f4fd98 | 510 | pim_if_find_by_vif_index(c_oil->pim, *oil_parent(c_oil)); |
d62a17ae | 511 | |
512 | if (PIM_DEBUG_ZEBRA) { | |
51f4fd98 MR |
513 | more.src = *oil_origin(c_oil); |
514 | more.grp = *oil_mcastgrp(c_oil); | |
515 | zlog_debug( | |
516 | "Sending Request for New Channel Oil Information%pSG VIIF %d(%s)", | |
517 | &more, *oil_parent(c_oil), c_oil->pim->vrf->name); | |
d62a17ae | 518 | } |
519 | ||
520 | if (!ifp) | |
521 | return -1; | |
522 | ||
523 | stream_reset(s); | |
d3cc1e45 DS |
524 | zclient_create_header(s, ZEBRA_IPMR_ROUTE_STATS, |
525 | c_oil->pim->vrf->vrf_id); | |
51f4fd98 MR |
526 | stream_putl(s, PIM_AF); |
527 | stream_write(s, oil_origin(c_oil), sizeof(pim_addr)); | |
528 | stream_write(s, oil_mcastgrp(c_oil), sizeof(pim_addr)); | |
d62a17ae | 529 | stream_putl(s, ifp->ifindex); |
530 | stream_putw_at(s, 0, stream_get_endp(s)); | |
531 | ||
532 | count = stream_get_endp(s); | |
533 | ret = writen(zlookup->sock, s->data, count); | |
534 | if (ret <= 0) { | |
af4c2728 | 535 | flog_err( |
450971aa | 536 | EC_LIB_SOCKET, |
5cef40fc | 537 | "%s: writen() failure: %d writing to zclient lookup socket", |
15569c58 | 538 | __func__, errno); |
d62a17ae | 539 | return -1; |
540 | } | |
541 | ||
542 | s = zlookup->ibuf; | |
543 | ||
544 | while (command != ZEBRA_IPMR_ROUTE_STATS) { | |
545 | int err; | |
546 | uint16_t length = 0; | |
547 | vrf_id_t vrf_id; | |
d7c0a89a QY |
548 | uint8_t marker; |
549 | uint8_t version; | |
d62a17ae | 550 | |
551 | stream_reset(s); | |
552 | err = zclient_read_header(s, zlookup->sock, &length, &marker, | |
553 | &version, &vrf_id, &command); | |
554 | if (err < 0) { | |
450971aa | 555 | flog_err(EC_LIB_ZAPI_MISSMATCH, |
15569c58 | 556 | "%s: zclient_read_header() failed", __func__); |
d62a17ae | 557 | zclient_lookup_failed(zlookup); |
558 | return -1; | |
559 | } | |
560 | } | |
561 | ||
51f4fd98 MR |
562 | stream_get(&sg.src, s, sizeof(pim_addr)); |
563 | stream_get(&sg.grp, s, sizeof(pim_addr)); | |
5667319b | 564 | |
51f4fd98 MR |
565 | more.src = *oil_origin(c_oil); |
566 | more.grp = *oil_mcastgrp(c_oil); | |
567 | if (pim_sgaddr_cmp(sg, more)) { | |
568 | if (PIM_DEBUG_ZEBRA) | |
af4c2728 | 569 | flog_err( |
450971aa | 570 | EC_LIB_ZAPI_MISSMATCH, |
98a81d2b DL |
571 | "%s: Received wrong %pSG(%s) information requested", |
572 | __func__, &more, c_oil->pim->vrf->name); | |
d62a17ae | 573 | zclient_lookup_failed(zlookup); |
574 | return -3; | |
575 | } | |
576 | ||
577 | stream_get(&lastused, s, sizeof(lastused)); | |
f3aa221f QY |
578 | /* signed success value from netlink_talk; currently unused */ |
579 | (void)stream_getl(s); | |
d62a17ae | 580 | |
d62a17ae | 581 | c_oil->cc.lastused = lastused; |
e3be0432 | 582 | |
d62a17ae | 583 | return 0; |
e3be0432 | 584 | } |