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 | |
| 25 | #include "zebra/rib.h" |
| 26 | |
Everton Marques | 075ac8d | 2014-09-24 15:18:37 -0300 | [diff] [blame] | 27 | #include "if.h" |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 28 | #include "log.h" |
| 29 | #include "prefix.h" |
| 30 | #include "zclient.h" |
| 31 | #include "stream.h" |
| 32 | #include "network.h" |
| 33 | |
| 34 | #include "pimd.h" |
| 35 | #include "pim_pim.h" |
| 36 | #include "pim_zebra.h" |
| 37 | #include "pim_iface.h" |
| 38 | #include "pim_str.h" |
| 39 | #include "pim_oil.h" |
| 40 | #include "pim_rpf.h" |
| 41 | #include "pim_time.h" |
| 42 | #include "pim_join.h" |
| 43 | #include "pim_zlookup.h" |
| 44 | #include "pim_ifchannel.h" |
| 45 | |
| 46 | #undef PIM_DEBUG_IFADDR_DUMP |
| 47 | #define PIM_DEBUG_IFADDR_DUMP |
| 48 | |
| 49 | static int fib_lookup_if_vif_index(struct in_addr addr); |
| 50 | static int del_oif(struct channel_oil *channel_oil, |
| 51 | struct interface *oif, |
| 52 | uint32_t proto_mask); |
| 53 | |
Everton Marques | 2a0ecf2 | 2014-09-22 18:18:26 -0300 | [diff] [blame] | 54 | static void zclient_broken(struct zclient *zclient) |
| 55 | { |
Everton Marques | 075ac8d | 2014-09-24 15:18:37 -0300 | [diff] [blame] | 56 | struct listnode *ifnode; |
| 57 | struct interface *ifp; |
| 58 | |
Everton Marques | 2a0ecf2 | 2014-09-22 18:18:26 -0300 | [diff] [blame] | 59 | zlog_warn("%s %s: broken zclient connection", |
Everton Marques | 075ac8d | 2014-09-24 15:18:37 -0300 | [diff] [blame] | 60 | __FILE__, __PRETTY_FUNCTION__); |
| 61 | |
| 62 | for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) { |
Everton Marques | 2a0ecf2 | 2014-09-22 18:18:26 -0300 | [diff] [blame] | 63 | pim_if_addr_del_all(ifp); |
Everton Marques | 075ac8d | 2014-09-24 15:18:37 -0300 | [diff] [blame] | 64 | } |
Everton Marques | 2a0ecf2 | 2014-09-22 18:18:26 -0300 | [diff] [blame] | 65 | |
Everton Marques | 96b6dfe | 2014-09-22 15:47:52 -0300 | [diff] [blame] | 66 | /* discard connected addresses because zclient lib will reassign |
| 67 | them upon reconnection */ |
| 68 | if_connected_reset_all(); |
Everton Marques | 075ac8d | 2014-09-24 15:18:37 -0300 | [diff] [blame] | 69 | } |
| 70 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 71 | /* Router-id update message from zebra. */ |
| 72 | static int pim_router_id_update_zebra(int command, struct zclient *zclient, |
| 73 | zebra_size_t length) |
| 74 | { |
| 75 | struct prefix router_id; |
| 76 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 77 | zebra_router_id_update_read(zclient->ibuf, &router_id); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static int pim_zebra_if_add(int command, struct zclient *zclient, |
| 83 | zebra_size_t length) |
| 84 | { |
| 85 | struct interface *ifp; |
| 86 | |
| 87 | /* |
| 88 | zebra api adds/dels interfaces using the same call |
| 89 | interface_add_read below, see comments in lib/zclient.c |
| 90 | */ |
| 91 | ifp = zebra_interface_add_read(zclient->ibuf); |
| 92 | if (!ifp) |
| 93 | return 0; |
| 94 | |
| 95 | if (PIM_DEBUG_ZEBRA) { |
| 96 | zlog_debug("%s: %s index %d flags %ld metric %d mtu %d operative %d", |
| 97 | __PRETTY_FUNCTION__, |
| 98 | ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric, |
| 99 | ifp->mtu, if_is_operative(ifp)); |
| 100 | } |
| 101 | |
| 102 | if (if_is_operative(ifp)) |
| 103 | pim_if_addr_add_all(ifp); |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static int pim_zebra_if_del(int command, struct zclient *zclient, |
| 109 | zebra_size_t length) |
| 110 | { |
| 111 | struct interface *ifp; |
| 112 | |
| 113 | /* |
| 114 | zebra api adds/dels interfaces using the same call |
| 115 | interface_add_read below, see comments in lib/zclient.c |
Savannah SR#108542 | 6ab3e2f | 2014-09-25 16:59:38 -0300 | [diff] [blame] | 116 | |
| 117 | comments in lib/zclient.c seem to indicate that calling |
| 118 | zebra_interface_add_read is the correct call, but that |
| 119 | results in an attemted out of bounds read which causes |
| 120 | pimd to assert. Other clients use zebra_interface_state_read |
| 121 | and it appears to work just fine. |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 122 | */ |
Savannah SR#108542 | 6ab3e2f | 2014-09-25 16:59:38 -0300 | [diff] [blame] | 123 | ifp = zebra_interface_state_read(zclient->ibuf); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 124 | if (!ifp) |
| 125 | return 0; |
| 126 | |
| 127 | if (PIM_DEBUG_ZEBRA) { |
| 128 | zlog_debug("%s: %s index %d flags %ld metric %d mtu %d operative %d", |
| 129 | __PRETTY_FUNCTION__, |
| 130 | ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric, |
| 131 | ifp->mtu, if_is_operative(ifp)); |
| 132 | } |
| 133 | |
| 134 | if (!if_is_operative(ifp)) |
| 135 | pim_if_addr_del_all(ifp); |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | static int pim_zebra_if_state_up(int command, struct zclient *zclient, |
| 141 | zebra_size_t length) |
| 142 | { |
| 143 | struct interface *ifp; |
| 144 | |
| 145 | /* |
| 146 | zebra api notifies interface up/down events by using the same call |
Savannah SR#108542 | 6ab3e2f | 2014-09-25 16:59:38 -0300 | [diff] [blame] | 147 | zebra_interface_state_read below, see comments in lib/zclient.c |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 148 | */ |
| 149 | ifp = zebra_interface_state_read(zclient->ibuf); |
| 150 | if (!ifp) |
| 151 | return 0; |
| 152 | |
Everton Marques | e96f0af | 2009-08-11 15:48:02 -0300 | [diff] [blame] | 153 | zlog_info("INTERFACE UP: %s", ifp->name); |
| 154 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 155 | if (PIM_DEBUG_ZEBRA) { |
| 156 | zlog_debug("%s: %s index %d flags %ld metric %d mtu %d operative %d", |
| 157 | __PRETTY_FUNCTION__, |
| 158 | ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric, |
| 159 | ifp->mtu, if_is_operative(ifp)); |
| 160 | } |
| 161 | |
| 162 | if (if_is_operative(ifp)) { |
| 163 | /* |
| 164 | pim_if_addr_add_all() suffices for bringing up both IGMP and PIM |
| 165 | */ |
| 166 | pim_if_addr_add_all(ifp); |
| 167 | } |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static int pim_zebra_if_state_down(int command, struct zclient *zclient, |
| 173 | zebra_size_t length) |
| 174 | { |
| 175 | struct interface *ifp; |
| 176 | |
| 177 | /* |
| 178 | zebra api notifies interface up/down events by using the same call |
Savannah SR#108542 | 6ab3e2f | 2014-09-25 16:59:38 -0300 | [diff] [blame] | 179 | zebra_interface_state_read below, see comments in lib/zclient.c |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 180 | */ |
| 181 | ifp = zebra_interface_state_read(zclient->ibuf); |
| 182 | if (!ifp) |
| 183 | return 0; |
| 184 | |
Everton Marques | e96f0af | 2009-08-11 15:48:02 -0300 | [diff] [blame] | 185 | zlog_info("INTERFACE DOWN: %s", ifp->name); |
| 186 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 187 | if (PIM_DEBUG_ZEBRA) { |
| 188 | zlog_debug("%s: %s index %d flags %ld metric %d mtu %d operative %d", |
| 189 | __PRETTY_FUNCTION__, |
| 190 | ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric, |
| 191 | ifp->mtu, if_is_operative(ifp)); |
| 192 | } |
| 193 | |
| 194 | if (!if_is_operative(ifp)) { |
| 195 | /* |
| 196 | pim_if_addr_del_all() suffices for shutting down IGMP, |
| 197 | but not for shutting down PIM |
| 198 | */ |
| 199 | pim_if_addr_del_all(ifp); |
| 200 | |
| 201 | /* |
| 202 | pim_sock_delete() closes the socket, stops read and timer threads, |
| 203 | and kills all neighbors. |
| 204 | */ |
Everton Marques | e96f0af | 2009-08-11 15:48:02 -0300 | [diff] [blame] | 205 | if (ifp->info) { |
| 206 | pim_sock_delete(ifp, "link down"); |
| 207 | } |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | #ifdef PIM_DEBUG_IFADDR_DUMP |
| 214 | static void dump_if_address(struct interface *ifp) |
| 215 | { |
| 216 | struct connected *ifc; |
| 217 | struct listnode *node; |
| 218 | |
| 219 | zlog_debug("%s %s: interface %s addresses:", |
| 220 | __FILE__, __PRETTY_FUNCTION__, |
| 221 | ifp->name); |
| 222 | |
| 223 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { |
| 224 | struct prefix *p = ifc->address; |
| 225 | |
| 226 | if (p->family != AF_INET) |
| 227 | continue; |
| 228 | |
Everton Marques | 306c99e | 2014-07-16 15:51:37 -0300 | [diff] [blame] | 229 | zlog_debug("%s %s: interface %s address %s %s", |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 230 | __FILE__, __PRETTY_FUNCTION__, |
| 231 | ifp->name, |
Everton Marques | 306c99e | 2014-07-16 15:51:37 -0300 | [diff] [blame] | 232 | inet_ntoa(p->u.prefix4), |
| 233 | CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY) ? |
| 234 | "secondary" : "primary"); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | #endif |
| 238 | |
| 239 | static int pim_zebra_if_address_add(int command, struct zclient *zclient, |
| 240 | zebra_size_t length) |
| 241 | { |
| 242 | struct connected *c; |
| 243 | struct prefix *p; |
| 244 | |
| 245 | zassert(command == ZEBRA_INTERFACE_ADDRESS_ADD); |
| 246 | |
| 247 | /* |
| 248 | zebra api notifies address adds/dels events by using the same call |
| 249 | interface_add_read below, see comments in lib/zclient.c |
| 250 | |
| 251 | zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD, ...) |
| 252 | will add address to interface list by calling |
| 253 | connected_add_by_prefix() |
| 254 | */ |
| 255 | c = zebra_interface_address_read(command, zclient->ibuf); |
| 256 | if (!c) |
| 257 | return 0; |
| 258 | |
| 259 | p = c->address; |
| 260 | if (p->family != AF_INET) |
| 261 | return 0; |
| 262 | |
| 263 | if (PIM_DEBUG_ZEBRA) { |
| 264 | char buf[BUFSIZ]; |
| 265 | prefix2str(p, buf, BUFSIZ); |
Everton Marques | 306c99e | 2014-07-16 15:51:37 -0300 | [diff] [blame] | 266 | zlog_debug("%s: %s connected IP address %s flags %u %s", |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 267 | __PRETTY_FUNCTION__, |
Everton Marques | 306c99e | 2014-07-16 15:51:37 -0300 | [diff] [blame] | 268 | c->ifp->name, buf, c->flags, |
| 269 | CHECK_FLAG(c->flags, ZEBRA_IFA_SECONDARY) ? "secondary" : "primary"); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 270 | |
| 271 | #ifdef PIM_DEBUG_IFADDR_DUMP |
| 272 | dump_if_address(c->ifp); |
| 273 | #endif |
| 274 | } |
| 275 | |
Everton Marques | 306c99e | 2014-07-16 15:51:37 -0300 | [diff] [blame] | 276 | if (!CHECK_FLAG(c->flags, ZEBRA_IFA_SECONDARY)) { |
| 277 | /* trying to add primary address */ |
| 278 | |
| 279 | struct in_addr primary_addr = pim_find_primary_addr(c->ifp); |
| 280 | if (primary_addr.s_addr != p->u.prefix4.s_addr) { |
| 281 | /* but we had a primary address already */ |
| 282 | |
| 283 | char buf[BUFSIZ]; |
| 284 | char old[100]; |
| 285 | |
| 286 | prefix2str(p, buf, BUFSIZ); |
| 287 | pim_inet4_dump("<old?>", primary_addr, old, sizeof(old)); |
| 288 | |
| 289 | zlog_warn("%s: %s primary addr old=%s: forcing secondary flag on new=%s", |
| 290 | __PRETTY_FUNCTION__, |
| 291 | c->ifp->name, old, buf); |
| 292 | SET_FLAG(c->flags, ZEBRA_IFA_SECONDARY); |
| 293 | } |
| 294 | } |
| 295 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 296 | pim_if_addr_add(c); |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | static int pim_zebra_if_address_del(int command, struct zclient *client, |
| 302 | zebra_size_t length) |
| 303 | { |
| 304 | struct connected *c; |
| 305 | struct prefix *p; |
| 306 | |
| 307 | zassert(command == ZEBRA_INTERFACE_ADDRESS_DELETE); |
| 308 | |
| 309 | /* |
| 310 | zebra api notifies address adds/dels events by using the same call |
| 311 | interface_add_read below, see comments in lib/zclient.c |
| 312 | |
| 313 | zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE, ...) |
| 314 | will remove address from interface list by calling |
| 315 | connected_delete_by_prefix() |
| 316 | */ |
| 317 | c = zebra_interface_address_read(command, client->ibuf); |
| 318 | if (!c) |
| 319 | return 0; |
| 320 | |
| 321 | p = c->address; |
| 322 | if (p->family != AF_INET) |
| 323 | return 0; |
| 324 | |
| 325 | if (PIM_DEBUG_ZEBRA) { |
| 326 | char buf[BUFSIZ]; |
| 327 | prefix2str(p, buf, BUFSIZ); |
Everton Marques | 306c99e | 2014-07-16 15:51:37 -0300 | [diff] [blame] | 328 | zlog_debug("%s: %s disconnected IP address %s flags %u %s", |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 329 | __PRETTY_FUNCTION__, |
Everton Marques | 306c99e | 2014-07-16 15:51:37 -0300 | [diff] [blame] | 330 | c->ifp->name, buf, c->flags, |
| 331 | CHECK_FLAG(c->flags, ZEBRA_IFA_SECONDARY) ? "secondary" : "primary"); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 332 | |
| 333 | #ifdef PIM_DEBUG_IFADDR_DUMP |
| 334 | dump_if_address(c->ifp); |
| 335 | #endif |
| 336 | } |
Everton Marques | 306c99e | 2014-07-16 15:51:37 -0300 | [diff] [blame] | 337 | |
Everton Marques | 2a0ecf2 | 2014-09-22 18:18:26 -0300 | [diff] [blame] | 338 | pim_if_addr_del(c, 0); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | static void scan_upstream_rpf_cache() |
| 344 | { |
| 345 | struct listnode *up_node; |
| 346 | struct listnode *up_nextnode; |
| 347 | struct pim_upstream *up; |
| 348 | |
| 349 | for (ALL_LIST_ELEMENTS(qpim_upstream_list, up_node, up_nextnode, up)) { |
| 350 | struct in_addr old_rpf_addr; |
| 351 | enum pim_rpf_result rpf_result; |
| 352 | |
| 353 | rpf_result = pim_rpf_update(up, &old_rpf_addr); |
| 354 | if (rpf_result == PIM_RPF_FAILURE) |
| 355 | continue; |
| 356 | |
| 357 | if (rpf_result == PIM_RPF_CHANGED) { |
| 358 | |
| 359 | if (up->join_state == PIM_UPSTREAM_JOINED) { |
| 360 | |
| 361 | /* |
| 362 | RFC 4601: 4.5.7. Sending (S,G) Join/Prune Messages |
| 363 | |
| 364 | Transitions from Joined State |
| 365 | |
| 366 | RPF'(S,G) changes not due to an Assert |
| 367 | |
| 368 | The upstream (S,G) state machine remains in Joined |
| 369 | state. Send Join(S,G) to the new upstream neighbor, which is |
| 370 | the new value of RPF'(S,G). Send Prune(S,G) to the old |
| 371 | upstream neighbor, which is the old value of RPF'(S,G). Set |
| 372 | the Join Timer (JT) to expire after t_periodic seconds. |
| 373 | */ |
| 374 | |
| 375 | |
| 376 | /* send Prune(S,G) to the old upstream neighbor */ |
| 377 | pim_joinprune_send(up->rpf.source_nexthop.interface, |
| 378 | old_rpf_addr, |
| 379 | up->source_addr, |
| 380 | up->group_addr, |
| 381 | 0 /* prune */); |
| 382 | |
| 383 | /* send Join(S,G) to the current upstream neighbor */ |
| 384 | pim_joinprune_send(up->rpf.source_nexthop.interface, |
| 385 | up->rpf.rpf_addr, |
| 386 | up->source_addr, |
| 387 | up->group_addr, |
| 388 | 1 /* join */); |
| 389 | |
| 390 | pim_upstream_join_timer_restart(up); |
| 391 | } /* up->join_state == PIM_UPSTREAM_JOINED */ |
| 392 | |
| 393 | /* FIXME can join_desired actually be changed by pim_rpf_update() |
| 394 | returning PIM_RPF_CHANGED ? */ |
| 395 | pim_upstream_update_join_desired(up); |
| 396 | |
| 397 | } /* PIM_RPF_CHANGED */ |
| 398 | |
| 399 | } /* for (qpim_upstream_list) */ |
| 400 | |
| 401 | } |
| 402 | |
Everton Marques | f24200d | 2014-02-14 16:40:34 -0200 | [diff] [blame] | 403 | void pim_scan_oil() |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 404 | { |
| 405 | struct listnode *node; |
| 406 | struct listnode *nextnode; |
| 407 | struct channel_oil *c_oil; |
| 408 | |
Everton Marques | f24200d | 2014-02-14 16:40:34 -0200 | [diff] [blame] | 409 | qpim_scan_oil_last = pim_time_monotonic_sec(); |
| 410 | ++qpim_scan_oil_events; |
| 411 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 412 | for (ALL_LIST_ELEMENTS(qpim_channel_oil_list, node, nextnode, c_oil)) { |
| 413 | int old_vif_index; |
| 414 | int input_iface_vif_index = fib_lookup_if_vif_index(c_oil->oil.mfcc_origin); |
| 415 | if (input_iface_vif_index < 1) { |
| 416 | char source_str[100]; |
| 417 | char group_str[100]; |
| 418 | pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 419 | pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 420 | zlog_warn("%s %s: could not find input interface for (S,G)=(%s,%s)", |
| 421 | __FILE__, __PRETTY_FUNCTION__, |
| 422 | source_str, group_str); |
| 423 | continue; |
| 424 | } |
| 425 | |
| 426 | if (input_iface_vif_index == c_oil->oil.mfcc_parent) { |
| 427 | /* RPF unchanged */ |
| 428 | continue; |
| 429 | } |
| 430 | |
| 431 | if (PIM_DEBUG_ZEBRA) { |
| 432 | struct interface *old_iif = pim_if_find_by_vif_index(c_oil->oil.mfcc_parent); |
| 433 | struct interface *new_iif = pim_if_find_by_vif_index(input_iface_vif_index); |
| 434 | char source_str[100]; |
| 435 | char group_str[100]; |
| 436 | pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 437 | pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 438 | zlog_debug("%s %s: (S,G)=(%s,%s) input interface changed from %s vif_index=%d to %s vif_index=%d", |
| 439 | __FILE__, __PRETTY_FUNCTION__, |
| 440 | source_str, group_str, |
| 441 | old_iif ? old_iif->name : "<old_iif?>", c_oil->oil.mfcc_parent, |
| 442 | new_iif ? new_iif->name : "<new_iif?>", input_iface_vif_index); |
| 443 | } |
| 444 | |
| 445 | /* new iif loops to existing oif ? */ |
| 446 | if (c_oil->oil.mfcc_ttls[input_iface_vif_index]) { |
| 447 | struct interface *new_iif = pim_if_find_by_vif_index(input_iface_vif_index); |
| 448 | |
| 449 | if (PIM_DEBUG_ZEBRA) { |
| 450 | char source_str[100]; |
| 451 | char group_str[100]; |
| 452 | pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 453 | pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 454 | zlog_debug("%s %s: (S,G)=(%s,%s) new iif loops to existing oif: %s vif_index=%d", |
| 455 | __FILE__, __PRETTY_FUNCTION__, |
| 456 | source_str, group_str, |
| 457 | new_iif ? new_iif->name : "<new_iif?>", input_iface_vif_index); |
| 458 | } |
| 459 | |
| 460 | del_oif(c_oil, new_iif, PIM_OIF_FLAG_PROTO_ANY); |
| 461 | } |
| 462 | |
| 463 | /* update iif vif_index */ |
| 464 | old_vif_index = c_oil->oil.mfcc_parent; |
| 465 | c_oil->oil.mfcc_parent = input_iface_vif_index; |
| 466 | |
| 467 | /* update kernel multicast forwarding cache (MFC) */ |
| 468 | if (pim_mroute_add(&c_oil->oil)) { |
| 469 | /* just log warning */ |
| 470 | struct interface *old_iif = pim_if_find_by_vif_index(old_vif_index); |
| 471 | struct interface *new_iif = pim_if_find_by_vif_index(input_iface_vif_index); |
| 472 | char source_str[100]; |
| 473 | char group_str[100]; |
| 474 | pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 475 | pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 476 | zlog_warn("%s %s: (S,G)=(%s,%s) failure updating input interface from %s vif_index=%d to %s vif_index=%d", |
| 477 | __FILE__, __PRETTY_FUNCTION__, |
| 478 | source_str, group_str, |
| 479 | old_iif ? old_iif->name : "<old_iif?>", c_oil->oil.mfcc_parent, |
| 480 | new_iif ? new_iif->name : "<new_iif?>", input_iface_vif_index); |
| 481 | continue; |
| 482 | } |
| 483 | |
| 484 | } /* for (qpim_channel_oil_list) */ |
| 485 | } |
| 486 | |
| 487 | static int on_rpf_cache_refresh(struct thread *t) |
| 488 | { |
| 489 | zassert(t); |
| 490 | zassert(qpim_rpf_cache_refresher); |
| 491 | |
| 492 | qpim_rpf_cache_refresher = 0; |
| 493 | |
| 494 | /* update PIM protocol state */ |
| 495 | scan_upstream_rpf_cache(); |
| 496 | |
| 497 | /* update kernel multicast forwarding cache (MFC) */ |
Everton Marques | f24200d | 2014-02-14 16:40:34 -0200 | [diff] [blame] | 498 | pim_scan_oil(); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 499 | |
Everton Marques | bcc4abe | 2009-08-17 18:18:59 -0300 | [diff] [blame] | 500 | qpim_rpf_cache_refresh_last = pim_time_monotonic_sec(); |
Everton Marques | 613938d | 2009-08-13 15:39:31 -0300 | [diff] [blame] | 501 | ++qpim_rpf_cache_refresh_events; |
| 502 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | static void sched_rpf_cache_refresh() |
| 507 | { |
Everton Marques | 613938d | 2009-08-13 15:39:31 -0300 | [diff] [blame] | 508 | ++qpim_rpf_cache_refresh_requests; |
| 509 | |
| 510 | if (qpim_rpf_cache_refresher) { |
| 511 | /* Refresh timer is already running */ |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 512 | return; |
Everton Marques | 613938d | 2009-08-13 15:39:31 -0300 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | /* Start refresh timer */ |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 516 | |
| 517 | if (PIM_DEBUG_ZEBRA) { |
| 518 | zlog_debug("%s: triggering %ld msec timer", |
| 519 | __PRETTY_FUNCTION__, |
| 520 | qpim_rpf_cache_refresh_delay_msec); |
| 521 | } |
| 522 | |
| 523 | THREAD_TIMER_MSEC_ON(master, qpim_rpf_cache_refresher, |
| 524 | on_rpf_cache_refresh, |
| 525 | 0, qpim_rpf_cache_refresh_delay_msec); |
| 526 | } |
| 527 | |
| 528 | static int redist_read_ipv4_route(int command, struct zclient *zclient, |
| 529 | zebra_size_t length) |
| 530 | { |
| 531 | struct stream *s; |
| 532 | struct zapi_ipv4 api; |
| 533 | unsigned long ifindex; |
| 534 | struct in_addr nexthop; |
| 535 | struct prefix_ipv4 p; |
| 536 | int min_len = 4; |
| 537 | |
| 538 | if (length < min_len) { |
| 539 | zlog_warn("%s %s: short buffer: length=%d min=%d", |
| 540 | __FILE__, __PRETTY_FUNCTION__, |
| 541 | length, min_len); |
| 542 | return -1; |
| 543 | } |
| 544 | |
| 545 | s = zclient->ibuf; |
| 546 | ifindex = 0; |
| 547 | nexthop.s_addr = 0; |
| 548 | |
| 549 | /* Type, flags, message. */ |
| 550 | api.type = stream_getc(s); |
| 551 | api.flags = stream_getc(s); |
| 552 | api.message = stream_getc(s); |
| 553 | |
| 554 | /* IPv4 prefix length. */ |
| 555 | memset(&p, 0, sizeof(struct prefix_ipv4)); |
| 556 | p.family = AF_INET; |
| 557 | p.prefixlen = stream_getc(s); |
| 558 | |
| 559 | min_len += |
| 560 | PSIZE(p.prefixlen) + |
| 561 | CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP) ? 5 : 0 + |
| 562 | CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX) ? 5 : 0 + |
| 563 | CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? 1 : 0 + |
| 564 | CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? 4 : 0; |
| 565 | |
| 566 | if (PIM_DEBUG_ZEBRA) { |
| 567 | zlog_debug("%s %s: length=%d min_len=%d flags=%s%s%s%s", |
| 568 | __FILE__, __PRETTY_FUNCTION__, |
| 569 | length, min_len, |
| 570 | CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP) ? "nh" : "", |
| 571 | CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX) ? " ifi" : "", |
| 572 | CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? " dist" : "", |
| 573 | CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? " metr" : ""); |
| 574 | } |
| 575 | |
| 576 | if (length < min_len) { |
| 577 | zlog_warn("%s %s: short buffer: length=%d min_len=%d flags=%s%s%s%s", |
| 578 | __FILE__, __PRETTY_FUNCTION__, |
| 579 | length, min_len, |
| 580 | CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP) ? "nh" : "", |
| 581 | CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX) ? " ifi" : "", |
| 582 | CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? " dist" : "", |
| 583 | CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? " metr" : ""); |
| 584 | return -1; |
| 585 | } |
| 586 | |
| 587 | /* IPv4 prefix. */ |
| 588 | stream_get(&p.prefix, s, PSIZE(p.prefixlen)); |
| 589 | |
| 590 | /* Nexthop, ifindex, distance, metric. */ |
| 591 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP)) { |
| 592 | api.nexthop_num = stream_getc(s); |
| 593 | nexthop.s_addr = stream_get_ipv4(s); |
| 594 | } |
| 595 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX)) { |
| 596 | api.ifindex_num = stream_getc(s); |
| 597 | ifindex = stream_getl(s); |
| 598 | } |
| 599 | |
| 600 | api.distance = CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? |
David Lamparter | 105ad86 | 2012-02-16 04:50:35 +0000 | [diff] [blame] | 601 | stream_getc(s) : |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 602 | 0; |
| 603 | |
| 604 | api.metric = CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? |
| 605 | stream_getl(s) : |
| 606 | 0; |
| 607 | |
| 608 | switch (command) { |
| 609 | case ZEBRA_IPV4_ROUTE_ADD: |
| 610 | if (PIM_DEBUG_ZEBRA) { |
| 611 | char buf[2][INET_ADDRSTRLEN]; |
| 612 | zlog_debug("%s: add %s %s/%d " |
| 613 | "nexthop %s ifindex %ld metric%s %u distance%s %u", |
| 614 | __PRETTY_FUNCTION__, |
| 615 | zebra_route_string(api.type), |
| 616 | inet_ntop(AF_INET, &p.prefix, buf[0], sizeof(buf[0])), |
| 617 | p.prefixlen, |
| 618 | inet_ntop(AF_INET, &nexthop, buf[1], sizeof(buf[1])), |
| 619 | ifindex, |
| 620 | CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? "-recv" : "-miss", |
| 621 | api.metric, |
| 622 | CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? "-recv" : "-miss", |
| 623 | api.distance); |
| 624 | } |
| 625 | break; |
| 626 | case ZEBRA_IPV4_ROUTE_DELETE: |
| 627 | if (PIM_DEBUG_ZEBRA) { |
| 628 | char buf[2][INET_ADDRSTRLEN]; |
| 629 | zlog_debug("%s: delete %s %s/%d " |
| 630 | "nexthop %s ifindex %ld metric%s %u distance%s %u", |
| 631 | __PRETTY_FUNCTION__, |
| 632 | zebra_route_string(api.type), |
| 633 | inet_ntop(AF_INET, &p.prefix, buf[0], sizeof(buf[0])), |
| 634 | p.prefixlen, |
| 635 | inet_ntop(AF_INET, &nexthop, buf[1], sizeof(buf[1])), |
| 636 | ifindex, |
| 637 | CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? "-recv" : "-miss", |
| 638 | api.metric, |
| 639 | CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? "-recv" : "-miss", |
| 640 | api.distance); |
| 641 | } |
| 642 | break; |
| 643 | default: |
| 644 | zlog_warn("%s: unknown command=%d", __PRETTY_FUNCTION__, command); |
| 645 | return -1; |
| 646 | } |
| 647 | |
| 648 | sched_rpf_cache_refresh(); |
| 649 | |
| 650 | return 0; |
| 651 | } |
| 652 | |
Everton Marques | 1f29894 | 2014-08-21 15:47:28 -0300 | [diff] [blame] | 653 | void pim_zebra_init(char *zebra_sock_path) |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 654 | { |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 655 | int i; |
| 656 | |
Everton Marques | 1f29894 | 2014-08-21 15:47:28 -0300 | [diff] [blame] | 657 | if (zebra_sock_path) |
| 658 | zclient_serv_path_set(zebra_sock_path); |
| 659 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 660 | #ifdef HAVE_TCP_ZEBRA |
| 661 | zlog_notice("zclient update contacting ZEBRA daemon at socket TCP %s,%d", "127.0.0.1", ZEBRA_PORT); |
| 662 | #else |
Everton Marques | 1f29894 | 2014-08-21 15:47:28 -0300 | [diff] [blame] | 663 | zlog_notice("zclient update contacting ZEBRA daemon at socket UNIX %s", zclient_serv_path_get()); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 664 | #endif |
| 665 | |
| 666 | /* Socket for receiving updates from Zebra daemon */ |
Everton Marques | 3456a80 | 2014-07-22 14:52:57 -0300 | [diff] [blame] | 667 | qpim_zclient_update = zclient_new(); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 668 | |
Everton Marques | 3456a80 | 2014-07-22 14:52:57 -0300 | [diff] [blame] | 669 | qpim_zclient_update->zclient_broken = zclient_broken; |
| 670 | qpim_zclient_update->router_id_update = pim_router_id_update_zebra; |
| 671 | qpim_zclient_update->interface_add = pim_zebra_if_add; |
| 672 | qpim_zclient_update->interface_delete = pim_zebra_if_del; |
| 673 | qpim_zclient_update->interface_up = pim_zebra_if_state_up; |
| 674 | qpim_zclient_update->interface_down = pim_zebra_if_state_down; |
| 675 | qpim_zclient_update->interface_address_add = pim_zebra_if_address_add; |
| 676 | qpim_zclient_update->interface_address_delete = pim_zebra_if_address_del; |
| 677 | qpim_zclient_update->ipv4_route_add = redist_read_ipv4_route; |
| 678 | qpim_zclient_update->ipv4_route_delete = redist_read_ipv4_route; |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 679 | |
Everton Marques | c1b228c | 2014-08-27 15:27:26 -0300 | [diff] [blame] | 680 | if (PIM_DEBUG_PIM_TRACE) { |
| 681 | zlog_info("zclient_init cleared redistribution request"); |
| 682 | } |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 683 | |
Everton Marques | 8150bee | 2014-09-29 17:58:30 -0300 | [diff] [blame] | 684 | zclient_init(qpim_zclient_update, ZEBRA_ROUTE_PIM); |
| 685 | |
Everton Marques | 3456a80 | 2014-07-22 14:52:57 -0300 | [diff] [blame] | 686 | zassert(qpim_zclient_update->redist_default == ZEBRA_ROUTE_PIM); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 687 | |
| 688 | /* Request all redistribution */ |
| 689 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { |
Everton Marques | 3456a80 | 2014-07-22 14:52:57 -0300 | [diff] [blame] | 690 | if (i == qpim_zclient_update->redist_default) |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 691 | continue; |
Everton Marques | 3456a80 | 2014-07-22 14:52:57 -0300 | [diff] [blame] | 692 | qpim_zclient_update->redist[i] = 1; |
Everton Marques | c1b228c | 2014-08-27 15:27:26 -0300 | [diff] [blame] | 693 | if (PIM_DEBUG_PIM_TRACE) { |
| 694 | zlog_debug("%s: requesting redistribution for %s (%i)", |
| 695 | __PRETTY_FUNCTION__, zebra_route_string(i), i); |
| 696 | } |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /* Request default information */ |
Everton Marques | 3456a80 | 2014-07-22 14:52:57 -0300 | [diff] [blame] | 700 | qpim_zclient_update->default_information = 1; |
Everton Marques | c1b228c | 2014-08-27 15:27:26 -0300 | [diff] [blame] | 701 | if (PIM_DEBUG_PIM_TRACE) { |
| 702 | zlog_info("%s: requesting default information redistribution", |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 703 | __PRETTY_FUNCTION__); |
| 704 | |
Everton Marques | c1b228c | 2014-08-27 15:27:26 -0300 | [diff] [blame] | 705 | zlog_notice("%s: zclient update socket initialized", |
| 706 | __PRETTY_FUNCTION__); |
| 707 | } |
| 708 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 709 | zassert(!qpim_zclient_lookup); |
| 710 | qpim_zclient_lookup = zclient_lookup_new(); |
| 711 | zassert(qpim_zclient_lookup); |
| 712 | } |
| 713 | |
| 714 | void igmp_anysource_forward_start(struct igmp_group *group) |
| 715 | { |
| 716 | /* Any source (*,G) is forwarded only if mode is EXCLUDE {empty} */ |
| 717 | zassert(group->group_filtermode_isexcl); |
| 718 | zassert(listcount(group->group_source_list) < 1); |
| 719 | |
| 720 | if (PIM_DEBUG_IGMP_TRACE) { |
| 721 | zlog_debug("%s %s: UNIMPLEMENTED", |
| 722 | __FILE__, __PRETTY_FUNCTION__); |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | void igmp_anysource_forward_stop(struct igmp_group *group) |
| 727 | { |
| 728 | /* Any source (*,G) is forwarded only if mode is EXCLUDE {empty} */ |
| 729 | zassert((!group->group_filtermode_isexcl) || (listcount(group->group_source_list) > 0)); |
| 730 | |
| 731 | if (PIM_DEBUG_IGMP_TRACE) { |
| 732 | zlog_debug("%s %s: UNIMPLEMENTED", |
| 733 | __FILE__, __PRETTY_FUNCTION__); |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | static int fib_lookup_if_vif_index(struct in_addr addr) |
| 738 | { |
| 739 | struct pim_zlookup_nexthop nexthop_tab[PIM_NEXTHOP_IFINDEX_TAB_SIZE]; |
| 740 | int num_ifindex; |
| 741 | int vif_index; |
| 742 | int first_ifindex; |
| 743 | |
| 744 | num_ifindex = zclient_lookup_nexthop(qpim_zclient_lookup, nexthop_tab, |
| 745 | PIM_NEXTHOP_IFINDEX_TAB_SIZE, addr, |
| 746 | PIM_NEXTHOP_LOOKUP_MAX); |
| 747 | if (num_ifindex < 1) { |
| 748 | char addr_str[100]; |
| 749 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
| 750 | zlog_warn("%s %s: could not find nexthop ifindex for address %s", |
| 751 | __FILE__, __PRETTY_FUNCTION__, |
| 752 | addr_str); |
| 753 | return -1; |
| 754 | } |
| 755 | |
| 756 | first_ifindex = nexthop_tab[0].ifindex; |
| 757 | |
| 758 | if (num_ifindex > 1) { |
| 759 | char addr_str[100]; |
| 760 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
| 761 | zlog_debug("%s %s: FIXME ignoring multiple nexthop ifindex'es num_ifindex=%d for address %s (using only ifindex=%d)", |
| 762 | __FILE__, __PRETTY_FUNCTION__, |
| 763 | num_ifindex, addr_str, first_ifindex); |
| 764 | /* debug warning only, do not return */ |
| 765 | } |
| 766 | |
| 767 | if (PIM_DEBUG_ZEBRA) { |
| 768 | char addr_str[100]; |
| 769 | pim_inet4_dump("<ifaddr?>", addr, addr_str, sizeof(addr_str)); |
| 770 | zlog_debug("%s %s: found nexthop ifindex=%d (interface %s) for address %s", |
| 771 | __FILE__, __PRETTY_FUNCTION__, |
| 772 | first_ifindex, ifindex2ifname(first_ifindex), addr_str); |
| 773 | } |
| 774 | |
| 775 | vif_index = pim_if_find_vifindex_by_ifindex(first_ifindex); |
| 776 | |
| 777 | if (vif_index < 1) { |
| 778 | char addr_str[100]; |
| 779 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
| 780 | zlog_warn("%s %s: low vif_index=%d < 1 nexthop for address %s", |
| 781 | __FILE__, __PRETTY_FUNCTION__, |
| 782 | vif_index, addr_str); |
| 783 | return -2; |
| 784 | } |
| 785 | |
| 786 | zassert(qpim_mroute_oif_highest_vif_index < MAXVIFS); |
| 787 | |
| 788 | if (vif_index > qpim_mroute_oif_highest_vif_index) { |
| 789 | char addr_str[100]; |
| 790 | pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); |
| 791 | zlog_warn("%s %s: high vif_index=%d > highest_vif_index=%d nexthop for address %s", |
| 792 | __FILE__, __PRETTY_FUNCTION__, |
| 793 | vif_index, qpim_mroute_oif_highest_vif_index, addr_str); |
| 794 | |
| 795 | zlog_warn("%s %s: pim disabled on interface %s vif_index=%d ?", |
| 796 | __FILE__, __PRETTY_FUNCTION__, |
| 797 | ifindex2ifname(vif_index), |
| 798 | vif_index); |
| 799 | |
| 800 | return -3; |
| 801 | } |
| 802 | |
| 803 | return vif_index; |
| 804 | } |
| 805 | |
| 806 | static int add_oif(struct channel_oil *channel_oil, |
| 807 | struct interface *oif, |
| 808 | uint32_t proto_mask) |
| 809 | { |
| 810 | struct pim_interface *pim_ifp; |
| 811 | int old_ttl; |
| 812 | |
| 813 | zassert(channel_oil); |
| 814 | |
| 815 | pim_ifp = oif->info; |
| 816 | |
Everton Marques | 67faabc | 2010-02-23 12:11:11 -0300 | [diff] [blame] | 817 | if (PIM_DEBUG_MROUTE) { |
| 818 | char group_str[100]; |
| 819 | char source_str[100]; |
| 820 | pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 821 | pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 822 | zlog_debug("%s %s: (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d", |
| 823 | __FILE__, __PRETTY_FUNCTION__, |
| 824 | source_str, group_str, |
| 825 | proto_mask, oif->name, pim_ifp->mroute_vif_index); |
| 826 | } |
| 827 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 828 | if (pim_ifp->mroute_vif_index < 1) { |
| 829 | zlog_warn("%s %s: interface %s vif_index=%d < 1", |
| 830 | __FILE__, __PRETTY_FUNCTION__, |
| 831 | oif->name, pim_ifp->mroute_vif_index); |
| 832 | return -1; |
| 833 | } |
| 834 | |
| 835 | #ifdef PIM_ENFORCE_LOOPFREE_MFC |
| 836 | /* |
| 837 | Prevent creating MFC entry with OIF=IIF. |
| 838 | |
| 839 | This is a protection against implementation mistakes. |
| 840 | |
| 841 | PIM protocol implicitely ensures loopfree multicast topology. |
| 842 | |
| 843 | IGMP must be protected against adding looped MFC entries created |
| 844 | by both source and receiver attached to the same interface. See |
| 845 | TODO T22. |
| 846 | */ |
| 847 | if (pim_ifp->mroute_vif_index == channel_oil->oil.mfcc_parent) { |
| 848 | char group_str[100]; |
| 849 | char source_str[100]; |
| 850 | pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 851 | pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 852 | zlog_warn("%s %s: refusing protocol mask %u request for IIF=OIF=%s (vif_index=%d) for channel (S,G)=(%s,%s)", |
| 853 | __FILE__, __PRETTY_FUNCTION__, |
| 854 | proto_mask, oif->name, pim_ifp->mroute_vif_index, |
| 855 | source_str, group_str); |
| 856 | return -2; |
| 857 | } |
| 858 | #endif |
| 859 | |
| 860 | zassert(qpim_mroute_oif_highest_vif_index < MAXVIFS); |
| 861 | zassert(pim_ifp->mroute_vif_index <= qpim_mroute_oif_highest_vif_index); |
| 862 | |
| 863 | /* Prevent single protocol from subscribing same interface to |
| 864 | channel (S,G) multiple times */ |
| 865 | if (channel_oil->oif_flags[pim_ifp->mroute_vif_index] & proto_mask) { |
| 866 | char group_str[100]; |
| 867 | char source_str[100]; |
| 868 | pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 869 | pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 870 | zlog_warn("%s %s: existing protocol mask %u requested OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%s,%s)", |
| 871 | __FILE__, __PRETTY_FUNCTION__, |
| 872 | proto_mask, oif->name, pim_ifp->mroute_vif_index, |
| 873 | channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index], |
| 874 | source_str, group_str); |
| 875 | return -3; |
| 876 | } |
| 877 | |
| 878 | /* Allow other protocol to request subscription of same interface to |
| 879 | channel (S,G) multiple times, by silently ignoring further |
| 880 | requests */ |
| 881 | if (channel_oil->oif_flags[pim_ifp->mroute_vif_index] & PIM_OIF_FLAG_PROTO_ANY) { |
| 882 | |
| 883 | /* Check the OIF really exists before returning, and only log |
| 884 | warning otherwise */ |
| 885 | if (channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] < 1) { |
| 886 | char group_str[100]; |
| 887 | char source_str[100]; |
| 888 | pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 889 | pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 890 | zlog_warn("%s %s: new protocol mask %u requested nonexistent OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%s,%s)", |
| 891 | __FILE__, __PRETTY_FUNCTION__, |
| 892 | proto_mask, oif->name, pim_ifp->mroute_vif_index, |
| 893 | channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index], |
| 894 | source_str, group_str); |
| 895 | } |
| 896 | |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | old_ttl = channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index]; |
| 901 | |
| 902 | if (old_ttl > 0) { |
| 903 | char group_str[100]; |
| 904 | char source_str[100]; |
| 905 | pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 906 | pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 907 | zlog_warn("%s %s: interface %s (vif_index=%d) is existing output for channel (S,G)=(%s,%s)", |
| 908 | __FILE__, __PRETTY_FUNCTION__, |
| 909 | oif->name, pim_ifp->mroute_vif_index, |
| 910 | source_str, group_str); |
| 911 | return -4; |
| 912 | } |
| 913 | |
| 914 | channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] = PIM_MROUTE_MIN_TTL; |
| 915 | |
| 916 | if (pim_mroute_add(&channel_oil->oil)) { |
| 917 | char group_str[100]; |
| 918 | char source_str[100]; |
| 919 | pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 920 | pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 921 | zlog_warn("%s %s: could not add output interface %s (vif_index=%d) for channel (S,G)=(%s,%s)", |
| 922 | __FILE__, __PRETTY_FUNCTION__, |
| 923 | oif->name, pim_ifp->mroute_vif_index, |
| 924 | source_str, group_str); |
| 925 | |
| 926 | channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] = old_ttl; |
| 927 | return -5; |
| 928 | } |
| 929 | |
| 930 | channel_oil->oif_creation[pim_ifp->mroute_vif_index] = pim_time_monotonic_sec(); |
| 931 | ++channel_oil->oil_size; |
| 932 | channel_oil->oif_flags[pim_ifp->mroute_vif_index] |= proto_mask; |
| 933 | |
Everton Marques | 67faabc | 2010-02-23 12:11:11 -0300 | [diff] [blame] | 934 | if (PIM_DEBUG_MROUTE) { |
| 935 | char group_str[100]; |
| 936 | char source_str[100]; |
| 937 | pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 938 | pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 939 | zlog_debug("%s %s: (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d: DONE", |
| 940 | __FILE__, __PRETTY_FUNCTION__, |
| 941 | source_str, group_str, |
| 942 | proto_mask, oif->name, pim_ifp->mroute_vif_index); |
| 943 | } |
| 944 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 945 | return 0; |
| 946 | } |
| 947 | |
| 948 | static int del_oif(struct channel_oil *channel_oil, |
| 949 | struct interface *oif, |
| 950 | uint32_t proto_mask) |
| 951 | { |
| 952 | struct pim_interface *pim_ifp; |
| 953 | int old_ttl; |
| 954 | |
| 955 | zassert(channel_oil); |
| 956 | |
| 957 | pim_ifp = oif->info; |
| 958 | |
| 959 | zassert(pim_ifp->mroute_vif_index >= 1); |
| 960 | zassert(qpim_mroute_oif_highest_vif_index < MAXVIFS); |
| 961 | zassert(pim_ifp->mroute_vif_index <= qpim_mroute_oif_highest_vif_index); |
| 962 | |
Everton Marques | 67faabc | 2010-02-23 12:11:11 -0300 | [diff] [blame] | 963 | if (PIM_DEBUG_MROUTE) { |
| 964 | char group_str[100]; |
| 965 | char source_str[100]; |
| 966 | pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 967 | pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 968 | zlog_debug("%s %s: (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d", |
| 969 | __FILE__, __PRETTY_FUNCTION__, |
| 970 | source_str, group_str, |
| 971 | proto_mask, oif->name, pim_ifp->mroute_vif_index); |
| 972 | } |
| 973 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 974 | /* Prevent single protocol from unsubscribing same interface from |
| 975 | channel (S,G) multiple times */ |
| 976 | if (!(channel_oil->oif_flags[pim_ifp->mroute_vif_index] & proto_mask)) { |
| 977 | char group_str[100]; |
| 978 | char source_str[100]; |
| 979 | pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 980 | pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 981 | zlog_warn("%s %s: nonexistent protocol mask %u removed OIF %s (vif_index=%d, min_ttl=%d) from channel (S,G)=(%s,%s)", |
| 982 | __FILE__, __PRETTY_FUNCTION__, |
| 983 | proto_mask, oif->name, pim_ifp->mroute_vif_index, |
| 984 | channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index], |
| 985 | source_str, group_str); |
| 986 | return -2; |
| 987 | } |
| 988 | |
| 989 | /* Mark that protocol is no longer interested in this OIF */ |
| 990 | channel_oil->oif_flags[pim_ifp->mroute_vif_index] &= ~proto_mask; |
| 991 | |
| 992 | /* Allow multiple protocols to unsubscribe same interface from |
| 993 | channel (S,G) multiple times, by silently ignoring requests while |
| 994 | there is at least one protocol interested in the channel */ |
| 995 | if (channel_oil->oif_flags[pim_ifp->mroute_vif_index] & PIM_OIF_FLAG_PROTO_ANY) { |
| 996 | |
| 997 | /* Check the OIF keeps existing before returning, and only log |
| 998 | warning otherwise */ |
| 999 | if (channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] < 1) { |
| 1000 | char group_str[100]; |
| 1001 | char source_str[100]; |
| 1002 | pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 1003 | pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 1004 | zlog_warn("%s %s: protocol mask %u removing nonexistent OIF %s (vif_index=%d, min_ttl=%d) from channel (S,G)=(%s,%s)", |
| 1005 | __FILE__, __PRETTY_FUNCTION__, |
| 1006 | proto_mask, oif->name, pim_ifp->mroute_vif_index, |
| 1007 | channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index], |
| 1008 | source_str, group_str); |
| 1009 | } |
| 1010 | |
| 1011 | return 0; |
| 1012 | } |
| 1013 | |
| 1014 | old_ttl = channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index]; |
| 1015 | |
| 1016 | if (old_ttl < 1) { |
| 1017 | char group_str[100]; |
| 1018 | char source_str[100]; |
| 1019 | pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 1020 | pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 1021 | zlog_warn("%s %s: interface %s (vif_index=%d) is not output for channel (S,G)=(%s,%s)", |
| 1022 | __FILE__, __PRETTY_FUNCTION__, |
| 1023 | oif->name, pim_ifp->mroute_vif_index, |
| 1024 | source_str, group_str); |
| 1025 | return -3; |
| 1026 | } |
| 1027 | |
| 1028 | channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] = 0; |
| 1029 | |
| 1030 | if (pim_mroute_add(&channel_oil->oil)) { |
| 1031 | char group_str[100]; |
| 1032 | char source_str[100]; |
| 1033 | pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 1034 | pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 1035 | zlog_warn("%s %s: could not remove output interface %s (vif_index=%d) from channel (S,G)=(%s,%s)", |
| 1036 | __FILE__, __PRETTY_FUNCTION__, |
| 1037 | oif->name, pim_ifp->mroute_vif_index, |
| 1038 | source_str, group_str); |
| 1039 | |
| 1040 | channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] = old_ttl; |
| 1041 | return -4; |
| 1042 | } |
| 1043 | |
| 1044 | --channel_oil->oil_size; |
| 1045 | |
| 1046 | if (channel_oil->oil_size < 1) { |
| 1047 | if (pim_mroute_del(&channel_oil->oil)) { |
| 1048 | /* just log a warning in case of failure */ |
| 1049 | char group_str[100]; |
| 1050 | char source_str[100]; |
| 1051 | pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 1052 | pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 1053 | zlog_warn("%s %s: failure removing OIL for channel (S,G)=(%s,%s)", |
| 1054 | __FILE__, __PRETTY_FUNCTION__, |
| 1055 | source_str, group_str); |
| 1056 | } |
| 1057 | } |
| 1058 | |
Everton Marques | 67faabc | 2010-02-23 12:11:11 -0300 | [diff] [blame] | 1059 | if (PIM_DEBUG_MROUTE) { |
| 1060 | char group_str[100]; |
| 1061 | char source_str[100]; |
| 1062 | pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str)); |
| 1063 | pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str)); |
| 1064 | zlog_debug("%s %s: (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d: DONE", |
| 1065 | __FILE__, __PRETTY_FUNCTION__, |
| 1066 | source_str, group_str, |
| 1067 | proto_mask, oif->name, pim_ifp->mroute_vif_index); |
| 1068 | } |
| 1069 | |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 1070 | return 0; |
| 1071 | } |
| 1072 | |
| 1073 | void igmp_source_forward_start(struct igmp_source *source) |
| 1074 | { |
| 1075 | struct igmp_group *group; |
| 1076 | |
| 1077 | if (PIM_DEBUG_IGMP_TRACE) { |
| 1078 | char source_str[100]; |
| 1079 | char group_str[100]; |
| 1080 | pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str)); |
| 1081 | pim_inet4_dump("<group?>", source->source_group->group_addr, group_str, sizeof(group_str)); |
| 1082 | zlog_debug("%s: (S,G)=(%s,%s) igmp_sock=%d oif=%s fwd=%d", |
| 1083 | __PRETTY_FUNCTION__, |
| 1084 | source_str, group_str, |
| 1085 | source->source_group->group_igmp_sock->fd, |
| 1086 | source->source_group->group_igmp_sock->interface->name, |
| 1087 | IGMP_SOURCE_TEST_FORWARDING(source->source_flags)); |
| 1088 | } |
| 1089 | |
| 1090 | /* Prevent IGMP interface from installing multicast route multiple |
| 1091 | times */ |
| 1092 | if (IGMP_SOURCE_TEST_FORWARDING(source->source_flags)) { |
| 1093 | return; |
| 1094 | } |
| 1095 | |
| 1096 | group = source->source_group; |
| 1097 | |
| 1098 | if (!source->source_channel_oil) { |
| 1099 | struct pim_interface *pim_oif; |
| 1100 | int input_iface_vif_index = fib_lookup_if_vif_index(source->source_addr); |
| 1101 | if (input_iface_vif_index < 1) { |
| 1102 | char source_str[100]; |
| 1103 | pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str)); |
| 1104 | zlog_warn("%s %s: could not find input interface for source %s", |
| 1105 | __FILE__, __PRETTY_FUNCTION__, |
| 1106 | source_str); |
| 1107 | return; |
| 1108 | } |
| 1109 | |
| 1110 | /* |
| 1111 | Protect IGMP against adding looped MFC entries created by both |
| 1112 | source and receiver attached to the same interface. See TODO |
| 1113 | T22. |
| 1114 | */ |
| 1115 | pim_oif = source->source_group->group_igmp_sock->interface->info; |
| 1116 | if (!pim_oif) { |
| 1117 | zlog_warn("%s: multicast not enabled on oif=%s ?", |
| 1118 | __PRETTY_FUNCTION__, |
| 1119 | source->source_group->group_igmp_sock->interface->name); |
| 1120 | return; |
| 1121 | } |
| 1122 | if (pim_oif->mroute_vif_index < 1) { |
| 1123 | zlog_warn("%s %s: oif=%s vif_index=%d < 1", |
| 1124 | __FILE__, __PRETTY_FUNCTION__, |
| 1125 | source->source_group->group_igmp_sock->interface->name, |
| 1126 | pim_oif->mroute_vif_index); |
| 1127 | return; |
| 1128 | } |
| 1129 | if (input_iface_vif_index == pim_oif->mroute_vif_index) { |
| 1130 | /* ignore request for looped MFC entry */ |
| 1131 | if (PIM_DEBUG_IGMP_TRACE) { |
| 1132 | char source_str[100]; |
| 1133 | char group_str[100]; |
| 1134 | pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str)); |
| 1135 | pim_inet4_dump("<group?>", source->source_group->group_addr, group_str, sizeof(group_str)); |
| 1136 | zlog_debug("%s: ignoring request for looped MFC entry (S,G)=(%s,%s): igmp_sock=%d oif=%s vif_index=%d", |
| 1137 | __PRETTY_FUNCTION__, |
| 1138 | source_str, group_str, |
| 1139 | source->source_group->group_igmp_sock->fd, |
| 1140 | source->source_group->group_igmp_sock->interface->name, |
| 1141 | input_iface_vif_index); |
| 1142 | } |
| 1143 | return; |
| 1144 | } |
| 1145 | |
| 1146 | source->source_channel_oil = pim_channel_oil_add(group->group_addr, |
| 1147 | source->source_addr, |
| 1148 | input_iface_vif_index); |
| 1149 | if (!source->source_channel_oil) { |
| 1150 | char group_str[100]; |
| 1151 | char source_str[100]; |
| 1152 | pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str)); |
| 1153 | pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str)); |
| 1154 | zlog_warn("%s %s: could not create OIL for channel (S,G)=(%s,%s)", |
| 1155 | __FILE__, __PRETTY_FUNCTION__, |
| 1156 | source_str, group_str); |
| 1157 | return; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | if (add_oif(source->source_channel_oil, |
| 1162 | group->group_igmp_sock->interface, |
| 1163 | PIM_OIF_FLAG_PROTO_IGMP)) { |
| 1164 | return; |
| 1165 | } |
| 1166 | |
| 1167 | /* |
| 1168 | Feed IGMPv3-gathered local membership information into PIM |
| 1169 | per-interface (S,G) state. |
| 1170 | */ |
| 1171 | pim_ifchannel_local_membership_add(group->group_igmp_sock->interface, |
| 1172 | source->source_addr, group->group_addr); |
| 1173 | |
| 1174 | IGMP_SOURCE_DO_FORWARDING(source->source_flags); |
| 1175 | } |
| 1176 | |
| 1177 | void igmp_source_forward_stop(struct igmp_source *source) |
| 1178 | { |
| 1179 | struct igmp_group *group; |
| 1180 | |
| 1181 | if (PIM_DEBUG_IGMP_TRACE) { |
| 1182 | char source_str[100]; |
| 1183 | char group_str[100]; |
| 1184 | pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str)); |
| 1185 | pim_inet4_dump("<group?>", source->source_group->group_addr, group_str, sizeof(group_str)); |
| 1186 | zlog_debug("%s: (S,G)=(%s,%s) igmp_sock=%d oif=%s fwd=%d", |
| 1187 | __PRETTY_FUNCTION__, |
| 1188 | source_str, group_str, |
| 1189 | source->source_group->group_igmp_sock->fd, |
| 1190 | source->source_group->group_igmp_sock->interface->name, |
| 1191 | IGMP_SOURCE_TEST_FORWARDING(source->source_flags)); |
| 1192 | } |
| 1193 | |
| 1194 | /* Prevent IGMP interface from removing multicast route multiple |
| 1195 | times */ |
| 1196 | if (!IGMP_SOURCE_TEST_FORWARDING(source->source_flags)) { |
| 1197 | return; |
| 1198 | } |
| 1199 | |
| 1200 | group = source->source_group; |
| 1201 | |
Savannah SR#108542 | ecc1fb9 | 2014-09-25 14:41:43 -0300 | [diff] [blame] | 1202 | /* |
| 1203 | It appears that in certain circumstances that |
| 1204 | igmp_source_forward_stop is called when IGMP forwarding |
| 1205 | was not enabled in oif_flags for this outgoing interface. |
| 1206 | Possibly because of multiple calls. When that happens, we |
| 1207 | enter the below if statement and this function returns early |
| 1208 | which in turn triggers the calling function to assert. |
| 1209 | Making the call to del_oif and ignoring the return code |
| 1210 | fixes the issue without ill effect, similar to |
| 1211 | pim_forward_stop below. |
| 1212 | */ |
| 1213 | /*if (del_oif(source->source_channel_oil, |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 1214 | group->group_igmp_sock->interface, |
| 1215 | PIM_OIF_FLAG_PROTO_IGMP)) { |
| 1216 | return; |
Savannah SR#108542 | ecc1fb9 | 2014-09-25 14:41:43 -0300 | [diff] [blame] | 1217 | }*/ |
| 1218 | del_oif(source->source_channel_oil, |
| 1219 | group->group_igmp_sock->interface, |
| 1220 | PIM_OIF_FLAG_PROTO_IGMP); |
Everton Marques | 871dbcf | 2009-08-11 15:43:05 -0300 | [diff] [blame] | 1221 | |
| 1222 | /* |
| 1223 | Feed IGMPv3-gathered local membership information into PIM |
| 1224 | per-interface (S,G) state. |
| 1225 | */ |
| 1226 | pim_ifchannel_local_membership_del(group->group_igmp_sock->interface, |
| 1227 | source->source_addr, group->group_addr); |
| 1228 | |
| 1229 | IGMP_SOURCE_DONT_FORWARDING(source->source_flags); |
| 1230 | } |
| 1231 | |
| 1232 | void pim_forward_start(struct pim_ifchannel *ch) |
| 1233 | { |
| 1234 | struct pim_upstream *up = ch->upstream; |
| 1235 | |
| 1236 | if (PIM_DEBUG_PIM_TRACE) { |
| 1237 | char source_str[100]; |
| 1238 | char group_str[100]; |
| 1239 | pim_inet4_dump("<source?>", ch->source_addr, source_str, sizeof(source_str)); |
| 1240 | pim_inet4_dump("<group?>", ch->group_addr, group_str, sizeof(group_str)); |
| 1241 | zlog_debug("%s: (S,G)=(%s,%s) oif=%s", |
| 1242 | __PRETTY_FUNCTION__, |
| 1243 | source_str, group_str, ch->interface->name); |
| 1244 | } |
| 1245 | |
| 1246 | if (!up->channel_oil) { |
| 1247 | int input_iface_vif_index = fib_lookup_if_vif_index(up->source_addr); |
| 1248 | if (input_iface_vif_index < 1) { |
| 1249 | char source_str[100]; |
| 1250 | pim_inet4_dump("<source?>", up->source_addr, source_str, sizeof(source_str)); |
| 1251 | zlog_warn("%s %s: could not find input interface for source %s", |
| 1252 | __FILE__, __PRETTY_FUNCTION__, |
| 1253 | source_str); |
| 1254 | return; |
| 1255 | } |
| 1256 | |
| 1257 | up->channel_oil = pim_channel_oil_add(up->group_addr, up->source_addr, |
| 1258 | input_iface_vif_index); |
| 1259 | if (!up->channel_oil) { |
| 1260 | char group_str[100]; |
| 1261 | char source_str[100]; |
| 1262 | pim_inet4_dump("<group?>", up->group_addr, group_str, sizeof(group_str)); |
| 1263 | pim_inet4_dump("<source?>", up->source_addr, source_str, sizeof(source_str)); |
| 1264 | zlog_warn("%s %s: could not create OIL for channel (S,G)=(%s,%s)", |
| 1265 | __FILE__, __PRETTY_FUNCTION__, |
| 1266 | source_str, group_str); |
| 1267 | return; |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | add_oif(up->channel_oil, |
| 1272 | ch->interface, |
| 1273 | PIM_OIF_FLAG_PROTO_PIM); |
| 1274 | } |
| 1275 | |
| 1276 | void pim_forward_stop(struct pim_ifchannel *ch) |
| 1277 | { |
| 1278 | struct pim_upstream *up = ch->upstream; |
| 1279 | |
| 1280 | if (PIM_DEBUG_PIM_TRACE) { |
| 1281 | char source_str[100]; |
| 1282 | char group_str[100]; |
| 1283 | pim_inet4_dump("<source?>", ch->source_addr, source_str, sizeof(source_str)); |
| 1284 | pim_inet4_dump("<group?>", ch->group_addr, group_str, sizeof(group_str)); |
| 1285 | zlog_debug("%s: (S,G)=(%s,%s) oif=%s", |
| 1286 | __PRETTY_FUNCTION__, |
| 1287 | source_str, group_str, ch->interface->name); |
| 1288 | } |
| 1289 | |
| 1290 | if (!up->channel_oil) { |
| 1291 | char source_str[100]; |
| 1292 | char group_str[100]; |
| 1293 | pim_inet4_dump("<source?>", ch->source_addr, source_str, sizeof(source_str)); |
| 1294 | pim_inet4_dump("<group?>", ch->group_addr, group_str, sizeof(group_str)); |
| 1295 | zlog_warn("%s: (S,G)=(%s,%s) oif=%s missing channel OIL", |
| 1296 | __PRETTY_FUNCTION__, |
| 1297 | source_str, group_str, ch->interface->name); |
| 1298 | |
| 1299 | return; |
| 1300 | } |
| 1301 | |
| 1302 | del_oif(up->channel_oil, |
| 1303 | ch->interface, |
| 1304 | PIM_OIF_FLAG_PROTO_PIM); |
| 1305 | } |