pim_ifchannel.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  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 "linklist.h"
  20. #include "thread.h"
  21. #include "memory.h"
  22. #include "pimd.h"
  23. #include "pim_str.h"
  24. #include "pim_iface.h"
  25. #include "pim_ifchannel.h"
  26. #include "pim_zebra.h"
  27. #include "pim_time.h"
  28. #include "pim_msg.h"
  29. #include "pim_pim.h"
  30. #include "pim_join.h"
  31. #include "pim_rpf.h"
  32. #include "pim_macro.h"
  33. void pim_ifchannel_free(struct pim_ifchannel *ch)
  34. {
  35. zassert(!ch->t_ifjoin_expiry_timer);
  36. zassert(!ch->t_ifjoin_prune_pending_timer);
  37. zassert(!ch->t_ifassert_timer);
  38. XFREE(MTYPE_PIM_IFCHANNEL, ch);
  39. }
  40. void pim_ifchannel_delete(struct pim_ifchannel *ch)
  41. {
  42. struct pim_interface *pim_ifp;
  43. pim_ifp = ch->interface->info;
  44. zassert(pim_ifp);
  45. if (ch->ifjoin_state != PIM_IFJOIN_NOINFO) {
  46. pim_upstream_update_join_desired(ch->upstream);
  47. }
  48. pim_upstream_del(ch->upstream);
  49. THREAD_OFF(ch->t_ifjoin_expiry_timer);
  50. THREAD_OFF(ch->t_ifjoin_prune_pending_timer);
  51. THREAD_OFF(ch->t_ifassert_timer);
  52. /*
  53. notice that listnode_delete() can't be moved
  54. into pim_ifchannel_free() because the later is
  55. called by list_delete_all_node()
  56. */
  57. listnode_delete(pim_ifp->pim_ifchannel_list, ch);
  58. pim_ifchannel_free(ch);
  59. }
  60. #define IFCHANNEL_NOINFO(ch) \
  61. ( \
  62. ((ch)->local_ifmembership == PIM_IFMEMBERSHIP_NOINFO) \
  63. && \
  64. ((ch)->ifjoin_state == PIM_IFJOIN_NOINFO) \
  65. && \
  66. ((ch)->ifassert_state == PIM_IFASSERT_NOINFO) \
  67. )
  68. static void delete_on_noinfo(struct pim_ifchannel *ch)
  69. {
  70. if (IFCHANNEL_NOINFO(ch)) {
  71. /* In NOINFO state, timers should have been cleared */
  72. zassert(!ch->t_ifjoin_expiry_timer);
  73. zassert(!ch->t_ifjoin_prune_pending_timer);
  74. zassert(!ch->t_ifassert_timer);
  75. pim_ifchannel_delete(ch);
  76. }
  77. }
  78. void pim_ifchannel_ifjoin_switch(const char *caller,
  79. struct pim_ifchannel *ch,
  80. enum pim_ifjoin_state new_state)
  81. {
  82. enum pim_ifjoin_state old_state = ch->ifjoin_state;
  83. if (old_state == new_state) {
  84. zlog_debug("%s calledby %s: non-transition on state %d (%s)",
  85. __PRETTY_FUNCTION__, caller, new_state,
  86. pim_ifchannel_ifjoin_name(new_state));
  87. return;
  88. }
  89. zassert(old_state != new_state);
  90. ch->ifjoin_state = new_state;
  91. /* Transition to/from NOINFO ? */
  92. if (
  93. (old_state == PIM_IFJOIN_NOINFO)
  94. ||
  95. (new_state == PIM_IFJOIN_NOINFO)
  96. ) {
  97. if (PIM_DEBUG_PIM_EVENTS) {
  98. char src_str[100];
  99. char grp_str[100];
  100. pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
  101. pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
  102. zlog_debug("PIM_IFCHANNEL_%s: (S,G)=(%s,%s) on interface %s",
  103. ((new_state == PIM_IFJOIN_NOINFO) ? "DOWN" : "UP"),
  104. src_str, grp_str, ch->interface->name);
  105. }
  106. /*
  107. Record uptime of state transition to/from NOINFO
  108. */
  109. ch->ifjoin_creation = pim_time_monotonic_sec();
  110. pim_upstream_update_join_desired(ch->upstream);
  111. pim_ifchannel_update_could_assert(ch);
  112. pim_ifchannel_update_assert_tracking_desired(ch);
  113. }
  114. }
  115. const char *pim_ifchannel_ifjoin_name(enum pim_ifjoin_state ifjoin_state)
  116. {
  117. switch (ifjoin_state) {
  118. case PIM_IFJOIN_NOINFO: return "NOINFO";
  119. case PIM_IFJOIN_JOIN: return "JOIN";
  120. case PIM_IFJOIN_PRUNE_PENDING: return "PRUNEP";
  121. }
  122. return "ifjoin_bad_state";
  123. }
  124. const char *pim_ifchannel_ifassert_name(enum pim_ifassert_state ifassert_state)
  125. {
  126. switch (ifassert_state) {
  127. case PIM_IFASSERT_NOINFO: return "NOINFO";
  128. case PIM_IFASSERT_I_AM_WINNER: return "WINNER";
  129. case PIM_IFASSERT_I_AM_LOSER: return "LOSER";
  130. }
  131. return "ifassert_bad_state";
  132. }
  133. /*
  134. RFC 4601: 4.6.5. Assert State Macros
  135. AssertWinner(S,G,I) defaults to NULL and AssertWinnerMetric(S,G,I)
  136. defaults to Infinity when in the NoInfo state.
  137. */
  138. void reset_ifassert_state(struct pim_ifchannel *ch)
  139. {
  140. THREAD_OFF(ch->t_ifassert_timer);
  141. pim_ifassert_winner_set(ch,
  142. PIM_IFASSERT_NOINFO,
  143. qpim_inaddr_any,
  144. qpim_infinite_assert_metric);
  145. }
  146. static struct pim_ifchannel *pim_ifchannel_new(struct interface *ifp,
  147. struct in_addr source_addr,
  148. struct in_addr group_addr)
  149. {
  150. struct pim_ifchannel *ch;
  151. struct pim_interface *pim_ifp;
  152. struct pim_upstream *up;
  153. pim_ifp = ifp->info;
  154. zassert(pim_ifp);
  155. up = pim_upstream_add(source_addr, group_addr);
  156. if (!up) {
  157. char src_str[100];
  158. char grp_str[100];
  159. pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
  160. pim_inet4_dump("<grp?>", group_addr, grp_str, sizeof(grp_str));
  161. zlog_err("%s: could not attach upstream (S,G)=(%s,%s) on interface %s",
  162. __PRETTY_FUNCTION__,
  163. src_str, grp_str, ifp->name);
  164. return 0;
  165. }
  166. ch = XMALLOC(MTYPE_PIM_IFCHANNEL, sizeof(*ch));
  167. if (!ch) {
  168. zlog_err("%s: PIM XMALLOC(%zu) failure",
  169. __PRETTY_FUNCTION__, sizeof(*ch));
  170. return 0;
  171. }
  172. ch->flags = 0;
  173. ch->upstream = up;
  174. ch->interface = ifp;
  175. ch->source_addr = source_addr;
  176. ch->group_addr = group_addr;
  177. ch->local_ifmembership = PIM_IFMEMBERSHIP_NOINFO;
  178. ch->ifjoin_state = PIM_IFJOIN_NOINFO;
  179. ch->t_ifjoin_expiry_timer = 0;
  180. ch->t_ifjoin_prune_pending_timer = 0;
  181. ch->ifjoin_creation = 0;
  182. /* Assert state */
  183. ch->t_ifassert_timer = 0;
  184. reset_ifassert_state(ch);
  185. if (pim_macro_ch_could_assert_eval(ch))
  186. PIM_IF_FLAG_SET_COULD_ASSERT(ch->flags);
  187. else
  188. PIM_IF_FLAG_UNSET_COULD_ASSERT(ch->flags);
  189. if (pim_macro_assert_tracking_desired_eval(ch))
  190. PIM_IF_FLAG_SET_ASSERT_TRACKING_DESIRED(ch->flags);
  191. else
  192. PIM_IF_FLAG_UNSET_ASSERT_TRACKING_DESIRED(ch->flags);
  193. ch->ifassert_my_metric = pim_macro_ch_my_assert_metric_eval(ch);
  194. /* Attach to list */
  195. listnode_add(pim_ifp->pim_ifchannel_list, ch);
  196. zassert(IFCHANNEL_NOINFO(ch));
  197. return ch;
  198. }
  199. struct pim_ifchannel *pim_ifchannel_find(struct interface *ifp,
  200. struct in_addr source_addr,
  201. struct in_addr group_addr)
  202. {
  203. struct pim_interface *pim_ifp;
  204. struct listnode *ch_node;
  205. struct pim_ifchannel *ch;
  206. zassert(ifp);
  207. pim_ifp = ifp->info;
  208. if (!pim_ifp) {
  209. char src_str[100];
  210. char grp_str[100];
  211. pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
  212. pim_inet4_dump("<grp?>", group_addr, grp_str, sizeof(grp_str));
  213. zlog_warn("%s: (S,G)=(%s,%s): multicast not enabled on interface %s",
  214. __PRETTY_FUNCTION__,
  215. src_str, grp_str,
  216. ifp->name);
  217. return 0;
  218. }
  219. for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
  220. if (
  221. (source_addr.s_addr == ch->source_addr.s_addr) &&
  222. (group_addr.s_addr == ch->group_addr.s_addr)
  223. ) {
  224. return ch;
  225. }
  226. }
  227. return 0;
  228. }
  229. static void ifmembership_set(struct pim_ifchannel *ch,
  230. enum pim_ifmembership membership)
  231. {
  232. if (ch->local_ifmembership == membership)
  233. return;
  234. /* if (PIM_DEBUG_PIM_EVENTS) */ {
  235. char src_str[100];
  236. char grp_str[100];
  237. pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
  238. pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
  239. zlog_debug("%s: (S,G)=(%s,%s) membership now is %s on interface %s",
  240. __PRETTY_FUNCTION__,
  241. src_str, grp_str,
  242. membership == PIM_IFMEMBERSHIP_INCLUDE ? "INCLUDE" : "NOINFO",
  243. ch->interface->name);
  244. }
  245. ch->local_ifmembership = membership;
  246. pim_upstream_update_join_desired(ch->upstream);
  247. pim_ifchannel_update_could_assert(ch);
  248. pim_ifchannel_update_assert_tracking_desired(ch);
  249. }
  250. void pim_ifchannel_membership_clear(struct interface *ifp)
  251. {
  252. struct pim_interface *pim_ifp;
  253. struct listnode *ch_node;
  254. struct pim_ifchannel *ch;
  255. pim_ifp = ifp->info;
  256. zassert(pim_ifp);
  257. for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
  258. ifmembership_set(ch, PIM_IFMEMBERSHIP_NOINFO);
  259. }
  260. }
  261. void pim_ifchannel_delete_on_noinfo(struct interface *ifp)
  262. {
  263. struct pim_interface *pim_ifp;
  264. struct listnode *node;
  265. struct listnode *next_node;
  266. struct pim_ifchannel *ch;
  267. pim_ifp = ifp->info;
  268. zassert(pim_ifp);
  269. for (ALL_LIST_ELEMENTS(pim_ifp->pim_ifchannel_list, node, next_node, ch)) {
  270. delete_on_noinfo(ch);
  271. }
  272. }
  273. struct pim_ifchannel *pim_ifchannel_add(struct interface *ifp,
  274. struct in_addr source_addr,
  275. struct in_addr group_addr)
  276. {
  277. struct pim_ifchannel *ch;
  278. char src_str[100];
  279. char grp_str[100];
  280. ch = pim_ifchannel_find(ifp, source_addr, group_addr);
  281. if (ch)
  282. return ch;
  283. ch = pim_ifchannel_new(ifp, source_addr, group_addr);
  284. if (ch)
  285. return ch;
  286. pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
  287. pim_inet4_dump("<grp?>", group_addr, grp_str, sizeof(grp_str));
  288. zlog_warn("%s: pim_ifchannel_new() failure for (S,G)=(%s,%s) on interface %s",
  289. __PRETTY_FUNCTION__,
  290. src_str, grp_str, ifp->name);
  291. return 0;
  292. }
  293. static void ifjoin_to_noinfo(struct pim_ifchannel *ch)
  294. {
  295. pim_forward_stop(ch);
  296. pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, ch, PIM_IFJOIN_NOINFO);
  297. delete_on_noinfo(ch);
  298. }
  299. static int on_ifjoin_expiry_timer(struct thread *t)
  300. {
  301. struct pim_ifchannel *ch;
  302. zassert(t);
  303. ch = THREAD_ARG(t);
  304. zassert(ch);
  305. ch->t_ifjoin_expiry_timer = 0;
  306. zassert(ch->ifjoin_state == PIM_IFJOIN_JOIN);
  307. ifjoin_to_noinfo(ch);
  308. /* ch may have been deleted */
  309. return 0;
  310. }
  311. static void prune_echo(struct interface *ifp,
  312. struct in_addr source_addr,
  313. struct in_addr group_addr)
  314. {
  315. struct pim_interface *pim_ifp;
  316. struct in_addr neigh_dst_addr;
  317. pim_ifp = ifp->info;
  318. zassert(pim_ifp);
  319. neigh_dst_addr = pim_ifp->primary_address;
  320. if (PIM_DEBUG_PIM_EVENTS) {
  321. char source_str[100];
  322. char group_str[100];
  323. char neigh_dst_str[100];
  324. pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
  325. pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
  326. pim_inet4_dump("<neigh?>", neigh_dst_addr, neigh_dst_str, sizeof(neigh_dst_str));
  327. zlog_debug("%s: sending PruneEcho(S,G)=(%s,%s) to upstream=%s on interface %s",
  328. __PRETTY_FUNCTION__, source_str, group_str, neigh_dst_str, ifp->name);
  329. }
  330. pim_joinprune_send(ifp, neigh_dst_addr, source_addr, group_addr,
  331. 0 /* boolean: send_join=false (prune) */);
  332. }
  333. static int on_ifjoin_prune_pending_timer(struct thread *t)
  334. {
  335. struct pim_ifchannel *ch;
  336. int send_prune_echo; /* boolean */
  337. struct interface *ifp;
  338. struct pim_interface *pim_ifp;
  339. struct in_addr ch_source;
  340. struct in_addr ch_group;
  341. zassert(t);
  342. ch = THREAD_ARG(t);
  343. zassert(ch);
  344. ch->t_ifjoin_prune_pending_timer = 0;
  345. zassert(ch->ifjoin_state == PIM_IFJOIN_PRUNE_PENDING);
  346. /* Send PruneEcho(S,G) ? */
  347. ifp = ch->interface;
  348. pim_ifp = ifp->info;
  349. send_prune_echo = (listcount(pim_ifp->pim_neighbor_list) > 1);
  350. /* Save (S,G) */
  351. ch_source = ch->source_addr;
  352. ch_group = ch->group_addr;
  353. ifjoin_to_noinfo(ch);
  354. /* from here ch may have been deleted */
  355. if (send_prune_echo)
  356. prune_echo(ifp, ch_source, ch_group);
  357. return 0;
  358. }
  359. static void check_recv_upstream(int is_join,
  360. struct interface *recv_ifp,
  361. struct in_addr upstream,
  362. struct in_addr source_addr,
  363. struct in_addr group_addr,
  364. uint8_t source_flags,
  365. int holdtime)
  366. {
  367. struct pim_upstream *up;
  368. /* Upstream (S,G) in Joined state ? */
  369. up = pim_upstream_find(source_addr, group_addr);
  370. if (!up)
  371. return;
  372. if (up->join_state != PIM_UPSTREAM_JOINED)
  373. return;
  374. /* Upstream (S,G) in Joined state */
  375. if (PIM_INADDR_IS_ANY(up->rpf.rpf_addr)) {
  376. /* RPF'(S,G) not found */
  377. char src_str[100];
  378. char grp_str[100];
  379. pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
  380. pim_inet4_dump("<grp?>", group_addr, grp_str, sizeof(grp_str));
  381. zlog_warn("%s %s: RPF'(%s,%s) not found",
  382. __FILE__, __PRETTY_FUNCTION__,
  383. src_str, grp_str);
  384. return;
  385. }
  386. /* upstream directed to RPF'(S,G) ? */
  387. if (upstream.s_addr != up->rpf.rpf_addr.s_addr) {
  388. char src_str[100];
  389. char grp_str[100];
  390. char up_str[100];
  391. char rpf_str[100];
  392. pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
  393. pim_inet4_dump("<grp?>", group_addr, grp_str, sizeof(grp_str));
  394. pim_inet4_dump("<up?>", upstream, up_str, sizeof(up_str));
  395. pim_inet4_dump("<rpf?>", up->rpf.rpf_addr, rpf_str, sizeof(rpf_str));
  396. zlog_warn("%s %s: (S,G)=(%s,%s) upstream=%s not directed to RPF'(S,G)=%s on interface %s",
  397. __FILE__, __PRETTY_FUNCTION__,
  398. src_str, grp_str,
  399. up_str, rpf_str, recv_ifp->name);
  400. return;
  401. }
  402. /* upstream directed to RPF'(S,G) */
  403. if (is_join) {
  404. /* Join(S,G) to RPF'(S,G) */
  405. pim_upstream_join_suppress(up, up->rpf.rpf_addr, holdtime);
  406. return;
  407. }
  408. /* Prune to RPF'(S,G) */
  409. if (source_flags & PIM_RPT_BIT_MASK) {
  410. if (source_flags & PIM_WILDCARD_BIT_MASK) {
  411. /* Prune(*,G) to RPF'(S,G) */
  412. pim_upstream_join_timer_decrease_to_t_override("Prune(*,G)",
  413. up, up->rpf.rpf_addr);
  414. return;
  415. }
  416. /* Prune(S,G,rpt) to RPF'(S,G) */
  417. pim_upstream_join_timer_decrease_to_t_override("Prune(S,G,rpt)",
  418. up, up->rpf.rpf_addr);
  419. return;
  420. }
  421. /* Prune(S,G) to RPF'(S,G) */
  422. pim_upstream_join_timer_decrease_to_t_override("Prune(S,G)", up,
  423. up->rpf.rpf_addr);
  424. }
  425. static int nonlocal_upstream(int is_join,
  426. struct interface *recv_ifp,
  427. struct in_addr upstream,
  428. struct in_addr source_addr,
  429. struct in_addr group_addr,
  430. uint8_t source_flags,
  431. uint16_t holdtime)
  432. {
  433. struct pim_interface *recv_pim_ifp;
  434. int is_local; /* boolean */
  435. recv_pim_ifp = recv_ifp->info;
  436. zassert(recv_pim_ifp);
  437. is_local = (upstream.s_addr == recv_pim_ifp->primary_address.s_addr);
  438. if (PIM_DEBUG_PIM_TRACE) {
  439. char up_str[100];
  440. char src_str[100];
  441. char grp_str[100];
  442. pim_inet4_dump("<upstream?>", upstream, up_str, sizeof(up_str));
  443. pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
  444. pim_inet4_dump("<grp?>", group_addr, grp_str, sizeof(grp_str));
  445. zlog_warn("%s: recv %s (S,G)=(%s,%s) to %s upstream=%s on %s",
  446. __PRETTY_FUNCTION__,
  447. is_join ? "join" : "prune",
  448. src_str, grp_str,
  449. is_local ? "local" : "non-local",
  450. up_str, recv_ifp->name);
  451. }
  452. if (is_local)
  453. return 0;
  454. /*
  455. Since recv upstream addr was not directed to our primary
  456. address, check if we should react to it in any way.
  457. */
  458. check_recv_upstream(is_join, recv_ifp, upstream, source_addr, group_addr,
  459. source_flags, holdtime);
  460. return 1; /* non-local */
  461. }
  462. void pim_ifchannel_join_add(struct interface *ifp,
  463. struct in_addr neigh_addr,
  464. struct in_addr upstream,
  465. struct in_addr source_addr,
  466. struct in_addr group_addr,
  467. uint8_t source_flags,
  468. uint16_t holdtime)
  469. {
  470. struct pim_interface *pim_ifp;
  471. struct pim_ifchannel *ch;
  472. if (nonlocal_upstream(1 /* join */, ifp, upstream,
  473. source_addr, group_addr, source_flags, holdtime)) {
  474. return;
  475. }
  476. ch = pim_ifchannel_add(ifp, source_addr, group_addr);
  477. if (!ch)
  478. return;
  479. /*
  480. RFC 4601: 4.6.1. (S,G) Assert Message State Machine
  481. Transitions from "I am Assert Loser" State
  482. Receive Join(S,G) on Interface I
  483. We receive a Join(S,G) that has the Upstream Neighbor Address
  484. field set to my primary IP address on interface I. The action is
  485. to transition to NoInfo state, delete this (S,G) assert state
  486. (Actions A5 below), and allow the normal PIM Join/Prune mechanisms
  487. to operate.
  488. Notice: The nonlocal_upstream() test above ensures the upstream
  489. address of the join message is our primary address.
  490. */
  491. if (ch->ifassert_state == PIM_IFASSERT_I_AM_LOSER) {
  492. char src_str[100];
  493. char grp_str[100];
  494. char neigh_str[100];
  495. pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
  496. pim_inet4_dump("<grp?>", group_addr, grp_str, sizeof(grp_str));
  497. pim_inet4_dump("<neigh?>", neigh_addr, neigh_str, sizeof(neigh_str));
  498. zlog_warn("%s: Assert Loser recv Join(%s,%s) from %s on %s",
  499. __PRETTY_FUNCTION__,
  500. src_str, grp_str, neigh_str, ifp->name);
  501. assert_action_a5(ch);
  502. }
  503. pim_ifp = ifp->info;
  504. zassert(pim_ifp);
  505. switch (ch->ifjoin_state) {
  506. case PIM_IFJOIN_NOINFO:
  507. pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, ch, PIM_IFJOIN_JOIN);
  508. if (pim_macro_chisin_oiflist(ch)) {
  509. pim_forward_start(ch);
  510. }
  511. break;
  512. case PIM_IFJOIN_JOIN:
  513. zassert(!ch->t_ifjoin_prune_pending_timer);
  514. /*
  515. In the JOIN state ch->t_ifjoin_expiry_timer may be NULL due to a
  516. previously received join message with holdtime=0xFFFF.
  517. */
  518. if (ch->t_ifjoin_expiry_timer) {
  519. unsigned long remain =
  520. thread_timer_remain_second(ch->t_ifjoin_expiry_timer);
  521. if (remain > holdtime) {
  522. /*
  523. RFC 4601: 4.5.3. Receiving (S,G) Join/Prune Messages
  524. Transitions from Join State
  525. The (S,G) downstream state machine on interface I remains in
  526. Join state, and the Expiry Timer (ET) is restarted, set to
  527. maximum of its current value and the HoldTime from the
  528. triggering Join/Prune message.
  529. Conclusion: Do not change the ET if the current value is
  530. higher than the received join holdtime.
  531. */
  532. return;
  533. }
  534. }
  535. THREAD_OFF(ch->t_ifjoin_expiry_timer);
  536. break;
  537. case PIM_IFJOIN_PRUNE_PENDING:
  538. zassert(!ch->t_ifjoin_expiry_timer);
  539. zassert(ch->t_ifjoin_prune_pending_timer);
  540. THREAD_OFF(ch->t_ifjoin_prune_pending_timer);
  541. pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, ch, PIM_IFJOIN_JOIN);
  542. break;
  543. }
  544. zassert(!IFCHANNEL_NOINFO(ch));
  545. if (holdtime != 0xFFFF) {
  546. THREAD_TIMER_ON(master, ch->t_ifjoin_expiry_timer,
  547. on_ifjoin_expiry_timer,
  548. ch, holdtime);
  549. }
  550. }
  551. void pim_ifchannel_prune(struct interface *ifp,
  552. struct in_addr upstream,
  553. struct in_addr source_addr,
  554. struct in_addr group_addr,
  555. uint8_t source_flags,
  556. uint16_t holdtime)
  557. {
  558. struct pim_ifchannel *ch;
  559. int jp_override_interval_msec;
  560. if (nonlocal_upstream(0 /* prune */, ifp, upstream,
  561. source_addr, group_addr, source_flags, holdtime)) {
  562. return;
  563. }
  564. ch = pim_ifchannel_add(ifp, source_addr, group_addr);
  565. if (!ch)
  566. return;
  567. switch (ch->ifjoin_state) {
  568. case PIM_IFJOIN_NOINFO:
  569. case PIM_IFJOIN_PRUNE_PENDING:
  570. /* nothing to do */
  571. break;
  572. case PIM_IFJOIN_JOIN:
  573. {
  574. struct pim_interface *pim_ifp;
  575. pim_ifp = ifp->info;
  576. zassert(ch->t_ifjoin_expiry_timer);
  577. zassert(!ch->t_ifjoin_prune_pending_timer);
  578. THREAD_OFF(ch->t_ifjoin_expiry_timer);
  579. pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, ch, PIM_IFJOIN_PRUNE_PENDING);
  580. if (listcount(pim_ifp->pim_neighbor_list) > 1) {
  581. jp_override_interval_msec = pim_if_jp_override_interval_msec(ifp);
  582. }
  583. else {
  584. jp_override_interval_msec = 0; /* schedule to expire immediately */
  585. /* If we called ifjoin_prune() directly instead, care should
  586. be taken not to use "ch" afterwards since it would be
  587. deleted. */
  588. }
  589. THREAD_TIMER_MSEC_ON(master, ch->t_ifjoin_prune_pending_timer,
  590. on_ifjoin_prune_pending_timer,
  591. ch, jp_override_interval_msec);
  592. zassert(!ch->t_ifjoin_expiry_timer);
  593. zassert(ch->t_ifjoin_prune_pending_timer);
  594. }
  595. break;
  596. }
  597. }
  598. void pim_ifchannel_local_membership_add(struct interface *ifp,
  599. struct in_addr source_addr,
  600. struct in_addr group_addr)
  601. {
  602. struct pim_ifchannel *ch;
  603. struct pim_interface *pim_ifp;
  604. /* PIM enabled on interface? */
  605. pim_ifp = ifp->info;
  606. if (!pim_ifp)
  607. return;
  608. if (!PIM_IF_TEST_PIM(pim_ifp->options))
  609. return;
  610. ch = pim_ifchannel_add(ifp, source_addr, group_addr);
  611. if (!ch) {
  612. return;
  613. }
  614. ifmembership_set(ch, PIM_IFMEMBERSHIP_INCLUDE);
  615. zassert(!IFCHANNEL_NOINFO(ch));
  616. }
  617. void pim_ifchannel_local_membership_del(struct interface *ifp,
  618. struct in_addr source_addr,
  619. struct in_addr group_addr)
  620. {
  621. struct pim_ifchannel *ch;
  622. struct pim_interface *pim_ifp;
  623. /* PIM enabled on interface? */
  624. pim_ifp = ifp->info;
  625. if (!pim_ifp)
  626. return;
  627. if (!PIM_IF_TEST_PIM(pim_ifp->options))
  628. return;
  629. ch = pim_ifchannel_find(ifp, source_addr, group_addr);
  630. if (!ch)
  631. return;
  632. ifmembership_set(ch, PIM_IFMEMBERSHIP_NOINFO);
  633. delete_on_noinfo(ch);
  634. }
  635. void pim_ifchannel_update_could_assert(struct pim_ifchannel *ch)
  636. {
  637. int old_couldassert = PIM_FORCE_BOOLEAN(PIM_IF_FLAG_TEST_COULD_ASSERT(ch->flags));
  638. int new_couldassert = PIM_FORCE_BOOLEAN(pim_macro_ch_could_assert_eval(ch));
  639. if (new_couldassert == old_couldassert)
  640. return;
  641. if (PIM_DEBUG_PIM_EVENTS) {
  642. char src_str[100];
  643. char grp_str[100];
  644. pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
  645. pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
  646. zlog_debug("%s: CouldAssert(%s,%s,%s) changed from %d to %d",
  647. __PRETTY_FUNCTION__,
  648. src_str, grp_str, ch->interface->name,
  649. old_couldassert, new_couldassert);
  650. }
  651. if (new_couldassert) {
  652. /* CouldAssert(S,G,I) switched from FALSE to TRUE */
  653. PIM_IF_FLAG_SET_COULD_ASSERT(ch->flags);
  654. }
  655. else {
  656. /* CouldAssert(S,G,I) switched from TRUE to FALSE */
  657. PIM_IF_FLAG_UNSET_COULD_ASSERT(ch->flags);
  658. if (ch->ifassert_state == PIM_IFASSERT_I_AM_WINNER) {
  659. assert_action_a4(ch);
  660. }
  661. }
  662. pim_ifchannel_update_my_assert_metric(ch);
  663. }
  664. /*
  665. my_assert_metric may be affected by:
  666. CouldAssert(S,G)
  667. pim_ifp->primary_address
  668. rpf->source_nexthop.mrib_metric_preference;
  669. rpf->source_nexthop.mrib_route_metric;
  670. */
  671. void pim_ifchannel_update_my_assert_metric(struct pim_ifchannel *ch)
  672. {
  673. struct pim_assert_metric my_metric_new = pim_macro_ch_my_assert_metric_eval(ch);
  674. if (pim_assert_metric_match(&my_metric_new, &ch->ifassert_my_metric))
  675. return;
  676. if (PIM_DEBUG_PIM_EVENTS) {
  677. char src_str[100];
  678. char grp_str[100];
  679. char old_addr_str[100];
  680. char new_addr_str[100];
  681. pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
  682. pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
  683. pim_inet4_dump("<old_addr?>", ch->ifassert_my_metric.ip_address, old_addr_str, sizeof(old_addr_str));
  684. pim_inet4_dump("<new_addr?>", my_metric_new.ip_address, new_addr_str, sizeof(new_addr_str));
  685. zlog_debug("%s: my_assert_metric(%s,%s,%s) changed from %u,%u,%u,%s to %u,%u,%u,%s",
  686. __PRETTY_FUNCTION__,
  687. src_str, grp_str, ch->interface->name,
  688. ch->ifassert_my_metric.rpt_bit_flag,
  689. ch->ifassert_my_metric.metric_preference,
  690. ch->ifassert_my_metric.route_metric,
  691. old_addr_str,
  692. my_metric_new.rpt_bit_flag,
  693. my_metric_new.metric_preference,
  694. my_metric_new.route_metric,
  695. new_addr_str);
  696. }
  697. ch->ifassert_my_metric = my_metric_new;
  698. if (pim_assert_metric_better(&ch->ifassert_my_metric,
  699. &ch->ifassert_winner_metric)) {
  700. assert_action_a5(ch);
  701. }
  702. }
  703. void pim_ifchannel_update_assert_tracking_desired(struct pim_ifchannel *ch)
  704. {
  705. int old_atd = PIM_FORCE_BOOLEAN(PIM_IF_FLAG_TEST_ASSERT_TRACKING_DESIRED(ch->flags));
  706. int new_atd = PIM_FORCE_BOOLEAN(pim_macro_assert_tracking_desired_eval(ch));
  707. if (new_atd == old_atd)
  708. return;
  709. if (PIM_DEBUG_PIM_EVENTS) {
  710. char src_str[100];
  711. char grp_str[100];
  712. pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
  713. pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
  714. zlog_debug("%s: AssertTrackingDesired(%s,%s,%s) changed from %d to %d",
  715. __PRETTY_FUNCTION__,
  716. src_str, grp_str, ch->interface->name,
  717. old_atd, new_atd);
  718. }
  719. if (new_atd) {
  720. /* AssertTrackingDesired(S,G,I) switched from FALSE to TRUE */
  721. PIM_IF_FLAG_SET_ASSERT_TRACKING_DESIRED(ch->flags);
  722. }
  723. else {
  724. /* AssertTrackingDesired(S,G,I) switched from TRUE to FALSE */
  725. PIM_IF_FLAG_UNSET_ASSERT_TRACKING_DESIRED(ch->flags);
  726. if (ch->ifassert_state == PIM_IFASSERT_I_AM_LOSER) {
  727. assert_action_a5(ch);
  728. }
  729. }
  730. }