gtphub: refactor: use side_idx everywhere.

This is a mostly cosmetic change. Instead of separate buffer handling
functions, reduce some code duplication by using a side_idx just like the
plane_idx, with arrays.

Sponsored-by: On-Waves ehi
diff --git a/openbsc/src/gprs/gtphub_vty.c b/openbsc/src/gprs/gtphub_vty.c
index 5e5c1dd..e79cdd0 100644
--- a/openbsc/src/gprs/gtphub_vty.c
+++ b/openbsc/src/gprs/gtphub_vty.c
@@ -80,17 +80,17 @@
 	vty_out(vty, "gtphub%s", VTY_NEWLINE);
 
 	write_addrs(vty, "bind-to-sgsns",
-		    &g_cfg->to_sgsns[GTPH_PLANE_CTRL].bind,
-		    &g_cfg->to_sgsns[GTPH_PLANE_USER].bind);
+		    &g_cfg->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL].bind,
+		    &g_cfg->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_USER].bind);
 
 	write_addrs(vty, "bind-to-ggsns",
-		    &g_cfg->to_ggsns[GTPH_PLANE_CTRL].bind,
-		    &g_cfg->to_ggsns[GTPH_PLANE_USER].bind);
+		    &g_cfg->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL].bind,
+		    &g_cfg->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_USER].bind);
 
-	if (g_cfg->ggsn_proxy[GTPH_PLANE_CTRL].addr_str) {
+	if (g_cfg->proxy[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL].addr_str) {
 		write_addrs(vty, "ggsn-proxy",
-			    &g_cfg->ggsn_proxy[GTPH_PLANE_CTRL],
-			    &g_cfg->ggsn_proxy[GTPH_PLANE_USER]);
+			    &g_cfg->proxy[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL],
+			    &g_cfg->proxy[GTPH_SIDE_GGSN][GTPH_PLANE_USER]);
 	}
 
 	return CMD_SUCCESS;
@@ -123,9 +123,9 @@
 {
 	int 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;
+		g_cfg->to_gsns[GTPH_SIDE_SGSN][i].bind.addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
+	g_cfg->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL].bind.port = GTPH_DEFAULT_CONTROL_PORT;
+	g_cfg->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_USER].bind.port = GTPH_DEFAULT_USER_PORT;
 	return CMD_SUCCESS;
 }
 
@@ -138,9 +138,9 @@
 {
 	int 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;
+		g_cfg->to_gsns[GTPH_SIDE_GGSN][i].bind.addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
+	g_cfg->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL].bind.port = GTPH_DEFAULT_CONTROL_PORT;
+	g_cfg->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_USER].bind.port = GTPH_DEFAULT_USER_PORT;
 	return CMD_SUCCESS;
 }
 
@@ -161,7 +161,7 @@
 	BIND_DOCS
 	)
 {
-	return handle_binds(g_cfg->to_sgsns, argv);
+	return handle_binds(g_cfg->to_gsns[GTPH_SIDE_SGSN], argv);
 }
 
 DEFUN(cfg_gtphub_bind_to_ggsns, cfg_gtphub_bind_to_ggsns_cmd,
@@ -171,7 +171,7 @@
 	BIND_DOCS
 	)
 {
-	return handle_binds(g_cfg->to_ggsns, argv);
+	return handle_binds(g_cfg->to_gsns[GTPH_SIDE_GGSN], argv);
 }
 
 DEFUN(cfg_gtphub_ggsn_proxy_short, cfg_gtphub_ggsn_proxy_short_cmd,
@@ -181,10 +181,10 @@
 	"Remote IP address (v4 or v6)\n"
 	)
 {
-	g_cfg->ggsn_proxy[GTPH_PLANE_CTRL].addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
-	g_cfg->ggsn_proxy[GTPH_PLANE_CTRL].port = GTPH_DEFAULT_CONTROL_PORT;
-	g_cfg->ggsn_proxy[GTPH_PLANE_USER].addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
-	g_cfg->ggsn_proxy[GTPH_PLANE_USER].port = GTPH_DEFAULT_USER_PORT;
+	g_cfg->proxy[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL].addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
+	g_cfg->proxy[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL].port = GTPH_DEFAULT_CONTROL_PORT;
+	g_cfg->proxy[GTPH_SIDE_GGSN][GTPH_PLANE_USER].addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
+	g_cfg->proxy[GTPH_SIDE_GGSN][GTPH_PLANE_USER].port = GTPH_DEFAULT_USER_PORT;
 	return CMD_SUCCESS;
 }
 
@@ -195,10 +195,10 @@
 	BIND_DOCS
 	)
 {
-	g_cfg->ggsn_proxy[GTPH_PLANE_CTRL].addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
-	g_cfg->ggsn_proxy[GTPH_PLANE_CTRL].port = atoi(argv[1]);
-	g_cfg->ggsn_proxy[GTPH_PLANE_USER].addr_str = talloc_strdup(tall_vty_ctx, argv[2]);
-	g_cfg->ggsn_proxy[GTPH_PLANE_USER].port = atoi(argv[3]);
+	g_cfg->proxy[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL].addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
+	g_cfg->proxy[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL].port = atoi(argv[1]);
+	g_cfg->proxy[GTPH_SIDE_GGSN][GTPH_PLANE_USER].addr_str = talloc_strdup(tall_vty_ctx, argv[2]);
+	g_cfg->proxy[GTPH_SIDE_GGSN][GTPH_PLANE_USER].port = atoi(argv[3]);
 	return CMD_SUCCESS;
 }
 
@@ -209,10 +209,10 @@
 	"Remote IP address (v4 or v6)\n"
 	)
 {
-	g_cfg->sgsn_proxy[GTPH_PLANE_CTRL].addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
-	g_cfg->sgsn_proxy[GTPH_PLANE_CTRL].port = GTPH_DEFAULT_CONTROL_PORT;
-	g_cfg->sgsn_proxy[GTPH_PLANE_USER].addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
-	g_cfg->sgsn_proxy[GTPH_PLANE_USER].port = GTPH_DEFAULT_USER_PORT;
+	g_cfg->proxy[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL].addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
+	g_cfg->proxy[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL].port = GTPH_DEFAULT_CONTROL_PORT;
+	g_cfg->proxy[GTPH_SIDE_SGSN][GTPH_PLANE_USER].addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
+	g_cfg->proxy[GTPH_SIDE_SGSN][GTPH_PLANE_USER].port = GTPH_DEFAULT_USER_PORT;
 	return CMD_SUCCESS;
 }
 
@@ -223,10 +223,10 @@
 	BIND_DOCS
 	)
 {
-	g_cfg->sgsn_proxy[GTPH_PLANE_CTRL].addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
-	g_cfg->sgsn_proxy[GTPH_PLANE_CTRL].port = atoi(argv[1]);
-	g_cfg->sgsn_proxy[GTPH_PLANE_USER].addr_str = talloc_strdup(tall_vty_ctx, argv[2]);
-	g_cfg->sgsn_proxy[GTPH_PLANE_USER].port = atoi(argv[3]);
+	g_cfg->proxy[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL].addr_str = talloc_strdup(tall_vty_ctx, argv[0]);
+	g_cfg->proxy[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL].port = atoi(argv[1]);
+	g_cfg->proxy[GTPH_SIDE_SGSN][GTPH_PLANE_USER].addr_str = talloc_strdup(tall_vty_ctx, argv[2]);
+	g_cfg->proxy[GTPH_SIDE_SGSN][GTPH_PLANE_USER].port = atoi(argv[3]);
 	return CMD_SUCCESS;
 }
 
@@ -258,13 +258,13 @@
 		vty_out(vty, "- %s Plane:%s",
 			gtphub_plane_idx_names[plane_idx], VTY_NEWLINE);
 
-		struct gtphub_bind *b = &g_hub->to_ggsns[plane_idx];
+		struct gtphub_bind *b = &g_hub->to_gsns[GTPH_SIDE_GGSN][plane_idx];
 		vty_out(vty, "  - to/from GGSNs: %s port %d%s",
 			gsn_addr_to_str(&b->local_addr), (int)b->local_port,
 			VTY_NEWLINE);
 		vty_out_rate_ctr_group(vty, "    ", b->counters_io);
 
-		b = &g_hub->to_sgsns[plane_idx];
+		b = &g_hub->to_gsns[GTPH_SIDE_SGSN][plane_idx];
 		vty_out(vty, "  - to/from SGSNs: %s port %d%s",
 			gsn_addr_to_str(&b->local_addr), (int)b->local_port,
 			VTY_NEWLINE);