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