Skip to content

Commit e680c2d

Browse files
benceszigetikordian-pawelec
authored andcommitted
TELECOM-11807: Add SO_MARK support
1 parent 3508b8d commit e680c2d

10 files changed

Lines changed: 31 additions & 5 deletions

File tree

cfg.lex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ SLASH "/"
318318
AS {EAT_ABLE}("as"|"AS"){EAT_ABLE}
319319
USE_WORKERS {EAT_ABLE}("use_workers"|"USE_WORKERS"){EAT_ABLE}
320320
SOCK_TOS {EAT_ABLE}("tos"|"TOS"){EAT_ABLE}
321+
MARK {EAT_ABLE}("mark"|"MARK"){EAT_ABLE}
321322
USE_AUTO_SCALING_PROFILE {EAT_ABLE}("use_auto_scaling_profile"|"USE_AUTO_SCALING_PROFILE"){EAT_ABLE}
322323
SCALE_UP_TO {EAT_ABLE}("scale"|"SCALE"){EAT_ABLE}+("up"|"UP"){EAT_ABLE}+("to"|"TO"){EAT_ABLE}
323324
SCALE_DOWN_TO {EAT_ABLE}("scale"|"SCALE"){EAT_ABLE}+("down"|"DOWN"){EAT_ABLE}+("to"|"TO"){EAT_ABLE}
@@ -600,6 +601,7 @@ SPACE [ ]
600601
<INITIAL>{SEMICOLON} { count(); return SEMICOLON; }
601602
<INITIAL>{USE_WORKERS} { count(); return USE_WORKERS; }
602603
<INITIAL>{SOCK_TOS} { count(); return SOCK_TOS; }
604+
<INITIAL>{MARK} { count(); return MARK; }
603605
<INITIAL>{USE_AUTO_SCALING_PROFILE} { count(); return USE_AUTO_SCALING_PROFILE; }
604606
<INITIAL>{COLON} { count(); return COLON; }
605607
<INITIAL>{RPAREN} { count(); return RPAREN; }

cfg.y

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ struct listen_param {
183183
enum si_flags flags;
184184
int workers;
185185
int tos;
186+
int mark;
186187
struct socket_id *socket;
187188
char *tag;
188189
char *auto_scaling_profile;
@@ -459,6 +460,7 @@ extern int cfg_parse_only_routes;
459460
%token AS
460461
%token USE_WORKERS
461462
%token SOCK_TOS
463+
%token MARK
462464
%token USE_AUTO_SCALING_PROFILE
463465
%token MAX
464466
%token MIN
@@ -763,6 +765,9 @@ socket_def_param: ANYCAST { IFOR();
763765
| SOCK_TOS NUMBER { IFOR();
764766
p_tmp.tos=$2;
765767
}
768+
| MARK NUMBER { IFOR();
769+
p_tmp.mark = $2;
770+
}
766771
| AS listen_id_def { IFOR();
767772
p_tmp.socket = $2;
768773
}
@@ -2788,6 +2793,7 @@ static void fill_socket_id(struct listen_param *param, struct socket_id *s)
27882793
s->flags |= param->flags;
27892794
s->workers = param->workers;
27902795
s->tos = param->tos;
2796+
s->mark = param->mark;
27912797
s->auto_scaling_profile = param->auto_scaling_profile;
27922798
s->tag = param->tag;
27932799
if (param->socket) {

ip_addr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ struct socket_id {
155155
int port;
156156
int workers;
157157
int tos;
158+
int mark;
158159
enum si_flags flags;
159160
struct socket_id* next;
160161
};

modules/cgrates/cgrates_engine.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static int cgrc_conn(struct cgr_conn *c)
271271

272272
tcp_con_get_profile(&c->engine->su, src_su, PROTO_TCP, &prof);
273273

274-
s = tcp_sync_connect_fd(src_su, &c->engine->su, PROTO_TCP, &prof, 0, 0);
274+
s = tcp_sync_connect_fd(src_su, &c->engine->su, PROTO_TCP, &prof, 0, 0, 0);
275275
if (s < 0) {
276276
LM_ERR("cannot connect to %.*s:%d\n", c->engine->host.len,
277277
c->engine->host.s, c->engine->port);

modules/janus/ws_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ static int janus_ws_sync_connect(janus_connection *sock)
946946

947947
tcp_con_get_profile(to_su, src_su, PROTO_TCP, &sock->profile);
948948

949-
s = tcp_sync_connect_fd(src_su, to_su, PROTO_TCP, &sock->profile,0,0);
949+
s = tcp_sync_connect_fd(src_su, to_su, PROTO_TCP, &sock->profile,0,0,0);
950950
if (s < 0) {
951951
LM_ERR("cannot TCP connect to %.*s:%d\n",
952952
sock->parsed_url.host.len,sock->parsed_url.host.s,

net/net_tcp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2551,7 +2551,8 @@ static int tcpconn_prepare_write(struct tcp_connection *tcpconn)
25512551
fd = tcp_sync_connect_fd(&tcpconn->rcv.bind_address->su,
25522552
&tcpconn->rcv.src_su, tcpconn->type, &tcpconn->profile,
25532553
tcpconn->rcv.bind_address->flags,
2554-
tcpconn->rcv.bind_address->tos);
2554+
tcpconn->rcv.bind_address->tos,
2555+
tcpconn->rcv.bind_address->mark);
25552556
if (fd < 0)
25562557
return -1;
25572558

net/tcp_common.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ int tcp_connect_blocking(int fd, const struct sockaddr *servaddr,
175175
}
176176

177177
int tcp_sync_connect_fd(const union sockaddr_union* src, const union sockaddr_union* dst,
178-
enum sip_protos proto, const struct tcp_conn_profile *prof, enum si_flags flags, int sock_tos)
178+
enum sip_protos proto, const struct tcp_conn_profile *prof, enum si_flags flags, int sock_tos, int mark)
179179
{
180180
int s;
181181
union sockaddr_union my_name;
@@ -192,6 +192,17 @@ int tcp_sync_connect_fd(const union sockaddr_union* src, const union sockaddr_un
192192
goto error;
193193
}
194194

195+
if (mark > 0) {
196+
#ifdef SO_MARK
197+
if (setsockopt(s, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0) {
198+
LM_ERR("SO_MARK setsockopt failed (%d) %s\n", errno, strerror(errno));
199+
goto error;
200+
}
201+
#else
202+
LM_WARN("SO_MARK not available on this platform\n");
203+
#endif
204+
}
205+
195206
if (src) {
196207
my_name_len = sockaddru_len(*src);
197208
memcpy( &my_name, src, my_name_len);

net/tcp_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int tcp_connect_blocking_timeout(int fd, const struct sockaddr *servaddr,
3131

3232

3333
int tcp_sync_connect_fd(const union sockaddr_union* src, const union sockaddr_union* dst,
34-
enum sip_protos proto, const struct tcp_conn_profile *prof, enum si_flags flags, int sock_tos);
34+
enum sip_protos proto, const struct tcp_conn_profile *prof, enum si_flags flags, int sock_tos, int mark);
3535

3636
struct tcp_connection* tcp_sync_connect(const struct socket_info* send_sock,
3737
const union sockaddr_union* server, struct tcp_conn_profile *prof,

socket_info.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ struct socket_info_full* new_sock_info(struct socket_id *sid, str *orig_name)
150150
si->proto=sid->proto;
151151
si->flags=sid->flags;
152152

153+
if (sid->mark) {
154+
si->mark = sid->mark;
155+
}
156+
153157
/* advertised socket information */
154158
/* Make sure the adv_sock_string is initialized, because if there is
155159
* no adv_sock_name, no other code will initialize it!

socket_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct socket_info {
6868
unsigned short adv_port; /* optimization for grep_sock_info() */
6969
unsigned short workers;
7070
unsigned short tos;
71+
int mark;
7172
struct scaling_profile *s_profile;
7273
void *extra_data;
7374
struct socket_info_ref *bond_sis;

0 commit comments

Comments
 (0)