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

SVN commits to the libss7 project libss7-commits at lists.digium.com
Thu Dec 11 11:31:08 CST 2008


Author: mattf
Date: Thu Dec 11 11:31:07 2008
New Revision: 239

URL: http://svn.digium.com/view/libss7?view=rev&rev=239
Log:
Using this as development branch until we get ANSI support tested.  Starting on ISUP masquerade and clustering support, initial check in of this code.

Modified:
    team/mattf/bug13495/Makefile
    team/mattf/bug13495/isup.c
    team/mattf/bug13495/libss7.h
    team/mattf/bug13495/mtp2.c
    team/mattf/bug13495/mtp2.h
    team/mattf/bug13495/mtp3.c
    team/mattf/bug13495/parser_debug.c
    team/mattf/bug13495/ss7.c
    team/mattf/bug13495/ss7_internal.h

Modified: team/mattf/bug13495/Makefile
URL: http://svn.digium.com/view/libss7/team/mattf/bug13495/Makefile?view=diff&rev=239&r1=238&r2=239
==============================================================================
--- team/mattf/bug13495/Makefile (original)
+++ team/mattf/bug13495/Makefile Thu Dec 11 11:31:07 2008
@@ -7,8 +7,8 @@
 INSTALL_PREFIX=$(DESTDIR)
 INSTALL_BASE=/usr
 libdir?=$(INSTALL_BASE)/lib
-STATIC_OBJS=mtp2.o ss7_sched.o ss7.o mtp3.o isup.o version.o
-DYNAMIC_OBJS=mtp2.o ss7_sched.o ss7.o mtp3.o isup.o version.o
+STATIC_OBJS=mtp2.o ss7_sched.o ss7.o mtp3.o isup.o version.o isup_masq.o
+DYNAMIC_OBJS=mtp2.o ss7_sched.o ss7.o mtp3.o isup.o version.o isup_masq.o
 STATIC_LIBRARY=libss7.a
 DYNAMIC_LIBRARY=libss7.so.1.0
 CFLAGS=-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g -fPIC
@@ -16,7 +16,7 @@
 SOFLAGS=-Wl,-hlibss7.so.1
 LDCONFIG=/sbin/ldconfig
 
-UTILITIES=parser_debug
+#UTILITIES=parser_debug
 
 ifneq ($(wildcard /usr/include/dahdi/user.h),)
 UTILITIES+=ss7test ss7linktest

Modified: team/mattf/bug13495/isup.c
URL: http://svn.digium.com/view/libss7/team/mattf/bug13495/isup.c?view=diff&rev=239&r1=238&r2=239
==============================================================================
--- team/mattf/bug13495/isup.c (original)
+++ team/mattf/bug13495/isup.c Thu Dec 11 11:31:07 2008
@@ -36,6 +36,7 @@
 #include "isup.h"
 #include "ss7_internal.h"
 #include "mtp3.h"
+#include "mtp2.h"
 
 #define FUNC_DUMP(name) int ((name))(struct ss7 *ss7, int messagetype, unsigned char *parm, int len)
 /* Length here is paramter length */
@@ -3123,6 +3124,8 @@
 	return 0;
 }
 
+int isup_needs_masquerade(struct ss7 *ss7, struct routing_label *rl, unsigned int cic, unsigned char *buf, int len);
+
 static int isup_handle_unexpected(struct ss7 *ss7, struct isup_call *c, unsigned int opc)
 {
 	int res;
@@ -3164,6 +3167,9 @@
 	} else {
 		cic = mh->cic[0] | ((mh->cic[1] & 0x3f) << 8);
 	}
+
+	if (isup_needs_masquerade(ss7, rl, cic, buf, len))
+		return 0;
 
 	/* Find us in the message list */
 	for (x = 0; x < sizeof(messages)/sizeof(struct message_data); x++)

Modified: team/mattf/bug13495/libss7.h
URL: http://svn.digium.com/view/libss7/team/mattf/bug13495/libss7.h?view=diff&rev=239&r1=238&r2=239
==============================================================================
--- team/mattf/bug13495/libss7.h (original)
+++ team/mattf/bug13495/libss7.h Thu Dec 11 11:31:07 2008
@@ -329,7 +329,7 @@
 
 typedef struct {
 	int e;
-	unsigned int data;
+	void *data;
 } ss7_event_generic;
 
 typedef struct {
@@ -608,4 +608,7 @@
 int ss7_set_mtp3_timer(struct ss7 *ss7, char *name, int ms);
 
 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);
+
 #endif /* _LIBSS7_H */

Modified: team/mattf/bug13495/mtp2.c
URL: http://svn.digium.com/view/libss7/team/mattf/bug13495/mtp2.c?view=diff&rev=239&r1=238&r2=239
==============================================================================
--- team/mattf/bug13495/mtp2.c (original)
+++ team/mattf/bug13495/mtp2.c Thu Dec 11 11:31:07 2008
@@ -514,7 +514,6 @@
 int mtp2_setstate(struct mtp2 *link, int newstate)
 {
 	ss7_event *e;
-	int i;
 
 	if (link->master->debug & SS7_DEBUG_MTP2)
 		mtp_message(link->master, "Link state change: %s -> %s\n", linkstate2str(link->state), linkstate2str(newstate));
@@ -620,12 +619,7 @@
 						return -1;
 					}
 					e->gen.e = MTP2_LINK_UP;
-					for (i = 0; i < link->master->numlinks; i++) {
-						if (link->master->links[i] == link) {
-							e->gen.data = i;
-							break;
-						}
-					}
+					e->gen.data = (void *) link;
 					break;
 				default:
 					mtp_error(link->master, "Don't know how to handle state change from %d to %d\n", link->state, newstate);
@@ -641,12 +635,7 @@
 					return -1;
 				}
 				e->gen.e = MTP2_LINK_DOWN;
-				for (i = 0; i < link->master->numlinks; i++) {
-					if (link->master->links[i] == link) {
-						e->gen.data = i;
-						break;
-					}
-				}
+				e->gen.data = (void *) link;
 				return to_idle(link);
 			}
 			break;
@@ -911,9 +900,18 @@
 }
 
 /* returns an event */
-int mtp2_receive(struct mtp2 *link, unsigned char *buf, int len)
-{
+int mtp2_receive(struct mtp2 *link)
+{
+	unsigned char buf[1024];
 	struct mtp_su_head *h = (struct mtp_su_head *)buf;
+	int len;
+
+	len = read(link->fd, buf, sizeof(buf));
+
+	if (len <= 0) {
+		return len;
+	}
+
 	len -= 2; /* Strip the CRC off */
 
 	if (len < MTP2_SIZE) {

Modified: team/mattf/bug13495/mtp2.h
URL: http://svn.digium.com/view/libss7/team/mattf/bug13495/mtp2.h?view=diff&rev=239&r1=238&r2=239
==============================================================================
--- team/mattf/bug13495/mtp2.h (original)
+++ team/mattf/bug13495/mtp2.h Thu Dec 11 11:31:07 2008
@@ -162,6 +162,7 @@
 /* Flags for the struct mtp2 flags parameter */
 #define MTP2_FLAG_ZAPMTP2 (1 << 0)
 #define MTP2_FLAG_WRITE (1 << 1)
+#define MTP2_FLAG_TCP (1 << 2)
 
 /* Initialize MTP link */
 int mtp2_start(struct mtp2 *link, int emergency);
@@ -171,7 +172,7 @@
 int mtp2_setstate(struct mtp2 *link, int state);
 struct mtp2 * mtp2_new(int fd, unsigned int switchtype);
 int mtp2_transmit(struct mtp2 *link);
-int mtp2_receive(struct mtp2 *link, unsigned char *buf, int len);
+int mtp2_receive(struct mtp2 *link);
 int mtp2_msu(struct mtp2 *link, struct ss7_msg *m);
 void mtp2_dump(struct mtp2 *link, char prefix, unsigned char *buf, int len);
 char *linkstate2strext(int linkstate);

Modified: team/mattf/bug13495/mtp3.c
URL: http://svn.digium.com/view/libss7/team/mattf/bug13495/mtp3.c?view=diff&rev=239&r1=238&r2=239
==============================================================================
--- team/mattf/bug13495/mtp3.c (original)
+++ team/mattf/bug13495/mtp3.c Thu Dec 11 11:31:07 2008
@@ -1707,6 +1707,10 @@
 
 
 	if (winner) {
+		if (winner->flags & MTP2_FLAG_TCP) {
+			return isup_ip_msu(winner, m);
+		}
+
 		if (buffer)
 			return mtp3_to_buffer(buffer, m);
 		else
@@ -1775,6 +1779,34 @@
 
 	/* Check point codes to make sure the message is destined for us */
 	rlsize = get_routinglabel(ss7->switchtype, sif, &rl);
+
+	/* Check for messages we need to pass along due to ISUP masquerading */
+	if (rl.opc == ss7->pc) {
+		struct ss7_msg *m;
+
+		if (userpart != SIG_ISUP) {
+			/* Make sure we drop non ISUP traffic */
+			return 0;
+		}
+
+		m = ss7_msg_new();
+
+		if (!m) {
+			mtp_error(ss7, "Could not allocate space to forward message!\n");
+			return -1;
+		}
+
+		memcpy(ss7_msg_userpart(m), msg, len);
+
+		ss7_msg_userpart_len(m, len);
+
+		if (mtp3_transmit(ss7, (*sio) & 0xf, rl, m)) {
+			mtp_error(ss7, "Unable to transmit message to be forwarded\n");
+			return -1;
+		}
+
+		return 0;
+	}
 
 	if (ss7->pc != rl.dpc) {
 		mtp_error(ss7, "Received message destined for point code 0x%x but we're 0x%x.  Dropping\n", rl.dpc, ss7->pc);
@@ -1826,11 +1858,11 @@
 	return link;
 }
 
-static struct mtp2 * mtp2_event_to_mtp2(struct ss7 *ss7, unsigned int link_index)
+static struct mtp2 * mtp2_event_to_mtp2(struct ss7 *ss7, struct mtp2 *mtp2)
 {
 	struct mtp2 *link = NULL;
 
-	link = ss7->links[link_index];
+	link = mtp2;
 	if (!link) {
 		ss7_error(ss7, "Badness! could not find MTP2 link from MTP2 event\n");
 	}
@@ -1868,7 +1900,9 @@
 
 	for (i = 0; i < ss7->numlinks; i++) {
 		if ((ss7->mtp2_linkstate[i] == MTP2_LINKSTATE_DOWN)) {
-			mtp2_start(ss7->links[i], 1);
+			if (!(ss7->links[i]->flags & MTP2_FLAG_TCP)) {
+				mtp2_start(ss7->links[i], 1);
+			}
 			ss7->mtp2_linkstate[i] = MTP2_LINKSTATE_ALIGNING;
 		}
 	}

Modified: team/mattf/bug13495/parser_debug.c
URL: http://svn.digium.com/view/libss7/team/mattf/bug13495/parser_debug.c?view=diff&rev=239&r1=238&r2=239
==============================================================================
--- team/mattf/bug13495/parser_debug.c (original)
+++ team/mattf/bug13495/parser_debug.c Thu Dec 11 11:31:07 2008
@@ -46,6 +46,7 @@
 	int ss7type;
 	int res = 0, i = 0, size;
 	ss7_event *e;
+	struct ss7_msg *m;
 
 	if (argc != 3)
 		return -1;
@@ -59,14 +60,16 @@
 
 	ss7 = ss7_new(ss7type);
 
+	m = ss7_msg_new();
+
 	fp = fopen(argv[2], "r");
 
 	while (res != EOF) {
 		res = fscanf(fp, "%x ", &tmp);
-		mybuf[i++] = (unsigned char) tmp;
+		m->buf[i++] = (unsigned char) tmp;
 	}
 
-	size = i + 1;
+	m->size = i + 1;
 
 	for (i = 0; i < size; i++) {
 		printf("%.2x ", mybuf[i]);
@@ -79,7 +82,7 @@
 	ss7->debug = SS7_DEBUG_MTP2 | SS7_DEBUG_MTP3 | SS7_DEBUG_ISUP;
 	ss7->links[0]->state = MTP_INSERVICE;
 
-	mtp2_receive(ss7->links[0], mybuf, size);
+	mtp2_receive(ss7->links[0], m);
 
 	e = ss7_check_event(ss7);
 

Modified: team/mattf/bug13495/ss7.c
URL: http://svn.digium.com/view/libss7/team/mattf/bug13495/ss7.c?view=diff&rev=239&r1=238&r2=239
==============================================================================
--- team/mattf/bug13495/ss7.c (original)
+++ team/mattf/bug13495/ss7.c Thu Dec 11 11:31:07 2008
@@ -212,12 +212,63 @@
 	if (winner > -1) {
 		ss7->links[winner]->dpc = pc;
 		mtp3_add_adj_sp(ss7->links[winner]);
-	} else
+	} 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;
 
 	return 0;
 }
 
+int ss7_add_slave_link(struct ss7 *ss7, int transport, int fd, int slc, unsigned int adjpc)
+{
+	struct mtp2 *m;
+
+	if (ss7->numlinks >= SS7_MAX_LINKS)
+		return -1;
+
+	m = mtp2_new(fd, ss7->switchtype);
+	
+	if (!m)
+		return -1;
+
+	m->master = ss7;
+
+	if ((transport == SS7_TRANSPORT_DAHDIDCHAN) || (transport == SS7_TRANSPORT_DAHDIMTP2) ||
+			(transport == SS7_TRANSPORT_TCP)) {
+		if (slc > -1)
+			m->slc = slc;
+		else
+			m->slc = ss7->numslavelinks;
+		
+		ss7->numslavelinks += 1;
+
+		if (transport == SS7_TRANSPORT_DAHDIMTP2)
+			m->flags |= MTP2_FLAG_ZAPMTP2;
+
+		if (transport == SS7_TRANSPORT_TCP)
+			m->flags |= MTP2_FLAG_TCP;
+
+		ss7->slavelinks[ss7->numslavelinks - 1] = m;
+
+		ss7_set_adjpc(ss7, fd, adjpc);
+
+	} else {
+		return -1;
+	}
+
+	return 0;
+}
+
 int ss7_add_link(struct ss7 *ss7, int transport, int fd, int slc, unsigned int adjpc)
 {
 	struct mtp2 *m;
@@ -225,33 +276,35 @@
 	if (ss7->numlinks >= SS7_MAX_LINKS)
 		return -1;
 
-	if (transport == SS7_TRANSPORT_TCP) {
-	}
-
-	if ((transport == SS7_TRANSPORT_DAHDIDCHAN) || (transport == SS7_TRANSPORT_DAHDIMTP2)) {
-		int zapmtp2 = 0;
-
-		if (transport == SS7_TRANSPORT_DAHDIMTP2)
-			zapmtp2 = 1;
-
-		m = mtp2_new(fd, ss7->switchtype);
-		
-		if (!m)
-			return -1;
-
+	m = mtp2_new(fd, ss7->switchtype);
+	
+	if (!m)
+		return -1;
+
+	m->master = ss7;
+
+	if ((transport == SS7_TRANSPORT_DAHDIDCHAN) || (transport == SS7_TRANSPORT_DAHDIMTP2) ||
+		(transport == SS7_TRANSPORT_TCP)) {
 		if (slc > -1)
 			m->slc = slc;
 		else
 			m->slc = ss7->numlinks;
+		
 		ss7->numlinks += 1;
-		m->master = ss7;
-		if (zapmtp2)
+
+		if (transport == SS7_TRANSPORT_DAHDIMTP2)
 			m->flags |= MTP2_FLAG_ZAPMTP2;
 
+		if (transport == SS7_TRANSPORT_TCP)
+			m->flags |= MTP2_FLAG_TCP;
+
 		ss7->links[ss7->numlinks - 1] = m;
-	}
-
-	ss7_set_adjpc(ss7, fd, adjpc);
+
+		ss7_set_adjpc(ss7, fd, adjpc);
+
+	} else {
+		return -1;
+	}
 
 	return 0;
 }
@@ -275,8 +328,9 @@
 	if (ss7->links[winner]->flags & MTP2_FLAG_ZAPMTP2) {
 		if (ss7->links[winner]->flags & MTP2_FLAG_WRITE)
 			flags |= POLLOUT;
-	} else
+	} else if (!(ss7->links[winner]->flags & MTP2_FLAG_TCP)) {
 		flags |= POLLOUT;
+	}
 
 	return flags;
 }
@@ -423,8 +477,7 @@
 
 int ss7_read(struct ss7 *ss7, int fd)
 {
-	unsigned char buf[1024];
-	int res;
+	int res = -1;
 	int winner = -1;
 	int i;
 
@@ -434,16 +487,28 @@
 			break;
 		}
 	}
-	
-	if (winner < 0)
-		return -1;
-
-	res = read(ss7->links[winner]->fd, buf, sizeof(buf));
-	if (res <= 0) {
-		return res;
-	}
-
-	res = mtp2_receive(ss7->links[winner], buf, res);
+
+	if (winner != -1) {
+		if (ss7->links[winner]->flags & MTP2_FLAG_TCP) {
+			res = isup_ip_receive(ss7->links[winner]);
+		} else {
+			res = mtp2_receive(ss7->links[winner]);
+		}
+
+	}
+
+	/* Maybe it's a lite link */
+	for (i = 0; i < ss7->numslavelinks; i++) {
+		if (ss7->slavelinks[i]->fd == fd) {
+			winner = i;
+			break;
+		}
+	}
+
+	if (winner != -1) {
+		res = isup_ip_receive(ss7->links[winner]);
+	}
+	
 
 	return res;
 }

Modified: team/mattf/bug13495/ss7_internal.h
URL: http://svn.digium.com/view/libss7/team/mattf/bug13495/ss7_internal.h?view=diff&rev=239&r1=238&r2=239
==============================================================================
--- team/mattf/bug13495/ss7_internal.h (original)
+++ team/mattf/bug13495/ss7_internal.h Thu Dec 11 11:31:07 2008
@@ -88,6 +88,22 @@
 	void *data;
 };
 
+#define ISUP_MASQ_MAX_ENTRIES 128
+
+struct isup_masq_route {
+	/* These three fields are what defines the reception route */
+	point_code opc;
+	int startcic;
+	int endcic;
+
+	struct mtp2 *mtp2;
+};
+
+struct isup_masq {
+	struct isup_masq_route routes[ISUP_MASQ_MAX_ENTRIES];
+	int numentries;
+};
+
 struct ss7 {
 	unsigned int switchtype;
 	unsigned int numsps;
@@ -119,6 +135,13 @@
 	unsigned int flags;
 	unsigned char cb_seq;
 	int linkset_up_timer;
+	
+	/* lite links are links that pretty much go straight to and from a user part */
+	struct mtp2 *slavelinks[SS7_MAX_LINKS];
+	int numslavelinks;
+
+	/* Data members needed for ISUP slave channels */
+	struct isup_masq isup_masq_table;
 };
 
 /* Getto hacks for developmental purposes */
@@ -151,4 +174,12 @@
 
 void (*ss7_call_null)(struct ss7 *ss7, struct isup_call *c, int lock);
 
+int isup_needs_masquerade(struct ss7 *ss7, struct routing_label *rl, unsigned int cic, unsigned char *buf, int len);
+
+int isup_ip_msu(struct mtp2 *mtp2, struct ss7_msg *msg);
+
+int isup_ip_receive(struct mtp2 *mtp2);
+
+int ss7_add_slave_link(struct ss7 *ss7, int transport, int fd, int slc, unsigned int adjpc);
+
 #endif /* _SS7_H */




More information about the libss7-commits mailing list