Kamailio SIP Server Initialization and Configuration Flow
This codemap traces the Kamailio SIP server’s initialization and configuration loading process, from main() through configuration parsing to socket setup. Key locations include the entry point [1a], configuration parsing invocation [1c], listen statement grammar rules [2a], socket_info structure definition [2d], and advanced features like advertised addresses [5a].
1. Main Entry Point and Configuration Loading
Traces the startup sequence from main() through configuration file parsing
1a. Application Entry Point (main.c:2198)
Main function begins Kamailio startup process
int main(int argc, char **argv)
1b. Set Configuration Input (main.c:2760)
Assign configuration file stream to parser
yyin = cfg_stream;
1c. Parse Configuration (main.c:2763)
Invoke Bison parser to process configuration file
r = yyparse();
1d. Validate Parsing Results (main.c:2768)
Check for configuration parsing errors
if((r != 0) || (cfg_errors) || (pp_ifdef_level_check() < 0)) {
2. Listen Statement Processing
Shows how configuration listen directives are parsed and converted to socket structures
2a. Listen Grammar Rule (cfg.y:1711)
Basic listen statement pattern matching in configuration grammar
| LISTEN EQUAL id_lst {
2b. Add Listen Interface (cfg.y:1713)
Create socket_info structure from parsed listen directive
if (add_listen_iface( lst_tmp->addr_lst->name,
2c. Socket Interface Creation (socket_info.c:1244)
Function that creates and initializes socket_info structures
int add_listen_iface(char *name, struct name_lst *addr_l, unsigned short port,
2d. Socket Structure Definition (ip_addr.h:149)
Core data structure holding network binding information
typedef struct socket_info
3. Socket Information Management
Demonstrates how socket_info structures store network configuration
3a. Socket File Descriptor (ip_addr.h:151)
Actual socket file descriptor for network communication
int socket;
3b. Interface Name (ip_addr.h:153)
Hostname or IP address string representation
str name;
3c. IP Address Structure (ip_addr.h:154)
Binary IP address representation
struct ip_addr address;
3d. Protocol Type (ip_addr.h:162)
Protocol identifier (UDP/TCP/TLS/SCTP)
char proto;
3e. Worker Process Count (ip_addr.h:167)
Number of worker processes for this socket
int workers;
4. Configuration Lexer Integration
Shows how the lexer tokenizes configuration files for the parser
4a. Parser Header Include (cfg.lex:42)
Include generated parser token definitions
#include "cfg.tab.h"
4b. Parser Function Declaration (main.c:546)
External declaration of Bison-generated parser function
extern int yyparse(void);
4c. Lexer Input Stream (main.c:545)
Global variable for lexer input source
extern FILE *yyin;
4d. Error Handler (cfg.lex:47)
Custom error handling for lexer failures
static void ksr_yy_fatal_error(const char* msg);
5. Advanced Listen Features
Illustrates complex listen directive processing with advertising and virtual sockets
5a. Advertise Address Pattern (cfg.y:1761)
Listen directive with external advertising address
| LISTEN EQUAL id_lst ADVERTISE listen_id COLON NUMBER {
5b. Create Advertised Socket (cfg.y:1763)
Add socket with external advertising information
if (add_listen_advertise_iface( lst_tmp->addr_lst->name,
5c. Advertising Information (ip_addr.h:170)
Structure holding external address details
struct advertise_info useinfo;
5d. Virtual Socket Flag (cfg.y:1725)
Mark socket as virtual for internal routing
lst_tmp->flags |= SI_IS_VIRTUAL;