2 * Copyright (c) 2011 Jakub Zawadzki
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote
15 * products derived from this software without specific prior written
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #ifdef NEED_STRERROR_H
45 #include <sys/socket.h>
46 #include <arpa/inet.h>
50 #include <netinet/in.h>
51 #include <linux/types.h>
53 #include <linux/netlink.h>
54 #include <linux/netfilter.h>
55 #include <linux/netfilter/nfnetlink.h>
56 #include <linux/netfilter/nfnetlink_log.h>
57 #include <linux/netfilter/nfnetlink_queue.h>
59 /* NOTE: if your program drops privilages after pcap_activate() it WON'T work with nfqueue.
60 * It took me quite some time to debug ;/
62 * Sending any data to nfnetlink socket requires CAP_NET_ADMIN privilages,
63 * and in nfqueue we need to send verdict reply after recving packet.
65 * In tcpdump you can disable dropping privilages with -Z root
68 #include "pcap-netfilter-linux.h"
70 #define HDR_LENGTH (NLMSG_LENGTH(NLMSG_ALIGN(sizeof(struct nfgenmsg))))
72 #define NFLOG_IFACE "nflog"
73 #define NFQUEUE_IFACE "nfqueue"
75 typedef enum { OTHER
= -1, NFLOG
, NFQUEUE
} nftype_t
;
78 * Private data for capturing on Linux netfilter sockets.
80 struct pcap_netfilter
{
81 u_int packets_read
; /* count of packets read with recvfrom() */
82 u_int packets_nobufs
; /* ENOBUFS counter */
85 static int nfqueue_send_verdict(const pcap_t
*handle
, uint16_t group_id
, u_int32_t id
, u_int32_t verdict
);
89 netfilter_read_linux(pcap_t
*handle
, int max_packets
, pcap_handler callback
, u_char
*user
)
91 struct pcap_netfilter
*handlep
= handle
->priv
;
92 register u_char
*bp
, *ep
;
97 * Has "pcap_breakloop()" been called?
99 if (handle
->break_loop
) {
101 * Yes - clear the flag that indicates that it
102 * has, and return PCAP_ERROR_BREAK to indicate
103 * that we were told to break out of the loop.
105 handle
->break_loop
= 0;
106 return PCAP_ERROR_BREAK
;
111 * The buffer is empty; refill it.
113 * We ignore EINTR, as that might just be due to a signal
114 * being delivered - if the signal should interrupt the
115 * loop, the signal handler should call pcap_breakloop()
116 * to set handle->break_loop (we ignore it on other
117 * platforms as well).
120 len
= recv(handle
->fd
, handle
->buffer
, handle
->bufsize
, 0);
121 if (handle
->break_loop
) {
122 handle
->break_loop
= 0;
123 return PCAP_ERROR_BREAK
;
125 if (errno
== ENOBUFS
)
126 handlep
->packets_nobufs
++;
127 } while ((len
== -1) && (errno
== EINTR
|| errno
== ENOBUFS
));
130 pcap_fmt_errmsg_for_errno(handle
->errbuf
,
131 PCAP_ERRBUF_SIZE
, errno
, "Can't receive packet");
135 bp
= (unsigned char *)handle
->buffer
;
140 const struct nlmsghdr
*nlh
= (const struct nlmsghdr
*) bp
;
142 nftype_t type
= OTHER
;
144 * Has "pcap_breakloop()" been called?
145 * If so, return immediately - if we haven't read any
146 * packets, clear the flag and return PCAP_ERROR_BREAK
147 * to indicate that we were told to break out of the loop,
148 * otherwise leave the flag set, so that the *next* call
149 * will break out of the loop without having read any
150 * packets, and return the number of packets we've
153 if (handle
->break_loop
) {
155 handle
->cc
= (int)(ep
- bp
);
157 handle
->break_loop
= 0;
158 return PCAP_ERROR_BREAK
;
162 if (ep
- bp
< NLMSG_SPACE(0)) {
164 * There's less than one netlink message left
165 * in the buffer. Give up.
170 if (nlh
->nlmsg_len
< sizeof(struct nlmsghdr
) || (u_int
)len
< nlh
->nlmsg_len
) {
171 pcap_snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
, "Message truncated: (got: %zd) (nlmsg_len: %u)", len
, nlh
->nlmsg_len
);
175 if (NFNL_SUBSYS_ID(nlh
->nlmsg_type
) == NFNL_SUBSYS_ULOG
&&
176 NFNL_MSG_TYPE(nlh
->nlmsg_type
) == NFULNL_MSG_PACKET
)
178 else if (NFNL_SUBSYS_ID(nlh
->nlmsg_type
) == NFNL_SUBSYS_QUEUE
&&
179 NFNL_MSG_TYPE(nlh
->nlmsg_type
) == NFQNL_MSG_PACKET
)
183 const unsigned char *payload
= NULL
;
184 struct pcap_pkthdr pkth
;
186 const struct nfgenmsg
*nfg
= NULL
;
189 if (handle
->linktype
!= DLT_NFLOG
) {
190 const struct nfattr
*payload_attr
= NULL
;
192 if (nlh
->nlmsg_len
< HDR_LENGTH
) {
193 pcap_snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
, "Malformed message: (nlmsg_len: %u)", nlh
->nlmsg_len
);
197 nfg
= NLMSG_DATA(nlh
);
198 if (nlh
->nlmsg_len
> HDR_LENGTH
) {
199 struct nfattr
*attr
= NFM_NFA(nfg
);
200 int attr_len
= nlh
->nlmsg_len
- NLMSG_ALIGN(HDR_LENGTH
);
202 while (NFA_OK(attr
, attr_len
)) {
203 if (type
== NFQUEUE
) {
204 switch (NFA_TYPE(attr
)) {
205 case NFQA_PACKET_HDR
:
207 const struct nfqnl_msg_packet_hdr
*pkt_hdr
= (const struct nfqnl_msg_packet_hdr
*) NFA_DATA(attr
);
209 id
= ntohl(pkt_hdr
->packet_id
);
217 } else if (type
== NFLOG
) {
218 switch (NFA_TYPE(attr
)) {
224 attr
= NFA_NEXT(attr
, attr_len
);
229 payload
= NFA_DATA(payload_attr
);
230 pkth
.len
= pkth
.caplen
= NFA_PAYLOAD(payload_attr
);
234 payload
= NLMSG_DATA(nlh
);
235 pkth
.caplen
= pkth
.len
= nlh
->nlmsg_len
-NLMSG_ALIGN(sizeof(struct nlmsghdr
));
239 /* pkth.caplen = min (payload_len, handle->snapshot); */
241 gettimeofday(&pkth
.ts
, NULL
);
242 if (handle
->fcode
.bf_insns
== NULL
||
243 pcap_filter(handle
->fcode
.bf_insns
, payload
, pkth
.len
, pkth
.caplen
))
245 handlep
->packets_read
++;
246 callback(user
, &pkth
, payload
);
251 if (type
== NFQUEUE
) {
252 /* XXX, possible responses: NF_DROP, NF_ACCEPT, NF_STOLEN, NF_QUEUE, NF_REPEAT, NF_STOP */
253 /* if type == NFQUEUE, handle->linktype is always != DLT_NFLOG,
254 so nfg is always initialized to NLMSG_DATA(nlh). */
256 nfqueue_send_verdict(handle
, ntohs(nfg
->res_id
), id
, NF_ACCEPT
);
260 msg_len
= NLMSG_ALIGN(nlh
->nlmsg_len
);
262 * If the message length would run past the end of the
263 * buffer, truncate it to the remaining space in the
266 if (msg_len
> ep
- bp
)
267 msg_len
= (uint32_t)(ep
- bp
);
270 if (count
>= max_packets
&& !PACKET_COUNT_IS_UNLIMITED(max_packets
)) {
272 handle
->cc
= (int)(ep
- bp
);
284 netfilter_set_datalink(pcap_t
*handle
, int dlt
)
286 handle
->linktype
= dlt
;
291 netfilter_stats_linux(pcap_t
*handle
, struct pcap_stat
*stats
)
293 struct pcap_netfilter
*handlep
= handle
->priv
;
295 stats
->ps_recv
= handlep
->packets_read
;
296 stats
->ps_drop
= handlep
->packets_nobufs
;
297 stats
->ps_ifdrop
= 0;
302 netfilter_inject_linux(pcap_t
*handle
, const void *buf _U_
, int size _U_
)
304 pcap_snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
305 "Packet injection is not supported on netfilter devices");
316 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
)
318 char buf
[1024] __attribute__ ((aligned
));
320 struct nlmsghdr
*nlh
= (struct nlmsghdr
*) buf
;
321 struct nfgenmsg
*nfg
= (struct nfgenmsg
*) (buf
+ sizeof(struct nlmsghdr
));
323 struct sockaddr_nl snl
;
324 static unsigned int seq_id
;
330 nlh
->nlmsg_len
= NLMSG_LENGTH(sizeof(struct nfgenmsg
));
331 nlh
->nlmsg_type
= msg_type
;
332 nlh
->nlmsg_flags
= NLM_F_REQUEST
| (ack
? NLM_F_ACK
: 0);
333 nlh
->nlmsg_pid
= 0; /* to kernel */
334 nlh
->nlmsg_seq
= seq_id
;
336 nfg
->nfgen_family
= family
;
337 nfg
->version
= NFNETLINK_V0
;
338 nfg
->res_id
= htons(res_id
);
341 struct nfattr
*nfa
= (struct nfattr
*) (buf
+ NLMSG_ALIGN(nlh
->nlmsg_len
));
343 nfa
->nfa_type
= mynfa
->nfa_type
;
344 nfa
->nfa_len
= NFA_LENGTH(mynfa
->nfa_len
);
345 memcpy(NFA_DATA(nfa
), mynfa
->data
, mynfa
->nfa_len
);
346 nlh
->nlmsg_len
= NLMSG_ALIGN(nlh
->nlmsg_len
) + NFA_ALIGN(nfa
->nfa_len
);
349 memset(&snl
, 0, sizeof(snl
));
350 snl
.nl_family
= AF_NETLINK
;
352 if (sendto(handle
->fd
, nlh
, nlh
->nlmsg_len
, 0, (struct sockaddr
*) &snl
, sizeof(snl
)) == -1)
358 /* waiting for reply loop */
360 socklen_t addrlen
= sizeof(snl
);
363 /* ignore interrupt system call error */
366 * The buffer is not so big that its size won't
369 len
= (int)recvfrom(handle
->fd
, buf
, sizeof(buf
), 0, (struct sockaddr
*) &snl
, &addrlen
);
370 } while ((len
== -1) && (errno
== EINTR
));
375 if (addrlen
!= sizeof(snl
) || snl
.nl_family
!= AF_NETLINK
) {
380 nlh
= (struct nlmsghdr
*) buf
;
381 if (snl
.nl_pid
!= 0 || seq_id
!= nlh
->nlmsg_seq
) /* if not from kernel or wrong sequence skip */
384 while ((u_int
)len
>= NLMSG_SPACE(0) && NLMSG_OK(nlh
, (u_int
)len
)) {
385 if (nlh
->nlmsg_type
== NLMSG_ERROR
|| (nlh
->nlmsg_type
== NLMSG_DONE
&& nlh
->nlmsg_flags
& NLM_F_MULTI
)) {
386 if (nlh
->nlmsg_len
< NLMSG_ALIGN(sizeof(struct nlmsgerr
))) {
390 errno
= -(*((int *)NLMSG_DATA(nlh
)));
391 return (errno
== 0) ? 0 : -1;
393 nlh
= NLMSG_NEXT(nlh
, len
);
397 return -1; /* never here */
401 nflog_send_config_msg(const pcap_t
*handle
, uint8_t family
, u_int16_t group_id
, const struct my_nfattr
*mynfa
)
403 return netfilter_send_config_msg(handle
, (NFNL_SUBSYS_ULOG
<< 8) | NFULNL_MSG_CONFIG
, 1, family
, group_id
, mynfa
);
407 nflog_send_config_cmd(const pcap_t
*handle
, uint16_t group_id
, u_int8_t cmd
, u_int8_t family
)
409 struct nfulnl_msg_config_cmd msg
;
410 struct my_nfattr nfa
;
415 nfa
.nfa_type
= NFULA_CFG_CMD
;
416 nfa
.nfa_len
= sizeof(msg
);
418 return nflog_send_config_msg(handle
, family
, group_id
, &nfa
);
422 nflog_send_config_mode(const pcap_t
*handle
, uint16_t group_id
, u_int8_t copy_mode
, u_int32_t copy_range
)
424 struct nfulnl_msg_config_mode msg
;
425 struct my_nfattr nfa
;
427 msg
.copy_range
= htonl(copy_range
);
428 msg
.copy_mode
= copy_mode
;
431 nfa
.nfa_type
= NFULA_CFG_MODE
;
432 nfa
.nfa_len
= sizeof(msg
);
434 return nflog_send_config_msg(handle
, AF_UNSPEC
, group_id
, &nfa
);
438 nfqueue_send_verdict(const pcap_t
*handle
, uint16_t group_id
, u_int32_t id
, u_int32_t verdict
)
440 struct nfqnl_msg_verdict_hdr msg
;
441 struct my_nfattr nfa
;
444 msg
.verdict
= htonl(verdict
);
447 nfa
.nfa_type
= NFQA_VERDICT_HDR
;
448 nfa
.nfa_len
= sizeof(msg
);
450 return netfilter_send_config_msg(handle
, (NFNL_SUBSYS_QUEUE
<< 8) | NFQNL_MSG_VERDICT
, 0, AF_UNSPEC
, group_id
, &nfa
);
454 nfqueue_send_config_msg(const pcap_t
*handle
, uint8_t family
, u_int16_t group_id
, const struct my_nfattr
*mynfa
)
456 return netfilter_send_config_msg(handle
, (NFNL_SUBSYS_QUEUE
<< 8) | NFQNL_MSG_CONFIG
, 1, family
, group_id
, mynfa
);
460 nfqueue_send_config_cmd(const pcap_t
*handle
, uint16_t group_id
, u_int8_t cmd
, u_int16_t pf
)
462 struct nfqnl_msg_config_cmd msg
;
463 struct my_nfattr nfa
;
469 nfa
.nfa_type
= NFQA_CFG_CMD
;
470 nfa
.nfa_len
= sizeof(msg
);
472 return nfqueue_send_config_msg(handle
, AF_UNSPEC
, group_id
, &nfa
);
476 nfqueue_send_config_mode(const pcap_t
*handle
, uint16_t group_id
, u_int8_t copy_mode
, u_int32_t copy_range
)
478 struct nfqnl_msg_config_params msg
;
479 struct my_nfattr nfa
;
481 msg
.copy_range
= htonl(copy_range
);
482 msg
.copy_mode
= copy_mode
;
485 nfa
.nfa_type
= NFQA_CFG_PARAMS
;
486 nfa
.nfa_len
= sizeof(msg
);
488 return nfqueue_send_config_msg(handle
, AF_UNSPEC
, group_id
, &nfa
);
492 netfilter_activate(pcap_t
* handle
)
494 const char *dev
= handle
->opt
.device
;
495 unsigned short groups
[32];
497 nftype_t type
= OTHER
;
500 if (strncmp(dev
, NFLOG_IFACE
, strlen(NFLOG_IFACE
)) == 0) {
501 dev
+= strlen(NFLOG_IFACE
);
504 } else if (strncmp(dev
, NFQUEUE_IFACE
, strlen(NFQUEUE_IFACE
)) == 0) {
505 dev
+= strlen(NFQUEUE_IFACE
);
509 if (type
!= OTHER
&& *dev
== ':') {
515 if (group_count
== 32) {
516 pcap_snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
517 "Maximum 32 netfilter groups! dev: %s",
522 group_id
= strtol(dev
, &end_dev
, 0);
523 if (end_dev
!= dev
) {
524 if (group_id
< 0 || group_id
> 65535) {
525 pcap_snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
526 "Netfilter group range from 0 to 65535 (got %ld)",
531 groups
[group_count
++] = (unsigned short) group_id
;
540 if (type
== OTHER
|| *dev
) {
541 pcap_snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
542 "Can't get netfilter group(s) index from %s",
547 /* if no groups, add default: 0 */
554 * Turn a negative snapshot value (invalid), a snapshot value of
555 * 0 (unspecified), or a value bigger than the normal maximum
556 * value, into the maximum allowed value.
558 * If some application really *needs* a bigger snapshot
559 * length, we should just increase MAXIMUM_SNAPLEN.
561 if (handle
->snapshot
<= 0 || handle
->snapshot
> MAXIMUM_SNAPLEN
)
562 handle
->snapshot
= MAXIMUM_SNAPLEN
;
564 /* Initialize some components of the pcap structure. */
565 handle
->bufsize
= 128 + handle
->snapshot
;
567 handle
->read_op
= netfilter_read_linux
;
568 handle
->inject_op
= netfilter_inject_linux
;
569 handle
->setfilter_op
= install_bpf_program
; /* no kernel filtering */
570 handle
->setdirection_op
= NULL
;
571 handle
->set_datalink_op
= netfilter_set_datalink
;
572 handle
->getnonblock_op
= pcap_getnonblock_fd
;
573 handle
->setnonblock_op
= pcap_setnonblock_fd
;
574 handle
->stats_op
= netfilter_stats_linux
;
576 /* Create netlink socket */
577 handle
->fd
= socket(AF_NETLINK
, SOCK_RAW
, NETLINK_NETFILTER
);
578 if (handle
->fd
< 0) {
579 pcap_fmt_errmsg_for_errno(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
580 errno
, "Can't create raw socket");
585 handle
->linktype
= DLT_NFLOG
;
586 handle
->dlt_list
= (u_int
*) malloc(sizeof(u_int
) * 2);
587 if (handle
->dlt_list
!= NULL
) {
588 handle
->dlt_list
[0] = DLT_NFLOG
;
589 handle
->dlt_list
[1] = DLT_IPV4
;
590 handle
->dlt_count
= 2;
594 handle
->linktype
= DLT_IPV4
;
596 handle
->buffer
= malloc(handle
->bufsize
);
597 if (!handle
->buffer
) {
598 pcap_fmt_errmsg_for_errno(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
599 errno
, "Can't allocate dump buffer");
604 if (nflog_send_config_cmd(handle
, 0, NFULNL_CFG_CMD_PF_UNBIND
, AF_INET
) < 0) {
605 pcap_fmt_errmsg_for_errno(handle
->errbuf
,
606 PCAP_ERRBUF_SIZE
, errno
,
607 "NFULNL_CFG_CMD_PF_UNBIND");
611 if (nflog_send_config_cmd(handle
, 0, NFULNL_CFG_CMD_PF_BIND
, AF_INET
) < 0) {
612 pcap_fmt_errmsg_for_errno(handle
->errbuf
,
613 PCAP_ERRBUF_SIZE
, errno
, "NFULNL_CFG_CMD_PF_BIND");
617 /* Bind socket to the nflog groups */
618 for (i
= 0; i
< group_count
; i
++) {
619 if (nflog_send_config_cmd(handle
, groups
[i
], NFULNL_CFG_CMD_BIND
, AF_UNSPEC
) < 0) {
620 pcap_fmt_errmsg_for_errno(handle
->errbuf
,
621 PCAP_ERRBUF_SIZE
, errno
,
622 "Can't listen on group group index");
626 if (nflog_send_config_mode(handle
, groups
[i
], NFULNL_COPY_PACKET
, handle
->snapshot
) < 0) {
627 pcap_fmt_errmsg_for_errno(handle
->errbuf
,
628 PCAP_ERRBUF_SIZE
, errno
,
629 "NFULNL_COPY_PACKET");
635 if (nfqueue_send_config_cmd(handle
, 0, NFQNL_CFG_CMD_PF_UNBIND
, AF_INET
) < 0) {
636 pcap_fmt_errmsg_for_errno(handle
->errbuf
,
637 PCAP_ERRBUF_SIZE
, errno
, "NFQNL_CFG_CMD_PF_UNBIND");
641 if (nfqueue_send_config_cmd(handle
, 0, NFQNL_CFG_CMD_PF_BIND
, AF_INET
) < 0) {
642 pcap_fmt_errmsg_for_errno(handle
->errbuf
,
643 PCAP_ERRBUF_SIZE
, errno
, "NFQNL_CFG_CMD_PF_BIND");
647 /* Bind socket to the nfqueue groups */
648 for (i
= 0; i
< group_count
; i
++) {
649 if (nfqueue_send_config_cmd(handle
, groups
[i
], NFQNL_CFG_CMD_BIND
, AF_UNSPEC
) < 0) {
650 pcap_fmt_errmsg_for_errno(handle
->errbuf
,
651 PCAP_ERRBUF_SIZE
, errno
,
652 "Can't listen on group group index");
656 if (nfqueue_send_config_mode(handle
, groups
[i
], NFQNL_COPY_PACKET
, handle
->snapshot
) < 0) {
657 pcap_fmt_errmsg_for_errno(handle
->errbuf
,
658 PCAP_ERRBUF_SIZE
, errno
,
659 "NFQNL_COPY_PACKET");
665 if (handle
->opt
.rfmon
) {
667 * Monitor mode doesn't apply to netfilter devices.
669 pcap_cleanup_live_common(handle
);
670 return PCAP_ERROR_RFMON_NOTSUP
;
673 if (handle
->opt
.buffer_size
!= 0) {
675 * Set the socket buffer size to the specified value.
677 if (setsockopt(handle
->fd
, SOL_SOCKET
, SO_RCVBUF
, &handle
->opt
.buffer_size
, sizeof(handle
->opt
.buffer_size
)) == -1) {
678 pcap_fmt_errmsg_for_errno(handle
->errbuf
,
679 PCAP_ERRBUF_SIZE
, errno
, "SO_RCVBUF");
684 handle
->selectable_fd
= handle
->fd
;
688 pcap_cleanup_live_common(handle
);
693 netfilter_create(const char *device
, char *ebuf
, int *is_ours
)
698 /* Does this look like an netfilter device? */
699 cp
= strrchr(device
, '/');
703 /* Does it begin with NFLOG_IFACE or NFQUEUE_IFACE? */
704 if (strncmp(cp
, NFLOG_IFACE
, sizeof NFLOG_IFACE
- 1) == 0)
705 cp
+= sizeof NFLOG_IFACE
- 1;
706 else if (strncmp(cp
, NFQUEUE_IFACE
, sizeof NFQUEUE_IFACE
- 1) == 0)
707 cp
+= sizeof NFQUEUE_IFACE
- 1;
709 /* Nope, doesn't begin with NFLOG_IFACE nor NFQUEUE_IFACE */
715 * Yes - is that either the end of the name, or is it followed
718 if (*cp
!= ':' && *cp
!= '\0') {
724 /* OK, it's probably ours. */
727 p
= pcap_create_common(ebuf
, sizeof (struct pcap_netfilter
));
731 p
->activate_op
= netfilter_activate
;
736 netfilter_findalldevs(pcap_if_list_t
*devlistp
, char *err_str
)
740 sock
= socket(AF_NETLINK
, SOCK_RAW
, NETLINK_NETFILTER
);
742 /* if netlink is not supported this is not fatal */
743 if (errno
== EAFNOSUPPORT
|| errno
== EPROTONOSUPPORT
)
745 pcap_fmt_errmsg_for_errno(err_str
, PCAP_ERRBUF_SIZE
,
746 errno
, "Can't open netlink socket");
752 * The notion of "connected" vs. "disconnected" doesn't apply.
753 * XXX - what about "up" and "running"?
755 if (add_dev(devlistp
, NFLOG_IFACE
,
756 PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE
,
757 "Linux netfilter log (NFLOG) interface", err_str
) == NULL
)
759 if (add_dev(devlistp
, NFQUEUE_IFACE
,
760 PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE
,
761 "Linux netfilter queue (NFQUEUE) interface", err_str
) == NULL
)