From: Paul Mackerras Date: Wed, 1 May 2024 10:43:58 +0000 (+1000) Subject: plugins/pppoe: Export AC name to scripts via an environment variable X-Git-Tag: v2.5.1~29^2 X-Git-Url: https://git.ozlabs.org/?a=commitdiff_plain;h=c8d842b36e6ded837e6cd66d43cbcff4cf639f38;p=ppp.git plugins/pppoe: Export AC name to scripts via an environment variable This saves the access concentrator (AC) name supplied by the AC in the PADO packet and creates an environment variable called "ACNAME" with the name as its value for scripts to use if desired. This was inspired by a pull request from "bearmi" on github, but reimplemented somewhat differently by me. Signed-off-by: Paul Mackerras --- diff --git a/pppd/plugins/pppoe/discovery.c b/pppd/plugins/pppoe/discovery.c index 4f0b561..c1df4ff 100644 --- a/pppd/plugins/pppoe/discovery.c +++ b/pppd/plugins/pppoe/discovery.c @@ -158,6 +158,10 @@ parsePADOTags(UINT16_t type, UINT16_t len, unsigned char *data, !strncmp((char *) data, conn->acName, len)) { pc->acNameOK = 1; } + /* save a copy of the AC name if we can */ + conn->actualACname = realloc(conn->actualACname, len + 1); + if (conn->actualACname) + strlcpy(conn->actualACname, (char *) data, len + 1); break; case TAG_SERVICE_NAME: pc->seenServiceName = 1; diff --git a/pppd/plugins/pppoe/plugin.c b/pppd/plugins/pppoe/plugin.c index 70dcc50..00e68d5 100644 --- a/pppd/plugins/pppoe/plugin.c +++ b/pppd/plugins/pppoe/plugin.c @@ -254,6 +254,8 @@ PPPOEConnectDevice(void) ppp_set_remote_number(remote_number); ppp_script_setenv("MACREMOTE", remote_number, 0); + if (conn->actualACname) + ppp_script_setenv("ACNAME", conn->actualACname, 0); if (connect(conn->sessionSocket, (struct sockaddr *) &sp, sizeof(struct sockaddr_pppox)) < 0) { @@ -315,6 +317,8 @@ PPPOEDisconnectDevice(void) sendPADT(conn, NULL); close(conn->discoverySocket); } + free(conn->actualACname); + conn->actualACname = NULL; } static void diff --git a/pppd/plugins/pppoe/pppoe.h b/pppd/plugins/pppoe/pppoe.h index 88c3c23..2eb97bd 100644 --- a/pppd/plugins/pppoe/pppoe.h +++ b/pppd/plugins/pppoe/pppoe.h @@ -242,6 +242,7 @@ typedef struct PPPoEConnectionStruct { int storedmru; /* Stored MRU */ int mtu; int mru; + char *actualACname; /* Name of AC we connected to */ } PPPoEConnection; /* Structure used to determine acceptable PADO or PADS packet */ diff --git a/pppd/pppd.8 b/pppd/pppd.8 index 3765041..317549b 100644 --- a/pppd/pppd.8 +++ b/pppd/pppd.8 @@ -1823,6 +1823,11 @@ first WINS server address supplied. .B WINS2 If the peer supplies WINS server addresses, this variable is set to the second WINS server address supplied. +.TP +.B ACNAME +If the pppoe plugin is used to establish a connection to an access +concentrator (AC), this variable is set to the name of the AC, as +supplied by the AC. .P .P Pppd invokes the following scripts, if they exist. It is not an error