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