libosmocore 1.9.0.196-9975
Osmocom core library
netdev.h
Go to the documentation of this file.
1
4#pragma once
5#if (!EMBEDDED)
6
7#include <stddef.h>
8#include <stdint.h>
9
10#include <osmocom/core/msgb.h>
11#include <osmocom/core/socket.h>
12
13struct osmo_netdev;
14
15typedef int (*osmo_netdev_ifupdown_ind_cb_t)(struct osmo_netdev *netdev, bool ifupdown);
16typedef int (*osmo_netdev_dev_name_chg_cb_t)(struct osmo_netdev *netdev, const char *new_dev_name);
17typedef int (*osmo_netdev_mtu_chg_cb_t)(struct osmo_netdev *netdev, unsigned int new_mtu);
18
19struct osmo_netdev *osmo_netdev_alloc(void *ctx, const char *name);
20void osmo_netdev_free(struct osmo_netdev *netdev);
21
22int osmo_netdev_register(struct osmo_netdev *netdev);
23int osmo_netdev_unregister(struct osmo_netdev *netdev);
24bool osmo_netdev_is_registered(struct osmo_netdev *netdev);
25
26const char *osmo_netdev_get_name(const struct osmo_netdev *netdev);
27
28void osmo_netdev_set_priv_data(struct osmo_netdev *netdev, void *priv_data);
29void *osmo_netdev_get_priv_data(struct osmo_netdev *netdev);
30
31int osmo_netdev_set_ifindex(struct osmo_netdev *netdev, unsigned int ifindex);
32unsigned int osmo_netdev_get_ifindex(const struct osmo_netdev *netdev);
33
34const char *osmo_netdev_get_dev_name(const struct osmo_netdev *netdev);
35
36int osmo_netdev_set_netns_name(struct osmo_netdev *netdev, const char *netns);
37const char *osmo_netdev_get_netns_name(const struct osmo_netdev *netdev);
38
42
43int osmo_netdev_add_addr(struct osmo_netdev *netdev, const struct osmo_sockaddr *addr, uint8_t prefixlen);
44int osmo_netdev_add_route(struct osmo_netdev *netdev, const struct osmo_sockaddr *dst_addr,
45 uint8_t dst_prefixlen, const struct osmo_sockaddr *gw_addr);
46int osmo_netdev_ifupdown(struct osmo_netdev *netdev, bool ifupdown);
47
48#endif /* (!EMBEDDED) */
const char * 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:831
unsigned int osmo_netdev_get_ifindex(const struct osmo_netdev *netdev)
Get interface index identifying the interface managed by netdev.
Definition: netdev.c:813
struct osmo_netdev * osmo_netdev_alloc(void *ctx, const char *name)
Allocate a new netdev object.
Definition: netdev.c:643
bool osmo_netdev_is_registered(struct osmo_netdev *netdev)
Retrieve whether the netdev object is in "registered" state.
Definition: netdev.c:731
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:739
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:801
void * osmo_netdev_get_priv_data(struct osmo_netdev *netdev)
Get private user data pointer from the netdev object.
Definition: netdev.c:748
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:930
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:775
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:855
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:897
int osmo_netdev_unregister(struct osmo_netdev *netdev)
Unregister the netdev object (stop managing /moniutoring the interface)
Definition: netdev.c:714
void osmo_netdev_set_ifupdown_ind_cb(struct osmo_netdev *netdev, osmo_netdev_ifupdown_ind_cb_t ifupdown_ind_cb)
Set data_ind_cb callback, called when a new packet is received on the network interface.
Definition: netdev.c:757
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:843
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:766
const char * osmo_netdev_get_name(const struct osmo_netdev *netdev)
Get name used to identify the netdev object.
Definition: netdev.c:784
int osmo_netdev_register(struct osmo_netdev *netdev)
Start managing the network device referenced by the netdev object.
Definition: netdev.c:674
void osmo_netdev_free(struct osmo_netdev *netdev)
Free an allocated netdev object.
Definition: netdev.c:660
int osmo_netdev_ifupdown(struct osmo_netdev *netdev, bool ifupdown)
Bring netdev interface UP or DOWN.
Definition: netdev.c:865
int(* osmo_netdev_ifupdown_ind_cb_t)(struct osmo_netdev *netdev, bool ifupdown)
Definition: netdev.h:15
int(* osmo_netdev_mtu_chg_cb_t)(struct osmo_netdev *netdev, unsigned int new_mtu)
Definition: netdev.h:17
int(* osmo_netdev_dev_name_chg_cb_t)(struct osmo_netdev *netdev, const char *new_dev_name)
Definition: netdev.h:16
Osmocom socket convenience functions.
Definition: netdev.c:255
osmo_netdev_dev_name_chg_cb_t dev_name_chg_cb
Definition: netdev.c:284
osmo_netdev_mtu_chg_cb_t mtu_chg_cb
Definition: netdev.c:287
unsigned int ifindex
Definition: netdev.c:266
void * priv_data
Definition: netdev.c:275
osmo_netdev_ifupdown_ind_cb_t ifupdown_ind_cb
Definition: netdev.c:281
Definition: socket.h:38