blob: f2729cbdb83e808dcfaae7a7a5c58fe7cc8195e8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Generic PPP layer for Linux.
3 *
4 * Copyright 1999-2002 Paul Mackerras.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 * The generic PPP layer handles the PPP network interfaces, the
12 * /dev/ppp device, packet and VJ compression, and multilink.
13 * It talks to PPP `channels' via the interface defined in
14 * include/linux/ppp_channel.h. Channels provide the basic means for
15 * sending and receiving PPP frames on some kind of communications
16 * channel.
17 *
18 * Part of the code in this driver was inspired by the old async-only
19 * PPP driver, written by Michael Callahan and Al Longyear, and
20 * subsequently hacked by Paul Mackerras.
21 *
22 * ==FILEVERSION 20041108==
23 */
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/module.h>
26#include <linux/kernel.h>
27#include <linux/kmod.h>
28#include <linux/init.h>
29#include <linux/list.h>
Cyrill Gorcunov7a95d262008-12-17 00:34:06 -080030#include <linux/idr.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/netdevice.h>
32#include <linux/poll.h>
33#include <linux/ppp_defs.h>
34#include <linux/filter.h>
Paul Mackerrasbf7daeb2012-03-04 12:56:04 +000035#include <linux/ppp-ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/ppp_channel.h>
37#include <linux/ppp-comp.h>
38#include <linux/skbuff.h>
39#include <linux/rtnetlink.h>
40#include <linux/if_arp.h>
41#include <linux/ip.h>
42#include <linux/tcp.h>
43#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/rwsem.h>
45#include <linux/stddef.h>
46#include <linux/device.h>
Arjan van de Ven8ed965d2006-03-23 03:00:21 -080047#include <linux/mutex.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090048#include <linux/slab.h>
Guillaume Nault96d934c2016-04-28 17:55:30 +020049#include <linux/file.h>
Changli Gao96545ae2011-01-06 13:37:36 +000050#include <asm/unaligned.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <net/slhc_vj.h>
Arun Sharma600634972011-07-26 16:09:06 -070052#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Cyrill Gorcunov273ec512009-01-21 15:55:35 -080054#include <linux/nsproxy.h>
55#include <net/net_namespace.h>
56#include <net/netns/generic.h>
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define PPP_VERSION "2.4.2"
59
60/*
61 * Network protocols we support.
62 */
63#define NP_IP 0 /* Internet Protocol V4 */
64#define NP_IPV6 1 /* Internet Protocol V6 */
65#define NP_IPX 2 /* IPX protocol */
66#define NP_AT 3 /* Appletalk protocol */
67#define NP_MPLS_UC 4 /* MPLS unicast */
68#define NP_MPLS_MC 5 /* MPLS multicast */
69#define NUM_NP 6 /* Number of NPs. */
70
71#define MPHDRLEN 6 /* multilink protocol header length */
72#define MPHDRLEN_SSN 4 /* ditto with short sequence numbers */
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74/*
75 * An instance of /dev/ppp can be associated with either a ppp
76 * interface unit or a ppp channel. In both cases, file->private_data
77 * points to one of these.
78 */
79struct ppp_file {
80 enum {
81 INTERFACE=1, CHANNEL
82 } kind;
83 struct sk_buff_head xq; /* pppd transmit queue */
84 struct sk_buff_head rq; /* receive queue for pppd */
85 wait_queue_head_t rwait; /* for poll on reading /dev/ppp */
86 atomic_t refcnt; /* # refs (incl /dev/ppp attached) */
87 int hdrlen; /* space to leave for headers */
88 int index; /* interface unit / channel number */
89 int dead; /* unit/channel has been shut down */
90};
91
Robert P. J. Dayb385a142007-02-10 01:46:25 -080092#define PF_TO_X(pf, X) container_of(pf, X, file)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94#define PF_TO_PPP(pf) PF_TO_X(pf, struct ppp)
95#define PF_TO_CHANNEL(pf) PF_TO_X(pf, struct channel)
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097/*
Kevin Groenevelde51f6ff2012-07-27 17:38:53 +000098 * Data structure to hold primary network stats for which
99 * we want to use 64 bit storage. Other network stats
100 * are stored in dev->stats of the ppp strucute.
101 */
102struct ppp_link_stats {
103 u64 rx_packets;
104 u64 tx_packets;
105 u64 rx_bytes;
106 u64 tx_bytes;
107};
108
109/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 * Data structure describing one ppp unit.
111 * A ppp unit corresponds to a ppp network interface device
112 * and represents a multilink bundle.
113 * It can have 0 or more ppp channels connected to it.
114 */
115struct ppp {
116 struct ppp_file file; /* stuff for read/write/poll 0 */
117 struct file *owner; /* file that owns this unit 48 */
118 struct list_head channels; /* list of attached channels 4c */
119 int n_channels; /* how many channels are attached 54 */
120 spinlock_t rlock; /* lock for receive side 58 */
121 spinlock_t wlock; /* lock for transmit side 5c */
Gao Feng3b25bfc2017-07-17 18:34:42 +0800122 int *xmit_recursion __percpu; /* xmit recursion detect */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 int mru; /* max receive unit 60 */
124 unsigned int flags; /* control bits 64 */
125 unsigned int xstate; /* transmit state bits 68 */
126 unsigned int rstate; /* receive state bits 6c */
127 int debug; /* debug flags 70 */
128 struct slcompress *vj; /* state for VJ header compression */
129 enum NPmode npmode[NUM_NP]; /* what to do with each net proto 78 */
130 struct sk_buff *xmit_pending; /* a packet ready to go out 88 */
131 struct compressor *xcomp; /* transmit packet compressor 8c */
132 void *xc_state; /* its internal state 90 */
133 struct compressor *rcomp; /* receive decompressor 94 */
134 void *rc_state; /* its internal state 98 */
135 unsigned long last_xmit; /* jiffies when last pkt sent 9c */
136 unsigned long last_recv; /* jiffies when last pkt rcvd a0 */
137 struct net_device *dev; /* network interface device a4 */
James Chapman739840d2008-12-17 12:02:16 +0000138 int closing; /* is device closing down? a8 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#ifdef CONFIG_PPP_MULTILINK
140 int nxchan; /* next channel to send something on */
141 u32 nxseq; /* next sequence number to send */
142 int mrru; /* MP: max reconst. receive unit */
143 u32 nextseq; /* MP: seq no of next packet */
144 u32 minseq; /* MP: min of most recent seqnos */
145 struct sk_buff_head mrq; /* MP: receive reconstruction queue */
146#endif /* CONFIG_PPP_MULTILINK */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#ifdef CONFIG_PPP_FILTER
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -0700148 struct bpf_prog *pass_filter; /* filter for packets to pass */
149 struct bpf_prog *active_filter; /* filter for pkts to reset idle */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#endif /* CONFIG_PPP_FILTER */
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800151 struct net *ppp_net; /* the net we belong to */
Kevin Groenevelde51f6ff2012-07-27 17:38:53 +0000152 struct ppp_link_stats stats64; /* 64 bit network stats */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153};
154
155/*
156 * Bits in flags: SC_NO_TCP_CCID, SC_CCP_OPEN, SC_CCP_UP, SC_LOOP_TRAFFIC,
Matt Domschb3f9b922005-11-08 09:40:47 -0800157 * SC_MULTILINK, SC_MP_SHORTSEQ, SC_MP_XSHORTSEQ, SC_COMP_TCP, SC_REJ_COMP_TCP,
158 * SC_MUST_COMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 * Bits in rstate: SC_DECOMP_RUN, SC_DC_ERROR, SC_DC_FERROR.
160 * Bits in xstate: SC_COMP_RUN
161 */
162#define SC_FLAG_BITS (SC_NO_TCP_CCID|SC_CCP_OPEN|SC_CCP_UP|SC_LOOP_TRAFFIC \
163 |SC_MULTILINK|SC_MP_SHORTSEQ|SC_MP_XSHORTSEQ \
Matt Domschb3f9b922005-11-08 09:40:47 -0800164 |SC_COMP_TCP|SC_REJ_COMP_TCP|SC_MUST_COMP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166/*
167 * Private data structure for each channel.
168 * This includes the data structure used for multilink.
169 */
170struct channel {
171 struct ppp_file file; /* stuff for read/write/poll */
172 struct list_head list; /* link in all/new_channels list */
173 struct ppp_channel *chan; /* public channel data structure */
174 struct rw_semaphore chan_sem; /* protects `chan' during chan ioctl */
175 spinlock_t downl; /* protects `chan', file.xq dequeue */
176 struct ppp *ppp; /* ppp unit we're connected to */
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800177 struct net *chan_net; /* the net channel belongs to */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 struct list_head clist; /* link in list of channels per unit */
179 rwlock_t upl; /* protects `ppp' */
180#ifdef CONFIG_PPP_MULTILINK
181 u8 avail; /* flag used in multilink stuff */
182 u8 had_frag; /* >= 1 fragments have been sent */
183 u32 lastseq; /* MP: last sequence # received */
Lennart Sorensenfa44a732010-01-18 12:59:55 +0000184 int speed; /* speed of the corresponding ppp channel*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185#endif /* CONFIG_PPP_MULTILINK */
186};
187
Guillaume Nault7d9f0b42016-04-28 17:55:28 +0200188struct ppp_config {
189 struct file *file;
190 s32 unit;
Guillaume Nault96d934c2016-04-28 17:55:30 +0200191 bool ifname_is_set;
Guillaume Nault7d9f0b42016-04-28 17:55:28 +0200192};
193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194/*
195 * SMP locking issues:
196 * Both the ppp.rlock and ppp.wlock locks protect the ppp.channels
197 * list and the ppp.n_channels field, you need to take both locks
198 * before you modify them.
199 * The lock ordering is: channel.upl -> ppp.wlock -> ppp.rlock ->
200 * channel.downl.
201 */
202
Arnd Bergmann15fd0cd2010-07-11 11:18:57 +0000203static DEFINE_MUTEX(ppp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204static atomic_t ppp_unit_count = ATOMIC_INIT(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205static atomic_t channel_count = ATOMIC_INIT(0);
206
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800207/* per-net private data for this module */
Eric Dumazetf99189b2009-11-17 10:42:49 +0000208static int ppp_net_id __read_mostly;
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800209struct ppp_net {
210 /* units to ppp mapping */
211 struct idr units_idr;
212
213 /*
214 * all_ppp_mutex protects the units_idr mapping.
215 * It also ensures that finding a ppp unit in the units_idr
216 * map and updating its file.refcnt field is atomic.
217 */
218 struct mutex all_ppp_mutex;
219
220 /* channels */
221 struct list_head all_channels;
222 struct list_head new_channels;
223 int last_channel_index;
224
225 /*
226 * all_channels_lock protects all_channels and
227 * last_channel_index, and the atomicity of find
228 * a channel and updating its file.refcnt field.
229 */
230 spinlock_t all_channels_lock;
231};
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233/* Get the PPP protocol number from a skb */
Changli Gao96545ae2011-01-06 13:37:36 +0000234#define PPP_PROTO(skb) get_unaligned_be16((skb)->data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236/* We limit the length of ppp->file.rq to this (arbitrary) value */
237#define PPP_MAX_RQLEN 32
238
239/*
240 * Maximum number of multilink fragments queued up.
241 * This has to be large enough to cope with the maximum latency of
242 * the slowest channel relative to the others. Strictly it should
243 * depend on the number of channels and their characteristics.
244 */
245#define PPP_MP_MAX_QLEN 128
246
247/* Multilink header bits. */
248#define B 0x80 /* this fragment begins a packet */
249#define E 0x40 /* this fragment ends a packet */
250
251/* Compare multilink sequence numbers (assumed to be 32 bits wide) */
252#define seq_before(a, b) ((s32)((a) - (b)) < 0)
253#define seq_after(a, b) ((s32)((a) - (b)) > 0)
254
255/* Prototypes. */
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800256static int ppp_unattached_ioctl(struct net *net, struct ppp_file *pf,
257 struct file *file, unsigned int cmd, unsigned long arg);
Guillaume Naultfe3627f2018-03-20 16:49:26 +0100258static void ppp_xmit_process(struct ppp *ppp, struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259static void ppp_send_frame(struct ppp *ppp, struct sk_buff *skb);
260static void ppp_push(struct ppp *ppp);
261static void ppp_channel_push(struct channel *pch);
262static void ppp_receive_frame(struct ppp *ppp, struct sk_buff *skb,
263 struct channel *pch);
264static void ppp_receive_error(struct ppp *ppp);
265static void ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb);
266static struct sk_buff *ppp_decompress_frame(struct ppp *ppp,
267 struct sk_buff *skb);
268#ifdef CONFIG_PPP_MULTILINK
269static void ppp_receive_mp_frame(struct ppp *ppp, struct sk_buff *skb,
270 struct channel *pch);
271static void ppp_mp_insert(struct ppp *ppp, struct sk_buff *skb);
272static struct sk_buff *ppp_mp_reconstruct(struct ppp *ppp);
273static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb);
274#endif /* CONFIG_PPP_MULTILINK */
275static int ppp_set_compress(struct ppp *ppp, unsigned long arg);
276static void ppp_ccp_peek(struct ppp *ppp, struct sk_buff *skb, int inbound);
277static void ppp_ccp_closed(struct ppp *ppp);
278static struct compressor *find_compressor(int type);
279static void ppp_get_stats(struct ppp *ppp, struct ppp_stats *st);
Guillaume Nault7d9f0b42016-04-28 17:55:28 +0200280static int ppp_create_interface(struct net *net, struct file *file, int *unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281static void init_ppp_file(struct ppp_file *pf, int kind);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282static void ppp_destroy_interface(struct ppp *ppp);
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800283static struct ppp *ppp_find_unit(struct ppp_net *pn, int unit);
284static struct channel *ppp_find_channel(struct ppp_net *pn, int unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285static int ppp_connect_channel(struct channel *pch, int unit);
286static int ppp_disconnect_channel(struct channel *pch);
287static void ppp_destroy_channel(struct channel *pch);
Cyrill Gorcunov7a95d262008-12-17 00:34:06 -0800288static int unit_get(struct idr *p, void *ptr);
Cyrill Gorcunov85997572009-01-12 22:11:56 -0800289static int unit_set(struct idr *p, void *ptr, int n);
Cyrill Gorcunov7a95d262008-12-17 00:34:06 -0800290static void unit_put(struct idr *p, int n);
291static void *unit_find(struct idr *p, int n);
Guillaume Nault96d934c2016-04-28 17:55:30 +0200292static void ppp_setup(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Guillaume Nault79c441a2015-08-24 11:35:30 +0200294static const struct net_device_ops ppp_netdev_ops;
295
gregkh@suse.de56b22932005-03-23 10:01:41 -0800296static struct class *ppp_class;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800298/* per net-namespace data */
299static inline struct ppp_net *ppp_pernet(struct net *net)
300{
301 BUG_ON(!net);
302
303 return net_generic(net, ppp_net_id);
304}
305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306/* Translates a PPP protocol number to a NP index (NP == network protocol) */
307static inline int proto_to_npindex(int proto)
308{
309 switch (proto) {
310 case PPP_IP:
311 return NP_IP;
312 case PPP_IPV6:
313 return NP_IPV6;
314 case PPP_IPX:
315 return NP_IPX;
316 case PPP_AT:
317 return NP_AT;
318 case PPP_MPLS_UC:
319 return NP_MPLS_UC;
320 case PPP_MPLS_MC:
321 return NP_MPLS_MC;
322 }
323 return -EINVAL;
324}
325
326/* Translates an NP index into a PPP protocol number */
327static const int npindex_to_proto[NUM_NP] = {
328 PPP_IP,
329 PPP_IPV6,
330 PPP_IPX,
331 PPP_AT,
332 PPP_MPLS_UC,
333 PPP_MPLS_MC,
334};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336/* Translates an ethertype into an NP index */
337static inline int ethertype_to_npindex(int ethertype)
338{
339 switch (ethertype) {
340 case ETH_P_IP:
341 return NP_IP;
342 case ETH_P_IPV6:
343 return NP_IPV6;
344 case ETH_P_IPX:
345 return NP_IPX;
346 case ETH_P_PPPTALK:
347 case ETH_P_ATALK:
348 return NP_AT;
349 case ETH_P_MPLS_UC:
350 return NP_MPLS_UC;
351 case ETH_P_MPLS_MC:
352 return NP_MPLS_MC;
353 }
354 return -1;
355}
356
357/* Translates an NP index into an ethertype */
358static const int npindex_to_ethertype[NUM_NP] = {
359 ETH_P_IP,
360 ETH_P_IPV6,
361 ETH_P_IPX,
362 ETH_P_PPPTALK,
363 ETH_P_MPLS_UC,
364 ETH_P_MPLS_MC,
365};
366
367/*
368 * Locking shorthand.
369 */
370#define ppp_xmit_lock(ppp) spin_lock_bh(&(ppp)->wlock)
371#define ppp_xmit_unlock(ppp) spin_unlock_bh(&(ppp)->wlock)
372#define ppp_recv_lock(ppp) spin_lock_bh(&(ppp)->rlock)
373#define ppp_recv_unlock(ppp) spin_unlock_bh(&(ppp)->rlock)
374#define ppp_lock(ppp) do { ppp_xmit_lock(ppp); \
375 ppp_recv_lock(ppp); } while (0)
376#define ppp_unlock(ppp) do { ppp_recv_unlock(ppp); \
377 ppp_xmit_unlock(ppp); } while (0)
378
379/*
380 * /dev/ppp device routines.
381 * The /dev/ppp device is used by pppd to control the ppp unit.
382 * It supports the read, write, ioctl and poll functions.
383 * Open instances of /dev/ppp can be in one of three states:
384 * unattached, attached to a ppp unit, or attached to a ppp channel.
385 */
386static int ppp_open(struct inode *inode, struct file *file)
387{
388 /*
389 * This could (should?) be enforced by the permissions on /dev/ppp.
390 */
391 if (!capable(CAP_NET_ADMIN))
392 return -EPERM;
393 return 0;
394}
395
Alan Coxf3ff8a42008-05-25 23:40:58 -0700396static int ppp_release(struct inode *unused, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
398 struct ppp_file *pf = file->private_data;
399 struct ppp *ppp;
400
Joe Perchescd228d52007-11-12 18:07:31 -0800401 if (pf) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 file->private_data = NULL;
403 if (pf->kind == INTERFACE) {
404 ppp = PF_TO_PPP(pf);
Guillaume Nault8cb775b2015-08-14 10:42:56 +0200405 rtnl_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 if (file == ppp->owner)
Guillaume Nault8cb775b2015-08-14 10:42:56 +0200407 unregister_netdevice(ppp->dev);
408 rtnl_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 }
410 if (atomic_dec_and_test(&pf->refcnt)) {
411 switch (pf->kind) {
412 case INTERFACE:
413 ppp_destroy_interface(PF_TO_PPP(pf));
414 break;
415 case CHANNEL:
416 ppp_destroy_channel(PF_TO_CHANNEL(pf));
417 break;
418 }
419 }
420 }
421 return 0;
422}
423
424static ssize_t ppp_read(struct file *file, char __user *buf,
425 size_t count, loff_t *ppos)
426{
427 struct ppp_file *pf = file->private_data;
428 DECLARE_WAITQUEUE(wait, current);
429 ssize_t ret;
430 struct sk_buff *skb = NULL;
Simon Arlott19937d02010-05-03 10:20:27 +0000431 struct iovec iov;
Al Viroba568402014-11-24 17:48:04 -0500432 struct iov_iter to;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
434 ret = count;
435
Joe Perchescd228d52007-11-12 18:07:31 -0800436 if (!pf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 return -ENXIO;
438 add_wait_queue(&pf->rwait, &wait);
439 for (;;) {
440 set_current_state(TASK_INTERRUPTIBLE);
441 skb = skb_dequeue(&pf->rq);
442 if (skb)
443 break;
444 ret = 0;
445 if (pf->dead)
446 break;
447 if (pf->kind == INTERFACE) {
448 /*
449 * Return 0 (EOF) on an interface that has no
450 * channels connected, unless it is looping
451 * network traffic (demand mode).
452 */
453 struct ppp *ppp = PF_TO_PPP(pf);
Guillaume Naultedffc212016-02-26 18:45:34 +0100454
455 ppp_recv_lock(ppp);
Joe Perches8e95a202009-12-03 07:58:21 +0000456 if (ppp->n_channels == 0 &&
Guillaume Naultedffc212016-02-26 18:45:34 +0100457 (ppp->flags & SC_LOOP_TRAFFIC) == 0) {
458 ppp_recv_unlock(ppp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 break;
Guillaume Naultedffc212016-02-26 18:45:34 +0100460 }
461 ppp_recv_unlock(ppp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 }
463 ret = -EAGAIN;
464 if (file->f_flags & O_NONBLOCK)
465 break;
466 ret = -ERESTARTSYS;
467 if (signal_pending(current))
468 break;
469 schedule();
470 }
471 set_current_state(TASK_RUNNING);
472 remove_wait_queue(&pf->rwait, &wait);
473
Joe Perchescd228d52007-11-12 18:07:31 -0800474 if (!skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 goto out;
476
477 ret = -EOVERFLOW;
478 if (skb->len > count)
479 goto outf;
480 ret = -EFAULT;
Simon Arlott19937d02010-05-03 10:20:27 +0000481 iov.iov_base = buf;
482 iov.iov_len = count;
Al Viroba568402014-11-24 17:48:04 -0500483 iov_iter_init(&to, READ, &iov, 1, count);
484 if (skb_copy_datagram_iter(skb, 0, &to, skb->len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 goto outf;
486 ret = skb->len;
487
488 outf:
489 kfree_skb(skb);
490 out:
491 return ret;
492}
493
494static ssize_t ppp_write(struct file *file, const char __user *buf,
495 size_t count, loff_t *ppos)
496{
497 struct ppp_file *pf = file->private_data;
498 struct sk_buff *skb;
499 ssize_t ret;
500
Joe Perchescd228d52007-11-12 18:07:31 -0800501 if (!pf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 return -ENXIO;
503 ret = -ENOMEM;
504 skb = alloc_skb(count + pf->hdrlen, GFP_KERNEL);
Joe Perchescd228d52007-11-12 18:07:31 -0800505 if (!skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 goto out;
507 skb_reserve(skb, pf->hdrlen);
508 ret = -EFAULT;
509 if (copy_from_user(skb_put(skb, count), buf, count)) {
510 kfree_skb(skb);
511 goto out;
512 }
513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 switch (pf->kind) {
515 case INTERFACE:
Guillaume Naultfe3627f2018-03-20 16:49:26 +0100516 ppp_xmit_process(PF_TO_PPP(pf), skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 break;
518 case CHANNEL:
Guillaume Naultfe3627f2018-03-20 16:49:26 +0100519 skb_queue_tail(&pf->xq, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 ppp_channel_push(PF_TO_CHANNEL(pf));
521 break;
522 }
523
524 ret = count;
525
526 out:
527 return ret;
528}
529
530/* No kernel lock - fine */
531static unsigned int ppp_poll(struct file *file, poll_table *wait)
532{
533 struct ppp_file *pf = file->private_data;
534 unsigned int mask;
535
Joe Perchescd228d52007-11-12 18:07:31 -0800536 if (!pf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 return 0;
538 poll_wait(file, &pf->rwait, wait);
539 mask = POLLOUT | POLLWRNORM;
Joe Perchescd228d52007-11-12 18:07:31 -0800540 if (skb_peek(&pf->rq))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 mask |= POLLIN | POLLRDNORM;
542 if (pf->dead)
543 mask |= POLLHUP;
544 else if (pf->kind == INTERFACE) {
545 /* see comment in ppp_read */
546 struct ppp *ppp = PF_TO_PPP(pf);
Guillaume Naultedffc212016-02-26 18:45:34 +0100547
548 ppp_recv_lock(ppp);
Joe Perches8e95a202009-12-03 07:58:21 +0000549 if (ppp->n_channels == 0 &&
550 (ppp->flags & SC_LOOP_TRAFFIC) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 mask |= POLLIN | POLLRDNORM;
Guillaume Naultedffc212016-02-26 18:45:34 +0100552 ppp_recv_unlock(ppp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 }
554
555 return mask;
556}
557
558#ifdef CONFIG_PPP_FILTER
559static int get_filter(void __user *arg, struct sock_filter **p)
560{
561 struct sock_fprog uprog;
562 struct sock_filter *code = NULL;
Christoph Schulz3916a312014-07-14 08:01:10 +0200563 int len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 if (copy_from_user(&uprog, arg, sizeof(uprog)))
566 return -EFAULT;
567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 if (!uprog.len) {
569 *p = NULL;
570 return 0;
571 }
572
573 len = uprog.len * sizeof(struct sock_filter);
Julia Lawallb23d00e2010-05-21 22:18:59 +0000574 code = memdup_user(uprog.filter, len);
575 if (IS_ERR(code))
576 return PTR_ERR(code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 *p = code;
579 return uprog.len;
580}
581#endif /* CONFIG_PPP_FILTER */
582
Alan Coxf3ff8a42008-05-25 23:40:58 -0700583static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
Guillaume Naulte8e56ff2016-03-14 21:17:16 +0100585 struct ppp_file *pf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 struct ppp *ppp;
587 int err = -EFAULT, val, val2, i;
588 struct ppp_idle idle;
589 struct npioctl npi;
590 int unit, cflags;
591 struct slcompress *vj;
592 void __user *argp = (void __user *)arg;
593 int __user *p = argp;
594
Guillaume Naulte8e56ff2016-03-14 21:17:16 +0100595 mutex_lock(&ppp_mutex);
596
597 pf = file->private_data;
598 if (!pf) {
599 err = ppp_unattached_ioctl(current->nsproxy->net_ns,
600 pf, file, cmd, arg);
601 goto out;
602 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
604 if (cmd == PPPIOCDETACH) {
605 /*
606 * We have to be careful here... if the file descriptor
607 * has been dup'd, we could have another process in the
608 * middle of a poll using the same file *, so we had
609 * better not free the interface data structures -
610 * instead we fail the ioctl. Even in this case, we
611 * shut down the interface if we are the owner of it.
612 * Actually, we should get rid of PPPIOCDETACH, userland
613 * (i.e. pppd) could achieve the same effect by closing
614 * this fd and reopening /dev/ppp.
615 */
616 err = -EINVAL;
617 if (pf->kind == INTERFACE) {
618 ppp = PF_TO_PPP(pf);
Guillaume Nault8cb775b2015-08-14 10:42:56 +0200619 rtnl_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 if (file == ppp->owner)
Guillaume Nault8cb775b2015-08-14 10:42:56 +0200621 unregister_netdevice(ppp->dev);
622 rtnl_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 }
Al Viro24dff962014-10-08 23:44:00 -0400624 if (atomic_long_read(&file->f_count) < 2) {
Alan Coxf3ff8a42008-05-25 23:40:58 -0700625 ppp_release(NULL, file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 err = 0;
627 } else
David S. Millerb48f8c22011-01-20 22:44:36 -0800628 pr_warn("PPPIOCDETACH file->f_count=%ld\n",
629 atomic_long_read(&file->f_count));
Guillaume Naulte8e56ff2016-03-14 21:17:16 +0100630 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 }
632
633 if (pf->kind == CHANNEL) {
Alan Coxf3ff8a42008-05-25 23:40:58 -0700634 struct channel *pch;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 struct ppp_channel *chan;
636
Alan Coxf3ff8a42008-05-25 23:40:58 -0700637 pch = PF_TO_CHANNEL(pf);
638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 switch (cmd) {
640 case PPPIOCCONNECT:
641 if (get_user(unit, p))
642 break;
643 err = ppp_connect_channel(pch, unit);
644 break;
645
646 case PPPIOCDISCONN:
647 err = ppp_disconnect_channel(pch);
648 break;
649
650 default:
651 down_read(&pch->chan_sem);
652 chan = pch->chan;
653 err = -ENOTTY;
654 if (chan && chan->ops->ioctl)
655 err = chan->ops->ioctl(chan, cmd, arg);
656 up_read(&pch->chan_sem);
657 }
Guillaume Naulte8e56ff2016-03-14 21:17:16 +0100658 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 }
660
661 if (pf->kind != INTERFACE) {
662 /* can't happen */
David S. Millerb48f8c22011-01-20 22:44:36 -0800663 pr_err("PPP: not interface or channel??\n");
Guillaume Naulte8e56ff2016-03-14 21:17:16 +0100664 err = -EINVAL;
665 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 }
667
668 ppp = PF_TO_PPP(pf);
669 switch (cmd) {
670 case PPPIOCSMRU:
671 if (get_user(val, p))
672 break;
673 ppp->mru = val;
674 err = 0;
675 break;
676
677 case PPPIOCSFLAGS:
678 if (get_user(val, p))
679 break;
680 ppp_lock(ppp);
681 cflags = ppp->flags & ~val;
Christoph Schulza9f559c2014-07-16 23:41:26 +0200682#ifdef CONFIG_PPP_MULTILINK
Christoph Schulzd762d032014-07-15 11:51:03 +0200683 if (!(ppp->flags & SC_MULTILINK) && (val & SC_MULTILINK))
684 ppp->nextseq = 0;
Christoph Schulza9f559c2014-07-16 23:41:26 +0200685#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 ppp->flags = val & SC_FLAG_BITS;
687 ppp_unlock(ppp);
688 if (cflags & SC_CCP_OPEN)
689 ppp_ccp_closed(ppp);
690 err = 0;
691 break;
692
693 case PPPIOCGFLAGS:
694 val = ppp->flags | ppp->xstate | ppp->rstate;
695 if (put_user(val, p))
696 break;
697 err = 0;
698 break;
699
700 case PPPIOCSCOMPRESS:
701 err = ppp_set_compress(ppp, arg);
702 break;
703
704 case PPPIOCGUNIT:
705 if (put_user(ppp->file.index, p))
706 break;
707 err = 0;
708 break;
709
710 case PPPIOCSDEBUG:
711 if (get_user(val, p))
712 break;
713 ppp->debug = val;
714 err = 0;
715 break;
716
717 case PPPIOCGDEBUG:
718 if (put_user(ppp->debug, p))
719 break;
720 err = 0;
721 break;
722
723 case PPPIOCGIDLE:
724 idle.xmit_idle = (jiffies - ppp->last_xmit) / HZ;
725 idle.recv_idle = (jiffies - ppp->last_recv) / HZ;
726 if (copy_to_user(argp, &idle, sizeof(idle)))
727 break;
728 err = 0;
729 break;
730
731 case PPPIOCSMAXCID:
732 if (get_user(val, p))
733 break;
734 val2 = 15;
735 if ((val >> 16) != 0) {
736 val2 = val >> 16;
737 val &= 0xffff;
738 }
739 vj = slhc_init(val2+1, val+1);
Ben Hutchings4ab42d72015-11-01 16:22:53 +0000740 if (IS_ERR(vj)) {
741 err = PTR_ERR(vj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 break;
743 }
744 ppp_lock(ppp);
Joe Perchescd228d52007-11-12 18:07:31 -0800745 if (ppp->vj)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 slhc_free(ppp->vj);
747 ppp->vj = vj;
748 ppp_unlock(ppp);
749 err = 0;
750 break;
751
752 case PPPIOCGNPMODE:
753 case PPPIOCSNPMODE:
754 if (copy_from_user(&npi, argp, sizeof(npi)))
755 break;
756 err = proto_to_npindex(npi.protocol);
757 if (err < 0)
758 break;
759 i = err;
760 if (cmd == PPPIOCGNPMODE) {
761 err = -EFAULT;
762 npi.mode = ppp->npmode[i];
763 if (copy_to_user(argp, &npi, sizeof(npi)))
764 break;
765 } else {
766 ppp->npmode[i] = npi.mode;
767 /* we may be able to transmit more packets now (??) */
768 netif_wake_queue(ppp->dev);
769 }
770 err = 0;
771 break;
772
773#ifdef CONFIG_PPP_FILTER
774 case PPPIOCSPASS:
775 {
776 struct sock_filter *code;
Daniel Borkmann568f1942014-03-28 18:58:23 +0100777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 err = get_filter(argp, &code);
779 if (err >= 0) {
Takashi Iwai5748eb82014-11-10 11:50:21 +0100780 struct bpf_prog *pass_filter = NULL;
Daniel Borkmannb1fcd352014-05-23 18:43:58 +0200781 struct sock_fprog_kern fprog = {
Daniel Borkmann568f1942014-03-28 18:58:23 +0100782 .len = err,
783 .filter = code,
784 };
785
Takashi Iwai5748eb82014-11-10 11:50:21 +0100786 err = 0;
787 if (fprog.filter)
788 err = bpf_prog_create(&pass_filter, &fprog);
789 if (!err) {
790 ppp_lock(ppp);
791 if (ppp->pass_filter)
792 bpf_prog_destroy(ppp->pass_filter);
793 ppp->pass_filter = pass_filter;
794 ppp_unlock(ppp);
Christoph Schulzcc25eaa2014-07-16 22:10:29 +0200795 }
Daniel Borkmann568f1942014-03-28 18:58:23 +0100796 kfree(code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 }
798 break;
799 }
800 case PPPIOCSACTIVE:
801 {
802 struct sock_filter *code;
Daniel Borkmann568f1942014-03-28 18:58:23 +0100803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 err = get_filter(argp, &code);
805 if (err >= 0) {
Takashi Iwai5748eb82014-11-10 11:50:21 +0100806 struct bpf_prog *active_filter = NULL;
Daniel Borkmannb1fcd352014-05-23 18:43:58 +0200807 struct sock_fprog_kern fprog = {
Daniel Borkmann568f1942014-03-28 18:58:23 +0100808 .len = err,
809 .filter = code,
810 };
811
Takashi Iwai5748eb82014-11-10 11:50:21 +0100812 err = 0;
813 if (fprog.filter)
814 err = bpf_prog_create(&active_filter, &fprog);
815 if (!err) {
816 ppp_lock(ppp);
817 if (ppp->active_filter)
818 bpf_prog_destroy(ppp->active_filter);
819 ppp->active_filter = active_filter;
820 ppp_unlock(ppp);
Christoph Schulzcc25eaa2014-07-16 22:10:29 +0200821 }
Daniel Borkmann568f1942014-03-28 18:58:23 +0100822 kfree(code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 }
824 break;
825 }
826#endif /* CONFIG_PPP_FILTER */
827
828#ifdef CONFIG_PPP_MULTILINK
829 case PPPIOCSMRRU:
830 if (get_user(val, p))
831 break;
832 ppp_recv_lock(ppp);
833 ppp->mrru = val;
834 ppp_recv_unlock(ppp);
835 err = 0;
836 break;
837#endif /* CONFIG_PPP_MULTILINK */
838
839 default:
840 err = -ENOTTY;
841 }
Guillaume Naulte8e56ff2016-03-14 21:17:16 +0100842
843out:
Arnd Bergmann15fd0cd2010-07-11 11:18:57 +0000844 mutex_unlock(&ppp_mutex);
Guillaume Naulte8e56ff2016-03-14 21:17:16 +0100845
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 return err;
847}
848
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800849static int ppp_unattached_ioctl(struct net *net, struct ppp_file *pf,
850 struct file *file, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
852 int unit, err = -EFAULT;
853 struct ppp *ppp;
854 struct channel *chan;
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800855 struct ppp_net *pn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 int __user *p = (int __user *)arg;
857
858 switch (cmd) {
859 case PPPIOCNEWUNIT:
860 /* Create a new ppp unit */
861 if (get_user(unit, p))
862 break;
Guillaume Nault7d9f0b42016-04-28 17:55:28 +0200863 err = ppp_create_interface(net, file, &unit);
864 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 break;
Guillaume Nault7d9f0b42016-04-28 17:55:28 +0200866
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 err = -EFAULT;
Guillaume Nault7d9f0b42016-04-28 17:55:28 +0200868 if (put_user(unit, p))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 break;
870 err = 0;
871 break;
872
873 case PPPIOCATTACH:
874 /* Attach to an existing ppp unit */
875 if (get_user(unit, p))
876 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 err = -ENXIO;
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800878 pn = ppp_pernet(net);
879 mutex_lock(&pn->all_ppp_mutex);
880 ppp = ppp_find_unit(pn, unit);
Joe Perchescd228d52007-11-12 18:07:31 -0800881 if (ppp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 atomic_inc(&ppp->file.refcnt);
883 file->private_data = &ppp->file;
884 err = 0;
885 }
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800886 mutex_unlock(&pn->all_ppp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 break;
888
889 case PPPIOCATTCHAN:
890 if (get_user(unit, p))
891 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 err = -ENXIO;
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800893 pn = ppp_pernet(net);
894 spin_lock_bh(&pn->all_channels_lock);
895 chan = ppp_find_channel(pn, unit);
Joe Perchescd228d52007-11-12 18:07:31 -0800896 if (chan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 atomic_inc(&chan->file.refcnt);
898 file->private_data = &chan->file;
899 err = 0;
900 }
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800901 spin_unlock_bh(&pn->all_channels_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 break;
903
904 default:
905 err = -ENOTTY;
906 }
Guillaume Naulte8e56ff2016-03-14 21:17:16 +0100907
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 return err;
909}
910
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800911static const struct file_operations ppp_device_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 .owner = THIS_MODULE,
913 .read = ppp_read,
914 .write = ppp_write,
915 .poll = ppp_poll,
Alan Coxf3ff8a42008-05-25 23:40:58 -0700916 .unlocked_ioctl = ppp_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 .open = ppp_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200918 .release = ppp_release,
919 .llseek = noop_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920};
921
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800922static __net_init int ppp_init_net(struct net *net)
923{
Eric W. Biederman741a6fa2009-11-29 15:46:09 +0000924 struct ppp_net *pn = net_generic(net, ppp_net_id);
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800925
926 idr_init(&pn->units_idr);
927 mutex_init(&pn->all_ppp_mutex);
928
929 INIT_LIST_HEAD(&pn->all_channels);
930 INIT_LIST_HEAD(&pn->new_channels);
931
932 spin_lock_init(&pn->all_channels_lock);
933
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800934 return 0;
935}
936
937static __net_exit void ppp_exit_net(struct net *net)
938{
Eric W. Biederman741a6fa2009-11-29 15:46:09 +0000939 struct ppp_net *pn = net_generic(net, ppp_net_id);
Guillaume Nault79c441a2015-08-24 11:35:30 +0200940 struct net_device *dev;
941 struct net_device *aux;
Guillaume Nault8cb775b2015-08-14 10:42:56 +0200942 struct ppp *ppp;
943 LIST_HEAD(list);
944 int id;
945
946 rtnl_lock();
Guillaume Nault79c441a2015-08-24 11:35:30 +0200947 for_each_netdev_safe(net, dev, aux) {
948 if (dev->netdev_ops == &ppp_netdev_ops)
949 unregister_netdevice_queue(dev, &list);
950 }
951
Guillaume Nault8cb775b2015-08-14 10:42:56 +0200952 idr_for_each_entry(&pn->units_idr, ppp, id)
Guillaume Nault79c441a2015-08-24 11:35:30 +0200953 /* Skip devices already unregistered by previous loop */
954 if (!net_eq(dev_net(ppp->dev), net))
955 unregister_netdevice_queue(ppp->dev, &list);
Guillaume Nault8cb775b2015-08-14 10:42:56 +0200956
957 unregister_netdevice_many(&list);
958 rtnl_unlock();
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800959
Gao Fengcf16dac2017-10-31 18:25:37 +0800960 mutex_destroy(&pn->all_ppp_mutex);
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800961 idr_destroy(&pn->units_idr);
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800962}
963
Alexey Dobriyan00129852009-02-09 18:05:16 -0800964static struct pernet_operations ppp_net_ops = {
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800965 .init = ppp_init_net,
966 .exit = ppp_exit_net,
Eric W. Biederman741a6fa2009-11-29 15:46:09 +0000967 .id = &ppp_net_id,
968 .size = sizeof(struct ppp_net),
Cyrill Gorcunov273ec512009-01-21 15:55:35 -0800969};
970
Guillaume Nault96d934c2016-04-28 17:55:30 +0200971static int ppp_unit_register(struct ppp *ppp, int unit, bool ifname_is_set)
Guillaume Nault7d9f0b42016-04-28 17:55:28 +0200972{
973 struct ppp_net *pn = ppp_pernet(ppp->ppp_net);
974 int ret;
975
976 mutex_lock(&pn->all_ppp_mutex);
977
978 if (unit < 0) {
979 ret = unit_get(&pn->units_idr, ppp);
980 if (ret < 0)
981 goto err;
982 } else {
983 /* Caller asked for a specific unit number. Fail with -EEXIST
984 * if unavailable. For backward compatibility, return -EEXIST
985 * too if idr allocation fails; this makes pppd retry without
986 * requesting a specific unit number.
987 */
988 if (unit_find(&pn->units_idr, unit)) {
989 ret = -EEXIST;
990 goto err;
991 }
992 ret = unit_set(&pn->units_idr, ppp, unit);
993 if (ret < 0) {
994 /* Rewrite error for backward compatibility */
995 ret = -EEXIST;
996 goto err;
997 }
998 }
999 ppp->file.index = ret;
1000
Guillaume Nault96d934c2016-04-28 17:55:30 +02001001 if (!ifname_is_set)
1002 snprintf(ppp->dev->name, IFNAMSIZ, "ppp%i", ppp->file.index);
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02001003
Guillaume Nault00f9e472018-01-10 16:24:45 +01001004 mutex_unlock(&pn->all_ppp_mutex);
1005
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02001006 ret = register_netdevice(ppp->dev);
1007 if (ret < 0)
1008 goto err_unit;
1009
1010 atomic_inc(&ppp_unit_count);
1011
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02001012 return 0;
1013
1014err_unit:
Guillaume Nault00f9e472018-01-10 16:24:45 +01001015 mutex_lock(&pn->all_ppp_mutex);
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02001016 unit_put(&pn->units_idr, ppp->file.index);
1017err:
1018 mutex_unlock(&pn->all_ppp_mutex);
1019
1020 return ret;
1021}
1022
1023static int ppp_dev_configure(struct net *src_net, struct net_device *dev,
1024 const struct ppp_config *conf)
1025{
1026 struct ppp *ppp = netdev_priv(dev);
1027 int indx;
1028 int err;
Gao Feng3b25bfc2017-07-17 18:34:42 +08001029 int cpu;
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02001030
1031 ppp->dev = dev;
1032 ppp->ppp_net = src_net;
1033 ppp->mru = PPP_MRU;
1034 ppp->owner = conf->file;
1035
1036 init_ppp_file(&ppp->file, INTERFACE);
1037 ppp->file.hdrlen = PPP_HDRLEN - 2; /* don't count proto bytes */
1038
1039 for (indx = 0; indx < NUM_NP; ++indx)
1040 ppp->npmode[indx] = NPMODE_PASS;
1041 INIT_LIST_HEAD(&ppp->channels);
1042 spin_lock_init(&ppp->rlock);
1043 spin_lock_init(&ppp->wlock);
Gao Feng3b25bfc2017-07-17 18:34:42 +08001044
1045 ppp->xmit_recursion = alloc_percpu(int);
1046 if (!ppp->xmit_recursion) {
1047 err = -ENOMEM;
1048 goto err1;
1049 }
1050 for_each_possible_cpu(cpu)
1051 (*per_cpu_ptr(ppp->xmit_recursion, cpu)) = 0;
1052
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02001053#ifdef CONFIG_PPP_MULTILINK
1054 ppp->minseq = -1;
1055 skb_queue_head_init(&ppp->mrq);
1056#endif /* CONFIG_PPP_MULTILINK */
1057#ifdef CONFIG_PPP_FILTER
1058 ppp->pass_filter = NULL;
1059 ppp->active_filter = NULL;
1060#endif /* CONFIG_PPP_FILTER */
1061
Guillaume Nault96d934c2016-04-28 17:55:30 +02001062 err = ppp_unit_register(ppp, conf->unit, conf->ifname_is_set);
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02001063 if (err < 0)
Gao Feng3b25bfc2017-07-17 18:34:42 +08001064 goto err2;
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02001065
1066 conf->file->private_data = &ppp->file;
1067
1068 return 0;
Gao Feng3b25bfc2017-07-17 18:34:42 +08001069err2:
1070 free_percpu(ppp->xmit_recursion);
1071err1:
1072 return err;
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02001073}
1074
Guillaume Nault96d934c2016-04-28 17:55:30 +02001075static const struct nla_policy ppp_nl_policy[IFLA_PPP_MAX + 1] = {
1076 [IFLA_PPP_DEV_FD] = { .type = NLA_S32 },
1077};
1078
1079static int ppp_nl_validate(struct nlattr *tb[], struct nlattr *data[])
1080{
1081 if (!data)
1082 return -EINVAL;
1083
1084 if (!data[IFLA_PPP_DEV_FD])
1085 return -EINVAL;
1086 if (nla_get_s32(data[IFLA_PPP_DEV_FD]) < 0)
1087 return -EBADF;
1088
1089 return 0;
1090}
1091
1092static int ppp_nl_newlink(struct net *src_net, struct net_device *dev,
1093 struct nlattr *tb[], struct nlattr *data[])
1094{
1095 struct ppp_config conf = {
1096 .unit = -1,
1097 .ifname_is_set = true,
1098 };
1099 struct file *file;
1100 int err;
1101
1102 file = fget(nla_get_s32(data[IFLA_PPP_DEV_FD]));
1103 if (!file)
1104 return -EBADF;
1105
1106 /* rtnl_lock is already held here, but ppp_create_interface() locks
1107 * ppp_mutex before holding rtnl_lock. Using mutex_trylock() avoids
1108 * possible deadlock due to lock order inversion, at the cost of
1109 * pushing the problem back to userspace.
1110 */
1111 if (!mutex_trylock(&ppp_mutex)) {
1112 err = -EBUSY;
1113 goto out;
1114 }
1115
1116 if (file->f_op != &ppp_device_fops || file->private_data) {
1117 err = -EBADF;
1118 goto out_unlock;
1119 }
1120
1121 conf.file = file;
Guillaume Naultbb8082f2016-08-09 15:12:26 +02001122
1123 /* Don't use device name generated by the rtnetlink layer when ifname
1124 * isn't specified. Let ppp_dev_configure() set the device name using
1125 * the PPP unit identifer as suffix (i.e. ppp<unit_id>). This allows
1126 * userspace to infer the device name using to the PPPIOCGUNIT ioctl.
1127 */
1128 if (!tb[IFLA_IFNAME])
1129 conf.ifname_is_set = false;
1130
Guillaume Nault96d934c2016-04-28 17:55:30 +02001131 err = ppp_dev_configure(src_net, dev, &conf);
1132
1133out_unlock:
1134 mutex_unlock(&ppp_mutex);
1135out:
1136 fput(file);
1137
1138 return err;
1139}
1140
1141static void ppp_nl_dellink(struct net_device *dev, struct list_head *head)
1142{
1143 unregister_netdevice_queue(dev, head);
1144}
1145
1146static size_t ppp_nl_get_size(const struct net_device *dev)
1147{
1148 return 0;
1149}
1150
1151static int ppp_nl_fill_info(struct sk_buff *skb, const struct net_device *dev)
1152{
1153 return 0;
1154}
1155
1156static struct net *ppp_nl_get_link_net(const struct net_device *dev)
1157{
1158 struct ppp *ppp = netdev_priv(dev);
1159
1160 return ppp->ppp_net;
1161}
1162
1163static struct rtnl_link_ops ppp_link_ops __read_mostly = {
1164 .kind = "ppp",
1165 .maxtype = IFLA_PPP_MAX,
1166 .policy = ppp_nl_policy,
1167 .priv_size = sizeof(struct ppp),
1168 .setup = ppp_setup,
1169 .validate = ppp_nl_validate,
1170 .newlink = ppp_nl_newlink,
1171 .dellink = ppp_nl_dellink,
1172 .get_size = ppp_nl_get_size,
1173 .fill_info = ppp_nl_fill_info,
1174 .get_link_net = ppp_nl_get_link_net,
1175};
1176
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177#define PPP_MAJOR 108
1178
1179/* Called at boot time if ppp is compiled into the kernel,
1180 or at module load time (from init_module) if compiled as a module. */
1181static int __init ppp_init(void)
1182{
1183 int err;
1184
David S. Millerb48f8c22011-01-20 22:44:36 -08001185 pr_info("PPP generic driver version " PPP_VERSION "\n");
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08001186
Eric W. Biederman741a6fa2009-11-29 15:46:09 +00001187 err = register_pernet_device(&ppp_net_ops);
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08001188 if (err) {
David S. Millerb48f8c22011-01-20 22:44:36 -08001189 pr_err("failed to register PPP pernet device (%d)\n", err);
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08001190 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 }
1192
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08001193 err = register_chrdev(PPP_MAJOR, "ppp", &ppp_device_fops);
1194 if (err) {
David S. Millerb48f8c22011-01-20 22:44:36 -08001195 pr_err("failed to register PPP device (%d)\n", err);
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08001196 goto out_net;
1197 }
1198
1199 ppp_class = class_create(THIS_MODULE, "ppp");
1200 if (IS_ERR(ppp_class)) {
1201 err = PTR_ERR(ppp_class);
1202 goto out_chrdev;
1203 }
1204
Guillaume Nault96d934c2016-04-28 17:55:30 +02001205 err = rtnl_link_register(&ppp_link_ops);
1206 if (err) {
1207 pr_err("failed to register rtnetlink PPP handler\n");
1208 goto out_class;
1209 }
1210
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08001211 /* not a big deal if we fail here :-) */
1212 device_create(ppp_class, NULL, MKDEV(PPP_MAJOR, 0), NULL, "ppp");
1213
1214 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
Guillaume Nault96d934c2016-04-28 17:55:30 +02001216out_class:
1217 class_destroy(ppp_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218out_chrdev:
1219 unregister_chrdev(PPP_MAJOR, "ppp");
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08001220out_net:
Eric W. Biederman741a6fa2009-11-29 15:46:09 +00001221 unregister_pernet_device(&ppp_net_ops);
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08001222out:
1223 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224}
1225
1226/*
1227 * Network interface unit routines.
1228 */
Stephen Hemminger424efe92009-08-31 19:50:51 +00001229static netdev_tx_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230ppp_start_xmit(struct sk_buff *skb, struct net_device *dev)
1231{
Wang Chenc8019bf2008-11-20 04:24:17 -08001232 struct ppp *ppp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 int npi, proto;
1234 unsigned char *pp;
1235
1236 npi = ethertype_to_npindex(ntohs(skb->protocol));
1237 if (npi < 0)
1238 goto outf;
1239
1240 /* Drop, accept or reject the packet */
1241 switch (ppp->npmode[npi]) {
1242 case NPMODE_PASS:
1243 break;
1244 case NPMODE_QUEUE:
1245 /* it would be nice to have a way to tell the network
1246 system to queue this one up for later. */
1247 goto outf;
1248 case NPMODE_DROP:
1249 case NPMODE_ERROR:
1250 goto outf;
1251 }
1252
1253 /* Put the 2-byte PPP protocol number on the front,
1254 making sure there is room for the address and control fields. */
Herbert Xu7b797d52007-09-16 16:21:42 -07001255 if (skb_cow_head(skb, PPP_HDRLEN))
1256 goto outf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 pp = skb_push(skb, 2);
1259 proto = npindex_to_proto[npi];
Changli Gao96545ae2011-01-06 13:37:36 +00001260 put_unaligned_be16(proto, pp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Guillaume Nault79c441a2015-08-24 11:35:30 +02001262 skb_scrub_packet(skb, !net_eq(ppp->ppp_net, dev_net(dev)));
Guillaume Naultfe3627f2018-03-20 16:49:26 +01001263 ppp_xmit_process(ppp, skb);
1264
Patrick McHardy6ed10652009-06-23 06:03:08 +00001265 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
1267 outf:
1268 kfree_skb(skb);
Paulius Zaleckas6ceffd42009-02-23 04:59:43 +00001269 ++dev->stats.tx_dropped;
Patrick McHardy6ed10652009-06-23 06:03:08 +00001270 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271}
1272
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273static int
1274ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1275{
Wang Chenc8019bf2008-11-20 04:24:17 -08001276 struct ppp *ppp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 int err = -EFAULT;
1278 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
1279 struct ppp_stats stats;
1280 struct ppp_comp_stats cstats;
1281 char *vers;
1282
1283 switch (cmd) {
1284 case SIOCGPPPSTATS:
1285 ppp_get_stats(ppp, &stats);
1286 if (copy_to_user(addr, &stats, sizeof(stats)))
1287 break;
1288 err = 0;
1289 break;
1290
1291 case SIOCGPPPCSTATS:
1292 memset(&cstats, 0, sizeof(cstats));
Joe Perchescd228d52007-11-12 18:07:31 -08001293 if (ppp->xc_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 ppp->xcomp->comp_stat(ppp->xc_state, &cstats.c);
Joe Perchescd228d52007-11-12 18:07:31 -08001295 if (ppp->rc_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 ppp->rcomp->decomp_stat(ppp->rc_state, &cstats.d);
1297 if (copy_to_user(addr, &cstats, sizeof(cstats)))
1298 break;
1299 err = 0;
1300 break;
1301
1302 case SIOCGPPPVER:
1303 vers = PPP_VERSION;
1304 if (copy_to_user(addr, vers, strlen(vers) + 1))
1305 break;
1306 err = 0;
1307 break;
1308
1309 default:
1310 err = -EINVAL;
1311 }
1312
1313 return err;
1314}
1315
stephen hemmingerb77bc202012-10-29 08:34:02 +00001316static struct rtnl_link_stats64*
Kevin Groenevelde51f6ff2012-07-27 17:38:53 +00001317ppp_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats64)
1318{
1319 struct ppp *ppp = netdev_priv(dev);
1320
1321 ppp_recv_lock(ppp);
1322 stats64->rx_packets = ppp->stats64.rx_packets;
1323 stats64->rx_bytes = ppp->stats64.rx_bytes;
1324 ppp_recv_unlock(ppp);
1325
1326 ppp_xmit_lock(ppp);
1327 stats64->tx_packets = ppp->stats64.tx_packets;
1328 stats64->tx_bytes = ppp->stats64.tx_bytes;
1329 ppp_xmit_unlock(ppp);
1330
1331 stats64->rx_errors = dev->stats.rx_errors;
1332 stats64->tx_errors = dev->stats.tx_errors;
1333 stats64->rx_dropped = dev->stats.rx_dropped;
1334 stats64->tx_dropped = dev->stats.tx_dropped;
1335 stats64->rx_length_errors = dev->stats.rx_length_errors;
1336
1337 return stats64;
1338}
1339
Eric Dumazet303c07d2013-02-19 10:42:03 -08001340static int ppp_dev_init(struct net_device *dev)
1341{
Guillaume Naultac4cfc72017-10-06 17:05:49 +02001342 struct ppp *ppp;
1343
Eric Dumazetd3fff6c2016-06-09 07:45:12 -07001344 netdev_lockdep_set_classes(dev);
Guillaume Naultac4cfc72017-10-06 17:05:49 +02001345
1346 ppp = netdev_priv(dev);
1347 /* Let the netdevice take a reference on the ppp file. This ensures
1348 * that ppp_destroy_interface() won't run before the device gets
1349 * unregistered.
1350 */
1351 atomic_inc(&ppp->file.refcnt);
1352
Eric Dumazet303c07d2013-02-19 10:42:03 -08001353 return 0;
1354}
1355
Guillaume Nault8cb775b2015-08-14 10:42:56 +02001356static void ppp_dev_uninit(struct net_device *dev)
1357{
1358 struct ppp *ppp = netdev_priv(dev);
1359 struct ppp_net *pn = ppp_pernet(ppp->ppp_net);
1360
1361 ppp_lock(ppp);
1362 ppp->closing = 1;
1363 ppp_unlock(ppp);
1364
1365 mutex_lock(&pn->all_ppp_mutex);
1366 unit_put(&pn->units_idr, ppp->file.index);
1367 mutex_unlock(&pn->all_ppp_mutex);
1368
1369 ppp->owner = NULL;
1370
1371 ppp->file.dead = 1;
1372 wake_up_interruptible(&ppp->file.rwait);
1373}
1374
Guillaume Naultac4cfc72017-10-06 17:05:49 +02001375static void ppp_dev_priv_destructor(struct net_device *dev)
1376{
1377 struct ppp *ppp;
1378
1379 ppp = netdev_priv(dev);
1380 if (atomic_dec_and_test(&ppp->file.refcnt))
1381 ppp_destroy_interface(ppp);
1382}
1383
Stephen Hemminger52256cf2008-11-19 22:22:30 -08001384static const struct net_device_ops ppp_netdev_ops = {
Eric Dumazet303c07d2013-02-19 10:42:03 -08001385 .ndo_init = ppp_dev_init,
Guillaume Nault8cb775b2015-08-14 10:42:56 +02001386 .ndo_uninit = ppp_dev_uninit,
Kevin Groenevelde51f6ff2012-07-27 17:38:53 +00001387 .ndo_start_xmit = ppp_start_xmit,
1388 .ndo_do_ioctl = ppp_net_ioctl,
1389 .ndo_get_stats64 = ppp_get_stats64,
Stephen Hemminger52256cf2008-11-19 22:22:30 -08001390};
1391
Guillaume Nault94dbffe2015-12-11 19:54:49 +01001392static struct device_type ppp_type = {
1393 .name = "ppp",
1394};
1395
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396static void ppp_setup(struct net_device *dev)
1397{
Stephen Hemminger52256cf2008-11-19 22:22:30 -08001398 dev->netdev_ops = &ppp_netdev_ops;
Guillaume Nault94dbffe2015-12-11 19:54:49 +01001399 SET_NETDEV_DEVTYPE(dev, &ppp_type);
1400
Guillaume Nault07712772016-08-27 22:22:51 +02001401 dev->features |= NETIF_F_LLTX;
1402
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 dev->hard_header_len = PPP_HDRLEN;
Paul Mackerrasbf7daeb2012-03-04 12:56:04 +00001404 dev->mtu = PPP_MRU;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 dev->addr_len = 0;
1406 dev->tx_queue_len = 3;
1407 dev->type = ARPHRD_PPP;
1408 dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
Guillaume Naultac4cfc72017-10-06 17:05:49 +02001409 dev->destructor = ppp_dev_priv_destructor;
Eric Dumazet02875872014-10-05 18:38:35 -07001410 netif_keep_dst(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411}
1412
1413/*
1414 * Transmit-side routines.
1415 */
1416
Guillaume Nault55454a52016-08-27 22:22:32 +02001417/* Called to do any work queued up on the transmit side that can now be done */
Guillaume Naultfe3627f2018-03-20 16:49:26 +01001418static void __ppp_xmit_process(struct ppp *ppp, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 ppp_xmit_lock(ppp);
James Chapman739840d2008-12-17 12:02:16 +00001421 if (!ppp->closing) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 ppp_push(ppp);
Guillaume Naultfe3627f2018-03-20 16:49:26 +01001423
1424 if (skb)
1425 skb_queue_tail(&ppp->file.xq, skb);
Joe Perches8e95a202009-12-03 07:58:21 +00001426 while (!ppp->xmit_pending &&
1427 (skb = skb_dequeue(&ppp->file.xq)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 ppp_send_frame(ppp, skb);
1429 /* If there's no work left to do, tell the core net
1430 code that we can accept some more. */
David Woodhouse9a5d2bd2012-04-08 10:01:44 +00001431 if (!ppp->xmit_pending && !skb_peek(&ppp->file.xq))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 netif_wake_queue(ppp->dev);
David Woodhouse9a5d2bd2012-04-08 10:01:44 +00001433 else
1434 netif_stop_queue(ppp->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 }
1436 ppp_xmit_unlock(ppp);
1437}
1438
Guillaume Naultfe3627f2018-03-20 16:49:26 +01001439static void ppp_xmit_process(struct ppp *ppp, struct sk_buff *skb)
Guillaume Nault55454a52016-08-27 22:22:32 +02001440{
1441 local_bh_disable();
1442
Gao Feng3b25bfc2017-07-17 18:34:42 +08001443 if (unlikely(*this_cpu_ptr(ppp->xmit_recursion)))
Guillaume Nault55454a52016-08-27 22:22:32 +02001444 goto err;
1445
Gao Feng3b25bfc2017-07-17 18:34:42 +08001446 (*this_cpu_ptr(ppp->xmit_recursion))++;
Guillaume Naultfe3627f2018-03-20 16:49:26 +01001447 __ppp_xmit_process(ppp, skb);
Gao Feng3b25bfc2017-07-17 18:34:42 +08001448 (*this_cpu_ptr(ppp->xmit_recursion))--;
Guillaume Nault55454a52016-08-27 22:22:32 +02001449
1450 local_bh_enable();
1451
1452 return;
1453
1454err:
1455 local_bh_enable();
1456
Guillaume Naultfe3627f2018-03-20 16:49:26 +01001457 kfree_skb(skb);
1458
Guillaume Nault55454a52016-08-27 22:22:32 +02001459 if (net_ratelimit())
1460 netdev_err(ppp->dev, "recursion detected\n");
1461}
1462
Matt Domschb3f9b922005-11-08 09:40:47 -08001463static inline struct sk_buff *
1464pad_compress_skb(struct ppp *ppp, struct sk_buff *skb)
1465{
1466 struct sk_buff *new_skb;
1467 int len;
1468 int new_skb_size = ppp->dev->mtu +
1469 ppp->xcomp->comp_extra + ppp->dev->hard_header_len;
1470 int compressor_skb_size = ppp->dev->mtu +
1471 ppp->xcomp->comp_extra + PPP_HDRLEN;
1472 new_skb = alloc_skb(new_skb_size, GFP_ATOMIC);
1473 if (!new_skb) {
1474 if (net_ratelimit())
David S. Millerb48f8c22011-01-20 22:44:36 -08001475 netdev_err(ppp->dev, "PPP: no memory (comp pkt)\n");
Matt Domschb3f9b922005-11-08 09:40:47 -08001476 return NULL;
1477 }
1478 if (ppp->dev->hard_header_len > PPP_HDRLEN)
1479 skb_reserve(new_skb,
1480 ppp->dev->hard_header_len - PPP_HDRLEN);
1481
1482 /* compressor still expects A/C bytes in hdr */
1483 len = ppp->xcomp->compress(ppp->xc_state, skb->data - 2,
1484 new_skb->data, skb->len + 2,
1485 compressor_skb_size);
1486 if (len > 0 && (ppp->flags & SC_CCP_UP)) {
Eric Dumazet968d7012012-05-18 20:23:00 +00001487 consume_skb(skb);
Matt Domschb3f9b922005-11-08 09:40:47 -08001488 skb = new_skb;
1489 skb_put(skb, len);
1490 skb_pull(skb, 2); /* pull off A/C bytes */
1491 } else if (len == 0) {
1492 /* didn't compress, or CCP not up yet */
Eric Dumazet968d7012012-05-18 20:23:00 +00001493 consume_skb(new_skb);
Matt Domschb3f9b922005-11-08 09:40:47 -08001494 new_skb = skb;
1495 } else {
1496 /*
1497 * (len < 0)
1498 * MPPE requires that we do not send unencrypted
1499 * frames. The compressor will return -1 if we
1500 * should drop the frame. We cannot simply test
1501 * the compress_proto because MPPE and MPPC share
1502 * the same number.
1503 */
1504 if (net_ratelimit())
David S. Millerb48f8c22011-01-20 22:44:36 -08001505 netdev_err(ppp->dev, "ppp: compressor dropped pkt\n");
Matt Domschb3f9b922005-11-08 09:40:47 -08001506 kfree_skb(skb);
Eric Dumazet968d7012012-05-18 20:23:00 +00001507 consume_skb(new_skb);
Matt Domschb3f9b922005-11-08 09:40:47 -08001508 new_skb = NULL;
1509 }
1510 return new_skb;
1511}
1512
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513/*
1514 * Compress and send a frame.
1515 * The caller should have locked the xmit path,
1516 * and xmit_pending should be 0.
1517 */
1518static void
1519ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
1520{
1521 int proto = PPP_PROTO(skb);
1522 struct sk_buff *new_skb;
1523 int len;
1524 unsigned char *cp;
1525
1526 if (proto < 0x8000) {
1527#ifdef CONFIG_PPP_FILTER
1528 /* check if we should pass this packet */
1529 /* the filter instructions are constructed assuming
1530 a four-byte PPP header on each packet */
1531 *skb_push(skb, 2) = 1;
Joe Perches8e95a202009-12-03 07:58:21 +00001532 if (ppp->pass_filter &&
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07001533 BPF_PROG_RUN(ppp->pass_filter, skb) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 if (ppp->debug & 1)
David S. Millerb48f8c22011-01-20 22:44:36 -08001535 netdev_printk(KERN_DEBUG, ppp->dev,
1536 "PPP: outbound frame "
1537 "not passed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 kfree_skb(skb);
1539 return;
1540 }
1541 /* if this packet passes the active filter, record the time */
Joe Perches8e95a202009-12-03 07:58:21 +00001542 if (!(ppp->active_filter &&
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07001543 BPF_PROG_RUN(ppp->active_filter, skb) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 ppp->last_xmit = jiffies;
1545 skb_pull(skb, 2);
1546#else
1547 /* for data packets, record the time */
1548 ppp->last_xmit = jiffies;
1549#endif /* CONFIG_PPP_FILTER */
1550 }
1551
Kevin Groenevelde51f6ff2012-07-27 17:38:53 +00001552 ++ppp->stats64.tx_packets;
1553 ppp->stats64.tx_bytes += skb->len - 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
1555 switch (proto) {
1556 case PPP_IP:
Joe Perchescd228d52007-11-12 18:07:31 -08001557 if (!ppp->vj || (ppp->flags & SC_COMP_TCP) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 break;
1559 /* try to do VJ TCP header compression */
1560 new_skb = alloc_skb(skb->len + ppp->dev->hard_header_len - 2,
1561 GFP_ATOMIC);
Joe Perchescd228d52007-11-12 18:07:31 -08001562 if (!new_skb) {
David S. Millerb48f8c22011-01-20 22:44:36 -08001563 netdev_err(ppp->dev, "PPP: no memory (VJ comp pkt)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 goto drop;
1565 }
1566 skb_reserve(new_skb, ppp->dev->hard_header_len - 2);
1567 cp = skb->data + 2;
1568 len = slhc_compress(ppp->vj, cp, skb->len - 2,
1569 new_skb->data + 2, &cp,
1570 !(ppp->flags & SC_NO_TCP_CCID));
1571 if (cp == skb->data + 2) {
1572 /* didn't compress */
Eric Dumazet968d7012012-05-18 20:23:00 +00001573 consume_skb(new_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 } else {
1575 if (cp[0] & SL_TYPE_COMPRESSED_TCP) {
1576 proto = PPP_VJC_COMP;
1577 cp[0] &= ~SL_TYPE_COMPRESSED_TCP;
1578 } else {
1579 proto = PPP_VJC_UNCOMP;
1580 cp[0] = skb->data[2];
1581 }
Eric Dumazet968d7012012-05-18 20:23:00 +00001582 consume_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 skb = new_skb;
1584 cp = skb_put(skb, len + 2);
1585 cp[0] = 0;
1586 cp[1] = proto;
1587 }
1588 break;
1589
1590 case PPP_CCP:
1591 /* peek at outbound CCP frames */
1592 ppp_ccp_peek(ppp, skb, 0);
1593 break;
1594 }
1595
1596 /* try to do packet compression */
Joe Perches8e95a202009-12-03 07:58:21 +00001597 if ((ppp->xstate & SC_COMP_RUN) && ppp->xc_state &&
1598 proto != PPP_LCP && proto != PPP_CCP) {
Matt Domschb3f9b922005-11-08 09:40:47 -08001599 if (!(ppp->flags & SC_CCP_UP) && (ppp->flags & SC_MUST_COMP)) {
1600 if (net_ratelimit())
David S. Millerb48f8c22011-01-20 22:44:36 -08001601 netdev_err(ppp->dev,
1602 "ppp: compression required but "
1603 "down - pkt dropped.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 goto drop;
1605 }
Matt Domschb3f9b922005-11-08 09:40:47 -08001606 skb = pad_compress_skb(ppp, skb);
1607 if (!skb)
1608 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 }
1610
1611 /*
1612 * If we are waiting for traffic (demand dialling),
1613 * queue it up for pppd to receive.
1614 */
1615 if (ppp->flags & SC_LOOP_TRAFFIC) {
1616 if (ppp->file.rq.qlen > PPP_MAX_RQLEN)
1617 goto drop;
1618 skb_queue_tail(&ppp->file.rq, skb);
1619 wake_up_interruptible(&ppp->file.rwait);
1620 return;
1621 }
1622
1623 ppp->xmit_pending = skb;
1624 ppp_push(ppp);
1625 return;
1626
1627 drop:
Wei Yongjun1d2f8c92009-02-25 00:16:08 +00001628 kfree_skb(skb);
Paulius Zaleckas8c0469c2008-04-23 18:54:01 -07001629 ++ppp->dev->stats.tx_errors;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630}
1631
1632/*
1633 * Try to send the frame in xmit_pending.
1634 * The caller should have the xmit path locked.
1635 */
1636static void
1637ppp_push(struct ppp *ppp)
1638{
1639 struct list_head *list;
1640 struct channel *pch;
1641 struct sk_buff *skb = ppp->xmit_pending;
1642
Joe Perchescd228d52007-11-12 18:07:31 -08001643 if (!skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 return;
1645
1646 list = &ppp->channels;
1647 if (list_empty(list)) {
1648 /* nowhere to send the packet, just drop it */
1649 ppp->xmit_pending = NULL;
1650 kfree_skb(skb);
1651 return;
1652 }
1653
1654 if ((ppp->flags & SC_MULTILINK) == 0) {
1655 /* not doing multilink: send it down the first channel */
1656 list = list->next;
1657 pch = list_entry(list, struct channel, clist);
1658
1659 spin_lock_bh(&pch->downl);
1660 if (pch->chan) {
1661 if (pch->chan->ops->start_xmit(pch->chan, skb))
1662 ppp->xmit_pending = NULL;
1663 } else {
1664 /* channel got unregistered */
1665 kfree_skb(skb);
1666 ppp->xmit_pending = NULL;
1667 }
1668 spin_unlock_bh(&pch->downl);
1669 return;
1670 }
1671
1672#ifdef CONFIG_PPP_MULTILINK
1673 /* Multilink: fragment the packet over as many links
1674 as can take the packet at the moment. */
1675 if (!ppp_mp_explode(ppp, skb))
1676 return;
1677#endif /* CONFIG_PPP_MULTILINK */
1678
1679 ppp->xmit_pending = NULL;
1680 kfree_skb(skb);
1681}
1682
1683#ifdef CONFIG_PPP_MULTILINK
stephen hemmingerd39cd5e2010-12-20 17:58:33 +00001684static bool mp_protocol_compress __read_mostly = true;
1685module_param(mp_protocol_compress, bool, S_IRUGO | S_IWUSR);
1686MODULE_PARM_DESC(mp_protocol_compress,
1687 "compress protocol id in multilink fragments");
1688
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689/*
1690 * Divide a packet to be transmitted into fragments and
1691 * send them out the individual links.
1692 */
1693static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb)
1694{
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001695 int len, totlen;
1696 int i, bits, hdrlen, mtu;
1697 int flen;
1698 int navail, nfree, nzero;
1699 int nbigger;
1700 int totspeed;
1701 int totfree;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 unsigned char *p, *q;
1703 struct list_head *list;
1704 struct channel *pch;
1705 struct sk_buff *frag;
1706 struct ppp_channel *chan;
1707
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001708 totspeed = 0; /*total bitrate of the bundle*/
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001709 nfree = 0; /* # channels which have no packet already queued */
1710 navail = 0; /* total # of usable channels (not deregistered) */
1711 nzero = 0; /* number of channels with zero speed associated*/
1712 totfree = 0; /*total # of channels available and
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001713 *having no queued packets before
1714 *starting the fragmentation*/
1715
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 hdrlen = (ppp->flags & SC_MP_XSHORTSEQ)? MPHDRLEN_SSN: MPHDRLEN;
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001717 i = 0;
1718 list_for_each_entry(pch, &ppp->channels, clist) {
Dan Carpenter34297692010-09-10 01:58:10 +00001719 if (pch->chan) {
1720 pch->avail = 1;
1721 navail++;
1722 pch->speed = pch->chan->speed;
1723 } else {
1724 pch->avail = 0;
1725 }
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001726 if (pch->avail) {
David S. Millerb03efcf2005-07-08 14:57:23 -07001727 if (skb_queue_empty(&pch->file.xq) ||
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001728 !pch->had_frag) {
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001729 if (pch->speed == 0)
1730 nzero++;
1731 else
1732 totspeed += pch->speed;
1733
1734 pch->avail = 2;
1735 ++nfree;
1736 ++totfree;
1737 }
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001738 if (!pch->had_frag && i < ppp->nxchan)
1739 ppp->nxchan = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 }
Paul Mackerras516cd152005-05-12 19:47:12 -04001741 ++i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 }
Paul Mackerras516cd152005-05-12 19:47:12 -04001743 /*
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001744 * Don't start sending this packet unless at least half of
1745 * the channels are free. This gives much better TCP
1746 * performance if we have a lot of channels.
Paul Mackerras516cd152005-05-12 19:47:12 -04001747 */
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001748 if (nfree == 0 || nfree < navail / 2)
1749 return 0; /* can't take now, leave it in xmit_pending */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
stephen hemmingerd39cd5e2010-12-20 17:58:33 +00001751 /* Do protocol field compression */
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001752 p = skb->data;
1753 len = skb->len;
stephen hemmingerd39cd5e2010-12-20 17:58:33 +00001754 if (*p == 0 && mp_protocol_compress) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 ++p;
1756 --len;
1757 }
1758
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001759 totlen = len;
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001760 nbigger = len % nfree;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001762 /* skip to the channel after the one we last used
1763 and start at that one */
Domen Puncer81616c52005-09-10 00:27:04 -07001764 list = &ppp->channels;
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001765 for (i = 0; i < ppp->nxchan; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 list = list->next;
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001767 if (list == &ppp->channels) {
1768 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 break;
1770 }
1771 }
1772
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001773 /* create a fragment for each channel */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 bits = B;
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001775 while (len > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 list = list->next;
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001777 if (list == &ppp->channels) {
1778 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 continue;
1780 }
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001781 pch = list_entry(list, struct channel, clist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 ++i;
1783 if (!pch->avail)
1784 continue;
1785
Paul Mackerras516cd152005-05-12 19:47:12 -04001786 /*
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001787 * Skip this channel if it has a fragment pending already and
1788 * we haven't given a fragment to all of the free channels.
Paul Mackerras516cd152005-05-12 19:47:12 -04001789 */
1790 if (pch->avail == 1) {
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001791 if (nfree > 0)
Paul Mackerras516cd152005-05-12 19:47:12 -04001792 continue;
1793 } else {
Paul Mackerras516cd152005-05-12 19:47:12 -04001794 pch->avail = 1;
1795 }
1796
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 /* check the channel's mtu and whether it is still attached. */
1798 spin_lock_bh(&pch->downl);
Paul Mackerras516cd152005-05-12 19:47:12 -04001799 if (pch->chan == NULL) {
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001800 /* can't use this channel, it's being deregistered */
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001801 if (pch->speed == 0)
1802 nzero--;
1803 else
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001804 totspeed -= pch->speed;
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001805
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 spin_unlock_bh(&pch->downl);
1807 pch->avail = 0;
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001808 totlen = len;
1809 totfree--;
1810 nfree--;
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001811 if (--navail == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 break;
1813 continue;
1814 }
1815
1816 /*
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001817 *if the channel speed is not set divide
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001818 *the packet evenly among the free channels;
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001819 *otherwise divide it according to the speed
1820 *of the channel we are going to transmit on
1821 */
David S. Miller886f9fe2009-08-19 13:55:55 -07001822 flen = len;
Ben McKeegana53a8b52009-07-28 07:43:57 +00001823 if (nfree > 0) {
1824 if (pch->speed == 0) {
Ben McKeegan536e00e2010-06-02 23:14:33 +00001825 flen = len/nfree;
Ben McKeegana53a8b52009-07-28 07:43:57 +00001826 if (nbigger > 0) {
1827 flen++;
1828 nbigger--;
1829 }
1830 } else {
1831 flen = (((totfree - nzero)*(totlen + hdrlen*totfree)) /
1832 ((totspeed*totfree)/pch->speed)) - hdrlen;
1833 if (nbigger > 0) {
1834 flen += ((totfree - nzero)*pch->speed)/totspeed;
1835 nbigger -= ((totfree - nzero)*pch->speed)/
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001836 totspeed;
Ben McKeegana53a8b52009-07-28 07:43:57 +00001837 }
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001838 }
Ben McKeegana53a8b52009-07-28 07:43:57 +00001839 nfree--;
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001840 }
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001841
1842 /*
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001843 *check if we are on the last channel or
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001844 *we exceded the length of the data to
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001845 *fragment
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 */
Ben McKeegana53a8b52009-07-28 07:43:57 +00001847 if ((nfree <= 0) || (flen > len))
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001848 flen = len;
1849 /*
1850 *it is not worth to tx on slow channels:
1851 *in that case from the resulting flen according to the
1852 *above formula will be equal or less than zero.
1853 *Skip the channel in this case
1854 */
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001855 if (flen <= 0) {
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001856 pch->avail = 2;
1857 spin_unlock_bh(&pch->downl);
1858 continue;
1859 }
1860
Henry Wong22e83a22011-09-18 13:41:49 +00001861 /*
1862 * hdrlen includes the 2-byte PPP protocol field, but the
1863 * MTU counts only the payload excluding the protocol field.
1864 * (RFC1661 Section 2)
1865 */
1866 mtu = pch->chan->mtu - (hdrlen - 2);
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001867 if (mtu < 4)
1868 mtu = 4;
Paul Mackerras516cd152005-05-12 19:47:12 -04001869 if (flen > mtu)
1870 flen = mtu;
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001871 if (flen == len)
1872 bits |= E;
1873 frag = alloc_skb(flen + hdrlen + (flen == 0), GFP_ATOMIC);
Joe Perchescd228d52007-11-12 18:07:31 -08001874 if (!frag)
Paul Mackerras516cd152005-05-12 19:47:12 -04001875 goto noskb;
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001876 q = skb_put(frag, flen + hdrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001878 /* make the MP header */
Changli Gao96545ae2011-01-06 13:37:36 +00001879 put_unaligned_be16(PPP_MP, q);
Paul Mackerras516cd152005-05-12 19:47:12 -04001880 if (ppp->flags & SC_MP_XSHORTSEQ) {
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001881 q[2] = bits + ((ppp->nxseq >> 8) & 0xf);
Paul Mackerras516cd152005-05-12 19:47:12 -04001882 q[3] = ppp->nxseq;
1883 } else {
1884 q[2] = bits;
1885 q[3] = ppp->nxseq >> 16;
1886 q[4] = ppp->nxseq >> 8;
1887 q[5] = ppp->nxseq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 }
Paul Mackerras516cd152005-05-12 19:47:12 -04001889
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001890 memcpy(q + hdrlen, p, flen);
Paul Mackerras516cd152005-05-12 19:47:12 -04001891
1892 /* try to send it down the channel */
1893 chan = pch->chan;
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001894 if (!skb_queue_empty(&pch->file.xq) ||
Gabriele Paoloni9c705262009-03-13 16:09:12 -07001895 !chan->ops->start_xmit(chan, frag))
Paul Mackerras516cd152005-05-12 19:47:12 -04001896 skb_queue_tail(&pch->file.xq, frag);
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001897 pch->had_frag = 1;
Paul Mackerras516cd152005-05-12 19:47:12 -04001898 p += flen;
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001899 len -= flen;
Paul Mackerras516cd152005-05-12 19:47:12 -04001900 ++ppp->nxseq;
1901 bits = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 spin_unlock_bh(&pch->downl);
Paul Mackerras516cd152005-05-12 19:47:12 -04001903 }
Lennart Sorensenfa44a732010-01-18 12:59:55 +00001904 ppp->nxchan = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
1906 return 1;
1907
1908 noskb:
1909 spin_unlock_bh(&pch->downl);
1910 if (ppp->debug & 1)
David S. Millerb48f8c22011-01-20 22:44:36 -08001911 netdev_err(ppp->dev, "PPP: no memory (fragment)\n");
Paulius Zaleckas8c0469c2008-04-23 18:54:01 -07001912 ++ppp->dev->stats.tx_errors;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 ++ppp->nxseq;
1914 return 1; /* abandon the frame */
1915}
1916#endif /* CONFIG_PPP_MULTILINK */
1917
Guillaume Nault55454a52016-08-27 22:22:32 +02001918/* Try to send data out on a channel */
1919static void __ppp_channel_push(struct channel *pch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920{
1921 struct sk_buff *skb;
1922 struct ppp *ppp;
1923
1924 spin_lock_bh(&pch->downl);
Joe Perchescd228d52007-11-12 18:07:31 -08001925 if (pch->chan) {
David S. Millerb03efcf2005-07-08 14:57:23 -07001926 while (!skb_queue_empty(&pch->file.xq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 skb = skb_dequeue(&pch->file.xq);
1928 if (!pch->chan->ops->start_xmit(pch->chan, skb)) {
1929 /* put the packet back and try again later */
1930 skb_queue_head(&pch->file.xq, skb);
1931 break;
1932 }
1933 }
1934 } else {
1935 /* channel got deregistered */
1936 skb_queue_purge(&pch->file.xq);
1937 }
1938 spin_unlock_bh(&pch->downl);
1939 /* see if there is anything from the attached unit to be sent */
David S. Millerb03efcf2005-07-08 14:57:23 -07001940 if (skb_queue_empty(&pch->file.xq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 ppp = pch->ppp;
Joe Perchescd228d52007-11-12 18:07:31 -08001942 if (ppp)
Guillaume Naultfe3627f2018-03-20 16:49:26 +01001943 __ppp_xmit_process(ppp, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 }
1945}
1946
Guillaume Nault55454a52016-08-27 22:22:32 +02001947static void ppp_channel_push(struct channel *pch)
1948{
Guillaume Nault6ec6ec32017-08-08 11:43:24 +02001949 read_lock_bh(&pch->upl);
1950 if (pch->ppp) {
1951 (*this_cpu_ptr(pch->ppp->xmit_recursion))++;
1952 __ppp_channel_push(pch);
1953 (*this_cpu_ptr(pch->ppp->xmit_recursion))--;
1954 } else {
1955 __ppp_channel_push(pch);
1956 }
1957 read_unlock_bh(&pch->upl);
Guillaume Nault55454a52016-08-27 22:22:32 +02001958}
1959
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960/*
1961 * Receive-side routines.
1962 */
1963
David S. Millera00eac02010-10-05 01:36:52 -07001964struct ppp_mp_skb_parm {
1965 u32 sequence;
1966 u8 BEbits;
1967};
1968#define PPP_MP_CB(skb) ((struct ppp_mp_skb_parm *)((skb)->cb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969
1970static inline void
1971ppp_do_recv(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1972{
1973 ppp_recv_lock(ppp);
James Chapman739840d2008-12-17 12:02:16 +00001974 if (!ppp->closing)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 ppp_receive_frame(ppp, skb, pch);
1976 else
1977 kfree_skb(skb);
1978 ppp_recv_unlock(ppp);
1979}
1980
Sam Protsenkof74ba31b2018-12-20 20:29:20 +02001981/**
1982 * __ppp_decompress_proto - Decompress protocol field, slim version.
1983 * @skb: Socket buffer where protocol field should be decompressed. It must have
1984 * at least 1 byte of head room and 1 byte of linear data. First byte of
1985 * data must be a protocol field byte.
1986 *
1987 * Decompress protocol field in PPP header if it's compressed, e.g. when
1988 * Protocol-Field-Compression (PFC) was negotiated. No checks w.r.t. skb data
1989 * length are done in this function.
1990 */
1991static void __ppp_decompress_proto(struct sk_buff *skb)
1992{
1993 if (skb->data[0] & 0x01)
1994 *(u8 *)skb_push(skb, 1) = 0x00;
1995}
1996
1997/**
1998 * ppp_decompress_proto - Check skb data room and decompress protocol field.
1999 * @skb: Socket buffer where protocol field should be decompressed. First byte
2000 * of data must be a protocol field byte.
2001 *
2002 * Decompress protocol field in PPP header if it's compressed, e.g. when
2003 * Protocol-Field-Compression (PFC) was negotiated. This function also makes
2004 * sure that skb data room is sufficient for Protocol field, before and after
2005 * decompression.
2006 *
2007 * Return: true - decompressed successfully, false - not enough room in skb.
2008 */
2009static bool ppp_decompress_proto(struct sk_buff *skb)
2010{
2011 /* At least one byte should be present (if protocol is compressed) */
2012 if (!pskb_may_pull(skb, 1))
2013 return false;
2014
2015 __ppp_decompress_proto(skb);
2016
2017 /* Protocol field should occupy 2 bytes when not compressed */
2018 return pskb_may_pull(skb, 2);
2019}
2020
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021void
2022ppp_input(struct ppp_channel *chan, struct sk_buff *skb)
2023{
2024 struct channel *pch = chan->ppp;
2025 int proto;
2026
Simon Arlottea8420e2010-05-03 10:19:33 +00002027 if (!pch) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 kfree_skb(skb);
2029 return;
2030 }
Paul Mackerras516cd152005-05-12 19:47:12 -04002031
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 read_lock_bh(&pch->upl);
Sam Protsenkof74ba31b2018-12-20 20:29:20 +02002033 if (!ppp_decompress_proto(skb)) {
Simon Arlottea8420e2010-05-03 10:19:33 +00002034 kfree_skb(skb);
2035 if (pch->ppp) {
2036 ++pch->ppp->dev->stats.rx_length_errors;
2037 ppp_receive_error(pch->ppp);
2038 }
2039 goto done;
2040 }
2041
2042 proto = PPP_PROTO(skb);
Joe Perchescd228d52007-11-12 18:07:31 -08002043 if (!pch->ppp || proto >= 0xc000 || proto == PPP_CCPFRAG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 /* put it on the channel queue */
2045 skb_queue_tail(&pch->file.rq, skb);
2046 /* drop old frames if queue too long */
Joe Perches8e95a202009-12-03 07:58:21 +00002047 while (pch->file.rq.qlen > PPP_MAX_RQLEN &&
2048 (skb = skb_dequeue(&pch->file.rq)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 kfree_skb(skb);
2050 wake_up_interruptible(&pch->file.rwait);
2051 } else {
2052 ppp_do_recv(pch->ppp, skb, pch);
2053 }
Simon Arlottea8420e2010-05-03 10:19:33 +00002054
2055done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 read_unlock_bh(&pch->upl);
2057}
2058
2059/* Put a 0-length skb in the receive queue as an error indication */
2060void
2061ppp_input_error(struct ppp_channel *chan, int code)
2062{
2063 struct channel *pch = chan->ppp;
2064 struct sk_buff *skb;
2065
Joe Perchescd228d52007-11-12 18:07:31 -08002066 if (!pch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 return;
2068
2069 read_lock_bh(&pch->upl);
Joe Perchescd228d52007-11-12 18:07:31 -08002070 if (pch->ppp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 skb = alloc_skb(0, GFP_ATOMIC);
Joe Perchescd228d52007-11-12 18:07:31 -08002072 if (skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 skb->len = 0; /* probably unnecessary */
2074 skb->cb[0] = code;
2075 ppp_do_recv(pch->ppp, skb, pch);
2076 }
2077 }
2078 read_unlock_bh(&pch->upl);
2079}
2080
2081/*
2082 * We come in here to process a received frame.
2083 * The receive side of the ppp unit is locked.
2084 */
2085static void
2086ppp_receive_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
2087{
Simon Arlottea8420e2010-05-03 10:19:33 +00002088 /* note: a 0-length skb is used as an error indication */
2089 if (skb->len > 0) {
Tom Herbert3dfb0532015-04-20 14:10:05 -07002090 skb_checksum_complete_unset(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091#ifdef CONFIG_PPP_MULTILINK
2092 /* XXX do channel-level decompression here */
2093 if (PPP_PROTO(skb) == PPP_MP)
2094 ppp_receive_mp_frame(ppp, skb, pch);
2095 else
2096#endif /* CONFIG_PPP_MULTILINK */
2097 ppp_receive_nonmp_frame(ppp, skb);
Simon Arlottea8420e2010-05-03 10:19:33 +00002098 } else {
2099 kfree_skb(skb);
2100 ppp_receive_error(ppp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102}
2103
2104static void
2105ppp_receive_error(struct ppp *ppp)
2106{
Paulius Zaleckas8c0469c2008-04-23 18:54:01 -07002107 ++ppp->dev->stats.rx_errors;
Joe Perchescd228d52007-11-12 18:07:31 -08002108 if (ppp->vj)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 slhc_toss(ppp->vj);
2110}
2111
2112static void
2113ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
2114{
2115 struct sk_buff *ns;
2116 int proto, len, npi;
2117
2118 /*
2119 * Decompress the frame, if compressed.
2120 * Note that some decompressors need to see uncompressed frames
2121 * that come in as well as compressed frames.
2122 */
Joe Perches8e95a202009-12-03 07:58:21 +00002123 if (ppp->rc_state && (ppp->rstate & SC_DECOMP_RUN) &&
2124 (ppp->rstate & (SC_DC_FERROR | SC_DC_ERROR)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 skb = ppp_decompress_frame(ppp, skb);
2126
Matt Domschb3f9b922005-11-08 09:40:47 -08002127 if (ppp->flags & SC_MUST_COMP && ppp->rstate & SC_DC_FERROR)
2128 goto err;
2129
Sam Protsenkof74ba31b2018-12-20 20:29:20 +02002130 /* At this point the "Protocol" field MUST be decompressed, either in
2131 * ppp_input(), ppp_decompress_frame() or in ppp_receive_mp_frame().
2132 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 proto = PPP_PROTO(skb);
2134 switch (proto) {
2135 case PPP_VJC_COMP:
2136 /* decompress VJ compressed packets */
Joe Perchescd228d52007-11-12 18:07:31 -08002137 if (!ppp->vj || (ppp->flags & SC_REJ_COMP_TCP))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 goto err;
2139
Herbert Xu2a38b772007-09-16 16:22:13 -07002140 if (skb_tailroom(skb) < 124 || skb_cloned(skb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 /* copy to a new sk_buff with more tailroom */
2142 ns = dev_alloc_skb(skb->len + 128);
Joe Perchescd228d52007-11-12 18:07:31 -08002143 if (!ns) {
David S. Millerb48f8c22011-01-20 22:44:36 -08002144 netdev_err(ppp->dev, "PPP: no memory "
2145 "(VJ decomp)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 goto err;
2147 }
2148 skb_reserve(ns, 2);
2149 skb_copy_bits(skb, 0, skb_put(ns, skb->len), skb->len);
Eric Dumazet968d7012012-05-18 20:23:00 +00002150 consume_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 skb = ns;
2152 }
Herbert Xue3f749c2006-02-05 20:23:33 -08002153 else
2154 skb->ip_summed = CHECKSUM_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
2156 len = slhc_uncompress(ppp->vj, skb->data + 2, skb->len - 2);
2157 if (len <= 0) {
David S. Millerb48f8c22011-01-20 22:44:36 -08002158 netdev_printk(KERN_DEBUG, ppp->dev,
2159 "PPP: VJ decompression error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 goto err;
2161 }
2162 len += 2;
2163 if (len > skb->len)
2164 skb_put(skb, len - skb->len);
2165 else if (len < skb->len)
2166 skb_trim(skb, len);
2167 proto = PPP_IP;
2168 break;
2169
2170 case PPP_VJC_UNCOMP:
Joe Perchescd228d52007-11-12 18:07:31 -08002171 if (!ppp->vj || (ppp->flags & SC_REJ_COMP_TCP))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 goto err;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002173
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 /* Until we fix the decompressor need to make sure
2175 * data portion is linear.
2176 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002177 if (!pskb_may_pull(skb, skb->len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 goto err;
2179
2180 if (slhc_remember(ppp->vj, skb->data + 2, skb->len - 2) <= 0) {
David S. Millerb48f8c22011-01-20 22:44:36 -08002181 netdev_err(ppp->dev, "PPP: VJ uncompressed error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 goto err;
2183 }
2184 proto = PPP_IP;
2185 break;
2186
2187 case PPP_CCP:
2188 ppp_ccp_peek(ppp, skb, 1);
2189 break;
2190 }
2191
Kevin Groenevelde51f6ff2012-07-27 17:38:53 +00002192 ++ppp->stats64.rx_packets;
2193 ppp->stats64.rx_bytes += skb->len - 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
2195 npi = proto_to_npindex(proto);
2196 if (npi < 0) {
2197 /* control or unknown frame - pass it to pppd */
2198 skb_queue_tail(&ppp->file.rq, skb);
2199 /* limit queue length by dropping old frames */
Joe Perches8e95a202009-12-03 07:58:21 +00002200 while (ppp->file.rq.qlen > PPP_MAX_RQLEN &&
2201 (skb = skb_dequeue(&ppp->file.rq)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 kfree_skb(skb);
2203 /* wake up any process polling or blocking on read */
2204 wake_up_interruptible(&ppp->file.rwait);
2205
2206 } else {
2207 /* network protocol frame - give it to the kernel */
2208
2209#ifdef CONFIG_PPP_FILTER
2210 /* check if the packet passes the pass and active filters */
2211 /* the filter instructions are constructed assuming
2212 a four-byte PPP header on each packet */
Herbert Xu2a38b772007-09-16 16:22:13 -07002213 if (ppp->pass_filter || ppp->active_filter) {
Pravin B Shelar14bbd6a2013-02-14 09:44:49 +00002214 if (skb_unclone(skb, GFP_ATOMIC))
Herbert Xu2a38b772007-09-16 16:22:13 -07002215 goto err;
2216
2217 *skb_push(skb, 2) = 0;
Joe Perches8e95a202009-12-03 07:58:21 +00002218 if (ppp->pass_filter &&
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07002219 BPF_PROG_RUN(ppp->pass_filter, skb) == 0) {
Herbert Xu2a38b772007-09-16 16:22:13 -07002220 if (ppp->debug & 1)
David S. Millerb48f8c22011-01-20 22:44:36 -08002221 netdev_printk(KERN_DEBUG, ppp->dev,
2222 "PPP: inbound frame "
2223 "not passed\n");
Herbert Xu2a38b772007-09-16 16:22:13 -07002224 kfree_skb(skb);
2225 return;
2226 }
Joe Perches8e95a202009-12-03 07:58:21 +00002227 if (!(ppp->active_filter &&
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07002228 BPF_PROG_RUN(ppp->active_filter, skb) == 0))
Herbert Xu2a38b772007-09-16 16:22:13 -07002229 ppp->last_recv = jiffies;
2230 __skb_pull(skb, 2);
2231 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232#endif /* CONFIG_PPP_FILTER */
Herbert Xu2a38b772007-09-16 16:22:13 -07002233 ppp->last_recv = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234
Joe Perches8e95a202009-12-03 07:58:21 +00002235 if ((ppp->dev->flags & IFF_UP) == 0 ||
2236 ppp->npmode[npi] != NPMODE_PASS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 kfree_skb(skb);
2238 } else {
Herbert Xucbb042f2006-03-20 22:43:56 -08002239 /* chop off protocol */
2240 skb_pull_rcsum(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 skb->dev = ppp->dev;
2242 skb->protocol = htons(npindex_to_ethertype[npi]);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07002243 skb_reset_mac_header(skb);
Guillaume Nault79c441a2015-08-24 11:35:30 +02002244 skb_scrub_packet(skb, !net_eq(ppp->ppp_net,
2245 dev_net(ppp->dev)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 }
2248 }
2249 return;
2250
2251 err:
2252 kfree_skb(skb);
2253 ppp_receive_error(ppp);
2254}
2255
2256static struct sk_buff *
2257ppp_decompress_frame(struct ppp *ppp, struct sk_buff *skb)
2258{
2259 int proto = PPP_PROTO(skb);
2260 struct sk_buff *ns;
2261 int len;
2262
2263 /* Until we fix all the decompressor's need to make sure
2264 * data portion is linear.
2265 */
2266 if (!pskb_may_pull(skb, skb->len))
2267 goto err;
2268
2269 if (proto == PPP_COMP) {
Konstantin Sharlaimov4b2a8fb2007-06-23 23:05:54 -07002270 int obuff_size;
2271
2272 switch(ppp->rcomp->compress_proto) {
2273 case CI_MPPE:
2274 obuff_size = ppp->mru + PPP_HDRLEN + 1;
2275 break;
2276 default:
2277 obuff_size = ppp->mru + PPP_HDRLEN;
2278 break;
2279 }
2280
2281 ns = dev_alloc_skb(obuff_size);
Joe Perchescd228d52007-11-12 18:07:31 -08002282 if (!ns) {
David S. Millerb48f8c22011-01-20 22:44:36 -08002283 netdev_err(ppp->dev, "ppp_decompress_frame: "
2284 "no memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 goto err;
2286 }
2287 /* the decompressor still expects the A/C bytes in the hdr */
2288 len = ppp->rcomp->decompress(ppp->rc_state, skb->data - 2,
Konstantin Sharlaimov06c7af52007-08-21 00:12:44 -07002289 skb->len + 2, ns->data, obuff_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 if (len < 0) {
2291 /* Pass the compressed frame to pppd as an
2292 error indication. */
2293 if (len == DECOMP_FATALERROR)
2294 ppp->rstate |= SC_DC_FERROR;
2295 kfree_skb(ns);
2296 goto err;
2297 }
2298
Eric Dumazet968d7012012-05-18 20:23:00 +00002299 consume_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 skb = ns;
2301 skb_put(skb, len);
2302 skb_pull(skb, 2); /* pull off the A/C bytes */
2303
Sam Protsenkof74ba31b2018-12-20 20:29:20 +02002304 /* Don't call __ppp_decompress_proto() here, but instead rely on
2305 * corresponding algo (mppe/bsd/deflate) to decompress it.
2306 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 } else {
2308 /* Uncompressed frame - pass to decompressor so it
2309 can update its dictionary if necessary. */
2310 if (ppp->rcomp->incomp)
2311 ppp->rcomp->incomp(ppp->rc_state, skb->data - 2,
2312 skb->len + 2);
2313 }
2314
2315 return skb;
2316
2317 err:
2318 ppp->rstate |= SC_DC_ERROR;
2319 ppp_receive_error(ppp);
2320 return skb;
2321}
2322
2323#ifdef CONFIG_PPP_MULTILINK
2324/*
2325 * Receive a multilink frame.
2326 * We put it on the reconstruction queue and then pull off
2327 * as many completed frames as we can.
2328 */
2329static void
2330ppp_receive_mp_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
2331{
2332 u32 mask, seq;
Domen Puncer81616c52005-09-10 00:27:04 -07002333 struct channel *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 int mphdrlen = (ppp->flags & SC_MP_SHORTSEQ)? MPHDRLEN_SSN: MPHDRLEN;
2335
Herbert Xu2a38b772007-09-16 16:22:13 -07002336 if (!pskb_may_pull(skb, mphdrlen + 1) || ppp->mrru == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 goto err; /* no good, throw it away */
2338
2339 /* Decode sequence number and begin/end bits */
2340 if (ppp->flags & SC_MP_SHORTSEQ) {
2341 seq = ((skb->data[2] & 0x0f) << 8) | skb->data[3];
2342 mask = 0xfff;
2343 } else {
2344 seq = (skb->data[3] << 16) | (skb->data[4] << 8)| skb->data[5];
2345 mask = 0xffffff;
2346 }
David S. Millera00eac02010-10-05 01:36:52 -07002347 PPP_MP_CB(skb)->BEbits = skb->data[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 skb_pull(skb, mphdrlen); /* pull off PPP and MP headers */
2349
2350 /*
2351 * Do protocol ID decompression on the first fragment of each packet.
Sam Protsenkof74ba31b2018-12-20 20:29:20 +02002352 * We have to do that here, because ppp_receive_nonmp_frame() expects
2353 * decompressed protocol field.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 */
Sam Protsenkof74ba31b2018-12-20 20:29:20 +02002355 if (PPP_MP_CB(skb)->BEbits & B)
2356 __ppp_decompress_proto(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
2358 /*
2359 * Expand sequence number to 32 bits, making it as close
2360 * as possible to ppp->minseq.
2361 */
2362 seq |= ppp->minseq & ~mask;
2363 if ((int)(ppp->minseq - seq) > (int)(mask >> 1))
2364 seq += mask + 1;
2365 else if ((int)(seq - ppp->minseq) > (int)(mask >> 1))
2366 seq -= mask + 1; /* should never happen */
David S. Millera00eac02010-10-05 01:36:52 -07002367 PPP_MP_CB(skb)->sequence = seq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 pch->lastseq = seq;
2369
2370 /*
2371 * If this packet comes before the next one we were expecting,
2372 * drop it.
2373 */
2374 if (seq_before(seq, ppp->nextseq)) {
2375 kfree_skb(skb);
Paulius Zaleckas8c0469c2008-04-23 18:54:01 -07002376 ++ppp->dev->stats.rx_dropped;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 ppp_receive_error(ppp);
2378 return;
2379 }
2380
2381 /*
2382 * Reevaluate minseq, the minimum over all channels of the
2383 * last sequence number received on each channel. Because of
2384 * the increasing sequence number rule, we know that any fragment
2385 * before `minseq' which hasn't arrived is never going to arrive.
2386 * The list of channels can't change because we have the receive
2387 * side of the ppp unit locked.
2388 */
Domen Puncer81616c52005-09-10 00:27:04 -07002389 list_for_each_entry(ch, &ppp->channels, clist) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 if (seq_before(ch->lastseq, seq))
2391 seq = ch->lastseq;
2392 }
2393 if (seq_before(ppp->minseq, seq))
2394 ppp->minseq = seq;
2395
2396 /* Put the fragment on the reconstruction queue */
2397 ppp_mp_insert(ppp, skb);
2398
2399 /* If the queue is getting long, don't wait any longer for packets
2400 before the start of the queue. */
David S. Miller38ce7c72008-09-23 01:17:18 -07002401 if (skb_queue_len(&ppp->mrq) >= PPP_MP_MAX_QLEN) {
stephen hemmingerc6b20d92010-06-01 06:05:46 +00002402 struct sk_buff *mskb = skb_peek(&ppp->mrq);
David S. Millera00eac02010-10-05 01:36:52 -07002403 if (seq_before(ppp->minseq, PPP_MP_CB(mskb)->sequence))
2404 ppp->minseq = PPP_MP_CB(mskb)->sequence;
David S. Miller38ce7c72008-09-23 01:17:18 -07002405 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
2407 /* Pull completed packets off the queue and receive them. */
Ben McKeegan82b3cc12009-11-16 03:44:25 +00002408 while ((skb = ppp_mp_reconstruct(ppp))) {
2409 if (pskb_may_pull(skb, 2))
2410 ppp_receive_nonmp_frame(ppp, skb);
2411 else {
2412 ++ppp->dev->stats.rx_length_errors;
2413 kfree_skb(skb);
2414 ppp_receive_error(ppp);
2415 }
2416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
2418 return;
2419
2420 err:
2421 kfree_skb(skb);
2422 ppp_receive_error(ppp);
2423}
2424
2425/*
2426 * Insert a fragment on the MP reconstruction queue.
2427 * The queue is ordered by increasing sequence number.
2428 */
2429static void
2430ppp_mp_insert(struct ppp *ppp, struct sk_buff *skb)
2431{
2432 struct sk_buff *p;
2433 struct sk_buff_head *list = &ppp->mrq;
David S. Millera00eac02010-10-05 01:36:52 -07002434 u32 seq = PPP_MP_CB(skb)->sequence;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
2436 /* N.B. we don't need to lock the list lock because we have the
2437 ppp unit receive-side lock. */
David S. Miller13c98212008-10-09 16:40:29 -07002438 skb_queue_walk(list, p) {
David S. Millera00eac02010-10-05 01:36:52 -07002439 if (seq_before(seq, PPP_MP_CB(p)->sequence))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 break;
David S. Miller13c98212008-10-09 16:40:29 -07002441 }
David S. Miller43f59c82008-09-21 21:28:51 -07002442 __skb_queue_before(list, p, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443}
2444
2445/*
2446 * Reconstruct a packet from the MP fragment queue.
2447 * We go through increasing sequence numbers until we find a
2448 * complete packet, or we get to the sequence number for a fragment
2449 * which hasn't arrived but might still do so.
2450 */
Stephen Hemminger3c582b32008-01-23 20:54:07 -08002451static struct sk_buff *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452ppp_mp_reconstruct(struct ppp *ppp)
2453{
2454 u32 seq = ppp->nextseq;
2455 u32 minseq = ppp->minseq;
2456 struct sk_buff_head *list = &ppp->mrq;
David S. Millerd52344a2011-01-20 22:52:05 -08002457 struct sk_buff *p, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 struct sk_buff *head, *tail;
2459 struct sk_buff *skb = NULL;
2460 int lost = 0, len = 0;
2461
2462 if (ppp->mrru == 0) /* do nothing until mrru is set */
2463 return NULL;
2464 head = list->next;
2465 tail = NULL;
David S. Millerd52344a2011-01-20 22:52:05 -08002466 skb_queue_walk_safe(list, p, tmp) {
2467 again:
David S. Millera00eac02010-10-05 01:36:52 -07002468 if (seq_before(PPP_MP_CB(p)->sequence, seq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 /* this can't happen, anyway ignore the skb */
David S. Millerb48f8c22011-01-20 22:44:36 -08002470 netdev_err(ppp->dev, "ppp_mp_reconstruct bad "
2471 "seq %u < %u\n",
2472 PPP_MP_CB(p)->sequence, seq);
David S. Millerd52344a2011-01-20 22:52:05 -08002473 __skb_unlink(p, list);
2474 kfree_skb(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 continue;
2476 }
David S. Millera00eac02010-10-05 01:36:52 -07002477 if (PPP_MP_CB(p)->sequence != seq) {
Ben McKeegan8a49ad62012-02-24 06:33:56 +00002478 u32 oldseq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 /* Fragment `seq' is missing. If it is after
2480 minseq, it might arrive later, so stop here. */
2481 if (seq_after(seq, minseq))
2482 break;
2483 /* Fragment `seq' is lost, keep going. */
2484 lost = 1;
Ben McKeegan8a49ad62012-02-24 06:33:56 +00002485 oldseq = seq;
David S. Millera00eac02010-10-05 01:36:52 -07002486 seq = seq_before(minseq, PPP_MP_CB(p)->sequence)?
2487 minseq + 1: PPP_MP_CB(p)->sequence;
Ben McKeegan8a49ad62012-02-24 06:33:56 +00002488
2489 if (ppp->debug & 1)
2490 netdev_printk(KERN_DEBUG, ppp->dev,
2491 "lost frag %u..%u\n",
2492 oldseq, seq-1);
2493
David S. Millerd52344a2011-01-20 22:52:05 -08002494 goto again;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 }
2496
2497 /*
2498 * At this point we know that all the fragments from
2499 * ppp->nextseq to seq are either present or lost.
2500 * Also, there are no complete packets in the queue
2501 * that have no missing fragments and end before this
2502 * fragment.
2503 */
2504
2505 /* B bit set indicates this fragment starts a packet */
David S. Millera00eac02010-10-05 01:36:52 -07002506 if (PPP_MP_CB(p)->BEbits & B) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 head = p;
2508 lost = 0;
2509 len = 0;
2510 }
2511
2512 len += p->len;
2513
2514 /* Got a complete packet yet? */
David S. Millera00eac02010-10-05 01:36:52 -07002515 if (lost == 0 && (PPP_MP_CB(p)->BEbits & E) &&
2516 (PPP_MP_CB(head)->BEbits & B)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 if (len > ppp->mrru + 2) {
Paulius Zaleckas8c0469c2008-04-23 18:54:01 -07002518 ++ppp->dev->stats.rx_length_errors;
David S. Millerb48f8c22011-01-20 22:44:36 -08002519 netdev_printk(KERN_DEBUG, ppp->dev,
2520 "PPP: reconstructed packet"
2521 " is too long (%d)\n", len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 } else {
2523 tail = p;
2524 break;
2525 }
2526 ppp->nextseq = seq + 1;
2527 }
2528
2529 /*
2530 * If this is the ending fragment of a packet,
2531 * and we haven't found a complete valid packet yet,
2532 * we can discard up to and including this fragment.
2533 */
David S. Millerd52344a2011-01-20 22:52:05 -08002534 if (PPP_MP_CB(p)->BEbits & E) {
2535 struct sk_buff *tmp2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536
David S. Millerd52344a2011-01-20 22:52:05 -08002537 skb_queue_reverse_walk_from_safe(list, p, tmp2) {
Ben McKeegan8a49ad62012-02-24 06:33:56 +00002538 if (ppp->debug & 1)
2539 netdev_printk(KERN_DEBUG, ppp->dev,
2540 "discarding frag %u\n",
2541 PPP_MP_CB(p)->sequence);
David S. Millerd52344a2011-01-20 22:52:05 -08002542 __skb_unlink(p, list);
2543 kfree_skb(p);
2544 }
2545 head = skb_peek(list);
2546 if (!head)
2547 break;
2548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 ++seq;
2550 }
2551
2552 /* If we have a complete packet, copy it all into one skb. */
2553 if (tail != NULL) {
2554 /* If we have discarded any fragments,
2555 signal a receive error. */
David S. Millera00eac02010-10-05 01:36:52 -07002556 if (PPP_MP_CB(head)->sequence != ppp->nextseq) {
Ben McKeegan8a49ad62012-02-24 06:33:56 +00002557 skb_queue_walk_safe(list, p, tmp) {
2558 if (p == head)
2559 break;
2560 if (ppp->debug & 1)
2561 netdev_printk(KERN_DEBUG, ppp->dev,
2562 "discarding frag %u\n",
2563 PPP_MP_CB(p)->sequence);
2564 __skb_unlink(p, list);
2565 kfree_skb(p);
2566 }
2567
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 if (ppp->debug & 1)
David S. Millerb48f8c22011-01-20 22:44:36 -08002569 netdev_printk(KERN_DEBUG, ppp->dev,
2570 " missed pkts %u..%u\n",
2571 ppp->nextseq,
2572 PPP_MP_CB(head)->sequence-1);
Paulius Zaleckas8c0469c2008-04-23 18:54:01 -07002573 ++ppp->dev->stats.rx_dropped;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 ppp_receive_error(ppp);
2575 }
2576
David S. Miller212bfb92011-01-20 22:46:07 -08002577 skb = head;
2578 if (head != tail) {
2579 struct sk_buff **fragpp = &skb_shinfo(skb)->frag_list;
2580 p = skb_queue_next(list, head);
2581 __skb_unlink(skb, list);
2582 skb_queue_walk_from_safe(list, p, tmp) {
2583 __skb_unlink(p, list);
2584 *fragpp = p;
2585 p->next = NULL;
2586 fragpp = &p->next;
2587
2588 skb->len += p->len;
2589 skb->data_len += p->len;
Eric Dumazet19c6c8f2012-02-13 04:23:24 +00002590 skb->truesize += p->truesize;
David S. Miller212bfb92011-01-20 22:46:07 -08002591
2592 if (p == tail)
2593 break;
2594 }
2595 } else {
2596 __skb_unlink(skb, list);
2597 }
2598
David S. Millera00eac02010-10-05 01:36:52 -07002599 ppp->nextseq = PPP_MP_CB(tail)->sequence + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 }
2601
2602 return skb;
2603}
2604#endif /* CONFIG_PPP_MULTILINK */
2605
2606/*
2607 * Channel interface.
2608 */
2609
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08002610/* Create a new, unattached ppp channel. */
2611int ppp_register_channel(struct ppp_channel *chan)
2612{
2613 return ppp_register_net_channel(current->nsproxy->net_ns, chan);
2614}
2615
2616/* Create a new, unattached ppp channel for specified net. */
2617int ppp_register_net_channel(struct net *net, struct ppp_channel *chan)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618{
2619 struct channel *pch;
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08002620 struct ppp_net *pn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621
Panagiotis Issarisd4274b52006-08-15 16:01:07 -07002622 pch = kzalloc(sizeof(struct channel), GFP_KERNEL);
Joe Perchescd228d52007-11-12 18:07:31 -08002623 if (!pch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 return -ENOMEM;
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08002625
2626 pn = ppp_pernet(net);
2627
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 pch->ppp = NULL;
2629 pch->chan = chan;
Guillaume Nault1f461dc2016-03-23 16:38:55 +01002630 pch->chan_net = get_net(net);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 chan->ppp = pch;
2632 init_ppp_file(&pch->file, CHANNEL);
2633 pch->file.hdrlen = chan->hdrlen;
2634#ifdef CONFIG_PPP_MULTILINK
2635 pch->lastseq = -1;
2636#endif /* CONFIG_PPP_MULTILINK */
2637 init_rwsem(&pch->chan_sem);
2638 spin_lock_init(&pch->downl);
2639 rwlock_init(&pch->upl);
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08002640
2641 spin_lock_bh(&pn->all_channels_lock);
2642 pch->file.index = ++pn->last_channel_index;
2643 list_add(&pch->list, &pn->new_channels);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 atomic_inc(&channel_count);
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08002645 spin_unlock_bh(&pn->all_channels_lock);
2646
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 return 0;
2648}
2649
2650/*
2651 * Return the index of a channel.
2652 */
2653int ppp_channel_index(struct ppp_channel *chan)
2654{
2655 struct channel *pch = chan->ppp;
2656
Joe Perchescd228d52007-11-12 18:07:31 -08002657 if (pch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 return pch->file.index;
2659 return -1;
2660}
2661
2662/*
2663 * Return the PPP unit number to which a channel is connected.
2664 */
2665int ppp_unit_number(struct ppp_channel *chan)
2666{
2667 struct channel *pch = chan->ppp;
2668 int unit = -1;
2669
Joe Perchescd228d52007-11-12 18:07:31 -08002670 if (pch) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 read_lock_bh(&pch->upl);
Joe Perchescd228d52007-11-12 18:07:31 -08002672 if (pch->ppp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 unit = pch->ppp->file.index;
2674 read_unlock_bh(&pch->upl);
2675 }
2676 return unit;
2677}
2678
2679/*
James Chapman63f96072010-04-02 06:18:39 +00002680 * Return the PPP device interface name of a channel.
2681 */
2682char *ppp_dev_name(struct ppp_channel *chan)
2683{
2684 struct channel *pch = chan->ppp;
2685 char *name = NULL;
2686
2687 if (pch) {
2688 read_lock_bh(&pch->upl);
2689 if (pch->ppp && pch->ppp->dev)
2690 name = pch->ppp->dev->name;
2691 read_unlock_bh(&pch->upl);
2692 }
2693 return name;
2694}
2695
2696
2697/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 * Disconnect a channel from the generic layer.
2699 * This must be called in process context.
2700 */
2701void
2702ppp_unregister_channel(struct ppp_channel *chan)
2703{
2704 struct channel *pch = chan->ppp;
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08002705 struct ppp_net *pn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706
Joe Perchescd228d52007-11-12 18:07:31 -08002707 if (!pch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 return; /* should never happen */
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08002709
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 chan->ppp = NULL;
2711
2712 /*
2713 * This ensures that we have returned from any calls into the
2714 * the channel's start_xmit or ioctl routine before we proceed.
2715 */
2716 down_write(&pch->chan_sem);
2717 spin_lock_bh(&pch->downl);
2718 pch->chan = NULL;
2719 spin_unlock_bh(&pch->downl);
2720 up_write(&pch->chan_sem);
2721 ppp_disconnect_channel(pch);
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08002722
2723 pn = ppp_pernet(pch->chan_net);
2724 spin_lock_bh(&pn->all_channels_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 list_del(&pch->list);
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08002726 spin_unlock_bh(&pn->all_channels_lock);
2727
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 pch->file.dead = 1;
2729 wake_up_interruptible(&pch->file.rwait);
2730 if (atomic_dec_and_test(&pch->file.refcnt))
2731 ppp_destroy_channel(pch);
2732}
2733
2734/*
2735 * Callback from a channel when it can accept more to transmit.
2736 * This should be called at BH/softirq level, not interrupt level.
2737 */
2738void
2739ppp_output_wakeup(struct ppp_channel *chan)
2740{
2741 struct channel *pch = chan->ppp;
2742
Joe Perchescd228d52007-11-12 18:07:31 -08002743 if (!pch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 return;
2745 ppp_channel_push(pch);
2746}
2747
2748/*
2749 * Compression control.
2750 */
2751
2752/* Process the PPPIOCSCOMPRESS ioctl. */
2753static int
2754ppp_set_compress(struct ppp *ppp, unsigned long arg)
2755{
2756 int err;
2757 struct compressor *cp, *ocomp;
2758 struct ppp_option_data data;
2759 void *state, *ostate;
2760 unsigned char ccp_option[CCP_MAX_OPTION_LENGTH];
2761
2762 err = -EFAULT;
Guillaume Nault555d5b72016-02-23 13:59:43 +01002763 if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 goto out;
Guillaume Nault555d5b72016-02-23 13:59:43 +01002765 if (data.length > CCP_MAX_OPTION_LENGTH)
2766 goto out;
2767 if (copy_from_user(ccp_option, (void __user *) data.ptr, data.length))
2768 goto out;
2769
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 err = -EINVAL;
Guillaume Nault555d5b72016-02-23 13:59:43 +01002771 if (data.length < 2 || ccp_option[1] < 2 || ccp_option[1] > data.length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 goto out;
2773
Johannes Berga65e5d72008-07-09 10:28:38 +02002774 cp = try_then_request_module(
2775 find_compressor(ccp_option[0]),
2776 "ppp-compress-%d", ccp_option[0]);
Joe Perchescd228d52007-11-12 18:07:31 -08002777 if (!cp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 goto out;
2779
2780 err = -ENOBUFS;
2781 if (data.transmit) {
2782 state = cp->comp_alloc(ccp_option, data.length);
Joe Perchescd228d52007-11-12 18:07:31 -08002783 if (state) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 ppp_xmit_lock(ppp);
2785 ppp->xstate &= ~SC_COMP_RUN;
2786 ocomp = ppp->xcomp;
2787 ostate = ppp->xc_state;
2788 ppp->xcomp = cp;
2789 ppp->xc_state = state;
2790 ppp_xmit_unlock(ppp);
Joe Perchescd228d52007-11-12 18:07:31 -08002791 if (ostate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 ocomp->comp_free(ostate);
2793 module_put(ocomp->owner);
2794 }
2795 err = 0;
2796 } else
2797 module_put(cp->owner);
2798
2799 } else {
2800 state = cp->decomp_alloc(ccp_option, data.length);
Joe Perchescd228d52007-11-12 18:07:31 -08002801 if (state) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 ppp_recv_lock(ppp);
2803 ppp->rstate &= ~SC_DECOMP_RUN;
2804 ocomp = ppp->rcomp;
2805 ostate = ppp->rc_state;
2806 ppp->rcomp = cp;
2807 ppp->rc_state = state;
2808 ppp_recv_unlock(ppp);
Joe Perchescd228d52007-11-12 18:07:31 -08002809 if (ostate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 ocomp->decomp_free(ostate);
2811 module_put(ocomp->owner);
2812 }
2813 err = 0;
2814 } else
2815 module_put(cp->owner);
2816 }
2817
2818 out:
2819 return err;
2820}
2821
2822/*
2823 * Look at a CCP packet and update our state accordingly.
2824 * We assume the caller has the xmit or recv path locked.
2825 */
2826static void
2827ppp_ccp_peek(struct ppp *ppp, struct sk_buff *skb, int inbound)
2828{
2829 unsigned char *dp;
2830 int len;
2831
2832 if (!pskb_may_pull(skb, CCP_HDRLEN + 2))
2833 return; /* no header */
2834 dp = skb->data + 2;
2835
2836 switch (CCP_CODE(dp)) {
2837 case CCP_CONFREQ:
2838
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002839 /* A ConfReq starts negotiation of compression
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 * in one direction of transmission,
2841 * and hence brings it down...but which way?
2842 *
2843 * Remember:
2844 * A ConfReq indicates what the sender would like to receive
2845 */
2846 if(inbound)
2847 /* He is proposing what I should send */
2848 ppp->xstate &= ~SC_COMP_RUN;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002849 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 /* I am proposing to what he should send */
2851 ppp->rstate &= ~SC_DECOMP_RUN;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002852
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 break;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002854
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 case CCP_TERMREQ:
2856 case CCP_TERMACK:
2857 /*
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002858 * CCP is going down, both directions of transmission
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 */
2860 ppp->rstate &= ~SC_DECOMP_RUN;
2861 ppp->xstate &= ~SC_COMP_RUN;
2862 break;
2863
2864 case CCP_CONFACK:
2865 if ((ppp->flags & (SC_CCP_OPEN | SC_CCP_UP)) != SC_CCP_OPEN)
2866 break;
2867 len = CCP_LENGTH(dp);
2868 if (!pskb_may_pull(skb, len + 2))
2869 return; /* too short */
2870 dp += CCP_HDRLEN;
2871 len -= CCP_HDRLEN;
2872 if (len < CCP_OPT_MINLEN || len < CCP_OPT_LENGTH(dp))
2873 break;
2874 if (inbound) {
2875 /* we will start receiving compressed packets */
Joe Perchescd228d52007-11-12 18:07:31 -08002876 if (!ppp->rc_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 break;
2878 if (ppp->rcomp->decomp_init(ppp->rc_state, dp, len,
2879 ppp->file.index, 0, ppp->mru, ppp->debug)) {
2880 ppp->rstate |= SC_DECOMP_RUN;
2881 ppp->rstate &= ~(SC_DC_ERROR | SC_DC_FERROR);
2882 }
2883 } else {
2884 /* we will soon start sending compressed packets */
Joe Perchescd228d52007-11-12 18:07:31 -08002885 if (!ppp->xc_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 break;
2887 if (ppp->xcomp->comp_init(ppp->xc_state, dp, len,
2888 ppp->file.index, 0, ppp->debug))
2889 ppp->xstate |= SC_COMP_RUN;
2890 }
2891 break;
2892
2893 case CCP_RESETACK:
2894 /* reset the [de]compressor */
2895 if ((ppp->flags & SC_CCP_UP) == 0)
2896 break;
2897 if (inbound) {
2898 if (ppp->rc_state && (ppp->rstate & SC_DECOMP_RUN)) {
2899 ppp->rcomp->decomp_reset(ppp->rc_state);
2900 ppp->rstate &= ~SC_DC_ERROR;
2901 }
2902 } else {
2903 if (ppp->xc_state && (ppp->xstate & SC_COMP_RUN))
2904 ppp->xcomp->comp_reset(ppp->xc_state);
2905 }
2906 break;
2907 }
2908}
2909
2910/* Free up compression resources. */
2911static void
2912ppp_ccp_closed(struct ppp *ppp)
2913{
2914 void *xstate, *rstate;
2915 struct compressor *xcomp, *rcomp;
2916
2917 ppp_lock(ppp);
2918 ppp->flags &= ~(SC_CCP_OPEN | SC_CCP_UP);
2919 ppp->xstate = 0;
2920 xcomp = ppp->xcomp;
2921 xstate = ppp->xc_state;
2922 ppp->xc_state = NULL;
2923 ppp->rstate = 0;
2924 rcomp = ppp->rcomp;
2925 rstate = ppp->rc_state;
2926 ppp->rc_state = NULL;
2927 ppp_unlock(ppp);
2928
2929 if (xstate) {
2930 xcomp->comp_free(xstate);
2931 module_put(xcomp->owner);
2932 }
2933 if (rstate) {
2934 rcomp->decomp_free(rstate);
2935 module_put(rcomp->owner);
2936 }
2937}
2938
2939/* List of compressors. */
2940static LIST_HEAD(compressor_list);
2941static DEFINE_SPINLOCK(compressor_list_lock);
2942
2943struct compressor_entry {
2944 struct list_head list;
2945 struct compressor *comp;
2946};
2947
2948static struct compressor_entry *
2949find_comp_entry(int proto)
2950{
2951 struct compressor_entry *ce;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952
Domen Puncer81616c52005-09-10 00:27:04 -07002953 list_for_each_entry(ce, &compressor_list, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 if (ce->comp->compress_proto == proto)
2955 return ce;
2956 }
2957 return NULL;
2958}
2959
2960/* Register a compressor */
2961int
2962ppp_register_compressor(struct compressor *cp)
2963{
2964 struct compressor_entry *ce;
2965 int ret;
2966 spin_lock(&compressor_list_lock);
2967 ret = -EEXIST;
Joe Perchescd228d52007-11-12 18:07:31 -08002968 if (find_comp_entry(cp->compress_proto))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 goto out;
2970 ret = -ENOMEM;
2971 ce = kmalloc(sizeof(struct compressor_entry), GFP_ATOMIC);
Joe Perchescd228d52007-11-12 18:07:31 -08002972 if (!ce)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 goto out;
2974 ret = 0;
2975 ce->comp = cp;
2976 list_add(&ce->list, &compressor_list);
2977 out:
2978 spin_unlock(&compressor_list_lock);
2979 return ret;
2980}
2981
2982/* Unregister a compressor */
2983void
2984ppp_unregister_compressor(struct compressor *cp)
2985{
2986 struct compressor_entry *ce;
2987
2988 spin_lock(&compressor_list_lock);
2989 ce = find_comp_entry(cp->compress_proto);
Joe Perchescd228d52007-11-12 18:07:31 -08002990 if (ce && ce->comp == cp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 list_del(&ce->list);
2992 kfree(ce);
2993 }
2994 spin_unlock(&compressor_list_lock);
2995}
2996
2997/* Find a compressor. */
2998static struct compressor *
2999find_compressor(int type)
3000{
3001 struct compressor_entry *ce;
3002 struct compressor *cp = NULL;
3003
3004 spin_lock(&compressor_list_lock);
3005 ce = find_comp_entry(type);
Joe Perchescd228d52007-11-12 18:07:31 -08003006 if (ce) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 cp = ce->comp;
3008 if (!try_module_get(cp->owner))
3009 cp = NULL;
3010 }
3011 spin_unlock(&compressor_list_lock);
3012 return cp;
3013}
3014
3015/*
3016 * Miscelleneous stuff.
3017 */
3018
3019static void
3020ppp_get_stats(struct ppp *ppp, struct ppp_stats *st)
3021{
3022 struct slcompress *vj = ppp->vj;
3023
3024 memset(st, 0, sizeof(*st));
Kevin Groenevelde51f6ff2012-07-27 17:38:53 +00003025 st->p.ppp_ipackets = ppp->stats64.rx_packets;
Paulius Zaleckas8c0469c2008-04-23 18:54:01 -07003026 st->p.ppp_ierrors = ppp->dev->stats.rx_errors;
Kevin Groenevelde51f6ff2012-07-27 17:38:53 +00003027 st->p.ppp_ibytes = ppp->stats64.rx_bytes;
3028 st->p.ppp_opackets = ppp->stats64.tx_packets;
Paulius Zaleckas8c0469c2008-04-23 18:54:01 -07003029 st->p.ppp_oerrors = ppp->dev->stats.tx_errors;
Kevin Groenevelde51f6ff2012-07-27 17:38:53 +00003030 st->p.ppp_obytes = ppp->stats64.tx_bytes;
Joe Perchescd228d52007-11-12 18:07:31 -08003031 if (!vj)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 return;
3033 st->vj.vjs_packets = vj->sls_o_compressed + vj->sls_o_uncompressed;
3034 st->vj.vjs_compressed = vj->sls_o_compressed;
3035 st->vj.vjs_searches = vj->sls_o_searches;
3036 st->vj.vjs_misses = vj->sls_o_misses;
3037 st->vj.vjs_errorin = vj->sls_i_error;
3038 st->vj.vjs_tossed = vj->sls_i_tossed;
3039 st->vj.vjs_uncompressedin = vj->sls_i_uncompressed;
3040 st->vj.vjs_compressedin = vj->sls_i_compressed;
3041}
3042
3043/*
3044 * Stuff for handling the lists of ppp units and channels
3045 * and for initialization.
3046 */
3047
3048/*
3049 * Create a new ppp interface unit. Fails if it can't allocate memory
3050 * or if there is already a unit with the requested number.
3051 * unit == -1 means allocate a new number.
3052 */
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02003053static int ppp_create_interface(struct net *net, struct file *file, int *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054{
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02003055 struct ppp_config conf = {
3056 .file = file,
3057 .unit = *unit,
Guillaume Nault96d934c2016-04-28 17:55:30 +02003058 .ifname_is_set = false,
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02003059 };
3060 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 struct ppp *ppp;
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02003062 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063
Guillaume Nault69d97282015-12-11 19:54:52 +01003064 dev = alloc_netdev(sizeof(struct ppp), "", NET_NAME_ENUM, ppp_setup);
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02003065 if (!dev) {
3066 err = -ENOMEM;
3067 goto err;
3068 }
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08003069 dev_net_set(dev, net);
Guillaume Nault96d934c2016-04-28 17:55:30 +02003070 dev->rtnl_link_ops = &ppp_link_ops;
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08003071
Guillaume Nault58a89ec2015-09-24 12:54:01 +02003072 rtnl_lock();
Cyrill Gorcunov7a95d262008-12-17 00:34:06 -08003073
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02003074 err = ppp_dev_configure(net, dev, &conf);
3075 if (err < 0)
3076 goto err_dev;
3077 ppp = netdev_priv(dev);
3078 *unit = ppp->file.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079
Guillaume Nault58a89ec2015-09-24 12:54:01 +02003080 rtnl_unlock();
Cyrill Gorcunov7a95d262008-12-17 00:34:06 -08003081
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02003082 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02003084err_dev:
Guillaume Nault6faac632016-03-07 19:36:44 +01003085 rtnl_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 free_netdev(dev);
Guillaume Nault7d9f0b42016-04-28 17:55:28 +02003087err:
3088 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089}
3090
3091/*
3092 * Initialize a ppp_file structure.
3093 */
3094static void
3095init_ppp_file(struct ppp_file *pf, int kind)
3096{
3097 pf->kind = kind;
3098 skb_queue_head_init(&pf->xq);
3099 skb_queue_head_init(&pf->rq);
3100 atomic_set(&pf->refcnt, 1);
3101 init_waitqueue_head(&pf->rwait);
3102}
3103
3104/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 * Free the memory used by a ppp unit. This is only called once
3106 * there are no channels connected to the unit and no file structs
3107 * that reference the unit.
3108 */
3109static void ppp_destroy_interface(struct ppp *ppp)
3110{
3111 atomic_dec(&ppp_unit_count);
3112
3113 if (!ppp->file.dead || ppp->n_channels) {
3114 /* "can't happen" */
David S. Millerb48f8c22011-01-20 22:44:36 -08003115 netdev_err(ppp->dev, "ppp: destroying ppp struct %p "
3116 "but dead=%d n_channels=%d !\n",
3117 ppp, ppp->file.dead, ppp->n_channels);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 return;
3119 }
3120
3121 ppp_ccp_closed(ppp);
3122 if (ppp->vj) {
3123 slhc_free(ppp->vj);
3124 ppp->vj = NULL;
3125 }
3126 skb_queue_purge(&ppp->file.xq);
3127 skb_queue_purge(&ppp->file.rq);
3128#ifdef CONFIG_PPP_MULTILINK
3129 skb_queue_purge(&ppp->mrq);
3130#endif /* CONFIG_PPP_MULTILINK */
3131#ifdef CONFIG_PPP_FILTER
Daniel Borkmann568f1942014-03-28 18:58:23 +01003132 if (ppp->pass_filter) {
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07003133 bpf_prog_destroy(ppp->pass_filter);
Daniel Borkmann568f1942014-03-28 18:58:23 +01003134 ppp->pass_filter = NULL;
3135 }
3136
3137 if (ppp->active_filter) {
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07003138 bpf_prog_destroy(ppp->active_filter);
Daniel Borkmann568f1942014-03-28 18:58:23 +01003139 ppp->active_filter = NULL;
3140 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141#endif /* CONFIG_PPP_FILTER */
3142
Wei Yongjun1d2f8c92009-02-25 00:16:08 +00003143 kfree_skb(ppp->xmit_pending);
Gao Feng3b25bfc2017-07-17 18:34:42 +08003144 free_percpu(ppp->xmit_recursion);
G. Liakhovetski165de5b2007-03-25 19:04:09 -07003145
James Chapman739840d2008-12-17 12:02:16 +00003146 free_netdev(ppp->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147}
3148
3149/*
3150 * Locate an existing ppp unit.
Arjan van de Ven8ed965d2006-03-23 03:00:21 -08003151 * The caller should have locked the all_ppp_mutex.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 */
3153static struct ppp *
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08003154ppp_find_unit(struct ppp_net *pn, int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155{
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08003156 return unit_find(&pn->units_idr, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157}
3158
3159/*
3160 * Locate an existing ppp channel.
3161 * The caller should have locked the all_channels_lock.
3162 * First we look in the new_channels list, then in the
3163 * all_channels list. If found in the new_channels list,
3164 * we move it to the all_channels list. This is for speed
3165 * when we have a lot of channels in use.
3166 */
3167static struct channel *
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08003168ppp_find_channel(struct ppp_net *pn, int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169{
3170 struct channel *pch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08003172 list_for_each_entry(pch, &pn->new_channels, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 if (pch->file.index == unit) {
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08003174 list_move(&pch->list, &pn->all_channels);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 return pch;
3176 }
3177 }
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08003178
3179 list_for_each_entry(pch, &pn->all_channels, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 if (pch->file.index == unit)
3181 return pch;
3182 }
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08003183
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 return NULL;
3185}
3186
3187/*
3188 * Connect a PPP channel to a PPP interface unit.
3189 */
3190static int
3191ppp_connect_channel(struct channel *pch, int unit)
3192{
3193 struct ppp *ppp;
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08003194 struct ppp_net *pn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 int ret = -ENXIO;
3196 int hdrlen;
3197
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08003198 pn = ppp_pernet(pch->chan_net);
3199
3200 mutex_lock(&pn->all_ppp_mutex);
3201 ppp = ppp_find_unit(pn, unit);
Joe Perchescd228d52007-11-12 18:07:31 -08003202 if (!ppp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 goto out;
3204 write_lock_bh(&pch->upl);
3205 ret = -EINVAL;
Joe Perchescd228d52007-11-12 18:07:31 -08003206 if (pch->ppp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 goto outl;
3208
3209 ppp_lock(ppp);
Guillaume Nault3741c8f2018-03-02 18:41:16 +01003210 spin_lock_bh(&pch->downl);
3211 if (!pch->chan) {
3212 /* Don't connect unregistered channels */
3213 spin_unlock_bh(&pch->downl);
3214 ppp_unlock(ppp);
3215 ret = -ENOTCONN;
3216 goto outl;
3217 }
3218 spin_unlock_bh(&pch->downl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 if (pch->file.hdrlen > ppp->file.hdrlen)
3220 ppp->file.hdrlen = pch->file.hdrlen;
3221 hdrlen = pch->file.hdrlen + 2; /* for protocol bytes */
James Chapman739840d2008-12-17 12:02:16 +00003222 if (hdrlen > ppp->dev->hard_header_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 ppp->dev->hard_header_len = hdrlen;
3224 list_add_tail(&pch->clist, &ppp->channels);
3225 ++ppp->n_channels;
3226 pch->ppp = ppp;
3227 atomic_inc(&ppp->file.refcnt);
3228 ppp_unlock(ppp);
3229 ret = 0;
3230
3231 outl:
3232 write_unlock_bh(&pch->upl);
3233 out:
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08003234 mutex_unlock(&pn->all_ppp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 return ret;
3236}
3237
3238/*
3239 * Disconnect a channel from its ppp unit.
3240 */
3241static int
3242ppp_disconnect_channel(struct channel *pch)
3243{
3244 struct ppp *ppp;
3245 int err = -EINVAL;
3246
3247 write_lock_bh(&pch->upl);
3248 ppp = pch->ppp;
3249 pch->ppp = NULL;
3250 write_unlock_bh(&pch->upl);
Joe Perchescd228d52007-11-12 18:07:31 -08003251 if (ppp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252 /* remove it from the ppp unit's list */
3253 ppp_lock(ppp);
3254 list_del(&pch->clist);
3255 if (--ppp->n_channels == 0)
3256 wake_up_interruptible(&ppp->file.rwait);
3257 ppp_unlock(ppp);
3258 if (atomic_dec_and_test(&ppp->file.refcnt))
3259 ppp_destroy_interface(ppp);
3260 err = 0;
3261 }
3262 return err;
3263}
3264
3265/*
3266 * Free up the resources used by a ppp channel.
3267 */
3268static void ppp_destroy_channel(struct channel *pch)
3269{
WANG Cong205e1e22016-07-05 22:12:36 -07003270 put_net(pch->chan_net);
3271 pch->chan_net = NULL;
3272
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 atomic_dec(&channel_count);
3274
3275 if (!pch->file.dead) {
3276 /* "can't happen" */
David S. Millerb48f8c22011-01-20 22:44:36 -08003277 pr_err("ppp: destroying undead channel %p !\n", pch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 return;
3279 }
3280 skb_queue_purge(&pch->file.xq);
3281 skb_queue_purge(&pch->file.rq);
3282 kfree(pch);
3283}
3284
3285static void __exit ppp_cleanup(void)
3286{
3287 /* should never happen */
3288 if (atomic_read(&ppp_unit_count) || atomic_read(&channel_count))
David S. Millerb48f8c22011-01-20 22:44:36 -08003289 pr_err("PPP: removing module but units remain!\n");
Guillaume Nault96d934c2016-04-28 17:55:30 +02003290 rtnl_link_unregister(&ppp_link_ops);
Akinobu Mita68fc4fa2007-07-19 01:47:50 -07003291 unregister_chrdev(PPP_MAJOR, "ppp");
Greg Kroah-Hartman9a6a2a52006-09-12 17:00:10 +02003292 device_destroy(ppp_class, MKDEV(PPP_MAJOR, 0));
gregkh@suse.de56b22932005-03-23 10:01:41 -08003293 class_destroy(ppp_class);
Eric W. Biederman741a6fa2009-11-29 15:46:09 +00003294 unregister_pernet_device(&ppp_net_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295}
3296
3297/*
Cyrill Gorcunov7a95d262008-12-17 00:34:06 -08003298 * Units handling. Caller must protect concurrent access
3299 * by holding all_ppp_mutex
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301
Cyrill Gorcunovbcc70bb2010-11-23 11:43:44 +00003302/* associate pointer with specified number */
3303static int unit_set(struct idr *p, void *ptr, int n)
3304{
3305 int unit;
3306
Tejun Heo2fa532c2013-02-27 17:04:36 -08003307 unit = idr_alloc(p, ptr, n, n + 1, GFP_KERNEL);
3308 if (unit == -ENOSPC)
3309 unit = -EINVAL;
Cyrill Gorcunov85997572009-01-12 22:11:56 -08003310 return unit;
3311}
3312
Cyrill Gorcunov7a95d262008-12-17 00:34:06 -08003313/* get new free unit number and associate pointer with it */
3314static int unit_get(struct idr *p, void *ptr)
3315{
Tejun Heo2fa532c2013-02-27 17:04:36 -08003316 return idr_alloc(p, ptr, 0, 0, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317}
3318
Cyrill Gorcunov7a95d262008-12-17 00:34:06 -08003319/* put unit number back to a pool */
3320static void unit_put(struct idr *p, int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321{
Cyrill Gorcunov7a95d262008-12-17 00:34:06 -08003322 idr_remove(p, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323}
3324
Cyrill Gorcunov7a95d262008-12-17 00:34:06 -08003325/* get pointer associated with the number */
3326static void *unit_find(struct idr *p, int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327{
Cyrill Gorcunov7a95d262008-12-17 00:34:06 -08003328 return idr_find(p, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329}
3330
3331/* Module/initialization stuff */
3332
3333module_init(ppp_init);
3334module_exit(ppp_cleanup);
3335
Cyrill Gorcunov273ec512009-01-21 15:55:35 -08003336EXPORT_SYMBOL(ppp_register_net_channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337EXPORT_SYMBOL(ppp_register_channel);
3338EXPORT_SYMBOL(ppp_unregister_channel);
3339EXPORT_SYMBOL(ppp_channel_index);
3340EXPORT_SYMBOL(ppp_unit_number);
James Chapman63f96072010-04-02 06:18:39 +00003341EXPORT_SYMBOL(ppp_dev_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342EXPORT_SYMBOL(ppp_input);
3343EXPORT_SYMBOL(ppp_input_error);
3344EXPORT_SYMBOL(ppp_output_wakeup);
3345EXPORT_SYMBOL(ppp_register_compressor);
3346EXPORT_SYMBOL(ppp_unregister_compressor);
3347MODULE_LICENSE("GPL");
Kay Sievers578454f2010-05-20 18:07:20 +02003348MODULE_ALIAS_CHARDEV(PPP_MAJOR, 0);
Guillaume Nault96d934c2016-04-28 17:55:30 +02003349MODULE_ALIAS_RTNL_LINK("ppp");
Kay Sievers578454f2010-05-20 18:07:20 +02003350MODULE_ALIAS("devname:ppp");