Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 1 | /* |
| 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 |
| 16 | along with this program; see the file COPYING; if not, write to the |
| 17 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 18 | MA 02110-1301 USA |
| 19 | |
| 20 | $QuaggaId: $Format:%an, %ai, %h$ $ |
| 21 | */ |
| 22 | |
| 23 | #include <zebra.h> |
| 24 | #include "zebra/rib.h" |
| 25 | |
| 26 | #include "log.h" |
| 27 | #include "prefix.h" |
| 28 | #include "zclient.h" |
| 29 | #include "stream.h" |
| 30 | #include "network.h" |
| 31 | #include "thread.h" |
| 32 | |
| 33 | #include "pimd.h" |
| 34 | #include "pim_pim.h" |
| 35 | #include "pim_str.h" |
| 36 | #include "pim_zlookup.h" |
| 37 | |
| 38 | extern int zclient_debug; |
| 39 | |
| 40 | static void zclient_lookup_sched(struct zclient *zlookup, int delay); |
| 41 | |
| 42 | /* Connect to zebra for nexthop lookup. */ |
| 43 | static int zclient_lookup_connect(struct thread *t) |
| 44 | { |
| 45 | struct zclient *zlookup; |
| 46 | |
| 47 | zlookup = THREAD_ARG(t); |
| 48 | zlookup->t_connect = NULL; |
| 49 | |
| 50 | if (zlookup->sock >= 0) { |
| 51 | return 0; |
| 52 | } |
| 53 | |
Everton Marques | c77f01b | 2014-02-13 14:54:43 -0200 | [diff] [blame] | 54 | if (zclient_socket_connect(zlookup) < 0) { |
Everton Marques | a59f21b | 2014-09-30 17:23:56 -0300 | [diff] [blame] | 55 | ++zlookup->fail; |
| 56 | zlog_warn("%s: failure connecting zclient socket: failures=%d", |
| 57 | __PRETTY_FUNCTION__, zlookup->fail); |
| 58 | } |
| 59 | else { |
| 60 | zlookup->fail = 0; /* reset counter on connection */ |
Everton Marques | c77f01b | 2014-02-13 14:54:43 -0200 | [diff] [blame] | 61 | } |
| 62 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 63 | zassert(!zlookup->t_connect); |
| 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 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | /* Schedule connection with delay. */ |
| 74 | static void zclient_lookup_sched(struct zclient *zlookup, int delay) |
| 75 | { |
| 76 | zassert(!zlookup->t_connect); |
| 77 | |
| 78 | THREAD_TIMER_ON(master, zlookup->t_connect, |
| 79 | zclient_lookup_connect, |
| 80 | zlookup, delay); |
| 81 | |
| 82 | zlog_notice("%s: zclient lookup connection scheduled for %d seconds", |
| 83 | __PRETTY_FUNCTION__, delay); |
| 84 | } |
| 85 | |
| 86 | /* Schedule connection for now. */ |
| 87 | static void zclient_lookup_sched_now(struct zclient *zlookup) |
| 88 | { |
| 89 | zassert(!zlookup->t_connect); |
| 90 | |
| 91 | zlookup->t_connect = thread_add_event(master, zclient_lookup_connect, |
| 92 | zlookup, 0); |
| 93 | |
| 94 | zlog_notice("%s: zclient lookup immediate connection scheduled", |
| 95 | __PRETTY_FUNCTION__); |
| 96 | } |
| 97 | |
| 98 | /* Schedule reconnection, if needed. */ |
| 99 | static void zclient_lookup_reconnect(struct zclient *zlookup) |
| 100 | { |
| 101 | if (zlookup->t_connect) { |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | zclient_lookup_sched_now(zlookup); |
| 106 | } |
| 107 | |
Everton Marques | a59f21b | 2014-09-30 17:23:56 -0300 | [diff] [blame] | 108 | static void zclient_lookup_failed(struct zclient *zlookup) |
| 109 | { |
| 110 | if (zlookup->sock >= 0) { |
| 111 | if (close(zlookup->sock)) { |
| 112 | zlog_warn("%s: closing fd=%d: errno=%d %s", __func__, zlookup->sock, |
| 113 | errno, safe_strerror(errno)); |
| 114 | } |
| 115 | zlookup->sock = -1; |
| 116 | } |
| 117 | |
| 118 | zclient_lookup_reconnect(zlookup); |
| 119 | } |
| 120 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 121 | struct zclient *zclient_lookup_new() |
| 122 | { |
| 123 | struct zclient *zlookup; |
| 124 | |
| 125 | zlookup = zclient_new(); |
| 126 | if (!zlookup) { |
| 127 | zlog_err("%s: zclient_new() failure", |
| 128 | __PRETTY_FUNCTION__); |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | zlookup->sock = -1; |
| 133 | zlookup->ibuf = stream_new(ZEBRA_MAX_PACKET_SIZ); |
| 134 | zlookup->obuf = stream_new(ZEBRA_MAX_PACKET_SIZ); |
| 135 | zlookup->t_connect = 0; |
| 136 | |
| 137 | zclient_lookup_sched_now(zlookup); |
| 138 | |
| 139 | zlog_notice("%s: zclient lookup socket initialized", |
| 140 | __PRETTY_FUNCTION__); |
| 141 | |
| 142 | return zlookup; |
| 143 | } |
| 144 | |
| 145 | static int zclient_read_nexthop(struct zclient *zlookup, |
| 146 | struct pim_zlookup_nexthop nexthop_tab[], |
| 147 | const int tab_size, |
| 148 | struct in_addr addr) |
| 149 | { |
| 150 | int num_ifindex = 0; |
| 151 | struct stream *s; |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 152 | const uint16_t MIN_LEN = 10; /* getipv4=4 getc=1 getl=4 getc=1 */ |
| 153 | uint16_t length; |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 154 | u_char marker; |
| 155 | u_char version; |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 156 | uint16_t vrf_id; |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 157 | uint16_t command; |
| 158 | int nbytes; |
| 159 | struct in_addr raddr; |
| 160 | uint8_t distance; |
| 161 | uint32_t metric; |
| 162 | int nexthop_num; |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 163 | int i, err; |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 164 | |
| 165 | if (PIM_DEBUG_ZEBRA) { |
| 166 | char addr_str[100]; |
| 167 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
| 168 | zlog_debug("%s: addr=%s", |
| 169 | __PRETTY_FUNCTION__, |
| 170 | addr_str); |
| 171 | } |
| 172 | |
| 173 | s = zlookup->ibuf; |
| 174 | stream_reset(s); |
| 175 | |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 176 | err = zclient_read_header (s, zlookup->sock, &length, &marker, &version, |
| 177 | &vrf_id, &command); |
| 178 | if (err < 0) { |
| 179 | zlog_err("%s %s: zclient_read_header() failed", |
| 180 | __FILE__, __PRETTY_FUNCTION__); |
Everton Marques | a59f21b | 2014-09-30 17:23:56 -0300 | [diff] [blame] | 181 | zclient_lookup_failed(zlookup); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 182 | return -1; |
| 183 | } |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 184 | |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 185 | if (length < MIN_LEN) { |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 186 | zlog_err("%s %s: failure reading zclient lookup socket: len=%d < MIN_LEN=%d", |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 187 | __FILE__, __PRETTY_FUNCTION__, length, MIN_LEN); |
Everton Marques | a59f21b | 2014-09-30 17:23:56 -0300 | [diff] [blame] | 188 | zclient_lookup_failed(zlookup); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 189 | return -2; |
| 190 | } |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 191 | |
| 192 | nbytes = stream_read(s, zlookup->sock, length); |
| 193 | if (nbytes < length) { |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 194 | zlog_err("%s %s: failure reading zclient lookup socket: nbytes=%d < len=%d", |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 195 | __FILE__, __PRETTY_FUNCTION__, nbytes, length); |
Everton Marques | a59f21b | 2014-09-30 17:23:56 -0300 | [diff] [blame] | 196 | zclient_lookup_failed(zlookup); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 197 | return -3; |
| 198 | } |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 199 | |
| 200 | if (version != ZSERV_VERSION || marker != ZEBRA_HEADER_MARKER) { |
| 201 | zlog_err("%s: socket %d version mismatch, marker %d, version %d", |
| 202 | __func__, zlookup->sock, marker, version); |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 203 | zclient_lookup_failed(zlookup); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 204 | return -4; |
| 205 | } |
| 206 | |
Everton Marques | 04c833a | 2014-09-22 19:35:24 -0300 | [diff] [blame] | 207 | if (command != ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB) { |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 208 | zlog_err("%s: socket %d command mismatch: %d", |
| 209 | __func__, zlookup->sock, command); |
| 210 | return -5; |
| 211 | } |
| 212 | |
| 213 | raddr.s_addr = stream_get_ipv4(s); |
| 214 | |
| 215 | if (raddr.s_addr != addr.s_addr) { |
| 216 | char addr_str[100]; |
| 217 | char raddr_str[100]; |
| 218 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
| 219 | pim_inet4_dump("<raddr?>", raddr, raddr_str, sizeof(raddr_str)); |
| 220 | zlog_warn("%s: address mismatch: addr=%s raddr=%s", |
| 221 | __PRETTY_FUNCTION__, |
| 222 | addr_str, raddr_str); |
| 223 | /* warning only */ |
| 224 | } |
| 225 | |
| 226 | distance = stream_getc(s); |
| 227 | metric = stream_getl(s); |
| 228 | nexthop_num = stream_getc(s); |
| 229 | |
| 230 | if (nexthop_num < 1) { |
| 231 | zlog_err("%s: socket %d bad nexthop_num=%d", |
| 232 | __func__, zlookup->sock, nexthop_num); |
| 233 | return -6; |
| 234 | } |
| 235 | |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 236 | length -= MIN_LEN; |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 237 | |
| 238 | for (i = 0; i < nexthop_num; ++i) { |
| 239 | enum nexthop_types_t nexthop_type; |
| 240 | |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 241 | if (length < 1) { |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 242 | zlog_err("%s: socket %d empty input expecting nexthop_type: len=%d", |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 243 | __func__, zlookup->sock, length); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 244 | return -7; |
| 245 | } |
| 246 | |
| 247 | nexthop_type = stream_getc(s); |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 248 | --length; |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 249 | |
| 250 | switch (nexthop_type) { |
| 251 | case ZEBRA_NEXTHOP_IFINDEX: |
| 252 | case ZEBRA_NEXTHOP_IFNAME: |
| 253 | case ZEBRA_NEXTHOP_IPV4_IFINDEX: |
| 254 | if (num_ifindex >= tab_size) { |
| 255 | char addr_str[100]; |
| 256 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
| 257 | zlog_warn("%s %s: found too many nexthop ifindexes (%d > %d) for address %s", |
| 258 | __FILE__, __PRETTY_FUNCTION__, |
| 259 | (num_ifindex + 1), tab_size, addr_str); |
| 260 | return num_ifindex; |
| 261 | } |
| 262 | if (nexthop_type == ZEBRA_NEXTHOP_IPV4_IFINDEX) { |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 263 | if (length < 4) { |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 264 | zlog_err("%s: socket %d short input expecting nexthop IPv4-addr: len=%d", |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 265 | __func__, zlookup->sock, length); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 266 | return -8; |
| 267 | } |
| 268 | nexthop_tab[num_ifindex].nexthop_addr.s_addr = stream_get_ipv4(s); |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 269 | length -= 4; |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 270 | } |
| 271 | else { |
| 272 | nexthop_tab[num_ifindex].nexthop_addr.s_addr = PIM_NET_INADDR_ANY; |
| 273 | } |
| 274 | nexthop_tab[num_ifindex].ifindex = stream_getl(s); |
| 275 | nexthop_tab[num_ifindex].protocol_distance = distance; |
| 276 | nexthop_tab[num_ifindex].route_metric = metric; |
| 277 | ++num_ifindex; |
| 278 | break; |
| 279 | case ZEBRA_NEXTHOP_IPV4: |
| 280 | if (num_ifindex >= tab_size) { |
| 281 | char addr_str[100]; |
| 282 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
| 283 | zlog_warn("%s %s: found too many nexthop ifindexes (%d > %d) for address %s", |
| 284 | __FILE__, __PRETTY_FUNCTION__, |
| 285 | (num_ifindex + 1), tab_size, addr_str); |
| 286 | return num_ifindex; |
| 287 | } |
| 288 | nexthop_tab[num_ifindex].nexthop_addr.s_addr = stream_get_ipv4(s); |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 289 | length -= 4; |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 290 | nexthop_tab[num_ifindex].ifindex = 0; |
| 291 | nexthop_tab[num_ifindex].protocol_distance = distance; |
| 292 | nexthop_tab[num_ifindex].route_metric = metric; |
| 293 | { |
| 294 | char addr_str[100]; |
| 295 | char nexthop_str[100]; |
| 296 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
| 297 | pim_inet4_dump("<nexthop?>", nexthop_tab[num_ifindex].nexthop_addr, nexthop_str, sizeof(nexthop_str)); |
| 298 | zlog_warn("%s %s: zebra returned recursive nexthop %s for address %s", |
| 299 | __FILE__, __PRETTY_FUNCTION__, |
| 300 | nexthop_str, addr_str); |
| 301 | } |
| 302 | ++num_ifindex; |
| 303 | break; |
| 304 | default: |
| 305 | /* do nothing */ |
| 306 | { |
| 307 | char addr_str[100]; |
| 308 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
| 309 | zlog_warn("%s %s: found non-ifindex nexthop type=%d for address %s", |
| 310 | __FILE__, __PRETTY_FUNCTION__, |
| 311 | nexthop_type, addr_str); |
| 312 | } |
| 313 | break; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | return num_ifindex; |
| 318 | } |
| 319 | |
| 320 | static int zclient_lookup_nexthop_once(struct zclient *zlookup, |
| 321 | struct pim_zlookup_nexthop nexthop_tab[], |
| 322 | const int tab_size, |
| 323 | struct in_addr addr) |
| 324 | { |
| 325 | struct stream *s; |
| 326 | int ret; |
| 327 | |
| 328 | if (PIM_DEBUG_ZEBRA) { |
| 329 | char addr_str[100]; |
| 330 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
| 331 | zlog_debug("%s: addr=%s", |
| 332 | __PRETTY_FUNCTION__, |
| 333 | addr_str); |
| 334 | } |
| 335 | |
| 336 | /* Check socket. */ |
| 337 | if (zlookup->sock < 0) { |
| 338 | zlog_err("%s %s: zclient lookup socket is not connected", |
| 339 | __FILE__, __PRETTY_FUNCTION__); |
Everton Marques | a59f21b | 2014-09-30 17:23:56 -0300 | [diff] [blame] | 340 | zclient_lookup_failed(zlookup); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 341 | return -1; |
| 342 | } |
| 343 | |
| 344 | s = zlookup->obuf; |
| 345 | stream_reset(s); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 346 | zclient_create_header(s, ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB, VRF_DEFAULT); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 347 | stream_put_in_addr(s, &addr); |
| 348 | stream_putw_at(s, 0, stream_get_endp(s)); |
| 349 | |
| 350 | ret = writen(zlookup->sock, s->data, stream_get_endp(s)); |
| 351 | if (ret < 0) { |
| 352 | zlog_err("%s %s: writen() failure writing to zclient lookup socket", |
| 353 | __FILE__, __PRETTY_FUNCTION__); |
Everton Marques | a59f21b | 2014-09-30 17:23:56 -0300 | [diff] [blame] | 354 | zclient_lookup_failed(zlookup); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 355 | return -2; |
| 356 | } |
| 357 | if (ret == 0) { |
| 358 | zlog_err("%s %s: connection closed on zclient lookup socket", |
| 359 | __FILE__, __PRETTY_FUNCTION__); |
Everton Marques | a59f21b | 2014-09-30 17:23:56 -0300 | [diff] [blame] | 360 | zclient_lookup_failed(zlookup); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 361 | return -3; |
| 362 | } |
| 363 | |
| 364 | return zclient_read_nexthop(zlookup, nexthop_tab, |
| 365 | tab_size, addr); |
| 366 | } |
| 367 | |
| 368 | int zclient_lookup_nexthop(struct zclient *zlookup, |
| 369 | struct pim_zlookup_nexthop nexthop_tab[], |
| 370 | const int tab_size, |
| 371 | struct in_addr addr, |
| 372 | int max_lookup) |
| 373 | { |
| 374 | int lookup; |
Everton Marques | e4f2a2b | 2014-07-16 12:19:40 -0300 | [diff] [blame] | 375 | uint32_t route_metric = 0xFFFFFFFF; |
| 376 | uint8_t protocol_distance = 0xFF; |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 377 | |
| 378 | for (lookup = 0; lookup < max_lookup; ++lookup) { |
| 379 | int num_ifindex; |
| 380 | int first_ifindex; |
| 381 | struct in_addr nexthop_addr; |
| 382 | |
| 383 | num_ifindex = zclient_lookup_nexthop_once(qpim_zclient_lookup, nexthop_tab, |
| 384 | PIM_NEXTHOP_IFINDEX_TAB_SIZE, addr); |
| 385 | if (num_ifindex < 1) { |
| 386 | char addr_str[100]; |
| 387 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
| 388 | zlog_warn("%s %s: lookup=%d/%d: could not find nexthop ifindex for address %s", |
| 389 | __FILE__, __PRETTY_FUNCTION__, |
| 390 | lookup, max_lookup, addr_str); |
| 391 | return -1; |
| 392 | } |
Everton Marques | e4f2a2b | 2014-07-16 12:19:40 -0300 | [diff] [blame] | 393 | |
| 394 | if (lookup < 1) { |
| 395 | /* this is the non-recursive lookup - save original metric/distance */ |
| 396 | route_metric = nexthop_tab[0].route_metric; |
| 397 | protocol_distance = nexthop_tab[0].protocol_distance; |
| 398 | } |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 399 | |
| 400 | /* |
| 401 | FIXME: Non-recursive nexthop ensured only for first ifindex. |
| 402 | However, recursive route lookup should really be fixed in zebra daemon. |
| 403 | See also TODO T24. |
| 404 | */ |
| 405 | first_ifindex = nexthop_tab[0].ifindex; |
| 406 | nexthop_addr = nexthop_tab[0].nexthop_addr; |
| 407 | if (first_ifindex > 0) { |
| 408 | /* found: first ifindex is non-recursive nexthop */ |
| 409 | |
| 410 | if (lookup > 0) { |
| 411 | /* Report non-recursive success after first lookup */ |
| 412 | char addr_str[100]; |
| 413 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
Everton Marques | e4f2a2b | 2014-07-16 12:19:40 -0300 | [diff] [blame] | 414 | zlog_info("%s %s: lookup=%d/%d: found non-recursive ifindex=%d for address %s dist=%d met=%d", |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 415 | __FILE__, __PRETTY_FUNCTION__, |
Everton Marques | e4f2a2b | 2014-07-16 12:19:40 -0300 | [diff] [blame] | 416 | lookup, max_lookup, first_ifindex, addr_str, |
| 417 | nexthop_tab[0].protocol_distance, |
| 418 | nexthop_tab[0].route_metric); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 419 | |
| 420 | /* use last address as nexthop address */ |
| 421 | nexthop_tab[0].nexthop_addr = addr; |
Everton Marques | e4f2a2b | 2014-07-16 12:19:40 -0300 | [diff] [blame] | 422 | |
| 423 | /* report original route metric/distance */ |
| 424 | nexthop_tab[0].route_metric = route_metric; |
| 425 | nexthop_tab[0].protocol_distance = protocol_distance; |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | return num_ifindex; |
| 429 | } |
| 430 | |
| 431 | { |
| 432 | char addr_str[100]; |
| 433 | char nexthop_str[100]; |
| 434 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
| 435 | pim_inet4_dump("<nexthop?>", nexthop_addr, nexthop_str, sizeof(nexthop_str)); |
Everton Marques | e4f2a2b | 2014-07-16 12:19:40 -0300 | [diff] [blame] | 436 | zlog_warn("%s %s: lookup=%d/%d: zebra returned recursive nexthop %s for address %s dist=%d met=%d", |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 437 | __FILE__, __PRETTY_FUNCTION__, |
Everton Marques | e4f2a2b | 2014-07-16 12:19:40 -0300 | [diff] [blame] | 438 | lookup, max_lookup, nexthop_str, addr_str, |
| 439 | nexthop_tab[0].protocol_distance, |
| 440 | nexthop_tab[0].route_metric); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | addr = nexthop_addr; /* use nexthop addr for recursive lookup */ |
| 444 | |
| 445 | } /* for (max_lookup) */ |
| 446 | |
| 447 | char addr_str[100]; |
| 448 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
| 449 | zlog_warn("%s %s: lookup=%d/%d: failure searching recursive nexthop ifindex for address %s", |
| 450 | __FILE__, __PRETTY_FUNCTION__, |
| 451 | lookup, max_lookup, addr_str); |
| 452 | |
| 453 | return -2; |
| 454 | } |