libosmocore 1.10.0.57-8972
Osmocom core library
|
tun network device (interface) convenience functions More...
Data Structures | |
struct | osmo_tundev |
Macros | |
#define | TUN_DEV_PATH "/dev/net/tun" |
#define | TUN_PACKET_MAX 8196 |
#define | LOGTUN(tun, lvl, fmt, args ...) |
Functions | |
static int | tundev_decaps (struct osmo_tundev *tundev) |
static int | tundev_read_cb (struct osmo_fd *fd) |
static int | tundev_write_cb (struct osmo_fd *fd, struct msgb *msg) |
static int | tundev_ifupdown_ind_cb (struct osmo_netdev *netdev, bool ifupdown) |
static int | tundev_dev_name_chg_cb (struct osmo_netdev *netdev, const char *new_dev_name) |
static int | tundev_mtu_chg_cb (struct osmo_netdev *netdev, uint32_t new_mtu) |
struct osmo_tundev * | osmo_tundev_alloc (void *ctx, const char *name) |
Allocate a new tundev object. More... | |
void | osmo_tundev_free (struct osmo_tundev *tundev) |
Free an allocated tundev object. More... | |
static int | tundev_open_fd (struct osmo_tundev *tundev, int flags) |
Open and configure fd of the tunnel device. More... | |
int | osmo_tundev_open (struct osmo_tundev *tundev) |
Open the tunnel device owned by the tundev object. More... | |
int | osmo_tundev_close (struct osmo_tundev *tundev) |
Close the tunnel device owned by the tundev object. More... | |
bool | osmo_tundev_is_open (struct osmo_tundev *tundev) |
Retrieve whether the tundev object is in "opened" state. More... | |
void | osmo_tundev_set_priv_data (struct osmo_tundev *tundev, void *priv_data) |
Set private user data pointer on the tundev object. More... | |
void * | osmo_tundev_get_priv_data (struct osmo_tundev *tundev) |
Get private user data pointer from the tundev object. More... | |
void | osmo_tundev_set_data_ind_cb (struct osmo_tundev *tundev, osmo_tundev_data_ind_cb_t data_ind_cb) |
Set data_ind_cb callback, called when a new packet is received on the tun interface. More... | |
const char * | osmo_tundev_get_name (const struct osmo_tundev *tundev) |
Get name used to identify the tundev object. More... | |
int | osmo_tundev_get_fd (const struct osmo_tundev *tundev) |
Get FD associated to the tundev object. More... | |
int | osmo_tundev_set_dev_name (struct osmo_tundev *tundev, const char *dev_name) |
Set name used to name the tunnel interface created by the tundev object. More... | |
const char * | osmo_tundev_get_dev_name (const struct osmo_tundev *tundev) |
Get name used to name the tunnel interface created by the tundev object. More... | |
int | osmo_tundev_set_netns_name (struct osmo_tundev *tundev, const char *netns_name) |
Set name of the network namespace to use when opening the tunnel interface. More... | |
const char * | osmo_tundev_get_netns_name (const struct osmo_tundev *tundev) |
Get name of network namespace used when opening the tunnel interface. More... | |
struct osmo_netdev * | osmo_tundev_get_netdev (struct osmo_tundev *tundev) |
Get netdev managing the tunnel interface of tundev. More... | |
int | osmo_tundev_send (struct osmo_tundev *tundev, struct msgb *msg) |
Submit a packet to the tunnel device managed by the tundev object. More... | |
tun network device (interface) convenience functions
#define LOGTUN | ( | tun, | |
lvl, | |||
fmt, | |||
args ... | |||
) |
#define TUN_DEV_PATH "/dev/net/tun" |
#define TUN_PACKET_MAX 8196 |
struct osmo_tundev * osmo_tundev_alloc | ( | void * | ctx, |
const char * | name | ||
) |
Allocate a new tundev object.
[in] | ctx | talloc context to use as a parent when allocating the tundev object |
[in] | name | A name providen to identify the tundev object |
References osmo_wqueue::bfd, name, osmo_tundev::name, osmo_tundev::netdev, OSMO_FD_READ, osmo_fd_setup(), osmo_netdev_alloc(), osmo_netdev_set_dev_name_chg_cb(), osmo_netdev_set_ifupdown_ind_cb(), osmo_netdev_set_mtu_chg_cb(), osmo_netdev_set_priv_data(), osmo_wqueue_bfd_cb(), osmo_wqueue_init(), osmo_wqueue::read_cb, tundev_dev_name_chg_cb(), tundev_ifupdown_ind_cb(), tundev_mtu_chg_cb(), tundev_read_cb(), tundev_write_cb(), osmo_tundev::wqueue, and osmo_wqueue::write_cb.
int osmo_tundev_close | ( | struct osmo_tundev * | tundev | ) |
Close the tunnel device owned by the tundev object.
[in] | tundev | The tundev object to close |
References osmo_wqueue::bfd, osmo_tundev::dev_name, osmo_tundev::dev_name_dynamic, osmo_fd::fd, osmo_tundev::netdev, osmo_tundev::opened, osmo_fd_unregister(), osmo_netdev_unregister(), osmo_wqueue_clear(), and osmo_tundev::wqueue.
Referenced by osmo_tundev_free().
void osmo_tundev_free | ( | struct osmo_tundev * | tundev | ) |
Free an allocated tundev object.
[in] | tundev | The tundev object to free |
References osmo_tundev::netdev, osmo_netdev_free(), and osmo_tundev_close().
const char * osmo_tundev_get_dev_name | ( | const struct osmo_tundev * | tundev | ) |
Get name used to name the tunnel interface created by the tundev object.
[in] | tundev | The tundev object from where to retrieve the field |
References osmo_tundev::dev_name.
int osmo_tundev_get_fd | ( | const struct osmo_tundev * | tundev | ) |
Get FD associated to the tundev object.
[in] | tundev | The tundev object from where to retrieve the field |
References osmo_wqueue::bfd, osmo_fd::fd, and osmo_tundev::wqueue.
const char * osmo_tundev_get_name | ( | const struct osmo_tundev * | tundev | ) |
Get name used to identify the tundev object.
[in] | tundev | The tundev object from where to retrieve the field |
References osmo_tundev::name.
struct osmo_netdev * osmo_tundev_get_netdev | ( | struct osmo_tundev * | tundev | ) |
Get netdev managing the tunnel interface of tundev.
[in] | tundev | The tundev object from where to retrieve the field |
References osmo_tundev::netdev.
const char * osmo_tundev_get_netns_name | ( | const struct osmo_tundev * | tundev | ) |
Get name of network namespace used when opening the tunnel interface.
[in] | tundev | The tundev object from where to retrieve the field |
References osmo_tundev::netns_name.
void * osmo_tundev_get_priv_data | ( | struct osmo_tundev * | tundev | ) |
Get private user data pointer from the tundev object.
[in] | tundev | The tundev object from where to retrieve the field |
References osmo_tundev::priv_data.
bool osmo_tundev_is_open | ( | struct osmo_tundev * | tundev | ) |
Retrieve whether the tundev object is in "opened" state.
[in] | tundev | The tundev object to check |
References osmo_tundev::opened.
int osmo_tundev_open | ( | struct osmo_tundev * | tundev | ) |
Open the tunnel device owned by the tundev object.
[in] | tundev | The tundev object to open |
References osmo_wqueue::bfd, DLGLOBAL, osmo_fd::fd, osmo_tundev::ifindex, LOGL_ERROR, LOGL_INFO, LOGP, LOGTUN, osmo_tundev::netdev, osmo_tundev::netns_name, osmo_tundev::opened, osmo_fd_register(), osmo_netdev_register(), osmo_netdev_set_ifindex(), osmo_netdev_set_netns_name(), osmo_netdev_unregister(), tundev_open_fd(), and osmo_tundev::wqueue.
int osmo_tundev_send | ( | struct osmo_tundev * | tundev, |
struct msgb * | msg | ||
) |
Submit a packet to the tunnel device managed by the tundev object.
[in] | tundev | The tundev object owning the tunnel device where to inject the packet |
[in] | msg | The msgb containg the packet to transfer |
This function takes the ownership of msg in all cases.
References LOGL_ERROR, LOGTUN, msg, msgb_free(), OSMO_ASSERT, osmo_wqueue_enqueue(), and osmo_tundev::wqueue.
void osmo_tundev_set_data_ind_cb | ( | struct osmo_tundev * | tundev, |
osmo_tundev_data_ind_cb_t | data_ind_cb | ||
) |
Set data_ind_cb callback, called when a new packet is received on the tun interface.
[in] | tundev | The tundev object where the field is set |
[in] | data_ind_cb | the user provided function to be called when a new packet is received |
References osmo_tundev::data_ind_cb.
int osmo_tundev_set_dev_name | ( | struct osmo_tundev * | tundev, |
const char * | dev_name | ||
) |
Set name used to name the tunnel interface created by the tundev object.
[in] | tundev | The tundev object where the field is set |
[in] | dev_name | The tunnel interface name to use |
This is used during osmo_tundev_open() time, and hence shouldn't be changed when the tundev object is in "opened" state. If left as NULL (default), the system will pick a suitable name during osmo_tundev_open(), and the field will be updated to the system-selected name, which can be retrieved later with osmo_tundev_get_dev_name().
References osmo_tundev::dev_name, osmo_tundev::dev_name_dynamic, osmo_tundev::opened, and osmo_talloc_replace_string().
int osmo_tundev_set_netns_name | ( | struct osmo_tundev * | tundev, |
const char * | netns_name | ||
) |
Set name of the network namespace to use when opening the tunnel interface.
[in] | tundev | The tundev object where the field is set |
[in] | netns_name | The network namespace to use during tunnel interface creation |
This is used during osmo_tundev_open() time, and hence shouldn't be changed when the tundev object is in "opened" state. If left as NULL (default), the system will stay in the current network namespace.
References osmo_tundev::netns_name, osmo_tundev::opened, and osmo_talloc_replace_string().
void osmo_tundev_set_priv_data | ( | struct osmo_tundev * | tundev, |
void * | priv_data | ||
) |
Set private user data pointer on the tundev object.
[in] | tundev | The tundev object where the field is set |
References osmo_tundev::priv_data.
|
static |
References osmo_wqueue::bfd, osmo_tundev::data_ind_cb, osmo_fd::fd, LOGL_ERROR, LOGTUN, msg, msgb_alloc(), msgb_data(), msgb_free(), msgb_put(), TUN_PACKET_MAX, and osmo_tundev::wqueue.
Referenced by tundev_read_cb().
|
static |
|
static |
References LOGL_NOTICE, LOGTUN, osmo_tundev::netdev, osmo_netdev_get_priv_data(), osmo_wqueue_clear(), and osmo_tundev::wqueue.
Referenced by osmo_tundev_alloc().
|
static |
References LOGL_NOTICE, LOGTUN, osmo_tundev::netdev, and osmo_netdev_get_priv_data().
Referenced by osmo_tundev_alloc().
|
static |
Open and configure fd of the tunnel device.
[in] | tundev | The tundev object whose tunnel interface to open |
[in] | flags | internal linux flags to pass when creating the device (not used yet) |
References osmo_tundev::dev_name, osmo_tundev::dev_name_dynamic, flags, osmo_tundev::ifindex, LOGL_ERROR, LOGL_INFO, LOGTUN, osmo_strlcpy(), and TUN_DEV_PATH.
Referenced by osmo_tundev_open().
|
static |
References osmo_fd::data, and tundev_decaps().
Referenced by osmo_tundev_alloc().
References osmo_wqueue::bfd, osmo_fd::data, osmo_fd::fd, LOGL_ERROR, LOGTUN, msg, msgb_data(), msgb_length(), and osmo_tundev::wqueue.
Referenced by osmo_tundev_alloc().