Need check if nfqueue was really binded

This commit is contained in:
DomySh
2022-07-16 10:15:29 +02:00
parent 5917554af8
commit 76cd4f7407
2 changed files with 5 additions and 17 deletions

Binary file not shown.

View File

@@ -120,19 +120,13 @@ class NetfilterQueue {
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
nl = mnl_socket_open(NETLINK_NETFILTER); nl = mnl_socket_open(NETLINK_NETFILTER);
if (nl == NULL) { if (nl == NULL) { throw runtime_error( "mnl_socket_open" );}
throw runtime_error( "mnl_socket_open" );
}
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { throw std::runtime_error( "mnl_socket_bind" );}
throw std::invalid_argument( "mnl_socket_bind" );
}
portid = mnl_socket_get_portid(nl); portid = mnl_socket_get_portid(nl);
buf = (char*) malloc(BUF_SIZE); buf = (char*) malloc(BUF_SIZE);
if (!buf) { if (!buf) { throw runtime_error( "allocate receive buffer" ); }
throw runtime_error( "allocate receive buffer" );
}
nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_num); nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_num);
nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_BIND); nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_BIND);
@@ -153,6 +147,8 @@ class NetfilterQueue {
throw runtime_error( "mnl_socket_send" ); throw runtime_error( "mnl_socket_send" );
} }
} }
void run(){ void run(){
@@ -373,13 +369,6 @@ int main(int argc, char *argv[])
cerr << "[fatal] [main] You must be root to run this program" << endl; cerr << "[fatal] [main] You must be root to run this program" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
NFQueueSequence<input_callb> nfq_input(1);
NetfilterQueue<output_callb> nfq_output(1000);
cout << "RUN INPUT" << endl;
nfq_input.start();
cout << "RUN OUTPUT" << endl;
nfq_output.run(); //Only in mnl_cb_run is checked is a nfqueue can be binded
/*
int n_of_queue = 1; int n_of_queue = 1;
if (argc >= 2) n_of_queue = atoi(argv[1]); if (argc >= 2) n_of_queue = atoi(argv[1]);
NFQueueSequence<input_callb> input_queues(n_of_queue); NFQueueSequence<input_callb> input_queues(n_of_queue);
@@ -390,7 +379,6 @@ int main(int argc, char *argv[])
cout << "QUEUE INPUT " << input_queues.init() << " " << input_queues.end() << " OUTPUT " << output_queues.init() << " " << output_queues.end() << endl; cout << "QUEUE INPUT " << input_queues.init() << " " << input_queues.end() << " OUTPUT " << output_queues.init() << " " << output_queues.end() << endl;
config_updater(); config_updater();
*/
} }