00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <libnfnetlink/libnfnetlink.h>
00011 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
00012
00013 #include "internal/internal.h"
00014
00015 struct nfct_handle *nfct_open_nfnl(struct nfnl_handle *nfnlh,
00016 u_int8_t subsys_id,
00017 unsigned int subscriptions)
00018 {
00019 struct nfct_handle *cth;
00020
00021 cth = malloc(sizeof(struct nfct_handle));
00022 if (!cth)
00023 return NULL;
00024
00025 memset(cth, 0, sizeof(*cth));
00026 cth->nfnlh = nfnlh;
00027
00028 if (subsys_id == 0 || subsys_id == NFNL_SUBSYS_CTNETLINK) {
00029 cth->nfnlssh_ct = nfnl_subsys_open(cth->nfnlh,
00030 NFNL_SUBSYS_CTNETLINK,
00031 IPCTNL_MSG_MAX,
00032 subscriptions);
00033 if (!cth->nfnlssh_ct)
00034 goto out_free;
00035 }
00036
00037 if (subsys_id == 0 || subsys_id == NFNL_SUBSYS_CTNETLINK_EXP) {
00038 cth->nfnlssh_exp = nfnl_subsys_open(cth->nfnlh,
00039 NFNL_SUBSYS_CTNETLINK_EXP,
00040 IPCTNL_MSG_EXP_MAX,
00041 subscriptions);
00042 if (!cth->nfnlssh_exp)
00043 goto out_free;
00044 }
00045
00046 return cth;
00047
00048 out_free:
00049 if (cth->nfnlssh_exp) {
00050 nfnl_subsys_close(cth->nfnlssh_exp);
00051 cth->nfnlssh_exp = NULL;
00052 }
00053 if (cth->nfnlssh_ct) {
00054 nfnl_subsys_close(cth->nfnlssh_ct);
00055 cth->nfnlssh_ct = NULL;
00056 }
00057 free(cth);
00058 return NULL;
00059 }
00060
00084 struct nfct_handle *nfct_open(u_int8_t subsys_id, unsigned subscriptions)
00085 {
00086 struct nfnl_handle *nfnlh = nfnl_open();
00087 struct nfct_handle *nfcth;
00088
00089 if (!nfnlh)
00090 return NULL;
00091
00092 nfcth = nfct_open_nfnl(nfnlh, subsys_id, subscriptions);
00093 if (!nfcth)
00094 nfnl_close(nfnlh);
00095
00096 return nfcth;
00097 }
00098
00105 int nfct_close(struct nfct_handle *cth)
00106 {
00107 int err;
00108
00109 if (cth->nfnlssh_exp) {
00110 nfnl_subsys_close(cth->nfnlssh_exp);
00111 cth->nfnlssh_exp = NULL;
00112 }
00113 if (cth->nfnlssh_ct) {
00114 nfnl_subsys_close(cth->nfnlssh_ct);
00115 cth->nfnlssh_ct = NULL;
00116 }
00117
00118
00119 cth->cb = NULL;
00120 cth->cb2 = NULL;
00121 cth->expect_cb = NULL;
00122 cth->expect_cb2 = NULL;
00123 free(cth->nfnl_cb_ct.data);
00124 free(cth->nfnl_cb_exp.data);
00125
00126 cth->nfnl_cb_ct.call = NULL;
00127 cth->nfnl_cb_ct.data = NULL;
00128 cth->nfnl_cb_ct.attr_count = 0;
00129
00130 cth->nfnl_cb_exp.call = NULL;
00131 cth->nfnl_cb_exp.data = NULL;
00132 cth->nfnl_cb_exp.attr_count = 0;
00133
00134 err = nfnl_close(cth->nfnlh);
00135 free(cth);
00136
00137 return err;
00138 }
00139
00144 int nfct_fd(struct nfct_handle *cth)
00145 {
00146 return nfnl_fd(cth->nfnlh);
00147 }
00148
00149 const struct nfnl_handle *nfct_nfnlh(struct nfct_handle *cth)
00150 {
00151 return cth->nfnlh;
00152 }
00153