📄 ppp.c
字号:
u32_t asyncmap, int pcomp, int accomp){ PPPControl *pc = &pppControl[unit]; int i; pc->mtu = mtu; pc->pcomp = pcomp; pc->accomp = accomp; /* Load the ACCM bits for the 32 control codes. */ for (i = 0; i < 32/8; i++) pc->outACCM[i] = (u_char)((asyncmap >> (8 * i)) & 0xFF); PPPDEBUG((LOG_INFO, "ppp_send_config[%d]: outACCM=%X %X %X %X\n", unit, pc->outACCM[0], pc->outACCM[1], pc->outACCM[2], pc->outACCM[3]));}/* * ppp_set_xaccm - set the extended transmit ACCM for the interface. */void ppp_set_xaccm(int unit, ext_accm *accm){ memcpy(pppControl[unit].outACCM, accm, sizeof(ext_accm)); PPPDEBUG((LOG_INFO, "ppp_set_xaccm[%d]: outACCM=%X %X %X %X\n", unit, pppControl[unit].outACCM[0], pppControl[unit].outACCM[1], pppControl[unit].outACCM[2], pppControl[unit].outACCM[3]));}/* * ppp_recv_config - configure the receive-side characteristics of * the ppp interface. */void ppp_recv_config( int unit, int mru, u32_t asyncmap, int pcomp, int accomp){ PPPControl *pc = &pppControl[unit]; int i; (void)accomp; (void)pcomp; (void)mru; /* Load the ACCM bits for the 32 control codes. */ for (i = 0; i < 32 / 8; i++) pc->inACCM[i] = (u_char)(asyncmap >> (i * 8)); PPPDEBUG((LOG_INFO, "ppp_recv_config[%d]: inACCM=%X %X %X %X\n", unit, pc->inACCM[0], pc->inACCM[1], pc->inACCM[2], pc->inACCM[3]));}#if 0/* * ccp_test - ask kernel whether a given compression method * is acceptable for use. Returns 1 if the method and parameters * are OK, 0 if the method is known but the parameters are not OK * (e.g. code size should be reduced), or -1 if the method is unknown. */int ccp_test( int unit, int opt_len, int for_transmit, u_char *opt_ptr){ return 0; /* XXX Currently no compression. */}/* * ccp_flags_set - inform kernel about the current state of CCP. */void ccp_flags_set(int unit, int isopen, int isup){ /* XXX */}/* * ccp_fatal_error - returns 1 if decompression was disabled as a * result of an error detected after decompression of a packet, * 0 otherwise. This is necessary because of patent nonsense. */int ccp_fatal_error(int unit){ /* XXX */ return 0;}#endif/* * get_idle_time - return how long the link has been idle. */int get_idle_time(int u, struct ppp_idle *ip){ /* XXX */ (void)u; (void)ip; return 0;}/* * Return user specified netmask, modified by any mask we might determine * for address `addr' (in network byte order). * Here we scan through the system's list of interfaces, looking for * any non-point-to-point interfaces which might appear to be on the same * network as `addr'. If we find any, we OR in their netmask to the * user-specified netmask. */u32_t GetMask(u32_t addr){ u32_t mask, nmask; htonl(addr); if (IN_CLASSA(addr)) /* determine network mask for address class */ nmask = IN_CLASSA_NET; else if (IN_CLASSB(addr)) nmask = IN_CLASSB_NET; else nmask = IN_CLASSC_NET; /* class D nets are disallowed by bad_ip_adrs */ mask = subnetMask | htonl(nmask); /* XXX * Scan through the system's network interfaces. * Get each netmask and OR them into our mask. */ return mask;}/* * sifvjcomp - config tcp header compression */int sifvjcomp( int pd, int vjcomp, int cidcomp, int maxcid){#if VJ_SUPPORT > 0 PPPControl *pc = &pppControl[pd]; pc->vjEnabled = vjcomp; pc->vjComp.compressSlot = cidcomp; pc->vjComp.maxSlotIndex = maxcid; PPPDEBUG((LOG_INFO, "sifvjcomp: VJ compress enable=%d slot=%d max slot=%d\n", vjcomp, cidcomp, maxcid));#endif return 0;}/* * pppifNetifInit - netif init callback */static err_t pppifNetifInit(struct netif *netif){ netif->name[0] = 'p'; netif->name[1] = 'p'; netif->output = pppifOutput; netif->mtu = pppMTU((int)netif->state); return ERR_OK;}/* * sifup - Config the interface up and enable IP packets to pass. */int sifup(int pd){ PPPControl *pc = &pppControl[pd]; int st = 1; if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) { st = 0; PPPDEBUG((LOG_WARNING, "sifup[%d]: bad parms\n", pd)); } else { netif_remove(&pc->netif); if (netif_add(&pc->netif, &pc->addrs.our_ipaddr, &pc->addrs.netmask, &pc->addrs.his_ipaddr, (void *)pd, pppifNetifInit, ip_input)) { netif_set_up(&pc->netif); pc->if_up = 1; pc->errCode = PPPERR_NONE; PPPDEBUG((LOG_DEBUG, "sifup: unit %d: linkStatusCB=%lx errCode=%d\n", pd, pc->linkStatusCB, pc->errCode)); if(pc->linkStatusCB) pc->linkStatusCB(pc->linkStatusCtx, pc->errCode, &pc->addrs); } else { st = 0; PPPDEBUG((LOG_ERR, "sifup[%d]: netif_add failed\n", pd)); } } return st;}/* * sifnpmode - Set the mode for handling packets for a given NP. */int sifnpmode(int u, int proto, enum NPmode mode){ (void)u; (void)proto; (void)mode; return 0;}/* * sifdown - Config the interface down and disable IP. */int sifdown(int pd){ PPPControl *pc = &pppControl[pd]; int st = 1; if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) { st = 0; PPPDEBUG((LOG_WARNING, "sifdown[%d]: bad parms\n", pd)); } else { pc->if_up = 0; netif_remove(&pc->netif); PPPDEBUG((LOG_DEBUG, "sifdown: unit %d: linkStatusCB=%lx errCode=%d\n", pd, pc->linkStatusCB, pc->errCode)); if(pc->linkStatusCB) pc->linkStatusCB(pc->linkStatusCtx, PPPERR_CONNECT, NULL); } return st;}/* * sifaddr - Config the interface IP addresses and netmask. */int sifaddr( int pd, /* Interface unit ??? */ u32_t o, /* Our IP address ??? */ u32_t h, /* His IP address ??? */ u32_t m, /* IP subnet mask ??? */ u32_t ns1, /* Primary DNS */ u32_t ns2 /* Secondary DNS */){ PPPControl *pc = &pppControl[pd]; int st = 1; if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) { st = 0; PPPDEBUG((LOG_WARNING, "sifup[%d]: bad parms\n", pd)); } else { memcpy(&pc->addrs.our_ipaddr, &o, sizeof(o)); memcpy(&pc->addrs.his_ipaddr, &h, sizeof(h)); memcpy(&pc->addrs.netmask, &m, sizeof(m)); memcpy(&pc->addrs.dns1, &ns1, sizeof(ns1)); memcpy(&pc->addrs.dns2, &ns2, sizeof(ns2)); } return st;}/* * cifaddr - Clear the interface IP addresses, and delete routes * through the interface if possible. */int cifaddr( int pd, /* Interface unit ??? */ u32_t o, /* Our IP address ??? */ u32_t h /* IP broadcast address ??? */){ PPPControl *pc = &pppControl[pd]; int st = 1; (void)o; (void)h; if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) { st = 0; PPPDEBUG((LOG_WARNING, "sifup[%d]: bad parms\n", pd)); } else { IP4_ADDR(&pc->addrs.our_ipaddr, 0,0,0,0); IP4_ADDR(&pc->addrs.his_ipaddr, 0,0,0,0); IP4_ADDR(&pc->addrs.netmask, 255,255,255,0); IP4_ADDR(&pc->addrs.dns1, 0,0,0,0); IP4_ADDR(&pc->addrs.dns2, 0,0,0,0); } return st;}/* * sifdefaultroute - assign a default route through the address given. */int sifdefaultroute(int pd, u32_t l, u32_t g){ PPPControl *pc = &pppControl[pd]; int st = 1; (void)l; (void)g; if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) { st = 0; PPPDEBUG((LOG_WARNING, "sifup[%d]: bad parms\n", pd)); } else { netif_set_default(&pc->netif); } /* TODO: check how PPP handled the netMask, previously not set by ipSetDefault */ return st;}/* * cifdefaultroute - delete a default route through the address given. */int cifdefaultroute(int pd, u32_t l, u32_t g){ PPPControl *pc = &pppControl[pd]; int st = 1; (void)l; (void)g; if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) { st = 0; PPPDEBUG((LOG_WARNING, "sifup[%d]: bad parms\n", pd)); } else { netif_set_default(NULL); } return st;}voidpppMainWakeup(int pd){ PPPDEBUG((LOG_DEBUG, "pppMainWakeup: unit %d\n", pd)); sio_read_abort(pppControl[pd].fd);}/* these callbacks are necessary because lcp_* functions must be called in the same context as pppInput(), namely the tcpip_thread(), essentially because they manipulate timeouts which are thread-private*/static voidpppStartCB(void *arg){ int pd = (int)arg; PPPDEBUG((LOG_DEBUG, "pppStartCB: unit %d\n", pd)); lcp_lowerup(pd); lcp_open(pd); /* Start protocol */}static voidpppStopCB(void *arg){ int pd = (int)arg; PPPDEBUG((LOG_DEBUG, "pppStopCB: unit %d\n", pd)); lcp_close(pd, "User request");}static voidpppHupCB(void *arg){ int pd = (int)arg; PPPDEBUG((LOG_DEBUG, "pppHupCB: unit %d\n", pd)); lcp_lowerdown(pd); link_terminated(pd);}/**********************************//*** LOCAL FUNCTION DEFINITIONS ***//**********************************//* The main PPP process function. This implements the state machine according * to section 4 of RFC 1661: The Point-To-Point Protocol. */static void pppMain(void *arg){ int pd = (int)arg; struct pbuf *p; PPPControl* pc; pc = &pppControl[pd]; p = pbuf_alloc(PBUF_RAW, PPP_MRU+PPP_HDRLEN, PBUF_RAM); if(!p) { LWIP_ASSERT("p != NULL", p); pc->errCode = PPPERR_ALLOC; goto out; } /* * Start the connection and handle incoming events (packet or timeout). */ PPPDEBUG((LOG_INFO, "pppMain: unit %d: Connecting\n", pd)); tcpip_callback(pppStartCB, arg); while (lcp_phase[pd] != PHASE_DEAD) { if (pc->kill_link) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -