mptcpd
Multipath TCP Daemon
commands.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
10 #ifndef MPTCPD_COMMANDS_H
11 #define MPTCPD_COMMANDS_H
12 
13 #ifdef HAVE_CONFIG_H
14 # include <mptcpd/private/config.h>
15 #endif
16 
17 #include <stdbool.h>
18 #include <stddef.h> // For NULL.
19 #include <assert.h>
20 #include <sys/socket.h>
21 #include <netinet/in.h>
22 #include <linux/netlink.h> // For NLA_* macros.
23 
29 #define MPTCPD_NLA_ALIGN(v) (NLA_HDRLEN + NLA_ALIGN(sizeof(v)))
30 
40 #define MPTCPD_NLA_ALIGN_OPT(v) ((v) == 0 ? 0 : (MPTCPD_NLA_ALIGN(v)))
41 
52 #define MPTCPD_NLA_ALIGN_ADDR(v) \
53  (NLA_HDRLEN + NLA_ALIGN(mptcpd_get_addr_size(v)))
54 
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 struct l_genl_msg;
61 
70 static inline bool mptcpd_is_inet_family(struct sockaddr const *addr)
71 {
72  return addr->sa_family == AF_INET || addr->sa_family == AF_INET6;
73 }
74 
83 static inline size_t mptcpd_get_addr_size(struct sockaddr const *addr)
84 {
85  assert(mptcpd_is_inet_family(addr));
86 
87  return addr->sa_family == AF_INET
88  ? sizeof(struct in_addr)
89  : sizeof(struct in6_addr);
90 }
91 
103 static inline uint16_t mptcpd_get_addr_family(struct sockaddr const *addr)
104 {
105  sa_family_t const family = (addr == NULL ? 0 : addr->sa_family);
106 
107  return family;
108 }
109 
121 uint16_t mptcpd_get_port_number(struct sockaddr const *addr);
122 
128 
134 
147 bool mptcpd_check_genl_error(struct l_genl_msg *msg, char const *fname);
148 
155 void mptcpd_family_send_callback(struct l_genl_msg *msg, void *user_data);
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 
162 #endif /* MPTCPD_COMMANDS_H */
163 
164 
165 /*
166  Local Variables:
167  c-file-style: "linux"
168  End:
169 */
struct mptcpd_pm_cmd_ops const * mptcpd_get_mptcp_org_cmd_ops(void)
Get multipath-tcp.org kernel MPTCP generic netlink command operations.
struct mptcpd_pm_cmd_ops const * mptcpd_get_upstream_cmd_ops(void)
Get upstream kernel MPTCP generic netlink command operations.
uint16_t mptcpd_get_port_number(struct sockaddr const *addr)
Get IP port number (host byte order).
Definition: commands.c:29
bool mptcpd_check_genl_error(struct l_genl_msg *msg, char const *fname)
Check for genl operation failure.
Definition: commands.c:52
void mptcpd_family_send_callback(struct l_genl_msg *msg, void *user_data)
Generic error reporting callback.
Definition: commands.c:85
MPTCP path management generic netlink command functions.
Definition: path_manager.h:123