blob: ab8ee2fd014fe1d0d53925c25a3560331b624325 [file] [log] [blame]
subrata_modaka73a8502008-09-19 12:17:10 +00001/*
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 Gao4548c6c2012-10-19 18:03:36 +080014* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
subrata_modaka73a8502008-09-19 12:17:10 +000015*
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>
yaberauneyaeea384d2010-02-10 23:12:53 +000024#include "config.h"
yaberauneya98379aa2010-02-10 23:24:45 +000025#include "libclone.h"
yaberauneyaeea384d2010-02-10 23:12:53 +000026#include "linux_syscall_numbers.h"
subrata_modaka73a8502008-09-19 12:17:10 +000027#include "test.h"
28
yaberauneya98379aa2010-02-10 23:24:45 +000029char *TCID = "check_netns_enabled";
30int TST_COUNT = 1;
Garrett Cooper2c282152010-12-16 00:55:50 -080031int TST_TOTAL = 1;
yaberauneya98379aa2010-02-10 23:24:45 +000032
yaberauneyaeea384d2010-02-10 23:12:53 +000033#ifndef CLONE_NEWNET
34#define CLONE_NEWNET -1
35#endif
36
37#ifndef CLONE_NEWNS
38#define CLONE_NEWNS -1
39#endif
40
Wanlong Gao354ebb42012-12-07 10:10:04 +080041int main(void)
subrata_modaka73a8502008-09-19 12:17:10 +000042{
yaberauneya98379aa2010-02-10 23:24:45 +000043 /* Checking if the kernel supports unshare with netns capabilities. */
Garrett Cooperad14e902010-12-16 10:03:44 -080044 if (CLONE_NEWNET == -1 || CLONE_NEWNS == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +080045 tst_resm(TBROK | TERRNO,
46 "CLONE_NEWNET (%d) or CLONE_NEWNS (%d) not supported",
47 CLONE_NEWNET, CLONE_NEWNS);
Jan Stancek359980f2013-02-15 10:16:05 +010048 else if (ltp_syscall(__NR_unshare, CLONE_NEWNET | CLONE_NEWNS) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +080049 tst_resm(TFAIL | TERRNO, "unshare syscall smoke test failed");
Garrett Cooperad14e902010-12-16 10:03:44 -080050 else
51 tst_resm(TPASS, "unshare syscall smoke test passed");
yaberauneya98379aa2010-02-10 23:24:45 +000052 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -070053}