Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef _NET_DN_FIB_H |
| 3 | #define _NET_DN_FIB_H |
| 4 | |
Thomas Graf | 58d7d8f | 2013-03-21 07:45:28 +0000 | [diff] [blame] | 5 | #include <linux/netlink.h> |
Reshetova, Elena | e0542dd | 2017-07-04 15:53:00 +0300 | [diff] [blame] | 6 | #include <linux/refcount.h> |
Thomas Graf | 58d7d8f | 2013-03-21 07:45:28 +0000 | [diff] [blame] | 7 | |
| 8 | extern const struct nla_policy rtm_dn_policy[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | struct dn_fib_res { |
Steven Whitehouse | a8731cb | 2006-08-09 15:56:46 -0700 | [diff] [blame] | 11 | struct fib_rule *r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | struct dn_fib_info *fi; |
| 13 | unsigned char prefixlen; |
| 14 | unsigned char nh_sel; |
| 15 | unsigned char type; |
| 16 | unsigned char scope; |
| 17 | }; |
| 18 | |
| 19 | struct dn_fib_nh { |
| 20 | struct net_device *nh_dev; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 21 | unsigned int nh_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | unsigned char nh_scope; |
| 23 | int nh_weight; |
| 24 | int nh_power; |
| 25 | int nh_oif; |
Steven Whitehouse | c4ea94a | 2006-03-20 22:42:39 -0800 | [diff] [blame] | 26 | __le16 nh_gw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | struct dn_fib_info { |
| 30 | struct dn_fib_info *fib_next; |
| 31 | struct dn_fib_info *fib_prev; |
| 32 | int fib_treeref; |
Reshetova, Elena | e0542dd | 2017-07-04 15:53:00 +0300 | [diff] [blame] | 33 | refcount_t fib_clntref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | int fib_dead; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 35 | unsigned int fib_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | int fib_protocol; |
Steven Whitehouse | c4ea94a | 2006-03-20 22:42:39 -0800 | [diff] [blame] | 37 | __le16 fib_prefsrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | __u32 fib_priority; |
| 39 | __u32 fib_metrics[RTAX_MAX]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | int fib_nhs; |
| 41 | int fib_power; |
| 42 | struct dn_fib_nh fib_nh[0]; |
| 43 | #define dn_fib_dev fib_nh[0].nh_dev |
| 44 | }; |
| 45 | |
| 46 | |
| 47 | #define DN_FIB_RES_RESET(res) ((res).nh_sel = 0) |
| 48 | #define DN_FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel]) |
| 49 | |
| 50 | #define DN_FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __dn_fib_res_prefsrc(&res)) |
| 51 | #define DN_FIB_RES_GW(res) (DN_FIB_RES_NH(res).nh_gw) |
| 52 | #define DN_FIB_RES_DEV(res) (DN_FIB_RES_NH(res).nh_dev) |
| 53 | #define DN_FIB_RES_OIF(res) (DN_FIB_RES_NH(res).nh_oif) |
| 54 | |
| 55 | typedef struct { |
Steven Whitehouse | c4ea94a | 2006-03-20 22:42:39 -0800 | [diff] [blame] | 56 | __le16 datum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } dn_fib_key_t; |
| 58 | |
| 59 | typedef struct { |
Steven Whitehouse | c4ea94a | 2006-03-20 22:42:39 -0800 | [diff] [blame] | 60 | __le16 datum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } dn_fib_hash_t; |
| 62 | |
| 63 | typedef struct { |
Steven Whitehouse | c4ea94a | 2006-03-20 22:42:39 -0800 | [diff] [blame] | 64 | __u16 datum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } dn_fib_idx_t; |
| 66 | |
| 67 | struct dn_fib_node { |
| 68 | struct dn_fib_node *fn_next; |
| 69 | struct dn_fib_info *fn_info; |
| 70 | #define DN_FIB_INFO(f) ((f)->fn_info) |
| 71 | dn_fib_key_t fn_key; |
| 72 | u8 fn_type; |
| 73 | u8 fn_scope; |
| 74 | u8 fn_state; |
| 75 | }; |
| 76 | |
| 77 | |
| 78 | struct dn_fib_table { |
Patrick McHardy | abcab26 | 2006-08-10 23:11:47 -0700 | [diff] [blame] | 79 | struct hlist_node hlist; |
Patrick McHardy | 2dfe55b | 2006-08-10 23:08:33 -0700 | [diff] [blame] | 80 | u32 n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | int (*insert)(struct dn_fib_table *t, struct rtmsg *r, |
Thomas Graf | 58d7d8f | 2013-03-21 07:45:28 +0000 | [diff] [blame] | 83 | struct nlattr *attrs[], struct nlmsghdr *n, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | struct netlink_skb_parms *req); |
| 85 | int (*delete)(struct dn_fib_table *t, struct rtmsg *r, |
Thomas Graf | 58d7d8f | 2013-03-21 07:45:28 +0000 | [diff] [blame] | 86 | struct nlattr *attrs[], struct nlmsghdr *n, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | struct netlink_skb_parms *req); |
David S. Miller | bef55ae | 2011-03-12 17:17:10 -0500 | [diff] [blame] | 88 | int (*lookup)(struct dn_fib_table *t, const struct flowidn *fld, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | struct dn_fib_res *res); |
| 90 | int (*flush)(struct dn_fib_table *t); |
| 91 | int (*dump)(struct dn_fib_table *t, struct sk_buff *skb, struct netlink_callback *cb); |
| 92 | |
| 93 | unsigned char data[0]; |
| 94 | }; |
| 95 | |
| 96 | #ifdef CONFIG_DECNET_ROUTER |
| 97 | /* |
| 98 | * dn_fib.c |
| 99 | */ |
Joe Perches | 59ddd96 | 2013-09-20 11:23:20 -0700 | [diff] [blame] | 100 | void dn_fib_init(void); |
| 101 | void dn_fib_cleanup(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Joe Perches | 59ddd96 | 2013-09-20 11:23:20 -0700 | [diff] [blame] | 103 | int dn_fib_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); |
| 104 | struct dn_fib_info *dn_fib_create_info(const struct rtmsg *r, |
| 105 | struct nlattr *attrs[], |
| 106 | const struct nlmsghdr *nlh, int *errp); |
| 107 | int dn_fib_semantic_match(int type, struct dn_fib_info *fi, |
| 108 | const struct flowidn *fld, struct dn_fib_res *res); |
| 109 | void dn_fib_release_info(struct dn_fib_info *fi); |
| 110 | void dn_fib_flush(void); |
| 111 | void dn_fib_select_multipath(const struct flowidn *fld, struct dn_fib_res *res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | /* |
| 114 | * dn_tables.c |
| 115 | */ |
Joe Perches | 59ddd96 | 2013-09-20 11:23:20 -0700 | [diff] [blame] | 116 | struct dn_fib_table *dn_fib_get_table(u32 n, int creat); |
| 117 | struct dn_fib_table *dn_fib_empty_table(void); |
| 118 | void dn_fib_table_init(void); |
| 119 | void dn_fib_table_cleanup(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | /* |
| 122 | * dn_rules.c |
| 123 | */ |
Joe Perches | 59ddd96 | 2013-09-20 11:23:20 -0700 | [diff] [blame] | 124 | void dn_fib_rules_init(void); |
| 125 | void dn_fib_rules_cleanup(void); |
| 126 | unsigned int dnet_addr_type(__le16 addr); |
| 127 | int dn_fib_lookup(struct flowidn *fld, struct dn_fib_res *res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Joe Perches | 59ddd96 | 2013-09-20 11:23:20 -0700 | [diff] [blame] | 129 | int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Joe Perches | 59ddd96 | 2013-09-20 11:23:20 -0700 | [diff] [blame] | 131 | void dn_fib_free_info(struct dn_fib_info *fi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | static inline void dn_fib_info_put(struct dn_fib_info *fi) |
| 134 | { |
Reshetova, Elena | e0542dd | 2017-07-04 15:53:00 +0300 | [diff] [blame] | 135 | if (refcount_dec_and_test(&fi->fib_clntref)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | dn_fib_free_info(fi); |
| 137 | } |
| 138 | |
| 139 | static inline void dn_fib_res_put(struct dn_fib_res *res) |
| 140 | { |
| 141 | if (res->fi) |
| 142 | dn_fib_info_put(res->fi); |
| 143 | if (res->r) |
Steven Whitehouse | a8731cb | 2006-08-09 15:56:46 -0700 | [diff] [blame] | 144 | fib_rule_put(res->r); |
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 | #else /* Endnode */ |
| 148 | |
| 149 | #define dn_fib_init() do { } while(0) |
| 150 | #define dn_fib_cleanup() do { } while(0) |
| 151 | |
| 152 | #define dn_fib_lookup(fl, res) (-ESRCH) |
| 153 | #define dn_fib_info_put(fi) do { } while(0) |
| 154 | #define dn_fib_select_multipath(fl, res) do { } while(0) |
| 155 | #define dn_fib_rules_policy(saddr,res,flags) (0) |
| 156 | #define dn_fib_res_put(res) do { } while(0) |
| 157 | |
| 158 | #endif /* CONFIG_DECNET_ROUTER */ |
| 159 | |
Steven Whitehouse | c4ea94a | 2006-03-20 22:42:39 -0800 | [diff] [blame] | 160 | static inline __le16 dnet_make_mask(int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
Harvey Harrison | c4106aa | 2008-11-27 00:12:47 -0800 | [diff] [blame] | 162 | if (n) |
| 163 | return cpu_to_le16(~((1 << (16 - n)) - 1)); |
| 164 | return cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | #endif /* _NET_DN_FIB_H */ |