📄 pppipcp.c
字号:
/*-----------------------------------------------------------------*/ if ((signed_length -= option.len) < 0) {#if PPP_TRACE pppLog("IPCP NAK: bad header length");#endif return -1; } /*-----------------------------------------------------------------*/ /* Check if option is an unsolicited NAK suggestion. */ /*-----------------------------------------------------------------*/ if ((Ppp->ipcp_request_opts & (1 << option.type)) == FALSE) {#if PPP_TRACE pppLog(" unsolicated NAK");#endif /*---------------------------------------------------------------*/ /* If option is allowed, add it to our request list. */ /*---------------------------------------------------------------*/ if (Ppp->ipcp_accept_opts & (1 << option.type)) ipcp->local.options |= (1 << option.type); } /*-----------------------------------------------------------------*/ /* Check an option and update its working value. */ /*-----------------------------------------------------------------*/ result = check_nak_opt(&ipcp->local, &option); /*-----------------------------------------------------------------*/ /* Discard packet if it was too short. */ /*-----------------------------------------------------------------*/ if (result == -1) {#if PPP_TRACE pppLog("IPCP NAK: ran out of data");#endif return -1; } }#if PPP_TRACE pppLog("IPCP NAK: valid");#endif return 0;}/***********************************************************************//* check_rej: Process configuration reject sent by the peer *//* *//***********************************************************************/static int check_rej(FSM *fsm, ConfigHdr *config){ IpcpOpts *local = &Ppp->ipcp.local; int signed_length = config->len; OptHdr option; int last_option = 0; /*-------------------------------------------------------------------*/ /* The ID field must match the last request we sent. */ /*-------------------------------------------------------------------*/ if (config->id != fsm->lastid) {#if PPP_TRACE pppLog("IPCP REJ: wrong ID");#endif return -1; } /*-------------------------------------------------------------------*/ /* Process in order, checking for errors. */ /*-------------------------------------------------------------------*/ while ((signed_length > 0) && (pppRdOpt(&option) != -1)) { int i; /*-----------------------------------------------------------------*/ /* Ensure configuraton length is long enough to hold next option. */ /*-----------------------------------------------------------------*/ if ((signed_length -= option.len) < 0) {#if PPP_TRACE pppLog("IPCP REJ: bad header length");#endif return -1; } /*-----------------------------------------------------------------*/ /* Ensure option order and type is legal. */ /*-----------------------------------------------------------------*/ if (option.type > IPCP_OPT_LIMIT) {#if PPP_TRACE pppLog("IPCP REJ: option out of range");#endif } else if ((option.type < last_option) || !(local->options & (1 << option.type))) {#if PPP_TRACE pppLog("IPCP REJ: option out of order");#endif return -1; } /*-----------------------------------------------------------------*/ /* Strip option from receive buffer. */ /*-----------------------------------------------------------------*/ for (i = option.len - OPTION_HDR_LEN; i > 0; --i) { if (pullchar(pppRcvBuf) == -1) {#if PPP_TRACE pppLog("IPCP REJ: ran out of data");#endif return -1; } } last_option = option.type; /*-----------------------------------------------------------------*/ /* Remove rejected option from list of options being negotiated. */ /*-----------------------------------------------------------------*/ if (option.type <= IPCP_OPT_LIMIT) local->options &= ~(1 << option.type); }#if PPP_TRACE pppLog("IPCP REJ: valid");#endif return 0;}/***********************************************************************//* ipcp_finished: After termination *//* *//***********************************************************************/static void ipcp_finished(FSM *fsm){}/***********************************************************************//* ipcp_down: Left IPCP Opened state *//* *//***********************************************************************/static void ipcp_down(FSM *fsm){ /*-------------------------------------------------------------------*/ /* Delete PPP network interface from protocol stack. */ /*-------------------------------------------------------------------*/ if (Ppp->public.flags & PPPF_NI_UP) { void (*report)(Ni *ni, int event); /*-----------------------------------------------------------------*/ /* Temporarily NULL the report routine, so our tcpDelNi() doesn't */ /* result in a callback to us. */ /*-----------------------------------------------------------------*/ report = Ppp->public.ni.report; Ppp->public.ni.report = NULL; /*-----------------------------------------------------------------*/ /* Clear flag and delete the PPP network interface. */ /*-----------------------------------------------------------------*/ Ppp->public.flags &= ~PPPF_NI_UP; semPost(Net.IntSem); tcpDelNi(&Ppp->public.ni); semPend(Net.IntSem, WAIT_FOREVER); /*-----------------------------------------------------------------*/ /* Restore the event callback pointer. */ /*-----------------------------------------------------------------*/ Ppp->public.ni.report = report;#if PPP_TRACE pppLogn("PPP/IPCP Dropped route to %s", pppIps(Ppp->public.ni.remote_addr));#endif }}/***********************************************************************//* ipcp_up: Configuration negotiation complete *//* *//***********************************************************************/static void ipcp_up(FSM *fsm){ IpcpCB *ipcp = &Ppp->ipcp; int rc, mtu, rslots, tslots; Ni *ni = &Ppp->public.ni; /*-------------------------------------------------------------------*/ /* If not default gateway, verify remote address has been provided. */ /*-------------------------------------------------------------------*/ if ((ipcp->remote.address == 0) && !(Ppp->public.flags & PPPF_DEF_GW)) {#if PPP_TRACE pppLogn("IPCP no remote address and not default gateway");#endif fsmLcpClose(); return; } /*-------------------------------------------------------------------*/ /* Verify that a local IP address has been provided. */ /*-------------------------------------------------------------------*/ if (ipcp->local.address == 0) {#if PPP_TRACE pppLogn("IPCP lacking local IP address");#endif fsmLcpClose(); return; } /*-------------------------------------------------------------------*/ /* If using borrowed address, must release and re-borrow it. */ /*-------------------------------------------------------------------*/ if (Ppp->borrowed_addr == ipcp->local.address) ipcp->local.address = 0; /*-------------------------------------------------------------------*/ /* Set MTU to minimum of working value and size of largest buffer. */ /*-------------------------------------------------------------------*/ mtu = TCP_BIG_SIZE - (NIMHLEN + CRC16_LEN); mtu = min(mtu, Ppp->lcp.remote.mru); /*-------------------------------------------------------------------*/ /* Initialize network interface control block. */ /*-------------------------------------------------------------------*/ ni->mtu = mtu; ni->hw_addr = Ppp; /* using hwa field as ctrl block ptr */ ni->hw_type = 0; ni->ha_len = 0; ni->flags = NIF_P2P; if (Ppp->public.flags & PPPF_DEF_GW) ni->flags |= NIF_DEF_GW; ni->ip_addr = ipcp->local.address; ni->remote_addr = ipcp->remote.address; ni->ip_mask = 0xFFFFFFFF; ni->transmit = ppp_send; ni->broadcast = NULL; /*-------------------------------------------------------------------*/ /* Add PPP network interface to protocol stack. */ /*-------------------------------------------------------------------*/ semPost(Net.IntSem); rc = tcpAddNi(ni); semPend(Net.IntSem, WAIT_FOREVER); if (rc == 0) Ppp->public.flags |= PPPF_NI_UP; else {#if PPP_TRACE pppLogn("IPCP tcpAddNi() failed");#endif fsmLcpClose(); return; } /*-------------------------------------------------------------------*/ /* If we borrowed a local address, announced it to the peer, and got */ /* a different borrowed address later, must close. */ /*-------------------------------------------------------------------*/ if ((Ppp->borrowed_addr) && !(ipcp->local.options & IPCP_N_ADDRESS) && (Ppp->borrowed_addr != ni->ip_addr)) {#if PPP_TRACE pppLogn("IPCP borrowed address changed");#endif fsmLcpClose(); return; } /*-------------------------------------------------------------------*/ /* If trace enabled, print the resulting configuration. */ /*-------------------------------------------------------------------*/#if PPP_TRACE pppPrintCfg(Ppp);#endif /*-------------------------------------------------------------------*/ /* If negotiated, initialize VJ header compression. */ /*-------------------------------------------------------------------*/ rslots = tslots = 0; if (ipcp->local.options & IPCP_N_COMPRESS) rslots = ipcp->local.slots; if (ipcp->remote.options & IPCP_N_COMPRESS) tslots = ipcp->remote.slots; if (rslots || tslots) { vjhc_init(&Ppp->comp, rslots, tslots);#if PPP_TRACE pppLogn("IPCP VJHC enabled: slots=%u/%u, flag=%u/%u (r/t)", rslots, tslots, ipcp->local.comp_slot, ipcp->remote.comp_slot);#endif }}/***********************************************************************//* ipcp_starting: Received Open event *//* *//* Note: Remote options initialized in check_req() *//* *//***********************************************************************/static void ipcp_starting(FSM *fsm){ IpcpCB *ipcp = &Ppp->ipcp; /*-------------------------------------------------------------------*/ /* Initialize local options. */ /*-------------------------------------------------------------------*/ ipcp->local.options = Ppp->ipcp_request_opts; ipcp->local.address = Ppp->public.local_addr; ipcp->local.comp_proto = PPP_COMP_PROTO; /* compression protocol */ ipcp->local.slots = VJ_SLOT_DEF; /* number of slots (0-n) */ ipcp->local.comp_slot = IPCP_COMP_SLOT; /* id may be compressed */ /*-------------------------------------------------------------------*/ /* Try to borrow a local IP address if none is provided. */ /*-------------------------------------------------------------------*/ if (Ppp->public.local_addr == 0) ipcp->local.address = Ppp->borrowed_addr = NiBorrowAddr(); else Ppp->borrowed_addr = 0;}/***********************************************************************//* ipcpInit: Initialize configuration structure *//* *//***********************************************************************/void ipcpInit(PPP ppp){ FSM *fsm = &ppp->fsm[kIPCP]; /*-------------------------------------------------------------------*/ /* Supply IPCP finite state machine constants. */ /*-------------------------------------------------------------------*/ fsm->pdc = &ipcp_constants; /*-------------------------------------------------------------------*/ /* Initialize state machine. */ /*-------------------------------------------------------------------*/ pppFsmInit(fsm);}#endif /* MAX_PPP_INTF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -