From: David Miller <davem@davemloft.net>
To: lucien.xin@gmail.com
Cc: netdev@vger.kernel.org, linux-sctp@vger.kernel.org,
marcelo.leitner@gmail.com, nhorman@tuxdriver.com
Subject: Re: [PATCH net] sctp: do not check port in sctp_inet6_cmp_addr
Date: Wed, 11 Apr 2018 10:51:37 -0400 (EDT) [thread overview]
Message-ID: <20180411.105137.2091306176910843241.davem@davemloft.net> (raw)
In-Reply-To: <340aad3be762046ca9d02e54edba5bfefa2f4e71.1523451485.git.lucien.xin@gmail.com>
From: Xin Long <lucien.xin@gmail.com>
Date: Wed, 11 Apr 2018 20:58:05 +0800
> @@ -863,10 +863,31 @@ static int sctp_inet6_cmp_addr(const union sctp_addr *addr1,
> if (sctp_is_any(sk, addr1) || sctp_is_any(sk, addr2))
> return 1;
>
> - if (addr1->sa.sa_family != addr2->sa.sa_family)
> + if (addr1->sa.sa_family != addr2->sa.sa_family) {
> + if (addr1->sa.sa_family == AF_INET &&
> + addr2->sa.sa_family == AF_INET6 &&
> + ipv6_addr_v4mapped(&addr2->v6.sin6_addr))
> + if (addr2->v6.sin6_addr.s6_addr32[3] ==
> + addr1->v4.sin_addr.s_addr)
> + return 1;
> + if (addr2->sa.sa_family == AF_INET &&
> + addr1->sa.sa_family == AF_INET6 &&
> + ipv6_addr_v4mapped(&addr1->v6.sin6_addr))
> + if (addr1->v6.sin6_addr.s6_addr32[3] ==
> + addr2->v4.sin_addr.s_addr)
> + return 1;
> + return 0;
> + }
> +
> + if (!ipv6_addr_equal(&addr1->v6.sin6_addr, &addr2->v6.sin6_addr))
> + return 0;
> +
> + if ((ipv6_addr_type(&addr1->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) &&
> + addr1->v6.sin6_scope_id && addr2->v6.sin6_scope_id &&
> + addr1->v6.sin6_scope_id != addr2->v6.sin6_scope_id)
> return 0;
>
> - return af1->cmp_addr(addr1, addr2);
> + return 1;
> }
I agree with Neil that we should try to avoid the code duplication here
somehow.
Although we risk gcc emitting two copies of the function if we do
something like:
__sctp_v6_cmp_addr(addr1, addr2, check_ports)
{
}
sctp_v6_cmp_addr(addr, addr2)
{
return __sctp_v6_cmp_addr(addr1, addr2, true);
}
and invoke __sctp_v6_cmp_addr(addr1, addr2, true) from sctp_inet6_cmp_addr().
WARNING: multiple messages have this Message-ID (diff)
From: David Miller <davem@davemloft.net>
To: lucien.xin@gmail.com
Cc: netdev@vger.kernel.org, linux-sctp@vger.kernel.org,
marcelo.leitner@gmail.com, nhorman@tuxdriver.com
Subject: Re: [PATCH net] sctp: do not check port in sctp_inet6_cmp_addr
Date: Wed, 11 Apr 2018 14:51:37 +0000 [thread overview]
Message-ID: <20180411.105137.2091306176910843241.davem@davemloft.net> (raw)
In-Reply-To: <340aad3be762046ca9d02e54edba5bfefa2f4e71.1523451485.git.lucien.xin@gmail.com>
From: Xin Long <lucien.xin@gmail.com>
Date: Wed, 11 Apr 2018 20:58:05 +0800
> @@ -863,10 +863,31 @@ static int sctp_inet6_cmp_addr(const union sctp_addr *addr1,
> if (sctp_is_any(sk, addr1) || sctp_is_any(sk, addr2))
> return 1;
>
> - if (addr1->sa.sa_family != addr2->sa.sa_family)
> + if (addr1->sa.sa_family != addr2->sa.sa_family) {
> + if (addr1->sa.sa_family = AF_INET &&
> + addr2->sa.sa_family = AF_INET6 &&
> + ipv6_addr_v4mapped(&addr2->v6.sin6_addr))
> + if (addr2->v6.sin6_addr.s6_addr32[3] =
> + addr1->v4.sin_addr.s_addr)
> + return 1;
> + if (addr2->sa.sa_family = AF_INET &&
> + addr1->sa.sa_family = AF_INET6 &&
> + ipv6_addr_v4mapped(&addr1->v6.sin6_addr))
> + if (addr1->v6.sin6_addr.s6_addr32[3] =
> + addr2->v4.sin_addr.s_addr)
> + return 1;
> + return 0;
> + }
> +
> + if (!ipv6_addr_equal(&addr1->v6.sin6_addr, &addr2->v6.sin6_addr))
> + return 0;
> +
> + if ((ipv6_addr_type(&addr1->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) &&
> + addr1->v6.sin6_scope_id && addr2->v6.sin6_scope_id &&
> + addr1->v6.sin6_scope_id != addr2->v6.sin6_scope_id)
> return 0;
>
> - return af1->cmp_addr(addr1, addr2);
> + return 1;
> }
I agree with Neil that we should try to avoid the code duplication here
somehow.
Although we risk gcc emitting two copies of the function if we do
something like:
__sctp_v6_cmp_addr(addr1, addr2, check_ports)
{
}
sctp_v6_cmp_addr(addr, addr2)
{
return __sctp_v6_cmp_addr(addr1, addr2, true);
}
and invoke __sctp_v6_cmp_addr(addr1, addr2, true) from sctp_inet6_cmp_addr().
next prev parent reply other threads:[~2018-04-11 14:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-11 12:58 [PATCH net] sctp: do not check port in sctp_inet6_cmp_addr Xin Long
2018-04-11 12:58 ` Xin Long
2018-04-11 14:36 ` Neil Horman
2018-04-11 14:36 ` Neil Horman
2018-04-11 14:59 ` Marcelo Ricardo Leitner
2018-04-11 14:59 ` Marcelo Ricardo Leitner
2018-04-11 16:16 ` Xin Long
2018-04-11 16:16 ` Xin Long
2018-04-11 16:40 ` David Miller
2018-04-11 16:40 ` David Miller
2018-04-11 19:59 ` Neil Horman
2018-04-11 19:59 ` Neil Horman
2018-04-11 14:42 ` Marcelo Ricardo Leitner
2018-04-11 14:42 ` Marcelo Ricardo Leitner
2018-04-11 14:51 ` Marcelo Ricardo Leitner
2018-04-11 14:51 ` Marcelo Ricardo Leitner
2018-04-11 14:51 ` David Miller [this message]
2018-04-11 14:51 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180411.105137.2091306176910843241.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=linux-sctp@vger.kernel.org \
--cc=lucien.xin@gmail.com \
--cc=marcelo.leitner@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=nhorman@tuxdriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.