Lines Matching full:handle

84 static int nfqueue_send_verdict(const pcap_t *handle, uint16_t group_id, u_int32_t id, u_int32_t verdict);
88 netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
90 struct pcap_netfilter *handlep = handle->priv;
98 if (handle->break_loop) {
104 handle->break_loop = 0;
107 len = handle->cc;
115 * to set handle->break_loop (we ignore it on other
119 len = recv(handle->fd, handle->buffer, handle->bufsize, 0);
120 if (handle->break_loop) {
121 handle->break_loop = 0;
129 pcapint_fmt_errmsg_for_errno(handle->errbuf,
134 bp = (unsigned char *)handle->buffer;
136 bp = handle->bp;
159 if (handle->break_loop) {
160 handle->bp = bp;
161 handle->cc = (int)(ep - bp);
163 handle->break_loop = 0;
188 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Message truncated: (got: %zd) (nlmsg_len: %u)", len, nlh->nlmsg_len);
206 if (handle->linktype != DLT_NFLOG) {
210 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Malformed message: (nlmsg_len: %u)", nlh->nlmsg_len);
256 /* pkth.caplen = min (payload_len, handle->snapshot); */
259 if (handle->fcode.bf_insns == NULL ||
260 pcapint_filter(handle->fcode.bf_insns, payload, pkth.len, pkth.caplen))
270 /* if type == NFQUEUE, handle->linktype is always != DLT_NFLOG,
273 nfqueue_send_verdict(handle, ntohs(nfg->res_id), id, NF_ACCEPT);
295 handle->bp = bp;
296 handle->cc = (int)(ep - bp);
297 if (handle->cc < 0)
298 handle->cc = 0;
303 handle->cc = 0;
308 netfilter_set_datalink(pcap_t *handle, int dlt)
310 handle->linktype = dlt;
315 netfilter_stats_linux(pcap_t *handle, struct pcap_stat *stats)
317 struct pcap_netfilter *handlep = handle->priv;
326 netfilter_inject_linux(pcap_t *handle, const void *buf _U_, int size _U_)
328 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
340 netfilter_send_config_msg(const pcap_t *handle, uint16_t msg_type, int ack, u_int8_t family, u_int16_t res_id, const struct my_nfattr *mynfa)
379 if (sendto(handle->fd, nlh, nlh->nlmsg_len, 0, (struct sockaddr *) &snl, sizeof(snl)) == -1)
396 len = (int)recvfrom(handle->fd, buf, sizeof(buf), 0, (struct sockaddr *) &snl, &addrlen);
428 nflog_send_config_msg(const pcap_t *handle, uint8_t family, u_int16_t group_id, const struct my_nfattr *mynfa)
430 return netfilter_send_config_msg(handle, (NFNL_SUBSYS_ULOG << 8) | NFULNL_MSG_CONFIG, 1, family, group_id, mynfa);
434 nflog_send_config_cmd(const pcap_t *handle, uint16_t group_id, u_int8_t cmd, u_int8_t family)
445 return nflog_send_config_msg(handle, family, group_id, &nfa);
449 nflog_send_config_mode(const pcap_t *handle, uint16_t group_id, u_int8_t copy_mode, u_int32_t copy_range)
461 return nflog_send_config_msg(handle, AF_UNSPEC, group_id, &nfa);
465 nfqueue_send_verdict(const pcap_t *handle, uint16_t group_id, u_int32_t id, u_int32_t verdict)
477 return netfilter_send_config_msg(handle, (NFNL_SUBSYS_QUEUE << 8) | NFQNL_MSG_VERDICT, 0, AF_UNSPEC, group_id, &nfa);
481 nfqueue_send_config_msg(const pcap_t *handle, uint8_t family, u_int16_t group_id, const struct my_nfattr *mynfa)
483 return netfilter_send_config_msg(handle, (NFNL_SUBSYS_QUEUE << 8) | NFQNL_MSG_CONFIG, 1, family, group_id, mynfa);
487 nfqueue_send_config_cmd(const pcap_t *handle, uint16_t group_id, u_int8_t cmd, u_int16_t pf)
499 return nfqueue_send_config_msg(handle, AF_UNSPEC, group_id, &nfa);
503 nfqueue_send_config_mode(const pcap_t *handle, uint16_t group_id, u_int8_t copy_mode, u_int32_t copy_range)
515 return nfqueue_send_config_msg(handle, AF_UNSPEC, group_id, &nfa);
519 netfilter_activate(pcap_t* handle)
521 const char *dev = handle->opt.device;
543 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
545 handle->opt.device);
552 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
568 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
570 handle->opt.device);
588 if (handle->snapshot <= 0 || handle->snapshot > MAXIMUM_SNAPLEN)
589 handle->snapshot = MAXIMUM_SNAPLEN;
592 handle->bufsize = 128 + handle->snapshot;
593 handle->offset = 0;
594 handle->read_op = netfilter_read_linux;
595 handle->inject_op = netfilter_inject_linux;
596 handle->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */
597 handle->setdirection_op = NULL;
598 handle->set_datalink_op = netfilter_set_datalink;
599 handle->getnonblock_op = pcapint_getnonblock_fd;
600 handle->setnonblock_op = pcapint_setnonblock_fd;
601 handle->stats_op = netfilter_stats_linux;
604 handle->fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_NETFILTER);
605 if (handle->fd < 0) {
606 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
612 handle->linktype = DLT_NFLOG;
613 handle->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
614 if (handle->dlt_list == NULL) {
615 pcapint_fmt_errmsg_for_errno(handle->errbuf,
620 handle->dlt_list[0] = DLT_NFLOG;
621 handle->dlt_list[1] = DLT_IPV4;
622 handle->dlt_count = 2;
624 handle->linktype = DLT_IPV4;
626 handle->buffer = malloc(handle->bufsize);
627 if (!handle->buffer) {
628 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
634 if (nflog_send_config_cmd(handle, 0, NFULNL_CFG_CMD_PF_UNBIND, AF_INET) < 0) {
635 pcapint_fmt_errmsg_for_errno(handle->errbuf,
641 if (nflog_send_config_cmd(handle, 0, NFULNL_CFG_CMD_PF_BIND, AF_INET) < 0) {
642 pcapint_fmt_errmsg_for_errno(handle->errbuf,
649 if (nflog_send_config_cmd(handle, groups[i], NFULNL_CFG_CMD_BIND, AF_UNSPEC) < 0) {
650 pcapint_fmt_errmsg_for_errno(handle->errbuf,
656 if (nflog_send_config_mode(handle, groups[i], NFULNL_COPY_PACKET, handle->snapshot) < 0) {
657 pcapint_fmt_errmsg_for_errno(handle->errbuf,
665 if (nfqueue_send_config_cmd(handle, 0, NFQNL_CFG_CMD_PF_UNBIND, AF_INET) < 0) {
666 pcapint_fmt_errmsg_for_errno(handle->errbuf,
671 if (nfqueue_send_config_cmd(handle, 0, NFQNL_CFG_CMD_PF_BIND, AF_INET) < 0) {
672 pcapint_fmt_errmsg_for_errno(handle->errbuf,
679 if (nfqueue_send_config_cmd(handle, groups[i], NFQNL_CFG_CMD_BIND, AF_UNSPEC) < 0) {
680 pcapint_fmt_errmsg_for_errno(handle->errbuf,
686 if (nfqueue_send_config_mode(handle, groups[i], NFQNL_COPY_PACKET, handle->snapshot) < 0) {
687 pcapint_fmt_errmsg_for_errno(handle->errbuf,
695 if (handle->opt.rfmon) {
699 pcapint_cleanup_live_common(handle);
703 if (handle->opt.buffer_size != 0) {
707 if (setsockopt(handle->fd, SOL_SOCKET, SO_RCVBUF, &handle->opt.buffer_size, sizeof(handle->opt.buffer_size)) == -1) {
708 pcapint_fmt_errmsg_for_errno(handle->errbuf,
714 handle->selectable_fd = handle->fd;
718 pcapint_cleanup_live_common(handle);