Re: Get current network namespace

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Sharwan,

Thank you very much for the answer. Yes, I read the network namespace
code, you could get namespace from sk by calling sock_net(sk), and it
is also available from device.

For our case, it is how to get the namespace in the first place, so we
can match against open socks and/or devices. Since you mentioned that
process fills sk_buff, then how does the process know which namespace
it is in then? This is the answer I am looking for.

In our case, the user space code tells kernel code what IP/port it is
interested, ( net namespace implied ?), so I am wondering where I
could get this namespace, implied by user space code, or available
from the process structure in kernel space.

Thank you, guys.
Haibin

On Wed, Apr 8, 2009 at 12:26 AM, Sharwan Joram <sharwan.joram@xxxxxxxxx> wrote:
> A namespace parameter is obtained in every function which creates the
> socket. This namespace field is present in the sk_buff structure which is
> filled up either by the process which is creating the socket or in second
> case from the device it is received.
>>> >

>> >>
>> >> A question on how to get the current network namespace.
>> >>
>> >> I am porting a driver from 2.6.18 to 2.6.28. We do protocol analysis
>> >> by the 5 tuples: src IP, dst IP, src port, dst port and transportation
>> >> protocol. We have code in usr space to pass in these parameters, then
>> >> kernel space code do search through udp_hash and tcp_hash to locate
>> >> the exact socks. Since 2.6.18 doesn't support network namespace, this
>> >> works fine.
>> >>
>> >> But as 2.6.28 supports network namespace, search through udp_hash and
>> >> tcp_hash requires a sixth parameter -- network namespace as well. So
>> >> the question is, how to get current network namespace in this case? Is
>> >> it available from user space code and passed to kernel code, or there
>> >> is function to get it in kernel space?
>> >>
>> >> It seems I could go by by using the system init_net, but I want to be
>> >> new feature friendly at least.
>> >
>> > Netmark namespace means that different user space processes have a different
>> > view of the network (used e.g. by vservers). I do not know what will happen,
>> > if you pass the init_net (default namespace), if the socket is created
>> > in a
>> > different namespace.

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux