]>
git.proxmox.com Git - mirror_frr.git/blob - lib/tc.c
2 * Traffic Control (TC) main library
3 * Copyright (C) 2022 Shichu Yang
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 int tc_getrate(const char *str
, uint64_t *rate
)
25 uint64_t raw
= strtoull(str
, &endp
, 10);
30 /* if the string only contains a number, it must be valid rate (bps) */
31 bool valid
= (*endp
== '\0');
34 bool bytes
= false, binary_base
= false;
38 if (strcmp(p
, "Bps") == 0) {
42 } else if (strcmp(p
, "bit") == 0) {
79 for (int i
= 0; i
< power
; i
++)
80 raw
*= binary_base
? 1024ULL : 1000ULL;