X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fauth.c;h=76fc8210388e8431c227806471fd3f52b3046a85;hb=0a5f7f46f597ae4fee342163de31c724096feb12;hp=727c69d4af8d92bf55924d95eef3edf1c3070b17;hpb=7bb8beb860037a6c18dd0b64b8d542a20aa2c8c0;p=ppp.git diff --git a/pppd/auth.c b/pppd/auth.c index 727c69d..76fc821 100644 --- a/pppd/auth.c +++ b/pppd/auth.c @@ -32,7 +32,7 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#define RCSID "$Id: auth.c,v 1.77 2002/05/21 17:26:49 dfs Exp $" +#define RCSID "$Id: auth.c,v 1.81 2002/09/01 12:00:15 dfs Exp $" #include #include @@ -217,6 +217,10 @@ static int set_noauth_addr __P((char **)); static void check_access __P((FILE *, char *)); static int wordlist_count __P((struct wordlist *)); +#ifdef MAXOCTETS +static void check_maxoctets __P((void *)); +#endif + /* * Authentication-related options. */ @@ -604,59 +608,62 @@ void start_networks(unit) int unit; { - static int started = 0; int i; struct protent *protp; int ecp_required, mppe_required; - if (!started) { - started = 1; - new_phase(PHASE_NETWORK); + new_phase(PHASE_NETWORK); #ifdef HAVE_MULTILINK - if (multilink) { - if (mp_join_bundle()) { - if (updetach && !nodetach) - detach(); - return; - } + if (multilink) { + if (mp_join_bundle()) { + if (updetach && !nodetach) + detach(); + return; } + } #endif /* HAVE_MULTILINK */ #ifdef PPP_FILTER - if (!demand) - set_filters(&pass_filter, &active_filter); + if (!demand) + set_filters(&pass_filter, &active_filter); #endif - /* Start CCP and ECP */ - for (i = 0; (protp = protocols[i]) != NULL; ++i) - if ((protp->protocol == PPP_ECP || protp->protocol == PPP_CCP) - && protp->enabled_flag && protp->open != NULL) - (*protp->open)(0); - } + /* Start CCP and ECP */ + for (i = 0; (protp = protocols[i]) != NULL; ++i) + if ((protp->protocol == PPP_ECP || protp->protocol == PPP_CCP) + && protp->enabled_flag && protp->open != NULL) + (*protp->open)(0); /* - * Bring up other network protocols after encryption has completed. - * OPENED here merely means that negotiation has completed. It is - * up to the protocol to correctly terminate or disable LCP/NCP - * based on the result of the negotiation. + * Bring up other network protocols iff encryption is not required. */ ecp_required = ecp_gotoptions[unit].required; mppe_required = ccp_gotoptions[unit].mppe; - if ((!ecp_required && !mppe_required) - || (ecp_required && ecp_fsm[unit].state == OPENED) - || (mppe_required && ccp_fsm[unit].state == OPENED)) { - for (i = 0; (protp = protocols[i]) != NULL; ++i) - if (protp->protocol < 0xC000 - && protp->protocol != PPP_CCP && protp->protocol != PPP_ECP - && protp->enabled_flag && protp->open != NULL) { - (*protp->open)(0); - ++num_np_open; - } + if (!ecp_required && !mppe_required) + continue_networks(unit); +} - if (num_np_open == 0) - /* nothing to do */ - lcp_close(0, "No network protocols running"); - } +void +continue_networks(unit) + int unit; +{ + int i; + struct protent *protp; + + /* + * Start the "real" network protocols. + */ + for (i = 0; (protp = protocols[i]) != NULL; ++i) + if (protp->protocol < 0xC000 + && protp->protocol != PPP_CCP && protp->protocol != PPP_ECP + && protp->enabled_flag && protp->open != NULL) { + (*protp->open)(0); + ++num_np_open; + } + + if (num_np_open == 0) + /* nothing to do */ + lcp_close(0, "No network protocols running"); } /* @@ -827,6 +834,11 @@ np_up(unit, proto) if (maxconnect > 0) TIMEOUT(connect_time_expired, 0, maxconnect); +#ifdef MAXOCTETS + if (maxoctets > 0) + TIMEOUT(check_maxoctets, NULL, maxoctets_timeout); +#endif + /* * Detach now, if the updetach option was given. */ @@ -846,6 +858,9 @@ np_down(unit, proto) if (--num_np_up == 0) { UNTIMEOUT(check_idle, NULL); UNTIMEOUT(connect_time_expired, NULL); +#ifdef MAXOCTETS + UNTIMEOUT(check_maxoctets, NULL); +#endif new_phase(PHASE_NETWORK); } } @@ -863,6 +878,44 @@ np_finished(unit, proto) } } +#ifdef MAXOCTETS +static void +check_maxoctets(arg) + void *arg; +{ + int diff; + unsigned int used; + + update_link_stats(ifunit); + link_stats_valid=0; + + switch(maxoctets_dir) { + case PPP_OCTETS_DIRECTION_IN: + used = link_stats.bytes_in; + break; + case PPP_OCTETS_DIRECTION_OUT: + used = link_stats.bytes_out; + break; + case PPP_OCTETS_DIRECTION_MAXOVERAL: + case PPP_OCTETS_DIRECTION_MAXSESSION: + used = (link_stats.bytes_in > link_stats.bytes_out) ? link_stats.bytes_in : link_stats.bytes_out; + break; + default: + used = link_stats.bytes_in+link_stats.bytes_out; + break; + } + diff = maxoctets - used; + if(diff < 0) { + notice("Traffic limit reached. Limit: %u Used: %u", maxoctets, used); + lcp_close(0, "Traffic limit"); + need_holdoff = 0; + status = EXIT_TRAFFIC_LIMIT; + } else { + TIMEOUT(check_maxoctets, NULL, maxoctets_timeout); + } +} +#endif + /* * check_idle - check whether the link has been idle for long * enough that we can shut it down.