kernel: update 5.10 flow offload patches
[openwrt/staging/rmilecki.git] / target / linux / generic / pending-5.10 / 640-11-net-ppp-resolve-forwarding-path-for-bridge-pppoe-dev.patch
1 From: Pablo Neira Ayuso <pablo@netfilter.org>
2 Date: Tue, 2 Mar 2021 21:45:16 +0100
3 Subject: [PATCH] net: ppp: resolve forwarding path for bridge pppoe
4 devices
5
6 Pass on the PPPoE session ID and the real device.
7 ---
8
9 --- a/drivers/net/ppp/ppp_generic.c
10 +++ b/drivers/net/ppp/ppp_generic.c
11 @@ -1450,12 +1450,34 @@ static void ppp_dev_priv_destructor(stru
12 ppp_destroy_interface(ppp);
13 }
14
15 +static int ppp_fill_forward_path(struct net_device_path_ctx *ctx,
16 + struct net_device_path *path)
17 +{
18 + struct ppp *ppp = netdev_priv(path->dev);
19 + struct ppp_channel *chan;
20 + struct channel *pch;
21 +
22 + if (ppp->flags & SC_MULTILINK)
23 + return -EOPNOTSUPP;
24 +
25 + if (list_empty(&ppp->channels))
26 + return -ENODEV;
27 +
28 + pch = list_first_entry(&ppp->channels, struct channel, clist);
29 + chan = pch->chan;
30 + if (!chan->ops->fill_forward_path)
31 + return -EOPNOTSUPP;
32 +
33 + return chan->ops->fill_forward_path(ctx, path, chan);
34 +}
35 +
36 static const struct net_device_ops ppp_netdev_ops = {
37 .ndo_init = ppp_dev_init,
38 .ndo_uninit = ppp_dev_uninit,
39 .ndo_start_xmit = ppp_start_xmit,
40 .ndo_do_ioctl = ppp_net_ioctl,
41 .ndo_get_stats64 = ppp_get_stats64,
42 + .ndo_fill_forward_path = ppp_fill_forward_path,
43 };
44
45 static struct device_type ppp_type = {
46 --- a/drivers/net/ppp/pppoe.c
47 +++ b/drivers/net/ppp/pppoe.c
48 @@ -972,8 +972,30 @@ static int pppoe_xmit(struct ppp_channel
49 return __pppoe_xmit(sk, skb);
50 }
51
52 +static int pppoe_fill_forward_path(struct net_device_path_ctx *ctx,
53 + struct net_device_path *path,
54 + const struct ppp_channel *chan)
55 +{
56 + struct sock *sk = (struct sock *)chan->private;
57 + struct pppox_sock *po = pppox_sk(sk);
58 + struct net_device *dev = po->pppoe_dev;
59 +
60 + if (sock_flag(sk, SOCK_DEAD) ||
61 + !(sk->sk_state & PPPOX_CONNECTED) || !dev)
62 + return -1;
63 +
64 + path->type = DEV_PATH_PPPOE;
65 + path->encap.proto = htons(ETH_P_PPP_SES);
66 + path->encap.id = be16_to_cpu(po->num);
67 + path->dev = ctx->dev;
68 + ctx->dev = dev;
69 +
70 + return 0;
71 +}
72 +
73 static const struct ppp_channel_ops pppoe_chan_ops = {
74 .start_xmit = pppoe_xmit,
75 + .fill_forward_path = pppoe_fill_forward_path,
76 };
77
78 static int pppoe_recvmsg(struct socket *sock, struct msghdr *m,
79 --- a/include/linux/netdevice.h
80 +++ b/include/linux/netdevice.h
81 @@ -837,6 +837,7 @@ enum net_device_path_type {
82 DEV_PATH_ETHERNET = 0,
83 DEV_PATH_VLAN,
84 DEV_PATH_BRIDGE,
85 + DEV_PATH_PPPOE,
86 };
87
88 struct net_device_path {
89 --- a/include/linux/ppp_channel.h
90 +++ b/include/linux/ppp_channel.h
91 @@ -28,6 +28,9 @@ struct ppp_channel_ops {
92 int (*start_xmit)(struct ppp_channel *, struct sk_buff *);
93 /* Handle an ioctl call that has come in via /dev/ppp. */
94 int (*ioctl)(struct ppp_channel *, unsigned int, unsigned long);
95 + int (*fill_forward_path)(struct net_device_path_ctx *,
96 + struct net_device_path *,
97 + const struct ppp_channel *);
98 };
99
100 struct ppp_channel {