make xl2tpd quit when the connections close

This commit is contained in:
Daniel Barlow 2024-07-08 20:29:48 +01:00
parent 8f0ab5be40
commit 159bfa3057
3 changed files with 62 additions and 2 deletions

View File

@ -44,8 +44,9 @@ let
require authentication = no
pppoptfile = ${writeText "ppp-options" ppp-options'}
autodial = yes
redial = no
max redials = 1
redial = yes
redial timeout = 1
max redials = 2 # this gives 1 actual retry, as xl2tpd can't count
'';
control = "/run/xl2tpd/control-${name}";
in

View File

@ -291,4 +291,8 @@ extraPkgs // {
translateManpages = false;
capabilitiesSupport = false;
};
xl2tpd = prev.xl2tpd.overrideAttrs(o: {
patches = [ ./pkgs/xl2tpd-exit-on-close.patch ];
});
}

View File

@ -0,0 +1,55 @@
diff --git a/xl2tpd.c b/xl2tpd.c
index 791d5a4..1382b68 100644
--- a/xl2tpd.c
+++ b/xl2tpd.c
@@ -814,6 +814,33 @@ static struct call *lac_call (int tid, struct lac *lac, struct lns *lns)
return NULL;
}
+void terminate_if_no_active(void * _unused)
+{
+ l2tp_log (LOG_WARNING, "%s : is anything still happening?\n", __FUNCTION__);
+
+ struct lac *lac = (struct lac *) laclist;
+ while(lac) {
+ l2tp_log (LOG_INFO, "%s : lac %s active %s\n", __FUNCTION__,
+ lac->entname, (lac->active ? "yes" : "no"));
+ if(lac->active)
+ return;
+ lac = lac->next;
+ }
+
+ struct lns *lns = (struct lns *) lnslist;
+ while(lns) {
+ l2tp_log (LOG_INFO, "%s : lns %s active %s\n", __FUNCTION__,
+ lns->entname, (lns->active ? "yes" : "no"));
+ if(lns->active)
+ return;
+ lns = lns->next;
+ }
+
+ l2tp_log (LOG_WARNING, "%s : apparently nothing\n", __FUNCTION__);
+
+ death_handler(SIGTERM);
+}
+
void magic_lac_dial (void *data)
{
struct lac *lac;
@@ -832,7 +859,15 @@ void magic_lac_dial (void *data)
lac->rtries++;
if (lac->rmax && (lac->rtries > lac->rmax))
{
- l2tp_log (LOG_INFO, "%s: maximum retries exceeded.\n", __FUNCTION__);
+ struct timeval tv;
+
+ l2tp_log (LOG_INFO, "%s: maximum retries exceeded %d/%d.\n",
+ __FUNCTION__, lac->rtries , lac->rmax);
+ lac->active = 0;
+ tv.tv_sec = 0;
+ tv.tv_usec = 100;
+ schedule (tv, &terminate_if_no_active, NULL);
+
return;
}
if (!lac->t)