]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/rp-pppoe/pppoe.h
pppoe: Custom host-uniq tag
[ppp.git] / pppd / plugins / rp-pppoe / pppoe.h
index 813dcf368cf3369ff48a94db10b5e5b028716175..b4b309fbeb04ed2c36cd08bf7aa8d0eeed95cb5c 100644 (file)
 
 #include "config.h"
 
-#if defined(HAVE_NETPACKET_PACKET_H) || defined(HAVE_LINUX_IF_PACKET_H)
-#define _POSIX_SOURCE 1 /* For sigaction defines */
-#endif
-
 #include <stdio.h>             /* For FILE */
 #include <sys/types.h>         /* For pid_t */
+#include <ctype.h>
+#include <string.h>
+
+#include "pppd/pppd.h"         /* For error */
 
 /* How do we access raw Ethernet devices? */
 #undef USE_LINUX_PACKET
@@ -236,7 +236,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 */
+    PPPoETag hostUniq;         /* Use Host-Uniq tag */
     int printACNames;          /* Just print AC names */
     FILE *debugFile;           /* Debug file for dumping packets */
     int numPADOs;              /* Number of PADO packets received */
@@ -293,6 +293,32 @@ void pppoe_printpkt(PPPoEPacket *packet,
                    void (*printer)(void *, char *, ...), void *arg);
 void pppoe_log_packet(const char *prefix, PPPoEPacket *packet);
 
+static inline int parseHostUniq(const char *uniq, PPPoETag *tag)
+{
+    unsigned i, len = strlen(uniq);
+
+#define hex(x) \
+    (((x) <= '9') ? ((x) - '0') : \
+        (((x) <= 'F') ? ((x) - 'A' + 10) : \
+            ((x) - 'a' + 10)))
+
+    if (!len || len % 2 || len / 2 > sizeof(tag->payload))
+        return 0;
+
+    for (i = 0; i < len; i += 2) {
+        if (!isxdigit(uniq[i]) || !isxdigit(uniq[i+1]))
+            return 0;
+
+        tag->payload[i / 2] = (char)(hex(uniq[i]) << 4 | hex(uniq[i+1]));
+    }
+
+#undef hex
+
+    tag->type = htons(TAG_HOST_UNIQ);
+    tag->length = htons(len / 2);
+    return 1;
+}
+
 #define SET_STRING(var, val) do { if (var) free(var); var = strDup(val); } while(0);
 
 #define CHECK_ROOM(cursor, start, len) \