All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Aditi Ghag <aditi.ghag@isovalent.com>
Cc: bpf@vger.kernel.org, kafai@fb.com, edumazet@google.com,
	Stanislav Fomichev <sdf@google.com>
Subject: Re: [PATCH 6/7] selftests/bpf: Add helper to get port using getsockname
Date: Mon, 24 Apr 2023 10:58:10 -0700	[thread overview]
Message-ID: <118c84c2-bb4e-72ac-5b0d-b23100867b3e@linux.dev> (raw)
In-Reply-To: <ZD7lRqlxGfgzggAu@google.com>

On 4/18/23 11:45 AM, Stanislav Fomichev wrote:
>> +
>> +int get_socket_local_port(int family, int sock_fd, __u16 *out_port)
>> +{
>> +	socklen_t addr_len;
>> +	int err;
> 
> Sorry for keeping bikeshedding this part, but if you're going to do
> another respin, we can also drop the family argument:
> 
> int get_socket_local_port(int sock_fd, __be16 *out_port)
> /*                                       ^^ maybe also do be16? */

I would also just return the port as the return value instead of having another 
arg for this. The int is more than enough.

> {
> 	struct sockaddr_storage addr;
> 	socklen_t addrlen;
> 
> 	addrlen = sizeof(addr);
> 	getsockname(sock_fd, (struct sockaddr *)&addr, &addrlen);
> 
> 	if (addr.ss_family == AF_INET) {
> 	} else if () {
> 	}
> }
> 
>> +
>> +	if (family == AF_INET) {
>> +		struct sockaddr_in addr = {};
>> +
>> +		addr_len = sizeof(addr);
>> +		err = getsockname(sock_fd, (struct sockaddr *)&addr, &addr_len);
>> +		if (err < 0)
>> +			return err;
>> +		*out_port = addr.sin_port;
>> +		return 0;
>> +	} else if (family == AF_INET6) {
>> +		struct sockaddr_in6 addr = {};
>> +
>> +		addr_len = sizeof(addr);
>> +		err = getsockname(sock_fd, (struct sockaddr *)&addr, &addr_len);
>> +		if (err < 0)
>> +			return err;
>> +		*out_port = addr.sin6_port;
>> +		return 0;
>> +	}
>> +
>> +	return -1;
>> +}


  reply	other threads:[~2023-04-24 17:58 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18 15:31 [PATCH v6 bpf-next 0/7] bpf: Add socket destroy capability Aditi Ghag
2023-04-18 15:31 ` [PATCH 1/7] bpf: tcp: Avoid taking fast sock lock in iterator Aditi Ghag
2023-04-20  8:55   ` Paolo Abeni
2023-05-03 20:25     ` Aditi Ghag
2023-04-25  5:45   ` Yonghong Song
2023-05-03 20:26     ` Aditi Ghag
2023-04-18 15:31 ` [PATCH 2/7] udp: seq_file: Remove bpf_seq_afinfo from udp_iter_state Aditi Ghag
2023-04-24  0:18   ` Martin KaFai Lau
2023-05-01 22:39     ` Aditi Ghag
2023-04-18 15:31 ` [PATCH 3/7] udp: seq_file: Helper function to match socket attributes Aditi Ghag
2023-04-18 15:31 ` [PATCH 4/7] bpf: udp: Implement batching for sockets iterator Aditi Ghag
2023-04-20 14:07   ` Paolo Abeni
2023-04-24  5:46   ` Martin KaFai Lau
2023-04-18 15:31 ` [PATCH 5/7] bpf: Add bpf_sock_destroy kfunc Aditi Ghag
2023-04-18 15:31 ` [PATCH 6/7] selftests/bpf: Add helper to get port using getsockname Aditi Ghag
2023-04-18 18:45   ` Stanislav Fomichev
2023-04-24 17:58     ` Martin KaFai Lau [this message]
2023-04-18 15:31 ` [PATCH 7/7] selftests/bpf: Test bpf_sock_destroy Aditi Ghag
2023-04-24 19:20   ` Martin KaFai Lau
2023-04-24 22:15 ` [PATCH v6 bpf-next 0/7] bpf: Add socket destroy capability Martin KaFai Lau
2023-05-01 23:32   ` Aditi Ghag
2023-05-01 23:37     ` Aditi Ghag
2023-05-02 23:24       ` Martin KaFai Lau
2023-05-02 22:52     ` Aditi Ghag
2023-05-02 23:40       ` Martin KaFai Lau
2023-05-04 17:32         ` Aditi Ghag

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=118c84c2-bb4e-72ac-5b0d-b23100867b3e@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=aditi.ghag@isovalent.com \
    --cc=bpf@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=kafai@fb.com \
    --cc=sdf@google.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.