Discussion:
pppd idle option and idle_time_hook
(too old to reply)
Chris Nelson
2006-07-19 20:53:15 UTC
Permalink
Is the processing done by the pppd idle_time_hook done _in_ _addition_
_to_ counting packets (with consideration for the active-filter) or
_instead_ _of_ that processing? That is, does it do:

if I've been idle for a while
or (idle_time_hook != NULL && idle_time_hook() < 0)
disconnect

or

if idle_time_hook != NULL
if idle_time_hook() < 0
disconnect
else if I've been idle for a while
disconnect

?
James Carlson
2006-07-19 21:15:48 UTC
Permalink
Post by Chris Nelson
Is the processing done by the pppd idle_time_hook done _in_ _addition_
_to_ counting packets (with consideration for the active-filter) or
if I've been idle for a while
or (idle_time_hook != NULL && idle_time_hook() < 0)
disconnect
or
if idle_time_hook != NULL
if idle_time_hook() < 0
disconnect
else if I've been idle for a while
disconnect
It's instead-of -- i.e., the latter.

The code is in pppd/auth.c. It's pretty simple. When a network
protocol comes up, we do this:

if (idle_time_hook != 0)
tlim = (*idle_time_hook)(NULL);
else
tlim = idle_time_limit;
if (tlim > 0)
TIMEOUT(check_idle, NULL, tlim);

When that timer fires, it does this:

if (idle_time_hook != 0) {
tlim = idle_time_hook(&idle);
} else {
itime = MIN(idle.xmit_idle, idle.recv_idle);
tlim = idle_time_limit - itime;
}
if (tlim <= 0) {
/* link is idle: shut it down. */
notice("Terminating connection due to lack of activity.");
--
James Carlson, KISS Network <***@sun.com>
Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677
Chris Nelson
2006-07-20 11:28:55 UTC
Permalink
Post by James Carlson
Post by Chris Nelson
Is the processing done by the pppd idle_time_hook done _in_ _addition_
_to_ counting packets (with consideration for the active-filter) or
_instead_ _of_ that processing? ...
It's instead-of -- i.e., the latter.
The code is in pppd/auth.c. It's pretty simple. When a network
if (idle_time_hook != 0)
tlim = (*idle_time_hook)(NULL);
else
tlim = idle_time_limit;
if (tlim > 0)
TIMEOUT(check_idle, NULL, tlim);
if (idle_time_hook != 0) {
tlim = idle_time_hook(&idle);
} else {
itime = MIN(idle.xmit_idle, idle.recv_idle);
tlim = idle_time_limit - itime;
}
if (tlim <= 0) {
/* link is idle: shut it down. */
notice("Terminating connection due to lack of activity.");
I could add the contents of the else above to my idle hook to keep that
behavior, too, I guess. I'll play with that.

Do the counters on the ppp_idle struct passed to the hook reflect
active-filter?
James Carlson
2006-07-20 11:55:35 UTC
Permalink
Post by Chris Nelson
I could add the contents of the else above to my idle hook to keep that
behavior, too, I guess. I'll play with that.
Sure, you can do that.

If you provide such a hook, it's up to you to determine what's
appropriate for your situation.

The hooks in pppd aren't exactly designed for casual use. It's pretty
well expected that if you're using them, you're certainly also
examining the pppd source code in detail, and may also be changing
that code to accomodate what you need to do with the hook.

So, no, there's no simple documentation for them, nor very many simple
answers for what you can do with them.
Post by Chris Nelson
Do the counters on the ppp_idle struct passed to the hook reflect
active-filter?
Yes.
--
James Carlson, KISS Network <***@sun.com>
Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677
Chris Nelson
2006-07-21 14:11:16 UTC
Permalink
Post by James Carlson
Post by Chris Nelson
I could add the contents of the else above to my idle hook to keep that
behavior, too, I guess. I'll play with that.
Sure, you can do that.
If you provide such a hook, it's up to you to determine what's
appropriate for your situation.
Seems to work well. What I ended up with is:

#define DFT_CD_CHECK_INTERVAL 2

// Returns <= 0 to disconnect, seconds until next call otherwise.
static int idle_check(struct ppp_idle* idlep) {
if (idlep != NULL) {
int tioBits;

// If CD is down, return -1 to shutdown link
if (ioctl(devfd, TIOCMGET, &tioBits) == 0
&& ! (tioBits & TIOCM_CD)) {
return -1;
}

// This code is adapted from check_idle() in pppd/auth.c
if (idle_time_limit > 0) {
int itime; // The shortest time since xmit or recv
itime = MIN(idlep->xmit_idle, idlep->recv_idle);
if ((idle_time_limit - itime) <= 0) {
return -2;
}
}
}

if (idle_time_limit <= 0) {
return DFT_CD_CHECK_INTERVAL; // We want to check CD
periodically.
}
else {
return idle_time_limit; // Return configured idle time
}
}
Post by James Carlson
The hooks in pppd aren't exactly designed for casual use. It's pretty
well expected that if you're using them, you're certainly also
examining the pppd source code in detail, and may also be changing
that code to accomodate what you need to do with the hook.
So, no, there's no simple documentation for them, nor very many simple
answers for what you can do with them.
I'm tempted to "patch" pppd/PLUGINS to make some of what I learned more
explicit. Would that change be accepted?
Post by James Carlson
Post by Chris Nelson
Do the counters on the ppp_idle struct passed to the hook reflect
active-filter?
Yes.
Good. Thanks.
James Carlson
2006-07-21 17:07:31 UTC
Permalink
Post by Chris Nelson
Post by James Carlson
So, no, there's no simple documentation for them, nor very many simple
answers for what you can do with them.
I'm tempted to "patch" pppd/PLUGINS to make some of what I learned more
explicit. Would that change be accepted?
It seems reasonable. The only caution I have would be misleading
others into thinking that the plugin documentation is complete without
also reading the source, but I suppose that's not a serious risk.
--
James Carlson, KISS Network <***@sun.com>
Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677
Loading...