pimd.c 4.5 KB

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