[libss7-commits] mattf: branch mattf/bug13495 r252 - /team/mattf/bug13495/

SVN commits to the libss7 project libss7-commits at lists.digium.com
Sat Jan 24 15:59:06 CST 2009


Author: mattf
Date: Sat Jan 24 15:59:06 2009
New Revision: 252

URL: http://svn.digium.com/svn-view/libss7?view=rev&rev=252
Log:
Change API so that we are able to handle IP based links that change file descriptors when they go up and down

Modified:
    team/mattf/bug13495/isup_masq.c
    team/mattf/bug13495/libss7.h
    team/mattf/bug13495/mtp2.c
    team/mattf/bug13495/mtp2.h
    team/mattf/bug13495/mtp3.c
    team/mattf/bug13495/ss7.c
    team/mattf/bug13495/ss7_internal.h

Modified: team/mattf/bug13495/isup_masq.c
URL: http://svn.digium.com/svn-view/libss7/team/mattf/bug13495/isup_masq.c?view=diff&rev=252&r1=251&r2=252
==============================================================================
--- team/mattf/bug13495/isup_masq.c (original)
+++ team/mattf/bug13495/isup_masq.c Sat Jan 24 15:59:06 2009
@@ -253,10 +253,28 @@
 	return res;
 }
 
-int isup_masquerade_add_route(struct ss7 *ss7, int fd, int startcic, int endcic, unsigned int opc)
+int isup_masquerade_set_route_fd(struct ss7 *ss7, int fd, int startcic, int endcic, unsigned int opc)
 {
 	struct isup_masq *masq_table = &ss7->isup_masq_table;
-	int i, j;
+	int i;
+
+	for (i = 0; i < masq_table->numentries; i++) {
+		if ((masq_table->routes[i].startcic == startcic)
+			&& (masq_table->routes[i].endcic == endcic)
+			&& (masq_table->routes[i].opc == opc)) {
+
+			masq_table->routes[i].mtp2->fd = fd;
+			return 0;
+		}
+	}
+
+	return -1;
+}
+
+int isup_masquerade_add_route(struct ss7 *ss7, int startcic, int endcic, unsigned int opc)
+{
+	struct isup_masq *masq_table = &ss7->isup_masq_table;
+	int i;
 
 	if (!ss7)
 		return -1;
@@ -270,15 +288,11 @@
 	masq_table->routes[i].endcic = endcic;
 	masq_table->routes[i].opc = opc;
 
-	ss7_add_slave_link(ss7, SS7_TRANSPORT_TCP, fd, 0, 0);
-
-	for (j = 0; j < ss7->numslavelinks; j++) {
-		if (ss7->slavelinks[j]->fd == fd)
-			break;
-	}
-
-	masq_table->routes[i].mtp2 = ss7->slavelinks[j];
-	
+	masq_table->routes[i].mtp2 = ss7_add_slave_link(ss7, SS7_TRANSPORT_TCP, "slave_link", 0, 0);
+
+	if (!masq_table->routes[i].mtp2)
+		return -1;
+
 	return 0;
 }
 
@@ -308,7 +322,9 @@
 		if ((isup_masq_table->routes[i].opc == rl->opc)
 		&& (cic >= isup_masq_table->routes[i].startcic)
 		&& (cic <= isup_masq_table->routes[i].endcic)) {
-			isup_masquerade_transmit(isup_masq_table->routes[i].mtp2, rl, buf, len);
+			if (isup_masq_table->routes[i].mtp2->fd != -1) {
+				isup_masquerade_transmit(isup_masq_table->routes[i].mtp2, rl, buf, len);
+			}
 			return 1;
 		}
 	}

Modified: team/mattf/bug13495/libss7.h
URL: http://svn.digium.com/svn-view/libss7/team/mattf/bug13495/libss7.h?view=diff&rev=252&r1=251&r2=252
==============================================================================
--- team/mattf/bug13495/libss7.h (original)
+++ team/mattf/bug13495/libss7.h Sat Jan 24 15:59:06 2009
@@ -329,7 +329,7 @@
 
 typedef struct {
 	int e;
-	void *data;
+	int data;
 } ss7_event_generic;
 
 typedef struct {
@@ -422,7 +422,9 @@
 
 struct timeval *ss7_schedule_next(struct ss7 *ss7);
 
-int ss7_add_link(struct ss7 *ss7, int transport, int fd, int slc, unsigned int adjpc);
+int ss7_add_link(struct ss7 *ss7, int transport, char *name, int slc, unsigned int adjpc);
+
+int ss7_set_link_fd(struct ss7 *ss7, char *name, int fd);
 
 int ss7_set_network_ind(struct ss7 *ss7, int ni);
 
@@ -609,6 +611,8 @@
 
 void ss7_pc_to_str(int ss7type, unsigned int pc, char *str);
 
-int isup_masquerade_add_route(struct ss7 *ss7, int fd, int startcic, int endcic, unsigned int opc);
+int isup_masquerade_add_route(struct ss7 *ss7, int startcic, int endcic, unsigned int opc);
+
+int isup_masquerade_set_route_fd(struct ss7 *ss7, int fd, int startcic, int endcic, unsigned int opc);
 
 #endif /* _LIBSS7_H */

Modified: team/mattf/bug13495/mtp2.c
URL: http://svn.digium.com/svn-view/libss7/team/mattf/bug13495/mtp2.c?view=diff&rev=252&r1=251&r2=252
==============================================================================
--- team/mattf/bug13495/mtp2.c (original)
+++ team/mattf/bug13495/mtp2.c Sat Jan 24 15:59:06 2009
@@ -619,7 +619,7 @@
 						return -1;
 					}
 					e->gen.e = MTP2_LINK_UP;
-					e->gen.data = (void *) link;
+					e->gen.data = link->fd;
 					break;
 				default:
 					mtp_error(link->master, "Don't know how to handle state change from %d to %d\n", link->state, newstate);
@@ -635,7 +635,7 @@
 					return -1;
 				}
 				e->gen.e = MTP2_LINK_DOWN;
-				e->gen.data = (void *) link;
+				e->gen.data = link->fd;
 				return to_idle(link);
 			}
 			break;
@@ -776,7 +776,7 @@
 	return 0;
 }
 
-struct mtp2 * mtp2_new(int fd, unsigned int switchtype)
+struct mtp2 * mtp2_new(char *name, unsigned int switchtype)
 {
 	struct mtp2 * new = calloc(1, sizeof(struct mtp2));
 	int x;
@@ -786,7 +786,10 @@
 
 	reset_mtp(new);
 
-	new->fd = fd;
+	strncpy(new->name, name, sizeof(new->name));
+	new->name[sizeof(new->name)] = 0;
+
+	new->fd = -1;
 	new->autotxsutype = LSSU_SIOS;
 	new->lastsurxd = -1;
 	new->lastsutxd = -1;

Modified: team/mattf/bug13495/mtp2.h
URL: http://svn.digium.com/svn-view/libss7/team/mattf/bug13495/mtp2.h?view=diff&rev=252&r1=251&r2=252
==============================================================================
--- team/mattf/bug13495/mtp2.h (original)
+++ team/mattf/bug13495/mtp2.h Sat Jan 24 15:59:06 2009
@@ -109,7 +109,10 @@
 #define TCPSTATE_NEED_LEN 0
 #define TCPSTATE_NEED_MSG 1
 
+#define MTP2_MAX_NAME 128
+
 struct mtp2 {
+	char name[MTP2_MAX_NAME];
 	int state;
 	int std_test_passed;
 	int inhibit;
@@ -177,7 +180,7 @@
 int mtp2_alarm(struct mtp2 *link);
 int mtp2_noalarm(struct mtp2 *link);
 int mtp2_setstate(struct mtp2 *link, int state);
-struct mtp2 * mtp2_new(int fd, unsigned int switchtype);
+struct mtp2 * mtp2_new(char *name, unsigned int switchtype);
 int mtp2_transmit(struct mtp2 *link);
 int mtp2_receive(struct mtp2 *link);
 int mtp2_msu(struct mtp2 *link, struct ss7_msg *m);

Modified: team/mattf/bug13495/mtp3.c
URL: http://svn.digium.com/svn-view/libss7/team/mattf/bug13495/mtp3.c?view=diff&rev=252&r1=251&r2=252
==============================================================================
--- team/mattf/bug13495/mtp3.c (original)
+++ team/mattf/bug13495/mtp3.c Sat Jan 24 15:59:06 2009
@@ -1861,13 +1861,16 @@
 	return link;
 }
 
-static struct mtp2 * mtp2_event_to_mtp2(struct ss7 *ss7, struct mtp2 *mtp2)
+static struct mtp2 * mtp2_event_to_mtp2(struct ss7 *ss7, int fd)
 {
 	struct mtp2 *link = NULL;
-
-	link = mtp2;
-	if (!link) {
-		ss7_error(ss7, "Badness! could not find MTP2 link from MTP2 event\n");
+	int i;
+
+	for (i = 0; i < ss7->numlinks; i++) {
+		if (ss7->links[i]->fd == fd) {
+			link = ss7->links[i];
+			break;
+		}
 	}
 
 	return link;
@@ -1884,13 +1887,13 @@
 	switch (e->e) {
 		case MTP2_LINK_UP:
 			link = mtp2_event_to_mtp2(ss7, e->gen.data);
-			mtp3_event_link_up(link);
-			e->gen.data = (void *)link->fd;
+			if (link)
+				mtp3_event_link_up(link);
 			return e;
 		case MTP2_LINK_DOWN:
 			link = mtp2_event_to_mtp2(ss7, e->gen.data);
-			mtp3_event_link_down(link);
-			e->gen.data = (void *)link->fd;
+			if (link)
+				mtp3_event_link_down(link);
 			return e;
 		default:
 			return e;

Modified: team/mattf/bug13495/ss7.c
URL: http://svn.digium.com/svn-view/libss7/team/mattf/bug13495/ss7.c?view=diff&rev=252&r1=251&r2=252
==============================================================================
--- team/mattf/bug13495/ss7.c (original)
+++ team/mattf/bug13495/ss7.c Sat Jan 24 15:59:06 2009
@@ -200,46 +200,38 @@
 }
 
 /* TODO: Add entry to routing table instead */
-static int ss7_set_adjpc(struct ss7 *ss7, int fd, unsigned int pc)
+static int ss7_set_adjpc(struct mtp2 *mtp2, unsigned int pc)
+{
+	mtp2->dpc = pc;
+	mtp3_add_adj_sp(mtp2);
+	return 0;
+}
+
+int ss7_set_link_fd(struct ss7 *ss7, char *name, int fd)
 {
 	int i;
-	int winner = -1;
 
 	for (i = 0; i < ss7->numlinks; i++) {
-		if (ss7->links[i]->fd == fd)
-			winner = i;
-	}
-	if (winner > -1) {
-		ss7->links[winner]->dpc = pc;
-		mtp3_add_adj_sp(ss7->links[winner]);
-	} else {
-		/* Maybe a slave */
-		for (i = 0; i < ss7->numslavelinks; i++) {
-			if (ss7->slavelinks[i]->fd == fd)
-				winner = i;
-		}
-		if (winner > -1) {
-			ss7->slavelinks[winner]->dpc = pc;
-			mtp3_add_adj_sp(ss7->slavelinks[winner]);
-
-		}
-	}
-		return -1;
+		if (!strcasecmp(ss7->links[i]->name, name)) {
+			ss7->links[i]->fd = fd;
+			break;
+		}
+	}
 
 	return 0;
 }
 
-int ss7_add_slave_link(struct ss7 *ss7, int transport, int fd, int slc, unsigned int adjpc)
+struct mtp2* ss7_add_slave_link(struct ss7 *ss7, int transport, char *name, int slc, unsigned int adjpc)
 {
 	struct mtp2 *m;
 
 	if (ss7->numlinks >= SS7_MAX_LINKS)
-		return -1;
-
-	m = mtp2_new(fd, ss7->switchtype);
+		return NULL;
+
+	m = mtp2_new(name, ss7->switchtype);
 	
 	if (!m)
-		return -1;
+		return NULL;
 
 	m->master = ss7;
 
@@ -260,23 +252,28 @@
 
 		ss7->slavelinks[ss7->numslavelinks - 1] = m;
 
-		ss7_set_adjpc(ss7, fd, adjpc);
+		ss7_set_adjpc(ss7->slavelinks[ss7->numslavelinks-1], adjpc);
+
+		return ss7->slavelinks[ss7->numslavelinks-1];
 
 	} else {
-		return -1;
-	}
-
-	return 0;
-}
-
-int ss7_add_link(struct ss7 *ss7, int transport, int fd, int slc, unsigned int adjpc)
+		return NULL;
+	}
+
+	return NULL;
+}
+
+int ss7_add_link(struct ss7 *ss7, int transport, char *name, int slc, unsigned int adjpc)
 {
 	struct mtp2 *m;
 
 	if (ss7->numlinks >= SS7_MAX_LINKS)
 		return -1;
 
-	m = mtp2_new(fd, ss7->switchtype);
+	if (!name && (name[0] == 0))
+		return -1;
+
+	m = mtp2_new(name, ss7->switchtype);
 	
 	if (!m)
 		return -1;
@@ -301,7 +298,7 @@
 
 		ss7->links[ss7->numlinks - 1] = m;
 
-		ss7_set_adjpc(ss7, fd, adjpc);
+		ss7_set_adjpc(ss7->links[ss7->numlinks-1], adjpc);
 
 		if (transport == SS7_TRANSPORT_TCP) {
 			ss7->links[ss7->numlinks - 1]->adj_sp->state = MTP3_UP;

Modified: team/mattf/bug13495/ss7_internal.h
URL: http://svn.digium.com/svn-view/libss7/team/mattf/bug13495/ss7_internal.h?view=diff&rev=252&r1=251&r2=252
==============================================================================
--- team/mattf/bug13495/ss7_internal.h (original)
+++ team/mattf/bug13495/ss7_internal.h Sat Jan 24 15:59:06 2009
@@ -180,6 +180,6 @@
 
 int isup_ip_receive(struct mtp2 *mtp2);
 
-int ss7_add_slave_link(struct ss7 *ss7, int transport, int fd, int slc, unsigned int adjpc);
+struct mtp2* ss7_add_slave_link(struct ss7 *ss7, int transport, char *name, int slc, unsigned int adjpc);
 
 #endif /* _SS7_H */




More information about the libss7-commits mailing list