summaryrefslogtreecommitdiffstats
path: root/src/nfct-extensions/helper.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2013-09-30 20:09:57 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2013-10-01 13:22:41 +0200
commit386968d321d02571b593b3bbbf39891f44397469 (patch)
tree03415ae3e04ae36cf165b973ded09eced00d7ecb /src/nfct-extensions/helper.c
parent5c0d2ffd9cc954b94344795deaaadb1a8fd68b59 (diff)
nfct: src: add nfct_mnl_talk and use it
Add helper function nfct_mnl_talk and use it. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/nfct-extensions/helper.c')
-rw-r--r--src/nfct-extensions/helper.c99
1 files changed, 13 insertions, 86 deletions
diff --git a/src/nfct-extensions/helper.c b/src/nfct-extensions/helper.c
index 98ccde2..4171a47 100644
--- a/src/nfct-extensions/helper.c
+++ b/src/nfct-extensions/helper.c
@@ -127,7 +127,6 @@ static int nfct_cmd_helper_list(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
unsigned int seq, portid;
- int ret;
if (argc > 3) {
nfct_perror("too many arguments");
@@ -150,22 +149,11 @@ static int nfct_cmd_helper_list(int argc, char *argv[])
}
portid = mnl_socket_get_portid(nl);
- if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
- nfct_perror("mnl_socket_send");
+ if (nfct_mnl_talk(nl, nlh, seq, portid, nfct_helper_cb, NULL) < 0) {
+ nfct_perror("netlink error");
return -1;
}
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- while (ret > 0) {
- ret = mnl_cb_run(buf, ret, seq, portid, nfct_helper_cb, NULL);
- if (ret <= 0)
- break;
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- }
- if (ret == -1) {
- nfct_perror("error");
- return -1;
- }
mnl_socket_close(nl);
return 0;
@@ -181,7 +169,7 @@ static int nfct_cmd_helper_add(int argc, char *argv[])
uint16_t l3proto;
uint8_t l4proto;
struct ctd_helper *helper;
- int ret, j;
+ int j;
if (argc < 6) {
nfct_perror("missing parameters\n"
@@ -266,22 +254,11 @@ static int nfct_cmd_helper_add(int argc, char *argv[])
}
portid = mnl_socket_get_portid(nl);
- if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
- nfct_perror("mnl_socket_send");
+ if (nfct_mnl_talk(nl, nlh, seq, portid, NULL, NULL) < 0) {
+ nfct_perror("netlink error");
return -1;
}
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- while (ret > 0) {
- ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);
- if (ret <= 0)
- break;
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- }
- if (ret == -1) {
- nfct_perror("error");
- return -1;
- }
mnl_socket_close(nl);
return 0;
@@ -294,7 +271,6 @@ static int nfct_cmd_helper_delete(int argc, char *argv[])
struct nlmsghdr *nlh;
uint32_t portid, seq;
struct nfct_helper *t;
- int ret;
if (argc < 4) {
nfct_perror("missing helper policy name");
@@ -359,20 +335,8 @@ static int nfct_cmd_helper_delete(int argc, char *argv[])
}
portid = mnl_socket_get_portid(nl);
- if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
- nfct_perror("mnl_socket_send");
- return -1;
- }
-
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- while (ret > 0) {
- ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);
- if (ret <= 0)
- break;
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- }
- if (ret == -1) {
- nfct_perror("error");
+ if (nfct_mnl_talk(nl, nlh, seq, portid, NULL, NULL) < 0) {
+ nfct_perror("netlink error");
return -1;
}
@@ -388,7 +352,6 @@ static int nfct_cmd_helper_get(int argc, char *argv[])
struct nlmsghdr *nlh;
uint32_t portid, seq;
struct nfct_helper *t;
- int ret;
if (argc < 4) {
nfct_perror("missing helper policy name");
@@ -453,22 +416,11 @@ static int nfct_cmd_helper_get(int argc, char *argv[])
}
portid = mnl_socket_get_portid(nl);
- if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
- nfct_perror("mnl_socket_send");
+ if (nfct_mnl_talk(nl, nlh, seq, portid, nfct_helper_cb, NULL) < 0) {
+ nfct_perror("netlink error");
return -1;
}
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- while (ret > 0) {
- ret = mnl_cb_run(buf, ret, seq, portid, nfct_helper_cb, NULL);
- if (ret <= 0)
- break;
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- }
- if (ret == -1) {
- nfct_perror("error");
- return -1;
- }
mnl_socket_close(nl);
return 0;
@@ -480,7 +432,6 @@ static int nfct_cmd_helper_flush(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
uint32_t portid, seq;
- int ret;
if (argc > 3) {
nfct_perror("too many arguments");
@@ -503,20 +454,8 @@ static int nfct_cmd_helper_flush(int argc, char *argv[])
}
portid = mnl_socket_get_portid(nl);
- if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
- nfct_perror("mnl_socket_send");
- return -1;
- }
-
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- while (ret > 0) {
- ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);
- if (ret <= 0)
- break;
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- }
- if (ret == -1) {
- nfct_perror("error");
+ if (nfct_mnl_talk(nl, nlh, seq, portid, NULL, NULL) < 0) {
+ nfct_perror("netlink error");
return -1;
}
@@ -535,7 +474,6 @@ static int nfct_cmd_helper_disable(int argc, char *argv[])
uint16_t l3proto;
uint8_t l4proto;
struct ctd_helper *helper;
- int ret;
if (argc < 6) {
nfct_perror("missing parameters\n"
@@ -598,22 +536,11 @@ static int nfct_cmd_helper_disable(int argc, char *argv[])
}
portid = mnl_socket_get_portid(nl);
- if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
- nfct_perror("mnl_socket_send");
+ if (nfct_mnl_talk(nl, nlh, seq, portid, NULL, NULL) < 0) {
+ nfct_perror("netlink error");
return -1;
}
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- while (ret > 0) {
- ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);
- if (ret <= 0)
- break;
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- }
- if (ret == -1) {
- nfct_perror("error");
- return -1;
- }
mnl_socket_close(nl);
return 0;