aboutsummaryrefslogtreecommitdiffstats
path: root/net/decnet
diff options
context:
space:
mode:
Diffstat (limited to 'net/decnet')
-rw-r--r--net/decnet/Kconfig1
-rw-r--r--net/decnet/af_decnet.c1
-rw-r--r--net/decnet/dn_dev.c3
-rw-r--r--net/decnet/dn_fib.c1
-rw-r--r--net/decnet/dn_route.c3
-rw-r--r--net/decnet/dn_rules.c494
-rw-r--r--net/decnet/dn_table.c1
7 files changed, 191 insertions, 313 deletions
diff --git a/net/decnet/Kconfig b/net/decnet/Kconfig
index 92f2ec46fd22..36e72cb145b0 100644
--- a/net/decnet/Kconfig
+++ b/net/decnet/Kconfig
@@ -27,6 +27,7 @@ config DECNET
27config DECNET_ROUTER 27config DECNET_ROUTER
28 bool "DECnet: router support (EXPERIMENTAL)" 28 bool "DECnet: router support (EXPERIMENTAL)"
29 depends on DECNET && EXPERIMENTAL 29 depends on DECNET && EXPERIMENTAL
30 select FIB_RULES
30 ---help--- 31 ---help---
31 Add support for turning your DECnet Endnode into a level 1 or 2 32 Add support for turning your DECnet Endnode into a level 1 or 2
32 router. This is an experimental, but functional option. If you 33 router. This is an experimental, but functional option. If you
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index 5486247735f6..70e027375682 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -130,6 +130,7 @@ Version 0.0.6 2.1.110 07-aug-98 Eduardo Marcelo Serrat
130#include <linux/poll.h> 130#include <linux/poll.h>
131#include <net/neighbour.h> 131#include <net/neighbour.h>
132#include <net/dst.h> 132#include <net/dst.h>
133#include <net/fib_rules.h>
133#include <net/dn.h> 134#include <net/dn.h>
134#include <net/dn_nsp.h> 135#include <net/dn_nsp.h>
135#include <net/dn_dev.h> 136#include <net/dn_dev.h>
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index 632c5a90b589..88ea7a13bb24 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -46,6 +46,7 @@
46#include <net/neighbour.h> 46#include <net/neighbour.h>
47#include <net/dst.h> 47#include <net/dst.h>
48#include <net/flow.h> 48#include <net/flow.h>
49#include <net/fib_rules.h>
49#include <net/dn.h> 50#include <net/dn.h>
50#include <net/dn_dev.h> 51#include <net/dn_dev.h>
51#include <net/dn_route.h> 52#include <net/dn_route.h>
@@ -1418,8 +1419,6 @@ static struct rtnetlink_link dnet_rtnetlink_table[RTM_NR_MSGTYPES] =
1418 [RTM_DELROUTE - RTM_BASE] = { .doit = dn_fib_rtm_delroute, }, 1419 [RTM_DELROUTE - RTM_BASE] = { .doit = dn_fib_rtm_delroute, },
1419 [RTM_GETROUTE - RTM_BASE] = { .doit = dn_cache_getroute, 1420 [RTM_GETROUTE - RTM_BASE] = { .doit = dn_cache_getroute,
1420 .dumpit = dn_fib_dump, }, 1421 .dumpit = dn_fib_dump, },
1421 [RTM_NEWRULE - RTM_BASE] = { .doit = dn_fib_rtm_newrule, },
1422 [RTM_DELRULE - RTM_BASE] = { .doit = dn_fib_rtm_delrule, },
1423 [RTM_GETRULE - RTM_BASE] = { .dumpit = dn_fib_dump_rules, }, 1422 [RTM_GETRULE - RTM_BASE] = { .dumpit = dn_fib_dump_rules, },
1424#else 1423#else
1425 [RTM_GETROUTE - RTM_BASE] = { .doit = dn_cache_getroute, 1424 [RTM_GETROUTE - RTM_BASE] = { .doit = dn_cache_getroute,
diff --git a/net/decnet/dn_fib.c b/net/decnet/dn_fib.c
index fa20e2efcfc1..846df3954a63 100644
--- a/net/decnet/dn_fib.c
+++ b/net/decnet/dn_fib.c
@@ -34,6 +34,7 @@
34#include <net/neighbour.h> 34#include <net/neighbour.h>
35#include <net/dst.h> 35#include <net/dst.h>
36#include <net/flow.h> 36#include <net/flow.h>
37#include <net/fib_rules.h>
37#include <net/dn.h> 38#include <net/dn.h>
38#include <net/dn_route.h> 39#include <net/dn_route.h>
39#include <net/dn_fib.h> 40#include <net/dn_fib.h>
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 743e9fcf7c5a..5e6f4616ca10 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -80,6 +80,7 @@
80#include <net/neighbour.h> 80#include <net/neighbour.h>
81#include <net/dst.h> 81#include <net/dst.h>
82#include <net/flow.h> 82#include <net/flow.h>
83#include <net/fib_rules.h>
83#include <net/dn.h> 84#include <net/dn.h>
84#include <net/dn_dev.h> 85#include <net/dn_dev.h>
85#include <net/dn_nsp.h> 86#include <net/dn_nsp.h>
@@ -1284,7 +1285,7 @@ static int dn_route_input_slow(struct sk_buff *skb)
1284 dev_hold(out_dev); 1285 dev_hold(out_dev);
1285 1286
1286 if (res.r) 1287 if (res.r)
1287 src_map = dn_fib_rules_policy(fl.fld_src, &res, &flags); 1288 src_map = fl.fld_src; /* no NAT support for now */
1288 1289
1289 gateway = DN_FIB_RES_GW(res); 1290 gateway = DN_FIB_RES_GW(res);
1290 if (res.type == RTN_NAT) { 1291 if (res.type == RTN_NAT) {
diff --git a/net/decnet/dn_rules.c b/net/decnet/dn_rules.c
index 6986be754ef2..096f1273e714 100644
--- a/net/decnet/dn_rules.c
+++ b/net/decnet/dn_rules.c
@@ -11,259 +11,198 @@
11 * 11 *
12 * 12 *
13 * Changes: 13 * Changes:
14 * Steve Whitehouse <steve@chygwyn.com>
15 * Updated for Thomas Graf's generic rules
14 * 16 *
15 */ 17 */
16#include <linux/string.h>
17#include <linux/net.h> 18#include <linux/net.h>
18#include <linux/socket.h>
19#include <linux/sockios.h>
20#include <linux/init.h> 19#include <linux/init.h>
21#include <linux/skbuff.h>
22#include <linux/netlink.h> 20#include <linux/netlink.h>
23#include <linux/rtnetlink.h> 21#include <linux/rtnetlink.h>
24#include <linux/proc_fs.h>
25#include <linux/netdevice.h> 22#include <linux/netdevice.h>
26#include <linux/timer.h>
27#include <linux/spinlock.h> 23#include <linux/spinlock.h>
28#include <linux/in_route.h>
29#include <linux/list.h> 24#include <linux/list.h>
30#include <linux/rcupdate.h> 25#include <linux/rcupdate.h>
31#include <asm/atomic.h>
32#include <asm/uaccess.h>
33#include <net/neighbour.h> 26#include <net/neighbour.h>
34#include <net/dst.h> 27#include <net/dst.h>
35#include <net/flow.h> 28#include <net/flow.h>
29#include <net/fib_rules.h>
36#include <net/dn.h> 30#include <net/dn.h>
37#include <net/dn_fib.h> 31#include <net/dn_fib.h>
38#include <net/dn_neigh.h> 32#include <net/dn_neigh.h>
39#include <net/dn_dev.h> 33#include <net/dn_dev.h>
40 34
35static struct fib_rules_ops dn_fib_rules_ops;
36
41struct dn_fib_rule 37struct dn_fib_rule
42{ 38{
43 struct hlist_node r_hlist; 39 struct fib_rule common;
44 atomic_t r_clntref; 40 unsigned char dst_len;
45 u32 r_preference; 41 unsigned char src_len;
46 unsigned char r_table; 42 __le16 src;
47 unsigned char r_action; 43 __le16 srcmask;
48 unsigned char r_dst_len; 44 __le16 dst;
49 unsigned char r_src_len; 45 __le16 dstmask;
50 __le16 r_src; 46 __le16 srcmap;
51 __le16 r_srcmask; 47 u8 flags;
52 __le16 r_dst;
53 __le16 r_dstmask;
54 __le16 r_srcmap;
55 u8 r_flags;
56#ifdef CONFIG_DECNET_ROUTE_FWMARK 48#ifdef CONFIG_DECNET_ROUTE_FWMARK
57 u32 r_fwmark; 49 u32 fwmark;
58#endif 50#endif
59 int r_ifindex;
60 char r_ifname[IFNAMSIZ];
61 int r_dead;
62 struct rcu_head rcu;
63}; 51};
64 52
65static struct dn_fib_rule default_rule = { 53static struct dn_fib_rule default_rule = {
66 .r_clntref = ATOMIC_INIT(2), 54 .common = {
67 .r_preference = 0x7fff, 55 .refcnt = ATOMIC_INIT(2),
68 .r_table = RT_TABLE_MAIN, 56 .pref = 0x7fff,
69 .r_action = RTN_UNICAST 57 .table = RT_TABLE_MAIN,
58 .action = FR_ACT_TO_TBL,
59 },
70}; 60};
71 61
72static struct hlist_head dn_fib_rules; 62static LIST_HEAD(dn_fib_rules);
63
73 64
74int dn_fib_rtm_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 65int dn_fib_lookup(struct flowi *flp, struct dn_fib_res *res)
75{ 66{
76 struct rtattr **rta = arg; 67 struct fib_lookup_arg arg = {
77 struct rtmsg *rtm = NLMSG_DATA(nlh); 68 .result = res,
78 struct dn_fib_rule *r; 69 };
79 struct hlist_node *node; 70 int err;
80 int err = -ESRCH; 71
81 72 err = fib_rules_lookup(&dn_fib_rules_ops, flp, 0, &arg);
82 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) { 73 res->r = arg.rule;
83 if ((!rta[RTA_SRC-1] || memcmp(RTA_DATA(rta[RTA_SRC-1]), &r->r_src, 2) == 0) &&
84 rtm->rtm_src_len == r->r_src_len &&
85 rtm->rtm_dst_len == r->r_dst_len &&
86 (!rta[RTA_DST-1] || memcmp(RTA_DATA(rta[RTA_DST-1]), &r->r_dst, 2) == 0) &&
87#ifdef CONFIG_DECNET_ROUTE_FWMARK
88 (!rta[RTA_PROTOINFO-1] || memcmp(RTA_DATA(rta[RTA_PROTOINFO-1]), &r->r_fwmark, 4) == 0) &&
89#endif
90 (!rtm->rtm_type || rtm->rtm_type == r->r_action) &&
91 (!rta[RTA_PRIORITY-1] || memcmp(RTA_DATA(rta[RTA_PRIORITY-1]), &r->r_preference, 4) == 0) &&
92 (!rta[RTA_IIF-1] || rtattr_strcmp(rta[RTA_IIF-1], r->r_ifname) == 0) &&
93 (!rtm->rtm_table || (r && rtm->rtm_table == r->r_table))) {
94
95 err = -EPERM;
96 if (r == &default_rule)
97 break;
98
99 hlist_del_rcu(&r->r_hlist);
100 r->r_dead = 1;
101 dn_fib_rule_put(r);
102 err = 0;
103 break;
104 }
105 }
106 74
107 return err; 75 return err;
108} 76}
109 77
110static inline void dn_fib_rule_put_rcu(struct rcu_head *head) 78int dn_fib_rule_action(struct fib_rule *rule, struct flowi *flp, int flags,
79 struct fib_lookup_arg *arg)
111{ 80{
112 struct dn_fib_rule *r = container_of(head, struct dn_fib_rule, rcu); 81 int err = -EAGAIN;
113 kfree(r); 82 struct dn_fib_table *tbl;
114}
115 83
116void dn_fib_rule_put(struct dn_fib_rule *r) 84 switch(rule->action) {
117{ 85 case FR_ACT_TO_TBL:
118 if (atomic_dec_and_test(&r->r_clntref)) { 86 break;
119 if (r->r_dead) 87
120 call_rcu(&r->rcu, dn_fib_rule_put_rcu); 88 case FR_ACT_UNREACHABLE:
121 else 89 err = -ENETUNREACH;
122 printk(KERN_DEBUG "Attempt to free alive dn_fib_rule\n"); 90 goto errout;
91
92 case FR_ACT_PROHIBIT:
93 err = -EACCES;
94 goto errout;
95
96 case FR_ACT_BLACKHOLE:
97 default:
98 err = -EINVAL;
99 goto errout;
123 } 100 }
101
102 tbl = dn_fib_get_table(rule->table, 0);
103 if (tbl == NULL)
104 goto errout;
105
106 err = tbl->lookup(tbl, flp, (struct dn_fib_res *)arg->result);
107 if (err > 0)
108 err = -EAGAIN;
109errout:
110 return err;
124} 111}
125 112
113static struct nla_policy dn_fib_rule_policy[FRA_MAX+1] __read_mostly = {
114 [FRA_IFNAME] = { .type = NLA_STRING },
115 [FRA_PRIORITY] = { .type = NLA_U32 },
116 [FRA_SRC] = { .type = NLA_U16 },
117 [FRA_DST] = { .type = NLA_U16 },
118 [FRA_FWMARK] = { .type = NLA_U32 },
119};
126 120
127int dn_fib_rtm_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 121static int dn_fib_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)
128{ 122{
129 struct rtattr **rta = arg; 123 struct dn_fib_rule *r = (struct dn_fib_rule *)rule;
130 struct rtmsg *rtm = NLMSG_DATA(nlh); 124 u16 daddr = fl->fld_dst;
131 struct dn_fib_rule *r, *new_r, *last = NULL; 125 u16 saddr = fl->fld_src;
132 struct hlist_node *node = NULL; 126
133 unsigned char table_id; 127 if (((saddr ^ r->src) & r->srcmask) ||
134 128 ((daddr ^ r->dst) & r->dstmask))
135 if (rtm->rtm_src_len > 16 || rtm->rtm_dst_len > 16) 129 return 0;
136 return -EINVAL;
137
138 if (rta[RTA_IIF-1] && RTA_PAYLOAD(rta[RTA_IIF-1]) > IFNAMSIZ)
139 return -EINVAL;
140
141 if (rtm->rtm_type == RTN_NAT)
142 return -EINVAL;
143
144 table_id = rtm->rtm_table;
145 if (table_id == RT_TABLE_UNSPEC) {
146 struct dn_fib_table *tb;
147 if (rtm->rtm_type == RTN_UNICAST) {
148 if ((tb = dn_fib_empty_table()) == NULL)
149 return -ENOBUFS;
150 table_id = tb->n;
151 }
152 }
153 130
154 new_r = kzalloc(sizeof(*new_r), GFP_KERNEL);
155 if (!new_r)
156 return -ENOMEM;
157
158 if (rta[RTA_SRC-1])
159 memcpy(&new_r->r_src, RTA_DATA(rta[RTA_SRC-1]), 2);
160 if (rta[RTA_DST-1])
161 memcpy(&new_r->r_dst, RTA_DATA(rta[RTA_DST-1]), 2);
162 if (rta[RTA_GATEWAY-1])
163 memcpy(&new_r->r_srcmap, RTA_DATA(rta[RTA_GATEWAY-1]), 2);
164 new_r->r_src_len = rtm->rtm_src_len;
165 new_r->r_dst_len = rtm->rtm_dst_len;
166 new_r->r_srcmask = dnet_make_mask(rtm->rtm_src_len);
167 new_r->r_dstmask = dnet_make_mask(rtm->rtm_dst_len);
168#ifdef CONFIG_DECNET_ROUTE_FWMARK 131#ifdef CONFIG_DECNET_ROUTE_FWMARK
169 if (rta[RTA_PROTOINFO-1]) 132 if (r->fwmark && (r->fwmark != fl->fld_fwmark))
170 memcpy(&new_r->r_fwmark, RTA_DATA(rta[RTA_PROTOINFO-1]), 4); 133 return 0;
171#endif 134#endif
172 new_r->r_action = rtm->rtm_type;
173 new_r->r_flags = rtm->rtm_flags;
174 if (rta[RTA_PRIORITY-1])
175 memcpy(&new_r->r_preference, RTA_DATA(rta[RTA_PRIORITY-1]), 4);
176 new_r->r_table = table_id;
177 if (rta[RTA_IIF-1]) {
178 struct net_device *dev;
179 rtattr_strlcpy(new_r->r_ifname, rta[RTA_IIF-1], IFNAMSIZ);
180 new_r->r_ifindex = -1;
181 dev = dev_get_by_name(new_r->r_ifname);
182 if (dev) {
183 new_r->r_ifindex = dev->ifindex;
184 dev_put(dev);
185 }
186 }
187 135
188 r = container_of(dn_fib_rules.first, struct dn_fib_rule, r_hlist); 136 return 1;
189 if (!new_r->r_preference) { 137}
190 if (r && r->r_hlist.next != NULL) { 138
191 r = container_of(r->r_hlist.next, struct dn_fib_rule, r_hlist); 139static int dn_fib_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
192 if (r->r_preference) 140 struct nlmsghdr *nlh, struct fib_rule_hdr *frh,
193 new_r->r_preference = r->r_preference - 1; 141 struct nlattr **tb)
142{
143 int err = -EINVAL;
144 struct dn_fib_rule *r = (struct dn_fib_rule *)rule;
145
146 if (frh->src_len > 16 || frh->dst_len > 16 || frh->tos)
147 goto errout;
148
149 if (rule->table == RT_TABLE_UNSPEC) {
150 if (rule->action == FR_ACT_TO_TBL) {
151 struct dn_fib_table *table;
152
153 table = dn_fib_empty_table();
154 if (table == NULL) {
155 err = -ENOBUFS;
156 goto errout;
157 }
158
159 rule->table = table->n;
194 } 160 }
195 } 161 }
196 162
197 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) { 163 if (tb[FRA_SRC])
198 if (r->r_preference > new_r->r_preference) 164 r->src = nla_get_u16(tb[FRA_SRC]);
199 break;
200 last = r;
201 }
202 atomic_inc(&new_r->r_clntref);
203 165
204 if (last) 166 if (tb[FRA_DST])
205 hlist_add_after_rcu(&last->r_hlist, &new_r->r_hlist); 167 r->dst = nla_get_u16(tb[FRA_DST]);
206 else
207 hlist_add_before_rcu(&new_r->r_hlist, &r->r_hlist);
208 return 0;
209}
210 168
169#ifdef CONFIG_DECNET_ROUTE_FWMARK
170 if (tb[FRA_FWMARK])
171 r->fwmark = nla_get_u32(tb[FRA_FWMARK]);
172#endif
173
174 r->src_len = frh->src_len;
175 r->srcmask = dnet_make_mask(r->src_len);
176 r->dst_len = frh->dst_len;
177 r->dstmask = dnet_make_mask(r->dst_len);
178 err = 0;
179errout:
180 return err;
181}
211 182
212int dn_fib_lookup(const struct flowi *flp, struct dn_fib_res *res) 183static int dn_fib_rule_compare(struct fib_rule *rule, struct fib_rule_hdr *frh,
184 struct nlattr **tb)
213{ 185{
214 struct dn_fib_rule *r, *policy; 186 struct dn_fib_rule *r = (struct dn_fib_rule *)rule;
215 struct dn_fib_table *tb; 187
216 __le16 saddr = flp->fld_src; 188 if (frh->src_len && (r->src_len != frh->src_len))
217 __le16 daddr = flp->fld_dst; 189 return 0;
218 struct hlist_node *node;
219 int err;
220 190
221 rcu_read_lock(); 191 if (frh->dst_len && (r->dst_len != frh->dst_len))
192 return 0;
222 193
223 hlist_for_each_entry_rcu(r, node, &dn_fib_rules, r_hlist) {
224 if (((saddr^r->r_src) & r->r_srcmask) ||
225 ((daddr^r->r_dst) & r->r_dstmask) ||
226#ifdef CONFIG_DECNET_ROUTE_FWMARK 194#ifdef CONFIG_DECNET_ROUTE_FWMARK
227 (r->r_fwmark && r->r_fwmark != flp->fld_fwmark) || 195 if (tb[FRA_FWMARK] && (r->fwmark != nla_get_u32(tb[FRA_FWMARK])))
196 return 0;
228#endif 197#endif
229 (r->r_ifindex && r->r_ifindex != flp->iif))
230 continue;
231
232 switch(r->r_action) {
233 case RTN_UNICAST:
234 case RTN_NAT:
235 policy = r;
236 break;
237 case RTN_UNREACHABLE:
238 rcu_read_unlock();
239 return -ENETUNREACH;
240 default:
241 case RTN_BLACKHOLE:
242 rcu_read_unlock();
243 return -EINVAL;
244 case RTN_PROHIBIT:
245 rcu_read_unlock();
246 return -EACCES;
247 }
248 198
249 if ((tb = dn_fib_get_table(r->r_table, 0)) == NULL) 199 if (tb[FRA_SRC] && (r->src != nla_get_u32(tb[FRA_SRC])))
250 continue; 200 return 0;
251 err = tb->lookup(tb, flp, res); 201
252 if (err == 0) { 202 if (tb[FRA_DST] && (r->dst != nla_get_u32(tb[FRA_DST])))
253 res->r = policy; 203 return 0;
254 if (policy)
255 atomic_inc(&policy->r_clntref);
256 rcu_read_unlock();
257 return 0;
258 }
259 if (err < 0 && err != -EAGAIN) {
260 rcu_read_unlock();
261 return err;
262 }
263 }
264 204
265 rcu_read_unlock(); 205 return 1;
266 return -ESRCH;
267} 206}
268 207
269unsigned dnet_addr_type(__le16 addr) 208unsigned dnet_addr_type(__le16 addr)
@@ -284,142 +223,77 @@ unsigned dnet_addr_type(__le16 addr)
284 return ret; 223 return ret;
285} 224}
286 225
287__le16 dn_fib_rules_policy(__le16 saddr, struct dn_fib_res *res, unsigned *flags) 226static int dn_fib_rule_fill(struct fib_rule *rule, struct sk_buff *skb,
227 struct nlmsghdr *nlh, struct fib_rule_hdr *frh)
288{ 228{
289 struct dn_fib_rule *r = res->r; 229 struct dn_fib_rule *r = (struct dn_fib_rule *)rule;
290
291 if (r->r_action == RTN_NAT) {
292 int addrtype = dnet_addr_type(r->r_srcmap);
293
294 if (addrtype == RTN_NAT) {
295 saddr = (saddr&~r->r_srcmask)|r->r_srcmap;
296 *flags |= RTCF_SNAT;
297 } else if (addrtype == RTN_LOCAL || r->r_srcmap == 0) {
298 saddr = r->r_srcmap;
299 *flags |= RTCF_MASQ;
300 }
301 }
302 return saddr;
303}
304 230
305static void dn_fib_rules_detach(struct net_device *dev) 231 frh->family = AF_DECnet;
306{ 232 frh->dst_len = r->dst_len;
307 struct hlist_node *node; 233 frh->src_len = r->src_len;
308 struct dn_fib_rule *r; 234 frh->tos = 0;
309 235
310 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) { 236#ifdef CONFIG_DECNET_ROUTE_FWMARK
311 if (r->r_ifindex == dev->ifindex) 237 if (r->fwmark)
312 r->r_ifindex = -1; 238 NLA_PUT_U32(skb, FRA_FWMARK, r->fwmark);
313 } 239#endif
314} 240 if (r->dst_len)
241 NLA_PUT_U16(skb, FRA_DST, r->dst);
242 if (r->src_len)
243 NLA_PUT_U16(skb, FRA_SRC, r->src);
315 244
316static void dn_fib_rules_attach(struct net_device *dev) 245 return 0;
317{
318 struct hlist_node *node;
319 struct dn_fib_rule *r;
320 246
321 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) { 247nla_put_failure:
322 if (r->r_ifindex == -1 && strcmp(dev->name, r->r_ifname) == 0) 248 return -ENOBUFS;
323 r->r_ifindex = dev->ifindex;
324 }
325} 249}
326 250
327static int dn_fib_rules_event(struct notifier_block *this, unsigned long event, void *ptr) 251static u32 dn_fib_rule_default_pref(void)
328{ 252{
329 struct net_device *dev = ptr; 253 struct list_head *pos;
330 254 struct fib_rule *rule;
331 switch(event) { 255
332 case NETDEV_UNREGISTER: 256 if (!list_empty(&dn_fib_rules)) {
333 dn_fib_rules_detach(dev); 257 pos = dn_fib_rules.next;
334 dn_fib_sync_down(0, dev, 1); 258 if (pos->next != &dn_fib_rules) {
335 case NETDEV_REGISTER: 259 rule = list_entry(pos->next, struct fib_rule, list);
336 dn_fib_rules_attach(dev); 260 if (rule->pref)
337 dn_fib_sync_up(dev); 261 return rule->pref - 1;
262 }
338 } 263 }
339 264
340 return NOTIFY_DONE; 265 return 0;
341}
342
343
344static struct notifier_block dn_fib_rules_notifier = {
345 .notifier_call = dn_fib_rules_event,
346};
347
348static int dn_fib_fill_rule(struct sk_buff *skb, struct dn_fib_rule *r,
349 struct netlink_callback *cb, unsigned int flags)
350{
351 struct rtmsg *rtm;
352 struct nlmsghdr *nlh;
353 unsigned char *b = skb->tail;
354
355
356 nlh = NLMSG_NEW_ANSWER(skb, cb, RTM_NEWRULE, sizeof(*rtm), flags);
357 rtm = NLMSG_DATA(nlh);
358 rtm->rtm_family = AF_DECnet;
359 rtm->rtm_dst_len = r->r_dst_len;
360 rtm->rtm_src_len = r->r_src_len;
361 rtm->rtm_tos = 0;
362#ifdef CONFIG_DECNET_ROUTE_FWMARK
363 if (r->r_fwmark)
364 RTA_PUT(skb, RTA_PROTOINFO, 4, &r->r_fwmark);
365#endif
366 rtm->rtm_table = r->r_table;
367 rtm->rtm_protocol = 0;
368 rtm->rtm_scope = 0;
369 rtm->rtm_type = r->r_action;
370 rtm->rtm_flags = r->r_flags;
371
372 if (r->r_dst_len)
373 RTA_PUT(skb, RTA_DST, 2, &r->r_dst);
374 if (r->r_src_len)
375 RTA_PUT(skb, RTA_SRC, 2, &r->r_src);
376 if (r->r_ifname[0])
377 RTA_PUT(skb, RTA_IIF, IFNAMSIZ, &r->r_ifname);
378 if (r->r_preference)
379 RTA_PUT(skb, RTA_PRIORITY, 4, &r->r_preference);
380 if (r->r_srcmap)
381 RTA_PUT(skb, RTA_GATEWAY, 2, &r->r_srcmap);
382 nlh->nlmsg_len = skb->tail - b;
383 return skb->len;
384
385nlmsg_failure:
386rtattr_failure:
387 skb_trim(skb, b - skb->data);
388 return -1;
389} 266}
390 267
391int dn_fib_dump_rules(struct sk_buff *skb, struct netlink_callback *cb) 268int dn_fib_dump_rules(struct sk_buff *skb, struct netlink_callback *cb)
392{ 269{
393 int idx = 0; 270 return fib_rules_dump(skb, cb, AF_DECnet);
394 int s_idx = cb->args[0];
395 struct dn_fib_rule *r;
396 struct hlist_node *node;
397
398 rcu_read_lock();
399 hlist_for_each_entry(r, node, &dn_fib_rules, r_hlist) {
400 if (idx < s_idx)
401 goto next;
402 if (dn_fib_fill_rule(skb, r, cb, NLM_F_MULTI) < 0)
403 break;
404next:
405 idx++;
406 }
407 rcu_read_unlock();
408 cb->args[0] = idx;
409
410 return skb->len;
411} 271}
412 272
273static struct fib_rules_ops dn_fib_rules_ops = {
274 .family = AF_DECnet,
275 .rule_size = sizeof(struct dn_fib_rule),
276 .action = dn_fib_rule_action,
277 .match = dn_fib_rule_match,
278 .configure = dn_fib_rule_configure,
279 .compare = dn_fib_rule_compare,
280 .fill = dn_fib_rule_fill,
281 .default_pref = dn_fib_rule_default_pref,
282 .nlgroup = RTNLGRP_DECnet_RULE,
283 .policy = dn_fib_rule_policy,
284 .rules_list = &dn_fib_rules,
285 .owner = THIS_MODULE,
286};
287
413void __init dn_fib_rules_init(void) 288void __init dn_fib_rules_init(void)
414{ 289{
415 INIT_HLIST_HEAD(&dn_fib_rules); 290 list_add_tail(&default_rule.common.list, &dn_fib_rules);
416 hlist_add_head(&default_rule.r_hlist, &dn_fib_rules); 291 fib_rules_register(&dn_fib_rules_ops);
417 register_netdevice_notifier(&dn_fib_rules_notifier);
418} 292}
419 293
420void __exit dn_fib_rules_cleanup(void) 294void __exit dn_fib_rules_cleanup(void)
421{ 295{
422 unregister_netdevice_notifier(&dn_fib_rules_notifier); 296 fib_rules_unregister(&dn_fib_rules_ops);
423} 297}
424 298
425 299
diff --git a/net/decnet/dn_table.c b/net/decnet/dn_table.c
index e926c952e363..2e01b67398c8 100644
--- a/net/decnet/dn_table.c
+++ b/net/decnet/dn_table.c
@@ -30,6 +30,7 @@
30#include <net/neighbour.h> 30#include <net/neighbour.h>
31#include <net/dst.h> 31#include <net/dst.h>
32#include <net/flow.h> 32#include <net/flow.h>
33#include <net/fib_rules.h>
33#include <net/dn.h> 34#include <net/dn.h>
34#include <net/dn_route.h> 35#include <net/dn_route.h>
35#include <net/dn_fib.h> 36#include <net/dn_fib.h>