handle an incoming STUN message.
Do some basic sanity checks on packet size and content, try to extract a bit of information, and possibly reply. At the moment this only processes BIND requests, and returns the externally visible address of the request. If a callback is specified, invoke it with the attribute.
294{
299 int x;
300
301
302
303
304
307 return -1;
308 }
315 ast_debug_stun(1,
"Scrambled STUN packet length (got %d, expecting %d)\n", x, (
int)
len);
316 } else
318 memset(&st, 0, sizeof(st));
322 break;
323 }
325
328 ast_debug_stun(1,
"Inconsistent Attribute (length %d exceeds remaining msg len %d)\n", x, (
int)
len);
329 break;
330 }
331 if (stun_cb)
335 break;
336 }
337
338
339
341 data += x;
343 }
344
345
346
347
348
349
350 *data = '\0';
351
352
353
354
356 unsigned char respdata[1024];
358 int resplen = 0;
359 int respleft =
sizeof(respdata) -
sizeof(
struct stun_header);
360 char combined[33];
361
370 st.username ? st.username : "<none>");
371 if (st.username) {
373
374
375
376
377
378 snprintf(combined, 17, "%16s", st.username + 16);
379 snprintf(combined + 16, 17, "%16s", st.username);
380 } else {
381 combined[0] = '\0';
382 }
383
385 resp->
msglen = htons(resplen);
390 break;
391 default:
394 }
395 }
396 return ret;
397}
void ast_verbose(const char *fmt,...)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
here we store credentials extracted from a message
static const char * stun_msg2str(int msg)
helper function to print message names
int ast_stun_request(int s, struct sockaddr_in *dst, const char *username, struct sockaddr_in *answer)
Generic STUN request.
#define STUN_MAPPED_ADDRESS
Basic attribute types in stun messages. Messages can also contain custom attributes (codes above 0x7f...
static void append_attr_address(struct stun_attr **attr, int attrval, struct sockaddr_in *sin, int *len, int *left)
append an address to an STUN message
static const char * stun_attr2str(int msg)
helper function to print attribute names
#define STUN_BINDREQ
STUN message types 'BIND' refers to transactions used to determine the externally visible addresses....
static int stun_process_attr(struct stun_state *state, struct stun_attr *attr)
static int stun_send(int s, struct sockaddr_in *dst, struct stun_header *resp)
wrapper to send an STUN message
static void append_attr_string(struct stun_attr **attr, int attrval, const char *s, int *len, int *left)
append a string to an STUN message
#define ast_debug_stun(sublevel,...)
Log debug level STUN information.
#define ast_debug_stun_packet_is_allowed