Change in osmo-pcap[master]: Use new stat item/ctr getter APIs

laforge gerrit-no-reply at lists.osmocom.org
Fri Jun 4 19:38:57 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-pcap/+/24556 )

Change subject: Use new stat item/ctr getter APIs
......................................................................

Use new stat item/ctr getter APIs

Generated with spatch:
"""
@@
expression E1, E2;
@@
- &E2->ctr[E1]
+ rate_ctr_group_get_ctr(E2, E1)
"""

Change-Id: Ic860db04489e9ee7312edb008497186116f30bfc
---
M src/osmo_client_core.c
M src/osmo_client_network.c
M src/osmo_server_network.c
3 files changed, 21 insertions(+), 21 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/src/osmo_client_core.c b/src/osmo_client_core.c
index 025e3a4..59a6777 100644
--- a/src/osmo_client_core.c
+++ b/src/osmo_client_core.c
@@ -161,7 +161,7 @@
 
 	data = pcap_next(client->handle, &hdr);
 	if (!data) {
-		rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_PERR]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(client->ctrg, CLIENT_CTR_PERR));
 		return -1;
 	}
 
@@ -190,14 +190,14 @@
 	 * Only issue is we don't know sizeof(u_int)
 	 */
 	if (*old_val > new_val) {
-		rate_ctr_add(&client->ctrg->ctr[ctr], P_CAP_UINT_MAX() - *old_val);
-		rate_ctr_add(&client->ctrg->ctr[ctr], new_val);
+		rate_ctr_add(rate_ctr_group_get_ctr(client->ctrg, ctr), P_CAP_UINT_MAX() - *old_val);
+		rate_ctr_add(rate_ctr_group_get_ctr(client->ctrg, ctr), new_val);
 		*old_val = new_val;
 		return;
 	}
 
 	/* Just increment it */
-	rate_ctr_add(&client->ctrg->ctr[ctr], new_val - *old_val);
+	rate_ctr_add(rate_ctr_group_get_ctr(client->ctrg, ctr), new_val - *old_val);
 	*old_val = new_val;
 }
 
@@ -215,7 +215,7 @@
 	if (rc != 0) {
 		LOGP(DCLIENT, LOGL_ERROR, "Failed to query pcap stats: %s\n",
 			pcap_geterr(client->handle));
-		rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_PERR]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(client->ctrg, CLIENT_CTR_PERR));
 		return;
 	}
 
diff --git a/src/osmo_client_network.c b/src/osmo_client_network.c
index e5616af..a36a285 100644
--- a/src/osmo_client_network.c
+++ b/src/osmo_client_network.c
@@ -60,7 +60,7 @@
 {
 	if (osmo_wqueue_enqueue_quiet(&conn->wqueue, msg) != 0) {
 		LOGP(DCLIENT, LOGL_ERROR, "Failed to enqueue conn=%s\n", conn->name);
-		rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_QERR]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(conn->client->ctrg, CLIENT_CTR_QERR));
 		msgb_free(msg);
 		return;
 	}
@@ -92,7 +92,7 @@
 		struct osmo_pcap_client_conn *conn = fd->data;
 		LOGP(DCLIENT, LOGL_ERROR, "Lost connection on write to %s %s:%d.\n",
 			conn->name, conn->srv_ip, conn->srv_port);
-		rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_WERR]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(conn->client->ctrg, CLIENT_CTR_WERR));
 		lost_connection(conn);
 		return -1;
 	}
@@ -173,13 +173,13 @@
 		LOGP(DCLIENT, LOGL_ERROR,
 			"Recording truncated packet, len %zu > snaplen %zu\n",
 			(size_t) in_hdr->len, (size_t) in_hdr->caplen);
-		rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_2BIG]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(conn->client->ctrg, CLIENT_CTR_2BIG));
 	}
 
 	msg = msgb_alloc(in_hdr->caplen + sizeof(*om_hdr) + sizeof(*hdr), "data-data");
 	if (!msg) {
 		LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate.\n");
-		rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_NOMEM]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(conn->client->ctrg, CLIENT_CTR_NOMEM));
 		return;
 	}
 
@@ -199,8 +199,8 @@
 		memcpy(msg->l3h, data, in_hdr->caplen);
 
 		om_hdr->len = htons(msgb_l2len(msg));
-		rate_ctr_add(&conn->client->ctrg->ctr[CLIENT_CTR_BYTES], hdr->caplen);
-		rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_PKTS]);
+		rate_ctr_add(rate_ctr_group_get_ctr(conn->client->ctrg, CLIENT_CTR_BYTES), hdr->caplen);
+		rate_ctr_inc(rate_ctr_group_get_ctr(conn->client->ctrg, CLIENT_CTR_PKTS));
 		break;
 	case PROTOCOL_IPIP:
 		offset = get_iphdr_offset(pcap_datalink(conn->client->handle));
@@ -305,7 +305,7 @@
 	osmo_fd_setup(&conn->wqueue.bfd, rc, when, conn_cb, conn, 0);
 	osmo_fd_register(&conn->wqueue.bfd);
 
-	rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_CONNECT]);
+	rate_ctr_inc(rate_ctr_group_get_ctr(conn->client->ctrg, CLIENT_CTR_CONNECT));
 }
 
 void osmo_client_reconnect(struct osmo_pcap_client_conn *conn)
diff --git a/src/osmo_server_network.c b/src/osmo_server_network.c
index 164b161..47ede72 100644
--- a/src/osmo_server_network.c
+++ b/src/osmo_server_network.c
@@ -120,8 +120,8 @@
 
 	if (conn->curr_filename) {
 		client_event(conn, "closingtracefile", conn->curr_filename);
-		rate_ctr_inc(&conn->ctrg->ctr[PEER_CTR_PROTATE]);
-		rate_ctr_inc(&conn->server->ctrg->ctr[SERVER_CTR_PROTATE]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(conn->ctrg, PEER_CTR_PROTATE));
+		rate_ctr_inc(rate_ctr_group_get_ctr(conn->server->ctrg, SERVER_CTR_PROTATE));
 		talloc_free(conn->curr_filename);
 		conn->curr_filename = NULL;
 	}
@@ -422,12 +422,12 @@
 		conn->pend = sizeof(*conn->data);
 
 		/* count the full packet we got */
-		rate_ctr_inc(&conn->ctrg->ctr[PEER_CTR_PKTS]);
-		rate_ctr_inc(&conn->server->ctrg->ctr[SERVER_CTR_PKTS]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(conn->ctrg, PEER_CTR_PKTS));
+		rate_ctr_inc(rate_ctr_group_get_ctr(conn->server->ctrg, SERVER_CTR_PKTS));
 
 		/* count the bytes of it */
-		rate_ctr_add(&conn->ctrg->ctr[PEER_CTR_BYTES], conn->data->len);
-		rate_ctr_add(&conn->server->ctrg->ctr[SERVER_CTR_BYTES], conn->data->len);
+		rate_ctr_add(rate_ctr_group_get_ctr(conn->ctrg, PEER_CTR_BYTES), conn->data->len);
+		rate_ctr_add(rate_ctr_group_get_ctr(conn->server->ctrg, SERVER_CTR_BYTES), conn->data->len);
 
 		switch (conn->data->type) {
 		case PKT_LINK_HDR:
@@ -520,7 +520,7 @@
 		return;
 	}
 
-	rate_ctr_inc(&client->ctrg->ctr[PEER_CTR_CONNECT]);
+	rate_ctr_inc(rate_ctr_group_get_ctr(client->ctrg, PEER_CTR_CONNECT));
 
 	client->state = STATE_INITIAL;
 	client->pend = sizeof(*client->data);
@@ -565,7 +565,7 @@
 	server = fd->data;
 
 	/* count any accept to see no clients */
-	rate_ctr_inc(&server->ctrg->ctr[SERVER_CTR_CONNECT]);
+	rate_ctr_inc(rate_ctr_group_get_ctr(server->ctrg, SERVER_CTR_CONNECT));
 
 	llist_for_each_entry(conn, &server->conn, entry) {
 		if (conn->remote_addr.s_addr == addr.sin_addr.s_addr) {
@@ -577,7 +577,7 @@
 		}
 	}
 
-	rate_ctr_inc(&server->ctrg->ctr[SERVER_CTR_NOCLIENT]);
+	rate_ctr_inc(rate_ctr_group_get_ctr(server->ctrg, SERVER_CTR_NOCLIENT));
 
 	/*
 	 * TODO: In the future start with a tls handshake and see if we know

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-pcap/+/24556
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-pcap
Gerrit-Branch: master
Gerrit-Change-Id: Ic860db04489e9ee7312edb008497186116f30bfc
Gerrit-Change-Number: 24556
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210604/5ea477fd/attachment.htm>


More information about the gerrit-log mailing list