From 35033fb1a91b7e78ee538c50304b14eedca6ff33 Mon Sep 17 00:00:00 2001 From: Jaco Kroon Date: Tue, 18 Oct 2022 12:46:11 +0200 Subject: [PATCH] Pass remotenumber to pppd. Use the IP address if no remote number is available, or we're on the LNS side and we don't trust the remote side (default) to provide the correct AVP. Signed-off-by: Jaco Kroon --- file.c | 17 +++++++++++++++++ file.h | 1 + xl2tpd.c | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/file.c b/file.c index 17dc3775..29fcb668 100644 --- a/file.c +++ b/file.c @@ -676,6 +676,22 @@ int set_pass_peer (char *word, char *value, int context, void *item) return 0; } +int set_trust_remotenumber (char *word, char *value, int context, void *item) +{ + switch (context & ~CONTEXT_DEFAULT) + { + case CONTEXT_LNS: + if (set_boolean (word, value, &(((struct lns *) item)->trust_remotenumber))) + return -1; + break; + default: + snprintf (filerr, sizeof (filerr), "'%s' not valid in this context\n", + word); + return -1; + } + return 0; +} + int set_pppoptfile (char *word, char *value, int context, void *item) { struct lac *l = (struct lac *) item; @@ -1611,6 +1627,7 @@ struct keyword words[] = { {"hostname", &set_hostname}, {"ppp debug", &set_debug}, {"pass peer", &set_pass_peer}, + {"trust remotenumber", &set_trust_remotenumber}, {"pppoptfile", &set_pppoptfile}, {"call rws", &set_rws}, {"tunnel rws", &set_rws}, diff --git a/file.h b/file.h index a2707c2d..9d763593 100644 --- a/file.h +++ b/file.h @@ -97,6 +97,7 @@ struct lns int proxyauth; /* Allow proxy authentication? */ int debug; /* Debug PPP? */ int pass_peer; /* Pass peer IP to pppd as ipparam? */ + int trust_remotenumber; /* Whether or not to trust remotely supplied "Dialing Number" AVP */ char pppoptfile[STRLEN]; /* File containing PPP options */ struct tunnel *t; /* Tunnel of this, if it's ready */ }; diff --git a/xl2tpd.c b/xl2tpd.c index 3195988a..b551146d 100644 --- a/xl2tpd.c +++ b/xl2tpd.c @@ -495,6 +495,14 @@ int start_pppd (struct call *c, struct ppp_opts *opts) } { + stropt[pos++] = strdup("remotenumber"); + if (c->dialing[0] && (!c->lns || c->lns->trust_remotenumber)) { + /* if a remotenumber is available, and we're a LAC or the remote "dialing number" AVP is trusted */ + stropt[pos++] = strdup(c->dialing); + } else { + stropt[pos++] = strdup(IPADDY(c->container->peer.sin_addr)); + } + struct ppp_opts *p = opts; int maxn_opts = sizeof(stropt) / sizeof(stropt[0]) - 1; while (p && pos < maxn_opts)