mroute.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #ifndef __LINUX_MROUTE_H
  2. #define __LINUX_MROUTE_H
  3. #include <linux/sockios.h>
  4. #include <linux/in.h>
  5. /*
  6. * Based on the MROUTING 3.5 defines primarily to keep
  7. * source compatibility with BSD.
  8. *
  9. * See the mrouted code for the original history.
  10. *
  11. * Protocol Independent Multicast (PIM) data structures included
  12. * Carlos Picoto (cap@di.fc.ul.pt)
  13. *
  14. */
  15. #define MRT_BASE 200
  16. #define MRT_INIT (MRT_BASE) /* Activate the kernel mroute code */
  17. #define MRT_DONE (MRT_BASE+1) /* Shutdown the kernel mroute */
  18. #define MRT_ADD_VIF (MRT_BASE+2) /* Add a virtual interface */
  19. #define MRT_DEL_VIF (MRT_BASE+3) /* Delete a virtual interface */
  20. #define MRT_ADD_MFC (MRT_BASE+4) /* Add a multicast forwarding entry */
  21. #define MRT_DEL_MFC (MRT_BASE+5) /* Delete a multicast forwarding entry */
  22. #define MRT_VERSION (MRT_BASE+6) /* Get the kernel multicast version */
  23. #define MRT_ASSERT (MRT_BASE+7) /* Activate PIM assert mode */
  24. #define MRT_PIM (MRT_BASE+8) /* enable PIM code */
  25. #define SIOCGETVIFCNT SIOCPROTOPRIVATE /* IP protocol privates */
  26. #define SIOCGETSGCNT (SIOCPROTOPRIVATE+1)
  27. #define SIOCGETRPF (SIOCPROTOPRIVATE+2)
  28. #define MAXVIFS 32
  29. typedef unsigned long vifbitmap_t; /* User mode code depends on this lot */
  30. typedef unsigned short vifi_t;
  31. #define ALL_VIFS ((vifi_t)(-1))
  32. /*
  33. * Same idea as select
  34. */
  35. #define VIFM_SET(n,m) ((m)|=(1<<(n)))
  36. #define VIFM_CLR(n,m) ((m)&=~(1<<(n)))
  37. #define VIFM_ISSET(n,m) ((m)&(1<<(n)))
  38. #define VIFM_CLRALL(m) ((m)=0)
  39. #define VIFM_COPY(mfrom,mto) ((mto)=(mfrom))
  40. #define VIFM_SAME(m1,m2) ((m1)==(m2))
  41. /*
  42. * Passed by mrouted for an MRT_ADD_VIF - again we use the
  43. * mrouted 3.6 structures for compatibility
  44. */
  45. struct vifctl {
  46. vifi_t vifc_vifi; /* Index of VIF */
  47. unsigned char vifc_flags; /* VIFF_ flags */
  48. unsigned char vifc_threshold; /* ttl limit */
  49. unsigned int vifc_rate_limit; /* Rate limiter values (NI) */
  50. struct in_addr vifc_lcl_addr; /* Our address */
  51. struct in_addr vifc_rmt_addr; /* IPIP tunnel addr */
  52. };
  53. #define VIFF_TUNNEL 0x1 /* IPIP tunnel */
  54. #define VIFF_SRCRT 0x2 /* NI */
  55. #define VIFF_REGISTER 0x4 /* register vif */
  56. /*
  57. * Cache manipulation structures for mrouted and PIMd
  58. */
  59. struct mfcctl
  60. {
  61. struct in_addr mfcc_origin; /* Origin of mcast */
  62. struct in_addr mfcc_mcastgrp; /* Group in question */
  63. vifi_t mfcc_parent; /* Where it arrived */
  64. unsigned char mfcc_ttls[MAXVIFS]; /* Where it is going */
  65. unsigned int mfcc_pkt_cnt; /* pkt count for src-grp */
  66. unsigned int mfcc_byte_cnt;
  67. unsigned int mfcc_wrong_if;
  68. int mfcc_expire;
  69. };
  70. /*
  71. * Group count retrieval for mrouted
  72. */
  73. struct sioc_sg_req
  74. {
  75. struct in_addr src;
  76. struct in_addr grp;
  77. unsigned long pktcnt;
  78. unsigned long bytecnt;
  79. unsigned long wrong_if;
  80. };
  81. /*
  82. * To get vif packet counts
  83. */
  84. struct sioc_vif_req
  85. {
  86. vifi_t vifi; /* Which iface */
  87. unsigned long icount; /* In packets */
  88. unsigned long ocount; /* Out packets */
  89. unsigned long ibytes; /* In bytes */
  90. unsigned long obytes; /* Out bytes */
  91. };
  92. /*
  93. * This is the format the mroute daemon expects to see IGMP control
  94. * data. Magically happens to be like an IP packet as per the original
  95. */
  96. struct igmpmsg
  97. {
  98. __u32 unused1,unused2;
  99. unsigned char im_msgtype; /* What is this */
  100. unsigned char im_mbz; /* Must be zero */
  101. unsigned char im_vif; /* Interface (this ought to be a vifi_t!) */
  102. unsigned char unused3;
  103. struct in_addr im_src,im_dst;
  104. };
  105. /*
  106. * That's all usermode folks
  107. */
  108. #ifdef __KERNEL__
  109. #include <net/sock.h>
  110. extern int ip_mroute_setsockopt(struct sock *, int, char __user *, int);
  111. extern int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
  112. extern int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
  113. extern void ip_mr_init(void);
  114. struct vif_device
  115. {
  116. struct net_device *dev; /* Device we are using */
  117. unsigned long bytes_in,bytes_out;
  118. unsigned long pkt_in,pkt_out; /* Statistics */
  119. unsigned long rate_limit; /* Traffic shaping (NI) */
  120. unsigned char threshold; /* TTL threshold */
  121. unsigned short flags; /* Control flags */
  122. __be32 local,remote; /* Addresses(remote for tunnels)*/
  123. int link; /* Physical interface index */
  124. };
  125. #define VIFF_STATIC 0x8000
  126. struct mfc_cache
  127. {
  128. struct mfc_cache *next; /* Next entry on cache line */
  129. __be32 mfc_mcastgrp; /* Group the entry belongs to */
  130. __be32 mfc_origin; /* Source of packet */
  131. vifi_t mfc_parent; /* Source interface */
  132. int mfc_flags; /* Flags on line */
  133. union {
  134. struct {
  135. unsigned long expires;
  136. struct sk_buff_head unresolved; /* Unresolved buffers */
  137. } unres;
  138. struct {
  139. unsigned long last_assert;
  140. int minvif;
  141. int maxvif;
  142. unsigned long bytes;
  143. unsigned long pkt;
  144. unsigned long wrong_if;
  145. unsigned char ttls[MAXVIFS]; /* TTL thresholds */
  146. } res;
  147. } mfc_un;
  148. };
  149. #define MFC_STATIC 1
  150. #define MFC_NOTIFY 2
  151. #define MFC_LINES 64
  152. #ifdef __BIG_ENDIAN
  153. #define MFC_HASH(a,b) (((((__force u32)(__be32)a)>>24)^(((__force u32)(__be32)b)>>26))&(MFC_LINES-1))
  154. #else
  155. #define MFC_HASH(a,b) ((((__force u32)(__be32)a)^(((__force u32)(__be32)b)>>2))&(MFC_LINES-1))
  156. #endif
  157. #endif
  158. #define MFC_ASSERT_THRESH (3*HZ) /* Maximal freq. of asserts */
  159. /*
  160. * Pseudo messages used by mrouted
  161. */
  162. #define IGMPMSG_NOCACHE 1 /* Kern cache fill request to mrouted */
  163. #define IGMPMSG_WRONGVIF 2 /* For PIM assert processing (unused) */
  164. #define IGMPMSG_WHOLEPKT 3 /* For PIM Register processing */
  165. #ifdef __KERNEL__
  166. #define PIM_V1_VERSION __constant_htonl(0x10000000)
  167. #define PIM_V1_REGISTER 1
  168. #define PIM_VERSION 2
  169. #define PIM_REGISTER 1
  170. #define PIM_NULL_REGISTER __constant_htonl(0x40000000)
  171. /* PIMv2 register message header layout (ietf-draft-idmr-pimvsm-v2-00.ps */
  172. struct pimreghdr
  173. {
  174. __u8 type;
  175. __u8 reserved;
  176. __be16 csum;
  177. __be32 flags;
  178. };
  179. extern int pim_rcv_v1(struct sk_buff *);
  180. struct rtmsg;
  181. extern int ipmr_get_route(struct sk_buff *skb, struct rtmsg *rtm, int nowait);
  182. #endif
  183. #endif