1 # This file is part of Scapy 2 # Scapy is free software: you can redistribute it and/or modify 3 # it under the terms of the GNU General Public License as published by 4 # the Free Software Foundation, either version 2 of the License, or 5 # any later version. 6 # 7 # Scapy is distributed in the hope that it will be useful, 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # GNU General Public License for more details. 11 # 12 # You should have received a copy of the GNU General Public License 13 # along with Scapy. If not, see <http://www.gnu.org/licenses/>. 14 15 # scapy.contrib.description = VLAN Query Protocol 16 # scapy.contrib.status = loads 17 18 from scapy.packet import * 19 from scapy.fields import * 20 from scapy.layers.inet import UDP 21 22 class VQP(Packet): 23 name = "VQP" 24 fields_desc = [ 25 ByteField("const", 1), 26 ByteEnumField("type", 1, { 27 1:"requestPort", 2:"responseVLAN", 28 3:"requestReconfirm", 4:"responseReconfirm" 29 }), 30 ByteEnumField("errorcodeaction", 0, { 31 0:"none",3:"accessDenied", 32 4:"shutdownPort", 5:"wrongDomain" 33 }), 34 ByteEnumField("unknown", 2, { 35 2:"inGoodResponse", 6:"inRequests" 36 }), 37 IntField("seq",0), 38 ] 39 40 class VQPEntry(Packet): 41 name = "VQPEntry" 42 fields_desc = [ 43 IntEnumField("datatype", 0, { 44 3073:"clientIPAddress", 3074:"portName", 45 3075:"VLANName", 3076:"Domain", 3077:"ethernetPacket", 46 3078:"ReqMACAddress", 3079:"unknown", 47 3080:"ResMACAddress" 48 }), 49 FieldLenField("len", None), 50 ConditionalField(IPField("datatom", "0.0.0.0"), 51 lambda p:p.datatype==3073), 52 ConditionalField(MACField("data", "00:00:00:00:00:00"), 53 lambda p:p.datatype==3078), 54 ConditionalField(MACField("data", "00:00:00:00:00:00"), 55 lambda p:p.datatype==3080), 56 ConditionalField(StrLenField("data", None, 57 length_from=lambda p:p.len), 58 lambda p:p.datatype not in [3073, 3078, 3080]), 59 ] 60 def post_build(self, p, pay): 61 if self.len is None: 62 l = len(p.data) 63 p = p[:2]+struct.pack("!H",l)+p[4:] 64 return p 65 66 bind_layers(UDP, VQP, sport=1589) 67 bind_layers(UDP, VQP, dport=1589) 68 bind_layers(VQP, VQPEntry, ) 69 bind_layers(VQPEntry, VQPEntry, ) 70