diff options
author | Nobuhiro MIKI <nmiki@yahoo-corp.jp> | 2023-03-06 11:49:16 +0900 |
---|---|---|
committer | Ilya Maximets <i.maximets@ovn.org> | 2023-03-07 18:23:01 +0100 |
commit | 915f084b9ff80f32e265c66c9b1aa51f9bbbd275 (patch) | |
tree | 9a05c3a4ffbd61fa6a78672d5a0d8e7f5349d6a8 /lib | |
parent | de6589799e7e810d5ff243b7b00fd2af5bf99ff2 (diff) | |
download | openvswitch-915f084b9ff80f32e265c66c9b1aa51f9bbbd275.tar.gz |
ovs-router: Cleanup parser for ovs/route/add command.
This patch cleans up the parser to accept pkt_mark and gw in any order.
pkt_mark and gw are normally expected to be specified exactly once.
However, as with other tools, if specified multiple times, the last
specification is used. Also, pkt_mark and gw have separate prefix
strings so they can be parsed in any order.
Acked-by: Eelco Chaudron <echaudro@redhat.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Nobuhiro MIKI <nmiki@yahoo-corp.jp>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ovs-router.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/lib/ovs-router.c b/lib/ovs-router.c index 5d0fbd503..b5ac1edb6 100644 --- a/lib/ovs-router.c +++ b/lib/ovs-router.c @@ -345,41 +345,46 @@ ovs_router_add(struct unixctl_conn *conn, int argc, struct in6_addr ip6; uint32_t mark = 0; unsigned int plen; + ovs_be32 gw = 0; + bool is_ipv6; ovs_be32 ip; int err; + int i; if (scan_ipv4_route(argv[1], &ip, &plen)) { - ovs_be32 gw = 0; - - if (argc > 3) { - if (!ovs_scan(argv[3], "pkt_mark=%"SCNi32, &mark) && - !ip_parse(argv[3], &gw)) { - unixctl_command_reply_error(conn, "Invalid pkt_mark or gateway"); - return; - } - } in6_addr_set_mapped_ipv4(&ip6, ip); - if (gw) { - in6_addr_set_mapped_ipv4(&gw6, gw); - } plen += 96; + is_ipv6 = false; } else if (scan_ipv6_route(argv[1], &ip6, &plen)) { - if (argc > 3) { - if (!ovs_scan(argv[3], "pkt_mark=%"SCNi32, &mark) && - !ipv6_parse(argv[3], &gw6)) { - unixctl_command_reply_error(conn, "Invalid pkt_mark or IPv6 gateway"); - return; - } - } + is_ipv6 = true; } else { - unixctl_command_reply_error(conn, "Invalid parameters"); + unixctl_command_reply_error(conn, + "Invalid 'ip_addr/prefix_len' parameter"); return; } - if (argc > 4) { - if (!ovs_scan(argv[4], "pkt_mark=%"SCNi32, &mark)) { - unixctl_command_reply_error(conn, "Invalid pkt_mark"); - return; + + /* Parse optional parameters. */ + for (i = 3; i < argc; i++) { + if (ovs_scan(argv[i], "pkt_mark=%"SCNi32, &mark)) { + continue; + } + + if (is_ipv6) { + if (ipv6_parse(argv[i], &gw6)) { + continue; + } + } else { + if (ip_parse(argv[i], &gw)) { + continue; + } } + + unixctl_command_reply_error(conn, "Invalid pkt_mark or IP gateway"); + return; + } + + if (gw) { + in6_addr_set_mapped_ipv4(&gw6, gw); } err = ovs_router_insert__(mark, plen + 32, false, &ip6, plen, argv[2], &gw6); |