177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes/* 277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com> 377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * Copyright (c) 2017 The strace developers. 477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * All rights reserved. 577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * 677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * Redistribution and use in source and binary forms, with or without 777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * modification, are permitted provided that the following conditions 877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * are met: 977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * 1. Redistributions of source code must retain the above copyright 1077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * notice, this list of conditions and the following disclaimer. 1177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * 2. Redistributions in binary form must reproduce the above copyright 1277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * notice, this list of conditions and the following disclaimer in the 1377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * documentation and/or other materials provided with the distribution. 1477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * 3. The name of the author may not be used to endorse or promote products 1577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * derived from this software without specific prior written permission. 1677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * 1777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes */ 2877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 2977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#include "tests.h" 3077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 3177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#include <stdio.h> 3277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#include <stddef.h> 3377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#include "test_nlattr.h" 3477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 3577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#include <linux/if.h> 3677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#include <linux/if_arp.h> 3777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#ifdef HAVE_LINUX_IF_LINK_H 3877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes# include <linux/if_link.h> 3977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#endif 4077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#include <linux/rtnetlink.h> 4177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 4277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#ifndef IFLA_LINKINFO 4377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes# define IFLA_LINKINFO 18 4477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#endif 4577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#ifndef IFLA_VF_PORTS 4677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes# define IFLA_VF_PORTS 24 4777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#endif 4877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#define IFLA_LINK_NETNSID 37 4977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 5077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#ifndef IFLA_INFO_KIND 5177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes# define IFLA_INFO_KIND 1 5277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#endif 5377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 5477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#ifndef IFLA_VF_PORT 5577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes# define IFLA_VF_PORT 1 5677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#endif 5777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 5877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughesstatic void 5977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughesinit_ifinfomsg(struct nlmsghdr *const nlh, const unsigned int msg_len) 6077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes{ 6177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes SET_STRUCT(struct nlmsghdr, nlh, 6277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .nlmsg_len = msg_len, 6377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .nlmsg_type = RTM_GETLINK, 6477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .nlmsg_flags = NLM_F_DUMP 6577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes ); 6677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 6777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes struct ifinfomsg *const msg = NLMSG_DATA(nlh); 6877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes SET_STRUCT(struct ifinfomsg, msg, 6977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .ifi_family = AF_UNIX, 7077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .ifi_type = ARPHRD_LOOPBACK, 7177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .ifi_index = ifindex_lo(), 7277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .ifi_flags = IFF_UP, 7377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes ); 7477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes} 7577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 7677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughesstatic void 7777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughesprint_ifinfomsg(const unsigned int msg_len) 7877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes{ 7977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes printf("{len=%u, type=RTM_GETLINK, flags=NLM_F_DUMP" 8077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes ", seq=0, pid=0}, {ifi_family=AF_UNIX" 8177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes ", ifi_type=ARPHRD_LOOPBACK" 8277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes ", ifi_index=" IFINDEX_LO_STR 8377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes ", ifi_flags=IFF_UP, ifi_change=0}", 8477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes msg_len); 8577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes} 8677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 8777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughesint 8877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughesmain(void) 8977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes{ 9077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes skip_if_unavailable("/proc/self/fd/"); 9177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 9277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes const int fd = create_nl_socket(NETLINK_ROUTE); 9377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes const unsigned int hdrlen = sizeof(struct ifinfomsg); 9477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); 9577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 9677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes static char pattern[4096]; 9777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); 9877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 9977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes const unsigned int nla_type = 0xffff & NLA_TYPE_MASK; 10077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes char nla_type_str[256]; 10177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes sprintf(nla_type_str, "%#x /* IFLA_??? */", nla_type); 10277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes TEST_NLATTR_(fd, nlh0, hdrlen, 10377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes init_ifinfomsg, print_ifinfomsg, 10477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes nla_type, nla_type_str, 10577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 4, pattern, 4, 10677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes print_quoted_hex(pattern, 4)); 10777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 10877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes const int32_t netnsid = 0xacbdabda; 10977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, 11077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes init_ifinfomsg, print_ifinfomsg, 11177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes IFLA_LINK_NETNSID, pattern, netnsid, 11277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes printf("%d", netnsid)); 11377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 11477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes static const struct rtnl_link_stats st = { 11577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_packets = 0xabcdefac, 11677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_packets = 0xbcdacdab, 11777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_bytes = 0xcdbafaab, 11877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_bytes = 0xdafabadb, 11977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_errors = 0xeabcdaeb, 12077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_errors = 0xfefabeab, 12177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_dropped = 0xadbafafb, 12277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_dropped = 0xbdffabda, 12377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .multicast = 0xcdabdfea, 12477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .collisions = 0xefadbaeb, 12577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_length_errors = 0xfabffabd, 12677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_over_errors = 0xafbafabc, 12777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_crc_errors = 0xbfdabdad, 12877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_frame_errors = 0xcfdabfad, 12977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_fifo_errors = 0xddfdebad, 13077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_missed_errors = 0xefabdcba, 13177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_aborted_errors = 0xefdadbfa, 13277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_carrier_errors = 0xfaefbada, 13377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_fifo_errors = 0xaebdffab, 13477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_heartbeat_errors = 0xbadebaaf, 13577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_window_errors = 0xcdafbada, 13677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_compressed = 0xdeffadbd, 13777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_compressed = 0xefdadfab 13877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes }; 13977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, 14077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes init_ifinfomsg, print_ifinfomsg, 14177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes IFLA_STATS, pattern, st, 14277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U("{", st, rx_packets); 14377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_packets); 14477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_bytes); 14577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_bytes); 14677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_errors); 14777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_errors); 14877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_dropped); 14977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_dropped); 15077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, multicast); 15177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, collisions); 15277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_length_errors); 15377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_over_errors); 15477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_crc_errors); 15577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_frame_errors); 15677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_fifo_errors); 15777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_missed_errors); 15877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_aborted_errors); 15977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_carrier_errors); 16077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_fifo_errors); 16177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_heartbeat_errors); 16277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_window_errors); 16377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_compressed); 16477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_compressed); 16577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#ifdef HAVE_STRUCT_RTNL_LINK_STATS_RX_NOHANDLER 16677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_nohandler); 16777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#endif 16877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes printf("}")); 16977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 17077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#ifdef HAVE_STRUCT_RTNL_LINK_STATS_RX_NOHANDLER 17177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes const unsigned int sizeof_stats = 17277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes offsetofend(struct rtnl_link_stats, tx_compressed); 17377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes TEST_NLATTR(fd, nlh0, hdrlen, 17477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes init_ifinfomsg, print_ifinfomsg, 17577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes IFLA_STATS, sizeof_stats, &st, sizeof_stats, 17677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U("{", st, rx_packets); 17777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_packets); 17877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_bytes); 17977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_bytes); 18077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_errors); 18177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_errors); 18277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_dropped); 18377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_dropped); 18477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, multicast); 18577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, collisions); 18677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_length_errors); 18777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_over_errors); 18877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_crc_errors); 18977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_frame_errors); 19077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_fifo_errors); 19177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_missed_errors); 19277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_aborted_errors); 19377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_carrier_errors); 19477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_fifo_errors); 19577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_heartbeat_errors); 19677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_window_errors); 19777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, rx_compressed); 19877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st, tx_compressed); 19977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes printf("}")); 20077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#endif /* HAVE_STRUCT_RTNL_LINK_STATS_RX_NOHANDLER */ 20177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 20277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes static const struct rtnl_link_ifmap map = { 20377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .mem_start = 0xadcbefedefbcdedb, 20477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .mem_end = 0xefcbeabdecdcdefa, 20577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .base_addr = 0xaddbeabdfaacdbae, 20677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .irq = 0xefaf, 20777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .dma = 0xab, 20877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .port = 0xcd 20977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes }; 21077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes const unsigned int sizeof_ifmap = 21177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes offsetofend(struct rtnl_link_ifmap, port); 21277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes const unsigned int plen = sizeof_ifmap - 1 > DEFAULT_STRLEN 21377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes ? DEFAULT_STRLEN 21477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes : (int) sizeof_ifmap - 1; 21577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes /* len < sizeof_ifmap */ 21677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes TEST_NLATTR(fd, nlh0, hdrlen, 21777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes init_ifinfomsg, print_ifinfomsg, 21877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes IFLA_MAP, plen, pattern, plen, 21977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes print_quoted_hex(pattern, plen)); 22077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 22177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes /* short read of sizeof_ifmap */ 22277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes TEST_NLATTR(fd, nlh0, hdrlen, 22377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes init_ifinfomsg, print_ifinfomsg, 22477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes IFLA_MAP, sizeof_ifmap, &map, sizeof_ifmap - 1, 22577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes printf("%p", RTA_DATA(TEST_NLATTR_nla))); 22677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 22777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes /* sizeof_ifmap */ 22877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes TEST_NLATTR(fd, nlh0, hdrlen, 22977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes init_ifinfomsg, print_ifinfomsg, 23077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes IFLA_MAP, sizeof_ifmap, &map, sizeof_ifmap, 23177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_X("{", map, mem_start); 23277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_X(", ", map, mem_end); 23377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_X(", ", map, base_addr); 23477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", map, irq); 23577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", map, dma); 23677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", map, port); 23777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes printf("}")); 23877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 23977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#ifdef HAVE_STRUCT_RTNL_LINK_STATS64 24077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes static const struct rtnl_link_stats64 st64 = { 24177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_packets = 0xadcbefedefbcdedb, 24277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_packets = 0xbdabdedabdcdeabd, 24377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_bytes = 0xcdbaefbaeadfabec, 24477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_bytes = 0xdbaedbafabbeacdb, 24577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_errors = 0xefabfdaefabaefab, 24677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_errors = 0xfaebfabfabbaeabf, 24777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_dropped = 0xacdbaedbadbabeba, 24877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_dropped = 0xbcdeffebdabeadbe, 24977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .multicast = 0xeeffbaeabaeffabe, 25077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .collisions = 0xffbaefcefbafacef, 25177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_length_errors = 0xaabbdeabceffdecb, 25277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_over_errors = 0xbbdcdadebadeaeed, 25377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_crc_errors= 0xccdeabecefaedbef, 25477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_frame_errors = 0xddbedaedebcedaef, 25577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_fifo_errors = 0xeffbadefafdaeaab, 25677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_missed_errors = 0xfefaebccceadeecd, 25777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_aborted_errors = 0xabcdadefcdadef, 25877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_carrier_errors = 0xbccdafaeeaaefe, 25977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_fifo_errors = 0xcddefdbedeadce, 26077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_heartbeat_errors = 0xedaededdadcdea, 26177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_window_errors = 0xfdacdeaccedcda, 26277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .rx_compressed = 0xacdbbcacdbccef, 26377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .tx_compressed = 0xbcdadefcdedfea 26477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes }; 26577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, 26677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes init_ifinfomsg, print_ifinfomsg, 26777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes IFLA_STATS64, pattern, st64, 26877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U("{", st64, rx_packets); 26977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_packets); 27077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_bytes); 27177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_bytes); 27277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_errors); 27377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_errors); 27477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_dropped); 27577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_dropped); 27677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, multicast); 27777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, collisions); 27877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_length_errors); 27977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_over_errors); 28077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_crc_errors); 28177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_frame_errors); 28277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_fifo_errors); 28377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_missed_errors); 28477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_aborted_errors); 28577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_carrier_errors); 28677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_fifo_errors); 28777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_heartbeat_errors); 28877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_window_errors); 28977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_compressed); 29077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_compressed); 29177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#ifdef HAVE_STRUCT_RTNL_LINK_STATS64_RX_NOHANDLER 29277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_nohandler); 29377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#endif 29477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes printf("}")); 29577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 29677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#ifdef HAVE_STRUCT_RTNL_LINK_STATS64_RX_NOHANDLER 29777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes const unsigned int sizeof_stats64 = 29877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes offsetofend(struct rtnl_link_stats64, tx_compressed); 29977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes TEST_NLATTR(fd, nlh0, hdrlen, 30077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes init_ifinfomsg, print_ifinfomsg, 30177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes IFLA_STATS64, sizeof_stats64, &st64, sizeof_stats64, 30277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U("{", st64, rx_packets); 30377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_packets); 30477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_bytes); 30577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_bytes); 30677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_errors); 30777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_errors); 30877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_dropped); 30977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_dropped); 31077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, multicast); 31177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, collisions); 31277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_length_errors); 31377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_over_errors); 31477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_crc_errors); 31577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_frame_errors); 31677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_fifo_errors); 31777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_missed_errors); 31877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_aborted_errors); 31977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_carrier_errors); 32077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_fifo_errors); 32177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_heartbeat_errors); 32277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_window_errors); 32377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, rx_compressed); 32477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes PRINT_FIELD_U(", ", st64, tx_compressed); 32577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes printf("}")); 32677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#endif /* HAVE_STRUCT_RTNL_LINK_STATS64_RX_NOHANDLER */ 32777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes#endif /* HAVE_STRUCT_RTNL_LINK_STATS64 */ 32877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 32977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes struct nlattr nla = { 33077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .nla_len = sizeof(nla), 33177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes .nla_type = IFLA_INFO_KIND, 33277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes }; 33377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes TEST_NLATTR(fd, nlh0, hdrlen, 33477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes init_ifinfomsg, print_ifinfomsg, 33577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes IFLA_LINKINFO, sizeof(nla), &nla, sizeof(nla), 33677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes printf("{nla_len=%u, nla_type=IFLA_INFO_KIND}", 33777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes nla.nla_len)); 33877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 33977c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes nla.nla_type = IFLA_VF_PORT; 34077c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes TEST_NLATTR(fd, nlh0, hdrlen, 34177c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes init_ifinfomsg, print_ifinfomsg, 34277c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes IFLA_VF_PORTS, sizeof(nla), &nla, sizeof(nla), 34377c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes printf("{nla_len=%u, nla_type=IFLA_VF_PORT}", 34477c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes nla.nla_len)); 34577c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes 34677c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes puts("+++ exited with 0 +++"); 34777c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes return 0; 34877c3ff8e0644f1e120e4b2ebc7222150b0446f3bElliott Hughes} 349