1. VPN related source code in froyo.
1.1 Java layer:
A. UI source code:
Packages/apps/settings/src/COM/Android/settings/VPN
B. VPN Server Source Code:
Frameworks/base/VPN/Java/Android/NET/VPN
Framework/base/packages/vpnservices/src/COM/Android/Server/VPN
1.2 native layer:
External/mtpd: used to control PPTP and L2TP modules.
External/IPSec-tools: used to configure IPSec.
Of cause, it will use pppd, which is in/external/PPP /.
1.3 driver layer:
Apart from the feature in standard Linux kernel, Google adds the below two files for PPTP and L2TP.
Driver/NET/pppopns. C: for PPP over PPTP.
Driver/NET/pppolac. C: for PPP over L2TP.
2. Java layer.
VPN Java layer is responsible for VPN configuration, it can be divided into two sub-layers, the upper layer is VPN settings, the lower layer is VPN service which is in framework.
VPN Java layer has two interfaces to impact native layer,
A. It uses daemon class to start/stop two daemons, these two daemons are: mtpd and racoon.
Mtpd is for PPTP and L2TP.
Racoon is for IPSec.
B. It uses local socket to communicate with native layer. VPN Java layer uses this local socket to do two things.
The first is to send launch parameters to mtpd or racoon deamon.
The second is to receive the status of mtpd.
In addition, Java layer will read the status of VPN from system property-"VPN. Status" which is writen by IP-Up-VPN.
The VPN profiles is saved in/MISC/VPN/profiles/folder.
3. Native layer.
As we said in Java layer, mtpd and Racoon daemon are launched by Java layer, what is more, Java layer also send launch parameter to these daemon by local socket.
For mtpd daemon, the local socket server file is/dev/socket/mtpd.
For racoon deamon, the local socket server file is/dev/socket/racoon.
In fact, we can launch these daemon by command line which can emulate Java layer's operation.
The below is a example:
Mtpd PPTP 192.168.1.32 1723 'linkname VPN name 111 password 222 refuse-EAP nodefaultroute usepeerdns idle 1800 MTU 1300 MRU 1300 + MPPE &
Mtpd L2TP 192.168.1.32 1701 'linkname VPN name 111 password 222 refuse-EAP nodefaultroute usepeerdns idle 1800 MTU 1300 MRU 1300 &
The usage of mtpd and Racoon are as below.
# Mtpd
Usage: mtpd <protocol-ARGs> ''<pppd-ARGs>, where protocol-ARGs are one:
L2TP <Server> <port> [secret]
PPTP <Server> <port>
# Racoon
Usage: racoon server port pre-shared-Key
Racoon server port my-private-key my-Cert CA-Cert
How does mtpd control driver layer to enable/disable VPN link, let us focus on it and continue it in the second part.
In froyo, there are four types of VPN.
Pptp vpn.
L2TP VPN.
L2TP/IPSec psk vpn.
L2TP/IPSec crt vpn.
The below describes the principle of pptp vpn, we divide main process into two planes: control plane and data plane, control plane describes how to set up pptp vpn and prepares for data plane. data plane describes data transmission.
1. Control Plane
While mtpd is launched, it will do the below things:
A. Use get_control_and_arguments () to set up local socket, then receive boot parameter from Java layer, and divide the boot parameter into two parts: one is for itself, another is for PPP daemon.
B. Use initialize () to do initialization, according to boot parameter, it will call PPTP or L2TP's connect () funciton, for PPTP, the function is pptp_connect () function.
Timeout = the_protocol-> connect (argc-2, & argv [2]);
C. In pptp_connect () function, it creates a stream socket to setup a link which connects to PPTP server by using TCP protocol and 1723 port, and then send sccrq message.
D. Use poll () function to receive message from PPTP server, and then call pptp_process () to process message.
E. Once the PPTP link is established, it will call start_pppd () to launch pppd daemon, however, it need call create_pppox () to create pppox handle firstly.
F. In create_pppox () function, it uses the below sentence to create a af_pppox type socket,
Socket (af_pppox, sock_dgram, px_proto_opns );
And then call connect () function which will call pppopns_connect () function in/driver/NET/pppopns. C of kernel in fact, the input parameter type is
Struct sockaddr_pppopns address = {
. Sa_family = af_pppox,
. Sa_protocol = px_proto_opns,
. Tcp_socket = the_socket,
. Local = local,
. Remote = remote,
};
In this struct, the_socket is wrongly ded which contains the info about PPTP server. So kernel can use these info to setup GRE socket for VPN data plane.
The above describes mtpd daemon, now let us focus on kernel layer.
G. While kernel is launched, pppopns_init () function is called, in this function, it will call proto_register () and register_pppox_proto () to register pppopns protocol.
H. as we said in 'f' item, mtpd CILS pppopns_connect () function, in this function, it use socket_create () to generate a gre link to PPTP server which is used to encapsulate PPP package, and then set & pppopns_channel_ops for po-> Chan. ops, and also set pppopns_recv () for sk_raw-> sk_data_ready. so now pppopns_xmit () which is responsible for transmiting package and pppopns_recv () which is responsible for processing package is installed successfully.
Till now GRE tunnel is ready for PPP package.
2. Date plane
A. While pppd daemon is launched, it will execute normal PPP process, such as LCP, NCP, and also IP package at last.
While PPP package is ready, kernel will call pppopns_xmit () function which has already been registered into kernel.
B. In pppopns_xmit () function, this PPP package will be as a gre payload, and be sent to PPTP server by using GRE tunnel, so now the package's format is as below:
| L1 | L2 | IP | GRE | PPP |
Please note: This PPP message contains PPP, IP and upper layer data.
C. While package is stored from PPTP server, the package will be parsed as a normal GRE package, for GRE raw data, it will be transfered to pppopns_recv () funciton.
D. In pppopns_recv (), the raw PPP package will be transfered to ppp_input () function.