1 /* 2 * 3 * Copyright (c) Rusty Russell <rusty (at) 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 (at) rustcorp.com.au> 35 * 36 * History: Created - Nov 28 2008 - Rusty Russell <rusty (at) rustcorp.com.au> 37 * Ported to LTP 38 * - Nov 28 2008 - Subrata <subrata (at) linux.vnet.ibm.com> 39 */ 40 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> 47 #include <linux/if_tun.h> 48 49 #include "test.h" 50 51 #ifndef TUNGETFEATURES 52 #define TUNGETFEATURES _IOR('T', 207, unsigned int) 53 #endif 54 55 #ifndef IFF_VNET_HDR 56 #define IFF_VNET_HDR 0x4000 57 #endif 58 59 #ifndef IFF_MULTI_QUEUE 60 #define IFF_MULTI_QUEUE 0x0100 61 #endif 62 63 char *TCID = "ioctl03"; 64 int TST_TOTAL = 1; 65 66 static void cleanup(void) 67 { 68 tst_rmdir(); 69 } 70 71 static void setup(void) 72 { 73 TEST_PAUSE; 74 tst_tmpdir(); 75 } 76 77 static struct { 78 unsigned int flag; 79 const char *name; 80 } known_flags[] = { 81 { 82 IFF_TUN, "TUN"}, { 83 IFF_TAP, "TAP"}, { 84 IFF_NO_PI, "NO_PI"}, { 85 IFF_ONE_QUEUE, "ONE_QUEUE"}, { 86 IFF_VNET_HDR, "VNET_HDR"}, { 87 IFF_MULTI_QUEUE, "MULTI_QUEUE"} 88 }; 89 90 int main(void) 91 { 92 unsigned int features, i; 93 94 setup(); 95 tst_require_root(); 96 97 int netfd = open("/dev/net/tun", O_RDWR); 98 if (netfd < 0) 99 tst_brkm(TBROK | TERRNO, cleanup, 100 "opening /dev/net/tun failed"); 101 102 if (ioctl(netfd, TUNGETFEATURES, &features) != 0) 103 tst_brkm(TCONF, cleanup, 104 "Kernel does not support TUNGETFEATURES"); 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(); 117 } 118