diff --git a/examples/cbq.init-v0.7.3 b/examples/cbq.init-v0.7.3 index 888aba43..35a0a05e 100644 --- a/examples/cbq.init-v0.7.3 +++ b/examples/cbq.init-v0.7.3 @@ -18,8 +18,7 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# along with this program; if not, see . # # To get the latest version, check on Freshmeat for actual location: # diff --git a/include/libnetlink.h b/include/libnetlink.h index ec3d6576..fe7d5d38 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -22,13 +22,22 @@ struct rtnl_handle extern int rcvbuf; -extern int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions); -extern int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, int protocol); +extern int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions) + __attribute__((warn_unused_result)); + +extern int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, + int protocol) + __attribute__((warn_unused_result)); + extern void rtnl_close(struct rtnl_handle *rth); -extern int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type); +extern int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type) + __attribute__((warn_unused_result)); extern int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int fam, int type, - __u32 filt_mask); -extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len); + __u32 filt_mask) + __attribute__((warn_unused_result)); +extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, + int len) + __attribute__((warn_unused_result)); typedef int (*rtnl_filter_t)(const struct sockaddr_nl *, struct nlmsghdr *n, void *); @@ -44,9 +53,12 @@ extern int rtnl_dump_filter_l(struct rtnl_handle *rth, extern int rtnl_dump_filter(struct rtnl_handle *rth, rtnl_filter_t filter, void *arg); extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, - unsigned groups, struct nlmsghdr *answer); -extern int rtnl_send(struct rtnl_handle *rth, const void *buf, int); -extern int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int); + unsigned groups, struct nlmsghdr *answer) + __attribute__((warn_unused_result)); +extern int rtnl_send(struct rtnl_handle *rth, const void *buf, int) + __attribute__((warn_unused_result)); +extern int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int) + __attribute__((warn_unused_result)); extern int addattr(struct nlmsghdr *n, int maxlen, int type); extern int addattr8(struct nlmsghdr *n, int maxlen, int type, __u8 data); diff --git a/include/utils.h b/include/utils.h index a3e310ee..a4b5b4cc 100644 --- a/include/utils.h +++ b/include/utils.h @@ -156,5 +156,5 @@ extern int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6); struct iplink_req; int iplink_parse(int argc, char **argv, struct iplink_req *req, char **name, char **type, char **link, char **dev, - int *group); + int *group, int *index); #endif /* __UTILS_H__ */ diff --git a/ip/Makefile b/ip/Makefile index 89a7a36a..6b08cb57 100644 --- a/ip/Makefile +++ b/ip/Makefile @@ -5,7 +5,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \ iplink_vlan.o link_veth.o link_gre.o iplink_can.o \ iplink_macvlan.o iplink_macvtap.o ipl2tp.o link_vti.o \ iplink_vxlan.o tcp_metrics.o iplink_ipoib.o ipnetconf.o link_ip6tnl.o \ - link_iptnl.o link_gre6.o iplink_bond.o + link_iptnl.o link_gre6.o iplink_bond.o iplink_hsr.o RTMONOBJ=rtmon.o diff --git a/ip/ip6tunnel.c b/ip/ip6tunnel.c index 463be42b..25d5ba32 100644 --- a/ip/ip6tunnel.c +++ b/ip/ip6tunnel.c @@ -12,8 +12,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* * Author: diff --git a/ip/ipaddrlabel.c b/ip/ipaddrlabel.c index 68a94ddf..8295727f 100644 --- a/ip/ipaddrlabel.c +++ b/ip/ipaddrlabel.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . * * * Based on iprule.c. diff --git a/ip/iplink.c b/ip/iplink.c index 58b6c203..343b29f9 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -47,7 +47,7 @@ void iplink_usage(void) fprintf(stderr, " [ txqueuelen PACKETS ]\n"); fprintf(stderr, " [ address LLADDR ]\n"); fprintf(stderr, " [ broadcast LLADDR ]\n"); - fprintf(stderr, " [ mtu MTU ]\n"); + fprintf(stderr, " [ mtu MTU ] [index IDX ]\n"); fprintf(stderr, " [ numtxqueues QUEUE_COUNT ]\n"); fprintf(stderr, " [ numrxqueues QUEUE_COUNT ]\n"); fprintf(stderr, " type TYPE [ ARGS ]\n"); @@ -178,7 +178,10 @@ static int iplink_have_newlink(void) req.n.nlmsg_type = RTM_NEWLINK; req.i.ifi_family = AF_UNSPEC; - rtnl_send(&rth, &req.n, req.n.nlmsg_len); + if (rtnl_send(&rth, &req.n, req.n.nlmsg_len) < 0) { + perror("request send failed"); + exit(1); + } rtnl_listen(&rth, accept_msg, NULL); } return have_rtnl_newlink; @@ -288,7 +291,7 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp, } int iplink_parse(int argc, char **argv, struct iplink_req *req, - char **name, char **type, char **link, char **dev, int *group) + char **name, char **type, char **link, char **dev, int *group, int *index) { int ret, len; char abuf[32]; @@ -312,6 +315,9 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, } else if (strcmp(*argv, "name") == 0) { NEXT_ARG(); *name = *argv; + } else if (strcmp(*argv, "index") == 0) { + NEXT_ARG(); + *index = atoi(*argv); } else if (matches(*argv, "link") == 0) { NEXT_ARG(); *link = *argv; @@ -503,6 +509,7 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) char *name = NULL; char *link = NULL; char *type = NULL; + int index = 0; int group; struct link_util *lu = NULL; struct iplink_req req; @@ -515,7 +522,7 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) req.n.nlmsg_type = cmd; req.i.ifi_family = preferred_family; - ret = iplink_parse(argc, argv, &req, &name, &type, &link, &dev, &group); + ret = iplink_parse(argc, argv, &req, &name, &type, &link, &dev, &group, &index); if (ret < 0) return ret; @@ -575,6 +582,8 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) } addattr_l(&req.n, sizeof(req), IFLA_LINK, &ifindex, 4); } + + req.i.ifi_index = index; } if (name) { diff --git a/ip/iplink_hsr.c b/ip/iplink_hsr.c new file mode 100644 index 00000000..136da358 --- /dev/null +++ b/ip/iplink_hsr.c @@ -0,0 +1,129 @@ +/* + * iplink_hsr.c HSR device support + * + * This program 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 of the License, or (at your option) any later version. + * + * Authors: Arvid Brodin + * + * Based on iplink_vlan.c by Patrick McHardy + */ + +#include +#include +#include +#include /* Needed by linux/if.h for some reason */ +#include +#include +#include "rt_names.h" +#include "utils.h" +#include "ip_common.h" + +static void usage(void) +{ + fprintf(stderr, +"Usage:\tip link add name NAME type hsr slave1 SLAVE1-IF slave2 SLAVE2-IF\n" +"\t[ supervision ADDR-BYTE ]\n" +"\n" +"NAME\n" +" name of new hsr device (e.g. hsr0)\n" +"SLAVE1-IF, SLAVE2-IF\n" +" the two slave devices bound to the HSR device\n" +"ADDR-BYTE\n" +" 0-255; the last byte of the multicast address used for HSR supervision\n" +" frames (default = 0)\n"); +} + +static int hsr_parse_opt(struct link_util *lu, int argc, char **argv, + struct nlmsghdr *n) +{ + int ifindex; + unsigned char multicast_spec; + + while (argc > 0) { + if (matches(*argv, "supervision") == 0) { + NEXT_ARG(); + if (get_u8(&multicast_spec, *argv, 0)) + invarg("ADDR-BYTE is invalid", *argv); + addattr_l(n, 1024, IFLA_HSR_MULTICAST_SPEC, + &multicast_spec, 1); + } else if (matches(*argv, "slave1") == 0) { + NEXT_ARG(); + ifindex = ll_name_to_index(*argv); + if (ifindex == 0) + invarg("No such interface", *argv); + addattr_l(n, 1024, IFLA_HSR_SLAVE1, &ifindex, 4); + } else if (matches(*argv, "slave2") == 0) { + NEXT_ARG(); + ifindex = ll_name_to_index(*argv); + if (ifindex == 0) + invarg("No such interface", *argv); + addattr_l(n, 1024, IFLA_HSR_SLAVE2, &ifindex, 4); + } else if (matches(*argv, "help") == 0) { + usage(); + return -1; + } else { + fprintf(stderr, "hsr: what is \"%s\"?\n", *argv); + usage(); + return -1; + } + argc--, argv++; + } + + return 0; +} + +static void hsr_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) +{ + SPRINT_BUF(b1); + + if (!tb) + return; + + if (tb[IFLA_HSR_SLAVE1] && + RTA_PAYLOAD(tb[IFLA_HSR_SLAVE1]) < sizeof(__u32)) + return; + if (tb[IFLA_HSR_SLAVE2] && + RTA_PAYLOAD(tb[IFLA_HSR_SLAVE2]) < sizeof(__u32)) + return; + if (tb[IFLA_HSR_SEQ_NR] && + RTA_PAYLOAD(tb[IFLA_HSR_SEQ_NR]) < sizeof(__u16)) + return; + if (tb[IFLA_HSR_SUPERVISION_ADDR] && + RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]) < ETH_ALEN) + return; + + fprintf(f, "slave1 "); + if (tb[IFLA_HSR_SLAVE1]) + fprintf(f, "%s ", + ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE1]))); + else + fprintf(f, " "); + + fprintf(f, "slave2 "); + if (tb[IFLA_HSR_SLAVE2]) + fprintf(f, "%s ", + ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE2]))); + else + fprintf(f, " "); + + if (tb[IFLA_HSR_SEQ_NR]) + fprintf(f, "sequence %d ", + rta_getattr_u16(tb[IFLA_HSR_SEQ_NR])); + + if (tb[IFLA_HSR_SUPERVISION_ADDR]) + fprintf(f, "supervision %s ", + ll_addr_n2a(RTA_DATA(tb[IFLA_HSR_SUPERVISION_ADDR]), + RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]), + ARPHRD_VOID, + b1, sizeof(b1))); +} + +struct link_util hsr_link_util = { + .id = "hsr", + .maxattr = IFLA_VLAN_MAX, + .parse_opt = hsr_parse_opt, + .print_opt = hsr_print_opt, +}; diff --git a/ip/ipnetconf.c b/ip/ipnetconf.c index 7353f595..0e44cc8c 100644 --- a/ip/ipnetconf.c +++ b/ip/ipnetconf.c @@ -165,7 +165,10 @@ static int do_show(int argc, char **argv) addattr_l(&req.n, sizeof(req), NETCONFA_IFINDEX, &filter.ifindex, sizeof(filter.ifindex)); - rtnl_send(&rth, &req.n, req.n.nlmsg_len); + if (rtnl_send(&rth, &req.n, req.n.nlmsg_len) < 0) { + perror("Can not send request"); + exit(1); + } rtnl_listen(&rth, print_netconf, stdout); } else { dump: diff --git a/ip/ipntable.c b/ip/ipntable.c index 193e50cf..00b3b0b7 100644 --- a/ip/ipntable.c +++ b/ip/ipntable.c @@ -12,8 +12,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* * based on ipneigh.c diff --git a/ip/ipprefix.c b/ip/ipprefix.c index 97250778..018913e8 100644 --- a/ip/ipprefix.c +++ b/ip/ipprefix.c @@ -12,8 +12,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* * based on ip.c, iproute.c diff --git a/ip/iptunnel.c b/ip/iptunnel.c index 40186d3d..8479c720 100644 --- a/ip/iptunnel.c +++ b/ip/iptunnel.c @@ -240,8 +240,9 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p) } } - if (p->iph.protocol == IPPROTO_IPIP || p->iph.protocol == IPPROTO_IPV6) { - if ((p->i_flags & GRE_KEY) || (p->o_flags & GRE_KEY)) { + if ((p->i_flags & GRE_KEY) || (p->o_flags & GRE_KEY)) { + if (!(p->i_flags & VTI_ISVTI) && + (p->iph.protocol != IPPROTO_GRE)) { fprintf(stderr, "Keys are not allowed with ipip and sit tunnels\n"); return -1; } diff --git a/ip/ipxfrm.c b/ip/ipxfrm.c index 411d9d53..2ebfd38e 100644 --- a/ip/ipxfrm.c +++ b/ip/ipxfrm.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* * based on ip.c, iproute.c diff --git a/ip/link_veth.c b/ip/link_veth.c index 7730f394..3cbeb544 100644 --- a/ip/link_veth.c +++ b/ip/link_veth.c @@ -26,7 +26,11 @@ static void usage(void) static int veth_parse_opt(struct link_util *lu, int argc, char **argv, struct nlmsghdr *hdr) { - char *name, *type, *link, *dev; + char *dev = NULL; + char *name = NULL; + char *link = NULL; + char *type = NULL; + int index = 0; int err, len; struct rtattr * data; int group; @@ -42,7 +46,7 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv, hdr->nlmsg_len += sizeof(struct ifinfomsg); err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)hdr, - &name, &type, &link, &dev, &group); + &name, &type, &link, &dev, &group, &index); if (err < 0) return err; @@ -53,6 +57,14 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv, addattr_l(hdr, 1024, IFLA_IFNAME, name, len); } + if (index) { + struct ifinfomsg *ifi = (struct ifinfomsg *)(data + 1); + ifi->ifi_index = index; + } + + if (group != -1) + addattr32(hdr, 1024, IFLA_GROUP, group); + data->rta_len = (void *)NLMSG_TAIL(hdr) - (void *)data; return argc - 1 - err; } diff --git a/ip/tunnel.c b/ip/tunnel.c index a6a28466..2f1ec302 100644 --- a/ip/tunnel.c +++ b/ip/tunnel.c @@ -12,8 +12,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* * split from ip_tunnel.c diff --git a/ip/tunnel.h b/ip/tunnel.h index 7e7fe135..9c2f5d29 100644 --- a/ip/tunnel.h +++ b/ip/tunnel.h @@ -12,8 +12,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* * Author: diff --git a/ip/xfrm.h b/ip/xfrm.h index 784a2012..773c92e9 100644 --- a/ip/xfrm.h +++ b/ip/xfrm.h @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* * Authors: diff --git a/ip/xfrm_monitor.c b/ip/xfrm_monitor.c index a1f5d53d..dea0afc6 100644 --- a/ip/xfrm_monitor.c +++ b/ip/xfrm_monitor.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* * based on ipmonitor.c diff --git a/ip/xfrm_policy.c b/ip/xfrm_policy.c index a8d8b98b..9421ba97 100644 --- a/ip/xfrm_policy.c +++ b/ip/xfrm_policy.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* * based on iproute.c diff --git a/ip/xfrm_state.c b/ip/xfrm_state.c index c4d2bf67..14f2fa76 100644 --- a/ip/xfrm_state.c +++ b/ip/xfrm_state.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* * based on iproute.c diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in index 1825dc54..94d07fc5 100644 --- a/man/man8/ip-link.8.in +++ b/man/man8/ip-link.8.in @@ -39,6 +39,8 @@ ip-link \- network device configuration .br .RB "[ " mtu .IR MTU " ]" +.RB "[ " index +.IR IDX " ]" .br .RB "[ " numtxqueues .IR QUEUE_COUNT " ]" @@ -54,6 +56,7 @@ ip-link \- network device configuration .BR bond " ]" .BR can " | " .BR dummy " | " +.BR hsr " | " .BR ifb " | " .BR ipoib " |" .BR macvlan " | " @@ -216,6 +219,10 @@ specifies the number of transmit queues for new device. .BI numrxqueues " QUEUE_COUNT " specifies the number of receive queues for new device. +.TP +.BI index " IDX " +specifies the desired index of the new virtual device. The link creation fails, if the index is busy. + .TP VXLAN Type Support For a link of type diff --git a/misc/arpd.c b/misc/arpd.c index ec9d570f..bfe7de94 100644 --- a/misc/arpd.c +++ b/misc/arpd.c @@ -428,7 +428,11 @@ static int do_one_request(struct nlmsghdr *n) static void load_initial_table(void) { - rtnl_wilddump_request(&rth, AF_INET, RTM_GETNEIGH); + if (rtnl_wilddump_request(&rth, AF_INET, RTM_GETNEIGH) < 0) { + perror("dump request failed"); + exit(1); + } + } static void get_kern_msg(void) diff --git a/misc/ss.c b/misc/ss.c index 6f38ae7e..e59ca5c7 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -996,7 +996,9 @@ static int xll_initted = 0; static void xll_init(void) { struct rtnl_handle rth; - rtnl_open(&rth, 0); + if (rtnl_open(&rth, 0) < 0) + exit(1); + ll_init_map(&rth); rtnl_close(&rth); xll_initted = 1; diff --git a/tc/m_action.c b/tc/m_action.c index 4acabef0..77479d6e 100644 --- a/tc/m_action.c +++ b/tc/m_action.c @@ -32,7 +32,6 @@ static struct action_util * action_list; #ifdef CONFIG_GACT int gact_ld = 0 ; //fuckin backward compatibility #endif -int batch_c = 0; int tab_flush = 0; static void act_usage(void) @@ -144,6 +143,7 @@ new_cmd(char **argv) if ((matches(*argv, "change") == 0) || (matches(*argv, "replace") == 0)|| (matches(*argv, "delete") == 0)|| + (matches(*argv, "get") == 0)|| (matches(*argv, "add") == 0)) return 1; @@ -303,7 +303,7 @@ tc_print_action(FILE * f, const struct rtattr *arg) for (i = 0; i < TCA_ACT_MAX_PRIO; i++) { if (tb[i]) { - fprintf(f, "\n\taction order %d: ", i + batch_c); + fprintf(f, "\n\taction order %d: ", i); if (0 > tc_print_one_action(f, tb[i])) { fprintf(f, "Error printing action\n"); } @@ -311,7 +311,6 @@ tc_print_action(FILE * f, const struct rtattr *arg) } - batch_c+=TCA_ACT_MAX_PRIO ; return 0; } diff --git a/tc/m_police.c b/tc/m_police.c index 300287e9..df295e04 100644 --- a/tc/m_police.c +++ b/tc/m_police.c @@ -38,7 +38,6 @@ static void usage(void) fprintf(stderr, " [ peakrate BPS ] [ avrate BPS ] [ overhead BYTES ]\n"); fprintf(stderr, " [ linklayer TYPE ] [ ACTIONTERM ]\n"); - fprintf(stderr, "Old Syntax ACTIONTERM := action [/NOTEXCEEDACT] \n"); fprintf(stderr, "New Syntax ACTIONTERM := conform-exceed [/NOTEXCEEDACT] \n"); fprintf(stderr, "Where: *EXCEEDACT := pipe | ok | reclassify | drop | continue \n"); fprintf(stderr, "Where: pipe is only valid for new syntax \n"); @@ -150,6 +149,7 @@ int act_parse_police(struct action_util *a,int *argc_p, char ***argv_p, int tca_ while (argc > 0) { + fprintf(stderr,"police argc %d argv %s\n", argc, *argv); if (matches(*argv, "index") == 0) { NEXT_ARG(); if (get_u32(&p.index, *argv, 10)) { @@ -230,8 +230,7 @@ int act_parse_police(struct action_util *a,int *argc_p, char ***argv_p, int tca_ p.action = TC_POLICE_OK; } else if (matches(*argv, "pipe") == 0) { p.action = TC_POLICE_PIPE; - } else if (strcmp(*argv, "action") == 0 || - strcmp(*argv, "conform-exceed") == 0) { + } else if (strcmp(*argv, "conform-exceed") == 0) { NEXT_ARG(); if (get_police_result(&p.action, &presult, *argv)) { fprintf(stderr, "Illegal \"action\"\n"); diff --git a/tc/m_simple.c b/tc/m_simple.c index 02244406..a8e1d6b2 100644 --- a/tc/m_simple.c +++ b/tc/m_simple.c @@ -188,9 +188,9 @@ static int print_simple(struct action_util *au, FILE * f, struct rtattr *arg) if (tb[TCA_DEF_TM]) { struct tcf_t *tm = RTA_DATA(tb[TCA_DEF_TM]); print_tm(f, tm); - fprintf(f, "\n"); } } + fprintf(f, "\n"); return 0; } diff --git a/tc/m_skbedit.c b/tc/m_skbedit.c index c7eef44f..4b4ee060 100644 --- a/tc/m_skbedit.c +++ b/tc/m_skbedit.c @@ -12,9 +12,8 @@ * 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; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307 USA. + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . * * Authors: Alexander Duyck * @@ -100,6 +99,7 @@ parse_skbedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, argv++; } + sel.action = TC_ACT_PIPE; if (argc) { if (matches(*argv, "reclassify") == 0) { sel.action = TC_ACT_RECLASSIFY; @@ -165,6 +165,7 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg) __u32 *priority; __u32 *mark; __u16 *queue_mapping; + struct tc_skbedit *p = NULL; if (arg == NULL) return -1; @@ -175,6 +176,7 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg) fprintf(f, "[NULL skbedit parameters]"); return -1; } + p = RTA_DATA(tb[TCA_SKBEDIT_PARMS]); fprintf(f, " skbedit"); @@ -191,6 +193,8 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg) fprintf(f, " mark %d", *mark); } + fprintf(f, "\n\t index %d ref %d bind %d", p->index, p->refcnt, p->bindcnt); + if (show_stats) { if (tb[TCA_SKBEDIT_TM]) { struct tcf_t *tm = RTA_DATA(tb[TCA_SKBEDIT_TM]); @@ -198,6 +202,8 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg) } } + fprintf(f, "\n "); + return 0; } diff --git a/tc/q_multiq.c b/tc/q_multiq.c index 546ae011..de292027 100644 --- a/tc/q_multiq.c +++ b/tc/q_multiq.c @@ -12,9 +12,8 @@ * 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; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place - Suite 330, Boston, MA 02111-1307 USA. + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . * * Author: Alexander Duyck * diff --git a/tc/tc_util.c b/tc/tc_util.c index 2f979dfa..15fb0534 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -198,28 +198,22 @@ int get_rate64(__u64 *rate, const char *str) void print_rate(char *buf, int len, __u64 rate) { - double tmp = (double)rate*8; extern int use_iec; + unsigned long kilo = use_iec ? 1024 : 1000; + const char *str = use_iec ? "i" : ""; + int i = 0; + static char *units[5] = {"", "K", "M", "G", "T"}; - if (use_iec) { - if (tmp >= 1000.0*1024.0*1024.0*1024.0) - snprintf(buf, len, "%.0fGibit", tmp/(1024.0*1024.0*1024.0)); - else if (tmp >= 1000.0*1024.0*1024.0) - snprintf(buf, len, "%.0fMibit", tmp/(1024.0*1024.0)); - else if (tmp >= 1000.0*1024) - snprintf(buf, len, "%.0fKibit", tmp/1024); - else - snprintf(buf, len, "%.0fbit", tmp); - } else { - if (tmp >= 1000.0*1000000000.0) - snprintf(buf, len, "%.0fGbit", tmp/1000000000.0); - else if (tmp >= 1000.0*1000000.0) - snprintf(buf, len, "%.0fMbit", tmp/1000000.0); - else if (tmp >= 1000.0 * 1000.0) - snprintf(buf, len, "%.0fKbit", tmp/1000.0); - else - snprintf(buf, len, "%.0fbit", tmp); + rate <<= 3; /* bytes/sec -> bits/sec */ + + for (i = 0; i < ARRAY_SIZE(units); i++) { + if (rate < kilo) + break; + if (((rate % kilo) != 0) && rate < 1000*kilo) + break; + rate /= kilo; } + snprintf(buf, len, "%.0f%s%sbit", (double)rate, units[i], str); } char * sprint_rate(__u64 rate, char *buf)