Loading...
Searching...
No Matches
Netns

Network namespace convenience functions More...

## Files

file | netns.c

## Macros

#define | _GNU_SOURCE
#define | NETNS_PREFIX_PATH "/var/run/netns"
#define | NETNS_CURRENT_PATH "/proc/self/ns/net"

## Functions

int | osmo_netns_switch_enter (int nsfd, struct osmo_netns_switch_state *state)
| switch to a (non-default) namespace, store existing signal mask in oldmask.
int | osmo_netns_switch_exit (struct osmo_netns_switch_state *state)
| switch back to the previous namespace, restoring signal mask.
static int | create_netns (const char *name)
int | osmo_netns_open_fd (const char *name)
| Open a file descriptor for the network namespace with provided name.

## Detailed Description

Network namespace convenience functions

## Macro Definition Documentation

## _GNU_SOURCE

#define _GNU_SOURCE

## NETNS_CURRENT_PATH

#define NETNS_CURRENT_PATH "/proc/self/ns/net"

Referenced by create_netns().

## NETNS_PREFIX_PATH

#define NETNS_PREFIX_PATH "/var/run/netns"

Referenced by create_netns(), and osmo_netns_open_fd().

## Function Documentation

## create_netns()

int create_netns | ( | const char * | name | ) |

static

References name, NETNS_CURRENT_PATH, and NETNS_PREFIX_PATH.

Referenced by osmo_netns_open_fd().

## osmo_netns_open_fd()

int osmo_netns_open_fd | ( | const char * | name | ) |

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

Creates /var/run/netns/ directory if it doesn't exist already.

Parameters

  [in] | name | Name of the network namespace (in /var/run/netns/)

Returns
  File descriptor of network namespace; negative in case of error

References create_netns(), name, and NETNS_PREFIX_PATH.

Referenced by netdev_netns_ctx_init(), and osmo_tundev_open().

## osmo_netns_switch_enter()

int osmo_netns_switch_enter | ( | int | nsfd,
|  | struct osmo_netns_switch_state * | state )

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

Parameters

  [in] | nsfd | file descriptor representing the namespace to which we shall switch
  [out] | state | caller-provided memory location to which state of previous netns is stored

Returns
  0 on success; negative on error

References osmo_netns_switch_state::prev_nsfd, and osmo_netns_switch_state::prev_sigmask.

Referenced by netdev_netns_ctx_init(), and osmo_tundev_open().

## osmo_netns_switch_exit()

int osmo_netns_switch_exit | ( | struct osmo_netns_switch_state * | state | ) |

switch back to the previous namespace, restoring signal mask.

Parameters

  [in] | state | information about previous netns, filled by osmo_netns_switch_enter()

Returns
  0 on successs; negative on error

References osmo_netns_switch_state::prev_nsfd, and osmo_netns_switch_state::prev_sigmask.

Referenced by netdev_netns_ctx_init(), and osmo_tundev_open().