Skip to content

Commit ed449dd

Browse files
keesPaolo Abeni
authored andcommitted
net: core: Convert inet_addr_is_any() to sockaddr_storage
All the callers of inet_addr_is_any() have a sockaddr_storage-backed sockaddr. Avoid casts and switch prototype to the actual object being used. Reviewed-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> # SCSI Signed-off-by: Kees Cook <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 5bccdc5 commit ed449dd

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

drivers/nvme/target/rdma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1999,7 +1999,7 @@ static void nvmet_rdma_disc_port_addr(struct nvmet_req *req,
19991999
struct nvmet_rdma_port *port = nport->priv;
20002000
struct rdma_cm_id *cm_id = port->cm_id;
20012001

2002-
if (inet_addr_is_any((struct sockaddr *)&cm_id->route.addr.src_addr)) {
2002+
if (inet_addr_is_any(&cm_id->route.addr.src_addr)) {
20032003
struct nvmet_rdma_rsp *rsp =
20042004
container_of(req, struct nvmet_rdma_rsp, req);
20052005
struct rdma_cm_id *req_cm_id = rsp->queue->cm_id;

drivers/nvme/target/tcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,7 @@ static void nvmet_tcp_disc_port_addr(struct nvmet_req *req,
21942194
{
21952195
struct nvmet_tcp_port *port = nport->priv;
21962196

2197-
if (inet_addr_is_any((struct sockaddr *)&port->addr)) {
2197+
if (inet_addr_is_any(&port->addr)) {
21982198
struct nvmet_tcp_cmd *cmd =
21992199
container_of(req, struct nvmet_tcp_cmd, req);
22002200
struct nvmet_tcp_queue *queue = cmd->queue;

drivers/target/iscsi/iscsi_target.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3419,7 +3419,7 @@ iscsit_build_sendtargets_response(struct iscsit_cmd *cmd,
34193419
}
34203420
}
34213421

3422-
if (inet_addr_is_any((struct sockaddr *)&np->np_sockaddr))
3422+
if (inet_addr_is_any(&np->np_sockaddr))
34233423
sockaddr = &conn->local_sockaddr;
34243424
else
34253425
sockaddr = &np->np_sockaddr;

include/linux/inet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ extern int in6_pton(const char *src, int srclen, u8 *dst, int delim, const char
5555

5656
extern int inet_pton_with_scope(struct net *net, unsigned short af,
5757
const char *src, const char *port, struct sockaddr_storage *addr);
58-
extern bool inet_addr_is_any(struct sockaddr *addr);
58+
bool inet_addr_is_any(struct sockaddr_storage *addr);
5959

6060
#endif /* _LINUX_INET_H */

net/core/utils.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,23 +399,23 @@ int inet_pton_with_scope(struct net *net, __kernel_sa_family_t af,
399399
}
400400
EXPORT_SYMBOL(inet_pton_with_scope);
401401

402-
bool inet_addr_is_any(struct sockaddr *addr)
402+
bool inet_addr_is_any(struct sockaddr_storage *addr)
403403
{
404-
if (addr->sa_family == AF_INET6) {
404+
if (addr->ss_family == AF_INET6) {
405405
struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr;
406406
const struct sockaddr_in6 in6_any =
407407
{ .sin6_addr = IN6ADDR_ANY_INIT };
408408

409409
if (!memcmp(in6->sin6_addr.s6_addr,
410410
in6_any.sin6_addr.s6_addr, 16))
411411
return true;
412-
} else if (addr->sa_family == AF_INET) {
412+
} else if (addr->ss_family == AF_INET) {
413413
struct sockaddr_in *in = (struct sockaddr_in *)addr;
414414

415415
if (in->sin_addr.s_addr == htonl(INADDR_ANY))
416416
return true;
417417
} else {
418-
pr_warn("unexpected address family %u\n", addr->sa_family);
418+
pr_warn("unexpected address family %u\n", addr->ss_family);
419419
}
420420

421421
return false;

0 commit comments

Comments
 (0)