gprs_ns2: add member name to bind

Every bind will have a unique name. Add a name argument
to all bind creating functions and require them to be unique.

This is an API break but there wasn't yet a release with NS2.

Change-Id: I8f1d66b7b3b12da12db8b5e6bd08c1beff085b3e
diff --git a/src/gb/gprs_ns2_fr.c b/src/gb/gprs_ns2_fr.c
index 6b4fa52..5da6fce 100644
--- a/src/gb/gprs_ns2_fr.c
+++ b/src/gb/gprs_ns2_fr.c
@@ -453,19 +453,33 @@
  *  \param[out] result pointer to created bind
  *  \return 0 on success; negative on error */
 int gprs_ns2_fr_bind(struct gprs_ns2_inst *nsi,
+		     const char *name,
 		     const char *netif,
 		     struct osmo_fr_network *fr_network,
 		     enum osmo_fr_role fr_role,
 		     struct gprs_ns2_vc_bind **result)
 {
-	struct gprs_ns2_vc_bind *bind = talloc_zero(nsi, struct gprs_ns2_vc_bind);
+	struct gprs_ns2_vc_bind *bind;
 	struct priv_bind *priv;
 	struct osmo_fr_link *fr_link;
 	int rc = 0;
 
+	if (!name)
+		return -EINVAL;
+
+	if (gprs_ns2_bind_by_name(nsi, name))
+		return -EALREADY;
+
+	bind = talloc_zero(nsi, struct gprs_ns2_vc_bind);
 	if (!bind)
 		return -ENOSPC;
 
+	bind->name = talloc_strdup(bind, name);
+	if (!bind->name) {
+		rc = -ENOSPC;
+		goto err_bind;
+	}
+
 	bind->driver = &vc_driver_fr;
 	bind->ll = GPRS_NS2_LL_FR;
 	bind->send_vc = fr_vc_sendmsg;
@@ -475,7 +489,7 @@
 	priv = bind->priv = talloc_zero(bind, struct priv_bind);
 	if (!priv) {
 		rc = -ENOSPC;
-		goto err_bind;
+		goto err_name;
 	}
 
 	priv->fd.cb = fr_fd_cb;
@@ -536,6 +550,8 @@
 	osmo_fr_link_free(fr_link);
 err_priv:
 	talloc_free(priv);
+err_name:
+	talloc_free((char *)bind->name);
 err_bind:
 	talloc_free(bind);