From 57d954e1689ab31c6afac0a787f13754b8a39a49 Mon Sep 17 00:00:00 2001 From: Jeffrey Smith Date: Sun, 6 Sep 2015 20:56:30 -0500 Subject: [PATCH] Treat IPv4 subnet masks as distinct from addresses While IPv4 subnet masks are obviously related and similar to IPv4 addresses, they are distinct enough that they need to be treated seperately in some aspects. For instance, there is no value in attempting to resolve a subnet mask. This change creates a new display type: BASE_NETMASK, which allows distinction from FT_IPv4 (and possible name resolution) where appropriate. Change-Id: I99e19c9a58eb613f8e58d481af84c30e2e5e14d7 Reviewed-on: https://code.wireshark.org/review/10438 Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Alexis La Goutte Reviewed-by: Michael Mann --- doc/README.dissector | 7 +++++++ epan/dfilter/scanner.l | 2 +- epan/dissectors/packet-adwin-config.c | 2 +- epan/dissectors/packet-afs.c | 2 +- epan/dissectors/packet-bootp.c | 4 ++-- epan/dissectors/packet-capwap.c | 4 ++-- epan/dissectors/packet-chdlc.c | 2 +- epan/dissectors/packet-dvmrp.c | 2 +- epan/dissectors/packet-enip.c | 2 +- epan/dissectors/packet-epl.c | 2 +- epan/dissectors/packet-gvcp.c | 6 +++--- epan/dissectors/packet-isakmp.c | 4 ++-- epan/dissectors/packet-olsr.c | 2 +- epan/dissectors/packet-opsi.c | 2 +- epan/dissectors/packet-ospf.c | 8 ++++---- epan/dissectors/packet-rip.c | 2 +- epan/dissectors/packet-rsip.c | 2 +- epan/dissectors/packet-smcr.c | 2 +- epan/dissectors/packet-wassp.c | 4 ++-- epan/proto.c | 25 ++++++++++++++++++++++++- epan/proto.h | 6 +++++- 21 files changed, 63 insertions(+), 29 deletions(-) diff --git a/doc/README.dissector b/doc/README.dissector index e5c955d21a..addd967d5a 100644 --- a/doc/README.dissector +++ b/doc/README.dissector @@ -138,6 +138,13 @@ FIELDDISPLAY --For FT_UINT{8,16,24,32,40,48,56,64} and a separator between bytes. BASE_NONE has no separator between bytes + --For FT_IPv4: + + BASE_NETMASK - Used for IPv4 address that should never + attempted to be resolved (like netmasks) + otherwise: + (must be) BASE_NONE + --For all other types: BASE_NONE diff --git a/epan/dfilter/scanner.l b/epan/dfilter/scanner.l index 7a6b66eaa4..eedee62b07 100644 --- a/epan/dfilter/scanner.l +++ b/epan/dfilter/scanner.l @@ -250,7 +250,7 @@ static void mark_lval_deprecated(const char *s); -[-[:alnum:]_\.:]+\/[[:digit:]]+ { +[-[:alnum:]_\.:]*\/[[:digit:]]+ { /* CIDR */ return set_lval(TOKEN_UNPARSED, yytext); } diff --git a/epan/dissectors/packet-adwin-config.c b/epan/dissectors/packet-adwin-config.c index 9a6477876d..6a304e7646 100644 --- a/epan/dissectors/packet-adwin-config.c +++ b/epan/dissectors/packet-adwin-config.c @@ -565,7 +565,7 @@ proto_register_adwin_config(void) }, { &hf_adwin_config_netmask, { "Netmask", "adwin_config.netmask", - FT_IPv4, BASE_NONE, NULL, 0x0, + FT_IPv4, BASE_NETMASK, NULL, 0x0, NULL, HFILL } }, { &hf_adwin_config_netmask_count, diff --git a/epan/dissectors/packet-afs.c b/epan/dissectors/packet-afs.c index 1e9a5dac12..8b152e15ca 100644 --- a/epan/dissectors/packet-afs.c +++ b/epan/dissectors/packet-afs.c @@ -3444,7 +3444,7 @@ proto_register_afs(void) { &hf_afs_cm_ipaddr, { "IP Address", "afs.cm.ipaddr", FT_IPv4, BASE_NONE, 0, 0, NULL, HFILL }}, { &hf_afs_cm_netmask, { "Netmask", "afs.cm.netmask", - FT_IPv4, BASE_NONE, 0, 0, NULL, HFILL }}, + FT_IPv4, BASE_NETMASK, 0, 0, NULL, HFILL }}, { &hf_afs_cm_mtu, { "MTU", "afs.cm.mtu", FT_UINT32, BASE_DEC, 0, 0, NULL, HFILL }}, diff --git a/epan/dissectors/packet-bootp.c b/epan/dissectors/packet-bootp.c index d36715f993..c5c0f4df19 100644 --- a/epan/dissectors/packet-bootp.c +++ b/epan/dissectors/packet-bootp.c @@ -6258,7 +6258,7 @@ proto_register_bootp(void) { &hf_bootp_option_subnet_mask, { "Subnet Mask", "bootp.option.subnet_mask", - FT_IPv4, BASE_NONE, NULL, 0x00, + FT_IPv4, BASE_NETMASK, NULL, 0x00, "Option 1: Subnet Mask", HFILL }}, { &hf_bootp_option_time_offset, @@ -6358,7 +6358,7 @@ proto_register_bootp(void) { &hf_bootp_option_policy_filter_subnet_mask, { "Subnet Mask", "bootp.option.policy_filter.subnet_mask", - FT_IPv4, BASE_NONE, NULL, 0x00, + FT_IPv4, BASE_NETMASK, NULL, 0x00, "Option 21: Subnet Mask", HFILL }}, { &hf_bootp_option_non_local_source_routing, diff --git a/epan/dissectors/packet-capwap.c b/epan/dissectors/packet-capwap.c index 35eade0625..1ee2463f66 100644 --- a/epan/dissectors/packet-capwap.c +++ b/epan/dissectors/packet-capwap.c @@ -5424,7 +5424,7 @@ proto_register_capwap_control(void) }, { &hf_capwap_fortinet_cfg_mask, { "Mask", "capwap.control.fortinet.cfg.mask", - FT_IPv4, BASE_NONE, NULL, 0x0, + FT_IPv4, BASE_NETMASK, NULL, 0x0, NULL, HFILL } }, { &hf_capwap_fortinet_split_tun_cfg_enable_local_subnet, @@ -5583,7 +5583,7 @@ proto_register_capwap_control(void) }, { &hf_capwap_cisco_ap_static_ip_netmask, { "Netmask", "capwap.control.cisco.ap_static_ip.netmask", - FT_IPv4, BASE_NONE, NULL, 0x0, + FT_IPv4, BASE_NETMASK, NULL, 0x0, NULL, HFILL } }, { &hf_capwap_cisco_ap_static_ip_gateway, diff --git a/epan/dissectors/packet-chdlc.c b/epan/dissectors/packet-chdlc.c index f6214b9271..5299626887 100644 --- a/epan/dissectors/packet-chdlc.c +++ b/epan/dissectors/packet-chdlc.c @@ -360,7 +360,7 @@ proto_register_slarp(void) /* XXX - need an FT_ for netmasks, which is like FT_IPV4 but doesn't get translated to a host name. */ { &hf_slarp_netmask, - { "Netmask", "slarp.netmask", FT_IPv4, BASE_NONE, + { "Netmask", "slarp.netmask", FT_IPv4, BASE_NETMASK, NULL, 0x0, NULL, HFILL }}, { &hf_slarp_mysequence, { "Outgoing sequence number", "slarp.mysequence", FT_UINT32, BASE_DEC, diff --git a/epan/dissectors/packet-dvmrp.c b/epan/dissectors/packet-dvmrp.c index 78c873c1d3..d645226075 100644 --- a/epan/dissectors/packet-dvmrp.c +++ b/epan/dissectors/packet-dvmrp.c @@ -745,7 +745,7 @@ proto_register_dvmrp(void) NULL, 0, NULL, HFILL }}, { &hf_netmask, - { "Netmask", "dvmrp.netmask", FT_IPv4, BASE_NONE, + { "Netmask", "dvmrp.netmask", FT_IPv4, BASE_NETMASK, NULL, 0, "DVMRP Netmask", HFILL }}, { &hf_metric, diff --git a/epan/dissectors/packet-enip.c b/epan/dissectors/packet-enip.c index 87cae5b744..8cf74f0c34 100644 --- a/epan/dissectors/packet-enip.c +++ b/epan/dissectors/packet-enip.c @@ -2917,7 +2917,7 @@ proto_register_enip(void) { &hf_tcpip_ic_subnet_mask, { "Subnet Mask", "cip.tcpip.subnet_mask", - FT_IPv4, BASE_NONE, NULL, 0, + FT_IPv4, BASE_NETMASK, NULL, 0, NULL, HFILL }}, { &hf_tcpip_ic_gateway, diff --git a/epan/dissectors/packet-epl.c b/epan/dissectors/packet-epl.c index de53ffded9..26a46b0e31 100644 --- a/epan/dissectors/packet-epl.c +++ b/epan/dissectors/packet-epl.c @@ -3898,7 +3898,7 @@ proto_register_epl(void) }, { &hf_epl_asnd_identresponse_snm, { "SubnetMask", "epl.asnd.ires.subnet", - FT_IPv4, BASE_NONE, NULL, 0x00, NULL, HFILL } + FT_IPv4, BASE_NETMASK, NULL, 0x00, NULL, HFILL } }, { &hf_epl_asnd_identresponse_gtw, { "DefaultGateway", "epl.asnd.ires.gateway", diff --git a/epan/dissectors/packet-gvcp.c b/epan/dissectors/packet-gvcp.c index e0eea9065c..00147571e9 100644 --- a/epan/dissectors/packet-gvcp.c +++ b/epan/dissectors/packet-gvcp.c @@ -2566,7 +2566,7 @@ void proto_register_gvcp(void) { &hf_gvcp_forceip_static_subnet_mask, { "Subnet Mask", "gvcp.cmd.forceip.subnetmask", - FT_IPv4, BASE_NONE, NULL, 0x0, + FT_IPv4, BASE_NETMASK, NULL, 0x0, NULL, HFILL }}, { &hf_gvcp_forceip_static_default_gateway, @@ -2847,7 +2847,7 @@ void proto_register_gvcp(void) { &hf_gvcp_current_subnet_mask, { "Subnet Mask", "gvcp.bootstrap.currentsubnetmask", - FT_IPv4, BASE_NONE, NULL, 0x0, + FT_IPv4, BASE_NETMASK, NULL, 0x0, NULL, HFILL }}, /* GVCP_CURRENT_DEFAULT_GATEWAY_0, 1, 2, 3 */ @@ -2933,7 +2933,7 @@ void proto_register_gvcp(void) {& hf_gvcp_persistent_subnet, { "Persistent Subnet Mask", "gvcp.bootstrap.persistentsubnetmask", - FT_IPv4, BASE_NONE, NULL, 0x0, + FT_IPv4, BASE_NETMASK, NULL, 0x0, NULL, HFILL }}, diff --git a/epan/dissectors/packet-isakmp.c b/epan/dissectors/packet-isakmp.c index 48f4aab017..1b8f1f3adf 100644 --- a/epan/dissectors/packet-isakmp.c +++ b/epan/dissectors/packet-isakmp.c @@ -6314,7 +6314,7 @@ proto_register_isakmp(void) "An IPv4 address on the internal network", HFILL }}, { &hf_isakmp_cfg_attr_internal_ip4_netmask, { "INTERNAL IP4 NETMASK", "isakmp.cfg.attr.internal_ip4_netmask", - FT_IPv4, BASE_NONE, NULL, 0x00, + FT_IPv4, BASE_NETMASK, NULL, 0x00, "The internal network's netmask", HFILL }}, { &hf_isakmp_cfg_attr_internal_ip4_dns, { "INTERNAL IP4 DNS", "isakmp.cfg.attr.internal_ip4_dns", @@ -6366,7 +6366,7 @@ proto_register_isakmp(void) "The protected sub-networks that this edge-device protects (IP)", HFILL }}, { &hf_isakmp_cfg_attr_internal_ip4_subnet_netmask, { "INTERNAL IP4 SUBNET (NETMASK)", "isakmp.cfg.attr.internal_ip4_subnet_netmask", - FT_IPv4, BASE_NONE, NULL, 0x00, + FT_IPv4, BASE_NETMASK, NULL, 0x00, "The protected sub-networks that this edge-device protects (IP)", HFILL }}, { &hf_isakmp_cfg_attr_supported_attributes, { "SUPPORTED ATTRIBUTES", "isakmp.cfg.attr.supported_attributes", diff --git a/epan/dissectors/packet-olsr.c b/epan/dissectors/packet-olsr.c index 3bc69521f1..334a0e337d 100644 --- a/epan/dissectors/packet-olsr.c +++ b/epan/dissectors/packet-olsr.c @@ -816,7 +816,7 @@ void proto_register_olsr(void) { { &hf_olsr_netmask, { "Netmask", "olsr.netmask", - FT_IPv4, BASE_NONE, NULL, 0, + FT_IPv4, BASE_NETMASK, NULL, 0, NULL, HFILL } }, diff --git a/epan/dissectors/packet-opsi.c b/epan/dissectors/packet-opsi.c index cd6c8ce713..f67e9fc39a 100644 --- a/epan/dissectors/packet-opsi.c +++ b/epan/dissectors/packet-opsi.c @@ -672,7 +672,7 @@ proto_register_opsi(void) }, { &hf_framed_netmask_att, { "Framed netmask", "opsi.attr.framed_netmask", - FT_IPv4, BASE_NONE, NULL, 0x00, + FT_IPv4, BASE_NETMASK, NULL, 0x00, NULL, HFILL } }, { &hf_framed_routing_att, diff --git a/epan/dissectors/packet-ospf.c b/epan/dissectors/packet-ospf.c index 61c186b96c..655ee1fe9b 100644 --- a/epan/dissectors/packet-ospf.c +++ b/epan/dissectors/packet-ospf.c @@ -3164,7 +3164,7 @@ proto_register_ospf(void) BASE_NONE, NULL, 0x0, NULL, HFILL }}, {&hf_ospf_hello_network_mask, { "Network Mask", "ospf.hello.network_mask", FT_IPv4, - BASE_NONE, NULL, 0x0, NULL, HFILL }}, + BASE_NETMASK, NULL, 0x0, NULL, HFILL }}, {&hf_ospf_hello_interface_id, { "Interface ID", "ospf.hello.interface_id", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }}, @@ -3265,7 +3265,7 @@ proto_register_ospf(void) { "Network LSA", "ospf.lsa.network", FT_BOOLEAN, BASE_NONE, NULL, 0x0, NULL, HFILL }}, {&hf_ospf_ls_network_netmask, - { "Netmask", "ospf.lsa.network.netmask", FT_IPv4, BASE_NONE, NULL, 0x0, + { "Netmask", "ospf.lsa.network.netmask", FT_IPv4, BASE_NETMASK, NULL, 0x0, NULL, HFILL }}, {&hf_ospf_ls_network_attachrtr, { "Attached Router", "ospf.lsa.network.attchrtr", FT_IPv4, BASE_NONE, NULL, 0x0, @@ -3278,14 +3278,14 @@ proto_register_ospf(void) { "Summary LSA (ASBR)", "ospf.lsa.asbr", FT_BOOLEAN, BASE_NONE, NULL, 0x0, NULL, HFILL }}, {&hf_ospf_ls_asbr_netmask, - { "Netmask", "ospf.lsa.asbr.netmask", FT_IPv4, BASE_NONE, NULL, 0x0, + { "Netmask", "ospf.lsa.asbr.netmask", FT_IPv4, BASE_NETMASK, NULL, 0x0, NULL, HFILL }}, {&hf_ospf_ls_asext, { "AS-External LSA (ASBR)", "ospf.lsa.asext", FT_BOOLEAN, BASE_NONE, NULL, 0x0, NULL, HFILL }}, {&hf_ospf_ls_asext_netmask, - { "Netmask", "ospf.lsa.asext.netmask", FT_IPv4, BASE_NONE, NULL, 0x0, + { "Netmask", "ospf.lsa.asext.netmask", FT_IPv4, BASE_NETMASK, NULL, 0x0, NULL, HFILL }}, {&hf_ospf_ls_asext_fwdaddr, { "Forwarding Address", "ospf.lsa.asext.fwdaddr", FT_IPv4, BASE_NONE, NULL, 0x0, diff --git a/epan/dissectors/packet-rip.c b/epan/dissectors/packet-rip.c index cdd9d655fb..e5919689f3 100644 --- a/epan/dissectors/packet-rip.c +++ b/epan/dissectors/packet-rip.c @@ -108,7 +108,7 @@ static header_field_info hfi_rip_ip RIP_HFI_INIT = { NULL, 0, NULL, HFILL}; static header_field_info hfi_rip_netmask RIP_HFI_INIT = { - "Netmask", "rip.netmask", FT_IPv4, BASE_NONE, + "Netmask", "rip.netmask", FT_IPv4, BASE_NETMASK, NULL, 0, NULL, HFILL}; static header_field_info hfi_rip_next_hop RIP_HFI_INIT = { diff --git a/epan/dissectors/packet-rsip.c b/epan/dissectors/packet-rsip.c index 3dd9479d7c..273f864eb9 100644 --- a/epan/dissectors/packet-rsip.c +++ b/epan/dissectors/packet-rsip.c @@ -1112,7 +1112,7 @@ proto_register_rsip(void) }, { &hf_rsip_parameter_address_ipv4_netmask, { "IPv4 Netmask", "rsip.parameter.netmask", - FT_IPv4, BASE_NONE, NULL, 0x0, + FT_IPv4, BASE_NETMASK, NULL, 0x0, NULL, HFILL } }, { &hf_rsip_parameter_address_ipv6, diff --git a/epan/dissectors/packet-smcr.c b/epan/dissectors/packet-smcr.c index ae6ad26c5f..0abef03b74 100644 --- a/epan/dissectors/packet-smcr.c +++ b/epan/dissectors/packet-smcr.c @@ -1033,7 +1033,7 @@ proto_register_smcr(void) { &hf_smcr_proposal_outgoing_interface_subnet_mask, { "Outgoing Interface Subnet Mask", "smcr.outgoing.interface.subnet.mask", - FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL}}, + FT_IPv4, BASE_NETMASK, NULL, 0x0, NULL, HFILL}}, { &hf_smcr_proposal_outgoing_subnet_mask_signifcant_bits, { "Outgoing Interface Subnet Mask Number of Significant Bits", diff --git a/epan/dissectors/packet-wassp.c b/epan/dissectors/packet-wassp.c index f9fe3ea7f8..8883b2aca3 100644 --- a/epan/dissectors/packet-wassp.c +++ b/epan/dissectors/packet-wassp.c @@ -1175,7 +1175,7 @@ proto_register_wassp(void) 0x0, NULL, HFILL }}, { &hf_static_bp_netmask, - { "STATIC-BP-NETMASK", "wassp.static.bp.netmask", FT_IPv4, BASE_NONE, NULL, + { "STATIC-BP-NETMASK", "wassp.static.bp.netmask", FT_IPv4, BASE_NETMASK, NULL, 0x0, NULL, HFILL }}, { &hf_static_bp_gateway, @@ -1235,7 +1235,7 @@ proto_register_wassp(void) 0x0, NULL, HFILL }}, { &hf_ap_netmask, - { "AP-NETMASK", "wassp.ap.netmask", FT_IPv4, BASE_NONE, NULL, + { "AP-NETMASK", "wassp.ap.netmask", FT_IPv4, BASE_NETMASK, NULL, 0x0, NULL, HFILL }}, { &hf_ap_gateway, diff --git a/epan/proto.c b/epan/proto.c index e822588af6..3bbb04c0fe 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -6174,6 +6174,22 @@ tmp_fld_check_assert(header_field_info *hfinfo) ftype_name(hfinfo->type)); break; + case FT_IPv4: + switch (hfinfo->display) { + case BASE_NONE: + case BASE_NETMASK: + break; + + default: + tmp_str = val_to_str_wmem(NULL, hfinfo->display, hf_display, "(Unknown: 0x%x)"); + g_error("Field '%s' (%s) is an IPv4 value (%s)" + " but is being displayed as %s\n", + hfinfo->name, hfinfo->abbrev, + ftype_name(hfinfo->type), tmp_str); + wmem_free(NULL, tmp_str); + break; + } + break; default: if (hfinfo->display != BASE_NONE) { tmp_str = val_to_str_wmem(NULL, hfinfo->display, hf_display, "(Bit count: %d)"); @@ -6659,7 +6675,14 @@ proto_item_fill_label(field_info *fi, gchar *label_str) addr.len = 4; addr.data = &n_addr; - addr_str = (char*)address_with_resolution_to_str(NULL, &addr); + if (hfinfo->display == BASE_NETMASK) + { + addr_str = (char*)address_to_str(NULL, &addr); + } + else + { + addr_str = (char*)address_with_resolution_to_str(NULL, &addr); + } g_snprintf(label_str, ITEM_LABEL_LENGTH, "%s: %s", hfinfo->name, addr_str); wmem_free(NULL, addr_str); diff --git a/epan/proto.h b/epan/proto.h index c30437f9b6..3f0cef278d 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -520,7 +520,11 @@ typedef enum { SEP_DOT = 8, /**< hexadecimal bytes with a period (.) between each byte */ SEP_DASH = 9, /**< hexadecimal bytes with a dash (-) between each byte */ SEP_COLON = 10, /**< hexadecimal bytes with a colon (:) between each byte */ - SEP_SPACE = 11 /**< hexadecimal bytes with a space between each byte */ + SEP_SPACE = 11, /**< hexadecimal bytes with a space between each byte */ + +/* Address types */ + BASE_NETMASK = 12 /**< Used for IPv4 address that shouldn't be resolved (like for netmasks) */ + } field_display_e; /* Following constants have to be ORed with a field_display_e when dissector -- 2.34.1