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