Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __LINUX_MROUTE_H |
| 2 | #define __LINUX_MROUTE_H |
| 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/in.h> |
David S. Miller | 7c19a3d | 2008-08-29 14:37:23 -0700 | [diff] [blame] | 5 | #include <linux/pim.h> |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 6 | #include <linux/rhashtable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <net/sock.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 8 | #include <uapi/linux/mroute.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 10 | #ifdef CONFIG_IP_MROUTE |
| 11 | static inline int ip_mroute_opt(int opt) |
| 12 | { |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 13 | return opt >= MRT_BASE && opt <= MRT_MAX; |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 14 | } |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 15 | |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 16 | int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int); |
| 17 | int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *); |
| 18 | int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg); |
| 19 | int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg); |
| 20 | int ip_mr_init(void); |
YOSHIFUJI Hideaki | e0835f8 | 2008-07-03 16:51:22 +0900 | [diff] [blame] | 21 | #else |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 22 | static inline int ip_mroute_setsockopt(struct sock *sock, int optname, |
| 23 | char __user *optval, unsigned int optlen) |
YOSHIFUJI Hideaki | e0835f8 | 2008-07-03 16:51:22 +0900 | [diff] [blame] | 24 | { |
| 25 | return -ENOPROTOOPT; |
| 26 | } |
| 27 | |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 28 | static inline int ip_mroute_getsockopt(struct sock *sock, int optname, |
| 29 | char __user *optval, int __user *optlen) |
YOSHIFUJI Hideaki | e0835f8 | 2008-07-03 16:51:22 +0900 | [diff] [blame] | 30 | { |
| 31 | return -ENOPROTOOPT; |
| 32 | } |
| 33 | |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 34 | static inline int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg) |
YOSHIFUJI Hideaki | e0835f8 | 2008-07-03 16:51:22 +0900 | [diff] [blame] | 35 | { |
| 36 | return -ENOIOCTLCMD; |
| 37 | } |
| 38 | |
| 39 | static inline int ip_mr_init(void) |
| 40 | { |
| 41 | return 0; |
| 42 | } |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 43 | |
| 44 | static inline int ip_mroute_opt(int opt) |
| 45 | { |
| 46 | return 0; |
| 47 | } |
YOSHIFUJI Hideaki | e0835f8 | 2008-07-03 16:51:22 +0900 | [diff] [blame] | 48 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 50 | struct vif_device { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | struct net_device *dev; /* Device we are using */ |
| 52 | unsigned long bytes_in,bytes_out; |
| 53 | unsigned long pkt_in,pkt_out; /* Statistics */ |
| 54 | unsigned long rate_limit; /* Traffic shaping (NI) */ |
| 55 | unsigned char threshold; /* TTL threshold */ |
| 56 | unsigned short flags; /* Control flags */ |
Al Viro | 114c784 | 2006-09-27 18:39:29 -0700 | [diff] [blame] | 57 | __be32 local,remote; /* Addresses(remote for tunnels)*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | int link; /* Physical interface index */ |
| 59 | }; |
| 60 | |
| 61 | #define VIFF_STATIC 0x8000 |
| 62 | |
Nikolay Aleksandrov | 5ea1f13 | 2015-11-26 15:23:47 +0100 | [diff] [blame] | 63 | #define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL) |
Nikolay Aleksandrov | 5ea1f13 | 2015-11-26 15:23:47 +0100 | [diff] [blame] | 64 | |
| 65 | struct mr_table { |
| 66 | struct list_head list; |
| 67 | possible_net_t net; |
| 68 | u32 id; |
| 69 | struct sock __rcu *mroute_sk; |
| 70 | struct timer_list ipmr_expire_timer; |
| 71 | struct list_head mfc_unres_queue; |
Nikolay Aleksandrov | 5ea1f13 | 2015-11-26 15:23:47 +0100 | [diff] [blame] | 72 | struct vif_device vif_table[MAXVIFS]; |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 73 | struct rhltable mfc_hash; |
| 74 | struct list_head mfc_cache_list; |
Nikolay Aleksandrov | 5ea1f13 | 2015-11-26 15:23:47 +0100 | [diff] [blame] | 75 | int maxvif; |
| 76 | atomic_t cache_resolve_queue_len; |
| 77 | bool mroute_do_assert; |
| 78 | bool mroute_do_pim; |
| 79 | int mroute_reg_vif_num; |
| 80 | }; |
| 81 | |
Nikolay Aleksandrov | 06bd6c0 | 2015-11-26 15:23:45 +0100 | [diff] [blame] | 82 | /* mfc_flags: |
| 83 | * MFC_STATIC - the entry was added statically (not by a routing daemon) |
| 84 | */ |
| 85 | enum { |
| 86 | MFC_STATIC = BIT(0), |
| 87 | }; |
| 88 | |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 89 | struct mfc_cache_cmp_arg { |
| 90 | __be32 mfc_mcastgrp; |
| 91 | __be32 mfc_origin; |
| 92 | }; |
| 93 | |
| 94 | /** |
| 95 | * struct mfc_cache - multicast routing entries |
| 96 | * @mnode: rhashtable list |
| 97 | * @mfc_mcastgrp: destination multicast group address |
| 98 | * @mfc_origin: source address |
| 99 | * @cmparg: used for rhashtable comparisons |
| 100 | * @mfc_parent: source interface (iif) |
| 101 | * @mfc_flags: entry flags |
| 102 | * @expires: unresolved entry expire time |
| 103 | * @unresolved: unresolved cached skbs |
| 104 | * @last_assert: time of last assert |
| 105 | * @minvif: minimum VIF id |
| 106 | * @maxvif: maximum VIF id |
| 107 | * @bytes: bytes that have passed for this entry |
| 108 | * @pkt: packets that have passed for this entry |
| 109 | * @wrong_if: number of wrong source interface hits |
| 110 | * @lastuse: time of last use of the group (traffic or update) |
| 111 | * @ttls: OIF TTL threshold array |
| 112 | * @list: global entry list |
| 113 | * @rcu: used for entry destruction |
| 114 | */ |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 115 | struct mfc_cache { |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 116 | struct rhlist_head mnode; |
| 117 | union { |
| 118 | struct { |
| 119 | __be32 mfc_mcastgrp; |
| 120 | __be32 mfc_origin; |
| 121 | }; |
| 122 | struct mfc_cache_cmp_arg cmparg; |
| 123 | }; |
| 124 | vifi_t mfc_parent; |
| 125 | int mfc_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
| 127 | union { |
| 128 | struct { |
| 129 | unsigned long expires; |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 130 | struct sk_buff_head unresolved; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } unres; |
| 132 | struct { |
| 133 | unsigned long last_assert; |
| 134 | int minvif; |
| 135 | int maxvif; |
| 136 | unsigned long bytes; |
| 137 | unsigned long pkt; |
| 138 | unsigned long wrong_if; |
Nikolay Aleksandrov | 43b9e12 | 2016-07-14 19:28:27 +0300 | [diff] [blame] | 139 | unsigned long lastuse; |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 140 | unsigned char ttls[MAXVIFS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } res; |
| 142 | } mfc_un; |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 143 | struct list_head list; |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 144 | struct rcu_head rcu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | struct rtmsg; |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 148 | int ipmr_get_route(struct net *net, struct sk_buff *skb, |
| 149 | __be32 saddr, __be32 daddr, |
David Ahern | 9f09eae | 2017-01-06 17:39:06 -0800 | [diff] [blame] | 150 | struct rtmsg *rtm, u32 portid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | #endif |