📄 pppchap.c
字号:
}/***********************************************************************//* chap_timeout: Timeout while waiting for reply from authenticator *//* *//***********************************************************************/static void chap_timeout(void *object){ FSM *fsm; /*-------------------------------------------------------------------*/ /* Set global PPP channel identifier before calling other routines. */ /*-------------------------------------------------------------------*/ Ppp = object; fsm = &Ppp->fsm[kCHAP]; /*-------------------------------------------------------------------*/ /* 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 /*-----------------------------------------------------------------*/ /* If not in client mode, resend challenge. */ /*-----------------------------------------------------------------*/ if (fsm->state != fsmAckRcvd) send_challenge(fsm); /*-----------------------------------------------------------------*/ /* If response sent previously, resend it now. */ /*-----------------------------------------------------------------*/ if (Ppp->public.flags & PPPF_CHAP_RESPONDED) send_response(fsm); } else {#if PPP_TRACE pppFsmLog(fsm, "Request retry exceeded");#endif chap_shutdown(fsm); }}/***********************************************************************//* Global Function Definitions *//***********************************************************************//***********************************************************************//* chapProc: Process incoming packet *//* *//***********************************************************************/void chapProc(FSM *fsm, NetBuf *buf){ ConfigHdr hdr; /*-------------------------------------------------------------------*/ /* Ignore incoming packets if state machine is closed. */ /*-------------------------------------------------------------------*/ if (fsm->state == fsmCLOSED) return; /*-------------------------------------------------------------------*/ /* 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 /*-------------------------------------------------------------------*/ /* Perform responses common to all states. */ /*-------------------------------------------------------------------*/ switch (hdr.code) { case CHALLENGE: /*---------------------------------------------------------------*/ /* Check for remote authentication. */ /*---------------------------------------------------------------*/ if (((Ppp->lcp.remote.options & LCP_N_AUTHENT) == 0) || (Ppp->lcp.remote.auth_proto != PPP_CHAP_PROTO)) return; /*---------------------------------------------------------------*/ /* Send response and then break to continue message processing. */ /*---------------------------------------------------------------*/ if (prep_response(fsm, hdr.id, buf) == 0) send_response(fsm); break; case RESPONSE: /*---------------------------------------------------------------*/ /* Check for local authentication. */ /*---------------------------------------------------------------*/ if (((Ppp->lcp.local.options & LCP_N_AUTHENT) == 0) || (Ppp->lcp.local.auth_proto != PPP_CHAP_PROTO) || (hdr.id != fsm->lastid)) return; /*---------------------------------------------------------------*/ /* Ensure ID matches the challenge message. */ /*---------------------------------------------------------------*/ if (hdr.id != fsm->lastid) {#if PPP_TRACE pppLog("CHAP: wrong ID - %u should be %u\n", hdr.id,fsm->lastid);#endif return; } /*---------------------------------------------------------------*/ /* If response incorrect, then shutdown and return after sending */ /* failure message. This completes negative response processing. */ /*---------------------------------------------------------------*/ if (check_response(fsm, &hdr, buf)) { send_failure(fsm, hdr.id); chap_shutdown(fsm); return; } /*---------------------------------------------------------------*/ /* Else send "success" message and break to continue processing */ /* correct response. */ /*---------------------------------------------------------------*/ else { send_success(fsm, hdr.id); break; } case SUCCESS: /*---------------------------------------------------------------*/ /* Check for remote authentication and correct message ID. */ /*---------------------------------------------------------------*/ if (((Ppp->lcp.remote.options & LCP_N_AUTHENT) == 0) || (Ppp->lcp.remote.auth_proto != PPP_CHAP_PROTO) || (hdr.id != Ppp->last_response)) return; /*---------------------------------------------------------------*/ /* Break to continue "success" message processing. */ /*---------------------------------------------------------------*/ break; case FAILURE: /*---------------------------------------------------------------*/ /* Check for remote authentication and correct message ID. */ /*---------------------------------------------------------------*/ if (((Ppp->lcp.remote.options & LCP_N_AUTHENT) == 0) || (Ppp->lcp.remote.auth_proto != PPP_CHAP_PROTO) || (hdr.id != Ppp->last_response)) return; /*---------------------------------------------------------------*/ /* Failure message closes state machine. */ /*---------------------------------------------------------------*/ chap_shutdown(fsm); /*---------------------------------------------------------------*/ /* This completes "failure" message processing. */ /*---------------------------------------------------------------*/ return; default:#if PPP_TRACE pppLogn("CHAP unknown packet type: %u dropping packet", hdr.code);#endif return; } /*-------------------------------------------------------------------*/ /* State-dependent processing. Responses have been verified correct. */ /*-------------------------------------------------------------------*/ switch (fsm->state) { /*-----------------------------------------------------------------*/ /* "Req-Sent" State (Bi-directional authentication). */ /*-----------------------------------------------------------------*/ case fsmReqSent: switch (hdr.code) { case SUCCESS: fsm->state = fsmAckSent; break; case RESPONSE: fsm->state = fsmAckRcvd; break; } break; /*-----------------------------------------------------------------*/ /* "Ack-Rcvd" State (client authentication). */ /*-----------------------------------------------------------------*/ case fsmAckRcvd: switch (hdr.code) { case SUCCESS: chap_up(fsm); break; } break; /*-----------------------------------------------------------------*/ /* "Ack-Sent" State (server authentication). */ /*-----------------------------------------------------------------*/ case fsmAckSent: switch (hdr.code) { case RESPONSE: chap_up(fsm); break; case CHALLENGE: send_challenge(fsm); break; } break; }}/***********************************************************************//* chapNcpMsg: A NCP negotiation message was received during CHAP *//* *//***********************************************************************/void chapNcpMsg(void){ FSM *fsm = &Ppp->fsm[kCHAP]; /*-------------------------------------------------------------------*/ /* Start up if a "success" message must have been lost. */ /*-------------------------------------------------------------------*/ if (fsm->state == fsmAckRcvd) chap_up(fsm);}/***********************************************************************//* chapDown: CHAP layer down *//* *//***********************************************************************/void chapDown(void){ FSM *fsm = &Ppp->fsm[kCHAP];#if PPP_TRACE pppFsmLog(fsm, "Down");#endif fsm->state = fsmINITIAL; NetTimerStop(&fsm->timer); Ppp->public.flags &= ~(PPPF_CHAP_LOCAL | PPPF_CHAP_REMOTE);}/***********************************************************************//* chapInit: Initialize configuration structure *//* *//***********************************************************************/void chapInit(PPP ppp){ FSM *fsm = &ppp->fsm[kCHAP]; /*-------------------------------------------------------------------*/ /* Supply LCP finite state machine constants. */ /*-------------------------------------------------------------------*/ fsm->pdc = &chap_constants; /*-------------------------------------------------------------------*/ /* Assign initial state. */ /*-------------------------------------------------------------------*/ fsm->state = fsmCLOSED; /*-------------------------------------------------------------------*/ /* Initialize timer. */ /*-------------------------------------------------------------------*/ fsm->timer.action = chap_timeout; fsm->timer.object = ppp; INIT_TMR(fsm->timer);}/***********************************************************************//* chapOpen: Initialize CHAP state machine *//* *//***********************************************************************/void chapOpen(void){ FSM *fsm = &Ppp->fsm[kCHAP]; /*-------------------------------------------------------------------*/ /* Initialize response flag and retry counters. */ /*-------------------------------------------------------------------*/ Ppp->public.flags &= ~PPPF_CHAP_RESPONDED; fsm->retry = fsm->pdc->req_limit; fsm->rcn_cnt = 0; /*-------------------------------------------------------------------*/ /* Check if bidirectional protocol. */ /*-------------------------------------------------------------------*/ if ((Ppp->public.flags & PPPF_CHAP_LOCAL) && (Ppp->public.flags & PPPF_CHAP_REMOTE)) { fsm->state = fsmReqSent; send_challenge(fsm); } /*-------------------------------------------------------------------*/ /* Else check if server protocol. */ /*-------------------------------------------------------------------*/ else if (Ppp->public.flags & PPPF_CHAP_LOCAL) { fsm->state = fsmAckSent; send_challenge(fsm); } /*-------------------------------------------------------------------*/ /* Else client protocol. */ /*-------------------------------------------------------------------*/ else fsm->state = fsmAckRcvd;}#endif /* MAX_PPP_INTF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -