pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/31071 )
Change subject: netdev: Fix compilation building with --disable-libmnl ......................................................................
netdev: Fix compilation building with --disable-libmnl
netdev.h doesn't expose its use of libmnl publicly. It could actually be implemented using other subsystems internally, such as ioctl() or other OS-dependent APIs. Hence, if --disable-libmnl is used, still make the API available but make it fail with -ENOTSUP on functionalities which are only implemented through libmnl so far.
Change-Id: I62bdea075afb9e0cc2bbcec6dd3a930e8f7bbc40 --- M src/core/netdev.c 1 file changed, 31 insertions(+), 1 deletion(-)
Approvals: daniel: Looks good to me, but someone else must approve msuraev: Looks good to me, but someone else must approve fixeria: Looks good to me, but someone else must approve pespin: Looks good to me, approved Jenkins Builder: Verified
diff --git a/src/core/netdev.c b/src/core/netdev.c index c0097fe..28eafbd 100644 --- a/src/core/netdev.c +++ b/src/core/netdev.c @@ -94,10 +94,13 @@ #include <osmocom/core/linuxlist.h> #include <osmocom/core/logging.h> #include <osmocom/core/socket.h> -#include <osmocom/core/mnl.h> #include <osmocom/core/netns.h> #include <osmocom/core/netdev.h>
+#if ENABLE_LIBMNL +#include <osmocom/core/mnl.h> +#endif + #define IFINDEX_UNUSED 0
#define LOGNETDEV(netdev, lvl, fmt, args ...) \ @@ -114,7 +117,9 @@ unsigned int refcount; /* Number of osmo_netdev currently registered on this netns */ const char *netns_name; /* default netns has empty string "" (never NULL!) */ int netns_fd; /* FD to the netns with name "netns_name" above */ +#if ENABLE_LIBMNL struct osmo_mnl *omnl; +#endif };
static struct netdev_netns_ctx *netdev_netns_ctx_alloc(void *ctx, const char *netns_name) @@ -141,10 +146,12 @@
llist_del(&netns_ctx->entry);
+#if ENABLE_LIBMNL if (netns_ctx->omnl) { osmo_mnl_destroy(netns_ctx->omnl); netns_ctx->omnl = NULL; } +#endif
if (netns_ctx->netns_fd != -1) { close(netns_ctx->netns_fd); @@ -153,7 +160,9 @@ talloc_free(netns_ctx); }
+#if ENABLE_LIBMNL static int netdev_netns_ctx_mnl_cb(const struct nlmsghdr *nlh, void *data); +#endif
static int netdev_netns_ctx_init(struct netdev_netns_ctx *netns_ctx) { @@ -179,8 +188,12 @@ } }
+#if ENABLE_LIBMNL netns_ctx->omnl = osmo_mnl_init(NULL, NETLINK_ROUTE, RTMGRP_LINK, netdev_netns_ctx_mnl_cb, netns_ctx); rc = (netns_ctx->omnl ? 0 : -EFAULT); +#else + rc = 0; +#endif
/* switch back to default namespace */ if (netns_ctx->netns_name[0] != '\0') { @@ -312,6 +325,7 @@ } \ } while (0)
+#if ENABLE_LIBMNL /* validate the netlink attributes */ static int netdev_mnl_data_attr_cb(const struct nlattr *attr, void *data) { @@ -596,6 +610,7 @@
return 0; } +#endif /* if ENABLE_LIBMNL */
/*! Allocate a new netdev object. * \param[in] ctx talloc context to use as a parent when allocating the netdev object @@ -833,8 +848,13 @@
NETDEV_NETNS_ENTER(netdev, &switch_state, "ifupdown");
+#if ENABLE_LIBMNL rc = netdev_mnl_set_ifupdown(netdev->netns_ctx->omnl, netdev->ifindex, netdev->dev_name, ifupdown); +#else + LOGNETDEV(netdev, LOGL_ERROR, "%s: NOT SUPPORTED. Build libosmocore with --enable-libmnl.\n", __func__); + rc = -ENOTSUP; +#endif
NETDEV_NETNS_EXIT(netdev, &switch_state, "ifupdown");
@@ -861,7 +881,12 @@
NETDEV_NETNS_ENTER(netdev, &switch_state, "Add address");
+#if ENABLE_LIBMNL rc = netdev_mnl_add_addr(netdev->netns_ctx->omnl, netdev->ifindex, addr, prefixlen); +#else + LOGNETDEV(netdev, LOGL_ERROR, "%s: NOT SUPPORTED. Build libosmocore with --enable-libmnl.\n", __func__); + rc = -ENOTSUP; +#endif
NETDEV_NETNS_EXIT(netdev, &switch_state, "Add address");
@@ -893,7 +918,12 @@
NETDEV_NETNS_ENTER(netdev, &switch_state, "Add route");
+#if ENABLE_LIBMNL rc = netdev_mnl_add_route(netdev->netns_ctx->omnl, netdev->ifindex, dst_addr, dst_prefixlen, gw_addr); +#else + LOGNETDEV(netdev, LOGL_ERROR, "%s: NOT SUPPORTED. Build libosmocore with --enable-libmnl.\n", __func__); + rc = -ENOTSUP; +#endif
NETDEV_NETNS_EXIT(netdev, &switch_state, "Add route");