Skip to content

Commit

Permalink
sip: add setter for ToS (RFC-791)
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 authored and sreimers committed Apr 26, 2021
1 parent bda9c00 commit f821ffb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
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
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

0 comments on commit f821ffb

Please sign in to comment.