diff --git a/sys/conf/files b/sys/conf/files index c1a89e1362c7..e6f80aef4785 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $NetBSD: files,v 1.1281 2021/05/14 08:31:14 yamaguchi Exp $ +# $NetBSD: files,v 1.1282 2021/05/14 08:41:25 yamaguchi Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 version 20171118 @@ -292,6 +292,7 @@ defflag opt_pppoe.h PPPOE_SERVER PPPOE_DEBUG defparam opt_sppp.h SPPP_KEEPALIVE_INTERVAL SPPP_NORECV_TIME + SPPP_ALIVE_INTERVAL # networking options # diff --git a/sys/net/if_sppp.h b/sys/net/if_sppp.h index 322b68254333..72efe640b675 100644 --- a/sys/net/if_sppp.h +++ b/sys/net/if_sppp.h @@ -1,4 +1,4 @@ -/* $NetBSD: if_sppp.h,v 1.35 2021/05/11 06:42:42 yamaguchi Exp $ */ +/* $NetBSD: if_sppp.h,v 1.36 2021/05/14 08:41:25 yamaguchi Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -153,6 +153,7 @@ struct spppkeepalivesettings { u_int maxalive; /* number of LCP echo req. w/o reply */ time_t max_noreceive; /* (sec.) grace period before we start sending LCP echo requests. */ + u_int alive_interval; /* number of keepalive between echo req. */ }; struct spppkeepalivesettings50 { char ifname[IFNAMSIZ]; /* pppoe interface name */ diff --git a/sys/net/if_spppsubr.c b/sys/net/if_spppsubr.c index eecf5f293cec..04c78b39f66e 100644 --- a/sys/net/if_spppsubr.c +++ b/sys/net/if_spppsubr.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_spppsubr.c,v 1.240 2021/05/14 08:31:14 yamaguchi Exp $ */ +/* $NetBSD: if_spppsubr.c,v 1.241 2021/05/14 08:41:25 yamaguchi Exp $ */ /* * Synchronous PPP/Cisco link level subroutines. @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.240 2021/05/14 08:31:14 yamaguchi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.241 2021/05/14 08:41:25 yamaguchi Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" @@ -98,6 +98,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.240 2021/05/14 08:31:14 yamaguchi #endif #define DEFAULT_KEEPALIVE_INTERVAL 10 /* seconds between checks */ +#define DEFAULT_ALIVE_INTERVAL 1 /* count of sppp_keepalive */ #define LOOPALIVECNT 3 /* loopback detection tries */ #define DEFAULT_MAXALIVECNT 3 /* max. missed alive packets */ #define DEFAULT_NORECV_TIME 15 /* before we get worried */ @@ -111,6 +112,10 @@ __KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.240 2021/05/14 08:31:14 yamaguchi #define SPPP_NORECV_TIME DEFAULT_NORECV_TIME #endif +#ifndef SPPP_ALIVE_INTERVAL +#define SPPP_ALIVE_INTERVAL DEFAULT_ALIVE_INTERVAL +#endif + /* * Interface flags that can be set in an ifconfig command. * @@ -289,6 +294,7 @@ enum auth_role { static struct sppp *spppq; static kmutex_t *spppq_lock = NULL; static callout_t keepalive_ch; +static unsigned int sppp_keepalive_cnt = 0; #define SPPPQ_LOCK() if (spppq_lock) \ mutex_enter(spppq_lock); @@ -1102,6 +1108,7 @@ sppp_attach(struct ifnet *ifp) sp->pp_cpq.ifq_maxlen = 20; sp->pp_loopcnt = 0; sp->pp_alivecnt = 0; + sp->pp_alive_interval = SPPP_ALIVE_INTERVAL; sp->pp_last_activity = 0; sp->pp_last_receive = 0; sp->pp_maxalive = DEFAULT_MAXALIVECNT; @@ -5637,6 +5644,18 @@ sppp_keepalive(void *dummy) continue; } + /* No echo request */ + if (sp->pp_alive_interval == 0) { + SPPP_UNLOCK(sp); + continue; + } + + /* send a ECHO_REQ once in sp->pp_alive_interval times */ + if ((sppp_keepalive_cnt % sp->pp_alive_interval) != 0) { + SPPP_UNLOCK(sp); + continue; + } + if (sp->pp_alivecnt >= sp->pp_maxalive) { /* No keepalive packets got. Stop the interface. */ sppp_wq_add(sp->wq_cp, &sp->work_ifdown); @@ -5671,6 +5690,7 @@ sppp_keepalive(void *dummy) SPPP_UNLOCK(sp); } splx(s); + sppp_keepalive_cnt++; callout_reset(&keepalive_ch, hz * SPPP_KEEPALIVE_INTERVAL, sppp_keepalive, NULL); SPPPQ_UNLOCK(); @@ -6318,6 +6338,7 @@ sppp_params(struct sppp *sp, u_long cmd, void *data) SPPP_LOCK(sp, RW_READER); settings->maxalive = sp->pp_maxalive; settings->max_noreceive = sp->pp_max_noreceive; + settings->alive_interval = sp->pp_alive_interval; SPPP_UNLOCK(sp); } break; @@ -6329,6 +6350,7 @@ sppp_params(struct sppp *sp, u_long cmd, void *data) SPPP_LOCK(sp, RW_WRITER); sp->pp_maxalive = settings->maxalive; sp->pp_max_noreceive = settings->max_noreceive; + sp->pp_alive_interval = settings->alive_interval; SPPP_UNLOCK(sp); } break; diff --git a/sys/net/if_spppvar.h b/sys/net/if_spppvar.h index 7663a1083338..ec460a6d19e9 100644 --- a/sys/net/if_spppvar.h +++ b/sys/net/if_spppvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: if_spppvar.h,v 1.37 2021/05/11 01:27:45 yamaguchi Exp $ */ +/* $NetBSD: if_spppvar.h,v 1.38 2021/05/14 08:41:25 yamaguchi Exp $ */ #ifndef _NET_IF_SPPPVAR_H_ #define _NET_IF_SPPPVAR_H_ @@ -144,6 +144,7 @@ struct sppp { u_int pp_ncpflags; /* enable or disable each NCP */ u_int pp_framebytes; /* number of bytes added by (hardware) framing */ u_int pp_alivecnt; /* keepalive packets counter */ + u_int pp_alive_interval; /* keepalive interval */ u_int pp_loopcnt; /* loopback detection counter */ u_int pp_maxalive; /* number or echo req. w/o reply */ uint64_t pp_saved_mtu; /* saved MTU value */