Advertisement
teknoraver

Host-Uniq

Jul 15th, 2014
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.06 KB | None | 0 0
  1. --- a/src/discovery.c   2014-07-13 15:39:25.618377527 +0200
  2. +++ b/src/discovery.c   2014-07-13 16:33:49.661124198 +0200
  3. @@ -61,12 +61,10 @@
  4.  parseForHostUniq(UINT16_t type, UINT16_t len, unsigned char *data,
  5.          void *extra)
  6.  {
  7. -    int *val = (int *) extra;
  8. -    if (type == TAG_HOST_UNIQ && len == sizeof(pid_t)) {
  9. -   pid_t tmp;
  10. -   memcpy(&tmp, data, len);
  11. -   if (tmp == getpid()) {
  12. -       *val = 1;
  13. +    char *val = (char *) extra;
  14. +    if (type == TAG_HOST_UNIQ && len == strlen(val)) {
  15. +   if (strcmp(data, val)) {
  16. +       *val = 0;
  17.     }
  18.      }
  19.  }
  20. @@ -85,16 +83,15 @@
  21.  static int
  22.  packetIsForMe(PPPoEConnection *conn, PPPoEPacket *packet)
  23.  {
  24. -    int forMe = 0;
  25. -
  26. +    char uniq = conn->useHostUniq;
  27.      /* If packet is not directed to our MAC address, forget it */
  28.      if (memcmp(packet->ethHdr.h_dest, conn->myEth, ETH_ALEN)) return 0;
  29.  
  30.      /* If we're not using the Host-Unique tag, then accept the packet */
  31.      if (!conn->useHostUniq) return 1;
  32.  
  33. -    parsePacket(packet, parseForHostUniq, &forMe);
  34. -    return forMe;
  35. +    parsePacket(packet, parseForHostUniq, uniq);
  36. +    return uniq;
  37.  }
  38.  
  39.  /**********************************************************************
  40. @@ -284,14 +281,14 @@
  41.      /* If we're using Host-Uniq, copy it over */
  42.      if (conn->useHostUniq) {
  43.     PPPoETag hostUniq;
  44. -   pid_t pid = getpid();
  45. +   int len = strlen(conn->useHostUniq);
  46.     hostUniq.type = htons(TAG_HOST_UNIQ);
  47. -   hostUniq.length = htons(sizeof(pid));
  48. -   memcpy(hostUniq.payload, &pid, sizeof(pid));
  49. -   CHECK_ROOM(cursor, packet.payload, sizeof(pid) + TAG_HDR_SIZE);
  50. -   memcpy(cursor, &hostUniq, sizeof(pid) + TAG_HDR_SIZE);
  51. -   cursor += sizeof(pid) + TAG_HDR_SIZE;
  52. -   plen += sizeof(pid) + TAG_HDR_SIZE;
  53. +   hostUniq.length = htons(len);
  54. +   memcpy(hostUniq.payload, conn->useHostUniq, len);
  55. +   CHECK_ROOM(cursor, packet.payload, len + TAG_HDR_SIZE);
  56. +   memcpy(cursor, &hostUniq, len + TAG_HDR_SIZE);
  57. +   cursor += len + TAG_HDR_SIZE;
  58. +   plen += len + TAG_HDR_SIZE;
  59.      }
  60.  
  61.      packet.length = htons(plen);
  62. @@ -454,14 +451,14 @@
  63.      /* If we're using Host-Uniq, copy it over */
  64.      if (conn->useHostUniq) {
  65.     PPPoETag hostUniq;
  66. -   pid_t pid = getpid();
  67. +   int len = strlen(conn->useHostUniq);
  68.     hostUniq.type = htons(TAG_HOST_UNIQ);
  69. -   hostUniq.length = htons(sizeof(pid));
  70. -   memcpy(hostUniq.payload, &pid, sizeof(pid));
  71. -   CHECK_ROOM(cursor, packet.payload, sizeof(pid)+TAG_HDR_SIZE);
  72. -   memcpy(cursor, &hostUniq, sizeof(pid) + TAG_HDR_SIZE);
  73. -   cursor += sizeof(pid) + TAG_HDR_SIZE;
  74. -   plen += sizeof(pid) + TAG_HDR_SIZE;
  75. +   hostUniq.length = htons(len);
  76. +   memcpy(hostUniq.payload, &conn->useHostUniq, len);
  77. +   CHECK_ROOM(cursor, packet.payload, len+TAG_HDR_SIZE);
  78. +   memcpy(cursor, &hostUniq, len + TAG_HDR_SIZE);
  79. +   cursor += len + TAG_HDR_SIZE;
  80. +   plen += len + TAG_HDR_SIZE;
  81.      }
  82.  
  83.      /* Copy cookie and relay-ID if needed */
  84. --- a/src/pppoe.c   2014-07-13 15:28:11.000000000 +0200
  85. +++ b/src/pppoe.c   2014-07-13 15:45:34.774387413 +0200
  86. @@ -415,7 +415,7 @@
  87.         "   -A             -- Print access concentrator names and exit.\n"
  88.         "   -S name        -- Set desired service name.\n"
  89.         "   -C name        -- Set desired access concentrator name.\n"
  90. -       "   -U             -- Use Host-Unique to allow multiple PPPoE sessions.\n"
  91. +       "   -U unique      -- Use Host-Unique to allow multiple PPPoE sessions.\n"
  92.         "   -s             -- Use synchronous PPP encapsulation.\n"
  93.         "   -m MSS         -- Clamp incoming and outgoing MSS options.\n"
  94.         "   -p pidfile     -- Write process-ID to pidfile.\n"
  95. @@ -479,9 +479,9 @@
  96.  
  97.      char const *options;
  98.  #ifdef DEBUGGING_ENABLED
  99. -    options = "I:VAT:D:hS:C:Usm:np:e:kdf:F:t:H:";
  100. +    options = "I:VAT:D:hS:C:U:sm:np:e:kdf:F:t:H:";
  101.  #else
  102. -    options = "I:VAT:hS:C:Usm:np:e:kdf:F:t:H:";
  103. +    options = "I:VAT:hS:C:U:sm:np:e:kdf:F:t:H:";
  104.  #endif
  105.      while((opt = getopt(argc, argv, options)) != -1) {
  106.     switch(opt) {
  107. @@ -581,7 +581,7 @@
  108.         conn.synchronous = 1;
  109.         break;
  110.     case 'U':
  111. -       conn.useHostUniq = 1;
  112. +       SET_STRING(conn.useHostUniq, optarg);
  113.         break;
  114.  #ifdef DEBUGGING_ENABLED
  115.     case 'D':
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement