Skip to content

Commit

Permalink
plugins/pppoe: Export AC name to scripts via an environment variable
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
paulusmack committed May 16, 2024
1 parent 2cd2d13 commit c8d842b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pppd/plugins/pppoe/discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions pppd/plugins/pppoe/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -315,6 +317,8 @@ PPPOEDisconnectDevice(void)
sendPADT(conn, NULL);
close(conn->discoverySocket);
}
free(conn->actualACname);
conn->actualACname = NULL;
}

static void
Expand Down
1 change: 1 addition & 0 deletions pppd/plugins/pppoe/pppoe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 5 additions & 0 deletions pppd/pppd.8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c8d842b

Please sign in to comment.