blob: f01626cbbed6f147ff7eed79687fd57cfedaba26 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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 */
7struct dn_kern_rta
8{
9 void *rta_dst;
10 void *rta_src;
11 int *rta_iif;
12 int *rta_oif;
13 void *rta_gw;
14 u32 *rta_priority;
15 void *rta_prefsrc;
16 struct rtattr *rta_mx;
17 struct rtattr *rta_mp;
18 unsigned char *rta_protoinfo;
19 u32 *rta_flow;
20 struct rta_cacheinfo *rta_ci;
21 struct rta_session *rta_sess;
22};
23
24struct dn_fib_res {
Steven Whitehousea8731cb2006-08-09 15:56:46 -070025 struct fib_rule *r;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 struct dn_fib_info *fi;
27 unsigned char prefixlen;
28 unsigned char nh_sel;
29 unsigned char type;
30 unsigned char scope;
31};
32
33struct dn_fib_nh {
34 struct net_device *nh_dev;
35 unsigned nh_flags;
36 unsigned char nh_scope;
37 int nh_weight;
38 int nh_power;
39 int nh_oif;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080040 __le16 nh_gw;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041};
42
43struct dn_fib_info {
44 struct dn_fib_info *fib_next;
45 struct dn_fib_info *fib_prev;
46 int fib_treeref;
47 atomic_t fib_clntref;
48 int fib_dead;
49 unsigned fib_flags;
50 int fib_protocol;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080051 __le16 fib_prefsrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 __u32 fib_priority;
53 __u32 fib_metrics[RTAX_MAX];
54#define dn_fib_mtu fib_metrics[RTAX_MTU-1]
55#define dn_fib_window fib_metrics[RTAX_WINDOW-1]
56#define dn_fib_rtt fib_metrics[RTAX_RTT-1]
57#define dn_fib_advmss fib_metrics[RTAX_ADVMSS-1]
58 int fib_nhs;
59 int fib_power;
60 struct dn_fib_nh fib_nh[0];
61#define dn_fib_dev fib_nh[0].nh_dev
62};
63
64
65#define DN_FIB_RES_RESET(res) ((res).nh_sel = 0)
66#define DN_FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
67
68#define DN_FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __dn_fib_res_prefsrc(&res))
69#define DN_FIB_RES_GW(res) (DN_FIB_RES_NH(res).nh_gw)
70#define DN_FIB_RES_DEV(res) (DN_FIB_RES_NH(res).nh_dev)
71#define DN_FIB_RES_OIF(res) (DN_FIB_RES_NH(res).nh_oif)
72
73typedef struct {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080074 __le16 datum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075} dn_fib_key_t;
76
77typedef struct {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080078 __le16 datum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079} dn_fib_hash_t;
80
81typedef struct {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080082 __u16 datum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083} dn_fib_idx_t;
84
85struct dn_fib_node {
86 struct dn_fib_node *fn_next;
87 struct dn_fib_info *fn_info;
88#define DN_FIB_INFO(f) ((f)->fn_info)
89 dn_fib_key_t fn_key;
90 u8 fn_type;
91 u8 fn_scope;
92 u8 fn_state;
93};
94
95
96struct dn_fib_table {
Patrick McHardyabcab262006-08-10 23:11:47 -070097 struct hlist_node hlist;
Patrick McHardy2dfe55b2006-08-10 23:08:33 -070098 u32 n;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 int (*insert)(struct dn_fib_table *t, struct rtmsg *r,
101 struct dn_kern_rta *rta, struct nlmsghdr *n,
102 struct netlink_skb_parms *req);
103 int (*delete)(struct dn_fib_table *t, struct rtmsg *r,
104 struct dn_kern_rta *rta, struct nlmsghdr *n,
105 struct netlink_skb_parms *req);
106 int (*lookup)(struct dn_fib_table *t, const struct flowi *fl,
107 struct dn_fib_res *res);
108 int (*flush)(struct dn_fib_table *t);
109 int (*dump)(struct dn_fib_table *t, struct sk_buff *skb, struct netlink_callback *cb);
110
111 unsigned char data[0];
112};
113
114#ifdef CONFIG_DECNET_ROUTER
115/*
116 * dn_fib.c
117 */
118extern void dn_fib_init(void);
119extern void dn_fib_cleanup(void);
120
121extern int dn_fib_ioctl(struct socket *sock, unsigned int cmd,
122 unsigned long arg);
123extern struct dn_fib_info *dn_fib_create_info(const struct rtmsg *r,
124 struct dn_kern_rta *rta,
125 const struct nlmsghdr *nlh, int *errp);
126extern int dn_fib_semantic_match(int type, struct dn_fib_info *fi,
127 const struct flowi *fl,
128 struct dn_fib_res *res);
129extern void dn_fib_release_info(struct dn_fib_info *fi);
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800130extern __le16 dn_fib_get_attr16(struct rtattr *attr, int attrlen, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131extern void dn_fib_flush(void);
132extern void dn_fib_select_multipath(const struct flowi *fl,
133 struct dn_fib_res *res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135/*
136 * dn_tables.c
137 */
Patrick McHardy2dfe55b2006-08-10 23:08:33 -0700138extern struct dn_fib_table *dn_fib_get_table(u32 n, int creat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139extern struct dn_fib_table *dn_fib_empty_table(void);
140extern void dn_fib_table_init(void);
141extern void dn_fib_table_cleanup(void);
142
143/*
144 * dn_rules.c
145 */
146extern void dn_fib_rules_init(void);
147extern void dn_fib_rules_cleanup(void);
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800148extern unsigned dnet_addr_type(__le16 addr);
Steven Whitehousea8731cb2006-08-09 15:56:46 -0700149extern int dn_fib_lookup(struct flowi *fl, struct dn_fib_res *res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151/*
152 * rtnetlink interface
153 */
154extern int dn_fib_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
155extern int dn_fib_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
156extern int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb);
157
158extern int dn_fib_rtm_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
159extern int dn_fib_rtm_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
160extern int dn_fib_dump_rules(struct sk_buff *skb, struct netlink_callback *cb);
161
162extern void dn_fib_free_info(struct dn_fib_info *fi);
163
164static inline void dn_fib_info_put(struct dn_fib_info *fi)
165{
166 if (atomic_dec_and_test(&fi->fib_clntref))
167 dn_fib_free_info(fi);
168}
169
170static inline void dn_fib_res_put(struct dn_fib_res *res)
171{
172 if (res->fi)
173 dn_fib_info_put(res->fi);
174 if (res->r)
Steven Whitehousea8731cb2006-08-09 15:56:46 -0700175 fib_rule_put(res->r);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178#else /* Endnode */
179
180#define dn_fib_init() do { } while(0)
181#define dn_fib_cleanup() do { } while(0)
182
183#define dn_fib_lookup(fl, res) (-ESRCH)
184#define dn_fib_info_put(fi) do { } while(0)
185#define dn_fib_select_multipath(fl, res) do { } while(0)
186#define dn_fib_rules_policy(saddr,res,flags) (0)
187#define dn_fib_res_put(res) do { } while(0)
188
189#endif /* CONFIG_DECNET_ROUTER */
190
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800191static inline __le16 dnet_make_mask(int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
193 if (n)
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800194 return dn_htons(~((1<<(16-n))-1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 return 0;
196}
197
198#endif /* _NET_DN_FIB_H */