title: Getting instance of global network namespace in linux kernel module
body: <p>I am writing a Linux kernel module and want to get a <code>struct net*</code> pointer to the global network namespace on the device. I tried the code below in my module initialization function:</p>
  
  <pre><code>// test-module.c
  #include &lt;linux/kernel.h&gt;
  #include &lt;linux/module.h&gt;
  #include &lt;net/net_namespace.h&gt;
  
  int init_dev (void)
  {
      struct net *net1;
  
      printk ("Init Module\n");
  
      net1 = get_net_ns_by_pid(1); // getting NS for PID 1 (init process)
      if(net1 != NULL){
          printk ("Init Module --- Got net ns pointer \n");
      }
      else {
          printk ("Init Module --- Blank net ns pointer \n");
      }
  
      return 0;
  }
  
  void cleanup (void)
  {
      printk ("Cleaning Up the Module\n");
      return;
  }
  
  module_init (init_dev);
  module_exit (cleanup);
  </code></pre>
  
  <p>Makefile:</p>
  
  <pre><code>obj-m += test-module.o
  
  all:
      make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
  
  clean:
      make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
  </code></pre>
  
  <p>I can compile the module but when I try to insert the module using <code>sudo insmod test-module.ko</code> I get the error in dmesg:</p>
  
  <pre><code>test-module: Unknown symbol get_net_ns_by_pid (err 0)
  </code></pre>
  
  <p>I want to ask if anyone knows how to get the <code>struct net*</code> pointer.</p>