Merge code associated with AST-2009-006

(closes issue #12912)
Reported by: rathaus
Tested by: tilghman, russell, dvossel, dbrooks



git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@216000 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
David Vossel
2009-09-03 18:32:32 +00:00
parent 82b1e162e1
commit ed1951d895
9 changed files with 1321 additions and 139 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -442,7 +442,9 @@ void iax_frame_subclass2str(int subclass, char *str, size_t len)
"PROVISN",
"FWDWNLD",
"FWDATA ",
"TXMEDIA"
"TXMEDIA",
"RTKEY ",
"CTOKEN ",
};
if ((copylen > len) || !subclass || (subclass < 0)) {
str[0] = '\0';
@@ -959,6 +961,12 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen)
ies->rr_ooo = ntohl(get_unaligned_uint32(data + 2));
}
break;
case IAX_IE_CALLTOKEN:
if (len) {
ies->calltokendata = (unsigned char *) data + 2;
}
ies->calltoken = 1;
break;
default:
snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
outputf(tmp);

View File

@@ -74,6 +74,8 @@ struct iax_ies {
unsigned short rr_delay;
unsigned int rr_dropped;
unsigned int rr_ooo;
unsigned char calltoken;
unsigned char *calltokendata;
};
#define DIRECTION_INGRESS 1

View File

@@ -73,6 +73,8 @@
#define IAX_COMMAND_FWDOWNL 36 /* Download firmware */
#define IAX_COMMAND_FWDATA 37 /* Firmware Data */
#define IAX_COMMAND_TXMEDIA 38 /* Transfer media only */
#define IAX_COMMAND_CALLTOKEN 40 /*! Call number token */
#define IAX_DEFAULT_REG_EXPIRE 60 /* By default require re-registration once per minute */
@@ -133,6 +135,7 @@
#define IAX_IE_RR_DELAY 49 /* Max playout delay for received frames (in ms) u16 */
#define IAX_IE_RR_DROPPED 50 /* Dropped frames (presumably by jitterbuf) u32 */
#define IAX_IE_RR_OOO 51 /* Frames received Out of Order u32 */
#define IAX_IE_CALLTOKEN 54 /* Call number security token */
#define IAX_AUTH_PLAINTEXT (1 << 0)

View File

@@ -268,6 +268,62 @@ autokill=yes
; has expired based on its registration interval, used the stored
; address information regardless. (yes|no)
;
; The following two options are used to disable call token validation for the
; purposes of interoperability with IAX2 endpoints that do not yet support it.
;
; Call token validation can be set as optional for a single IP address or IP
; address range by using the 'calltokenoptional' option. 'calltokenoptional' is
; only a global option.
;
;calltokenoptional=209.16.236.73/255.255.255.0
;
; In a peer/user/friend definition, the 'requirecalltoken' option may be used.
; By setting 'requirecalltoken=no', call token validation becomes optional for
; that peer/user. By setting 'requirecalltoken=auto', call token validation
; is optional until a call token supporting peer registers successfully using
; call token validation. This is used as an indication that from now on, we
; can require it from this peer. So, requirecalltoken is internally set to yes.
; By default, 'requirecalltoken=yes'.
;
;requirecalltoken=no
;
;
; These options are used to limit the amount of call numbers allocated to a
; single IP address. Before changing any of these values, it is highly encouraged
; to read the user guide associated with these options first. In most cases, the
; default values for these options are sufficient.
;
; The 'maxcallnumbers' option limits the amount of call numbers allowed for each
; individual remote IP address. Once an IP address reaches it's call number
; limit, no more new connections are allowed until the previous ones close. This
; option can be used in a peer definition as well, but only takes effect for
; the IP of a dynamic peer after it completes registration.
;
;maxcallnumbers=512
;
; The 'maxcallnumbers_nonvalidated' is used to set the combined number of call
; numbers that can be allocated for connections where call token validation
; has been disabled. Unlike the 'maxcallnumbers' option, this limit is not
; separate for each individual IP address. Any connection resulting in a
; non-call token validated call number being allocated contributes to this
; limit. For use cases, see the call token user guide. This option's
; default value of 8192 should be sufficient in most cases.
;
;maxcallnumbers_nonvalidated=1024
;
; The [callnumberlimits] section allows custom call number limits to be set
; for specific IP addresses and IP address ranges. These limits take precedence
; over the global 'maxcallnumbers' option, but may still be overridden by a
; peer defined 'maxcallnumbers' entry. Note that these limits take effect
; for every individual address within the range, not the range as a whole.
;
;[callnumberlimits]
;10.1.1.0/255.255.255.0 = 24
;10.1.2.0/255.255.255.0 = 32
;
; Guest sections for unauthenticated connection attempts. Just specify an
; empty secret, or provide no secret section.
;

View File

@@ -35,11 +35,17 @@ extern "C" {
#define AST_SENSE_ALLOW 1
/* Host based access control */
struct ast_ha;
struct ast_ha {
/* Host access rule */
struct in_addr netaddr;
struct in_addr netmask;
int sense;
struct ast_ha *next;
};
void ast_free_ha(struct ast_ha *ha);
struct ast_ha *ast_append_ha(char *sense, char *stuff, struct ast_ha *path);
void ast_copy_ha(const struct ast_ha *from, struct ast_ha *to);
struct ast_ha *ast_append_ha(char *sense, const char *stuff, struct ast_ha *path);
int ast_apply_ha(struct ast_ha *ha, struct sockaddr_in *sin);
int ast_get_ip(struct sockaddr_in *sin, const char *value);
int ast_get_ip_or_srv(struct sockaddr_in *sin, const char *value, const char *service);

View File

@@ -290,6 +290,16 @@ enum search_flags {
* This implies that it can be passed to the object's hash function
* for optimized searching. */
OBJ_POINTER = (1 << 3),
/*!
* \brief Continue if a match is not found in the hashed out bucket
*
* This flag is to be used in combination with OBJ_POINTER. This tells
* the ao2_callback() core to keep searching through the rest of the
* buckets if a match is not found in the starting bucket defined by
* the hash value on the argument.
*/
OBJ_CONTINUE = (1 << 4),
};
/*!

View File

@@ -72,14 +72,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/lock.h"
#include "asterisk/srv.h"
struct ast_ha {
/* Host access rule */
struct in_addr netaddr;
struct in_addr netmask;
int sense;
struct ast_ha *next;
};
/* Default IP - if not otherwise set, don't breathe garbage */
static struct in_addr __ourip = { .s_addr = 0x00000000, };
@@ -261,7 +253,7 @@ void ast_free_ha(struct ast_ha *ha)
}
/* Copy HA structure */
static void ast_copy_ha(struct ast_ha *from, struct ast_ha *to)
void ast_copy_ha(const struct ast_ha *from, struct ast_ha *to)
{
memcpy(&to->netaddr, &from->netaddr, sizeof(from->netaddr));
memcpy(&to->netmask, &from->netmask, sizeof(from->netmask));
@@ -303,7 +295,7 @@ struct ast_ha *ast_duplicate_ha_list(struct ast_ha *original)
return ret; /* Return start of list */
}
struct ast_ha *ast_append_ha(char *sense, char *stuff, struct ast_ha *path)
struct ast_ha *ast_append_ha(char *sense, const char *stuff, struct ast_ha *path)
{
struct ast_ha *ha;
char *nm = "255.255.255.255";

View File

@@ -453,7 +453,7 @@ void *ao2_callback(struct ao2_container *c,
const enum search_flags flags,
ao2_callback_fn cb_fn, void *arg)
{
int i, last; /* search boundaries */
int i, start, last; /* search boundaries */
void *ret = NULL;
if (INTERNAL_OBJ(c) == NULL) /* safety check on the argument */
@@ -483,13 +483,15 @@ void *ao2_callback(struct ao2_container *c,
* (this only for the time being. We need to optimize this.)
*/
if ((flags & OBJ_POINTER)) /* we know hash can handle this case */
i = c->hash_fn(arg, flags & OBJ_POINTER) % c->n_buckets;
start = i = c->hash_fn(arg, flags & OBJ_POINTER) % c->n_buckets;
else /* don't know, let's scan all buckets */
i = -1; /* XXX this must be fixed later. */
/* determine the search boundaries: i..last-1 */
if (i < 0) {
i = 0;
start = i = 0;
last = c->n_buckets;
} else if ((flags & OBJ_CONTINUE)) {
last = c->n_buckets;
} else {
last = i + 1;
@@ -545,6 +547,17 @@ void *ao2_callback(struct ao2_container *c,
}
}
AST_LIST_TRAVERSE_SAFE_END
if (ret) {
/* This assumes OBJ_MULTIPLE with !OBJ_NODATA is still not implemented */
break;
}
if (i == c->n_buckets - 1 && (flags & OBJ_POINTER) && (flags & OBJ_CONTINUE)) {
/* Move to the beginning to ensure we check every bucket */
i = -1;
last = start;
}
}
ao2_unlock(c);
return ret;