libosmocore 1.13.1.1-afb4 Osmocom core library

Files | Macros | Functions
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. More...
int | osmo_netns_switch_exit (struct osmo_netns_switch_state *state)
| switch back to the previous namespace, restoring signal mask. More...
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. More...

## 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"

## ◆ NETNS_PREFIX_PATH

#define NETNS_PREFIX_PATH "/var/run/netns"

## Function Documentation

## ◆ create_netns()

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

References ENOTSUP, MAXPATHLEN, 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(), MAXPATHLEN, 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 ENOTSUP, 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 ENOTSUP, osmo_netns_switch_state::prev_nsfd, and osmo_netns_switch_state::prev_sigmask.

Referenced by netdev_netns_ctx_init(), and osmo_tundev_open().