Ethereal-dev: [ethereal-dev] Diameter (using new prefs.c)

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: David Frascone <dave@xxxxxxxxxxxx>
Date: Sun, 9 Jul 2000 17:38:28 -0500
Ok, attached is a tarball containing the diffs and two new files.  I'm also
attaching the diffs in text to this message.  This is a change to the diameter
code I posted last week.  The main difference is that it now uses the prefs
dialog box to change ports.

There are two new tabs in the preferences, one for diameter, and one for 
Radius.  We might want to instead register the preference tab in the UDP
package, and make the handle global.  That way, the diameter, radius, and
other protocols can register to allow their ports tuned in only one spot . . .

Let me know what you think.

Dave


---------------------cut here------------------------

? packet-diameter.c
? packet-diameter.h
? diameter-dict2h.pl
? nohup.out
? old.conf
? ethereal.conf
Index: Makefile.am
===================================================================
RCS file: /cvsroot/ethereal/Makefile.am,v
retrieving revision 1.208
diff -u -r1.208 Makefile.am
--- Makefile.am	2000/07/06 10:03:41	1.208
+++ Makefile.am	2000/07/09 22:28:34
@@ -51,6 +51,7 @@
 	packet-cops.c  \
 	packet-data.c  \
 	packet-ddtp.c  \
+	packet-diameter.c \
 	packet-dns.c   \
 	packet-eigrp.c \
 	packet-esis.c  \
Index: Makefile.nmake
===================================================================
RCS file: /cvsroot/ethereal/Makefile.nmake,v
retrieving revision 1.45
diff -u -r1.45 Makefile.nmake
--- Makefile.nmake	2000/06/16 15:05:26	1.45
+++ Makefile.nmake	2000/07/09 22:28:34
@@ -37,6 +37,7 @@
 	packet-clnp.c  \
 	packet-cops.c  \
 	packet-data.c  \
+	packet-diameter.c \
 	packet-ddtp.c  \
 	packet-dns.c   \
 	packet-eigrp.c \
Index: packet-radius.c
===================================================================
RCS file: /cvsroot/ethereal/packet-radius.c,v
retrieving revision 1.13
diff -u -r1.13 packet-radius.c
--- packet-radius.c	2000/05/31 05:07:33	1.13
+++ packet-radius.c	2000/07/09 22:28:37
@@ -39,6 +39,7 @@
 #include <glib.h>
 #include "packet.h"
 #include "resolv.h"
+#include "prefs.h"
 
 static int proto_radius = -1;
 static int hf_radius_length = -1;
@@ -53,6 +54,12 @@
 #define UDP_PORT_RADACCT	1646
 #define UDP_PORT_RADACCT_NEW	1813
 
+static int gbl_radiusPort = UDP_PORT_RADIUS_NEW;
+static int gbl_radiusOldPort = UDP_PORT_RADIUS;
+static int gbl_radAcctPort = UDP_PORT_RADACCT_NEW;
+static int gbl_radAcctOldPort = UDP_PORT_RADACCT;
+static char gbl_radiusString[200];
+
 typedef struct _e_radiushdr {
         guint8 rh_code;
         guint8 rh_ident;
@@ -455,6 +462,8 @@
 {0,NULL},
 };
 
+void proto_reg_handoff_radius(void);
+
 guint32 match_numval(guint32 val, const value_value_pair *vs)
 {
   guint32 i = 0;
@@ -742,6 +751,38 @@
         }
   }
 }
+#if 0
+void
+configRadius( void )
+{
+	int rc;
+	int port1, port2, port3, port4;
+
+	/* Set our defaults */
+	sprintf(gbl_radiusString, "Radius Protocol (ports %d, %d, %d, %d)",
+	    gbl_radiusPort, gbl_radiusOldPort, gbl_radAcctPort, gbl_radAcctOldPort);
+
+	/* Get our port number */
+	confGetConfiguration("packet-radius", gbl_confString,
+	    sizeof(gbl_confString)-1);
+	
+	if (gbl_confString[0] == 0)
+		return;
+
+	rc = sscanf(gbl_confString, " ports %d %d %d %d", &port1, &port2,
+	    &port3, &port4);
+	if (rc == 4) {
+		gbl_radiusPort = port1;
+		gbl_radiusOldPort = port2;
+		gbl_radAcctPort = port3;
+		gbl_radAcctOldPort = port4;
+	}
+
+	sprintf(gbl_radiusString, "Radius Protocol (ports %d, %d, %d, %d)",
+	    gbl_radiusPort, gbl_radiusOldPort, gbl_radAcctPort,
+	    gbl_radAcctOldPort);
+}
+#endif
 /* registration with the filtering engine */
 void
 proto_register_radius(void)
@@ -764,16 +805,64 @@
 		&ett_radius_avp,
 	};
 
-	proto_radius = proto_register_protocol ("Radius Protocol", "radius");
+	module_t *radius_module;
+
+	radius_module = prefs_register_module("Radius", "Radius",
+	    proto_reg_handoff_radius);
+	prefs_register_uint_preference(radius_module, "rad_port",
+	    "RADIUS Port",
+	    "Set the port for RADIUS messages", 10,
+	    &gbl_radiusPort);
+	prefs_register_uint_preference(radius_module, "rad_old_port",
+	    "RADIUS Port (old)",
+	    "Set the OLD port for RADIUS messages", 10,
+	    &gbl_radiusOldPort);
+	prefs_register_uint_preference(radius_module, "radacct_port",
+	    "RADIUS Accounting Port",
+	    "Set the port for RADIUS accounting messages", 10,
+	    &gbl_radAcctPort);
+	prefs_register_uint_preference(radius_module, "radacct_old_port",
+	    "RADIUS Accounting Port (old)",
+	    "Set the OLD port for RADIUS accounting messages", 10,
+	    &gbl_radAcctOldPort);
+
+	proto_radius = proto_register_protocol (gbl_radiusString, "radius");
 	proto_register_field_array(proto_radius, hf, array_length(hf));
 	proto_register_subtree_array(ett, array_length(ett));
 }
 
+
 void
 proto_reg_handoff_radius(void)
 {
-	dissector_add("udp.port", UDP_PORT_RADIUS, dissect_radius);
-	dissector_add("udp.port", UDP_PORT_RADIUS_NEW, dissect_radius);
-	dissector_add("udp.port", UDP_PORT_RADACCT, dissect_radius);
-	dissector_add("udp.port", UDP_PORT_RADACCT_NEW, dissect_radius);
+  static int Initialized = FALSE;
+  static int port=0, oldPort=0, acctPort=0, oldAcctPort=0;
+
+
+  if (Initialized) {
+	dissector_delete("udp.port", port, dissect_radius);
+	dissector_delete("udp.port", oldPort, dissect_radius);
+	dissector_delete("udp.port", acctPort, dissect_radius);
+	dissector_delete("udp.port", oldAcctPort, dissect_radius);
+  } else {
+    Initialized = TRUE;
+  }
+  /* save them for future deletion */
+  port = gbl_radiusPort;
+  oldPort = gbl_radiusOldPort;
+  acctPort = gbl_radAcctPort;
+  oldAcctPort = gbl_radAcctOldPort;
+
+  /* and, add our new disectors */
+  dissector_add("udp.port", gbl_radiusPort, dissect_radius);
+  dissector_add("udp.port", gbl_radiusOldPort, dissect_radius);
+  dissector_add("udp.port", gbl_radAcctPort, dissect_radius);
+  dissector_add("udp.port", gbl_radAcctOldPort, dissect_radius);
+
+  sprintf(gbl_radiusString, "Radius Protocol (ports %d, %d, %d, %d)",
+	  gbl_radiusPort, gbl_radiusOldPort, gbl_radAcctPort,
+	  gbl_radAcctOldPort);
+
 }
+
+