Quantcast
Channel: CodeSection,代码区,Linux操作系统:Ubuntu_Centos_Debian - CodeSec
Viewing all articles
Browse latest Browse all 11063

Linux PPP实现源码分析

$
0
0

……

new_phase ( PHASE_INITIALIZE ) ; //PPPD中的状态机,目前是初始化阶段

/*

* Initialize magic number generator now so that protocols may

* use magic numbers in initialization.

*/

magic_init () ;

/*

* Initialize each protocol.

*/

for ( i = 0 ; ( protp = protocols [ i ]) != NULL ; ++i ) //protocols[]是全局变量的协议数组

( *protp-> init )( 0 ) ; //初始化协议数组中所有协议

/*

* Initialize the default channel.

*/

tty_init () ; //channel初始化,默认就是全局的tty_channel,里面包括很多TTY函数指针

if ( ! options_from_file ( _PATH_SYSOPTIONS , ! privileged , 0 , 1 ) //解析/etc/ppp/options中的参数

|| ! options_from_user ()

|| ! parse_args ( argc -1 , argv +1 )) //解析PPPD命令行参数

exit ( EXIT_OPTION_ERROR ) ;

devnam_fixed = 1 ; /* can no longer change device name */

/*

* Work out the device name, if it hasn't already been specified,

* and parse the tty's options file.

*/

if ( the_channel -> process_extra_options )

( * the_channel -> process_extra_options )() ; //实际上是调用tty_process_extra_options解析TTY 参数

if ( ! ppp_available ()) { //检测/dev/ppp设备文件是否有效

option_error ( "%s" , no_ppp_msg ) ;

exit ( EXIT_NO_KERNEL_SUPPORT ) ;

}

/*

* Check that the options given are valid and consistent.

*/

check_options () ; //检查选项参数

if ( ! sys_check_options ()) //检测系统参数,比如内核是否支持Multilink等

exit ( EXIT_OPTION_ERROR ) ;

auth_check_options () ; //检查认证相关的参数

#ifdef HAVE_MULTILINK

mp_check_options () ;

#endif for ( i = 0 ; ( protp = protocols [ i ]) != NULL ; ++i )

if ( protp-> check_options != NULL )

( *protp-> check_options )() ; //检查每个控制协议的参数配置

if ( the_channel -> check_options )

( * the_channel -> check_options )() ; //实际上是调用tty_check_options检测TTY参数

……

/*

* Detach ourselves from the terminal, if required,

* and identify who is running us.

*/

if ( ! nodetach && ! updetach )

detach () ; //默认放在后台以daemon执行,也可配置/etc/ppp/option中的nodetach参数放在前台执行

……

syslog ( LOG_NOTICE , "pppd %s started by %s, uid %d" , VERSION , p, uid ) ; //熟悉的log,现在准备执行了

script_setenv ( "PPPLOGNAME" , p, 0 ) ;

if ( devnam [ 0 ])

script_setenv ( "DEVICE" , devnam , 1 ) ;

slprintf ( numbuf, sizeof ( numbuf ) , "%d" , getpid ()) ;

script_setenv ( "PPPD_PID" , numbuf, 1 ) ;

setup_signals () ; //设置信号处理函数


Viewing all articles
Browse latest Browse all 11063

Trending Articles