Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToS for video and sip #98

Merged
merged 3 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/re_sip.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ enum sip_transp sip_transp_decode(const struct pl *pl);
uint16_t sip_transp_port(enum sip_transp tp, uint16_t port);
int sip_transp_laddr(struct sip *sip, struct sa *laddr, enum sip_transp tp,
const struct sa *dst);
int sip_settos(struct sip *sip, uint8_t tos);


/* request */
Expand Down
2 changes: 2 additions & 0 deletions include/re_tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ int tcp_accept(struct tcp_conn **tcp, struct tcp_sock *ts, tcp_estab_h *eh,
tcp_recv_h *rh, tcp_close_h *ch, void *arg);
void tcp_reject(struct tcp_sock *ts);
int tcp_sock_local_get(const struct tcp_sock *ts, struct sa *local);
int tcp_settos(struct tcp_sock *ts, uint32_t tos);
int tcp_conn_settos(struct tcp_conn *tc, uint32_t tos);


/* TCP Connection */
Expand Down
1 change: 1 addition & 0 deletions include/re_udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ int udp_sock_fd(const struct udp_sock *us, int af);

int udp_multicast_join(struct udp_sock *us, const struct sa *group);
int udp_multicast_leave(struct udp_sock *us, const struct sa *group);
int udp_settos(struct udp_sock *us, uint8_t tos);


/* Helper API */
Expand Down
1 change: 1 addition & 0 deletions src/sip/sip.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct sip {
sip_trace_h *traceh;
void *arg;
bool closing;
uint8_t tos;
};


Expand Down
39 changes: 39 additions & 0 deletions src/sip/transp.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct sip_transport {
struct tls *tls;
void *sock;
enum sip_transp tp;
uint8_t tos;

struct http_cli *http_cli;
struct http_sock *http_sock;
Expand Down Expand Up @@ -619,6 +620,7 @@ static void tcp_connect_handler(const struct sa *paddr, void *arg)
if (err)
goto out;

(void)tcp_conn_settos(conn->tc, transp->tos);
#ifdef USE_TLS
if (transp->tls) {
err = tls_start_tcp(&conn->sc, transp->tls, conn->tc, 0);
Expand Down Expand Up @@ -717,6 +719,7 @@ static int conn_send(struct sip_connqent **qentp, struct sip *sip, bool secure,
if (err)
goto out;

(void)tcp_conn_settos(conn->tc, sip->tos);
#ifdef USE_TLS
if (secure) {
const struct sip_transport *transp;
Expand Down Expand Up @@ -1550,6 +1553,42 @@ uint16_t sip_transp_port(enum sip_transp tp, uint16_t port)
}


int sip_settos(struct sip *sip, uint8_t tos)
{
struct le *le;
int err = 0;

if (!sip)
return EINVAL;

sip->tos = tos;

for (le = sip->transpl.head; le; le = le->next) {

struct sip_transport *transp = le->data;
transp->tos = tos;
switch (transp->tp) {
case SIP_TRANSP_UDP:
err = udp_settos(transp->sock, tos);
break;

case SIP_TRANSP_TCP:
case SIP_TRANSP_TLS:
err = tcp_settos(transp->sock, tos);
break;
break;
default:
break;
}

if (err)
break;
}

return err;
}


static bool debug_handler(struct le *le, void *arg)
{
const struct sip_transport *transp = le->data;
Expand Down
60 changes: 60 additions & 0 deletions src/tcp/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct tcp_sock {
int fdc; /**< Cached connection file descriptor */
tcp_conn_h *connh; /**< TCP Connect handler */
void *arg; /**< Handler argument */
uint8_t tos; /**< Type-of-service field */
};


Expand All @@ -79,6 +80,7 @@ struct tcp_conn {
size_t txqsz_max;
bool active; /**< We are connecting flag */
bool connected; /**< Connection is connected flag */
uint8_t tos; /**< Type-of-service field */
};


Expand Down Expand Up @@ -488,6 +490,30 @@ static void tcp_sockopt_set(int fd)
}


static int tcp_sock_setopt(struct tcp_sock *ts, int level, int optname,
const void *optval, uint32_t optlen)
{
int err = 0;

if (!ts)
return EINVAL;

if (-1 != ts->fdc) {
if (0 != setsockopt(ts->fdc, level, optname,
BUF_CAST optval, optlen))
err |= errno;
}

if (-1 != ts->fd) {
if (0 != setsockopt(ts->fd, level, optname,
BUF_CAST optval, optlen))
err |= errno;
}

return err;
}


/**
* Handler for incoming TCP connections.
*
Expand Down Expand Up @@ -1413,3 +1439,37 @@ int tcp_register_helper(struct tcp_helper **thp, struct tcp_conn *tc,

return 0;
}


int tcp_settos(struct tcp_sock *ts, uint32_t tos)
{
int err = 0;
int v = tos;

if (!ts)
return EINVAL;

ts->tos = tos;
err = tcp_sock_setopt(ts, IPPROTO_IP, IP_TOS, &v, sizeof(v));

return err;
}


int tcp_conn_settos(struct tcp_conn *tc, uint32_t tos)
{
int err = 0;
int v = tos;

if (!tc)
return EINVAL;

tc->tos = tos;
if (-1 != tc->fdc) {
if (0 != setsockopt(tc->fdc, IPPROTO_IP, IP_TOS,
BUF_CAST &v, sizeof(v)))
err = errno;
}

return err;
}
13 changes: 13 additions & 0 deletions src/udp/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,19 @@ int udp_sockbuf_set(struct udp_sock *us, int size)
}


int udp_settos(struct udp_sock *us, uint8_t tos)
{
int err = 0;
int v = tos;

if (!us)
return EINVAL;

err = udp_setsockopt(us, IPPROTO_IP, IP_TOS, &v, sizeof(v));
return err;
}


/**
* Set the maximum receive chunk size on a UDP Socket
*
Expand Down