summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2022-06-15 09:48:20 -0400
committerDaniil Baturin <daniil@vyos.io>2022-06-15 09:48:20 -0400
commitdb5952f2bb09a3997b3bef1904497a068fff59ce (patch)
tree112b91821638578950ad5e90826ea65fd5b6ef5d
parentaeb9491a7ac33314c78dce1157cecc4d6645acb6 (diff)
downloadvyos-1x-db5952f2bb09a3997b3bef1904497a068fff59ce.tar.gz
vyos-1x-db5952f2bb09a3997b3bef1904497a068fff59ce.zip
T2719: add reset command to the neighbor script
-rw-r--r--op-mode-definitions/ipv4-route.xml.in10
-rwxr-xr-xsrc/op_mode/neighbor.py19
2 files changed, 24 insertions, 5 deletions
diff --git a/op-mode-definitions/ipv4-route.xml.in b/op-mode-definitions/ipv4-route.xml.in
index 8f001d5bb..660b34496 100644
--- a/op-mode-definitions/ipv4-route.xml.in
+++ b/op-mode-definitions/ipv4-route.xml.in
@@ -39,7 +39,7 @@
<list>&lt;x.x.x.x&gt;</list>
</completionHelp>
</properties>
- <command>sudo ip neigh flush to "$5"</command>
+ <command>sudo ${vyos_op_scripts_dir}/neighbor.py reset --family inet --address "$5"</command>
</tagNode>
<tagNode name="interface">
<properties>
@@ -48,8 +48,14 @@
<script>${vyos_completion_dir}/list_interfaces.py</script>
</completionHelp>
</properties>
- <command>sudo ip neigh flush dev "$5"</command>
+ <command>sudo ${vyos_op_scripts_dir}/neighbor.py reset --family inet --interface "$5"</command>
</tagNode>
+ <node name="table">
+ <properties>
+ <help>Flush the ARP cache completely</help>
+ </properties>
+ <command>sudo ${vyos_op_scripts_dir}/neighbor.py reset --family inet</command>
+ </node>
</children>
</node>
<node name="route">
diff --git a/src/op_mode/neighbor.py b/src/op_mode/neighbor.py
index 1f686843d..13ea46b8f 100755
--- a/src/op_mode/neighbor.py
+++ b/src/op_mode/neighbor.py
@@ -92,12 +92,25 @@ def show(raw: bool, family: str, interface: typing.Optional[str], state: typing.
else:
return format_neighbors(data, interface)
+def reset(family: str, interface: typing.Optional[str], address: typing.Optional[str]):
+ from vyos.util import run
+
+ if address and interface:
+ raise ValueError("interface and address parameters are mutually exclusive")
+ elif address:
+ run(f"""ip --family {family} neighbor flush to {address}""")
+ elif interface:
+ run(f"""ip --family {family} neighbor flush dev {interface}""")
+ else:
+ # Flush an entire neighbor table
+ run(f"""ip --family {family} neighbor flush""")
-if __name__ == '__main__':
- from argparse import ArgumentParser
+if __name__ == '__main__':
try:
- print(opmode.run(sys.modules[__name__]))
+ res = opmode.run(sys.modules[__name__])
+ if res:
+ print(res)
except ValueError as e:
print(e)
sys.exit(1)