diff --git a/src/netif/ppp/auth.c b/src/netif/ppp/auth.c index 7e5d546b..694283e6 100644 --- a/src/netif/ppp/auth.c +++ b/src/netif/ppp/auth.c @@ -569,10 +569,11 @@ link_required(unit) void start_link(unit) int unit; { + ppp_pcb *pcb = &ppp_pcb_list[unit]; char *msg; status = EXIT_NEGOTIATION_FAILED; - new_phase(unit, PHASE_SERIALCONN); + new_phase(pcb, PHASE_SERIALCONN); hungup = 0; devfd = the_channel->connect(); @@ -608,18 +609,18 @@ void start_link(unit) notice("Starting negotiation on %s", ppp_devnam); add_fd(fd_ppp); - new_phase(unit, PHASE_ESTABLISH); + new_phase(pcb, PHASE_ESTABLISH); lcp_lowerup(0); return; disconnect: - new_phase(unit, PHASE_DISCONNECT); + new_phase(pcb, PHASE_DISCONNECT); if (the_channel->disconnect) the_channel->disconnect(); fail: - new_phase(unit, PHASE_DEAD); + new_phase(pcb, PHASE_DEAD); if (the_channel->cleanup) (*the_channel->cleanup)(); } @@ -633,10 +634,10 @@ void link_terminated(unit) int unit; { - ppp_pcb *pc = &ppp_pcb_list[unit]; - if (pc->phase == PHASE_DEAD || pc->phase == PHASE_MASTER) + ppp_pcb *pcb = &ppp_pcb_list[unit]; + if (pcb->phase == PHASE_DEAD || pcb->phase == PHASE_MASTER) return; - new_phase(unit, PHASE_DISCONNECT); + new_phase(pcb, PHASE_DISCONNECT); #if 0 /* UNUSED */ if (pap_logout_hook) { @@ -656,7 +657,7 @@ link_terminated(unit) lcp_lowerdown(0); new_phase(unit, PHASE_DEAD); - ppp_link_terminated(unit); + ppp_link_terminated(pcb); #if 0 /* * Delete pid files before disestablishing ppp. Otherwise it @@ -697,11 +698,11 @@ link_terminated(unit) if (doing_multilink && multilink_master) { if (!bundle_terminating) - new_phase(unit, PHASE_MASTER); + new_phase(pcb, PHASE_MASTER); else mp_bundle_terminated(); } else - new_phase(unit, PHASE_DEAD); + new_phase(pcb, PHASE_DEAD); #endif } @@ -712,20 +713,20 @@ void link_down(unit) int unit; { - ppp_pcb *pc = &ppp_pcb_list[unit]; + ppp_pcb *pcb = &ppp_pcb_list[unit]; #if PPP_NOTIFY notify(link_down_notifier, 0); #endif /* #if PPP_NOTIFY */ if (!doing_multilink) { upper_layers_down(unit); - if (pc->phase != PHASE_DEAD && pc->phase != PHASE_MASTER) - new_phase(unit, PHASE_ESTABLISH); + if (pcb->phase != PHASE_DEAD && pcb->phase != PHASE_MASTER) + new_phase(pcb, PHASE_ESTABLISH); } /* XXX if doing_multilink, should do something to stop network-layer traffic on the link */ - ppp_link_down(unit); + ppp_link_down(pcb); } void upper_layers_down(int unit) @@ -753,6 +754,7 @@ void link_established(unit) int unit; { + ppp_pcb *pcb = &ppp_pcb_list[unit]; int auth; #if 0 /* UNUSED */ lcp_options *wo = &lcp_wantoptions[unit]; @@ -763,7 +765,6 @@ link_established(unit) lcp_options *ho = &lcp_hisoptions[unit]; int i; struct protent *protp; - ppp_pcb *pc = &ppp_pcb_list[unit]; /* * Tell higher-level protocols that LCP is up. @@ -814,18 +815,18 @@ link_established(unit) } #endif /* UNUSED */ - new_phase(unit, PHASE_AUTHENTICATE); + new_phase(pcb, PHASE_AUTHENTICATE); auth = 0; #if PPP_SERVER #if EAP_SUPPORT if (go->neg_eap) { - eap_authpeer(unit, pc->settings.our_name); + eap_authpeer(unit, pcb->settings.our_name); auth |= EAP_PEER; } else #endif /* EAP_SUPPORT */ #if CHAP_SUPPORT if (go->neg_chap) { - chap_auth_peer(unit, pc->settings.our_name, CHAP_DIGEST(go->chap_mdtype)); + chap_auth_peer(unit, pcb->settings.our_name, CHAP_DIGEST(go->chap_mdtype)); auth |= CHAP_PEER; } else #endif /* CHAP_SUPPORT */ @@ -840,19 +841,19 @@ link_established(unit) #if EAP_SUPPORT if (ho->neg_eap) { - eap_authwithpeer(unit, pc->settings.user); + eap_authwithpeer(unit, pcb->settings.user); auth |= EAP_WITHPEER; } else #endif /* EAP_SUPPORT */ #if CHAP_SUPPORT if (ho->neg_chap) { - chap_auth_with_peer(unit, pc->settings.user, CHAP_DIGEST(ho->chap_mdtype)); + chap_auth_with_peer(unit, pcb->settings.user, CHAP_DIGEST(ho->chap_mdtype)); auth |= CHAP_WITHPEER; } else #endif /* CHAP_SUPPORT */ #if PAP_SUPPORT if (ho->neg_upap) { - upap_authwithpeer(unit, pc->settings.user, pc->settings.passwd); + upap_authwithpeer(unit, pcb->settings.user, pcb->settings.passwd); auth |= PAP_WITHPEER; } else #endif /* PAP_SUPPORT */ @@ -872,6 +873,7 @@ static void network_phase(unit) int unit; { + ppp_pcb *pcb = &ppp_pcb_list[unit]; #if 0 /* UNUSED */ lcp_options *go = &lcp_gotoptions[unit]; #endif /* UNUSED */ @@ -906,7 +908,7 @@ network_phase(unit) * If we negotiated callback, do it now. */ if (go->neg_cbcp) { - new_phase(unit, PHASE_CALLBACK); + new_phase(pcb, PHASE_CALLBACK); (*cbcp_protent.open)(unit); return; } @@ -929,6 +931,7 @@ void start_networks(unit) int unit; { + ppp_pcb *pcb = &ppp_pcb_list[unit]; #if CCP_SUPPORT || ECP_SUPPORT int i; struct protent *protp; @@ -940,7 +943,7 @@ start_networks(unit) int mppe_required; #endif /* MPPE */ - new_phase(unit, PHASE_NETWORK); + new_phase(pcb, PHASE_NETWORK); #ifdef HAVE_MULTILINK if (multilink) { @@ -1203,21 +1206,21 @@ np_up(unit, proto) int unit, proto; { int tlim; - ppp_pcb *pc = &ppp_pcb_list[unit]; + ppp_pcb *pcb = &ppp_pcb_list[unit]; if (num_np_up == 0) { /* * At this point we consider that the link has come up successfully. */ - pc->status = EXIT_OK; - new_phase(unit, PHASE_RUNNING); + pcb->status = EXIT_OK; + new_phase(pcb, PHASE_RUNNING); #if 0 /* UNUSED */ if (idle_time_hook != 0) tlim = (*idle_time_hook)(NULL); else #endif /* UNUSED */ - tlim = pc->settings.idle_time_limit; + tlim = pcb->settings.idle_time_limit; if (tlim > 0) TIMEOUT(check_idle, NULL, tlim); @@ -1225,8 +1228,8 @@ np_up(unit, proto) * Set a timeout to close the connection once the maximum * connect time has expired. */ - if (pc->settings.maxconnect > 0) - TIMEOUT(connect_time_expired, 0, pc->settings.maxconnect); + if (pcb->settings.maxconnect > 0) + TIMEOUT(connect_time_expired, 0, pcb->settings.maxconnect); #ifdef MAXOCTETS if (maxoctets > 0) @@ -1251,13 +1254,14 @@ void np_down(unit, proto) int unit, proto; { + ppp_pcb *pcb = &ppp_pcb_list[unit]; if (--num_np_up == 0) { UNTIMEOUT(check_idle, NULL); UNTIMEOUT(connect_time_expired, NULL); #ifdef MAXOCTETS UNTIMEOUT(check_maxoctets, NULL); #endif - new_phase(unit, PHASE_NETWORK); + new_phase(pcb, PHASE_NETWORK); } } @@ -1323,12 +1327,12 @@ check_idle(arg) void *arg; { /* FIXME: fix forced unit 0 */ - ppp_pcb *pc = &ppp_pcb_list[0]; + ppp_pcb *pcb = &ppp_pcb_list[0]; struct ppp_idle idle; time_t itime; int tlim; - if (!get_idle_time(0, &idle)) + if (!get_idle_time(pcb, &idle)) return; #if 0 /* UNUSED */ if (idle_time_hook != 0) { @@ -1336,14 +1340,14 @@ check_idle(arg) } else { #endif /* UNUSED */ itime = LWIP_MIN(idle.xmit_idle, idle.recv_idle); - tlim = pc->settings.idle_time_limit - itime; + tlim = pcb->settings.idle_time_limit - itime; #if 0 /* UNUSED */ } #endif /* UNUSED */ if (tlim <= 0) { /* link is idle: shut it down. */ notice("Terminating connection due to lack of activity."); - pc->status = EXIT_IDLE_TIMEOUT; + pcb->status = EXIT_IDLE_TIMEOUT; lcp_close(0, "Link inactive"); #if 0 /* UNUSED */ need_holdoff = 0; @@ -1361,9 +1365,9 @@ connect_time_expired(arg) void *arg; { /* FIXME: fix forced unit 0 */ - ppp_pcb *pc = &ppp_pcb_list[0]; + ppp_pcb *pcb = &ppp_pcb_list[0]; info("Connect time expired"); - pc->status = EXIT_CONNECT_TIME; + pcb->status = EXIT_CONNECT_TIME; lcp_close(0, "Connect time expired"); /* Close connection */ } @@ -1517,26 +1521,26 @@ auth_reset(unit) { lcp_options *go = &lcp_gotoptions[unit]; lcp_options *ao = &lcp_allowoptions[unit]; - ppp_pcb *pc = &ppp_pcb_list[unit]; + ppp_pcb *pcb = &ppp_pcb_list[unit]; - if( pc->settings.passwd[0] ) { + if( pcb->settings.passwd[0] ) { #if PAP_SUPPORT - ao->neg_upap = !pc->settings.refuse_pap; + ao->neg_upap = !pcb->settings.refuse_pap; #endif /* PAP_SUPPORT */ #if EAP_SUPPORT - ao->neg_eap = !pc->settings.refuse_eap; + ao->neg_eap = !pcb->settings.refuse_eap; #endif /* EAP_SUPPORT */ #if CHAP_SUPPORT ao->chap_mdtype = MDTYPE_NONE; - if(!pc->settings.refuse_chap) + if(!pcb->settings.refuse_chap) ao->chap_mdtype |= MDTYPE_MD5; #if MSCHAP_SUPPORT - if(!pc->settings.refuse_mschap) + if(!pcb->settings.refuse_mschap) ao->chap_mdtype |= MDTYPE_MICROSOFT; - if(!pc->settings.refuse_mschap_v2) + if(!pcb->settings.refuse_mschap_v2) ao->chap_mdtype |= MDTYPE_MICROSOFT_V2; #endif /* MSCHAP_SUPPORT */ @@ -1990,23 +1994,23 @@ get_secret(unit, client, server, secret, secret_len, am_server) int am_server; { int len; - ppp_pcb *pc = &ppp_pcb_list[unit]; + ppp_pcb *pcb = &ppp_pcb_list[unit]; LWIP_UNUSED_ARG(unit); LWIP_UNUSED_ARG(server); LWIP_UNUSED_ARG(am_server); - if(!client || !client[0] || strcmp(client, pc->settings.user)) { + if(!client || !client[0] || strcmp(client, pcb->settings.user)) { return 0; } - len = (int)strlen(pc->settings.passwd); + len = (int)strlen(pcb->settings.passwd); if (len > MAXSECRETLEN) { error("Secret for %s on %s is too long", client, server); len = MAXSECRETLEN; } - MEMCPY(secret, pc->settings.passwd, len); + MEMCPY(secret, pcb->settings.passwd, len); *secret_len = len; return 1; diff --git a/src/netif/ppp/ccp.c b/src/netif/ppp/ccp.c index d2e04569..de1ad4e8 100644 --- a/src/netif/ppp/ccp.c +++ b/src/netif/ppp/ccp.c @@ -1084,6 +1084,7 @@ ccp_reqci(f, p, lenp, dont_nak) int *lenp; int dont_nak; { + ppp_pcb *pcb = &ppp_pcb_list[f->unit]; int ret, newret, res; u_char *p0, *retp; int len, clen, type, nb; @@ -1200,9 +1201,9 @@ ccp_reqci(f, p, lenp, dont_nak) * because MPPE frames **grow**. The kernel [must] * allocate MPPE_PAD extra bytes in xmit buffers. */ - mtu = netif_get_mtu(f->unit); + mtu = netif_get_mtu(pcb); if (mtu) - netif_set_mtu(f->unit, mtu - MPPE_PAD); + netif_set_mtu(pcb, mtu - MPPE_PAD); else newret = CONFREJ; } diff --git a/src/netif/ppp/chap-new.c b/src/netif/ppp/chap-new.c index 62556c52..6d246dae 100644 --- a/src/netif/ppp/chap-new.c +++ b/src/netif/ppp/chap-new.c @@ -282,6 +282,8 @@ chap_auth_with_peer(int unit, char *our_name, int digest_code) static void chap_timeout(void *arg) { + /* FIXME: fix forced unit 0 */ + ppp_pcb *pcb = &ppp_pcb_list[0]; struct chap_server_state *ss = arg; ss->flags &= ~TIMEOUT_PENDING; @@ -296,7 +298,7 @@ chap_timeout(void *arg) return; } - ppp_write(0, ss->challenge, ss->challenge_pktlen); + ppp_write(pcb, ss->challenge, ss->challenge_pktlen); ++ss->challenge_xmits; ss->flags |= TIMEOUT_PENDING; TIMEOUT(chap_timeout, arg, chap_timeout_time); @@ -337,6 +339,8 @@ static void chap_handle_response(struct chap_server_state *ss, int id, unsigned char *pkt, int len) { + /* FIXME: fix forced unit 0 */ + ppp_pcb *pcb = &ppp_pcb_list[0]; int response_len, ok, mlen; unsigned char *response, *p; char *name = NULL; /* initialized to shut gcc up */ @@ -397,7 +401,7 @@ chap_handle_response(struct chap_server_state *ss, int id, p[3] = len; if (mlen > 0) memcpy(p + CHAP_HDRLEN, ss->message, mlen); - ppp_write(0, outpacket_buf, PPP_HDRLEN + len); + ppp_write(pcb, outpacket_buf, PPP_HDRLEN + len); if (ss->flags & CHALLENGE_VALID) { ss->flags &= ~CHALLENGE_VALID; @@ -474,6 +478,8 @@ static void chap_respond(struct chap_client_state *cs, int id, unsigned char *pkt, int len) { + /* FIXME: fix forced unit 0 */ + ppp_pcb *pcb = &ppp_pcb_list[0]; int clen, nlen; int secret_len; unsigned char *p; @@ -521,7 +527,7 @@ chap_respond(struct chap_client_state *cs, int id, p[2] = len >> 8; p[3] = len; - ppp_write(0, response, PPP_HDRLEN + len); + ppp_write(pcb, response, PPP_HDRLEN + len); } static void diff --git a/src/netif/ppp/eap.c b/src/netif/ppp/eap.c index 0e382313..95176380 100644 --- a/src/netif/ppp/eap.c +++ b/src/netif/ppp/eap.c @@ -268,6 +268,7 @@ static void eap_send_failure(esp) eap_state *esp; { + ppp_pcb *pcb = &ppp_pcb_list[esp->es_unit]; u_char *outp; outp = outpacket_buf; @@ -279,7 +280,7 @@ eap_state *esp; PUTCHAR(esp->es_server.ea_id, outp); PUTSHORT(EAP_HEADERLEN, outp); - ppp_write(esp->es_unit, outpacket_buf, EAP_HEADERLEN + PPP_HDRLEN); + ppp_write(pcb, outpacket_buf, EAP_HEADERLEN + PPP_HDRLEN); esp->es_server.ea_state = eapBadAuth; auth_peer_fail(esp->es_unit, PPP_EAP); @@ -293,6 +294,7 @@ static void eap_send_success(esp) eap_state *esp; { + ppp_pcb *pcb = &ppp_pcb_list[esp->es_unit]; u_char *outp; outp = outpacket_buf; @@ -304,7 +306,7 @@ eap_state *esp; PUTCHAR(esp->es_server.ea_id, outp); PUTSHORT(EAP_HEADERLEN, outp); - ppp_write(esp->es_unit, outpacket_buf, PPP_HDRLEN + EAP_HEADERLEN); + ppp_write(pcb, outpacket_buf, PPP_HDRLEN + EAP_HEADERLEN); auth_peer_success(esp->es_unit, PPP_EAP, 0, esp->es_server.ea_peer, esp->es_server.ea_peerlen); @@ -648,6 +650,7 @@ static void eap_send_request(esp) eap_state *esp; { + ppp_pcb *pcb = &ppp_pcb_list[esp->es_unit]; u_char *outp; u_char *lenloc; u_char *ptr; @@ -867,7 +870,7 @@ eap_state *esp; outlen = (outp - outpacket_buf) - PPP_HDRLEN; PUTSHORT(outlen, lenloc); - ppp_write(esp->es_unit, outpacket_buf, outlen + PPP_HDRLEN); + ppp_write(pcb, outpacket_buf, outlen + PPP_HDRLEN); esp->es_server.ea_requests++; @@ -1066,6 +1069,7 @@ u_char typenum; u_char *str; int lenstr; { + ppp_pcb *pcb = &ppp_pcb_list[esp->es_unit]; u_char *outp; int msglen; @@ -1083,7 +1087,7 @@ int lenstr; MEMCPY(outp, str, lenstr); } - ppp_write(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen); + ppp_write(pcb, outpacket_buf, PPP_HDRLEN + msglen); } /* @@ -1097,6 +1101,7 @@ u_char *hash; char *name; int namelen; { + ppp_pcb *pcb = &ppp_pcb_list[esp->es_unit]; u_char *outp; int msglen; @@ -1118,7 +1123,7 @@ int namelen; MEMCPY(outp, name, namelen); } - ppp_write(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen); + ppp_write(pcb, outpacket_buf, PPP_HDRLEN + msglen); } #ifdef USE_SRP @@ -1133,6 +1138,7 @@ u_char subtypenum; u_char *str; int lenstr; { + ppp_pcb *pcb = &ppp_pcb_list[esp->es_unit]; u_char *outp; int msglen; @@ -1151,7 +1157,7 @@ int lenstr; MEMCPY(outp, str, lenstr); } - ppp_write(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen); + ppp_write(pcb, outpacket_buf, PPP_HDRLEN + msglen); } /* @@ -1164,6 +1170,7 @@ u_char id; u_int32_t flags; u_char *str; { + ppp_pcb *pcb = &ppp_pcb_list[esp->es_unit]; u_char *outp; int msglen; @@ -1182,7 +1189,7 @@ u_char *str; PUTLONG(flags, outp); MEMCPY(outp, str, SHA_DIGESTSIZE); - ppp_write(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen); + ppp_write(pcb, outpacket_buf, PPP_HDRLEN + msglen); } #endif /* USE_SRP */ @@ -1192,6 +1199,7 @@ eap_state *esp; u_char id; u_char type; { + ppp_pcb *pcb = &ppp_pcb_list[esp->es_unit]; u_char *outp; int msglen; @@ -1207,7 +1215,7 @@ u_char type; PUTCHAR(EAPT_NAK, outp); PUTCHAR(type, outp); - ppp_write(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen); + ppp_write(pcb, outpacket_buf, PPP_HDRLEN + msglen); } #ifdef USE_SRP diff --git a/src/netif/ppp/fsm.c b/src/netif/ppp/fsm.c index 57b366b2..856ccfcd 100644 --- a/src/netif/ppp/fsm.c +++ b/src/netif/ppp/fsm.c @@ -808,6 +808,7 @@ fsm_sdata(f, code, id, data, datalen) u_char *data; int datalen; { + ppp_pcb *pcb = &ppp_pcb_list[f->unit]; u_char *outp; int outlen; @@ -822,7 +823,7 @@ fsm_sdata(f, code, id, data, datalen) PUTCHAR(code, outp); PUTCHAR(id, outp); PUTSHORT(outlen, outp); - ppp_write(f->unit, outpacket_buf, outlen + PPP_HDRLEN); + ppp_write(pcb, outpacket_buf, outlen + PPP_HDRLEN); } #endif /* PPP_SUPPORT */ diff --git a/src/netif/ppp/ipcp.c b/src/netif/ppp/ipcp.c index 2434b5f1..3b8589e5 100644 --- a/src/netif/ppp/ipcp.c +++ b/src/netif/ppp/ipcp.c @@ -1756,6 +1756,7 @@ static int ip_demand_conf(u) int u; { + ppp_pcb *pcb = &ppp_pcb_list[u]; ipcp_options *wo = &ipcp_wantoptions[u]; if (wo->hisaddr == 0 && !noremoteip) { @@ -1769,18 +1770,18 @@ ip_demand_conf(u) wo->accept_local = 1; ask_for_local = 0; /* don't tell the peer this address */ } - if (!sifaddr(u, wo->ouraddr, wo->hisaddr, get_mask(wo->ouraddr))) + if (!sifaddr(pcb, wo->ouraddr, wo->hisaddr, get_mask(wo->ouraddr))) return 0; - if (!sifup(u)) + if (!sifup(pcb)) return 0; - if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE)) + if (!sifnpmode(pcb, PPP_IP, NPMODE_QUEUE)) return 0; if (wo->default_route) - if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr, + if (sifdefaultroute(pcb, wo->ouraddr, wo->hisaddr, wo->replace_default_route)) default_route_set[u] = 1; if (wo->proxy_arp) - if (sifproxyarp(u, wo->hisaddr)) + if (sifproxyarp(pcb, wo->hisaddr)) proxy_arp_set[u] = 1; notice("local IP address %I", wo->ouraddr); @@ -1800,8 +1801,8 @@ static void ipcp_up(f) fsm *f; { + ppp_pcb *pcb = &ppp_pcb_list[f->unit]; u_int32_t mask; - ppp_pcb *pc = &ppp_pcb_list[f->unit]; ipcp_options *ho = &ipcp_hisoptions[f->unit]; ipcp_options *go = &ipcp_gotoptions[f->unit]; ipcp_options *wo = &ipcp_wantoptions[f->unit]; @@ -1846,8 +1847,8 @@ ipcp_up(f) if (go->dnsaddr[1]) script_setenv("DNS2", ip_ntoa(go->dnsaddr[1]), 0); #endif /* UNUSED */ - if (pc->settings.usepeerdns && (go->dnsaddr[0] || go->dnsaddr[1])) { - sdns(f->unit, go->dnsaddr[0], go->dnsaddr[1]); + if (pcb->settings.usepeerdns && (go->dnsaddr[0] || go->dnsaddr[1])) { + sdns(pcb, go->dnsaddr[0], go->dnsaddr[1]); #if 0 /* UNUSED */ script_setenv("USEPEERDNS", "1", 0); create_resolv(go->dnsaddr[0], go->dnsaddr[1]); @@ -1867,7 +1868,7 @@ ipcp_up(f) #endif /* Unused */ /* set tcp compression */ - sifvjcomp(f->unit, ho->neg_vj, ho->cflag, ho->maxslotindex); + sifvjcomp(pcb, ho->neg_vj, ho->cflag, ho->maxslotindex); #if DEMAND_SUPPORT /* @@ -1894,7 +1895,7 @@ ipcp_up(f) /* Set the interface to the new addresses */ mask = get_mask(go->ouraddr); - if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) { + if (!sifaddr(pcb, go->ouraddr, ho->hisaddr, mask)) { #if PPP_DEBUG warn("Interface configuration failed"); #endif /* PPP_DEBUG */ @@ -1904,18 +1905,18 @@ ipcp_up(f) /* assign a default route through the interface if required */ if (ipcp_wantoptions[f->unit].default_route) - if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr, + if (sifdefaultroute(pcb, go->ouraddr, ho->hisaddr, wo->replace_default_route)) default_route_set[f->unit] = 1; /* Make a proxy ARP entry if requested. */ if (ho->hisaddr != 0 && ipcp_wantoptions[f->unit].proxy_arp) - if (sifproxyarp(f->unit, ho->hisaddr)) + if (sifproxyarp(pcb, ho->hisaddr)) proxy_arp_set[f->unit] = 1; } demand_rexmit(PPP_IP,go->ouraddr); - sifnpmode(f->unit, PPP_IP, NPMODE_PASS); + sifnpmode(pcb, PPP_IP, NPMODE_PASS); } else #endif /* DEMAND_SUPPORT */ @@ -1926,7 +1927,7 @@ ipcp_up(f) mask = get_mask(go->ouraddr); #if !(defined(SVR4) && (defined(SNI) || defined(__USLC__))) - if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) { + if (!sifaddr(pcb, go->ouraddr, ho->hisaddr, mask)) { #if PPP_DEBUG warn("Interface configuration failed"); #endif /* PPP_DEBUG */ @@ -1936,7 +1937,7 @@ ipcp_up(f) #endif /* bring the interface up for IP */ - if (!sifup(f->unit)) { + if (!sifup(pcb)) { #if PPP_DEBUG warn("Interface failed to come up"); #endif /* PPP_DEBUG */ @@ -1945,7 +1946,7 @@ ipcp_up(f) } #if (defined(SVR4) && (defined(SNI) || defined(__USLC__))) - if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) { + if (!sifaddr(pcb, go->ouraddr, ho->hisaddr, mask)) { #if PPP_DEBUG warn("Interface configuration failed"); #endif /* PPP_DEBUG */ @@ -1953,17 +1954,17 @@ ipcp_up(f) return; } #endif - sifnpmode(f->unit, PPP_IP, NPMODE_PASS); + sifnpmode(pcb, PPP_IP, NPMODE_PASS); /* assign a default route through the interface if required */ if (ipcp_wantoptions[f->unit].default_route) - if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr, + if (sifdefaultroute(pcb, go->ouraddr, ho->hisaddr, wo->replace_default_route)) default_route_set[f->unit] = 1; /* Make a proxy ARP entry if requested. */ if (ho->hisaddr != 0 && ipcp_wantoptions[f->unit].proxy_arp) - if (sifproxyarp(f->unit, ho->hisaddr)) + if (sifproxyarp(pcb, ho->hisaddr)) proxy_arp_set[f->unit] = 1; ipcp_wantoptions[0].ouraddr = go->ouraddr; @@ -2004,6 +2005,7 @@ static void ipcp_down(f) fsm *f; { + ppp_pcb *pcb = &ppp_pcb_list[f->unit]; IPCPDEBUG(("ipcp: down")); #if PPP_STATS_SUPPORT /* XXX a bit IPv4-centric here, we only need to get the stats @@ -2023,7 +2025,7 @@ ipcp_down(f) ipcp_is_up = 0; np_down(f->unit, PPP_IP); } - sifvjcomp(f->unit, 0, 0, 0); + sifvjcomp(pcb, 0, 0, 0); #if PPP_STATS_SUPPORT print_link_stats(); /* _after_ running the notifiers and ip_down_hook(), @@ -2037,15 +2039,15 @@ ipcp_down(f) * to queue up outgoing packets (for now). */ if (demand) { - sifnpmode(f->unit, PPP_IP, NPMODE_QUEUE); + sifnpmode(pcb, PPP_IP, NPMODE_QUEUE); } else #endif /* DEMAND_SUPPORT */ { - sifnpmode(f->unit, PPP_IP, NPMODE_DROP); - sifdown(f->unit); + sifnpmode(pcb, PPP_IP, NPMODE_DROP); + sifdown(pcb); ipcp_clear_addrs(f->unit, ipcp_gotoptions[f->unit].ouraddr, ipcp_hisoptions[f->unit].hisaddr, 0); - cdns(f->unit, ipcp_gotoptions[f->unit].dnsaddr[0], ipcp_gotoptions[f->unit].dnsaddr[1]); + cdns(pcb, ipcp_gotoptions[f->unit].dnsaddr[0], ipcp_gotoptions[f->unit].dnsaddr[1]); } } @@ -2056,8 +2058,10 @@ ipcp_down(f) */ static void ipcp_clear_addrs(int unit, u_int32_t ouraddr, u_int32_t hisaddr, bool replacedefaultroute) { + ppp_pcb *pcb = &ppp_pcb_list[unit]; + if (proxy_arp_set[unit]) { - cifproxyarp(unit, hisaddr); + cifproxyarp(pcb, hisaddr); proxy_arp_set[unit] = 0; } /* If replacedefaultroute, sifdefaultroute will be called soon @@ -2069,10 +2073,10 @@ static void ipcp_clear_addrs(int unit, u_int32_t ouraddr, u_int32_t hisaddr, boo * is one saved by an sifdefaultroute with replacedefaultroute. */ if (!replacedefaultroute && default_route_set[unit]) { - cifdefaultroute(unit, ouraddr, hisaddr); + cifdefaultroute(pcb, ouraddr, hisaddr); default_route_set[unit] = 0; } - cifaddr(unit, ouraddr, hisaddr); + cifaddr(pcb, ouraddr, hisaddr); } diff --git a/src/netif/ppp/lcp.c b/src/netif/ppp/lcp.c index 12fbe0de..acfd4116 100644 --- a/src/netif/ppp/lcp.c +++ b/src/netif/ppp/lcp.c @@ -462,12 +462,12 @@ lcp_close(unit, reason) int unit; char *reason; { - ppp_pcb *pc = &ppp_pcb_list[unit]; + ppp_pcb *pcb = &ppp_pcb_list[unit]; fsm *f = &lcp_fsm[unit]; int oldstate; - if (pc->phase != PHASE_DEAD && pc->phase != PHASE_MASTER) - new_phase(unit, PHASE_TERMINATE); + if (pcb->phase != PHASE_DEAD && pcb->phase != PHASE_MASTER) + new_phase(pcb, PHASE_TERMINATE); if (f->flags & DELAYED_UP) { UNTIMEOUT(lcp_delayed_up, f); @@ -497,19 +497,19 @@ void lcp_lowerup(unit) int unit; { + ppp_pcb *pcb = &ppp_pcb_list[unit]; lcp_options *wo = &lcp_wantoptions[unit]; fsm *f = &lcp_fsm[unit]; - ppp_pcb *pc = &ppp_pcb_list[unit]; /* * Don't use A/C or protocol compression on transmission, * but accept A/C and protocol compressed packets * if we are going to ask for A/C and protocol compression. */ #if PPPOS_SUPPORT - ppp_set_xaccm(unit, &xmit_accm[unit]); + ppp_set_xaccm(pcb, &xmit_accm[unit]); #endif /* PPPOS_SUPPORT */ - if (ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0) < 0 - || ppp_recv_config(unit, PPP_MRU, (lax_recv? 0: 0xffffffff), + if (ppp_send_config(pcb, PPP_MRU, 0xffffffff, 0, 0) < 0 + || ppp_recv_config(pcb, PPP_MRU, (lax_recv? 0: 0xffffffff), wo->neg_pcompression, wo->neg_accompression) < 0) return; peer_mru[unit] = PPP_MRU; @@ -526,9 +526,9 @@ lcp_lowerup(unit) xmit_accm[unit][0])); #endif /* PPPOS_SUPPORT */ - if (pc->settings.listen_time != 0) { + if (pcb->settings.listen_time != 0) { f->flags |= DELAYED_UP; - TIMEOUTMS(lcp_delayed_up, f, pc->settings.listen_time); + TIMEOUTMS(lcp_delayed_up, f, pcb->settings.listen_time); } else fsm_lowerup(f); } @@ -2278,6 +2278,7 @@ static void lcp_up(f) fsm *f; { + ppp_pcb *pcb = &ppp_pcb_list[f->unit]; lcp_options *wo = &lcp_wantoptions[f->unit]; lcp_options *ho = &lcp_hisoptions[f->unit]; lcp_options *go = &lcp_gotoptions[f->unit]; @@ -2303,11 +2304,11 @@ lcp_up(f) #ifdef HAVE_MULTILINK if (!(multilink && go->neg_mrru && ho->neg_mrru)) #endif /* HAVE_MULTILINK */ - netif_set_mtu(f->unit, LWIP_MIN(LWIP_MIN(mtu, mru), ao->mru)); - ppp_send_config(f->unit, mtu, + netif_set_mtu(pcb, LWIP_MIN(LWIP_MIN(mtu, mru), ao->mru)); + ppp_send_config(pcb, mtu, (ho->neg_asyncmap? ho->asyncmap: 0xffffffff), ho->neg_pcompression, ho->neg_accompression); - ppp_recv_config(f->unit, mru, + ppp_recv_config(pcb, mru, (lax_recv? 0: go->neg_asyncmap? go->asyncmap: 0xffffffff), go->neg_pcompression, go->neg_accompression); @@ -2329,14 +2330,15 @@ static void lcp_down(f) fsm *f; { + ppp_pcb *pcb = &ppp_pcb_list[f->unit]; lcp_options *go = &lcp_gotoptions[f->unit]; lcp_echo_lowerdown(f->unit); link_down(f->unit); - ppp_send_config(f->unit, PPP_MRU, 0xffffffff, 0, 0); - ppp_recv_config(f->unit, PPP_MRU, + ppp_send_config(pcb, PPP_MRU, 0xffffffff, 0, 0); + ppp_recv_config(pcb, PPP_MRU, (go->neg_asyncmap? go->asyncmap: 0xffffffff), go->neg_pcompression, go->neg_accompression); peer_mru[f->unit] = PPP_MRU; diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index d5012819..e4851095 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -126,25 +126,6 @@ /*** LOCAL DEFINITIONS ***/ /*************************/ -/** PPP_INPROC_MULTITHREADED==1 call ppp_input using tcpip_callback(). - * Set this to 0 if pppos_input_proc is called inside tcpip_thread or with NO_SYS==1. - * Default is 1 for NO_SYS==0 (multithreaded) and 0 for NO_SYS==1 (single-threaded). - */ -#ifndef PPP_INPROC_MULTITHREADED -#define PPP_INPROC_MULTITHREADED (NO_SYS==0) -#endif - -/** PPP_INPROC_OWNTHREAD==1: start a dedicated RX thread per PPP session. - * Default is 0: call pppos_input() for received raw characters, character - * reception is up to the port */ -#ifndef PPP_INPROC_OWNTHREAD -#define PPP_INPROC_OWNTHREAD PPP_INPROC_MULTITHREADED -#endif - -#if PPP_INPROC_OWNTHREAD && !PPP_INPROC_MULTITHREADED - #error "PPP_INPROC_OWNTHREAD needs PPP_INPROC_MULTITHREADED==1" -#endif - /* * Buffers for outgoing packets. This must be accessed only from the appropriate * PPP task so that it doesn't need to be protected to avoid collisions. @@ -201,24 +182,7 @@ struct protent *protocols[] = { }; #if PPPOS_SUPPORT -/* PPP packet parser states. Current state indicates operation yet to be - * completed. */ -typedef enum { - PDIDLE = 0, /* Idle state - waiting. */ - PDSTART, /* Process start flag. */ - PDADDRESS, /* Process address field. */ - PDCONTROL, /* Process control field. */ - PDPROTOCOL1, /* Process protocol field 1. */ - PDPROTOCOL2, /* Process protocol field 2. */ - PDDATA /* Process data byte. */ -} ppp_dev_states; - #define ESCAPE_P(accm, c) ((accm)[(c) >> 3] & ppp_accm_mask[c & 0x07]) - -/** RX buffer size: this may be configured smaller! */ -#ifndef PPPOS_RX_BUFSIZE -#define PPPOS_RX_BUFSIZE (PPP_MRU + PPP_HDRLEN) -#endif #endif /* PPPOS_SUPPORT */ /* Prototypes for procedures local to this file. */ @@ -227,7 +191,7 @@ static void ppp_start(int pd); /** Initiate LCP open request */ static void ppp_input(int unit, void *arg); #if PPPOS_SUPPORT -static void ppp_receive_wakeup(int pd); +static void ppp_receive_wakeup(ppp_pcb *pcb); #endif /* #if PPPOS_SUPPORT */ static void ppp_stop(int pd); @@ -246,9 +210,9 @@ static err_t ppp_netif_init_cb(struct netif *netif); static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, ip_addr_t *ipaddr); #if PPPOE_SUPPORT -static err_t ppp_netif_output_over_ethernet(int pd, struct pbuf *p); +static err_t ppp_netif_output_over_ethernet(ppp_pcb *pcb, struct pbuf *p); /* function called by ppp_write() */ -static int ppp_write_over_ethernet(int pd, const u_char *s, int n); +static int ppp_write_over_ethernet(ppp_pcb *pcb, const u_char *s, int n); #endif /* PPPOE_SUPPORT */ /******************************/ @@ -308,7 +272,7 @@ ppp_pcb *ppp_new(void) { pcb->unit = pd; pcb->open_flag = 1; pcb->status = EXIT_OK; - new_phase(pd, PHASE_INITIALIZE); + new_phase(pcb, PHASE_INITIALIZE); pcb->settings.usepeerdns = 1; pcb->settings.persist = 1; @@ -390,7 +354,7 @@ int ppp_over_serial_open(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_s pcb->fd = fd; - pcb->rx.pd = unit; + pcb->rx.pd = pcb->unit; pcb->rx.fd = fd; #if VJ_SUPPORT @@ -410,26 +374,26 @@ int ppp_over_serial_open(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_s /* * Start the connection and handle incoming events (packet or timeout). */ - PPPDEBUG(LOG_INFO, ("ppp_over_serial_open: unit %d: Connecting\n", pd)); - ppp_start(unit); + PPPDEBUG(LOG_INFO, ("ppp_over_serial_open: unit %d: Connecting\n", pcb->unit)); + ppp_start(pcb->unit); #if PPP_INPROC_OWNTHREAD sys_thread_new(PPP_THREAD_NAME, ppp_input_thread, (void*)&pcb->rx, PPP_THREAD_STACKSIZE, PPP_THREAD_PRIO); #endif /* PPP_INPROC_OWNTHREAD */ - return unit; + return pcb->unit; } /* * ppp_set_xaccm - set the extended transmit ACCM for the interface. */ -void ppp_set_xaccm(int unit, ext_accm *accm) { - SMEMCPY(ppp_pcb_list[unit].out_accm, accm, sizeof(ext_accm)); +void ppp_set_xaccm(ppp_pcb *pcb, ext_accm *accm) { + SMEMCPY(pcb->out_accm, accm, sizeof(ext_accm)); PPPDEBUG(LOG_INFO, ("ppp_set_xaccm[%d]: out_accm=%X %X %X %X\n", - unit, - ppp_pcb_list[unit].out_accm[0], - ppp_pcb_list[unit].out_accm[1], - ppp_pcb_list[unit].out_accm[2], - ppp_pcb_list[unit].out_accm[3])); + pcb->unit, + pcb->out_accm[0], + pcb->out_accm[1], + pcb->out_accm[2], + pcb->out_accm[3])); } #endif /* PPPOS_SUPPORT */ @@ -500,7 +464,7 @@ ppp_close(ppp_pcb *pcb) /* This will leave us at PHASE_DEAD. */ ppp_stop(pcb->unit); #if PPP_INPROC_OWNTHREAD - ppp_receive_wakeup(pcb->unit); + ppp_receive_wakeup(pcb); #endif /* PPP_INPROC_OWNTHREAD */ #endif /* PPPOS_SUPPORT */ } @@ -554,7 +518,7 @@ ppp_hup(int pd) * or it is used in output ? have to find out... */ static void ppp_input(int unit, void *arg) { - ppp_pcb *pc = &ppp_pcb_list[unit]; + ppp_pcb *pcb = &ppp_pcb_list[unit]; struct pbuf *nb = (struct pbuf *)arg; u16_t protocol; int pd; @@ -583,7 +547,7 @@ static void ppp_input(int unit, void *arg) { * Until we get past the authentication phase, toss all packets * except LCP, LQR and authentication packets. */ - if (pc->phase <= PHASE_AUTHENTICATE + if (pcb->phase <= PHASE_AUTHENTICATE && !(protocol == PPP_LCP #if LQR_SUPPORT || protocol == PPP_LQR @@ -599,7 +563,7 @@ static void ppp_input(int unit, void *arg) { #endif /* EAP_SUPPORT */ )) { dbglog("discarding proto 0x%x in phase %d", - protocol, pc->phase); + protocol, pcb->phase); goto drop; } @@ -856,12 +820,11 @@ static u_char ppp_accm_mask[] = { #if PPP_INPROC_OWNTHREAD /** Wake up the task blocked in reading from serial line (if any) */ static void -ppp_receive_wakeup(int pd) +ppp_receive_wakeup(ppp_pcb *pcb) { - PPPDEBUG(LOG_DEBUG, ("ppp_receive_wakeup: unit %d\n", pd)); - if (ppp_pcb_list[pd].open_flag != 0) { - sio_read_abort(ppp_pcb_list[pd].fd); - } + PPPDEBUG(LOG_DEBUG, ("ppp_receive_wakeup: unit %d\n", pcb->unit)); + if (pcb->open_flag != 0) + sio_read_abort(pcb->fd); } #endif /* PPP_INPROC_OWNTHREAD */ #endif /* PPPOS_SUPPORT */ @@ -921,7 +884,7 @@ static err_t ppp_netif_init_cb(struct netif *netif) { netif->name[0] = 'p'; netif->name[1] = 'p'; netif->output = ppp_netif_output; - netif->mtu = netif_get_mtu((int)(size_t)netif->state); + netif->mtu = netif_get_mtu((ppp_pcb*)netif->state); netif->flags = NETIF_FLAG_POINTTOPOINT | NETIF_FLAG_LINK_UP; #if LWIP_NETIF_HOSTNAME /* @todo: Initialize interface hostname */ @@ -943,8 +906,9 @@ ppp_input_thread(void *arg) { int count; ppp_pcb_rx *pcrx = arg; + ppp_pcb *pcb = &ppp_pcb_list[pcrx->pd]; - while (phase != PHASE_DEAD) { + while (pcb->phase != PHASE_DEAD) { count = sio_read(pcrx->fd, pcrx->rxbuf, PPPOS_RX_BUFSIZE); if(count > 0) { pppos_input_proc(pcrx, pcrx->rxbuf, count); @@ -959,25 +923,25 @@ ppp_input_thread(void *arg) #if PPPOS_SUPPORT static void -pppos_put(ppp_pcb *pc, struct pbuf *nb) +pppos_put(ppp_pcb *pcb, struct pbuf *nb) { struct pbuf *b; int c; for(b = nb; b != NULL; b = b->next) { - if((c = sio_write(pc->fd, b->payload, b->len)) != b->len) { + if((c = sio_write(pcb->fd, b->payload, b->len)) != b->len) { PPPDEBUG(LOG_WARNING, - ("PPP pppos_put: incomplete sio_write(fd:%"SZT_F", len:%d, c: 0x%"X8_F") c = %d\n", (size_t)pc->fd, b->len, c, c)); + ("PPP pppos_put: incomplete sio_write(fd:%"SZT_F", len:%d, c: 0x%"X8_F") c = %d\n", (size_t)pcb->fd, b->len, c, c)); LINK_STATS_INC(link.err); - pc->last_xmit = 0; /* prepend PPP_FLAG to next packet */ - snmp_inc_ifoutdiscards(&pc->netif); + pcb->last_xmit = 0; /* prepend PPP_FLAG to next packet */ + snmp_inc_ifoutdiscards(&pcb->netif); pbuf_free(nb); return; } } - snmp_add_ifoutoctets(&pc->netif, nb->tot_len); - snmp_inc_ifoutucastpkts(&pc->netif); + snmp_add_ifoutoctets(&pcb->netif, nb->tot_len); + snmp_inc_ifoutucastpkts(&pcb->netif); pbuf_free(nb); LINK_STATS_INC(link.xmit); } @@ -1025,8 +989,7 @@ ppp_append(u_char c, struct pbuf *nb, ext_accm *out_accm) * This is the low level function that send the PPP packet. */ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, ip_addr_t *ipaddr) { - int pd = (int)(size_t)netif->state; - ppp_pcb *pc = &ppp_pcb_list[pd]; + ppp_pcb *pcb = (ppp_pcb*)netif->state; #if PPPOS_SUPPORT u_short protocol = PPP_IP; u_int fcs_out = PPP_INITFCS; @@ -1039,9 +1002,9 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, ip_addr_t *i /* Validate parameters. */ /* We let any protocol value go through - it can't hurt us * and the peer will just drop it if it's not accepting it. */ - if (pd < 0 || pd >= NUM_PPP || !pc->open_flag || !pb) { + if (!pcb->open_flag || !pb) { PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: bad params prot=%d pb=%p\n", - pd, PPP_IP, (void*)pb)); + pcb->unit, PPP_IP, (void*)pb)); LINK_STATS_INC(link.opterr); LINK_STATS_INC(link.drop); snmp_inc_ifoutdiscards(netif); @@ -1049,8 +1012,8 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, ip_addr_t *i } /* Check that the link is up. */ - if (pc->phase == PHASE_DEAD) { - PPPDEBUG(LOG_ERR, ("ppp_netif_output[%d]: link not up\n", pd)); + if (pcb->phase == PHASE_DEAD) { + PPPDEBUG(LOG_ERR, ("ppp_netif_output[%d]: link not up\n", pcb->unit)); LINK_STATS_INC(link.rterr); LINK_STATS_INC(link.drop); snmp_inc_ifoutdiscards(netif); @@ -1058,8 +1021,8 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, ip_addr_t *i } #if PPPOE_SUPPORT - if(pc->ethif) { - return ppp_netif_output_over_ethernet(pd, pb); + if(pcb->ethif) { + return ppp_netif_output_over_ethernet(pcb, pb); } #endif /* PPPOE_SUPPORT */ @@ -1067,7 +1030,7 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, ip_addr_t *i /* Grab an output buffer. */ head = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL); if (head == NULL) { - PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: first alloc fail\n", pd)); + PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: first alloc fail\n", pcb->unit)); LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); snmp_inc_ifoutdiscards(netif); @@ -1079,8 +1042,8 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, ip_addr_t *i * Attempt Van Jacobson header compression if VJ is configured and * this is an IP packet. */ - if (protocol == PPP_IP && pc->vj_enabled) { - switch (vj_compress_tcp(&pc->vj_comp, pb)) { + if (protocol == PPP_IP && pcb->vj_enabled) { + switch (vj_compress_tcp(&pcb->vj_comp, pb)) { case TYPE_IP: /* No change... protocol = PPP_IP_PROTOCOL; */ @@ -1092,7 +1055,7 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, ip_addr_t *i protocol = PPP_VJC_UNCOMP; break; default: - PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: bad IP packet\n", pd)); + PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: bad IP packet\n", pcb->unit)); LINK_STATS_INC(link.proterr); LINK_STATS_INC(link.drop); snmp_inc_ifoutdiscards(netif); @@ -1105,25 +1068,25 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, ip_addr_t *i tail = head; /* Build the PPP header. */ - if ((sys_jiffies() - pc->last_xmit) >= PPP_MAXIDLEFLAG) { + if ((sys_jiffies() - pcb->last_xmit) >= PPP_MAXIDLEFLAG) { tail = ppp_append(PPP_FLAG, tail, NULL); } - pc->last_xmit = sys_jiffies(); - if (!pc->accomp) { + pcb->last_xmit = sys_jiffies(); + if (!pcb->accomp) { fcs_out = PPP_FCS(fcs_out, PPP_ALLSTATIONS); - tail = ppp_append(PPP_ALLSTATIONS, tail, &pc->out_accm); + tail = ppp_append(PPP_ALLSTATIONS, tail, &pcb->out_accm); fcs_out = PPP_FCS(fcs_out, PPP_UI); - tail = ppp_append(PPP_UI, tail, &pc->out_accm); + tail = ppp_append(PPP_UI, tail, &pcb->out_accm); } - if (!pc->pcomp || protocol > 0xFF) { + if (!pcb->pcomp || protocol > 0xFF) { c = (protocol >> 8) & 0xFF; fcs_out = PPP_FCS(fcs_out, c); - tail = ppp_append(c, tail, &pc->out_accm); + tail = ppp_append(c, tail, &pcb->out_accm); } c = protocol & 0xFF; fcs_out = PPP_FCS(fcs_out, c); - tail = ppp_append(c, tail, &pc->out_accm); + tail = ppp_append(c, tail, &pcb->out_accm); /* Load packet. */ for(p = pb; p; p = p->next) { @@ -1139,22 +1102,22 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, ip_addr_t *i fcs_out = PPP_FCS(fcs_out, c); /* Copy to output buffer escaping special characters. */ - tail = ppp_append(c, tail, &pc->out_accm); + tail = ppp_append(c, tail, &pcb->out_accm); } } /* Add FCS and trailing flag. */ c = ~fcs_out & 0xFF; - tail = ppp_append(c, tail, &pc->out_accm); + tail = ppp_append(c, tail, &pcb->out_accm); c = (~fcs_out >> 8) & 0xFF; - tail = ppp_append(c, tail, &pc->out_accm); + tail = ppp_append(c, tail, &pcb->out_accm); tail = ppp_append(PPP_FLAG, tail, NULL); /* If we failed to complete the packet, throw it away. */ if (!tail) { PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: Alloc err - dropping proto=%d\n", - pd, protocol)); + pcb->unit, protocol)); pbuf_free(head); LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); @@ -1163,17 +1126,16 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, ip_addr_t *i } /* Send it. */ - PPPDEBUG(LOG_INFO, ("ppp_netif_output[%d]: proto=0x%"X16_F"\n", pd, protocol)); + PPPDEBUG(LOG_INFO, ("ppp_netif_output[%d]: proto=0x%"X16_F"\n", pcb->unit, protocol)); - pppos_put(pc, head); + pppos_put(pcb, head); #endif /* PPPOS_SUPPORT */ return ERR_OK; } #if PPPOE_SUPPORT -static err_t ppp_netif_output_over_ethernet(int pd, struct pbuf *p) { - ppp_pcb *pc = &ppp_pcb_list[pd]; +static err_t ppp_netif_output_over_ethernet(ppp_pcb *pcb, struct pbuf *p) { struct pbuf *pb; u_short protocol = PPP_IP; int i=0; @@ -1184,15 +1146,15 @@ static err_t ppp_netif_output_over_ethernet(int pd, struct pbuf *p) { if(!pb) { LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.proterr); - snmp_inc_ifoutdiscards(&pc->netif); + snmp_inc_ifoutdiscards(&pcb->netif); return ERR_MEM; } pbuf_header(pb, -(s16_t)PPPOE_HDRLEN); - pc->last_xmit = sys_jiffies(); + pcb->last_xmit = sys_jiffies(); - if (!pc->pcomp || protocol > 0xFF) { + if (!pcb->pcomp || protocol > 0xFF) { *((u_char*)pb->payload + i++) = (protocol >> 8) & 0xFF; } *((u_char*)pb->payload + i) = protocol & 0xFF; @@ -1200,14 +1162,14 @@ static err_t ppp_netif_output_over_ethernet(int pd, struct pbuf *p) { pbuf_chain(pb, p); tot_len = pb->tot_len; - if(pppoe_xmit(pc->pppoe_sc, pb) != ERR_OK) { + if(pppoe_xmit(pcb->pppoe_sc, pb) != ERR_OK) { LINK_STATS_INC(link.err); - snmp_inc_ifoutdiscards(&pc->netif); + snmp_inc_ifoutdiscards(&pcb->netif); return PPPERR_DEVICE; } - snmp_add_ifoutoctets(&pc->netif, tot_len); - snmp_inc_ifoutucastpkts(&pc->netif); + snmp_add_ifoutoctets(&pcb->netif, tot_len); + snmp_inc_ifoutucastpkts(&pcb->netif); LINK_STATS_INC(link.xmit); return ERR_OK; } @@ -1269,8 +1231,7 @@ ppp_ioctl(ppp_pcb *pcb, int cmd, void *arg) * RETURN: >= 0 Number of characters written * -1 Failed to write to device */ -int ppp_write(int pd, const u_char *s, int n) { - ppp_pcb *pc = &ppp_pcb_list[pd]; +int ppp_write(ppp_pcb *pcb, const u_char *s, int n) { #if PPPOS_SUPPORT u_char c; u_int fcs_out; @@ -1278,8 +1239,8 @@ int ppp_write(int pd, const u_char *s, int n) { #endif /* PPPOS_SUPPORT */ #if PPPOE_SUPPORT - if(pc->ethif) { - return ppp_write_over_ethernet(pd, s, n); + if(pcb->ethif) { + return ppp_write_over_ethernet(pcb, s, n); } #endif /* PPPOE_SUPPORT */ @@ -1288,7 +1249,7 @@ int ppp_write(int pd, const u_char *s, int n) { if (head == NULL) { LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.proterr); - snmp_inc_ifoutdiscards(&pc->netif); + snmp_inc_ifoutdiscards(&pcb->netif); return PPPERR_ALLOC; } @@ -1296,10 +1257,10 @@ int ppp_write(int pd, const u_char *s, int n) { /* If the link has been idle, we'll send a fresh flag character to * flush any noise. */ - if ((sys_jiffies() - pc->last_xmit) >= PPP_MAXIDLEFLAG) { + if ((sys_jiffies() - pcb->last_xmit) >= PPP_MAXIDLEFLAG) { tail = ppp_append(PPP_FLAG, tail, NULL); } - pc->last_xmit = sys_jiffies(); + pcb->last_xmit = sys_jiffies(); fcs_out = PPP_INITFCS; /* Load output buffer. */ @@ -1310,40 +1271,39 @@ int ppp_write(int pd, const u_char *s, int n) { fcs_out = PPP_FCS(fcs_out, c); /* Copy to output buffer escaping special characters. */ - tail = ppp_append(c, tail, &pc->out_accm); + tail = ppp_append(c, tail, &pcb->out_accm); } /* Add FCS and trailing flag. */ c = ~fcs_out & 0xFF; - tail = ppp_append(c, tail, &pc->out_accm); + tail = ppp_append(c, tail, &pcb->out_accm); c = (~fcs_out >> 8) & 0xFF; - tail = ppp_append(c, tail, &pc->out_accm); + tail = ppp_append(c, tail, &pcb->out_accm); tail = ppp_append(PPP_FLAG, tail, NULL); /* If we failed to complete the packet, throw it away. * Otherwise send it. */ if (!tail) { PPPDEBUG(LOG_WARNING, - ("ppp_write[%d]: Alloc err - dropping pbuf len=%d\n", pd, head->len)); + ("ppp_write[%d]: Alloc err - dropping pbuf len=%d\n", pcb->unit, head->len)); /*"ppp_write[%d]: Alloc err - dropping %d:%.*H", pd, head->len, LWIP_MIN(head->len * 2, 40), head->payload)); */ pbuf_free(head); LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.proterr); - snmp_inc_ifoutdiscards(&pc->netif); + snmp_inc_ifoutdiscards(&pcb->netif); return PPPERR_ALLOC; } - PPPDEBUG(LOG_INFO, ("ppp_write[%d]: len=%d\n", pd, head->len)); + PPPDEBUG(LOG_INFO, ("ppp_write[%d]: len=%d\n", pcb->unit, head->len)); /* "ppp_write[%d]: %d:%.*H", pd, head->len, LWIP_MIN(head->len * 2, 40), head->payload)); */ - pppos_put(pc, head); + pppos_put(pcb, head); #endif /* PPPOS_SUPPORT */ return PPPERR_NONE; } #if PPPOE_SUPPORT -static int ppp_write_over_ethernet(int pd, const u_char *s, int n) { - ppp_pcb *pc = &ppp_pcb_list[pd]; +static int ppp_write_over_ethernet(ppp_pcb *pcb, const u_char *s, int n) { struct pbuf *pb; /* skip address & flags */ @@ -1355,19 +1315,19 @@ static int ppp_write_over_ethernet(int pd, const u_char *s, int n) { if(!pb) { LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.proterr); - snmp_inc_ifoutdiscards(&pc->netif); + snmp_inc_ifoutdiscards(&pcb->netif); return PPPERR_ALLOC; } pbuf_header(pb, -(s16_t)PPPOE_HDRLEN); - pc->last_xmit = sys_jiffies(); + pcb->last_xmit = sys_jiffies(); MEMCPY(pb->payload, s, n); - if(pppoe_xmit(pc->pppoe_sc, pb) != ERR_OK) { + if(pppoe_xmit(pcb->pppoe_sc, pb) != ERR_OK) { LINK_STATS_INC(link.err); - snmp_inc_ifoutdiscards(&pc->netif); + snmp_inc_ifoutdiscards(&pcb->netif); return PPPERR_DEVICE; } @@ -1375,8 +1335,8 @@ static int ppp_write_over_ethernet(int pd, const u_char *s, int n) { dump_packet("sent", (unsigned char *)s, n); #endif /* PRINTPKT_SUPPORT */ - snmp_add_ifoutoctets(&pc->netif, (u16_t)n); - snmp_inc_ifoutucastpkts(&pc->netif); + snmp_add_ifoutoctets(&pcb->netif, (u16_t)n); + snmp_inc_ifoutucastpkts(&pcb->netif); LINK_STATS_INC(link.xmit); return PPPERR_NONE; } @@ -1711,36 +1671,34 @@ static void ppp_over_ethernet_link_status_cb(ppp_pcb *pcb, int state) { } #endif /* PPPOE_SUPPORT */ -void ppp_link_down(int pd) { - PPPDEBUG(LOG_DEBUG, ("ppp_link_down: unit %d\n", pd)); +void ppp_link_down(ppp_pcb *pcb) { + PPPDEBUG(LOG_DEBUG, ("ppp_link_down: unit %d\n", pcb->unit)); #if PPPOS_SUPPORT && PPP_INPROC_OWNTHREAD - ppp_receive_wakeup(pd); + ppp_receive_wakeup(pcb); #endif /* PPPOS_SUPPORT && PPP_INPROC_OWNTHREAD*/ } -void ppp_link_terminated(int pd) { - PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: unit %d\n", pd)); +void ppp_link_terminated(ppp_pcb *pcb) { + PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: unit %d\n", pcb->unit)); #if PPPOE_SUPPORT - if (ppp_pcb_list[pd].ethif) { - pppoe_disconnect(ppp_pcb_list[pd].pppoe_sc); + if (pcb->ethif) { + pppoe_disconnect(pcb->pppoe_sc); } else #endif /* PPPOE_SUPPORT */ { #if PPPOS_SUPPORT - ppp_pcb* pc; #if PPP_INPROC_OWNTHREAD - ppp_receive_wakeup(pd); + ppp_receive_wakeup(pcb); #endif /* PPP_INPROC_OWNTHREAD */ - pc = &ppp_pcb_list[pd]; - PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: unit %d: link_status_cb=%p err_code=%d\n", pd, pc->link_status_cb, pc->err_code)); - if (pc->link_status_cb) { - pc->link_status_cb(pc->link_status_ctx, pc->err_code ? pc->err_code : PPPERR_PROTOCOL, NULL); + PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: unit %d: link_status_cb=%p err_code=%d\n", pcb->unit, pcb->link_status_cb, pcb->err_code)); + if (pcb->link_status_cb) { + pcb->link_status_cb(pcb->link_status_ctx, pcb->err_code ? pcb->err_code : PPPERR_PROTOCOL, NULL); } - pc->open_flag = 0;/**/ + pcb->open_flag = 0; #endif /* PPPOS_SUPPORT */ } PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: finished.\n")); @@ -1785,9 +1743,8 @@ ppp_set_netif_linkcallback(ppp_pcb *pcb, netif_status_callback_fn link_callback) /* * new_phase - signal the start of a new phase of pppd's operation. */ -void new_phase(int unit, int p) { - ppp_pcb *pc = &ppp_pcb_list[unit]; - pc->phase = p; +void new_phase(ppp_pcb *pcb, int p) { + pcb->phase = p; #if PPP_NOTIFY /* The one willing notify support should add here the code to be notified of phase changes */ #endif /* PPP_NOTIFY */ @@ -1797,20 +1754,19 @@ void new_phase(int unit, int p) { * ppp_send_config - configure the transmit-side characteristics of * the ppp interface. */ -int ppp_send_config(int unit, int mtu, u_int32_t accm, int pcomp, int accomp) { - ppp_pcb *pc = &ppp_pcb_list[unit]; +int ppp_send_config(ppp_pcb *pcb, int mtu, u_int32_t accm, int pcomp, int accomp) { #if PPPOS_SUPPORT int i; #endif /* PPPOS_SUPPORT */ - /* pc->mtu = mtu; -- set correctly with netif_set_mtu */ - pc->pcomp = pcomp; - pc->accomp = accomp; + /* pcb->mtu = mtu; -- set correctly with netif_set_mtu */ + pcb->pcomp = pcomp; + pcb->accomp = accomp; #if PPPOS_SUPPORT /* Load the ACCM bits for the 32 control codes. */ for (i = 0; i < 32/8; i++) { - pc->out_accm[i] = (u_char)((accm >> (8 * i)) & 0xFF); + pcb->out_accm[i] = (u_char)((accm >> (8 * i)) & 0xFF); } #else LWIP_UNUSED_ARG(accm); @@ -1818,10 +1774,10 @@ int ppp_send_config(int unit, int mtu, u_int32_t accm, int pcomp, int accomp) { #if PPPOS_SUPPORT PPPDEBUG(LOG_INFO, ("ppp_send_config[%d]: out_accm=%X %X %X %X\n", - unit, - pc->out_accm[0], pc->out_accm[1], pc->out_accm[2], pc->out_accm[3])); + pcb->unit, + pcb->out_accm[0], pcb->out_accm[1], pcb->out_accm[2], pcb->out_accm[3])); #else - PPPDEBUG(LOG_INFO, ("ppp_send_config[%d]\n", unit) ); + PPPDEBUG(LOG_INFO, ("ppp_send_config[%d]\n", pcb->unit) ); #endif /* PPPOS_SUPPORT */ return 0; } @@ -1830,9 +1786,8 @@ int ppp_send_config(int unit, int mtu, u_int32_t accm, int pcomp, int accomp) { * ppp_recv_config - configure the receive-side characteristics of * the ppp interface. */ -int ppp_recv_config(int unit, int mru, u_int32_t accm, int pcomp, int accomp) { +int ppp_recv_config(ppp_pcb *pcb, int mru, u_int32_t accm, int pcomp, int accomp) { #if PPPOS_SUPPORT - ppp_pcb *pc = &ppp_pcb_list[unit]; int i; SYS_ARCH_DECL_PROTECT(lev); #endif /* PPPOS_SUPPORT */ @@ -1846,7 +1801,7 @@ int ppp_recv_config(int unit, int mru, u_int32_t accm, int pcomp, int accomp) { SYS_ARCH_PROTECT(lev); for (i = 0; i < 32 / 8; i++) { /* @todo: does this work? ext_accm has been modified from pppd! */ - pc->rx.in_accm[i] = (u_char)(accm >> (i * 8)); + pcb->rx.in_accm[i] = (u_char)(accm >> (i * 8)); } SYS_ARCH_UNPROTECT(lev); #else @@ -1855,10 +1810,10 @@ int ppp_recv_config(int unit, int mru, u_int32_t accm, int pcomp, int accomp) { #if PPPOS_SUPPORT PPPDEBUG(LOG_INFO, ("ppp_recv_config[%d]: in_accm=%X %X %X %X\n", - unit, - pc->rx.in_accm[0], pc->rx.in_accm[1], pc->rx.in_accm[2], pc->rx.in_accm[3])); + pcb->unit, + pcb->rx.in_accm[0], pcb->rx.in_accm[1], pcb->rx.in_accm[2], pcb->rx.in_accm[3])); #else - PPPDEBUG(LOG_INFO, ("ppp_recv_config[%d]\n", unit) ); + PPPDEBUG(LOG_INFO, ("ppp_recv_config[%d]\n", pcb->unit) ); #endif /* PPPOS_SUPPORT */ return 0; } @@ -1867,20 +1822,18 @@ int ppp_recv_config(int unit, int mru, u_int32_t accm, int pcomp, int accomp) { /* * sifaddr - Config the interface IP addresses and netmask. */ -int sifaddr (int unit, u_int32_t our_adr, u_int32_t his_adr, +int sifaddr(ppp_pcb *pcb, u_int32_t our_adr, u_int32_t his_adr, u_int32_t net_mask) { - ppp_pcb *pc = &ppp_pcb_list[unit]; - int st = 1; - if (unit < 0 || unit >= NUM_PPP || !pc->open_flag) { - st = 0; - PPPDEBUG(LOG_WARNING, ("sifaddr[%d]: bad params\n", unit)); - } else { - SMEMCPY(&pc->addrs.our_ipaddr, &our_adr, sizeof(our_adr)); - SMEMCPY(&pc->addrs.his_ipaddr, &his_adr, sizeof(his_adr)); - SMEMCPY(&pc->addrs.netmask, &net_mask, sizeof(net_mask)); + if(!pcb->open_flag) { + PPPDEBUG(LOG_WARNING, ("sifaddr[%d]: bad params\n", pcb->unit)); + return 0; } - return st; + + SMEMCPY(&pcb->addrs.our_ipaddr, &our_adr, sizeof(our_adr)); + SMEMCPY(&pcb->addrs.his_ipaddr, &his_adr, sizeof(his_adr)); + SMEMCPY(&pcb->addrs.netmask, &net_mask, sizeof(net_mask)); + return 1; } @@ -1889,39 +1842,36 @@ int sifaddr (int unit, u_int32_t our_adr, u_int32_t his_adr, * cifaddr - Clear the interface IP addresses, and delete routes * through the interface if possible. */ -int cifaddr (int unit, u_int32_t our_adr, u_int32_t his_adr) { - ppp_pcb *pc = &ppp_pcb_list[unit]; - int st = 1; +int cifaddr(ppp_pcb *pcb, u_int32_t our_adr, u_int32_t his_adr) { LWIP_UNUSED_ARG(our_adr); LWIP_UNUSED_ARG(his_adr); - if (unit < 0 || unit >= NUM_PPP || !pc->open_flag) { - st = 0; - PPPDEBUG(LOG_WARNING, ("cifaddr[%d]: bad params\n", unit)); - } 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,255); + + if(!pcb->open_flag) { + PPPDEBUG(LOG_WARNING, ("cifaddr[%d]: bad params\n", pcb->unit)); + return 0; } - return st; + + IP4_ADDR(&pcb->addrs.our_ipaddr, 0,0,0,0); + IP4_ADDR(&pcb->addrs.his_ipaddr, 0,0,0,0); + IP4_ADDR(&pcb->addrs.netmask, 255,255,255,255); + return 1; } /* * sdns - Config the DNS servers */ -int sdns (int unit, u_int32_t ns1, u_int32_t ns2) { - ppp_pcb *pc = &ppp_pcb_list[unit]; - int st = 1; +int sdns(ppp_pcb *pcb, u_int32_t ns1, u_int32_t ns2) { - if (unit < 0 || unit >= NUM_PPP || !pc->open_flag) { - st = 0; - PPPDEBUG(LOG_WARNING, ("sdns[%d]: bad params\n", unit)); - } else { - SMEMCPY(&pc->addrs.dns1, &ns1, sizeof(ns1)); - SMEMCPY(&pc->addrs.dns2, &ns2, sizeof(ns2)); + if(!pcb->open_flag) { + PPPDEBUG(LOG_WARNING, ("sdns[%d]: bad params\n", pcb->unit)); + return 0; } - return st; + + SMEMCPY(&pcb->addrs.dns1, &ns1, sizeof(ns1)); + SMEMCPY(&pcb->addrs.dns2, &ns2, sizeof(ns2)); + return 1; } @@ -1929,53 +1879,48 @@ int sdns (int unit, u_int32_t ns1, u_int32_t ns2) { * * cdns - Clear the DNS servers */ -int cdns (int unit, u_int32_t ns1, u_int32_t ns2) { - ppp_pcb *pc = &ppp_pcb_list[unit]; - int st = 1; +int cdns(ppp_pcb *pcb, u_int32_t ns1, u_int32_t ns2) { LWIP_UNUSED_ARG(ns1); LWIP_UNUSED_ARG(ns2); - if (unit < 0 || unit >= NUM_PPP || !pc->open_flag) { - st = 0; - PPPDEBUG(LOG_WARNING, ("cdns[%d]: bad params\n", unit)); - } else { - IP4_ADDR(&pc->addrs.dns1, 0,0,0,0); - IP4_ADDR(&pc->addrs.dns2, 0,0,0,0); + + if(!pcb->open_flag) { + PPPDEBUG(LOG_WARNING, ("cdns[%d]: bad params\n", pcb->unit)); + return 0; } - return st; + + IP4_ADDR(&pcb->addrs.dns1, 0,0,0,0); + IP4_ADDR(&pcb->addrs.dns2, 0,0,0,0); + return 1; } /* * sifup - Config the interface up and enable IP packets to pass. */ -int sifup(int u) -{ - ppp_pcb *pc = &ppp_pcb_list[u]; - int st = 1; +int sifup(ppp_pcb *pcb) { - if (u < 0 || u >= NUM_PPP || !pc->open_flag) { - st = 0; - PPPDEBUG(LOG_WARNING, ("sifup[%d]: bad params\n", u)); - } else { - netif_remove(&pc->netif); - if (netif_add(&pc->netif, &pc->addrs.our_ipaddr, &pc->addrs.netmask, - &pc->addrs.his_ipaddr, (void *)(size_t)u, ppp_netif_init_cb, ip_input)) { - netif_set_up(&pc->netif); - pc->if_up = 1; - pc->err_code = PPPERR_NONE; - - PPPDEBUG(LOG_DEBUG, ("sifup: unit %d: link_status_cb=%p err_code=%d\n", u, pc->link_status_cb, pc->err_code)); - if (pc->link_status_cb) { - pc->link_status_cb(pc->link_status_ctx, pc->err_code, &pc->addrs); - } - } else { - st = 0; - PPPDEBUG(LOG_ERR, ("sifup[%d]: netif_add failed\n", u)); - } + if(!pcb->open_flag) { + PPPDEBUG(LOG_WARNING, ("sifup[%d]: bad params\n", pcb->unit)); + return 0; } - return st; + netif_remove(&pcb->netif); + if (!netif_add(&pcb->netif, &pcb->addrs.our_ipaddr, &pcb->addrs.netmask, + &pcb->addrs.his_ipaddr, (void *)pcb, ppp_netif_init_cb, ip_input)) { + PPPDEBUG(LOG_ERR, ("sifup[%d]: netif_add failed\n", pcb->unit)); + return 0; + } + + netif_set_up(&pcb->netif); + pcb->if_up = 1; + pcb->err_code = PPPERR_NONE; + + PPPDEBUG(LOG_DEBUG, ("sifup: unit %d: link_status_cb=%p err_code=%d\n", pcb->unit, pcb->link_status_cb, pcb->err_code)); + if (pcb->link_status_cb) + pcb->link_status_cb(pcb->link_status_ctx, pcb->err_code, &pcb->addrs); + + return 1; } /******************************************************************** @@ -1983,31 +1928,29 @@ int sifup(int u) * sifdown - Disable the indicated protocol and config the interface * down if there are no remaining protocols. */ -int sifdown(int unit) { - ppp_pcb *pc = &ppp_pcb_list[unit]; - int st = 1; +int sifdown(ppp_pcb *pcb) { - if (unit < 0 || unit >= NUM_PPP || !pc->open_flag) { - st = 0; - PPPDEBUG(LOG_WARNING, ("sifdown[%d]: bad params\n", unit)); - } else { - pc->if_up = 0; - /* make sure the netif status callback is called */ - netif_set_down(&pc->netif); - netif_remove(&pc->netif); - PPPDEBUG(LOG_DEBUG, ("sifdown: unit %d: link_status_cb=%p err_code=%d\n", unit, pc->link_status_cb, pc->err_code)); - if (pc->link_status_cb) { - pc->link_status_cb(pc->link_status_ctx, PPPERR_CONNECT, NULL); - } + if(!pcb->open_flag) { + PPPDEBUG(LOG_WARNING, ("sifdown[%d]: bad params\n", pcb->unit)); + return 0; } - return st; + + pcb->if_up = 0; + /* make sure the netif status callback is called */ + netif_set_down(&pcb->netif); + netif_remove(&pcb->netif); + PPPDEBUG(LOG_DEBUG, ("sifdown: unit %d: link_status_cb=%p err_code=%d\n", pcb->unit, pcb->link_status_cb, pcb->err_code)); + if (pcb->link_status_cb) + pcb->link_status_cb(pcb->link_status_ctx, PPPERR_CONNECT, NULL); + + return 1; } /* * sifnpmode - Set the mode for handling packets for a given NP. */ -int sifnpmode(int u, int proto, enum NPmode mode) { - LWIP_UNUSED_ARG(u); +int sifnpmode(ppp_pcb *pcb, int proto, enum NPmode mode) { + LWIP_UNUSED_ARG(pcb); LWIP_UNUSED_ARG(proto); LWIP_UNUSED_ARG(mode); return 0; @@ -2016,27 +1959,25 @@ int sifnpmode(int u, int proto, enum NPmode mode) { /* * netif_set_mtu - set the MTU on the PPP network interface. */ -void netif_set_mtu(int unit, int mtu) { - ppp_pcb *pc = &ppp_pcb_list[unit]; +void netif_set_mtu(ppp_pcb *pcb, int mtu) { /* Validate parameters. */ - if (unit < 0 || unit >= NUM_PPP || !pc->open_flag) + if(!pcb->open_flag) return; - pc->mtu = mtu; + pcb->mtu = mtu; } /* * netif_get_mtu - get PPP interface MTU */ -int netif_get_mtu(int unit) { - ppp_pcb *pc = &ppp_pcb_list[unit]; +int netif_get_mtu(ppp_pcb *pcb) { /* Validate parameters. */ - if (unit < 0 || unit >= NUM_PPP || !pc->open_flag) - return 0; + if(!pcb->open_flag) + return 0; - return pc->mtu; + return pcb->mtu; } /******************************************************************** @@ -2051,45 +1992,37 @@ int netif_get_mtu(int unit) { * and then changes the temporary addresses to the addresses for the real * ppp connection when it has come up. */ -int sifdefaultroute(int unit, u_int32_t ouraddr, u_int32_t gateway, bool replace) { - ppp_pcb *pc = &ppp_pcb_list[unit]; - int st = 1; +int sifdefaultroute(ppp_pcb *pcb, u_int32_t ouraddr, u_int32_t gateway, bool replace) { LWIP_UNUSED_ARG(ouraddr); LWIP_UNUSED_ARG(gateway); LWIP_UNUSED_ARG(replace); - if (unit < 0 || unit >= NUM_PPP || !pc->open_flag) { - st = 0; - PPPDEBUG(LOG_WARNING, ("sifdefaultroute[%d]: bad params\n", unit)); - } else { - netif_set_default(&pc->netif); + if(!pcb->open_flag) { + PPPDEBUG(LOG_WARNING, ("sifdefaultroute[%d]: bad params\n", pcb->unit)); + return 0; } - /* TODO: check how PPP handled the netMask, previously not set by ipSetDefault */ - - return st; + netif_set_default(&pcb->netif); + return 1; } /******************************************************************** * * cifdefaultroute - delete a default route through the address given. */ -int cifdefaultroute(int unit, u_int32_t ouraddr, u_int32_t gateway) { - ppp_pcb *pc = &ppp_pcb_list[unit]; - int st = 1; +int cifdefaultroute(ppp_pcb *pcb, u_int32_t ouraddr, u_int32_t gateway) { LWIP_UNUSED_ARG(ouraddr); LWIP_UNUSED_ARG(gateway); - if (unit < 0 || unit >= NUM_PPP || !pc->open_flag) { - st = 0; - PPPDEBUG(LOG_WARNING, ("cifdefaultroute[%d]: bad params\n", unit)); - } else { - netif_set_default(NULL); + if(!pcb->open_flag) { + PPPDEBUG(LOG_WARNING, ("cifdefaultroute[%d]: bad params\n", pcb->unit)); + return 0; } - return st; + netif_set_default(NULL); + return 1; } /******************************************************************** @@ -2097,9 +2030,11 @@ int cifdefaultroute(int unit, u_int32_t ouraddr, u_int32_t gateway) { * sifproxyarp - Make a proxy ARP entry for the peer. */ -int sifproxyarp(int unit, u_int32_t his_adr) { - /* FIXME: do we really need that in IPCP ? */ - return 0; +int sifproxyarp(ppp_pcb *pcb, u_int32_t his_adr) { + LWIP_UNUSED_ARG(pcb); + LWIP_UNUSED_ARG(his_adr); + /* FIXME: do we really need that in IPCP ? */ + return 0; } /******************************************************************** @@ -2107,26 +2042,27 @@ int sifproxyarp(int unit, u_int32_t his_adr) { * cifproxyarp - Delete the proxy ARP entry for the peer. */ -int cifproxyarp(int unit, u_int32_t his_adr) { - /* FIXME: do we really need that in IPCP ? */ - return 0; +int cifproxyarp(ppp_pcb *pcb, u_int32_t his_adr) { + LWIP_UNUSED_ARG(pcb); + LWIP_UNUSED_ARG(his_adr); + /* FIXME: do we really need that in IPCP ? */ + return 0; } /******************************************************************** * * sifvjcomp - config tcp header compression */ -int sifvjcomp(int u, int vjcomp, int cidcomp, int maxcid) { -#if PPPOS_SUPPORT && VJ_SUPPORT - ppp_pcb *pc = &ppp_pcb_list[u]; +int sifvjcomp(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid) { - pc->vj_enabled = vjcomp; - pc->vj_comp.compressSlot = cidcomp; - pc->vj_comp.maxSlotIndex = maxcid; +#if PPPOS_SUPPORT && VJ_SUPPORT + pcb->vj_enabled = vjcomp; + pcb->vj_comp.compressSlot = cidcomp; + pcb->vj_comp.maxSlotIndex = maxcid; PPPDEBUG(LOG_INFO, ("sifvjcomp: VJ compress enable=%d slot=%d max slot=%d\n", vjcomp, cidcomp, maxcid)); #else /* PPPOS_SUPPORT && VJ_SUPPORT */ - LWIP_UNUSED_ARG(u); + LWIP_UNUSED_ARG(pcb); LWIP_UNUSED_ARG(vjcomp); LWIP_UNUSED_ARG(cidcomp); LWIP_UNUSED_ARG(maxcid); @@ -2139,9 +2075,9 @@ int sifvjcomp(int u, int vjcomp, int cidcomp, int maxcid) { * * get_idle_time - return how long the link has been idle. */ -int get_idle_time(int u, struct ppp_idle *ip) { +int get_idle_time(ppp_pcb *pcb, struct ppp_idle *ip) { /* FIXME: add idle time support and make it optional */ - LWIP_UNUSED_ARG(u); + LWIP_UNUSED_ARG(pcb); LWIP_UNUSED_ARG(ip); return 1; } diff --git a/src/netif/ppp/ppp.h b/src/netif/ppp/ppp.h index c2339d02..27a82b6f 100644 --- a/src/netif/ppp/ppp.h +++ b/src/netif/ppp/ppp.h @@ -45,6 +45,35 @@ #include "lwip/sys.h" #include "lwip/timers.h" +#include "vj.h" + + +/** PPP_INPROC_MULTITHREADED==1 call ppp_input using tcpip_callback(). + * Set this to 0 if pppos_input_proc is called inside tcpip_thread or with NO_SYS==1. + * Default is 1 for NO_SYS==0 (multithreaded) and 0 for NO_SYS==1 (single-threaded). + */ +#ifndef PPP_INPROC_MULTITHREADED +#define PPP_INPROC_MULTITHREADED (NO_SYS==0) +#endif + +/** PPP_INPROC_OWNTHREAD==1: start a dedicated RX thread per PPP session. + * Default is 0: call pppos_input() for received raw characters, character + * reception is up to the port */ +#ifndef PPP_INPROC_OWNTHREAD +#define PPP_INPROC_OWNTHREAD PPP_INPROC_MULTITHREADED +#endif + +#if PPP_INPROC_OWNTHREAD && !PPP_INPROC_MULTITHREADED + #error "PPP_INPROC_OWNTHREAD needs PPP_INPROC_MULTITHREADED==1" +#endif + +#if PPPOS_SUPPORT +/** RX buffer size: this may be configured smaller! */ +#ifndef PPPOS_RX_BUFSIZE +#define PPPOS_RX_BUFSIZE (PPP_MRU + PPP_HDRLEN) +#endif +#endif /* PPPOS_SUPPORT */ + #ifndef __u_char_defined @@ -61,6 +90,12 @@ typedef unsigned char u_char; *** PUBLIC DEFINITIONS *** *************************/ +/* + * The basic PPP frame. + */ +#define PPP_HDRLEN 4 /* octets for standard ppp header */ +#define PPP_FCSLEN 2 /* octets for FCS */ + /* Error codes. */ #define PPPERR_NONE 0 /* No error. */ #define PPPERR_PARAM -1 /* Invalid parameter. */ @@ -135,7 +170,25 @@ struct ppp_addrs { ip_addr_t our_ipaddr, his_ipaddr, netmask, dns1, dns2; }; +/* FIXME: find a way to move ppp_dev_states and ppp_pcb_rx_s to ppp_impl.h */ #if PPPOS_SUPPORT +/* + * Extended asyncmap - allows any character to be escaped. + */ +typedef u_char ext_accm[32]; + +/* PPP packet parser states. Current state indicates operation yet to be + * completed. */ +typedef enum { + PDIDLE = 0, /* Idle state - waiting. */ + PDSTART, /* Process start flag. */ + PDADDRESS, /* Process address field. */ + PDCONTROL, /* Process control field. */ + PDPROTOCOL1, /* Process protocol field 1. */ + PDPROTOCOL2, /* Process protocol field 2. */ + PDDATA /* Process data byte. */ +} ppp_dev_states; + /* * PPP interface RX control block. */ diff --git a/src/netif/ppp/ppp_impl.h b/src/netif/ppp/ppp_impl.h index f84690b2..d10af710 100644 --- a/src/netif/ppp/ppp_impl.h +++ b/src/netif/ppp/ppp_impl.h @@ -69,9 +69,6 @@ typedef unsigned char bool; /* * The basic PPP frame. */ -#define PPP_HDRLEN 4 /* octets for standard ppp header */ -#define PPP_FCSLEN 2 /* octets for FCS */ - #define PPP_ADDRESS(p) (((u_char *)(p))[0]) #define PPP_CONTROL(p) (((u_char *)(p))[1]) #define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3]) @@ -155,11 +152,6 @@ typedef unsigned short u_int16_t; #endif #endif -/* - * Extended asyncmap - allows any character to be escaped. - */ -typedef u_char ext_accm[32]; - /* * What to do with network protocol (NP) packets. */ @@ -312,7 +304,7 @@ struct protent { */ /* Process a received data packet */ void (*datainput) (int unit, u_char *pkt, int len); - bool enabled_flag; /* 0 iff protocol is disabled */ + bool enabled_flag; /* 0 if protocol is disabled */ #if PRINTPKT_SUPPORT char *name; /* Text name of protocol */ char *data_name; /* Text name of corresponding data protocol */ @@ -396,17 +388,16 @@ ppp_pcb ppp_pcb_list[NUM_PPP]; /* The PPP interface control blocks. */ /* PPP flow functions */ #if PPPOE_SUPPORT -void ppp_over_ethernet_init_failed(int pd); /* function called by pppoe.c */ void ppp_input_over_ethernet(ppp_pcb *pcb, struct pbuf *pb); #endif /* PPPOE_SUPPORT */ /* function called by all PPP subsystems to send packets */ -int ppp_write(int pd, const u_char *s, int n); +int ppp_write(ppp_pcb *pcb, const u_char *s, int n); /* functions called by auth.c link_terminated() */ -void ppp_link_down(int pd); -void ppp_link_terminated(int pd); +void ppp_link_down(ppp_pcb *pcb); +void ppp_link_terminated(ppp_pcb *pcb); /* merge a pbuf chain into one pbuf */ struct pbuf * ppp_singlebuf(struct pbuf *p); @@ -415,37 +406,37 @@ struct pbuf * ppp_singlebuf(struct pbuf *p); /* Functions called by various PPP subsystems to configure * the PPP interface or change the PPP phase. */ -void new_phase(int unit, int p); +void new_phase(ppp_pcb *pcb, int p); #if PPPOS_SUPPORT -void ppp_set_xaccm(int unit, ext_accm *accm); +void ppp_set_xaccm(ppp_pcb *pcb, ext_accm *accm); #endif /* PPPOS_SUPPORT */ -int ppp_send_config(int unit, int mtu, u_int32_t accm, int pcomp, int accomp); -int ppp_recv_config(int unit, int mru, u_int32_t accm, int pcomp, int accomp); +int ppp_send_config(ppp_pcb *pcb, int mtu, u_int32_t accm, int pcomp, int accomp); +int ppp_recv_config(ppp_pcb *pcb, int mru, u_int32_t accm, int pcomp, int accomp); -int sifaddr(int unit, u_int32_t our_adr, u_int32_t his_adr, u_int32_t net_mask); -int cifaddr(int unit, u_int32_t our_adr, u_int32_t his_adr); +int sifaddr(ppp_pcb *pcb, u_int32_t our_adr, u_int32_t his_adr, u_int32_t net_mask); +int cifaddr(ppp_pcb *pcb, u_int32_t our_adr, u_int32_t his_adr); -int sdns(int unit, u_int32_t ns1, u_int32_t ns2); -int cdns(int unit, u_int32_t ns1, u_int32_t ns2); +int sdns(ppp_pcb *pcb, u_int32_t ns1, u_int32_t ns2); +int cdns(ppp_pcb *pcb, u_int32_t ns1, u_int32_t ns2); -int sifup(int u); -int sifdown (int u); +int sifup(ppp_pcb *pcb); +int sifdown (ppp_pcb *pcb); -int sifnpmode(int u, int proto, enum NPmode mode); +int sifnpmode(ppp_pcb *pcb, int proto, enum NPmode mode); -void netif_set_mtu(int unit, int mtu); -int netif_get_mtu(int unit); +void netif_set_mtu(ppp_pcb *pcb, int mtu); +int netif_get_mtu(ppp_pcb *pcb); -int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway, bool replace); -int cifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway); +int sifdefaultroute(ppp_pcb *pcb, u_int32_t ouraddr, u_int32_t gateway, bool replace); +int cifdefaultroute(ppp_pcb *pcb, u_int32_t ouraddr, u_int32_t gateway); -int sifproxyarp (int unit, u_int32_t his_adr); -int cifproxyarp (int unit, u_int32_t his_adr); +int sifproxyarp(ppp_pcb *pcb, u_int32_t his_adr); +int cifproxyarp(ppp_pcb *pcb, u_int32_t his_adr); -int sifvjcomp (int u, int vjcomp, int cidcomp, int maxcid); +int sifvjcomp(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid); -int get_idle_time(int u, struct ppp_idle *ip); +int get_idle_time(ppp_pcb *pcb, struct ppp_idle *ip); int get_loop_output(void); diff --git a/src/netif/ppp/upap.c b/src/netif/ppp/upap.c index cd8d2c2b..8f471920 100644 --- a/src/netif/ppp/upap.c +++ b/src/netif/ppp/upap.c @@ -584,6 +584,7 @@ static void upap_sauthreq(u) upap_state *u; { + ppp_pcb *pcb = &ppp_pcb_list[u->us_unit]; u_char *outp; int outlen; @@ -602,7 +603,7 @@ upap_sauthreq(u) PUTCHAR(u->us_passwdlen, outp); MEMCPY(outp, u->us_passwd, u->us_passwdlen); - ppp_write(u->us_unit, outpacket_buf, outlen + PPP_HDRLEN); + ppp_write(pcb, outpacket_buf, outlen + PPP_HDRLEN); TIMEOUT(upap_timeout, u, u->us_timeouttime); ++u->us_transmits; @@ -620,6 +621,7 @@ upap_sresp(u, code, id, msg, msglen) char *msg; int msglen; { + ppp_pcb *pcb = &ppp_pcb_list[u->us_unit]; u_char *outp; int outlen; @@ -632,7 +634,7 @@ upap_sresp(u, code, id, msg, msglen) PUTSHORT(outlen, outp); PUTCHAR(msglen, outp); MEMCPY(outp, msg, msglen); - ppp_write(u->us_unit, outpacket_buf, outlen + PPP_HDRLEN); + ppp_write(pcb, outpacket_buf, outlen + PPP_HDRLEN); } #endif /* UNUSED */