]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
ip: add IP_LIB_DIR environment variable
authorSergey Ryazanov <ryazanov.s.a@gmail.com>
Sun, 22 Nov 2020 17:39:21 +0000 (20:39 +0300)
committerDavid Ahern <dsahern@gmail.com>
Wed, 2 Dec 2020 16:37:07 +0000 (16:37 +0000)
Do not hardcode /usr/lib/ip as a path and allow libraries path
configuration in run-time.

Signed-off-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
ip/ip.c
ip/ip_common.h
ip/iplink.c

diff --git a/ip/ip.c b/ip/ip.c
index 466dbb5263d644aa735541e736d07b6c93ad89a7..40d2998ae60bab32ef6ef7bf708e735cf51dd772 100644 (file)
--- a/ip/ip.c
+++ b/ip/ip.c
 #include "rt_names.h"
 #include "bpf_util.h"
 
+#ifndef LIBDIR
+#define LIBDIR "/usr/lib"
+#endif
+
 int preferred_family = AF_UNSPEC;
 int human_readable;
 int use_iec;
@@ -42,6 +46,17 @@ bool do_all;
 
 struct rtnl_handle rth = { .fd = -1 };
 
+const char *get_ip_lib_dir(void)
+{
+       const char *lib_dir;
+
+       lib_dir = getenv("IP_LIB_DIR");
+       if (!lib_dir)
+               lib_dir = LIBDIR "/ip";
+
+       return lib_dir;
+}
+
 static void usage(void) __attribute__((noreturn));
 
 static void usage(void)
index d604f7554405ade78abd7aec84325136a57871e8..227eddd3baf2972252a283dbb419f398c41bc3e1 100644 (file)
@@ -27,6 +27,8 @@ struct link_filter {
        int target_nsid;
 };
 
+const char *get_ip_lib_dir(void);
+
 int get_operstate(const char *name);
 int print_linkinfo(struct nlmsghdr *n, void *arg);
 int print_addrinfo(struct nlmsghdr *n, void *arg);
index f5766c39507b22853a94e47292fcb27dd82ed7eb..27c9be442a7ab9369ceadb88b1323b7fd8a73dbe 100644 (file)
@@ -34,9 +34,6 @@
 #include "namespace.h"
 
 #define IPLINK_IOCTL_COMPAT    1
-#ifndef LIBDIR
-#define LIBDIR "/usr/lib"
-#endif
 
 #ifndef GSO_MAX_SIZE
 #define GSO_MAX_SIZE           65536
@@ -157,7 +154,7 @@ struct link_util *get_link_kind(const char *id)
                if (strcmp(l->id, id) == 0)
                        return l;
 
-       snprintf(buf, sizeof(buf), LIBDIR "/ip/link_%s.so", id);
+       snprintf(buf, sizeof(buf), "%s/link_%s.so", get_ip_lib_dir(), id);
        dlh = dlopen(buf, RTLD_LAZY);
        if (dlh == NULL) {
                /* look in current binary, only open once */