ppp: use file.dead to check channel unregistration
Subsystems (9)
PATCH 1/3 ppp: use file.dead to check channel unregistration
Currently, ppp_generic checks if pch->chan is NULL to determine if a channel is being unregistered. However, struct ppp_file already has a 'dead' flag for this purpose, which is used by ppp units and other parts of the driver.
Switch all pch->chan NULL checks to pch->file.dead checks. In ppp_unregister_channel, move the setting of pch->file.dead inside the locked section to ensure atomicity and remove the now redundant pch->chan = NULL assignment.
This is a preparation to eventually unify 'struct ppp_channel' and 'struct channel' into a single struct.
--- drivers/net/ppp/ppp_generic.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/net/ppp/ppp_generic.c +5 -6
@@ -790,7 +790,7 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)down_read (&pch->chan_sem); chan = pch->chan; err = -ENOTTY ; -if (chan && chan->ops->ioctl) +if (!pch->file.dead && chan->ops->ioctl) err = chan->ops->ioctl (chan, cmd, arg);up_read (&pch->chan_sem); }
@@ -2167,7 +2167,7 @@ static void __ppp_channel_push(struct channel *pch, struct ppp *ppp)struct sk_buff *skb;spin_lock (&pch->downl); -if (pch->chan) { +if (!pch->file.dead) {while (!skb_queue_empty (&pch->file.xq)) { skb =skb_dequeue (&pch->file.xq);if (!pch->chan->ops->start_xmit (pch->chan, skb)) {
@@ -2288,7 +2288,7 @@ static bool ppp_channel_bridge_input(struct channel *pch, struct sk_buff *skb) goto out_rcu;spin_lock_bh (&pchb->downl); -if (!pchb->chan) { +if (pchb->file.dead) {/* channel got unregistered */ kfree_skb (skb); goto outl;
@@ -3002,7 +3002,7 @@ ppp_unregister_channel(struct ppp_channel *chan)ppp_disconnect_channel (pch);down_write (&pch->chan_sem);spin_lock_bh (&pch->downl); - pch->chan =NULL ; + pch->file.dead =1 ;spin_unlock_bh (&pch->downl);up_write (&pch->chan_sem);
@@ -3013,7 +3013,6 @@ ppp_unregister_channel(struct ppp_channel *chan)ppp_unbridge_channels (pch); - pch->file.dead =1 ;wake_up_interruptible (&pch->file.rwait);ppp_release_channel (pch);
@@ -3505,7 +3504,7 @@ ppp_connect_channel(struct channel *pch, int unit)ppp_lock (ppp);spin_lock_bh (&pch->downl); -if (!pch->chan) { +if (pch->file.dead) {/* Don't connect unregistered channels */ spin_unlock_bh (&pch->downl);ppp_unlock (ppp);
Signature · 1 line
2.43.0
PATCH 2/3 ppp: unify two channel structs
Historically, PPP maintained two separate structures for a channel:
'struct channel' was internal to ppp_generic.c, while 'struct ppp_channel' was the public interface that drivers were required to embed. This duplication was redundant and forced drivers to manage the lifecycle of the public structure.
Unify these two structures into a single 'struct ppp_channel', which is now internal to ppp_generic.c. Drivers now use a 'ppp_channel_conf' structure to specify registration parameters and receive an opaque pointer to the allocated channel.
Key changes:
- ppp_register_channel() and ppp_register_net_channel() now return a 'struct ppp_channel *' instead of taking a pointer to a driver- embedded structure.
- 'struct ppp_channel_ops' methods now take the driver's 'private' pointer directly as their first argument, simplifying driver logic.
- ppp_unregister_channel() now takes the opaque pointer.
- Multilink-specific fields are unified and handled via the new configuration structure.
This cleanup simplifies the driver interface and makes the channel lifecycle management more robust by centralizing allocation in the PPP generic layer.
--- drivers/net/ppp/ppp_async.c | 51 +++++----- drivers/net/ppp/ppp_generic.c | 161 +++++++++++++++---------------- drivers/net/ppp/ppp_synctty.c | 51 +++++----- drivers/net/ppp/pppoe.c | 34 ++++--- drivers/net/ppp/pppox.c | 4 +- drivers/net/ppp/pptp.c | 40 ++++---- drivers/tty/ipwireless/network.c | 30 +++--- include/linux/if_pppox.h | 2 +- include/linux/ppp_channel.h | 49 ++++++---- net/atm/pppoatm.c | 61 ++++++------ net/l2tp/l2tp_ppp.c | 34 ++++--- 11 files changed, 271 insertions(+), 246 deletions(-)
drivers/net/ppp/ppp_async.c +28 -23
@@ -67,7 +67,7 @@ struct asyncppp {refcount_t refcnt;struct completion dead; -struct ppp_channel chan;/* interface to generic ppp layer */ +struct ppp_channel *chan;/* interface to generic ppp layer */ unsigned char obuf[OBUFSIZE ]; };
@@ -95,12 +95,12 @@ MODULE_ALIAS_LDISC(N_PPP);* Prototypes. */ static int ppp_async_encode (struct asyncppp *ap); -static int ppp_async_send (struct ppp_channel *chan,struct sk_buff *skb); +static int ppp_async_send (void *private,struct sk_buff *skb);static int ppp_async_push (struct asyncppp *ap);static void ppp_async_flush_output (struct asyncppp *ap);static void ppp_async_input (struct asyncppp *ap,const unsigned char *buf,const u8 *flags,int count); -static int ppp_async_ioctl (struct ppp_channel *chan,unsigned int cmd, +static int ppp_async_ioctl (void *private,unsigned int cmd,unsigned long arg);static void ppp_async_process (struct tasklet_struct *t);
@@ -155,9 +155,10 @@ static void ap_put(struct asyncppp *ap)static int ppp_asynctty_open (struct tty_struct *tty) { +struct ppp_channel_conf conf = {}; +struct ppp_channel *chan;struct asyncppp *ap;int err; -int speed;if (tty->ops->write ==NULL )return -EOPNOTSUPP ;
@@ -185,14 +186,18 @@ ppp_asynctty_open(struct tty_struct *tty)refcount_set (&ap->refcnt,1 );init_completion (&ap->dead); - ap->chan.private = ap; - ap->chan.ops = &async_ops; - ap->chan.mtu =PPP_MRU ; - speed =tty_get_baud_rate (tty); - ap->chan.speed = speed; - err =ppp_register_channel (&ap->chan); -if (err) + conf.private = ap; + conf.ops = &async_ops; +#ifdef CONFIG_PPP_MULTILINK + conf.mtu =PPP_MRU ; + conf.speed =tty_get_baud_rate (tty); +#endif + chan =ppp_register_channel (&conf); +if (!chan) { + err = -ENOMEM ; goto out_free; + } + ap->chan = chan; tty->disc_data = ap; tty->receive_room =65536 ;
@@ -235,7 +240,7 @@ ppp_asynctty_close(struct tty_struct *tty)wait_for_completion (&ap->dead);tasklet_kill (&ap->tsk); -ppp_unregister_channel (&ap->chan); +ppp_unregister_channel (ap->chan);kfree_skb (ap->rpkt);skb_queue_purge (&ap->rqueue);kfree_skb (ap->tpkt);
@@ -293,14 +298,14 @@ ppp_asynctty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)switch (cmd) {case PPPIOCGCHAN : err = -EFAULT ; -if (put_user (ppp_channel_index (&ap->chan), p)) +if (put_user (ppp_channel_index (ap->chan), p))break ; err =0 ;break ;case PPPIOCGUNIT : err = -EFAULT ; -if (put_user (ppp_unit_number (&ap->chan), p)) +if (put_user (ppp_unit_number (ap->chan), p))break ; err =0 ;break ;
@@ -391,9 +396,9 @@ ppp_async_init(void)* The following routines provide the PPP channel interface. */ static int -ppp_async_ioctl (struct ppp_channel *chan,unsigned int cmd,unsigned long arg) +ppp_async_ioctl (void *private,unsigned int cmd,unsigned long arg) { -struct asyncppp *ap = chan->private; +struct asyncppp *ap = private;void __user *argp = (void __user *)arg;int __user *p = argp;int err, val;
@@ -491,13 +496,13 @@ static void ppp_async_process(struct tasklet_struct *t)/* process received packets */ while ((skb =skb_dequeue (&ap->rqueue)) !=NULL ) {if (skb->cb[0 ]) -ppp_input_error (&ap->chan); -ppp_input (&ap->chan, skb); +ppp_input_error (ap->chan); +ppp_input (ap->chan, skb); }/* try to push more stuff out */ if (test_bit (XMIT_WAKEUP , &ap->xmit_flags) &&ppp_async_push (ap)) -ppp_output_wakeup (&ap->chan); +ppp_output_wakeup (ap->chan); }/*
@@ -620,9 +625,9 @@ ppp_async_encode(struct asyncppp *ap)* at some later time. */ static int -ppp_async_send (struct ppp_channel *chan,struct sk_buff *skb) +ppp_async_send (void *private,struct sk_buff *skb) { -struct asyncppp *ap = chan->private; +struct asyncppp *ap = private;ppp_async_push (ap);
@@ -733,7 +738,7 @@ ppp_async_flush_output(struct asyncppp *ap) }spin_unlock_bh (&ap->xmit_lock);if (done) -ppp_output_wakeup (&ap->chan); +ppp_output_wakeup (ap->chan); }/*
@@ -992,7 +997,7 @@ static void async_lcp_peek(struct asyncppp *ap, unsigned char *data,if (inbound) ap->mru = val;else - ap->chan.mtu = val; +ppp_channel_update_mtu (ap->chan, val);break ;case LCP_ASYNCMAP : val =get_unaligned_be32 (data +2 );
drivers/net/ppp/ppp_generic.c +77 -84
474 lines not on this page · raw message
drivers/net/ppp/ppp_synctty.c +28 -23
129 lines not on this page · raw message
drivers/net/ppp/pppoe.c +20 -14
@@ -357,7 +357,7 @@ static int pppoe_rcv_core(struct sock *sk, struct sk_buff *skb)*/ if (sk->sk_state &PPPOX_BOUND ) { -ppp_input (&po->chan, skb); +ppp_input (po->chan, skb); }else {if (sock_queue_rcv_skb (sk, skb)) goto abort_kfree;
@@ -631,7 +631,7 @@ static int pppoe_connect(struct socket *sock, struct sockaddr_unsized *uservaddr po->pppoe_ifindex =0 ;memset (&po->pppoe_pa,0 ,sizeof (po->pppoe_pa)); -memset (&po->chan,0 ,sizeof (po->chan)); + po->chan =NULL ; po->next =NULL ; po->num =0 ;
@@ -640,6 +640,9 @@ static int pppoe_connect(struct socket *sock, struct sockaddr_unsized *uservaddr/* Re-bind in session stage only */ if (stage_session (sp->sa_addr.pppoe.sid)) { +struct ppp_channel_conf conf = {}; +struct ppp_channel *chan; + error = -ENODEV ; net =sock_net (sk); dev =dev_get_by_name (net, sp->sa_addr.pppoe.dev);
@@ -663,20 +666,23 @@ static int pppoe_connect(struct socket *sock, struct sockaddr_unsized *uservaddrif (error <0 ) goto err_put; - po->chan.hdrlen = (sizeof (struct pppoe_hdr ) + + conf.hdrlen = (sizeof (struct pppoe_hdr ) + dev->hard_header_len); +#ifdef CONFIG_PPP_MULTILINK + conf.mtu = dev->mtu -sizeof (struct pppoe_hdr ) -2 ; +#endif + conf.private = sk; + conf.ops = &pppoe_chan_ops; + conf.direct_xmit = true; - po->chan.mtu = dev->mtu -sizeof (struct pppoe_hdr ) -2 ; - po->chan.private = sk; - po->chan.ops = &pppoe_chan_ops; - po->chan.direct_xmit = true; - - error =ppp_register_net_channel (dev_net (dev), &po->chan); -if (error) { + chan =ppp_register_net_channel (dev_net (dev), &conf); +if (!chan) { + error = -ENOMEM ;delete_item (pn, po->pppoe_pa.sid, po->pppoe_pa.remote, po->pppoe_ifindex); goto err_put; } + po->chan = chan; sk->sk_state =PPPOX_CONNECTED ; }
@@ -897,17 +903,17 @@ static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb)* sends PPP frame over PPPoE socket * ***********************************************************************/ -static int pppoe_xmit (struct ppp_channel *chan,struct sk_buff *skb) +static int pppoe_xmit (void *private,struct sk_buff *skb) { -struct sock *sk = chan->private; +struct sock *sk = private;return __pppoe_xmit (sk, skb); }static int pppoe_fill_forward_path (struct net_device_path_ctx *ctx,struct net_device_path *path, -const struct ppp_channel *chan) +void *private) { -struct sock *sk = chan->private; +struct sock *sk = private;struct pppox_sock *po =pppox_sk (sk);struct net_device *dev = po->pppoe_dev;
drivers/net/ppp/pppox.c +2 -2
@@ -55,7 +55,7 @@ void pppox_unbind_sock(struct sock *sk)/* Clear connection to ppp device, if attached. */ if (sk->sk_state & (PPPOX_BOUND |PPPOX_CONNECTED )) { -ppp_unregister_channel (&pppox_sk (sk)->chan); +ppp_unregister_channel (pppox_sk (sk)->chan); sk->sk_state =PPPOX_DEAD ; } }
@@ -80,7 +80,7 @@ int pppox_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)break ; rc = -EINVAL ; - index =ppp_channel_index (&po->chan); + index =ppp_channel_index (po->chan);if (put_user (index , (int __user *) arg))break ;
drivers/net/ppp/pptp.c +22 -18
@@ -146,9 +146,9 @@ static struct rtable *pptp_route_output(const struct pppox_sock *po,return ip_route_output_flow (net, fl4, sk); } -static int pptp_xmit (struct ppp_channel *chan,struct sk_buff *skb) +static int pptp_xmit (void *private,struct sk_buff *skb) { -struct sock *sk = chan->private; +struct sock *sk = private;struct pppox_sock *po =pppox_sk (sk);struct net *net =sock_net (sk);struct pptp_opt *opt = &po->proto.pptp;
@@ -338,7 +338,7 @@ static int pptp_rcv_core(struct sock *sk, struct sk_buff *skb) skb->ip_summed =CHECKSUM_NONE ;skb_set_network_header (skb, skb->head-skb->data); -ppp_input (&po->chan, skb); +ppp_input (po->chan, skb);return NET_RX_SUCCESS ; }
@@ -422,6 +422,8 @@ static int pptp_connect(struct socket *sock, struct sockaddr_unsized *uservaddr,struct sockaddr_pppox *sp = (struct sockaddr_pppox *) uservaddr;struct pppox_sock *po =pppox_sk (sk);struct pptp_opt *opt = &po->proto.pptp; +struct ppp_channel_conf conf = {}; +struct ppp_channel *chan;struct rtable *rt;struct flowi4 fl4;int error =0 ;
@@ -453,9 +455,6 @@ static int pptp_connect(struct socket *sock, struct sockaddr_unsized *uservaddr, goto end; } - po->chan.private = sk; - po->chan.ops = &pptp_chan_ops; - rt =pptp_route_output (po, &fl4);if (IS_ERR (rt)) { error = -EHOSTUNREACH ;
@@ -463,18 +462,23 @@ static int pptp_connect(struct socket *sock, struct sockaddr_unsized *uservaddr, }sk_setup_caps (sk, &rt->dst); - po->chan.mtu =dst_mtu (&rt->dst); -if (!po->chan.mtu) - po->chan.mtu =PPP_MRU ; - po->chan.mtu -=PPTP_HEADER_OVERHEAD ; - - po->chan.hdrlen =2 +sizeof (struct pptp_gre_header ); - po->chan.direct_xmit = true; - error =ppp_register_channel (&po->chan); -if (error) { + conf.private = sk; + conf.ops = &pptp_chan_ops; + conf.hdrlen =2 +sizeof (struct pptp_gre_header ); + conf.direct_xmit = true; +#ifdef CONFIG_PPP_MULTILINK + conf.mtu =dst_mtu (&rt->dst); +if (!conf.mtu) + conf.mtu =PPP_MRU ; + conf.mtu -=PPTP_HEADER_OVERHEAD ; +#endif + chan =ppp_register_channel (&conf); +if (!chan) { + error = -ENOMEM ;pr_err ("PPTP: failed to register PPP channel (%d)\n" , error); goto end; } + po->chan = chan; opt->dst_addr = sp->sa_addr.pptp; sk->sk_state |=PPPOX_CONNECTED ;
@@ -577,10 +581,10 @@ static int pptp_create(struct net *net, struct socket *sock, int kern)return error; } -static int pptp_ppp_ioctl (struct ppp_channel *chan,unsigned int cmd, -unsigned long arg) +static int pptp_ppp_ioctl (void *private,unsigned int cmd, +unsigned long arg) { -struct sock *sk = chan->private; +struct sock *sk = private;struct pppox_sock *po =pppox_sk (sk);struct pptp_opt *opt = &po->proto.pptp;void __user *argp = (void __user *)arg;
drivers/tty/ipwireless/network.c +14 -16
@@ -88,10 +88,10 @@ static void notify_packet_sent(void *callback_data, unsigned int packet_length)/* * Called by the ppp system when it has a packet to send to the hardware. */ -static int ipwireless_ppp_start_xmit (struct ppp_channel *ppp_channel, +static int ipwireless_ppp_start_xmit (void *private,struct sk_buff *skb) { -struct ipw_network *network = ppp_channel->private; +struct ipw_network *network = private;unsigned long flags;spin_lock_irqsave (&network->lock, flags);
@@ -153,10 +153,10 @@ static int ipwireless_ppp_start_xmit(struct ppp_channel *ppp_channel, }/* Handle an ioctl call that has come in via ppp. (copy of ppp_async_ioctl() */ -static int ipwireless_ppp_ioctl (struct ppp_channel *ppp_channel, +static int ipwireless_ppp_ioctl (void *private,unsigned int cmd,unsigned long arg) { -struct ipw_network *network = ppp_channel->private; +struct ipw_network *network = private;int err, val;u32 accm[8 ];int __user *user_arg = (int __user *) arg;
@@ -254,19 +254,17 @@ static void do_go_online(struct work_struct *work_go_online)spin_lock_irqsave (&network->lock, flags);if (!network->ppp_channel) { +struct ppp_channel_conf conf = {};struct ppp_channel *channel;spin_unlock_irqrestore (&network->lock, flags); - channel = kzalloc_obj(struct ppp_channel); -if (!channel) { - printk(KERN_ERR IPWIRELESS_PCCARD_NAME - ": unable to allocate PPP channel\n"); -return ; - } - channel->private = network; - channel->mtu =16384 ;/* Wild guess */ - channel->hdrlen =2 ; - channel->ops = &ipwireless_ppp_channel_ops; + + conf.private = network; + conf.hdrlen =2 ; + conf.ops = &ipwireless_ppp_channel_ops; +#ifdef CONFIG_PPP_MULTILINK + conf.mtu =16384 ;/* Wild guess */ +#endif network->flags =0 ; network->rbits =0 ;
@@ -275,10 +273,10 @@ static void do_go_online(struct work_struct *work_go_online) network->xaccm[0 ] = ~0U ; network->xaccm[3 ] =0x60000000U ; network->raccm = ~0U ; -if (ppp_register_channel (channel) <0 ) { + channel =ppp_register_channel (&conf); +if (!channel) { printk(KERN_ERR IPWIRELESS_PCCARD_NAME ": unable to register PPP channel\n"); -kfree (channel);return ; }spin_lock_irqsave (&network->lock, flags);
include/linux/if_pppox.h +1 -1
@@ -40,7 +40,7 @@ struct pptp_opt {struct pppox_sock {/* struct sock must be the first member of pppox_sock */ struct sock sk; -struct ppp_channel chan; +struct ppp_channel *chan;struct pppox_sock __rcu *next;/* for hash table */ union {struct pppoe_opt pppoe;
include/linux/ppp_channel.h +29 -20
84 lines not on this page · raw message
net/atm/pppoatm.c +30 -31
149 lines not on this page · raw message
net/l2tp/l2tp_ppp.c +20 -14
@@ -121,7 +121,7 @@ struct pppol2tp_session {struct sock *__sk;/* Copy of .sk, for cleanup */ }; -static int pppol2tp_xmit (struct ppp_channel *chan,struct sk_buff *skb); +static int pppol2tp_xmit (void *private,struct sk_buff *skb);static const struct ppp_channel_ops pppol2tp_chan_ops = { .start_xmit = pppol2tp_xmit,
@@ -221,7 +221,7 @@ static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, intstruct pppox_sock *po; po =pppox_sk (sk); -ppp_input (&po->chan, skb); +ppp_input (po->chan, skb); }else {if (sock_queue_rcv_skb (sk, skb) <0 ) {atomic_long_inc (&session->stats.rx_errors);
@@ -326,9 +326,9 @@ static int pppol2tp_sendmsg(struct socket *sock, struct msghdr *m,* the skb it supplied, not our cloned skb. So we take care to always * leave the original skb unfreed if we return an error. */ -static int pppol2tp_xmit (struct ppp_channel *chan,struct sk_buff *skb) +static int pppol2tp_xmit (void *private,struct sk_buff *skb) { -struct sock *sk = (struct sock *)chan->private; +struct sock *sk = private;struct l2tp_session *session;struct l2tp_tunnel *tunnel;int uhlen, headroom;
@@ -504,7 +504,7 @@ static void pppol2tp_show(struct seq_file *m, void *arg)if (sk) {struct pppox_sock *po =pppox_sk (sk); -seq_printf (m," interface %s\n" ,ppp_dev_name (&po->chan)); +seq_printf (m," interface %s\n" ,ppp_dev_name (po->chan)); }rcu_read_unlock (); }
@@ -612,7 +612,7 @@ static int pppol2tp_sockaddr_get_info(const void *sa, int sa_len,* numbers and no IP option. Not quite accurate, but the result is mostly * unused anyway. */ -static int pppol2tp_tunnel_mtu (const struct l2tp_tunnel *tunnel) +static int __maybe_unused pppol2tp_tunnel_mtu (const struct l2tp_tunnel *tunnel) {int mtu;
@@ -694,6 +694,8 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr_unsized *uservastruct l2tp_tunnel *tunnel;struct pppol2tp_session *ps;struct l2tp_session_cfg cfg = {0 , }; +struct ppp_channel_conf conf = {}; +struct ppp_channel *chan;bool drop_refcnt = false;bool new_session = false;bool new_tunnel = false;
@@ -792,18 +794,22 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr_unsized *userva* the net device's hard_header_len at registration, which must be * sufficient regardless of whether sequence numbers are enabled later. */ - po->chan.hdrlen =PPPOL2TP_L2TP_HDR_SIZE_SEQ ; + conf.hdrlen =PPPOL2TP_L2TP_HDR_SIZE_SEQ ; - po->chan.private = sk; - po->chan.ops = &pppol2tp_chan_ops; - po->chan.mtu =pppol2tp_tunnel_mtu (tunnel); - po->chan.direct_xmit = true; + conf.private = sk; + conf.ops = &pppol2tp_chan_ops; +#ifdef CONFIG_PPP_MULTILINK + conf.mtu =pppol2tp_tunnel_mtu (tunnel); +#endif + conf.direct_xmit = true; - error =ppp_register_net_channel (sock_net (sk), &po->chan); -if (error) { + chan =ppp_register_net_channel (sock_net (sk), &conf); +if (!chan) { + error = -ENOMEM ;mutex_unlock (&ps->sk_lock); goto end; } + po->chan = chan; out_no_ppp:/* This is how we get the session context from the socket. */
@@ -1550,7 +1556,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v)if (sk) {struct pppox_sock *po =pppox_sk (sk); -seq_printf (m," interface %s\n" ,ppp_dev_name (&po->chan)); +seq_printf (m," interface %s\n" ,ppp_dev_name (po->chan)); }rcu_read_unlock (); }
Signature · 1 line
2.43.0
PATCH 3/3 docs: update ppp_generic.rst for API changes
In reply to Qingfang DengDocument the new ppp_channel_conf struct and ppp_channel lifecycle management changes.
--- Documentation/networking/ppp_generic.rst | 33 ++++++++++-------------- 1 file changed, 13 insertions(+), 20 deletions(-)
Documentation/networking/ppp_generic.rst +13 -20
@@ -124,18 +124,19 @@ presented to the start_xmit() function contain only the 2-byte protocol number and the data, and the skbuffs presented to ppp_input() must be in the same format. -The channel must provide an instance of a ppp_channel struct to -represent the channel. The channel is free to use the ``private`` field -however it wishes. The channel should initialize the ``mtu`` and -``hdrlen`` fields before calling ppp_register_channel() and not change -them until after ppp_unregister_channel() returns. The ``mtu`` field -represents the maximum size of the data part of the PPP frames, that -is, it does not include the 2-byte protocol number. +The channel must provide an instance of a ppp_channel_conf struct to +describe the channel during registration. The generic layer will +allocate a ppp_channel struct and return a pointer to it. The +ppp_channel struct is opaque to the channel driver. The ``mtu`` field +(if multilink is enabled) represents the maximum size of the data part +of the PPP frames, that is, it does not include the 2-byte protocol +number. ppp_channel_update_mtu() can be called by the channel driver +to update the ``mtu`` field once LCP MRU negotiation is complete. If the channel needs some headroom in the skbuffs presented to it for transmission (i.e., some space free in the skbuff data area before the start of the PPP frame), it should set the ``hdrlen`` field of the -ppp_channel struct to the amount of headroom required. The generic +ppp_channel_conf struct to the amount of headroom required. The generic PPP layer will attempt to provide that much headroom but the channel should still check if there is sufficient headroom and copy the skbuff if there isn't.
@@ -199,20 +200,12 @@ The PPP generic layer has been designed to be SMP-safe. Locks are used around accesses to the internal data structures where necessary to ensure their integrity. As part of this, the generic layer requires that the channels adhere to certain requirements and in turn -provides certain guarantees to the channels. Essentially the channels -are required to provide the appropriate locking on the ppp_channel -structures that form the basis of the communication between the -channel and the generic layer. This is because the channel provides -the storage for the ppp_channel structure, and so the channel is -required to provide the guarantee that this storage exists and is -valid at the appropriate times. +provides certain guarantees to the channels. The generic layer manages +the ppp_channel object, ensuring it exists and is valid while the +channel is registered. The generic layer requires these guarantees from the channel: -* The ppp_channel object must exist from the time that - ppp_register_channel() is called until after the call to - ppp_unregister_channel() returns. - * No thread may be in a call to any of ppp_input(), ppp_input_error(), ppp_output_wakeup(), ppp_channel_index() or ppp_unit_number() for a channel at the time that ppp_unregister_channel() is called for that
@@ -453,4 +446,4 @@ an interface unit are: fragments is disabled. This ioctl is only available if the CONFIG_PPP_MULTILINK option is selected. -Last modified: 7-feb-2002 +Last modified: 16-apr-2026
Signature · 1 line
2.43.0
Paolo Abeni
maintainerRe: [PATCH net-next 2/3] ppp: unify two channel structs
In reply to Qingfang DengQuoted 27 lines · Qingfang Deng
Historically, PPP maintained two separate structures for a channel:
'struct channel' was internal toppp_generic.c, while 'structppp_channel' was the public interface that drivers were required to embed. This duplication was redundant and forced drivers to manage the lifecycle of the public structure.Unify these two structures into a single 'struct
ppp_channel', which is now internal toppp_generic.c. Drivers now use a 'ppp_channel_conf' structure to specify registration parameters and receive an opaque pointer to the allocated channel.Key changes:
-ppp_register_channel()andppp_register_net_channel()now return a 'structppp_channel*' instead of taking a pointer to a driver- embedded structure.
- 'structppp_channel_ops' methods now take the driver's 'private' pointer directly as their first argument, simplifying driver logic.
-ppp_unregister_channel()now takes the opaque pointer.
- Multilink-specific fields are unified and handled via the new configuration structure.This cleanup simplifies the driver interface and makes the channel lifecycle management more robust by centralizing allocation in the PPP generic layer.
Assisted-by Gemini:gemini-3-flashSigned-off-by Qingfang Deng <[email protected]>
Quoted 13 lines
--- drivers/net/ppp/ppp_async.c | 51 +++++----- drivers/net/ppp/ppp_generic.c | 161 +++++++++++++++---------------- drivers/net/ppp/ppp_synctty.c | 51 +++++----- drivers/net/ppp/pppoe.c | 34 ++++--- drivers/net/ppp/pppox.c | 4 +- drivers/net/ppp/pptp.c | 40 ++++---- drivers/tty/ipwireless/network.c | 30 +++--- include/linux/if_pppox.h | 2 +- include/linux/ppp_channel.h | 49 ++++++---- net/atm/pppoatm.c | 61 ++++++------ net/l2tp/l2tp_ppp.c | 34 ++++--- 11 files changed, 271 insertions(+), 246 deletions(-)
This patch is IMHO a bit too big and should be split. Also this kind of refactor looks very invasive and potentially regression prone. I think it should include a signficant self-test coverage increase.
drivers/net/ppp/ppp_async.c ppp_async_init(void) · line 404
Quoted 12 lines
drivers/net/ppp/ppp_async.c +2
-2@@ -391,9 +396,9 @@ ppp_async_init(void)* The following routines provide the PPP channel interface. */ static int -ppp_async_ioctl (struct ppp_channel *chan,unsigned int cmd,unsigned long arg) +ppp_async_ioctl (void *private,unsigned int cmd,unsigned long arg) { -struct asyncppp *ap = chan->private; +struct asyncppp *ap = private;void __user *argp = (void __user *)arg;int __user *p = argp;int err, val;
Minor nit: reverse christmas tree above
Quoted 5 lines
drivers/net/ppp/ppp_generic.c +0
-1@@ -2985,16 +2983,13 @@ char *ppp_dev_name(struct ppp_channel *chan)* This must be called in process context. */ void -ppp_unregister_channel (struct ppp_channel *chan)
drivers/net/ppp/ppp_generic.c char *ppp_dev_name(struct ppp_channel *chan) · line 2997
Quoted 10 lines
drivers/net/ppp/ppp_generic.c +1
-3+ppp_unregister_channel(struct ppp_channel *pch) { -struct channel *pch = chan->ppp;struct ppp_net *pn;if (!pch)return ;/* should never happen */ - chan->ppp =NULL ; -
Sashiko says:
Could this specific ordering introduce a race condition that might lead to a use-after-free?
If userspace has a file descriptor attached to this channel, it can concurrently invoke the PPPIOCCONNECT ioctl. Because ppp_disconnect_channel()
clears pch->ppp and removes the channel from its current unit before pch->file.dead is set to 1, the concurrent ioctl could observe pch->file.dead == 0.
This would allow ppp_connect_channel() to successfully attach the dying channel to a new PPP unit. Once ppp_unregister_channel() completes and frees the channel, the new PPP unit would retain a pointer to the freed memory in its channels list, which might be accessed during a later packet transmission via ppp_push().
net/atm/pppoatm.c static void pppoatm_push(struct atm_vcc *atmvcc, struct sk_buff *skb) · line 214
Quoted 7 lines
net/atm/pppoatm.c +2
-1@@ -215,7 +210,8 @@ static void pppoatm_push(struct atm_vcc *atmvcc, struct sk_buff *skb) !memcmp(skb->data, &pppllc[LLC_LEN], sizeof(pppllc) - LLC_LEN)) { pvcc->encaps = e_vc; - pvcc->chan.mtu +=LLC_LEN ; +ppp_channel_update_mtu (pvcc->chan, + atmvcc->qos.txtp.max_sdu -PPP_HDRLEN );
Does the above introduce a functional change? At very least some comment needed. Also possibly better move the update_mtu wrapper to a pre-req patch.
net/l2tp/l2tp_ppp.c static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, int · line 224
Quoted 6 lines
net/l2tp/l2tp_ppp.c +1
-1@@ -221,7 +221,7 @@ static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, intstruct pppox_sock *po; po =pppox_sk (sk); -ppp_input (&po->chan, skb); +ppp_input (po->chan, skb);
Sashiko says:
Does decoupling the channel lifetime from the driver structure introduce a use-after-free when receiving packets?
Previously, the struct ppp_channel was embedded in struct pppox_sock, meaning its lifecycle was safely tied to the socket's refcount. Now that po->chan is dynamically allocated and freed during pppox_unbind_sock() via ppp_unregister_channel(), it seems possible for pppol2tp_recv() to access freed memory.
Since pppol2tp_recv() runs locklessly in softirq context while holding only rcu_read_lock() and a socket reference, can it observe the PPPOX_BOUND state and dereference po->chan just after it was freed on another CPU?
/P
Re: [PATCH net-next 2/3] ppp: unify two channel structs
Quoted 41 lines · Paolo Abeni
Quoted 27 lines · Qingfang Deng
Historically, PPP maintained two separate structures for a channel:
'struct channel' was internal toppp_generic.c, while 'structppp_channel' was the public interface that drivers were required to embed. This duplication was redundant and forced drivers to manage the lifecycle of the public structure.Unify these two structures into a single 'struct
ppp_channel', which is now internal toppp_generic.c. Drivers now use a 'ppp_channel_conf' structure to specify registration parameters and receive an opaque pointer to the allocated channel.Key changes:
-ppp_register_channel()andppp_register_net_channel()now return a 'structppp_channel*' instead of taking a pointer to a driver- embedded structure.
- 'structppp_channel_ops' methods now take the driver's 'private' pointer directly as their first argument, simplifying driver logic.
-ppp_unregister_channel()now takes the opaque pointer.
- Multilink-specific fields are unified and handled via the new configuration structure.This cleanup simplifies the driver interface and makes the channel lifecycle management more robust by centralizing allocation in the PPP generic layer.
Assisted-by Gemini:gemini-3-flashSigned-off-by Qingfang Deng <[email protected]>Quoted 13 lines
--- drivers/net/ppp/ppp_async.c | 51 +++++----- drivers/net/ppp/ppp_generic.c | 161 +++++++++++++++---------------- drivers/net/ppp/ppp_synctty.c | 51 +++++----- drivers/net/ppp/pppoe.c | 34 ++++--- drivers/net/ppp/pppox.c | 4 +- drivers/net/ppp/pptp.c | 40 ++++---- drivers/tty/ipwireless/network.c | 30 +++--- include/linux/if_pppox.h | 2 +- include/linux/ppp_channel.h | 49 ++++++---- net/atm/pppoatm.c | 61 ++++++------ net/l2tp/l2tp_ppp.c | 34 ++++--- 11 files changed, 271 insertions(+), 246 deletions(-)
Quoted 3 lines
This patch is IMHO a bit too big and should be split. Also this kind of refactor looks very invasive and potentially regression prone. I think it should include a signficant self-test coverage increase.
This is indeed too big. But how do I split it without breaking the build?
Paolo Abeni
maintainerRe: [PATCH net-next 2/3] ppp: unify two channel structs
Quoted 42 lines · Qingfang Deng
Quoted 41 lines · Paolo Abeni
Quoted 40 lines · Qingfang Deng
Historically, PPP maintained two separate structures for a channel:
'struct channel' was internal toppp_generic.c, while 'structppp_channel' was the public interface that drivers were required to embed. This duplication was redundant and forced drivers to manage the lifecycle of the public structure.Unify these two structures into a single 'struct
ppp_channel', which is now internal toppp_generic.c. Drivers now use a 'ppp_channel_conf' structure to specify registration parameters and receive an opaque pointer to the allocated channel.Key changes:
-ppp_register_channel()andppp_register_net_channel()now return a 'structppp_channel*' instead of taking a pointer to a driver- embedded structure.
- 'structppp_channel_ops' methods now take the driver's 'private' pointer directly as their first argument, simplifying driver logic.
-ppp_unregister_channel()now takes the opaque pointer.
- Multilink-specific fields are unified and handled via the new configuration structure.This cleanup simplifies the driver interface and makes the channel lifecycle management more robust by centralizing allocation in the PPP generic layer.
Assisted-by Gemini:gemini-3-flashSigned-off-by Qingfang Deng <[email protected]>--- drivers/net/ppp/ppp_async.c | 51 +++++----- drivers/net/ppp/ppp_generic.c | 161 +++++++++++++++---------------- drivers/net/ppp/ppp_synctty.c | 51 +++++----- drivers/net/ppp/pppoe.c | 34 ++++--- drivers/net/ppp/pppox.c | 4 +- drivers/net/ppp/pptp.c | 40 ++++---- drivers/tty/ipwireless/network.c | 30 +++--- include/linux/if_pppox.h | 2 +- include/linux/ppp_channel.h | 49 ++++++---- net/atm/pppoatm.c | 61 ++++++------ net/l2tp/l2tp_ppp.c | 34 ++++--- 11 files changed, 271 insertions(+), 246 deletions(-)
Quoted 4 lines
Quoted 3 lines
This patch is IMHO a bit too big and should be split. Also this kind of refactor looks very invasive and potentially regression prone. I think it should include a signficant self-test coverage increase.
This is indeed too big. But how do I split it without breaking the build?
This is indeed a good question, but I'm really unable to give you a good answer without allocating to this topic much more time than I have available.
I think that the (indeed smallish) mtu changes could easily go in a separate patch.
You could try introducing the struct and/or variables renaming separately, with no actual functional change, i.e.
- one patch to rename ppp_channel -> ppp_channel_conf
- one patch to rename channel -> ppp_channel
(possibly adjust accordingly the variables name if can done mechanically)
no idea if the end result would be more palatable, but possibly worth a try.
/P
Re: [PATCH net-next 2/3] ppp: unify two channel structs
In reply to Qingfang DengQuoted 4 lines · Qingfang Deng
Quoted 3 lines
This patch is IMHO a bit too big and should be split. Also this kind of refactor looks very invasive and potentially regression prone. I think it should include a signficant self-test coverage increase.
This is indeed too big. But how do I split it without breaking the build?
The current ppp tests would yell if you accidentally broke something?
Sebastian
Re: [PATCH net-next 2/3] ppp: unify two channel structs
Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 4 lines · Qingfang Deng
Quoted 3 lines
This patch is IMHO a bit too big and should be split. Also this kind of refactor looks very invasive and potentially regression prone. I think it should include a signficant self-test coverage increase.
This is indeed too big. But how do I split it without breaking the build?
The current ppp tests would yell if you accidentally broke something?
By "breaking the build" I meant compile-time errors (due to API changes).
Re: [PATCH net-next 2/3] ppp: unify two channel structs
Quoted 8 lines · Qingfang Deng
Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 4 lines · Qingfang Deng
Quoted 3 lines
This patch is IMHO a bit too big and should be split. Also this kind of refactor looks very invasive and potentially regression prone. I think it should include a signficant self-test coverage increase.
This is indeed too big. But how do I split it without breaking the build?
The current ppp tests would yell if you accidentally broke something?
By "breaking the build" I meant compile-time errors (due to API changes).
If this change would flip the logic somewhere and as such break ppp at runtime.
Would the existing test suite be able to catch it?
Sebastian
Re: [PATCH net-next 2/3] ppp: unify two channel structs
Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 5 lines · Qingfang Deng
Quoted 4 lines · Sebastian Andrzej Siewior
Quoted 3 lines · Qingfang Deng
Quoted 3 lines
This patch is IMHO a bit too big and should be split. Also this kind of refactor looks very invasive and potentially regression prone. I think it should include a signficant self-test coverage increase.
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line
This is indeed too big. But how do I split it without breaking the build?
The current ppp tests would yell if you accidentally broke something?
By "breaking the build" I meant compile-time errors (due to API changes).
If this change would flip the logic somewhere and as such break ppp at runtime.
Would the existing test suite be able to catch it?
The current self-test only covers PPP async and PPPoE, and that's why Paolo suggests more self-tests.