mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-05 22:29:49 +00:00
PPP, code cleaning
This commit is contained in:
parent
b0b7240022
commit
653657ae43
@ -380,20 +380,31 @@ struct pppd_stats {
|
|||||||
#endif /* PPP_STATS_SUPPORT */
|
#endif /* PPP_STATS_SUPPORT */
|
||||||
|
|
||||||
|
|
||||||
/* PPP functions
|
/*
|
||||||
|
* PPP private functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Functions called from lwIP core.
|
||||||
|
*/
|
||||||
|
|
||||||
/* initialize the PPP subsystem */
|
/* initialize the PPP subsystem */
|
||||||
int ppp_init(void);
|
int ppp_init(void);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Functions called from PPP link protocols.
|
||||||
|
*/
|
||||||
|
|
||||||
/* Create a new PPP control block */
|
/* Create a new PPP control block */
|
||||||
ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
|
ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
|
||||||
|
|
||||||
/* Set a PPP PCB to its initial state */
|
|
||||||
void ppp_clear(ppp_pcb *pcb);
|
|
||||||
|
|
||||||
/* Set link callback functions */
|
/* Set link callback functions */
|
||||||
void ppp_link_set_callbacks(ppp_pcb *pcb, const struct link_callbacks *callbacks, void *ctx);
|
void ppp_link_set_callbacks(ppp_pcb *pcb, const struct link_callbacks *callbacks, void *ctx);
|
||||||
|
|
||||||
|
/* Set a PPP PCB to its initial state */
|
||||||
|
void ppp_clear(ppp_pcb *pcb);
|
||||||
|
|
||||||
/* Initiate LCP open request */
|
/* Initiate LCP open request */
|
||||||
void ppp_start(ppp_pcb *pcb);
|
void ppp_start(ppp_pcb *pcb);
|
||||||
|
|
||||||
@ -403,22 +414,23 @@ void ppp_link_failed(ppp_pcb *pcb);
|
|||||||
/* Called when link is normally down (i.e. it was asked to end) */
|
/* Called when link is normally down (i.e. it was asked to end) */
|
||||||
void ppp_link_end(ppp_pcb *pcb);
|
void ppp_link_end(ppp_pcb *pcb);
|
||||||
|
|
||||||
/* function called by pppoe.c */
|
/* function called to process input packet */
|
||||||
void ppp_input(ppp_pcb *pcb, struct pbuf *pb);
|
void ppp_input(ppp_pcb *pcb, struct pbuf *pb);
|
||||||
|
|
||||||
|
/* helper function, merge a pbuf chain into one pbuf */
|
||||||
|
struct pbuf *ppp_singlebuf(struct pbuf *p);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Functions called by PPP protocols.
|
||||||
|
*/
|
||||||
|
|
||||||
/* function called by all PPP subsystems to send packets */
|
/* function called by all PPP subsystems to send packets */
|
||||||
int ppp_write(ppp_pcb *pcb, struct pbuf *p);
|
int ppp_write(ppp_pcb *pcb, struct pbuf *p);
|
||||||
|
|
||||||
/* functions called by auth.c link_terminated() */
|
/* functions called by auth.c link_terminated() */
|
||||||
void ppp_link_terminated(ppp_pcb *pcb);
|
void ppp_link_terminated(ppp_pcb *pcb);
|
||||||
|
|
||||||
/* merge a pbuf chain into one pbuf */
|
|
||||||
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(ppp_pcb *pcb, int p);
|
void new_phase(ppp_pcb *pcb, int p);
|
||||||
|
|
||||||
int ppp_send_config(ppp_pcb *pcb, int mtu, u32_t accm, int pcomp, int accomp);
|
int ppp_send_config(ppp_pcb *pcb, int mtu, u32_t accm, int pcomp, int accomp);
|
||||||
@ -456,15 +468,13 @@ int get_idle_time(ppp_pcb *pcb, struct ppp_idle *ip);
|
|||||||
|
|
||||||
int get_loop_output(void);
|
int get_loop_output(void);
|
||||||
|
|
||||||
u32_t get_mask (u32_t addr);
|
u32_t get_mask(u32_t addr);
|
||||||
|
|
||||||
|
|
||||||
/* Optional protocol names list, to make our messages a little more informative. */
|
/* Optional protocol names list, to make our messages a little more informative. */
|
||||||
#if PPP_PROTOCOLNAME
|
#if PPP_PROTOCOLNAME
|
||||||
const char * protocol_name(int proto);
|
const char * protocol_name(int proto);
|
||||||
#endif /* PPP_PROTOCOLNAME */
|
#endif /* PPP_PROTOCOLNAME */
|
||||||
|
|
||||||
|
|
||||||
/* Optional stats support, to get some statistics on the PPP interface */
|
/* Optional stats support, to get some statistics on the PPP interface */
|
||||||
#if PPP_STATS_SUPPORT
|
#if PPP_STATS_SUPPORT
|
||||||
void print_link_stats(void); /* Print stats, if available */
|
void print_link_stats(void); /* Print stats, if available */
|
||||||
@ -486,8 +496,6 @@ void update_link_stats(int u); /* Get stats at link termination */
|
|||||||
#define PUTCHAR(c, cp) { \
|
#define PUTCHAR(c, cp) { \
|
||||||
*(cp)++ = (u_char) (c); \
|
*(cp)++ = (u_char) (c); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define GETSHORT(s, cp) { \
|
#define GETSHORT(s, cp) { \
|
||||||
(s) = *(cp)++ << 8; \
|
(s) = *(cp)++ << 8; \
|
||||||
(s) |= *(cp)++; \
|
(s) |= *(cp)++; \
|
||||||
@ -496,7 +504,6 @@ void update_link_stats(int u); /* Get stats at link termination */
|
|||||||
*(cp)++ = (u_char) ((s) >> 8); \
|
*(cp)++ = (u_char) ((s) >> 8); \
|
||||||
*(cp)++ = (u_char) (s); \
|
*(cp)++ = (u_char) (s); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GETLONG(l, cp) { \
|
#define GETLONG(l, cp) { \
|
||||||
(l) = *(cp)++ << 8; \
|
(l) = *(cp)++ << 8; \
|
||||||
(l) |= *(cp)++; (l) <<= 8; \
|
(l) |= *(cp)++; (l) <<= 8; \
|
||||||
@ -516,9 +523,9 @@ void update_link_stats(int u); /* Get stats at link termination */
|
|||||||
/*
|
/*
|
||||||
* System dependent definitions for user-level 4.3BSD UNIX implementation.
|
* System dependent definitions for user-level 4.3BSD UNIX implementation.
|
||||||
*/
|
*/
|
||||||
#define TIMEOUT(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t)*1000, (f), (a)); } while(0)
|
#define TIMEOUT(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t)*1000, (f), (a)); } while(0)
|
||||||
#define TIMEOUTMS(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t), (f), (a)); } while(0)
|
#define TIMEOUTMS(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t), (f), (a)); } while(0)
|
||||||
#define UNTIMEOUT(f, a) sys_untimeout((f), (a))
|
#define UNTIMEOUT(f, a) sys_untimeout((f), (a))
|
||||||
|
|
||||||
#define BZERO(s, n) memset(s, 0, n)
|
#define BZERO(s, n) memset(s, 0, n)
|
||||||
#define BCMP(s1, s2, l) memcmp(s1, s2, l)
|
#define BCMP(s1, s2, l) memcmp(s1, s2, l)
|
||||||
@ -610,5 +617,4 @@ void ppp_dump_packet(const char *tag, unsigned char *p, int len);
|
|||||||
|
|
||||||
|
|
||||||
#endif /* PPP_IMP_H_ */
|
#endif /* PPP_IMP_H_ */
|
||||||
|
|
||||||
#endif /* PPP_SUPPORT */
|
#endif /* PPP_SUPPORT */
|
||||||
|
@ -590,6 +590,11 @@ ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void
|
|||||||
return pcb;
|
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 */
|
/* Set a PPP PCB to its initial state */
|
||||||
void ppp_clear(ppp_pcb *pcb) {
|
void ppp_clear(ppp_pcb *pcb) {
|
||||||
const struct protent *protp;
|
const struct protent *protp;
|
||||||
@ -616,11 +621,6 @@ void ppp_clear(ppp_pcb *pcb) {
|
|||||||
new_phase(pcb, PPP_PHASE_INITIALIZE);
|
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 */
|
/** Initiate LCP open request */
|
||||||
void ppp_start(ppp_pcb *pcb) {
|
void ppp_start(ppp_pcb *pcb) {
|
||||||
PPPDEBUG(LOG_DEBUG, ("ppp_start: unit %d\n", pcb->netif->num));
|
PPPDEBUG(LOG_DEBUG, ("ppp_start: unit %d\n", pcb->netif->num));
|
||||||
@ -780,27 +780,8 @@ out:
|
|||||||
return;
|
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 */
|
/* 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;
|
struct pbuf *q, *b;
|
||||||
u_char *pl;
|
u_char *pl;
|
||||||
|
|
||||||
@ -825,6 +806,24 @@ struct pbuf * ppp_singlebuf(struct pbuf *p) {
|
|||||||
return q;
|
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) {
|
void ppp_link_terminated(ppp_pcb *pcb) {
|
||||||
PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: unit %d\n", pcb->netif->num));
|
PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: unit %d\n", pcb->netif->num));
|
||||||
pcb->link_cb->disconnect(pcb, pcb->link_ctx_cb);
|
pcb->link_cb->disconnect(pcb, pcb->link_ctx_cb);
|
||||||
|
@ -244,8 +244,8 @@ pppos_write(ppp_pcb *ppp, void *ctx, struct pbuf *p)
|
|||||||
* Otherwise send it. */
|
* Otherwise send it. */
|
||||||
if (!tail) {
|
if (!tail) {
|
||||||
PPPDEBUG(LOG_WARNING,
|
PPPDEBUG(LOG_WARNING,
|
||||||
("ppp_write[%d]: Alloc err - dropping pbuf len=%d\n", ppp->netif->num, head->len));
|
("pppos_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 %d:%.*H", pd, head->len, LWIP_MIN(head->len * 2, 40), head->payload)); */
|
||||||
pbuf_free(head);
|
pbuf_free(head);
|
||||||
LINK_STATS_INC(link.memerr);
|
LINK_STATS_INC(link.memerr);
|
||||||
LINK_STATS_INC(link.proterr);
|
LINK_STATS_INC(link.proterr);
|
||||||
@ -254,8 +254,8 @@ pppos_write(ppp_pcb *ppp, void *ctx, struct pbuf *p)
|
|||||||
return ERR_MEM;
|
return ERR_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
PPPDEBUG(LOG_INFO, ("ppp_write[%d]: len=%d\n", ppp->netif->num, head->len));
|
PPPDEBUG(LOG_INFO, ("pppos_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_write[%d]: %d:%.*H", pd, head->len, LWIP_MIN(head->len * 2, 40), head->payload)); */
|
||||||
pppos_xmit(pppos, head);
|
pppos_xmit(pppos, head);
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
@ -426,7 +426,7 @@ pppos_disconnect(ppp_pcb *ppp, void *ctx)
|
|||||||
{
|
{
|
||||||
LWIP_UNUSED_ARG(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()
|
* rx thread might still call pppos_input()
|
||||||
*/
|
*/
|
||||||
ppp_link_end(ppp); /* notify upper layers */
|
ppp_link_end(ppp); /* notify upper layers */
|
||||||
|
Loading…
Reference in New Issue
Block a user