Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ |
| 2 | |
| 3 | #ifndef _UTILS_MCTP_CAPTURE_H |
| 4 | #define _UTILS_MCTP_CAPTURE_H |
| 5 | |
| 6 | #include "config.h" |
| 7 | |
Andrew Jeffery | 5ab7825 | 2022-02-17 21:04:59 +1030 | [diff] [blame] | 8 | #include "compiler.h" |
Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 9 | #include "libmctp.h" |
| 10 | |
| 11 | #include <sys/types.h> |
| 12 | |
| 13 | #if HAVE_PCAP |
| 14 | #include <pcap/pcap.h> |
Rashmica Gupta | f298897 | 2022-11-09 12:26:44 +1100 | [diff] [blame] | 15 | |
Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 16 | #else |
| 17 | typedef void pcap_t; |
| 18 | typedef void pcap_dumper_t; |
| 19 | #endif |
| 20 | |
Rashmica Gupta | f298897 | 2022-11-09 12:26:44 +1100 | [diff] [blame] | 21 | #define CAPTURE_LINKTYPE_LINUX_SLL2 276 |
Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 22 | |
Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 23 | struct capture { |
Andrew Jeffery | 9497718 | 2022-09-30 14:12:48 +0930 | [diff] [blame] | 24 | const char *path; |
Andrew Jeffery | 9497718 | 2022-09-30 14:12:48 +0930 | [diff] [blame] | 25 | pcap_t *pcap; |
| 26 | pcap_dumper_t *dumper; |
Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | #if HAVE_PCAP |
| 30 | int capture_init(void); |
| 31 | int capture_prepare(struct capture *cap); |
| 32 | void capture_close(struct capture *cap); |
Rashmica Gupta | f298897 | 2022-11-09 12:26:44 +1100 | [diff] [blame] | 33 | void capture_binding(struct mctp_pktbuf *pkt, bool outgoing, void *user); |
| 34 | void capture_socket(pcap_dumper_t *dumper, const void *buf, size_t len, |
| 35 | bool outgoing, int eid); |
Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 36 | #else |
| 37 | #include <stdio.h> |
Andrew Jeffery | 9497718 | 2022-09-30 14:12:48 +0930 | [diff] [blame] | 38 | static inline int capture_init(void) |
Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 39 | { |
Andrew Jeffery | 9497718 | 2022-09-30 14:12:48 +0930 | [diff] [blame] | 40 | fprintf(stderr, |
| 41 | "libpcap support is disabled, cannot initialise libpcap\n"); |
Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 42 | return 0; |
| 43 | } |
| 44 | |
Andrew Jeffery | 9497718 | 2022-09-30 14:12:48 +0930 | [diff] [blame] | 45 | static inline int capture_prepare(struct capture *cap) |
Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 46 | { |
| 47 | fprintf(stderr, "libpcap support is disabled, cannot capture to %s\n", |
| 48 | cap->path); |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | static inline void capture_close(struct capture *cap __unused) |
| 53 | { |
| 54 | } |
| 55 | |
Andrew Jeffery | 9497718 | 2022-09-30 14:12:48 +0930 | [diff] [blame] | 56 | static inline void capture_binding(struct mctp_pktbuf *pkt __unused, |
Rashmica Gupta | f298897 | 2022-11-09 12:26:44 +1100 | [diff] [blame] | 57 | bool outgoing __unused, void *user __unused) |
Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 58 | { |
| 59 | } |
| 60 | |
| 61 | static inline void capture_socket(pcap_dumper_t *dumper __unused, |
Rashmica Gupta | f298897 | 2022-11-09 12:26:44 +1100 | [diff] [blame] | 62 | const void *buf __unused, size_t len __unused, |
| 63 | bool outgoing __unused, int eid __unused) |
Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 64 | { |
| 65 | } |
| 66 | #endif |
| 67 | #endif |