Imported Upstream version 0.3.2
[anytun.git] / wireshark-lua / satp.lua
1 --  anytun
2 --
3 --  The secure anycast tunneling protocol (satp) defines a protocol used
4 --  for communication between any combination of unicast and anycast
5 --  tunnel endpoints.  It has less protocol overhead than IPSec in Tunnel
6 --  mode and allows tunneling of every ETHER TYPE protocol (e.g.
7 --  ethernet, ip, arp ...). satp directly includes cryptography and
8 --  message authentication based on the methodes used by SRTP.  It is
9 --  intended to deliver a generic, scaleable and secure solution for
10 --  tunneling and relaying of packets of any protocol.
11 --
12 --
13 --  Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, 
14 --                          Christian Pointner <satp@wirdorange.org>
15 --
16 --  This file is part of Anytun.
17 --
18 --  Anytun is free software: you can redistribute it and/or modify
19 --  it under the terms of the GNU General Public License as published by
20 --  the Free Software Foundation, either version 3 of the License, or
21 --  any later version.
22 --
23 --  Anytun is distributed in the hope that it will be useful,
24 --  but WITHOUT ANY WARRANTY; without even the implied warranty of
25 --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 --  GNU General Public License for more details.
27 --
28 --  You should have received a copy of the GNU General Public License
29 --  along with anytun.  If not, see <http://www.gnu.org/licenses/>.
30
31
32 do
33  local proto_satp = Proto("SATP","Secure Anycast Tunneling Protocol")
34
35  local payload_types = {
36        [0x0800] = "IPv4",
37        [0x6558] = "Ethernet",
38        [0x86DD] = "IPv6"
39  }
40
41  local payload_dissector = {
42        [0x0800] = "ip",
43        [0x6558] = "eth",
44        [0x86DD] = "ipv6"
45  }
46
47  local field_seq = ProtoField.uint32("satp.seq","Sequence Number",base.DEC)
48  local field_sid = ProtoField.uint16("satp.sid","Sender ID",base.DEC)
49  local field_mux = ProtoField.uint16("satp.mux","Mux",base.DEC)
50  local field_ptype = ProtoField.uint16("satp.ptype","Payload Type (plain?)",base.HEX,payload_types)
51
52  proto_satp.fields = { field_seq, field_sid, field_mux, field_ptype }
53
54
55  -- create a function to dissect it
56  function proto_satp.dissector(buffer,pinfo,tree)
57     local info_string = "Sender Id: " .. buffer(4,2):uint() .. ", Mux: " .. buffer(6,2):uint() .. ", SeqNr: " .. buffer(0,4):uint()
58     pinfo.cols.protocol = "SATP"
59     pinfo.cols.info = info_string
60
61     local subtree = tree:add(proto_satp,buffer(),"SATP, " .. info_string)
62
63     subtree:add(field_seq, buffer(0,4))
64     subtree:add(field_sid, buffer(4,2))
65     subtree:add(field_mux, buffer(6,2))
66
67     local payload_type = buffer(8,2):uint()
68
69     if payload_dissector[payload_type] ~= nil then
70        subtree:add(field_ptype, buffer(8,2))
71        Dissector.get(payload_dissector[payload_type]):call(buffer(10):tvb(),pinfo,tree)
72     else
73        Dissector.get("data"):call(buffer(8):tvb(),pinfo,tree)
74     end
75  end
76
77  -- load the udp.port table
78
79  udp_table = DissectorTable.get("udp.port")
80  
81  -- register our protocol to handle udp port 4444
82  udp_table:add(4444,proto_satp)
83 end