From b5c198ae873150ffc54bfd32f6342c37ef7d6636 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 9 Mar 2025 17:08:13 +0100 Subject: [PATCH] l2tplac: fast-forward session that triggered tunnel creation Previously, when we got a call to be forwarded to another LNS and we didn't have a tunnel to it yet, we would wait for a PAP/CHAP re-send to trigger the creation of a session in the fresh tunnel. We do not have to wait, we can trigger that on SCCCN ack. --- l2tplac.c | 6 +++++- l2tpns.c | 7 +++++++ l2tpns.h | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/l2tplac.c b/l2tplac.c index f515d85..2af1570 100644 --- a/l2tplac.c +++ b/l2tplac.c @@ -341,6 +341,8 @@ static int lac_create_tunnelsession(tunnelidt t, sessionidt s, confrlnsidt i_con tunnel[t].window = 4; // default window tunnel[t].isremotelns = i_conf; tunnel[t].indexudp = config->indexlacudpfd; + tunn_local[t].initialsession = s; + strncpy(tunn_local[t].initialuser, puser, sizeof(tunn_local[t].initialuser) - 1); STAT(tunnel_created); random_data(pconfigrlns[i_conf].auth, sizeof(pconfigrlns[i_conf].auth)); @@ -354,7 +356,9 @@ static int lac_create_tunnelsession(tunnelidt t, sessionidt s, confrlnsidt i_con } else { - /** TODO **/ + /** TODO: ideally we would queue all sessions waiting for the tunnel to + * be finished creating, to trigger forwarding them all on SCCCN ack, + * not just the initial one **/ LOG(1, 0, t, "(REMOTE LNS) tunnel is not open\n"); } diff --git a/l2tpns.c b/l2tpns.c index bc215e2..f82fa08 100644 --- a/l2tpns.c +++ b/l2tpns.c @@ -4289,6 +4289,13 @@ void processudp(uint8_t *buf, int len, struct sockaddr_in *addr, uint16_t indexu LOG(3, s, t, "REMOTE LNS acked our SCCCN %d\n", tunn_local[t].scccn); tunn_local[t].scccn = -1; tunnel[t].state = TUNNELOPEN; + + if (tunn_local[t].initialsession) + { + // Forward the call that triggered the tunnel creation + lac_create_session(t, tunn_local[t].initialsession, tunn_local[t].initialuser); + tunn_local[t].initialsession = 0; + } } } if (l) diff --git a/l2tpns.h b/l2tpns.h index d468d22..e182597 100644 --- a/l2tpns.h +++ b/l2tpns.h @@ -520,6 +520,8 @@ typedef struct int32_t scccn; // seq number of last sccn waiting for an ack (-1 if none) controlt *controlr; // queue of OoO-received messages int l2tp_fd; // kernel acceleration UDP socket + sessionidt initialsession; // initial session that triggered creating the tunnel to another LNS + char initialuser[MAXUSER]; // user of initial session } tunnellocalt;