Wanlong Gao | a8e7b2f | 2012-11-05 11:19:57 +0800 | [diff] [blame] | 1 | /* |
| 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_modak | 7b3d3d2 | 2008-12-12 14:19:13 +0000 | [diff] [blame] | 40 | |
subrata_modak | 7b3d3d2 | 2008-12-12 14:19:13 +0000 | [diff] [blame] | 41 | #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_modak | e3ca5de | 2008-12-22 07:21:41 +0000 | [diff] [blame] | 47 | #include <linux/if_tun.h> |
subrata_modak | 7b3d3d2 | 2008-12-12 14:19:13 +0000 | [diff] [blame] | 48 | |
subrata_modak | 7b3d3d2 | 2008-12-12 14:19:13 +0000 | [diff] [blame] | 49 | #include "test.h" |
subrata_modak | 7b3d3d2 | 2008-12-12 14:19:13 +0000 | [diff] [blame] | 50 | |
| 51 | #ifndef TUNGETFEATURES |
| 52 | #define TUNGETFEATURES _IOR('T', 207, unsigned int) |
| 53 | #endif |
| 54 | |
Wanlong Gao | 5f16816 | 2012-12-17 13:43:45 +0800 | [diff] [blame] | 55 | #ifndef IFF_VNET_HDR |
subrata_modak | e3ca5de | 2008-12-22 07:21:41 +0000 | [diff] [blame] | 56 | #define IFF_VNET_HDR 0x4000 |
| 57 | #endif |
| 58 | |
Wanlong Gao | 6180d13 | 2012-12-17 13:47:03 +0800 | [diff] [blame] | 59 | #ifndef IFF_MULTI_QUEUE |
| 60 | #define IFF_MULTI_QUEUE 0x0100 |
| 61 | #endif |
| 62 | |
Wanlong Gao | a8e7b2f | 2012-11-05 11:19:57 +0800 | [diff] [blame] | 63 | char *TCID = "ioctl03"; |
| 64 | int TST_TOTAL = 1; |
subrata_modak | 7b3d3d2 | 2008-12-12 14:19:13 +0000 | [diff] [blame] | 65 | |
Wanlong Gao | a8e7b2f | 2012-11-05 11:19:57 +0800 | [diff] [blame] | 66 | static void cleanup(void) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 67 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 68 | tst_rmdir(); |
subrata_modak | 7b3d3d2 | 2008-12-12 14:19:13 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Wanlong Gao | a8e7b2f | 2012-11-05 11:19:57 +0800 | [diff] [blame] | 71 | static void setup(void) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 72 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 73 | TEST_PAUSE; |
| 74 | tst_tmpdir(); |
subrata_modak | 7b3d3d2 | 2008-12-12 14:19:13 +0000 | [diff] [blame] | 75 | } |
| 76 | |
subrata_modak | 7b3d3d2 | 2008-12-12 14:19:13 +0000 | [diff] [blame] | 77 | static struct { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 78 | unsigned int flag; |
| 79 | const char *name; |
subrata_modak | 7b3d3d2 | 2008-12-12 14:19:13 +0000 | [diff] [blame] | 80 | } known_flags[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 81 | { |
| 82 | IFF_TUN, "TUN"}, { |
| 83 | IFF_TAP, "TAP"}, { |
| 84 | IFF_NO_PI, "NO_PI"}, { |
| 85 | IFF_ONE_QUEUE, "ONE_QUEUE"}, { |
Wanlong Gao | 6180d13 | 2012-12-17 13:47:03 +0800 | [diff] [blame] | 86 | IFF_VNET_HDR, "VNET_HDR"}, { |
| 87 | IFF_MULTI_QUEUE, "MULTI_QUEUE"} |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 88 | }; |
subrata_modak | 7b3d3d2 | 2008-12-12 14:19:13 +0000 | [diff] [blame] | 89 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 90 | int main(void) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 91 | { |
| 92 | unsigned int features, i; |
subrata_modak | 7b3d3d2 | 2008-12-12 14:19:13 +0000 | [diff] [blame] | 93 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 94 | setup(); |
Garrett Cooper | 04d4f10 | 2010-12-19 05:09:19 -0800 | [diff] [blame] | 95 | tst_require_root(NULL); |
| 96 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 97 | int netfd = open("/dev/net/tun", O_RDWR); |
| 98 | if (netfd < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 99 | tst_brkm(TBROK | TERRNO, cleanup, |
| 100 | "opening /dev/net/tun failed"); |
subrata_modak | 7b3d3d2 | 2008-12-12 14:19:13 +0000 | [diff] [blame] | 101 | |
Garrett Cooper | 04d4f10 | 2010-12-19 05:09:19 -0800 | [diff] [blame] | 102 | if (ioctl(netfd, TUNGETFEATURES, &features) != 0) |
| 103 | tst_brkm(TCONF, cleanup, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 104 | "Kernel does not support TUNGETFEATURES"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 105 | 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 Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 117 | } |