demystified a bit the PPP impl, renamed output() to ppp_output() to prevent conflict

This commit is contained in:
Sylvain Rochet 2012-06-03 00:30:12 +02:00
parent e1261c9620
commit b5b075eb04
6 changed files with 88 additions and 69 deletions

View File

@ -276,7 +276,7 @@ chap_timeout(void *arg)
return;
}
output(0, ss->challenge, ss->challenge_pktlen);
ppp_output(0, ss->challenge, ss->challenge_pktlen);
++ss->challenge_xmits;
ss->flags |= TIMEOUT_PENDING;
TIMEOUT(chap_timeout, arg, chap_timeout_time);
@ -377,7 +377,7 @@ chap_handle_response(struct chap_server_state *ss, int id,
p[3] = len;
if (mlen > 0)
memcpy(p + CHAP_HDRLEN, ss->message, mlen);
output(0, outpacket_buf, PPP_HDRLEN + len);
ppp_output(0, outpacket_buf, PPP_HDRLEN + len);
if (ss->flags & CHALLENGE_VALID) {
ss->flags &= ~CHALLENGE_VALID;
@ -499,7 +499,7 @@ chap_respond(struct chap_client_state *cs, int id,
p[2] = len >> 8;
p[3] = len;
output(0, response, PPP_HDRLEN + len);
ppp_output(0, response, PPP_HDRLEN + len);
}
static void

View File

@ -274,7 +274,7 @@ eap_state *esp;
PUTCHAR(esp->es_server.ea_id, outp);
PUTSHORT(EAP_HEADERLEN, outp);
output(esp->es_unit, outpacket_buf, EAP_HEADERLEN + PPP_HDRLEN);
ppp_output(esp->es_unit, outpacket_buf, EAP_HEADERLEN + PPP_HDRLEN);
esp->es_server.ea_state = eapBadAuth;
auth_peer_fail(esp->es_unit, PPP_EAP);
@ -299,7 +299,7 @@ eap_state *esp;
PUTCHAR(esp->es_server.ea_id, outp);
PUTSHORT(EAP_HEADERLEN, outp);
output(esp->es_unit, outpacket_buf, PPP_HDRLEN + EAP_HEADERLEN);
ppp_output(esp->es_unit, 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);
@ -860,7 +860,7 @@ eap_state *esp;
outlen = (outp - outpacket_buf) - PPP_HDRLEN;
PUTSHORT(outlen, lenloc);
output(esp->es_unit, outpacket_buf, outlen + PPP_HDRLEN);
ppp_output(esp->es_unit, outpacket_buf, outlen + PPP_HDRLEN);
esp->es_server.ea_requests++;
@ -1067,7 +1067,7 @@ int lenstr;
MEMCPY(outp, str, lenstr);
}
output(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen);
ppp_output(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen);
}
/*
@ -1102,7 +1102,7 @@ int namelen;
MEMCPY(outp, name, namelen);
}
output(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen);
ppp_output(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen);
}
#ifdef USE_SRP
@ -1135,7 +1135,7 @@ int lenstr;
MEMCPY(outp, str, lenstr);
}
output(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen);
ppp_output(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen);
}
/*
@ -1166,7 +1166,7 @@ u_char *str;
PUTLONG(flags, outp);
MEMCPY(outp, str, SHA_DIGESTSIZE);
output(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen);
ppp_output(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen);
}
#endif /* USE_SRP */
@ -1191,7 +1191,7 @@ u_char type;
PUTCHAR(EAPT_NAK, outp);
PUTCHAR(type, outp);
output(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen);
ppp_output(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen);
}
#ifdef USE_SRP

View File

@ -818,5 +818,5 @@ fsm_sdata(f, code, id, data, datalen)
PUTCHAR(code, outp);
PUTCHAR(id, outp);
PUTSHORT(outlen, outp);
output(f->unit, outpacket_buf, outlen + PPP_HDRLEN);
ppp_output(f->unit, outpacket_buf, outlen + PPP_HDRLEN);
}

View File

@ -184,10 +184,12 @@ typedef struct PPPControl_s {
static void pppStart(int pd); /** Initiate LCP open request */
static void ppp_input(void *arg);
#if PPPOE_SUPPORT
static void pppOverEthernetLinkStatusCB(int pd, int up);
static err_t pppifOutputOverEthernet(int pd, struct pbuf *p);
static err_t pppifOutput(struct netif *netif, struct pbuf *pb, ip_addr_t *ipaddr);
static err_t pppifNetifInit(struct netif *netif);
#endif /* PPPOE_SUPPORT */
static err_t ppp_low_level_output(struct netif *netif, struct pbuf *pb, ip_addr_t *ipaddr);
static err_t ppp_netif_init_cb(struct netif *netif);
/******************************/
@ -807,8 +809,12 @@ static err_t pppifOutputOverEthernet(int pd, struct pbuf *p) {
}
#endif /* PPPOE_SUPPORT */
/* Send a packet on the given connection. */
static err_t pppifOutput(struct netif *netif, struct pbuf *pb, ip_addr_t *ipaddr) {
/* Send a packet on the given connection.
*
* This is the low level function that send the PPP packet.
*/
static err_t ppp_low_level_output(struct netif *netif, struct pbuf *pb, ip_addr_t *ipaddr) {
int pd = (int)(size_t)netif->state;
PPPControl *pc = &pppControl[pd];
#if PPPOS_SUPPORT
@ -824,7 +830,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, ip_addr_t *ipaddr
/* 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->openFlag || !pb) {
PPPDEBUG(LOG_WARNING, ("pppifOutput[%d]: bad parms prot=%d pb=%p\n",
PPPDEBUG(LOG_WARNING, ("ppp_low_level_output[%d]: bad parms prot=%d pb=%p\n",
pd, PPP_IP, (void*)pb));
LINK_STATS_INC(link.opterr);
LINK_STATS_INC(link.drop);
@ -834,7 +840,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, ip_addr_t *ipaddr
/* Check that the link is up. */
if (phase == PHASE_DEAD) {
PPPDEBUG(LOG_ERR, ("pppifOutput[%d]: link not up\n", pd));
PPPDEBUG(LOG_ERR, ("ppp_low_level_output[%d]: link not up\n", pd));
LINK_STATS_INC(link.rterr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(netif);
@ -851,7 +857,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, ip_addr_t *ipaddr
/* Grab an output buffer. */
headMB = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL);
if (headMB == NULL) {
PPPDEBUG(LOG_WARNING, ("pppifOutput[%d]: first alloc fail\n", pd));
PPPDEBUG(LOG_WARNING, ("ppp_low_level_output[%d]: first alloc fail\n", pd));
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(netif);
@ -876,7 +882,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, ip_addr_t *ipaddr
protocol = PPP_VJC_UNCOMP;
break;
default:
PPPDEBUG(LOG_WARNING, ("pppifOutput[%d]: bad IP packet\n", pd));
PPPDEBUG(LOG_WARNING, ("ppp_low_level_output[%d]: bad IP packet\n", pd));
LINK_STATS_INC(link.proterr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(netif);
@ -937,7 +943,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, ip_addr_t *ipaddr
/* If we failed to complete the packet, throw it away. */
if (!tailMB) {
PPPDEBUG(LOG_WARNING,
("pppifOutput[%d]: Alloc err - dropping proto=%d\n",
("ppp_low_level_output[%d]: Alloc err - dropping proto=%d\n",
pd, protocol));
pbuf_free(headMB);
LINK_STATS_INC(link.memerr);
@ -947,7 +953,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, ip_addr_t *ipaddr
}
/* Send it. */
PPPDEBUG(LOG_INFO, ("pppifOutput[%d]: proto=0x%"X16_F"\n", pd, protocol));
PPPDEBUG(LOG_INFO, ("ppp_low_level_output[%d]: proto=0x%"X16_F"\n", pd, protocol));
nPut(pc, headMB);
#endif /* PPPOS_SUPPORT */
@ -1015,7 +1021,7 @@ int pppWriteOverEthernet(int pd, const u_char *s, int n) {
* RETURN: >= 0 Number of characters written
* -1 Failed to write to device
*/
int pppWrite(int pd, const u_char *s, int n) {
int ppp_output(int pd, const u_char *s, int n) {
PPPControl *pc = &pppControl[pd];
#if PPPOS_SUPPORT
u_char c;
@ -1070,8 +1076,8 @@ int pppWrite(int pd, const u_char *s, int n) {
* Otherwise send it. */
if (!tailMB) {
PPPDEBUG(LOG_WARNING,
("pppWrite[%d]: Alloc err - dropping pbuf len=%d\n", pd, headMB->len));
/*"pppWrite[%d]: Alloc err - dropping %d:%.*H", pd, headMB->len, LWIP_MIN(headMB->len * 2, 40), headMB->payload)); */
("ppp_output[%d]: Alloc err - dropping pbuf len=%d\n", pd, headMB->len));
/*"ppp_output[%d]: Alloc err - dropping %d:%.*H", pd, headMB->len, LWIP_MIN(headMB->len * 2, 40), headMB->payload)); */
pbuf_free(headMB);
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.proterr);
@ -1079,8 +1085,8 @@ int pppWrite(int pd, const u_char *s, int n) {
return PPPERR_ALLOC;
}
PPPDEBUG(LOG_INFO, ("pppWrite[%d]: len=%d\n", pd, headMB->len));
/* "pppWrite[%d]: %d:%.*H", pd, headMB->len, LWIP_MIN(headMB->len * 2, 40), headMB->payload)); */
PPPDEBUG(LOG_INFO, ("ppp_output[%d]: len=%d\n", pd, headMB->len));
/* "ppp_output[%d]: %d:%.*H", pd, headMB->len, LWIP_MIN(headMB->len * 2, 40), headMB->payload)); */
nPut(pc, headMB);
#endif /* PPPOS_SUPPORT */
@ -1093,13 +1099,30 @@ int pppWrite(int pd, const u_char *s, int n) {
*
* output - Output PPP packet.
*/
/*
void output (int unit, unsigned char *p, int len)
{
pppWrite(unit, p, len);
}
*/
/************************************************************************
* Functions called by various PPP subsystems to configure
* the PPP interface or change the PPP phase.
*/
/*
* new_phase - signal the start of a new phase of pppd's operation.
*/
void new_phase(int p) {
phase = p;
#if PPP_NOTIFY
/* The one willing notify support should add here the code to be notified of phase changes */
#endif /* PPP_NOTIFY */
}
/*
* ppp_send_config - configure the transmit-side characteristics of
* the ppp interface.
@ -1182,25 +1205,6 @@ int cifaddr (int unit, u_int32_t our_adr, u_int32_t his_adr) {
return 0;
}
/*
* pppifNetifInit - netif init callback
*/
static err_t
pppifNetifInit(struct netif *netif)
{
netif->name[0] = 'p';
netif->name[1] = 'p';
netif->output = pppifOutput;
netif->mtu = pppMTU((int)(size_t)netif->state);
netif->flags = NETIF_FLAG_POINTTOPOINT | NETIF_FLAG_LINK_UP;
#if LWIP_NETIF_HOSTNAME
/* @todo: Initialize interface hostname */
/* netif_set_hostname(netif, "lwip"); */
#endif /* LWIP_NETIF_HOSTNAME */
return ERR_OK;
}
/*
* sifup - Config the interface up and enable IP packets to pass.
*/
@ -1215,7 +1219,7 @@ int sifup(int 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, pppifNetifInit, ip_input)) {
&pc->addrs.his_ipaddr, (void *)(size_t)u, ppp_netif_init_cb, ip_input)) {
netif_set_up(&pc->netif);
pc->if_up = 1;
pc->errCode = PPPERR_NONE;
@ -1233,6 +1237,22 @@ int sifup(int u)
return st;
}
/*
* ppp_netif_init_cb - netif init callback
*/
static err_t ppp_netif_init_cb(struct netif *netif) {
netif->name[0] = 'p';
netif->name[1] = 'p';
netif->output = ppp_low_level_output;
netif->mtu = pppMTU((int)(size_t)netif->state);
netif->flags = NETIF_FLAG_POINTTOPOINT | NETIF_FLAG_LINK_UP;
#if LWIP_NETIF_HOSTNAME
/* @todo: Initialize interface hostname */
/* netif_set_hostname(netif, "lwip"); */
#endif /* LWIP_NETIF_HOSTNAME */
return ERR_OK;
}
/********************************************************************
*
* sifdown - Disable the indicated protocol and config the interface
@ -1510,16 +1530,6 @@ const char * protocol_name(int proto) {
}
#endif /* PPP_PROTOCOLNAME */
/*
* new_phase - signal the start of a new phase of pppd's operation.
*/
void new_phase(int p) {
phase = p;
#if PPP_NOTIFY
/* The one willing notify support should add here the code to be notified of phase changes */
#endif /* PPP_NOTIFY */
}
#if PPP_STATS_SUPPORT
/* ---- Note on PPP Stats support ----

View File

@ -293,9 +293,6 @@ struct ppp_settings ppp_settings;
*** PUBLIC FUNCTIONS ***
************************/
/* Initialize the PPP subsystem. */
int ppp_init(void);
/* Warning: Using PPPAUTHTYPE_ANY might have security consequences.
* RFC 1994 says:
*
@ -324,6 +321,7 @@ enum pppAuthType {
PPPAUTHTYPE_NONE
};
/* Initialize the PPP subsystem. */
int ppp_init(void);
void pppSetAuth(enum pppAuthType authType, const char *user, const char *passwd);
@ -338,8 +336,12 @@ int pppOverEthernetOpen(struct netif *ethif, const char *service_name, const cha
pppLinkStatusCB_fn linkStatusCB, void *linkStatusCtx);
/* -- private */
/* --- EVERYTHING BELOW SHOULD BE CONSIDERED PRIVATE ---- */
/* PPP flow functions
*/
struct pbuf * pppSingleBuf(struct pbuf *p);
void pppInProcOverEthernet(int pd, struct pbuf *pb);
@ -350,11 +352,15 @@ u_short pppMTU(int pd);
int pppWriteOverEthernet(int pd, const u_char *s, int n);
int pppWrite(int pd, const u_char *s, int n);
int ppp_output(int pd, const u_char *s, int n);
void pppInProcOverEthernet(int pd, struct pbuf *pb);
void output (int unit, unsigned char *p, int len);
/* Functions called by various PPP subsystems to configure
* the PPP interface or change the PPP phase.
*/
void new_phase(int p);
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);
@ -384,20 +390,20 @@ int get_loop_output(void);
u_int32_t GetMask (u_int32_t addr);
/* Optional protocol names list, to make our messages a little more informative. */
#if PPP_PROTOCOLNAME
const char * protocol_name(int proto);
#endif /* PPP_PROTOCOLNAME */
void new_phase(int p);
/* Optional stats support, to get some statistics on the PPP interface */
#if PPP_STATS_SUPPORT
void print_link_stats(void); /* Print stats, if available */
void reset_link_stats(int u); /* Reset (init) stats when link goes up */
void update_link_stats(int u); /* Get stats at link termination */
#endif /* PPP_STATS_SUPPORT */
#endif /* PPPMY_H_ */
/*
@ -560,3 +566,6 @@ void end_pr_log __P((void)); /* finish up after using pr_log */
void dump_packet __P((const char *, u_char *, int));
/* dump packet to debug log if interesting */
#endif /* PRINTPKT_SUPPORT */
#endif /* PPPMY_H_ */

View File

@ -592,7 +592,7 @@ upap_sauthreq(u)
PUTCHAR(u->us_passwdlen, outp);
MEMCPY(outp, u->us_passwd, u->us_passwdlen);
output(u->us_unit, outpacket_buf, outlen + PPP_HDRLEN);
ppp_output(u->us_unit, outpacket_buf, outlen + PPP_HDRLEN);
TIMEOUT(upap_timeout, u, u->us_timeouttime);
++u->us_transmits;
@ -622,7 +622,7 @@ upap_sresp(u, code, id, msg, msglen)
PUTSHORT(outlen, outp);
PUTCHAR(msglen, outp);
MEMCPY(outp, msg, msglen);
output(u->us_unit, outpacket_buf, outlen + PPP_HDRLEN);
ppp_output(u->us_unit, outpacket_buf, outlen + PPP_HDRLEN);
}
#endif /* UNUSED */