📄 ppppap.c
字号:
/*-------------------------------------------------------------------*/ return result;}/***********************************************************************//* check_response: Check peer's response *//* *//***********************************************************************/static int check_response(FSM *fsm, ConfigHdr *hdr, NetBuf *data){ int i, msg_len, buf_len, min_len; /*-------------------------------------------------------------------*/ /* The ID field must match the last request we sent. */ /*-------------------------------------------------------------------*/ if (hdr->id != fsm->lastid) {#if PPP_TRACE pppLog("PAP: wrong ID - %u should be %u\n", hdr->id, fsm->lastid);#endif return -1; } /*-------------------------------------------------------------------*/ /* Determine message length, buffer length, and the lessor value. */ /*-------------------------------------------------------------------*/ msg_len = pullchar(data); if (msg_len == -1) {#if PPP_TRACE pppLog("PAP: missing message count");#endif return -1; } buf_len = data->length; min_len = min(msg_len, buf_len); /*-------------------------------------------------------------------*/ /* Null terminate the peer's message. */ /*-------------------------------------------------------------------*/ data->ip_pkt[min_len] = 0; /*-------------------------------------------------------------------*/ /* Determine if buffer is short, too long, or just right. */ /*-------------------------------------------------------------------*/ if (min_len < msg_len) i = 0; else if (msg_len < buf_len) i = 1; else i = 2; /*-------------------------------------------------------------------*/ /* Optionally record event. */ /*-------------------------------------------------------------------*/#if PPP_TRACE { char *size[3] = {"Short", "Long", "Valid"}; pppLogn("PAP %s %s: %s", size[i], (hdr->code == CONFIG_ACK) ? "Ack" : "Nak", data->ip_pkt); }#endif /*-------------------------------------------------------------------*/ /* Return 0 iff packet length was just right. */ /*-------------------------------------------------------------------*/ return i != 2;}/***********************************************************************//* pap_timeout: Timeout while waiting for reply from authenticator *//* *//***********************************************************************/static void pap_timeout(void *object){ FSM *fsm = object; int fsmi = fsm->pdc->fsmi; /*-------------------------------------------------------------------*/ /* Set global PPP channel identifier before calling other routines. */ /*-------------------------------------------------------------------*/ Ppp = (PPP)((ui8 *)fsm - offsetof(struct PppCB, fsm[fsmi])); /*-------------------------------------------------------------------*/ /* Either send another request or shutdown if retry limit exceeded. */ /*-------------------------------------------------------------------*/ if (fsm->retry && (fsm->rcn_cnt < RCN_LIMIT)) {#if PPP_TRACE pppFsmLog(fsm, "Request timeout");#endif fsmSendReq(fsm); } else {#if PPP_TRACE pppFsmLog(fsm, "Request retry exceeded");#endif pap_shutdown(fsm); }}/***********************************************************************//* Global Function Definitions *//***********************************************************************//***********************************************************************//* papProc: Process incoming packet *//* *//***********************************************************************/void papProc(FSM *fsm, NetBuf *buf){ ConfigHdr hdr; /*-------------------------------------------------------------------*/ /* Extract configuration header from packet. */ /*-------------------------------------------------------------------*/ if (pppRdConf(&hdr, buf) == -1) {#if PPP_TRACE pppFsmLog(fsm, "short authentication packet");#endif return; } /*-------------------------------------------------------------------*/ /* Optionally record event. */ /*-------------------------------------------------------------------*/#if PPP_TRACE pppLogn("PPP/%s Recv, option: %s, id=%u, len=%u", fsm->pdc->name, fsmCodes[hdr.code], hdr.id, hdr.len + CONFIG_HDR_LEN);#endif /*-------------------------------------------------------------------*/ /* Process the header code according to the current state. */ /*-------------------------------------------------------------------*/ switch (hdr.code) { case CONFIG_REQ: if (check_request(fsm, &hdr) == CONFIG_ACK) pap_up(fsm, PPPF_PAP_LOCAL); break; case CONFIG_ACK: if (check_response(fsm, &hdr, buf) == 0) { NetTimerStop(&fsm->timer); pap_up(fsm, PPPF_PAP_REMOTE); } break; case CONFIG_NAK: if (check_response(fsm, &hdr, buf) == 0) pap_shutdown(fsm); break; default:#if PPP_TRACE pppLogn("PAP unknown packet type: %u dropping packet", hdr.code);#endif break; }}/***********************************************************************//* papDown: PAP layer down *//* *//***********************************************************************/void papDown(void){ FSM *fsm = &Ppp->fsm[kPAP];#if PPP_TRACE pppFsmLog(fsm, "Down");#endif fsm->state = fsmCLOSED; NetTimerStop(&fsm->timer); Ppp->public.flags &= ~(PPPF_PAP_LOCAL | PPPF_PAP_REMOTE);}/***********************************************************************//* papInit: Initialize configuration structure *//* *//***********************************************************************/void papInit(PPP ppp){ FSM *fsm = &ppp->fsm[kPAP]; /*-------------------------------------------------------------------*/ /* Supply LCP finite state machine constants. */ /*-------------------------------------------------------------------*/ fsm->pdc = &pap_constants; /*-------------------------------------------------------------------*/ /* Set default negotiation parameters. */ /*-------------------------------------------------------------------*/ fsm->state = fsmCLOSED; /*-------------------------------------------------------------------*/ /* Initialize timer. */ /*-------------------------------------------------------------------*/ fsm->timer.action = pap_timeout; fsm->timer.object = fsm; INIT_TMR(fsm->timer);}/***********************************************************************//* papOpen: Initialize PAP state machine *//* *//***********************************************************************/void papOpen(void){ FSM *fsm = &Ppp->fsm[kPAP]; /*-------------------------------------------------------------------*/ /* Initialize retry counters. */ /*-------------------------------------------------------------------*/ fsm->retry = fsm->pdc->req_limit; fsm->rcn_cnt = 0; /*-------------------------------------------------------------------*/ /* Check if authenticator. */ /*-------------------------------------------------------------------*/ if (Ppp->public.flags & PPPF_PAP_LOCAL) { fsm->state = fsmSTOPPED; } /*-------------------------------------------------------------------*/ /* Check if authenticatee. */ /*-------------------------------------------------------------------*/ if (Ppp->public.flags & PPPF_PAP_REMOTE) { fsm->state = fsmReqSent; fsmSendReq(fsm); }}#endif /* MAX_PPP_INTF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -