ipmr, ip6mr: Make mfc_cache a common structure
[linux-block.git] / include / linux / mroute_base.h
CommitLineData
6853f21f
YM
1#ifndef __LINUX_MROUTE_BASE_H
2#define __LINUX_MROUTE_BASE_H
3
4#include <linux/netdevice.h>
b70432f7
YM
5#include <linux/rhashtable.h>
6#include <net/net_namespace.h>
7#include <net/sock.h>
6853f21f
YM
8
9/**
10 * struct vif_device - interface representor for multicast routing
11 * @dev: network device being used
12 * @bytes_in: statistic; bytes ingressing
13 * @bytes_out: statistic; bytes egresing
14 * @pkt_in: statistic; packets ingressing
15 * @pkt_out: statistic; packets egressing
16 * @rate_limit: Traffic shaping (NI)
17 * @threshold: TTL threshold
18 * @flags: Control flags
19 * @link: Physical interface index
20 * @dev_parent_id: device parent id
21 * @local: Local address
22 * @remote: Remote address for tunnels
23 */
24struct vif_device {
25 struct net_device *dev;
26 unsigned long bytes_in, bytes_out;
27 unsigned long pkt_in, pkt_out;
28 unsigned long rate_limit;
29 unsigned char threshold;
30 unsigned short flags;
31 int link;
32
33 /* Currently only used by ipmr */
34 struct netdev_phys_item_id dev_parent_id;
35 __be32 local, remote;
36};
37
b70432f7
YM
38#ifndef MAXVIFS
39/* This one is nasty; value is defined in uapi using different symbols for
40 * mroute and morute6 but both map into same 32.
41 */
42#define MAXVIFS 32
43#endif
44
45#define VIF_EXISTS(_mrt, _idx) (!!((_mrt)->vif_table[_idx].dev))
46
494fff56
YM
47/**
48 * struct mr_mfc - common multicast routing entries
49 * @mnode: rhashtable list
50 * @mfc_parent: source interface (iif)
51 * @mfc_flags: entry flags
52 * @expires: unresolved entry expire time
53 * @unresolved: unresolved cached skbs
54 * @last_assert: time of last assert
55 * @minvif: minimum VIF id
56 * @maxvif: maximum VIF id
57 * @bytes: bytes that have passed for this entry
58 * @pkt: packets that have passed for this entry
59 * @wrong_if: number of wrong source interface hits
60 * @lastuse: time of last use of the group (traffic or update)
61 * @ttls: OIF TTL threshold array
62 * @refcount: reference count for this entry
63 * @list: global entry list
64 * @rcu: used for entry destruction
65 */
66struct mr_mfc {
67 struct rhlist_head mnode;
68 unsigned short mfc_parent;
69 int mfc_flags;
70
71 union {
72 struct {
73 unsigned long expires;
74 struct sk_buff_head unresolved;
75 } unres;
76 struct {
77 unsigned long last_assert;
78 int minvif;
79 int maxvif;
80 unsigned long bytes;
81 unsigned long pkt;
82 unsigned long wrong_if;
83 unsigned long lastuse;
84 unsigned char ttls[MAXVIFS];
85 refcount_t refcount;
86 } res;
87 } mfc_un;
88 struct list_head list;
89 struct rcu_head rcu;
90};
91
b70432f7
YM
92/**
93 * struct mr_table - a multicast routing table
94 * @list: entry within a list of multicast routing tables
95 * @net: net where this table belongs
96 * @id: identifier of the table
97 * @mroute_sk: socket associated with the table
98 * @ipmr_expire_timer: timer for handling unresolved routes
99 * @mfc_unres_queue: list of unresolved MFC entries
100 * @vif_table: array containing all possible vifs
101 * @mfc_hash: Hash table of all resolved routes for easy lookup
102 * @mfc_cache_list: list of resovled routes for possible traversal
103 * @maxvif: Identifier of highest value vif currently in use
104 * @cache_resolve_queue_len: current size of unresolved queue
105 * @mroute_do_assert: Whether to inform userspace on wrong ingress
106 * @mroute_do_pim: Whether to receive IGMP PIMv1
107 * @mroute_reg_vif_num: PIM-device vif index
108 */
109struct mr_table {
110 struct list_head list;
111 possible_net_t net;
112 u32 id;
113 struct sock __rcu *mroute_sk;
114 struct timer_list ipmr_expire_timer;
115 struct list_head mfc_unres_queue;
116 struct vif_device vif_table[MAXVIFS];
117 struct rhltable mfc_hash;
118 struct list_head mfc_cache_list;
119 int maxvif;
120 atomic_t cache_resolve_queue_len;
121 bool mroute_do_assert;
122 bool mroute_do_pim;
123 int mroute_reg_vif_num;
124};
125
6853f21f
YM
126#ifdef CONFIG_IP_MROUTE_COMMON
127void vif_device_init(struct vif_device *v,
128 struct net_device *dev,
129 unsigned long rate_limit,
130 unsigned char threshold,
131 unsigned short flags,
132 unsigned short get_iflink_mask);
0bbbf0e7
YM
133
134struct mr_table *
135mr_table_alloc(struct net *net, u32 id,
136 const struct rhashtable_params *rht_params,
137 void (*expire_func)(struct timer_list *t),
138 void (*table_set)(struct mr_table *mrt,
139 struct net *net));
6853f21f
YM
140#else
141static inline void vif_device_init(struct vif_device *v,
142 struct net_device *dev,
143 unsigned long rate_limit,
144 unsigned char threshold,
145 unsigned short flags,
146 unsigned short get_iflink_mask)
147{
148}
0bbbf0e7
YM
149
150static inline struct mr_table *
151mr_table_alloc(struct net *net, u32 id,
152 const struct rhashtable_params *rht_params,
153 void (*expire_func)(struct timer_list *t),
154 void (*table_set)(struct mr_table *mrt,
155 struct net *net))
156{
157 return NULL;
158}
6853f21f
YM
159#endif
160#endif