PPP, using PPP netif->num number instead of ppp->num

Saved 2 bytes of RAM if debug is enabled, we are now using the
netif->num number instead of using our own ppp->num
This commit is contained in:
Sylvain Rochet 2015-02-21 01:21:24 +01:00
parent c5973dd411
commit f57d4818a4
3 changed files with 40 additions and 52 deletions

View File

@ -305,9 +305,6 @@ struct ppp_addrs {
*/
struct ppp_pcb_s {
/* -- below are data that will NOT be cleared between two sessions */
#if PPP_DEBUG
u8_t num; /* Interface number - only useful for debugging */
#endif /* PPP_DEBUG */
ppp_settings settings;
const struct link_callbacks *link_cb;
void *link_ctx_cb;

View File

@ -125,12 +125,6 @@
#include "netif/ppp/ipv6cp.h"
#endif /* PPP_IPV6_SUPPORT */
/* Global variables */
#if PPP_DEBUG
u8_t ppp_num; /* PPP Interface counter, used for debugging messages */
#endif /* PPP_DEBUG */
/*************************/
/*** LOCAL DEFINITIONS ***/
/*************************/
@ -292,7 +286,7 @@ ppp_close(ppp_pcb *pcb)
PPPDEBUG(LOG_DEBUG, ("ppp_close() called\n"));
/* Disconnect */
PPPDEBUG(LOG_DEBUG, ("ppp_close: unit %d kill_link -> lcp_close\n", pcb->num));
PPPDEBUG(LOG_DEBUG, ("ppp_close: unit %d kill_link -> lcp_close\n", pcb->netif->num));
/* LCP close request, this will leave us at PPP_PHASE_DEAD. */
lcp_close(pcb, "User request");
@ -303,7 +297,7 @@ ppp_close(ppp_pcb *pcb)
void
ppp_sighup(ppp_pcb *pcb)
{
PPPDEBUG(LOG_DEBUG, ("ppp_sighup: unit %d\n", pcb->num));
PPPDEBUG(LOG_DEBUG, ("ppp_sighup: unit %d\n", pcb->netif->num));
lcp_lowerdown(pcb);
/* forced link termination, this will leave us at PPP_PHASE_DEAD. */
link_terminated(pcb);
@ -325,7 +319,7 @@ err_t ppp_free(ppp_pcb *pcb) {
return ERR_CONN;
}
PPPDEBUG(LOG_DEBUG, ("ppp_free: unit %d\n", pcb->num));
PPPDEBUG(LOG_DEBUG, ("ppp_free: unit %d\n", pcb->netif->num));
netif_remove(pcb->netif);
@ -466,7 +460,7 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u_short prot
* and the peer will just drop it if it's not accepting it. */
if (!pcb || !pb) {
PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: bad params prot=%d pb=%p\n",
pcb->num, PPP_IP, (void*)pb));
pcb->netif->num, PPP_IP, (void*)pb));
LINK_STATS_INC(link.opterr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(netif);
@ -475,7 +469,7 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u_short prot
/* Check that the link is up. */
if (!pcb->if_up) {
PPPDEBUG(LOG_ERR, ("ppp_netif_output[%d]: link not up\n", pcb->num));
PPPDEBUG(LOG_ERR, ("ppp_netif_output[%d]: link not up\n", pcb->netif->num));
LINK_STATS_INC(link.rterr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(netif);
@ -526,9 +520,6 @@ ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void
}
memset(pcb, 0, sizeof(ppp_pcb));
#if PPP_DEBUG
pcb->num = ppp_num++;
#endif /* PPP_DEBUG */
/* default configuration */
pcb->settings.usepeerdns = 1;
@ -571,7 +562,7 @@ ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void
if (!netif_add(pcb->netif, &pcb->addrs.our_ipaddr, &pcb->addrs.netmask,
&pcb->addrs.his_ipaddr, (void *)pcb, ppp_netif_init_cb, NULL)) {
memp_free(MEMP_PPP_PCB, pcb);
PPPDEBUG(LOG_ERR, ("ppp_new[%d]: netif_add failed\n", pcb->num));
PPPDEBUG(LOG_ERR, ("ppp_new: netif_add failed\n"));
return NULL;
}
@ -612,7 +603,7 @@ void ppp_link_set_callbacks(ppp_pcb *pcb, const struct link_callbacks *callbacks
/** Initiate LCP open request */
void ppp_start(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_start: unit %d\n", pcb->num));
PPPDEBUG(LOG_DEBUG, ("ppp_start: unit %d\n", pcb->netif->num));
lcp_open(pcb); /* Start protocol */
lcp_lowerup(pcb);
PPPDEBUG(LOG_DEBUG, ("ppp_start: finished\n"));
@ -620,7 +611,7 @@ void ppp_start(ppp_pcb *pcb) {
/** Called when link failed to setup */
void ppp_link_failed(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_failed: unit %d\n", pcb->num));
PPPDEBUG(LOG_DEBUG, ("ppp_failed: unit %d\n", pcb->netif->num));
new_phase(pcb, PPP_PHASE_DEAD);
pcb->err_code = PPPERR_OPEN;
pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb);
@ -628,7 +619,7 @@ void ppp_link_failed(ppp_pcb *pcb) {
/** Called when link is normally down (i.e. it was asked to end) */
void ppp_link_end(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_end: unit %d\n", pcb->num));
PPPDEBUG(LOG_DEBUG, ("ppp_end: unit %d\n", pcb->netif->num));
if (pcb->err_code == PPPERR_NONE) {
pcb->err_code = PPPERR_CONNECT;
}
@ -695,13 +686,13 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) {
switch(protocol) {
case PPP_IP: /* Internet Protocol */
PPPDEBUG(LOG_INFO, ("ppp_input[%d]: ip in pbuf len=%d\n", pcb->num, pb->len));
PPPDEBUG(LOG_INFO, ("ppp_input[%d]: ip in pbuf len=%d\n", pcb->netif->num, pb->len));
ip_input(pb, pcb->netif);
return;
#if PPP_IPV6_SUPPORT
case PPP_IPV6: /* Internet Protocol Version 6 */
PPPDEBUG(LOG_INFO, ("ppp_input[%d]: ip6 in pbuf len=%d\n", pcb->num, pb->len));
PPPDEBUG(LOG_INFO, ("ppp_input[%d]: ip6 in pbuf len=%d\n", pcb->netif->num, pb->len));
ip6_input(pb, pcb->netif);
return;
#endif /* PPP_IPV6_SUPPORT */
@ -815,7 +806,7 @@ struct pbuf * ppp_singlebuf(struct pbuf *p) {
}
void ppp_link_terminated(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: unit %d\n", pcb->num));
PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: unit %d\n", pcb->netif->num));
pcb->link_cb->disconnect(pcb, pcb->link_ctx_cb);
PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: finished.\n"));
}
@ -831,7 +822,7 @@ void ppp_link_terminated(ppp_pcb *pcb) {
*/
void new_phase(ppp_pcb *pcb, int p) {
pcb->phase = p;
PPPDEBUG(LOG_DEBUG, ("ppp phase changed: unit %d: phase=%d\n", pcb->num, pcb->phase));
PPPDEBUG(LOG_DEBUG, ("ppp phase changed: unit %d: phase=%d\n", pcb->netif->num, pcb->phase));
#if PPP_NOTIFY_PHASE
if (pcb->notify_phase_cb != NULL) {
pcb->notify_phase_cb(pcb, p, pcb->ctx_cb);
@ -854,7 +845,7 @@ int ppp_send_config(ppp_pcb *pcb, int mtu, u32_t accm, int pcomp, int accomp) {
pcb->link_cb->send_config(pcb, pcb->link_ctx_cb, accm);
}
PPPDEBUG(LOG_INFO, ("ppp_send_config[%d]\n", pcb->num) );
PPPDEBUG(LOG_INFO, ("ppp_send_config[%d]\n", pcb->netif->num) );
return 0;
}
@ -871,7 +862,7 @@ int ppp_recv_config(ppp_pcb *pcb, int mru, u32_t accm, int pcomp, int accomp) {
pcb->link_cb->recv_config(pcb, pcb->link_ctx_cb, accm);
}
PPPDEBUG(LOG_INFO, ("ppp_recv_config[%d]\n", pcb->num));
PPPDEBUG(LOG_INFO, ("ppp_recv_config[%d]\n", pcb->netif->num));
return 0;
}
@ -978,7 +969,7 @@ int sifup(ppp_pcb *pcb) {
pcb->if_up = 1;
pcb->err_code = PPPERR_NONE;
PPPDEBUG(LOG_DEBUG, ("sifup: unit %d: err_code=%d\n", pcb->num, pcb->err_code));
PPPDEBUG(LOG_DEBUG, ("sifup: unit %d: err_code=%d\n", pcb->netif->num, pcb->err_code));
pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb);
return 1;
}
@ -1004,7 +995,7 @@ int sifdown(ppp_pcb *pcb) {
/* make sure the netif status callback is called */
netif_set_down(pcb->netif);
}
PPPDEBUG(LOG_DEBUG, ("sifdown: unit %d: err_code=%d\n", pcb->num, pcb->err_code));
PPPDEBUG(LOG_DEBUG, ("sifdown: unit %d: err_code=%d\n", pcb->netif->num, pcb->err_code));
return 1;
}
@ -1021,7 +1012,7 @@ int sif6up(ppp_pcb *pcb) {
pcb->if6_up = 1;
pcb->err_code = PPPERR_NONE;
PPPDEBUG(LOG_DEBUG, ("sif6up: unit %d: err_code=%d\n", pcb->num, pcb->err_code));
PPPDEBUG(LOG_DEBUG, ("sif6up: unit %d: err_code=%d\n", pcb->netif->num, pcb->err_code));
pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb);
return 1;
}
@ -1042,7 +1033,7 @@ int sif6down(ppp_pcb *pcb) {
/* make sure the netif status callback is called */
netif_set_down(pcb->netif);
}
PPPDEBUG(LOG_DEBUG, ("sif6down: unit %d: err_code=%d\n", pcb->num, pcb->err_code));
PPPDEBUG(LOG_DEBUG, ("sif6down: unit %d: err_code=%d\n", pcb->netif->num, pcb->err_code));
return 1;
}
#endif /* PPP_IPV6_SUPPORT */

View File

@ -247,7 +247,7 @@ pppos_write(ppp_pcb *ppp, void *ctx, struct pbuf *p)
* Otherwise send it. */
if (!tail) {
PPPDEBUG(LOG_WARNING,
("ppp_write[%d]: Alloc err - dropping pbuf len=%d\n", ppp->num, head->len));
("ppp_write[%d]: Alloc err - dropping pbuf len=%d\n", ppp->netif->num, 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);
@ -257,7 +257,7 @@ pppos_write(ppp_pcb *ppp, void *ctx, struct pbuf *p)
return ERR_MEM;
}
PPPDEBUG(LOG_INFO, ("ppp_write[%d]: len=%d\n", ppp->num, head->len));
PPPDEBUG(LOG_INFO, ("ppp_write[%d]: len=%d\n", ppp->netif->num, head->len));
/* "ppp_write[%d]: %d:%.*H", pd, head->len, LWIP_MIN(head->len * 2, 40), head->payload)); */
pppos_xmit(pppos, head);
pbuf_free(p);
@ -276,7 +276,7 @@ pppos_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *pb, u_short protocol)
/* 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", ppp->num));
PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: first alloc fail\n", ppp->netif->num));
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(ppp->netif);
@ -301,7 +301,7 @@ pppos_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *pb, u_short protocol)
protocol = PPP_VJC_UNCOMP;
break;
default:
PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: bad IP packet\n", ppp->num));
PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: bad IP packet\n", ppp->netif->num));
LINK_STATS_INC(link.proterr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(ppp->netif);
@ -363,7 +363,7 @@ pppos_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *pb, u_short protocol)
if (!tail) {
PPPDEBUG(LOG_WARNING,
("ppp_netif_output[%d]: Alloc err - dropping proto=%d\n",
ppp->num, protocol));
ppp->netif->num, protocol));
pbuf_free(head);
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
@ -372,7 +372,7 @@ pppos_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *pb, u_short protocol)
}
/* Send it. */
PPPDEBUG(LOG_INFO, ("ppp_netif_output[%d]: proto=0x%"X16_F"\n", ppp->num, protocol));
PPPDEBUG(LOG_INFO, ("ppp_netif_output[%d]: proto=0x%"X16_F"\n", ppp->netif->num, protocol));
pppos_xmit(pppos, head);
return ERR_OK;
@ -417,7 +417,7 @@ pppos_connect(ppp_pcb *ppp, void *ctx)
/*
* Start the connection and handle incoming events (packet or timeout).
*/
PPPDEBUG(LOG_INFO, ("pppos_connect: unit %d: connecting\n", ppp->num));
PPPDEBUG(LOG_INFO, ("pppos_connect: unit %d: connecting\n", ppp->netif->num));
ppp_start(ppp); /* notify upper layers */
return ERR_OK;
}
@ -478,7 +478,7 @@ pppos_input(ppp_pcb *ppp, u_char *s, int l)
u_char escaped;
SYS_ARCH_DECL_PROTECT(lev);
PPPDEBUG(LOG_DEBUG, ("pppos_input[%d]: got %d bytes\n", ppp->num, l));
PPPDEBUG(LOG_DEBUG, ("pppos_input[%d]: got %d bytes\n", ppp->netif->num, l));
while (l-- > 0) {
cur_char = *s++;
@ -503,14 +503,14 @@ pppos_input(ppp_pcb *ppp, u_char *s, int l)
} else if (pppos->in_state < PDDATA) {
PPPDEBUG(LOG_WARNING,
("pppos_input[%d]: Dropping incomplete packet %d\n",
ppp->num, pppos->in_state));
ppp->netif->num, pppos->in_state));
LINK_STATS_INC(link.lenerr);
pppos_drop(pppos);
/* If the fcs is invalid, drop the packet. */
} else if (pppos->in_fcs != PPP_GOODFCS) {
PPPDEBUG(LOG_INFO,
("pppos_input[%d]: Dropping bad fcs 0x%"X16_F" proto=0x%"X16_F"\n",
ppp->num, pppos->in_fcs, pppos->in_protocol));
ppp->netif->num, pppos->in_fcs, pppos->in_protocol));
/* Note: If you get lots of these, check for UART frame errors or try different baud rate */
LINK_STATS_INC(link.chkerr);
pppos_drop(pppos);
@ -545,7 +545,7 @@ pppos_input(ppp_pcb *ppp, u_char *s, int l)
#endif /* IP_FORWARD || LWIP_IPV6_FORWARD */
#if PPP_INPROC_MULTITHREADED
if(tcpip_callback_with_block(pppos_input_callback, inp, 0) != ERR_OK) {
PPPDEBUG(LOG_ERR, ("pppos_input[%d]: tcpip_callback() failed, dropping packet\n", ppp->num));
PPPDEBUG(LOG_ERR, ("pppos_input[%d]: tcpip_callback() failed, dropping packet\n", ppp->netif->num));
pbuf_free(inp);
LINK_STATS_INC(link.drop);
snmp_inc_ifindiscards(ppp->netif);
@ -563,7 +563,7 @@ pppos_input(ppp_pcb *ppp, u_char *s, int l)
* been inserted by the physical layer so here we just drop them. */
} else {
PPPDEBUG(LOG_WARNING,
("pppos_input[%d]: Dropping ACCM char <%d>\n", ppp->num, cur_char));
("pppos_input[%d]: Dropping ACCM char <%d>\n", ppp->netif->num, cur_char));
}
/* Process other characters. */
} else {
@ -610,7 +610,7 @@ pppos_input(ppp_pcb *ppp, u_char *s, int l)
#if 0
else {
PPPDEBUG(LOG_WARNING,
("pppos_input[%d]: Invalid control <%d>\n", ppp->num, cur_char));
("pppos_input[%d]: Invalid control <%d>\n", ppp->netif->num, cur_char));
pppos->in_state = PDSTART;
}
#endif
@ -657,7 +657,7 @@ pppos_input(ppp_pcb *ppp, u_char *s, int l)
/* No free buffers. Drop the input packet and let the
* higher layers deal with it. Continue processing
* the received pbuf chain in case a new packet starts. */
PPPDEBUG(LOG_ERR, ("pppos_input[%d]: NO FREE PBUFS!\n", ppp->num));
PPPDEBUG(LOG_ERR, ("pppos_input[%d]: NO FREE PBUFS!\n", ppp->netif->num));
LINK_STATS_INC(link.memerr);
pppos_drop(pppos);
pppos->in_state = PDSTART; /* Wait for flag sequence. */
@ -729,7 +729,7 @@ pppos_send_config(ppp_pcb *ppp, void *ctx, u32_t accm)
}
PPPDEBUG(LOG_INFO, ("pppos_send_config[%d]: in_accm=%X %X %X %X\n",
pppos->ppp->num,
pppos->ppp->netif->num,
pppos->out_accm[0], pppos->out_accm[1], pppos->out_accm[2], pppos->out_accm[3]));
}
@ -749,7 +749,7 @@ pppos_recv_config(ppp_pcb *ppp, void *ctx, u32_t accm)
SYS_ARCH_UNPROTECT(lev);
PPPDEBUG(LOG_INFO, ("pppos_recv_config[%d]: in_accm=%X %X %X %X\n",
pppos->ppp->num,
pppos->ppp->netif->num,
pppos->in_accm[0], pppos->in_accm[1], pppos->in_accm[2], pppos->in_accm[3]));
}
@ -784,7 +784,7 @@ pppos_vjc_config(ppp_pcb *ppp, void *ctx, int vjcomp, int cidcomp, int maxcid)
pppos->vj_comp.compressSlot = cidcomp;
pppos->vj_comp.maxSlotIndex = maxcid;
PPPDEBUG(LOG_INFO, ("pppos_vjc_config[%d]: VJ compress enable=%d slot=%d max slot=%d\n",
ppp->num, vjcomp, cidcomp, maxcid));
ppp->netif->num, vjcomp, cidcomp, maxcid));
}
static err_t
@ -802,14 +802,14 @@ pppos_netif_input(ppp_pcb *ppp, void *ctx, struct pbuf *p, u16_t protocol)
* Clip off the VJ header and prepend the rebuilt TCP/IP header and
* pass the result to IP.
*/
PPPDEBUG(LOG_INFO, ("pppos_vjc_comp[%d]: vj_comp in pbuf len=%d\n", ppp->num, p->len));
PPPDEBUG(LOG_INFO, ("pppos_vjc_comp[%d]: vj_comp in pbuf len=%d\n", ppp->netif->num, p->len));
ret = vj_uncompress_tcp(&p, &pppos->vj_comp);
if (ret >= 0) {
ip_input(p, pppos->ppp->netif);
return ERR_OK;
}
/* Something's wrong so drop it. */
PPPDEBUG(LOG_WARNING, ("pppos_vjc_comp[%d]: Dropping VJ compressed\n", ppp->num));
PPPDEBUG(LOG_WARNING, ("pppos_vjc_comp[%d]: Dropping VJ compressed\n", ppp->netif->num));
break;
case PPP_VJC_UNCOMP: /* VJ uncompressed TCP */
@ -820,14 +820,14 @@ pppos_netif_input(ppp_pcb *ppp, void *ctx, struct pbuf *p, u16_t protocol)
* Process the TCP/IP header for VJ header compression and then pass
* the packet to IP.
*/
PPPDEBUG(LOG_INFO, ("pppos_vjc_uncomp[%d]: vj_un in pbuf len=%d\n", ppp->num, p->len));
PPPDEBUG(LOG_INFO, ("pppos_vjc_uncomp[%d]: vj_un in pbuf len=%d\n", ppp->netif->num, p->len));
ret = vj_uncompress_uncomp(p, &pppos->vj_comp);
if (ret >= 0) {
ip_input(p, pppos->ppp->netif);
return ERR_OK;
}
/* Something's wrong so drop it. */
PPPDEBUG(LOG_WARNING, ("pppos_vjc_uncomp[%d]: Dropping VJ uncompressed\n", ppp->num));
PPPDEBUG(LOG_WARNING, ("pppos_vjc_uncomp[%d]: Dropping VJ uncompressed\n", ppp->netif->num));
break;
/* Pass the packet to other handlers */