mtp: Rename link_data to mtp_link and move out the transport specific things

Rename link_data to mtp_link and move it into the mtp_data header
file, also remove the union to ease creating more of the subtypes.

This is done in preparation to the linkset knowing more about the
link (e.g. having a link test per link instead of per link).
diff --git a/src/link_udp.c b/src/link_udp.c
index e05bd17..09b680f 100644
--- a/src/link_udp.c
+++ b/src/link_udp.c
@@ -37,18 +37,18 @@
 
 static int udp_write_cb(struct bsc_fd *fd, struct msgb *msg)
 {
-	struct link_data *link;
+	struct mtp_udp_link *link;
 	int rc;
 
-	link = (struct link_data *) fd->data;
+	link = fd->data;
 
 	LOGP(DINP, LOGL_DEBUG, "Sending MSU: %s\n", hexdump(msg->data, msg->len));
-	if (link->pcap_fd >= 0)
-		mtp_pcap_write_msu(link->pcap_fd, msg->l2h, msgb_l2len(msg));
+	if (link->base.pcap_fd >= 0)
+		mtp_pcap_write_msu(link->base.pcap_fd, msg->l2h, msgb_l2len(msg));
 
 	/* the assumption is we have connected the socket to the remote */
 	rc = sendto(fd->fd, msg->data, msg->len, 0,
-		     (struct sockaddr *) &link->udp.remote, sizeof(link->udp.remote));
+		     (struct sockaddr *) &link->remote, sizeof(link->remote));
 	if (rc != msg->len) {
 		LOGP(DINP, LOGL_ERROR, "Failed to write msg to socket: %d\n", rc);
 		return -1;
@@ -59,7 +59,7 @@
 
 static int udp_read_cb(struct bsc_fd *fd)
 {
-	struct link_data *link;
+	struct mtp_link *link;
 	struct udp_data_hdr *hdr;
 	struct msgb *msg;
 	int rc;
@@ -72,7 +72,7 @@
 	}
 	    
 
-	link = (struct link_data *) fd->data;
+	link = (struct mtp_link *) fd->data;
 	rc = read(fd->fd, msg->data, 2096);
 	if (rc < sizeof(*hdr)) {
 		LOGP(DINP, LOGL_ERROR, "Failed to read at least size of the header: %d\n", rc);
@@ -120,7 +120,7 @@
 	return rc;
 }
 
-static int udp_link_dummy(struct link_data *link)
+static int udp_link_dummy(struct mtp_link *link)
 {
 	/* nothing todo */
 	return 0;
@@ -128,38 +128,46 @@
 
 static void do_start(void *_data)
 {
-	struct link_data *link = (struct link_data *) _data;
+	struct mtp_udp_link *link = (struct mtp_udp_link *) _data;
 
-	snmp_mtp_activate(link->udp.session, link->udp.link_index);
-	mtp_link_up(link);
+	snmp_mtp_activate(link->session, link->link_index);
+	mtp_link_up(&link->base);
 }
 
-static int udp_link_reset(struct link_data *link)
+static int udp_link_reset(struct mtp_link *link)
 {
+	struct mtp_udp_link *ulnk;
+
+	ulnk = (struct mtp_udp_link *) link;
+
 	LOGP(DINP, LOGL_NOTICE, "Will restart SLTM transmission in %d seconds.\n",
-	     link->udp.reset_timeout);
-	snmp_mtp_deactivate(link->udp.session, link->udp.link_index);
+	     ulnk->reset_timeout);
+
+	snmp_mtp_deactivate(ulnk->session, ulnk->link_index);
 	mtp_link_down(link);
 
 	/* restart the link in 90 seconds... to force a timeout on the BSC */
 	link->link_activate.cb = do_start;
 	link->link_activate.data = link;
-	bsc_schedule_timer(&link->link_activate, link->udp.reset_timeout, 0);
+	bsc_schedule_timer(&link->link_activate, ulnk->reset_timeout, 0);
 	return 0;
 }
 
-static int udp_link_write(struct link_data *link, struct msgb *msg)
+static int udp_link_write(struct mtp_link *link, struct msgb *msg)
 {
+	struct mtp_udp_link *ulnk;
 	struct udp_data_hdr *hdr;
 
+	ulnk = (struct mtp_udp_link *) link;
+
 	hdr = (struct udp_data_hdr *) msgb_push(msg, sizeof(*hdr));
 	hdr->format_type = UDP_FORMAT_SIMPLE_UDP;
 	hdr->data_type = UDP_DATA_MSU_PRIO_0;
-	hdr->data_link_index = htons(link->udp.link_index);
+	hdr->data_link_index = htons(ulnk->link_index);
 	hdr->user_context = 0;
 	hdr->data_length = htonl(msgb_l2len(msg));
 
-	if (write_queue_enqueue(&link->udp.write_queue, msg) != 0) {
+	if (write_queue_enqueue(&ulnk->write_queue, msg) != 0) {
 		LOGP(DINP, LOGL_ERROR, "Failed to enqueue msg.\n");
 		msgb_free(msg);
 		return -1;
@@ -168,36 +176,36 @@
 	return 0;
 }
 
-static int udp_link_start(struct link_data *link)
+static int udp_link_start(struct mtp_link *link)
 {
 	LOGP(DINP, LOGL_NOTICE, "UDP input is ready.\n");
 	do_start(link);
 	return 0;
 }
 
-int link_udp_init(struct link_data *link, int src_port, const char *remote, int remote_port)
+int link_udp_init(struct mtp_udp_link *link, int src_port, const char *remote, int remote_port)
 {
 	struct sockaddr_in addr;
 	int fd;
 	int on;
 
-	write_queue_init(&link->udp.write_queue, 100);
+	write_queue_init(&link->write_queue, 100);
 
 	/* function table */
-	link->shutdown = udp_link_dummy;
-	link->clear_queue = udp_link_dummy;
+	link->base.shutdown = udp_link_dummy;
+	link->base.clear_queue = udp_link_dummy;
 
-	link->reset = udp_link_reset;
-	link->start = udp_link_start;
-	link->write = udp_link_write;
+	link->base.reset = udp_link_reset;
+	link->base.start = udp_link_start;
+	link->base.write = udp_link_write;
 
 	/* socket creation */
-	link->udp.write_queue.bfd.data = link;
-	link->udp.write_queue.bfd.when = BSC_FD_READ;
-	link->udp.write_queue.read_cb = udp_read_cb;
-	link->udp.write_queue.write_cb = udp_write_cb;
+	link->write_queue.bfd.data = link;
+	link->write_queue.bfd.when = BSC_FD_READ;
+	link->write_queue.read_cb = udp_read_cb;
+	link->write_queue.write_cb = udp_write_cb;
 
-	link->udp.write_queue.bfd.fd = fd = socket(AF_INET, SOCK_DGRAM, 0);
+	link->write_queue.bfd.fd = fd = socket(AF_INET, SOCK_DGRAM, 0);
 	if (fd < 0) {
 		LOGP(DINP, LOGL_ERROR, "Failed to create UDP socket.\n");
 		return -1;
@@ -218,12 +226,12 @@
 	}
 
 	/* now connect the socket to the remote */
-	memset(&link->udp.remote, 0, sizeof(link->udp.remote));
-	link->udp.remote.sin_family = AF_INET;
-	link->udp.remote.sin_port = htons(remote_port);
-	inet_aton(remote, &link->udp.remote.sin_addr);
+	memset(&link->remote, 0, sizeof(link->remote));
+	link->remote.sin_family = AF_INET;
+	link->remote.sin_port = htons(remote_port);
+	inet_aton(remote, &link->remote.sin_addr);
 
-	if (bsc_register_fd(&link->udp.write_queue.bfd) != 0) {
+	if (bsc_register_fd(&link->write_queue.bfd) != 0) {
 		LOGP(DINP, LOGL_ERROR, "Failed to register BFD.\n");
 		close(fd);
 		return -1;
diff --git a/src/links.c b/src/links.c
index 023a7f4..1134e59 100644
--- a/src/links.c
+++ b/src/links.c
@@ -31,7 +31,7 @@
 
 int is_one_up(struct mtp_link_set *set)
 {
-	struct link_data *entry;
+	struct mtp_link *entry;
 
 	llist_for_each_entry(entry, &set->links, entry)
 		if (entry->available)
@@ -39,7 +39,7 @@
 	return 0;
 }
 
-void mtp_link_down(struct link_data *link)
+void mtp_link_down(struct mtp_link *link)
 {
 	int one_up;
 	int was_up;
@@ -55,7 +55,7 @@
 	mtp_link_set_init_slc(link->the_link);
 }
 
-void mtp_link_up(struct link_data *link)
+void mtp_link_up(struct mtp_link *link)
 {
 	int one_up;
 
@@ -71,12 +71,12 @@
 {
 }
 
-void mtp_link_set_submit(struct link_data *link, struct msgb *msg)
+void mtp_link_set_submit(struct mtp_link *link, struct msgb *msg)
 {
 	link->write(link, msg);
 }
 
-void mtp_link_restart(struct link_data *link)
+void mtp_link_restart(struct mtp_link *link)
 {
 	LOGP(DINP, LOGL_ERROR, "Need to restart the SS7 link.\n");
 	link->reset(link);
@@ -84,7 +84,7 @@
 
 static void start_rest(void *start)
 {
-	struct link_data *data;
+	struct mtp_link *data;
 	bsc.setup = 1;
 
 	if (msc_init(&bsc, 1) != 0) {
@@ -98,7 +98,7 @@
 
 int link_init(struct bsc_data *bsc)
 {
-	struct link_data *lnk;
+	struct mtp_udp_link *lnk;
 
 	bsc->link_set = mtp_link_set_alloc();
 	bsc->link_set->dpc = bsc->dpc;
@@ -109,13 +109,13 @@
 	bsc->link_set->spare = bsc->ni_spare;
 	bsc->link_set->bsc = bsc;
 
-	lnk = talloc_zero(bsc->link_set, struct link_data);
+	lnk = talloc_zero(bsc->link_set, struct mtp_udp_link);
+	lnk->base.pcap_fd = bsc->pcap_fd;
+	lnk->base.the_link = bsc->link_set;
 	lnk->bsc = bsc;
-	lnk->udp.link_index = 1;
-	lnk->pcap_fd = bsc->pcap_fd;
-	lnk->udp.reset_timeout = bsc->udp_reset_timeout;
-	lnk->the_link = bsc->link_set;
-	mtp_link_set_add_link(bsc->link_set, lnk);
+	lnk->link_index = 1;
+	lnk->reset_timeout = bsc->udp_reset_timeout;
+	mtp_link_set_add_link(bsc->link_set, (struct mtp_link *) lnk);
 
 	if (!bsc->src_port) {
 		LOGP(DINP, LOGL_ERROR, "You need to set a UDP address.\n");
@@ -125,8 +125,8 @@
 	LOGP(DINP, LOGL_NOTICE, "Using UDP MTP mode.\n");
 
 	/* setup SNMP first, it is blocking */
-	lnk->udp.session = snmp_mtp_session_create(bsc->udp_ip);
-	if (!lnk->udp.session)
+	lnk->session = snmp_mtp_session_create(bsc->udp_ip);
+	if (!lnk->session)
 		return -1;
 
 	/* now connect to the transport */
@@ -139,11 +139,11 @@
 	 * SLTM and it begins a reset. Then we will take it up
 	 * again and do the usual business.
 	 */
-	snmp_mtp_deactivate(lnk->udp.session,
-			    lnk->udp.link_index);
+	snmp_mtp_deactivate(lnk->session,
+			    lnk->link_index);
 	bsc->start_timer.cb = start_rest;
 	bsc->start_timer.data = &bsc;
-	bsc_schedule_timer(&bsc->start_timer, lnk->udp.reset_timeout, 0);
+	bsc_schedule_timer(&bsc->start_timer, lnk->reset_timeout, 0);
 	LOGP(DMSC, LOGL_NOTICE, "Making sure SLTM will timeout.\n");
 
 	return 0;
@@ -151,7 +151,7 @@
 
 int link_shutdown_all(struct mtp_link_set *set)
 {
-	struct link_data *lnk;
+	struct mtp_link *lnk;
 
 	llist_for_each_entry(lnk, &set->links, entry)
 		lnk->shutdown(lnk);
@@ -160,7 +160,7 @@
 
 int link_reset_all(struct mtp_link_set *set)
 {
-	struct link_data *lnk;
+	struct mtp_link *lnk;
 
 	llist_for_each_entry(lnk, &set->links, entry)
 		lnk->reset(lnk);
@@ -169,7 +169,7 @@
 
 int link_clear_all(struct mtp_link_set *set)
 {
-	struct link_data *lnk;
+	struct mtp_link *lnk;
 
 	llist_for_each_entry(lnk, &set->links, entry)
 		lnk->clear_queue(lnk);
diff --git a/src/mtp_layer3.c b/src/mtp_layer3.c
index 531e121..c3f3878 100644
--- a/src/mtp_layer3.c
+++ b/src/mtp_layer3.c
@@ -551,11 +551,11 @@
 	return 0;
 }
 
-static struct link_data *find_next_link(struct mtp_link_set *set,
-					struct link_data *data)
+static struct mtp_link *find_next_link(struct mtp_link_set *set,
+					struct mtp_link *data)
 {
 	int found = 0;
-	struct link_data *next;
+	struct mtp_link *next;
 
 	if (llist_empty(&set->links))
 		return NULL;
@@ -581,7 +581,7 @@
 
 void mtp_link_set_init_slc(struct mtp_link_set *set)
 {
-	struct link_data *link = NULL;
+	struct mtp_link *link = NULL;
 	int i;
 
 
@@ -591,7 +591,7 @@
 	}
 }
 
-void mtp_link_set_add_link(struct mtp_link_set *set, struct link_data *lnk)
+void mtp_link_set_add_link(struct mtp_link_set *set, struct mtp_link *lnk)
 {
 	llist_add_tail(&lnk->entry, &set->links);
 	mtp_link_set_init_slc(set);