Skip to content

Commit 157c11d

Browse files
jukkarcarlescufi
authored andcommitted
net: context: Check interface status when sending
If the network interface is down when trying to send a message, return -ENETDOWN as we cannot send a message in this case. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 8289b8c commit 157c11d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

subsys/net/ip/net_context.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,7 @@ static int context_sendto(struct net_context *context,
13971397
bool sendto)
13981398
{
13991399
const struct msghdr *msghdr = NULL;
1400+
struct net_if *iface;
14001401
struct net_pkt *pkt;
14011402
size_t tmp_len;
14021403
int ret;
@@ -1471,7 +1472,6 @@ static int context_sendto(struct net_context *context,
14711472
} else if (IS_ENABLED(CONFIG_NET_SOCKETS_PACKET) &&
14721473
net_context_get_family(context) == AF_PACKET) {
14731474
struct sockaddr_ll *ll_addr = (struct sockaddr_ll *)dst_addr;
1474-
struct net_if *iface;
14751475

14761476
if (msghdr) {
14771477
ll_addr = msghdr->msg_name;
@@ -1520,7 +1520,6 @@ static int context_sendto(struct net_context *context,
15201520
} else if (IS_ENABLED(CONFIG_NET_SOCKETS_CAN) &&
15211521
net_context_get_family(context) == AF_CAN) {
15221522
struct sockaddr_can *can_addr = (struct sockaddr_can *)dst_addr;
1523-
struct net_if *iface;
15241523

15251524
if (msghdr) {
15261525
can_addr = msghdr->msg_name;
@@ -1571,6 +1570,11 @@ static int context_sendto(struct net_context *context,
15711570
}
15721571
}
15731572

1573+
iface = net_context_get_iface(context);
1574+
if (iface && !net_if_is_up(iface)) {
1575+
return -ENETDOWN;
1576+
}
1577+
15741578
pkt = context_alloc_pkt(context, len, PKT_WAIT_TIME);
15751579
if (!pkt) {
15761580
return -ENOBUFS;

0 commit comments

Comments
 (0)