PPP程序基本流程.docx

上传人:牧羊曲112 文档编号:4888056 上传时间:2023-05-21 格式:DOCX 页数:14 大小:452.42KB
返回 下载 相关 举报
PPP程序基本流程.docx_第1页
第1页 / 共14页
PPP程序基本流程.docx_第2页
第2页 / 共14页
PPP程序基本流程.docx_第3页
第3页 / 共14页
PPP程序基本流程.docx_第4页
第4页 / 共14页
PPP程序基本流程.docx_第5页
第5页 / 共14页
亲,该文档总共14页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《PPP程序基本流程.docx》由会员分享,可在线阅读,更多相关《PPP程序基本流程.docx(14页珍藏版)》请在三一办公上搜索。

1、PPP程序基本流程图/* Interface unit number */* Data Link Layer Protocol field value */* State */* Contains option bits */* Current id */* Current request id */* Have received valid Ack/Nak/Rej to Req */* Timeout time in milliseconds */PPPD程序用到的几个重要的结构体: typedef struct fsm ( int unit; int protocol; int state

2、; int flags; u_char id; u_char reqid; u_char seen_ack; int timeouttime;int maxconfreqtransmits; /* Maximum Configure-Request transmissions */ int retransmits;/* Number of retransmissions left */int maxtermtransmits; /* Maximum Terminate-Request transmissions */ int nakloops; /* Number of nak loops s

3、ince last ack */ int rnakloops; /* Number of naks received */ int maxnakloops; /* Maximum number of nak loops tolerated */ struct fsm_callbacks callbacks; /* Callback routines */ char *term_reason; /* Reason for closing protocol */ int term_reason_len; /* Length of term_reason */ fsm;typedef struct

4、fsm_callbacks (void (*resetci) /* Reset our Configuration Information */P(fsm *);int (*cilen) /* Length of our Configuration Information */P(fsm *);void (*addci) /* Add our Configuration Information */_P(fsm *, u_char *, int *);int (*ackci) /* ACK our Configuration Information */_P(fsm *, u_char *,

5、int);int (*nakci) /* NAK our Configuration Information */_P(fsm *, u_char *, int, int);int (*rejci) /* Reject our Configuration Information */_P(fsm *, u_char *, int);int (*reqci) /* Request peers Configuration Information */_P(fsm *, u_char *, int *, int);void (*up)/* Called when fsm reaches OPENED

6、 state */P(fsm *);P(fsm *); void (starting)P(fsm *); void (finished)P(fsm *); void (*protreject)_P(int);void (retransmit)P(fsm *);int (*extcode)void (*down) /* Called when fsm leaves OPENED state */* Called when we want the lower layer */* Called when we dont want the lower layer */* Called when Pro

7、tocol-Reject received */* Retransmission is necessary */* Called when unknown code received */ _P(fsm *, int, int, u_char *, int);char *proto_name; /* String name for protocol (for messages) */ fsm_callbacks;typedef struct (char *name; /* name of the option */ enum opt_type type;void *addr;char desc

8、ription;unsigned int flags;void *addr2;int upper_limit;int lower_limit;const char *source;short int priority;short int winner; option_t;struct protent (u_short protocol; /* PPP protocol number */* Initialization procedure */ void (*init) _P(int unit);/* Process a received packet */void (*input) _P(i

9、nt unit, u_char *pkt, int len);/* Process a received protocol-reject */void (*protrej) _P(int unit);/* Lower layer has come up */ void (*lowerup) _P(int unit);/* Lower layer has gone down */void (*lowerdown) _P(int unit);/* Open the protocol */void (*open) _P(int unit);/* Close the protocol */void (

10、*close) _P(int unit, char *reason);/* Print a packet in readable form */ int (*printpkt) _P(u_char *pkt, int len,void (*printer) _P(void *, char *,.), void *arg);/* Process a received data packet */void (*datainput) _P(int unit, u_char *pkt, int len);bool enabled_flag;char *name;char *data_name;opti

11、on_t *options;/* 0 iff protocol is disabled */* Text name of protocol */* Text name of corresponding data protocol */* List of command-line options */* Check requested options, assign defaults */ void (*check_options) _P(void);/* Configure interface for demand-dial */ int (*demand_conf) _P(int unit)

12、;/* Say whether to bring up link for this pkt */ int (*active_pkt) _P(u_char *pkt, int len);struct channel (/* set of options for this channel */ option_t *options;/* find and process a per-channel options file */ void (*process_extra_options) _P(void);/* check all the options that have been given *

13、/void (*check_options) _P(void);/* get the channel ready to do PPP, return a file descriptor */int (*connect) _P(void);/* were finished with the channel */void (disconnect) _P(void);/* put the channel into PPP mode */int (*establish_ppp) _P(int);/* take the channel out of PPP mode, restore loopback

14、if demand */ void (*disestablish_ppp) _P(int);/* set the transmit-side PPP parameters of the channel */ void (*send_config) _P(int, u_int32_t, int, int);/* set the receive-side PPP parameters of the channel */ void (*recv_config) _P(int, u_int32_t, int, int); /* cleanup on error or normal exit */ vo

15、id (*cleanup) _P(void);/* close the device, called in children after fork */ void (*close) _P(void);;PPP的状态转换图:对程序流程的基本框架的说明因为程序是利用protent结构指针指向当前所在协议层的方法来实现的因此,每一层都要 经历几个阶段,直到本层达到OPENED状态时才可进入下一阶段来实现下一阶段的协议。 所以对每一层的协议都有相同的函数指针,只是函数指针指向的协议不同而已。整个程序的主体实现是从主函数的LCP_OPEN()开始的,在这个函数里,调用了有限状态 机 FSM_OPEN()

16、,而在 FSM_OPEN()中,callback 指针指向 了 starting,于是就到 了 LCP_STARTING()函数来实现 一个OPEN事件从而使 得PPP状态准备从DEAD到 ESTABLISHED的转变。接下来,回到主函数,下面一步是调用START_LINK()在此函数 中会把一个串口设备作为 PPP的接口,并把状态转变为 ESTABLISHED,然后调用 lcp_lowerup()来告诉上层底层已经UP,lcp_lowerup()中调用FSM_LOWERUP()来发送一个 configure-request请求,再把当前状态设置为REQSENT状态,至此,第一个LCP协商的报

17、 文已经发送出去。while (phase != PHASE_DEAD) (handle_events();get_input();if (kill_link)lcp_close(0, User request);if (asked_to_quit) (bundle_terminating = 1;if (phase = PHASE_MASTER)mp_bundle_terminated();if (open_ccp_flag) (if (phase = PHASE_NETWORK II phase = PHASE_RUNNING) ( ccp_fsm0.flags = OPT_RESTART

18、; /* clears OPT_SILENT */ (*ccp_protent.open)(0);接下来的流程实现主要就是在这个while循环中实现了。之前说过了我们已经发送了第一个 配置协商报文,所以handle_events()主要就是做等待接收数据包的时间处理了,在 handle_events()里主要调用了两个函数一个是wait_input(),他的任务是等待并判断是否超 时。还有一个是calltimeout()他主要是做超时的处理。当等待并未超时而且有数据包过来, 则调用整个PPPD中最重要的函数get_input()函数。他主要接收过来的数据包并做出相应的 动作。接下来就get_i

19、nput()函数进行详细的说明。首先对包进行判断,丢弃所有不在LCP阶段和没有OPENED状态的包,然后protop指针 指向当前协议的input函数。于是就进入了 LCP_INPUT(),同理LCP_INPUT()调用了 FSM_INPUT ()对收到的包进行代码域的判断,判断收到的是什么包。假设比较顺利,我们 收到的是CONFACK的包,于是调用fsm_rconack()函数,在此函数中根据当前自身的状态 来决定下一步的状态如何改变,这里我们假设也很顺利,已经发送完了 configure-ack,因此我 们把FSM当前状态变成了 OPENED状态,并把callback指针指向UP所以我们马

20、上就调用 LCP_UP()在那里我们又调用了 LINK_ESTABLISHED(涵数来进入认证的协商,或者如 果没有认证则直接进入网络层协议。当然这里我们还是要认证的所有在 LINK_ESTABLISHED(浬我们选择是利用何种认证方式是PAP还是EAP,还是CHAP假设 我们这里采用CHAP而且是选择CHAP WITH PEER,意思是等待对端先发送CHALLENGE 挑战报文。于是我们又调用了 chap_with_peer()函数,并等待接收挑战报文。于是从新又来 到handle_events()等待接收。再利用get_input()来接收包,在get_input()里这次调用 chap_

21、input(),再调用FSM_INPUT(),在那里我们再对包的代码域进行判断,这次判断出是 CHAP_CHALLENGE包,则我们要调用chap_respons()函数来回应对端,继续等待对方 的报文,再次利用 CHAP_INPUT(),FSM_INPUT()来判断,如果是 SUCCESS,则调用 handle_status(),在这个函数里调用success_chap_with_peer函数(),从而进入网络层阶段, 调用network_phase()函数。网络层的互动是从start_networks()开始的,如果在网络层阶段同 时有CCP协议(压缩控制协议)则进行压缩控制协议的协商,然

22、后再进入正式的IPCP的协 商,而IPCP的协商主要也是通过protop指针指向IPCP_OPEN()开始的。而IPCP_OPEN() 则是调用了 FSM_OPEN(),在这里,首先发送一个configure-request包,然后和之前一样等 待接收。经过几个交互后最后调用NP_UP()完成网络层的协商,至此PPP链路可以承载网 络层的数据包了。选项的协商以LCP为例,它使用了 lcp_options结构,并定义了该结构的四个变量lcp_wantoptions, lcp_gotoptions, lcp_allowoptions, lcp_hisoptions,分别用来表示我们想要请求的选项,

23、对方 ack的选项,我们允许对方请求的选项,我们ack对方的选项。lcp_options结构中每个域的 含义见附录。pppd根据lcp_wantoptions生成发送的选项请求,根据lcp_allowoptions决定接 受还是拒绝接收到的选项请求。pppd在lcp_init函数中对lcp_wantoptions和lcp_allowoptions进行赋值。在状态机的发 送函数中,在当前状态不为REQSENT,ACKRCVD,ACKSENT的情况下,调用状态机的 reset函数把lcp_wantoptions赋值给lcp_gotoptions来组装选项。选项的组装是靠状态机的回 调函数指针add

24、ci完成的,对于LCP就是lcp_addci,组装好选项后发送数据是通过调用 fsm_sdata 实现的。一些看不懂的变量的初始化否Get_input()否是是否要CCP是LCP_OPEN()一木T 是否需再次L INK或有要求断开,或LINK 否不成功数大于最大失败是把当前状态设为HOLDOFFHandle_event()否当前状态是否是HOLD_OFF等待脚本的结束Clean up stateExit withspecific state二是否要kill_link二是*增加一个等待input 的 fd等待处理函数handle_event()是4是否有要求退 出链接fsm结构体中的PASSI

25、VE 和 SLIENT 的 flag 不 置位。中是否要商PASSIVE 的 flag 一 -PASSIVE , i 置位否 1-WQ 中是否有 SLIENT SLIENT 的 flag 置位否 1FSM_QPEN()read_packet(读取一个PPP对读取包的长度进行判断如MLCP没有OPENED而且是非LCP包,全部丢弃对protop指针指向的当前协议层调用input函数判 .ode是否CONREQ kFSM_RCONREQ()否T 是否如onfackA 是是否是CONNAK调用FSM_RCONACK()调用FSM RCONNAKREJ()是否是CONREJ是是否 是TERMREQ否是是否 是TERMACK否调用FSM_SDATA()发送CODEREJECTBREAK调用FSM_RTERMREQ(

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号