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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
// SPDX-License-Identifier: BSD-3-Clause
/**
* @file two.c
*
* @brief MPTCP test plugin.
*
* Copyright (c) 2019-2022, Intel Corporation
*/
#include <ell/ell.h>
#ifdef HAVE_CONFIG_H
# include <mptcpd/private/config.h>
#endif
#include <mptcpd/plugin.h>
#include "test-plugin.h"
#undef NDEBUG
#include <assert.h>
// ----------------------------------------------------------------
static struct plugin_call_count call_count;
static struct sockaddr const *const local_addr =
(struct sockaddr const *) &test_laddr_2;
static struct sockaddr const *const remote_addr =
(struct sockaddr const *) &test_raddr_2;
// ----------------------------------------------------------------
static void plugin_two_new_connection(mptcpd_token_t token,
struct sockaddr const *laddr,
struct sockaddr const *raddr,
bool server_side,
bool deny_join_id0,
struct mptcpd_pm *pm)
{
(void) pm;
assert(token == test_token_2);
assert(laddr != NULL && raddr != NULL);
assert(!sockaddr_is_equal(laddr, raddr));
assert(sockaddr_is_equal(laddr, local_addr));
assert(sockaddr_is_equal(raddr, remote_addr));
assert(server_side == test_server_side_2);
assert(deny_join_id0 == test_deny_join_id0_2);
++call_count.new_connection;
}
static void plugin_two_connection_established(
mptcpd_token_t token,
struct sockaddr const *laddr,
struct sockaddr const *raddr,
bool server_side,
bool deny_join_id0,
struct mptcpd_pm *pm)
{
(void) pm;
assert(token == test_token_2);
assert(laddr != NULL && raddr != NULL);
assert(!sockaddr_is_equal(laddr, raddr));
assert(sockaddr_is_equal(laddr, local_addr));
assert(sockaddr_is_equal(raddr, remote_addr));
assert(server_side == test_server_side_2);
assert(deny_join_id0 == test_deny_join_id0_2);
++call_count.connection_established;
}
static void plugin_two_connection_closed(mptcpd_token_t token,
struct mptcpd_pm *pm)
{
(void) pm;
assert(token == test_token_2);
++call_count.connection_closed;
}
static void plugin_two_new_address(mptcpd_token_t token,
mptcpd_aid_t addr_id,
struct sockaddr const *addr,
struct mptcpd_pm *pm)
{
(void) pm;
assert(token == test_token_2);
assert(addr_id == test_raddr_id_2);
assert(sockaddr_is_equal(addr, remote_addr));
++call_count.new_address;
}
static void plugin_two_address_removed(mptcpd_token_t token,
mptcpd_aid_t addr_id,
struct mptcpd_pm *pm)
{
(void) pm;
assert(token == test_token_2);
assert(addr_id == test_raddr_id_2);
++call_count.address_removed;
}
static void plugin_two_new_subflow(mptcpd_token_t token,
struct sockaddr const *laddr,
struct sockaddr const *raddr,
bool backup,
struct mptcpd_pm *pm)
{
(void) pm;
assert(token == test_token_2);
assert(!sockaddr_is_equal(laddr, raddr));
assert(sockaddr_is_equal(laddr, local_addr));
assert(sockaddr_is_equal(raddr, remote_addr));
assert(backup == test_backup_2);
++call_count.new_subflow;
}
static void plugin_two_subflow_closed(mptcpd_token_t token,
struct sockaddr const *laddr,
struct sockaddr const *raddr,
bool backup,
uint8_t error,
struct mptcpd_pm *pm)
{
(void) pm;
assert(token == test_token_2);
assert(sockaddr_is_equal(laddr, local_addr));
assert(sockaddr_is_equal(raddr, remote_addr));
assert(backup == test_backup_2);
assert(error == test_error_2);
++call_count.subflow_closed;
}
static void plugin_two_subflow_priority(mptcpd_token_t token,
struct sockaddr const *laddr,
struct sockaddr const *raddr,
bool backup,
struct mptcpd_pm *pm)
{
(void) pm;
assert(token == test_token_2);
assert(!sockaddr_is_equal(laddr, raddr));
assert(sockaddr_is_equal(laddr, local_addr));
assert(sockaddr_is_equal(raddr, remote_addr));
assert(backup == test_backup_2);
++call_count.subflow_priority;
}
static void plugin_two_listener_created(struct sockaddr const *laddr,
struct mptcpd_pm *pm)
{
(void) pm;
assert(laddr != NULL);
assert(sockaddr_is_equal(laddr, local_addr));
++call_count.listener_created;
}
static void plugin_two_listener_closed(struct sockaddr const *laddr,
struct mptcpd_pm *pm)
{
(void) pm;
assert(laddr != NULL);
assert(sockaddr_is_equal(laddr, local_addr));
++call_count.listener_closed;
}
void plugin_two_new_interface(struct mptcpd_interface const *i,
struct mptcpd_pm *pm)
{
(void) i;
(void) pm;
++call_count.new_interface;
}
void plugin_two_update_interface(struct mptcpd_interface const *i,
struct mptcpd_pm *pm)
{
(void) i;
(void) pm;
++call_count.update_interface;
}
void plugin_two_delete_interface(struct mptcpd_interface const *i,
struct mptcpd_pm *pm)
{
(void) i;
(void) pm;
++call_count.delete_interface;
}
void plugin_two_new_local_address(struct mptcpd_interface const *i,
struct sockaddr const *sa,
struct mptcpd_pm *pm)
{
(void) i;
(void) sa;
(void) pm;
++call_count.new_local_address;
}
void plugin_two_delete_local_address(struct mptcpd_interface const *i,
struct sockaddr const *sa,
struct mptcpd_pm *pm)
{
(void) i;
(void) sa;
(void) pm;
++call_count.delete_local_address;
}
static struct mptcpd_plugin_ops const pm_ops = {
.new_connection = plugin_two_new_connection,
.connection_established = plugin_two_connection_established,
.connection_closed = plugin_two_connection_closed,
.new_address = plugin_two_new_address,
.address_removed = plugin_two_address_removed,
.new_subflow = plugin_two_new_subflow,
.subflow_closed = plugin_two_subflow_closed,
.subflow_priority = plugin_two_subflow_priority,
.listener_created = plugin_two_listener_created,
.listener_closed = plugin_two_listener_closed,
.new_interface = plugin_two_new_interface,
.update_interface = plugin_two_update_interface,
.delete_interface = plugin_two_delete_interface,
.new_local_address = plugin_two_new_local_address,
.delete_local_address = plugin_two_delete_local_address
};
static int plugin_two_init(struct mptcpd_pm *pm)
{
(void) pm;
static char const name[] = TEST_PLUGIN;
if (!mptcpd_plugin_register_ops(name, &pm_ops)) {
l_error("Failed to initialize test "
"plugin \"" TEST_PLUGIN "\".");
return -1;
}
return 0;
}
static void plugin_two_exit(struct mptcpd_pm *pm)
{
(void) pm;
assert(call_count_is_sane(&call_count));
assert(call_count_is_equal(&call_count, &test_count_2));
call_count_reset(&call_count);
}
MPTCPD_PLUGIN_DEFINE(plugin_two,
"test plugin two",
MPTCPD_PLUGIN_PRIORITY_LOW, // unfavorable priority
plugin_two_init,
plugin_two_exit)
/*
Local Variables:
c-file-style: "linux"
End:
*/
|