\doxysection{Netns}
\label{group__netns}\index{Netns@{Netns}}


Network namespace convenience functions.  


\doxysubsection*{Files}
\begin{DoxyCompactItemize}
\item 
file \textbf{ netns.\+c}
\end{DoxyCompactItemize}
\doxysubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \textbf{ \+\_\+\+GNU\+\_\+\+SOURCE}
\item 
\#define \textbf{ NETNS\+\_\+\+PREFIX\+\_\+\+PATH}~\char`\"{}/var/run/netns\char`\"{}
\item 
\#define \textbf{ NETNS\+\_\+\+CURRENT\+\_\+\+PATH}~\char`\"{}/proc/self/ns/\textbf{ net}\char`\"{}
\end{DoxyCompactItemize}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
int \textbf{ osmo\+\_\+netns\+\_\+switch\+\_\+enter} (int nsfd, struct \textbf{ osmo\+\_\+netns\+\_\+switch\+\_\+state} $\ast$state)
\begin{DoxyCompactList}\small\item\em switch to a (non-\/default) namespace, store existing signal mask in oldmask. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+netns\+\_\+switch\+\_\+exit} (struct \textbf{ osmo\+\_\+netns\+\_\+switch\+\_\+state} $\ast$state)
\begin{DoxyCompactList}\small\item\em switch back to the previous namespace, restoring signal mask. \end{DoxyCompactList}\item 
static int \textbf{ create\+\_\+netns} (const char $\ast$\textbf{ name})
\item 
int \textbf{ osmo\+\_\+netns\+\_\+open\+\_\+fd} (const char $\ast$\textbf{ name})
\begin{DoxyCompactList}\small\item\em Open a file descriptor for the network namespace with provided name. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Network namespace convenience functions. 



\doxysubsection{Macro Definition Documentation}
\mbox{\label{group__netns_ga369266c24eacffb87046522897a570d5}} 
\index{Netns@{Netns}!\_GNU\_SOURCE@{\_GNU\_SOURCE}}
\index{\_GNU\_SOURCE@{\_GNU\_SOURCE}!Netns@{Netns}}
\doxysubsubsection{\_GNU\_SOURCE}
{\footnotesize\ttfamily \#define \+\_\+\+GNU\+\_\+\+SOURCE}

\mbox{\label{group__netns_ga9fd453e784a7796939100c1a30a6ab93}} 
\index{Netns@{Netns}!NETNS\_CURRENT\_PATH@{NETNS\_CURRENT\_PATH}}
\index{NETNS\_CURRENT\_PATH@{NETNS\_CURRENT\_PATH}!Netns@{Netns}}
\doxysubsubsection{NETNS\_CURRENT\_PATH}
{\footnotesize\ttfamily \#define NETNS\+\_\+\+CURRENT\+\_\+\+PATH~\char`\"{}/proc/self/ns/\textbf{ net}\char`\"{}}

\mbox{\label{group__netns_gabe26a585817471419f8fb2fb09a91a95}} 
\index{Netns@{Netns}!NETNS\_PREFIX\_PATH@{NETNS\_PREFIX\_PATH}}
\index{NETNS\_PREFIX\_PATH@{NETNS\_PREFIX\_PATH}!Netns@{Netns}}
\doxysubsubsection{NETNS\_PREFIX\_PATH}
{\footnotesize\ttfamily \#define NETNS\+\_\+\+PREFIX\+\_\+\+PATH~\char`\"{}/var/run/netns\char`\"{}}



\doxysubsection{Function Documentation}
\mbox{\label{group__netns_ga22f3010073b79b212d0b766686b9912c}} 
\index{Netns@{Netns}!create\_netns@{create\_netns}}
\index{create\_netns@{create\_netns}!Netns@{Netns}}
\doxysubsubsection{create\_netns()}
{\footnotesize\ttfamily static int create\+\_\+netns (\begin{DoxyParamCaption}\item[{const char $\ast$}]{name }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}



References \textbf{ ENOTSUP}, \textbf{ MAXPATHLEN}, \textbf{ name}, \textbf{ NETNS\+\_\+\+CURRENT\+\_\+\+PATH}, and \textbf{ NETNS\+\_\+\+PREFIX\+\_\+\+PATH}.



Referenced by \textbf{ osmo\+\_\+netns\+\_\+open\+\_\+fd()}.

\mbox{\label{group__netns_gaf99b37aab415c93e1b1a083b9d1a7366}} 
\index{Netns@{Netns}!osmo\_netns\_open\_fd@{osmo\_netns\_open\_fd}}
\index{osmo\_netns\_open\_fd@{osmo\_netns\_open\_fd}!Netns@{Netns}}
\doxysubsubsection{osmo\_netns\_open\_fd()}
{\footnotesize\ttfamily int osmo\+\_\+netns\+\_\+open\+\_\+fd (\begin{DoxyParamCaption}\item[{const char $\ast$}]{name }\end{DoxyParamCaption})}



Open a file descriptor for the network namespace with provided name. 

Creates /var/run/netns/ directory if it doesn\textquotesingle{}t exist already. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em name} & Name of the network namespace (in /var/run/netns/) \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
File descriptor of network namespace; negative in case of error 
\end{DoxyReturn}


References \textbf{ create\+\_\+netns()}, \textbf{ MAXPATHLEN}, \textbf{ name}, and \textbf{ NETNS\+\_\+\+PREFIX\+\_\+\+PATH}.



Referenced by \textbf{ netdev\+\_\+netns\+\_\+ctx\+\_\+init()}, and \textbf{ osmo\+\_\+tundev\+\_\+open()}.

\mbox{\label{group__netns_ga78aa2179b3dc90dfac0d0ac4cd12c9ce}} 
\index{Netns@{Netns}!osmo\_netns\_switch\_enter@{osmo\_netns\_switch\_enter}}
\index{osmo\_netns\_switch\_enter@{osmo\_netns\_switch\_enter}!Netns@{Netns}}
\doxysubsubsection{osmo\_netns\_switch\_enter()}
{\footnotesize\ttfamily int osmo\+\_\+netns\+\_\+switch\+\_\+enter (\begin{DoxyParamCaption}\item[{int}]{nsfd,  }\item[{struct \textbf{ osmo\+\_\+netns\+\_\+switch\+\_\+state} $\ast$}]{state }\end{DoxyParamCaption})}



switch to a (non-\/default) namespace, store existing signal mask in oldmask. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em nsfd} & file descriptor representing the namespace to which we shall switch \\
\hline
\mbox{\texttt{ out}}  & {\em state} & caller-\/provided memory location to which state of previous netns is stored \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 on success; negative on error 
\end{DoxyReturn}


References \textbf{ ENOTSUP}, \textbf{ osmo\+\_\+netns\+\_\+switch\+\_\+state\+::prev\+\_\+nsfd}, and \textbf{ osmo\+\_\+netns\+\_\+switch\+\_\+state\+::prev\+\_\+sigmask}.



Referenced by \textbf{ netdev\+\_\+netns\+\_\+ctx\+\_\+init()}, and \textbf{ osmo\+\_\+tundev\+\_\+open()}.

\mbox{\label{group__netns_gaaed38f1781aeeaf93d6b399359358ab4}} 
\index{Netns@{Netns}!osmo\_netns\_switch\_exit@{osmo\_netns\_switch\_exit}}
\index{osmo\_netns\_switch\_exit@{osmo\_netns\_switch\_exit}!Netns@{Netns}}
\doxysubsubsection{osmo\_netns\_switch\_exit()}
{\footnotesize\ttfamily int osmo\+\_\+netns\+\_\+switch\+\_\+exit (\begin{DoxyParamCaption}\item[{struct \textbf{ osmo\+\_\+netns\+\_\+switch\+\_\+state} $\ast$}]{state }\end{DoxyParamCaption})}



switch back to the previous namespace, restoring signal mask. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em state} & information about previous netns, filled by \doxyref{osmo\+\_\+netns\+\_\+switch\+\_\+enter()}{p.}{group__netns_ga78aa2179b3dc90dfac0d0ac4cd12c9ce} \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 on successs; negative on error 
\end{DoxyReturn}


References \textbf{ ENOTSUP}, \textbf{ osmo\+\_\+netns\+\_\+switch\+\_\+state\+::prev\+\_\+nsfd}, and \textbf{ osmo\+\_\+netns\+\_\+switch\+\_\+state\+::prev\+\_\+sigmask}.



Referenced by \textbf{ netdev\+\_\+netns\+\_\+ctx\+\_\+init()}, and \textbf{ osmo\+\_\+tundev\+\_\+open()}.

