Skip to content

Commit 29a2b5c

Browse files
rluboskartben
authored andcommitted
net: sockets: packet: Fix default binding order
Default binding should take place before we actually make use of the local address when registering packet socket "connection". Also, instead of hard coding the protocol for default binding to ETH_P_ALL, use the protocol that the socket was created with. Signed-off-by: Robert Lubos <[email protected]>
1 parent c8798d0 commit 29a2b5c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

subsys/net/ip/net_context.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ static int bind_default(struct net_context *context)
771771
}
772772

773773
ll_addr.sll_family = AF_PACKET;
774-
ll_addr.sll_protocol = htons(ETH_P_ALL);
774+
ll_addr.sll_protocol = htons(net_context_get_proto(context));
775775
ll_addr.sll_ifindex = (iface == NULL) ? 0 : net_if_get_by_iface(iface);
776776

777777
return net_context_bind(context, (struct sockaddr *)&ll_addr,
@@ -3055,11 +3055,6 @@ static int recv_raw(struct net_context *context,
30553055

30563056
ARG_UNUSED(timeout);
30573057

3058-
ret = bind_default(context);
3059-
if (ret) {
3060-
return ret;
3061-
}
3062-
30633058
context->recv_cb = cb;
30643059

30653060
/* If the context already has a connection handler, it means it's
@@ -3134,6 +3129,11 @@ int net_context_recv(struct net_context *context,
31343129
family == AF_PACKET) {
31353130
struct sockaddr_ll addr = { 0 };
31363131

3132+
ret = bind_default(context);
3133+
if (ret < 0) {
3134+
goto unlock;
3135+
}
3136+
31373137
addr.sll_family = AF_PACKET;
31383138
addr.sll_ifindex =
31393139
net_sll_ptr(&context->local)->sll_ifindex;
@@ -3156,6 +3156,11 @@ int net_context_recv(struct net_context *context,
31563156
.can_family = AF_CAN,
31573157
};
31583158

3159+
ret = bind_default(context);
3160+
if (ret < 0) {
3161+
goto unlock;
3162+
}
3163+
31593164
ret = recv_raw(context, cb, timeout,
31603165
(struct sockaddr *)&local_addr,
31613166
user_data);

0 commit comments

Comments
 (0)