~ubuntu-branches/debian/sid/kamailio/sid

« back to all changes in this revision

Viewing changes to udp_server.c

  • Committer: Package Import Robot
  • Author(s): Victor Seva
  • Date: 2014-01-06 11:47:13 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140106114713-t8xidp4arzrnyeya
Tags: 4.1.1-1
* New upstream release
* debian/patches:
  - add upstream fixes
* Added tls outbound websocket autheph dnssec modules
  - openssl exception added to their license
* removing sparc and ia64 from supported archs
  for mono module (Closes: #728915)

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
#include "ip_addr.h"
77
77
#include "cfg/cfg_struct.h"
78
78
#include "events.h"
 
79
#include "stun.h"
79
80
#ifdef USE_RAW_SOCKS
80
81
#include "raw_sock.h"
81
82
#endif /* USE_RAW_SOCKS */
82
83
 
83
84
 
84
 
#ifdef USE_STUN
85
 
  #include "ser_stun.h"
86
 
#endif
87
 
 
88
85
#ifdef DBG_MSG_QA
89
86
/* message quality assurance -- frequently, bugs in ser have
90
87
   been indicated by zero characters or long whitespaces
243
240
static int setup_mcast_rcvr(int sock, union sockaddr_union* addr)
244
241
{
245
242
        struct ip_mreq mreq;
246
 
#ifdef USE_IPV6
247
243
        struct ipv6_mreq mreq6;
248
 
#endif /* USE_IPV6 */
249
244
        
250
245
        if (addr->s.sa_family==AF_INET){
251
246
                memcpy(&mreq.imr_multiaddr, &addr->sin.sin_addr, 
259
254
                        return -1;
260
255
                }
261
256
                
262
 
#ifdef USE_IPV6
263
257
        } else if (addr->s.sa_family==AF_INET6){
264
258
                memcpy(&mreq6.ipv6mr_multiaddr, &addr->sin6.sin6_addr, 
265
259
                       sizeof(struct in6_addr));
275
269
                        return -1;
276
270
                }
277
271
                
278
 
#endif /* USE_IPV6 */
279
272
        } else {
280
273
                LOG(L_ERR, "ERROR: setup_mcast_rcvr: Unsupported protocol family\n");
281
274
                return -1;
328
321
                                        strerror(errno));
329
322
                        /* continue since this is not critical */
330
323
                }
331
 
#ifdef USE_IPV6
332
324
        } else if (addr->s.sa_family==AF_INET6){
333
325
                if (setsockopt(sock_info->socket, IPPROTO_IPV6, IPV6_TCLASS,
334
326
                                        (void*)&optval, sizeof(optval)) ==-1) {
336
328
                                        strerror(errno));
337
329
                        /* continue since this is not critical */
338
330
                }
339
 
#endif
340
331
        }
341
332
 
342
333
#if defined (__OS_linux) && defined(UDP_ERRORS)
382
373
                                                " %s\n", strerror(errno));
383
374
                        }
384
375
                }
385
 
#ifdef USE_IPV6
386
376
        } else if (addr->s.sa_family==AF_INET6){
387
377
                if (setsockopt(sock_info->socket, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, 
388
378
                                                &mcast_loopback, sizeof(mcast_loopback))==-1){
396
386
                                                "(IPV6_MULTICAST_HOPS): %s\n", strerror(errno));
397
387
                        }
398
388
                }
399
 
#endif /* USE_IPV6*/
400
389
        } else {
401
390
                LOG(L_ERR, "ERROR: udp_init: Unsupported protocol family %d\n",
402
391
                                        addr->s.sa_family);
412
401
                                (unsigned)sockaddru_len(*addr),
413
402
                                sock_info->address_str.s,
414
403
                                strerror(errno));
415
 
        #ifdef USE_IPV6
416
404
                if (addr->s.sa_family==AF_INET6)
417
405
                        LOG(L_ERR, "ERROR: udp_init: might be caused by using a link "
418
406
                                        " local address, try site local or global\n");
419
 
        #endif
420
407
                goto error;
421
408
        }
422
409
 
501
488
                        }
502
489
                }
503
490
#ifndef NO_ZERO_CHECKS
504
 
#ifdef USE_STUN
505
 
                /* STUN support can be switched off even if it's compiled */
506
 
                if (stun_allow_stun == 0 || (unsigned char)*buf != 0x00) {
507
 
#endif
508
 
                  if (len<MIN_UDP_PACKET) {
509
 
                          tmp=ip_addr2a(&ri.src_ip);
510
 
                          DBG("udp_rcv_loop: probing packet received from %s %d\n",
511
 
                                        tmp, htons(ri.src_port));
512
 
                          continue;
513
 
                  }
514
 
#ifdef USE_STUN
 
491
                if (!unlikely(sr_event_enabled(SREV_STUN_IN)) || (unsigned char)*buf != 0x00) {
 
492
                        if (len<MIN_UDP_PACKET) {
 
493
                                tmp=ip_addr2a(&ri.src_ip);
 
494
                                DBG("udp_rcv_loop: probing packet received from %s %d\n",
 
495
                                        tmp, htons(ri.src_port));
 
496
                                continue;
 
497
                        }
515
498
                }
516
 
#endif
517
499
/* historically, zero-terminated packets indicated a bug in clients
518
500
 * that calculated wrongly packet length and included string-terminating
519
501
 * zero; today clients exist with legitimate binary payloads and we
544
526
                
545
527
                /* update the local config */
546
528
                cfg_update();
547
 
#ifdef USE_STUN
548
 
                        /* STUN support can be switched off even if it's compiled */
549
 
                        if (stun_allow_stun && (unsigned char)*buf == 0x00) {
550
 
                            /* stun_process_msg releases buf memory if necessary */
551
 
                                if ((stun_process_msg(buf, len, &ri)) != 0) {
552
 
                                        continue; /* some error occurred */
553
 
                                }
554
 
                        } else
555
 
#endif
556
 
                /* receive_msg must free buf too!*/
557
 
                receive_msg(buf, len, &ri);
 
529
                if (unlikely(sr_event_enabled(SREV_STUN_IN)) && (unsigned char)*buf == 0x00) {
 
530
                        /* stun_process_msg releases buf memory if necessary */
 
531
                        if ((stun_process_msg(buf, len, &ri)) != 0) {
 
532
                                continue; /* some error occurred */
 
533
                        }
 
534
                } else {
 
535
                        /* receive_msg must free buf too!*/
 
536
                        receive_msg(buf, len, &ri);
 
537
                }
558
538
                
559
539
        /* skip: do other stuff */
560
540