From: Stephen Hemminger Date: Tue, 6 Mar 2007 21:03:19 +0000 (-0800) Subject: iptables library fix X-Git-Tag: v2.6.23-071016~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de539ecf6cc04530ee88839722be700fd1b0db01;p=thirdparty%2Fiproute2.git iptables library fix Don't hard code iptables library path. Allow use of environment variable. Signed-off-by: Stephen Hemminger --- diff --git a/include/iptables_common.h b/include/iptables_common.h index 82b0febdc..6f7e4295e 100644 --- a/include/iptables_common.h +++ b/include/iptables_common.h @@ -5,34 +5,47 @@ enum exittype { OTHER_PROBLEM = 1, 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)); int check_inverse(const char option[], int *invert, int *optind, int argc); -extern int string_to_number(const char *, - unsigned int, +extern int string_to_number(const char *, + unsigned int, unsigned int, unsigned int *); -extern int string_to_number_l(const char *, - unsigned long int, +extern int string_to_number_l(const char *, + unsigned long int, unsigned long int, unsigned long *); -extern int string_to_number_ll(const char *, - unsigned long long int, +extern int string_to_number_ll(const char *, + unsigned long long int, unsigned long long int, unsigned long long *); 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, format(printf,2,3))); extern const char *program_name, *program_version; extern char *lib_dir; +#define _init __attribute__((constructor)) my_init #ifdef NO_SHARED_LIBS # ifdef _INIT +# undef _init # define _init _INIT # endif extern void init_extensions(void); #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*/ diff --git a/tc/m_ipt.c b/tc/m_ipt.c index 3d6533916..01914dc63 100644 --- a/tc/m_ipt.c +++ b/tc/m_ipt.c @@ -8,10 +8,7 @@ * 2 of the License, or (at your option) any later version. * * Authors: J Hadi Salim (hadi@cyberus.ca) - * - * TODO: bad bad hardcoding IPT_LIB_DIR and PROC_SYS_MODPROBE - * -*/ + */ #include #include @@ -58,6 +55,7 @@ static struct option *opts = original_opts; static unsigned int global_option_offset = 0; #define OPTION_OFFSET 256 +char *lib_dir; void register_target(struct iptables_target *me) @@ -212,14 +210,13 @@ find_t(char *name) } static struct iptables_target * -get_target_name(char *name) +get_target_name(const char *name) { void *handle; char *error; char *new_name, *lname; struct iptables_target *m; - - char path[sizeof (IPT_LIB_DIR) + sizeof ("/libipt_.so") + strlen(name)]; + char path[strlen(lib_dir) + sizeof ("/libipt_.so") + strlen(name)]; new_name = malloc(strlen(name) + 1); lname = malloc(strlen(name) + 1); @@ -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); if (!handle) { - sprintf(path, IPT_LIB_DIR "/libipt_%s.so", lname); + sprintf(path, lib_dir, "/libipt_%s.so", lname); handle = dlopen(path, RTLD_LAZY); if (!handle) { fputs(dlerror(), stderr); @@ -374,6 +371,10 @@ static int parse_ipt(struct action_util *a,int *argc_p, __u32 hook = 0, index = 0; res = 0; + lib_dir = getenv("IPTABLES_LIB_DIR"); + if (!lib_dir) + lib_dir = IPT_LIB_DIR; + { int i; for (i = 0; i < rargc; i++) {