Hi Matt,

Matthieu Baerts <matthieu.baerts@tessares.net> 于2020年11月4日周三 上午1:29写道:
Hi Geliang,

On 31/10/2020 16:31, Geliang Tang wrote:
> This patch added the MPTCP_PM_ADDR_ATTR_PORT filling and parsing in PM
> netlink.
>
> Signed-off-by: Geliang Tang <geliangtang@gmail.com>
> ---
>   net/mptcp/pm_netlink.c | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
> index ab0e68426c9e..069447424ddb 100644
> --- a/net/mptcp/pm_netlink.c
> +++ b/net/mptcp/pm_netlink.c
> @@ -725,6 +725,9 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
>       if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
>               entry->addr.flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);
>   
> +     if (tb[MPTCP_PM_ADDR_ATTR_PORT])
> +             entry->addr.port = htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT]));
> +
>       return 0;
>   }
>   
> @@ -911,6 +914,8 @@ static int mptcp_nl_fill_addr(struct sk_buff *skb,
>   
>       if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_FAMILY, addr->family))
>               goto nla_put_failure;
> +     if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_PORT, ntohs(addr->port)))

It looks strange to me to store something in "network" order. Do we not
store everything in "host" order, no?


I think we can't. Since the 'skc_dport' in struct sock_common and the
'sin_port' in struct sockaddr_in are all defined as big-endian order. It's
simply to keep the 'port' in struct mptcp_addr_info as a big-endian order
too.

If we define mptcp_addr_info's port as a little-endian order, we can avoid
this ntohs conversion in mptcp_nl_fill_addr, but we need add more other
order conversions in other places, like:

  in mptcp_info2sockaddr:

    in_addr->sin_port = htons(info->port);

  in remote_address:

    addr->port = ntohs(skc->skc_dport);

-Geliang

 
Cheers,
Matt
--
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net