Veerendra wrote:
Signed-off-by: Veerendra C <[EMAIL PROTECTED]>

This patch consists of the files..

containers/libclone/libclone.h
containers/libclone/libnetns.c
containers/libclone/Makefile


Regards
Veerendra C

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"lxc-dev" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/lxc-dev?hl=en
-~----------~----~----~----~------~----~------~--~---


Attaching the patch..

Index: containers/libclone/libclone.h
===================================================================
--- containers.orig/libclone/libclone.h
+++ containers/libclone/libclone.h
@@ -58,6 +58,46 @@ extern int  __clone2(int (*fn) (void *ar
                 pid_t *parent_tid, void *tls, pid_t *child_tid);
 #endif
 
+#ifndef HAVE_UNSHARE
+
+#if __i386__
+#    define __NR_unshare 310
+#elif __x86_64__
+#    define __NR_unshare 272
+#elif __ia64__
+#    define __NR_unshare 1296
+#elif __s390x__
+#    define __NR_unshare 303
+#elif __powerpc__
+#    define __NR_unshare 282
+#else
+#    error "Architecture not supported"
+#endif
+
+static inline int unshare(unsigned long flags)
+{
+        return syscall(__NR_unshare, flags);
+}
+
+#endif /* HAVE_UNSHARE */
+
+#if __i386__
+#    define __NR_clone64       333
+#    define __NR_unshare64     334
+#elif __powerpc__
+#    define __NR_clone64       313
+#    define __NR_unshare64     314
+#elif __s390x__ || __s390__
+#    define __NR_clone64       322
+#    define __NR_unshare64     323
+#elif __x86_64__
+#    define __NR_clone64       295
+#    define __NR_unshare64     296
+#else
+#    error "Architecture not supported"
+#endif
+
+
 #ifndef CLONE_NEWUTS
 #define CLONE_NEWUTS		0x04000000
 #endif
@@ -74,6 +114,10 @@ extern int  __clone2(int (*fn) (void *ar
 #define CLONE_NEWPID            0x20000000
 #endif
 
+#ifndef CLONE_NEWNET
+#define CLONE_NEWNET		0x40000000
+#endif
+
 /*
  * Run fn1 in a unshared environmnent, and fn2 in the original context
  * Fn2 may be NULL.
@@ -97,4 +141,10 @@ int do_clone_unshare_tests(int use_clone
 			int (*fn1)(void *arg), void *arg1,
 			int (*fn2)(void *arg), void *arg2);
 
+static inline int unshare64(unsigned long long int flags)
+{
+       return syscall(__NR_unshare64, (unsigned long) (flags >> 32), 
+                      (unsigned long) (flags & 0xffffffff));
+}
+
 #endif
Index: containers/libclone/libnetns.c
===================================================================
--- /dev/null
+++ containers/libclone/libnetns.c
@@ -0,0 +1,105 @@
+/*
+* Copyright (c) International Business Machines Corp., 2007
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+* the GNU General Public License for more details.
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+***************************************************************************/
+/*=========================================================================
+* This testcase creates the network namespace. 
+* It creates veth pair veth8 & veth9. Also assigns IP addresses to the childNS.
+* Also it starts the sshd daemon @ port 7890
+*
+* Scripts Used: parentns.sh childns.sh
+=========================================================================*/
+
+#include <sys/utsname.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "libclone.h"
+#include <sched.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <signal.h>
+#include <string.h>
+#include <errno.h>
+#include <libgen.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+ 
+extern pid_t getpgid(pid_t pid);
+extern pid_t getsid(pid_t pid);
+
+int crtchild(char *s1 , char *s2)
+{
+    char *cmd[] = { "/bin/bash", s1, s2, (char *)0 };
+    execve("/bin/bash", cmd, __environ);
+    printf("The code would not reach here on success\n");
+    perror("execve");
+    return 1;
+}
+
+int create_net_namespace(char *p1, char *c1)
+{
+	int pid, status, ret;
+    long long flags = 0;
+    char par[256], child[256];
+    char path[128];
+
+	if (tst_kvercmp(2,6,19) < 0)
+		return 1;
+
+    if (ret = getenv("LTPROOT")) {
+        sprintf(path,"%s%s",getenv("LTPROOT"),"/testcases/kernel/containers/netns/");
+    } 
+    else{
+        printf("LTPROOT env variable is not set\n");
+        printf("Please set LTPROOT and re-run the test.. Thankyou\n");
+        return -1;
+    } 
+
+    flags |= CLONE_NEWNS;
+    flags |= CLONE_NEWNET;
+
+    sprintf(par , "%s%s %s", path, "parentns.sh", p1);
+    sprintf(child , "%s%s", path,"childns.sh");
+
+    if ((pid = fork()) == 0) {
+
+        // Child.
+        ret = unshare64(flags);
+        if (ret < 0) {
+            perror("unshare");
+            return 1;
+        }
+    return crtchild(child,c1);
+    }
+    else{
+
+        //parent
+        ret = system(par);
+        if (ret != 0) {
+            printf("Error not able to assign the pid to the net\n");
+            fflush(stdout);
+            exit(1);
+        }
+    fflush(stdout);
+
+    if ((ret = waitpid(pid, &status, __WALL)) < 0){
+        printf("waitpid() returns %d, errno %d\n", ret, errno);
+        return errno;
+    }
+    return 0;
+    }
+}
Index: containers/libclone/Makefile
===================================================================
--- containers.orig/libclone/Makefile
+++ containers/libclone/Makefile
@@ -18,7 +18,7 @@
 ##                                                                            ##
 ################################################################################
 
-TARGET=libclone.a
+TARGET=libclone.a libnetns.a
 SRCS=$(wildcard *.c)
 OBJS=$(patsubst %.c,%.o,$(SRCS))
 
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to