From cbe036db892c298c33e77dec2c5129dbb4dccc2c Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Tue, 30 Sep 2014 19:40:18 +0200 Subject: iptables-compat: get rid of error reporting via perror The compat layer should report problems in the iptables way instead. Signed-off-by: Pablo Neira Ayuso --- iptables/xtables-events.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'iptables/xtables-events.c') diff --git a/iptables/xtables-events.c b/iptables/xtables-events.c index 4746825e..1e0b1752 100644 --- a/iptables/xtables-events.c +++ b/iptables/xtables-events.c @@ -34,15 +34,11 @@ static int table_cb(const struct nlmsghdr *nlh, int type) char buf[4096]; t = nft_table_alloc(); - if (t == NULL) { - perror("OOM"); + if (t == NULL) goto err; - } - if (nft_table_nlmsg_parse(nlh, t) < 0) { - perror("nft_table_nlmsg_parse"); + if (nft_table_nlmsg_parse(nlh, t) < 0) goto err_free; - } nft_table_snprintf(buf, sizeof(buf), t, NFT_OUTPUT_DEFAULT, 0); /* FIXME: define syntax to represent table events */ @@ -65,15 +61,11 @@ static int rule_cb(const struct nlmsghdr *nlh, int type) uint8_t family; r = nft_rule_alloc(); - if (r == NULL) { - perror("OOM"); + if (r == NULL) goto err; - } - if (nft_rule_nlmsg_parse(nlh, r) < 0) { - perror("nft_rule_nlmsg_parse"); + if (nft_rule_nlmsg_parse(nlh, r) < 0) goto err_free; - } family = nft_rule_attr_get_u32(r, NFT_RULE_ATTR_FAMILY); switch (family) { @@ -109,15 +101,11 @@ static int chain_cb(const struct nlmsghdr *nlh, int type) char buf[4096]; t = nft_chain_alloc(); - if (t == NULL) { - perror("OOM"); + if (t == NULL) goto err; - } - if (nft_chain_nlmsg_parse(nlh, t) < 0) { - perror("nft_chain_nlmsg_parse"); + if (nft_chain_nlmsg_parse(nlh, t) < 0) goto err_free; - } nft_chain_snprintf(buf, sizeof(buf), t, NFT_OUTPUT_DEFAULT, 0); /* FIXME: define syntax to represent chain events */ @@ -198,12 +186,12 @@ int xtables_events_main(int argc, char *argv[]) nl = mnl_socket_open(NETLINK_NETFILTER); if (nl == NULL) { - perror("mnl_socket_open"); + perror("cannot open nfnetlink socket"); exit(EXIT_FAILURE); } if (mnl_socket_bind(nl, (1 << (NFNLGRP_NFTABLES-1)), MNL_SOCKET_AUTOPID) < 0) { - perror("mnl_socket_bind"); + perror("cannot bind to nfnetlink socket"); exit(EXIT_FAILURE); } @@ -215,7 +203,7 @@ int xtables_events_main(int argc, char *argv[]) ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); } if (ret == -1) { - perror("error"); + perror("cannot receive from nfnetlink socket"); exit(EXIT_FAILURE); } mnl_socket_close(nl); -- cgit v1.2.3