Skip to contentSkip to conversation

cosmetic cleanup of the pppoe plugin

PATCH In review Marco d'Itri 1 participant 1 message Aug 19, 2007 PPP protocol drivers and compressors

lore
Share & tools
lore
#0 lore raw

PATCH 12/14 cosmetic cleanup of the pppoe plugin

Removed unnecessary braces, ifdefs, dead code not used by the plugin, custom types and useless casts and switched to the usual pppd logging API. I tried to be conservative in my changes, so there is still some space for improvements and some refactoring.

There are no functionality changes. It tried to take care at not introducing linuxisms, but I do not have a Solaris system to test the code. I suspect that the Solaris DLPI code is bit-rotten anyway, compiling it requires manually adjusting config.h and I doubt that somebody ever bothered to try.

pppd/plugins/rp-pppoe/common.c +14 -14
@@ -18,10 +18,6 @@ static char const RCSID[]  
 #include "pppoe.h"
 
-#ifdef HAVE_SYSLOG_H
-#include <syslog.h>
-#endif
-
 #include <string.h>
 #include <errno.h>
 #include <stdlib.h>
@@ -50,17 +46,17 @@ parsePacket(PPPoEPacket *packet, ParseFu
     UINT16_t tagType, tagLen;
 
     if (packet->ver != 1) {
-	syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
+	error("Invalid PPPoE version (%u)", packet->ver);
 	return -1;
     }
     if (packet->type != 1) {
-	syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
+	error("Invalid PPPoE type (%u)", packet->type);
 	return -1;
     }
 
     /* Do some sanity checks on packet */
     if (len > ETH_DATA_LEN - 6) { /* 6-byte overhead for PPPoE header */
-	syslog(LOG_ERR, "Invalid PPPoE packet length (%u)", len);
+	error("Invalid PPPoE packet length (%u)", len);
 	return -1;
     }
 
@@ -76,7 +72,7 @@ parsePacket(PPPoEPacket *packet, ParseFu
 	    return 0;
 	}
 	if ((curTag - packet->payload) + tagLen + TAG_HDR_SIZE > len) {
-	    syslog(LOG_ERR, "Invalid PPPoE tag length (%u)", tagLen);
+	    error("Invalid PPPoE tag length (%u)", tagLen);
 	    return -1;
 	}
 	func(tagType, tagLen, curTag+TAG_HDR_SIZE, extra);
@@ -105,17 +101,17 @@ findTag(PPPoEPacket *packet, UINT16_t ty
     UINT16_t tagType, tagLen;
 
     if (packet->ver != 1) {
-	syslog(LOG_ERR, "Invalid PPPoE version (%d)", (int) packet->ver);
+	error("Invalid PPPoE version (%u)", packet->ver);
 	return NULL;
     }
     if (packet->type != 1) {
-	syslog(LOG_ERR, "Invalid PPPoE type (%d)", (int) packet->type);
+	error("Invalid PPPoE type (%u)", packet->type);
 	return NULL;
     }
 
     /* Do some sanity checks on packet */
     if (len > ETH_DATA_LEN - 6) { /* 6-byte overhead for PPPoE header */
-	syslog(LOG_ERR, "Invalid PPPoE packet length (%u)", len);
+	error("Invalid PPPoE packet length (%u)", len);
 	return NULL;
     }
 
@@ -131,7 +127,7 @@ findTag(PPPoEPacket *packet, UINT16_t ty
 	    return NULL;
 	}
 	if ((curTag - packet->payload) + tagLen + TAG_HDR_SIZE > len) {
-	    syslog(LOG_ERR, "Invalid PPPoE tag length (%u)", tagLen);
+	    error("Invalid PPPoE tag length (%u)", tagLen);
 	    return NULL;
 	}
 	if (tagType = type) {
@@ -143,6 +139,7 @@ findTag(PPPoEPacket *packet, UINT16_t ty
     return NULL;
 }
 
+#ifdef unused
 /**********************************************************************
 *%FUNCTION: printErr
 *%ARGUMENTS:
@@ -158,6 +155,7 @@ printErr(char const *str)
     fprintf(stderr, "pppoe: %s\n", str);
     syslog(LOG_ERR, "%s", str);
 }
+#endif
 
 
 /**********************************************************************
@@ -172,7 +170,7 @@ strDup(char const *str)
 {
     char *copy = malloc(strlen(str)+1);
     if (!copy) {
-	rp_fatal("strdup failed");
+	fatal("strdup failed");
     }
     strcpy(copy, str);
     return copy;
@@ -467,9 +465,10 @@ sendPADT(PPPoEConnection *conn, char con
 	fprintf(conn->debugFile, "\n");
 	fflush(conn->debugFile);
     }
-    syslog(LOG_INFO,"Sent PADT");
+    info("Sent PADT");
 }
 
+#ifdef unused
 /**********************************************************************
 *%FUNCTION: parseLogErrs
 *%ARGUMENTS:
@@ -501,4 +500,5 @@ parseLogErrs(UINT16_t type, UINT16_t len
 	break;
     }
 }
+#endif
 
pppd/plugins/rp-pppoe/discovery.c +18 -32

135 lines not on this page · raw message

pppd/plugins/rp-pppoe/if.c +75 -132

537 lines not on this page · raw message

pppd/plugins/rp-pppoe/Makefile.linux +2 -2
@@ -28,8 +28,8 @@ COPTS=-O2 -g
 CFLAGS=$(COPTS) -I../../../include/linux
 all: rp-pppoe.so pppoe-discovery
 
-pppoe-discovery: libplugin.a pppoe-discovery.o
-	$(CC) -o pppoe-discovery pppoe-discovery.o libplugin.a
+pppoe-discovery: pppoe-discovery.o utils.o libplugin.a
+	$(CC) -o pppoe-discovery pppoe-discovery.o utils.o libplugin.a
 
 pppoe-discovery.o: pppoe-discovery.c
 	$(CC) $(CFLAGS) '-DVERSION="$(VERSION)"' -c -o pppoe-discovery.o pppoe-discovery.c
pppd/plugins/rp-pppoe/plugin.c +3 -7
@@ -35,7 +35,6 @@ static char const RCSID[]  #include "pppd/pathnames.h"
 
 #include <linux/types.h>
-#include <syslog.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -173,10 +172,8 @@ PPPOEConnectDevice(void)
 	    (unsigned) conn->peerEth[5]);
 
     if (connect(conn->sessionSocket, (struct sockaddr *) &sp,
-		sizeof(struct sockaddr_pppox)) < 0) {
+		sizeof(struct sockaddr_pppox)) < 0)
 	fatal("Failed to connect PPPoE socket: %d %m", errno);
-	return -1;
-    }
 
     return conn->sessionSocket;
 }
@@ -320,11 +317,9 @@ plugin_init(void)
     }
 
     add_options(Options);
-
-    info("RP-PPPoE plugin version %s compiled against pppd %s",
-	 RP_VERSION, VERSION);
 }
 
+#ifdef unused
 /**********************************************************************
 *%FUNCTION: fatalSys
 *%ARGUMENTS:
@@ -378,6 +373,7 @@ sysErr(char const *str)
 {
     rp_fatal(str);
 }
+#endif
 
 void pppoe_check_options(void)
 {
pppd/plugins/rp-pppoe/pppoe-discovery.c +5 -44

89 lines not on this page · raw message

pppd/plugins/rp-pppoe/pppoe.h +7 -1
@@ -307,12 +307,18 @@ void discovery(PPPoEConnection *conn);
 unsigned char *findTag(PPPoEPacket *packet, UINT16_t tagType,
 		       PPPoETag *tag);
 
+void dbglog(char *, ...);	/* log a debug message */
+void info(char *, ...);		/* log an informational message */
+void warn(char *, ...);		/* log a warning message */
+void error(char *, ...);	/* log an error message */
+void fatal(char *, ...);	/* log an error message and die(1) */
+
 #define SET_STRING(var, val) do { if (var) free(var); var = strDup(val); } while(0);
 
 #define CHECK_ROOM(cursor, start, len) \
 do {\
     if (((cursor)-(start))+(len) > MAX_PPPOE_PAYLOAD) { \
-        syslog(LOG_ERR, "Would create too-long packet"); \
+        error("Would create too-long packet"); \
         return; \
     } \
 } while(0)
pppd/plugins/rp-pppoe/utils.c new file +62 -0

62 lines not on this page · raw message

Signature · 2 lines
ciao,
Marco