1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_MROUTE_H
3 #define __LINUX_MROUTE_H
7 #include <linux/rhashtable.h>
9 #include <net/fib_rules.h>
10 #include <net/fib_notifier.h>
11 #include <uapi/linux/mroute.h>
13 #ifdef CONFIG_IP_MROUTE
14 static inline int ip_mroute_opt(int opt
)
16 return opt
>= MRT_BASE
&& opt
<= MRT_MAX
;
19 int ip_mroute_setsockopt(struct sock
*, int, char __user
*, unsigned int);
20 int ip_mroute_getsockopt(struct sock
*, int, char __user
*, int __user
*);
21 int ipmr_ioctl(struct sock
*sk
, int cmd
, void __user
*arg
);
22 int ipmr_compat_ioctl(struct sock
*sk
, unsigned int cmd
, void __user
*arg
);
24 bool ipmr_rule_default(const struct fib_rule
*rule
);
26 static inline int ip_mroute_setsockopt(struct sock
*sock
, int optname
,
27 char __user
*optval
, unsigned int optlen
)
32 static inline int ip_mroute_getsockopt(struct sock
*sock
, int optname
,
33 char __user
*optval
, int __user
*optlen
)
38 static inline int ipmr_ioctl(struct sock
*sk
, int cmd
, void __user
*arg
)
43 static inline int ip_mr_init(void)
48 static inline int ip_mroute_opt(int opt
)
53 static inline bool ipmr_rule_default(const struct fib_rule
*rule
)
60 struct net_device
*dev
; /* Device we are using */
61 struct netdev_phys_item_id dev_parent_id
; /* Device parent ID */
62 unsigned long bytes_in
,bytes_out
;
63 unsigned long pkt_in
,pkt_out
; /* Statistics */
64 unsigned long rate_limit
; /* Traffic shaping (NI) */
65 unsigned char threshold
; /* TTL threshold */
66 unsigned short flags
; /* Control flags */
67 __be32 local
,remote
; /* Addresses(remote for tunnels)*/
68 int link
; /* Physical interface index */
71 struct vif_entry_notifier_info
{
72 struct fib_notifier_info info
;
73 struct net_device
*dev
;
75 unsigned short vif_flags
;
79 #define VIFF_STATIC 0x8000
81 #define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL)
84 struct list_head list
;
87 struct sock __rcu
*mroute_sk
;
88 struct timer_list ipmr_expire_timer
;
89 struct list_head mfc_unres_queue
;
90 struct vif_device vif_table
[MAXVIFS
];
91 struct rhltable mfc_hash
;
92 struct list_head mfc_cache_list
;
94 atomic_t cache_resolve_queue_len
;
95 bool mroute_do_assert
;
97 int mroute_reg_vif_num
;
101 * MFC_STATIC - the entry was added statically (not by a routing daemon)
102 * MFC_OFFLOAD - the entry was offloaded to the hardware
106 MFC_OFFLOAD
= BIT(1),
109 struct mfc_cache_cmp_arg
{
115 * struct mfc_cache - multicast routing entries
116 * @mnode: rhashtable list
117 * @mfc_mcastgrp: destination multicast group address
118 * @mfc_origin: source address
119 * @cmparg: used for rhashtable comparisons
120 * @mfc_parent: source interface (iif)
121 * @mfc_flags: entry flags
122 * @expires: unresolved entry expire time
123 * @unresolved: unresolved cached skbs
124 * @last_assert: time of last assert
125 * @minvif: minimum VIF id
126 * @maxvif: maximum VIF id
127 * @bytes: bytes that have passed for this entry
128 * @pkt: packets that have passed for this entry
129 * @wrong_if: number of wrong source interface hits
130 * @lastuse: time of last use of the group (traffic or update)
131 * @ttls: OIF TTL threshold array
132 * @refcount: reference count for this entry
133 * @list: global entry list
134 * @rcu: used for entry destruction
137 struct rhlist_head mnode
;
143 struct mfc_cache_cmp_arg cmparg
;
150 unsigned long expires
;
151 struct sk_buff_head unresolved
;
154 unsigned long last_assert
;
159 unsigned long wrong_if
;
160 unsigned long lastuse
;
161 unsigned char ttls
[MAXVIFS
];
165 struct list_head list
;
169 struct mfc_entry_notifier_info
{
170 struct fib_notifier_info info
;
171 struct mfc_cache
*mfc
;
176 int ipmr_get_route(struct net
*net
, struct sk_buff
*skb
,
177 __be32 saddr
, __be32 daddr
,
178 struct rtmsg
*rtm
, u32 portid
);
180 #ifdef CONFIG_IP_MROUTE
181 void ipmr_cache_free(struct mfc_cache
*mfc_cache
);
183 static inline void ipmr_cache_free(struct mfc_cache
*mfc_cache
)
188 static inline void ipmr_cache_put(struct mfc_cache
*c
)
190 if (refcount_dec_and_test(&c
->mfc_un
.res
.refcount
))
193 static inline void ipmr_cache_hold(struct mfc_cache
*c
)
195 refcount_inc(&c
->mfc_un
.res
.refcount
);