pim_zebra.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  1. /*
  2. PIM for Quagga
  3. Copyright (C) 2008 Everton da Silva Marques
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; see the file COPYING; if not, write to the
  14. Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  15. MA 02110-1301 USA
  16. $QuaggaId: $Format:%an, %ai, %h$ $
  17. */
  18. #include <zebra.h>
  19. #include "zebra/rib.h"
  20. #include "log.h"
  21. #include "prefix.h"
  22. #include "zclient.h"
  23. #include "stream.h"
  24. #include "network.h"
  25. #include "pimd.h"
  26. #include "pim_pim.h"
  27. #include "pim_zebra.h"
  28. #include "pim_iface.h"
  29. #include "pim_str.h"
  30. #include "pim_oil.h"
  31. #include "pim_rpf.h"
  32. #include "pim_time.h"
  33. #include "pim_join.h"
  34. #include "pim_zlookup.h"
  35. #include "pim_ifchannel.h"
  36. #undef PIM_DEBUG_IFADDR_DUMP
  37. #define PIM_DEBUG_IFADDR_DUMP
  38. static int fib_lookup_if_vif_index(struct in_addr addr);
  39. static int del_oif(struct channel_oil *channel_oil,
  40. struct interface *oif,
  41. uint32_t proto_mask);
  42. /* Router-id update message from zebra. */
  43. static int pim_router_id_update_zebra(int command, struct zclient *zclient,
  44. zebra_size_t length)
  45. {
  46. struct prefix router_id;
  47. /* FIXME: actually use router_id for anything ? */
  48. zebra_router_id_update_read(zclient->ibuf, &router_id);
  49. return 0;
  50. }
  51. static int pim_zebra_if_add(int command, struct zclient *zclient,
  52. zebra_size_t length)
  53. {
  54. struct interface *ifp;
  55. /*
  56. zebra api adds/dels interfaces using the same call
  57. interface_add_read below, see comments in lib/zclient.c
  58. */
  59. ifp = zebra_interface_add_read(zclient->ibuf);
  60. if (!ifp)
  61. return 0;
  62. if (PIM_DEBUG_ZEBRA) {
  63. zlog_debug("%s: %s index %d flags %ld metric %d mtu %d operative %d",
  64. __PRETTY_FUNCTION__,
  65. ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric,
  66. ifp->mtu, if_is_operative(ifp));
  67. }
  68. if (if_is_operative(ifp))
  69. pim_if_addr_add_all(ifp);
  70. return 0;
  71. }
  72. static int pim_zebra_if_del(int command, struct zclient *zclient,
  73. zebra_size_t length)
  74. {
  75. struct interface *ifp;
  76. /*
  77. zebra api adds/dels interfaces using the same call
  78. interface_add_read below, see comments in lib/zclient.c
  79. */
  80. ifp = zebra_interface_add_read(zclient->ibuf);
  81. if (!ifp)
  82. return 0;
  83. if (PIM_DEBUG_ZEBRA) {
  84. zlog_debug("%s: %s index %d flags %ld metric %d mtu %d operative %d",
  85. __PRETTY_FUNCTION__,
  86. ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric,
  87. ifp->mtu, if_is_operative(ifp));
  88. }
  89. if (!if_is_operative(ifp))
  90. pim_if_addr_del_all(ifp);
  91. return 0;
  92. }
  93. static int pim_zebra_if_state_up(int command, struct zclient *zclient,
  94. zebra_size_t length)
  95. {
  96. struct interface *ifp;
  97. /*
  98. zebra api notifies interface up/down events by using the same call
  99. interface_add_read below, see comments in lib/zclient.c
  100. */
  101. ifp = zebra_interface_state_read(zclient->ibuf);
  102. if (!ifp)
  103. return 0;
  104. zlog_info("INTERFACE UP: %s", ifp->name);
  105. if (PIM_DEBUG_ZEBRA) {
  106. zlog_debug("%s: %s index %d flags %ld metric %d mtu %d operative %d",
  107. __PRETTY_FUNCTION__,
  108. ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric,
  109. ifp->mtu, if_is_operative(ifp));
  110. }
  111. if (if_is_operative(ifp)) {
  112. /*
  113. pim_if_addr_add_all() suffices for bringing up both IGMP and PIM
  114. */
  115. pim_if_addr_add_all(ifp);
  116. }
  117. return 0;
  118. }
  119. static int pim_zebra_if_state_down(int command, struct zclient *zclient,
  120. zebra_size_t length)
  121. {
  122. struct interface *ifp;
  123. /*
  124. zebra api notifies interface up/down events by using the same call
  125. interface_add_read below, see comments in lib/zclient.c
  126. */
  127. ifp = zebra_interface_state_read(zclient->ibuf);
  128. if (!ifp)
  129. return 0;
  130. zlog_info("INTERFACE DOWN: %s", ifp->name);
  131. if (PIM_DEBUG_ZEBRA) {
  132. zlog_debug("%s: %s index %d flags %ld metric %d mtu %d operative %d",
  133. __PRETTY_FUNCTION__,
  134. ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric,
  135. ifp->mtu, if_is_operative(ifp));
  136. }
  137. if (!if_is_operative(ifp)) {
  138. /*
  139. pim_if_addr_del_all() suffices for shutting down IGMP,
  140. but not for shutting down PIM
  141. */
  142. pim_if_addr_del_all(ifp);
  143. /*
  144. pim_sock_delete() closes the socket, stops read and timer threads,
  145. and kills all neighbors.
  146. */
  147. if (ifp->info) {
  148. pim_sock_delete(ifp, "link down");
  149. }
  150. }
  151. return 0;
  152. }
  153. #ifdef PIM_DEBUG_IFADDR_DUMP
  154. static void dump_if_address(struct interface *ifp)
  155. {
  156. struct connected *ifc;
  157. struct listnode *node;
  158. zlog_debug("%s %s: interface %s addresses:",
  159. __FILE__, __PRETTY_FUNCTION__,
  160. ifp->name);
  161. for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
  162. struct prefix *p = ifc->address;
  163. if (p->family != AF_INET)
  164. continue;
  165. zlog_debug("%s %s: interface %s address %s",
  166. __FILE__, __PRETTY_FUNCTION__,
  167. ifp->name,
  168. inet_ntoa(p->u.prefix4));
  169. }
  170. }
  171. #endif
  172. static int pim_zebra_if_address_add(int command, struct zclient *zclient,
  173. zebra_size_t length)
  174. {
  175. struct connected *c;
  176. struct prefix *p;
  177. zassert(command == ZEBRA_INTERFACE_ADDRESS_ADD);
  178. /*
  179. zebra api notifies address adds/dels events by using the same call
  180. interface_add_read below, see comments in lib/zclient.c
  181. zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD, ...)
  182. will add address to interface list by calling
  183. connected_add_by_prefix()
  184. */
  185. c = zebra_interface_address_read(command, zclient->ibuf);
  186. if (!c)
  187. return 0;
  188. p = c->address;
  189. if (p->family != AF_INET)
  190. return 0;
  191. if (PIM_DEBUG_ZEBRA) {
  192. char buf[BUFSIZ];
  193. prefix2str(p, buf, BUFSIZ);
  194. zlog_debug("%s: %s connected IP address %s flags %u",
  195. __PRETTY_FUNCTION__,
  196. c->ifp->name, buf, c->flags);
  197. #ifdef PIM_DEBUG_IFADDR_DUMP
  198. dump_if_address(c->ifp);
  199. #endif
  200. }
  201. pim_if_addr_add(c);
  202. return 0;
  203. }
  204. static int pim_zebra_if_address_del(int command, struct zclient *client,
  205. zebra_size_t length)
  206. {
  207. struct connected *c;
  208. struct prefix *p;
  209. zassert(command == ZEBRA_INTERFACE_ADDRESS_DELETE);
  210. /*
  211. zebra api notifies address adds/dels events by using the same call
  212. interface_add_read below, see comments in lib/zclient.c
  213. zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE, ...)
  214. will remove address from interface list by calling
  215. connected_delete_by_prefix()
  216. */
  217. c = zebra_interface_address_read(command, client->ibuf);
  218. if (!c)
  219. return 0;
  220. p = c->address;
  221. if (p->family != AF_INET)
  222. return 0;
  223. if (PIM_DEBUG_ZEBRA) {
  224. char buf[BUFSIZ];
  225. prefix2str(p, buf, BUFSIZ);
  226. zlog_debug("%s: %s disconnected IP address %s flags %u",
  227. __PRETTY_FUNCTION__,
  228. c->ifp->name, buf, c->flags);
  229. #ifdef PIM_DEBUG_IFADDR_DUMP
  230. dump_if_address(c->ifp);
  231. #endif
  232. }
  233. pim_if_addr_del(c);
  234. return 0;
  235. }
  236. static void scan_upstream_rpf_cache()
  237. {
  238. struct listnode *up_node;
  239. struct listnode *up_nextnode;
  240. struct pim_upstream *up;
  241. for (ALL_LIST_ELEMENTS(qpim_upstream_list, up_node, up_nextnode, up)) {
  242. struct in_addr old_rpf_addr;
  243. enum pim_rpf_result rpf_result;
  244. rpf_result = pim_rpf_update(up, &old_rpf_addr);
  245. if (rpf_result == PIM_RPF_FAILURE)
  246. continue;
  247. if (rpf_result == PIM_RPF_CHANGED) {
  248. if (up->join_state == PIM_UPSTREAM_JOINED) {
  249. /*
  250. RFC 4601: 4.5.7. Sending (S,G) Join/Prune Messages
  251. Transitions from Joined State
  252. RPF'(S,G) changes not due to an Assert
  253. The upstream (S,G) state machine remains in Joined
  254. state. Send Join(S,G) to the new upstream neighbor, which is
  255. the new value of RPF'(S,G). Send Prune(S,G) to the old
  256. upstream neighbor, which is the old value of RPF'(S,G). Set
  257. the Join Timer (JT) to expire after t_periodic seconds.
  258. */
  259. /* send Prune(S,G) to the old upstream neighbor */
  260. pim_joinprune_send(up->rpf.source_nexthop.interface,
  261. old_rpf_addr,
  262. up->source_addr,
  263. up->group_addr,
  264. 0 /* prune */);
  265. /* send Join(S,G) to the current upstream neighbor */
  266. pim_joinprune_send(up->rpf.source_nexthop.interface,
  267. up->rpf.rpf_addr,
  268. up->source_addr,
  269. up->group_addr,
  270. 1 /* join */);
  271. pim_upstream_join_timer_restart(up);
  272. } /* up->join_state == PIM_UPSTREAM_JOINED */
  273. /* FIXME can join_desired actually be changed by pim_rpf_update()
  274. returning PIM_RPF_CHANGED ? */
  275. pim_upstream_update_join_desired(up);
  276. } /* PIM_RPF_CHANGED */
  277. } /* for (qpim_upstream_list) */
  278. }
  279. void pim_scan_oil()
  280. {
  281. struct listnode *node;
  282. struct listnode *nextnode;
  283. struct channel_oil *c_oil;
  284. qpim_scan_oil_last = pim_time_monotonic_sec();
  285. ++qpim_scan_oil_events;
  286. for (ALL_LIST_ELEMENTS(qpim_channel_oil_list, node, nextnode, c_oil)) {
  287. int old_vif_index;
  288. int input_iface_vif_index = fib_lookup_if_vif_index(c_oil->oil.mfcc_origin);
  289. if (input_iface_vif_index < 1) {
  290. char source_str[100];
  291. char group_str[100];
  292. pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  293. pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  294. zlog_warn("%s %s: could not find input interface for (S,G)=(%s,%s)",
  295. __FILE__, __PRETTY_FUNCTION__,
  296. source_str, group_str);
  297. continue;
  298. }
  299. if (input_iface_vif_index == c_oil->oil.mfcc_parent) {
  300. /* RPF unchanged */
  301. continue;
  302. }
  303. if (PIM_DEBUG_ZEBRA) {
  304. struct interface *old_iif = pim_if_find_by_vif_index(c_oil->oil.mfcc_parent);
  305. struct interface *new_iif = pim_if_find_by_vif_index(input_iface_vif_index);
  306. char source_str[100];
  307. char group_str[100];
  308. pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  309. pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  310. zlog_debug("%s %s: (S,G)=(%s,%s) input interface changed from %s vif_index=%d to %s vif_index=%d",
  311. __FILE__, __PRETTY_FUNCTION__,
  312. source_str, group_str,
  313. old_iif ? old_iif->name : "<old_iif?>", c_oil->oil.mfcc_parent,
  314. new_iif ? new_iif->name : "<new_iif?>", input_iface_vif_index);
  315. }
  316. /* new iif loops to existing oif ? */
  317. if (c_oil->oil.mfcc_ttls[input_iface_vif_index]) {
  318. struct interface *new_iif = pim_if_find_by_vif_index(input_iface_vif_index);
  319. if (PIM_DEBUG_ZEBRA) {
  320. char source_str[100];
  321. char group_str[100];
  322. pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  323. pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  324. zlog_debug("%s %s: (S,G)=(%s,%s) new iif loops to existing oif: %s vif_index=%d",
  325. __FILE__, __PRETTY_FUNCTION__,
  326. source_str, group_str,
  327. new_iif ? new_iif->name : "<new_iif?>", input_iface_vif_index);
  328. }
  329. del_oif(c_oil, new_iif, PIM_OIF_FLAG_PROTO_ANY);
  330. }
  331. /* update iif vif_index */
  332. old_vif_index = c_oil->oil.mfcc_parent;
  333. c_oil->oil.mfcc_parent = input_iface_vif_index;
  334. /* update kernel multicast forwarding cache (MFC) */
  335. if (pim_mroute_add(&c_oil->oil)) {
  336. /* just log warning */
  337. struct interface *old_iif = pim_if_find_by_vif_index(old_vif_index);
  338. struct interface *new_iif = pim_if_find_by_vif_index(input_iface_vif_index);
  339. char source_str[100];
  340. char group_str[100];
  341. pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  342. pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  343. zlog_warn("%s %s: (S,G)=(%s,%s) failure updating input interface from %s vif_index=%d to %s vif_index=%d",
  344. __FILE__, __PRETTY_FUNCTION__,
  345. source_str, group_str,
  346. old_iif ? old_iif->name : "<old_iif?>", c_oil->oil.mfcc_parent,
  347. new_iif ? new_iif->name : "<new_iif?>", input_iface_vif_index);
  348. continue;
  349. }
  350. } /* for (qpim_channel_oil_list) */
  351. }
  352. static int on_rpf_cache_refresh(struct thread *t)
  353. {
  354. zassert(t);
  355. zassert(qpim_rpf_cache_refresher);
  356. qpim_rpf_cache_refresher = 0;
  357. /* update PIM protocol state */
  358. scan_upstream_rpf_cache();
  359. /* update kernel multicast forwarding cache (MFC) */
  360. pim_scan_oil();
  361. qpim_rpf_cache_refresh_last = pim_time_monotonic_sec();
  362. ++qpim_rpf_cache_refresh_events;
  363. return 0;
  364. }
  365. static void sched_rpf_cache_refresh()
  366. {
  367. ++qpim_rpf_cache_refresh_requests;
  368. if (qpim_rpf_cache_refresher) {
  369. /* Refresh timer is already running */
  370. return;
  371. }
  372. /* Start refresh timer */
  373. if (PIM_DEBUG_ZEBRA) {
  374. zlog_debug("%s: triggering %ld msec timer",
  375. __PRETTY_FUNCTION__,
  376. qpim_rpf_cache_refresh_delay_msec);
  377. }
  378. THREAD_TIMER_MSEC_ON(master, qpim_rpf_cache_refresher,
  379. on_rpf_cache_refresh,
  380. 0, qpim_rpf_cache_refresh_delay_msec);
  381. }
  382. static int redist_read_ipv4_route(int command, struct zclient *zclient,
  383. zebra_size_t length)
  384. {
  385. struct stream *s;
  386. struct zapi_ipv4 api;
  387. unsigned long ifindex;
  388. struct in_addr nexthop;
  389. struct prefix_ipv4 p;
  390. int min_len = 4;
  391. if (length < min_len) {
  392. zlog_warn("%s %s: short buffer: length=%d min=%d",
  393. __FILE__, __PRETTY_FUNCTION__,
  394. length, min_len);
  395. return -1;
  396. }
  397. s = zclient->ibuf;
  398. ifindex = 0;
  399. nexthop.s_addr = 0;
  400. /* Type, flags, message. */
  401. api.type = stream_getc(s);
  402. api.flags = stream_getc(s);
  403. api.message = stream_getc(s);
  404. /* IPv4 prefix length. */
  405. memset(&p, 0, sizeof(struct prefix_ipv4));
  406. p.family = AF_INET;
  407. p.prefixlen = stream_getc(s);
  408. min_len +=
  409. PSIZE(p.prefixlen) +
  410. CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP) ? 5 : 0 +
  411. CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX) ? 5 : 0 +
  412. CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? 1 : 0 +
  413. CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? 4 : 0;
  414. if (PIM_DEBUG_ZEBRA) {
  415. zlog_debug("%s %s: length=%d min_len=%d flags=%s%s%s%s",
  416. __FILE__, __PRETTY_FUNCTION__,
  417. length, min_len,
  418. CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP) ? "nh" : "",
  419. CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX) ? " ifi" : "",
  420. CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? " dist" : "",
  421. CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? " metr" : "");
  422. }
  423. if (length < min_len) {
  424. zlog_warn("%s %s: short buffer: length=%d min_len=%d flags=%s%s%s%s",
  425. __FILE__, __PRETTY_FUNCTION__,
  426. length, min_len,
  427. CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP) ? "nh" : "",
  428. CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX) ? " ifi" : "",
  429. CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? " dist" : "",
  430. CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? " metr" : "");
  431. return -1;
  432. }
  433. /* IPv4 prefix. */
  434. stream_get(&p.prefix, s, PSIZE(p.prefixlen));
  435. /* Nexthop, ifindex, distance, metric. */
  436. if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP)) {
  437. api.nexthop_num = stream_getc(s);
  438. nexthop.s_addr = stream_get_ipv4(s);
  439. }
  440. if (CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX)) {
  441. api.ifindex_num = stream_getc(s);
  442. ifindex = stream_getl(s);
  443. }
  444. api.distance = CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ?
  445. stream_getc(s) :
  446. 0;
  447. api.metric = CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ?
  448. stream_getl(s) :
  449. 0;
  450. switch (command) {
  451. case ZEBRA_IPV4_ROUTE_ADD:
  452. if (PIM_DEBUG_ZEBRA) {
  453. char buf[2][INET_ADDRSTRLEN];
  454. zlog_debug("%s: add %s %s/%d "
  455. "nexthop %s ifindex %ld metric%s %u distance%s %u",
  456. __PRETTY_FUNCTION__,
  457. zebra_route_string(api.type),
  458. inet_ntop(AF_INET, &p.prefix, buf[0], sizeof(buf[0])),
  459. p.prefixlen,
  460. inet_ntop(AF_INET, &nexthop, buf[1], sizeof(buf[1])),
  461. ifindex,
  462. CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? "-recv" : "-miss",
  463. api.metric,
  464. CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? "-recv" : "-miss",
  465. api.distance);
  466. }
  467. break;
  468. case ZEBRA_IPV4_ROUTE_DELETE:
  469. if (PIM_DEBUG_ZEBRA) {
  470. char buf[2][INET_ADDRSTRLEN];
  471. zlog_debug("%s: delete %s %s/%d "
  472. "nexthop %s ifindex %ld metric%s %u distance%s %u",
  473. __PRETTY_FUNCTION__,
  474. zebra_route_string(api.type),
  475. inet_ntop(AF_INET, &p.prefix, buf[0], sizeof(buf[0])),
  476. p.prefixlen,
  477. inet_ntop(AF_INET, &nexthop, buf[1], sizeof(buf[1])),
  478. ifindex,
  479. CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? "-recv" : "-miss",
  480. api.metric,
  481. CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? "-recv" : "-miss",
  482. api.distance);
  483. }
  484. break;
  485. default:
  486. zlog_warn("%s: unknown command=%d", __PRETTY_FUNCTION__, command);
  487. return -1;
  488. }
  489. sched_rpf_cache_refresh();
  490. return 0;
  491. }
  492. void pim_zebra_init()
  493. {
  494. struct zclient *zclient;
  495. int i;
  496. #ifdef HAVE_TCP_ZEBRA
  497. zlog_notice("zclient update contacting ZEBRA daemon at socket TCP %s,%d", "127.0.0.1", ZEBRA_PORT);
  498. #else
  499. zlog_notice("zclient update contacting ZEBRA daemon at socket UNIX %s", ZEBRA_SERV_PATH);
  500. #endif
  501. /* Socket for receiving updates from Zebra daemon */
  502. zclient = zclient_new();
  503. zclient->router_id_update = pim_router_id_update_zebra;
  504. zclient->interface_add = pim_zebra_if_add;
  505. zclient->interface_delete = pim_zebra_if_del;
  506. zclient->interface_up = pim_zebra_if_state_up;
  507. zclient->interface_down = pim_zebra_if_state_down;
  508. zclient->interface_address_add = pim_zebra_if_address_add;
  509. zclient->interface_address_delete = pim_zebra_if_address_del;
  510. zclient->ipv4_route_add = redist_read_ipv4_route;
  511. zclient->ipv4_route_delete = redist_read_ipv4_route;
  512. zclient_init(zclient, ZEBRA_ROUTE_PIM);
  513. zlog_info("zclient_init cleared redistribution request");
  514. zassert(zclient->redist_default == ZEBRA_ROUTE_PIM);
  515. /* Request all redistribution */
  516. for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
  517. if (i == zclient->redist_default)
  518. continue;
  519. zclient->redist[i] = 1;
  520. zlog_info("%s: requesting redistribution for %s (%i)",
  521. __PRETTY_FUNCTION__, zebra_route_string(i), i);
  522. }
  523. /* Request default information */
  524. zclient->default_information = 1;
  525. zlog_info("%s: requesting default information redistribution",
  526. __PRETTY_FUNCTION__);
  527. zlog_notice("%s: zclient update socket initialized",
  528. __PRETTY_FUNCTION__);
  529. zassert(!qpim_zclient_lookup);
  530. qpim_zclient_lookup = zclient_lookup_new();
  531. zassert(qpim_zclient_lookup);
  532. }
  533. void igmp_anysource_forward_start(struct igmp_group *group)
  534. {
  535. /* Any source (*,G) is forwarded only if mode is EXCLUDE {empty} */
  536. zassert(group->group_filtermode_isexcl);
  537. zassert(listcount(group->group_source_list) < 1);
  538. if (PIM_DEBUG_IGMP_TRACE) {
  539. zlog_debug("%s %s: UNIMPLEMENTED",
  540. __FILE__, __PRETTY_FUNCTION__);
  541. }
  542. }
  543. void igmp_anysource_forward_stop(struct igmp_group *group)
  544. {
  545. /* Any source (*,G) is forwarded only if mode is EXCLUDE {empty} */
  546. zassert((!group->group_filtermode_isexcl) || (listcount(group->group_source_list) > 0));
  547. if (PIM_DEBUG_IGMP_TRACE) {
  548. zlog_debug("%s %s: UNIMPLEMENTED",
  549. __FILE__, __PRETTY_FUNCTION__);
  550. }
  551. }
  552. static int fib_lookup_if_vif_index(struct in_addr addr)
  553. {
  554. struct pim_zlookup_nexthop nexthop_tab[PIM_NEXTHOP_IFINDEX_TAB_SIZE];
  555. int num_ifindex;
  556. int vif_index;
  557. int first_ifindex;
  558. num_ifindex = zclient_lookup_nexthop(qpim_zclient_lookup, nexthop_tab,
  559. PIM_NEXTHOP_IFINDEX_TAB_SIZE, addr,
  560. PIM_NEXTHOP_LOOKUP_MAX);
  561. if (num_ifindex < 1) {
  562. char addr_str[100];
  563. pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
  564. zlog_warn("%s %s: could not find nexthop ifindex for address %s",
  565. __FILE__, __PRETTY_FUNCTION__,
  566. addr_str);
  567. return -1;
  568. }
  569. first_ifindex = nexthop_tab[0].ifindex;
  570. if (num_ifindex > 1) {
  571. char addr_str[100];
  572. pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
  573. zlog_debug("%s %s: FIXME ignoring multiple nexthop ifindex'es num_ifindex=%d for address %s (using only ifindex=%d)",
  574. __FILE__, __PRETTY_FUNCTION__,
  575. num_ifindex, addr_str, first_ifindex);
  576. /* debug warning only, do not return */
  577. }
  578. if (PIM_DEBUG_ZEBRA) {
  579. char addr_str[100];
  580. pim_inet4_dump("<ifaddr?>", addr, addr_str, sizeof(addr_str));
  581. zlog_debug("%s %s: found nexthop ifindex=%d (interface %s) for address %s",
  582. __FILE__, __PRETTY_FUNCTION__,
  583. first_ifindex, ifindex2ifname(first_ifindex), addr_str);
  584. }
  585. vif_index = pim_if_find_vifindex_by_ifindex(first_ifindex);
  586. if (vif_index < 1) {
  587. char addr_str[100];
  588. pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
  589. zlog_warn("%s %s: low vif_index=%d < 1 nexthop for address %s",
  590. __FILE__, __PRETTY_FUNCTION__,
  591. vif_index, addr_str);
  592. return -2;
  593. }
  594. zassert(qpim_mroute_oif_highest_vif_index < MAXVIFS);
  595. if (vif_index > qpim_mroute_oif_highest_vif_index) {
  596. char addr_str[100];
  597. pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
  598. zlog_warn("%s %s: high vif_index=%d > highest_vif_index=%d nexthop for address %s",
  599. __FILE__, __PRETTY_FUNCTION__,
  600. vif_index, qpim_mroute_oif_highest_vif_index, addr_str);
  601. zlog_warn("%s %s: pim disabled on interface %s vif_index=%d ?",
  602. __FILE__, __PRETTY_FUNCTION__,
  603. ifindex2ifname(vif_index),
  604. vif_index);
  605. return -3;
  606. }
  607. return vif_index;
  608. }
  609. static int add_oif(struct channel_oil *channel_oil,
  610. struct interface *oif,
  611. uint32_t proto_mask)
  612. {
  613. struct pim_interface *pim_ifp;
  614. int old_ttl;
  615. zassert(channel_oil);
  616. pim_ifp = oif->info;
  617. if (PIM_DEBUG_MROUTE) {
  618. char group_str[100];
  619. char source_str[100];
  620. pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  621. pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  622. zlog_debug("%s %s: (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d",
  623. __FILE__, __PRETTY_FUNCTION__,
  624. source_str, group_str,
  625. proto_mask, oif->name, pim_ifp->mroute_vif_index);
  626. }
  627. if (pim_ifp->mroute_vif_index < 1) {
  628. zlog_warn("%s %s: interface %s vif_index=%d < 1",
  629. __FILE__, __PRETTY_FUNCTION__,
  630. oif->name, pim_ifp->mroute_vif_index);
  631. return -1;
  632. }
  633. #ifdef PIM_ENFORCE_LOOPFREE_MFC
  634. /*
  635. Prevent creating MFC entry with OIF=IIF.
  636. This is a protection against implementation mistakes.
  637. PIM protocol implicitely ensures loopfree multicast topology.
  638. IGMP must be protected against adding looped MFC entries created
  639. by both source and receiver attached to the same interface. See
  640. TODO T22.
  641. */
  642. if (pim_ifp->mroute_vif_index == channel_oil->oil.mfcc_parent) {
  643. char group_str[100];
  644. char source_str[100];
  645. pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  646. pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  647. zlog_warn("%s %s: refusing protocol mask %u request for IIF=OIF=%s (vif_index=%d) for channel (S,G)=(%s,%s)",
  648. __FILE__, __PRETTY_FUNCTION__,
  649. proto_mask, oif->name, pim_ifp->mroute_vif_index,
  650. source_str, group_str);
  651. return -2;
  652. }
  653. #endif
  654. zassert(qpim_mroute_oif_highest_vif_index < MAXVIFS);
  655. zassert(pim_ifp->mroute_vif_index <= qpim_mroute_oif_highest_vif_index);
  656. /* Prevent single protocol from subscribing same interface to
  657. channel (S,G) multiple times */
  658. if (channel_oil->oif_flags[pim_ifp->mroute_vif_index] & proto_mask) {
  659. char group_str[100];
  660. char source_str[100];
  661. pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  662. pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  663. zlog_warn("%s %s: existing protocol mask %u requested OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%s,%s)",
  664. __FILE__, __PRETTY_FUNCTION__,
  665. proto_mask, oif->name, pim_ifp->mroute_vif_index,
  666. channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index],
  667. source_str, group_str);
  668. return -3;
  669. }
  670. /* Allow other protocol to request subscription of same interface to
  671. channel (S,G) multiple times, by silently ignoring further
  672. requests */
  673. if (channel_oil->oif_flags[pim_ifp->mroute_vif_index] & PIM_OIF_FLAG_PROTO_ANY) {
  674. /* Check the OIF really exists before returning, and only log
  675. warning otherwise */
  676. if (channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] < 1) {
  677. char group_str[100];
  678. char source_str[100];
  679. pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  680. pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  681. zlog_warn("%s %s: new protocol mask %u requested nonexistent OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%s,%s)",
  682. __FILE__, __PRETTY_FUNCTION__,
  683. proto_mask, oif->name, pim_ifp->mroute_vif_index,
  684. channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index],
  685. source_str, group_str);
  686. }
  687. return 0;
  688. }
  689. old_ttl = channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index];
  690. if (old_ttl > 0) {
  691. char group_str[100];
  692. char source_str[100];
  693. pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  694. pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  695. zlog_warn("%s %s: interface %s (vif_index=%d) is existing output for channel (S,G)=(%s,%s)",
  696. __FILE__, __PRETTY_FUNCTION__,
  697. oif->name, pim_ifp->mroute_vif_index,
  698. source_str, group_str);
  699. return -4;
  700. }
  701. channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] = PIM_MROUTE_MIN_TTL;
  702. if (pim_mroute_add(&channel_oil->oil)) {
  703. char group_str[100];
  704. char source_str[100];
  705. pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  706. pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  707. zlog_warn("%s %s: could not add output interface %s (vif_index=%d) for channel (S,G)=(%s,%s)",
  708. __FILE__, __PRETTY_FUNCTION__,
  709. oif->name, pim_ifp->mroute_vif_index,
  710. source_str, group_str);
  711. channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] = old_ttl;
  712. return -5;
  713. }
  714. channel_oil->oif_creation[pim_ifp->mroute_vif_index] = pim_time_monotonic_sec();
  715. ++channel_oil->oil_size;
  716. channel_oil->oif_flags[pim_ifp->mroute_vif_index] |= proto_mask;
  717. if (PIM_DEBUG_MROUTE) {
  718. char group_str[100];
  719. char source_str[100];
  720. pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  721. pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  722. zlog_debug("%s %s: (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d: DONE",
  723. __FILE__, __PRETTY_FUNCTION__,
  724. source_str, group_str,
  725. proto_mask, oif->name, pim_ifp->mroute_vif_index);
  726. }
  727. return 0;
  728. }
  729. static int del_oif(struct channel_oil *channel_oil,
  730. struct interface *oif,
  731. uint32_t proto_mask)
  732. {
  733. struct pim_interface *pim_ifp;
  734. int old_ttl;
  735. zassert(channel_oil);
  736. pim_ifp = oif->info;
  737. zassert(pim_ifp->mroute_vif_index >= 1);
  738. zassert(qpim_mroute_oif_highest_vif_index < MAXVIFS);
  739. zassert(pim_ifp->mroute_vif_index <= qpim_mroute_oif_highest_vif_index);
  740. if (PIM_DEBUG_MROUTE) {
  741. char group_str[100];
  742. char source_str[100];
  743. pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  744. pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  745. zlog_debug("%s %s: (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d",
  746. __FILE__, __PRETTY_FUNCTION__,
  747. source_str, group_str,
  748. proto_mask, oif->name, pim_ifp->mroute_vif_index);
  749. }
  750. /* Prevent single protocol from unsubscribing same interface from
  751. channel (S,G) multiple times */
  752. if (!(channel_oil->oif_flags[pim_ifp->mroute_vif_index] & proto_mask)) {
  753. char group_str[100];
  754. char source_str[100];
  755. pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  756. pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  757. zlog_warn("%s %s: nonexistent protocol mask %u removed OIF %s (vif_index=%d, min_ttl=%d) from channel (S,G)=(%s,%s)",
  758. __FILE__, __PRETTY_FUNCTION__,
  759. proto_mask, oif->name, pim_ifp->mroute_vif_index,
  760. channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index],
  761. source_str, group_str);
  762. return -2;
  763. }
  764. /* Mark that protocol is no longer interested in this OIF */
  765. channel_oil->oif_flags[pim_ifp->mroute_vif_index] &= ~proto_mask;
  766. /* Allow multiple protocols to unsubscribe same interface from
  767. channel (S,G) multiple times, by silently ignoring requests while
  768. there is at least one protocol interested in the channel */
  769. if (channel_oil->oif_flags[pim_ifp->mroute_vif_index] & PIM_OIF_FLAG_PROTO_ANY) {
  770. /* Check the OIF keeps existing before returning, and only log
  771. warning otherwise */
  772. if (channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] < 1) {
  773. char group_str[100];
  774. char source_str[100];
  775. pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  776. pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  777. zlog_warn("%s %s: protocol mask %u removing nonexistent OIF %s (vif_index=%d, min_ttl=%d) from channel (S,G)=(%s,%s)",
  778. __FILE__, __PRETTY_FUNCTION__,
  779. proto_mask, oif->name, pim_ifp->mroute_vif_index,
  780. channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index],
  781. source_str, group_str);
  782. }
  783. return 0;
  784. }
  785. old_ttl = channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index];
  786. if (old_ttl < 1) {
  787. char group_str[100];
  788. char source_str[100];
  789. pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  790. pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  791. zlog_warn("%s %s: interface %s (vif_index=%d) is not output for channel (S,G)=(%s,%s)",
  792. __FILE__, __PRETTY_FUNCTION__,
  793. oif->name, pim_ifp->mroute_vif_index,
  794. source_str, group_str);
  795. return -3;
  796. }
  797. channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] = 0;
  798. if (pim_mroute_add(&channel_oil->oil)) {
  799. char group_str[100];
  800. char source_str[100];
  801. pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  802. pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  803. zlog_warn("%s %s: could not remove output interface %s (vif_index=%d) from channel (S,G)=(%s,%s)",
  804. __FILE__, __PRETTY_FUNCTION__,
  805. oif->name, pim_ifp->mroute_vif_index,
  806. source_str, group_str);
  807. channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] = old_ttl;
  808. return -4;
  809. }
  810. --channel_oil->oil_size;
  811. if (channel_oil->oil_size < 1) {
  812. if (pim_mroute_del(&channel_oil->oil)) {
  813. /* just log a warning in case of failure */
  814. char group_str[100];
  815. char source_str[100];
  816. pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  817. pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  818. zlog_warn("%s %s: failure removing OIL for channel (S,G)=(%s,%s)",
  819. __FILE__, __PRETTY_FUNCTION__,
  820. source_str, group_str);
  821. }
  822. }
  823. if (PIM_DEBUG_MROUTE) {
  824. char group_str[100];
  825. char source_str[100];
  826. pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
  827. pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
  828. zlog_debug("%s %s: (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d: DONE",
  829. __FILE__, __PRETTY_FUNCTION__,
  830. source_str, group_str,
  831. proto_mask, oif->name, pim_ifp->mroute_vif_index);
  832. }
  833. return 0;
  834. }
  835. void igmp_source_forward_start(struct igmp_source *source)
  836. {
  837. struct igmp_group *group;
  838. if (PIM_DEBUG_IGMP_TRACE) {
  839. char source_str[100];
  840. char group_str[100];
  841. pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
  842. pim_inet4_dump("<group?>", source->source_group->group_addr, group_str, sizeof(group_str));
  843. zlog_debug("%s: (S,G)=(%s,%s) igmp_sock=%d oif=%s fwd=%d",
  844. __PRETTY_FUNCTION__,
  845. source_str, group_str,
  846. source->source_group->group_igmp_sock->fd,
  847. source->source_group->group_igmp_sock->interface->name,
  848. IGMP_SOURCE_TEST_FORWARDING(source->source_flags));
  849. }
  850. /* Prevent IGMP interface from installing multicast route multiple
  851. times */
  852. if (IGMP_SOURCE_TEST_FORWARDING(source->source_flags)) {
  853. return;
  854. }
  855. group = source->source_group;
  856. if (!source->source_channel_oil) {
  857. struct pim_interface *pim_oif;
  858. int input_iface_vif_index = fib_lookup_if_vif_index(source->source_addr);
  859. if (input_iface_vif_index < 1) {
  860. char source_str[100];
  861. pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
  862. zlog_warn("%s %s: could not find input interface for source %s",
  863. __FILE__, __PRETTY_FUNCTION__,
  864. source_str);
  865. return;
  866. }
  867. /*
  868. Protect IGMP against adding looped MFC entries created by both
  869. source and receiver attached to the same interface. See TODO
  870. T22.
  871. */
  872. pim_oif = source->source_group->group_igmp_sock->interface->info;
  873. if (!pim_oif) {
  874. zlog_warn("%s: multicast not enabled on oif=%s ?",
  875. __PRETTY_FUNCTION__,
  876. source->source_group->group_igmp_sock->interface->name);
  877. return;
  878. }
  879. if (pim_oif->mroute_vif_index < 1) {
  880. zlog_warn("%s %s: oif=%s vif_index=%d < 1",
  881. __FILE__, __PRETTY_FUNCTION__,
  882. source->source_group->group_igmp_sock->interface->name,
  883. pim_oif->mroute_vif_index);
  884. return;
  885. }
  886. if (input_iface_vif_index == pim_oif->mroute_vif_index) {
  887. /* ignore request for looped MFC entry */
  888. if (PIM_DEBUG_IGMP_TRACE) {
  889. char source_str[100];
  890. char group_str[100];
  891. pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
  892. pim_inet4_dump("<group?>", source->source_group->group_addr, group_str, sizeof(group_str));
  893. zlog_debug("%s: ignoring request for looped MFC entry (S,G)=(%s,%s): igmp_sock=%d oif=%s vif_index=%d",
  894. __PRETTY_FUNCTION__,
  895. source_str, group_str,
  896. source->source_group->group_igmp_sock->fd,
  897. source->source_group->group_igmp_sock->interface->name,
  898. input_iface_vif_index);
  899. }
  900. return;
  901. }
  902. source->source_channel_oil = pim_channel_oil_add(group->group_addr,
  903. source->source_addr,
  904. input_iface_vif_index);
  905. if (!source->source_channel_oil) {
  906. char group_str[100];
  907. char source_str[100];
  908. pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
  909. pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
  910. zlog_warn("%s %s: could not create OIL for channel (S,G)=(%s,%s)",
  911. __FILE__, __PRETTY_FUNCTION__,
  912. source_str, group_str);
  913. return;
  914. }
  915. }
  916. if (add_oif(source->source_channel_oil,
  917. group->group_igmp_sock->interface,
  918. PIM_OIF_FLAG_PROTO_IGMP)) {
  919. return;
  920. }
  921. /*
  922. Feed IGMPv3-gathered local membership information into PIM
  923. per-interface (S,G) state.
  924. */
  925. pim_ifchannel_local_membership_add(group->group_igmp_sock->interface,
  926. source->source_addr, group->group_addr);
  927. IGMP_SOURCE_DO_FORWARDING(source->source_flags);
  928. }
  929. void igmp_source_forward_stop(struct igmp_source *source)
  930. {
  931. struct igmp_group *group;
  932. if (PIM_DEBUG_IGMP_TRACE) {
  933. char source_str[100];
  934. char group_str[100];
  935. pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
  936. pim_inet4_dump("<group?>", source->source_group->group_addr, group_str, sizeof(group_str));
  937. zlog_debug("%s: (S,G)=(%s,%s) igmp_sock=%d oif=%s fwd=%d",
  938. __PRETTY_FUNCTION__,
  939. source_str, group_str,
  940. source->source_group->group_igmp_sock->fd,
  941. source->source_group->group_igmp_sock->interface->name,
  942. IGMP_SOURCE_TEST_FORWARDING(source->source_flags));
  943. }
  944. /* Prevent IGMP interface from removing multicast route multiple
  945. times */
  946. if (!IGMP_SOURCE_TEST_FORWARDING(source->source_flags)) {
  947. return;
  948. }
  949. group = source->source_group;
  950. if (del_oif(source->source_channel_oil,
  951. group->group_igmp_sock->interface,
  952. PIM_OIF_FLAG_PROTO_IGMP)) {
  953. return;
  954. }
  955. /*
  956. Feed IGMPv3-gathered local membership information into PIM
  957. per-interface (S,G) state.
  958. */
  959. pim_ifchannel_local_membership_del(group->group_igmp_sock->interface,
  960. source->source_addr, group->group_addr);
  961. IGMP_SOURCE_DONT_FORWARDING(source->source_flags);
  962. }
  963. void pim_forward_start(struct pim_ifchannel *ch)
  964. {
  965. struct pim_upstream *up = ch->upstream;
  966. if (PIM_DEBUG_PIM_TRACE) {
  967. char source_str[100];
  968. char group_str[100];
  969. pim_inet4_dump("<source?>", ch->source_addr, source_str, sizeof(source_str));
  970. pim_inet4_dump("<group?>", ch->group_addr, group_str, sizeof(group_str));
  971. zlog_debug("%s: (S,G)=(%s,%s) oif=%s",
  972. __PRETTY_FUNCTION__,
  973. source_str, group_str, ch->interface->name);
  974. }
  975. if (!up->channel_oil) {
  976. int input_iface_vif_index = fib_lookup_if_vif_index(up->source_addr);
  977. if (input_iface_vif_index < 1) {
  978. char source_str[100];
  979. pim_inet4_dump("<source?>", up->source_addr, source_str, sizeof(source_str));
  980. zlog_warn("%s %s: could not find input interface for source %s",
  981. __FILE__, __PRETTY_FUNCTION__,
  982. source_str);
  983. return;
  984. }
  985. up->channel_oil = pim_channel_oil_add(up->group_addr, up->source_addr,
  986. input_iface_vif_index);
  987. if (!up->channel_oil) {
  988. char group_str[100];
  989. char source_str[100];
  990. pim_inet4_dump("<group?>", up->group_addr, group_str, sizeof(group_str));
  991. pim_inet4_dump("<source?>", up->source_addr, source_str, sizeof(source_str));
  992. zlog_warn("%s %s: could not create OIL for channel (S,G)=(%s,%s)",
  993. __FILE__, __PRETTY_FUNCTION__,
  994. source_str, group_str);
  995. return;
  996. }
  997. }
  998. add_oif(up->channel_oil,
  999. ch->interface,
  1000. PIM_OIF_FLAG_PROTO_PIM);
  1001. }
  1002. void pim_forward_stop(struct pim_ifchannel *ch)
  1003. {
  1004. struct pim_upstream *up = ch->upstream;
  1005. if (PIM_DEBUG_PIM_TRACE) {
  1006. char source_str[100];
  1007. char group_str[100];
  1008. pim_inet4_dump("<source?>", ch->source_addr, source_str, sizeof(source_str));
  1009. pim_inet4_dump("<group?>", ch->group_addr, group_str, sizeof(group_str));
  1010. zlog_debug("%s: (S,G)=(%s,%s) oif=%s",
  1011. __PRETTY_FUNCTION__,
  1012. source_str, group_str, ch->interface->name);
  1013. }
  1014. if (!up->channel_oil) {
  1015. char source_str[100];
  1016. char group_str[100];
  1017. pim_inet4_dump("<source?>", ch->source_addr, source_str, sizeof(source_str));
  1018. pim_inet4_dump("<group?>", ch->group_addr, group_str, sizeof(group_str));
  1019. zlog_warn("%s: (S,G)=(%s,%s) oif=%s missing channel OIL",
  1020. __PRETTY_FUNCTION__,
  1021. source_str, group_str, ch->interface->name);
  1022. return;
  1023. }
  1024. del_oif(up->channel_oil,
  1025. ch->interface,
  1026. PIM_OIF_FLAG_PROTO_PIM);
  1027. }