forked from osmocom/wireshark
netlink: make dissect_netlink_attributes() endianness aware
Always give the netlink data struct to dissect_netlink_attributes() so we can extract which endianness we should use. This fixes the netlink dissector on big endian. Change-Id: Ia485a29035c947908c29a9e30d0aba8d4fc94093 Signed-off-by: Hauke Mehrtens <hauke.mehrtens@intel.com> Reviewed-on: https://code.wireshark.org/review/17636 Reviewed-by: Michael Mann <mmann78@netscape.net> Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
parent
b1bbfaa9f7
commit
811bb3302b
|
@ -705,11 +705,11 @@ dissect_netfilter_queue(tvbuff_t *tvb, netlink_netfilter_info_t *info, proto_tre
|
|||
|
||||
switch (type) {
|
||||
case WS_NFQNL_MSG_CONFIG:
|
||||
return dissect_netlink_attributes(tvb, &hfi_nfq_config_attr, ett_nfq_config_attr, info, tree, offset, -1, dissect_nfq_config_attrs);
|
||||
return dissect_netlink_attributes(tvb, &hfi_nfq_config_attr, ett_nfq_config_attr, info, info->data, tree, offset, -1, dissect_nfq_config_attrs);
|
||||
|
||||
case WS_NFQNL_MSG_PACKET:
|
||||
case WS_NFQNL_MSG_VERDICT:
|
||||
return dissect_netlink_attributes(tvb, &hfi_nfq_attr, ett_nfq_attr, info, tree, offset, -1, dissect_nfq_attrs);
|
||||
return dissect_netlink_attributes(tvb, &hfi_nfq_attr, ett_nfq_attr, info, info->data, tree, offset, -1, dissect_nfq_attrs);
|
||||
|
||||
case WS_NFQNL_MSG_VERDICT_BATCH:
|
||||
/* TODO */
|
||||
|
@ -930,7 +930,7 @@ dissect_ipset_cadt_attrs(tvbuff_t *tvb, void *data, proto_tree *tree, int nla_ty
|
|||
case WS_IPSET_ATTR_IP_FROM:
|
||||
case WS_IPSET_ATTR_IP_TO:
|
||||
if (nla_type & NLA_F_NESTED)
|
||||
return dissect_netlink_attributes(tvb, &hfi_ipset_ip_attr, ett_ipset_ip_attr, info, tree, offset, len, dissect_ipset_ip_attrs);
|
||||
return dissect_netlink_attributes(tvb, &hfi_ipset_ip_attr, ett_ipset_ip_attr, info, info->data, tree, offset, len, dissect_ipset_ip_attrs);
|
||||
return 0;
|
||||
|
||||
case WS_IPSET_ATTR_CIDR:
|
||||
|
@ -1010,7 +1010,7 @@ dissect_ipset_adt_attrs(tvbuff_t *tvb, void *data, proto_tree *tree, int nla_typ
|
|||
netlink_netfilter_info_t *info = (netlink_netfilter_info_t *) data;
|
||||
|
||||
if (nla_type & NLA_F_NESTED)
|
||||
return dissect_netlink_attributes(tvb, &hfi_ipset_adt_attr, ett_ipset_adt_attr, info, tree, offset, len, dissect_ipset_adt_data_attrs);
|
||||
return dissect_netlink_attributes(tvb, &hfi_ipset_adt_attr, ett_ipset_adt_attr, info, info->data, tree, offset, len, dissect_ipset_adt_data_attrs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1057,16 +1057,16 @@ dissect_ipset_attrs(tvbuff_t *tvb, void *data, proto_tree *tree, int nla_type, i
|
|||
if (command == WS_IPSET_CMD_CREATE ||
|
||||
command == WS_IPSET_CMD_LIST ||
|
||||
command == WS_IPSET_CMD_SAVE)
|
||||
return dissect_netlink_attributes(tvb, &hfi_ipset_cadt_attr, ett_ipset_cadt_attr, info, tree, offset, len, dissect_ipset_cadt_attrs);
|
||||
return dissect_netlink_attributes(tvb, &hfi_ipset_cadt_attr, ett_ipset_cadt_attr, info, info->data, tree, offset, len, dissect_ipset_cadt_attrs);
|
||||
else
|
||||
return dissect_netlink_attributes(tvb, &hfi_ipset_adt_attr, ett_ipset_adt_attr, info, tree, offset, len, dissect_ipset_adt_data_attrs);
|
||||
return dissect_netlink_attributes(tvb, &hfi_ipset_adt_attr, ett_ipset_adt_attr, info, info->data, tree, offset, len, dissect_ipset_adt_data_attrs);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WS_IPSET_ATTR_ADT:
|
||||
/* Following this, there will be an IPSET_ATTR_DATA with regular ADT attributes, not CADT */
|
||||
if (nla_type & NLA_F_NESTED)
|
||||
return dissect_netlink_attributes(tvb, &hfi_ipset_attr, ett_ipset_attr, info, tree, offset, len, dissect_ipset_adt_attrs);
|
||||
return dissect_netlink_attributes(tvb, &hfi_ipset_attr, ett_ipset_attr, info, info->data, tree, offset, len, dissect_ipset_adt_attrs);
|
||||
return 0;
|
||||
|
||||
case WS_IPSET_ATTR_LINENO:
|
||||
|
@ -1082,7 +1082,7 @@ static int
|
|||
dissect_netfilter_ipset(tvbuff_t *tvb, netlink_netfilter_info_t *info, proto_tree *tree, int offset)
|
||||
{
|
||||
offset = dissect_netlink_netfilter_header(tvb, tree, offset);
|
||||
return dissect_netlink_attributes(tvb, &hfi_ipset_attr, ett_ipset_attr, info, tree, offset, -1, dissect_ipset_attrs);
|
||||
return dissect_netlink_attributes(tvb, &hfi_ipset_attr, ett_ipset_attr, info, info->data, tree, offset, -1, dissect_ipset_attrs);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -334,7 +334,7 @@ dissect_netlink_route_attributes(tvbuff_t *tvb, header_field_info *hfi_type, str
|
|||
*/
|
||||
|
||||
/* XXX, nice */
|
||||
return dissect_netlink_attributes(tvb, hfi_type, ett_netlink_route_attr, info, tree, offset, -1, (netlink_attributes_cb_t *) cb);
|
||||
return dissect_netlink_attributes(tvb, hfi_type, ett_netlink_route_attr, info, info->data, tree, offset, -1, (netlink_attributes_cb_t *) cb);
|
||||
}
|
||||
|
||||
/* Interface */
|
||||
|
|
|
@ -442,7 +442,7 @@ dissect_sock_diag_unix_reply(tvbuff_t *tvb, netlink_sock_diag_info_t *info, prot
|
|||
sock_diag_proto_tree_add_cookie(tree, info, tvb, offset);
|
||||
offset += 8;
|
||||
|
||||
return dissect_netlink_attributes(tvb, &hfi_netlink_sock_diag_unix_attr, ett_netlink_sock_diag_attr, info, tree, offset, -1, dissect_netlink_unix_sock_diag_reply_attrs);
|
||||
return dissect_netlink_attributes(tvb, &hfi_netlink_sock_diag_unix_attr, ett_netlink_sock_diag_attr, info, info->data, tree, offset, -1, dissect_netlink_unix_sock_diag_reply_attrs);
|
||||
}
|
||||
|
||||
/* AF_UNIX request */
|
||||
|
@ -699,7 +699,7 @@ dissect_sock_diag_inet_reply(tvbuff_t *tvb, netlink_sock_diag_info_t *info, prot
|
|||
proto_tree_add_item(tree, &hfi_netlink_sock_diag_inode, tvb, offset, 4, info->encoding);
|
||||
offset += 4;
|
||||
|
||||
return dissect_netlink_attributes(tvb, &hfi_netlink_sock_diag_inet_attr, ett_netlink_sock_diag_attr, info, tree, offset, -1, dissect_sock_diag_inet_attributes);
|
||||
return dissect_netlink_attributes(tvb, &hfi_netlink_sock_diag_inet_attr, ett_netlink_sock_diag_attr, info, info->data, tree, offset, -1, dissect_sock_diag_inet_attributes);
|
||||
}
|
||||
|
||||
/* AF_INET request */
|
||||
|
@ -815,7 +815,7 @@ dissect_sock_diag_netlink_reply(tvbuff_t *tvb, netlink_sock_diag_info_t *info, p
|
|||
sock_diag_proto_tree_add_cookie(tree, info, tvb, offset);
|
||||
offset += 8;
|
||||
|
||||
return dissect_netlink_attributes(tvb, &hfi_netlink_sock_diag_netlink_attr, ett_netlink_sock_diag_attr, info, tree, offset, -1, dissect_sock_diag_netlink_attributes);
|
||||
return dissect_netlink_attributes(tvb, &hfi_netlink_sock_diag_netlink_attr, ett_netlink_sock_diag_attr, info, info->data, tree, offset, -1, dissect_sock_diag_netlink_attributes);
|
||||
}
|
||||
|
||||
/* AF_NETLINK request */
|
||||
|
@ -943,7 +943,7 @@ dissect_sock_diag_packet_reply(tvbuff_t *tvb, netlink_sock_diag_info_t *info, pr
|
|||
sock_diag_proto_tree_add_cookie(tree, info, tvb, offset);
|
||||
offset += 8;
|
||||
|
||||
return dissect_netlink_attributes(tvb, &hfi_netlink_sock_diag_packet_attr, ett_netlink_sock_diag_attr, info, tree, offset, -1, dissect_netlink_packet_sock_diag_reply_attrs);
|
||||
return dissect_netlink_attributes(tvb, &hfi_netlink_sock_diag_packet_attr, ett_netlink_sock_diag_attr, info, info->data, tree, offset, -1, dissect_netlink_packet_sock_diag_reply_attrs);
|
||||
}
|
||||
|
||||
/* AF_PACKET request */
|
||||
|
|
|
@ -237,10 +237,15 @@ static const int *netlink_header_standard_flags[] = {
|
|||
|
||||
|
||||
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)
|
||||
dissect_netlink_attributes(tvbuff_t *tvb, header_field_info *hfi_type, int ett, void *data, struct packet_netlink_data *nl_data, proto_tree *tree, int offset, int length, netlink_attributes_cb_t cb)
|
||||
{
|
||||
int encoding;
|
||||
int padding = (4 - offset) & 3;
|
||||
|
||||
DISSECTOR_ASSERT(nl_data);
|
||||
|
||||
encoding = nl_data->encoding;
|
||||
|
||||
/* align to 4 */
|
||||
offset += padding;
|
||||
if (length == -1) {
|
||||
|
@ -255,7 +260,7 @@ dissect_netlink_attributes(tvbuff_t *tvb, header_field_info *hfi_type, int ett,
|
|||
proto_item *ti, *type_item;
|
||||
proto_tree *attr_tree, *type_tree;
|
||||
|
||||
rta_len = tvb_get_letohs(tvb, offset);
|
||||
rta_len = tvb_get_guint16(tvb, offset, encoding);
|
||||
if (rta_len < 4) {
|
||||
/* XXX invalid expert */
|
||||
break;
|
||||
|
@ -266,16 +271,16 @@ dissect_netlink_attributes(tvbuff_t *tvb, header_field_info *hfi_type, int ett,
|
|||
|
||||
attr_tree = proto_tree_add_subtree(tree, tvb, offset, rta_len, ett, &ti, "Attribute");
|
||||
|
||||
proto_tree_add_item(attr_tree, &hfi_netlink_attr_len, tvb, offset, 2, ENC_LITTLE_ENDIAN);
|
||||
proto_tree_add_item(attr_tree, &hfi_netlink_attr_len, tvb, offset, 2, encoding);
|
||||
offset += 2;
|
||||
|
||||
rta_type = tvb_get_letohs(tvb, offset);
|
||||
rta_type = tvb_get_guint16(tvb, offset, encoding);
|
||||
type = rta_type & NLA_TYPE_MASK;
|
||||
type_item = proto_tree_add_item(attr_tree, &hfi_netlink_attr_type, tvb, offset, 2, ENC_LITTLE_ENDIAN);
|
||||
type_item = proto_tree_add_item(attr_tree, &hfi_netlink_attr_type, tvb, offset, 2, encoding);
|
||||
type_tree = proto_item_add_subtree(type_item, ett_netlink_attr_type);
|
||||
proto_tree_add_item(type_tree, &hfi_netlink_attr_type_nested, tvb, offset, 2, ENC_LITTLE_ENDIAN);
|
||||
proto_tree_add_item(type_tree, &hfi_netlink_attr_type_net_byteorder, tvb, offset, 2, ENC_LITTLE_ENDIAN);
|
||||
proto_tree_add_item(type_tree, hfi_type, tvb, offset, 2, ENC_LITTLE_ENDIAN);
|
||||
proto_tree_add_item(type_tree, &hfi_netlink_attr_type_nested, tvb, offset, 2, encoding);
|
||||
proto_tree_add_item(type_tree, &hfi_netlink_attr_type_net_byteorder, tvb, offset, 2, encoding);
|
||||
proto_tree_add_item(type_tree, hfi_type, tvb, offset, 2, encoding);
|
||||
offset += 2;
|
||||
|
||||
if (rta_type & NLA_F_NESTED)
|
||||
|
|
|
@ -107,7 +107,7 @@ struct packet_netlink_data {
|
|||
|
||||
typedef int netlink_attributes_cb_t(tvbuff_t *, void *data, proto_tree *, int nla_type, int offset, int len);
|
||||
|
||||
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);
|
||||
int dissect_netlink_attributes(tvbuff_t *tvb, header_field_info *hfi_type, int ett, void *data, struct packet_netlink_data *nl_data, proto_tree *tree, int offset, int length, netlink_attributes_cb_t cb);
|
||||
|
||||
#define NLA_F_NESTED 0x8000
|
||||
#define NLA_F_NET_BYTEORDER 0x4000
|
||||
|
|
Loading…
Reference in New Issue