From a5311642f34de7ae00834ee78ddbcf820ddfbaf1 Mon Sep 17 00:00:00 2001
From: "zer0@platinum" <zer0@platinum>
Date: Tue, 29 Dec 2009 22:44:50 +0100
Subject: [PATCH] Support of VRRP.

Not fully tested. Based on:
http://trac.secdev.org/scapy/ticket/3
http://trac.secdev.org/scapy/ticket/60
---
 scapy/config.py      |  2 +-
 scapy/layers/vrrp.py | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 scapy/layers/vrrp.py

diff --git a/scapy/config.py b/scapy/config.py
index ebb15c67..af1b1e0c 100644
--- a/scapy/config.py
+++ b/scapy/config.py
@@ -366,7 +366,7 @@ extensions_paths: path or list of paths where extensions are to be looked for
     netcache = NetCache()
     load_layers = ["l2", "inet", "dhcp", "dns", "dot11", "gprs", "hsrp", "inet6", "ir", "isakmp", "l2tp",
                    "mgcp", "mobileip", "netbios", "netflow", "ntp", "ppp", "radius", "rip", "rtp",
-                   "sebek", "skinny", "smb", "snmp", "tftp", "x509", "bluetooth", "dhcp6", "llmnr", "sctp" ]
+                   "sebek", "skinny", "smb", "snmp", "tftp", "x509", "bluetooth", "dhcp6", "llmnr", "sctp", "vrrp" ]
     
 
 if not Conf.ipv6_enabled:
diff --git a/scapy/layers/vrrp.py b/scapy/layers/vrrp.py
new file mode 100644
index 00000000..a08a42f7
--- /dev/null
+++ b/scapy/layers/vrrp.py
@@ -0,0 +1,35 @@
+## This file is part of Scapy
+## See http://www.secdev.org/projects/scapy for more informations
+## Copyright (C) Philippe Biondi <phil@secdev.org>
+## Copyright (C) 6WIND <olivier.matz@6wind.com>
+## This program is published under a GPLv2 license
+
+from scapy.packet import *
+from scapy.fields import *
+from scapy.layers.inet import IP
+
+IPPROTO_VRRP=112
+
+# RFC 3768 - Virtual Router Redundancy Protocol (VRRP)
+class VRRP(Packet):
+    fields_desc = [
+        BitField("version" , 2, 4),
+        BitField("type" , 1, 4),
+        ByteField("vrid", 1),
+        ByteField("priority", 100),
+        FieldLenField("ipcount", None, count_of="addrlist", fmt="B"),
+        ByteField("authtype", 0),
+        ByteField("adv", 1),
+        XShortField("chksum", None),
+        FieldListField("addrlist", [], IPField("", "0.0.0.0"),
+                       count_from = lambda pkt: pkt.ipcount),
+        IntField("auth1", 0),
+        IntField("auth2", 0) ]
+
+    def post_build(self, p, pay):
+        if self.chksum is None:
+            ck = checksum(p)
+            p = p[:6]+chr(ck>>8)+chr(ck&0xff)+p[8:]
+        return p
+
+bind_layers( IP,            VRRP,          proto=IPPROTO_VRRP)
-- 
GitLab