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('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)"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():
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__':
......@@ -9,7 +9,7 @@ mkdir -p $target
cp userparameter_nova_router.conf $target
mkdir -p $target/bin
cp bfd-status $target/bin
cp bfd-status $target/bin
cp utils/ utils/ $target/bin
mkdir -p $target/lib
cp init-functions $target/lib
......@@ -12,6 +12,7 @@ requires = [
......@@ -27,6 +28,7 @@ setup(name='router-services',
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