Coverage Report

Created: 2026-08-13 06:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opensips/net/tcp_conn.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
 * History:
22
 * --------
23
 *  2003-01-29  tcp buffer size ++-ed to allow for 0-terminator
24
 *  2003-06-30  added tcp_connection flags & state (andrei)
25
 *  2003-10-27  tcp port aliases support added (andrei)
26
 *  2012-01-19  added TCP keepalive support
27
 */
28
29
/*!
30
 * \file
31
 * \brief TCP protocol support
32
 */
33
34
35
36
#ifndef _NET_tcp_conn_h
37
#define _NET_tcp_conn_h
38
39
#include "../locking.h"
40
#include "tcp_conn_defs.h"
41
42
43
/*!< TCP connection lifetime, in seconds */
44
#define DEFAULT_TCP_CONNECTION_LIFETIME 120
45
/*!< TCP socket backlog count */
46
#define DEFAULT_TCP_SOCKET_BACKLOG 10
47
/*!< If a connect doesn't complete in more than 100ms, timeout */
48
#define DEFAULT_TCP_CONNECT_TIMEOUT 100
49
/*!< Maximum number of connections */
50
#define DEFAULT_TCP_MAX_CONNECTIONS 2048
51
/*!< how often "tcp main" checks for timeout*/
52
#define TCP_MAIN_SELECT_TIMEOUT 1000 /* ms */
53
54
55
/*! \brief add a tcpconn to a list
56
 * list head, new element, next member, prev member */
57
#define tcpconn_listadd(head, c, next, prev) \
58
0
  do{ \
59
0
    /* add it at the beginning of the list*/ \
60
0
    (c)->next=(head); \
61
0
    (c)->prev=0; \
62
0
    if ((head)) (head)->prev=(c); \
63
0
    (head)=(c); \
64
0
  } while(0)
65
66
67
/*! \brief remove a tcpconn from a list*/
68
#define tcpconn_listrm(head, c, next, prev) \
69
0
  do{ \
70
0
    if ((head)==(c)) (head)=(c)->next; \
71
0
    if ((c)->next) (c)->next->prev=(c)->prev; \
72
0
    if ((c)->prev) (c)->prev->next=(c)->next; \
73
0
    (c)->prev = (c)->next = NULL; \
74
0
  }while(0)
75
76
0
#define TCPCONN_GET_PART(_id)  (_id%TCP_PARTITION_SIZE)
77
0
#define TCP_PART(_id)  (tcp_parts[TCPCONN_GET_PART(_id)])
78
79
#define TCPCONN_LOCK(_id) \
80
0
  lock_get(tcp_parts[TCPCONN_GET_PART(_id)].tcpconn_lock);
81
#define TCPCONN_UNLOCK(_id) \
82
0
  lock_release(tcp_parts[TCPCONN_GET_PART(_id)].tcpconn_lock);
83
84
0
#define TCP_ALIAS_HASH_SIZE 1024
85
0
#define TCP_ID_HASH_SIZE 1024
86
87
static inline unsigned tcp_addr_hash(struct ip_addr* ip, unsigned short port)
88
0
{
89
0
  if(ip->len==4) return (ip->u.addr32[0]^port)&(TCP_ALIAS_HASH_SIZE-1);
90
0
  else if (ip->len==16)
91
0
      return (ip->u.addr32[0]^ip->u.addr32[1]^ip->u.addr32[2]^
92
0
          ip->u.addr32[3]^port) & (TCP_ALIAS_HASH_SIZE-1);
93
0
  else{
94
0
    LM_CRIT("bad len %d for an ip address\n", ip->len);
95
0
    return 0;
96
0
  }
97
0
}
Unexecuted instantiation: net_tcp_proc.c:tcp_addr_hash
Unexecuted instantiation: net_tcp.c:tcp_addr_hash
98
99
0
#define tcp_id_hash(id) (id&(TCP_ID_HASH_SIZE-1))
100
101
void tcpconn_put(struct tcp_connection* c);
102
103
104
#endif