pimd.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 "log.h"
  20. #include "memory.h"
  21. #include "vrf.h"
  22. #include "pimd.h"
  23. #include "pim_cmd.h"
  24. #include "pim_iface.h"
  25. #include "pim_zebra.h"
  26. #include "pim_str.h"
  27. #include "pim_oil.h"
  28. #include "pim_pim.h"
  29. #include "pim_upstream.h"
  30. #include "pim_rpf.h"
  31. #include "pim_ssmpingd.h"
  32. #include "pim_static.h"
  33. const char *const PIM_ALL_SYSTEMS = MCAST_ALL_SYSTEMS;
  34. const char *const PIM_ALL_ROUTERS = MCAST_ALL_ROUTERS;
  35. const char *const PIM_ALL_PIM_ROUTERS = MCAST_ALL_PIM_ROUTERS;
  36. const char *const PIM_ALL_IGMP_ROUTERS = MCAST_ALL_IGMP_ROUTERS;
  37. struct thread_master *master = 0;
  38. uint32_t qpim_debugs = 0;
  39. int qpim_mroute_socket_fd = -1;
  40. int64_t qpim_mroute_socket_creation = 0; /* timestamp of creation */
  41. struct thread *qpim_mroute_socket_reader = 0;
  42. int qpim_mroute_oif_highest_vif_index = -1;
  43. struct list *qpim_channel_oil_list = 0;
  44. int qpim_t_periodic = PIM_DEFAULT_T_PERIODIC; /* Period between Join/Prune Messages */
  45. struct list *qpim_upstream_list = 0;
  46. struct zclient *qpim_zclient_update = 0;
  47. struct zclient *qpim_zclient_lookup = 0;
  48. struct pim_assert_metric qpim_infinite_assert_metric;
  49. long qpim_rpf_cache_refresh_delay_msec = 10000;
  50. struct thread *qpim_rpf_cache_refresher = 0;
  51. int64_t qpim_rpf_cache_refresh_requests = 0;
  52. int64_t qpim_rpf_cache_refresh_events = 0;
  53. int64_t qpim_rpf_cache_refresh_last = 0;
  54. struct in_addr qpim_inaddr_any;
  55. struct list *qpim_ssmpingd_list = 0;
  56. struct in_addr qpim_ssmpingd_group_addr;
  57. int64_t qpim_scan_oil_events = 0;
  58. int64_t qpim_scan_oil_last = 0;
  59. int64_t qpim_mroute_add_events = 0;
  60. int64_t qpim_mroute_add_last = 0;
  61. int64_t qpim_mroute_del_events = 0;
  62. int64_t qpim_mroute_del_last = 0;
  63. struct list *qpim_static_route_list = 0;
  64. static void pim_free()
  65. {
  66. pim_ssmpingd_destroy();
  67. if (qpim_channel_oil_list)
  68. list_free(qpim_channel_oil_list);
  69. if (qpim_upstream_list)
  70. list_free(qpim_upstream_list);
  71. if (qpim_static_route_list)
  72. list_free(qpim_static_route_list);
  73. }
  74. void pim_init()
  75. {
  76. srandom(time(NULL));
  77. if (!inet_aton(PIM_ALL_PIM_ROUTERS, &qpim_all_pim_routers_addr)) {
  78. zlog_err("%s %s: could not solve %s to group address: errno=%d: %s",
  79. __FILE__, __PRETTY_FUNCTION__,
  80. PIM_ALL_PIM_ROUTERS, errno, safe_strerror(errno));
  81. zassert(0);
  82. return;
  83. }
  84. qpim_channel_oil_list = list_new();
  85. if (!qpim_channel_oil_list) {
  86. zlog_err("%s %s: failure: channel_oil_list=list_new()",
  87. __FILE__, __PRETTY_FUNCTION__);
  88. return;
  89. }
  90. qpim_channel_oil_list->del = (void (*)(void *)) pim_channel_oil_free;
  91. qpim_upstream_list = list_new();
  92. if (!qpim_upstream_list) {
  93. zlog_err("%s %s: failure: upstream_list=list_new()",
  94. __FILE__, __PRETTY_FUNCTION__);
  95. pim_free();
  96. return;
  97. }
  98. qpim_upstream_list->del = (void (*)(void *)) pim_upstream_free;
  99. qpim_static_route_list = list_new();
  100. if (!qpim_static_route_list) {
  101. zlog_err("%s %s: failure: static_route_list=list_new()",
  102. __FILE__, __PRETTY_FUNCTION__);
  103. return;
  104. }
  105. qpim_static_route_list->del = (void (*)(void *)) pim_static_route_free;
  106. qpim_mroute_socket_fd = -1; /* mark mroute as disabled */
  107. qpim_mroute_oif_highest_vif_index = -1;
  108. zassert(!qpim_debugs);
  109. zassert(!PIM_MROUTE_IS_ENABLED);
  110. qpim_inaddr_any.s_addr = PIM_NET_INADDR_ANY;
  111. /*
  112. RFC 4601: 4.6.3. Assert Metrics
  113. assert_metric
  114. infinite_assert_metric() {
  115. return {1,infinity,infinity,0}
  116. }
  117. */
  118. qpim_infinite_assert_metric.rpt_bit_flag = 1;
  119. qpim_infinite_assert_metric.metric_preference = PIM_ASSERT_METRIC_PREFERENCE_MAX;
  120. qpim_infinite_assert_metric.route_metric = PIM_ASSERT_ROUTE_METRIC_MAX;
  121. qpim_infinite_assert_metric.ip_address = qpim_inaddr_any;
  122. pim_cmd_init();
  123. pim_ssmpingd_init();
  124. }
  125. void pim_terminate()
  126. {
  127. vrf_terminate();
  128. pim_free();
  129. }