PPP, CORE, compile out auth support if none of auth protocols are enabled

Added macro PPP_AUTH_SUPPORT, if none of auth protocols are enabled
(PAP, CHAP, EAP) we reduce PPP memory usage by compiling out all
struct fields and source code used for authentication.
This commit is contained in:
Sylvain Rochet 2015-02-21 19:32:38 +01:00
parent 973472c51e
commit 59b659b027
5 changed files with 34 additions and 6 deletions

View File

@ -140,6 +140,9 @@
#define PPPCTLG_ERRCODE 102 /* Get the error code */ #define PPPCTLG_ERRCODE 102 /* Get the error code */
#define PPPCTLG_FD 103 /* Get the fd associated with the ppp */ #define PPPCTLG_FD 103 /* Get the fd associated with the ppp */
/* Whether auth support is enabled at all */
#define PPP_AUTH_SUPPORT (PAP_SUPPORT || CHAP_SUPPORT || EAP_SUPPORT)
/************************ /************************
*** PUBLIC DATA TYPES *** *** PUBLIC DATA TYPES ***
************************/ ************************/
@ -187,12 +190,12 @@ typedef void (*ppp_link_status_cb_fn)(ppp_pcb *pcb, int err_code, void *ctx);
*/ */
typedef struct ppp_settings_s { typedef struct ppp_settings_s {
#if PPP_SERVER #if PPP_SERVER && PPP_AUTH_SUPPORT
unsigned int auth_required : 1; /* Peer is required to authenticate */ unsigned int auth_required : 1; /* Peer is required to authenticate */
unsigned int null_login : 1; /* Username of "" and a password of "" are acceptable */ unsigned int null_login : 1; /* Username of "" and a password of "" are acceptable */
#else #else
unsigned int :2; /* 2 bits of padding */ unsigned int :2; /* 2 bits of padding */
#endif /* PPP_SERVER */ #endif /* PPP_SERVER && PPP_AUTH_SUPPORT */
#if PPP_REMOTENAME #if PPP_REMOTENAME
unsigned int explicit_remote : 1; /* remote_name specified with remotename opt */ unsigned int explicit_remote : 1; /* remote_name specified with remotename opt */
#else #else
@ -245,6 +248,7 @@ typedef struct ppp_settings_s {
u32_t maxconnect; /* Maximum connect time (seconds) */ u32_t maxconnect; /* Maximum connect time (seconds) */
#endif /* PPP_MAXCONNECT */ #endif /* PPP_MAXCONNECT */
#if PPP_AUTH_SUPPORT
/* auth data */ /* auth data */
const char *user; /* Username for PAP */ const char *user; /* Username for PAP */
const char *passwd; /* Password for PAP, secret for CHAP */ const char *passwd; /* Password for PAP, secret for CHAP */
@ -280,6 +284,8 @@ typedef struct ppp_settings_s {
#endif /* PPP_SERVER */ #endif /* PPP_SERVER */
#endif /* EAP_SUPPORT */ #endif /* EAP_SUPPORT */
#endif /* PPP_AUTH_SUPPORT */
u8_t fsm_timeout_time; /* Timeout time in seconds */ u8_t fsm_timeout_time; /* Timeout time in seconds */
u8_t fsm_max_conf_req_transmits; /* Maximum Configure-Request transmissions */ u8_t fsm_max_conf_req_transmits; /* Maximum Configure-Request transmissions */
u8_t fsm_max_term_transmits; /* Maximum Terminate-Request transmissions */ u8_t fsm_max_term_transmits; /* Maximum Terminate-Request transmissions */

View File

@ -544,6 +544,7 @@ void upper_layers_down(ppp_pcb *pcb); /* take all NCPs down */
void link_established(ppp_pcb *pcb); /* the link is up; authenticate now */ void link_established(ppp_pcb *pcb); /* the link is up; authenticate now */
void start_networks(ppp_pcb *pcb); /* start all the network control protos */ void start_networks(ppp_pcb *pcb); /* start all the network control protos */
void continue_networks(ppp_pcb *pcb); /* start network [ip, etc] control protos */ void continue_networks(ppp_pcb *pcb); /* start network [ip, etc] control protos */
#if PPP_AUTH_SUPPORT
#if PPP_SERVER #if PPP_SERVER
void auth_peer_fail(ppp_pcb *pcb, int protocol); void auth_peer_fail(ppp_pcb *pcb, int protocol);
/* peer failed to authenticate itself */ /* peer failed to authenticate itself */
@ -554,12 +555,15 @@ void auth_withpeer_fail(ppp_pcb *pcb, int protocol);
/* we failed to authenticate ourselves */ /* we failed to authenticate ourselves */
void auth_withpeer_success(ppp_pcb *pcb, int protocol, int prot_flavor); void auth_withpeer_success(ppp_pcb *pcb, int protocol, int prot_flavor);
/* we successfully authenticated ourselves */ /* we successfully authenticated ourselves */
#endif /* PPP_AUTH_SUPPORT */
void np_up(ppp_pcb *pcb, int proto); /* a network protocol has come up */ void np_up(ppp_pcb *pcb, int proto); /* a network protocol has come up */
void np_down(ppp_pcb *pcb, int proto); /* a network protocol has gone down */ void np_down(ppp_pcb *pcb, int proto); /* a network protocol has gone down */
void np_finished(ppp_pcb *pcb, int proto); /* a network protocol no longer needs link */ void np_finished(ppp_pcb *pcb, int proto); /* a network protocol no longer needs link */
#if PPP_AUTH_SUPPORT
void auth_reset(ppp_pcb *pcb); /* check what secrets we have */ void auth_reset(ppp_pcb *pcb); /* check what secrets we have */
int get_secret(ppp_pcb *pcb, const char *client, const char *server, char *secret, int *secret_len, int am_server); int get_secret(ppp_pcb *pcb, const char *client, const char *server, char *secret, int *secret_len, int am_server);
/* get "secret" for chap */ /* get "secret" for chap */
#endif /* PPP_AUTH_SUPPORT */
/* Procedures exported from ipcp.c */ /* Procedures exported from ipcp.c */
/* int parse_dotted_ip (char *, u32_t *); */ /* int parse_dotted_ip (char *, u32_t *); */

View File

@ -725,17 +725,17 @@ void upper_layers_down(ppp_pcb *pcb) {
* Proceed to the Dead, Authenticate or Network phase as appropriate. * Proceed to the Dead, Authenticate or Network phase as appropriate.
*/ */
void link_established(ppp_pcb *pcb) { void link_established(ppp_pcb *pcb) {
#if PPP_AUTH_SUPPORT
int auth; int auth;
#if PPP_SERVER #if PPP_SERVER
int errcode;
lcp_options *wo = &pcb->lcp_wantoptions; lcp_options *wo = &pcb->lcp_wantoptions;
lcp_options *go = &pcb->lcp_gotoptions; lcp_options *go = &pcb->lcp_gotoptions;
#endif /* PPP_SERVER */ #endif /* PPP_SERVER */
lcp_options *ho = &pcb->lcp_hisoptions; lcp_options *ho = &pcb->lcp_hisoptions;
#endif /* PPP_AUTH_SUPPORT */
int i; int i;
const struct protent *protp; const struct protent *protp;
#if PPP_SERVER
int errcode;
#endif /* PPP_SERVER */
/* /*
* Tell higher-level protocols that LCP is up. * Tell higher-level protocols that LCP is up.
@ -747,6 +747,7 @@ void link_established(ppp_pcb *pcb) {
(*protp->lowerup)(pcb); (*protp->lowerup)(pcb);
} }
#if PPP_AUTH_SUPPORT
#if PPP_SERVER #if PPP_SERVER
#if PPP_ALLOWED_ADDRS #if PPP_ALLOWED_ADDRS
if (!auth_required && noauth_addrs != NULL) if (!auth_required && noauth_addrs != NULL)
@ -838,7 +839,7 @@ void link_established(ppp_pcb *pcb) {
pcb->auth_done = 0; pcb->auth_done = 0;
if (!auth) if (!auth)
#endif /* PPP_AUTH_SUPPORT */
network_phase(pcb); network_phase(pcb);
} }
@ -994,6 +995,7 @@ void continue_networks(ppp_pcb *pcb) {
lcp_close(pcb, "No network protocols running"); lcp_close(pcb, "No network protocols running");
} }
#if PPP_AUTH_SUPPORT
#if PPP_SERVER #if PPP_SERVER
/* /*
* The peer has failed to authenticate himself using `protocol'. * The peer has failed to authenticate himself using `protocol'.
@ -1156,6 +1158,7 @@ void auth_withpeer_success(ppp_pcb *pcb, int protocol, int prot_flavor) {
if ((pcb->auth_pending &= ~bit) == 0) if ((pcb->auth_pending &= ~bit) == 0)
network_phase(pcb); network_phase(pcb);
} }
#endif /* PPP_AUTH_SUPPORT */
/* /*
@ -1469,6 +1472,7 @@ auth_check_options()
} }
#endif /* PPP_OPTIONS */ #endif /* PPP_OPTIONS */
#if PPP_AUTH_SUPPORT
/* /*
* auth_reset - called when LCP is starting negotiations to recheck * auth_reset - called when LCP is starting negotiations to recheck
* authentication options, i.e. whether we have appropriate secrets * authentication options, i.e. whether we have appropriate secrets
@ -1581,6 +1585,7 @@ void auth_reset(ppp_pcb *pcb) {
go->neg_eap = 0; go->neg_eap = 0;
#endif #endif
} }
#endif /* PPP_AUTH_SUPPORT */
#if 0 /* UNUSED */ #if 0 /* UNUSED */
/* /*
@ -1934,6 +1939,7 @@ have_srp_secret(client, server, need_ip, lacks_ipp)
} }
#endif /* UNUSED */ #endif /* UNUSED */
#if PPP_AUTH_SUPPORT
/* /*
* get_secret - open the CHAP secret file and return the secret * get_secret - open the CHAP secret file and return the secret
* for authenticating the given client on the given server. * for authenticating the given client on the given server.
@ -2024,6 +2030,7 @@ int get_secret(ppp_pcb *pcb, const char *client, const char *server, char *secre
return 1; return 1;
#endif #endif
} }
#endif /* PPP_AUTH_SUPPORT */
#if 0 /* UNUSED */ #if 0 /* UNUSED */

View File

@ -665,7 +665,9 @@ static void lcp_resetci(fsm *f) {
if (pcb->settings.noendpoint) if (pcb->settings.noendpoint)
ao->neg_endpoint = 0; ao->neg_endpoint = 0;
pcb->peer_mru = PPP_MRU; pcb->peer_mru = PPP_MRU;
#if PPP_AUTH_SUPPORT
auth_reset(pcb); auth_reset(pcb);
#endif /* PPP_AUTH_SUPPORT */
} }

View File

@ -187,6 +187,8 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u_short prot
/***********************************/ /***********************************/
void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd) { void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd) {
#if PPP_AUTH_SUPPORT
#if PAP_SUPPORT #if PAP_SUPPORT
if (authtype & PPPAUTHTYPE_PAP) { if (authtype & PPPAUTHTYPE_PAP) {
pcb->settings.refuse_pap = 0; pcb->settings.refuse_pap = 0;
@ -227,6 +229,13 @@ void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *pas
if (passwd) { if (passwd) {
pcb->settings.passwd = passwd; pcb->settings.passwd = passwd;
} }
#else /* PPP_AUTH_SUPPORT */
LWIP_UNUSED_ARG(pcb);
LWIP_UNUSED_ARG(authtype);
LWIP_UNUSED_ARG(user);
LWIP_UNUSED_ARG(passwd);
#endif /* PPP_AUTH_SUPPORT */
} }
#if PPP_NOTIFY_PHASE #if PPP_NOTIFY_PHASE