[RP-PPPoE] Custom Host-Uniq v2
Matteo Croce
technoboy85 at gmail.com
Mon Jul 21 09:26:34 EDT 2014
This patch allow to set a custon Host-Uniq PPPoE tag via the -W option
This is required for authenticating with some ISPs.
--- a/src/common.c
+++ b/src/common.c
@@ -517,13 +517,13 @@ sendPADT(PPPoEConnection *conn, char con
/* If we're using Host-Uniq, copy it over */
if (conn->useHostUniq) {
PPPoETag hostUniq;
- pid_t pid = getpid();
+ int len = strlen(conn->useHostUniq);
hostUniq.type = htons(TAG_HOST_UNIQ);
- hostUniq.length = htons(sizeof(pid));
- memcpy(hostUniq.payload, &pid, sizeof(pid));
- memcpy(cursor, &hostUniq, sizeof(pid) + TAG_HDR_SIZE);
- cursor += sizeof(pid) + TAG_HDR_SIZE;
- plen += sizeof(pid) + TAG_HDR_SIZE;
+ hostUniq.length = htons(len);
+ memcpy(hostUniq.payload, conn->useHostUniq, len);
+ memcpy(cursor, &hostUniq, len + TAG_HDR_SIZE);
+ cursor += len + TAG_HDR_SIZE;
+ plen += len + TAG_HDR_SIZE;
}
/* Copy error message */
--- a/src/discovery.c
+++ b/src/discovery.c
@@ -68,12 +68,11 @@ static void
parseForHostUniq(UINT16_t type, UINT16_t len, unsigned char *data,
void *extra)
{
- int *val = (int *) extra;
- if (type == TAG_HOST_UNIQ && len == sizeof(pid_t)) {
- pid_t tmp;
- memcpy(&tmp, data, len);
- if (tmp == getpid()) {
- *val = 1;
+ char **val = (char **) extra;
+ char *uniq = *val;
+ if (type == TAG_HOST_UNIQ && len == strlen((char *)uniq)) {
+ if (strncmp((char *)data, uniq, len)) {
+ *val = 0;
}
}
}
@@ -92,16 +91,15 @@ parseForHostUniq(UINT16_t type, UINT16_t
static int
packetIsForMe(PPPoEConnection *conn, PPPoEPacket *packet)
{
- int forMe = 0;
-
+ char *uniq = conn->useHostUniq;
/* If packet is not directed to our MAC address, forget it */
if (memcmp(packet->ethHdr.h_dest, conn->myEth, ETH_ALEN)) return 0;
/* If we're not using the Host-Unique tag, then accept the packet */
if (!conn->useHostUniq) return 1;
- parsePacket(packet, parseForHostUniq, &forMe);
- return forMe;
+ parsePacket(packet, parseForHostUniq, &uniq);
+ return uniq != 0;
}
/**********************************************************************
@@ -332,14 +330,14 @@ sendPADI(PPPoEConnection *conn)
/* If we're using Host-Uniq, copy it over */
if (conn->useHostUniq) {
PPPoETag hostUniq;
- pid_t pid = getpid();
+ int len = strlen(conn->useHostUniq);
hostUniq.type = htons(TAG_HOST_UNIQ);
- hostUniq.length = htons(sizeof(pid));
- memcpy(hostUniq.payload, &pid, sizeof(pid));
- CHECK_ROOM(cursor, packet.payload, sizeof(pid) + TAG_HDR_SIZE);
- memcpy(cursor, &hostUniq, sizeof(pid) + TAG_HDR_SIZE);
- cursor += sizeof(pid) + TAG_HDR_SIZE;
- plen += sizeof(pid) + TAG_HDR_SIZE;
+ hostUniq.length = htons(len);
+ memcpy(hostUniq.payload, conn->useHostUniq, len);
+ CHECK_ROOM(cursor, packet.payload, len + TAG_HDR_SIZE);
+ memcpy(cursor, &hostUniq, len + TAG_HDR_SIZE);
+ cursor += len + TAG_HDR_SIZE;
+ plen += len + TAG_HDR_SIZE;
}
#ifdef PLUGIN
@@ -560,14 +558,14 @@ sendPADR(PPPoEConnection *conn)
/* If we're using Host-Uniq, copy it over */
if (conn->useHostUniq) {
PPPoETag hostUniq;
- pid_t pid = getpid();
+ int len = strlen(conn->useHostUniq);
hostUniq.type = htons(TAG_HOST_UNIQ);
- hostUniq.length = htons(sizeof(pid));
- memcpy(hostUniq.payload, &pid, sizeof(pid));
- CHECK_ROOM(cursor, packet.payload, sizeof(pid)+TAG_HDR_SIZE);
- memcpy(cursor, &hostUniq, sizeof(pid) + TAG_HDR_SIZE);
- cursor += sizeof(pid) + TAG_HDR_SIZE;
- plen += sizeof(pid) + TAG_HDR_SIZE;
+ hostUniq.length = htons(len);
+ memcpy(hostUniq.payload, conn->useHostUniq, len);
+ CHECK_ROOM(cursor, packet.payload, len+TAG_HDR_SIZE);
+ memcpy(cursor, &hostUniq, len + TAG_HDR_SIZE);
+ cursor += len + TAG_HDR_SIZE;
+ plen += len + TAG_HDR_SIZE;
}
/* Copy cookie and relay-ID if needed */
--- a/src/pppoe.c
+++ b/src/pppoe.c
@@ -48,6 +48,7 @@ static char const RCSID[] =
#endif
#include <signal.h>
+#include <stdio.h>
#ifdef HAVE_N_HDLC
#ifndef N_HDLC
@@ -370,6 +371,7 @@ usage(char const *argv0)
" -S name -- Set desired service name.\n"
" -C name -- Set desired access concentrator name.\n"
" -U -- Use Host-Unique to allow multiple PPPoE sessions.\n"
+ " -W unique -- Use custom Host-Unique for this PPPoE session.\n"
" -s -- Use synchronous PPP encapsulation.\n"
" -m MSS -- Clamp incoming and outgoing MSS options.\n"
" -p pidfile -- Write process-ID to pidfile.\n"
@@ -432,9 +434,9 @@ main(int argc, char *argv[])
openlog("pppoe", LOG_PID, LOG_DAEMON);
#ifdef DEBUGGING_ENABLED
- options = "I:VAT:D:hS:C:Usm:np:e:kdf:F:t:";
+ options = "I:VAT:D:hS:C:UW:sm:np:e:kdf:F:t:";
#else
- options = "I:VAT:hS:C:Usm:np:e:kdf:F:t:";
+ options = "I:VAT:hS:C:UW:sm:np:e:kdf:F:t:";
#endif
while((opt = getopt(argc, argv, options)) != -1) {
switch(opt) {
@@ -522,7 +524,19 @@ main(int argc, char *argv[])
conn.synchronous = 1;
break;
case 'U':
- conn.useHostUniq = 1;
+ if(conn.useHostUniq) {
+ fprintf(stderr, "-U and -W are mutually exclusive\n");
+ exit(EXIT_FAILURE);
+ }
+ conn.useHostUniq = malloc(10);
+ sprintf(conn.useHostUniq, "%d", getpid());
+ break;
+ case 'W':
+ if(conn.useHostUniq) {
+ fprintf(stderr, "-U and -W are mutually exclusive\n");
+ exit(EXIT_FAILURE);
+ }
+ SET_STRING(conn.useHostUniq, optarg);
break;
#ifdef DEBUGGING_ENABLED
case 'D':
--- a/src/pppoe.h
+++ b/src/pppoe.h
@@ -290,7 +290,7 @@ typedef struct PPPoEConnectionStruct {
char *serviceName; /* Desired service name, if any */
char *acName; /* Desired AC name, if any */
int synchronous; /* Use synchronous PPP */
- int useHostUniq; /* Use Host-Uniq tag */
+ char *useHostUniq; /* Use Host-Uniq tag */
int printACNames; /* Just print AC names */
int skipDiscovery; /* Skip discovery */
int noDiscoverySocket; /* Don't even open discovery socket */
--
Matteo Croce
OpenWrt Developer
More information about the RP-PPPoE
mailing list