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