Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0
0002 
0003 ========================================
0004 PPP Generic Driver and Channel Interface
0005 ========================================
0006 
0007                            Paul Mackerras
0008                            paulus@samba.org
0009 
0010                               7 Feb 2002
0011 
0012 The generic PPP driver in linux-2.4 provides an implementation of the
0013 functionality which is of use in any PPP implementation, including:
0014 
0015 * the network interface unit (ppp0 etc.)
0016 * the interface to the networking code
0017 * PPP multilink: splitting datagrams between multiple links, and
0018   ordering and combining received fragments
0019 * the interface to pppd, via a /dev/ppp character device
0020 * packet compression and decompression
0021 * TCP/IP header compression and decompression
0022 * detecting network traffic for demand dialling and for idle timeouts
0023 * simple packet filtering
0024 
0025 For sending and receiving PPP frames, the generic PPP driver calls on
0026 the services of PPP ``channels``.  A PPP channel encapsulates a
0027 mechanism for transporting PPP frames from one machine to another.  A
0028 PPP channel implementation can be arbitrarily complex internally but
0029 has a very simple interface with the generic PPP code: it merely has
0030 to be able to send PPP frames, receive PPP frames, and optionally
0031 handle ioctl requests.  Currently there are PPP channel
0032 implementations for asynchronous serial ports, synchronous serial
0033 ports, and for PPP over ethernet.
0034 
0035 This architecture makes it possible to implement PPP multilink in a
0036 natural and straightforward way, by allowing more than one channel to
0037 be linked to each ppp network interface unit.  The generic layer is
0038 responsible for splitting datagrams on transmit and recombining them
0039 on receive.
0040 
0041 
0042 PPP channel API
0043 ---------------
0044 
0045 See include/linux/ppp_channel.h for the declaration of the types and
0046 functions used to communicate between the generic PPP layer and PPP
0047 channels.
0048 
0049 Each channel has to provide two functions to the generic PPP layer,
0050 via the ppp_channel.ops pointer:
0051 
0052 * start_xmit() is called by the generic layer when it has a frame to
0053   send.  The channel has the option of rejecting the frame for
0054   flow-control reasons.  In this case, start_xmit() should return 0
0055   and the channel should call the ppp_output_wakeup() function at a
0056   later time when it can accept frames again, and the generic layer
0057   will then attempt to retransmit the rejected frame(s).  If the frame
0058   is accepted, the start_xmit() function should return 1.
0059 
0060 * ioctl() provides an interface which can be used by a user-space
0061   program to control aspects of the channel's behaviour.  This
0062   procedure will be called when a user-space program does an ioctl
0063   system call on an instance of /dev/ppp which is bound to the
0064   channel.  (Usually it would only be pppd which would do this.)
0065 
0066 The generic PPP layer provides seven functions to channels:
0067 
0068 * ppp_register_channel() is called when a channel has been created, to
0069   notify the PPP generic layer of its presence.  For example, setting
0070   a serial port to the PPPDISC line discipline causes the ppp_async
0071   channel code to call this function.
0072 
0073 * ppp_unregister_channel() is called when a channel is to be
0074   destroyed.  For example, the ppp_async channel code calls this when
0075   a hangup is detected on the serial port.
0076 
0077 * ppp_output_wakeup() is called by a channel when it has previously
0078   rejected a call to its start_xmit function, and can now accept more
0079   packets.
0080 
0081 * ppp_input() is called by a channel when it has received a complete
0082   PPP frame.
0083 
0084 * ppp_input_error() is called by a channel when it has detected that a
0085   frame has been lost or dropped (for example, because of a FCS (frame
0086   check sequence) error).
0087 
0088 * ppp_channel_index() returns the channel index assigned by the PPP
0089   generic layer to this channel.  The channel should provide some way
0090   (e.g. an ioctl) to transmit this back to user-space, as user-space
0091   will need it to attach an instance of /dev/ppp to this channel.
0092 
0093 * ppp_unit_number() returns the unit number of the ppp network
0094   interface to which this channel is connected, or -1 if the channel
0095   is not connected.
0096 
0097 Connecting a channel to the ppp generic layer is initiated from the
0098 channel code, rather than from the generic layer.  The channel is
0099 expected to have some way for a user-level process to control it
0100 independently of the ppp generic layer.  For example, with the
0101 ppp_async channel, this is provided by the file descriptor to the
0102 serial port.
0103 
0104 Generally a user-level process will initialize the underlying
0105 communications medium and prepare it to do PPP.  For example, with an
0106 async tty, this can involve setting the tty speed and modes, issuing
0107 modem commands, and then going through some sort of dialog with the
0108 remote system to invoke PPP service there.  We refer to this process
0109 as ``discovery``.  Then the user-level process tells the medium to
0110 become a PPP channel and register itself with the generic PPP layer.
0111 The channel then has to report the channel number assigned to it back
0112 to the user-level process.  From that point, the PPP negotiation code
0113 in the PPP daemon (pppd) can take over and perform the PPP
0114 negotiation, accessing the channel through the /dev/ppp interface.
0115 
0116 At the interface to the PPP generic layer, PPP frames are stored in
0117 skbuff structures and start with the two-byte PPP protocol number.
0118 The frame does *not* include the 0xff ``address`` byte or the 0x03
0119 ``control`` byte that are optionally used in async PPP.  Nor is there
0120 any escaping of control characters, nor are there any FCS or framing
0121 characters included.  That is all the responsibility of the channel
0122 code, if it is needed for the particular medium.  That is, the skbuffs
0123 presented to the start_xmit() function contain only the 2-byte
0124 protocol number and the data, and the skbuffs presented to ppp_input()
0125 must be in the same format.
0126 
0127 The channel must provide an instance of a ppp_channel struct to
0128 represent the channel.  The channel is free to use the ``private`` field
0129 however it wishes.  The channel should initialize the ``mtu`` and
0130 ``hdrlen`` fields before calling ppp_register_channel() and not change
0131 them until after ppp_unregister_channel() returns.  The ``mtu`` field
0132 represents the maximum size of the data part of the PPP frames, that
0133 is, it does not include the 2-byte protocol number.
0134 
0135 If the channel needs some headroom in the skbuffs presented to it for
0136 transmission (i.e., some space free in the skbuff data area before the
0137 start of the PPP frame), it should set the ``hdrlen`` field of the
0138 ppp_channel struct to the amount of headroom required.  The generic
0139 PPP layer will attempt to provide that much headroom but the channel
0140 should still check if there is sufficient headroom and copy the skbuff
0141 if there isn't.
0142 
0143 On the input side, channels should ideally provide at least 2 bytes of
0144 headroom in the skbuffs presented to ppp_input().  The generic PPP
0145 code does not require this but will be more efficient if this is done.
0146 
0147 
0148 Buffering and flow control
0149 --------------------------
0150 
0151 The generic PPP layer has been designed to minimize the amount of data
0152 that it buffers in the transmit direction.  It maintains a queue of
0153 transmit packets for the PPP unit (network interface device) plus a
0154 queue of transmit packets for each attached channel.  Normally the
0155 transmit queue for the unit will contain at most one packet; the
0156 exceptions are when pppd sends packets by writing to /dev/ppp, and
0157 when the core networking code calls the generic layer's start_xmit()
0158 function with the queue stopped, i.e. when the generic layer has
0159 called netif_stop_queue(), which only happens on a transmit timeout.
0160 The start_xmit function always accepts and queues the packet which it
0161 is asked to transmit.
0162 
0163 Transmit packets are dequeued from the PPP unit transmit queue and
0164 then subjected to TCP/IP header compression and packet compression
0165 (Deflate or BSD-Compress compression), as appropriate.  After this
0166 point the packets can no longer be reordered, as the decompression
0167 algorithms rely on receiving compressed packets in the same order that
0168 they were generated.
0169 
0170 If multilink is not in use, this packet is then passed to the attached
0171 channel's start_xmit() function.  If the channel refuses to take
0172 the packet, the generic layer saves it for later transmission.  The
0173 generic layer will call the channel's start_xmit() function again
0174 when the channel calls  ppp_output_wakeup() or when the core
0175 networking code calls the generic layer's start_xmit() function
0176 again.  The generic layer contains no timeout and retransmission
0177 logic; it relies on the core networking code for that.
0178 
0179 If multilink is in use, the generic layer divides the packet into one
0180 or more fragments and puts a multilink header on each fragment.  It
0181 decides how many fragments to use based on the length of the packet
0182 and the number of channels which are potentially able to accept a
0183 fragment at the moment.  A channel is potentially able to accept a
0184 fragment if it doesn't have any fragments currently queued up for it
0185 to transmit.  The channel may still refuse a fragment; in this case
0186 the fragment is queued up for the channel to transmit later.  This
0187 scheme has the effect that more fragments are given to higher-
0188 bandwidth channels.  It also means that under light load, the generic
0189 layer will tend to fragment large packets across all the channels,
0190 thus reducing latency, while under heavy load, packets will tend to be
0191 transmitted as single fragments, thus reducing the overhead of
0192 fragmentation.
0193 
0194 
0195 SMP safety
0196 ----------
0197 
0198 The PPP generic layer has been designed to be SMP-safe.  Locks are
0199 used around accesses to the internal data structures where necessary
0200 to ensure their integrity.  As part of this, the generic layer
0201 requires that the channels adhere to certain requirements and in turn
0202 provides certain guarantees to the channels.  Essentially the channels
0203 are required to provide the appropriate locking on the ppp_channel
0204 structures that form the basis of the communication between the
0205 channel and the generic layer.  This is because the channel provides
0206 the storage for the ppp_channel structure, and so the channel is
0207 required to provide the guarantee that this storage exists and is
0208 valid at the appropriate times.
0209 
0210 The generic layer requires these guarantees from the channel:
0211 
0212 * The ppp_channel object must exist from the time that
0213   ppp_register_channel() is called until after the call to
0214   ppp_unregister_channel() returns.
0215 
0216 * No thread may be in a call to any of ppp_input(), ppp_input_error(),
0217   ppp_output_wakeup(), ppp_channel_index() or ppp_unit_number() for a
0218   channel at the time that ppp_unregister_channel() is called for that
0219   channel.
0220 
0221 * ppp_register_channel() and ppp_unregister_channel() must be called
0222   from process context, not interrupt or softirq/BH context.
0223 
0224 * The remaining generic layer functions may be called at softirq/BH
0225   level but must not be called from a hardware interrupt handler.
0226 
0227 * The generic layer may call the channel start_xmit() function at
0228   softirq/BH level but will not call it at interrupt level.  Thus the
0229   start_xmit() function may not block.
0230 
0231 * The generic layer will only call the channel ioctl() function in
0232   process context.
0233 
0234 The generic layer provides these guarantees to the channels:
0235 
0236 * The generic layer will not call the start_xmit() function for a
0237   channel while any thread is already executing in that function for
0238   that channel.
0239 
0240 * The generic layer will not call the ioctl() function for a channel
0241   while any thread is already executing in that function for that
0242   channel.
0243 
0244 * By the time a call to ppp_unregister_channel() returns, no thread
0245   will be executing in a call from the generic layer to that channel's
0246   start_xmit() or ioctl() function, and the generic layer will not
0247   call either of those functions subsequently.
0248 
0249 
0250 Interface to pppd
0251 -----------------
0252 
0253 The PPP generic layer exports a character device interface called
0254 /dev/ppp.  This is used by pppd to control PPP interface units and
0255 channels.  Although there is only one /dev/ppp, each open instance of
0256 /dev/ppp acts independently and can be attached either to a PPP unit
0257 or a PPP channel.  This is achieved using the file->private_data field
0258 to point to a separate object for each open instance of /dev/ppp.  In
0259 this way an effect similar to Solaris' clone open is obtained,
0260 allowing us to control an arbitrary number of PPP interfaces and
0261 channels without having to fill up /dev with hundreds of device names.
0262 
0263 When /dev/ppp is opened, a new instance is created which is initially
0264 unattached.  Using an ioctl call, it can then be attached to an
0265 existing unit, attached to a newly-created unit, or attached to an
0266 existing channel.  An instance attached to a unit can be used to send
0267 and receive PPP control frames, using the read() and write() system
0268 calls, along with poll() if necessary.  Similarly, an instance
0269 attached to a channel can be used to send and receive PPP frames on
0270 that channel.
0271 
0272 In multilink terms, the unit represents the bundle, while the channels
0273 represent the individual physical links.  Thus, a PPP frame sent by a
0274 write to the unit (i.e., to an instance of /dev/ppp attached to the
0275 unit) will be subject to bundle-level compression and to fragmentation
0276 across the individual links (if multilink is in use).  In contrast, a
0277 PPP frame sent by a write to the channel will be sent as-is on that
0278 channel, without any multilink header.
0279 
0280 A channel is not initially attached to any unit.  In this state it can
0281 be used for PPP negotiation but not for the transfer of data packets.
0282 It can then be connected to a PPP unit with an ioctl call, which
0283 makes it available to send and receive data packets for that unit.
0284 
0285 The ioctl calls which are available on an instance of /dev/ppp depend
0286 on whether it is unattached, attached to a PPP interface, or attached
0287 to a PPP channel.  The ioctl calls which are available on an
0288 unattached instance are:
0289 
0290 * PPPIOCNEWUNIT creates a new PPP interface and makes this /dev/ppp
0291   instance the "owner" of the interface.  The argument should point to
0292   an int which is the desired unit number if >= 0, or -1 to assign the
0293   lowest unused unit number.  Being the owner of the interface means
0294   that the interface will be shut down if this instance of /dev/ppp is
0295   closed.
0296 
0297 * PPPIOCATTACH attaches this instance to an existing PPP interface.
0298   The argument should point to an int containing the unit number.
0299   This does not make this instance the owner of the PPP interface.
0300 
0301 * PPPIOCATTCHAN attaches this instance to an existing PPP channel.
0302   The argument should point to an int containing the channel number.
0303 
0304 The ioctl calls available on an instance of /dev/ppp attached to a
0305 channel are:
0306 
0307 * PPPIOCCONNECT connects this channel to a PPP interface.  The
0308   argument should point to an int containing the interface unit
0309   number.  It will return an EINVAL error if the channel is already
0310   connected to an interface, or ENXIO if the requested interface does
0311   not exist.
0312 
0313 * PPPIOCDISCONN disconnects this channel from the PPP interface that
0314   it is connected to.  It will return an EINVAL error if the channel
0315   is not connected to an interface.
0316 
0317 * PPPIOCBRIDGECHAN bridges a channel with another. The argument should
0318   point to an int containing the channel number of the channel to bridge
0319   to. Once two channels are bridged, frames presented to one channel by
0320   ppp_input() are passed to the bridge instance for onward transmission.
0321   This allows frames to be switched from one channel into another: for
0322   example, to pass PPPoE frames into a PPPoL2TP session. Since channel
0323   bridging interrupts the normal ppp_input() path, a given channel may
0324   not be part of a bridge at the same time as being part of a unit.
0325   This ioctl will return an EALREADY error if the channel is already
0326   part of a bridge or unit, or ENXIO if the requested channel does not
0327   exist.
0328 
0329 * PPPIOCUNBRIDGECHAN performs the inverse of PPPIOCBRIDGECHAN, unbridging
0330   a channel pair.  This ioctl will return an EINVAL error if the channel
0331   does not form part of a bridge.
0332 
0333 * All other ioctl commands are passed to the channel ioctl() function.
0334 
0335 The ioctl calls that are available on an instance that is attached to
0336 an interface unit are:
0337 
0338 * PPPIOCSMRU sets the MRU (maximum receive unit) for the interface.
0339   The argument should point to an int containing the new MRU value.
0340 
0341 * PPPIOCSFLAGS sets flags which control the operation of the
0342   interface.  The argument should be a pointer to an int containing
0343   the new flags value.  The bits in the flags value that can be set
0344   are:
0345 
0346         ================        ========================================
0347         SC_COMP_TCP             enable transmit TCP header compression
0348         SC_NO_TCP_CCID          disable connection-id compression for
0349                                 TCP header compression
0350         SC_REJ_COMP_TCP         disable receive TCP header decompression
0351         SC_CCP_OPEN             Compression Control Protocol (CCP) is
0352                                 open, so inspect CCP packets
0353         SC_CCP_UP               CCP is up, may (de)compress packets
0354         SC_LOOP_TRAFFIC         send IP traffic to pppd
0355         SC_MULTILINK            enable PPP multilink fragmentation on
0356                                 transmitted packets
0357         SC_MP_SHORTSEQ          expect short multilink sequence
0358                                 numbers on received multilink fragments
0359         SC_MP_XSHORTSEQ         transmit short multilink sequence nos.
0360         ================        ========================================
0361 
0362   The values of these flags are defined in <linux/ppp-ioctl.h>.  Note
0363   that the values of the SC_MULTILINK, SC_MP_SHORTSEQ and
0364   SC_MP_XSHORTSEQ bits are ignored if the CONFIG_PPP_MULTILINK option
0365   is not selected.
0366 
0367 * PPPIOCGFLAGS returns the value of the status/control flags for the
0368   interface unit.  The argument should point to an int where the ioctl
0369   will store the flags value.  As well as the values listed above for
0370   PPPIOCSFLAGS, the following bits may be set in the returned value:
0371 
0372         ================        =========================================
0373         SC_COMP_RUN             CCP compressor is running
0374         SC_DECOMP_RUN           CCP decompressor is running
0375         SC_DC_ERROR             CCP decompressor detected non-fatal error
0376         SC_DC_FERROR            CCP decompressor detected fatal error
0377         ================        =========================================
0378 
0379 * PPPIOCSCOMPRESS sets the parameters for packet compression or
0380   decompression.  The argument should point to a ppp_option_data
0381   structure (defined in <linux/ppp-ioctl.h>), which contains a
0382   pointer/length pair which should describe a block of memory
0383   containing a CCP option specifying a compression method and its
0384   parameters.  The ppp_option_data struct also contains a ``transmit``
0385   field.  If this is 0, the ioctl will affect the receive path,
0386   otherwise the transmit path.
0387 
0388 * PPPIOCGUNIT returns, in the int pointed to by the argument, the unit
0389   number of this interface unit.
0390 
0391 * PPPIOCSDEBUG sets the debug flags for the interface to the value in
0392   the int pointed to by the argument.  Only the least significant bit
0393   is used; if this is 1 the generic layer will print some debug
0394   messages during its operation.  This is only intended for debugging
0395   the generic PPP layer code; it is generally not helpful for working
0396   out why a PPP connection is failing.
0397 
0398 * PPPIOCGDEBUG returns the debug flags for the interface in the int
0399   pointed to by the argument.
0400 
0401 * PPPIOCGIDLE returns the time, in seconds, since the last data
0402   packets were sent and received.  The argument should point to a
0403   ppp_idle structure (defined in <linux/ppp_defs.h>).  If the
0404   CONFIG_PPP_FILTER option is enabled, the set of packets which reset
0405   the transmit and receive idle timers is restricted to those which
0406   pass the ``active`` packet filter.
0407   Two versions of this command exist, to deal with user space
0408   expecting times as either 32-bit or 64-bit time_t seconds.
0409 
0410 * PPPIOCSMAXCID sets the maximum connection-ID parameter (and thus the
0411   number of connection slots) for the TCP header compressor and
0412   decompressor.  The lower 16 bits of the int pointed to by the
0413   argument specify the maximum connection-ID for the compressor.  If
0414   the upper 16 bits of that int are non-zero, they specify the maximum
0415   connection-ID for the decompressor, otherwise the decompressor's
0416   maximum connection-ID is set to 15.
0417 
0418 * PPPIOCSNPMODE sets the network-protocol mode for a given network
0419   protocol.  The argument should point to an npioctl struct (defined
0420   in <linux/ppp-ioctl.h>).  The ``protocol`` field gives the PPP protocol
0421   number for the protocol to be affected, and the ``mode`` field
0422   specifies what to do with packets for that protocol:
0423 
0424         =============   ==============================================
0425         NPMODE_PASS     normal operation, transmit and receive packets
0426         NPMODE_DROP     silently drop packets for this protocol
0427         NPMODE_ERROR    drop packets and return an error on transmit
0428         NPMODE_QUEUE    queue up packets for transmit, drop received
0429                         packets
0430         =============   ==============================================
0431 
0432   At present NPMODE_ERROR and NPMODE_QUEUE have the same effect as
0433   NPMODE_DROP.
0434 
0435 * PPPIOCGNPMODE returns the network-protocol mode for a given
0436   protocol.  The argument should point to an npioctl struct with the
0437   ``protocol`` field set to the PPP protocol number for the protocol of
0438   interest.  On return the ``mode`` field will be set to the network-
0439   protocol mode for that protocol.
0440 
0441 * PPPIOCSPASS and PPPIOCSACTIVE set the ``pass`` and ``active`` packet
0442   filters.  These ioctls are only available if the CONFIG_PPP_FILTER
0443   option is selected.  The argument should point to a sock_fprog
0444   structure (defined in <linux/filter.h>) containing the compiled BPF
0445   instructions for the filter.  Packets are dropped if they fail the
0446   ``pass`` filter; otherwise, if they fail the ``active`` filter they are
0447   passed but they do not reset the transmit or receive idle timer.
0448 
0449 * PPPIOCSMRRU enables or disables multilink processing for received
0450   packets and sets the multilink MRRU (maximum reconstructed receive
0451   unit).  The argument should point to an int containing the new MRRU
0452   value.  If the MRRU value is 0, processing of received multilink
0453   fragments is disabled.  This ioctl is only available if the
0454   CONFIG_PPP_MULTILINK option is selected.
0455 
0456 Last modified: 7-feb-2002