PPP程序基本流程.doc_第1页
PPP程序基本流程.doc_第2页
PPP程序基本流程.doc_第3页
PPP程序基本流程.doc_第4页
PPP程序基本流程.doc_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

PPPD主函数main.cPPP程序基本流程图PPPD程序用到的几个重要的结构体:typedef struct fsm int unit;/* Interface unit number */ int protocol;/* Data Link Layer Protocol field value */ int state;/* State */ int flags;/* Contains option bits */ u_char id;/* Current id */ u_char reqid;/* Current request id */ u_char seen_ack;/* Have received valid Ack/Nak/Rej to Req */ int timeouttime;/* Timeout time in milliseconds */ int maxconfreqtransmits;/* Maximum Configure-Request transmissions */ int retransmits;/* Number of retransmissions left */ int maxtermtransmits;/* Maximum Terminate-Request transmissions */ int nakloops;/* Number of nak loops since 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 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 *, 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 state */_P(fsm *); void (*down)/* Called when fsm leaves OPENED state */_P(fsm *); void (*starting)/* Called when we want the lower layer */_P(fsm *); void (*finished)/* Called when we dont want the lower layer */_P(fsm *); void (*protreject)/* Called when Protocol-Reject received */_P(int); void (*retransmit)/* Retransmission is necessary */_P(fsm *); int (*extcode)/* 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*description;unsigned int flags;void*addr2;intupper_limit;intlower_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(int 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 (*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;/* 0 iff protocol is disabled */ char *name;/* Text name of protocol */ char *data_name;/* Text name of corresponding data protocol */ option_t *options;/* 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); /* 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 */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 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 */void (*cleanup) _P(void);/* close the device, called in children after fork */void (*close) _P(void);PPP的状态转换图:对程序流程的基本框架的说明因为程序是利用protent结构指针指向当前所在协议层的方法来实现的因此,每一层都要经历几个阶段,直到本层达到OPENED状态时才可进入下一阶段来实现下一阶段的协议。所以对每一层的协议都有相同的函数指针,只是函数指针指向的协议不同而已。整个程序的主体实现是从主函数的LCP_OPEN()开始的,在这个函数里,调用了有限状态机FSM_OPEN(),而在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协商的报文已经发送出去。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 | phase = PHASE_RUNNING) ccp_fsm0.flags = OPT_RESTART; /* clears OPT_SILENT */ (*ccp_protent.open)(0); 接下来的流程实现主要就是在这个while循环中实现了。之前说过了我们已经发送了第一个配置协商报文,所以handle_events()主要就是做等待接收数据包的时间处理了,在handle_events()里主要调用了两个函数一个是wait_input(),他的任务是等待并判断是否超时。还有一个是calltimeout()他主要是做超时的处理。当等待并未超时而且有数据包过来,则调用整个PPPD中最重要的函数get_input()函数。他主要接收过来的数据包并做出相应的动作。接下来就get_input()函数进行详细的说明。 首先对包进行判断,丢弃所有不在LCP阶段和没有OPENED状态的包,然后protop指针指向当前协议的input函数。于是就进入了LCP_INPUT(),同理LCP_INPUT()调用了FSM_INPUT()对收到的包进行代码域的判断,判断收到的是什么包。假设比较顺利,我们收到的是CONFACK的包,于是调用fsm_rconack()函数,在此函数中根据当前自身的状态来决定下一步的状态如何改变,这里我们假设也很顺利,已经发送完了configure-ack,因此我们把FSM当前状态变成了OPENED状态,并把callback指针指向UP.所以我们马上就调用LCP_UP()在那里我们又调用了LINK_ESTABLISHED()函数来进入认证的协商,或者如果没有认证则直接进入网络层协议。当然这里我们还是要认证的所有在LINK_ESTABLISHED()里我们选择是利用何种认证方式是PAP,还是EAP,还是CHAP.假设我们这里采用CHAP而且是选择CHAP WITH PEER,意思是等待对端先发送CHALLENGE挑战报文。于是我们又调用了chap_with_peer()函数,并等待接收挑战报文。于是从新又来到handle_events()等待接收。再利用get_input()来接收包,在get_input()里这次调用chap_input(),再调用FSM_INPUT(),在那里我们再对包的代码域进行判断,这次判断出是CHAP_CHALLENGE包,则我们要调用chap_respons()函数来回应对端,继续等待对方的报文,再次利用CHAP_INPUT(),FSM_INPUT()来判断,如果是SUCCESS,则调用handle_status(),在这个函数里调用success_chap_with_peer函数(),从而进入网络层阶段,调用network_phase()函数。网络层的互动是从st

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论