blob: e432df9fd695c10af9ab8da14e4235eabe0b3cee [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
6#include "config.h"
7
Andrew Jeffery5ab78252022-02-17 21:04:59 +10308#include "compiler.h"
Andrew Jefferycad47302021-08-20 21:37:57 +09309#include "libmctp.h"
10
11#include <sys/types.h>
12
13#if HAVE_PCAP
14#include <pcap/pcap.h>
Rashmica Guptaf2988972022-11-09 12:26:44 +110015
Andrew Jefferycad47302021-08-20 21:37:57 +093016#else
17typedef void pcap_t;
18typedef void pcap_dumper_t;
19#endif
20
Rashmica Guptaf2988972022-11-09 12:26:44 +110021#define CAPTURE_LINKTYPE_LINUX_SLL2 276
Andrew Jefferycad47302021-08-20 21:37:57 +093022
Andrew Jefferycad47302021-08-20 21:37:57 +093023struct capture {
Andrew Jeffery94977182022-09-30 14:12:48 +093024 const char *path;
Andrew Jeffery94977182022-09-30 14:12:48 +093025 pcap_t *pcap;
26 pcap_dumper_t *dumper;
Andrew Jefferycad47302021-08-20 21:37:57 +093027};
28
29#if HAVE_PCAP
30int capture_init(void);
31int capture_prepare(struct capture *cap);
32void capture_close(struct capture *cap);
Rashmica Guptaf2988972022-11-09 12:26:44 +110033void capture_binding(struct mctp_pktbuf *pkt, bool outgoing, void *user);
34void capture_socket(pcap_dumper_t *dumper, const void *buf, size_t len,
35 bool outgoing, int eid);
Andrew Jefferycad47302021-08-20 21:37:57 +093036#else
37#include <stdio.h>
Andrew Jeffery94977182022-09-30 14:12:48 +093038static inline int capture_init(void)
Andrew Jefferycad47302021-08-20 21:37:57 +093039{
Andrew Jeffery94977182022-09-30 14:12:48 +093040 fprintf(stderr,
41 "libpcap support is disabled, cannot initialise libpcap\n");
Andrew Jefferycad47302021-08-20 21:37:57 +093042 return 0;
43}
44
Andrew Jeffery94977182022-09-30 14:12:48 +093045static inline int capture_prepare(struct capture *cap)
Andrew Jefferycad47302021-08-20 21:37:57 +093046{
47 fprintf(stderr, "libpcap support is disabled, cannot capture to %s\n",
48 cap->path);
49 return 0;
50}
51
52static inline void capture_close(struct capture *cap __unused)
53{
54}
55
Andrew Jeffery94977182022-09-30 14:12:48 +093056static inline void capture_binding(struct mctp_pktbuf *pkt __unused,
Rashmica Guptaf2988972022-11-09 12:26:44 +110057 bool outgoing __unused, void *user __unused)
Andrew Jefferycad47302021-08-20 21:37:57 +093058{
59}
60
61static inline void capture_socket(pcap_dumper_t *dumper __unused,
Rashmica Guptaf2988972022-11-09 12:26:44 +110062 const void *buf __unused, size_t len __unused,
63 bool outgoing __unused, int eid __unused)
Andrew Jefferycad47302021-08-20 21:37:57 +093064{
65}
66#endif
67#endif