blob: 89a4666d239d390a970434b378e68b48416a6eb3 [file] [log] [blame]
Wanlong Gaoa8e7b2f2012-11-05 11:19:57 +08001/*
2 *
3 * Copyright (c) Rusty Russell <rusty@rustcorp.com.au>
4 * Copyright (c) International Business Machines Corp., 2008
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 * the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/*
22 *
23 *
24 * File: ioctl03.c
25 *
26 * Description: This program tests whether all the valid IFF flags are
27 * returned properly by implementation of TUNGETFEATURES ioctl
28 * on kernel 2.6.27
29 *
30 * Total Tests: 1
31 *
32 * Test Name: ioctl03
33 *
34 * Author: Rusty Russell <rusty@rustcorp.com.au>
35 *
36 * History: Created - Nov 28 2008 - Rusty Russell <rusty@rustcorp.com.au>
37 * Ported to LTP
38 * - Nov 28 2008 - Subrata <subrata@linux.vnet.ibm.com>
39 */
subrata_modak7b3d3d22008-12-12 14:19:13 +000040
subrata_modak7b3d3d22008-12-12 14:19:13 +000041#include <sys/types.h>
42#include <sys/ioctl.h>
43#include <sys/stat.h>
44#include <fcntl.h>
45#include <errno.h>
46#include <stdio.h>
subrata_modake3ca5de2008-12-22 07:21:41 +000047#include <linux/if_tun.h>
subrata_modak7b3d3d22008-12-12 14:19:13 +000048
subrata_modak7b3d3d22008-12-12 14:19:13 +000049#include "test.h"
subrata_modak7b3d3d22008-12-12 14:19:13 +000050
51#ifndef TUNGETFEATURES
52#define TUNGETFEATURES _IOR('T', 207, unsigned int)
53#endif
54
Wanlong Gao5f168162012-12-17 13:43:45 +080055#ifndef IFF_VNET_HDR
subrata_modake3ca5de2008-12-22 07:21:41 +000056#define IFF_VNET_HDR 0x4000
57#endif
58
Wanlong Gao6180d132012-12-17 13:47:03 +080059#ifndef IFF_MULTI_QUEUE
60#define IFF_MULTI_QUEUE 0x0100
61#endif
62
Wanlong Gaoa8e7b2f2012-11-05 11:19:57 +080063char *TCID = "ioctl03";
64int TST_TOTAL = 1;
subrata_modak7b3d3d22008-12-12 14:19:13 +000065
Wanlong Gaoa8e7b2f2012-11-05 11:19:57 +080066static void cleanup(void)
subrata_modak56207ce2009-03-23 13:35:39 +000067{
subrata_modak56207ce2009-03-23 13:35:39 +000068 tst_rmdir();
subrata_modak7b3d3d22008-12-12 14:19:13 +000069}
70
Wanlong Gaoa8e7b2f2012-11-05 11:19:57 +080071static void setup(void)
subrata_modak56207ce2009-03-23 13:35:39 +000072{
subrata_modak56207ce2009-03-23 13:35:39 +000073 TEST_PAUSE;
74 tst_tmpdir();
subrata_modak7b3d3d22008-12-12 14:19:13 +000075}
76
subrata_modak7b3d3d22008-12-12 14:19:13 +000077static struct {
subrata_modak56207ce2009-03-23 13:35:39 +000078 unsigned int flag;
79 const char *name;
subrata_modak7b3d3d22008-12-12 14:19:13 +000080} known_flags[] = {
subrata_modak56207ce2009-03-23 13:35:39 +000081 {
82 IFF_TUN, "TUN"}, {
83 IFF_TAP, "TAP"}, {
84 IFF_NO_PI, "NO_PI"}, {
85 IFF_ONE_QUEUE, "ONE_QUEUE"}, {
Wanlong Gao6180d132012-12-17 13:47:03 +080086 IFF_VNET_HDR, "VNET_HDR"}, {
87 IFF_MULTI_QUEUE, "MULTI_QUEUE"}
subrata_modak56207ce2009-03-23 13:35:39 +000088};
subrata_modak7b3d3d22008-12-12 14:19:13 +000089
Mike Frysingerc57fba52014-04-09 18:56:30 -040090int main(void)
subrata_modak56207ce2009-03-23 13:35:39 +000091{
92 unsigned int features, i;
subrata_modak7b3d3d22008-12-12 14:19:13 +000093
subrata_modak56207ce2009-03-23 13:35:39 +000094 setup();
Garrett Cooper04d4f102010-12-19 05:09:19 -080095 tst_require_root(NULL);
96
subrata_modak56207ce2009-03-23 13:35:39 +000097 int netfd = open("/dev/net/tun", O_RDWR);
98 if (netfd < 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +080099 tst_brkm(TBROK | TERRNO, cleanup,
100 "opening /dev/net/tun failed");
subrata_modak7b3d3d22008-12-12 14:19:13 +0000101
Garrett Cooper04d4f102010-12-19 05:09:19 -0800102 if (ioctl(netfd, TUNGETFEATURES, &features) != 0)
103 tst_brkm(TCONF, cleanup,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800104 "Kernel does not support TUNGETFEATURES");
subrata_modak56207ce2009-03-23 13:35:39 +0000105 tst_resm(TINFO, "Available features are: %#x", features);
106 for (i = 0; i < sizeof(known_flags) / sizeof(known_flags[0]); i++) {
107 if (features & known_flags[i].flag) {
108 features &= ~known_flags[i].flag;
109 tst_resm(TINFO, "%s %#x", known_flags[i].name,
110 known_flags[i].flag);
111 }
112 }
113 if (features)
114 tst_resm(TFAIL, "(UNKNOWN %#x)", features);
115 cleanup();
116 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700117}