Skip to content

Commit

Permalink
net: context: Fix the connect check for IPv4
Browse files Browse the repository at this point in the history
Make sure that we cannot connect to IPv4 multicast or broadcast
destination address for a TCP socket.

Signed-off-by: Jukka Rissanen <[email protected]>
  • Loading branch information
jukkar committed Nov 15, 2024
1 parent f5c7f46 commit 7ba4736
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion subsys/net/ip/net_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,13 @@ int net_context_connect(struct net_context *context,
goto unlock;
}

/* FIXME - Add multicast and broadcast address check */
if (net_context_get_proto(context) == IPPROTO_TCP &&
(net_ipv4_is_addr_mcast(&addr4->sin_addr) ||
net_ipv4_is_addr_bcast(net_context_get_iface(context),
&addr4->sin_addr))) {
ret = -EADDRNOTAVAIL;

Check notice on line 1314 in subsys/net/ip/net_context.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/net/ip/net_context.c:1314 - net_ipv4_is_addr_bcast(net_context_get_iface(context), - &addr4->sin_addr))) { + net_ipv4_is_addr_bcast(net_context_get_iface(context), &addr4->sin_addr))) {

Check notice on line 1314 in subsys/net/ip/net_context.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/net/ip/net_context.c:1314 - net_ipv4_is_addr_bcast(net_context_get_iface(context), - &addr4->sin_addr))) { + net_ipv4_is_addr_bcast(net_context_get_iface(context), &addr4->sin_addr))) {

Check notice on line 1314 in subsys/net/ip/net_context.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/net/ip/net_context.c:1314 - net_ipv4_is_addr_bcast(net_context_get_iface(context), - &addr4->sin_addr))) { + net_ipv4_is_addr_bcast(net_context_get_iface(context), &addr4->sin_addr))) {
goto unlock;
}

memcpy(&addr4->sin_addr, &net_sin(addr)->sin_addr,
sizeof(struct in_addr));
Expand Down

0 comments on commit 7ba4736

Please sign in to comment.