pim_mroute.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #ifndef PIM_MROUTE_H
  19. #define PIM_MROUTE_H
  20. /*
  21. For msghdr.msg_control in Solaris 10
  22. */
  23. #ifndef _XPG4_2
  24. #define _XPG4_2
  25. #endif
  26. #ifndef __EXTENSIONS__
  27. #define __EXTENSIONS__
  28. #endif
  29. #include <netinet/in.h>
  30. #ifdef HAVE_NETINET_IP_MROUTE_H
  31. #include <netinet/ip_mroute.h>
  32. #endif
  33. #define PIM_MROUTE_MIN_TTL (1)
  34. #if defined(HAVE_LINUX_MROUTE_H)
  35. #include <linux/mroute.h>
  36. #else
  37. /*
  38. Below: from <linux/mroute.h>
  39. */
  40. #ifndef MAXVIFS
  41. #define MAXVIFS (32)
  42. #endif
  43. #ifndef SIOCGETVIFCNT
  44. #define SIOCGETVIFCNT SIOCPROTOPRIVATE /* IP protocol privates */
  45. #define SIOCGETSGCNT (SIOCPROTOPRIVATE+1)
  46. #define SIOCGETRPF (SIOCPROTOPRIVATE+2)
  47. #endif
  48. #ifndef MRT_INIT
  49. #define MRT_BASE 200
  50. #define MRT_INIT (MRT_BASE) /* Activate the kernel mroute code */
  51. #define MRT_DONE (MRT_BASE+1) /* Shutdown the kernel mroute */
  52. #define MRT_ADD_VIF (MRT_BASE+2) /* Add a virtual interface */
  53. #define MRT_DEL_VIF (MRT_BASE+3) /* Delete a virtual interface */
  54. #define MRT_ADD_MFC (MRT_BASE+4) /* Add a multicast forwarding entry */
  55. #define MRT_DEL_MFC (MRT_BASE+5) /* Delete a multicast forwarding entry */
  56. #define MRT_VERSION (MRT_BASE+6) /* Get the kernel multicast version */
  57. #define MRT_ASSERT (MRT_BASE+7) /* Activate PIM assert mode */
  58. #define MRT_PIM (MRT_BASE+8) /* enable PIM code */
  59. #endif
  60. #ifndef HAVE_VIFI_T
  61. typedef unsigned short vifi_t;
  62. #endif
  63. #ifndef HAVE_STRUCT_VIFCTL
  64. struct vifctl {
  65. vifi_t vifc_vifi; /* Index of VIF */
  66. unsigned char vifc_flags; /* VIFF_ flags */
  67. unsigned char vifc_threshold; /* ttl limit */
  68. unsigned int vifc_rate_limit; /* Rate limiter values (NI) */
  69. struct in_addr vifc_lcl_addr; /* Our address */
  70. struct in_addr vifc_rmt_addr; /* IPIP tunnel addr */
  71. };
  72. #endif
  73. #ifndef HAVE_STRUCT_MFCCTL
  74. struct mfcctl {
  75. struct in_addr mfcc_origin; /* Origin of mcast */
  76. struct in_addr mfcc_mcastgrp; /* Group in question */
  77. vifi_t mfcc_parent; /* Where it arrived */
  78. unsigned char mfcc_ttls[MAXVIFS]; /* Where it is going */
  79. unsigned int mfcc_pkt_cnt; /* pkt count for src-grp */
  80. unsigned int mfcc_byte_cnt;
  81. unsigned int mfcc_wrong_if;
  82. int mfcc_expire;
  83. };
  84. #endif
  85. /*
  86. * Group count retrieval for mrouted
  87. */
  88. /*
  89. struct sioc_sg_req sgreq;
  90. memset(&sgreq, 0, sizeof(sgreq));
  91. memcpy(&sgreq.src, &source_addr, sizeof(sgreq.src));
  92. memcpy(&sgreq.grp, &group_addr, sizeof(sgreq.grp));
  93. ioctl(mrouter_s4, SIOCGETSGCNT, &sgreq);
  94. */
  95. #ifndef HAVE_STRUCT_SIOC_SG_REQ
  96. struct sioc_sg_req {
  97. struct in_addr src;
  98. struct in_addr grp;
  99. unsigned long pktcnt;
  100. unsigned long bytecnt;
  101. unsigned long wrong_if;
  102. };
  103. #endif
  104. /*
  105. * To get vif packet counts
  106. */
  107. /*
  108. struct sioc_vif_req vreq;
  109. memset(&vreq, 0, sizeof(vreq));
  110. vreq.vifi = vif_index;
  111. ioctl(mrouter_s4, SIOCGETVIFCNT, &vreq);
  112. */
  113. #ifndef HAVE_STRUCT_SIOC_VIF_REQ
  114. struct sioc_vif_req {
  115. vifi_t vifi; /* Which iface */
  116. unsigned long icount; /* In packets */
  117. unsigned long ocount; /* Out packets */
  118. unsigned long ibytes; /* In bytes */
  119. unsigned long obytes; /* Out bytes */
  120. };
  121. #endif
  122. /*
  123. * Pseudo messages used by mrouted
  124. */
  125. #ifndef IGMPMSG_NOCACHE
  126. #define IGMPMSG_NOCACHE 1 /* Kern cache fill request to mrouted */
  127. #define IGMPMSG_WRONGVIF 2 /* For PIM assert processing (unused) */
  128. #define IGMPMSG_WHOLEPKT 3 /* For PIM Register processing */
  129. #endif
  130. #ifndef HAVE_STRUCT_IGMPMSG
  131. struct igmpmsg
  132. {
  133. uint32_t unused1,unused2;
  134. unsigned char im_msgtype; /* What is this */
  135. unsigned char im_mbz; /* Must be zero */
  136. unsigned char im_vif; /* Interface (this ought to be a vifi_t!) */
  137. unsigned char unused3;
  138. struct in_addr im_src,im_dst;
  139. };
  140. #endif
  141. #endif
  142. /*
  143. Above: from <linux/mroute.h>
  144. */
  145. int pim_mroute_socket_enable(void);
  146. int pim_mroute_socket_disable(void);
  147. int pim_mroute_add_vif(int vif_index, struct in_addr ifaddr);
  148. int pim_mroute_del_vif(int vif_index);
  149. int pim_mroute_add(struct mfcctl *mc);
  150. int pim_mroute_del(struct mfcctl *mc);
  151. int pim_mroute_msg(int fd, const char *buf, int buf_size);
  152. #endif /* PIM_MROUTE_H */