blob: f2ca135ddcc979b07260c5d5996dc79bf7659536 [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>
5
6extern const struct nla_policy rtm_dn_policy[];
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8struct dn_fib_res {
Steven Whitehousea8731cb2006-08-09 15:56:46 -07009 struct fib_rule *r;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 struct dn_fib_info *fi;
11 unsigned char prefixlen;
12 unsigned char nh_sel;
13 unsigned char type;
14 unsigned char scope;
15};
16
17struct dn_fib_nh {
18 struct net_device *nh_dev;
Eric Dumazet95c96172012-04-15 05:58:06 +000019 unsigned int nh_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 unsigned char nh_scope;
21 int nh_weight;
22 int nh_power;
23 int nh_oif;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080024 __le16 nh_gw;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025};
26
27struct 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 Dumazet95c96172012-04-15 05:58:06 +000033 unsigned int fib_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 int fib_protocol;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080035 __le16 fib_prefsrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 __u32 fib_priority;
37 __u32 fib_metrics[RTAX_MAX];
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 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
53typedef struct {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080054 __le16 datum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055} dn_fib_key_t;
56
57typedef struct {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080058 __le16 datum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059} dn_fib_hash_t;
60
61typedef struct {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080062 __u16 datum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063} dn_fib_idx_t;
64
65struct 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
76struct dn_fib_table {
Patrick McHardyabcab262006-08-10 23:11:47 -070077 struct hlist_node hlist;
Patrick McHardy2dfe55b2006-08-10 23:08:33 -070078 u32 n;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 int (*insert)(struct dn_fib_table *t, struct rtmsg *r,
Thomas Graf58d7d8f2013-03-21 07:45:28 +000081 struct nlattr *attrs[], struct nlmsghdr *n,
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 struct netlink_skb_parms *req);
83 int (*delete)(struct dn_fib_table *t, struct rtmsg *r,
Thomas Graf58d7d8f2013-03-21 07:45:28 +000084 struct nlattr *attrs[], struct nlmsghdr *n,
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 struct netlink_skb_parms *req);
David S. Millerbef55ae2011-03-12 17:17:10 -050086 int (*lookup)(struct dn_fib_table *t, const struct flowidn *fld,
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 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 */
Joe Perches59ddd962013-09-20 11:23:20 -070098void dn_fib_init(void);
99void dn_fib_cleanup(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Joe Perches59ddd962013-09-20 11:23:20 -0700101int dn_fib_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
102struct dn_fib_info *dn_fib_create_info(const struct rtmsg *r,
103 struct nlattr *attrs[],
104 const struct nlmsghdr *nlh, int *errp);
105int dn_fib_semantic_match(int type, struct dn_fib_info *fi,
106 const struct flowidn *fld, struct dn_fib_res *res);
107void dn_fib_release_info(struct dn_fib_info *fi);
108void dn_fib_flush(void);
109void dn_fib_select_multipath(const struct flowidn *fld, struct dn_fib_res *res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111/*
112 * dn_tables.c
113 */
Joe Perches59ddd962013-09-20 11:23:20 -0700114struct dn_fib_table *dn_fib_get_table(u32 n, int creat);
115struct dn_fib_table *dn_fib_empty_table(void);
116void dn_fib_table_init(void);
117void dn_fib_table_cleanup(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119/*
120 * dn_rules.c
121 */
Joe Perches59ddd962013-09-20 11:23:20 -0700122void dn_fib_rules_init(void);
123void dn_fib_rules_cleanup(void);
124unsigned int dnet_addr_type(__le16 addr);
125int dn_fib_lookup(struct flowidn *fld, struct dn_fib_res *res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Joe Perches59ddd962013-09-20 11:23:20 -0700127int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Joe Perches59ddd962013-09-20 11:23:20 -0700129void dn_fib_free_info(struct dn_fib_info *fi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131static inline void dn_fib_info_put(struct dn_fib_info *fi)
132{
133 if (atomic_dec_and_test(&fi->fib_clntref))
134 dn_fib_free_info(fi);
135}
136
137static inline void dn_fib_res_put(struct dn_fib_res *res)
138{
139 if (res->fi)
140 dn_fib_info_put(res->fi);
141 if (res->r)
Steven Whitehousea8731cb2006-08-09 15:56:46 -0700142 fib_rule_put(res->r);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143}
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#else /* Endnode */
146
147#define dn_fib_init() do { } while(0)
148#define dn_fib_cleanup() do { } while(0)
149
150#define dn_fib_lookup(fl, res) (-ESRCH)
151#define dn_fib_info_put(fi) do { } while(0)
152#define dn_fib_select_multipath(fl, res) do { } while(0)
153#define dn_fib_rules_policy(saddr,res,flags) (0)
154#define dn_fib_res_put(res) do { } while(0)
155
156#endif /* CONFIG_DECNET_ROUTER */
157
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800158static inline __le16 dnet_make_mask(int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800160 if (n)
161 return cpu_to_le16(~((1 << (16 - n)) - 1));
162 return cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165#endif /* _NET_DN_FIB_H */