Coverage Report

Created: 2025-07-18 06:32

/src/opensips/socket_info.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2001-2003 FhG Fokus
3
 *
4
 * This file is part of opensips, a free SIP server.
5
 *
6
 * opensips is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version
10
 *
11
 * opensips is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to" the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19
 */
20
21
/*!
22
 * \file
23
 * \brief Find & manage listen addresses.
24
 * Contains code that initializes and handles server listen addresses
25
 * lists (struct socket_info). It is used mainly on startup.
26
 */
27
28
29
#ifndef socket_info_h
30
#define socket_info_h
31
32
#include <stdlib.h>
33
34
#include "ip_addr.h"
35
#include "dprint.h"
36
#include "globals.h"
37
#include "net/trans.h"
38
#include "ut.h"
39
40
struct last_real_ports {
41
  unsigned short local;
42
  unsigned short remote;
43
};
44
45
struct socket_info {
46
  int socket;
47
  str name; /*!< name - eg.: foo.bar or 10.0.0.1 */
48
  str tag;  /* the tag of the interface, use only in OpenSIPS ecosystem */
49
  struct ip_addr address; /*!< ip address */
50
  str address_str;        /*!< ip address converted to string -- optimization*/
51
  unsigned short port_no;  /*!< port number */
52
  str port_no_str; /*!< port number converted to string -- optimization*/
53
  enum si_flags flags; /*!< SI_IS_IP | SI_IS_LO | SI_IS_MCAST | SI_IS_ANYCAST */
54
  union sockaddr_union su;
55
  int proto; /*!< tcp or udp*/
56
  str sock_str;
57
  str adv_sock_str;
58
  str tag_sock_str;
59
  str adv_name_str; /* Advertised name of this interface */
60
  str adv_port_str; /* Advertised port of this interface */
61
  struct ip_addr adv_address; /* Advertised address in ip_addr form (for find_si) */
62
  unsigned short adv_port;    /* optimization for grep_sock_info() */
63
  unsigned short workers;
64
  unsigned short tos;
65
  struct scaling_profile *s_profile;
66
  void *extra_data;
67
  enum sip_protos internal_proto;
68
69
  /* these are IP-level local/remote ports used during the last write op via
70
   * this sock (or a connection belonging to this sock). These values are 
71
   * optional (populated only by the TCP-based protocol, for ephemeral ports.
72
   * Note: they are populate ONLY by a write op and they are not ever reset,
73
   * they are simply overwritten by the next write op on this socket/conn.
74
   * IMPORTANT: when reading them, be sure you are just after a write ops,
75
   * otherwise you may read old data here */
76
  struct last_real_ports *last_real_ports;
77
};
78
79
struct socket_info_full {
80
  struct socket_info socket_info;
81
  struct last_real_ports last_real_ports;
82
  struct socket_info_full* next;
83
  struct socket_info_full* prev;
84
};
85
86
#define get_socket_real_name(_s) \
87
  (&(_s)->sock_str)
88
89
#define get_socket_sip_name(_s) \
90
  ((_s)->adv_sock_str.len?&(_s)->adv_sock_str:&(_s)->sock_str)
91
92
#define get_socket_internal_name(_s) \
93
  ((_s)->tag_sock_str.len?&(_s)->tag_sock_str:&(_s)->sock_str)
94
95
0
#define NUM_IP_OCTETS 4
96
#define PROTO_NAME_MAX_SIZE  8 /* CHANGEME if you define a bigger protocol name
97
               * currently hep_tcp - biggest proto */
98
99
int new_sock2list(struct socket_id *sid, struct socket_info_full** list);
100
101
int fix_socket_list(struct socket_info_full **);
102
103
/*
104
 * This function will retrieve a list of all ip addresses and ports that
105
 * OpenSIPS is listening on, with respect to the transport protocol specified
106
 * with 'protocol'.
107
 *
108
 * The first parameter, ipList, is a pointer to a pointer. It will be assigned
109
 * new block of memory holding the IP Addresses and ports being listened to
110
 * with respect to 'protocol'.  The array maps a 2D array into a 1 dimensional
111
 * space, and is layed out as follows:
112
 *
113
 * The first NUM_IP_OCTETS indices will be the IP address, and the next index
114
 * the port.  So if NUM_IP_OCTETS is equal to 4 and there are two IP addresses
115
 * found, then:
116
 *
117
 *  - ipList[0] will be the first octet of the first ip address
118
 *  - ipList[3] will be the last octet of the first ip address.
119
 *  - iplist[4] will be the port of the first ip address
120
 *  -
121
 *  - iplist[5] will be the first octet of the first ip address,
122
 *  - and so on.
123
 *
124
 * The function will return the number of sockets which were found.  This can
125
 * be used to index into ipList.
126
 *
127
 * NOTE: This function assigns a block of memory equal to:
128
 *
129
 *            returnedValue * (NUM_IP_OCTETS + 1) * sizeof(int);
130
 *
131
 *       Therefore it is CRUCIAL that you free ipList when you are done with
132
 *       its contents, to avoid a nasty memory leak.
133
 */
134
int get_socket_list_from_proto(unsigned int **ipList, int protocol);
135
136
/*
137
 * Returns the sum of the number of bytes waiting to be consumed on all network
138
 * interfaces and transports that OpenSIPS is listening on.
139
 *
140
 * Note: This currently only works on systems supporting the
141
 *       /proc/net/[tcp|udp] interface.  On other systems, zero will always
142
 *       be returned.  Details of why this is so can be found in
143
 *       network_stats.c
144
 */
145
int get_total_bytes_waiting(int only_proto);
146
147
void print_aliases();
148
149
#define grep_sock_info(_host, _port, _proto) \
150
0
  grep_sock_info_ext(_host, _port, _proto, 0)
151
152
#define grep_internal_sock_info(_host, _port, _proto) \
153
0
  grep_sock_info_ext(_host, _port, _proto, 1)
154
155
const struct socket_info* grep_sock_info_ext(str* host, unsigned short port,
156
                    unsigned short proto, int check_tag);
157
158
const struct socket_info* parse_sock_info(str *spec);
159
160
const struct socket_info* find_si(const struct ip_addr* ip, unsigned short port,
161
                        unsigned short proto);
162
163
#define set_sip_defaults( _port, _proto) \
164
  do { \
165
    if ((_proto)==PROTO_NONE) (_proto) = PROTO_UDP; \
166
    if ((_port)==0) { \
167
      if ((_proto)==PROTO_TLS) (_port) = SIPS_PORT; else\
168
      (_port) = SIP_PORT; \
169
    } \
170
  } while(0)
171
172
173
174
/*! \brief helper function:
175
 * \return next protocol, if the last one is reached return 0
176
 * \note useful for cycling on the supported protocols */
177
static inline int next_proto(unsigned short proto)
178
0
{
179
0
  for( proto++ ; proto<PROTO_LAST ; proto++ )
180
0
    if (protos[proto].id!=PROTO_NONE)
181
0
      return proto;
182
0
  return PROTO_NONE;
183
0
}
Unexecuted instantiation: dprint.c:next_proto
Unexecuted instantiation: pt.c:next_proto
Unexecuted instantiation: statistics.c:next_proto
Unexecuted instantiation: pvar.c:next_proto
Unexecuted instantiation: route.c:next_proto
Unexecuted instantiation: socket_info.c:next_proto
Unexecuted instantiation: ipc.c:next_proto
Unexecuted instantiation: core_stats.c:next_proto
Unexecuted instantiation: pt_scaling.c:next_proto
Unexecuted instantiation: pt_load.c:next_proto
Unexecuted instantiation: sr_module.c:next_proto
Unexecuted instantiation: action.c:next_proto
Unexecuted instantiation: db_insertq.c:next_proto
Unexecuted instantiation: proto_tcp.c:next_proto
Unexecuted instantiation: proto_udp.c:next_proto
Unexecuted instantiation: trans.c:next_proto
Unexecuted instantiation: net_tcp_proc.c:next_proto
Unexecuted instantiation: net_tcp.c:next_proto
Unexecuted instantiation: tcp_common.c:next_proto
Unexecuted instantiation: net_udp.c:next_proto
Unexecuted instantiation: net_tcp_report.c:next_proto
Unexecuted instantiation: event_interface.c:next_proto
Unexecuted instantiation: receive.c:next_proto
Unexecuted instantiation: async.c:next_proto
Unexecuted instantiation: daemonize.c:next_proto
Unexecuted instantiation: timer.c:next_proto
Unexecuted instantiation: reactor.c:next_proto
Unexecuted instantiation: forward.c:next_proto
Unexecuted instantiation: xlog.c:next_proto
Unexecuted instantiation: blacklists.c:next_proto
Unexecuted instantiation: io_wait.c:next_proto
Unexecuted instantiation: sr_module_deps.c:next_proto
Unexecuted instantiation: cfg_reload.c:next_proto
Unexecuted instantiation: signals.c:next_proto
Unexecuted instantiation: msg_translator.c:next_proto
Unexecuted instantiation: cfg.tab.c:next_proto
Unexecuted instantiation: shutdown.c:next_proto
Unexecuted instantiation: core_cmds.c:next_proto
184
185
186
187
/*! \brief gets first non-null socket_info structure
188
 * (useful if for. e.g we are not listening on any udp sockets )
189
 */
190
inline static const struct socket_info* get_first_socket(void)
191
0
{
192
0
  int p;
193
0
194
0
  for( p=0 ; p<PROTO_LAST ; p++ )
195
0
    if (protos[p].listeners)
196
0
      return &protos[p].listeners->socket_info;
197
0
198
0
  return NULL;
199
0
}
Unexecuted instantiation: dprint.c:get_first_socket
Unexecuted instantiation: pt.c:get_first_socket
Unexecuted instantiation: statistics.c:get_first_socket
Unexecuted instantiation: pvar.c:get_first_socket
Unexecuted instantiation: route.c:get_first_socket
Unexecuted instantiation: socket_info.c:get_first_socket
Unexecuted instantiation: ipc.c:get_first_socket
Unexecuted instantiation: core_stats.c:get_first_socket
Unexecuted instantiation: pt_scaling.c:get_first_socket
Unexecuted instantiation: pt_load.c:get_first_socket
Unexecuted instantiation: sr_module.c:get_first_socket
Unexecuted instantiation: action.c:get_first_socket
Unexecuted instantiation: db_insertq.c:get_first_socket
Unexecuted instantiation: proto_tcp.c:get_first_socket
Unexecuted instantiation: proto_udp.c:get_first_socket
Unexecuted instantiation: trans.c:get_first_socket
Unexecuted instantiation: net_tcp_proc.c:get_first_socket
Unexecuted instantiation: net_tcp.c:get_first_socket
Unexecuted instantiation: tcp_common.c:get_first_socket
Unexecuted instantiation: net_udp.c:get_first_socket
Unexecuted instantiation: net_tcp_report.c:get_first_socket
Unexecuted instantiation: event_interface.c:get_first_socket
Unexecuted instantiation: receive.c:get_first_socket
Unexecuted instantiation: async.c:get_first_socket
Unexecuted instantiation: daemonize.c:get_first_socket
Unexecuted instantiation: timer.c:get_first_socket
Unexecuted instantiation: reactor.c:get_first_socket
Unexecuted instantiation: forward.c:get_first_socket
Unexecuted instantiation: xlog.c:get_first_socket
Unexecuted instantiation: blacklists.c:get_first_socket
Unexecuted instantiation: io_wait.c:get_first_socket
Unexecuted instantiation: sr_module_deps.c:get_first_socket
Unexecuted instantiation: cfg_reload.c:get_first_socket
Unexecuted instantiation: signals.c:get_first_socket
Unexecuted instantiation: msg_translator.c:get_first_socket
Unexecuted instantiation: cfg.tab.c:get_first_socket
Unexecuted instantiation: shutdown.c:get_first_socket
Unexecuted instantiation: core_cmds.c:get_first_socket
200
201
202
/*! \brief Sets protocol
203
 * \return -1 on error, 0 on success
204
 */
205
inline static int parse_proto(unsigned char* s, long len, int* proto)
206
0
{
207
0
#define PROTO2UINT(a, b, c) ((  (((unsigned int)(a))<<16)+ \
208
0
                (((unsigned int)(b))<<8)+  \
209
0
                ((unsigned int)(c)) ) | 0x20202020)
210
0
  unsigned int i;
211
0
  unsigned int j;
212
213
  /* must support 2-char arrays for ws
214
   * must support 3-char arrays for udp, tcp, tls, wss
215
   * must support 4-char arrays for sctp
216
   * must support 5-char arrays for ipsec
217
   * must support 7-char arrays for hep_tcp and hep_udp */
218
0
  *proto=PROTO_NONE;
219
0
  if ((len < 2 || len > 5) && len != 7) return -1;
220
221
0
  i=PROTO2UINT(s[0], s[1], s[2]);
222
0
  switch(i){
223
0
    case PROTO2UINT('u', 'd', 'p'):
224
0
      if(len==3) { *proto=PROTO_UDP; return 0; }
225
0
      break;
226
0
    case PROTO2UINT('t', 'c', 'p'):
227
0
      if(len==3) { *proto=PROTO_TCP; return 0; }
228
0
      break;
229
0
    case PROTO2UINT('t', 'l', 's'):
230
0
      if(len==3) { *proto=PROTO_TLS; return 0; }
231
0
      break;
232
0
    case PROTO2UINT('s', 'c', 't'):
233
0
      if(len==4 && (s[3]=='p' || s[3]=='P')) {
234
0
        *proto=PROTO_SCTP; return 0;
235
0
      }
236
0
      break;
237
0
    case PROTO2UINT('w', 's', 's'):
238
0
      if(len==3) { *proto=PROTO_WSS; return 0; }
239
0
      break;
240
0
    case PROTO2UINT('b', 'i', 'n'):
241
0
      if(len==3) { *proto=PROTO_BIN; return 0; }
242
0
      else if(len==4 && (s[3]=='s' || s[3]=='S')) {
243
0
        *proto=PROTO_BINS; return 0;
244
0
      }
245
0
      break;
246
0
    case PROTO2UINT('i', 'p', 's'):
247
0
      if(len==5 && (s[3]|0x20)=='e' && (s[4]|0x20)=='c') {
248
0
        *proto=PROTO_IPSEC; return 0;
249
0
      }
250
0
      return -1;
251
252
0
    case PROTO2UINT('h', 'e', 'p'):
253
0
      if (len != 7 || s[3] != '_') return -1;
254
255
0
      j=PROTO2UINT(s[4], s[5], s[6]);
256
0
      switch (j) {
257
0
        case PROTO2UINT('u','d', 'p'):
258
0
          *proto=PROTO_HEP_UDP;
259
0
          return 0;
260
0
        case PROTO2UINT('t','c', 'p'):
261
0
          *proto=PROTO_HEP_TCP;
262
0
          return 0;
263
0
        case PROTO2UINT('t','l', 's'):
264
0
          *proto=PROTO_HEP_TLS;
265
0
          return 0;
266
0
        default:
267
0
          return -1;
268
0
      }
269
0
      break;
270
0
    case PROTO2UINT('s', 'm', 'p'):
271
0
      if(len==4 && (s[3]=='p' || s[3]=='P')) {
272
0
        *proto=PROTO_SMPP; return 0;
273
0
      }
274
0
      break;
275
0
    case PROTO2UINT('m', 's', 'r'):
276
0
      if(len==4) {
277
0
        if (s[3]=='p' || s[3]=='P') {
278
0
          *proto=PROTO_MSRP; return 0;
279
0
        }
280
0
      } else
281
0
      if(len==5) {
282
0
        if ((s[3]=='p' || s[3]=='P') && (s[4]=='s' || s[4]=='S')) {
283
0
          *proto=PROTO_MSRPS; return 0;
284
0
        }
285
0
      }
286
0
      break;
287
0
    default:
288
0
      if(len==2 && (s[0]|0x20)=='w' && (s[1]|0x20)=='s') {
289
0
        *proto=PROTO_WS; return 0;
290
0
      }
291
0
      return -1;
292
0
  }
293
0
  return -1;
294
0
}
Unexecuted instantiation: dprint.c:parse_proto
Unexecuted instantiation: pt.c:parse_proto
Unexecuted instantiation: statistics.c:parse_proto
Unexecuted instantiation: pvar.c:parse_proto
Unexecuted instantiation: route.c:parse_proto
Unexecuted instantiation: socket_info.c:parse_proto
Unexecuted instantiation: ipc.c:parse_proto
Unexecuted instantiation: core_stats.c:parse_proto
Unexecuted instantiation: pt_scaling.c:parse_proto
Unexecuted instantiation: pt_load.c:parse_proto
Unexecuted instantiation: sr_module.c:parse_proto
Unexecuted instantiation: action.c:parse_proto
Unexecuted instantiation: db_insertq.c:parse_proto
Unexecuted instantiation: proto_tcp.c:parse_proto
Unexecuted instantiation: proto_udp.c:parse_proto
Unexecuted instantiation: trans.c:parse_proto
Unexecuted instantiation: net_tcp_proc.c:parse_proto
Unexecuted instantiation: net_tcp.c:parse_proto
Unexecuted instantiation: tcp_common.c:parse_proto
Unexecuted instantiation: net_udp.c:parse_proto
Unexecuted instantiation: net_tcp_report.c:parse_proto
Unexecuted instantiation: event_interface.c:parse_proto
Unexecuted instantiation: receive.c:parse_proto
Unexecuted instantiation: async.c:parse_proto
Unexecuted instantiation: daemonize.c:parse_proto
Unexecuted instantiation: timer.c:parse_proto
Unexecuted instantiation: reactor.c:parse_proto
Unexecuted instantiation: forward.c:parse_proto
Unexecuted instantiation: xlog.c:parse_proto
Unexecuted instantiation: blacklists.c:parse_proto
Unexecuted instantiation: io_wait.c:parse_proto
Unexecuted instantiation: sr_module_deps.c:parse_proto
Unexecuted instantiation: cfg_reload.c:parse_proto
Unexecuted instantiation: signals.c:parse_proto
Unexecuted instantiation: msg_translator.c:parse_proto
Unexecuted instantiation: cfg.tab.c:parse_proto
Unexecuted instantiation: shutdown.c:parse_proto
Unexecuted instantiation: core_cmds.c:parse_proto
295
296
297
298
/*! \brief
299
 * parses [proto:]host[:port] where proto= udp|tcp|tls
300
 * \return 0 on success and -1 on failure
301
 */
302
inline static int parse_phostport(char* s, int slen, char** host, int* hlen,
303
                          int* port, int* proto)
304
0
{
305
0
  char* first; /* first ':' occurrence */
306
0
  char* second; /* second ':' occurrence */
307
0
  char* p;
308
0
  int   bracket;
309
0
  str   tmp;
310
0
  char* end;
311
312
0
  first=second=0;
313
0
  bracket=0;
314
0
  end = s + slen;
315
316
  /* find the first 2 ':', ignoring possible ipv6 addresses
317
   * (substrings between [])
318
   */
319
0
  for(p=s; p<end ; p++){
320
0
    switch(*p){
321
0
      case '[':
322
0
        bracket++;
323
0
        if (bracket>1) goto error_brackets;
324
0
        break;
325
0
      case ']':
326
0
        bracket--;
327
0
        if (bracket<0) goto error_brackets;
328
0
        break;
329
0
      case ':':
330
0
        if (bracket==0){
331
0
          if (first==0) first=p;
332
0
          else if( second==0) second=p;
333
0
          else goto error_colons;
334
0
        }
335
0
        break;
336
0
    }
337
0
  }
338
0
  if (p==s) return -1;
339
0
  if (*(p-1)==':') goto error_colons;
340
341
0
  if (first==0){ /* no ':' => only host */
342
0
    *host=s;
343
0
    *hlen=(int)(p-s);
344
0
    *port=0;
345
0
    *proto=0;
346
0
    return 0;
347
0
  }
348
0
  if (second){ /* 2 ':' found => check if valid */
349
0
    if (parse_proto((unsigned char*)s, first-s, proto)<0)
350
0
      goto error_proto;
351
0
    tmp.s = second+1;
352
0
    tmp.len = end - tmp.s;
353
0
    if (str2int( &tmp, (unsigned int*)port )==-1) goto error_port;
354
0
    *host=first+1;
355
0
    *hlen=(int)(second-*host);
356
0
    return 0;
357
0
  }
358
  /* only 1 ':' found => it's either proto:host or host:port */
359
0
  tmp.s = first+1;
360
0
  tmp.len = end - tmp.s;
361
0
  if (str2int( &tmp, (unsigned int*)port )==-1) {
362
    /* invalid port => it's proto:host */
363
0
    if (parse_proto((unsigned char*)s, first-s, proto)<0) goto error_proto;
364
0
    *port=0;
365
0
    *host=first+1;
366
0
    *hlen=(int)(p-*host);
367
0
  }else{
368
    /* valid port => its host:port */
369
0
    *proto=0;
370
0
    *host=s;
371
0
    *hlen=(int)(first-*host);
372
0
  }
373
0
  return 0;
374
0
error_brackets:
375
0
  LM_ERR("too many brackets in %s\n", s);
376
0
  return -1;
377
0
error_colons:
378
0
  LM_ERR(" too many colons in %s\n", s);
379
0
  return -1;
380
0
error_proto:
381
0
  LM_ERR("bad protocol in %s\n", s);
382
0
  return -1;
383
0
error_port:
384
0
  LM_ERR("bad port number in %s\n", s);
385
0
  return -1;
386
0
}
Unexecuted instantiation: dprint.c:parse_phostport
Unexecuted instantiation: pt.c:parse_phostport
Unexecuted instantiation: statistics.c:parse_phostport
Unexecuted instantiation: pvar.c:parse_phostport
Unexecuted instantiation: route.c:parse_phostport
Unexecuted instantiation: socket_info.c:parse_phostport
Unexecuted instantiation: ipc.c:parse_phostport
Unexecuted instantiation: core_stats.c:parse_phostport
Unexecuted instantiation: pt_scaling.c:parse_phostport
Unexecuted instantiation: pt_load.c:parse_phostport
Unexecuted instantiation: sr_module.c:parse_phostport
Unexecuted instantiation: action.c:parse_phostport
Unexecuted instantiation: db_insertq.c:parse_phostport
Unexecuted instantiation: proto_tcp.c:parse_phostport
Unexecuted instantiation: proto_udp.c:parse_phostport
Unexecuted instantiation: trans.c:parse_phostport
Unexecuted instantiation: net_tcp_proc.c:parse_phostport
Unexecuted instantiation: net_tcp.c:parse_phostport
Unexecuted instantiation: tcp_common.c:parse_phostport
Unexecuted instantiation: net_udp.c:parse_phostport
Unexecuted instantiation: net_tcp_report.c:parse_phostport
Unexecuted instantiation: event_interface.c:parse_phostport
Unexecuted instantiation: receive.c:parse_phostport
Unexecuted instantiation: async.c:parse_phostport
Unexecuted instantiation: daemonize.c:parse_phostport
Unexecuted instantiation: timer.c:parse_phostport
Unexecuted instantiation: reactor.c:parse_phostport
Unexecuted instantiation: forward.c:parse_phostport
Unexecuted instantiation: xlog.c:parse_phostport
Unexecuted instantiation: blacklists.c:parse_phostport
Unexecuted instantiation: io_wait.c:parse_phostport
Unexecuted instantiation: sr_module_deps.c:parse_phostport
Unexecuted instantiation: cfg_reload.c:parse_phostport
Unexecuted instantiation: signals.c:parse_phostport
Unexecuted instantiation: msg_translator.c:parse_phostport
Unexecuted instantiation: cfg.tab.c:parse_phostport
Unexecuted instantiation: shutdown.c:parse_phostport
Unexecuted instantiation: core_cmds.c:parse_phostport
387
388
389
/* function will write the proto as string, starting from the p pointer. The
390
   new resulting pointer will be returned (where writing ended) */
391
static inline char* proto2str(int proto, char *p)
392
0
{
393
0
  switch (proto) {
394
0
    case PROTO_UDP:
395
0
      *(p++) = 'u';
396
0
      *(p++) = 'd';
397
0
      *(p++) = 'p';
398
0
      break;
399
0
    case PROTO_TCP:
400
0
      *(p++) = 't';
401
0
      *(p++) = 'c';
402
0
      *(p++) = 'p';
403
0
      break;
404
0
    case PROTO_TLS:
405
0
      *(p++) = 't';
406
0
      *(p++) = 'l';
407
0
      *(p++) = 's';
408
0
      break;
409
0
    case PROTO_SCTP:
410
0
      *(p++) = 's';
411
0
      *(p++) = 'c';
412
0
      *(p++) = 't';
413
0
      *(p++) = 'p';
414
0
      break;
415
0
    case PROTO_WS:
416
0
      *(p++) = 'w';
417
0
      *(p++) = 's';
418
0
      break;
419
0
    case PROTO_WSS:
420
0
      *(p++) = 'w';
421
0
      *(p++) = 's';
422
0
      *(p++) = 's';
423
0
      break;
424
0
    case PROTO_IPSEC:
425
0
      *(p++) = 'i';
426
0
      *(p++) = 'p';
427
0
      *(p++) = 's';
428
0
      *(p++) = 'e';
429
0
      *(p++) = 'c';
430
0
      break;
431
0
    case PROTO_BIN:
432
0
      *(p++) = 'b';
433
0
      *(p++) = 'i';
434
0
      *(p++) = 'n';
435
0
      break;
436
0
    case PROTO_BINS:
437
0
      *(p++) = 'b';
438
0
      *(p++) = 'i';
439
0
      *(p++) = 'n';
440
0
      *(p++) = 's';
441
0
      break;
442
0
    case PROTO_HEP_UDP:
443
0
      *(p++) = 'h';
444
0
      *(p++) = 'e';
445
0
      *(p++) = 'p';
446
0
      *(p++) = '_';
447
0
      *(p++) = 'u';
448
0
      *(p++) = 'd';
449
0
      *(p++) = 'p';
450
0
      break;
451
0
    case PROTO_HEP_TCP:
452
0
      *(p++) = 'h';
453
0
      *(p++) = 'e';
454
0
      *(p++) = 'p';
455
0
      *(p++) = '_';
456
0
      *(p++) = 't';
457
0
      *(p++) = 'c';
458
0
      *(p++) = 'p';
459
0
      break;
460
0
    case PROTO_HEP_TLS:
461
0
      *(p++) = 'h';
462
0
      *(p++) = 'e';
463
0
      *(p++) = 'p';
464
0
      *(p++) = '_';
465
0
      *(p++) = 't';
466
0
      *(p++) = 'l';
467
0
      *(p++) = 's';
468
0
      break;
469
0
    case PROTO_SMPP:
470
0
      *(p++) = 's';
471
0
      *(p++) = 'm';
472
0
      *(p++) = 'p';
473
0
      *(p++) = 'p';
474
0
      break;
475
0
    case PROTO_MSRP:
476
0
      *(p++) = 'm';
477
0
      *(p++) = 's';
478
0
      *(p++) = 'r';
479
0
      *(p++) = 'p';
480
0
      break;
481
0
    case PROTO_MSRPS:
482
0
      *(p++) = 'm';
483
0
      *(p++) = 's';
484
0
      *(p++) = 'r';
485
0
      *(p++) = 'p';
486
0
      *(p++) = 's';
487
0
      break;
488
489
0
    default:
490
0
      LM_CRIT("unsupported proto %d\n", proto);
491
0
  }
492
493
0
  return p;
494
0
}
Unexecuted instantiation: dprint.c:proto2str
Unexecuted instantiation: pt.c:proto2str
Unexecuted instantiation: statistics.c:proto2str
Unexecuted instantiation: pvar.c:proto2str
Unexecuted instantiation: route.c:proto2str
Unexecuted instantiation: socket_info.c:proto2str
Unexecuted instantiation: ipc.c:proto2str
Unexecuted instantiation: core_stats.c:proto2str
Unexecuted instantiation: pt_scaling.c:proto2str
Unexecuted instantiation: pt_load.c:proto2str
Unexecuted instantiation: sr_module.c:proto2str
Unexecuted instantiation: action.c:proto2str
Unexecuted instantiation: db_insertq.c:proto2str
Unexecuted instantiation: proto_tcp.c:proto2str
Unexecuted instantiation: proto_udp.c:proto2str
Unexecuted instantiation: trans.c:proto2str
Unexecuted instantiation: net_tcp_proc.c:proto2str
Unexecuted instantiation: net_tcp.c:proto2str
Unexecuted instantiation: tcp_common.c:proto2str
Unexecuted instantiation: net_udp.c:proto2str
Unexecuted instantiation: net_tcp_report.c:proto2str
Unexecuted instantiation: event_interface.c:proto2str
Unexecuted instantiation: receive.c:proto2str
Unexecuted instantiation: async.c:proto2str
Unexecuted instantiation: daemonize.c:proto2str
Unexecuted instantiation: timer.c:proto2str
Unexecuted instantiation: reactor.c:proto2str
Unexecuted instantiation: forward.c:proto2str
Unexecuted instantiation: xlog.c:proto2str
Unexecuted instantiation: blacklists.c:proto2str
Unexecuted instantiation: io_wait.c:proto2str
Unexecuted instantiation: sr_module_deps.c:proto2str
Unexecuted instantiation: cfg_reload.c:proto2str
Unexecuted instantiation: signals.c:proto2str
Unexecuted instantiation: msg_translator.c:proto2str
Unexecuted instantiation: cfg.tab.c:proto2str
Unexecuted instantiation: shutdown.c:proto2str
Unexecuted instantiation: core_cmds.c:proto2str
495
496
/* Similar to proto2str(), but proto is written in uppercase. The
497
   new resulting pointer will be returned (where writing ended) */
498
static inline char* proto2upper(int proto, char *p)
499
0
{
500
0
  switch (proto) {
501
0
  case PROTO_UDP:
502
0
    p = memcpy(p, STR_L("UDP")) + sizeof("UDP")-1;
503
0
    break;
504
0
  case PROTO_TCP:
505
0
    p = memcpy(p, STR_L("TCP")) + sizeof("TCP")-1;
506
0
    break;
507
0
  case PROTO_TLS:
508
0
    p = memcpy(p, STR_L("TLS")) + sizeof("TLS")-1;
509
0
    break;
510
0
  case PROTO_SCTP:
511
0
    p = memcpy(p, STR_L("SCTP")) + sizeof("SCTP")-1;
512
0
    break;
513
0
  case PROTO_WS:
514
0
    p = memcpy(p, STR_L("WS")) + sizeof("WS")-1;
515
0
    break;
516
0
  case PROTO_WSS:
517
0
    p = memcpy(p, STR_L("WSS")) + sizeof("WSS")-1;
518
0
    break;
519
0
  case PROTO_BIN:
520
0
    p = memcpy(p, STR_L("BIN")) + sizeof("BIN")-1;
521
0
    break;
522
0
  case PROTO_BINS:
523
0
    p = memcpy(p, STR_L("BINS")) + sizeof("BINS")-1;
524
0
    break;
525
0
  case PROTO_HEP_UDP:
526
0
    p = memcpy(p, STR_L("HEP_UDP")) + sizeof("HEP_UDP")-1;
527
0
    break;
528
0
  case PROTO_HEP_TCP:
529
0
    p = memcpy(p, STR_L("HEP_TCP")) + sizeof("HEP_TCP")-1;
530
0
    break;
531
0
  case PROTO_SMPP:
532
0
    p = memcpy(p, STR_L("SMPP")) + sizeof("SMPP")-1;
533
0
    break;
534
0
  case PROTO_MSRP:
535
0
    p = memcpy(p, STR_L("MSRP")) + sizeof("MSRP")-1;
536
0
    break;
537
0
  case PROTO_MSRPS:
538
0
    p = memcpy(p, STR_L("MSRPS")) + sizeof("MSRPS")-1;
539
0
    break;
540
0
  default:
541
0
    LM_CRIT("unsupported proto %d\n", proto);
542
0
  }
543
0
544
0
  return p;
545
0
}
Unexecuted instantiation: dprint.c:proto2upper
Unexecuted instantiation: pt.c:proto2upper
Unexecuted instantiation: statistics.c:proto2upper
Unexecuted instantiation: pvar.c:proto2upper
Unexecuted instantiation: route.c:proto2upper
Unexecuted instantiation: socket_info.c:proto2upper
Unexecuted instantiation: ipc.c:proto2upper
Unexecuted instantiation: core_stats.c:proto2upper
Unexecuted instantiation: pt_scaling.c:proto2upper
Unexecuted instantiation: pt_load.c:proto2upper
Unexecuted instantiation: sr_module.c:proto2upper
Unexecuted instantiation: action.c:proto2upper
Unexecuted instantiation: db_insertq.c:proto2upper
Unexecuted instantiation: proto_tcp.c:proto2upper
Unexecuted instantiation: proto_udp.c:proto2upper
Unexecuted instantiation: trans.c:proto2upper
Unexecuted instantiation: net_tcp_proc.c:proto2upper
Unexecuted instantiation: net_tcp.c:proto2upper
Unexecuted instantiation: tcp_common.c:proto2upper
Unexecuted instantiation: net_udp.c:proto2upper
Unexecuted instantiation: net_tcp_report.c:proto2upper
Unexecuted instantiation: event_interface.c:proto2upper
Unexecuted instantiation: receive.c:proto2upper
Unexecuted instantiation: async.c:proto2upper
Unexecuted instantiation: daemonize.c:proto2upper
Unexecuted instantiation: timer.c:proto2upper
Unexecuted instantiation: reactor.c:proto2upper
Unexecuted instantiation: forward.c:proto2upper
Unexecuted instantiation: xlog.c:proto2upper
Unexecuted instantiation: blacklists.c:proto2upper
Unexecuted instantiation: io_wait.c:proto2upper
Unexecuted instantiation: sr_module_deps.c:proto2upper
Unexecuted instantiation: cfg_reload.c:proto2upper
Unexecuted instantiation: signals.c:proto2upper
Unexecuted instantiation: msg_translator.c:proto2upper
Unexecuted instantiation: cfg.tab.c:proto2upper
Unexecuted instantiation: shutdown.c:proto2upper
Unexecuted instantiation: core_cmds.c:proto2upper
546
547
static inline char *proto2a(int proto)
548
0
{
549
0
  static char b[PROTO_NAME_MAX_SIZE+1];
550
0
  char *p;
551
552
  /* print the proto name */
553
0
  p = proto2str( proto, b);
554
555
  /* make it null terminated */
556
0
  *p = '\0';
557
558
0
  return  b;
559
0
}
Unexecuted instantiation: dprint.c:proto2a
Unexecuted instantiation: pt.c:proto2a
Unexecuted instantiation: statistics.c:proto2a
Unexecuted instantiation: pvar.c:proto2a
Unexecuted instantiation: route.c:proto2a
Unexecuted instantiation: socket_info.c:proto2a
Unexecuted instantiation: ipc.c:proto2a
Unexecuted instantiation: core_stats.c:proto2a
Unexecuted instantiation: pt_scaling.c:proto2a
Unexecuted instantiation: pt_load.c:proto2a
Unexecuted instantiation: sr_module.c:proto2a
Unexecuted instantiation: action.c:proto2a
Unexecuted instantiation: db_insertq.c:proto2a
Unexecuted instantiation: proto_tcp.c:proto2a
Unexecuted instantiation: proto_udp.c:proto2a
Unexecuted instantiation: trans.c:proto2a
Unexecuted instantiation: net_tcp_proc.c:proto2a
Unexecuted instantiation: net_tcp.c:proto2a
Unexecuted instantiation: tcp_common.c:proto2a
Unexecuted instantiation: net_udp.c:proto2a
Unexecuted instantiation: net_tcp_report.c:proto2a
Unexecuted instantiation: event_interface.c:proto2a
Unexecuted instantiation: receive.c:proto2a
Unexecuted instantiation: async.c:proto2a
Unexecuted instantiation: daemonize.c:proto2a
Unexecuted instantiation: timer.c:proto2a
Unexecuted instantiation: reactor.c:proto2a
Unexecuted instantiation: forward.c:proto2a
Unexecuted instantiation: xlog.c:proto2a
Unexecuted instantiation: blacklists.c:proto2a
Unexecuted instantiation: io_wait.c:proto2a
Unexecuted instantiation: sr_module_deps.c:proto2a
Unexecuted instantiation: cfg_reload.c:proto2a
Unexecuted instantiation: signals.c:proto2a
Unexecuted instantiation: msg_translator.c:proto2a
Unexecuted instantiation: cfg.tab.c:proto2a
Unexecuted instantiation: shutdown.c:proto2a
Unexecuted instantiation: core_cmds.c:proto2a
560
561
562
#define MAX_SOCKET_STR ( 4 + 1 + IP_ADDR_MAX_STR_SIZE+1+INT2STR_MAX_LEN+1)
563
0
#define sock_str_len(_sock,_type) (3 + 1*((_sock)->proto==PROTO_SCTP) + 1 + \
564
0
    (((_type)==0) ? (_sock)->address_str.len + (_sock)->port_no_str.len + 1 : \
565
0
        (((_type)==1) ? (_sock)->adv_name_str.len + (_sock)->adv_port_str.len + 1 : \
566
0
            (_sock)->tag.len)))
567
568
/* builds the full name of the socket ( proto:name[:port] ), using different
569
   naming for it, depending on the "type" parameter :
570
      0 - real name
571
      1 - advertised name
572
      2 - tagged name
573
*/
574
static inline char* socket2str(const struct socket_info *sock, char *s, int *len, int type)
575
0
{
576
0
  static char buf[MAX_SOCKET_STR];
577
0
  char *p,*p1;
578
579
0
  if (s) {
580
    /* buffer provided -> check lenght */
581
0
    if ( sock_str_len(sock,type) > *len ) {
582
0
      LM_ERR("buffer too short\n");
583
0
      return 0;
584
0
    }
585
0
    p = p1 = s;
586
0
  } else {
587
0
    p = p1 = buf;
588
0
  }
589
590
0
  p = proto2str( sock->proto, p);
591
0
  if (p==NULL) return 0;
592
593
0
  *(p++) = ':';
594
0
  switch (type) {
595
0
  case 0:
596
0
    memcpy( p, sock->address_str.s, sock->address_str.len);
597
0
    p += sock->address_str.len;
598
0
    *(p++) = ':';
599
0
    memcpy( p, sock->port_no_str.s, sock->port_no_str.len);
600
0
    p += sock->port_no_str.len;
601
0
    break;
602
0
  case 1:
603
0
    memcpy( p, sock->adv_name_str.s, sock->adv_name_str.len);
604
0
    p += sock->adv_name_str.len;
605
0
    *(p++) = ':';
606
0
    memcpy( p, sock->adv_port_str.s, sock->adv_port_str.len);
607
0
    p += sock->adv_port_str.len;
608
0
    break;
609
0
  case 2:
610
0
    memcpy( p, sock->tag.s, sock->tag.len);
611
0
    p += sock->tag.len;
612
0
    break;
613
0
  default:
614
0
    LM_BUG("unsupported type %d in printing socket name <%.*s>\n",
615
0
      type, sock->name.len, sock->name.s);
616
0
  }
617
0
  *len = (int)(long)(p-p1);
618
0
  LM_DBG("<%.*s>\n",*len,p1);
619
0
  return p1;
620
0
}
Unexecuted instantiation: dprint.c:socket2str
Unexecuted instantiation: pt.c:socket2str
Unexecuted instantiation: statistics.c:socket2str
Unexecuted instantiation: pvar.c:socket2str
Unexecuted instantiation: route.c:socket2str
Unexecuted instantiation: socket_info.c:socket2str
Unexecuted instantiation: ipc.c:socket2str
Unexecuted instantiation: core_stats.c:socket2str
Unexecuted instantiation: pt_scaling.c:socket2str
Unexecuted instantiation: pt_load.c:socket2str
Unexecuted instantiation: sr_module.c:socket2str
Unexecuted instantiation: action.c:socket2str
Unexecuted instantiation: db_insertq.c:socket2str
Unexecuted instantiation: proto_tcp.c:socket2str
Unexecuted instantiation: proto_udp.c:socket2str
Unexecuted instantiation: trans.c:socket2str
Unexecuted instantiation: net_tcp_proc.c:socket2str
Unexecuted instantiation: net_tcp.c:socket2str
Unexecuted instantiation: tcp_common.c:socket2str
Unexecuted instantiation: net_udp.c:socket2str
Unexecuted instantiation: net_tcp_report.c:socket2str
Unexecuted instantiation: event_interface.c:socket2str
Unexecuted instantiation: receive.c:socket2str
Unexecuted instantiation: async.c:socket2str
Unexecuted instantiation: daemonize.c:socket2str
Unexecuted instantiation: timer.c:socket2str
Unexecuted instantiation: reactor.c:socket2str
Unexecuted instantiation: forward.c:socket2str
Unexecuted instantiation: xlog.c:socket2str
Unexecuted instantiation: blacklists.c:socket2str
Unexecuted instantiation: io_wait.c:socket2str
Unexecuted instantiation: sr_module_deps.c:socket2str
Unexecuted instantiation: cfg_reload.c:socket2str
Unexecuted instantiation: signals.c:socket2str
Unexecuted instantiation: msg_translator.c:socket2str
Unexecuted instantiation: cfg.tab.c:socket2str
Unexecuted instantiation: shutdown.c:socket2str
Unexecuted instantiation: core_cmds.c:socket2str
621
622
623
#define get_sock_info_list(_proto) \
624
0
  (((_proto)>=PROTO_FIRST && (_proto)<PROTO_LAST)?(&protos[_proto].listeners):0)
625
626
int is_localhost(struct socket_info *si);
627
int fix_socket(struct socket_info_full *sif, int add_aliases);
628
629
630
int probe_max_sock_buff( int sock, int buff_choice, int buff_max,
631
    int buff_increment);
632
633
struct socket_id *socket_info2id(struct socket_info *si);
634
struct socket_info_full* new_sock_info( struct socket_id *sid);
635
void push_sock2list(struct socket_info_full *si);
636
void pop_sock2list(struct socket_info_full *si);
637
void free_sock_info(struct socket_info_full* si);
638
int update_default_socket_info(struct socket_info *si);
639
void remove_default_socket_info(struct socket_info *si);
640
641
#endif