[RP-PPPoE] Custom Host-Uniq

Matteo Croce matteo at openwrt.org
Tue Jul 15 09:37:29 EDT 2014


This patch allow to set a custon Host-Uniq PPPoE tag.
This is required for authenticating with some ISPskate

Index: rp-pppoe-3.11/src/discovery.c
===================================================================
--- rp-pppoe-3.11.orig/src/discovery.c 2014-07-15 15:30:16.473209733 +0200
+++ rp-pppoe-3.11/src/discovery.c 2014-07-15 15:30:16.473209733 +0200
@@ -68,12 +68,10 @@ 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;
+    if (type == TAG_HOST_UNIQ && len == strlen(val)) {
+ if (strcmp(data, val)) {
+    *val = 0;
  }
     }
 }
@@ -92,16 +90,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;
 }

 /**********************************************************************
@@ -332,14 +329,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 +557,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 */
Index: rp-pppoe-3.11/src/pppoe.c
===================================================================
--- rp-pppoe-3.11.orig/src/pppoe.c 2014-07-15 15:30:16.473209733 +0200
+++ rp-pppoe-3.11/src/pppoe.c 2014-07-15 15:30:50.901208293 +0200
@@ -369,7 +369,7 @@ usage(char const *argv0)
     "   -A             -- Print access concentrator names and exit.\n"
     "   -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"
+    "   -U unique      -- Use Host-Unique to allow multiple PPPoE sessions.\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 +432,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:U:sm:np:e:kdf:F:t:";
 #else
-    options = "I:VAT:hS:C:Usm:np:e:kdf:F:t:";
+    options = "I:VAT:hS:C:U:sm:np:e:kdf:F:t:";
 #endif
     while((opt = getopt(argc, argv, options)) != -1) {
  switch(opt) {
@@ -522,7 +522,7 @@ main(int argc, char *argv[])
     conn.synchronous = 1;
     break;
  case 'U':
-    conn.useHostUniq = 1;
+    SET_STRING(conn.useHostUniq, optarg);
     break;
 #ifdef DEBUGGING_ENABLED
  case 'D':

-- 
Matteo Croce
OpenWrt Developer


More information about the RP-PPPoE mailing list