diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2023-01-24 17:34:34 +0100 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2023-01-25 16:08:35 +0100 |
commit | 51e9dde95eb3eab16e572cff8b0f0841837201b8 (patch) | |
tree | b102a8365162579be415bf1347a33ed4967a66a5 /include/osmocom/core | |
parent | 9d0321d041860894578941dfb203328c61b5c645 (diff) |
Introduce tundev API
The data structre is held private so that it can be easily extended in
the future.
Change-Id: I6f8324da9ba49b9249682e2ec5b45297f18dd8c2
Diffstat (limited to 'include/osmocom/core')
-rw-r--r-- | include/osmocom/core/Makefile.am | 1 | ||||
-rw-r--r-- | include/osmocom/core/tun.h | 43 |
2 files changed, 44 insertions, 0 deletions
diff --git a/include/osmocom/core/Makefile.am b/include/osmocom/core/Makefile.am index 3b2ef30d..e1cd92ae 100644 --- a/include/osmocom/core/Makefile.am +++ b/include/osmocom/core/Makefile.am @@ -55,6 +55,7 @@ osmocore_HEADERS = \ thread.h \ timer.h \ timer_compat.h \ + tun.h \ utils.h \ write_queue.h \ sockaddr_str.h \ diff --git a/include/osmocom/core/tun.h b/include/osmocom/core/tun.h new file mode 100644 index 00000000..86bd8df0 --- /dev/null +++ b/include/osmocom/core/tun.h @@ -0,0 +1,43 @@ +/*! \file tun.h + * tunnel network device convenience functions. */ + +#pragma once +#if (!EMBEDDED) + +#include <stddef.h> +#include <stdint.h> + +#include <osmocom/core/msgb.h> +#include <osmocom/core/socket.h> +#include <osmocom/core/netdev.h> + +struct osmo_tundev; + +/* callback user gets ownership of the msgb and is expected to free it. */ +typedef int (*osmo_tundev_data_ind_cb_t)(struct osmo_tundev *tun, struct msgb *msg); + +struct osmo_tundev *osmo_tundev_alloc(void *ctx, const char *name); +void osmo_tundev_free(struct osmo_tundev *tundev); +int osmo_tundev_open(struct osmo_tundev *tundev); +int osmo_tundev_close(struct osmo_tundev *tundev); +bool osmo_tundev_is_open(struct osmo_tundev *tundev); + +void osmo_tundev_set_priv_data(struct osmo_tundev *tundev, void *priv_data); +void *osmo_tundev_get_priv_data(struct osmo_tundev *tundev); + +void osmo_tundev_set_data_ind_cb(struct osmo_tundev *tundev, osmo_tundev_data_ind_cb_t data_ind_cb); + +const char *osmo_tundev_get_name(const struct osmo_tundev *tundev); + +int osmo_tundev_set_dev_name(struct osmo_tundev *tundev, const char *dev_name); +const char *osmo_tundev_get_dev_name(const struct osmo_tundev *tundev); + +int osmo_tundev_set_netns_name(struct osmo_tundev *tundev, const char *netns); +const char *osmo_tundev_get_netns_name(const struct osmo_tundev *tundev); + +struct osmo_netdev *osmo_tundev_get_netdev(struct osmo_tundev *tundev); + +int osmo_tundev_send(struct osmo_tundev *tundev, struct msgb *msg); + +#endif /* (!EMBEDDED) */ +/*! @} */ |