X-Git-Url: https://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fplugins%2Frp-pppoe%2Fpppoe.h;h=e2dc2ff9c00260d8437274941db0eb3ee20c7d97;hp=813dcf368cf3369ff48a94db10b5e5b028716175;hb=f1e3aa2dc7e7772d8491c6ff61e4e6d28af33d4b;hpb=5c765a67fd25f9d84e71ed61ace37c8c97f6be15 diff --git a/pppd/plugins/rp-pppoe/pppoe.h b/pppd/plugins/rp-pppoe/pppoe.h index 813dcf3..e2dc2ff 100644 --- a/pppd/plugins/rp-pppoe/pppoe.h +++ b/pppd/plugins/rp-pppoe/pppoe.h @@ -15,12 +15,12 @@ #include "config.h" -#if defined(HAVE_NETPACKET_PACKET_H) || defined(HAVE_LINUX_IF_PACKET_H) -#define _POSIX_SOURCE 1 /* For sigaction defines */ -#endif - #include /* For FILE */ #include /* For pid_t */ +#include +#include + +#include "pppd/pppd.h" /* For error */ /* How do we access raw Ethernet devices? */ #undef USE_LINUX_PACKET @@ -39,10 +39,6 @@ #error Unknown method for accessing raw Ethernet frames #endif -#ifdef HAVE_SYS_CDEFS_H -#include -#endif - #ifdef HAVE_SYS_SOCKET_H #include #endif @@ -86,7 +82,7 @@ typedef unsigned long UINT32_t; #ifdef HAVE_LINUX_IF_ETHER_H #include -#endif +#else #ifdef HAVE_NETINET_IF_ETHER_H #include @@ -98,7 +94,7 @@ typedef unsigned long UINT32_t; #include #endif #endif - +#endif /* Ethernet frame types according to RFC 2516 */ #define ETH_PPPOE_DISCOVERY 0x8863 @@ -236,7 +232,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 +289,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) \