Skip to content

Commit cc065a9

Browse files
dsahernborkmann
authored andcommitted
net/ipv6: Refactor fib6_rule_action
Move source address lookup from fib6_rule_action to a helper. It will be used in a later patch by a second variant for fib6_rule_action. Signed-off-by: David Ahern <dsahern@gmail.com> Acked-by: David S. Miller <davem@davemloft.net> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 1d053da commit cc065a9

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

net/ipv6/fib6_rules.c

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,31 @@ struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
9696
return &net->ipv6.ip6_null_entry->dst;
9797
}
9898

99+
static int fib6_rule_saddr(struct net *net, struct fib_rule *rule, int flags,
100+
struct flowi6 *flp6, const struct net_device *dev)
101+
{
102+
struct fib6_rule *r = (struct fib6_rule *)rule;
103+
104+
/* If we need to find a source address for this traffic,
105+
* we check the result if it meets requirement of the rule.
106+
*/
107+
if ((rule->flags & FIB_RULE_FIND_SADDR) &&
108+
r->src.plen && !(flags & RT6_LOOKUP_F_HAS_SADDR)) {
109+
struct in6_addr saddr;
110+
111+
if (ipv6_dev_get_saddr(net, dev, &flp6->daddr,
112+
rt6_flags2srcprefs(flags), &saddr))
113+
return -EAGAIN;
114+
115+
if (!ipv6_prefix_equal(&saddr, &r->src.addr, r->src.plen))
116+
return -EAGAIN;
117+
118+
flp6->saddr = saddr;
119+
}
120+
121+
return 0;
122+
}
123+
99124
static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
100125
int flags, struct fib_lookup_arg *arg)
101126
{
@@ -134,27 +159,12 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
134159

135160
rt = lookup(net, table, flp6, arg->lookup_data, flags);
136161
if (rt != net->ipv6.ip6_null_entry) {
137-
struct fib6_rule *r = (struct fib6_rule *)rule;
138-
139-
/*
140-
* If we need to find a source address for this traffic,
141-
* we check the result if it meets requirement of the rule.
142-
*/
143-
if ((rule->flags & FIB_RULE_FIND_SADDR) &&
144-
r->src.plen && !(flags & RT6_LOOKUP_F_HAS_SADDR)) {
145-
struct in6_addr saddr;
146-
147-
if (ipv6_dev_get_saddr(net,
148-
ip6_dst_idev(&rt->dst)->dev,
149-
&flp6->daddr,
150-
rt6_flags2srcprefs(flags),
151-
&saddr))
152-
goto again;
153-
if (!ipv6_prefix_equal(&saddr, &r->src.addr,
154-
r->src.plen))
155-
goto again;
156-
flp6->saddr = saddr;
157-
}
162+
err = fib6_rule_saddr(net, rule, flags, flp6,
163+
ip6_dst_idev(&rt->dst)->dev);
164+
165+
if (err == -EAGAIN)
166+
goto again;
167+
158168
err = rt->dst.error;
159169
if (err != -EAGAIN)
160170
goto out;

0 commit comments

Comments
 (0)