a906dc06ce010430794f5aef105cdbc35d0e4a37
[openwrt/staging/wigyori.git] /
1 From: Pablo Neira Ayuso <pablo@netfilter.org>
2 Date: Wed, 24 Mar 2021 02:30:33 +0100
3 Subject: [PATCH] net: 8021q: resolve forwarding path for vlan devices
4
5 Add .ndo_fill_forward_path for vlan devices.
6
7 For instance, assuming the following topology:
8
9 IP forwarding
10 / \
11 eth0.100 eth0
12 |
13 eth0
14 .
15 .
16 .
17 ethX
18 ab:cd:ef:ab:cd:ef
19
20 For packets going through IP forwarding to eth0.100 whose destination
21 MAC address is ab:cd:ef:ab:cd:ef, dev_fill_forward_path() provides the
22 following path:
23
24 eth0.100 -> eth0
25
26 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
27 ---
28
29 --- a/include/linux/netdevice.h
30 +++ b/include/linux/netdevice.h
31 @@ -852,11 +852,18 @@ typedef u16 (*select_queue_fallback_t)(s
32
33 enum net_device_path_type {
34 DEV_PATH_ETHERNET = 0,
35 + DEV_PATH_VLAN,
36 };
37
38 struct net_device_path {
39 enum net_device_path_type type;
40 const struct net_device *dev;
41 + union {
42 + struct {
43 + u16 id;
44 + __be16 proto;
45 + } encap;
46 + };
47 };
48
49 #define NET_DEVICE_PATH_STACK_MAX 5
50 --- a/net/8021q/vlan_dev.c
51 +++ b/net/8021q/vlan_dev.c
52 @@ -770,6 +770,20 @@ static int vlan_dev_get_iflink(const str
53 return real_dev->ifindex;
54 }
55
56 +static int vlan_dev_fill_forward_path(struct net_device_path_ctx *ctx,
57 + struct net_device_path *path)
58 +{
59 + struct vlan_dev_priv *vlan = vlan_dev_priv(ctx->dev);
60 +
61 + path->type = DEV_PATH_VLAN;
62 + path->encap.id = vlan->vlan_id;
63 + path->encap.proto = vlan->vlan_proto;
64 + path->dev = ctx->dev;
65 + ctx->dev = vlan->real_dev;
66 +
67 + return 0;
68 +}
69 +
70 static const struct ethtool_ops vlan_ethtool_ops = {
71 .get_link_ksettings = vlan_ethtool_get_link_ksettings,
72 .get_drvinfo = vlan_ethtool_get_drvinfo,
73 @@ -808,6 +822,7 @@ static const struct net_device_ops vlan_
74 #endif
75 .ndo_fix_features = vlan_dev_fix_features,
76 .ndo_get_iflink = vlan_dev_get_iflink,
77 + .ndo_fill_forward_path = vlan_dev_fill_forward_path,
78 };
79
80 static void vlan_dev_free(struct net_device *dev)