multipath-tcp / mptcp_net-next

Development version of the Upstream MultiPath TCP Linux kernel 🐧
https://mptcp.dev
Other
287 stars 41 forks source link

sockopt: uniform code to get/set values #353

Open matttbe opened 1 year ago

matttbe commented 1 year ago

When looking at net/mptcp/sockopt.c code, I can see multiple ways to set and get values. For example, for the setsockopt() side, we have:

IP_TRANSPARENT:

IPV6_TRANSPARENT: the opposite

IP_TOS: similar to IP_TRANSPARENT but on all subflows

TCP_FASTOPEN:

TCP_INQ:

SO_TIMESTAMPNS:

etc.

matttbe commented 1 year ago

Suggestion: probably most cases can be handled with such generic function:

static int mptcp_setsockopt_all_sf(struct mptcp_sock *msk, int level,
                   int optname, sockptr_t optval,
                   unsigned int optlen,
                   int (*get_val)(struct sock *),
                   void (*set_val)(struct sock *, int))
{
    struct mptcp_subflow_context *subflow;
    struct sock *sk = (struct sock *)msk;
    int err, val;

    err = tcp_setsockopt(sk, level, optname, optval, optlen);
    if (err != 0)
        return err;

    lock_sock(sk);
    sockopt_seq_inc(msk);
    val = get_val(sk);
    mptcp_for_each_subflow(msk, subflow) {
        struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
        bool slow = lock_sock_fast(ssk); /* Not needed? */

        set_val(ssk, val);
        unlock_sock_fast(ssk, slow);
    }
    release_sock(sk);

    return 0;
}

Example:

static int get_ip_treansparent(struct sock *sk)
{
    return inet_sk(sk)->transparent;
}

static int set_ip_treansparent(struct sock *sk, int val)
{
    return inet_sk(sk)->transparent;
}

(...)

    switch (optname) {
    case IP_TRANSPARENT:
        return mptcp_setsockopt_all_sf(msk, level, optname, optval, optlen,
                            &get_ip_treansparent, &set_ip_treansparent);

(and add set_ip_treansparent() in sync_socket_options())

WDYT?

funglee2k22 commented 1 year ago

Hey,

I hit some issue with setsockopt() with IP_TRANSPARENT (IPv4) when using MPTCPv1 (kernel version 5.15.0-69). It seems that IP_TRANSPARENT is not supported in 5.15.0-69. Should I upgrade my kernel ? do you have any recommendation on which version I should use ? Thanks.

matttbe commented 1 year ago

Hi @funglee2k22,

You need at least the v5.17: https://github.com/multipath-tcp/mptcp_net-next/wiki#changelog We recommend to use the last stable version (or at least the last LTS version).

when using MPTCPv1

MPTCPv1 is the protocol version, not the implementation.

https://github.com/multipath-tcp/mptcp_net-next/wiki#mptcpv0-vs-mptcpv1

funglee2k22 commented 1 year ago

@matttbe Thanks Matt, I upgrade to 6.1.23. and IP_TRANSPARENT starts working. Thanks.

Currently, I have some issues with a dual haproxy setup. Before I move to haproxy I had the shadowsock-libev solution working w/ mptcpv1. The similar setup (dual haproxy setup) was working fine with the mptcpv0.97 (4.* kernel). But now, not matter what I did, I could not get the dual-haproxy working (subflow is not added). (Note, both haproxy are running as a transparent proxy.).

Is there any recommendation how to debug this issue ?

matttbe commented 1 year ago

@funglee2k22 I think it would be better if you open a new issue about that, that's not related to the factoring suggested here.

In the description of this new issue, please explain how you forced HAProxy to use MPTCP (with mptcpize?) + share output of ss -pinmHM and nstat -as Tcp* MPTcp*