netlink: fix flags dissection
authorPeter Wu <peter@lekensteyn.nl>
Wed, 17 Aug 2016 19:14:57 +0000 (21:14 +0200)
committerAnders Broman <a.broman58@gmail.com>
Fri, 19 Aug 2016 11:23:03 +0000 (11:23 +0000)
Flags are not in network byte order, use given encoding instead.

Show both flags fields for GET and NEW requests since the netlink
dissector cannot yet determine whether a request is for GET, NEW or
something else. This has no effect for the sockdiag dissector but it
will influence the route and netfilter netlink subdissectors.

Change-Id: I472ff9e0498debbbceef657a14408c4e6a9df75b
Reviewed-on: https://code.wireshark.org/review/17118
Reviewed-by: Anders Broman <a.broman58@gmail.com>
epan/dissectors/packet-netlink.c

index ca9a3c5fe4308788b2ddc22161bb2e3ad5fce02b..b939adac13bb0a1c7d093b5008d703a442288ed1 100644 (file)
@@ -225,6 +225,16 @@ static const int *netlink_header_new_flags[] = {
        NULL
 };
 
+static const int *netlink_header_standard_flags[] = {
+       &hfi_netlink_hdr_flag_request.id,
+       &hfi_netlink_hdr_flag_multi.id,
+       &hfi_netlink_hdr_flag_ack.id,
+       &hfi_netlink_hdr_flag_echo.id,
+       &hfi_netlink_hdr_flag_dumpintr.id,
+       &hfi_netlink_hdr_flag_dumpfiltered.id,
+       NULL
+};
+
 
 int
 dissect_netlink_attributes(tvbuff_t *tvb, header_field_info *hfi_type, int ett, void *data, proto_tree *tree, int offset, int length, netlink_attributes_cb_t cb)
@@ -318,14 +328,17 @@ dissect_netlink_hdr(tvbuff_t *tvb, proto_tree *tree, int offset, int encoding, g
        }
        offset += 2;
 
-       hdr_flags = tvb_get_letohs(tvb, offset);
-       if(hdr_flags & WS_NLM_F_REQUEST) {
+       hdr_flags = tvb_get_guint16(tvb, offset, encoding);
+       if ((hdr_flags & WS_NLM_F_REQUEST) && (hdr_flags & 0x0f00)) {
+               /* XXX detect based on the protocol family and message type
+                * whether this is a GET, NEW or regular request. */
                proto_tree_add_bitmask(fh_hdr, tvb, offset, hfi_netlink_hdr_flags.id,
-                       ett_netlink_hdr_flags, netlink_header_get_flags, ENC_BIG_ENDIAN);
-       }
-       else {
+                       ett_netlink_hdr_flags, netlink_header_get_flags, encoding);
+               proto_tree_add_bitmask(fh_hdr, tvb, offset, hfi_netlink_hdr_flags.id,
+                       ett_netlink_hdr_flags, netlink_header_new_flags, encoding);
+       } else {
                proto_tree_add_bitmask(fh_hdr, tvb, offset, hfi_netlink_hdr_flags.id,
-                       ett_netlink_hdr_flags, netlink_header_new_flags, ENC_BIG_ENDIAN);
+                       ett_netlink_hdr_flags, netlink_header_standard_flags, encoding);
        }
 
        offset += 2;