+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* SHARP - vty code
* Copyright (C) Cumulus Networks, Inc.
* Donald Sharp
- *
- * This file is part of FRR.
- *
- * FRR is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * FRR is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "linklist.h"
#include "link_state.h"
#include "cspf.h"
+#include "tc.h"
#include "sharpd/sharp_globals.h"
#include "sharpd/sharp_zebra.h"
#include "sharpd/sharp_nht.h"
#include "sharpd/sharp_vty.h"
-#ifndef VTYSH_EXTRACT_PL
#include "sharpd/sharp_vty_clippy.c"
-#endif
DEFINE_MTYPE_STATIC(SHARPD, SRV6_LOCATOR, "SRv6 Locator");
return CMD_SUCCESS;
}
+DEFPY (tc_filter_rate,
+ tc_filter_rate_cmd,
+ "sharp tc dev IFNAME$ifname \
+ source <A.B.C.D/M|X:X::X:X/M>$src \
+ destination <A.B.C.D/M|X:X::X:X/M>$dst \
+ ip-protocol <tcp|udp>$ip_proto \
+ src-port (1-65535)$src_port \
+ dst-port (1-65535)$dst_port \
+ rate RATE$ratestr",
+ SHARP_STR
+ "Traffic control\n"
+ "TC interface (for qdisc, class, filter)\n"
+ "TC interface name\n"
+ "TC filter source\n"
+ "TC filter source IPv4 prefix\n"
+ "TC filter source IPv6 prefix\n"
+ "TC filter destination\n"
+ "TC filter destination IPv4 prefix\n"
+ "TC filter destination IPv6 prefix\n"
+ "TC filter IP protocol\n"
+ "TC filter IP protocol TCP\n"
+ "TC filter IP protocol UDP\n"
+ "TC filter source port\n"
+ "TC filter source port\n"
+ "TC filter destination port\n"
+ "TC filter destination port\n"
+ "TC rate\n"
+ "TC rate number (bits/s) or rate string (suffixed with Bps or bit)\n")
+{
+ struct interface *ifp;
+ struct protoent *p;
+ uint64_t rate;
+
+ ifp = if_lookup_vrf_all(ifname);
+
+ if (!ifp) {
+ vty_out(vty, "%% Can't find interface %s\n", ifname);
+ return CMD_WARNING;
+ }
+
+ p = getprotobyname(ip_proto);
+ if (!p) {
+ vty_out(vty, "Unable to convert %s to proto id\n", ip_proto);
+ return CMD_WARNING;
+ }
+
+ if (tc_getrate(ratestr, &rate) != 0) {
+ vty_out(vty, "Unable to convert %s to rate\n", ratestr);
+ return CMD_WARNING;
+ }
+
+ if (sharp_zebra_send_tc_filter_rate(ifp, src, dst, p->p_proto, src_port,
+ dst_port, rate) != 0)
+ return CMD_WARNING;
+
+ return CMD_SUCCESS;
+}
+
void sharp_vty_init(void)
{
install_element(ENABLE_NODE, &install_routes_data_dump_cmd);
install_element(ENABLE_NODE, &sharp_interface_protodown_cmd);
install_element(ENABLE_NODE, &no_sharp_interface_protodown_cmd);
+ install_element(ENABLE_NODE, &tc_filter_rate_cmd);
+
return;
}