1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Wed, 24 Mar 2021 02:30:36 +0100
3 Subject: [PATCH] net: ppp: resolve forwarding path for bridge pppoe
6 Pass on the PPPoE session ID, destination hardware address and the real
9 Signed-off-by: Felix Fietkau <nbd@nbd.name>
10 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
13 --- a/drivers/net/ppp/ppp_generic.c
14 +++ b/drivers/net/ppp/ppp_generic.c
15 @@ -1466,12 +1466,34 @@ static void ppp_dev_priv_destructor(stru
16 ppp_destroy_interface(ppp);
19 +static int ppp_fill_forward_path(struct net_device_path_ctx *ctx,
20 + struct net_device_path *path)
22 + struct ppp *ppp = netdev_priv(ctx->dev);
23 + struct ppp_channel *chan;
24 + struct channel *pch;
26 + if (ppp->flags & SC_MULTILINK)
29 + if (list_empty(&ppp->channels))
32 + pch = list_first_entry(&ppp->channels, struct channel, clist);
34 + if (!chan->ops->fill_forward_path)
37 + return chan->ops->fill_forward_path(ctx, path, chan);
40 static const struct net_device_ops ppp_netdev_ops = {
41 .ndo_init = ppp_dev_init,
42 .ndo_uninit = ppp_dev_uninit,
43 .ndo_start_xmit = ppp_start_xmit,
44 .ndo_do_ioctl = ppp_net_ioctl,
45 .ndo_get_stats64 = ppp_get_stats64,
46 + .ndo_fill_forward_path = ppp_fill_forward_path,
49 static struct device_type ppp_type = {
50 --- a/drivers/net/ppp/pppoe.c
51 +++ b/drivers/net/ppp/pppoe.c
52 @@ -972,8 +972,31 @@ static int pppoe_xmit(struct ppp_channel
53 return __pppoe_xmit(sk, skb);
56 +static int pppoe_fill_forward_path(struct net_device_path_ctx *ctx,
57 + struct net_device_path *path,
58 + const struct ppp_channel *chan)
60 + struct sock *sk = (struct sock *)chan->private;
61 + struct pppox_sock *po = pppox_sk(sk);
62 + struct net_device *dev = po->pppoe_dev;
64 + if (sock_flag(sk, SOCK_DEAD) ||
65 + !(sk->sk_state & PPPOX_CONNECTED) || !dev)
68 + path->type = DEV_PATH_PPPOE;
69 + path->encap.proto = htons(ETH_P_PPP_SES);
70 + path->encap.id = be16_to_cpu(po->num);
71 + memcpy(path->encap.h_dest, po->pppoe_pa.remote, ETH_ALEN);
72 + path->dev = ctx->dev;
78 static const struct ppp_channel_ops pppoe_chan_ops = {
79 .start_xmit = pppoe_xmit,
80 + .fill_forward_path = pppoe_fill_forward_path,
83 static int pppoe_recvmsg(struct socket *sock, struct msghdr *m,
84 --- a/include/linux/netdevice.h
85 +++ b/include/linux/netdevice.h
86 @@ -854,6 +854,7 @@ enum net_device_path_type {
87 DEV_PATH_ETHERNET = 0,
93 struct net_device_path {
94 @@ -863,6 +864,7 @@ struct net_device_path {
98 + u8 h_dest[ETH_ALEN];
102 --- a/include/linux/ppp_channel.h
103 +++ b/include/linux/ppp_channel.h
104 @@ -28,6 +28,9 @@ struct ppp_channel_ops {
105 int (*start_xmit)(struct ppp_channel *, struct sk_buff *);
106 /* Handle an ioctl call that has come in via /dev/ppp. */
107 int (*ioctl)(struct ppp_channel *, unsigned int, unsigned long);
108 + int (*fill_forward_path)(struct net_device_path_ctx *,
109 + struct net_device_path *,
110 + const struct ppp_channel *);