Commit de539ecf authored by Stephen Hemminger's avatar Stephen Hemminger

iptables library fix

Don't hard code iptables library path. Allow use of environment variable.
Signed-off-by: default avatarStephen Hemminger <shemminger@linux-foundation.org>
parent 95dd5950
...@@ -5,34 +5,47 @@ ...@@ -5,34 +5,47 @@
enum exittype { enum exittype {
OTHER_PROBLEM = 1, OTHER_PROBLEM = 1,
PARAMETER_PROBLEM, PARAMETER_PROBLEM,
VERSION_PROBLEM VERSION_PROBLEM,
RESOURCE_PROBLEM
}; };
extern void exit_printhelp(void) __attribute__((noreturn));
/* this is a special 64bit data type that is 8-byte aligned */
#define aligned_u64 unsigned long long __attribute__((aligned(8)))
extern void exit_printhelp() __attribute__((noreturn));
extern void exit_tryhelp(int) __attribute__((noreturn)); extern void exit_tryhelp(int) __attribute__((noreturn));
int check_inverse(const char option[], int *invert, int *optind, int argc); int check_inverse(const char option[], int *invert, int *optind, int argc);
extern int string_to_number(const char *, extern int string_to_number(const char *,
unsigned int, unsigned int,
unsigned int, unsigned int,
unsigned int *); unsigned int *);
extern int string_to_number_l(const char *, extern int string_to_number_l(const char *,
unsigned long int, unsigned long int,
unsigned long int, unsigned long int,
unsigned long *); unsigned long *);
extern int string_to_number_ll(const char *, extern int string_to_number_ll(const char *,
unsigned long long int, unsigned long long int,
unsigned long long int, unsigned long long int,
unsigned long long *); unsigned long long *);
extern int iptables_insmod(const char *modname, const char *modprobe); extern int iptables_insmod(const char *modname, const char *modprobe);
extern int load_iptables_ko(const char *modprobe);
void exit_error(enum exittype, char *, ...)__attribute__((noreturn, void exit_error(enum exittype, char *, ...)__attribute__((noreturn,
format(printf,2,3))); format(printf,2,3)));
extern const char *program_name, *program_version; extern const char *program_name, *program_version;
extern char *lib_dir; extern char *lib_dir;
#define _init __attribute__((constructor)) my_init
#ifdef NO_SHARED_LIBS #ifdef NO_SHARED_LIBS
# ifdef _INIT # ifdef _INIT
# undef _init
# define _init _INIT # define _init _INIT
# endif # endif
extern void init_extensions(void); extern void init_extensions(void);
#endif #endif
#define __be32 u_int32_t
#define __le32 u_int32_t
#define __be16 u_int16_t
#define __le16 u_int16_t
#endif /*_IPTABLES_COMMON_H*/ #endif /*_IPTABLES_COMMON_H*/
...@@ -8,10 +8,7 @@ ...@@ -8,10 +8,7 @@
* 2 of the License, or (at your option) any later version. * 2 of the License, or (at your option) any later version.
* *
* Authors: J Hadi Salim (hadi@cyberus.ca) * Authors: J Hadi Salim (hadi@cyberus.ca)
* */
* TODO: bad bad hardcoding IPT_LIB_DIR and PROC_SYS_MODPROBE
*
*/
#include <syslog.h> #include <syslog.h>
#include <sys/socket.h> #include <sys/socket.h>
...@@ -58,6 +55,7 @@ static struct option *opts = original_opts; ...@@ -58,6 +55,7 @@ static struct option *opts = original_opts;
static unsigned int global_option_offset = 0; static unsigned int global_option_offset = 0;
#define OPTION_OFFSET 256 #define OPTION_OFFSET 256
char *lib_dir;
void void
register_target(struct iptables_target *me) register_target(struct iptables_target *me)
...@@ -212,14 +210,13 @@ find_t(char *name) ...@@ -212,14 +210,13 @@ find_t(char *name)
} }
static struct iptables_target * static struct iptables_target *
get_target_name(char *name) get_target_name(const char *name)
{ {
void *handle; void *handle;
char *error; char *error;
char *new_name, *lname; char *new_name, *lname;
struct iptables_target *m; struct iptables_target *m;
char path[strlen(lib_dir) + sizeof ("/libipt_.so") + strlen(name)];
char path[sizeof (IPT_LIB_DIR) + sizeof ("/libipt_.so") + strlen(name)];
new_name = malloc(strlen(name) + 1); new_name = malloc(strlen(name) + 1);
lname = malloc(strlen(name) + 1); lname = malloc(strlen(name) + 1);
...@@ -250,10 +247,10 @@ get_target_name(char *name) ...@@ -250,10 +247,10 @@ get_target_name(char *name)
} }
} }
sprintf(path, IPT_LIB_DIR "/libipt_%s.so", new_name); sprintf(path, lib_dir, "/libipt_%s.so", new_name);
handle = dlopen(path, RTLD_LAZY); handle = dlopen(path, RTLD_LAZY);
if (!handle) { if (!handle) {
sprintf(path, IPT_LIB_DIR "/libipt_%s.so", lname); sprintf(path, lib_dir, "/libipt_%s.so", lname);
handle = dlopen(path, RTLD_LAZY); handle = dlopen(path, RTLD_LAZY);
if (!handle) { if (!handle) {
fputs(dlerror(), stderr); fputs(dlerror(), stderr);
...@@ -374,6 +371,10 @@ static int parse_ipt(struct action_util *a,int *argc_p, ...@@ -374,6 +371,10 @@ static int parse_ipt(struct action_util *a,int *argc_p,
__u32 hook = 0, index = 0; __u32 hook = 0, index = 0;
res = 0; res = 0;
lib_dir = getenv("IPTABLES_LIB_DIR");
if (!lib_dir)
lib_dir = IPT_LIB_DIR;
{ {
int i; int i;
for (i = 0; i < rargc; i++) { for (i = 0; i < rargc; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment