Skip to content

Commit 9ee0034

Browse files
David Aherndavem330
authored andcommitted
net: flow: Add l3mdev flow update
Add l3mdev hook to set FLOWI_FLAG_SKIP_NH_OIF flag and update oif/iif in flow struct if its oif or iif points to a device enslaved to an L3 Master device. Only 1 needs to be converted to match the l3mdev FIB rule. This moves the flow adjustment for l3mdev to a single point catching all lookups. It is redundant for existing hooks (those are removed in later patches) but is needed for missed lookups such as PMTU updates. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cf9932a commit 9ee0034

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

include/net/l3mdev.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ struct l3mdev_ops {
4949
int l3mdev_fib_rule_match(struct net *net, struct flowi *fl,
5050
struct fib_lookup_arg *arg);
5151

52+
void l3mdev_update_flow(struct net *net, struct flowi *fl);
53+
5254
int l3mdev_master_ifindex_rcu(const struct net_device *dev);
5355
static inline int l3mdev_master_ifindex(struct net_device *dev)
5456
{
@@ -290,6 +292,10 @@ int l3mdev_fib_rule_match(struct net *net, struct flowi *fl,
290292
{
291293
return 1;
292294
}
295+
static inline
296+
void l3mdev_update_flow(struct net *net, struct flowi *fl)
297+
{
298+
}
293299
#endif
294300

295301
#endif /* _NET_L3MDEV_H_ */

net/ipv4/fib_rules.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ int __fib_lookup(struct net *net, struct flowi4 *flp,
5656
};
5757
int err;
5858

59+
/* update flow if oif or iif point to device enslaved to l3mdev */
60+
l3mdev_update_flow(net, flowi4_to_flowi(flp));
61+
5962
err = fib_rules_lookup(net->ipv4.rules_ops, flowi4_to_flowi(flp), 0, &arg);
6063
#ifdef CONFIG_IP_ROUTE_CLASSID
6164
if (arg.rule)

net/ipv6/fib6_rules.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
3838
.flags = FIB_LOOKUP_NOREF,
3939
};
4040

41+
/* update flow if oif or iif point to device enslaved to l3mdev */
42+
l3mdev_update_flow(net, flowi6_to_flowi(fl6));
43+
4144
fib_rules_lookup(net->ipv6.fib6_rules_ops,
4245
flowi6_to_flowi(fl6), flags, &arg);
4346

net/l3mdev/l3mdev.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,38 @@ int l3mdev_fib_rule_match(struct net *net, struct flowi *fl,
222222

223223
return rc;
224224
}
225+
226+
void l3mdev_update_flow(struct net *net, struct flowi *fl)
227+
{
228+
struct net_device *dev;
229+
int ifindex;
230+
231+
rcu_read_lock();
232+
233+
if (fl->flowi_oif) {
234+
dev = dev_get_by_index_rcu(net, fl->flowi_oif);
235+
if (dev) {
236+
ifindex = l3mdev_master_ifindex_rcu(dev);
237+
if (ifindex) {
238+
fl->flowi_oif = ifindex;
239+
fl->flowi_flags |= FLOWI_FLAG_SKIP_NH_OIF;
240+
goto out;
241+
}
242+
}
243+
}
244+
245+
if (fl->flowi_iif) {
246+
dev = dev_get_by_index_rcu(net, fl->flowi_iif);
247+
if (dev) {
248+
ifindex = l3mdev_master_ifindex_rcu(dev);
249+
if (ifindex) {
250+
fl->flowi_iif = ifindex;
251+
fl->flowi_flags |= FLOWI_FLAG_SKIP_NH_OIF;
252+
}
253+
}
254+
}
255+
256+
out:
257+
rcu_read_unlock();
258+
}
259+
EXPORT_SYMBOL_GPL(l3mdev_update_flow);

0 commit comments

Comments
 (0)