blob: 261cabaeeb03c31fef322aef5a8f2fdf4c453d31 [file] [log] [blame]
Andrew Jefferycad47302021-08-20 21:37:57 +09301/* 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 Johnston3ef47782024-12-11 15:19:06 +08006#ifdef HAVE_CONFIG_H
Andrew Jefferycad47302021-08-20 21:37:57 +09307#include "config.h"
Matt Johnston3ef47782024-12-11 15:19:06 +08008#endif
Andrew Jefferycad47302021-08-20 21:37:57 +09309
Andrew Jeffery5ab78252022-02-17 21:04:59 +103010#include "compiler.h"
Andrew Jefferycad47302021-08-20 21:37:57 +093011#include "libmctp.h"
12
13#include <sys/types.h>
14
15#if HAVE_PCAP
16#include <pcap/pcap.h>
Rashmica Guptaf2988972022-11-09 12:26:44 +110017
Andrew Jefferycad47302021-08-20 21:37:57 +093018#else
19typedef void pcap_t;
20typedef void pcap_dumper_t;
21#endif
22
Rashmica Guptaf2988972022-11-09 12:26:44 +110023#define CAPTURE_LINKTYPE_LINUX_SLL2 276
Andrew Jefferycad47302021-08-20 21:37:57 +093024
Andrew Jefferycad47302021-08-20 21:37:57 +093025struct capture {
Andrew Jeffery94977182022-09-30 14:12:48 +093026 const char *path;
Andrew Jeffery94977182022-09-30 14:12:48 +093027 pcap_t *pcap;
28 pcap_dumper_t *dumper;
Andrew Jefferycad47302021-08-20 21:37:57 +093029};
30
31#if HAVE_PCAP
32int capture_init(void);
33int capture_prepare(struct capture *cap);
34void capture_close(struct capture *cap);
Rashmica Guptaf2988972022-11-09 12:26:44 +110035void capture_binding(struct mctp_pktbuf *pkt, bool outgoing, void *user);
36void capture_socket(pcap_dumper_t *dumper, const void *buf, size_t len,
37 bool outgoing, int eid);
Andrew Jefferycad47302021-08-20 21:37:57 +093038#else
39#include <stdio.h>
Andrew Jeffery94977182022-09-30 14:12:48 +093040static inline int capture_init(void)
Andrew Jefferycad47302021-08-20 21:37:57 +093041{
Andrew Jeffery94977182022-09-30 14:12:48 +093042 fprintf(stderr,
43 "libpcap support is disabled, cannot initialise libpcap\n");
Andrew Jefferycad47302021-08-20 21:37:57 +093044 return 0;
45}
46
Andrew Jeffery94977182022-09-30 14:12:48 +093047static inline int capture_prepare(struct capture *cap)
Andrew Jefferycad47302021-08-20 21:37:57 +093048{
49 fprintf(stderr, "libpcap support is disabled, cannot capture to %s\n",
50 cap->path);
51 return 0;
52}
53
54static inline void capture_close(struct capture *cap __unused)
55{
56}
57
Andrew Jeffery94977182022-09-30 14:12:48 +093058static inline void capture_binding(struct mctp_pktbuf *pkt __unused,
Rashmica Guptaf2988972022-11-09 12:26:44 +110059 bool outgoing __unused, void *user __unused)
Andrew Jefferycad47302021-08-20 21:37:57 +093060{
61}
62
63static inline void capture_socket(pcap_dumper_t *dumper __unused,
Rashmica Guptaf2988972022-11-09 12:26:44 +110064 const void *buf __unused, size_t len __unused,
65 bool outgoing __unused, int eid __unused)
Andrew Jefferycad47302021-08-20 21:37:57 +093066{
67}
68#endif
69#endif