Skip to content

Commit

Permalink
ovs-router: Add "ovs/route/lookup" command
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Pravin B Shelar <[email protected]>
  • Loading branch information
yamt committed Dec 12, 2014
1 parent 2e60142 commit bc78679
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README-native-tunneling.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 27 additions & 0 deletions lib/ovs-router.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}

0 comments on commit bc78679

Please sign in to comment.