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

« back to all changes in this revision

Viewing changes to modules/stun/kam_stun.h

  • 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:
 
1
/*
 
2
 * $Id$
 
3
 *
 
4
 * Portions Copyright (C) 2013 Crocodile RCS Ltd
 
5
 *
 
6
 * Based on "ser_stun.h". Copyright (C) 2001-2003 FhG Fokus
 
7
 *
 
8
 * This file is part of Kamailio, a free SIP server.
 
9
 *
 
10
 * Kamailio is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 2 of the License, or
 
13
 * (at your option) any later version
 
14
 *
 
15
 * Kamailio is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public License 
 
21
 * along with this program; if not, write to the Free Software 
 
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
 *
 
24
 */
 
25
 
 
26
#ifndef _kam_stun_h
 
27
#define _kam_stun_h
 
28
 
 
29
#include "../../str.h"
 
30
#include "../../tcp_conn.h"
 
31
#include "../../ip_addr.h"
 
32
#include "../../stun.h"
 
33
 
 
34
/* STUN message types supported by Kamailio */
 
35
#define BINDING_REQUEST         0x0001
 
36
#define BINDING_RESPONSE        0x0101
 
37
#define BINDING_ERROR_RESPONSE  0x0111
 
38
 
 
39
/* common STUN attributes */
 
40
#define MAPPED_ADDRESS_ATTR     0x0001
 
41
#define USERNAME_ATTR           0x0006
 
42
#define MESSAGE_INTEGRITY_ATTR  0x0008
 
43
#define ERROR_CODE_ATTR         0x0009
 
44
#define UNKNOWN_ATTRIBUTES_ATTR 0x000A
 
45
 
 
46
/* STUN attributes defined by rfc5389 */
 
47
#define REALM_ATTR              0x0014
 
48
#define NONCE_ATTR              0x0015
 
49
#define XOR_MAPPED_ADDRESS_ATTR 0x0020 
 
50
#define FINGERPRINT_ATTR        0x8028
 
51
#define SOFTWARE_ATTR           0x8022
 
52
#define ALTERNATE_SERVER_ATTR   0x8023
 
53
 
 
54
/* STUN attributes defined by rfc3489 */
 
55
#define RESPONSE_ADDRESS_ATTR   0x0002
 
56
#define CHANGE_REQUEST_ATTR     0x0003
 
57
#define SOURCE_ADDRESS_ATTR     0x0004
 
58
#define CHANGED_ADDRESS_ATTR    0x0005
 
59
#define REFLECTED_FROM_ATTR     0x000b
 
60
 
 
61
/* STUN error codes supported by Kamailio */
 
62
#define RESPONSE_OK             200
 
63
#define TRY_ALTERNATE_ERR       300
 
64
#define BAD_REQUEST_ERR         400
 
65
#define UNAUTHORIZED_ERR        401
 
66
#define UNKNOWN_ATTRIBUTE_ERR   420
 
67
#define STALE_CREDENTIALS_ERR   430
 
68
#define INTEGRITY_CHECK_ERR     431
 
69
#define MISSING_USERNAME_ERR    432
 
70
#define USE_TLS_ERR             433
 
71
#define MISSING_REALM_ERR       434
 
72
#define MISSING_NONCE_ERR       435
 
73
#define UNKNOWN_USERNAME_ERR    436
 
74
#define STALE_NONCE_ERR         438
 
75
#define SERVER_ERROR_ERR        500
 
76
#define GLOBAL_FAILURE_ERR      600
 
77
 
 
78
#define TRY_ALTERNATE_TXT      "Try Alternate"
 
79
#define BAD_REQUEST_TXT        "Bad Request"
 
80
#define UNAUTHORIZED_TXT       "Unauthorized"
 
81
#define UNKNOWN_ATTRIBUTE_TXT  "Unknown Attribute"
 
82
#define STALE_CREDENTIALS_TXT  "Stale Credentials"
 
83
#define INTEGRITY_CHECK_TXT    "Integrity Check Failure"
 
84
#define MISSING_USERNAME_TXT   "Missing Username"
 
85
#define USE_TLS_TXT            "Use TLS"
 
86
#define MISSING_REALM_TXT      "Missing Realm"
 
87
#define MISSING_NONCE_TXT      "Missing Nonce"
 
88
#define UNKNOWN_USERNAME_TXT   "Unknown Username"
 
89
#define STALE_NONCE_TXT        "Stale Nonce"
 
90
#define SERVER_ERROR_TXT       "Server Error"
 
91
#define GLOBAL_FAILURE_TXT     "Global Failure"
 
92
 
 
93
/* other stuff */
 
94
#define MAGIC_COOKIE_2B         0x2112  /* because of XOR for port */
 
95
#define MANDATORY_ATTR          0x7fff
 
96
#define PAD4                    4
 
97
#define PAD64                   64
 
98
#define STUN_MSG_LEN            516
 
99
#define IPV4_LEN                4
 
100
#define IPV6_LEN                16
 
101
#define IPV4_FAMILY             0x0001
 
102
#define IPV6_FAMILY             0x0002
 
103
#define FATAL_ERROR             -1
 
104
#define IP_ADDR                 4
 
105
#define XOR                     1
 
106
 
 
107
#ifndef SHA_DIGEST_LENGTH
 
108
#define SHA_DIGEST_LENGTH       20
 
109
#endif
 
110
 
 
111
/** padd len to a multiple of sz.
 
112
 *  sz must be a power of the form 2^k (e.g. 2, 4, 8, 16 ...)
 
113
 */
 
114
#define PADD_TO(len, sz)        (((len) + (sz)-1) & (~((sz) - 1)))
 
115
 
 
116
#define PADDED_TO_FOUR(len)     PADD_TO(len, 4)
 
117
#define PADDED_TO_SIXTYFOUR(len) PADD_TO(len, 64)
 
118
 
 
119
struct stun_ip_addr {
 
120
        USHORT_T family; /* 0x01: IPv4; 0x02: IPv6 */
 
121
        USHORT_T port;
 
122
        UINT_T ip[IP_ADDR];
 
123
};
 
124
 
 
125
struct stun_buffer {
 
126
        str buf;
 
127
        USHORT_T empty; /* number of free bytes in buf before it'll be necessary
 
128
                           to realloc the buf */
 
129
};
 
130
 
 
131
struct stun_unknown_att {
 
132
        USHORT_T type;
 
133
        struct stun_unknown_att* next;
 
134
};
 
135
 
 
136
struct stun_msg {
 
137
        struct stun_hdr hdr;
 
138
        struct stun_ip_addr ip_addr; /* XOR values for rfc3489bis, normal values
 
139
                                        for rfc3489 */
 
140
        struct stun_buffer msg;
 
141
        UCHAR_T old; /* true: the format of message is in accordance with
 
142
                        rfc3489 */ 
 
143
};
 
144
 
 
145
int process_stun_msg(char* buf, unsigned len, struct receive_info* ri);
 
146
 
 
147
#endif  /* _kam_stun_h */