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