-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathmctp-ops.c
More file actions
91 lines (78 loc) · 1.9 KB
/
mctp-ops.c
File metadata and controls
91 lines (78 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* SPDX-License-Identifier: GPL-2.0 */
/*
* mctp-ops: Abstraction for socket operations for mctp & mctpd.
*
* Copyright (c) 2023 Code Construct
*/
#define _GNU_SOURCE
#include <unistd.h>
#include <linux/netlink.h>
#if HAVE_LIBSYSTEMD
#include <systemd/sd-event.h>
#endif
#include <err.h>
#include "mctp.h"
#include "mctp-ops.h"
static int mctp_op_mctp_socket(void)
{
return socket(AF_MCTP, SOCK_DGRAM, 0);
}
static int mctp_op_netlink_socket(void)
{
return socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
}
static int mctp_op_bind(int sd, struct sockaddr *addr, socklen_t addrlen)
{
return bind(sd, addr, addrlen);
}
static int mctp_op_setsockopt(int sd, int level, int optname, void *optval,
socklen_t optlen)
{
return setsockopt(sd, level, optname, optval, optlen);
}
static ssize_t mctp_op_sendto(int sd, const void *buf, size_t len, int flags,
const struct sockaddr *dest, socklen_t addrlen)
{
return sendto(sd, buf, len, flags, dest, addrlen);
}
static ssize_t mctp_op_recvfrom(int sd, void *buf, size_t len, int flags,
struct sockaddr *src, socklen_t *addrlen)
{
return recvfrom(sd, buf, len, flags, src, addrlen);
}
static int mctp_op_close(int sd)
{
return close(sd);
}
static void mctp_bug_warn(const char *fmt, va_list args)
{
vwarnx(fmt, args);
}
const struct mctp_ops mctp_ops = {
.mctp = {
.socket = mctp_op_mctp_socket,
.setsockopt = mctp_op_setsockopt,
.bind = mctp_op_bind,
.sendto = mctp_op_sendto,
.recvfrom = mctp_op_recvfrom,
.close = mctp_op_close,
},
.nl = {
.socket = mctp_op_netlink_socket,
.setsockopt = mctp_op_setsockopt,
.bind = mctp_op_bind,
.sendto = mctp_op_sendto,
.recvfrom = mctp_op_recvfrom,
.close = mctp_op_close,
},
#if HAVE_LIBSYSTEMD
.sd_event = {
.add_time_relative = sd_event_add_time_relative,
.source_set_time_relative = sd_event_source_set_time_relative,
},
#endif
.bug_warn = mctp_bug_warn,
};
void mctp_ops_init(void)
{
}