Skip to content

Commit

Permalink
Expose a conn fcntl like function to App level.
Browse files Browse the repository at this point in the history
1. tcp_conn_fcntl() function offered by TCP net layer
2. TLS and TCP protos reuses this function for Transport layer.
  • Loading branch information
bogdan-iancu committed Feb 23, 2015
1 parent 78c8462 commit 41dc79d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.
1 change: 1 addition & 0 deletions modules/proto_tls/proto_tls.c
Expand Up @@ -975,6 +975,7 @@ static int proto_tls_init(struct proto_info *pi)

pi->tran.init_listener = proto_tls_init_listener;
pi->tran.send = proto_tls_send;
pi->tran.dst_attr = tcp_conn_fcntl;

pi->net.flags = PROTO_NET_USE_TCP;
pi->net.read = (proto_net_read_f)tls_read_req;
Expand Down
4 changes: 3 additions & 1 deletion net/api_proto.h
Expand Up @@ -27,17 +27,19 @@
#define _API_PROTO_TI_H_

#include "../ip_addr.h"
#include "api_proto_net.h"

#define PROTO_PREFIX "proto_"

typedef int (*proto_init_listener_f)(struct socket_info *si);
typedef int (*proto_send_f)(struct socket_info *si, char* buf,unsigned int len,
union sockaddr_union* to, int id);
typedef int (*proto_dst_attr_f)(struct receive_info *rcv,
int attr, void *value);

struct api_proto {
proto_init_listener_f init_listener;
proto_send_f send;
proto_dst_attr_f dst_attr;
};

#endif /* _API_PROTO_TI_H_ */
42 changes: 23 additions & 19 deletions net/net_tcp.c
Expand Up @@ -605,29 +605,33 @@ int tcp_conn_get(int id, struct ip_addr* ip, int port, int timeout,
}


// used to tune the tcp_connection attributes
int tcp_conn_fcntl(struct tcp_connection *conn, int attr, void *value)
/* used to tune the tcp_connection attributes - not to be used inside the
network layer, but onlu from the above layer (otherwise we may end up
in strange deadlocks!) */
int tcp_conn_fcntl(struct receive_info *rcv, int attr, void *value)
{
// TODO: implementation
struct tcp_connection *con;

switch (attr) {
case DST_FCNTL_SET_LIFETIME:
/* set connection timeout */
TCPCONN_LOCK(rcv->proto_reserved1);
con =_tcpconn_find(rcv->proto_reserved1);
if (!con) {
LM_ERR("Strange, tcp conn not found (id=%d)\n",
rcv->proto_reserved1);
} else {
con->lifetime = (int)(long)(value);
}
TCPCONN_UNLOCK(rcv->proto_reserved1);
return 0;
default:
LM_ERR("unsupported operation %d on conn\n",attr);
return -1;
}
return -1;
}

/** FIXME - have it in tcp_conn_fcntl
void force_tcp_conn_lifetime(struct receive_info *rcv, unsigned int timeout)
{
struct tcp_connection* con;
unsigned int lifetime = get_ticks() + timeout;
TCPCONN_LOCK(rcv->proto_reserved1);
con =_tcpconn_find(rcv->proto_reserved1);
if (!con) {
LM_ERR("Strange, tcp conn not found (id=%d)\n",rcv->proto_reserved1);
} else {
con->lifetime = lifetime;
}
TCPCONN_UNLOCK(rcv->proto_reserved1);
}*/


static struct tcp_connection* tcpconn_add(struct tcp_connection *c)
{
Expand Down
4 changes: 2 additions & 2 deletions net/net_tcp.h
Expand Up @@ -84,7 +84,7 @@ struct tcp_connection* tcp_conn_create(int sock, union sockaddr_union* su,
/* release a connection aquired via tcp_conn_get() or tcp_conn_create() */
void tcp_conn_release(struct tcp_connection* c, int pending_data);

// used to tune the connection attributes
int tcp_conn_fcntl(struct tcp_connection *conn, int attr, void *value);
/* used to tune the connection attributes */
int tcp_conn_fcntl(struct receive_info *rcv, int attr, void *value);

#endif /* _NET_TCP_H_ */
1 change: 1 addition & 0 deletions net/proto_tcp/proto_tcp.c
Expand Up @@ -159,6 +159,7 @@ static int proto_tcp_init(struct proto_info *pi)

pi->tran.init_listener = proto_tcp_init_listener;
pi->tran.send = proto_tcp_send;
pi->tran.dst_attr = tcp_conn_fcntl;

pi->net.flags = PROTO_NET_USE_TCP;
pi->net.read = (proto_net_read_f)tcp_read_req;
Expand Down
7 changes: 7 additions & 0 deletions net/trans.h
Expand Up @@ -64,6 +64,13 @@ extern struct proto_info *protos;
#define is_udp_based_proto(_p) \
(protos[_p].net.flags&PROTO_NET_USE_UDP)

#define DST_FCNTL_SET_LIFETIME 1

#define trans_set_dst_attr( _rcv, _attr, _val) \
do { \
if (protos[(_rcv)->proto].tran.dst_attr) \
protos[(_rcv)->proto].tran.dst_attr(_rcv,_attr,_val);\
}while(0)

/*
* initializes transport interface structures
Expand Down

0 comments on commit 41dc79d

Please sign in to comment.