]>
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[], |
d62a17ae | 159 | const int tab_size, struct in_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; | |
168 | struct in_addr raddr; | |
169 | uint8_t distance; | |
170 | uint32_t metric; | |
171 | int nexthop_num; | |
172 | int i, err; | |
173 | ||
5cef40fc | 174 | if (PIM_DEBUG_PIM_NHT_DETAIL) { |
d62a17ae | 175 | char addr_str[INET_ADDRSTRLEN]; |
17da84a4 | 176 | |
d62a17ae | 177 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
15569c58 | 178 | zlog_debug("%s: addr=%s(%s)", __func__, addr_str, |
5cef40fc | 179 | pim->vrf->name); |
d62a17ae | 180 | } |
181 | ||
182 | s = zlookup->ibuf; | |
183 | ||
184 | while (command != ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB) { | |
185 | stream_reset(s); | |
186 | err = zclient_read_header(s, zlookup->sock, &length, &marker, | |
187 | &version, &vrf_id, &command); | |
188 | if (err < 0) { | |
450971aa | 189 | flog_err(EC_LIB_ZAPI_MISSMATCH, |
15569c58 | 190 | "%s: zclient_read_header() failed", __func__); |
d62a17ae | 191 | zclient_lookup_failed(zlookup); |
192 | return -1; | |
193 | } | |
7713e71a SW |
194 | |
195 | if (command == ZEBRA_ERROR) { | |
196 | enum zebra_error_types error; | |
197 | ||
198 | zapi_error_decode(s, &error); | |
199 | /* Do nothing with it for now */ | |
200 | return -1; | |
201 | } | |
d62a17ae | 202 | } |
203 | ||
204 | raddr.s_addr = stream_get_ipv4(s); | |
205 | ||
206 | if (raddr.s_addr != addr.s_addr) { | |
207 | char addr_str[INET_ADDRSTRLEN]; | |
208 | char raddr_str[INET_ADDRSTRLEN]; | |
209 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); | |
210 | pim_inet4_dump("<raddr?>", raddr, raddr_str, sizeof(raddr_str)); | |
5cef40fc | 211 | zlog_warn("%s: address mismatch: addr=%s(%s) raddr=%s", |
15569c58 | 212 | __func__, addr_str, pim->vrf->name, raddr_str); |
d62a17ae | 213 | /* warning only */ |
214 | } | |
215 | ||
216 | distance = stream_getc(s); | |
217 | metric = stream_getl(s); | |
218 | nexthop_num = stream_getc(s); | |
219 | ||
220 | if (nexthop_num < 1) { | |
209a5679 DS |
221 | if (PIM_DEBUG_PIM_NHT_DETAIL) |
222 | zlog_debug("%s: socket %d bad nexthop_num=%d", __func__, | |
223 | zlookup->sock, nexthop_num); | |
d62a17ae | 224 | return -6; |
225 | } | |
226 | ||
227 | for (i = 0; i < nexthop_num; ++i) { | |
a756969d | 228 | vrf_id_t nexthop_vrf_id; |
d62a17ae | 229 | enum nexthop_types_t nexthop_type; |
230 | struct pim_neighbor *nbr; | |
231 | struct prefix p; | |
232 | ||
a756969d | 233 | nexthop_vrf_id = stream_getl(s); |
d62a17ae | 234 | nexthop_type = stream_getc(s); |
235 | if (num_ifindex >= tab_size) { | |
236 | char addr_str[INET_ADDRSTRLEN]; | |
237 | pim_inet4_dump("<addr?>", addr, addr_str, | |
238 | sizeof(addr_str)); | |
239 | zlog_warn( | |
5cef40fc | 240 | "%s: found too many nexthop ifindexes (%d > %d) for address %s(%s)", |
15569c58 DA |
241 | __func__, (num_ifindex + 1), tab_size, addr_str, |
242 | pim->vrf->name); | |
d62a17ae | 243 | return num_ifindex; |
244 | } | |
56c1568b MB |
245 | nexthop_tab[num_ifindex].protocol_distance = distance; |
246 | nexthop_tab[num_ifindex].route_metric = metric; | |
a756969d | 247 | nexthop_tab[num_ifindex].vrf_id = nexthop_vrf_id; |
d62a17ae | 248 | switch (nexthop_type) { |
249 | case NEXTHOP_TYPE_IFINDEX: | |
66f5152f MB |
250 | nexthop_tab[num_ifindex].ifindex = stream_getl(s); |
251 | /* | |
252 | * Connected route (i.e. no nexthop), use | |
253 | * address passed in as PIM nexthop. This will | |
254 | * allow us to work in cases where we are | |
255 | * trying to find a route for this box. | |
256 | */ | |
257 | nexthop_tab[num_ifindex].nexthop_addr.family = AF_INET; | |
258 | nexthop_tab[num_ifindex].nexthop_addr.prefixlen = | |
259 | IPV4_MAX_BITLEN; | |
260 | nexthop_tab[num_ifindex].nexthop_addr.u.prefix4 = | |
261 | addr; | |
262 | ++num_ifindex; | |
263 | break; | |
d62a17ae | 264 | case NEXTHOP_TYPE_IPV4_IFINDEX: |
265 | case NEXTHOP_TYPE_IPV4: | |
266 | nexthop_tab[num_ifindex].nexthop_addr.family = AF_INET; | |
66f5152f MB |
267 | nexthop_tab[num_ifindex].nexthop_addr.u.prefix4.s_addr = |
268 | stream_get_ipv4(s); | |
d62a17ae | 269 | nexthop_tab[num_ifindex].ifindex = stream_getl(s); |
d62a17ae | 270 | ++num_ifindex; |
271 | break; | |
272 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
273 | nexthop_tab[num_ifindex].nexthop_addr.family = AF_INET6; | |
274 | stream_get(&nexthop_tab[num_ifindex] | |
275 | .nexthop_addr.u.prefix6, | |
276 | s, sizeof(struct in6_addr)); | |
277 | nexthop_tab[num_ifindex].ifindex = stream_getl(s); | |
278 | ||
279 | p.family = AF_INET6; | |
f4d81e55 | 280 | p.prefixlen = IPV6_MAX_BITLEN; |
d62a17ae | 281 | memcpy(&p.u.prefix6, |
282 | &nexthop_tab[num_ifindex].nexthop_addr.u.prefix6, | |
283 | sizeof(struct in6_addr)); | |
284 | ||
285 | /* | |
286 | * If we are sending v6 secondary assume we receive v6 | |
287 | * secondary | |
288 | */ | |
85948e7b DS |
289 | struct interface *ifp = if_lookup_by_index( |
290 | nexthop_tab[num_ifindex].ifindex, | |
291 | nexthop_vrf_id); | |
292 | ||
293 | if (!ifp) | |
294 | nbr = NULL; | |
295 | else if (pim->send_v6_secondary) | |
296 | nbr = pim_neighbor_find_by_secondary(ifp, &p); | |
d62a17ae | 297 | else |
85948e7b DS |
298 | nbr = pim_neighbor_find_if(ifp); |
299 | ||
d62a17ae | 300 | if (nbr) { |
301 | nexthop_tab[num_ifindex].nexthop_addr.family = | |
302 | AF_INET; | |
9bb93fa0 DL |
303 | pim_addr_to_prefix( |
304 | &nexthop_tab[num_ifindex].nexthop_addr, | |
305 | nbr->source_addr); | |
d62a17ae | 306 | } |
307 | ++num_ifindex; | |
308 | break; | |
56c1568b MB |
309 | default: |
310 | /* do nothing */ | |
311 | { | |
312 | char addr_str[INET_ADDRSTRLEN]; | |
313 | pim_inet4_dump("<addr?>", addr, addr_str, | |
314 | sizeof(addr_str)); | |
315 | zlog_warn( | |
316 | "%s: found non-ifindex nexthop type=%d for address %s(%s)", | |
15569c58 DA |
317 | __func__, nexthop_type, addr_str, |
318 | pim->vrf->name); | |
56c1568b MB |
319 | } |
320 | break; | |
d62a17ae | 321 | } |
322 | } | |
323 | ||
324 | return num_ifindex; | |
12e41d03 DL |
325 | } |
326 | ||
71edad0f DS |
327 | static int zclient_lookup_nexthop_once(struct pim_instance *pim, |
328 | struct pim_zlookup_nexthop nexthop_tab[], | |
d62a17ae | 329 | const int tab_size, struct in_addr addr) |
12e41d03 | 330 | { |
d62a17ae | 331 | struct stream *s; |
332 | int ret; | |
333 | ||
5cef40fc | 334 | if (PIM_DEBUG_PIM_NHT_DETAIL) { |
d62a17ae | 335 | char addr_str[INET_ADDRSTRLEN]; |
336 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); | |
15569c58 | 337 | zlog_debug("%s: addr=%s(%s)", __func__, addr_str, |
5cef40fc | 338 | pim->vrf->name); |
d62a17ae | 339 | } |
340 | ||
341 | /* Check socket. */ | |
342 | if (zlookup->sock < 0) { | |
450971aa | 343 | flog_err(EC_LIB_ZAPI_SOCKET, |
1c50c1c0 | 344 | "%s: zclient lookup socket is not connected", |
15569c58 | 345 | __func__); |
d62a17ae | 346 | zclient_lookup_failed(zlookup); |
347 | return -1; | |
348 | } | |
349 | ||
3af2452c | 350 | if (pim->vrf->vrf_id == VRF_UNKNOWN) { |
d9ff4302 | 351 | zlog_notice( |
3af2452c | 352 | "%s: VRF: %s does not fully exist yet, delaying lookup", |
15569c58 | 353 | __func__, pim->vrf->name); |
3af2452c DS |
354 | return -1; |
355 | } | |
356 | ||
d62a17ae | 357 | s = zlookup->obuf; |
358 | stream_reset(s); | |
b83e35c7 SW |
359 | zclient_create_header(s, ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB, |
360 | pim->vrf->vrf_id); | |
d62a17ae | 361 | stream_put_in_addr(s, &addr); |
362 | stream_putw_at(s, 0, stream_get_endp(s)); | |
363 | ||
364 | ret = writen(zlookup->sock, s->data, stream_get_endp(s)); | |
365 | if (ret < 0) { | |
af4c2728 | 366 | flog_err( |
450971aa | 367 | EC_LIB_SOCKET, |
5cef40fc | 368 | "%s: writen() failure: %d writing to zclient lookup socket", |
15569c58 | 369 | __func__, errno); |
d62a17ae | 370 | zclient_lookup_failed(zlookup); |
371 | return -2; | |
372 | } | |
373 | if (ret == 0) { | |
450971aa | 374 | flog_err_sys(EC_LIB_SOCKET, |
09c866e3 | 375 | "%s: connection closed on zclient lookup socket", |
15569c58 | 376 | __func__); |
d62a17ae | 377 | zclient_lookup_failed(zlookup); |
378 | return -3; | |
379 | } | |
380 | ||
71edad0f | 381 | return zclient_read_nexthop(pim, zlookup, nexthop_tab, tab_size, addr); |
12e41d03 DL |
382 | } |
383 | ||
cc9f21da | 384 | void zclient_lookup_read_pipe(struct thread *thread) |
0da02f3a DS |
385 | { |
386 | struct zclient *zlookup = THREAD_ARG(thread); | |
387 | struct pim_instance *pim = pim_get_pim_instance(VRF_DEFAULT); | |
388 | struct pim_zlookup_nexthop nexthop_tab[10]; | |
389 | struct in_addr l = {.s_addr = INADDR_ANY}; | |
390 | ||
391 | zclient_lookup_nexthop_once(pim, nexthop_tab, 10, l); | |
392 | thread_add_timer(router->master, zclient_lookup_read_pipe, zlookup, 60, | |
393 | &zlookup_read); | |
0da02f3a DS |
394 | } |
395 | ||
71edad0f DS |
396 | int zclient_lookup_nexthop(struct pim_instance *pim, |
397 | struct pim_zlookup_nexthop nexthop_tab[], | |
00b1f412 | 398 | const int tab_size, pim_addr addr, |
d62a17ae | 399 | int max_lookup) |
12e41d03 | 400 | { |
d62a17ae | 401 | int lookup; |
402 | uint32_t route_metric = 0xFFFFFFFF; | |
403 | uint8_t protocol_distance = 0xFF; | |
404 | ||
bfc92019 | 405 | pim->nexthop_lookups++; |
d62a17ae | 406 | |
407 | for (lookup = 0; lookup < max_lookup; ++lookup) { | |
408 | int num_ifindex; | |
409 | int first_ifindex; | |
410 | struct prefix nexthop_addr; | |
411 | ||
71edad0f DS |
412 | num_ifindex = zclient_lookup_nexthop_once(pim, nexthop_tab, |
413 | tab_size, addr); | |
d62a17ae | 414 | if (num_ifindex < 1) { |
6d733f0d | 415 | if (PIM_DEBUG_PIM_NHT_DETAIL) |
d62a17ae | 416 | zlog_debug( |
90ab4458 | 417 | "%s: lookup=%d/%d: could not find nexthop ifindex for address %pPA(%s)", |
418 | __func__, lookup, max_lookup, &addr, | |
15569c58 | 419 | pim->vrf->name); |
d62a17ae | 420 | return -1; |
421 | } | |
422 | ||
423 | if (lookup < 1) { | |
424 | /* this is the non-recursive lookup - save original | |
425 | * metric/distance */ | |
426 | route_metric = nexthop_tab[0].route_metric; | |
427 | protocol_distance = nexthop_tab[0].protocol_distance; | |
428 | } | |
429 | ||
430 | /* | |
431 | * FIXME: Non-recursive nexthop ensured only for first ifindex. | |
432 | * However, recursive route lookup should really be fixed in | |
433 | * zebra daemon. | |
434 | * See also TODO T24. | |
435 | * | |
436 | * So Zebra for NEXTHOP_TYPE_IPV4 returns the ifindex now since | |
437 | * it was being stored. This Doesn't solve all cases of | |
438 | * recursive lookup but for the most common types it does. | |
439 | */ | |
440 | first_ifindex = nexthop_tab[0].ifindex; | |
441 | nexthop_addr = nexthop_tab[0].nexthop_addr; | |
442 | if (first_ifindex > 0) { | |
443 | /* found: first ifindex is non-recursive nexthop */ | |
444 | ||
445 | if (lookup > 0) { | |
446 | /* Report non-recursive success after first | |
447 | * lookup */ | |
90ab4458 | 448 | if (PIM_DEBUG_PIM_NHT) |
d62a17ae | 449 | zlog_debug( |
90ab4458 | 450 | "%s: lookup=%d/%d: found non-recursive ifindex=%d for address %pPA(%s) dist=%d met=%d", |
15569c58 | 451 | __func__, lookup, max_lookup, |
90ab4458 | 452 | first_ifindex, &addr, |
15569c58 | 453 | pim->vrf->name, |
d62a17ae | 454 | nexthop_tab[0] |
455 | .protocol_distance, | |
456 | nexthop_tab[0].route_metric); | |
d62a17ae | 457 | |
458 | /* use last address as nexthop address */ | |
90ab4458 | 459 | pim_addr_to_prefix( |
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 | ||
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( | |
90ab4458 | 479 | "%s: lookup=%d/%d: zebra returned recursive nexthop %s for address %pPA(%s) dist=%d met=%d", |
15569c58 | 480 | __func__, lookup, max_lookup, nexthop_str, |
90ab4458 | 481 | &addr, pim->vrf->name, |
d62a17ae | 482 | nexthop_tab[0].protocol_distance, |
483 | nexthop_tab[0].route_metric); | |
484 | } | |
485 | ||
90ab4458 | 486 | addr = pim_addr_from_prefix(&(nexthop_addr)); /* use nexthop |
487 | addr for recursive lookup */ | |
d62a17ae | 488 | |
489 | } /* for (max_lookup) */ | |
490 | ||
90ab4458 | 491 | if (PIM_DEBUG_PIM_NHT) |
d62a17ae | 492 | zlog_warn( |
90ab4458 | 493 | "%s: lookup=%d/%d: failure searching recursive nexthop ifindex for address %pPA(%s)", |
494 | __func__, lookup, max_lookup, &addr, pim->vrf->name); | |
12e41d03 | 495 | |
d62a17ae | 496 | return -2; |
12e41d03 | 497 | } |
05b0d0d0 | 498 | |
d62a17ae | 499 | void pim_zlookup_show_ip_multicast(struct vty *vty) |
05b0d0d0 | 500 | { |
d62a17ae | 501 | vty_out(vty, "Zclient lookup socket: "); |
502 | if (zlookup) { | |
503 | vty_out(vty, "%d failures=%d\n", zlookup->sock, zlookup->fail); | |
504 | } else { | |
505 | vty_out(vty, "<null zclient>\n"); | |
506 | } | |
05b0d0d0 | 507 | } |
e3be0432 | 508 | |
d62a17ae | 509 | int pim_zlookup_sg_statistics(struct channel_oil *c_oil) |
e3be0432 | 510 | { |
d62a17ae | 511 | struct stream *s = zlookup->obuf; |
512 | uint16_t command = 0; | |
513 | unsigned long long lastused; | |
6fff2cc6 | 514 | pim_sgaddr sg; |
d62a17ae | 515 | int count = 0; |
516 | int ret; | |
517 | struct interface *ifp = | |
7cfc7bcf | 518 | pim_if_find_by_vif_index(c_oil->pim, c_oil->oil.mfcc_parent); |
d62a17ae | 519 | |
520 | if (PIM_DEBUG_ZEBRA) { | |
6fff2cc6 | 521 | pim_sgaddr more; |
d62a17ae | 522 | |
523 | more.src = c_oil->oil.mfcc_origin; | |
524 | more.grp = c_oil->oil.mfcc_mcastgrp; | |
98a81d2b DL |
525 | zlog_debug("Sending Request for New Channel Oil Information%pSG VIIF %d(%s)", |
526 | &more, c_oil->oil.mfcc_parent, | |
527 | c_oil->pim->vrf->name); | |
d62a17ae | 528 | } |
529 | ||
530 | if (!ifp) | |
531 | return -1; | |
532 | ||
533 | stream_reset(s); | |
d3cc1e45 DS |
534 | zclient_create_header(s, ZEBRA_IPMR_ROUTE_STATS, |
535 | c_oil->pim->vrf->vrf_id); | |
d62a17ae | 536 | stream_put_in_addr(s, &c_oil->oil.mfcc_origin); |
537 | stream_put_in_addr(s, &c_oil->oil.mfcc_mcastgrp); | |
538 | stream_putl(s, ifp->ifindex); | |
539 | stream_putw_at(s, 0, stream_get_endp(s)); | |
540 | ||
541 | count = stream_get_endp(s); | |
542 | ret = writen(zlookup->sock, s->data, count); | |
543 | if (ret <= 0) { | |
af4c2728 | 544 | flog_err( |
450971aa | 545 | EC_LIB_SOCKET, |
5cef40fc | 546 | "%s: writen() failure: %d writing to zclient lookup socket", |
15569c58 | 547 | __func__, errno); |
d62a17ae | 548 | return -1; |
549 | } | |
550 | ||
551 | s = zlookup->ibuf; | |
552 | ||
553 | while (command != ZEBRA_IPMR_ROUTE_STATS) { | |
554 | int err; | |
555 | uint16_t length = 0; | |
556 | vrf_id_t vrf_id; | |
d7c0a89a QY |
557 | uint8_t marker; |
558 | uint8_t version; | |
d62a17ae | 559 | |
560 | stream_reset(s); | |
561 | err = zclient_read_header(s, zlookup->sock, &length, &marker, | |
562 | &version, &vrf_id, &command); | |
563 | if (err < 0) { | |
450971aa | 564 | flog_err(EC_LIB_ZAPI_MISSMATCH, |
15569c58 | 565 | "%s: zclient_read_header() failed", __func__); |
d62a17ae | 566 | zclient_lookup_failed(zlookup); |
567 | return -1; | |
568 | } | |
569 | } | |
570 | ||
571 | sg.src.s_addr = stream_get_ipv4(s); | |
572 | sg.grp.s_addr = stream_get_ipv4(s); | |
573 | if (sg.src.s_addr != c_oil->oil.mfcc_origin.s_addr | |
574 | || sg.grp.s_addr != c_oil->oil.mfcc_mcastgrp.s_addr) { | |
5667319b | 575 | if (PIM_DEBUG_ZEBRA) { |
6fff2cc6 | 576 | pim_sgaddr more; |
5667319b DS |
577 | |
578 | more.src = c_oil->oil.mfcc_origin; | |
579 | more.grp = c_oil->oil.mfcc_mcastgrp; | |
af4c2728 | 580 | flog_err( |
450971aa | 581 | EC_LIB_ZAPI_MISSMATCH, |
98a81d2b DL |
582 | "%s: Received wrong %pSG(%s) information requested", |
583 | __func__, &more, c_oil->pim->vrf->name); | |
5667319b | 584 | } |
d62a17ae | 585 | zclient_lookup_failed(zlookup); |
586 | return -3; | |
587 | } | |
588 | ||
589 | stream_get(&lastused, s, sizeof(lastused)); | |
f3aa221f QY |
590 | /* signed success value from netlink_talk; currently unused */ |
591 | (void)stream_getl(s); | |
d62a17ae | 592 | |
d62a17ae | 593 | c_oil->cc.lastused = lastused; |
e3be0432 | 594 | |
d62a17ae | 595 | return 0; |
e3be0432 | 596 | } |