blob: 86bd8df0e53a73f9b0bd9bf9665dbe6e11431d46 [file] [log] [blame]
Pau Espin Pedrol51e9dde2023-01-24 17:34:34 +01001/*! \file tun.h
2 * tunnel network device convenience functions. */
3
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#include <osmocom/core/netdev.h>
13
14struct osmo_tundev;
15
16/* callback user gets ownership of the msgb and is expected to free it. */
17typedef int (*osmo_tundev_data_ind_cb_t)(struct osmo_tundev *tun, struct msgb *msg);
18
19struct osmo_tundev *osmo_tundev_alloc(void *ctx, const char *name);
20void osmo_tundev_free(struct osmo_tundev *tundev);
21int osmo_tundev_open(struct osmo_tundev *tundev);
22int osmo_tundev_close(struct osmo_tundev *tundev);
23bool osmo_tundev_is_open(struct osmo_tundev *tundev);
24
25void osmo_tundev_set_priv_data(struct osmo_tundev *tundev, void *priv_data);
26void *osmo_tundev_get_priv_data(struct osmo_tundev *tundev);
27
28void osmo_tundev_set_data_ind_cb(struct osmo_tundev *tundev, osmo_tundev_data_ind_cb_t data_ind_cb);
29
30const char *osmo_tundev_get_name(const struct osmo_tundev *tundev);
31
32int osmo_tundev_set_dev_name(struct osmo_tundev *tundev, const char *dev_name);
33const char *osmo_tundev_get_dev_name(const struct osmo_tundev *tundev);
34
35int osmo_tundev_set_netns_name(struct osmo_tundev *tundev, const char *netns);
36const char *osmo_tundev_get_netns_name(const struct osmo_tundev *tundev);
37
38struct osmo_netdev *osmo_tundev_get_netdev(struct osmo_tundev *tundev);
39
40int osmo_tundev_send(struct osmo_tundev *tundev, struct msgb *msg);
41
42#endif /* (!EMBEDDED) */
43/*! @} */