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