media/mtransport/third_party/nICEr/src/stun/stun.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /*
michael@0 2 Copyright (c) 2007, Adobe Systems, Incorporated
michael@0 3 All rights reserved.
michael@0 4
michael@0 5 Redistribution and use in source and binary forms, with or without
michael@0 6 modification, are permitted provided that the following conditions are
michael@0 7 met:
michael@0 8
michael@0 9 * Redistributions of source code must retain the above copyright
michael@0 10 notice, this list of conditions and the following disclaimer.
michael@0 11
michael@0 12 * Redistributions in binary form must reproduce the above copyright
michael@0 13 notice, this list of conditions and the following disclaimer in the
michael@0 14 documentation and/or other materials provided with the distribution.
michael@0 15
michael@0 16 * Neither the name of Adobe Systems, Network Resonance nor the names of its
michael@0 17 contributors may be used to endorse or promote products derived from
michael@0 18 this software without specific prior written permission.
michael@0 19
michael@0 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 21 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 23 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
michael@0 24 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@0 25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@0 26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
michael@0 27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
michael@0 28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 31 */
michael@0 32
michael@0 33
michael@0 34 #ifndef _STUN_H
michael@0 35 #define _STUN_H
michael@0 36
michael@0 37 #ifdef WIN32
michael@0 38 #include <winsock2.h>
michael@0 39 #else
michael@0 40 #include <sys/param.h>
michael@0 41 #include <sys/socket.h>
michael@0 42 #include <net/if.h>
michael@0 43 #ifndef LINUX
michael@0 44 #if !defined(__OpenBSD__) && !defined(__NetBSD__)
michael@0 45 #include <net/if_var.h>
michael@0 46 #endif
michael@0 47 #include <net/if_dl.h>
michael@0 48 #include <net/if_types.h>
michael@0 49 #endif
michael@0 50 #ifndef BSD
michael@0 51 #include <net/route.h>
michael@0 52 #endif
michael@0 53 #include <netinet/in.h>
michael@0 54 #ifndef LINUX
michael@0 55 #include <netinet/in_var.h>
michael@0 56 #endif
michael@0 57 #include <arpa/inet.h>
michael@0 58 #include <netdb.h>
michael@0 59 #endif
michael@0 60 #include <time.h>
michael@0 61
michael@0 62 #include "nr_api.h"
michael@0 63 #include "stun_msg.h"
michael@0 64 #include "stun_build.h"
michael@0 65 #include "stun_codec.h"
michael@0 66 #include "stun_hint.h"
michael@0 67 #include "stun_util.h"
michael@0 68 #include "nr_socket.h"
michael@0 69 #include "stun_client_ctx.h"
michael@0 70 #include "stun_server_ctx.h"
michael@0 71 #include "stun_proc.h"
michael@0 72
michael@0 73 #define NR_STUN_VERSION "rfc3489bis-11"
michael@0 74 #define NR_STUN_PORT 3478
michael@0 75
michael@0 76 /* STUN attributes */
michael@0 77 #define NR_STUN_ATTR_MAPPED_ADDRESS 0x0001
michael@0 78 #define NR_STUN_ATTR_USERNAME 0x0006
michael@0 79 #define NR_STUN_ATTR_MESSAGE_INTEGRITY 0x0008
michael@0 80 #define NR_STUN_ATTR_ERROR_CODE 0x0009
michael@0 81 #define NR_STUN_ATTR_UNKNOWN_ATTRIBUTES 0x000A
michael@0 82 #define NR_STUN_ATTR_REALM 0x0014
michael@0 83 #define NR_STUN_ATTR_NONCE 0x0015
michael@0 84 #define NR_STUN_ATTR_XOR_MAPPED_ADDRESS 0x0020
michael@0 85 #define NR_STUN_ATTR_SERVER 0x8022
michael@0 86 #define NR_STUN_ATTR_ALTERNATE_SERVER 0x8023
michael@0 87 #define NR_STUN_ATTR_FINGERPRINT 0x8028
michael@0 88
michael@0 89 /* for backwards compatibility with obsolete versions of the STUN spec */
michael@0 90 #define NR_STUN_ATTR_OLD_XOR_MAPPED_ADDRESS 0x8020
michael@0 91
michael@0 92 #ifdef USE_STUND_0_96
michael@0 93 #define NR_STUN_ATTR_OLD_CHANGE_REQUEST 0x0003
michael@0 94 #endif /* USE_STUND_0_96 */
michael@0 95
michael@0 96 #ifdef USE_RFC_3489_BACKWARDS_COMPATIBLE
michael@0 97 /* for backwards compatibility with obsolete versions of the STUN spec */
michael@0 98 #define NR_STUN_ATTR_OLD_PASSWORD 0x0007
michael@0 99 #define NR_STUN_ATTR_OLD_RESPONSE_ADDRESS 0x0002
michael@0 100 #define NR_STUN_ATTR_OLD_SOURCE_ADDRESS 0x0004
michael@0 101 #define NR_STUN_ATTR_OLD_CHANGED_ADDRESS 0x0005
michael@0 102 #endif /* USE_RFC_3489_BACKWARDS_COMPATIBLE */
michael@0 103
michael@0 104 #ifdef USE_ICE
michael@0 105 /* ICE attributes */
michael@0 106 #define NR_STUN_ATTR_PRIORITY 0x0024
michael@0 107 #define NR_STUN_ATTR_USE_CANDIDATE 0x0025
michael@0 108 #define NR_STUN_ATTR_ICE_CONTROLLED 0x8029
michael@0 109 #define NR_STUN_ATTR_ICE_CONTROLLING 0x802A
michael@0 110 #endif /* USE_ICE */
michael@0 111
michael@0 112 #ifdef USE_TURN
michael@0 113 /* TURN attributes */
michael@0 114 #define NR_STUN_ATTR_LIFETIME 0x000d
michael@0 115 #define NR_STUN_ATTR_XOR_PEER_ADDRESS 0x0012
michael@0 116 #define NR_STUN_ATTR_DATA 0x0013
michael@0 117 #define NR_STUN_ATTR_XOR_RELAY_ADDRESS 0x0016
michael@0 118 #define NR_STUN_ATTR_REQUESTED_TRANSPORT 0x0019
michael@0 119
michael@0 120 #define NR_STUN_ATTR_REQUESTED_TRANSPORT_UDP 17
michael@0 121 #endif /* USE_TURN */
michael@0 122
michael@0 123 /*
michael@0 124 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
michael@0 125 * |M|M|M|M|M|C|M|M|M|C|M|M|M|M|
michael@0 126 * |1|1|9|8|7|1|6|5|4|0|3|2|1|0|
michael@0 127 * |1|0| | | | | | | | | | | | |
michael@0 128 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
michael@0 129 *
michael@0 130 * Figure 3: Format of STUN Message Type Field
michael@0 131 */
michael@0 132 #define NR_STUN_METHOD_TYPE_BITS(m) \
michael@0 133 ((((m) & 0xf80) << 2) | (((m) & 0x070) << 1) | ((m) & 0x00f))
michael@0 134
michael@0 135 #define NR_STUN_CLASS_TYPE_BITS(c) \
michael@0 136 ((((c) & 0x002) << 7) | (((c) & 0x001) << 4))
michael@0 137
michael@0 138 #define NR_STUN_GET_TYPE_METHOD(t) \
michael@0 139 ((((t) >> 2) & 0xf80) | (((t) >> 1) & 0x070) | ((t) & 0x00f))
michael@0 140
michael@0 141 #define NR_STUN_GET_TYPE_CLASS(t) \
michael@0 142 ((((t) >> 7) & 0x002) | (((t) >> 4) & 0x001))
michael@0 143
michael@0 144 #define NR_STUN_TYPE(m,c) (NR_STUN_METHOD_TYPE_BITS((m)) | NR_STUN_CLASS_TYPE_BITS((c)))
michael@0 145
michael@0 146 /* building blocks for message types */
michael@0 147 #define NR_METHOD_BINDING 0x001
michael@0 148 #define NR_CLASS_REQUEST 0x0
michael@0 149 #define NR_CLASS_INDICATION 0x1
michael@0 150 #define NR_CLASS_RESPONSE 0x2
michael@0 151 #define NR_CLASS_ERROR_RESPONSE 0x3
michael@0 152
michael@0 153 /* define types for STUN messages */
michael@0 154 #define NR_STUN_MSG_BINDING_REQUEST NR_STUN_TYPE(NR_METHOD_BINDING, \
michael@0 155 NR_CLASS_REQUEST)
michael@0 156 #define NR_STUN_MSG_BINDING_INDICATION NR_STUN_TYPE(NR_METHOD_BINDING, \
michael@0 157 NR_CLASS_INDICATION)
michael@0 158 #define NR_STUN_MSG_BINDING_RESPONSE NR_STUN_TYPE(NR_METHOD_BINDING, \
michael@0 159 NR_CLASS_RESPONSE)
michael@0 160 #define NR_STUN_MSG_BINDING_ERROR_RESPONSE NR_STUN_TYPE(NR_METHOD_BINDING, \
michael@0 161 NR_CLASS_ERROR_RESPONSE)
michael@0 162
michael@0 163 #ifdef USE_TURN
michael@0 164 /* building blocks for TURN message types */
michael@0 165 #define NR_METHOD_ALLOCATE 0x003
michael@0 166 #define NR_METHOD_REFRESH 0x004
michael@0 167
michael@0 168 #define NR_METHOD_SEND 0x006
michael@0 169 #define NR_METHOD_DATA 0x007
michael@0 170 #define NR_METHOD_CREATE_PERMISSION 0x008
michael@0 171 #define NR_METHOD_CHANNEL_BIND 0x009
michael@0 172
michael@0 173 /* define types for a TURN message */
michael@0 174 #define NR_STUN_MSG_ALLOCATE_REQUEST NR_STUN_TYPE(NR_METHOD_ALLOCATE, \
michael@0 175 NR_CLASS_REQUEST)
michael@0 176 #define NR_STUN_MSG_ALLOCATE_RESPONSE NR_STUN_TYPE(NR_METHOD_ALLOCATE, \
michael@0 177 NR_CLASS_RESPONSE)
michael@0 178 #define NR_STUN_MSG_ALLOCATE_ERROR_RESPONSE NR_STUN_TYPE(NR_METHOD_ALLOCATE, \
michael@0 179 NR_CLASS_ERROR_RESPONSE)
michael@0 180 #define NR_STUN_MSG_REFRESH_REQUEST NR_STUN_TYPE(NR_METHOD_REFRESH, \
michael@0 181 NR_CLASS_REQUEST)
michael@0 182 #define NR_STUN_MSG_REFRESH_RESPONSE NR_STUN_TYPE(NR_METHOD_REFRESH, \
michael@0 183 NR_CLASS_RESPONSE)
michael@0 184 #define NR_STUN_MSG_REFRESH_ERROR_RESPONSE NR_STUN_TYPE(NR_METHOD_REFRESH, \
michael@0 185 NR_CLASS_ERROR_RESPONSE)
michael@0 186
michael@0 187 #define NR_STUN_MSG_SEND_INDICATION NR_STUN_TYPE(NR_METHOD_SEND, \
michael@0 188 NR_CLASS_INDICATION)
michael@0 189 #define NR_STUN_MSG_DATA_INDICATION NR_STUN_TYPE(NR_METHOD_DATA, \
michael@0 190 NR_CLASS_INDICATION)
michael@0 191
michael@0 192 #define NR_STUN_MSG_PERMISSION_REQUEST NR_STUN_TYPE(NR_METHOD_CREATE_PERMISSION, \
michael@0 193 NR_CLASS_REQUEST)
michael@0 194 #define NR_STUN_MSG_PERMISSION_RESPONSE NR_STUN_TYPE(NR_METHOD_CREATE_PERMISSION, \
michael@0 195 NR_CLASS_RESPONSE)
michael@0 196 #define NR_STUN_MSG_PERMISSION_ERROR_RESPONSE NR_STUN_TYPE(NR_METHOD_CREATE_PERMISSION, \
michael@0 197 NR_CLASS_ERROR_RESPONSE)
michael@0 198
michael@0 199 #define NR_STUN_MSG_CHANNEL_BIND_REQUEST NR_STUN_TYPE(NR_METHOD_CHANNEL_BIND, \
michael@0 200 NR_CLASS_REQUEST)
michael@0 201 #define NR_STUN_MSG_CHANNEL_BIND_RESPONSE NR_STUN_TYPE(NR_METHOD_CHANNEL_BIND, \
michael@0 202 NR_CLASS_RESPONSE)
michael@0 203 #define NR_STUN_MSG_CHANNEL_BIND_ERROR_RESPONSE NR_STUN_TYPE(NR_METHOD_CHANNEL_BIND, \
michael@0 204 NR_CLASS_ERROR_RESPONSE)
michael@0 205
michael@0 206
michael@0 207 #endif /* USE_TURN */
michael@0 208
michael@0 209
michael@0 210 #define NR_STUN_AUTH_RULE_OPTIONAL (1<<0)
michael@0 211 #define NR_STUN_AUTH_RULE_SHORT_TERM (1<<8)
michael@0 212 #define NR_STUN_AUTH_RULE_LONG_TERM (1<<9)
michael@0 213
michael@0 214 #endif

mercurial