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