Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 46) +++ channels/chan_sip.c (working copy) @@ -751,6 +751,14 @@ SIP_TRANSPORT_TLS = 1 << 2, /*!< TCP/TLS - reliable and secure transport for signalling */ }; +/*! \brief Automatic peer registration behavior +*/ +enum autocreatepeer_mode { + AUTOPEERS_DISABLED = 0, /*!< Automatic peer creation disabled */ + AUTOPEERS_VOLATILE, /*!< Automatic peers dropped on sip reload (pre-1.8 behavior) */ + AUTOPEERS_PERSIST /*!< Automatic peers survive sip configuration reload */ +}; + /*! \brief definition of a sip proxy server * * For outbound proxies, a sip_peer will contain a reference to a @@ -1000,7 +1008,7 @@ #define DEFAULT_NOTIFYRINGING TRUE /*!< Notify devicestate system on ringing state */ #define DEFAULT_NOTIFYCID DISABLED /*!< Include CID with ringing notifications */ #define DEFAULT_PEDANTIC FALSE /*!< Avoid following SIP standards for dialog matching */ -#define DEFAULT_AUTOCREATEPEER FALSE /*!< Don't create peers automagically */ +#define DEFAULT_AUTOCREATEPEER AUTOPEERS_DISABLED /*!< Don't create peers automagically */ #define DEFAULT_MATCHEXTERNIPLOCALLY FALSE /*!< Match extern IP locally default setting */ #define DEFAULT_QUALIFY FALSE /*!< Don't monitor devices */ #define DEFAULT_CALLEVENTS FALSE /*!< Extra manager SIP call events */ @@ -1054,7 +1062,7 @@ int rtautoclear; /*!< Realtime ?? */ int directrtpsetup; /*!< Enable support for Direct RTP setup (no re-invites) */ int pedanticsipchecking; /*!< Extra checking ? Default off */ - int autocreatepeer; /*!< Auto creation of peers at registration? Default off. */ + enum autocreatepeer_mode autocreatepeer; /*!< Auto creation of peers at registration? Default off. */ int srvlookup; /*!< SRV Lookup on or off. Default is on */ int allowguest; /*!< allow unauthenticated peers to connect? */ int alwaysauthreject; /*!< Send 401 Unauthorized for all failing requests */ @@ -13114,7 +13122,7 @@ } } } - if (!peer && sip_cfg.autocreatepeer) { + if (!peer && sip_cfg.autocreatepeer != AUTOPEERS_DISABLED) { /* Create peer if we have autocreate mode enabled */ peer = temp_peer(name); if (peer) { @@ -14484,7 +14492,19 @@ return map_s_x(strefreshers, s, -1); } +/* Autocreatepeer modes */ +static struct _map_x_s autopeermodes[] = { + { AUTOPEERS_DISABLED, "Off"}, + { AUTOPEERS_VOLATILE, "Volatile"}, + { AUTOPEERS_PERSIST, "Persisted"}, + { -1, NULL}, +}; +static const char *autocreatepeer2str(enum autocreatepeer_mode r) +{ + return map_x_s(autopeermodes, r, "Unknown"); +} + static int peer_status(struct sip_peer *peer, char *status, int statuslen) { int res = 0; @@ -16033,7 +16053,7 @@ ast_cli(a->fd, " Videosupport: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT))); ast_cli(a->fd, " Textsupport: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_TEXTSUPPORT))); ast_cli(a->fd, " Ignore SDP sess. ver.: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_IGNORESDPVERSION))); - ast_cli(a->fd, " AutoCreate Peer: %s\n", cli_yesno(sip_cfg.autocreatepeer)); + ast_cli(a->fd, " AutoCreate Peer: %s\n", autocreatepeer2str(sip_cfg.autocreatepeer)); ast_cli(a->fd, " Match Auth Username: %s\n", cli_yesno(global_match_auth_username)); ast_cli(a->fd, " Allow unknown access: %s\n", cli_yesno(sip_cfg.allowguest)); ast_cli(a->fd, " Allow subscriptions: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWSUBSCRIBE))); @@ -24349,7 +24369,9 @@ static int peer_markall_func(void *device, void *arg, int flags) { struct sip_peer *peer = device; - peer->the_mark = 1; + if (!peer->selfdestruct || sip_cfg.autocreatepeer != AUTOPEERS_PERSIST) { + peer->the_mark = 1; + } return 0; } @@ -24809,7 +24831,11 @@ proxy_update(&sip_cfg.outboundproxy); } else if (!strcasecmp(v->name, "autocreatepeer")) { - sip_cfg.autocreatepeer = ast_true(v->value); + if (!strcasecmp(v->value, "persist")) { + sip_cfg.autocreatepeer = AUTOPEERS_PERSIST; + } else { + sip_cfg.autocreatepeer = ast_true(v->value) ? AUTOPEERS_VOLATILE : AUTOPEERS_DISABLED; + } } else if (!strcasecmp(v->name, "match_auth_username")) { global_match_auth_username = ast_true(v->value); } else if (!strcasecmp(v->name, "srvlookup")) {