blob: 81210a8b8d7c235c812a8f82973d64f4afcaf86b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _NET_DN_FIB_H
2#define _NET_DN_FIB_H
3
Thomas Graf58d7d8f2013-03-21 07:45:28 +00004#include <linux/netlink.h>
Reshetova, Elenae0542dd2017-07-04 15:53:00 +03005#include <linux/refcount.h>
Thomas Graf58d7d8f2013-03-21 07:45:28 +00006
7extern const struct nla_policy rtm_dn_policy[];
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9struct dn_fib_res {
Steven Whitehousea8731cb2006-08-09 15:56:46 -070010 struct fib_rule *r;
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 struct dn_fib_info *fi;
12 unsigned char prefixlen;
13 unsigned char nh_sel;
14 unsigned char type;
15 unsigned char scope;
16};
17
18struct dn_fib_nh {
19 struct net_device *nh_dev;
Eric Dumazet95c96172012-04-15 05:58:06 +000020 unsigned int nh_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 unsigned char nh_scope;
22 int nh_weight;
23 int nh_power;
24 int nh_oif;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080025 __le16 nh_gw;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026};
27
28struct dn_fib_info {
29 struct dn_fib_info *fib_next;
30 struct dn_fib_info *fib_prev;
31 int fib_treeref;
Reshetova, Elenae0542dd2017-07-04 15:53:00 +030032 refcount_t fib_clntref;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 int fib_dead;
Eric Dumazet95c96172012-04-15 05:58:06 +000034 unsigned int fib_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 int fib_protocol;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080036 __le16 fib_prefsrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 __u32 fib_priority;
38 __u32 fib_metrics[RTAX_MAX];
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 int fib_nhs;
40 int fib_power;
41 struct dn_fib_nh fib_nh[0];
42#define dn_fib_dev fib_nh[0].nh_dev
43};
44
45
46#define DN_FIB_RES_RESET(res) ((res).nh_sel = 0)
47#define DN_FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
48
49#define DN_FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __dn_fib_res_prefsrc(&res))
50#define DN_FIB_RES_GW(res) (DN_FIB_RES_NH(res).nh_gw)
51#define DN_FIB_RES_DEV(res) (DN_FIB_RES_NH(res).nh_dev)
52#define DN_FIB_RES_OIF(res) (DN_FIB_RES_NH(res).nh_oif)
53
54typedef struct {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080055 __le16 datum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056} dn_fib_key_t;
57
58typedef struct {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080059 __le16 datum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060} dn_fib_hash_t;
61
62typedef struct {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080063 __u16 datum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064} dn_fib_idx_t;
65
66struct dn_fib_node {
67 struct dn_fib_node *fn_next;
68 struct dn_fib_info *fn_info;
69#define DN_FIB_INFO(f) ((f)->fn_info)
70 dn_fib_key_t fn_key;
71 u8 fn_type;
72 u8 fn_scope;
73 u8 fn_state;
74};
75
76
77struct dn_fib_table {
Patrick McHardyabcab262006-08-10 23:11:47 -070078 struct hlist_node hlist;
Patrick McHardy2dfe55b2006-08-10 23:08:33 -070079 u32 n;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81 int (*insert)(struct dn_fib_table *t, struct rtmsg *r,
Thomas Graf58d7d8f2013-03-21 07:45:28 +000082 struct nlattr *attrs[], struct nlmsghdr *n,
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 struct netlink_skb_parms *req);
84 int (*delete)(struct dn_fib_table *t, struct rtmsg *r,
Thomas Graf58d7d8f2013-03-21 07:45:28 +000085 struct nlattr *attrs[], struct nlmsghdr *n,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 struct netlink_skb_parms *req);
David S. Millerbef55ae2011-03-12 17:17:10 -050087 int (*lookup)(struct dn_fib_table *t, const struct flowidn *fld,
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 struct dn_fib_res *res);
89 int (*flush)(struct dn_fib_table *t);
90 int (*dump)(struct dn_fib_table *t, struct sk_buff *skb, struct netlink_callback *cb);
91
92 unsigned char data[0];
93};
94
95#ifdef CONFIG_DECNET_ROUTER
96/*
97 * dn_fib.c
98 */
Joe Perches59ddd962013-09-20 11:23:20 -070099void dn_fib_init(void);
100void dn_fib_cleanup(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Joe Perches59ddd962013-09-20 11:23:20 -0700102int dn_fib_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
103struct dn_fib_info *dn_fib_create_info(const struct rtmsg *r,
104 struct nlattr *attrs[],
105 const struct nlmsghdr *nlh, int *errp);
106int dn_fib_semantic_match(int type, struct dn_fib_info *fi,
107 const struct flowidn *fld, struct dn_fib_res *res);
108void dn_fib_release_info(struct dn_fib_info *fi);
109void dn_fib_flush(void);
110void dn_fib_select_multipath(const struct flowidn *fld, struct dn_fib_res *res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112/*
113 * dn_tables.c
114 */
Joe Perches59ddd962013-09-20 11:23:20 -0700115struct dn_fib_table *dn_fib_get_table(u32 n, int creat);
116struct dn_fib_table *dn_fib_empty_table(void);
117void dn_fib_table_init(void);
118void dn_fib_table_cleanup(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120/*
121 * dn_rules.c
122 */
Joe Perches59ddd962013-09-20 11:23:20 -0700123void dn_fib_rules_init(void);
124void dn_fib_rules_cleanup(void);
125unsigned int dnet_addr_type(__le16 addr);
126int dn_fib_lookup(struct flowidn *fld, struct dn_fib_res *res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Joe Perches59ddd962013-09-20 11:23:20 -0700128int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Joe Perches59ddd962013-09-20 11:23:20 -0700130void dn_fib_free_info(struct dn_fib_info *fi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132static inline void dn_fib_info_put(struct dn_fib_info *fi)
133{
Reshetova, Elenae0542dd2017-07-04 15:53:00 +0300134 if (refcount_dec_and_test(&fi->fib_clntref))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 dn_fib_free_info(fi);
136}
137
138static inline void dn_fib_res_put(struct dn_fib_res *res)
139{
140 if (res->fi)
141 dn_fib_info_put(res->fi);
142 if (res->r)
Steven Whitehousea8731cb2006-08-09 15:56:46 -0700143 fib_rule_put(res->r);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#else /* Endnode */
147
148#define dn_fib_init() do { } while(0)
149#define dn_fib_cleanup() do { } while(0)
150
151#define dn_fib_lookup(fl, res) (-ESRCH)
152#define dn_fib_info_put(fi) do { } while(0)
153#define dn_fib_select_multipath(fl, res) do { } while(0)
154#define dn_fib_rules_policy(saddr,res,flags) (0)
155#define dn_fib_res_put(res) do { } while(0)
156
157#endif /* CONFIG_DECNET_ROUTER */
158
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800159static inline __le16 dnet_make_mask(int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800161 if (n)
162 return cpu_to_le16(~((1 << (16 - n)) - 1));
163 return cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164}
165
166#endif /* _NET_DN_FIB_H */