Commit aca111bc authored by Olav Morken's avatar Olav Morken

Fix router responding to proxy ARP requests when down

parent bbcddb7f
......@@ -22,7 +22,7 @@ def main(logfile, interface):
bfd.set_state(state)
logging.info("bfd-check starting, initial state: %s", state)
upstream_state = bfd.get_upstream_state()
bfd.first_upstream_state(upstream_state)
bfd.first_upstream_state(interface, upstream_state)
while True:
time.sleep(1)
new_state = bfd.check_state(interface)
......@@ -31,7 +31,7 @@ def main(logfile, interface):
logging.info("state changed from %s to %s", state, new_state)
state = new_state
new_upstream_state = bfd.get_upstream_state()
bfd.new_upstream_state(new_upstream_state, upstream_state)
bfd.new_upstream_state(interface, new_upstream_state, upstream_state)
upstream_state = new_upstream_state
......
......@@ -51,71 +51,78 @@ def get_upstream_state():
return dict(ipv4=0, ipv6=0)
def up_ipv4():
def set_proxy_arp_pvlan(interface, value):
with open('/proc/sys/net/ipv4/conf/{interface}/proxy_arp_pvlan'.format(interface=interface), 'w') as fh:
fh.write(str(value))
def up_ipv4(interface):
if subprocess.call(['/usr/local/sbin/start_ucarp']) == 0:
logging.info("Successfully started ucarp")
else:
logging.error("Failure starting ucarp")
set_proxy_arp_pvlan(interface, 1)
def up_ipv6():
def up_ipv6(interface):
if subprocess.call(['systemctl', 'start', 'radvd']) == 0:
logging.info("Successfully started radvd")
else:
logging.error("Failure starting radvd")
def down_ipv4():
def down_ipv4(interface):
set_proxy_arp_pvlan(interface, 0)
if subprocess.call(['/usr/bin/pkill', 'ucarp']) == 0:
logging.info("Successfully stopped ucarp")
else:
logging.error("Failure stopping ucarp")
def down_ipv6():
def down_ipv6(interface):
if subprocess.call(['systemctl', 'stop', 'radvd']) == 0:
logging.info("Successfully stopped radvd")
else:
logging.error("Failure stopping radvd")
def up(proto):
def up(interface, proto):
if proto == "ipv4":
up_ipv4()
up_ipv4(interface)
elif proto == "ipv6":
up_ipv6()
up_ipv6(interface)
def down(proto):
def down(interface, proto):
if proto == "ipv4":
down_ipv4()
down_ipv4(interface)
elif proto == "ipv6":
down_ipv6()
down_ipv6(interface)
def first_upstream_state(sessions_up):
def first_upstream_state(interface, sessions_up):
for proto in 'ipv4', 'ipv6':
current = sessions_up[proto]
if current == 0:
logging.warning("No %s connectivity at startup", proto)
down(proto)
down(interface, proto)
elif current == 1:
logging.info("No redundant %s connectivty at startup", proto)
up(proto)
up(interface, proto)
else:
logging.info("Redundant %s connectivity at startup", proto)
up(proto)
up(interface, proto)
def new_upstream_state(sessions_up, previous_sessions_up):
def new_upstream_state(interface, sessions_up, previous_sessions_up):
for proto in 'ipv4', 'ipv6':
current = sessions_up[proto]
previous = previous_sessions_up[proto]
if current == 0 and previous > 0:
logging.warning("Lost %s connectivity!", proto)
down(proto)
down(interface, proto)
elif current > 0 and previous == 0:
up(proto)
up(interface, proto)
if current == 1:
logging.info("Regained partial %s connectivity", proto)
else:
......
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