On Mon, Jun 10, 2019 at 7:48 PM Stephen Hemminger <step...@networkplumber.org> wrote: > > On Fri, 7 Jun 2019 22:41:22 +0200 > Matteo Croce <mcr...@redhat.com> wrote: > > > When creating a new netns or executing a program into an existing one, > > the unshare() or setns() calls will change the current netns. > > In batch mode, this can run commands on the wrong interfaces, as the > > ifindex value is meaningful only in the current netns. For example, this > > command fails because veth-c doesn't exists in the init netns: > > Applied, thanks.
Great! I was thinking about the code flow when running ip netns exec in batch or doall mode: 1) save the current netns() 2) change netns with setns() 3) clear the clear vrf associations with vrf_reset() 4) fork(), exec in the child 5) restore the previous netns in the parent With a little rework (adding a parameter to cmd_exec), we could change the netns directly in the child, so the parent doesn't need steps 1,2,3,5 This could save some errors where the previous state can't be restored, eg. netns, vrp or the like. I have a draft patch for this which, by the way, eliminates some dead code, I will send to the ML soon. Regards, -- Matteo Croce per aspera ad upstream