1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15**********/
16// "mTunnel" multicast access service
17// Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved.
18// Encapsulation trailer for tunnels
19// C++ header
20
21#ifndef _TUNNEL_ENCAPS_HH
22#define _TUNNEL_ENCAPS_HH
23
24#ifndef _NET_ADDRESS_HH
25#include "NetAddress.hh"
26#endif
27
28typedef u_int16_t Cookie;
29
30class TunnelEncapsulationTrailer {
31 // The trailer is layed out as follows:
32 // bytes 0-1: source 'cookie'
33 // bytes 2-3: destination 'cookie'
34 // bytes 4-7: address
35 // bytes 8-9: port
36 // byte 10: ttl
37 // byte 11: command
38
39 // Optionally, there may also be a 4-byte 'auxilliary address'
40 // (e.g., for 'source-specific multicast' preceding this)
41 // bytes -4 through -1: auxilliary address
42
43 public:
44 Cookie& srcCookie()
45 { return *(Cookie*)byteOffset(0); }
46 Cookie& dstCookie()
47 { return *(Cookie*)byteOffset(2); }
48 u_int32_t& address()
49 { return *(u_int32_t*)byteOffset(4); }
50 Port& port()
51 { return *(Port*)byteOffset(8); }
52 u_int8_t& ttl()
53 { return *(u_int8_t*)byteOffset(10); }
54 u_int8_t& command()
55 { return *(u_int8_t*)byteOffset(11); }
56
57 u_int32_t& auxAddress()
58 { return *(u_int32_t*)byteOffset(-4); }
59
60 private:
61 inline char* byteOffset(int charIndex)
62 { return ((char*)this) + charIndex; }
63};
64
65const unsigned TunnelEncapsulationTrailerSize = 12; // bytes
66const unsigned TunnelEncapsulationTrailerAuxSize = 4; // bytes
67const unsigned TunnelEncapsulationTrailerMaxSize
68 = TunnelEncapsulationTrailerSize + TunnelEncapsulationTrailerAuxSize;
69
70// Command codes:
71// 0: unused
72const u_int8_t TunnelDataCmd = 1;
73const u_int8_t TunnelJoinGroupCmd = 2;
74const u_int8_t TunnelLeaveGroupCmd = 3;
75const u_int8_t TunnelTearDownCmd = 4;
76const u_int8_t TunnelProbeCmd = 5;
77const u_int8_t TunnelProbeAckCmd = 6;
78const u_int8_t TunnelProbeNackCmd = 7;
79const u_int8_t TunnelJoinRTPGroupCmd = 8;
80const u_int8_t TunnelLeaveRTPGroupCmd = 9;
81// 0x0A through 0x10: currently unused.
82const u_int8_t TunnelExtensionFlag = 0x80; // a flag, not a cmd code
83const u_int8_t TunnelDataAuxCmd
84 = (TunnelExtensionFlag|TunnelDataCmd);
85const u_int8_t TunnelJoinGroupAuxCmd
86 = (TunnelExtensionFlag|TunnelJoinGroupCmd);
87const u_int8_t TunnelLeaveGroupAuxCmd
88 = (TunnelExtensionFlag|TunnelLeaveGroupCmd);
89// Note: the TearDown, Probe, ProbeAck, ProbeNack cmds have no Aux version
90// 0x84 through 0x87: currently unused.
91const u_int8_t TunnelJoinRTPGroupAuxCmd
92 = (TunnelExtensionFlag|TunnelJoinRTPGroupCmd);
93const u_int8_t TunnelLeaveRTPGroupAuxCmd
94 = (TunnelExtensionFlag|TunnelLeaveRTPGroupCmd);
95// 0x8A through 0xFF: currently unused
96
97inline Boolean TunnelIsAuxCmd(u_int8_t cmd) {
98 return (cmd&TunnelExtensionFlag) != 0;
99}
100
101#endif
102