* xlat/af_packet_versions.in: New file.
* netlink_packet_diag.c: Include "xlat/af_packet_versions.h".
(decode_packet_diag_req): sdiag_protocol shouldn't be decoded as a protocol,
currently it should be set to 0.
(decode_packet_diag_info): Decode pdi_version field using af_packet_versions
xlat; decode pdi_index field as an interface index.
(packet_diag_msg_nla_decoders) <PACKET_DIAG_UID>: Decode using
decode_nla_uid.
(decode_packet_diag_msg): Decode pdiag_num as an low-level protocol.
* tests/netlink_sock_diag.c: Update expected output.
* tests/nlattr_packet_diag_msg.c: Likewise.
#include <linux/sock_diag.h>
#include <linux/packet_diag.h>
+#include "xlat/af_packet_versions.h"
#include "xlat/packet_diag_attrs.h"
#include "xlat/packet_diag_info_flags.h"
#include "xlat/packet_diag_show.h"
if (!umoven_or_printaddr(tcp, addr + offset,
sizeof(req) - offset,
(char *) &req + offset)) {
- tprints("sdiag_protocol=");
- printxval_searchn(ethernet_protocols,
- ethernet_protocols_size,
- req.sdiag_protocol, "ETH_P_???");
+ /*
+ * AF_PACKET currently doesn't support protocol values
+ * other than 0.
+ */
+ PRINT_FIELD_X("", req, sdiag_protocol);
PRINT_FIELD_U(", ", req, pdiag_ino);
PRINT_FIELD_FLAGS(", ", req, pdiag_show,
packet_diag_show, "PACKET_SHOW_???");
if (umove_or_printaddr(tcp, addr, &pinfo))
return true;
- PRINT_FIELD_U("{", pinfo, pdi_index);
- PRINT_FIELD_U(", ", pinfo, pdi_version);
+ PRINT_FIELD_IFINDEX("{", pinfo, pdi_index);
+ PRINT_FIELD_XVAL(", ", pinfo, pdi_version, af_packet_versions,
+ "TPACKET_???");
PRINT_FIELD_U(", ", pinfo, pdi_reserve);
PRINT_FIELD_U(", ", pinfo, pdi_copy_thresh);
PRINT_FIELD_U(", ", pinfo, pdi_tstamp);
[PACKET_DIAG_RX_RING] = decode_packet_diag_ring,
[PACKET_DIAG_TX_RING] = decode_packet_diag_ring,
[PACKET_DIAG_FANOUT] = decode_nla_u32,
- [PACKET_DIAG_UID] = decode_nla_u32,
+ [PACKET_DIAG_UID] = decode_nla_uid,
[PACKET_DIAG_MEMINFO] = decode_nla_meminfo,
[PACKET_DIAG_FILTER] = decode_packet_diag_filter
};
(char *) &msg + offset)) {
PRINT_FIELD_XVAL("", msg, pdiag_type,
socktypes, "SOCK_???");
- PRINT_FIELD_U(", ", msg, pdiag_num);
+ PRINT_FIELD_XVAL_SORTED_SIZED(", ", msg, pdiag_num,
+ ethernet_protocols,
+ ethernet_protocols_size,
+ "ETH_P_???");
PRINT_FIELD_U(", ", msg, pdiag_ino);
PRINT_FIELD_COOKIE(", ", msg, pdiag_cookie);
decode_nla = true;
TEST_SOCK_DIAG(fd, nlh0, AF_PACKET,
SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req,
printf("{sdiag_family=AF_PACKET"),
- printf(", sdiag_protocol=ETH_P_LOOP");
+ printf(", sdiag_protocol=%#x", req.sdiag_protocol);
PRINT_FIELD_U(", ", req, pdiag_ino);
printf(", pdiag_show=PACKET_SHOW_INFO");
PRINT_FIELD_COOKIE(", ", req, pdiag_cookie);
static const struct packet_diag_msg msg = {
.pdiag_family = AF_PACKET,
.pdiag_type = SOCK_STREAM,
- .pdiag_num = 0xbadc,
+ .pdiag_num = 0x9100,
.pdiag_ino = 0xfacefeed,
.pdiag_cookie = { 0xdeadbeef, 0xbadc0ded }
};
SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg,
printf("{pdiag_family=AF_PACKET"),
printf(", pdiag_type=SOCK_STREAM");
- PRINT_FIELD_U(", ", msg, pdiag_num);
+ printf(", pdiag_num=ETH_P_QINQ1");
PRINT_FIELD_U(", ", msg, pdiag_ino);
PRINT_FIELD_COOKIE(", ", msg, pdiag_cookie);
printf("}"));
struct packet_diag_msg *const msg = NLMSG_DATA(nlh);
SET_STRUCT(struct packet_diag_msg, msg,
.pdiag_family = AF_PACKET,
- .pdiag_type = SOCK_STREAM
+ .pdiag_type = SOCK_STREAM,
+ .pdiag_num = 3,
);
}
printf("{len=%u, type=SOCK_DIAG_BY_FAMILY"
", flags=NLM_F_DUMP, seq=0, pid=0}"
", {pdiag_family=AF_PACKET"
- ", pdiag_type=SOCK_STREAM, pdiag_num=0"
+ ", pdiag_type=SOCK_STREAM, pdiag_num=ETH_P_ALL"
", pdiag_ino=0, pdiag_cookie=[0, 0]}",
msg_len);
}
{
skip_if_unavailable("/proc/self/fd/");
- static const struct packet_diag_info pinfo = {
- .pdi_index = 0xabcddafa,
- .pdi_version = 0xbabcdafb,
+ struct packet_diag_info pinfo = {
+ .pdi_index = ifindex_lo(),
+ .pdi_version = 2,
.pdi_reserve = 0xcfaacdaf,
.pdi_copy_thresh = 0xdabacdaf,
.pdi_tstamp = 0xeafbaadf,
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_packet_diag_msg, print_packet_diag_msg,
PACKET_DIAG_INFO, pattern, pinfo,
- PRINT_FIELD_U("{", pinfo, pdi_index);
- PRINT_FIELD_U(", ", pinfo, pdi_version);
+ printf("{pdi_index=%s", IFINDEX_LO_STR);
+ printf(", pdi_version=TPACKET_V3");
PRINT_FIELD_U(", ", pinfo, pdi_reserve);
PRINT_FIELD_U(", ", pinfo, pdi_copy_thresh);
PRINT_FIELD_U(", ", pinfo, pdi_tstamp);
--- /dev/null
+TPACKET_V1 0
+TPACKET_V2 1
+TPACKET_V3 2