]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/blobdiff - tc/m_ipt.c
Convert to use rta_getattr_ functions
[lisovros/iproute2_canprio.git] / tc / m_ipt.c
index 01914dc636b3a61fb36c1335d3dfdeca4ac5cb16..dc2dedc0dd9ce7b481b462b797f29f1edf36798d 100644 (file)
@@ -14,7 +14,9 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <linux/if.h>
 #include <iptables.h>
+#include <linux/netfilter.h>
 #include <linux/netfilter_ipv4/ip_tables.h>
 #include "utils.h"
 #include "tc_util.h"
@@ -28,7 +30,6 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <stdarg.h>
-#include <limits.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/wait.h>
@@ -67,6 +68,13 @@ register_target(struct iptables_target *me)
 
 }
 
+void
+xtables_register_target(struct iptables_target *me)
+{
+       me->next = t_list;
+       t_list = me;
+}
+
 void
 exit_tryhelp(int status)
 {
@@ -153,10 +161,10 @@ int string_to_number(const char *s, unsigned int min, unsigned int max,
        return result;
 }
 
-static void free_opts(struct option *opts)
+static void free_opts(struct option *local_opts)
 {
-       if (opts != original_opts) {
-               free(opts);
+       if (local_opts != original_opts) {
+               free(local_opts);
                opts = original_opts;
                global_option_offset = 0;
        }
@@ -218,6 +226,10 @@ get_target_name(const char *name)
        struct iptables_target *m;
        char path[strlen(lib_dir) + sizeof ("/libipt_.so") + strlen(name)];
 
+#ifdef NO_SHARED_LIBS
+       return NULL;
+#endif
+
        new_name = malloc(strlen(name) + 1);
        lname = malloc(strlen(name) + 1);
        if (new_name)
@@ -247,14 +259,29 @@ get_target_name(const char *name)
                }
        }
 
-       sprintf(path, lib_dir, "/libipt_%s.so", new_name);
+       /* try libxt_xx first */
+       sprintf(path, "%s/libxt_%s.so", lib_dir, new_name);
        handle = dlopen(path, RTLD_LAZY);
        if (!handle) {
-               sprintf(path, lib_dir, "/libipt_%s.so", lname);
+               /* try libipt_xx next */
+               sprintf(path, "%s/libipt_%s.so", lib_dir, new_name);
                handle = dlopen(path, RTLD_LAZY);
+
+               if (!handle) {
+                       sprintf(path, "%s/libxt_%s.so", lib_dir , lname);
+                       handle = dlopen(path, RTLD_LAZY);
+               }
+
+               if (!handle) {
+                       sprintf(path, "%s/libipt_%s.so", lib_dir , lname);
+                       handle = dlopen(path, RTLD_LAZY);
+               }
+               /* ok, lets give up .. */
                if (!handle) {
                        fputs(dlerror(), stderr);
                        printf("\n");
+                       free(new_name);
+                       free(lname);
                        return NULL;
                }
        }
@@ -270,12 +297,16 @@ get_target_name(const char *name)
                                        fputs(error, stderr);
                                        fprintf(stderr, "\n");
                                        dlclose(handle);
+                                       free(new_name);
+                                       free(lname);
                                        return NULL;
                                }
                        }
                }
        }
 
+       free(new_name);
+       free(lname);
        return m;
 }
 
@@ -365,11 +396,9 @@ static int parse_ipt(struct action_util *a,int *argc_p,
        char **argv = *argv_p;
        int argc = 0, iargc = 0;
        char k[16];
-       int res = -1;
        int size = 0;
        int iok = 0, ok = 0;
        __u32 hook = 0, index = 0;
-       res = 0;
 
        lib_dir = getenv("IPTABLES_LIB_DIR");
        if (!lib_dir)
@@ -490,8 +519,15 @@ static int parse_ipt(struct action_util *a,int *argc_p,
        *argc_p = rargc - iargc;
        *argv_p = argv;
 
-       optind = 1;
+       optind = 0;
        free_opts(opts);
+       /* Clear flags if target will be used again */
+        m->tflags=0;
+        m->used=0;
+       /* Free allocated memory */
+        if (m->t)
+            free(m->t);
+
 
        return 0;
 
@@ -506,13 +542,17 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
        if (arg == NULL)
                return -1;
 
+       lib_dir = getenv("IPTABLES_LIB_DIR");
+       if (!lib_dir)
+               lib_dir = IPT_LIB_DIR;
+
        parse_rtattr_nested(tb, TCA_IPT_MAX, arg);
 
        if (tb[TCA_IPT_TABLE] == NULL) {
                fprintf(f, "[NULL ipt table name ] assuming mangle ");
        } else {
                fprintf(f, "tablename: %s ",
-                       (char *) RTA_DATA(tb[TCA_IPT_TABLE]));
+                       rta_getattr_str(tb[TCA_IPT_TABLE]));
        }
 
        if (tb[TCA_IPT_HOOK] == NULL) {
@@ -520,7 +560,7 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
                return -1;
        } else {
                __u32 hook;
-               hook = *(__u32 *) RTA_DATA(tb[TCA_IPT_HOOK]);
+               hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
                fprintf(f, " hook: %s \n", ipthooks[hook]);
        }
 
@@ -551,7 +591,7 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
                        fprintf(f, " [NULL ipt target index ]\n");
                } else {
                        __u32 index;
-                       index = *(__u32 *) RTA_DATA(tb[TCA_IPT_INDEX]);
+                       index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
                        fprintf(f, " \n\tindex %d", index);
                }