]> git.ozlabs.org Git - ppp.git/commitdiff
plugins/pppoe: Export AC name to scripts via an environment variable
authorPaul Mackerras <paulus@ozlabs.org>
Wed, 1 May 2024 10:43:58 +0000 (20:43 +1000)
committerPaul Mackerras <paulus@ozlabs.org>
Thu, 16 May 2024 10:31:41 +0000 (20:31 +1000)
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 <paulus@ozlabs.org>
pppd/plugins/pppoe/discovery.c
pppd/plugins/pppoe/plugin.c
pppd/plugins/pppoe/pppoe.h
pppd/pppd.8

index 4f0b561593b1a34a2468e54314c5f4547c1d38f7..c1df4ffad99b7c93265da9b1e41376bcccf36020 100644 (file)
@@ -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;
index 70dcc50adf4445aeba43b836141ed76ab72b3916..00e68d54ab9975699a58cbb80a3406a324c05317 100644 (file)
@@ -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
index 88c3c233a4987b597b283944d12a6e89baaecc7d..2eb97bd1c4755648e938aa4186d760d3f022dd04 100644 (file)
@@ -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 */
index 376504188f4750d4df52ce26a0cf41dbe14ff1b8..317549b2084f2a76eef805412b9c52dfe46d628a 100644 (file)
@@ -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