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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <net/sock.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 7 | #include <uapi/linux/mroute.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 9 | #ifdef CONFIG_IP_MROUTE |
| 10 | static inline int ip_mroute_opt(int opt) |
| 11 | { |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 12 | return opt >= MRT_BASE && opt <= MRT_MAX; |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 13 | } |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 14 | |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 15 | int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int); |
| 16 | int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *); |
| 17 | int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg); |
| 18 | int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg); |
| 19 | int ip_mr_init(void); |
YOSHIFUJI Hideaki | e0835f8 | 2008-07-03 16:51:22 +0900 | [diff] [blame] | 20 | #else |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 21 | static inline int ip_mroute_setsockopt(struct sock *sock, int optname, |
| 22 | char __user *optval, unsigned int optlen) |
YOSHIFUJI Hideaki | e0835f8 | 2008-07-03 16:51:22 +0900 | [diff] [blame] | 23 | { |
| 24 | return -ENOPROTOOPT; |
| 25 | } |
| 26 | |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 27 | static inline int ip_mroute_getsockopt(struct sock *sock, int optname, |
| 28 | char __user *optval, int __user *optlen) |
YOSHIFUJI Hideaki | e0835f8 | 2008-07-03 16:51:22 +0900 | [diff] [blame] | 29 | { |
| 30 | return -ENOPROTOOPT; |
| 31 | } |
| 32 | |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 33 | 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] | 34 | { |
| 35 | return -ENOIOCTLCMD; |
| 36 | } |
| 37 | |
| 38 | static inline int ip_mr_init(void) |
| 39 | { |
| 40 | return 0; |
| 41 | } |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 42 | |
| 43 | static inline int ip_mroute_opt(int opt) |
| 44 | { |
| 45 | return 0; |
| 46 | } |
YOSHIFUJI Hideaki | e0835f8 | 2008-07-03 16:51:22 +0900 | [diff] [blame] | 47 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 49 | struct vif_device { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | struct net_device *dev; /* Device we are using */ |
| 51 | unsigned long bytes_in,bytes_out; |
| 52 | unsigned long pkt_in,pkt_out; /* Statistics */ |
| 53 | unsigned long rate_limit; /* Traffic shaping (NI) */ |
| 54 | unsigned char threshold; /* TTL threshold */ |
| 55 | unsigned short flags; /* Control flags */ |
Al Viro | 114c784 | 2006-09-27 18:39:29 -0700 | [diff] [blame] | 56 | __be32 local,remote; /* Addresses(remote for tunnels)*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | int link; /* Physical interface index */ |
| 58 | }; |
| 59 | |
| 60 | #define VIFF_STATIC 0x8000 |
| 61 | |
Nikolay Aleksandrov | 5ea1f13 | 2015-11-26 15:23:47 +0100 | [diff] [blame] | 62 | #define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL) |
| 63 | #define MFC_LINES 64 |
| 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; |
| 72 | struct list_head mfc_cache_array[MFC_LINES]; |
| 73 | struct vif_device vif_table[MAXVIFS]; |
| 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 | |
Nikolay Aleksandrov | 06bd6c0 | 2015-11-26 15:23:45 +0100 | [diff] [blame] | 81 | /* mfc_flags: |
| 82 | * MFC_STATIC - the entry was added statically (not by a routing daemon) |
| 83 | */ |
| 84 | enum { |
| 85 | MFC_STATIC = BIT(0), |
| 86 | }; |
| 87 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 88 | struct mfc_cache { |
Patrick McHardy | 862465f | 2010-04-13 05:03:21 +0000 | [diff] [blame] | 89 | struct list_head list; |
Al Viro | 114c784 | 2006-09-27 18:39:29 -0700 | [diff] [blame] | 90 | __be32 mfc_mcastgrp; /* Group the entry belongs to */ |
| 91 | __be32 mfc_origin; /* Source of packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | vifi_t mfc_parent; /* Source interface */ |
| 93 | int mfc_flags; /* Flags on line */ |
| 94 | |
| 95 | union { |
| 96 | struct { |
| 97 | unsigned long expires; |
| 98 | struct sk_buff_head unresolved; /* Unresolved buffers */ |
| 99 | } unres; |
| 100 | struct { |
| 101 | unsigned long last_assert; |
| 102 | int minvif; |
| 103 | int maxvif; |
| 104 | unsigned long bytes; |
| 105 | unsigned long pkt; |
| 106 | unsigned long wrong_if; |
| 107 | unsigned char ttls[MAXVIFS]; /* TTL thresholds */ |
| 108 | } res; |
| 109 | } mfc_un; |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 110 | struct rcu_head rcu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | #ifdef __BIG_ENDIAN |
Al Viro | 114c784 | 2006-09-27 18:39:29 -0700 | [diff] [blame] | 114 | #define MFC_HASH(a,b) (((((__force u32)(__be32)a)>>24)^(((__force u32)(__be32)b)>>26))&(MFC_LINES-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | #else |
Al Viro | 114c784 | 2006-09-27 18:39:29 -0700 | [diff] [blame] | 116 | #define MFC_HASH(a,b) ((((__force u32)(__be32)a)^(((__force u32)(__be32)b)>>2))&(MFC_LINES-1)) |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 117 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | struct rtmsg; |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 120 | int ipmr_get_route(struct net *net, struct sk_buff *skb, |
| 121 | __be32 saddr, __be32 daddr, |
| 122 | struct rtmsg *rtm, int nowait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | #endif |