netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Default network namespace name
@ 2014-05-21  6:36 Peter Fassberg
  2014-05-21  9:44 ` Nicolas Dichtel
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Peter Fassberg @ 2014-05-21  6:36 UTC (permalink / raw)
  To: netdev


Hi!

Is there a name of the default network namespace?

I would like to execute a command in the default network namespace while running a shell in a non-default namespace.

Like this: ip netns exec "" ip link
Or this:   ip netns exec . ip link

That command end up with a mis-spelled error message: :)
seting the network namespace "" failed: Invalid argument



Regards,

Peter

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Default network namespace name
  2014-05-21  6:36 Default network namespace name Peter Fassberg
@ 2014-05-21  9:44 ` Nicolas Dichtel
  2014-05-21 16:43 ` Cong Wang
  2014-05-21 16:51 ` Rami Rosen
  2 siblings, 0 replies; 6+ messages in thread
From: Nicolas Dichtel @ 2014-05-21  9:44 UTC (permalink / raw)
  To: Peter Fassberg, netdev

Le 21/05/2014 08:36, Peter Fassberg a écrit :
>
> Hi!
>
> Is there a name of the default network namespace?
No.

>
> I would like to execute a command in the default network namespace while running
> a shell in a non-default namespace.
>
> Like this: ip netns exec "" ip link
> Or this:   ip netns exec . ip link
>
> That command end up with a mis-spelled error message: :)
> seting the network namespace "" failed: Invalid argument

You can try something like this (I suppose that init runs in your
"default network namespace") :

ip netns add foo (just to create /var/run/netns which is a tmpfs)
ip netns del foo
touch /var/run/netns/default
mount --bind /proc/1/ns/net /var/run/netns/default
ip netns exec default ip link

Regards,
Nicolas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Default network namespace name
  2014-05-21  6:36 Default network namespace name Peter Fassberg
  2014-05-21  9:44 ` Nicolas Dichtel
@ 2014-05-21 16:43 ` Cong Wang
  2014-05-21 16:51 ` Rami Rosen
  2 siblings, 0 replies; 6+ messages in thread
From: Cong Wang @ 2014-05-21 16:43 UTC (permalink / raw)
  To: Peter Fassberg; +Cc: netdev

On Tue, May 20, 2014 at 11:36 PM, Peter Fassberg <pf@leissner.se> wrote:
>
> Hi!
>
> Is there a name of the default network namespace?
>

Network namespace doesn't even have a name in kernel, it's
the user-space (ip netns) who gives a name to it. IOW, you
need to modify ip netns or write your own code.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Default network namespace name
  2014-05-21  6:36 Default network namespace name Peter Fassberg
  2014-05-21  9:44 ` Nicolas Dichtel
  2014-05-21 16:43 ` Cong Wang
@ 2014-05-21 16:51 ` Rami Rosen
  2014-05-21 17:21   ` Peter Fassberg
  2 siblings, 1 reply; 6+ messages in thread
From: Rami Rosen @ 2014-05-21 16:51 UTC (permalink / raw)
  To: Peter Fassberg; +Cc: Netdev

Hi,

The default, initial network namespace does not have a name. In fact,
according to the kernel implementation, all namespaces (and in
particular, the network namespace) do not have names. The names of the
network namespaces are created and deleted by the userspace "ip netns"
command.

You can move network interfaces to the initial namespace using pid 1,
for example:

ip netns add myns2
ip link set p4p1 netns myns2

#start bash in myns2
ip nents exec myns2 bash

#move p4p1 from myns2 to the default network namespace

ip link set p4p1 netns 1

Regards,
Rami Rosen

http://ramirose.wix.com/ramirosen


On Wed, May 21, 2014 at 9:36 AM, Peter Fassberg <pf@leissner.se> wrote:
>
> Hi!
>
> Is there a name of the default network namespace?
>
> I would like to execute a command in the default network namespace while
> running a shell in a non-default namespace.
>
> Like this: ip netns exec "" ip link
> Or this:   ip netns exec . ip link
>
> That command end up with a mis-spelled error message: :)
> seting the network namespace "" failed: Invalid argument
>
>
>
> Regards,
>
> Peter
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Default network namespace name
  2014-05-21 16:51 ` Rami Rosen
@ 2014-05-21 17:21   ` Peter Fassberg
  2014-05-21 17:29     ` Cong Wang
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Fassberg @ 2014-05-21 17:21 UTC (permalink / raw)
  To: Rami Rosen, Nicolas Dichtel; +Cc: Netdev


Hi Rami,

This was very interesting.

How does "ip link set" distinguish between PID 1 and a namespace named "1"?


Nicolas proposed a very useful solution, which was exactly what I was looking for:
touch /var/run/netns/default
mount --bind /proc/1/ns/net /var/run/netns/default

It work like a charm!

Thank you all!



Regards,

Peter




On Wed, 21 May 2014, Rami Rosen wrote:

> Hi,
>
> The default, initial network namespace does not have a name. In fact,
> according to the kernel implementation, all namespaces (and in
> particular, the network namespace) do not have names. The names of the
> network namespaces are created and deleted by the userspace "ip netns"
> command.
>
> You can move network interfaces to the initial namespace using pid 1,
> for example:
>
> ip netns add myns2
> ip link set p4p1 netns myns2
>
> #start bash in myns2
> ip nents exec myns2 bash
>
> #move p4p1 from myns2 to the default network namespace
>
> ip link set p4p1 netns 1
>
> Regards,
> Rami Rosen
>
> http://ramirose.wix.com/ramirosen
>
>
> On Wed, May 21, 2014 at 9:36 AM, Peter Fassberg <pf@leissner.se> wrote:
>>
>> Hi!
>>
>> Is there a name of the default network namespace?
>>
>> I would like to execute a command in the default network namespace while
>> running a shell in a non-default namespace.
>>
>> Like this: ip netns exec "" ip link
>> Or this:   ip netns exec . ip link
>>
>> That command end up with a mis-spelled error message: :)
>> seting the network namespace "" failed: Invalid argument
>>
>>
>>
>> Regards,
>>
>> Peter
>>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Default network namespace name
  2014-05-21 17:21   ` Peter Fassberg
@ 2014-05-21 17:29     ` Cong Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Cong Wang @ 2014-05-21 17:29 UTC (permalink / raw)
  To: Peter Fassberg; +Cc: Rami Rosen, Nicolas Dichtel, Netdev

On Wed, May 21, 2014 at 10:21 AM, Peter Fassberg <pf@leissner.se> wrote:
>
> How does "ip link set" distinguish between PID 1 and a namespace named "1"?

Looking at the code, it just checks if it's name "1" first, then
checks if it's a PID:

                        if ((netns = get_netns_fd(*argv)) >= 0)
                                addattr_l(&req->n, sizeof(*req),
IFLA_NET_NS_FD, &netns, 4);
                        else if (get_integer(&netns, *argv, 0) == 0)
                                addattr_l(&req->n, sizeof(*req),
IFLA_NET_NS_PID, &netns, 4);
                        else
                                invarg("Invalid \"netns\" value\n", *argv);

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-05-21 17:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-21  6:36 Default network namespace name Peter Fassberg
2014-05-21  9:44 ` Nicolas Dichtel
2014-05-21 16:43 ` Cong Wang
2014-05-21 16:51 ` Rami Rosen
2014-05-21 17:21   ` Peter Fassberg
2014-05-21 17:29     ` Cong Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).