Add support for aliases to dissector tables.

Add register_dissector_table_alias, similar proto_register_alias. Add
aliases for ssl.port, and ssl.handshake.extensions_alpn_str, and
dtls.handshake.extensions_alpn_str.

Change-Id: I87c3215e2872883ed0f581557e08c84f2dba12a0
Reviewed-on: https://code.wireshark.org/review/29652
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
Gerald Combs 2018-09-14 12:58:35 -07:00 committed by Peter Wu
parent 0dafb2bf88
commit 5dbc202063
10 changed files with 71 additions and 10 deletions

View File

@ -1314,6 +1314,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
register_depend_dissector@Base 2.1.0
register_dissector@Base 2.1.0
register_dissector_table@Base 1.9.1
register_dissector_table_alias@Base 2.9.0
register_dissector_with_data@Base 2.5.0
register_export_object@Base 2.3.0
register_export_pdu_tap@Base 1.99.0

View File

@ -1936,7 +1936,7 @@ proto_register_dtls(void)
dtls_associations = register_dissector_table("dtls.port", "DTLS Port", proto_dtls, FT_UINT16, BASE_DEC);
ssl_common_register_dtls_alpn_dissector_table("dtls.handshake.extensions_alpn_str",
ssl_common_register_dtls_alpn_dissector_table("dtls.alpn",
"DTLS Application-Layer Protocol Negotiation (ALPN) Protocol IDs",
proto_dtls);

View File

@ -4148,7 +4148,7 @@ proto_reg_handoff_http(void)
* SSL/TLS Application-Layer Protocol Negotiation (ALPN) protocol
* ID.
*/
dissector_add_string("tls.handshake.extensions_alpn_str", "http/1.1", http_tls_handle);
dissector_add_string("tls.alpn", "http/1.1", http_tls_handle);
ntlmssp_handle = find_dissector_add_dependency("ntlmssp", proto_http);
gssapi_handle = find_dissector_add_dependency("gssapi", proto_http);

View File

@ -3349,7 +3349,7 @@ proto_reg_handoff_http2(void)
/*
* SSL/TLS Application-Layer Protocol Negotiation (ALPN) protocol ID.
*/
dissector_add_string("tls.handshake.extensions_alpn_str", "h2", http2_handle);
dissector_add_string("tls.alpn", "h2", http2_handle);
dissector_add_string("http.upgrade", "h2", http2_handle);
dissector_add_string("http.upgrade", "h2c", http2_handle);

View File

@ -8767,6 +8767,7 @@ ssl_common_register_ssl_alpn_dissector_table(const char *name,
{
ssl_alpn_dissector_table = register_dissector_table(name, ui_name,
proto, FT_STRING, FALSE);
register_dissector_table_alias(ssl_alpn_dissector_table, "ssl.handshake.extensions_alpn_str");
}
void
@ -8775,6 +8776,7 @@ ssl_common_register_dtls_alpn_dissector_table(const char *name,
{
dtls_alpn_dissector_table = register_dissector_table(name, ui_name,
proto, FT_STRING, FALSE);
register_dissector_table_alias(ssl_alpn_dissector_table, "dtls.handshake.extensions_alpn_str");
}
void

View File

@ -4572,6 +4572,7 @@ proto_register_tls(void)
"TLS", "tls");
ssl_associations = register_dissector_table("tls.port", "TLS Port", proto_tls, FT_UINT16, BASE_DEC);
register_dissector_table_alias(ssl_associations, "ssl.port");
/* Required function calls to register the header fields and
* subtrees used */
@ -4647,7 +4648,7 @@ proto_register_tls(void)
/* heuristic dissectors for any premable e.g. CredSSP before RDP */
ssl_heur_subdissector_list = register_heur_dissector_list("tls", proto_tls);
ssl_common_register_ssl_alpn_dissector_table("tls.handshake.extensions_alpn_str",
ssl_common_register_ssl_alpn_dissector_table("tls.alpn",
"SSL/TLS Application-Layer Protocol Negotiation (ALPN) Protocol IDs",
proto_tls);

View File

@ -1735,8 +1735,8 @@ proto_reg_handoff_stun(void)
* SSL/TLS and DTLS Application-Layer Protocol Negotiation (ALPN)
* protocol ID.
*/
dissector_add_string("tls.handshake.extensions_alpn_str", "stun.nat-discovery", stun_tcp_handle);
dissector_add_string("dtls.handshake.extensions_alpn_str", "stun.nat-discovery", stun_udp_handle);
dissector_add_string("tls.alpn", "stun.nat-discovery", stun_tcp_handle);
dissector_add_string("dtls.alpn", "stun.nat-discovery", stun_udp_handle);
heur_dissector_add("udp", dissect_stun_heur, "STUN over UDP", "stun_udp", proto_stun, HEURISTIC_ENABLE);

View File

@ -206,8 +206,8 @@ proto_reg_handoff_turnchannel(void)
* SSL/TLS and DTLS Application-Layer Protocol Negotiation (ALPN)
* protocol ID.
*/
dissector_add_string("tls.handshake.extensions_alpn_str", "stun.turn", turnchannel_tcp_handle);
dissector_add_string("dtls.handshake.extensions_alpn_str", "stun.turn", turnchannel_udp_handle);
dissector_add_string("tls.alpn", "stun.turn", turnchannel_tcp_handle);
dissector_add_string("dtls.alpn", "stun.turn", turnchannel_udp_handle);
/* TURN negotiation is handled through STUN2 dissector (packet-stun.c),
so only it should be able to determine if a packet is a TURN packet */

View File

@ -91,8 +91,16 @@ struct dissector_table {
gboolean supports_decode_as;
};
/*
* Dissector tables. const char * -> dissector_table *
*/
static GHashTable *dissector_tables = NULL;
/*
* Dissector table aliases. const char * -> const char *
*/
static GHashTable *dissector_table_aliases = NULL;
/*
* List of registered dissectors.
*/
@ -191,6 +199,9 @@ packet_init(void)
dissector_tables = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, destroy_dissector_table);
dissector_table_aliases = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, NULL);
registered_dissectors = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, NULL);
@ -243,6 +254,7 @@ packet_cleanup(void)
g_slist_free(cleanup_routines);
g_slist_free(postseq_cleanup_routines);
g_hash_table_destroy(dissector_tables);
g_hash_table_destroy(dissector_table_aliases);
g_hash_table_destroy(registered_dissectors);
g_hash_table_destroy(depend_dissector_lists);
g_hash_table_destroy(heur_dissector_lists);
@ -914,7 +926,17 @@ struct dtbl_entry {
dissector_table_t
find_dissector_table(const char *name)
{
return (dissector_table_t)g_hash_table_lookup(dissector_tables, name);
dissector_table_t dissector_table = (dissector_table_t) g_hash_table_lookup(dissector_tables, name);
if (! dissector_table) {
const char *new_name = (const char *) g_hash_table_lookup(dissector_table_aliases, name);
if (new_name) {
dissector_table = (dissector_table_t) g_hash_table_lookup(dissector_tables, new_name);
}
if (dissector_table) {
g_warning("%s is now %s", name, new_name);
}
}
return dissector_table;
}
/* Find an entry in a uint dissector table. */
@ -2467,13 +2489,40 @@ dissector_table_t register_custom_dissector_table(const char *name,
return sub_dissectors;
}
void
register_dissector_table_alias(dissector_table_t dissector_table, const char *alias_name) {
if (!dissector_table || !alias_name) return;
const char *name = NULL;
GList *list = g_hash_table_get_keys(dissector_tables);
for (GList *cur = list; cur; cur = cur->next) {
if (g_hash_table_lookup(dissector_tables, cur->data) == dissector_table) {
name = (const char *) cur->data;
break;
}
}
g_list_free(list);
if (!name) return;
g_hash_table_insert(dissector_table_aliases, (gpointer) alias_name, (gpointer) name);
}
void
deregister_dissector_table(const char *name)
{
dissector_table_t sub_dissectors = find_dissector_table(name);
dissector_table_t sub_dissectors = (dissector_table_t) g_hash_table_lookup(dissector_tables, name);
if (!sub_dissectors) return;
g_hash_table_remove(dissector_tables, name);
GList *list = g_hash_table_get_keys(dissector_table_aliases);
for (GList *cur = list; cur; cur = cur->next) {
gpointer alias_name = cur->data;
if (g_hash_table_lookup(dissector_table_aliases, alias_name) == name) {
g_hash_table_remove(dissector_table_aliases, alias_name);
}
}
g_list_free(list);
}
const char *

View File

@ -179,6 +179,14 @@ WS_DLL_PUBLIC dissector_table_t register_dissector_table(const char *name,
WS_DLL_PUBLIC dissector_table_t register_custom_dissector_table(const char *name,
const char *ui_name, const int proto, GHashFunc hash_func, GEqualFunc key_equal_func);
/** Register a dissector table alias.
* This is for dissectors whose original name has changed, e.g. SSL to TLS.
* @param dissector_table_t dissector table returned by register_dissector_table.
* @param alias_name alias for the dissector table name.
*/
WS_DLL_PUBLIC void register_dissector_table_alias(dissector_table_t dissector_table,
const char *alias_name);
/** Deregister the dissector table by table name. */
void deregister_dissector_table(const char *name);