developer | 5d86c14 | 2023-12-06 14:18:27 +0800 | [diff] [blame] | 1 | --- a/drivers/net/ppp/ppp_generic.c |
| 2 | +++ b/drivers/net/ppp/ppp_generic.c |
| 3 | @@ -296,6 +296,9 @@ static void unit_put(struct idr *p, int |
| 4 | static void *unit_find(struct idr *p, int n); |
| 5 | static void ppp_setup(struct net_device *dev); |
| 6 | |
| 7 | +struct sock *ppp_netdev_get_sock(struct net_device *dev); |
| 8 | +EXPORT_SYMBOL(ppp_netdev_get_sock); |
| 9 | + |
| 10 | static const struct net_device_ops ppp_netdev_ops; |
| 11 | |
| 12 | static struct class *ppp_class; |
| 13 | @@ -1660,6 +1663,40 @@ ppp_send_frame(struct ppp *ppp, struct s |
| 14 | ++ppp->dev->stats.tx_errors; |
| 15 | } |
| 16 | |
| 17 | +struct sock *ppp_netdev_get_sock(struct net_device *dev) |
| 18 | +{ |
| 19 | + struct list_head *list; |
| 20 | + struct channel *pch; |
| 21 | + struct ppp *ppp; |
| 22 | + struct sock *sk; |
| 23 | + |
| 24 | + if (!dev) |
| 25 | + return ERR_PTR(-EINVAL); |
| 26 | + |
| 27 | + ppp = netdev_priv(dev); |
| 28 | + |
| 29 | + list = &ppp->channels; |
| 30 | + if (list_empty(list)) |
| 31 | + /* nowhere to send the packet */ |
| 32 | + return ERR_PTR(-EINVAL); |
| 33 | + |
| 34 | + if (ppp->flags & SC_MULTILINK) |
| 35 | + /* not doing multilink: send it down the first channel */ |
| 36 | + return ERR_PTR(-EPERM); |
| 37 | + |
| 38 | + list = list->next; |
| 39 | + pch = list_entry(list, struct channel, clist); |
| 40 | + |
| 41 | + spin_lock(&pch->downl); |
| 42 | + if (pch->chan) |
| 43 | + sk = (struct sock *)pch->chan->private; |
| 44 | + else |
| 45 | + sk = ERR_PTR(-EINVAL); |
| 46 | + spin_unlock(&pch->downl); |
| 47 | + |
| 48 | + return sk; |
| 49 | +} |
| 50 | + |
| 51 | /* |
| 52 | * Try to send the frame in xmit_pending. |
| 53 | * The caller should have the xmit path locked. |
| 54 | --- a/include/linux/ppp_channel.h |
| 55 | +++ b/include/linux/ppp_channel.h |
| 56 | @@ -75,6 +75,9 @@ extern int ppp_unit_number(struct ppp_ch |
| 57 | /* Get the device name associated with a channel, or NULL if none */ |
| 58 | extern char *ppp_dev_name(struct ppp_channel *); |
| 59 | |
| 60 | +/* Get the socket structure of a given ppp netdev */ |
| 61 | +extern struct sock *ppp_netdev_get_sock(struct net_device *dev); |
| 62 | + |
| 63 | /* |
| 64 | * SMP locking notes: |
| 65 | * The channel code must ensure that when it calls ppp_unregister_channel, |