subrata_modak | a73a850 | 2008-09-19 12:17:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) International Business Machines Corp., 2008 |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 11 | * the GNU General Public License for more details. |
| 12 | * You should have received a copy of the GNU General Public License |
| 13 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
subrata_modak | a73a850 | 2008-09-19 12:17:10 +0000 | [diff] [blame] | 15 | * |
| 16 | * Author: Veerendra C <vechandr@in.ibm.com> |
| 17 | * |
| 18 | * Net namespaces were introduced around 2.6.25. Kernels before that, |
| 19 | * assume they are not enabled. Kernels after that, check for -EINVAL |
| 20 | * when trying to use CLONE_NEWNET and CLONE_NEWNS. |
| 21 | ***************************************************************************/ |
| 22 | #include <stdio.h> |
| 23 | #include <sched.h> |
yaberauneya | eea384d | 2010-02-10 23:12:53 +0000 | [diff] [blame] | 24 | #include "config.h" |
yaberauneya | 98379aa | 2010-02-10 23:24:45 +0000 | [diff] [blame] | 25 | #include "libclone.h" |
yaberauneya | eea384d | 2010-02-10 23:12:53 +0000 | [diff] [blame] | 26 | #include "linux_syscall_numbers.h" |
subrata_modak | a73a850 | 2008-09-19 12:17:10 +0000 | [diff] [blame] | 27 | #include "test.h" |
| 28 | |
yaberauneya | 98379aa | 2010-02-10 23:24:45 +0000 | [diff] [blame] | 29 | char *TCID = "check_netns_enabled"; |
| 30 | int TST_COUNT = 1; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 31 | int TST_TOTAL = 1; |
yaberauneya | 98379aa | 2010-02-10 23:24:45 +0000 | [diff] [blame] | 32 | |
yaberauneya | eea384d | 2010-02-10 23:12:53 +0000 | [diff] [blame] | 33 | #ifndef CLONE_NEWNET |
| 34 | #define CLONE_NEWNET -1 |
| 35 | #endif |
| 36 | |
| 37 | #ifndef CLONE_NEWNS |
| 38 | #define CLONE_NEWNS -1 |
| 39 | #endif |
| 40 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 41 | int main(void) |
subrata_modak | a73a850 | 2008-09-19 12:17:10 +0000 | [diff] [blame] | 42 | { |
yaberauneya | 98379aa | 2010-02-10 23:24:45 +0000 | [diff] [blame] | 43 | /* Checking if the kernel supports unshare with netns capabilities. */ |
Garrett Cooper | ad14e90 | 2010-12-16 10:03:44 -0800 | [diff] [blame] | 44 | if (CLONE_NEWNET == -1 || CLONE_NEWNS == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 45 | tst_resm(TBROK | TERRNO, |
| 46 | "CLONE_NEWNET (%d) or CLONE_NEWNS (%d) not supported", |
| 47 | CLONE_NEWNET, CLONE_NEWNS); |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 48 | else if (ltp_syscall(__NR_unshare, CLONE_NEWNET | CLONE_NEWNS) == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 49 | tst_resm(TFAIL | TERRNO, "unshare syscall smoke test failed"); |
Garrett Cooper | ad14e90 | 2010-12-16 10:03:44 -0800 | [diff] [blame] | 50 | else |
| 51 | tst_resm(TPASS, "unshare syscall smoke test passed"); |
yaberauneya | 98379aa | 2010-02-10 23:24:45 +0000 | [diff] [blame] | 52 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 53 | } |