[svn-commits] gtjoseph: branch 12 r416737 - in /branches/12: include/asterisk/ main/ res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jun 19 15:12:24 CDT 2014


Author: gtjoseph
Date: Thu Jun 19 15:12:15 2014
New Revision: 416737

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=416737
Log:
pjsip cli: Change Identify to show CIDR notation instead of netmasks.

* Added ast_sockaddr_cidr_bits() to count the 1 bits in an ast_sockaddr.
* Added ast_ha_join_cidr() which uses ast_sockaddr_cidr_bits() for the netmask
  instead of ast_sockaddr_stringify_addr.
* Changed res_pjsip_endpoint_identifier_ip to call ast_ha_join_cidr() instead
  of ast_ha_join() for the CLI output.

This is a CLI change only.  AMI was not affected.

Tested by: George Joseph
Review: https://reviewboard.asterisk.org/r/3652/

Modified:
    branches/12/include/asterisk/acl.h
    branches/12/include/asterisk/netsock2.h
    branches/12/main/acl.c
    branches/12/main/netsock2.c
    branches/12/res/res_pjsip_endpoint_identifier_ip.c

Modified: branches/12/include/asterisk/acl.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/acl.h?view=diff&rev=416737&r1=416736&r2=416737
==============================================================================
--- branches/12/include/asterisk/acl.h (original)
+++ branches/12/include/asterisk/acl.h Thu Jun 19 15:12:15 2014
@@ -140,6 +140,13 @@
  * \param buf string buffer to convert data to
  */
 void ast_ha_join(const struct ast_ha *ha, struct ast_str **buf);
+
+/*!
+ * \brief Convert HAs to a comma separated string value using CIDR notation
+ * \param ha the starting ha head
+ * \param buf string buffer to convert data to
+ */
+void ast_ha_join_cidr(const struct ast_ha *ha, struct ast_str **buf);
 
 /*!
  * \brief Add a rule to an ACL struct

Modified: branches/12/include/asterisk/netsock2.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/netsock2.h?view=diff&rev=416737&r1=416736&r2=416737
==============================================================================
--- branches/12/include/asterisk/netsock2.h (original)
+++ branches/12/include/asterisk/netsock2.h Thu Jun 19 15:12:15 2014
@@ -263,6 +263,16 @@
 }
 
 /*!
+ * \since 12.4
+ *
+ * \brief
+ * Count the 1 bits in a netmask
+ *
+ * \return number of 1 bits
+ */
+int ast_sockaddr_cidr_bits(const struct ast_sockaddr *sa);
+
+/*!
  * \since 1.8
  *
  * \brief

Modified: branches/12/main/acl.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/acl.c?view=diff&rev=416737&r1=416736&r2=416737
==============================================================================
--- branches/12/main/acl.c (original)
+++ branches/12/main/acl.c Thu Jun 19 15:12:15 2014
@@ -671,6 +671,19 @@
 		ast_str_append(buf, 0, "%s%s/%s",
 			       ha->sense == AST_SENSE_ALLOW ? "!" : "",
 			       addr, ast_sockaddr_stringify_addr(&ha->netmask));
+		if (ha->next) {
+			ast_str_append(buf, 0, ",");
+		}
+	}
+}
+
+void ast_ha_join_cidr(const struct ast_ha *ha, struct ast_str **buf)
+{
+	for (; ha; ha = ha->next) {
+		const char *addr = ast_sockaddr_stringify_addr(&ha->addr);
+		ast_str_append(buf, 0, "%s%s/%d",
+			       ha->sense == AST_SENSE_ALLOW ? "!" : "",
+			       addr, ast_sockaddr_cidr_bits(&ha->netmask));
 		if (ha->next) {
 			ast_str_append(buf, 0, ",");
 		}

Modified: branches/12/main/netsock2.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/netsock2.c?view=diff&rev=416737&r1=416736&r2=416737
==============================================================================
--- branches/12/main/netsock2.c (original)
+++ branches/12/main/netsock2.c Thu Jun 19 15:12:15 2014
@@ -129,6 +129,40 @@
 	return ast_str_buffer(str);
 }
 
+int ast_sockaddr_cidr_bits(const struct ast_sockaddr *sa)
+{
+	struct ast_sockaddr sa_ipv4;
+	const struct ast_sockaddr *sa_tmp;
+	int bits = 0;
+	int bytes;
+	int i;
+	int j;
+	char *addr;
+
+	if (ast_sockaddr_isnull(sa)) {
+		return 0;
+	}
+
+	if (ast_sockaddr_ipv4_mapped(sa, &sa_ipv4)) {
+		sa_tmp = &sa_ipv4;
+	} else {
+		sa_tmp = sa;
+	}
+
+	bytes = sa_tmp->len;
+	addr = ((struct sockaddr *)&sa_tmp->ss)->sa_data;
+
+	for (i = 0; i < bytes ; ++i) {
+		for (j = 0; j < 8; ++j) {
+			if ((addr[i] >> j) & 1) {
+				bits++;
+			}
+		}
+	}
+
+	return bits;
+}
+
 int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
 {
 	char *s = str;

Modified: branches/12/res/res_pjsip_endpoint_identifier_ip.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip_endpoint_identifier_ip.c?view=diff&rev=416737&r1=416736&r2=416737
==============================================================================
--- branches/12/res/res_pjsip_endpoint_identifier_ip.c (original)
+++ branches/12/res/res_pjsip_endpoint_identifier_ip.c Thu Jun 19 15:12:15 2014
@@ -372,7 +372,7 @@
 
 	ast_str_append(&context->output_buffer, 0, "%*s:  ",
 		CLI_INDENT_TO_SPACES(context->indent_level), "Identify");
-	ast_ha_join(ident->matches, &str);
+	ast_ha_join_cidr(ident->matches, &str);
 	ast_str_append(&context->output_buffer, 0, "%s\n", ast_str_buffer(str));
 
 	return 0;




More information about the svn-commits mailing list