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