Skip to content

Commit 06e2b42

Browse files
author
Tomasz Bursztyka
committed
net: statistics: Make statistics calculation fully private
Let's change from macros to inlined function to make things nicer. Change-Id: Ie98e0667613961b03c84ca60bc551d0f473765f6 Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent a533eb9 commit 06e2b42

File tree

12 files changed

+345
-128
lines changed

12 files changed

+345
-128
lines changed

include/net/net_context.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -631,27 +631,6 @@ int net_context_recv(struct net_context *context,
631631
int32_t timeout,
632632
void *user_data);
633633

634-
/**
635-
* @brief Internal function that is called when network packet is sent
636-
* successfully.
637-
*
638-
* @param context The network context to use.
639-
* @param token User supplied token tied to the net_buf that was sent.
640-
* @param err_code Error code
641-
*/
642-
static inline void net_context_send_cb(struct net_context *context,
643-
void *token,
644-
int err_code)
645-
{
646-
if (context->send_cb) {
647-
context->send_cb(context, err_code, token, context->user_data);
648-
}
649-
650-
if (net_context_get_ip_proto(context) == IPPROTO_UDP) {
651-
NET_STATS_UDP(++net_stats.udp.sent);
652-
}
653-
}
654-
655634
typedef void (*net_context_cb_t)(struct net_context *context, void *user_data);
656635

657636
/**

include/net/net_stats.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@
3030
extern "C" {
3131
#endif
3232

33-
#if defined(CONFIG_NET_STATISTICS)
34-
#define NET_STATS(s) s
35-
extern struct net_stats net_stats;
36-
#else
37-
#define NET_STATS(s)
38-
#endif
39-
4033
typedef uint32_t net_stats_t;
4134

4235
struct net_stats_ip {
@@ -202,39 +195,24 @@ struct net_stats {
202195

203196
#if defined(CONFIG_NET_IPV6)
204197
struct net_stats_ip ipv6;
205-
#define NET_STATS_IPV6(s) NET_STATS(s)
206-
#else
207-
#define NET_STATS_IPV6(s)
208198
#endif
209199

210200
#if defined(CONFIG_NET_IPV4)
211201
struct net_stats_ip ipv4;
212-
#define NET_STATS_IPV4(s) NET_STATS(s)
213-
#else
214-
#define NET_STATS_IPV4(s)
215202
#endif
216203

217204
struct net_stats_icmp icmp;
218205

219206
#if defined(CONFIG_NET_TCP)
220207
struct net_stats_tcp tcp;
221-
#define NET_STATS_TCP(s) NET_STATS(s)
222-
#else
223-
#define NET_STATS_TCP(s)
224208
#endif
225209

226210
#if defined (CONFIG_NET_UDP)
227211
struct net_stats_udp udp;
228-
#define NET_STATS_UDP(s) NET_STATS(s)
229-
#else
230-
#define NET_STATS_UDP(s)
231212
#endif
232213

233214
#if defined(CONFIG_NET_IPV6_ND)
234215
struct net_stats_ipv6_nd ipv6_nd;
235-
#define NET_STATS_IPV6_ND(s) NET_STATS(s)
236-
#else
237-
#define NET_STATS_IPV6_ND(s)
238216
#endif
239217

240218
#if defined(CONFIG_NET_RPL_STATS)
@@ -255,11 +233,6 @@ struct net_stats {
255233
struct net_stats_rpl_dao dao;
256234
struct net_stats_rpl_dao_ack dao_ack;
257235
} rpl;
258-
#define NET_STATS_RPL(s) NET_STATS(s)
259-
#define NET_STATS_RPL_DIS(s) NET_STATS(s)
260-
#else
261-
#define NET_STATS_RPL(s)
262-
#define NET_STATS_RPL_DIS(s)
263236
#endif /* CONFIG_NET_RPL_STATS */
264237
};
265238

subsys/net/ip/connection.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828

2929
#include <net/net_core.h>
3030
#include <net/nbuf.h>
31-
#include <net/net_stats.h>
3231

3332
#include "net_private.h"
3433
#include "icmpv6.h"
3534
#include "icmpv4.h"
3635
#include "connection.h"
36+
#include "net_stats.h"
3737

3838
/** Is this connection used or not */
3939
#define NET_CONN_IN_USE BIT(0)
@@ -754,7 +754,7 @@ enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_buf *buf)
754754
}
755755

756756
if (proto == IPPROTO_UDP) {
757-
NET_STATS_UDP(++net_stats.udp.recv);
757+
net_stats_update_udp_recv();
758758
}
759759

760760
return NET_OK;
@@ -785,7 +785,7 @@ enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_buf *buf)
785785

786786
drop:
787787
if (proto == IPPROTO_UDP) {
788-
NET_STATS_UDP(++net_stats.udp.drop);
788+
net_stats_update_udp_drop();
789789
}
790790

791791
return NET_DROP;

subsys/net/ip/icmpv4.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
#include <net/net_core.h>
2929
#include <net/nbuf.h>
3030
#include <net/net_if.h>
31-
#include <net/net_stats.h>
3231
#include "net_private.h"
3332
#include "icmpv4.h"
33+
#include "net_stats.h"
3434

3535
static inline enum net_verdict handle_echo_request(struct net_buf *buf)
3636
{
@@ -66,11 +66,11 @@ static inline enum net_verdict handle_echo_request(struct net_buf *buf)
6666
#endif /* NET_DEBUG > 0 */
6767

6868
if (net_send_data(buf) < 0) {
69-
NET_STATS(++net_stats.icmp.drop);
69+
net_stats_update_icmp_drop();
7070
return NET_DROP;
7171
}
7272

73-
NET_STATS(++net_stats.icmp.sent);
73+
net_stats_update_icmp_sent();
7474

7575
return NET_OK;
7676
}
@@ -159,12 +159,12 @@ int net_icmpv4_send_echo_request(struct net_if *iface,
159159
sizeof(struct net_icmpv4_echo_req));
160160

161161
if (net_send_data(buf) >= 0) {
162-
NET_STATS(++net_stats.icmp.sent);
162+
net_stats_update_icmp_sent();
163163
return 0;
164164
}
165165

166166
net_nbuf_unref(buf);
167-
NET_STATS(++net_stats.icmp.drop);
167+
net_stats_update_icmp_drop();
168168

169169
return -EIO;
170170
}
@@ -268,13 +268,13 @@ int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code)
268268
#endif /* NET_DEBUG > 0 */
269269

270270
if (net_send_data(buf) >= 0) {
271-
NET_STATS(++net_stats.icmp.sent);
271+
net_stats_update_icmp_sent();
272272
return -EIO;
273273
}
274274

275275
drop:
276276
net_nbuf_unref(buf);
277-
NET_STATS(++net_stats.icmp.drop);
277+
net_stats_update_icmp_drop();
278278

279279
/* Note that we always return < 0 so that the caller knows to
280280
* discard the original buffer.

subsys/net/ip/icmpv6.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
#include <net/net_core.h>
3030
#include <net/nbuf.h>
3131
#include <net/net_if.h>
32-
#include <net/net_stats.h>
3332
#include "net_private.h"
3433
#include "icmpv6.h"
3534
#include "ipv6.h"
35+
#include "net_stats.h"
3636

3737
static sys_slist_t handlers;
3838

@@ -163,14 +163,14 @@ static enum net_verdict handle_echo_request(struct net_buf *orig)
163163
goto drop;
164164
}
165165

166-
NET_STATS(++net_stats.icmp.sent);
166+
net_stats_update_icmp_sent();
167167

168168
return NET_DROP;
169169

170170
drop:
171171
net_nbuf_unref(buf);
172+
net_stats_update_icmp_drop();
172173

173-
NET_STATS(++net_stats.icmp.drop);
174174
return NET_DROP;
175175
}
176176

@@ -279,13 +279,13 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code,
279279
#endif /* NET_DEBUG > 0 */
280280

281281
if (net_send_data(buf) >= 0) {
282-
NET_STATS(++net_stats.icmp.sent);
282+
net_stats_update_icmp_sent();
283283
return -EIO;
284284
}
285285

286286
drop:
287287
net_nbuf_unref(buf);
288-
NET_STATS(++net_stats.icmp.drop);
288+
net_stats_update_icmp_drop();
289289

290290
/* Note that we always return < 0 so that the caller knows to
291291
* discard the original buffer.
@@ -342,12 +342,12 @@ int net_icmpv6_send_echo_request(struct net_if *iface,
342342
#endif /* NET_DEBUG > 0 */
343343

344344
if (net_send_data(buf) >= 0) {
345-
NET_STATS(++net_stats.icmp.sent);
345+
net_stats_update_icmp_sent();
346346
return 0;
347347
}
348348

349349
net_nbuf_unref(buf);
350-
NET_STATS(++net_stats.icmp.drop);
350+
net_stats_update_icmp_drop();
351351

352352
return -EIO;
353353
}
@@ -368,7 +368,7 @@ enum net_verdict net_icmpv6_input(struct net_buf *buf, uint16_t len,
368368
}
369369

370370
if (cb->type == type && (cb->code == code || cb->code == 0)) {
371-
NET_STATS(++net_stats.icmp.recv);
371+
net_stats_update_icmp_recv();
372372
return cb->handler(buf);
373373
}
374374
}

subsys/net/ip/ipv6.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "6lo.h"
4141
#include "route.h"
4242
#include "rpl.h"
43+
#include "net_stats.h"
4344

4445
#if defined(CONFIG_NET_IPV6_ND)
4546

@@ -833,12 +834,14 @@ int net_ipv6_send_na(struct net_if *iface, struct in6_addr *src,
833834
goto drop;
834835
}
835836

836-
NET_STATS_IPV6_ND(++net_stats.ipv6_nd.sent);
837+
net_stats_update_ipv6_nd_sent();
838+
837839
return 0;
838840

839841
drop:
840842
net_nbuf_unref(buf);
841-
NET_STATS_IPV6_ND(++net_stats.ipv6_nd.drop);
843+
net_stats_update_ipv6_nd_drop();
844+
842845
return -EINVAL;
843846
}
844847

@@ -856,7 +859,7 @@ static enum net_verdict handle_ns_input(struct net_buf *buf)
856859
&NET_IPV6_BUF(buf)->dst,
857860
&NET_ICMPV6_NS_BUF(buf)->tgt);
858861

859-
NET_STATS_IPV6_ND(++net_stats.ipv6_nd.recv);
862+
net_stats_update_ipv6_nd_recv();
860863

861864
if ((total_len < (sizeof(struct net_ipv6_hdr) +
862865
sizeof(struct net_icmp_hdr) +
@@ -1011,7 +1014,8 @@ static enum net_verdict handle_ns_input(struct net_buf *buf)
10111014
return NET_DROP;
10121015

10131016
drop:
1014-
NET_STATS_IPV6_ND(++net_stats.ipv6_nd.drop);
1017+
net_stats_update_ipv6_nd_drop();
1018+
10151019
return NET_DROP;
10161020
}
10171021

@@ -1278,7 +1282,7 @@ static enum net_verdict handle_na_input(struct net_buf *buf)
12781282
&NET_IPV6_BUF(buf)->dst,
12791283
&NET_ICMPV6_NS_BUF(buf)->tgt);
12801284

1281-
NET_STATS_IPV6_ND(++net_stats.ipv6_nd.recv);
1285+
net_stats_update_ipv6_nd_recv();
12821286

12831287
if ((total_len < (sizeof(struct net_ipv6_hdr) +
12841288
sizeof(struct net_icmp_hdr) +
@@ -1357,11 +1361,13 @@ static enum net_verdict handle_na_input(struct net_buf *buf)
13571361
goto drop;
13581362
}
13591363

1360-
NET_STATS_IPV6_ND(++net_stats.ipv6_nd.sent);
1364+
net_stats_update_ipv6_nd_sent();
1365+
13611366
return NET_OK;
13621367

13631368
drop:
1364-
NET_STATS_IPV6_ND(++net_stats.ipv6_nd.drop);
1369+
net_stats_update_ipv6_nd_drop();
1370+
13651371
return NET_DROP;
13661372
}
13671373

@@ -1494,13 +1500,14 @@ int net_ipv6_send_ns(struct net_if *iface,
14941500
goto drop;
14951501
}
14961502

1497-
NET_STATS_IPV6_ND(++net_stats.ipv6_nd.sent);
1503+
net_stats_update_ipv6_nd_sent();
14981504

14991505
return 0;
15001506

15011507
drop:
15021508
net_nbuf_unref(buf);
1503-
NET_STATS_IPV6_ND(++net_stats.ipv6_nd.drop);
1509+
net_stats_update_ipv6_nd_drop();
1510+
15041511
return -EINVAL;
15051512
}
15061513

@@ -1566,13 +1573,14 @@ int net_ipv6_send_rs(struct net_if *iface)
15661573
goto drop;
15671574
}
15681575

1569-
NET_STATS_IPV6_ND(++net_stats.ipv6_nd.sent);
1576+
net_stats_update_ipv6_nd_sent();
15701577

15711578
return 0;
15721579

15731580
drop:
15741581
net_nbuf_unref(buf);
1575-
NET_STATS_IPV6_ND(++net_stats.ipv6_nd.drop);
1582+
net_stats_update_ipv6_nd_drop();
1583+
15761584
return -EINVAL;
15771585
}
15781586

@@ -1899,7 +1907,7 @@ static enum net_verdict handle_ra_input(struct net_buf *buf)
18991907
&NET_IPV6_BUF(buf)->src,
19001908
&NET_IPV6_BUF(buf)->dst);
19011909

1902-
NET_STATS_IPV6_ND(++net_stats.ipv6_nd.recv);
1910+
net_stats_update_ipv6_nd_recv();
19031911

19041912
if ((total_len < (sizeof(struct net_ipv6_hdr) +
19051913
sizeof(struct net_icmp_hdr) +
@@ -2074,7 +2082,7 @@ static enum net_verdict handle_ra_input(struct net_buf *buf)
20742082
return NET_OK;
20752083

20762084
drop:
2077-
NET_STATS_IPV6_ND(++net_stats.ipv6_nd.drop);
2085+
net_stats_update_ipv6_nd_drop();
20782086

20792087
return NET_DROP;
20802088
}

0 commit comments

Comments
 (0)