/src/opensips/net/tcp_conn_profile.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2022 - OpenSIPS Solutions |
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 | | #include "tcp_conn_profile.h" |
22 | | #include "../str.h" |
23 | | #include "../ut.h" |
24 | | |
25 | | /* a collection of default TCP connection settings which can be overridden |
26 | | * by defining specific settings (per TCP path) using the "tcp_mgm" module */ |
27 | | struct tcp_conn_profile tcp_con_df_profile; |
28 | | |
29 | | static int tcp_con_get_df_profile(const union sockaddr_union *_, |
30 | | const union sockaddr_union *__, enum sip_protos ___, |
31 | | struct tcp_conn_profile *out_profile) |
32 | 0 | { |
33 | 0 | *out_profile = tcp_con_df_profile; |
34 | 0 | return 0; |
35 | 0 | } |
36 | | |
37 | | |
38 | | /* global function/variable which may be overridden by tcp_mgm */ |
39 | | int (*tcp_con_get_profile)(const union sockaddr_union *remote, |
40 | | const union sockaddr_union *local, enum sip_protos proto, |
41 | | struct tcp_conn_profile *out_profile) = tcp_con_get_df_profile; |
42 | | |
43 | | struct tcp_conn_attr_key tcp_con_attr[] = { |
44 | | {str_init("max_msg_chunks"), TCP_ATTR_MAX_MSG_CHUNKS}, |
45 | | {STR_NULL, 0}, |
46 | | }; |
47 | | |
48 | | int tcp_con_attr_lookup(const str *attr, enum tcp_conn_attr *out_val) |
49 | 0 | { |
50 | 0 | struct tcp_conn_attr_key *it; |
51 | |
|
52 | 0 | for (it = tcp_con_attr; it->attr_key.s; it++) |
53 | 0 | if (str_match(&it->attr_key, attr)) { |
54 | 0 | *out_val = it->attr; |
55 | 0 | return 1; |
56 | 0 | } |
57 | | |
58 | 0 | return 0; |
59 | 0 | } |
60 | | |
61 | | void tcp_init_con_profiles(void) |
62 | 0 | { |
63 | | /* fill in a default profile, which simply gathers all TCP globals */ |
64 | 0 | tcp_con_df_profile = (struct tcp_conn_profile){ |
65 | 0 | .connect_timeout = tcp_connect_timeout, |
66 | 0 | .con_lifetime = tcp_con_lifetime, |
67 | 0 | .msg_read_timeout = tcp_max_msg_time, |
68 | 0 | .send_threshold = tcpthreshold, |
69 | 0 | .no_new_conn = 0, /* by default, the only way to enforce |
70 | | no-new-conn is via br/rpl flags */ |
71 | 0 | .alias_mode = tcp_accept_aliases, |
72 | 0 | .parallel_read = tcp_parallel_read_on_workers, |
73 | 0 | .keepalive = tcp_keepalive, |
74 | 0 | .keepcount = tcp_keepcount, |
75 | 0 | .keepidle = tcp_keepidle, |
76 | 0 | .keepinterval = tcp_keepinterval, |
77 | |
|
78 | 0 | .id = 0, |
79 | 0 | }; |
80 | |
|
81 | 0 | tcp_init_attrs(tcp_con_df_profile.attrs); |
82 | 0 | } |