gbproxy: Don't free NSE/BVC0 if SGSN NSE goes down

SGSN NSEs are static and should not be removed. Instead remove all
PtP-BVCs.
BVC0 can't be blocked and will be reset after the NSE becomes available
again. It might be cleaner to remove BVC0 on NS failure and create it
again, but that change is a bit more complicated.

Fixes ttcn3 test after commit f96cac5077 broke them.

Related: OS#4897
Change-Id: Ie0cef38e4423b672f5cba35ae7fc3eb2c4071d5a
diff --git a/src/gb_proxy.c b/src/gb_proxy.c
index c07c36b..c01c5c6 100644
--- a/src/gb_proxy.c
+++ b/src/gb_proxy.c
@@ -1522,6 +1522,7 @@
 	/* TODO: bss nsei available/unavailable  bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_BLOCK, nsvc->nsei, bvc->bvci, 0);
 	 */
 
+	int i;
 	struct gbproxy_bvc *bvc;
 	struct gbproxy_nse *nse;
 
@@ -1552,12 +1553,17 @@
 			break;
 		}
 		if (nse->sgsn_facing) {
+			struct hlist_node *ntmp;
 			/* SGSN */
 			/* TODO: When to block all PtP towards bss? Only if all SGSN are down? */
+			hash_for_each_safe(nse->bvcs, i, ntmp, bvc, list) {
+				if (bvc->bvci == 0)
+					continue;
+				gbproxy_bvc_free(bvc);
+			}
 			rate_ctr_inc(&cfg->ctrg->
 				     ctr[GBPROX_GLOB_CTR_RESTART_RESET_SGSN]);
 		} else {
-			int i;
 			/* BSS became unavailable
 			 * Block matching PtP-BVCs on SGSN-side */
 			hash_for_each(nse->bvcs, i, bvc, list) {
@@ -1576,10 +1582,9 @@
 				}
 			}
 
-
+			/* This frees the BVCs for us as well */
+			gbproxy_nse_free(nse);
 		}
-		/* This frees the BVCs for us as well */
-		gbproxy_nse_free(nse);
 		LOGP(DGPRS, LOGL_NOTICE, "NS-NSE %d became unavailable\n", nsp->nsei);
 		break;
 	default: