L2tp flow
来源:互联网 发布:数据库的安全性设计 编辑:程序博客网 时间:2024/05/16 04:27
1 主要模块
(1) l2tpd deamon
(2) pppd deamon
(3) ppp driver module
(4) fast forward module
(5) protocol stack
2 数据包收发流程
router 作为LAC端,与L2TP server进行连接。
(1) WAN------------------>LAN
1 l2tp协议控制封包
图1
l2tp 控制协议收发流程: 1->2->3->4
2 ppp相关协议封包
图2
ppp相关协议收发流程:1->2->3->4->5->6->7->8
3 data封包(封装在ppp)
图3
Data封包收发流程如下:1->2->3->4->5->6
当Ethernet driver 收到封包后,通过Protocol Stack将封包送到socket buffer, L2TPD deamon从socket读data ptk。若ptk是l2tp协议相关的,则l2tpd deamon自己处理,之后通过socket发送到Protocol Stack,最终通过Ethernet driver发送封包;若ptk是date封包和ppp控制封包,则将l2tp协议的header剥掉后,写到PTY device。之后,PPP Driver从PTY读ptk,通过ppp头来区分具体是IP data ptk还是ppp相关的ptk。若是PPP协议相关的,则由PPPD deamon来处理,PPPD会将control ptk 通过PPP Driver write到PTY,然后由L2TPD deamon从PTY read ptk,打上l2tp的header,通过socket将ptk发送到protocol Stack,最终通过ethernet driver 来发送;若是IP data ptk,则将data ptk送到 Protocol Stack,最终通过Ethernet driver发送。
(2) LAN ----------------->WAN
图4
LAN PC 发送ptk, router Ethernet driver收到ptk后,rx到Protocol Stack,查route,得到xmit的device是pppx,调用ppp的xmit函数,将ptk,打上ppp的头,之后将ptk write到PTY device,L2TPD deamon从PTY read ptk,打上l2tp header,通过socket tx到Protocol Stack,最终通过Ethernet driver TX出去。这样子从LAN PC发送的ptk发到router后,就会打上一层l2tp的包。最终通过driver发送出去。
3 数据包收发流程(开fast forward的数据收发流程)
(1) WAN------------------> lan
1 l2tp协议控制封包
如图1
2 ppp相关协议封包
如图2
3 data封包(封装在ppp)
图5
基于原来flow,在Ethernet driver Rx后,先将ptk送到Fast forward 模块,其他流程维持不变。若Fast forward模块可以将ptk转发,做完相关的NAT、NAPT之后,直接调用Ethernet driver,将ptk发送;若Fast forward模块无法将ptk转发,则执行之前的流程。
(2) LAN ----------------->WAN
图6
case 1:若fast forward能转,则1->2
case 2:若fastforward不能转,ppp driver能转,则1->3->4->5
case 3:若fastforward不能转,ppp driver不能转,则1->3->4->6->7->8->9
LAN PC通过router Ethernet driver rx到fast forward 模块。若fast forward能转发,则直接调用ppp的xmit函数。(l2tp的wan device 是pppx,故会调用ppp的xmit函数)。在ppp的xmit函数会将l2tp相关的ptk添加l2tp header、udp header、ip header,然后调用ethernet xmit函数发送ptk。这样子可以处理就不需要再将ptk收到上层的l2tpd deamon来处理,打l2tp的header,router 的转发效率会高很多。
---------------------------------------------------------------------------------------分割线--------------------------------------------------------------------------------------------------------------------
在上述实现过程中会用到raw socket,大概讲下自己的理解。
一定要在root下使用,原始套接字编程可以接收到本机网卡上的数据帧或者数据包,对监听网络的流量和分析是很有作用的.一共可以有3种方式创建这种socket
对于新的IP层协议,可以自定义新的类型,kernel可以自动识别。
socket(AF_INET, SOCK_RAW, L2TP_Type),这样子就可以接受IP protocol字段为L2TP_Type的封包,当然不包含传输层。socket收上来是完整的IP封装。
2.socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP|ETH_P_ARP|ETH_P_ALL))发送接收以太网数据帧
socket(PF_PACKET,SOCK_RAW,Eth_PPPOE_Discovery),这样子就可以接受ethernet type是Eth_PPPOE_Discovery的封包,这种socket需要在上层应用程序中处理完整的封包。发送的时候需要上层封装完整的ptk。
struct sockaddr_ll sll; // 注意结构体是sockaddr_ll
memset( &sll, 0, sizeof(sll) );
sll.sll_family = AF_PACKET;
struct ifreq ifstruct;
strcpy(ifstruct.ifr_name, "eth0");
ioctl(sockfd, SIOCGIFINDEX, &ifstruct); //控制I/O设备
sll.sll_ifindex = ifstruct.ifr_ifindex;
sll.sll_protocol = htons(ETH_P_ALL);
if(bind(fd, (struct sockaddr *) &sll, sizeof(sll)) == -1 ) { //在这里当然仍然需要绑定的
perror("bind()");
......
CSDN上写的第一篇blog,mark一下!
- L2tp flow
- L2TP
- L2TP
- L2TP
- l2tp
- L2TP
- flow
- flow
- flow
- flow
- flow
- flow
- L2TP&PPTP
- L2tp客户端
- L2TP配置
- L2TP介绍
- mpd5 l2tp
- L2TP VPN
- Hg Mercurial 邮件更新版本库
- 发布app到GoogLe Market教程
- showModalDialog的简单应用
- displaytag用法总结
- 0-1背包问题
- L2tp flow
- QTP_QTP 11.0 下载&安装&无限试用30天的暂时破解方法
- 系统的文件句柄数问题
- 毕业一周年
- iphone 界面实现下拉列表
- 瀑布流布局浅析
- centos 使用vsftpd问题
- The connection to adb is down, and a severe error has occured.解决办法
- linux ulimit命令调优系统参数