ppp腳本源碼分享
PPP撥號設置,在很多平臺上都有相關的操作。那么這里我們則重點講解一下平臺: L350和N300平臺上測試均通過的PPP腳本內容。那么現(xiàn)在就讓我們看下具體內容吧。希望對大家有所應用。
- /apps/etc/ppp >: uname -a
- Linux netaccess 2.6.22.1 #17 Thu Jan 7 18:03:30 EST 2010 armv5tejl unknown
pppd會從/etc/ppp下讀取相關配置文件,由于調試時會經常修改這些配置文件,所以建立了一個符號鏈接到我們的Nandflash分區(qū)上:
- /apps/etc/ppp >: ls -l /etc/ppp
- lrwxrwxrwx 1 root root 13 Nov 20 2009 /etc/ppp -> /apps/etc/ppp
當使用pppd作ppp server時,主要有以下配置文件。在下面的文檔中,將詳細介紹他們:
- /apps/etc/ppp >: ls
- chap-secrets gprs-start-chat options options.ttyS1 pap-secrets
pppd運行參數(shù)文件/etc/ppp/options
該文件指定pppd運行的參數(shù),若運行pppd時通過命令行指定的參數(shù)同時出現(xiàn)在該配置文件里時,pppd將使用/etc/ppp/options中的配置。關于pppd支持的一些參數(shù),可以在我們PC的linux上使用man命令查詢(man pppd)
[guowenxue@localhost ~]$ man 8 pppd
PPPD(8) PPPD(8)NAME
pppd - Point-to-Point Protocol DaemonSYNOPSIS
pppd [ options ]/apps/etc/ppp >: cat options
#tty Options
/dev/ttyS1 #例如,這里可以將/dev/ttyS1注釋,然后使用命令行#pppd /dev/ttyS1 運行來指定;
115200
#lock
modem
nocrtscts #無硬件流控#login
nodetach #若指定updetach則撥號成功后放入后臺運行,若為nodetach,則在前臺執(zhí)行debug
#Auth options
auth #使能Authentication
+pap #使用pap認證
-chap #不要支持chap認證# 源碼ppp-2.4.3/pppd/tty.c中的函數(shù)connect_tty()將會執(zhí)行這個腳本。主要是對客戶端的撥號的應答。
connect "/usr/sbin/chat -v -E -V -f /etc/ppp/gprs-start-chat"#lcp options
#passive
asyncmap 0
lcp-echo-failure 3
lcp-echo-interval 5
ipcp-accept-local
ipcp-accept-remote
#proxyarp
netmask 255.255.255.0
ms-dns 10.78.28.10
ms-dns 10.78.28.11
nodefaultroute
gprs-start-chat chat腳本
關于chat的用法,可以在Linux PC上使用man命令查詢:$ man 8 chat
- /apps/etc/ppp >: cat gprs-start-chat
- ABORT 'BUSY'
- ABORT 'NO CARRIER'
- ABORT 'NO DIALTONE'
- ABORT 'ERROR'
- TIMEOUT 0
- '' 'ATZ' //首先發(fā)送ATZ重置modem
- 'OK' 'ATE0' //收到OK后,使用ATE0消除回顯
- 'RING' 'ATA' //等待客戶端撥號,若客戶端開始撥號,Modem收到RING后,發(fā)送應答信號ATA
- 'CONNECT' '' //收到CONNECT信號后,將進入下一階段LCP的過程。
#p#options.ttyS1 IP地址分配
配置PPP服務器端(本地)IP地址和客戶端(遠端)的IP地址
- /apps/etc/ppp >: cat options.ttyS1
- #Server_IP_address:Client_IP_address
- 10.78.28.194:10.78.28.224
- chap和pap認證的帳號文件:
- /apps/etc/ppp >: cat pap-secrets
- # Secrets for authentication using PAP
- #User Server Secret IP Address
- na_admin * 123 *
- /apps/etc/ppp >: cat chap-secrets
- # Secrets for authentication using CHAP
- #User Server Secret IP Address
- na_admin * 123 *
pppd啟動撥號過程:
- /apps/etc/ppp >: pppd /dev/ttyS1
- OK
- ATE0 //chat腳本的調試輸出
- OK
- RING
- CONNECTSerial connection established.
- using channel 1
- Using interface ppp0
- Connect: ppp0 <--> /dev/ttyS1
- rcvd [LCP ConfReq id=0x0 <asyncmap 0x0> <magic 0x58452c14> <pcomp> <accomp> <callback CBCP>]
- Warning - secret file /etc/ppp/pap-secrets has world and/or group access
- sent [LCP ConfReq id=0x1 <asyncmap 0x0> <auth pap> <magic 0xb701c04a> <pcomp> <accomp>]
- sent [LCP ConfRej id=0x0 <callback CBCP>]
- rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <auth pap> <magic 0xb701c04a> <pcomp> <accomp>]
- rcvd [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x58452c14> <pcomp> <accomp>]
- sent [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x58452c14> <pcomp> <accomp>]
- sent [LCP EchoReq id=0x0 magic=0xb701c04a]
- rcvd [LCP code=0xc id=0x2 58 45 2c 14 4d 53 52 41 53 56 35 2e 31 30]
- sent [LCP CodeRej id=0x2 0c 02 00 12 58 45 2c 14 4d 53 52 41 53 56 35 2e 31 30]
- rcvd [LCP code=0xc id=0x3 58 45 2c 14 4d 53 52 41 53 2d 30 2d 4d 45 49 51 49 4e 50 43 30 31]
- sent [LCP CodeRej id=0x3 0c 03 00 1a 58 45 2c 14 4d 53 52 41 53 2d 30 2d 4d 45 49 51 49 4e 50 43 30 31]
- rcvd [PAP AuthReq id=0xc user="na_admin" password=<hidden>]
- Warning - secret file /etc/ppp/pap-secrets has world and/or group access
- sent [PAP AuthAck id=0xc "Login ok"]
- PAP peer authentication succeeded for na_admin
- sent [CCP ConfReq id=0x1 <deflate 15> <deflate(old#) 15> <bsd v1 15>]
- sent [IPCP ConfReq id=0x1 <compress VJ 0f 01> <addr 10.78.28.194>]
- rcvd [LCP EchoRep id=0x0 magic=0x58452c14]
- rcvd [CCP ConfReq id=0x4 < 12 06 00 00 00 01>]
- sent [CCP ConfRej id=0x4 < 12 06 00 00 00 01>]
- rcvd [IPCP ConfReq id=0x5 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-wins 0.0.0.0> <ms-
- dns3 0.0.0.0> <ms-wins 0.0.0.0>]
- sent [IPCP ConfRej id=0x5 <ms-wins 0.0.0.0> <ms-wins 0.0.0.0>]
- rcvd [CCP ConfRej id=0x1 <deflate 15> <deflate(old#) 15> <bsd v1 15>]
- sent [CCP ConfReq id=0x2]
- rcvd [IPCP ConfAck id=0x1 <compress VJ 0f 01> <addr 10.78.28.194>]
- rcvd [CCP TermReq id=0x6"XE,\024\000<\315t\000\000\002\334"]
- sent [CCP TermAck id=0x6]
- rcvd [IPCP ConfReq id=0x7 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]
- sent [IPCP ConfNak id=0x7 <addr 10.78.28.224> <ms-dns1 10.78.28.10> <ms-dns3 10.78.28.11>]
- rcvd [IPCP ConfReq id=0x8 <compress VJ 0f 01> <addr 10.78.28.224> <ms-dns1 10.78.28.10> <ms-dns3
- 10.78.28.11>]
- sent [IPCP ConfAck id=0x8 <compress VJ 0f 01> <addr 10.78.28.224> <ms-dns1 10.78.28.10> <ms-dns3
- 10.78.28.11>]
- local IP address 10.78.28.194
- remote IP address 10.78.28.224
測試
/apps/etc/ppp >: ping 10.78.28.224
PING 10.78.28.224 (10.78.28.224): 56 data bytes
64 bytes from 10.78.28.224: seq=0 ttl=64 time=194.570 ms
64 bytes from 10.78.28.224: seq=1 ttl=64 time=190.331 ms