[svn-commits] russell: branch russell/ais r78277 - in /team/russell/ais: include/asterisk/ ...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Aug 6 16:45:10 CDT 2007


Author: russell
Date: Mon Aug  6 16:45:09 2007
New Revision: 78277

URL: http://svn.digium.com/view/asterisk?view=rev&rev=78277
Log:
Add an Entity ID (similar to DUNDi) to signify which server an event originated
from.  Also, modify res_ais such that it will only attempt to forward events to
the cluster that originated locally.

Modified:
    team/russell/ais/include/asterisk/dundi.h
    team/russell/ais/include/asterisk/event.h
    team/russell/ais/include/asterisk/event_defs.h
    team/russell/ais/include/asterisk/utils.h
    team/russell/ais/main/event.c
    team/russell/ais/main/utils.c
    team/russell/ais/pbx/dundi-parser.c
    team/russell/ais/pbx/pbx_dundi.c
    team/russell/ais/res/res_ais.c

Modified: team/russell/ais/include/asterisk/dundi.h
URL: http://svn.digium.com/view/asterisk/team/russell/ais/include/asterisk/dundi.h?view=diff&rev=78277&r1=78276&r2=78277
==============================================================================
--- team/russell/ais/include/asterisk/dundi.h (original)
+++ team/russell/ais/include/asterisk/dundi.h Mon Aug  6 16:45:09 2007
@@ -25,15 +25,11 @@
 #define _ASTERISK_DUNDI_H
 
 #include "asterisk/channel.h"
+#include "asterisk/utils.h"
 
 #define DUNDI_PORT 4520
 
-/*!\brief A DUNDi Entity ID is essentially a MAC address, brief and unique */
-struct _dundi_eid {
-	unsigned char eid[6];
-} __attribute__ ((__packed__));
-
-typedef struct _dundi_eid dundi_eid;
+typedef struct ast_eid dundi_eid;
 
 struct dundi_hdr {
 	unsigned short strans;			/*!< Source transaction */

Modified: team/russell/ais/include/asterisk/event.h
URL: http://svn.digium.com/view/asterisk/team/russell/ais/include/asterisk/event.h?view=diff&rev=78277&r1=78276&r2=78277
==============================================================================
--- team/russell/ais/include/asterisk/event.h (original)
+++ team/russell/ais/include/asterisk/event.h Mon Aug  6 16:45:09 2007
@@ -205,7 +205,20 @@
  * This creates a MWI event with 3 information elements, a mailbox which is
  * a string, and the number of new and old messages, specified as integers.
  */
-struct ast_event *ast_event_new(enum ast_event_type event_type, ...);
+#define ast_event_new(event_type, ...) \
+	__ast_event_new(0, event_type, __VA_ARGS__)
+
+/*!
+ * \brief Create a new event that came from a remote server
+ *
+ * This function is handled the same as ast_event_new(), except that it indicates
+ * that this event was received from a remote server, as opposed to being generated
+ * as the result of something happening on this one.
+ */
+#define ast_remote_event_new(event_type, ...) \
+	__ast_event_new(1, event_type, __VA_ARGS__)
+
+struct ast_event *__ast_event_new(int remote, enum ast_event_type event_type, ...);
 
 /*!
  * \brief Destroy an event

Modified: team/russell/ais/include/asterisk/event_defs.h
URL: http://svn.digium.com/view/asterisk/team/russell/ais/include/asterisk/event_defs.h?view=diff&rev=78277&r1=78276&r2=78277
==============================================================================
--- team/russell/ais/include/asterisk/event_defs.h (original)
+++ team/russell/ais/include/asterisk/event_defs.h Mon Aug  6 16:45:09 2007
@@ -103,6 +103,13 @@
 	 * this IE is a part of.
 	 */
 	 AST_EVENT_IE_STATE    = 0x08,
+	 /*!
+	  * \brief Entity ID
+	  * Used by All events
+	  * Payload type: STR
+	  * This IE indicates which server the event originated from
+	  */
+	 AST_EVENT_IE_EID      = 0x09,
 };
 
 /*!

Modified: team/russell/ais/include/asterisk/utils.h
URL: http://svn.digium.com/view/asterisk/team/russell/ais/include/asterisk/utils.h?view=diff&rev=78277&r1=78276&r2=78277
==============================================================================
--- team/russell/ais/include/asterisk/utils.h (original)
+++ team/russell/ais/include/asterisk/utils.h Mon Aug  6 16:45:09 2007
@@ -667,4 +667,18 @@
 
 #include "asterisk/strings.h"
 
+/*!
+ * \brief An Entity ID is essentially a MAC address, brief and unique 
+ */
+struct ast_eid {
+	unsigned char eid[6];
+} __attribute__ ((__packed__));
+
+/*!
+ * \brief Fill in an ast_eid with the default eid of this machine
+ */
+void ast_set_eid(struct ast_eid *eid);
+
+char *ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid);
+
 #endif /* _ASTERISK_UTILS_H */

Modified: team/russell/ais/main/event.c
URL: http://svn.digium.com/view/asterisk/team/russell/ais/main/event.c?view=diff&rev=78277&r1=78276&r2=78277
==============================================================================
--- team/russell/ais/main/event.c (original)
+++ team/russell/ais/main/event.c Mon Aug  6 16:45:09 2007
@@ -106,6 +106,9 @@
  * needs to know this state, it can get the last known state from the cache. */
 static AST_RWLIST_HEAD(ast_event_ref_list, ast_event_ref) ast_event_cache[AST_EVENT_TOTAL];
 
+/*! \brief The server EID */
+static struct ast_eid g_eid;
+
 size_t ast_event_get_size(const struct ast_event *event)
 {
 	size_t res;
@@ -437,7 +440,7 @@
 	return 0;
 }
 
-struct ast_event *ast_event_new(enum ast_event_type type, ...)
+struct ast_event *__ast_event_new(int remote, enum ast_event_type type, ...)
 {
 	va_list ap;
 	struct ast_event *event;
@@ -474,6 +477,14 @@
 
 	event->type = htons(type);
 	event->event_len = htons(sizeof(*event));
+
+	if (!remote) {
+		char buf[32] = "";
+		/* If the event is originating on this server, add the server's
+		 * entity ID to the event. */
+		ast_eid_to_str(buf, sizeof(buf), &g_eid);
+		ast_event_append_ie_str(&event, AST_EVENT_IE_EID, buf);
+	}
 
 	AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) {
 		if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR)
@@ -768,6 +779,8 @@
 {
 	int i;
 
+	ast_set_eid(&g_eid);
+
 	for (i = 0; i < AST_EVENT_TOTAL; i++)
 		AST_RWLIST_HEAD_INIT(&ast_event_subs[i]);
 

Modified: team/russell/ais/main/utils.c
URL: http://svn.digium.com/view/asterisk/team/russell/ais/main/utils.c?view=diff&rev=78277&r1=78276&r2=78277
==============================================================================
--- team/russell/ais/main/utils.c (original)
+++ team/russell/ais/main/utils.c Mon Aug  6 16:45:09 2007
@@ -1377,6 +1377,72 @@
 	return 0;
 }
 
+char *ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
+{
+	int x;
+	char *os = s;
+	if (maxlen < 18) {
+		if (s && (maxlen > 0))
+			*s = '\0';
+	} else {
+		for (x=0;x<5;x++) {
+			sprintf(s, "%02x:", eid->eid[x]);
+			s += 3;
+		}
+		sprintf(s, "%02x", eid->eid[5]);
+	}
+	return os;
+}
+
+void ast_set_eid(struct ast_eid *eid)
+{
+#if defined(SIOCGIFHWADDR)
+	int s, x = 0;
+	char eid_str[20];
+	struct ifreq ifr;
+
+	s = socket(AF_INET, SOCK_STREAM, 0);
+	if (s < 0)
+		return;
+	for (x = 0; x < 10; x++) {
+		memset(&ifr, 0, sizeof(ifr));
+		snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "eth%d", x);
+		if (ioctl(s, SIOCGIFHWADDR, &ifr))
+			continue;
+		memcpy(&global_eid, ((unsigned char *)&ifr.ifr_hwaddr) + 2, sizeof(*eid));
+		if (option_debug) {
+			ast_log(LOG_DEBUG, "Seeding global EID '%s' from '%s'\n", 
+				ast_eid_to_str(eid_str, sizeof(eid_str), eid), ifr.ifr_name);
+		}
+		break;
+	}
+	close(s);
+#else
+#if defined(ifa_broadaddr) && !defined(SOLARIS)
+	char eid_str[20];
+	struct ifaddrs *ifap;
+	
+	if (getifaddrs(&ifap) == 0) {
+		struct ifaddrs *p;
+		for (p = ifap; p; p = p->ifa_next) {
+			if (p->ifa_addr->sa_family == AF_LINK) {
+				struct sockaddr_dl* sdp = (struct sockaddr_dl*) p->ifa_addr;
+				memcpy(
+					&(eid->eid),
+					sdp->sdl_data + sdp->sdl_nlen, 6);
+				if (option_debug)
+					ast_log(LOG_DEBUG, "Seeding global EID '%s' from '%s'\n", ast_eid_to_str(eid_str, sizeof(eid_str), eid), ifap->ifa_name);
+				freeifaddrs(ifap);
+				return;
+			}
+		}
+		freeifaddrs(ifap);
+	}
+#endif
+#endif
+	ast_log(LOG_ERROR, "No ethernet interface found for seeding default EID.  You will have to set it manually.\n");
+}
+
 int ast_utils_init(void)
 {
 #ifdef HAVE_DEV_URANDOM

Modified: team/russell/ais/pbx/dundi-parser.c
URL: http://svn.digium.com/view/asterisk/team/russell/ais/pbx/dundi-parser.c?view=diff&rev=78277&r1=78276&r2=78277
==============================================================================
--- team/russell/ais/pbx/dundi-parser.c (original)
+++ team/russell/ais/pbx/dundi-parser.c Mon Aug  6 16:45:09 2007
@@ -54,38 +54,7 @@
 static void (*outputf)(const char *str) = internaloutput;
 static void (*errorf)(const char *str) = internalerror;
 
-char *dundi_eid_to_str(char *s, int maxlen, dundi_eid *eid)
-{
-	int x;
-	char *os = s;
-	if (maxlen < 18) {
-		if (s && (maxlen > 0))
-			*s = '\0';
-	} else {
-		for (x=0;x<5;x++) {
-			sprintf(s, "%02x:", eid->eid[x]);
-			s += 3;
-		}
-		sprintf(s, "%02x", eid->eid[5]);
-	}
-	return os;
-}
-
-char *dundi_eid_to_str_short(char *s, int maxlen, dundi_eid *eid)
-{
-	int x;
-	char *os = s;
-	if (maxlen < 13) {
-		if (s && (maxlen > 0))
-			*s = '\0';
-	} else {
-		for (x=0;x<6;x++) {
-			sprintf(s, "%02X", eid->eid[x]);
-			s += 2;
-		}
-	}
-	return os;
-}
+#define dundi_eid_to_str(a,b,c) ast_eid_to_str(a,b,c)
 
 int dundi_str_to_eid(dundi_eid *eid, char *s)
 {

Modified: team/russell/ais/pbx/pbx_dundi.c
URL: http://svn.digium.com/view/asterisk/team/russell/ais/pbx/pbx_dundi.c?view=diff&rev=78277&r1=78276&r2=78277
==============================================================================
--- team/russell/ais/pbx/pbx_dundi.c (original)
+++ team/russell/ais/pbx/pbx_dundi.c Mon Aug  6 16:45:09 2007
@@ -397,51 +397,7 @@
 
 static void reset_global_eid(void)
 {
-#if defined(SIOCGIFHWADDR)
-	int s, x = 0;
-	char eid_str[20];
-	struct ifreq ifr;
-
-	s = socket(AF_INET, SOCK_STREAM, 0);
-	if (s < 0)
-		return;
-	for (x = 0; x < 10; x++) {
-		memset(&ifr, 0, sizeof(ifr));
-		snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "eth%d", x);
-		if (ioctl(s, SIOCGIFHWADDR, &ifr))
-			continue;
-		memcpy(&global_eid, ((unsigned char *)&ifr.ifr_hwaddr) + 2, sizeof(global_eid));
-		if (option_debug) {
-			ast_log(LOG_DEBUG, "Seeding global EID '%s' from '%s'\n", 
-				dundi_eid_to_str(eid_str, sizeof(eid_str), &global_eid), ifr.ifr_name);
-		}
-		break;
-	}
-	close(s);
-#else
-#if defined(ifa_broadaddr) && !defined(SOLARIS)
-	char eid_str[20];
-	struct ifaddrs *ifap;
-	
-	if (getifaddrs(&ifap) == 0) {
-		struct ifaddrs *p;
-		for (p = ifap; p; p = p->ifa_next) {
-			if (p->ifa_addr->sa_family == AF_LINK) {
-				struct sockaddr_dl* sdp = (struct sockaddr_dl*) p->ifa_addr;
-				memcpy(
-					&(global_eid.eid),
-					sdp->sdl_data + sdp->sdl_nlen, 6);
-				if (option_debug)
-					ast_log(LOG_DEBUG, "Seeding global EID '%s' from '%s'\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &global_eid), ifap->ifa_name);
-				freeifaddrs(ifap);
-				return;
-			}
-		}
-		freeifaddrs(ifap);
-	}
-#endif
-#endif
-	ast_log(LOG_NOTICE, "No ethernet interface found for seeding global EID  You will have to set it manually.\n");
+	ast_set_eid(&global_eid);
 }
 
 static int get_trans_id(void)

Modified: team/russell/ais/res/res_ais.c
URL: http://svn.digium.com/view/asterisk/team/russell/ais/res/res_ais.c?view=diff&rev=78277&r1=78276&r2=78277
==============================================================================
--- team/russell/ais/res/res_ais.c (original)
+++ team/russell/ais/res/res_ais.c Mon Aug  6 16:45:09 2007
@@ -63,6 +63,10 @@
 
 /*! Used to provide unique id's to egress subscriptions */
 static int unique_id;
+
+/*! \brief This server's unique entity ID */
+static struct ast_eid g_eid;
+static char g_eid_str[32];
 
 struct subscribe_event {
 	AST_LIST_ENTRY(subscribe_event) entry;
@@ -213,6 +217,11 @@
 	const char *filter_str;
 	SaEvtEventIdT event_id;
 
+	if (strcasecmp(g_eid_str, ast_event_get_ie_str(ast_event, AST_EVENT_IE_EID))) {
+		/* If the event didn't originate from this server, don't send it back out. */
+		return;
+	}
+
 	res = saEvtEventAllocate(event_channel->handle, &event_handle);
 	if (res != SA_AIS_OK) {
 		ast_log(LOG_ERROR, "Error allocating event: %s\n", ais_err2str(res));
@@ -374,8 +383,8 @@
 	
 	publish_event->type = type;
 
-	publish_event->sub = ast_event_subscribe(type, ast_event_cb, 
-		event_channel, NULL);
+	publish_event->sub = ast_event_subscribe(type, ast_event_cb, event_channel,
+		AST_EVENT_IE_END);
 
 	AST_LIST_INSERT_TAIL(&event_channel->publish_events, publish_event, entry);
 }
@@ -578,6 +587,9 @@
 {
 	int res;
 
+	ast_set_eid(&g_eid);
+	ast_eid_to_str(g_eid_str, sizeof(g_eid_str), &g_eid);
+
 	res = saClmInitialize(&clm_handle, &clm_callbacks, &version);
 	if (res != SA_AIS_OK) {
 		ast_log(LOG_ERROR, "Could not initialize cluster membership service: %s\n",




More information about the svn-commits mailing list