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 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 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 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 
120 uint16_t mptcpd_get_port_number(struct sockaddr const *addr);
121 
127 
133 
146 bool mptcpd_check_genl_error(struct l_genl_msg *msg, char const *fname);
147 
154 void mptcpd_family_send_callback(struct l_genl_msg *msg, void *user_data);
155 
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 
161 #endif /* MPTCPD_COMMANDS_H */
162 
163 
164 /*
165  Local Variables:
166  c-file-style: "linux"
167  End:
168 */
uint16_t mptcpd_get_addr_family(struct sockaddr const *addr)
Get network address family.
Definition: commands.h:103
struct mptcpd_pm_cmd_ops const * mptcpd_get_mptcp_org_cmd_ops(void)
Get multipath-tcp.org kernel MPTCP generic netlink command operations.
bool mptcpd_is_inet_family(struct sockaddr const *addr)
Check for internet address family.
Definition: commands.h:70
struct mptcpd_pm_cmd_ops const * mptcpd_get_upstream_cmd_ops(void)
Get upstream kernel MPTCP generic netlink command operations.
size_t mptcpd_get_addr_size(struct sockaddr const *addr)
Get the underlying internet address size.
Definition: commands.h:83
uint16_t mptcpd_get_port_number(struct sockaddr const *addr)
Get IP port number.
Definition: commands.c:25
bool mptcpd_check_genl_error(struct l_genl_msg *msg, char const *fname)
Check for genl operation failure.
Definition: commands.c:48
void mptcpd_family_send_callback(struct l_genl_msg *msg, void *user_data)
Generic error reporting callback.
Definition: commands.c:81
MPTCP path management generic netlink command functions.
Definition: path_manager.h:123