Commit 7b369d32 authored by Sigmund Augdal's avatar Sigmund Augdal

Added script to send unsolicited arp to clients when a router does failover

parent c5d01041
#! /usr/bin/env python
from scapy.all import sendp, Ether, ARP
import argparse
import logging
from nova_router import parse_ip, format_ip
from pyroute2.netlink.iproute import IPRoute
DESCRIPTION = "Send unsolicited arp packages"
BROADCAST_MAC = "ff:ff:ff:ff:ff:ff"
def parse_args():
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument('--interface', default="eth0",
help="Interface to send on")
parser.add_argument('--vip1')
parser.add_argument('--vip2')
parser.add_argument('--vip-up')
parser.add_argument('first_address', help="Address range to claim")
parser.add_argument('last_address', help="Address range to claim")
return parser.parse_args()
def mymac(interface):
return open("/sys/class/net/{}/address".format(interface)).read().strip()
def do_send(mymac, address, interface):
pkg = Ether(src=mymac, dst=BROADCAST_MAC) / ARP(pdst=address, op=1, psrc=address, hwdst=BROADCAST_MAC, hwsrc=mymac)
logging.info("Sending packet %s to interface %s", repr(pkg), interface)
# sendp(pkg, iface=interface)
def has_address(address):
ir = IPRoute()
for event in ir.get_addr():
if event['event'] == 'RTM_NEWADDR':
for (key, value) in event['attrs']:
if key == 'IFA_ADDRESS' and value == address:
return True
return False
def main():
logging.basicConfig(level=logging.DEBUG)
args = parse_args()
mac = mymac(args.interface)
do_send(mac, args.vip_up, args.interface)
if has_address(args.vip1) and has_address(args.vip2):
for address in range(parse_ip(args.first_address), parse_ip(args.last_address) + 1):
do_send(mac, format_ip(address), args.interface)
if __name__ == '__main__':
main()
......@@ -9,7 +9,7 @@ mkdir -p $target
cp userparameter_nova_router.conf $target
target=pkg/opt/nova_router_services
mkdir -p $target/bin
cp clean_stale.py dhcp_configurator.py iptables_configurator.py neighbors.py nova_bfd_monitor.py bfd-status $target/bin
cp arpy.py clean_stale.py dhcp_configurator.py iptables_configurator.py neighbors.py nova_bfd_monitor.py bfd-status $target/bin
cp utils/etcd_dump.py utils/etcd_restore.py $target/bin
mkdir -p $target/lib
cp init-functions $target/lib
......
......@@ -12,6 +12,7 @@ requires = [
'mock',
'scvmm-client-py',
'pyroute2',
'scapy',
]
setup(name='router-services',
......@@ -27,6 +28,7 @@ setup(name='router-services',
tests_require=requires,
dependency_links=[
'git+https://scm.uninett.no/nova/scvmm_client_py.git#egg=scvmm-client-py-0.4',
'git+https://github.com/jplana/python-etcd.git#egg=python-etcd-0.3.1'
'git+https://github.com/jplana/python-etcd.git#egg=python-etcd-0.3.1',
'http://www.secdev.org/projects/scapy/files/scapy-latest.tar.gz#egg=scapy-2.1.0',
],
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment