aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2015-11-27 00:05:56 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2015-12-03 11:40:18 +0100
commitf977320736fe15ffc3a0e6110bec7823a57c65ee (patch)
tree9b89e3e5b034574be13a5568282723081145e918
parentba9e9f63bce9a868b8b3e15adca616ac4dec9414 (diff)
gtphub: cosmetic: for_each_side,_plane macros.
Simplify looping over sides and planes. I'm tired of typing the same for loops all the time. Sponsored-by: On-Waves ehi
-rw-r--r--openbsc/include/openbsc/gtphub.h4
-rw-r--r--openbsc/src/gprs/gtphub.c38
-rw-r--r--openbsc/src/gprs/gtphub_vty.c6
3 files changed, 24 insertions, 24 deletions
diff --git a/openbsc/include/openbsc/gtphub.h b/openbsc/include/openbsc/gtphub.h
index cc204ef7e..2d9d39000 100644
--- a/openbsc/include/openbsc/gtphub.h
+++ b/openbsc/include/openbsc/gtphub.h
@@ -141,6 +141,10 @@ enum gtphub_side_idx {
GTPH_SIDE_N
};
+#define for_each_side(I) for (I = 0; I < GTPH_SIDE_N; I++)
+#define for_each_plane(I) for (I = 0; I < GTPH_PLANE_N; I++)
+#define for_each_side_and_plane(I,J) for_each_side(I) for_each_plane(J)
+
static inline int other_side_idx(int side_idx)
{
return (side_idx + 1) & 1;
diff --git a/openbsc/src/gprs/gtphub.c b/openbsc/src/gprs/gtphub.c
index db84a00c3..4f81c017f 100644
--- a/openbsc/src/gprs/gtphub.c
+++ b/openbsc/src/gprs/gtphub.c
@@ -1014,13 +1014,11 @@ int gtphub_tunnel_complete(struct gtphub_tunnel *tun)
return 0;
int side_idx;
int plane_idx;
- for (side_idx = 0; side_idx < GTPH_SIDE_N; side_idx++) {
- for (plane_idx = 0; plane_idx < GTPH_PLANE_N; plane_idx++) {
- struct gtphub_tunnel_endpoint *te =
- &tun->endpoint[side_idx][plane_idx];
- if (!(te->peer && te->tei_orig && te->tei_repl))
- return 0;
- }
+ for_each_side_and_plane(side_idx, plane_idx) {
+ struct gtphub_tunnel_endpoint *te =
+ &tun->endpoint[side_idx][plane_idx];
+ if (!(te->peer && te->tei_orig && te->tei_repl))
+ return 0;
}
return 1;
}
@@ -1040,12 +1038,10 @@ static void gtphub_tunnel_del_cb(struct expiring_item *expi)
int side_idx;
int plane_idx;
- for (side_idx = 0; side_idx < GTPH_SIDE_N; side_idx++) {
- for (plane_idx = 0; plane_idx < GTPH_PLANE_N; plane_idx++) {
- /* clear ref count */
- gtphub_tunnel_endpoint_set_peer(
- &tun->endpoint[side_idx][plane_idx], NULL);
- }
+ for_each_side_and_plane(side_idx, plane_idx) {
+ /* clear ref count */
+ gtphub_tunnel_endpoint_set_peer(&tun->endpoint[side_idx][plane_idx],
+ NULL);
}
talloc_free(tun);
@@ -2077,7 +2073,7 @@ void gtphub_gc(struct gtphub *hub, time_t now)
if (expired) {
int i;
- for (i = 0; i < GTPH_PLANE_N; i++) {
+ for_each_plane(i) {
gtphub_gc_bind(&hub->to_sgsns[i]);
gtphub_gc_bind(&hub->to_ggsns[i]);
}
@@ -2110,7 +2106,7 @@ void gtphub_init(struct gtphub *hub)
expiry_init(&hub->expire_slowly, GTPH_EXPIRE_SLOWLY_MINUTES * 60);
int plane_idx;
- for (plane_idx = 0; plane_idx < GTPH_PLANE_N; plane_idx++) {
+ for_each_plane(plane_idx) {
nr_pool_init(&hub->tei_pool[plane_idx], 1, 0xffffffff);
gtphub_bind_init(&hub->to_ggsns[plane_idx]);
@@ -2135,7 +2131,7 @@ void gtphub_free(struct gtphub *hub)
expiry_clear(&hub->expire_slowly);
int plane_idx;
- for (plane_idx = 0; plane_idx < GTPH_PLANE_N; plane_idx++) {
+ for_each_plane(plane_idx) {
gtphub_gc_bind(&hub->to_ggsns[plane_idx]);
gtphub_bind_free(&hub->to_ggsns[plane_idx]);
@@ -2147,7 +2143,7 @@ void gtphub_free(struct gtphub *hub)
void gtphub_stop(struct gtphub *hub)
{
int plane_idx;
- for (plane_idx = 0; plane_idx < GTPH_PLANE_N; plane_idx++) {
+ for_each_plane(plane_idx) {
gtphub_bind_stop(&hub->to_ggsns[plane_idx]);
gtphub_bind_stop(&hub->to_sgsns[plane_idx]);
}
@@ -2193,7 +2189,7 @@ int gtphub_start(struct gtphub *hub, struct gtphub_cfg *cfg,
/* TODO set hub->restart_counter from external file. */
int plane_idx;
- for (plane_idx = 0; plane_idx < GTPH_PLANE_N; plane_idx++) {
+ for_each_plane(plane_idx) {
rc = gtphub_bind_start(&hub->to_ggsns[plane_idx],
&cfg->to_ggsns[plane_idx],
from_ggsns_read_cb, hub, plane_idx);
@@ -2213,7 +2209,7 @@ int gtphub_start(struct gtphub *hub, struct gtphub_cfg *cfg,
}
}
- for (plane_idx = 0; plane_idx < GTPH_PLANE_N; plane_idx++) {
+ for_each_plane(plane_idx) {
if (gtphub_make_proxy(hub,
&hub->sgsn_proxy[plane_idx],
&hub->to_sgsns[plane_idx],
@@ -2235,14 +2231,14 @@ int gtphub_start(struct gtphub *hub, struct gtphub_cfg *cfg,
}
}
- for (plane_idx = 0; plane_idx < GTPH_PLANE_N; plane_idx++) {
+ for_each_plane(plane_idx) {
if (hub->sgsn_proxy[plane_idx])
LOG(LOGL_NOTICE, "Using SGSN %s proxy %s\n",
gtphub_plane_idx_names[plane_idx],
gtphub_port_str(hub->sgsn_proxy[plane_idx]));
}
- for (plane_idx = 0; plane_idx < GTPH_PLANE_N; plane_idx++) {
+ for_each_plane(plane_idx) {
if (hub->ggsn_proxy[plane_idx])
LOG(LOGL_NOTICE, "Using GGSN %s proxy %s\n",
gtphub_plane_idx_names[plane_idx],
diff --git a/openbsc/src/gprs/gtphub_vty.c b/openbsc/src/gprs/gtphub_vty.c
index f99f81803..5e5c1ddf7 100644
--- a/openbsc/src/gprs/gtphub_vty.c
+++ b/openbsc/src/gprs/gtphub_vty.c
@@ -122,7 +122,7 @@ DEFUN(cfg_gtphub_bind_to_sgsns_short, cfg_gtphub_bind_to_sgsns_short_cmd,
)
{
int i;
- for (i = 0; i < GTPH_PLANE_N; i++)
+ for_each_plane(i)
g_cfg->to_sgsns[i].bind.addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
g_cfg->to_sgsns[GTPH_PLANE_CTRL].bind.port = GTPH_DEFAULT_CONTROL_PORT;
g_cfg->to_sgsns[GTPH_PLANE_USER].bind.port = GTPH_DEFAULT_USER_PORT;
@@ -137,7 +137,7 @@ DEFUN(cfg_gtphub_bind_to_ggsns_short, cfg_gtphub_bind_to_ggsns_short_cmd,
)
{
int i;
- for (i = 0; i < GTPH_PLANE_N; i++)
+ for_each_plane(i)
g_cfg->to_ggsns[i].bind.addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
g_cfg->to_ggsns[GTPH_PLANE_CTRL].bind.port = GTPH_DEFAULT_CONTROL_PORT;
g_cfg->to_ggsns[GTPH_PLANE_USER].bind.port = GTPH_DEFAULT_USER_PORT;
@@ -254,7 +254,7 @@ DEFUN(cfg_grx_ggsn, cfg_grx_ggsn_cmd,
static void show_bind_stats_all(struct vty *vty)
{
int plane_idx;
- for (plane_idx = 0; plane_idx < GTPH_PLANE_N; plane_idx++) {
+ for_each_plane(plane_idx) {
vty_out(vty, "- %s Plane:%s",
gtphub_plane_idx_names[plane_idx], VTY_NEWLINE);