1 #ifndef _NET_DN_FIB_H
2 #define _NET_DN_FIB_H
3 
4 #include <linux/config.h>
5 
6 #ifdef CONFIG_DECNET_ROUTER
7 
8 #include <linux/rtnetlink.h>
9 
10 struct dn_kern_rta
11 {
12         void            *rta_dst;
13         void            *rta_src;
14         int             *rta_iif;
15         int             *rta_oif;
16         void            *rta_gw;
17         u32             *rta_priority;
18         void            *rta_prefsrc;
19         struct rtattr   *rta_mx;
20         struct rtattr   *rta_mp;
21         unsigned char   *rta_protoinfo;
22         unsigned char   *rta_flow;
23         struct rta_cacheinfo *rta_ci;
24 };
25 
26 struct dn_fib_key {
27 	dn_address src;
28 	dn_address dst;
29 	int iif;
30 	int oif;
31 	u32 fwmark;
32 	unsigned char scope;
33 };
34 
35 struct dn_fib_res {
36 	struct dn_fib_rule *r;
37 	struct dn_fib_info *fi;
38 	unsigned char prefixlen;
39 	unsigned char nh_sel;
40 	unsigned char type;
41 	unsigned char scope;
42 };
43 
44 struct dn_fib_nh {
45 	struct net_device	*nh_dev;
46 	unsigned		nh_flags;
47 	unsigned char		nh_scope;
48 	int			nh_weight;
49 	int			nh_power;
50 	int			nh_oif;
51 	u32			nh_gw;
52 };
53 
54 struct dn_fib_info {
55 	struct dn_fib_info	*fib_next;
56 	struct dn_fib_info	*fib_prev;
57 	int 			fib_treeref;
58 	atomic_t		fib_clntref;
59 	int			fib_dead;
60 	unsigned		fib_flags;
61 	int			fib_protocol;
62 	dn_address		fib_prefsrc;
63 	u32			fib_priority;
64 	int			fib_nhs;
65 	int			fib_power;
66 	struct dn_fib_nh	fib_nh[0];
67 #define fib_dev		fib_nh[0].nh_dev
68 };
69 
70 
71 #define DN_FIB_RES_NH(res)	((res).fi->fib_nh[(res).nh_sel])
72 #define DN_FIB_RES_RESET(res)	((res).nh_sel = 0)
73 #define DN_FIB_RES_GW(res)	(DN_FIB_RES_NH(res).nh_gw)
74 #define DN_FIB_RES_DEV(res)	(DN_FIB_RES_NH(res).nh_dev)
75 #define DN_FIB_RES_OIF(res)	(DN_FIB_RES_NH(res).nh_oif)
76 
77 typedef struct {
78 	u16	datum;
79 } dn_fib_key_t;
80 
81 typedef struct {
82 	u16	datum;
83 } dn_fib_hash_t;
84 
85 typedef struct {
86 	u16	datum;
87 } dn_fib_idx_t;
88 
89 struct dn_fib_node {
90 	struct dn_fib_node *fn_next;
91 	struct dn_fib_info *fn_info;
92 #define DN_FIB_INFO(f) ((f)->fn_info)
93 	dn_fib_key_t	fn_key;
94 	u8		fn_type;
95 	u8		fn_scope;
96 	u8		fn_state;
97 };
98 
99 
100 struct dn_fib_table {
101 	int n;
102 
103 	int (*insert)(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 (*delete)(struct dn_fib_table *t, struct rtmsg *r,
107 			struct dn_kern_rta *rta, struct nlmsghdr *n,
108 			struct netlink_skb_parms *req);
109 	int (*lookup)(struct dn_fib_table *t, const struct dn_fib_key *key,
110 			struct dn_fib_res *res);
111 	int (*flush)(struct dn_fib_table *t);
112 #ifdef CONFIG_PROC_FS
113 	int (*get_info)(struct dn_fib_table *table, char *buf,
114 			int first, int count);
115 #endif /* CONFIG_PROC_FS */
116 	int (*dump)(struct dn_fib_table *t, struct sk_buff *skb, struct netlink_callback *cb);
117 
118 	unsigned char data[0];
119 };
120 
121 
122 /*
123  * dn_fib.c
124  */
125 extern void dn_fib_init(void);
126 extern void dn_fib_cleanup(void);
127 
128 extern int dn_fib_rt_message(struct sk_buff *skb);
129 extern int dn_fib_ioctl(struct socket *sock, unsigned int cmd,
130 			unsigned long arg);
131 extern struct dn_fib_info *dn_fib_create_info(const struct rtmsg *r,
132 				struct dn_kern_rta *rta,
133 				const struct nlmsghdr *nlh, int *errp);
134 extern int dn_fib_semantic_match(int type, struct dn_fib_info *fi,
135 			const struct dn_fib_key *key, struct dn_fib_res *res);
136 extern void dn_fib_release_info(struct dn_fib_info *fi);
137 extern u16 dn_fib_get_attr16(struct rtattr *attr, int attrlen, int type);
138 extern void dn_fib_flush(void);
139 extern void dn_fib_select_multipath(const struct dn_fib_key *key,
140 					struct dn_fib_res *res);
141 extern int dn_fib_sync_down(dn_address local, struct net_device *dev,
142 				int force);
143 extern int dn_fib_sync_up(struct net_device *dev);
144 
145 /*
146  * dn_tables.c
147  */
148 extern struct dn_fib_table *dn_fib_get_table(int n, int creat);
149 extern struct dn_fib_table *dn_fib_empty_table(void);
150 extern void dn_fib_table_init(void);
151 extern void dn_fib_table_cleanup(void);
152 
153 /*
154  * dn_rules.c
155  */
156 extern void dn_fib_rules_init(void);
157 extern void dn_fib_rules_cleanup(void);
158 extern void dn_fib_rule_put(struct dn_fib_rule *);
159 extern int dn_fib_lookup(struct dn_fib_key *key, struct dn_fib_res *res);
160 
161 /*
162  * rtnetlink interface
163  */
164 extern int dn_fib_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
165 extern int dn_fib_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
166 extern int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb);
167 
168 extern int dn_fib_rtm_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
169 extern int dn_fib_rtm_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg);
170 extern int dn_fib_dump_rules(struct sk_buff *skb, struct netlink_callback *cb);
171 
172 #define DN_NUM_TABLES 255
173 #define DN_MIN_TABLE 1
174 #define DN_DEFAULT_TABLE 1
175 #define DN_L1_TABLE 1
176 #define DN_L2_TABLE 2
177 
178 extern void dn_fib_free_info(struct dn_fib_info *fi);
179 
dn_fib_info_put(struct dn_fib_info * fi)180 static __inline__ void dn_fib_info_put(struct dn_fib_info *fi)
181 {
182 	if (atomic_dec_and_test(&fi->fib_clntref))
183 		dn_fib_free_info(fi);
184 }
185 
dn_fib_res_put(struct dn_fib_res * res)186 static __inline__ void dn_fib_res_put(struct dn_fib_res *res)
187 {
188 	if (res->fi)
189 		dn_fib_info_put(res->fi);
190 	if (res->r)
191 		dn_fib_rule_put(res->r);
192 }
193 
dnet_make_mask(int n)194 static __inline__ u16 dnet_make_mask(int n)
195 {
196         if (n)
197                 return htons(~((1<<(16-n))-1));
198         return 0;
199 }
200 
201 #endif /* CONFIG_DECNET_ROUTER */
202 
203 #endif /* _NET_DN_FIB_H */
204