]> git.ozlabs.org Git - ppp.git/commitdiff
pppoe: Dump discovery packets when pppoe-verbose option is set to >= 2
authorPali Rohár <pali@kernel.org>
Fri, 1 Jan 2021 15:38:03 +0000 (16:38 +0100)
committerPali Rohár <pali@kernel.org>
Mon, 4 Jan 2021 23:43:57 +0000 (00:43 +0100)
Signed-off-by: Pali Rohár <pali@kernel.org>
pppd/plugins/pppoe/common.c
pppd/pppd.8

index 9ea7fd609c8774aafbaf2cbe9bb6a6d86679b516..9140ea90cbee2d8d2cda656157f8505b09ae8910 100644 (file)
@@ -160,6 +160,42 @@ sendPADT(PPPoEConnection *conn, char const *msg)
     info("Sent PADT");
 }
 
+static void
+pppoe_printpkt_hex(void (*printer)(void *, char *, ...), void *arg, unsigned char const *buf, int len)
+{
+    int i;
+    int base;
+
+    /* do NOT dump PAP packets */
+    if (len >= 2 && buf[0] == 0xC0 && buf[1] == 0x23) {
+       printer(arg, "(PAP Authentication Frame -- Contents not dumped)\n");
+       return;
+    }
+
+    for (base=0; base<len; base += 16) {
+       for (i=base; i<base+16; i++) {
+           if (i < len) {
+               printer(arg, "%02x ", (unsigned) buf[i]);
+           } else {
+               printer(arg, "   ");
+           }
+       }
+       printer(arg, "  ");
+       for (i=base; i<base+16; i++) {
+           if (i < len) {
+               if (isprint(buf[i])) {
+                   printer(arg, "%c", buf[i]);
+               } else {
+                   printer(arg, ".");
+               }
+           } else {
+               break;
+           }
+       }
+       printer(arg, "\n");
+    }
+}
+
 #define EH(x)  (x)[0], (x)[1], (x)[2], (x)[3], (x)[4], (x)[5]
 
 /* Print out a PPPOE packet for debugging */
@@ -207,6 +243,8 @@ void pppoe_printpkt(PPPoEPacket *packet,
 
     printer(arg, " dst %02x:%02x:%02x:%02x:%02x:%02x ", EH(packet->ethHdr.h_dest));
     printer(arg, " src %02x:%02x:%02x:%02x:%02x:%02x\n", EH(packet->ethHdr.h_source));
+    if (pppoe_verbose >= 2)
+       pppoe_printpkt_hex(printer, arg, packet->payload, ntohs(packet->length));
     if (ntohs(packet->ethHdr.h_proto) != ETH_PPPOE_DISCOVERY)
        return;
 
index 36156d6ea9d6da4c2380f719e731728c6311cccf..cbbcb45d812145186c9ed1f5c618471b96e348f6 100644 (file)
@@ -1243,8 +1243,9 @@ Attach to existing PPPoE session. For backward compatibility also
 \fBrp_pppoe_sess\fP option name is supported.
 .TP
 .B pppoe-verbose \fIn
-Be verbose about discovered access concentrators. For backward
-compatibility also \fBrp_pppoe_verbose\fP option name is supported.
+Be verbose about discovered access concentrators. When set to 2 or bigger
+value then dump also discovery packets. For backward compatibility also
+\fBrp_pppoe_verbose\fP option name is supported.
 .TP
 .B pppoe-mac \fImacaddr
 Connect to specified MAC address.