3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 2001 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #ifndef __PACKET_NETLINK_H__
11 #define __PACKET_NETLINK_H__
13 #include <epan/value_string.h>
15 /* from <include/uapi/linux/netlink.h> prefixed with WS_ */
18 WS_NETLINK_UNUSED
= 1,
19 WS_NETLINK_USERSOCK
= 2,
20 WS_NETLINK_FIREWALL
= 3,
21 WS_NETLINK_SOCK_DIAG
= 4,
24 WS_NETLINK_SELINUX
= 7,
27 WS_NETLINK_FIB_LOOKUP
= 10,
28 WS_NETLINK_CONNECTOR
= 11,
29 WS_NETLINK_NETFILTER
= 12,
30 WS_NETLINK_IP6_FW
= 13,
31 WS_NETLINK_DNRTMSG
= 14,
32 WS_NETLINK_KOBJECT_UEVENT
= 15,
33 WS_NETLINK_GENERIC
= 16,
34 /* leave room for NETLINK_DM (DM Events) */
35 WS_NETLINK_SCSITRANSPORT
= 18,
36 WS_NETLINK_ECRYPTFS
= 19,
38 WS_NETLINK_CRYPTO
= 21,
42 /* from <include/uapi/linux/netlink.h> prefixed with WS_ */
44 WS_NLM_F_REQUEST
= 1, /* It is request message.*/
45 WS_NLM_F_MULTI
= 2, /* Multipart message, terminated by NETLINK_MSG_DONE */
46 WS_NLM_F_ACK
= 4, /* Reply with ack, with zero or error code */
47 WS_NLM_F_ECHO
= 8, /* Echo this request */
48 WS_NLM_F_DUMP_INTR
= 16, /* Dump was inconsistent due to sequence change */
49 WS_NLM_F_DUMP_FILTERED
= 32, /* Dump was filtered as requested */
51 /* Modifiers to Get request */
52 WS_NLM_F_ROOT
= 0x100, /* specify tree root */
53 WS_NLM_F_MATCH
= 0x200, /* return all matching */
54 WS_NLM_F_ATOMIC
= 0x400, /* return an atomic snapshot of the table */
56 /* Modifiers to NEW request */
57 WS_NLM_F_REPLACE
= 0x100, /* Override existing */
58 WS_NLM_F_EXCL
= 0x200, /* Do not touch, if it exists */
59 WS_NLM_F_CREATE
= 0x400, /* Create, if it does */
60 WS_NLM_F_APPEND
= 0x800, /* Add to end of list */
62 /* Modifiers to DELETE request */
63 WS_NLM_F_NONREC
= 0x100, /* Do not delete recursively */
65 /* Flags for ACK message */
66 WS_NLM_F_CAPPED
= 0x100, /* request was capped */
67 WS_NLM_F_ACK_TLVS
= 0x200 /* extended ACK TLVs were included */
71 extern value_string_ext netlink_family_vals_ext
;
75 WS_NLMSG_ERROR
= 0x02,
77 WS_NLMSG_OVERRUN
= 0x04,
78 WS_NLMSG_MIN_TYPE
= 0x10 /** type < WS_NLMSG_MIN_TYPE are reserved */
81 /* from <include/uapi/linux/netfilter.h>. Looks like AF_xxx, except for NFPROTO_ARP */
83 WS_NFPROTO_UNSPEC
= 0,
87 WS_NFPROTO_NETDEV
= 5,
88 WS_NFPROTO_BRIDGE
= 7,
90 WS_NFPROTO_DECNET
= 12,
92 extern const value_string nfproto_family_vals
[];
93 extern const value_string netfilter_hooks_vals
[];
95 #define PACKET_NETLINK_MAGIC 0x4A5ACCCE
97 struct packet_netlink_data
{
98 uint32_t magic
; /* PACKET_NETLINK_MAGIC */
105 * Dissects the Netlink message header (struct nlmsghdr). The "hfi_type" field
106 * is added for the "nlmsg_type" field and returned into pi_type.
108 int dissect_netlink_header(tvbuff_t
*tvb
, proto_tree
*tree
, int offset
, int encoding
, int hf_type
, proto_item
**pi_type
);
110 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
);
112 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
);
114 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
);
117 * Similar to dissect_netlink_attributes, but used to parse nested attributes
118 * that model an array of attributes. The first level (tree ett_array) contains
119 * array elements and its type field is the array index. The next level (tree
120 * ett_attrib) contains attributes (where hfi_type applies).
122 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
);
124 #define NLA_F_NESTED 0x8000
125 #define NLA_F_NET_BYTEORDER 0x4000
126 #define NLA_TYPE_MASK 0x3fff
130 * Format of the data that is passed to "genl.family" dissectors.
133 struct packet_netlink_data
*nl_data
;
135 /* For internal use by genl. */
136 proto_tree
*genl_tree
;
138 /* fields from genlmsghdr */
139 uint8_t cmd
; /* Command number */
141 /* XXX This should contain a family version number as well. */
144 int dissect_genl_header(tvbuff_t
*tvb
, genl_info_t
*genl_info
, struct packet_netlink_data
*nl_data
, int hf_cmd
);
146 #endif /* __PACKET_NETLINK_H__ */
149 * Editor modelines - https://www.wireshark.org/tools/modelines.html
154 * indent-tabs-mode: t
157 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
158 * :indentSize=8:tabSize=8:noTabs=false: