Skip to content

Commit

Permalink
tgupdate: merge t/DO-NOT-MERGE-mptcp-enabled-by-default into t/upstre…
Browse files Browse the repository at this point in the history
…am base
  • Loading branch information
matttbe committed Sep 2, 2024
2 parents 2f64a49 + e170447 commit 549be5d
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 4 deletions.
5 changes: 5 additions & 0 deletions drivers/net/mctp/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ config MCTP_SERIAL
Say y here if you need to connect to MCTP endpoints over serial. To
compile as a module, use m; the module will be called mctp-serial.

config MCTP_SERIAL_TEST
bool "MCTP serial tests" if !KUNIT_ALL_TESTS
depends on MCTP_SERIAL=y && KUNIT=y
default KUNIT_ALL_TESTS

config MCTP_TRANSPORT_I2C
tristate "MCTP SMBus/I2C transport"
# i2c-mux is optional, but we must build as a module if i2c-mux is a module
Expand Down
113 changes: 111 additions & 2 deletions drivers/net/mctp/mctp-serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ static int next_chunk_len(struct mctp_serial *dev)
* will be those non-escaped bytes, and does not include the escaped
* byte.
*/
for (i = 1; i + dev->txpos + 1 < dev->txlen; i++) {
if (needs_escape(dev->txbuf[dev->txpos + i + 1]))
for (i = 1; i + dev->txpos < dev->txlen; i++) {
if (needs_escape(dev->txbuf[dev->txpos + i]))
break;
}

Expand Down Expand Up @@ -521,3 +521,112 @@ module_exit(mctp_serial_exit);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Jeremy Kerr <[email protected]>");
MODULE_DESCRIPTION("MCTP Serial transport");

#if IS_ENABLED(CONFIG_MCTP_SERIAL_TEST)
#include <kunit/test.h>

#define MAX_CHUNKS 6
struct test_chunk_tx {
u8 input_len;
u8 input[MCTP_SERIAL_MTU];
u8 chunks[MAX_CHUNKS];
};

static void test_next_chunk_len(struct kunit *test)
{
struct mctp_serial devx;
struct mctp_serial *dev = &devx;
int next;

const struct test_chunk_tx *params = test->param_value;

memset(dev, 0x0, sizeof(*dev));
memcpy(dev->txbuf, params->input, params->input_len);
dev->txlen = params->input_len;

for (size_t i = 0; i < MAX_CHUNKS; i++) {
next = next_chunk_len(dev);
dev->txpos += next;
KUNIT_EXPECT_EQ(test, next, params->chunks[i]);

if (next == 0) {
KUNIT_EXPECT_EQ(test, dev->txpos, dev->txlen);
return;
}
}

KUNIT_FAIL_AND_ABORT(test, "Ran out of chunks");
}

static struct test_chunk_tx chunk_tx_tests[] = {
{
.input_len = 5,
.input = { 0x00, 0x11, 0x22, 0x7e, 0x80 },
.chunks = { 3, 1, 1, 0},
},
{
.input_len = 5,
.input = { 0x00, 0x11, 0x22, 0x7e, 0x7d },
.chunks = { 3, 1, 1, 0},
},
{
.input_len = 3,
.input = { 0x7e, 0x11, 0x22, },
.chunks = { 1, 2, 0},
},
{
.input_len = 3,
.input = { 0x7e, 0x7e, 0x7d, },
.chunks = { 1, 1, 1, 0},
},
{
.input_len = 4,
.input = { 0x7e, 0x7e, 0x00, 0x7d, },
.chunks = { 1, 1, 1, 1, 0},
},
{
.input_len = 6,
.input = { 0x7e, 0x7e, 0x00, 0x7d, 0x10, 0x10},
.chunks = { 1, 1, 1, 1, 2, 0},
},
{
.input_len = 1,
.input = { 0x7e },
.chunks = { 1, 0 },
},
{
.input_len = 1,
.input = { 0x80 },
.chunks = { 1, 0 },
},
{
.input_len = 3,
.input = { 0x80, 0x80, 0x00 },
.chunks = { 3, 0 },
},
{
.input_len = 7,
.input = { 0x01, 0x00, 0x08, 0xc8, 0x00, 0x80, 0x02 },
.chunks = { 7, 0 },
},
{
.input_len = 7,
.input = { 0x01, 0x00, 0x08, 0xc8, 0x7e, 0x80, 0x02 },
.chunks = { 4, 1, 2, 0 },
},
};

KUNIT_ARRAY_PARAM(chunk_tx, chunk_tx_tests, NULL);

static struct kunit_case mctp_serial_test_cases[] = {
KUNIT_CASE_PARAM(test_next_chunk_len, chunk_tx_gen_params),
};

static struct kunit_suite mctp_serial_test_suite = {
.name = "mctp_serial",
.test_cases = mctp_serial_test_cases,
};

kunit_test_suite(mctp_serial_test_suite);

#endif /* CONFIG_MCTP_SERIAL_TEST */
2 changes: 1 addition & 1 deletion net/ipv4/tcp_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ static int tcp_bpf_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
err = sk_stream_error(sk, msg->msg_flags, err);
release_sock(sk);
sk_psock_put(sk, psock);
return copied ? copied : err;
return copied > 0 ? copied : err;
}

enum {
Expand Down
3 changes: 3 additions & 0 deletions net/smc/smc.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ struct smc_connection {

struct smc_sock { /* smc sock container */
struct sock sk;
#if IS_ENABLED(CONFIG_IPV6)
struct ipv6_pinfo *pinet6;
#endif
struct socket *clcsock; /* internal tcp socket */
void (*clcsk_state_change)(struct sock *sk);
/* original stat_change fct. */
Expand Down
8 changes: 7 additions & 1 deletion net/smc/smc_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,22 @@ static struct inet_protosw smc_inet_protosw = {
};

#if IS_ENABLED(CONFIG_IPV6)
struct smc6_sock {
struct smc_sock smc;
struct ipv6_pinfo inet6;
};

static struct proto smc_inet6_prot = {
.name = "INET6_SMC",
.owner = THIS_MODULE,
.init = smc_inet_init_sock,
.hash = smc_hash_sk,
.unhash = smc_unhash_sk,
.release_cb = smc_release_cb,
.obj_size = sizeof(struct smc_sock),
.obj_size = sizeof(struct smc6_sock),
.h.smc_hash = &smc_v6_hashinfo,
.slab_flags = SLAB_TYPESAFE_BY_RCU,
.ipv6_pinfo_offset = offsetof(struct smc6_sock, inet6),
};

static const struct proto_ops smc_inet6_stream_ops = {
Expand Down

0 comments on commit 549be5d

Please sign in to comment.