summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp/bundle.c
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>2000-07-11 22:11:36 +0000
committerbrian <brian@FreeBSD.org>2000-07-11 22:11:36 +0000
commit7bc7c104eeee992d6a92297317b9f35e89e9096c (patch)
treedf8dd7356dce1ca25dbb18c53c87fd96e8dc3265 /usr.sbin/ppp/bundle.c
parenta3d0c189ea25a7af3dfab30112f5d8d65e214e1c (diff)
downloadFreeBSD-src-7bc7c104eeee992d6a92297317b9f35e89e9096c.zip
FreeBSD-src-7bc7c104eeee992d6a92297317b9f35e89e9096c.tar.gz
Allow a ``timeout secs'' filter option to let specific packet types
effect the idle timer in different ways. Submitted by: Stefan Esser <se@freebsd.org> With adjustments by me to document the option in the man page and to give the same semantics for outgoing traffic as incoming. I made the style more consistent in ip.c - this should really have been done as a separate commit.
Diffstat (limited to 'usr.sbin/ppp/bundle.c')
-rw-r--r--usr.sbin/ppp/bundle.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/usr.sbin/ppp/bundle.c b/usr.sbin/ppp/bundle.c
index a1bcbbf..b6ed5ff 100644
--- a/usr.sbin/ppp/bundle.c
+++ b/usr.sbin/ppp/bundle.c
@@ -222,7 +222,7 @@ bundle_LinkAdded(struct bundle *bundle, struct datalink *dl)
if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL))
!= bundle->phys_type.open && bundle->idle.timer.state == TIMER_STOPPED)
/* We may need to start our idle timer */
- bundle_StartIdleTimer(bundle);
+ bundle_StartIdleTimer(bundle, 0);
}
void
@@ -265,7 +265,7 @@ bundle_LayerUp(void *v, struct fsm *fp)
} else if (fp->proto == PROTO_IPCP) {
bundle_CalculateBandwidth(fp->bundle);
time(&bundle->upat);
- bundle_StartIdleTimer(bundle);
+ bundle_StartIdleTimer(bundle, 0);
bundle_Notify(bundle, EX_NORMAL);
mp_CheckAutoloadTimer(&fp->bundle->ncp.mp);
}
@@ -519,6 +519,7 @@ bundle_DescriptorRead(struct fdescriptor *d, struct bundle *bundle,
const fd_set *fdset)
{
struct datalink *dl;
+ unsigned secs;
if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset))
descriptor_Read(&bundle->ncp.mp.server.desc, bundle, fdset);
@@ -561,7 +562,7 @@ bundle_DescriptorRead(struct fdescriptor *d, struct bundle *bundle,
bundle->dev.Name, n);
return;
}
- if (ntohl(tun.family) != AF_INET)
+ if (ntohl(tun.header.family) != AF_INET)
/* XXX: Should be maintaining drop/family counts ! */
return;
}
@@ -570,7 +571,7 @@ bundle_DescriptorRead(struct fdescriptor *d, struct bundle *bundle,
bundle->ncp.ipcp.my_ip.s_addr) {
/* we've been asked to send something addressed *to* us :( */
if (Enabled(bundle, OPT_LOOPBACK)) {
- pri = PacketCheck(bundle, tun.data, n, &bundle->filter.in, NULL);
+ pri = PacketCheck(bundle, tun.data, n, &bundle->filter.in, NULL, NULL);
if (pri >= 0) {
n += sz - sizeof tun.data;
write(bundle->dev.fd, data, n);
@@ -591,7 +592,7 @@ bundle_DescriptorRead(struct fdescriptor *d, struct bundle *bundle,
* Note, we must be in AUTO mode :-/ otherwise our interface should
* *not* be UP and we can't receive data
*/
- pri = PacketCheck(bundle, tun.data, n, &bundle->filter.dial, NULL);
+ pri = PacketCheck(bundle, tun.data, n, &bundle->filter.dial, NULL, NULL);
if (pri >= 0)
bundle_Open(bundle, NULL, PHYS_AUTO, 0);
else
@@ -605,9 +606,13 @@ bundle_DescriptorRead(struct fdescriptor *d, struct bundle *bundle,
return;
}
- pri = PacketCheck(bundle, tun.data, n, &bundle->filter.out, NULL);
- if (pri >= 0)
- ip_Enqueue(&bundle->ncp.ipcp, pri, tun.data, n);
+ secs = 0;
+ pri = PacketCheck(bundle, tun.data, n, &bundle->filter.out, NULL, &secs);
+ if (pri >= 0) {
+ /* Prepend the number of seconds timeout given in the filter */
+ tun.header.timeout = secs;
+ ip_Enqueue(&bundle->ncp.ipcp, pri, (char *)&tun, n + sizeof tun.header);
+ }
}
}
@@ -1246,18 +1251,22 @@ bundle_IdleTimeout(void *v)
* close LCP and link.
*/
void
-bundle_StartIdleTimer(struct bundle *bundle)
+bundle_StartIdleTimer(struct bundle *bundle, unsigned secs)
{
timer_Stop(&bundle->idle.timer);
if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) !=
bundle->phys_type.open && bundle->cfg.idle.timeout) {
- int secs;
+ time_t now = time(NULL);
+
+ if (secs == 0)
+ secs = bundle->cfg.idle.timeout;
- secs = bundle->cfg.idle.timeout;
+ /* We want at least `secs' */
if (bundle->cfg.idle.min_timeout > secs && bundle->upat) {
- int up = time(NULL) - bundle->upat;
+ int up = now - bundle->upat;
if ((long long)bundle->cfg.idle.min_timeout - up > (long long)secs)
+ /* Only increase from the current `remaining' value */
secs = bundle->cfg.idle.min_timeout - up;
}
bundle->idle.timer.func = bundle_IdleTimeout;
@@ -1265,7 +1274,7 @@ bundle_StartIdleTimer(struct bundle *bundle)
bundle->idle.timer.load = secs * SECTICKS;
bundle->idle.timer.arg = bundle;
timer_Start(&bundle->idle.timer);
- bundle->idle.done = time(NULL) + secs;
+ bundle->idle.done = now + secs;
}
}
@@ -1276,7 +1285,7 @@ bundle_SetIdleTimer(struct bundle *bundle, int timeout, int min_timeout)
if (min_timeout >= 0)
bundle->cfg.idle.min_timeout = min_timeout;
if (bundle_LinkIsUp(bundle))
- bundle_StartIdleTimer(bundle);
+ bundle_StartIdleTimer(bundle, 0);
}
void
OpenPOWER on IntegriCloud