aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>2014-11-17 15:05:54 +0900
committerYAMAMOTO Takashi <yamamoto@valinux.co.jp>2014-12-12 11:55:32 +0900
commitbc786797628efb67fb5fda93203b60481f6907db (patch)
treede9bdd8d925d7a058a7a5ab5556b7eb04bf64d0f
parent2e601425c6075b05cde37a1b9c64cc29f4791f16 (diff)
ovs-router: Add "ovs/route/lookup" command
This command is useful at least for testing. Example output: % ovs-appctl ovs/route/lookup '10.0.0.1' gateway 172.17.0.254 dev wm0 % Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Acked-by: Pravin B Shelar <pshelar@nicira.com>
-rw-r--r--README-native-tunneling.md2
-rw-r--r--lib/ovs-router.c27
2 files changed, 29 insertions, 0 deletions
diff --git a/README-native-tunneling.md b/README-native-tunneling.md
index 0ffd82b92..746d089c4 100644
--- a/README-native-tunneling.md
+++ b/README-native-tunneling.md
@@ -57,6 +57,8 @@ Tunnel routing table:
ovs-appctl ovs/route/show
To del route:
ovs-appctl ovs/route/del <IP address>/<prefix length>
+ To look up and display the route for a destination:
+ ovs-appctl ovs/route/lookup <IP address>
ARP:
To see arp cache content:
diff --git a/lib/ovs-router.c b/lib/ovs-router.c
index b095f681e..a12135437 100644
--- a/lib/ovs-router.c
+++ b/lib/ovs-router.c
@@ -260,6 +260,31 @@ ovs_router_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
ds_destroy(&ds);
}
+static void
+ovs_router_lookup_cmd(struct unixctl_conn *conn, int argc OVS_UNUSED,
+ const char *argv[], void *aux OVS_UNUSED)
+{
+ ovs_be32 ip;
+ unsigned int plen;
+
+ if (scan_ipv4_route(argv[1], &ip, &plen) && plen == 32) {
+ char iface[IFNAMSIZ];
+ ovs_be32 gw;
+
+ if (ovs_router_lookup(ip, iface, &gw)) {
+ struct ds ds = DS_EMPTY_INITIALIZER;
+
+ ds_put_format(&ds, "gateway " IP_FMT "\n", IP_ARGS(gw));
+ ds_put_format(&ds, "dev %s\n", iface);
+ unixctl_command_reply(conn, ds_cstr(&ds));
+ } else {
+ unixctl_command_reply(conn, "Not found");
+ }
+ } else {
+ unixctl_command_reply(conn, "Invalid parameters");
+ }
+}
+
void
ovs_router_flush(void)
{
@@ -289,4 +314,6 @@ ovs_router_init(void)
unixctl_command_register("ovs/route/show", "", 0, 0, ovs_router_show, NULL);
unixctl_command_register("ovs/route/del", "ipv4_addr/prefix_len", 1, 1, ovs_router_del,
NULL);
+ unixctl_command_register("ovs/route/lookup", "ipv4_addr", 1, 1,
+ ovs_router_lookup_cmd, NULL);
}