• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
3  * Copyright (c) 2017-2018 The strace developers.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "tests.h"
30 
31 #include <stdio.h>
32 #include "test_nlattr.h"
33 #include <linux/if.h>
34 #include <linux/if_arp.h>
35 #ifdef HAVE_LINUX_IF_LINK_H
36 # include <linux/if_link.h>
37 #endif
38 #include <linux/rtnetlink.h>
39 
40 #if !HAVE_DECL_IFLA_PORT_SELF
41 enum { IFLA_PORT_SELF = 25 };
42 #endif
43 #ifndef IFLA_PORT_VF
44 # define IFLA_PORT_VF 1
45 #endif
46 
47 #define IFLA_ATTR IFLA_PORT_SELF
48 #include "nlattr_ifla.h"
49 
50 int
main(void)51 main(void)
52 {
53 	skip_if_unavailable("/proc/self/fd/");
54 
55 	const int fd = create_nl_socket(NETLINK_ROUTE);
56 	void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), 2 * NLA_HDRLEN + 8);
57 
58 	static char pattern[4096];
59 	fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
60 
61 	const uint32_t num = 0xabacdbcd;
62 	TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen,
63 				  init_ifinfomsg, print_ifinfomsg,
64 				  IFLA_PORT_VF, pattern, num,
65 				  printf("%u", num));
66 
67 #ifdef HAVE_STRUCT_IFLA_PORT_VSI
68 	static const struct ifla_port_vsi vsi = {
69 		.vsi_mgr_id = 0xab,
70 		.vsi_type_id = "abc",
71 		.vsi_type_version = 0xef
72 	};
73 	TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen,
74 				  init_ifinfomsg, print_ifinfomsg,
75 				  IFLA_PORT_VSI_TYPE, pattern, vsi,
76 				  PRINT_FIELD_U("{", vsi, vsi_mgr_id);
77 				  printf(", vsi_type_id=\"\\x61\\x62\\x63\"");
78 				  PRINT_FIELD_U(", ", vsi, vsi_type_version);
79 				  printf("}"));
80 #endif
81 
82 	puts("+++ exited with 0 +++");
83 	return 0;
84 }
85