blob: 805305722803074b419ea0ba2834703ee121fccb [file] [log] [blame]
Yuval Mintz6853f212018-02-28 23:29:29 +02001#ifndef __LINUX_MROUTE_BASE_H
2#define __LINUX_MROUTE_BASE_H
3
4#include <linux/netdevice.h>
Yuval Mintzb70432f2018-02-28 23:29:32 +02005#include <linux/rhashtable.h>
6#include <net/net_namespace.h>
7#include <net/sock.h>
Yuval Mintz6853f212018-02-28 23:29:29 +02008
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
Yuval Mintzb70432f2018-02-28 23:29:32 +020038#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
47/**
48 * struct mr_table - a multicast routing table
49 * @list: entry within a list of multicast routing tables
50 * @net: net where this table belongs
51 * @id: identifier of the table
52 * @mroute_sk: socket associated with the table
53 * @ipmr_expire_timer: timer for handling unresolved routes
54 * @mfc_unres_queue: list of unresolved MFC entries
55 * @vif_table: array containing all possible vifs
56 * @mfc_hash: Hash table of all resolved routes for easy lookup
57 * @mfc_cache_list: list of resovled routes for possible traversal
58 * @maxvif: Identifier of highest value vif currently in use
59 * @cache_resolve_queue_len: current size of unresolved queue
60 * @mroute_do_assert: Whether to inform userspace on wrong ingress
61 * @mroute_do_pim: Whether to receive IGMP PIMv1
62 * @mroute_reg_vif_num: PIM-device vif index
63 */
64struct mr_table {
65 struct list_head list;
66 possible_net_t net;
67 u32 id;
68 struct sock __rcu *mroute_sk;
69 struct timer_list ipmr_expire_timer;
70 struct list_head mfc_unres_queue;
71 struct vif_device vif_table[MAXVIFS];
72 struct rhltable mfc_hash;
73 struct list_head mfc_cache_list;
74 int maxvif;
75 atomic_t cache_resolve_queue_len;
76 bool mroute_do_assert;
77 bool mroute_do_pim;
78 int mroute_reg_vif_num;
79};
80
Yuval Mintz6853f212018-02-28 23:29:29 +020081#ifdef CONFIG_IP_MROUTE_COMMON
82void vif_device_init(struct vif_device *v,
83 struct net_device *dev,
84 unsigned long rate_limit,
85 unsigned char threshold,
86 unsigned short flags,
87 unsigned short get_iflink_mask);
Yuval Mintz0bbbf0e2018-02-28 23:29:33 +020088
89struct mr_table *
90mr_table_alloc(struct net *net, u32 id,
91 const struct rhashtable_params *rht_params,
92 void (*expire_func)(struct timer_list *t),
93 void (*table_set)(struct mr_table *mrt,
94 struct net *net));
Yuval Mintz6853f212018-02-28 23:29:29 +020095#else
96static inline void vif_device_init(struct vif_device *v,
97 struct net_device *dev,
98 unsigned long rate_limit,
99 unsigned char threshold,
100 unsigned short flags,
101 unsigned short get_iflink_mask)
102{
103}
Yuval Mintz0bbbf0e2018-02-28 23:29:33 +0200104
105static inline struct mr_table *
106mr_table_alloc(struct net *net, u32 id,
107 const struct rhashtable_params *rht_params,
108 void (*expire_func)(struct timer_list *t),
109 void (*table_set)(struct mr_table *mrt,
110 struct net *net))
111{
112 return NULL;
113}
Yuval Mintz6853f212018-02-28 23:29:29 +0200114#endif
115#endif