Coverage Report

Created: 2026-03-11 06:49

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