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