Commit 2eb7b05b authored by mmann78's avatar mmann78
Browse files

Convert most UDP dissectors to use "auto" preferences.

Similar to the "tcp.port" changes in I99604f95d426ad345f4b494598d94178b886eb67,
convert dissectors that use "udp.port".

More cleanup done on dissectors that use both TCP and UDP dissector
tables, so that less preference callbacks exist.

Change-Id: If07be9b9e850c244336a7069599cd554ce312dd3
Reviewed-on: https://code.wireshark.org/review/18120


Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: default avatarPetri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: mmann78's avatarMichael Mann <mmann78@netscape.net>
parent 4d8581d7
......@@ -59,8 +59,7 @@
/**********************************************************/
/* Port definition's for PTP */
/**********************************************************/
#define EVENT_PORT_PTP 319
#define GENERAL_PORT_PTP 320
#define PTP_PORT_RANGE "319-320"
/* END Port definition's for PTP */
void proto_register_ptp(void);
......@@ -6258,8 +6257,7 @@ proto_reg_handoff_ptp(void)
ptp_handle = create_dissector_handle(dissect_ptp, proto_ptp);
ethertype_ptp_handle = create_dissector_handle(dissect_ptp_oE, proto_ptp);
dissector_add_uint("udp.port", EVENT_PORT_PTP, ptp_handle);
dissector_add_uint("udp.port", GENERAL_PORT_PTP, ptp_handle);
dissector_add_uint_range_with_preference("udp.port", PTP_PORT_RANGE, ptp_handle);
dissector_add_uint("ethertype", ETHERTYPE_PTP, ethertype_ptp_handle);
}
......
......@@ -29,12 +29,8 @@
# include "config.h"
#include <epan/packet.h>
#include <epan/prefs.h>
#define PORT_PULSE 539
static guint pulse_port = PORT_PULSE;
#define PORT_PULSE 539 /* Not IANA registered */
void proto_register_pulse(void);
void proto_reg_handoff_pulse(void);
......@@ -94,8 +90,6 @@ dissect_pulse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void*
void
proto_register_pulse(void)
{
module_t *pulse_module;
static hf_register_info hf[] = {
{ &hf_pulse_magic,
{ "Magic", "pulse.magic",
......@@ -108,42 +102,17 @@ proto_register_pulse(void)
};
proto_pulse = proto_register_protocol("PULSE protocol for Linux Virtual Server redundancy",
"PULSE",
"pulse");
proto_pulse = proto_register_protocol("PULSE protocol for Linux Virtual Server redundancy", "PULSE", "pulse");
proto_register_field_array(proto_pulse, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
pulse_module = prefs_register_protocol(proto_pulse, proto_reg_handoff_pulse);
prefs_register_uint_preference(pulse_module, "udp.port",
"UDP Port",
"Set the UDP port for pulse",
10,
&pulse_port);
}
void
proto_reg_handoff_pulse(void)
{
static gboolean initialized = FALSE;
static int port = 0;
static dissector_handle_t pulse_handle;
if (initialized)
{
dissector_delete_uint("udp.port", port, pulse_handle);
}
else
{
pulse_handle = create_dissector_handle(dissect_pulse,
proto_pulse);
initialized = TRUE;
}
port = pulse_port;
dissector_add_uint("udp.port", port, pulse_handle);
dissector_handle_t pulse_handle;
pulse_handle = create_dissector_handle(dissect_pulse, proto_pulse);
dissector_add_uint_with_preference("udp.port", PORT_PULSE, pulse_handle);
}
/*
......
......@@ -457,7 +457,7 @@ void proto_reg_handoff_pw_cesopsn(void)
pw_cesopsn_mpls_handle = create_dissector_handle( dissect_pw_cesopsn_mpls, proto );
dissector_add_for_decode_as("mpls.label", pw_cesopsn_mpls_handle);
dissector_add_for_decode_as("udp.port", find_dissector("pw_cesopsn_udp"));
dissector_add_for_decode_as_with_preference("udp.port", find_dissector("pw_cesopsn_udp"));
return;
}
......
......@@ -473,7 +473,7 @@ void proto_reg_handoff_pw_satop(void)
pw_satop_mpls_handle = create_dissector_handle( dissect_pw_satop_mpls, proto );
dissector_add_for_decode_as("mpls.label", pw_satop_mpls_handle);
dissector_add_for_decode_as("udp.port", find_dissector("pw_satop_udp"));
dissector_add_for_decode_as_with_preference("udp.port", find_dissector("pw_satop_udp"));
}
/*
......
......@@ -29,7 +29,6 @@
#include <epan/packet.h>
#include <epan/conversation.h>
#include <epan/prefs.h>
void proto_register_quake(void);
......@@ -80,7 +79,6 @@ static dissector_handle_t quake_handle;
/* I took these names directly out of the Q1 source. */
#define NET_HEADERSIZE 8
#define DEFAULTnet_hostport 26000
static guint gbl_quakeServerPort=DEFAULTnet_hostport;
#define NETFLAG_DATA 0x0001
#define NETFLAG_ACK 0x0002
......@@ -581,40 +579,18 @@ proto_register_quake(void)
&ett_quake_control_colors,
&ett_quake_flags,
};
module_t *quake_module;
proto_quake = proto_register_protocol("Quake Network Protocol",
"QUAKE", "quake");
proto_quake = proto_register_protocol("Quake Network Protocol", "QUAKE", "quake");
proto_register_field_array(proto_quake, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
/* Register a configuration option for port */
quake_module = prefs_register_protocol(proto_quake,
proto_reg_handoff_quake);
prefs_register_uint_preference(quake_module, "udp.port",
"Quake Server UDP Port",
"Set the UDP port for the Quake Server",
10, &gbl_quakeServerPort);
}
void
proto_reg_handoff_quake(void)
{
static gboolean Initialized=FALSE;
static guint ServerPort;
if (!Initialized) {
quake_handle = create_dissector_handle(dissect_quake, proto_quake);
Initialized=TRUE;
} else {
dissector_delete_uint("udp.port", ServerPort, quake_handle);
}
/* set port for future deletes */
ServerPort=gbl_quakeServerPort;
dissector_add_uint("udp.port", gbl_quakeServerPort, quake_handle);
quake_handle = create_dissector_handle(dissect_quake, proto_quake);
dissector_add_uint_with_preference("udp.port", DEFAULTnet_hostport, quake_handle);
}
/*
......
......@@ -32,8 +32,10 @@
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/prefs-int.h>
void proto_register_quake2(void);
void proto_reg_handoff_quake2(void);
static int proto_quake2 = -1;
......@@ -79,7 +81,7 @@ static gint ett_quake2_game_clc_cmd_move_bitfield = -1;
static gint ett_quake2_game_clc_cmd_move_moves = -1;
#define PORT_MASTER 27910
#define PORT_MASTER 27910 /* Not IANA registered */
static guint gbl_quake2ServerPort=PORT_MASTER;
......@@ -681,8 +683,13 @@ dissect_quake2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _
return tvb_captured_length(tvb);
}
void proto_reg_handoff_quake2(void);
static void
apply_quake2_prefs(void)
{
/* Port preference used to determine client/server */
pref_t *quake2_port = prefs_find_preference(prefs_find_module("quake2"), "udp.port");
gbl_quake2ServerPort = *quake2_port->varp.uint;
}
void
proto_register_quake2(void)
......@@ -822,42 +829,22 @@ proto_register_quake2(void)
&ett_quake2_game_clc_cmd_move_moves,
&ett_quake2_game_clc_cmd_move_bitfield
};
module_t *quake2_module;
proto_quake2 = proto_register_protocol("Quake II Network Protocol",
"QUAKE2", "quake2");
proto_quake2 = proto_register_protocol("Quake II Network Protocol", "QUAKE2", "quake2");
proto_register_field_array(proto_quake2, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
/* Register a configuration option for port */
quake2_module = prefs_register_protocol(proto_quake2,
proto_reg_handoff_quake2);
prefs_register_uint_preference(quake2_module, "udp.port",
"Quake II Server UDP Port",
"Set the UDP port for the Quake II Server",
10, &gbl_quake2ServerPort);
prefs_register_protocol(proto_quake2, apply_quake2_prefs);
}
void
proto_reg_handoff_quake2(void)
{
static gboolean Initialized=FALSE;
static dissector_handle_t quake2_handle;
static guint ServerPort;
if (!Initialized) {
quake2_handle = create_dissector_handle(dissect_quake2,
proto_quake2);
Initialized=TRUE;
} else {
dissector_delete_uint("udp.port", ServerPort, quake2_handle);
}
/* set port for future deletes */
ServerPort=gbl_quake2ServerPort;
dissector_handle_t quake2_handle;
quake2_handle = create_dissector_handle(dissect_quake2, proto_quake2);
dissector_add_uint("udp.port", gbl_quake2ServerPort, quake2_handle);
dissector_add_uint("udp.port", PORT_MASTER, quake2_handle);
}
/*
......
......@@ -557,14 +557,12 @@ proto_register_quake3(void)
};
module_t *quake3_module;
proto_quake3 = proto_register_protocol("Quake III Arena Network Protocol",
"QUAKE3", "quake3");
proto_quake3 = proto_register_protocol("Quake III Arena Network Protocol", "QUAKE3", "quake3");
proto_register_field_array(proto_quake3, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
/* Register a configuration option for port */
quake3_module = prefs_register_protocol(proto_quake3,
proto_reg_handoff_quake3);
quake3_module = prefs_register_protocol(proto_quake3, proto_reg_handoff_quake3);
prefs_register_uint_preference(quake3_module, "udp.arena_port",
"Quake III Arena Server UDP Base Port",
"Set the UDP base port for the Quake III Arena Server",
......@@ -600,7 +598,7 @@ proto_reg_handoff_quake3(void)
server_port = gbl_quake3_server_port;
master_port = gbl_quake3_master_port;
/* add dissectors */
/* add dissectors. Port preference names to specific to use "auto" */
for (i=0;i<4;i++)
dissector_add_uint("udp.port", gbl_quake3_server_port + i,
quake3_handle);
......
......@@ -30,7 +30,10 @@
#include <stdlib.h>
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/prefs-int.h>
void proto_register_quakeworld(void);
void proto_reg_handoff_quakeworld(void);
static int proto_quakeworld = -1;
......@@ -313,7 +316,7 @@ static const value_string names_direction[] = {
/* I took this name and value directly out of the QW source. */
#define PORT_MASTER 27500
#define PORT_MASTER 27500 /* Not IANA registered */
static guint gbl_quakeworldServerPort=PORT_MASTER;
......@@ -685,8 +688,13 @@ dissect_quakeworld(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* da
return tvb_captured_length(tvb);
}
void proto_reg_handoff_quakeworld(void);
static void
apply_quakeworld_prefs(void)
{
/* Port preference used to determine client/server */
pref_t *quakeworld_port = prefs_find_preference(prefs_find_module("quakeworld"), "udp.port");
gbl_quakeworldServerPort = *quakeworld_port->varp.uint;
}
void
proto_register_quakeworld(void)
......@@ -794,42 +802,23 @@ proto_register_quakeworld(void)
&ett_quakeworld_game_clc,
&ett_quakeworld_game_svc
};
module_t *quakeworld_module;
proto_quakeworld = proto_register_protocol("QuakeWorld Network Protocol",
"QUAKEWORLD", "quakeworld");
proto_quakeworld = proto_register_protocol("QuakeWorld Network Protocol", "QUAKEWORLD", "quakeworld");
proto_register_field_array(proto_quakeworld, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
/* Register a configuration option for port */
quakeworld_module = prefs_register_protocol(proto_quakeworld,
proto_reg_handoff_quakeworld);
prefs_register_uint_preference(quakeworld_module, "udp.port",
"QuakeWorld Server UDP Port",
"Set the UDP port for the QuakeWorld Server",
10, &gbl_quakeworldServerPort);
prefs_register_protocol(proto_quakeworld, apply_quakeworld_prefs);
}
void
proto_reg_handoff_quakeworld(void)
{
static gboolean Initialized=FALSE;
static dissector_handle_t quakeworld_handle;
static guint ServerPort;
if (!Initialized) {
quakeworld_handle = create_dissector_handle(dissect_quakeworld,
proto_quakeworld);
Initialized=TRUE;
} else {
dissector_delete_uint("udp.port", ServerPort, quakeworld_handle);
}
/* set port for future deletes */
ServerPort=gbl_quakeworldServerPort;
dissector_handle_t quakeworld_handle;
dissector_add_uint("udp.port", gbl_quakeworldServerPort, quakeworld_handle);
quakeworld_handle = create_dissector_handle(dissect_quakeworld, proto_quakeworld);
dissector_add_uint("udp.port", PORT_MASTER, quakeworld_handle);
}
/*
......
......@@ -177,8 +177,7 @@ static int hf_quic_padding = -1;
static int hf_quic_stream_data = -1;
static int hf_quic_payload = -1;
static guint g_quic_port = 80;
static guint g_quics_port = 443;
#define QUIC_PORT_RANGE "80,443"
static gboolean g_quic_debug = FALSE;
static gint ett_quic = -1;
......@@ -2847,22 +2846,12 @@ proto_register_quic(void)
expert_module_t *expert_quic;
proto_quic = proto_register_protocol("QUIC (Quick UDP Internet Connections)",
"QUIC", "quic");
proto_quic = proto_register_protocol("QUIC (Quick UDP Internet Connections)", "QUIC", "quic");
proto_register_field_array(proto_quic, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
quic_module = prefs_register_protocol(proto_quic, proto_reg_handoff_quic);
prefs_register_uint_preference(quic_module, "udp.quic.port", "QUIC UDP Port",
"QUIC UDP port if other than the default",
10, &g_quic_port);
prefs_register_uint_preference(quic_module, "udp.quics.port", "QUICS UDP Port",
"QUICS (Secure) UDP port if other than the default",
10, &g_quics_port);
quic_module = prefs_register_protocol(proto_quic, NULL);
prefs_register_bool_preference(quic_module, "debug.quic",
"Force decode of all QUIC Payload",
......@@ -2876,27 +2865,10 @@ proto_register_quic(void)
void
proto_reg_handoff_quic(void)
{
static gboolean initialized = FALSE;
static dissector_handle_t quic_handle;
static int current_quic_port;
static int current_quics_port;
if (!initialized) {
quic_handle = create_dissector_handle(dissect_quic,
proto_quic);
initialized = TRUE;
} else {
dissector_delete_uint("udp.port", current_quic_port, quic_handle);
dissector_delete_uint("udp.port", current_quics_port, quic_handle);
}
current_quic_port = g_quic_port;
current_quics_port = g_quics_port;
dissector_handle_t quic_handle;
dissector_add_uint("udp.port", current_quic_port, quic_handle);
dissector_add_uint("udp.port", current_quics_port, quic_handle);
quic_handle = create_dissector_handle(dissect_quic, proto_quic);
dissector_add_uint_range_with_preference("udp.port", QUIC_PORT_RANGE, quic_handle);
}
......
......@@ -221,8 +221,6 @@ static dissector_handle_t eap_handle;
static const gchar *shared_secret = "";
static gboolean validate_authenticator = FALSE;
static gboolean show_length = FALSE;
static guint alt_port_pref = 0;
static range_t *global_ports_range;
static guint8 authenticator[AUTHENTICATOR_LENGTH];
......@@ -2635,7 +2633,7 @@ proto_register_radius(void)
proto_radius = proto_register_protocol("RADIUS Protocol", "RADIUS", "radius");
register_dissector("radius", dissect_radius, proto_radius);
register_init_routine(&radius_init_protocol);
radius_module = prefs_register_protocol(proto_radius, proto_reg_handoff_radius);
radius_module = prefs_register_protocol(proto_radius, NULL);
prefs_register_string_preference(radius_module, "shared_secret", "Shared Secret",
"Shared secret used to decode User Passwords and validate Response Authenticators",
&shared_secret);
......@@ -2645,12 +2643,6 @@ proto_register_radius(void)
prefs_register_bool_preference(radius_module, "show_length", "Show AVP Lengths",
"Whether to add or not to the tree the AVP's payload length",
&show_length);
prefs_register_uint_preference(radius_module, "alternate_port", "Alternate Port",
"An alternate UDP port to decode as RADIUS", 10, &alt_port_pref);
range_convert_str(&global_ports_range, DEFAULT_RADIUS_PORT_RANGE, MAX_UDP_PORT);
prefs_register_range_preference(radius_module, "ports", "RADIUS ports",
"A list of UDP ports to decode as RADIUS", &global_ports_range, MAX_UDP_PORT);
prefs_register_obsolete_preference(radius_module, "request_ttl");
radius_tap = register_tap("radius");
......@@ -2669,34 +2661,11 @@ proto_register_radius(void)
void
proto_reg_handoff_radius(void)
{
static gboolean initialized = FALSE;
static dissector_handle_t radius_handle;
static range_t *ports_range;
if (!initialized) {
radius_handle = find_dissector("radius");
eap_handle = find_dissector_add_dependency("eap", proto_radius);
initialized = TRUE;
} else {
dissector_delete_uint_range("udp.port", ports_range, radius_handle);
g_free(ports_range);
}
if (alt_port_pref != 0) {
/* Append it to the range of ports but only if necessary */
if (!value_is_in_range(global_ports_range, alt_port_pref)) {
global_ports_range = (range_t *)g_realloc(global_ports_range,
/* see epan/range.c:range_copy function */
sizeof (range_t) - sizeof (range_admin_t) + (global_ports_range->nranges + 1) * sizeof (range_admin_t));
global_ports_range->ranges[global_ports_range->nranges].low = alt_port_pref;
global_ports_range->ranges[global_ports_range->nranges].high = alt_port_pref;
global_ports_range->nranges++;
}
}
dissector_handle_t radius_handle;
ports_range = range_copy(global_ports_range);
dissector_add_uint_range("udp.port", ports_range, radius_handle);
radius_handle = find_dissector("radius");
eap_handle = find_dissector_add_dependency("eap", proto_radius);
dissector_add_uint_range_with_preference("udp.port", DEFAULT_RADIUS_PORT_RANGE, radius_handle);
}
/*
......
......@@ -163,9 +163,7 @@ static gint ett_rdt_bw_probing_flags = -1;
static expert_field ei_rdt_packet_length = EI_INIT;
/* Port preference settings */
static gboolean global_rdt_register_udp_port = FALSE;
static guint global_rdt_udp_port = 6970;
#define RDT_UDP_PORT 6970
void proto_register_rdt(void);
void proto_reg_handoff_rdt(void);
......@@ -2165,62 +2163,20 @@ void proto_register_rdt(void)
register_dissector("rdt", dissect_rdt, proto_rdt);
/* Preference settings */
rdt_module = prefs_register_protocol(proto_rdt, proto_reg_handoff_rdt);
rdt_module = prefs_register_protocol(proto_rdt, NULL);
prefs_register_bool_preference(rdt_module, "show_setup_info",
"Show stream setup information",
"Where available, show which protocol and frame caused "
"this RDT stream to be created",
&global_rdt_show_setup_info);
prefs_register_bool_preference(rdt_module, "register_udp_port",
"Register default UDP client port",
"Register a client UDP port for RDT traffic",
&global_rdt_register_udp_port);
/* TODO: better to specify a range of ports instead? */
prefs_register_uint_preference(rdt_module, "default_udp_port",
"Default UDP client port",
"Set the UDP port for clients",
10, &global_rdt_udp_port);
prefs_register_obsolete_preference(rdt_module, "register_udp_port");
}
void proto_reg_handoff_rdt(void)
{
static gboolean rdt_prefs_initialized = FALSE;
/* Also store this so can delete registered setting properly */
static gboolean rdt_register_udp_port;
static guint rdt_udp_port;
if (!rdt_prefs_initialized)
{
/* Register this dissector as one that can be selected by a
UDP port number. */
rdt_handle = find_dissector("rdt");
dissector_add_for_decode_as("udp.port", rdt_handle);
rdt_prefs_initialized = TRUE;
}
else
{
/* Undo any current port registrations */
if (rdt_register_udp_port)
{
dissector_delete_uint("udp.port", rdt_udp_port, rdt_handle);
}
}
/* Remember whether a port is set for next time */
rdt_register_udp_port = global_rdt_register_udp_port;
/* Add any new port registration */
if (global_rdt_register_udp_port)
{
/* Set our port number for future use */
rdt_udp_port = global_rdt_udp_port;
/* And register with this port */
dissector_add_uint("udp.port", global_rdt_udp_port, rdt_handle);
}
rdt_handle = find_dissector("rdt");
dissector_add_uint_with_preference("udp.port", RDT_UDP_PORT, rdt_handle);
}
/*
......
......@@ -276,8 +276,7 @@ void proto_register_redbackli(void) {
&ett_redbackli
};
proto_redbackli = proto_register_protocol("Redback Lawful Intercept",
"RedbackLI", "redbackli");
proto_redbackli = proto_register_protocol("Redback Lawful Intercept", "RedbackLI", "redbackli");
proto_register_field_array(proto_redbackli, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
......@@ -291,7 +290,7 @@ void proto_reg_handoff_redbackli(void) {
ip_handle = find_dissector_add_dependency("ip", proto_redbackli);
redbackli_handle = find_dissector("redbackli");
dissector_add_for_decode_as("udp.port", redbackli_handle);
dissector_add_for_decode_as_with_preference("udp.port", redbackli_handle);
heur_dissector_add("udp", redbackli_dissect_heur, "Redback Lawful Intercept over UDP", "redbackli_udp", proto_redbackli, HEURISTIC_ENABLE);
}
......
......@@ -593,7 +593,7 @@ proto_reg_handoff_reload_framing(void)
reload_handle = find_dissector_add_dependency("reload", proto_reload_framing);
dissector_add_uint_with_preference("tcp.port", TCP_PORT_RELOAD, reload_framing_tcp_handle);
dissector_add_uint("udp.port", UDP_PORT_RELOAD, reload_framing_udp_handle);
dissector_add_uint_with_preference("udp.port", UDP_PORT_RELOAD, reload_framing_udp_handle);
heur_dissector_add("udp", dissect_reload_framing_heur, "RELOAD Framing over UDP", "reload_framing_udp", proto_reload_framing, HEURISTIC_ENABLE);
heur_dissector_add("tcp", dissect_reload_framing_heur, "RELOAD Framing over TCP", "reload_framing_tcp", proto_reload_framing, HEURISTIC_ENABLE);
......
......@@ -75,7 +75,6 @@
#include "config.h"
#include <epan/packet.h>
#include <epan/prefs.h>