aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/fib6_rules.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv6/fib6_rules.c')
-rw-r--r--net/ipv6/fib6_rules.c113
1 files changed, 71 insertions, 42 deletions
diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c
index 695c0ca8a417..8d05527524e3 100644
--- a/net/ipv6/fib6_rules.c
+++ b/net/ipv6/fib6_rules.c
@@ -29,24 +29,22 @@ struct fib6_rule
29 u8 tclass; 29 u8 tclass;
30}; 30};
31 31
32static struct fib_rules_ops fib6_rules_ops; 32struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi *fl,
33 33 int flags, pol_lookup_t lookup)
34struct dst_entry *fib6_rule_lookup(struct flowi *fl, int flags,
35 pol_lookup_t lookup)
36{ 34{
37 struct fib_lookup_arg arg = { 35 struct fib_lookup_arg arg = {
38 .lookup_ptr = lookup, 36 .lookup_ptr = lookup,
39 }; 37 };
40 38
41 fib_rules_lookup(&fib6_rules_ops, fl, flags, &arg); 39 fib_rules_lookup(net->ipv6.fib6_rules_ops, fl, flags, &arg);
42 if (arg.rule) 40 if (arg.rule)
43 fib_rule_put(arg.rule); 41 fib_rule_put(arg.rule);
44 42
45 if (arg.result) 43 if (arg.result)
46 return arg.result; 44 return arg.result;
47 45
48 dst_hold(&ip6_null_entry.u.dst); 46 dst_hold(&net->ipv6.ip6_null_entry->u.dst);
49 return &ip6_null_entry.u.dst; 47 return &net->ipv6.ip6_null_entry->u.dst;
50} 48}
51 49
52static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp, 50static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
@@ -54,28 +52,29 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
54{ 52{
55 struct rt6_info *rt = NULL; 53 struct rt6_info *rt = NULL;
56 struct fib6_table *table; 54 struct fib6_table *table;
55 struct net *net = rule->fr_net;
57 pol_lookup_t lookup = arg->lookup_ptr; 56 pol_lookup_t lookup = arg->lookup_ptr;
58 57
59 switch (rule->action) { 58 switch (rule->action) {
60 case FR_ACT_TO_TBL: 59 case FR_ACT_TO_TBL:
61 break; 60 break;
62 case FR_ACT_UNREACHABLE: 61 case FR_ACT_UNREACHABLE:
63 rt = &ip6_null_entry; 62 rt = net->ipv6.ip6_null_entry;
64 goto discard_pkt; 63 goto discard_pkt;
65 default: 64 default:
66 case FR_ACT_BLACKHOLE: 65 case FR_ACT_BLACKHOLE:
67 rt = &ip6_blk_hole_entry; 66 rt = net->ipv6.ip6_blk_hole_entry;
68 goto discard_pkt; 67 goto discard_pkt;
69 case FR_ACT_PROHIBIT: 68 case FR_ACT_PROHIBIT:
70 rt = &ip6_prohibit_entry; 69 rt = net->ipv6.ip6_prohibit_entry;
71 goto discard_pkt; 70 goto discard_pkt;
72 } 71 }
73 72
74 table = fib6_get_table(rule->table); 73 table = fib6_get_table(net, rule->table);
75 if (table) 74 if (table)
76 rt = lookup(table, flp, flags); 75 rt = lookup(net, table, flp, flags);
77 76
78 if (rt != &ip6_null_entry) { 77 if (rt != net->ipv6.ip6_null_entry) {
79 struct fib6_rule *r = (struct fib6_rule *)rule; 78 struct fib6_rule *r = (struct fib6_rule *)rule;
80 79
81 /* 80 /*
@@ -85,8 +84,18 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
85 if ((rule->flags & FIB_RULE_FIND_SADDR) && 84 if ((rule->flags & FIB_RULE_FIND_SADDR) &&
86 r->src.plen && !(flags & RT6_LOOKUP_F_HAS_SADDR)) { 85 r->src.plen && !(flags & RT6_LOOKUP_F_HAS_SADDR)) {
87 struct in6_addr saddr; 86 struct in6_addr saddr;
88 if (ipv6_get_saddr(&rt->u.dst, &flp->fl6_dst, 87 unsigned int srcprefs = 0;
89 &saddr)) 88
89 if (flags & RT6_LOOKUP_F_SRCPREF_TMP)
90 srcprefs |= IPV6_PREFER_SRC_TMP;
91 if (flags & RT6_LOOKUP_F_SRCPREF_PUBLIC)
92 srcprefs |= IPV6_PREFER_SRC_PUBLIC;
93 if (flags & RT6_LOOKUP_F_SRCPREF_COA)
94 srcprefs |= IPV6_PREFER_SRC_COA;
95
96 if (ipv6_dev_get_saddr(ip6_dst_idev(&rt->u.dst)->dev,
97 &flp->fl6_dst, srcprefs,
98 &saddr))
90 goto again; 99 goto again;
91 if (!ipv6_prefix_equal(&saddr, &r->src.addr, 100 if (!ipv6_prefix_equal(&saddr, &r->src.addr,
92 r->src.plen)) 101 r->src.plen))
@@ -145,13 +154,14 @@ static int fib6_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
145 struct nlattr **tb) 154 struct nlattr **tb)
146{ 155{
147 int err = -EINVAL; 156 int err = -EINVAL;
157 struct net *net = sock_net(skb->sk);
148 struct fib6_rule *rule6 = (struct fib6_rule *) rule; 158 struct fib6_rule *rule6 = (struct fib6_rule *) rule;
149 159
150 if (rule->action == FR_ACT_TO_TBL) { 160 if (rule->action == FR_ACT_TO_TBL) {
151 if (rule->table == RT6_TABLE_UNSPEC) 161 if (rule->table == RT6_TABLE_UNSPEC)
152 goto errout; 162 goto errout;
153 163
154 if (fib6_new_table(rule->table) == NULL) { 164 if (fib6_new_table(net, rule->table) == NULL) {
155 err = -ENOBUFS; 165 err = -ENOBUFS;
156 goto errout; 166 goto errout;
157 } 167 }
@@ -234,7 +244,7 @@ static size_t fib6_rule_nlmsg_payload(struct fib_rule *rule)
234 + nla_total_size(16); /* src */ 244 + nla_total_size(16); /* src */
235} 245}
236 246
237static struct fib_rules_ops fib6_rules_ops = { 247static struct fib_rules_ops fib6_rules_ops_template = {
238 .family = AF_INET6, 248 .family = AF_INET6,
239 .rule_size = sizeof(struct fib6_rule), 249 .rule_size = sizeof(struct fib6_rule),
240 .addr_size = sizeof(struct in6_addr), 250 .addr_size = sizeof(struct in6_addr),
@@ -247,45 +257,64 @@ static struct fib_rules_ops fib6_rules_ops = {
247 .nlmsg_payload = fib6_rule_nlmsg_payload, 257 .nlmsg_payload = fib6_rule_nlmsg_payload,
248 .nlgroup = RTNLGRP_IPV6_RULE, 258 .nlgroup = RTNLGRP_IPV6_RULE,
249 .policy = fib6_rule_policy, 259 .policy = fib6_rule_policy,
250 .rules_list = LIST_HEAD_INIT(fib6_rules_ops.rules_list),
251 .owner = THIS_MODULE, 260 .owner = THIS_MODULE,
252 .fro_net = &init_net, 261 .fro_net = &init_net,
253}; 262};
254 263
255static int __init fib6_default_rules_init(void) 264static int fib6_rules_net_init(struct net *net)
256{ 265{
257 int err; 266 int err = -ENOMEM;
258 267
259 err = fib_default_rule_add(&fib6_rules_ops, 0, 268 net->ipv6.fib6_rules_ops = kmemdup(&fib6_rules_ops_template,
260 RT6_TABLE_LOCAL, FIB_RULE_PERMANENT); 269 sizeof(*net->ipv6.fib6_rules_ops),
261 if (err < 0) 270 GFP_KERNEL);
262 return err; 271 if (!net->ipv6.fib6_rules_ops)
263 err = fib_default_rule_add(&fib6_rules_ops, 0x7FFE, RT6_TABLE_MAIN, 0); 272 goto out;
264 if (err < 0)
265 return err;
266 return 0;
267}
268 273
269int __init fib6_rules_init(void) 274 net->ipv6.fib6_rules_ops->fro_net = net;
270{ 275 INIT_LIST_HEAD(&net->ipv6.fib6_rules_ops->rules_list);
271 int ret;
272 276
273 ret = fib6_default_rules_init(); 277 err = fib_default_rule_add(net->ipv6.fib6_rules_ops, 0,
274 if (ret) 278 RT6_TABLE_LOCAL, FIB_RULE_PERMANENT);
275 goto out; 279 if (err)
280 goto out_fib6_rules_ops;
276 281
277 ret = fib_rules_register(&fib6_rules_ops); 282 err = fib_default_rule_add(net->ipv6.fib6_rules_ops,
278 if (ret) 283 0x7FFE, RT6_TABLE_MAIN, 0);
279 goto out_default_rules_init; 284 if (err)
285 goto out_fib6_default_rule_add;
286
287 err = fib_rules_register(net->ipv6.fib6_rules_ops);
288 if (err)
289 goto out_fib6_default_rule_add;
280out: 290out:
281 return ret; 291 return err;
282 292
283out_default_rules_init: 293out_fib6_default_rule_add:
284 fib_rules_cleanup_ops(&fib6_rules_ops); 294 fib_rules_cleanup_ops(net->ipv6.fib6_rules_ops);
295out_fib6_rules_ops:
296 kfree(net->ipv6.fib6_rules_ops);
285 goto out; 297 goto out;
286} 298}
287 299
300static void fib6_rules_net_exit(struct net *net)
301{
302 fib_rules_unregister(net->ipv6.fib6_rules_ops);
303 kfree(net->ipv6.fib6_rules_ops);
304}
305
306static struct pernet_operations fib6_rules_net_ops = {
307 .init = fib6_rules_net_init,
308 .exit = fib6_rules_net_exit,
309};
310
311int __init fib6_rules_init(void)
312{
313 return register_pernet_subsys(&fib6_rules_net_ops);
314}
315
316
288void fib6_rules_cleanup(void) 317void fib6_rules_cleanup(void)
289{ 318{
290 fib_rules_unregister(&fib6_rules_ops); 319 unregister_pernet_subsys(&fib6_rules_net_ops);
291} 320}