dns_unbound.patch
author Hajime Tazaki <tazaki@nict.go.jp>
Wed, 04 Jul 2012 17:06:26 +0900
changeset 24 02787e1dfd96
parent 20 5ca51e147e7f
permissions -rw-r--r--
cleanup patch

diff -r 70496fb51ab2 example/dce-unbound.cc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/dce-unbound.cc	Wed Jul 04 16:59:42 2012 +0900
@@ -0,0 +1,98 @@
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/dce-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/csma-module.h"
+#include "ns3/wifi-module.h"
+#include "ns3/mobility-module.h"
+#include <fstream>
+
+using namespace ns3;
+
+static void RunIp (Ptr<Node> node, Time at, std::string str)
+{
+  DceApplicationHelper process;
+  ApplicationContainer apps;
+  process.SetBinary ("ip");
+  process.SetStackSize (1<<16);
+  process.ResetArguments();
+  process.ParseArguments(str.c_str ());
+  apps = process.Install (node);
+  apps.Start (at);
+}
+
+static void AddAddress (Ptr<Node> node, Time at, const char *name, const std::string prefixAddr,
+                        int number, std::string suffixAddr)
+{
+  std::ostringstream oss;
+  oss << "-f inet addr add " << prefixAddr << number << suffixAddr << " dev " << name;
+  RunIp (node, at, oss.str ());
+}
+
+int main (int argc, char *argv[])
+{
+  CommandLine cmd;
+  cmd.Parse (argc, argv);
+
+  NodeContainer nodes;
+  nodes.Create (2);
+
+  NetDeviceContainer devices;
+
+  PointToPointHelper p2p;
+  p2p.SetDeviceAttribute ("DataRate", StringValue ("5Gbps"));
+  p2p.SetChannelAttribute ("Delay", StringValue ("1ms"));
+  devices = p2p.Install (nodes);
+  p2p.EnablePcapAll ("process-unbound");
+
+  DceManagerHelper processManager;
+  processManager.SetLoader ("ns3::DlmLoaderFactory");
+  // processManager.SetTaskManagerAttribute ("FiberManagerType",
+  //                                         EnumValue (0));
+  processManager.SetNetworkStack("ns3::LinuxSocketFdFactory",
+				 "Library", StringValue ("libnet-next-2.6.so"));
+  processManager.Install (nodes);
+
+  for (int n=0; n < 2; n++)
+    {
+      AddAddress (nodes.Get (n), Seconds (0.1), "sim0", "10.0.0.", 2 + n, "/8" );
+      RunIp (nodes.Get (n), Seconds (0.11), "link set sim0 up arp off");
+      RunIp (nodes.Get (n), Seconds (0.2), "link show");
+      RunIp (nodes.Get (n), Seconds (0.3), "route show table all");
+      RunIp (nodes.Get (n), Seconds (0.4), "addr list");
+    }
+  RunIp (nodes.Get (1), Seconds (1.2), "route add default via 10.0.0.2 dev sim0");
+
+  DceApplicationHelper process;
+  ApplicationContainer apps;
+
+  process.SetBinary ("unbound");
+  process.ResetArguments ();
+  process.ParseArguments ("-d");
+  process.SetStackSize (1<<16);
+  apps = process.Install (nodes.Get (0));
+  apps.Start (Seconds (1.0));
+
+  for (int i = 0; i < 20; i++)
+    {
+      process.SetBinary ("unbound-host");
+      process.ResetArguments ();
+      process.ParseArguments ("www.example.com");
+      process.ParseArguments ("-d");
+      process.ParseArguments ("-d");
+      process.ParseArguments ("-v");
+      process.ParseArguments ("-r");
+      process.ParseArguments ("-f");
+      process.ParseArguments ("/etc/root.key");
+      apps = process.Install (nodes.Get (1));
+
+      apps.Start (Seconds (1+ 10*i));
+    }
+
+
+  Simulator::Stop (Seconds (2000000.0));
+  Simulator::Run ();
+  Simulator::Destroy ();
+
+  return 0;
+}
diff -r 70496fb51ab2 model/dce-credentials.cc
--- a/model/dce-credentials.cc	Wed Jul 04 16:58:26 2012 +0900
+++ b/model/dce-credentials.cc	Wed Jul 04 16:59:42 2012 +0900
@@ -53,3 +53,15 @@
   int ret = eaccess (rPath.c_str (), mode);
   return ret;
 }
+
+int dce_chown(const char *path, uid_t owner, gid_t group)
+{
+  // XXX
+  return 0;
+}
+
+int dce_initgroups(const char *user, gid_t group)
+{
+  // XXX
+  return 0;
+}
diff -r 70496fb51ab2 model/dce-stdio.cc
--- a/model/dce-stdio.cc	Wed Jul 04 16:58:26 2012 +0900
+++ b/model/dce-stdio.cc	Wed Jul 04 16:59:42 2012 +0900
@@ -722,6 +722,16 @@
   va_end (ap);
   return retval;
 }
+int dce___vsnprintf_chk (char *__restrict __s, size_t __n, int __flag,
+						size_t __slen,
+						__const char *__restrict __format, _G_va_list __ap)
+{
+  NS_LOG_FUNCTION (Current () << UtilsGetNodeId ());
+  NS_ASSERT (Current () != 0);
+
+  int retval = vsnprintf (__s, __n, __format, __ap);
+  return retval;
+}
 void dce___fpurge (FILE *stream)
 {
   NS_LOG_FUNCTION (Current () << UtilsGetNodeId () << stream);
diff -r 70496fb51ab2 model/dce-stdio.h
--- a/model/dce-stdio.h	Wed Jul 04 16:58:26 2012 +0900
+++ b/model/dce-stdio.h	Wed Jul 04 16:59:42 2012 +0900
@@ -62,6 +62,9 @@
 					   __const char *__restrict __format, ...);
 int dce___snprintf_chk (char *__restrict __s, size_t __n, int __flag,
 						size_t __slen, __const char *__restrict __format, ...);
+int dce___vsnprintf_chk (char *__restrict __s, size_t __n, int __flag,
+						size_t __slen,
+                         __const char *__restrict __format, _G_va_list __ap);
 
 void dce___fpurge (FILE *stream);
 size_t dce___fpending(FILE *stream);
diff -r 70496fb51ab2 model/dce-syslog.cc
--- a/model/dce-syslog.cc	Wed Jul 04 16:58:26 2012 +0900
+++ b/model/dce-syslog.cc	Wed Jul 04 16:59:42 2012 +0900
@@ -67,3 +67,14 @@
 
   vfprintf (process->syslog, message, args);
 }
+
+void
+dce___syslog_chk (int __pri, int __flag, __const char *__fmt, ...)
+{
+  NS_ASSERT (Current () != 0);
+
+  va_list ap;
+  va_start (ap, __fmt);
+  dce_vsyslog (__pri, __fmt, ap);
+  va_end (ap);
+}
diff -r 70496fb51ab2 model/dce-syslog.h
--- a/model/dce-syslog.h	Wed Jul 04 16:58:26 2012 +0900
+++ b/model/dce-syslog.h	Wed Jul 04 16:59:42 2012 +0900
@@ -19,4 +19,7 @@
 void
 dce_vsyslog (int priority, const char *message, va_list args);
 
+void
+dce___syslog_chk (int __pri, int __flag, __const char *__fmt, ...);
+
 #endif // DCE_SYSLOG_H
diff -r 70496fb51ab2 model/dce-unistd.h
--- a/model/dce-unistd.h	Wed Jul 04 16:58:26 2012 +0900
+++ b/model/dce-unistd.h	Wed Jul 04 16:59:42 2012 +0900
@@ -74,6 +74,8 @@
 
 ssize_t dce_pread(int fd, void *buf, size_t count, off_t offset);
 ssize_t dce_pwrite(int fd, const void *buf, size_t count, off_t offset);
+int dce_chown(const char *path, uid_t owner, gid_t group);
+int dce_initgroups(const char *user, gid_t group);
 
 #ifdef __cplusplus
 }
diff -r 70496fb51ab2 model/dce.cc
--- a/model/dce.cc	Wed Jul 04 16:58:26 2012 +0900
+++ b/model/dce.cc	Wed Jul 04 16:59:42 2012 +0900
@@ -141,7 +141,7 @@
       current->err = EPERM;
       return -1;
     }
-  if (sgid != (gid_t)-1 ||
+  if (sgid != (gid_t)-1 &&
       !is_set_ucapable (sgid))
     {
       current->err = EPERM;
diff -r 70496fb51ab2 model/dlm-loader-factory.cc
--- a/model/dlm-loader-factory.cc	Wed Jul 04 16:58:26 2012 +0900
+++ b/model/dlm-loader-factory.cc	Wed Jul 04 16:59:42 2012 +0900
@@ -3,6 +3,7 @@
 #include "ns3/fatal-error.h"
 #include <list>
 #include <dlfcn.h>
+#include <sys/stat.h>
 
 NS_LOG_COMPONENT_DEFINE ("DlmLoaderFactory");
 
@@ -34,6 +35,10 @@
   virtual void Unload (void *module);
   virtual void *Lookup (void *module, std::string symbol);
 private:
+  bool SearchFile (std::string filename, std::string *fullname) const;
+  std::list<std::string> GetSearchDirectories (void) const;
+  std::list<std::string> Split (std::string input, std::string sep) const;
+  bool Exists (std::string filename) const;
   Lmid_t m_lmid;
   std::list<void *> m_loaded;
 };
@@ -83,11 +88,98 @@
       ::dlclose (*i);
     }
 }
+std::list<std::string>
+DlmLoader::Split (std::string input, std::string sep) const
+{
+  NS_LOG_FUNCTION (this << input << sep);
+  std::list<std::string> retval;
+  std::string::size_type cur = 0, next;
+  while (true)
+    {
+      next = input.find (sep, cur);
+      if (next == cur)
+	{
+	  cur ++;
+	  continue;
+	} 
+      else if (next == std::string::npos)
+	{
+	  if (input.size () != cur)
+	    {
+	      retval.push_back (input.substr (cur, input.size () - cur));
+	    }
+	  break;
+	}
+      retval.push_back (input.substr (cur, next - cur));
+      cur = next + 1;
+    }
+  return retval;
+}
+std::list<std::string>
+DlmLoader::GetSearchDirectories (void) const
+{
+  NS_LOG_FUNCTION (this);
+  std::list<std::string> directories;
+  char *ldLibraryPath = getenv ("LD_LIBRARY_PATH");
+  if (ldLibraryPath != 0)
+    {
+      std::list<std::string> tmp = Split (ldLibraryPath, ":");
+      directories.insert (directories.end (), 
+			  tmp.begin (),
+			  tmp.end ());
+    }
+  char *path = getenv ("PATH");
+  if (path != 0)
+    {
+      std::list<std::string> tmp = Split (path, ":");
+      directories.insert (directories.end (), 
+			  tmp.begin (),
+			  tmp.end ());
+    }
+  directories.push_back ("/lib");
+  directories.push_back ("/usr/lib");
+  directories.push_back (".");
+  return directories;
+}
+bool
+DlmLoader::Exists (std::string filename) const
+{
+  //NS_LOG_FUNCTION (this << filename);
+  struct stat st;
+  int retval = ::stat (filename.c_str (), &st);
+  return retval == 0;
+}
+bool
+DlmLoader::SearchFile (std::string filename, std::string *fullname) const
+{
+  NS_LOG_FUNCTION (this << filename);
+  if (Exists (filename))
+    {
+      *fullname = filename;
+      NS_LOG_DEBUG ("Found: " << filename << " as " << *fullname);
+      return true;
+    }
+  std::list<std::string> dirs = GetSearchDirectories ();
+  for (std::list<std::string>::const_iterator i = dirs.begin (); i != dirs.end (); i++)
+    {
+      if (Exists (*i + "/" + filename))
+	{
+	  *fullname = *i + "/" + filename;
+	  NS_LOG_DEBUG ("Found: " << filename << " as " << *fullname);
+	  return true;
+	}
+    }
+  return false;
+}
 void *
 DlmLoader::Load (std::string filename, int flag)
 {
+  std::string fullname;
+  bool found;
   NS_LOG_FUNCTION (this << filename << flag);
-  void *module = dlmopen (m_lmid, filename.c_str (), flag);
+  found = SearchFile (filename, &fullname);
+  NS_ASSERT (found);
+  void *module = dlmopen (m_lmid, fullname.c_str (), flag);
   m_loaded.push_back (module);
   return module;
 }
diff -r 70496fb51ab2 model/libc-dce.cc
--- a/model/libc-dce.cc	Wed Jul 04 16:58:26 2012 +0900
+++ b/model/libc-dce.cc	Wed Jul 04 16:59:42 2012 +0900
@@ -132,11 +132,13 @@
      __THROW;
 extern int __obstack_vprintf_chk (struct obstack *, int, const char *,
                   _G_va_list) __THROW;
+extern void __syslog_chk (int __pri, int __flag, __const char *__fmt, ...);
 
 typedef void (*func_t) (...);
 
 extern "C" {
 
+extern void *__memcpy_chk(void *dest, const void *src, size_t n, size_t __destlen);
 void libc_dce (struct Libc **libc)
 {
   *libc = new Libc;
diff -r 70496fb51ab2 model/libc-ns3.h
--- a/model/libc-ns3.h	Wed Jul 04 16:58:26 2012 +0900
+++ b/model/libc-ns3.h	Wed Jul 04 16:59:42 2012 +0900
@@ -127,6 +127,7 @@
 NATIVE_EXPLICIT (strchr, char* (*) (char *, int))
 NATIVE_EXPLICIT (strrchr, const char * (*) (const char *, int))
 //DCE (strrchr)
+NATIVE_EXPLICIT (strstr, const char * (*) (const char *, const char *))
 NATIVE (strcasecmp)
 NATIVE (strncasecmp)
 DCE_WITH_ALIAS (strdup) // because C++ defines both const and non-const functions
@@ -241,6 +242,8 @@
 NATIVE (getdtablesize)
 DCE (pread)
 DCE (pwrite)
+DCE (chown)
+DCE (initgroups)
 
 // SYS/UIO.H
 DCE (writev)
@@ -393,6 +396,10 @@
 NATIVE (pthread_rwlock_destroy)
 NATIVE (pthread_setcancelstate)
 NATIVE (pthread_sigmask)
+NATIVE (pthread_spin_init)
+NATIVE (pthread_spin_lock)
+NATIVE (pthread_spin_unlock)
+NATIVE (pthread_spin_destroy)
 
 // SEMAPHORE.H
 DCE (sem_init)
@@ -475,6 +482,9 @@
 DCE (setlogmask)
 DCE (syslog)
 DCE (vsyslog)
+DCE    (__syslog_chk)
+ 
+
 
 // SETJMP.H
 NATIVE (__sigsetjmp)
diff -r 70496fb51ab2 wscript
--- a/wscript	Wed Jul 04 16:58:26 2012 +0900
+++ b/wscript	Wed Jul 04 16:59:42 2012 +0900
@@ -40,6 +40,8 @@
 
     conf.env.prepend_value('LINKFLAGS', '-Wl,--no-as-needed')
     conf.env.append_value('LINKFLAGS', '-pthread')
+    conf.env.append_value('LINKFLAGS', '-Wl,--dynamic-linker=' +
+                             os.path.abspath ('../build/lib/ldso'))
     conf.check (lib='dl', mandatory = True)
     conf.check_cc(fragment='int main() {__get_cpu_features();}\n', msg='Checking for glibc get_cpu_features', define_name='HAVE_GETCPUFEATURES', mandatory=False)
      
@@ -288,6 +290,10 @@
                        target='bin/dce-linux',
                        source=['example/dce-linux.cc'])
 
+    module.add_example(needed = ['core', 'network', 'dce', 'wifi', 'point-to-point', 'csma', 'mobility' ],
+                       target='bin/dce-unbound',
+                       source=['example/dce-unbound.cc'])
+
 # Add a script to build system 
 def build_a_script(bld, name, needed = [], **kw):
     external = [i for i in needed if not i == name]