pppd idle option and idle_time_hook - PPP

This is a discussion on pppd idle option and idle_time_hook - PPP ; 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 ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: pppd idle option and idle_time_hook

  1. pppd idle option and idle_time_hook

    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

    ?


  2. Re: pppd idle option and idle_time_hook

    "Chris Nelson" writes:

    > 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


    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 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

  3. Re: pppd idle option and idle_time_hook

    James Carlson wrote:
    > "Chris Nelson" writes:
    > > 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
    > 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.");


    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?


  4. Re: pppd idle option and idle_time_hook

    "Chris Nelson" writes:
    > 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.

    > Do the counters on the ppp_idle struct passed to the hook reflect
    > active-filter?


    Yes.

    --
    James Carlson, KISS Network
    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

  5. Re: pppd idle option and idle_time_hook

    James Carlson wrote:
    > "Chris Nelson" writes:
    > > 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
    }
    }

    > 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?

    > > Do the counters on the ppp_idle struct passed to the hook reflect
    > > active-filter?

    >
    > Yes.


    Good. Thanks.


  6. Re: pppd idle option and idle_time_hook

    "Chris Nelson" writes:
    > > 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 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

+ Reply to Thread