3.4 Point-to-Point Protocol(PPP)
它有三个组件:
一个封装上层协议的方法
Link Control Protocol(LCP):负责链接的建立和断开。
Network Control Protocol(NCP):负责配置不同网络层的选项。
3.4.1 PPP Operaton
数据包交互过程如下:
1、PPP首先发送LCP packets来建立连接和测试连接。
2、发起连接的一端需要进入认证阶段(该阶段是可选的)
3、然后PPP会发送NCP数据包来配置多个network layer protocols(网络层协议)
4、一旦配置完成,network-layer packets就可以在该PPP上传输了。
5、LCP负责断开PPP连接。
3.4.2 PPP frame
1、Flag用于定界frames,固定为“01111110”
2、Address:固定设为“11111111”
3、Control:固定为“00000011”
4、Protocol:指明上层协议,是IP or IPX,默认是16bits,可以通过LCP来协商成8bits
5、Information:最大长度默认为1500bytes
6、FCS:使用CRC,默认为16bits,通过LCP协商可扩展成32bits。重传机制由上层协议维护,如TCP。
Remark:PPP没有Flow Control,也没有Medium Access Control。
3.4.3 IPCP
IPCP是NCP的一种,在建立PPP连接并认证成功之后,用于配置IP protocol over PPP。
IPCP的配置项有:IP-Compression-Protocol, and IP-Address。
在IPCP的协商之后,IP packets就可以被封装在PPP中,协议号为0x0021
3.4.4 PPP Drivers
在Linux中,PPP的实现只要由2部分构成:data-plane PPP Driver and control-plane PPP daemon(PPPd)。PPP driver负责建立网络接口并传递数据包。PPPd负责认证、协商。
PPP driver由PPP generic layer和PPP channel driver构成。
在linux中有asynchronous and synchronous PPP drivers (对应 ppp_async.c and ppp_synctty.c under the drivers/net directory)。至于到底使用同步还是异步的PPP channel driver取决于您使用的物理卡是同步还是异步。
PPP driver所关联的I/O函数指针定义在tty_ldisc_ops 结构中。
Packet Transmission
要发送的packets被传送到ppp_start_xmit()中,在该函数中,数据包被封装上PPP header,然后将数据包入队到发送队列xq中(see the ppp_file structure in ppp_generic.c )。最后,ppp_start_xmit() 调用 ppp_xmit_process(),该函数将packets出xq队列,然后调用ppp_send_frame()来处理packets,如header compression,之后,ppp_send_frame()会调用ppp_async_send()(异步) , or ppp_sync_send()(同步)来发送数据包。
Packet Reception
不论是同步还是异步的driver将接收的数据包发送给ppp_input(),该函数将packets加入到接收队列rq中。最后,PPPd将从/dev/ppp中读取该packets。
3.4.5 PPPOE
PPPOE就是PPP协议被ETHERNET封装。它一共有两个stages:the Discovery stage and the PPP Session stage。
Discovery stage有如下4步:
1、station会广播初始化frame,来得到AC(就是PPP的server)的mac address。
2、一些AC用mac address作为回应。
3、Station会选择一个AC,并向他发送Session-Request frame。
4、该AC生成PPPOE的session id,然后返回一个包含session id的确认帧。
PPP session stage跟PPP的数据交互过程相同,参见3.4.1
[此为原创,转载请标明出处,谢谢!]