Skip to content

Commit 76fc11e

Browse files
author
Tomasz Bursztyka
committed
net/context: Make recv_cb providing the ip and protocol headers
If status is 0, both ip_hdr and proto_hdr will own a pointer to the relevant IP and Protocol headers. In order to know which of ipv4/ipv6 and udp/tcp one will need to use respectively net_pkt_family(pkt) and net_context_get_ip_proto(context). Having access to those headers directly, many callbacks will not need to parse the packet again no get the src/dst addresses or the src/dst ports. This will be change after this commit. Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent bb50b7a commit 76fc11e

File tree

23 files changed

+80
-27
lines changed

23 files changed

+80
-27
lines changed

drivers/console/telnet_console.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ static inline void telnet_handle_input(struct net_pkt *pkt)
395395

396396
static void telnet_recv(struct net_context *client,
397397
struct net_pkt *pkt,
398+
union net_ip_header *ip_hdr,
399+
union net_proto_header *proto_hdr,
398400
int status,
399401
void *user_data)
400402
{

drivers/modem/wncm14a2a.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,8 @@ static void sockreadrecv_cb_work(struct k_work *work)
777777
pkt = sock->recv_pkt;
778778
sock->recv_pkt = NULL;
779779
if (sock->recv_cb) {
780-
sock->recv_cb(sock->context, pkt, 0, sock->recv_user_data);
780+
sock->recv_cb(sock->context, pkt, NULL, NULL,
781+
0, sock->recv_user_data);
781782
} else {
782783
net_pkt_unref(pkt);
783784
}

drivers/wifi/eswifi/eswifi_offload.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ static void eswifi_off_read_work(struct k_work *work)
9696
LOG_WRN("Incomplete buffer copy");
9797
}
9898

99-
socket->recv_cb(socket->context, pkt, 0, socket->user_data);
99+
socket->recv_cb(socket->context, pkt,
100+
NULL, NULL, 0, socket->user_data);
100101
k_sem_give(&socket->read_sem);
101102
k_yield();
102103

drivers/wifi/winc1500/wifi_winc1500.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ static bool handle_socket_msg_recv(SOCKET sock,
776776
if (sd->recv_cb) {
777777
sd->recv_cb(sd->context,
778778
sd->rx_pkt,
779+
NULL, NULL,
779780
0,
780781
sd->recv_user_data);
781782
}

include/net/net_context.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@ struct net_context;
7676
* @param pkt Network buffer that is received. If the pkt is not NULL,
7777
* then the callback will own the buffer and it needs to to unref the pkt
7878
* as soon as it has finished working with it. On EOF, pkt will be NULL.
79+
* @param ip_hdr a pointer to relevant IP (v4 or v6) header.
80+
* @param proto_hdr a pointer to relevant protocol (udp or tcp) header.
7981
* @param status Value is set to 0 if some data or the connection is
8082
* at EOF, <0 if there was an error receiving data, in this case the
8183
* pkt parameter is set to NULL.
8284
* @param user_data The user data given in net_recv() call.
8385
*/
8486
typedef void (*net_context_recv_cb_t)(struct net_context *context,
8587
struct net_pkt *pkt,
88+
union net_ip_header *ip_hdr,
89+
union net_proto_header *proto_hdr,
8690
int status,
8791
void *user_data);
8892

samples/bluetooth/ipsp/src/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ static inline void set_dst_addr(sa_family_t family,
225225

226226
static void udp_received(struct net_context *context,
227227
struct net_pkt *pkt,
228+
union net_ip_header *ip_hdr,
229+
union net_proto_header *proto_hdr,
228230
int status,
229231
void *user_data)
230232
{
@@ -268,6 +270,8 @@ static void setup_udp_recv(struct net_context *udp_recv6)
268270

269271
static void tcp_received(struct net_context *context,
270272
struct net_pkt *pkt,
273+
union net_ip_header *ip_hdr,
274+
union net_proto_header *proto_hdr,
271275
int status,
272276
void *user_data)
273277
{

samples/net/coap_client/src/coap-client.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ static int dump_payload(const struct coap_packet *response)
6262

6363
static void udp_receive(struct net_context *context,
6464
struct net_pkt *pkt,
65+
union net_ip_header *ip_hdr,
66+
union net_proto_header *proto_hdr,
6567
int status,
6668
void *user_data)
6769
{

samples/net/coap_server/src/coap-server.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,8 @@ static struct coap_resource *find_resouce_by_observer(
12291229

12301230
static void udp_receive(struct net_context *context,
12311231
struct net_pkt *pkt,
1232+
union net_ip_header *ip_hdr,
1233+
union net_proto_header *proto_hdr,
12321234
int status,
12331235
void *user_data)
12341236
{

samples/net/leds_demo/src/leds-demo.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ static struct coap_resource resources[] = {
458458

459459
static void udp_receive(struct net_context *context,
460460
struct net_pkt *pkt,
461+
union net_ip_header *ip_hdr,
462+
union net_proto_header *proto_hdr,
461463
int status,
462464
void *user_data)
463465
{

samples/net/nats/src/nats.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,11 @@ int nats_publish(const struct nats *nats,
536536
});
537537
}
538538

539-
static void receive_cb(struct net_context *ctx, struct net_pkt *pkt, int status,
539+
static void receive_cb(struct net_context *ctx,
540+
struct net_pkt *pkt,
541+
union net_ip_header *ip_hdr,
542+
union net_proto_header *proto_hdr,
543+
int status,
540544
void *user_data)
541545
{
542546
struct nats *nats = user_data;

0 commit comments

Comments
 (0)