diff options
author | João Valverde <j@v6e.pt> | 2021-12-11 14:05:11 +0000 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2021-12-11 16:32:28 +0000 |
commit | 3230ed2dac645ddc7d917323c27813300ff98df3 (patch) | |
tree | 6ebbab2877662f2127bcdc0c8cb1cc1c39f30fc7 | |
parent | 53cded5062330a0f1ee3c381e26ff2ec5dc9cf1a (diff) |
Netlink: Change dissector API to use HF index
Instead of passing a pointer to a header_field_info structure,
pass an integer index to the registry.
This allows each dissector to be converted to a more conventional
structure.
-rw-r--r-- | epan/dissectors/packet-netlink-generic.c | 20 | ||||
-rw-r--r-- | epan/dissectors/packet-netlink-net_dm.c | 14 | ||||
-rw-r--r-- | epan/dissectors/packet-netlink-netfilter.c | 40 | ||||
-rw-r--r-- | epan/dissectors/packet-netlink-nl80211.c | 8 | ||||
-rw-r--r-- | epan/dissectors/packet-netlink-psample.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-netlink-route.c | 12 | ||||
-rw-r--r-- | epan/dissectors/packet-netlink-sock_diag.c | 10 | ||||
-rw-r--r-- | epan/dissectors/packet-netlink.c | 43 | ||||
-rw-r--r-- | epan/dissectors/packet-netlink.h | 10 |
9 files changed, 83 insertions, 78 deletions
diff --git a/epan/dissectors/packet-netlink-generic.c b/epan/dissectors/packet-netlink-generic.c index 98adfcb2f6..36bd749a3f 100644 --- a/epan/dissectors/packet-netlink-generic.c +++ b/epan/dissectors/packet-netlink-generic.c @@ -323,10 +323,10 @@ dissect_genl_ctrl_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *n } break; case WS_CTRL_ATTR_OPS: - offset = dissect_netlink_attributes_array(tvb, &hfi_genl_ctrl_ops_attr, ett_genl_ctrl_ops, ett_genl_ctrl_ops_attr, info, nl_data, tree, offset, len, dissect_genl_ctrl_ops_attrs); + offset = dissect_netlink_attributes_array(tvb, hfi_genl_ctrl_ops_attr.id, ett_genl_ctrl_ops, ett_genl_ctrl_ops_attr, info, nl_data, tree, offset, len, dissect_genl_ctrl_ops_attrs); break; case WS_CTRL_ATTR_MCAST_GROUPS: - offset = dissect_netlink_attributes_array(tvb, &hfi_genl_ctrl_groups_attr, ett_genl_ctrl_groups, ett_genl_ctrl_groups_attr, info, nl_data, tree, offset, len, dissect_genl_ctrl_groups_attrs); + offset = dissect_netlink_attributes_array(tvb, hfi_genl_ctrl_groups_attr.id, ett_genl_ctrl_groups, ett_genl_ctrl_groups_attr, info, nl_data, tree, offset, len, dissect_genl_ctrl_groups_attrs); break; } @@ -355,13 +355,13 @@ dissect_genl_ctrl(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree _U_, v info.family_id = 0; info.family_name = NULL; - offset = dissect_genl_header(tvb, genl_info, genl_info->nl_data, &hfi_genl_ctrl_cmd); + offset = dissect_genl_header(tvb, genl_info, genl_info->nl_data, hfi_genl_ctrl_cmd.id); /* Return if command has no payload */ if (!tvb_reported_length_remaining(tvb, offset)) return offset; - dissect_netlink_attributes_to_end(tvb, &hfi_genl_ctrl_attr, ett_genl_ctrl_attr, &info, genl_info->nl_data, genl_info->genl_tree, offset, dissect_genl_ctrl_attrs); + dissect_netlink_attributes_to_end(tvb, hfi_genl_ctrl_attr.id, ett_genl_ctrl_attr, &info, genl_info->nl_data, genl_info->genl_tree, offset, dissect_genl_ctrl_attrs); /* * Remember association of dynamic ID with the family name such that @@ -392,14 +392,14 @@ static header_field_info hfi_genl_reserved = { "Reserved", "genl.reserved", FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL }; -int dissect_genl_header(tvbuff_t *tvb, genl_info_t *genl_info, struct packet_netlink_data *nl_data, header_field_info *hfi_cmd) +int dissect_genl_header(tvbuff_t *tvb, genl_info_t *genl_info, struct packet_netlink_data *nl_data, int hf_cmd) { int offset = 0; - if (!hfi_cmd) { - hfi_cmd = &hfi_genl_cmd; + if (hf_cmd < 0) { + hf_cmd = hfi_genl_cmd.id; } - proto_tree_add_item(genl_info->genl_tree, hfi_cmd->id, tvb, offset, 1, ENC_NA); + proto_tree_add_item(genl_info->genl_tree, hf_cmd, tvb, offset, 1, ENC_NA); offset++; /* XXX Family dissectors may want to know this */ proto_tree_add_item(genl_info->genl_tree, hfi_genl_version.id, tvb, offset, 1, ENC_NA); @@ -429,7 +429,7 @@ dissect_netlink_generic(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi nlmsg_tree = proto_item_add_subtree(pi, ett_netlink_generic); /* Netlink message header (nlmsghdr) */ - offset = dissect_netlink_header(tvb, nlmsg_tree, offset, nl_data->encoding, &hfi_genl_family_id, &pi_type); + offset = dissect_netlink_header(tvb, nlmsg_tree, offset, nl_data->encoding, hfi_genl_family_id.id, &pi_type); family_name = (const char *)wmem_map_lookup(genl_family_map, GUINT_TO_POINTER(nl_data->type)); proto_item_append_text(pi_type, " (%s)", family_name ? family_name : "Unknown"); @@ -450,7 +450,7 @@ dissect_netlink_generic(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi } /* No subdissector added the genl header, do it now. */ - offset = dissect_genl_header(next_tvb, &info, nl_data, NULL); + offset = dissect_genl_header(next_tvb, &info, nl_data, -1); if (tvb_reported_length_remaining(tvb, offset)) { next_tvb = tvb_new_subset_remaining(tvb, offset); call_data_dissector(next_tvb, pinfo, tree); diff --git a/epan/dissectors/packet-netlink-net_dm.c b/epan/dissectors/packet-netlink-net_dm.c index 29ac772867..e4c425a42b 100644 --- a/epan/dissectors/packet-netlink-net_dm.c +++ b/epan/dissectors/packet-netlink-net_dm.c @@ -327,7 +327,7 @@ dissect_net_dm_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_d proto_item_append_text(tree, ": %s", str); return 1; case WS_NET_DM_ATTR_IN_PORT: - return dissect_netlink_attributes(tvb, &hfi_net_dm_attrs_port, ett_net_dm_attrs_in_port, info, nl_data, tree, offset, len, + return dissect_netlink_attributes(tvb, hfi_net_dm_attrs_port.id, ett_net_dm_attrs_in_port, info, nl_data, tree, offset, len, dissect_net_dm_attrs_port); case WS_NET_DM_ATTR_TIMESTAMP: timestamp = tvb_get_guint64(tvb, offset, nl_data->encoding); @@ -363,10 +363,10 @@ dissect_net_dm_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_d proto_item_append_text(tree, ": %u", value); return 1; case WS_NET_DM_ATTR_STATS: - return dissect_netlink_attributes(tvb, &hfi_net_dm_attrs_stats, ett_net_dm_attrs_stats, info, nl_data, tree, offset, len, + return dissect_netlink_attributes(tvb, hfi_net_dm_attrs_stats.id, ett_net_dm_attrs_stats, info, nl_data, tree, offset, len, dissect_net_dm_attrs_stats); case WS_NET_DM_ATTR_HW_STATS: - return dissect_netlink_attributes(tvb, &hfi_net_dm_attrs_stats, ett_net_dm_attrs_hw_stats, info, nl_data, tree, offset, len, + return dissect_netlink_attributes(tvb, hfi_net_dm_attrs_stats.id, ett_net_dm_attrs_hw_stats, info, nl_data, tree, offset, len, dissect_net_dm_attrs_stats); case WS_NET_DM_ATTR_ORIGIN: proto_tree_add_item(tree, hfi_net_dm_origin.id, tvb, offset, len, nl_data->encoding); @@ -380,10 +380,10 @@ dissect_net_dm_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_d proto_item_append_text(tree, ": %s", str); return 1; case WS_NET_DM_ATTR_HW_ENTRIES: - return dissect_netlink_attributes(tvb, &hfi_net_dm_attrs, ett_net_dm_attrs_hw_entries, info, nl_data, tree, offset, len, + return dissect_netlink_attributes(tvb, hfi_net_dm_attrs.id, ett_net_dm_attrs_hw_entries, info, nl_data, tree, offset, len, dissect_net_dm_attrs); case WS_NET_DM_ATTR_HW_ENTRY: - return dissect_netlink_attributes(tvb, &hfi_net_dm_attrs, ett_net_dm_attrs_hw_entry, info, nl_data, tree, offset, len, + return dissect_netlink_attributes(tvb, hfi_net_dm_attrs.id, ett_net_dm_attrs_hw_entry, info, nl_data, tree, offset, len, dissect_net_dm_attrs); case WS_NET_DM_ATTR_HW_TRAP_COUNT: proto_tree_add_item_ret_uint(tree, hfi_net_dm_hw_trap_count.id, tvb, offset, len, nl_data->encoding, &value); @@ -418,7 +418,7 @@ dissect_netlink_net_dm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void col_clear(pinfo->cinfo, COL_INFO); /* Generic netlink header */ - offset = dissect_genl_header(tvb, genl_info, genl_info->nl_data, &hfi_net_dm_commands); + offset = dissect_genl_header(tvb, genl_info, genl_info->nl_data, hfi_net_dm_commands.id); /* Not all commands have a payload */ if (!tvb_reported_length_remaining(tvb, offset)) @@ -431,7 +431,7 @@ dissect_netlink_net_dm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void info.pinfo = pinfo; info.protocol = 0; - offset = dissect_netlink_attributes_to_end(tvb, &hfi_net_dm_attrs, ett_net_dm_attrs, &info, genl_info->nl_data, nlmsg_tree, offset, dissect_net_dm_attrs); + offset = dissect_netlink_attributes_to_end(tvb, hfi_net_dm_attrs.id, ett_net_dm_attrs, &info, genl_info->nl_data, nlmsg_tree, offset, dissect_net_dm_attrs); return offset; } diff --git a/epan/dissectors/packet-netlink-netfilter.c b/epan/dissectors/packet-netlink-netfilter.c index b76c371f90..6c4f159726 100644 --- a/epan/dissectors/packet-netlink-netfilter.c +++ b/epan/dissectors/packet-netlink-netfilter.c @@ -535,13 +535,13 @@ dissect_nfct_tuple_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data * switch (type) { case WS_CTA_TUPLE_IP: if (nla_type & NLA_F_NESTED) - return dissect_netlink_attributes(tvb, &hfi_nfct_tuple_ip_attr, ett_nfct_tuple_ip_attr, info, nl_data, + return dissect_netlink_attributes(tvb, hfi_nfct_tuple_ip_attr.id, ett_nfct_tuple_ip_attr, info, nl_data, tree, offset, len, dissect_nfct_tuple_ip_attrs); return 0; case WS_CTA_TUPLE_PROTO: if (nla_type & NLA_F_NESTED) - return dissect_netlink_attributes(tvb, &hfi_nfct_tuple_proto_attr, ett_nfct_tuple_proto_attr, info, nl_data, + return dissect_netlink_attributes(tvb, hfi_nfct_tuple_proto_attr.id, ett_nfct_tuple_proto_attr, info, nl_data, tree, offset, len, dissect_nfct_tuple_proto_attrs); return 0; @@ -793,14 +793,14 @@ dissect_nfct_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_dat case WS_CTA_HELP: if (nla_type & NLA_F_NESTED) - return dissect_netlink_attributes(tvb, &hfi_nfct_help_attr, ett_nfct_help_attr, info, nl_data, + return dissect_netlink_attributes(tvb, hfi_nfct_help_attr.id, ett_nfct_help_attr, info, nl_data, tree, offset, len, dissect_nfct_help_attrs); return 0; case WS_CTA_SEQ_ADJ_ORIG: case WS_CTA_SEQ_ADJ_REPLY: if (nla_type & NLA_F_NESTED) - return dissect_netlink_attributes(tvb, &hfi_nfct_seqadj_attr, ett_nfct_seqadj_attr, info, nl_data, + return dissect_netlink_attributes(tvb, hfi_nfct_seqadj_attr.id, ett_nfct_seqadj_attr, info, nl_data, tree, offset, len, dissect_nfct_seqadj_attrs); return 0; @@ -808,7 +808,7 @@ dissect_nfct_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_dat case WS_CTA_TUPLE_REPLY: case WS_CTA_TUPLE_MASTER: if (nla_type & NLA_F_NESTED) - return dissect_netlink_attributes(tvb, &hfi_nfct_tuple_attr, ett_nfct_tuple_attr, info, nl_data, + return dissect_netlink_attributes(tvb, hfi_nfct_tuple_attr.id, ett_nfct_tuple_attr, info, nl_data, tree, offset, len, dissect_nfct_tuple_attrs); return 0; @@ -827,7 +827,7 @@ static int dissect_netfilter_ct(tvbuff_t *tvb, netlink_netfilter_info_t *info, struct packet_netlink_data *nl_data, proto_tree *tree, int offset) { offset = dissect_netlink_netfilter_header(tvb, tree, offset); - return dissect_netlink_attributes_to_end(tvb, &hfi_nfct_attr, ett_nfct_attr, info, nl_data, + return dissect_netlink_attributes_to_end(tvb, hfi_nfct_attr.id, ett_nfct_attr, info, nl_data, tree, offset, dissect_nfct_attrs); } @@ -889,7 +889,7 @@ dissect_nfexp_nat_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *n case WS_CTA_EXPECT_NAT_TUPLE: if (nla_type & NLA_F_NESTED) - return dissect_netlink_attributes(tvb, &hfi_nfct_tuple_attr, ett_nfct_tuple_attr, info, nl_data, + return dissect_netlink_attributes(tvb, hfi_nfct_tuple_attr.id, ett_nfct_tuple_attr, info, nl_data, tree, offset, len, dissect_nfct_tuple_attrs); return 0; @@ -956,13 +956,13 @@ dissect_nfexp_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_da case WS_CTA_EXPECT_MASK: case WS_CTA_EXPECT_MASTER: if (nla_type & NLA_F_NESTED) - return dissect_netlink_attributes(tvb, &hfi_nfct_tuple_attr, ett_nfct_tuple_attr, info, nl_data, + return dissect_netlink_attributes(tvb, hfi_nfct_tuple_attr.id, ett_nfct_tuple_attr, info, nl_data, tree, offset, len, dissect_nfct_tuple_attrs); return 0; case WS_CTA_EXPECT_NAT: if (nla_type & NLA_F_NESTED) - return dissect_netlink_attributes(tvb, &hfi_nfexp_nat_attr, ett_nfexp_nat_attr, info, nl_data, + return dissect_netlink_attributes(tvb, hfi_nfexp_nat_attr.id, ett_nfexp_nat_attr, info, nl_data, tree, offset, len, dissect_nfexp_nat_attrs); return 0; @@ -1008,7 +1008,7 @@ dissect_netfilter_exp(tvbuff_t *tvb, netlink_netfilter_info_t *info, struct pack //enum ws_ctnl_exp_msg_types type = (enum ws_ctnl_exp_msg_types) (info->data->type & 0xff); offset = dissect_netlink_netfilter_header(tvb, tree, offset); - return dissect_netlink_attributes_to_end(tvb, &hfi_nfexp_attr, ett_nfexp_attr, info, nl_data, + return dissect_netlink_attributes_to_end(tvb, hfi_nfexp_attr.id, ett_nfexp_attr, info, nl_data, tree, offset, dissect_nfexp_attrs); } @@ -1378,7 +1378,7 @@ dissect_nfq_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_data case WS_NFQA_CT: if (nla_type & NLA_F_NESTED) - return dissect_netlink_attributes(tvb, &hfi_nfct_attr, ett_nfct_attr, info, nl_data, + return dissect_netlink_attributes(tvb, hfi_nfct_attr.id, ett_nfct_attr, info, nl_data, tree, offset, len, dissect_nfct_attrs); break; @@ -1440,11 +1440,11 @@ dissect_netfilter_queue(tvbuff_t *tvb, netlink_netfilter_info_t *info, struct pa switch (type) { case WS_NFQNL_MSG_CONFIG: - return dissect_netlink_attributes_to_end(tvb, &hfi_nfq_config_attr, ett_nfq_config_attr, info, nl_data, tree, offset, dissect_nfq_config_attrs); + return dissect_netlink_attributes_to_end(tvb, hfi_nfq_config_attr.id, ett_nfq_config_attr, info, nl_data, tree, offset, dissect_nfq_config_attrs); case WS_NFQNL_MSG_PACKET: case WS_NFQNL_MSG_VERDICT: - return dissect_netlink_attributes_to_end(tvb, &hfi_nfq_attr, ett_nfq_attr, info, nl_data, tree, offset, dissect_nfq_attrs); + return dissect_netlink_attributes_to_end(tvb, hfi_nfq_attr.id, ett_nfq_attr, info, nl_data, tree, offset, dissect_nfq_attrs); case WS_NFQNL_MSG_VERDICT_BATCH: /* TODO */ @@ -1671,7 +1671,7 @@ dissect_ipset_cadt_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data * 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, nl_data, tree, offset, len, dissect_ipset_ip_attrs); + return dissect_netlink_attributes(tvb, hfi_ipset_ip_attr.id, ett_ipset_ip_attr, info, nl_data, tree, offset, len, dissect_ipset_ip_attrs); return 0; case WS_IPSET_ATTR_CIDR: @@ -1751,7 +1751,7 @@ dissect_ipset_adt_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *n 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, nl_data, tree, offset, len, dissect_ipset_adt_data_attrs); + return dissect_netlink_attributes(tvb, hfi_ipset_adt_attr.id, ett_ipset_adt_attr, info, nl_data, tree, offset, len, dissect_ipset_adt_data_attrs); return 0; } @@ -1798,16 +1798,16 @@ dissect_ipset_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_da 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, nl_data, tree, offset, len, dissect_ipset_cadt_attrs); + return dissect_netlink_attributes(tvb, hfi_ipset_cadt_attr.id, ett_ipset_cadt_attr, info, nl_data, tree, offset, len, dissect_ipset_cadt_attrs); else - return dissect_netlink_attributes(tvb, &hfi_ipset_adt_attr, ett_ipset_adt_attr, info, nl_data, tree, offset, len, dissect_ipset_adt_data_attrs); + return dissect_netlink_attributes(tvb, hfi_ipset_adt_attr.id, ett_ipset_adt_attr, info, nl_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, nl_data, tree, offset, len, dissect_ipset_adt_attrs); + return dissect_netlink_attributes(tvb, hfi_ipset_attr.id, ett_ipset_attr, info, nl_data, tree, offset, len, dissect_ipset_adt_attrs); return 0; case WS_IPSET_ATTR_LINENO: @@ -1824,7 +1824,7 @@ static int dissect_netfilter_ipset(tvbuff_t *tvb, netlink_netfilter_info_t *info, struct packet_netlink_data *nl_data, proto_tree *tree, int offset) { offset = dissect_netlink_netfilter_header(tvb, tree, offset); - return dissect_netlink_attributes_to_end(tvb, &hfi_ipset_attr, ett_ipset_attr, info, nl_data, tree, offset, dissect_ipset_attrs); + return dissect_netlink_attributes_to_end(tvb, hfi_ipset_attr.id, ett_ipset_attr, info, nl_data, tree, offset, dissect_ipset_attrs); } @@ -1879,7 +1879,7 @@ dissect_netlink_netfilter(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, v nlmsg_tree = proto_item_add_subtree(pi, ett_netlink_netfilter); /* Netlink message header (nlmsghdr) */ - offset = dissect_netlink_header(tvb, nlmsg_tree, offset, nl_data->encoding, NULL, NULL); + offset = dissect_netlink_header(tvb, nlmsg_tree, offset, nl_data->encoding, -1, NULL); proto_tree_add_item(nlmsg_tree, hfi_netlink_netfilter_subsys.id, tvb, 4, 2, nl_data->encoding); switch (nl_data->type >> 8) { case WS_NFNL_SUBSYS_CTNETLINK_EXP: diff --git a/epan/dissectors/packet-netlink-nl80211.c b/epan/dissectors/packet-netlink-nl80211.c index 9db7df8275..f570ffedf5 100644 --- a/epan/dissectors/packet-netlink-nl80211.c +++ b/epan/dissectors/packet-netlink-nl80211.c @@ -3769,7 +3769,7 @@ dissect_nested_attr(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_da if (nested[i].attr_type != (nla_type & NLA_TYPE_MASK)) { continue; } - offset = dissect_netlink_attributes(tvb, nested[i].hfi, *nested[i].ett, info, + offset = dissect_netlink_attributes(tvb, nested[i].hfi->id, *nested[i].ett, info, nl_data, tree, offset, len, nested[i].func ? nested[i].func : dissect_nl80211_generic); break; @@ -3785,7 +3785,7 @@ dissect_nested_attr_array(tvbuff_t *tvb, void *data, struct packet_netlink_data if (nested_arr[i].attr_type != (nla_type & NLA_TYPE_MASK)) { continue; } - offset = dissect_netlink_attributes_array(tvb, nested_arr[i].hfi, *nested_arr[i].ett, + offset = dissect_netlink_attributes_array(tvb, nested_arr[i].hfi->id, *nested_arr[i].ett, *nested_arr[i].ett, info, nl_data, tree, offset, len, nested_arr[i].func ? @@ -4108,7 +4108,7 @@ dissect_netlink_nl80211(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi col_set_str(pinfo->cinfo, COL_PROTOCOL, "nl80211"); col_clear(pinfo->cinfo, COL_INFO); - offset = dissect_genl_header(tvb, genl_info, genl_info->nl_data, &hfi_nl80211_commands); + offset = dissect_genl_header(tvb, genl_info, genl_info->nl_data, hfi_nl80211_commands.id); /* Return if command has no payload */ if (!tvb_reported_length_remaining(tvb, offset)) @@ -4120,7 +4120,7 @@ dissect_netlink_nl80211(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi pi = proto_tree_add_item(tree, proto_netlink_nl80211, tvb, offset, -1, ENC_NA); nlmsg_tree = proto_item_add_subtree(pi, ett_nl80211); - offset = dissect_netlink_attributes_to_end(tvb, &hfi_nl80211_attrs, ett_nl80211_attrs, &info, genl_info->nl_data, nlmsg_tree, offset, dissect_nl80211_attrs); + offset = dissect_netlink_attributes_to_end(tvb, hfi_nl80211_attrs.id, ett_nl80211_attrs, &info, genl_info->nl_data, nlmsg_tree, offset, dissect_nl80211_attrs); return offset; } diff --git a/epan/dissectors/packet-netlink-psample.c b/epan/dissectors/packet-netlink-psample.c index 2be0b95ac2..e5f2633ff4 100644 --- a/epan/dissectors/packet-netlink-psample.c +++ b/epan/dissectors/packet-netlink-psample.c @@ -256,7 +256,7 @@ dissect_netlink_psample(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi col_clear(pinfo->cinfo, COL_INFO); /* Generic netlink header */ - offset = dissect_genl_header(tvb, genl_info, genl_info->nl_data, &hfi_psample_commands); + offset = dissect_genl_header(tvb, genl_info, genl_info->nl_data, hfi_psample_commands.id); /* Not all commands have a payload */ if (!tvb_reported_length_remaining(tvb, offset)) @@ -269,7 +269,7 @@ dissect_netlink_psample(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi info.pinfo = pinfo; info.protocol = 0; - offset = dissect_netlink_attributes_to_end(tvb, &hfi_psample_attrs, ett_psample_attrs, &info, genl_info->nl_data, nlmsg_tree, offset, dissect_psample_attrs); + offset = dissect_netlink_attributes_to_end(tvb, hfi_psample_attrs.id, ett_psample_attrs, &info, genl_info->nl_data, nlmsg_tree, offset, dissect_psample_attrs); return offset; } diff --git a/epan/dissectors/packet-netlink-route.c b/epan/dissectors/packet-netlink-route.c index 944975ffdb..1849e1db6f 100644 --- a/epan/dissectors/packet-netlink-route.c +++ b/epan/dissectors/packet-netlink-route.c @@ -397,7 +397,7 @@ _fill_label_value_string_bitmask(char *label, guint32 value, const value_string } static int -dissect_netlink_route_attributes(tvbuff_t *tvb, header_field_info *hfi_type, struct netlink_route_info *info, struct packet_netlink_data *nl_data, proto_tree *tree, int offset, netlink_attributes_cb_t cb) +dissect_netlink_route_attributes(tvbuff_t *tvb, int hf_type, struct netlink_route_info *info, struct packet_netlink_data *nl_data, proto_tree *tree, int offset, netlink_attributes_cb_t cb) { /* XXX, it's *almost* the same: * - rtnetlink is using struct rtattr with shorts @@ -405,7 +405,7 @@ dissect_netlink_route_attributes(tvbuff_t *tvb, header_field_info *hfi_type, str */ /* XXX, nice */ - return dissect_netlink_attributes_to_end(tvb, hfi_type, ett_netlink_route_attr, info, nl_data, tree, offset, cb); + return dissect_netlink_attributes_to_end(tvb, hf_type, ett_netlink_route_attr, info, nl_data, tree, offset, cb); } /* Interface */ @@ -1457,7 +1457,7 @@ dissect_netlink_route(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void nlmsg_tree = proto_item_add_subtree(pi, ett_netlink_route); /* Netlink message header (nlmsghdr) */ - offset = dissect_netlink_header(tvb, nlmsg_tree, offset, nl_data->encoding, &hfi_netlink_route_nltype, NULL); + offset = dissect_netlink_header(tvb, nlmsg_tree, offset, nl_data->encoding, hfi_netlink_route_nltype.id, NULL); info.pinfo = pinfo; @@ -1475,7 +1475,7 @@ dissect_netlink_route(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void info.legacy = (nl_data->type == WS_RTM_GETLINK) && (tvb_reported_length_remaining(tvb, offset) < 16); offset = dissect_netlink_route_ifinfomsg(tvb, &info, nl_data, nlmsg_tree, offset); /* Optional attributes */ - offset = dissect_netlink_route_attributes(tvb, &hfi_netlink_route_ifla_attr_type, &info, nl_data, nlmsg_tree, offset, dissect_netlink_route_ifla_attrs); + offset = dissect_netlink_route_attributes(tvb, hfi_netlink_route_ifla_attr_type.id, &info, nl_data, nlmsg_tree, offset, dissect_netlink_route_ifla_attrs); break; case WS_RTM_NEWADDR: @@ -1497,7 +1497,7 @@ dissect_netlink_route(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void * Not present in legacy-tool messages; * again, see the comment above. */ - offset = dissect_netlink_route_attributes(tvb, &hfi_netlink_route_ifa_attr_type, &info, nl_data, nlmsg_tree, offset, dissect_netlink_route_ifa_attrs); + offset = dissect_netlink_route_attributes(tvb, hfi_netlink_route_ifa_attr_type.id, &info, nl_data, nlmsg_tree, offset, dissect_netlink_route_ifa_attrs); } break; @@ -1521,7 +1521,7 @@ dissect_netlink_route(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void * Not present in legacy-tool messages; * again, see the comment above. */ - offset = dissect_netlink_route_attributes(tvb, &hfi_netlink_route_rta_attr_type, &info, nl_data, nlmsg_tree, offset, dissect_netlink_route_route_attrs); + offset = dissect_netlink_route_attributes(tvb, hfi_netlink_route_rta_attr_type.id, &info, nl_data, nlmsg_tree, offset, dissect_netlink_route_route_attrs); } break; diff --git a/epan/dissectors/packet-netlink-sock_diag.c b/epan/dissectors/packet-netlink-sock_diag.c index 45886ba586..b0b466ab6b 100644 --- a/epan/dissectors/packet-netlink-sock_diag.c +++ b/epan/dissectors/packet-netlink-sock_diag.c @@ -446,7 +446,7 @@ dissect_sock_diag_unix_reply(tvbuff_t *tvb, netlink_sock_diag_info_t *info, stru sock_diag_proto_tree_add_cookie(tree, info, nl_data, tvb, offset); offset += 8; - return dissect_netlink_attributes_to_end(tvb, &hfi_netlink_sock_diag_unix_attr, ett_netlink_sock_diag_attr, info, nl_data, tree, offset, dissect_netlink_unix_sock_diag_reply_attrs); + return dissect_netlink_attributes_to_end(tvb, hfi_netlink_sock_diag_unix_attr.id, ett_netlink_sock_diag_attr, info, nl_data, tree, offset, dissect_netlink_unix_sock_diag_reply_attrs); } /* AF_UNIX request */ @@ -730,7 +730,7 @@ dissect_sock_diag_inet_reply(tvbuff_t *tvb, netlink_sock_diag_info_t *info, stru proto_tree_add_item(tree, hfi_netlink_sock_diag_inode.id, tvb, offset, 4, nl_data->encoding); offset += 4; - return dissect_netlink_attributes_to_end(tvb, &hfi_netlink_sock_diag_inet_attr, ett_netlink_sock_diag_attr, info, nl_data, tree, offset, dissect_sock_diag_inet_attributes); + return dissect_netlink_attributes_to_end(tvb, hfi_netlink_sock_diag_inet_attr.id, ett_netlink_sock_diag_attr, info, nl_data, tree, offset, dissect_sock_diag_inet_attributes); } /* AF_INET request */ @@ -851,7 +851,7 @@ dissect_sock_diag_netlink_reply(tvbuff_t *tvb, netlink_sock_diag_info_t *info, s sock_diag_proto_tree_add_cookie(tree, info, nl_data, tvb, offset); offset += 8; - return dissect_netlink_attributes_to_end(tvb, &hfi_netlink_sock_diag_netlink_attr, ett_netlink_sock_diag_attr, info, nl_data, tree, offset, dissect_sock_diag_netlink_attributes); + return dissect_netlink_attributes_to_end(tvb, hfi_netlink_sock_diag_netlink_attr.id, ett_netlink_sock_diag_attr, info, nl_data, tree, offset, dissect_sock_diag_netlink_attributes); } /* AF_NETLINK request */ @@ -979,7 +979,7 @@ dissect_sock_diag_packet_reply(tvbuff_t *tvb, netlink_sock_diag_info_t *info, st sock_diag_proto_tree_add_cookie(tree, info, nl_data, tvb, offset); offset += 8; - return dissect_netlink_attributes_to_end(tvb, &hfi_netlink_sock_diag_packet_attr, ett_netlink_sock_diag_attr, info, nl_data, tree, offset, dissect_netlink_packet_sock_diag_reply_attrs); + return dissect_netlink_attributes_to_end(tvb, hfi_netlink_sock_diag_packet_attr.id, ett_netlink_sock_diag_attr, info, nl_data, tree, offset, dissect_netlink_packet_sock_diag_reply_attrs); } /* AF_PACKET request */ @@ -1127,7 +1127,7 @@ dissect_netlink_sock_diag(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, v nlmsg_tree = proto_item_add_subtree(pi, ett_netlink_sock_diag); /* Netlink message header (nlmsghdr) */ - offset = dissect_netlink_header(tvb, nlmsg_tree, offset, nl_data->encoding, &hfi_netlink_sock_diag_nltype, NULL); + offset = dissect_netlink_header(tvb, nlmsg_tree, offset, nl_data->encoding, hfi_netlink_sock_diag_nltype.id, NULL); info.pinfo = pinfo; diff --git a/epan/dissectors/packet-netlink.c b/epan/dissectors/packet-netlink.c index 44c17155fc..1d98a84522 100644 --- a/epan/dissectors/packet-netlink.c +++ b/epan/dissectors/packet-netlink.c @@ -236,11 +236,12 @@ static int * const netlink_header_standard_flags[] = { static int -dissect_netlink_attributes_common(tvbuff_t *tvb, header_field_info *hfi_type, int ett_tree, int ett_attrib, void *data, struct packet_netlink_data *nl_data, proto_tree *tree, int offset, int length, netlink_attributes_cb_t cb) +dissect_netlink_attributes_common(tvbuff_t *tvb, int hf_type, int ett_tree, int ett_attrib, 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; guint data_length; + header_field_info *hfi_type; DISSECTOR_ASSERT(nl_data); @@ -290,17 +291,18 @@ dissect_netlink_attributes_common(tvbuff_t *tvb, header_field_info *hfi_type, in type_tree = proto_item_add_subtree(type_item, ett_netlink_attr_type); proto_tree_add_item(type_tree, hfi_netlink_attr_type_nested.id, tvb, offset, 2, encoding); proto_tree_add_item(type_tree, hfi_netlink_attr_type_net_byteorder.id, tvb, offset, 2, encoding); - /* The hfi_type _must_ have NLA_TYPE_MASK in it's definition, otherwise the nested/net_byteorder + /* The hf_type _must_ have NLA_TYPE_MASK in it's definition, otherwise the nested/net_byteorder * flags influence the retrieved value. Since this is impossible to enforce (apart from using * a nasty DISSECTOR_ASSERT perhaps) we'll just have to make sure to feed in the properly * masked value. Luckily we already have it: 'type' is the value we need. */ - proto_tree_add_uint(type_tree, hfi_type->id, tvb, offset, 2, type); + proto_tree_add_uint(type_tree, hf_type, tvb, offset, 2, type); offset += 2; if (rta_type & NLA_F_NESTED) proto_item_append_text(type_item, ", Nested"); + hfi_type = proto_registrar_get_nth(hf_type); if (hfi_type->strings) { /* XXX, export hf_try_val_to_str */ const char *rta_str; @@ -343,7 +345,7 @@ dissect_netlink_attributes_common(tvbuff_t *tvb, header_field_info *hfi_type, in offset += 2; proto_item_append_text(ti, " %u", rta_type); - dissect_netlink_attributes(tvb, hfi_type, ett_attrib, data, nl_data, attr_tree, offset, rta_len - 4, cb); + dissect_netlink_attributes(tvb, hf_type, ett_attrib, data, nl_data, attr_tree, offset, rta_len - 4, cb); } /* Assume offset already aligned, next offset is rta_len plus alignment. */ @@ -358,31 +360,32 @@ dissect_netlink_attributes_common(tvbuff_t *tvb, header_field_info *hfi_type, in } 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) +dissect_netlink_attributes(tvbuff_t *tvb, int hf_type, int ett, void *data, struct packet_netlink_data *nl_data, proto_tree *tree, int offset, int length, netlink_attributes_cb_t cb) { - return dissect_netlink_attributes_common(tvb, hfi_type, ett, -1, data, nl_data, tree, offset, length, cb); + return dissect_netlink_attributes_common(tvb, hf_type, ett, -1, data, nl_data, tree, offset, length, cb); } int -dissect_netlink_attributes_to_end(tvbuff_t *tvb, header_field_info *hfi_type, int ett, void *data, struct packet_netlink_data *nl_data, proto_tree *tree, int offset, netlink_attributes_cb_t cb) +dissect_netlink_attributes_to_end(tvbuff_t *tvb, int hf_type, int ett, void *data, struct packet_netlink_data *nl_data, proto_tree *tree, int offset, netlink_attributes_cb_t cb) { - return dissect_netlink_attributes_common(tvb, hfi_type, ett, -1, data, nl_data, tree, offset, tvb_ensure_reported_length_remaining(tvb, offset), cb); + return dissect_netlink_attributes_common(tvb, hf_type, ett, -1, data, nl_data, tree, offset, tvb_ensure_reported_length_remaining(tvb, offset), cb); } int -dissect_netlink_attributes_array(tvbuff_t *tvb, header_field_info *hfi_type, int ett_array, int ett_attrib, void *data, struct packet_netlink_data *nl_data, proto_tree *tree, int offset, int length, netlink_attributes_cb_t cb) +dissect_netlink_attributes_array(tvbuff_t *tvb, int hf_type, int ett_array, int ett_attrib, void *data, struct packet_netlink_data *nl_data, proto_tree *tree, int offset, int length, netlink_attributes_cb_t cb) { DISSECTOR_ASSERT(ett_attrib != -1); - return dissect_netlink_attributes_common(tvb, hfi_type, ett_array, ett_attrib, data, nl_data, tree, offset, length, cb); + return dissect_netlink_attributes_common(tvb, hf_type, ett_array, ett_attrib, data, nl_data, tree, offset, length, cb); } int -dissect_netlink_header(tvbuff_t *tvb, proto_tree *tree, int offset, int encoding, header_field_info *hfi_type, proto_item **pi_type) +dissect_netlink_header(tvbuff_t *tvb, proto_tree *tree, int offset, int encoding, int hf_type, proto_item **pi_type) { guint16 hdr_flags; guint16 hdr_type; proto_tree *fh_hdr; proto_item *pi; + header_field_info *hfi_type; fh_hdr = proto_tree_add_subtree(tree, tvb, offset, 16, ett_netlink_msghdr, NULL, "Netlink message header"); @@ -392,17 +395,19 @@ dissect_netlink_header(tvbuff_t *tvb, proto_tree *tree, int offset, int encoding hdr_type = tvb_get_guint16(tvb, offset, encoding); if (hdr_type < WS_NLMSG_MIN_TYPE) { /* Reserved control messages. */ - hfi_type = &hfi_netlink_hdr_type; - pi = proto_tree_add_item(fh_hdr, hfi_type->id, tvb, offset, 2, encoding); + hf_type = hfi_netlink_hdr_type.id; + pi = proto_tree_add_item(fh_hdr, hf_type, tvb, offset, 2, encoding); } else { - if (hfi_type) { - pi = proto_tree_add_item(fh_hdr, hfi_type->id, tvb, offset, 2, encoding); + if (hf_type != -1) { + pi = proto_tree_add_item(fh_hdr, hf_type, tvb, offset, 2, encoding); } else { - hfi_type = &hfi_netlink_hdr_type; - pi = proto_tree_add_item(fh_hdr, hfi_type->id, tvb, offset, 2, encoding); + hf_type = hfi_netlink_hdr_type.id; + pi = proto_tree_add_item(fh_hdr, hf_type, tvb, offset, 2, encoding); proto_item_set_text(pi, "Message type: Protocol-specific (0x%04x)", hdr_type); } } + hfi_type = proto_registrar_get_nth(hf_type); + if (pi_type) { *pi_type = pi; } @@ -455,7 +460,7 @@ dissect_netlink_error(tvbuff_t *tvb, proto_tree *tree, int offset, int encoding) proto_tree_add_item(tree, hfi_netlink_error.id, tvb, offset, 4, encoding); offset += 4; - dissect_netlink_header(tvb, tree, offset, encoding, NULL, NULL); + dissect_netlink_header(tvb, tree, offset, encoding, -1, NULL); } static int @@ -578,7 +583,7 @@ dissect_netlink(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data * header and the payload. Note that pkt_len>=16. */ fh_msg = proto_tree_add_subtree(tree, tvb, offset, pkt_len, ett_netlink_msg, NULL, "Netlink message"); - offset = dissect_netlink_header(tvb, fh_msg, offset, encoding, NULL, NULL); + offset = dissect_netlink_header(tvb, fh_msg, offset, encoding, -1, NULL); if (msg_type == WS_NLMSG_ERROR) { dissect_netlink_error(tvb, fh_msg, offset, encoding); diff --git a/epan/dissectors/packet-netlink.h b/epan/dissectors/packet-netlink.h index 3380f33a33..8d510142c8 100644 --- a/epan/dissectors/packet-netlink.h +++ b/epan/dissectors/packet-netlink.h @@ -105,13 +105,13 @@ struct packet_netlink_data { * Dissects the Netlink message header (struct nlmsghdr). The "hfi_type" field * is added for the "nlmsg_type" field and returned into pi_type. */ -int dissect_netlink_header(tvbuff_t *tvb, proto_tree *tree, int offset, int encoding, header_field_info *hfi_type, proto_item **pi_type); +int dissect_netlink_header(tvbuff_t *tvb, proto_tree *tree, int offset, int encoding, int hf_type, proto_item **pi_type); typedef int netlink_attributes_cb_t(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_data, proto_tree *tree, int nla_type, int offset, int len); -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); +int dissect_netlink_attributes(tvbuff_t *tvb, int hf_type, int ett, void *data, struct packet_netlink_data *nl_data, proto_tree *tree, int offset, int length, netlink_attributes_cb_t cb); -int dissect_netlink_attributes_to_end(tvbuff_t *tvb, header_field_info *hfi_type, int ett, void *data, struct packet_netlink_data *nl_data, proto_tree *tree, int offset, netlink_attributes_cb_t cb); +int dissect_netlink_attributes_to_end(tvbuff_t *tvb, int hf_type, int ett, void *data, struct packet_netlink_data *nl_data, proto_tree *tree, int offset, netlink_attributes_cb_t cb); /* * Similar to dissect_netlink_attributes, but used to parse nested attributes @@ -119,7 +119,7 @@ int dissect_netlink_attributes_to_end(tvbuff_t *tvb, header_field_info *hfi_type * array elements and its type field is the array index. The next level (tree * ett_attrib) contains attributes (where hfi_type applies). */ -int dissect_netlink_attributes_array(tvbuff_t *tvb, header_field_info *hfi_type, int ett_array, int ett_attrib, void *data, struct packet_netlink_data *nl_data, proto_tree *tree, int offset, int length, netlink_attributes_cb_t cb); +int dissect_netlink_attributes_array(tvbuff_t *tvb, int hf_type, int ett_array, int ett_attrib, 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 @@ -141,7 +141,7 @@ typedef struct { /* XXX This should contain a family version number as well. */ } genl_info_t; -int dissect_genl_header(tvbuff_t *tvb, genl_info_t *genl_info, struct packet_netlink_data *nl_data, header_field_info *hfi_cmd); +int dissect_genl_header(tvbuff_t *tvb, genl_info_t *genl_info, struct packet_netlink_data *nl_data, int hf_cmd); #endif /* __PACKET_NETLINK_H__ */ |