|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Sippy Software, Inc., http://www.sippysoft.com |
| 3 | + * |
| 4 | + * Redistribution and use in source and binary forms, with or without |
| 5 | + * modification, are permitted provided that the following conditions |
| 6 | + * are met: |
| 7 | + * 1. Redistributions of source code must retain the above copyright |
| 8 | + * notice, this list of conditions and the following disclaimer. |
| 9 | + * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer in the |
| 11 | + * documentation and/or other materials provided with the distribution. |
| 12 | + * |
| 13 | + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 14 | + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 16 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 17 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 18 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 19 | + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 20 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 21 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 22 | + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 23 | + * SUCH DAMAGE. |
| 24 | + * |
| 25 | + */ |
| 26 | + |
| 27 | +#include<sys/socket.h> |
| 28 | +#include<stdint.h> |
| 29 | +#include<stdlib.h> |
| 30 | +#include<string.h> |
| 31 | + |
| 32 | +#include"config.h" |
| 33 | + |
| 34 | +#include"rtpp_codeptr.h" |
| 35 | +#include"rtpp_types.h" |
| 36 | +#include"rtpp_refcnt.h" |
| 37 | +#include"rtpp_log.h" |
| 38 | +#include"rtpp_log_obj.h" |
| 39 | +#include"rtpp_pipe.h" |
| 40 | +#include"rtpp_socket.h" |
| 41 | +#include"rtpp_session.h" |
| 42 | +#include"rtpp_stream.h" |
| 43 | +#include"rtpp_ttl.h" |
| 44 | +#include"rtpp_command.h" |
| 45 | +#include"rtpp_command_sub.h" |
| 46 | +#include"rtpp_command_args.h" |
| 47 | +#include"rtpp_command_private.h" |
| 48 | +#include"rtpp_mallocs.h" |
| 49 | +#include"rtpp_util.h" |
| 50 | +#include"commands/rpcpv1_ul.h" |
| 51 | +#include"commands/rpcpv1_ul_subc_set.h" |
| 52 | + |
| 53 | +staticint |
| 54 | +strmp_settos(conststructrtpp_subc_ctx*rscp,structrtpp_stream*strmp,intval) |
| 55 | +{ |
| 56 | +if (strmp->laddr->sa_family!=AF_INET) |
| 57 | +return (-1); |
| 58 | +structrtpp_socket*fd=CALL_SMETHOD(strmp,get_skt,HEREVAL); |
| 59 | +if (fd==NULL) |
| 60 | + gotoout; |
| 61 | +inttres=CALL_SMETHOD(fd,settos,val); |
| 62 | +RTPP_OBJ_DECREF(fd); |
| 63 | +if (tres==-1) { |
| 64 | +RTPP_ELOG(rscp->log,RTPP_LOG_ERR,"unable to set TOS to %d",val); |
| 65 | +return (-1); |
| 66 | + } |
| 67 | +out: |
| 68 | +strmp->tos=val; |
| 69 | +return (0); |
| 70 | +} |
| 71 | + |
| 72 | +staticint |
| 73 | +rtpp_subcommand_set_handler(conststructafter_success_h_args*ashap, |
| 74 | +conststructrtpp_subc_ctx*rscp) |
| 75 | +{ |
| 76 | +conststructrtpp_subcommand_set*tap; |
| 77 | +structrtpp_stream*strmp; |
| 78 | + |
| 79 | +tap= (structrtpp_subcommand_set*)ashap->dyn; |
| 80 | +switch (tap->direction) { |
| 81 | +caseSET_FORWARD: |
| 82 | +strmp=rscp->strmp_in; |
| 83 | +break; |
| 84 | + |
| 85 | +caseSET_REVERSE: |
| 86 | +strmp=rscp->strmp_out; |
| 87 | +if (strmp==NULL) |
| 88 | +return (-1); |
| 89 | +break; |
| 90 | + |
| 91 | +default: |
| 92 | +abort(); |
| 93 | + } |
| 94 | + |
| 95 | +switch (tap->param) { |
| 96 | +caseSET_PRM_TTL: |
| 97 | +strmp->stream_ttl=tap->val; |
| 98 | +CALL_SMETHOD(strmp->ttl,reset_with,tap->val); |
| 99 | +break; |
| 100 | + |
| 101 | +caseSET_PRM_TOS: |
| 102 | +if (strmp_settos(rscp,strmp,tap->val)!=0) |
| 103 | +return (-1); |
| 104 | +structrtpp_stream_pairrtcp=get_rtcp_pair(rscp->sessp,strmp); |
| 105 | +if (rtcp.ret!=0||rtcp.in==NULL) |
| 106 | +break; |
| 107 | +if (strmp_settos(rscp,rtcp.in,tap->val)!=0) |
| 108 | +return (-1); |
| 109 | +break; |
| 110 | + |
| 111 | +default: |
| 112 | +abort(); |
| 113 | + } |
| 114 | +return (0); |
| 115 | +} |
| 116 | + |
| 117 | +int |
| 118 | +handle_set_subc_parse(conststructrtpp_cfg*cfsp,constchar*cp, |
| 119 | +constrtpp_str_const_t*v,structafter_success_h*asp) |
| 120 | +{ |
| 121 | +structrtpp_subcommand_setset_arg,*tap; |
| 122 | + |
| 123 | +if (cp[0]=='r'||cp[0]=='R') { |
| 124 | +set_arg.direction=SET_REVERSE; |
| 125 | + }else { |
| 126 | +set_arg.direction=SET_FORWARD; |
| 127 | + } |
| 128 | +if (strcmp(v->s,"ttl=")==0) { |
| 129 | +set_arg.param=SET_PRM_TTL; |
| 130 | +cp=v->s+4; |
| 131 | + }elseif (strcmp(v->s,"tos=")==0) { |
| 132 | +set_arg.param=SET_PRM_TOS; |
| 133 | +cp=v->s+4; |
| 134 | + }else { |
| 135 | +return (-1); |
| 136 | + } |
| 137 | +if (atoi_safe(cp,&set_arg.val)!=ATOI_OK) |
| 138 | +return (-1); |
| 139 | +if (set_arg.val <=0) |
| 140 | +return (-1); |
| 141 | +tap=rtpp_zmalloc(sizeof(set_arg)); |
| 142 | +if (tap==NULL) |
| 143 | +return (-1); |
| 144 | +*tap=set_arg; |
| 145 | +asp->args.dyn=tap; |
| 146 | +asp->handler=rtpp_subcommand_set_handler; |
| 147 | +return (0); |
| 148 | +} |