1 /* $Id: pcplearndscp.c,v 1.2 2016/01/13 16:02:08 nanard Exp $ */
3 * Website : http://miniupnp.free.fr/
4 * Author : Miroslav Bagljas
6 Copyright (c) 2013 by Cisco Systems, Inc.
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 * The name of the author may not be used to endorse or promote products
18 derived from this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
41 #include "upnpglobalvars.h"
42 #include "pcplearndscp.h"
50 for (i
=0; i
< num_dscp_values
; i
++){
51 syslog(LOG_DEBUG
, "Appname %*.s, del %d, loss %d, jitter %d, dscp %d",
52 dscp_values_list
[i
].app_name_len
,
53 dscp_values_list
[i
].app_name
, dscp_values_list
[i
].delay
,
54 dscp_values_list
[i
].loss
, dscp_values_list
[i
].jitter
,
55 dscp_values_list
[i
].dscp_value
61 read_learn_dscp_line(struct dscp_values
*dscpvalues
, char *p
)
65 unsigned int sizeof_first_token
= sizeof("set_learn_dscp") - 1;
69 /* first token: (set_learn_dscp) skip it */
72 if(0 == memcmp(p
, "set_learn_dscp", sizeof_first_token
))
74 p
+= sizeof_first_token
;
83 /* second token: name of the application */
88 for(q
= p
; !(*q
== '"'); q
++);
91 dscpvalues
->app_name
= strndup(p
, len
);
93 dscpvalues
->app_name
= NULL
;
95 dscpvalues
->app_name_len
= len
;
98 /* third token: delay */
102 goto exit_err_and_cleanup
;
103 for(q
= p
; isdigit(*q
); q
++);
107 dscpvalues
->delay
= (unsigned char)atoi(p
);
108 if (dscpvalues
->delay
>= 3) {
109 fprintf(stderr
, "Wrong delay value %d in \n", dscpvalues
->delay
);
110 fprintf(stderr
, "Delay can be from set {0,1,2} 0=low delay, 1=medium delay, 2=high delay\n");
111 goto exit_err_and_cleanup
;
116 goto exit_err_and_cleanup
;
120 /* fourth token: loss */
124 goto exit_err_and_cleanup
;
126 for(q
= p
; isdigit(*q
); q
++);
130 dscpvalues
->loss
= (unsigned char)atoi(p
);
131 if (dscpvalues
->loss
>= 3) {
132 fprintf(stderr
, "Wrong loss value %d \n", dscpvalues
->loss
);
133 fprintf(stderr
, "Delay can be from set {0,1,2} 0=low loss, 1=medium loss, 2=high loss\n");
134 goto exit_err_and_cleanup
;
139 goto exit_err_and_cleanup
;
143 /* fifth token: jitter */
147 goto exit_err_and_cleanup
;
148 for(q
= p
; isdigit(*q
); q
++);
152 dscpvalues
->jitter
= (unsigned char)atoi(p
);
153 if (dscpvalues
->jitter
>= 3) {
154 fprintf(stderr
, "Wrong jitter value %d \n", dscpvalues
->jitter
);
155 fprintf(stderr
, "Delay can be from set {0,1,2} 0=low jitter, 1=medium jitter, 2=high jitter \n");
156 goto exit_err_and_cleanup
;
161 goto exit_err_and_cleanup
;
170 /* sixth token: DSCP value */
173 if(!isdigit(*p
) && !( toupper(*p
) == 'A' && toupper(*(p
+1)) == 'F') &&
174 !( toupper(*p
) == 'C' && toupper(*(p
+1)) == 'S') &&
175 !( toupper(*p
) == 'E' && toupper(*(p
+1)) == 'F')
177 goto exit_err_and_cleanup
;
178 // for(q = p; isdigit(*q) || (toupper(*q) == 'A') || (toupper(*q) == 'F'); q++);
179 for(q
= p
; isdigit(*q
) || isalpha(*q
); q
++);
180 if(isspace(*q
) || *q
== '\0')
183 if (toupper(*p
) == 'A' && toupper(*(p
+1)) == 'F'){
186 dscpvalues
->dscp_value
= 0;
188 else if (!isdigit(*p
)) {
189 goto exit_err_and_cleanup
;
195 dscpvalues
->dscp_value
= 10;
198 dscpvalues
->dscp_value
= 12;
201 dscpvalues
->dscp_value
= 14;
204 dscpvalues
->dscp_value
= 18;
207 dscpvalues
->dscp_value
= 20;
210 dscpvalues
->dscp_value
= 22;
213 dscpvalues
->dscp_value
= 26;
216 dscpvalues
->dscp_value
= 28;
219 dscpvalues
->dscp_value
= 30;
222 dscpvalues
->dscp_value
= 34;
225 dscpvalues
->dscp_value
= 36;
228 dscpvalues
->dscp_value
= 38;
231 fprintf(stderr
, "Unknown AF value %d \n", af_value
);
232 goto exit_err_and_cleanup
;
236 else if (toupper(*p
) == 'C' && toupper(*(p
+1)) == 'S'){
239 dscpvalues
->dscp_value
= 0;
241 else if (!isdigit(*p
)) {
242 fprintf(stderr
, "Not digit after CS but %c \n", *p
);
243 goto exit_err_and_cleanup
;
249 dscpvalues
->dscp_value
= 8;
252 dscpvalues
->dscp_value
= 16;
255 dscpvalues
->dscp_value
= 24;
258 dscpvalues
->dscp_value
= 32;
261 dscpvalues
->dscp_value
= 40;
264 dscpvalues
->dscp_value
= 48;
267 dscpvalues
->dscp_value
= 56;
270 fprintf(stderr
, "Unknown CS value %d \n", cs_value
);
271 goto exit_err_and_cleanup
;
275 else if (toupper(*p
) == 'E' && toupper(*(p
+1)) == 'F'){
276 dscpvalues
->dscp_value
= 46;
279 dscpvalues
->dscp_value
= (unsigned char)atoi(p
);
284 goto exit_err_and_cleanup
;
289 exit_err_and_cleanup
:
290 free(dscpvalues
->app_name
);
291 dscpvalues
->app_name
= NULL
;
292 dscpvalues
->app_name_len
= 0;