diff options
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/deprecated.c (renamed from src/libnetfilter_conntrack.c) | 102 | ||||
-rw-r--r-- | src/main.c | 111 |
3 files changed, 115 insertions, 100 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 544311a..4cb3e28 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,4 +15,4 @@ libnetfilter_conntrack_la_LIBADD = conntrack/libnetfilter_conntrack_new_api.la \ expect/libnetfilter_conntrack_expect.la libnetfilter_conntrack_la_LDFLAGS = -Wc,-nostartfiles -lnfnetlink -ldl \ -version-info $(LIBVERSION) -libnetfilter_conntrack_la_SOURCES = libnetfilter_conntrack.c +libnetfilter_conntrack_la_SOURCES = main.c deprecated.c diff --git a/src/libnetfilter_conntrack.c b/src/deprecated.c index b647694..6555062 100644 --- a/src/libnetfilter_conntrack.c +++ b/src/deprecated.c @@ -6,10 +6,11 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. + * + * Warning: This file contains the old API that is deprecated! */ #include <stdio.h> #include <unistd.h> -#include <getopt.h> #include <dlfcn.h> #include <stdlib.h> #include <signal.h> @@ -66,104 +67,6 @@ static int callback_handler(struct sockaddr_nl *nladdr, return ret; } -struct nfct_handle *nfct_open_nfnl(struct nfnl_handle *nfnlh, - u_int8_t subsys_id, - unsigned int subscriptions) -{ - struct nfct_handle *cth; - - cth = (struct nfct_handle *) malloc(sizeof(struct nfct_handle)); - if (!cth) - return NULL; - - memset(cth, 0, sizeof(*cth)); - cth->nfnlh = nfnlh; - - if (subsys_id == 0 || subsys_id == NFNL_SUBSYS_CTNETLINK) { - cth->nfnlssh_ct = nfnl_subsys_open(cth->nfnlh, - NFNL_SUBSYS_CTNETLINK, - IPCTNL_MSG_MAX, - subscriptions); - if (!cth->nfnlssh_ct) - goto out_free; - } - - if (subsys_id == 0 || subsys_id == NFNL_SUBSYS_CTNETLINK_EXP) { - cth->nfnlssh_exp = nfnl_subsys_open(cth->nfnlh, - NFNL_SUBSYS_CTNETLINK_EXP, - IPCTNL_MSG_EXP_MAX, - subscriptions); - if (!cth->nfnlssh_exp) - goto out_free; - } - - return cth; - -out_free: - if (cth->nfnlssh_exp) { - nfnl_subsys_close(cth->nfnlssh_exp); - cth->nfnlssh_exp = NULL; - } - if (cth->nfnlssh_ct) { - nfnl_subsys_close(cth->nfnlssh_ct); - cth->nfnlssh_ct = NULL; - } - free(cth); - return NULL; -} - -struct nfct_handle *nfct_open(u_int8_t subsys_id, unsigned subscriptions) -{ - struct nfnl_handle *nfnlh = nfnl_open(); - struct nfct_handle *nfcth; - - if (!nfnlh) - return NULL; - - nfcth = nfct_open_nfnl(nfnlh, subsys_id, subscriptions); - if (!nfcth) - nfnl_close(nfnlh); - - return nfcth; -} - -int nfct_close(struct nfct_handle *cth) -{ - int err; - - if (cth->nfnlssh_exp) { - nfnl_subsys_close(cth->nfnlssh_exp); - cth->nfnlssh_exp = NULL; - } - if (cth->nfnlssh_ct) { - nfnl_subsys_close(cth->nfnlssh_ct); - cth->nfnlssh_ct = NULL; - } - - /* required by the new API */ - cth->cb = NULL; - free(cth->nfnl_cb.data); - - cth->nfnl_cb.call = NULL; - cth->nfnl_cb.data = NULL; - cth->nfnl_cb.attr_count = 0; - - err = nfnl_close(cth->nfnlh); - free(cth); - - return err; -} - -int nfct_fd(struct nfct_handle *cth) -{ - return nfnl_fd(cth->nfnlh); -} - -const struct nfnl_handle *nfct_nfnlh(struct nfct_handle *cth) -{ - return cth->nfnlh; -} - void nfct_register_callback(struct nfct_handle *cth, nfct_callback callback, void *data) { @@ -1310,3 +1213,4 @@ int nfct_flush_expectation_table(struct nfct_handle *cth, int family) return nfnl_talk(cth->nfnlh, &req.nlh, 0, 0, NULL, NULL, NULL); } + diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..9b57d24 --- /dev/null +++ b/src/main.c @@ -0,0 +1,111 @@ +/* + * (C) 2005-2006 by Pablo Neira Ayuso <pablo@netfilter.org> + * Harald Welte <laforge@netfilter.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ +#include <libnfnetlink/libnfnetlink.h> +#include <libnetfilter_conntrack/libnetfilter_conntrack.h> + +#include "internal.h" + +struct nfct_handle *nfct_open_nfnl(struct nfnl_handle *nfnlh, + u_int8_t subsys_id, + unsigned int subscriptions) +{ + struct nfct_handle *cth; + + cth = (struct nfct_handle *) malloc(sizeof(struct nfct_handle)); + if (!cth) + return NULL; + + memset(cth, 0, sizeof(*cth)); + cth->nfnlh = nfnlh; + + if (subsys_id == 0 || subsys_id == NFNL_SUBSYS_CTNETLINK) { + cth->nfnlssh_ct = nfnl_subsys_open(cth->nfnlh, + NFNL_SUBSYS_CTNETLINK, + IPCTNL_MSG_MAX, + subscriptions); + if (!cth->nfnlssh_ct) + goto out_free; + } + + if (subsys_id == 0 || subsys_id == NFNL_SUBSYS_CTNETLINK_EXP) { + cth->nfnlssh_exp = nfnl_subsys_open(cth->nfnlh, + NFNL_SUBSYS_CTNETLINK_EXP, + IPCTNL_MSG_EXP_MAX, + subscriptions); + if (!cth->nfnlssh_exp) + goto out_free; + } + + return cth; + +out_free: + if (cth->nfnlssh_exp) { + nfnl_subsys_close(cth->nfnlssh_exp); + cth->nfnlssh_exp = NULL; + } + if (cth->nfnlssh_ct) { + nfnl_subsys_close(cth->nfnlssh_ct); + cth->nfnlssh_ct = NULL; + } + free(cth); + return NULL; +} + +struct nfct_handle *nfct_open(u_int8_t subsys_id, unsigned subscriptions) +{ + struct nfnl_handle *nfnlh = nfnl_open(); + struct nfct_handle *nfcth; + + if (!nfnlh) + return NULL; + + nfcth = nfct_open_nfnl(nfnlh, subsys_id, subscriptions); + if (!nfcth) + nfnl_close(nfnlh); + + return nfcth; +} + +int nfct_close(struct nfct_handle *cth) +{ + int err; + + if (cth->nfnlssh_exp) { + nfnl_subsys_close(cth->nfnlssh_exp); + cth->nfnlssh_exp = NULL; + } + if (cth->nfnlssh_ct) { + nfnl_subsys_close(cth->nfnlssh_ct); + cth->nfnlssh_ct = NULL; + } + + /* required by the new API */ + cth->cb = NULL; + free(cth->nfnl_cb.data); + + cth->nfnl_cb.call = NULL; + cth->nfnl_cb.data = NULL; + cth->nfnl_cb.attr_count = 0; + + err = nfnl_close(cth->nfnlh); + free(cth); + + return err; +} + +int nfct_fd(struct nfct_handle *cth) +{ + return nfnl_fd(cth->nfnlh); +} + +const struct nfnl_handle *nfct_nfnlh(struct nfct_handle *cth) +{ + return cth->nfnlh; +} |