PPP, code cleaning

This commit is contained in:
Sylvain Rochet
2015-02-22 16:45:38 +01:00
parent b0b7240022
commit 653657ae43
3 changed files with 57 additions and 52 deletions

View File

@@ -590,6 +590,11 @@ ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void
return pcb;
}
void ppp_link_set_callbacks(ppp_pcb *pcb, const struct link_callbacks *callbacks, void *ctx) {
pcb->link_cb = callbacks;
pcb->link_ctx_cb = ctx;
}
/* Set a PPP PCB to its initial state */
void ppp_clear(ppp_pcb *pcb) {
const struct protent *protp;
@@ -616,11 +621,6 @@ void ppp_clear(ppp_pcb *pcb) {
new_phase(pcb, PPP_PHASE_INITIALIZE);
}
void ppp_link_set_callbacks(ppp_pcb *pcb, const struct link_callbacks *callbacks, void *ctx) {
pcb->link_cb = callbacks;
pcb->link_ctx_cb = ctx;
}
/** Initiate LCP open request */
void ppp_start(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_start: unit %d\n", pcb->netif->num));
@@ -780,27 +780,8 @@ out:
return;
}
/*
* Write a pbuf to a ppp link, only used from PPP functions
* to send PPP packets.
*
* IPv4 and IPv6 packets from lwIP are sent, respectively,
* with ppp_netif_output_ip4() and ppp_netif_output_ip6()
* functions (which are callbacks of the netif PPP interface).
*
* RETURN: >= 0 Number of characters written
* -1 Failed to write to device
*/
int ppp_write(ppp_pcb *pcb, struct pbuf *p) {
#if PRINTPKT_SUPPORT
ppp_dump_packet("sent", (unsigned char *)p->payload+2, p->len-2);
#endif /* PRINTPKT_SUPPORT */
return pcb->link_cb->write(pcb, pcb->link_ctx_cb, p);
}
/* merge a pbuf chain into one pbuf */
struct pbuf * ppp_singlebuf(struct pbuf *p) {
struct pbuf *ppp_singlebuf(struct pbuf *p) {
struct pbuf *q, *b;
u_char *pl;
@@ -825,6 +806,24 @@ struct pbuf * ppp_singlebuf(struct pbuf *p) {
return q;
}
/*
* Write a pbuf to a ppp link, only used from PPP functions
* to send PPP packets.
*
* IPv4 and IPv6 packets from lwIP are sent, respectively,
* with ppp_netif_output_ip4() and ppp_netif_output_ip6()
* functions (which are callbacks of the netif PPP interface).
*
* RETURN: >= 0 Number of characters written
* -1 Failed to write to device
*/
int ppp_write(ppp_pcb *pcb, struct pbuf *p) {
#if PRINTPKT_SUPPORT
ppp_dump_packet("sent", (unsigned char *)p->payload+2, p->len-2);
#endif /* PRINTPKT_SUPPORT */
return pcb->link_cb->write(pcb, pcb->link_ctx_cb, p);
}
void ppp_link_terminated(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: unit %d\n", pcb->netif->num));
pcb->link_cb->disconnect(pcb, pcb->link_ctx_cb);

View File

@@ -244,8 +244,8 @@ 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->netif->num, head->len));
/*"ppp_write[%d]: Alloc err - dropping %d:%.*H", pd, head->len, LWIP_MIN(head->len * 2, 40), head->payload)); */
("pppos_write[%d]: Alloc err - dropping pbuf len=%d\n", ppp->netif->num, head->len));
/*"pppos_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);
@@ -254,8 +254,8 @@ pppos_write(ppp_pcb *ppp, void *ctx, struct pbuf *p)
return ERR_MEM;
}
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)); */
PPPDEBUG(LOG_INFO, ("pppos_write[%d]: len=%d\n", ppp->netif->num, head->len));
/* "pppos_write[%d]: %d:%.*H", pd, head->len, LWIP_MIN(head->len * 2, 40), head->payload)); */
pppos_xmit(pppos, head);
pbuf_free(p);
return ERR_OK;
@@ -426,7 +426,7 @@ pppos_disconnect(ppp_pcb *ppp, void *ctx)
{
LWIP_UNUSED_ARG(ctx);
/* We cannot call ppp_free_current_input_packet() here because
/* We cannot call pppos_free_current_input_packet() here because
* rx thread might still call pppos_input()
*/
ppp_link_end(ppp); /* notify upper layers */