> Daniel Pocock wrote:
>>
>>
>> I've been using patched version of rtpproxy with the following features:
>>
>> - the TTL is maintained for each direction independently, so if just one
>> side stops sending for max_ttl seconds, the connection can be dropped
>>
>> - whenever a connection is dropped, a notification is logged to a socket
>> (the socket is configured with the new parameter, -n )
>>
>> Does anyone have any comments on this patch and it's suitability for the
>> main rtpproxy CVS?  I'm going to post the patch and some other work on
>> this list shortly.
>
> Daniel,
>
> Both make sense to me. Please post them, but make sure they are for the
> CVS trunk before posting, though. There were many changes, particularly
> in the TTL tracking code.
>

The patches were originally developed on 0.2

I have modified them for the CVS trunk and attached a diff.

Another change that is included:  the command x or X will cause all
sessions to be dropped.  I invoke this command when my B2BUA starts, to
ensure there are no lingering sessions from a previous B2BUA that crashed.
? .deps
? Makefile
? config.h
? config.log
? config.status
? makeann
? rtpproxy
? stamp-h1
Index: main.c
===================================================================
RCS file: /cvsroot/ser/rtpproxy/main.c,v
retrieving revision 1.71
diff -u -r1.71 main.c
--- main.c	3 Apr 2008 20:51:45 -0000	1.71
+++ main.c	7 May 2008 08:53:29 -0000
@@ -67,6 +67,9 @@
 static const char *pid_file = PID_FILE;
 static rtpp_log_t glog;
 
+static const char *timeout_sock = NULL;                /* filename of socket */
+static int timeoutfd = -1;                     /* fd for current connection */
+
 static void setbindhost(struct sockaddr *, int, const char *, const char *);
 static void usage(void);
 static void send_packet(struct cfg *, struct rtpp_session *, int,
@@ -135,7 +138,7 @@
     if (getrlimit(RLIMIT_NOFILE, &(cf->nofile_limit)) != 0)
 	err(1, "getrlimit");
 
-    while ((ch = getopt(argc, argv, "vf2Rl:6:s:S:t:r:p:T:L:m:M:u:F")) != -1)
+    while ((ch = getopt(argc, argv, "vf2Rl:6:s:S:t:r:p:T:L:m:M:u:Fn:")) != -1)
 	switch (ch) {
 	case 'f':
 	    cf->nodaemon = 1;
@@ -248,6 +251,16 @@
 	    cf->no_check = 1;
 	    break;
 
+        case 'n':
+            if(strncmp("unix:", optarg, 5) == 0) {
+                optarg += 5;
+                timeout_sock = optarg;
+            } else {
+                fprintf(stderr, "can only send timeout notifications to UNIX socket, %s is invalid\n", optarg);
+                exit(0);
+            }
+            break;
+
 	case '?':
 	default:
 	    usage();
@@ -556,7 +569,7 @@
 {
     int i, sidx;
 
-    GET_RTP(sp)->ttl = cf->max_ttl;
+    GET_RTP(sp)->ttl[ridx] = cf->max_ttl;
 
     /* Select socket for sending packet out. */
     sidx = (ridx == 0) ? 1 : 0;
@@ -580,11 +593,42 @@
 }
 
 static void
+init_timeoutfd()
+{
+    int t, len;
+    struct sockaddr_un remote;
+
+    if(timeoutfd != -1)
+       close(timeoutfd);
+    timeoutfd = -1;
+
+    if(timeout_sock == NULL)
+       return;
+
+    if ((timeoutfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
+        perror("socket"); // FIXME
+        exit(1);
+    }
+    remote.sun_family = AF_UNIX;
+    strcpy(remote.sun_path, timeout_sock);
+    len = strlen(remote.sun_path) + sizeof(remote.sun_family);
+    if (connect(timeoutfd, (struct sockaddr *)&remote, len) == -1) {
+       rtpp_log_write(RTPP_LOG_INFO, NULL, "timeoutfd connect failed");
+       perror("connect");
+       timeoutfd = -1;
+       return;
+    }
+}
+
+#define BUF_LEN 80
+static void
 process_rtp(struct cfg *cf, double ctime, int alarm_tick)
 {
     int readyfd, skipfd, ridx;
     struct rtpp_session *sp;
     struct rtp_packet *packet;
+    char notify_buf[80];
+    int result;
 
     /* Relay RTP/RTCP */
     skipfd = 0;
@@ -593,11 +637,25 @@
 
 	if (alarm_tick != 0 && sp != NULL && sp->rtcp != NULL &&
 	  sp->sidx[0] == readyfd) {
-	    if (sp->ttl == 0) {
+	    if (sp->ttl[0] == 0 || sp->ttl[1] == 0) {
 		rtpp_log_write(RTPP_LOG_INFO, sp->log, "session timeout");
 		remove_session(cf, sp);
+		snprintf(notify_buf, BUF_LEN, "%d %d\n", sp->ports[0], sp->ports[1]);
+		if(timeoutfd == -1) {
+		    init_timeoutfd();
+		}
+		if(timeoutfd != -1) {
+		    result = send(timeoutfd, notify_buf, strlen(notify_buf) + 1, 0);
+		    if(result < 0) {
+			timeoutfd = -1;
+			init_timeoutfd();
+			if(send(timeoutfd, notify_buf, strlen(notify_buf) + 1, 0) < 0)
+			    timeoutfd = -1;
+		    }
+		}
 	    } else {
-		sp->ttl--;
+		sp->ttl[0]--;
+		sp->ttl[1]--;
 	    }
 	}
 
Index: rtpp_command.c
===================================================================
RCS file: /cvsroot/ser/rtpproxy/rtpp_command.c,v
retrieving revision 1.6
diff -u -r1.6 rtpp_command.c
--- rtpp_command.c	3 Apr 2008 23:05:41 -0000	1.6
+++ rtpp_command.c	7 May 2008 08:53:29 -0000
@@ -438,10 +438,10 @@
 
 	    len += sprintf(buf + len,
 	      "%s/%s: caller = %s:%d/%s, callee = %s:%d/%s, "
-	      "stats = %lu/%lu/%lu/%lu, ttl = %d\n",
+	      "stats = %lu/%lu/%lu/%lu, ttl = %d/%d\n",
 	      spb->call_id, spb->tag, addrs[0], spb->ports[1], addrs[1],
 	      addrs[2], spb->ports[0], addrs[3], spa->pcount[0], spa->pcount[1],
-	      spa->pcount[2], spa->pcount[3], spb->ttl);
+	      spa->pcount[2], spa->pcount[3], spb->ttl[0], spb->ttl[1]);
 	    if (len + 512 > sizeof(buf)) {
 		doreply(cf, controlfd, buf, len, &raddr, rlen);
 		len = 0;
@@ -458,6 +458,23 @@
 	rname = "query";
 	break;
 
+    case 'x':
+    case 'X':
+        /* Delete all active sessions */
+        rtpp_log_write(RTPP_LOG_WARN, glog, "deleting all active sessions...");
+        int counter = 0;
+        while(cf->nsessions > 0) {
+            if(cf->sessions[counter]->rtcp != NULL) {
+                remove_session(cf, cf->sessions[counter]);
+	    }
+            counter++;
+        }
+        len = sprintf(buf, "deleted %d sessions\n", counter);
+        if (len > 0)
+            doreply(cf, controlfd, buf, len, &raddr, rlen);
+        return;
+        break;
+
     default:
 	rtpp_log_write(RTPP_LOG_ERR, cf->glog, "unknown command");
 	reply_error(cf, controlfd, &raddr, rlen, cookie, 3);
@@ -680,7 +697,8 @@
 	lport = spa->ports[i];
 	lia[0] = spa->laddr[i];
 	pidx = (i == 0) ? 1 : 0;
-	spa->ttl = cf->max_ttl;
+	spa->ttl[0] = cf->max_ttl;
+	spa->ttl[1] = cf->max_ttl;
 	if (op == UPDATE) {
 	    rtpp_log_write(RTPP_LOG_INFO, spa->log,
 	      "adding %s flag to existing session, new=%d/%d/%d",
@@ -757,8 +775,10 @@
 	spb->fds[0] = fds[1];
 	spa->ports[0] = lport;
 	spb->ports[0] = lport + 1;
-	spa->ttl = cf->max_ttl;
-	spb->ttl = -1;
+	spa->ttl[0] = cf->max_ttl;
+        spa->ttl[1] = cf->max_ttl;
+	spb->ttl[0] = -1;
+        spb->ttl[1] = -1;
 	spa->log = rtpp_log_open("rtpproxy", spa->call_id, 0);
 	spb->log = spa->log;
 	spa->rtcp = spb;
Index: rtpp_session.h
===================================================================
RCS file: /cvsroot/ser/rtpproxy/rtpp_session.h,v
retrieving revision 1.9
diff -u -r1.9 rtpp_session.h
--- rtpp_session.h	3 Apr 2008 17:48:45 -0000	1.9
+++ rtpp_session.h	7 May 2008 08:53:29 -0000
@@ -39,7 +39,8 @@
 #include "rtpp_log.h"
 
 struct rtpp_session {
-    int ttl;
+    /* ttl for caller [0] and callee [1] */
+    int ttl[2];
     unsigned long pcount[4];
     char *call_id;
     char *tag;
_______________________________________________
Users mailing list
Users@rtpproxy.org
http://lists.rtpproxy.org/mailman/listinfo/users

Reply via email to