libosmocore 1.13.1.1-afb4 Osmocom core library

netdev.h
Go to the documentation of this file.
1
4#pragma once
5
6#include <stddef.h>
7#include <stdint.h>
8
9#include <osmocom/core/msgb.h>
10#include <osmocom/core/socket.h>
11
12 struct osmo_netdev;
13
14 typedef int (*osmo_netdev_ifupdown_ind_cb_t)(struct osmo_netdev *netdev, bool ifupdown);
15 typedef int (*osmo_netdev_dev_name_chg_cb_t)(struct osmo_netdev *netdev, const char *new_dev_name);
16 typedef int (*osmo_netdev_mtu_chg_cb_t)(struct osmo_netdev *netdev, unsigned int new_mtu);
17
18 struct osmo_netdev *osmo_netdev_alloc(void *ctx, const char *name);
19 void osmo_netdev_free(struct osmo_netdev *netdev);
20
21 int osmo_netdev_register(struct osmo_netdev *netdev);
22 int osmo_netdev_unregister(struct osmo_netdev *netdev);
23 bool osmo_netdev_is_registered(struct osmo_netdev *netdev);
24
25 const char *osmo_netdev_get_name(const struct osmo_netdev *netdev);
26
27 void osmo_netdev_set_priv_data(struct osmo_netdev *netdev, void *priv_data);
28 void *osmo_netdev_get_priv_data(struct osmo_netdev *netdev);
29
30 int osmo_netdev_set_ifindex(struct osmo_netdev *netdev, unsigned int ifindex);
31 unsigned int osmo_netdev_get_ifindex(const struct osmo_netdev *netdev);
32
33 const char *osmo_netdev_get_dev_name(const struct osmo_netdev *netdev);
34
35 int osmo_netdev_set_netns_name(struct osmo_netdev *netdev, const char *netns);
36 const char *osmo_netdev_get_netns_name(const struct osmo_netdev *netdev);
37
38 int osmo_netdev_set_mtu(struct osmo_netdev *netdev, uint32_t mtu);
39
40 void osmo_netdev_set_ifupdown_ind_cb(struct osmo_netdev *netdev, osmo_netdev_ifupdown_ind_cb_t ifupdown_ind_cb);
41 void osmo_netdev_set_dev_name_chg_cb(struct osmo_netdev *netdev, osmo_netdev_dev_name_chg_cb_t dev_name_chg_cb);
42 void osmo_netdev_set_mtu_chg_cb(struct osmo_netdev *netdev, osmo_netdev_mtu_chg_cb_t mtu_chg_cb);
43
44 int osmo_netdev_add_addr(struct osmo_netdev *netdev, const struct osmo_sockaddr *addr, uint8_t prefixlen);
45 int osmo_netdev_add_route(struct osmo_netdev *netdev, const struct osmo_sockaddr *dst_addr,
46 uint8_t dst_prefixlen, const struct osmo_sockaddr *gw_addr);
47 int osmo_netdev_ifupdown(struct osmo_netdev *netdev, bool ifupdown);
48
name
const char * name
osmo_netdev_set_netns_name
int osmo_netdev_set_netns_name(struct osmo_netdev *netdev, const char *netns)
Set (specify) name of the network namespace where the network interface to manage is located.
Definition: netdev.c:864
osmo_netdev_get_ifindex
unsigned int osmo_netdev_get_ifindex(const struct osmo_netdev *netdev)
Get interface index identifying the interface managed by netdev.
Definition: netdev.c:846
osmo_netdev_alloc
struct osmo_netdev * osmo_netdev_alloc(void *ctx, const char *name)
Allocate a new netdev object.
Definition: netdev.c:676
osmo_netdev_is_registered
bool osmo_netdev_is_registered(struct osmo_netdev *netdev)
Retrieve whether the netdev object is in "registered" state.
Definition: netdev.c:764
osmo_netdev_set_priv_data
void osmo_netdev_set_priv_data(struct osmo_netdev *netdev, void *priv_data)
Set private user data pointer on the netdev object.
Definition: netdev.c:772
osmo_netdev_set_ifindex
int osmo_netdev_set_ifindex(struct osmo_netdev *netdev, unsigned int ifindex)
Set (specify) interface index identifying the network interface to manage.
Definition: netdev.c:834
osmo_netdev_get_priv_data
void * osmo_netdev_get_priv_data(struct osmo_netdev *netdev)
Get private user data pointer from the netdev object.
Definition: netdev.c:781
osmo_netdev_add_route
int osmo_netdev_add_route(struct osmo_netdev *netdev, const struct osmo_sockaddr *dst_addr, uint8_t dst_prefixlen, const struct osmo_sockaddr *gw_addr)
Add IP route to netdev interface.
Definition: netdev.c:995
osmo_netdev_set_mtu_chg_cb
void osmo_netdev_set_mtu_chg_cb(struct osmo_netdev *netdev, osmo_netdev_mtu_chg_cb_t mtu_chg_cb)
Set mtu_chg_cb callback, called when a change in the network name is detected.
Definition: netdev.c:808
osmo_netdev_get_dev_name
const char * osmo_netdev_get_dev_name(const struct osmo_netdev *netdev)
Get name used to name the network interface created by the netdev object.
Definition: netdev.c:888
osmo_netdev_add_addr
int osmo_netdev_add_addr(struct osmo_netdev *netdev, const struct osmo_sockaddr *addr, uint8_t prefixlen)
Add IP address to netdev interface.
Definition: netdev.c:962
osmo_netdev_unregister
int osmo_netdev_unregister(struct osmo_netdev *netdev)
Unregister the netdev object (stop managing /moniutoring the interface)
Definition: netdev.c:747
osmo_netdev_set_ifupdown_ind_cb
void osmo_netdev_set_ifupdown_ind_cb(struct osmo_netdev *netdev, osmo_netdev_ifupdown_ind_cb_t ifupdown_ind_cb)
Set ifupdown_ind_cb callback, called when the link status (UP/DOWN) changes.
Definition: netdev.c:790
osmo_netdev_get_netns_name
const char * osmo_netdev_get_netns_name(const struct osmo_netdev *netdev)
Get name of network namespace used when opening the netdev interface.
Definition: netdev.c:876
osmo_netdev_set_dev_name_chg_cb
void osmo_netdev_set_dev_name_chg_cb(struct osmo_netdev *netdev, osmo_netdev_dev_name_chg_cb_t dev_name_chg_cb)
Set dev_name_chg_cb callback, called when a change in the network name is detected.
Definition: netdev.c:799
osmo_netdev_set_mtu
int osmo_netdev_set_mtu(struct osmo_netdev *netdev, uint32_t mtu)
Set the MTU of the network interface.
Definition: netdev.c:899
osmo_netdev_get_name
const char * osmo_netdev_get_name(const struct osmo_netdev *netdev)
Get name used to identify the netdev object.
Definition: netdev.c:817
osmo_netdev_register
int osmo_netdev_register(struct osmo_netdev *netdev)
Start managing the network device referenced by the netdev object.
Definition: netdev.c:707
osmo_netdev_free
void osmo_netdev_free(struct osmo_netdev *netdev)
Free an allocated netdev object.
Definition: netdev.c:693
osmo_netdev_ifupdown
int osmo_netdev_ifupdown(struct osmo_netdev *netdev, bool ifupdown)
Bring netdev interface UP or DOWN.
Definition: netdev.c:930
msgb.h
osmo_netdev_ifupdown_ind_cb_t
int(* osmo_netdev_ifupdown_ind_cb_t)(struct osmo_netdev *netdev, bool ifupdown)
Definition: netdev.h:14
osmo_netdev_mtu_chg_cb_t
int(* osmo_netdev_mtu_chg_cb_t)(struct osmo_netdev *netdev, unsigned int new_mtu)
Definition: netdev.h:16
osmo_netdev_dev_name_chg_cb_t
int(* osmo_netdev_dev_name_chg_cb_t)(struct osmo_netdev *netdev, const char *new_dev_name)
Definition: netdev.h:15
socket.h
Osmocom socket convenience functions.
osmo_netdev
Definition: netdev.c:259
osmo_netdev::dev_name_chg_cb
osmo_netdev_dev_name_chg_cb_t dev_name_chg_cb
Definition: netdev.c:288
osmo_netdev::mtu_chg_cb
osmo_netdev_mtu_chg_cb_t mtu_chg_cb
Definition: netdev.c:291
osmo_netdev::ifindex
unsigned int ifindex
Definition: netdev.c:270
osmo_netdev::priv_data
void * priv_data
Definition: netdev.c:279
osmo_netdev::ifupdown_ind_cb
osmo_netdev_ifupdown_ind_cb_t ifupdown_ind_cb
Definition: netdev.c:285
osmo_sockaddr
Definition: socket.h:33