Skip to content

Commit 64dc2b6

Browse files
committed
net: connection: Unconditionally forward into packet sockets
When handling packets for inputing into packet-sockets, unconditionally forward them, so that they may be handled by the rest of the network stack after. Signed-off-by: Cla Mattia Galliard <clamattia@gmail.com>
1 parent e17f88f commit 64dc2b6

File tree

5 files changed

+19
-65
lines changed

5 files changed

+19
-65
lines changed

subsys/net/ip/connection.c

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -637,16 +637,14 @@ static void conn_raw_socket_deliver(struct net_pkt *pkt, struct net_conn *conn,
637637
#endif /* defined(CONFIG_NET_SOCKETS_PACKET) || defined(CONFIG_NET_SOCKETS_INET_RAW) */
638638

639639
#if defined(CONFIG_NET_SOCKETS_PACKET)
640-
enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto, enum net_sock_type type)
640+
void net_conn_packet_input(struct net_pkt *pkt, uint16_t proto, enum net_sock_type type)
641641
{
642-
bool raw_sock_found = false;
643-
bool raw_pkt_continue = false;
644642
struct sockaddr_ll *local;
645643
struct net_conn *conn;
646644

647645
/* Only accept input with AF_PACKET family. */
648646
if (net_pkt_family(pkt) != AF_PACKET) {
649-
return NET_CONTINUE;
647+
return;
650648
}
651649

652650
NET_DBG("Check proto 0x%04x listener for pkt %p family %d",
@@ -666,33 +664,22 @@ enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto, enum
666664
* in this packet.
667665
*/
668666
if (conn->family != AF_PACKET) {
669-
raw_pkt_continue = true;
670667
continue; /* wrong family */
671668
}
672669

673-
if (conn->type == SOCK_DGRAM && type == SOCK_RAW) {
674-
/* If DGRAM packet sockets are present, we shall continue
675-
* with this packet regardless the result.
676-
*/
677-
raw_pkt_continue = true;
678-
continue; /* L2 not processed yet */
679-
}
680-
681-
if (conn->type == SOCK_RAW && type != SOCK_RAW) {
682-
continue; /* L2 already processed */
670+
if (conn->type != type) {
671+
continue;
683672
}
684673

685674
if (conn->proto == 0) {
686675
continue; /* Local proto 0 doesn't forward any packets */
687676
}
688677

689-
if (conn->proto != proto) {
690-
/* Allow proto mismatch if socket was created with ETH_P_ALL, or it's raw
691-
* packet socket input (proto ETH_P_ALL).
692-
*/
693-
if (conn->proto != ETH_P_ALL && proto != ETH_P_ALL) {
694-
continue; /* wrong protocol */
695-
}
678+
/* Allow proto mismatch if socket was created with ETH_P_ALL, or it's raw
679+
* packet socket input.
680+
*/
681+
if (conn->proto != proto && conn->proto != ETH_P_ALL && type != SOCK_RAW) {
682+
continue; /* wrong protocol */
696683
}
697684

698685
/* Apply protocol-specific matching criteria... */
@@ -708,32 +695,17 @@ enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto, enum
708695

709696
conn_raw_socket_deliver(pkt, conn, false);
710697

711-
raw_sock_found = true;
712698
}
713699

714700
k_mutex_unlock(&conn_lock);
715701

716-
if (!raw_pkt_continue && raw_sock_found) {
717-
/* As one or more raw socket packets have already been delivered
718-
* in the loop above, report NET_OK.
719-
*/
720-
net_pkt_unref(pkt);
721-
return NET_OK;
722-
}
723-
724-
/* When there is open connection different than AF_PACKET this
725-
* packet shall be also handled in the upper net stack layers.
726-
*/
727-
return NET_CONTINUE;
728702
}
729703
#else
730-
enum net_verdict net_conn_packet_input(struct net_pkt *pkt, uint16_t proto, enum net_sock_type type)
704+
void net_conn_packet_input(struct net_pkt *pkt, uint16_t proto, enum net_sock_type type)
731705
{
732706
ARG_UNUSED(pkt);
733707
ARG_UNUSED(proto);
734708
ARG_UNUSED(type);
735-
736-
return NET_CONTINUE;
737709
}
738710
#endif /* defined(CONFIG_NET_SOCKETS_PACKET) */
739711

subsys/net/ip/connection.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,8 @@ int net_conn_update(struct net_conn_handle *handle,
191191
* @param proto LL protocol for the connection
192192
* @param type socket type
193193
*
194-
* @return NET_OK if the packet was consumed, NET_CONTINUE if the packet should
195-
* be processed further in the stack.
196194
*/
197-
enum net_verdict net_conn_packet_input(struct net_pkt *pkt,
195+
void net_conn_packet_input(struct net_pkt *pkt,
198196
uint16_t proto,
199197
enum net_sock_type type);
200198

subsys/net/ip/net_core.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ static inline enum net_verdict process_data(struct net_pkt *pkt)
6868
{
6969
int ret;
7070

71-
ret = net_packet_socket_input(pkt, ETH_P_ALL, SOCK_RAW);
72-
if (ret != NET_CONTINUE) {
73-
return ret;
74-
}
71+
net_packet_socket_input(pkt, ETH_P_ALL, SOCK_RAW);
7572

7673
/* If there is no data, then drop the packet. */
7774
if (!pkt->frags) {
@@ -101,10 +98,7 @@ static inline enum net_verdict process_data(struct net_pkt *pkt)
10198
net_pkt_cursor_init(pkt);
10299

103100
if (IS_ENABLED(CONFIG_NET_SOCKETS_PACKET_DGRAM)) {
104-
ret = net_packet_socket_input(pkt, net_pkt_ll_proto_type(pkt), SOCK_DGRAM);
105-
if (ret != NET_CONTINUE) {
106-
return ret;
107-
}
101+
net_packet_socket_input(pkt, net_pkt_ll_proto_type(pkt), SOCK_DGRAM);
108102
}
109103

110104
uint8_t family = net_pkt_family(pkt);

subsys/net/ip/packet_socket.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ LOG_MODULE_REGISTER(net_sockets_raw, CONFIG_NET_SOCKETS_LOG_LEVEL);
2222
#include "connection.h"
2323
#include "packet_socket.h"
2424

25-
enum net_verdict net_packet_socket_input(struct net_pkt *pkt,
25+
void net_packet_socket_input(struct net_pkt *pkt,
2626
uint16_t proto,
2727
enum net_sock_type type)
2828
{
2929
sa_family_t orig_family;
30-
enum net_verdict net_verdict;
3130

3231
#if defined(CONFIG_NET_DSA_DEPRECATED)
3332
/*
@@ -43,9 +42,7 @@ enum net_verdict net_packet_socket_input(struct net_pkt *pkt,
4342

4443
net_pkt_set_family(pkt, AF_PACKET);
4544

46-
net_verdict = net_conn_packet_input(pkt, proto, type);
45+
net_conn_packet_input(pkt, proto, type);
4746

4847
net_pkt_set_family(pkt, orig_family);
49-
50-
return net_verdict;
5148
}

subsys/net/ip/packet_socket.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,14 @@
2020
*
2121
* @param pkt Network packet
2222
*
23-
* @return NET_OK if the packet was consumed, NET_DROP if
24-
* the packet parsing failed and the caller should handle
25-
* the received packet. If corresponding IP protocol support is
26-
* disabled, the function will always return NET_DROP.
2723
*/
2824
#if defined(CONFIG_NET_SOCKETS_PACKET)
29-
enum net_verdict net_packet_socket_input(struct net_pkt *pkt,
30-
uint16_t proto,
31-
enum net_sock_type type);
25+
void net_packet_socket_input(struct net_pkt *pkt, uint16_t proto, enum net_sock_type type);
3226
#else
33-
static inline enum net_verdict net_packet_socket_input(struct net_pkt *pkt,
34-
uint16_t proto,
35-
enum net_sock_type type)
27+
static inline void net_packet_socket_input(struct net_pkt *pkt,
28+
uint16_t proto,
29+
enum net_sock_type type)
3630
{
37-
return NET_CONTINUE;
3831
}
3932
#endif
4033

0 commit comments

Comments
 (0)