Commit 32a121cb authored by Stephen Hemminger's avatar Stephen Hemminger

tc: code cleanup

Use checkpatch to fix whitespace and other style issues.
parent 4733b18a
......@@ -49,7 +49,7 @@ static int cmp_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
memset(&cmp, 0, sizeof(cmp));
#define PARSE_ERR(CARG, FMT, ARGS...) \
em_parse_error(EINVAL, args, CARG, &cmp_ematch_util, FMT ,##ARGS)
em_parse_error(EINVAL, args, CARG, &cmp_ematch_util, FMT, ##ARGS)
if (args == NULL)
return PARSE_ERR(args, "cmp: missing arguments");
......
......@@ -52,8 +52,8 @@ union ip_set_name_index {
#define IP_SET_OP_GET_BYNAME 0x00000006 /* Get set index by name */
struct ip_set_req_get_set {
unsigned op;
unsigned version;
unsigned int op;
unsigned int version;
union ip_set_name_index set;
};
......@@ -62,14 +62,14 @@ struct ip_set_req_get_set {
#define IP_SET_OP_VERSION 0x00000100 /* Ask kernel version */
struct ip_set_req_version {
unsigned op;
unsigned version;
unsigned int op;
unsigned int version;
};
#endif /* IPSET_INVALID_ID */
extern struct ematch_util ipset_ematch_util;
static int get_version(unsigned *version)
static int get_version(unsigned int *version)
{
int res, sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
struct ip_set_req_version req_version;
......@@ -95,6 +95,7 @@ static int do_getsockopt(struct ip_set_req_get_set *req)
{
int sockfd, res;
socklen_t size = sizeof(struct ip_set_req_get_set);
sockfd = get_version(&req->version);
if (sockfd < 0)
return -1;
......@@ -107,8 +108,7 @@ static int do_getsockopt(struct ip_set_req_get_set *req)
if (size != sizeof(struct ip_set_req_get_set)) {
fprintf(stderr,
"Incorrect return size from kernel during ipset lookup, "
"(want %zu, got %zu)\n",
"Incorrect return size from kernel during ipset lookup, (want %zu, got %zu)\n",
sizeof(struct ip_set_req_get_set), (size_t)size);
return -1;
}
......@@ -158,29 +158,29 @@ get_set_byname(const char *setname, struct xt_set_info *info)
static int
parse_dirs(const char *opt_arg, struct xt_set_info *info)
{
char *saved = strdup(opt_arg);
char *ptr, *tmp = saved;
char *saved = strdup(opt_arg);
char *ptr, *tmp = saved;
if (!tmp) {
perror("strdup");
return -1;
}
while (info->dim < IPSET_DIM_MAX && tmp != NULL) {
info->dim++;
ptr = strsep(&tmp, ",");
if (strncmp(ptr, "src", 3) == 0)
info->flags |= (1 << info->dim);
else if (strncmp(ptr, "dst", 3) != 0) {
fputs("You must specify (the comma separated list of) 'src' or 'dst'\n", stderr);
while (info->dim < IPSET_DIM_MAX && tmp != NULL) {
info->dim++;
ptr = strsep(&tmp, ",");
if (strncmp(ptr, "src", 3) == 0)
info->flags |= (1 << info->dim);
else if (strncmp(ptr, "dst", 3) != 0) {
fputs("You must specify (the comma separated list of) 'src' or 'dst'\n", stderr);
free(saved);
return -1;
}
}
}
if (tmp)
fprintf(stderr, "Can't be more src/dst options than %u", IPSET_DIM_MAX);
free(saved);
if (tmp)
fprintf(stderr, "Can't be more src/dst options than %u", IPSET_DIM_MAX);
free(saved);
return tmp ? -1 : 0;
}
......@@ -204,7 +204,7 @@ static int ipset_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
memset(&set_info, 0, sizeof(set_info));
#define PARSE_ERR(CARG, FMT, ARGS...) \
em_parse_error(EINVAL, args, CARG, &ipset_ematch_util, FMT ,##ARGS)
em_parse_error(EINVAL, args, CARG, &ipset_ematch_util, FMT, ##ARGS)
if (args == NULL)
return PARSE_ERR(args, "ipset: missing set name");
......@@ -238,7 +238,7 @@ static int ipset_print_eopt(FILE *fd, struct tcf_ematch_hdr *hdr, void *data,
int data_len)
{
int i;
char setname[IPSET_MAXNAMELEN];
char setname[IPSET_MAXNAMELEN];
const struct xt_set_info *set_info = data;
if (data_len != sizeof(*set_info)) {
......@@ -246,7 +246,7 @@ static int ipset_print_eopt(FILE *fd, struct tcf_ematch_hdr *hdr, void *data,
return -1;
}
if (get_set_byid(setname, set_info->index))
if (get_set_byid(setname, set_info->index))
return -1;
fputs(setname, fd);
for (i = 1; i <= set_info->dim; i++) {
......
......@@ -41,9 +41,9 @@ static void meta_print_usage(FILE *fd)
struct meta_entry {
int id;
char * kind;
char * mask;
char * desc;
char *kind;
char *mask;
char *desc;
} meta_table[] = {
#define TCF_META_ID_SECTION 0
#define __A(id, name, mask, desc) { TCF_META_ID_##id, name, mask, desc }
......@@ -102,7 +102,7 @@ struct meta_entry {
__A(SK_RMEM_ALLOC, "sk_rmem", "i", "RMEM"),
__A(SK_WMEM_ALLOC, "sk_wmem", "i", "WMEM"),
__A(SK_OMEM_ALLOC, "sk_omem", "i", "OMEM"),
__A(SK_WMEM_QUEUED, "sk_wmem_queue","i", "WMEM queue"),
__A(SK_WMEM_QUEUED, "sk_wmem_queue", "i", "WMEM queue"),
__A(SK_SND_QLEN, "sk_snd_queue", "i", "Send queue length"),
__A(SK_RCV_QLEN, "sk_rcv_queue", "i", "Receive queue length"),
__A(SK_ERR_QLEN, "sk_err_queue", "i", "Error queue length"),
......@@ -122,11 +122,11 @@ static inline int map_type(char k)
return INT_MAX;
}
static struct meta_entry * lookup_meta_entry(struct bstr *kind)
static struct meta_entry *lookup_meta_entry(struct bstr *kind)
{
int i;
for (i = 0; i < (sizeof(meta_table)/sizeof(meta_table[0])); i++)
for (i = 0; i < ARRAY_SIZE(meta_table); i++)
if (!bstrcmp(kind, meta_table[i].kind) &&
meta_table[i].id != 0)
return &meta_table[i];
......@@ -134,11 +134,11 @@ static struct meta_entry * lookup_meta_entry(struct bstr *kind)
return NULL;
}
static struct meta_entry * lookup_meta_entry_byid(int id)
static struct meta_entry *lookup_meta_entry_byid(int id)
{
int i;
for (i = 0; i < (sizeof(meta_table)/sizeof(meta_table[0])); i++)
for (i = 0; i < ARRAY_SIZE(meta_table); i++)
if (meta_table[i].id == id)
return &meta_table[i];
......@@ -159,6 +159,7 @@ static inline void dump_value(struct nlmsghdr *n, int tlv, unsigned long val,
case TCF_META_TYPE_VAR:
if (TCF_META_ID(hdr->kind) == TCF_META_ID_VALUE) {
struct bstr *a = (struct bstr *) val;
addattr_l(n, MAX_MSG, tlv, a->data, a->len);
}
break;
......@@ -192,7 +193,7 @@ static void list_meta_ids(FILE *fd)
" ID Type Description\n" \
"--------------------------------------------------------");
for (i = 0; i < (sizeof(meta_table)/sizeof(meta_table[0])); i++) {
for (i = 0; i < ARRAY_SIZE(meta_table); i++) {
if (meta_table[i].id == TCF_META_ID_SECTION) {
fprintf(fd, "\n%s:\n", meta_table[i].kind);
} else {
......@@ -231,7 +232,7 @@ static void list_meta_ids(FILE *fd)
#define PARSE_FAILURE ((void *) (-1))
#define PARSE_ERR(CARG, FMT, ARGS...) \
em_parse_error(EINVAL, args, CARG, &meta_ematch_util, FMT ,##ARGS)
em_parse_error(EINVAL, args, CARG, &meta_ematch_util, FMT, ##ARGS)
static inline int can_adopt(struct tcf_meta_val *val)
{
......@@ -308,7 +309,7 @@ compatible:
a = bstr_next(arg);
while(a) {
while (a) {
if (!bstrcmp(a, "shift")) {
unsigned long shift;
......@@ -441,7 +442,7 @@ static inline int print_value(FILE *fd, int type, struct rtattr *rta)
return -1;
}
switch(type) {
switch (type) {
case TCF_META_TYPE_INT:
if (RTA_PAYLOAD(rta) < sizeof(__u32)) {
fprintf(stderr, "meta int type value TLV " \
......
......@@ -49,7 +49,7 @@ static int nbyte_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
memset(&nb, 0, sizeof(nb));
#define PARSE_ERR(CARG, FMT, ARGS...) \
em_parse_error(EINVAL, args, CARG, &nbyte_ematch_util, FMT ,##ARGS)
em_parse_error(EINVAL, args, CARG, &nbyte_ematch_util, FMT, ##ARGS)
if (args == NULL)
return PARSE_ERR(args, "nbyte: missing arguments");
......
......@@ -44,7 +44,7 @@ static int u32_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
memset(&u_key, 0, sizeof(u_key));
#define PARSE_ERR(CARG, FMT, ARGS...) \
em_parse_error(EINVAL, args, CARG, &u32_ematch_util, FMT ,##ARGS)
em_parse_error(EINVAL, args, CARG, &u32_ematch_util, FMT, ##ARGS)
if (args == NULL)
return PARSE_ERR(args, "u32: missing arguments");
......@@ -85,6 +85,7 @@ static int u32_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
nh_len = strlen("nexthdr+");
if (a->len > nh_len && !memcmp(a->data, "nexthdr+", nh_len)) {
char buf[a->len - nh_len + 1];
offmask = -1;
memcpy(buf, a->data + nh_len, a->len - nh_len);
offset = strtoul(buf, NULL, 0);
......
......@@ -27,7 +27,7 @@
static void explain(void)
{
fprintf(stderr, "Usage: ... basic [ match EMATCH_TREE ] \n");
fprintf(stderr, "Usage: ... basic [ match EMATCH_TREE ]\n");
fprintf(stderr, " [ action ACTION_SPEC ] [ classid CLASSID ]\n");
fprintf(stderr, "\n");
fprintf(stderr, "Where: SELECTOR := SAMPLE SAMPLE ...\n");
......@@ -56,7 +56,7 @@ static int basic_parse_opt(struct filter_util *qu, char *handle,
if (argc == 0)
return 0;
tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
tail = (struct rtattr *)(((void *)n)+NLMSG_ALIGN(n->nlmsg_len));
addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
while (argc > 0) {
......@@ -69,7 +69,8 @@ static int basic_parse_opt(struct filter_util *qu, char *handle,
continue;
} else if (matches(*argv, "classid") == 0 ||
strcmp(*argv, "flowid") == 0) {
unsigned handle;
unsigned int handle;
NEXT_ARG();
if (get_tc_classid(&handle, *argv)) {
fprintf(stderr, "Illegal \"classid\"\n");
......@@ -102,7 +103,7 @@ static int basic_parse_opt(struct filter_util *qu, char *handle,
argc--; argv++;
}
tail->rta_len = (((void*)n)+n->nlmsg_len) - (void*)tail;
tail->rta_len = (((void *)n)+n->nlmsg_len) - (void *)tail;
return 0;
}
......
......@@ -40,7 +40,7 @@ static int cgroup_parse_opt(struct filter_util *qu, char *handle,
t->tcm_handle = h;
tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
tail = (struct rtattr *)(((void *)n)+NLMSG_ALIGN(n->nlmsg_len));
addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
while (argc > 0) {
......@@ -76,7 +76,7 @@ static int cgroup_parse_opt(struct filter_util *qu, char *handle,
}
}
tail->rta_len = (((void*)n)+n->nlmsg_len) - (void*)tail;
tail->rta_len = (((void *)n)+n->nlmsg_len) - (void *)tail;
return 0;
}
......
......@@ -30,8 +30,8 @@ static void explain(void)
" [ action ACTION_SPEC ]\n"
"\n"
"KEY-LIST := [ KEY-LIST , ] KEY\n"
"KEY := [ src | dst | proto | proto-src | proto-dst | iif | priority | \n"
" mark | nfct | nfct-src | nfct-dst | nfct-proto-src | \n"
"KEY := [ src | dst | proto | proto-src | proto-dst | iif | priority |\n"
" mark | nfct | nfct-src | nfct-dst | nfct-proto-src |\n"
" nfct-proto-dst | rt-classid | sk-uid | sk-gid |\n"
" vlan-tag | rxhash ]\n"
"OPS := [ or NUM | and NUM | xor NUM | rshift NUM | addend NUM ]\n"
......@@ -270,6 +270,7 @@ static int flow_print_opt(struct filter_util *fu, FILE *f, struct rtattr *opt,
__u32 handle)
{
struct rtattr *tb[TCA_FLOW_MAX+1];
SPRINT_BUF(b1);
unsigned int i;
__u32 mask = ~0, val = 0;
......
......@@ -28,14 +28,14 @@ static void explain(void)
fprintf(stderr, " [ action ACTION-SPEC ] [ classid CLASSID ]\n");
fprintf(stderr, "\n");
fprintf(stderr, "Where: MATCH-LIST := [ MATCH-LIST ] MATCH\n");
fprintf(stderr, " MATCH := { indev DEV-NAME | \n");
fprintf(stderr, " dst_mac MAC-ADDR | \n");
fprintf(stderr, " src_mac MAC-ADDR | \n");
fprintf(stderr, " [ipv4 | ipv6 ] | \n");
fprintf(stderr, " ip_proto [tcp | udp | IP-PROTO ] | \n");
fprintf(stderr, " dst_ip [ IPV4-ADDR | IPV6-ADDR ] | \n");
fprintf(stderr, " src_ip [ IPV4-ADDR | IPV6-ADDR ] | \n");
fprintf(stderr, " dst_port PORT-NUMBER | \n");
fprintf(stderr, " MATCH := { indev DEV-NAME |\n");
fprintf(stderr, " dst_mac MAC-ADDR |\n");
fprintf(stderr, " src_mac MAC-ADDR |\n");
fprintf(stderr, " [ipv4 | ipv6 ] |\n");
fprintf(stderr, " ip_proto [tcp | udp | IP-PROTO ] |\n");
fprintf(stderr, " dst_ip [ IPV4-ADDR | IPV6-ADDR ] |\n");
fprintf(stderr, " src_ip [ IPV4-ADDR | IPV6-ADDR ] |\n");
fprintf(stderr, " dst_port PORT-NUMBER |\n");
fprintf(stderr, " src_port PORT-NUMBER }\n");
fprintf(stderr, " FILTERID := X:Y:Z\n");
fprintf(stderr, " ACTION-SPEC := ... look at individual actions\n");
......@@ -187,7 +187,7 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
while (argc > 0) {
if (matches(*argv, "classid") == 0 ||
matches(*argv, "flowid") == 0) {
unsigned handle;
unsigned int handle;
NEXT_ARG();
ret = get_tc_classid(&handle, *argv);
......@@ -301,7 +301,7 @@ parse_done:
return -1;
}
tail->rta_len = (((void*)n)+n->nlmsg_len) - (void*)tail;
tail->rta_len = (((void *)n)+n->nlmsg_len) - (void *)tail;
return 0;
}
......
......@@ -43,6 +43,7 @@ static int fw_parse_opt(struct filter_util *qu, char *handle, int argc, char **a
if (handle) {
char *slash;
if ((slash = strchr(handle, '/')) != NULL)
*slash = '\0';
if (get_u32(&t->tcm_handle, handle, 0)) {
......@@ -70,7 +71,8 @@ static int fw_parse_opt(struct filter_util *qu, char *handle, int argc, char **a
while (argc > 0) {
if (matches(*argv, "classid") == 0 ||
matches(*argv, "flowid") == 0) {
unsigned handle;
unsigned int handle;
NEXT_ARG();
if (get_tc_classid(&handle, *argv)) {
fprintf(stderr, "Illegal \"classid\"\n");
......@@ -93,14 +95,15 @@ static int fw_parse_opt(struct filter_util *qu, char *handle, int argc, char **a
continue;
} else if (strcmp(*argv, "indev") == 0) {
char d[IFNAMSIZ+1];
memset(d, 0, sizeof (d));
memset(d, 0, sizeof(d));
argc--;
argv++;
if (argc < 1) {
fprintf(stderr, "Illegal indev\n");
return -1;
}
strncpy(d, *argv, sizeof (d) - 1);
strncpy(d, *argv, sizeof(d) - 1);
addattr_l(n, MAX_MSG, TCA_FW_INDEV, d, strlen(d) + 1);
} else if (strcmp(*argv, "help") == 0) {
explain();
......@@ -127,9 +130,10 @@ static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u
if (handle || tb[TCA_FW_MASK]) {
__u32 mark = 0, mask = 0;
if(handle)
if (handle)
mark = handle;
if(tb[TCA_FW_MASK] &&
if (tb[TCA_FW_MASK] &&
(mask = rta_getattr_u32(tb[TCA_FW_MASK])) != 0xFFFFFFFF)
fprintf(f, "handle 0x%x/0x%x ", mark, mask);
else
......@@ -145,7 +149,8 @@ static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u
tc_print_police(f, tb[TCA_FW_POLICE]);
if (tb[TCA_FW_INDEV]) {
struct rtattr *idev = tb[TCA_FW_INDEV];
fprintf(f, "input dev %s ",rta_getattr_str(idev));
fprintf(f, "input dev %s ", rta_getattr_str(idev));
}
if (tb[TCA_FW_ACT]) {
......
......@@ -60,6 +60,7 @@ static int route_parse_opt(struct filter_util *qu, char *handle, int argc, char
while (argc > 0) {
if (matches(*argv, "to") == 0) {
__u32 id;
NEXT_ARG();
if (rtnl_rtrealm_a2n(&id, *argv)) {
fprintf(stderr, "Illegal \"to\"\n");
......@@ -70,6 +71,7 @@ static int route_parse_opt(struct filter_util *qu, char *handle, int argc, char
fh |= id&0xFF;
} else if (matches(*argv, "from") == 0) {
__u32 id;
NEXT_ARG();
if (rtnl_rtrealm_a2n(&id, *argv)) {
fprintf(stderr, "Illegal \"from\"\n");
......@@ -80,9 +82,10 @@ static int route_parse_opt(struct filter_util *qu, char *handle, int argc, char
fh |= id<<16;
} else if (matches(*argv, "fromif") == 0) {
__u32 id;
NEXT_ARG();
ll_init_map(&rth);
if ((id=ll_name_to_index(*argv)) <= 0) {
if ((id = ll_name_to_index(*argv)) <= 0) {
fprintf(stderr, "Illegal \"fromif\"\n");
return -1;
}
......@@ -91,7 +94,8 @@ static int route_parse_opt(struct filter_util *qu, char *handle, int argc, char
fh |= (0x8000|id)<<16;
} else if (matches(*argv, "classid") == 0 ||
strcmp(*argv, "flowid") == 0) {
unsigned handle;
unsigned int handle;
NEXT_ARG();
if (get_tc_classid(&handle, *argv)) {
fprintf(stderr, "Illegal \"classid\"\n");
......@@ -141,6 +145,7 @@ static int route_parse_opt(struct filter_util *qu, char *handle, int argc, char
static int route_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 handle)
{
struct rtattr *tb[TCA_ROUTE4_MAX+1];
SPRINT_BUF(b1);
if (opt == NULL)
......@@ -162,7 +167,7 @@ static int route_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt,
if (tb[TCA_ROUTE4_FROM])
fprintf(f, "from %s ", rtnl_rtrealm_n2a(rta_getattr_u32(tb[TCA_ROUTE4_FROM]), b1, sizeof(b1)));
if (tb[TCA_ROUTE4_IIF])
fprintf(f, "fromif %s", ll_index_to_name(*(int*)RTA_DATA(tb[TCA_ROUTE4_IIF])));
fprintf(f, "fromif %s", ll_index_to_name(*(int *)RTA_DATA(tb[TCA_ROUTE4_IIF])));
if (tb[TCA_ROUTE4_POLICE])
tc_print_police(f, tb[TCA_ROUTE4_POLICE]);
if (tb[TCA_ROUTE4_ACT])
......
......@@ -37,7 +37,7 @@ static void explain(void)
fprintf(stderr, "\nNOTE: CLASSID is parsed as hexadecimal input.\n");
}
static int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix * addr,
static int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix *addr,
struct tc_rsvp_pinfo *pinfo, int dir, int family)
{
int argc = *argc_p;
......@@ -76,6 +76,7 @@ static int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix * addr,
if (strcmp(*argv, "spi/ah") == 0 ||
strcmp(*argv, "gpi/ah") == 0) {
__u32 gpi;
NEXT_ARG();
if (get_u32(&gpi, *argv, 0))
return -1;
......@@ -88,6 +89,7 @@ static int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix * addr,
} else if (strcmp(*argv, "spi/esp") == 0 ||
strcmp(*argv, "gpi/esp") == 0) {
__u32 gpi;
NEXT_ARG();
if (get_u32(&gpi, *argv, 0))
return -1;
......@@ -99,6 +101,7 @@ static int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix * addr,
argc--; argv++;
} else if (strcmp(*argv, "flowlabel") == 0) {
__u32 flabel;
NEXT_ARG();
if (get_u32(&flabel, *argv, 0))
return -1;
......@@ -114,6 +117,7 @@ static int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix * addr,
int sz = 1;
__u32 tmp;
__u32 mask = 0xff;
if (strcmp(*argv, "u32") == 0) {
sz = 4;
mask = 0xffff;
......@@ -194,6 +198,7 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
while (argc > 0) {
if (matches(*argv, "session") == 0) {
inet_prefix addr;
NEXT_ARG();
if (get_addr_and_pi(&argc, &argv, &addr, &pinfo, 1, family)) {
fprintf(stderr, "Illegal \"session\"\n");
......@@ -206,6 +211,7 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
} else if (matches(*argv, "sender") == 0 ||
matches(*argv, "flowspec") == 0) {
inet_prefix addr;
NEXT_ARG();
if (get_addr_and_pi(&argc, &argv, &addr, &pinfo, 0, family)) {
fprintf(stderr, "Illegal \"sender\"\n");
......@@ -217,6 +223,7 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
continue;
} else if (matches("ipproto", *argv) == 0) {
int num;
NEXT_ARG();
num = inet_proto_a2n(*argv);
if (num < 0) {
......@@ -227,7 +234,8 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
pinfo_ok++;
} else if (matches(*argv, "classid") == 0 ||
strcmp(*argv, "flowid") == 0) {
unsigned handle;
unsigned int handle;
NEXT_ARG();
if (get_tc_classid(&handle, *argv)) {
fprintf(stderr, "Illegal \"classid\"\n");
......@@ -235,7 +243,8 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
}
addattr_l(n, 4096, TCA_RSVP_CLASSID, &handle, 4);
} else if (strcmp(*argv, "tunnelid") == 0) {
unsigned tid;
unsigned int tid;
NEXT_ARG();
if (get_unsigned(&tid, *argv, 0)) {
fprintf(stderr, "Illegal \"tunnelid\"\n");
......@@ -244,7 +253,8 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
pinfo.tunnelid = tid;
pinfo_ok++;
} else if (strcmp(*argv, "tunnel") == 0) {
unsigned tid;
unsigned int tid;
NEXT_ARG();
if (get_unsigned(&tid, *argv, 0)) {
fprintf(stderr, "Illegal \"tunnel\"\n");
......@@ -292,7 +302,7 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
return 0;
}
static char * sprint_spi(struct tc_rsvp_gpi *pi, int dir, char *buf)
static char *sprint_spi(struct tc_rsvp_gpi *pi, int dir, char *buf)
{
if (pi->offset == 0) {
if (dir && pi->mask == htonl(0xFFFF)) {
......@@ -351,6 +361,7 @@ static int rsvp_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, _
if (tb[TCA_RSVP_DST]) {
char buf[128];
fprintf(f, "session ");
if (inet_ntop(family, RTA_DATA(tb[TCA_RSVP_DST]), buf, sizeof(buf)) == 0)
fprintf(f, " [INVALID DADDR] ");
......@@ -377,6 +388,7 @@ static int rsvp_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, _
fprintf(f, "tunnelid %d ", pinfo->tunnelid);
if (tb[TCA_RSVP_SRC]) {
char buf[128];
fprintf(f, "sender ");
if (inet_ntop(family, RTA_DATA(tb[TCA_RSVP_SRC]), buf, sizeof(buf)) == 0) {
fprintf(f, "[BAD]");
......
......@@ -17,11 +17,9 @@
static void explain(void)
{
fprintf(stderr," Usage: ... tcindex [ hash SIZE ] [ mask MASK ]"
" [ shift SHIFT ]\n");
fprintf(stderr," [ pass_on | fall_through ]\n");
fprintf(stderr," [ classid CLASSID ] "
"[ action ACTION_SPEC ]\n");
fprintf(stderr," Usage: ... tcindex [ hash SIZE ] [ mask MASK ] [ shift SHIFT ]\n");
fprintf(stderr, " [ pass_on | fall_through ]\n");
fprintf(stderr," [ classid CLASSID ] [ action ACTION_SPEC ]\n");
}
static int tcindex_parse_opt(struct filter_util *qu, char *handle, int argc,
......@@ -32,7 +30,7 @@ static int tcindex_parse_opt(struct filter_util *qu, char *handle, int argc,
char *end;
if (handle) {
t->tcm_handle = strtoul(handle,&end,0);
t->tcm_handle = strtoul(handle, &end, 0);
if (*end) {
fprintf(stderr, "Illegal filter ID\n");
return -1;
......@@ -40,81 +38,73 @@ static int tcindex_parse_opt(struct filter_util *qu, char *handle, int argc,
}
if (!argc) return 0;
tail = NLMSG_TAIL(n);
addattr_l(n,4096,TCA_OPTIONS,NULL,0);
addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
while (argc) {
if (!strcmp(*argv,"hash")) {
if (!strcmp(*argv, "hash")) {
int hash;
NEXT_ARG();
hash = strtoul(*argv,&end,0);
hash = strtoul(*argv, &end, 0);
if (*end || !hash || hash > 0x10000) {
explain();
return -1;
}
addattr_l(n,4096,TCA_TCINDEX_HASH,&hash,sizeof(hash));
}
else if (!strcmp(*argv,"mask")) {
addattr_l(n, 4096, TCA_TCINDEX_HASH, &hash, sizeof(hash));
} else if (!strcmp(*argv,"mask")) {
__u16 mask;
NEXT_ARG();
mask = strtoul(*argv,&end,0);
mask = strtoul(*argv, &end, 0);
if (*end) {
explain();
return -1;
}
addattr_l(n,4096,TCA_TCINDEX_MASK,&mask,sizeof(mask));
}
else if (!strcmp(*argv,"shift")) {
addattr_l(n, 4096, TCA_TCINDEX_MASK, &mask, sizeof(mask));
} else if (!strcmp(*argv,"shift")) {
int shift;
NEXT_ARG();
shift = strtoul(*argv,&end,0);
shift = strtoul(*argv, &end, 0);
if (*end) {
explain();
return -1;
}
addattr_l(n,4096,TCA_TCINDEX_SHIFT,&shift,
addattr_l(n, 4096, TCA_TCINDEX_SHIFT, &shift,
sizeof(shift));
}
else if (!strcmp(*argv,"fall_through")) {
} else if (!strcmp(*argv,"fall_through")) {
int value = 1;
addattr_l(n,4096,TCA_TCINDEX_FALL_THROUGH,&value,
addattr_l(n, 4096, TCA_TCINDEX_FALL_THROUGH, &value,
sizeof(value));
}
else if (!strcmp(*argv,"pass_on")) {
} else if (!strcmp(*argv,"pass_on")) {
int value = 0;
addattr_l(n,4096,TCA_TCINDEX_FALL_THROUGH,&value,
addattr_l(n, 4096, TCA_TCINDEX_FALL_THROUGH, &value,
sizeof(value));
}
else if (!strcmp(*argv,"classid")) {
} else if (!strcmp(*argv,"classid")) {
__u32 handle;
NEXT_ARG();
if (get_tc_classid(&handle,*argv)) {
if (get_tc_classid(&handle, *argv)) {
fprintf(stderr, "Illegal \"classid\"\n");
return -1;
}
addattr_l(n, 4096, TCA_TCINDEX_CLASSID, &handle, 4);
}
else if (!strcmp(*argv,"police")) {
} else if (!strcmp(*argv,"police")) {
NEXT_ARG();
if (parse_police(&argc, &argv, TCA_TCINDEX_POLICE, n)) {
fprintf(stderr, "Illegal \"police\"\n");
return -1;
}
continue;
}
else if (!strcmp(*argv,"action")) {
} else if (!strcmp(*argv,"action")) {
NEXT_ARG();
if (parse_police(&argc, &argv, TCA_TCINDEX_ACT, n)) {
fprintf(stderr, "Illegal \"action\"\n");
return -1;
}
continue;
}
else {
} else {
explain();
return -1;
}
......@@ -136,14 +126,14 @@ static int tcindex_print_opt(struct filter_util *qu, FILE *f,
parse_rtattr_nested(tb, TCA_TCINDEX_MAX, opt);
if (handle != ~0) fprintf(f,"handle 0x%04x ",handle);
if (handle != ~0) fprintf(f, "handle 0x%04x ", handle);
if (tb[TCA_TCINDEX_HASH]) {
__u16 hash;
if (RTA_PAYLOAD(tb[TCA_TCINDEX_HASH]) < sizeof(hash))
return -1;
hash = rta_getattr_u16(tb[TCA_TCINDEX_HASH]);
fprintf(f,"hash %d ",hash);
fprintf(f, "hash %d ", hash);
}
if (tb[TCA_TCINDEX_MASK]) {
__u16 mask;
......@@ -151,7 +141,7 @@ static int tcindex_print_opt(struct filter_util *qu, FILE *f,
if (RTA_PAYLOAD(tb[TCA_TCINDEX_MASK]) < sizeof(mask))
return -1;
mask = rta_getattr_u16(tb[TCA_TCINDEX_MASK]);
fprintf(f,"mask 0x%04x ",mask);
fprintf(f, "mask 0x%04x ", mask);
}
if (tb[TCA_TCINDEX_SHIFT]) {
int shift;
......@@ -159,7 +149,7 @@ static int tcindex_print_opt(struct filter_util *qu, FILE *f,
if (RTA_PAYLOAD(tb[TCA_TCINDEX_SHIFT]) < sizeof(shift))
return -1;
shift = *(int *) RTA_DATA(tb[TCA_TCINDEX_SHIFT]);
fprintf(f,"shift %d ",shift);
fprintf(f, "shift %d ", shift);
}
if (tb[TCA_TCINDEX_FALL_THROUGH]) {
int fall_through;
......@@ -168,11 +158,11 @@ static int tcindex_print_opt(struct filter_util *qu, FILE *f,
sizeof(fall_through))
return -1;
fall_through = *(int *) RTA_DATA(tb[TCA_TCINDEX_FALL_THROUGH]);
fprintf(f,fall_through ? "fall_through " : "pass_on ");
fprintf(f, fall_through ? "fall_through " : "pass_on ");
}
if (tb[TCA_TCINDEX_CLASSID]) {
SPRINT_BUF(b1);
fprintf(f, "classid %s ",sprint_tc_classid(*(__u32 *)
fprintf(f, "classid %s ", sprint_tc_classid(*(__u32 *)
RTA_DATA(tb[TCA_TCINDEX_CLASSID]), b1));
}
if (tb[TCA_TCINDEX_POLICE]) {
......
......@@ -30,17 +30,14 @@ extern int show_pretty;
static void explain(void)
{
fprintf(stderr, "Usage: ... u32 [ match SELECTOR ... ] [ link HTID ]"
" [ classid CLASSID ]\n");
fprintf(stderr, " [ action ACTION_SPEC ]"
" [ offset OFFSET_SPEC ]\n");
fprintf(stderr, "Usage: ... u32 [ match SELECTOR ... ] [ link HTID ] [ classid CLASSID ]\n");
fprintf(stderr, " [ action ACTION_SPEC ] [ offset OFFSET_SPEC ]\n");
fprintf(stderr, " [ ht HTID ] [ hashkey HASHKEY_SPEC ]\n");
fprintf(stderr, " [ sample SAMPLE ]\n");
fprintf(stderr, "or u32 divisor DIVISOR\n");
fprintf(stderr, "\n");
fprintf(stderr, "Where: SELECTOR := SAMPLE SAMPLE ...\n");
fprintf(stderr, " SAMPLE := { ip | ip6 | udp | tcp | icmp |"
" u{32|16|8} | mark } SAMPLE_ARGS [divisor DIVISOR]\n");
fprintf(stderr, " SAMPLE := { ip | ip6 | udp | tcp | icmp | u{32|16|8} | mark } SAMPLE_ARGS [divisor DIVISOR]\n");
fprintf(stderr, " FILTERID := X:Y:Z\n");
fprintf(stderr, "\nNOTE: CLASSID is parsed at hexadecimal input.\n");
}
......@@ -94,17 +91,20 @@ static char *sprint_u32_handle(__u32 handle, char *buf)
}
if (htid) {
int l = snprintf(b, bsize, "%x:", htid>>20);
bsize -= l;
b += l;
}
if (nodeid|hash) {
if (hash) {
int l = snprintf(b, bsize, "%x", hash);
bsize -= l;
b += l;
}
if (nodeid) {
int l = snprintf(b, bsize, ":%x", nodeid);
bsize -= l;
b += l;
}
......@@ -390,6 +390,7 @@ static int parse_ip6_addr(int *argc_p, char ***argv_p,
return -1;
} else if (i < plen) {
__u32 mask = htonl(0xFFFFFFFF << (32 - (plen - i)));
res = pack_key(sel, addr.data[i / 32],
mask, off + 4 * (i / 32), offmask);
if (res < 0)
......@@ -712,7 +713,7 @@ static int parse_selector(int *argc_p, char ***argv_p,
} else if (matches(*argv, "ip") == 0) {
NEXT_ARG();
res = parse_ip(&argc, &argv, sel);
} else if (matches(*argv, "ip6") == 0) {
} else if (matches(*argv, "ip6") == 0) {
NEXT_ARG();
res = parse_ip6(&argc, &argv, sel);
} else if (matches(*argv, "udp") == 0) {
......@@ -746,6 +747,7 @@ static int parse_offset(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
while (argc > 0) {
if (matches(*argv, "plus") == 0) {
int off;
NEXT_ARG();
if (get_integer(&off, *argv, 0))
return -1;
......@@ -753,6 +755,7 @@ static int parse_offset(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
sel->flags |= TC_U32_OFFSET;
} else if (matches(*argv, "at") == 0) {
int off;
NEXT_ARG();
if (get_integer(&off, *argv, 0))
return -1;
......@@ -764,6 +767,7 @@ static int parse_offset(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
sel->flags |= TC_U32_VAROFFSET;
} else if (matches(*argv, "mask") == 0) {
__u16 mask;
NEXT_ARG();
if (get_u16(&mask, *argv, 16))
return -1;
......@@ -771,6 +775,7 @@ static int parse_offset(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
sel->flags |= TC_U32_VAROFFSET;
} else if (matches(*argv, "shift") == 0) {
int shift;
NEXT_ARG();
if (get_integer(&shift, *argv, 0))
return -1;
......@@ -797,12 +802,14 @@ static int parse_hashkey(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
while (argc > 0) {
if (matches(*argv, "mask") == 0) {
__u32 mask;
NEXT_ARG();
if (get_u32(&mask, *argv, 16))
return -1;
sel->hmask = htonl(mask);
} else if (matches(*argv, "at") == 0) {
int num;
NEXT_ARG();
if (get_integer(&num, *argv, 0))
return -1;
......@@ -844,6 +851,7 @@ static void print_ipv4(FILE *f, const struct tc_u32_key *key)
case 12:
case 16: {
int bits = mask2bits(key->mask);
if (bits >= 0) {
fprintf(f, "\n %s %s/%d",
key->off == 12 ? "match IP src" : "match IP dst",
......@@ -900,6 +908,7 @@ static void print_ipv6(FILE *f, const struct tc_u32_key *key)
case 12:
case 16: {
int bits = mask2bits(key->mask);
if (bits >= 0) {
fprintf(f, "\n %s %s/%d",
key->off == 12 ? "match IP src" : "match IP dst",
......@@ -946,7 +955,7 @@ static const struct {
__u16 pad;
void (*pprinter)(FILE *f, const struct tc_u32_key *key);
} u32_pprinters[] = {
{0, 0, print_raw},
{0, 0, print_raw},
{ETH_P_IP, 0, print_ipv4},
{ETH_P_IPV6, 0, print_ipv6},
};
......@@ -958,7 +967,7 @@ static void show_keys(FILE *f, const struct tc_u32_key *key)
if (!show_pretty)
goto show_k;
for (i = 0; i < sizeof(u32_pprinters) / sizeof(u32_pprinters[0]); i++) {
for (i = 0; i < ARRAY_SIZE(u32_pprinters); i++) {
if (u32_pprinters[i].proto == ntohs(f_proto)) {
show_k:
u32_pprinters[i].pprinter(f, key);
......@@ -1022,7 +1031,8 @@ static int u32_parse_opt(struct filter_util *qu, char *handle,
continue;
} else if (matches(*argv, "classid") == 0 ||
strcmp(*argv, "flowid") == 0) {
unsigned handle;
unsigned int handle;
NEXT_ARG();
if (get_tc_classid(&handle, *argv)) {
fprintf(stderr, "Illegal \"classid\"\n");
......@@ -1031,7 +1041,8 @@ static int u32_parse_opt(struct filter_util *qu, char *handle,
addattr_l(n, MAX_MSG, TCA_U32_CLASSID, &handle, 4);
sel.sel.flags |= TC_U32_TERMINAL;
} else if (matches(*argv, "divisor") == 0) {
unsigned divisor;
unsigned int divisor;
NEXT_ARG();
if (get_unsigned(&divisor, *argv, 0) ||
divisor == 0 ||
......@@ -1047,7 +1058,8 @@ static int u32_parse_opt(struct filter_util *qu, char *handle,
return -1;
}
} else if (strcmp(*argv, "link") == 0) {
unsigned handle;
unsigned int handle;
NEXT_ARG();
if (get_u32_handle(&handle, *argv)) {
fprintf(stderr, "Illegal \"link\"\n");
......@@ -1059,7 +1071,8 @@ static int u32_parse_opt(struct filter_util *qu, char *handle,
}
addattr_l(n, MAX_MSG, TCA_U32_LINK, &handle, 4);
} else if (strcmp(*argv, "ht") == 0) {
unsigned handle;
unsigned int handle;
NEXT_ARG();
if (get_u32_handle(&handle, *argv)) {
fprintf(stderr, "Illegal \"ht\"\n");
......@@ -1075,7 +1088,7 @@ static int u32_parse_opt(struct filter_util *qu, char *handle,
htid = (handle & 0xFFFFF000);
} else if (strcmp(*argv, "sample") == 0) {
__u32 hash;
unsigned divisor = 0x100;
unsigned int divisor = 0x100;
struct {
struct tc_u32_sel sel;
......@@ -1088,8 +1101,7 @@ static int u32_parse_opt(struct filter_util *qu, char *handle,
return -1;
}
if (sel2.sel.nkeys != 1) {
fprintf(stderr, "\"sample\" must contain"
" exactly ONE key.\n");
fprintf(stderr, "\"sample\" must contain exactly ONE key.\n");
return -1;
}
if (*argv != 0 && strcmp(*argv, "divisor") == 0) {
......@@ -1109,6 +1121,7 @@ static int u32_parse_opt(struct filter_util *qu, char *handle,
continue;
} else if (strcmp(*argv, "indev") == 0) {
char ind[IFNAMSIZ + 1];
memset(ind, 0, sizeof(ind));
argc--;
argv++;
......@@ -1199,6 +1212,7 @@ static int u32_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt,
fprintf(f, "ht divisor %d ", rta_getattr_u32(tb[TCA_U32_DIVISOR]));
} else if (tb[TCA_U32_HASH]) {
__u32 htid = rta_getattr_u32(tb[TCA_U32_HASH]);
fprintf(f, "key ht %x bkt %x ", TC_U32_USERHTID(htid),
TC_U32_HASH(htid));
} else {
......@@ -1220,7 +1234,7 @@ static int u32_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt,
if (tb[TCA_U32_PCNT]) {
if (RTA_PAYLOAD(tb[TCA_U32_PCNT]) < sizeof(*pf)) {
fprintf(f, "Broken perf counters \n");
fprintf(f, "Broken perf counters\n");
return -1;
}
pf = RTA_DATA(tb[TCA_U32_PCNT]);
......@@ -1233,6 +1247,7 @@ static int u32_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt,
if (tb[TCA_U32_MARK]) {
struct tc_u32_mark *mark = RTA_DATA(tb[TCA_U32_MARK]);
if (RTA_PAYLOAD(tb[TCA_U32_MARK]) < sizeof(*mark)) {
fprintf(f, "\n Invalid mark (kernel&iproute2 mismatch)\n");
} else {
......@@ -1244,6 +1259,7 @@ static int u32_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt,
if (sel) {
if (sel->nkeys) {
int i;
for (i = 0; i < sel->nkeys; i++) {
show_keys(f, sel->keys + i);
if (show_stats && NULL != pf)
......@@ -1276,6 +1292,7 @@ static int u32_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt,
}
if (tb[TCA_U32_INDEV]) {
struct rtattr *idev = tb[TCA_U32_INDEV];
fprintf(f, "\n input dev %s\n", rta_getattr_str(idev));
}
if (tb[TCA_U32_ACT]) {
......
......@@ -28,11 +28,11 @@
#include "tc_common.h"
#include "tc_util.h"
static struct action_util * action_list;
static struct action_util *action_list;
#ifdef CONFIG_GACT
int gact_ld = 0 ; //fuckin backward compatibility
int gact_ld; /* f*ckin backward compatibility */
#endif
int tab_flush = 0;
int tab_flush;
static void act_usage(void)
{
......@@ -43,10 +43,10 @@ static void act_usage(void)
* does that, they would know how to fix this ..
*
*/
fprintf (stderr, "usage: tc actions <ACTSPECOP>*\n");
fprintf(stderr, "usage: tc actions <ACTSPECOP>*\n");
fprintf(stderr,
"Where: \tACTSPECOP := ACR | GD | FL\n"
"\tACR := add | change | replace <ACTSPEC>* \n"
"\tACR := add | change | replace <ACTSPEC>*\n"
"\tGD := get | delete | <ACTISPEC>*\n"
"\tFL := ls | list | flush | <ACTNAMESPEC>\n"
"\tACTNAMESPEC := action <ACTNAME>\n"
......@@ -65,7 +65,7 @@ static int print_noaopt(struct action_util *au, FILE *f, struct rtattr *opt)
{
if (opt && RTA_PAYLOAD(opt))
fprintf(f, "[Unknown action, optlen=%u] ",
(unsigned) RTA_PAYLOAD(opt));
(unsigned int) RTA_PAYLOAD(opt));
return 0;
}
......@@ -122,7 +122,7 @@ noexist:
#ifdef CONFIG_GACT
if (!looked4gact) {
looked4gact = 1;
strcpy(str,"gact");
strcpy(str, "gact");
goto restart_s;
}
#endif
......@@ -141,9 +141,9 @@ static int
new_cmd(char **argv)
{
if ((matches(*argv, "change") == 0) ||
(matches(*argv, "replace") == 0)||
(matches(*argv, "delete") == 0)||
(matches(*argv, "get") == 0)||
(matches(*argv, "replace") == 0) ||
(matches(*argv, "delete") == 0) ||
(matches(*argv, "get") == 0) ||
(matches(*argv, "add") == 0))
return 1;
......@@ -173,9 +173,9 @@ parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
while (argc > 0) {
memset(k, 0, sizeof (k));
memset(k, 0, sizeof(k));
if (strcmp(*argv, "action") == 0 ) {
if (strcmp(*argv, "action") == 0) {
argc--;
argv++;
eap = 1;
......@@ -195,9 +195,10 @@ parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
goto done0;
} else {
struct action_util *a = NULL;
strncpy(k, *argv, sizeof (k) - 1);
strncpy(k, *argv, sizeof(k) - 1);
eap = 0;
if (argc > 0 ) {
if (argc > 0) {
a = get_action_kind(k);
} else {
done0:
......@@ -207,7 +208,7 @@ done0:
goto done;
}
if (NULL == a) {
if (a == NULL) {
goto bad_val;
}
......@@ -215,10 +216,10 @@ done0:
addattr_l(n, MAX_MSG, ++prio, NULL, 0);
addattr_l(n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1);
ret = a->parse_aopt(a,&argc, &argv, TCA_ACT_OPTIONS, n);
ret = a->parse_aopt(a, &argc, &argv, TCA_ACT_OPTIONS, n);
if (ret < 0) {
fprintf(stderr,"bad action parsing\n");
fprintf(stderr, "bad action parsing\n");
goto bad_val;
}
tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
......@@ -228,7 +229,7 @@ done0:
}
if (eap > 0) {
fprintf(stderr,"bad action empty %d\n",eap);
fprintf(stderr, "bad action empty %d\n", eap);
goto bad_val;
}
......@@ -241,12 +242,12 @@ done:
bad_val:
/* no need to undo things, returning from here should
* cause enough pain */
fprintf(stderr, "parse_action: bad value (%d:%s)!\n",argc,*argv);
fprintf(stderr, "parse_action: bad value (%d:%s)!\n", argc, *argv);
return -1;
}
static int
tc_print_one_action(FILE * f, struct rtattr *arg)
tc_print_one_action(FILE *f, struct rtattr *arg)
{
struct rtattr *tb[TCA_ACT_MAX + 1];
......@@ -265,12 +266,12 @@ tc_print_one_action(FILE * f, struct rtattr *arg)
a = get_action_kind(RTA_DATA(tb[TCA_ACT_KIND]));
if (NULL == a)
if (a == NULL)
return err;
err = a->print_aopt(a, f, tb[TCA_ACT_OPTIONS]);
if (0 > err)
if (err < 0)
return err;
if (show_stats && tb[TCA_ACT_STATS]) {
......@@ -299,11 +300,11 @@ tc_print_action_flush(FILE *f, const struct rtattr *arg)
}
a = get_action_kind(RTA_DATA(tb[TCA_KIND]));
if (NULL == a)
if (a == NULL)
return err;
delete_count = RTA_DATA(tb[TCA_FCNT]);
fprintf(f," %s (%d entries)\n", a->id, *delete_count);
fprintf(f, " %s (%d entries)\n", a->id, *delete_count);
tab_flush = 0;
return 0;
}
......@@ -326,7 +327,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);
if (0 > tc_print_one_action(f, tb[i])) {
if (tc_print_one_action(f, tb[i]) < 0) {
fprintf(f, "Error printing action\n");
}
}
......@@ -340,10 +341,10 @@ int print_action(const struct sockaddr_nl *who,
struct nlmsghdr *n,
void *arg)
{
FILE *fp = (FILE*)arg;
FILE *fp = (FILE *)arg;
struct tcamsg *t = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr * tb[TCAA_MAX+1];
struct rtattr *tb[TCAA_MAX+1];
len -= NLMSG_LENGTH(sizeof(*t));
......@@ -354,7 +355,7 @@ int print_action(const struct sockaddr_nl *who,
parse_rtattr(tb, TCAA_MAX, TA_RTA(t), len);
if (NULL == tb[TCA_ACT_TAB]) {
if (tb[TCA_ACT_TAB] == NULL) {
if (n->nlmsg_type != RTM_GETACTION)
fprintf(stderr, "print_action: NULL kind\n");
return -1;
......@@ -376,7 +377,7 @@ int print_action(const struct sockaddr_nl *who,
return 0;
}
static int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p)
static int tc_action_gd(int cmd, unsigned int flags, int *argc_p, char ***argv_p)
{
char k[16];
struct action_util *a = NULL;
......@@ -406,15 +407,15 @@ static int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p)
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
argc -=1;
argv +=1;
argc -= 1;
argv += 1;
tail = NLMSG_TAIL(&req.n);
addattr_l(&req.n, MAX_MSG, TCA_ACT_TAB, NULL, 0);
while (argc > 0) {
if (strcmp(*argv, "action") == 0 ) {
if (strcmp(*argv, "action") == 0) {
argc--;
argv++;
continue;
......@@ -422,23 +423,23 @@ static int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p)
return -1;
}
strncpy(k, *argv, sizeof (k) - 1);
strncpy(k, *argv, sizeof(k) - 1);
a = get_action_kind(k);
if (NULL == a) {
fprintf(stderr, "Error: non existent action: %s\n",k);
if (a == NULL) {
fprintf(stderr, "Error: non existent action: %s\n", k);
ret = -1;
goto bad_val;
}
if (strcmp(a->id, k) != 0) {
fprintf(stderr, "Error: non existent action: %s\n",k);
fprintf(stderr, "Error: non existent action: %s\n", k);
ret = -1;
goto bad_val;
}
argc -=1;
argv +=1;
argc -= 1;
argv += 1;
if (argc <= 0) {
fprintf(stderr, "Error: no index specified action: %s\n",k);
fprintf(stderr, "Error: no index specified action: %s\n", k);
ret = -1;
goto bad_val;
}
......@@ -450,10 +451,10 @@ static int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p)
ret = -1;
goto bad_val;
}
argc -=1;
argv +=1;
argc -= 1;
argv += 1;
} else {
fprintf(stderr, "Error: no index specified action: %s\n",k);
fprintf(stderr, "Error: no index specified action: %s\n", k);
ret = -1;
goto bad_val;
}
......@@ -477,7 +478,7 @@ static int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p)
return 1;
}
if (ans && print_action(NULL, &req.n, (void*)stdout) < 0) {
if (ans && print_action(NULL, &req.n, (void *)stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
return 1;
}
......@@ -488,7 +489,7 @@ bad_val:
return ret;
}
static int tc_action_modify(int cmd, unsigned flags, int *argc_p, char ***argv_p)
static int tc_action_modify(int cmd, unsigned int flags, int *argc_p, char ***argv_p)
{
int argc = *argc_p;
char **argv = *argv_p;
......@@ -509,8 +510,8 @@ static int tc_action_modify(int cmd, unsigned flags, int *argc_p, char ***argv_p
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
tail = NLMSG_TAIL(&req.n);
argc -=1;
argv +=1;
argc -= 1;
argv += 1;
if (parse_action(&argc, &argv, TCA_ACT_TAB, &req.n)) {
fprintf(stderr, "Illegal \"action\"\n");
return -1;
......@@ -532,7 +533,7 @@ static int tc_act_list_or_flush(int argc, char **argv, int event)
{
int ret = 0, prio = 0, msg_size = 0;
char k[16];
struct rtattr *tail,*tail2;
struct rtattr *tail, *tail2;
struct action_util *a = NULL;
struct {
struct nlmsghdr n;
......@@ -550,22 +551,22 @@ static int tc_act_list_or_flush(int argc, char **argv, int event)
addattr_l(&req.n, MAX_MSG, TCA_ACT_TAB, NULL, 0);
tail2 = NLMSG_TAIL(&req.n);
strncpy(k, *argv, sizeof (k) - 1);
strncpy(k, *argv, sizeof(k) - 1);
#ifdef CONFIG_GACT
if (!gact_ld) {
get_action_kind("gact");
}
#endif
a = get_action_kind(k);
if (NULL == a) {
fprintf(stderr,"bad action %s\n",k);
if (a == NULL) {
fprintf(stderr, "bad action %s\n", k);
goto bad_val;
}
if (strcmp(a->id, k) != 0) {
fprintf(stderr,"bad action %s\n",k);
fprintf(stderr, "bad action %s\n", k);
goto bad_val;
}
strncpy(k, *argv, sizeof (k) - 1);
strncpy(k, *argv, sizeof(k) - 1);
addattr_l(&req.n, MAX_MSG, ++prio, NULL, 0);
addattr_l(&req.n, MAX_MSG, TCA_ACT_KIND, k, strlen(k) + 1);
......@@ -612,12 +613,12 @@ int do_action(int argc, char **argv)
matches(*argv, "replace") == 0) {
ret = tc_action_modify(RTM_NEWACTION, NLM_F_CREATE|NLM_F_REPLACE, &argc, &argv);
} else if (matches(*argv, "delete") == 0) {
argc -=1;
argv +=1;
argc -= 1;
argv += 1;
ret = tc_action_gd(RTM_DELACTION, 0, &argc, &argv);
} else if (matches(*argv, "get") == 0) {
argc -=1;
argv +=1;
argc -= 1;
argv += 1;
ret = tc_action_gd(RTM_GETACTION, 0, &argc, &argv);
} else if (matches(*argv, "list") == 0 || matches(*argv, "show") == 0
|| matches(*argv, "lst") == 0) {
......
......@@ -156,6 +156,7 @@ static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)
{
struct rtattr *tb[TCA_ACT_BPF_MAX + 1];
struct tc_act_bpf *parm;
SPRINT_BUF(action_buf);
if (arg == NULL)
......@@ -190,6 +191,7 @@ static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)
if (show_stats) {
if (tb[TCA_ACT_BPF_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_ACT_BPF_TM]);
print_tm(f, tm);
}
}
......
......@@ -151,6 +151,7 @@ static int print_connmark(struct action_util *au, FILE *f, struct rtattr *arg)
if (show_stats) {
if (tb[TCA_CONNMARK_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_CONNMARK_TM]);
print_tm(f, tm);
}
}
......
......@@ -24,8 +24,7 @@ explain(void)
{
fprintf(stderr, "Usage: ... csum <UPDATE>\n"
"Where: UPDATE := <TARGET> [<UPDATE>]\n"
" TARGET := { ip4h | icmp | igmp |"
" tcp | udp | udplite | <SWEETS> }\n"
" TARGET := { ip4h | icmp | igmp | tcp | udp | udplite | <SWEETS> }\n"
" SWEETS := { and | or | \'+\' }\n");
}
......@@ -45,7 +44,7 @@ parse_csum_args(int *argc_p, char ***argv_p, struct tc_csum *sel)
if (argc <= 0)
return -1;
while(argc > 0) {
while (argc > 0) {
if ((matches(*argv, "iph") == 0) ||
(matches(*argv, "ip4h") == 0) ||
(matches(*argv, "ipv4h") == 0))
......@@ -108,8 +107,7 @@ parse_csum(struct action_util *a, int *argc_p,
continue;
} else if (matches(*argv, "help") == 0) {
usage();
}
else {
} else {
break;
}
}
......@@ -174,7 +172,7 @@ parse_csum(struct action_util *a, int *argc_p,
}
static int
print_csum(struct action_util *au, FILE * f, struct rtattr *arg)
print_csum(struct action_util *au, FILE *f, struct rtattr *arg)
{
struct tc_csum *sel;
......@@ -186,6 +184,7 @@ print_csum(struct action_util *au, FILE * f, struct rtattr *arg)
char *uflag_4 = "";
char *uflag_5 = "";
char *uflag_6 = "";
SPRINT_BUF(action_buf);
int uflag_count = 0;
......@@ -212,7 +211,7 @@ print_csum(struct action_util *au, FILE * f, struct rtattr *arg)
", " flag_string : flag_string; \
uflag_count++; \
} \
} while(0)
} while (0)
CSUM_UFLAG_BUFFER(uflag_2, TCA_CSUM_UPDATE_FLAG_ICMP, "icmp");
CSUM_UFLAG_BUFFER(uflag_3, TCA_CSUM_UPDATE_FLAG_IGMP, "igmp");
CSUM_UFLAG_BUFFER(uflag_4, TCA_CSUM_UPDATE_FLAG_TCP, "tcp");
......@@ -231,7 +230,8 @@ print_csum(struct action_util *au, FILE * f, struct rtattr *arg)
if (show_stats) {
if (tb[TCA_CSUM_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_CSUM_TM]);
print_tm(f,tm);
print_tm(f, tm);
}
}
fprintf(f, "\n");
......
......@@ -33,7 +33,7 @@ static struct ematch_util *ematch_list;
/* export to bison parser */
int ematch_argc;
char **ematch_argv;
char *ematch_err = NULL;
char *ematch_err;
struct ematch *ematch_root;
static int begin_argc;
......@@ -188,6 +188,7 @@ static int parse_tree(struct nlmsghdr *n, struct ematch *tree)
if (t->child) {
__u32 r = t->child_ref;
addraw_l(n, MAX_MSG, &hdr, sizeof(hdr));
addraw_l(n, MAX_MSG, &r, sizeof(r));
} else {
......@@ -198,7 +199,7 @@ static int parse_tree(struct nlmsghdr *n, struct ematch *tree)
if (t->args == NULL)
return -1;
strncpy(buf, (char*) t->args->data, sizeof(buf)-1);
strncpy(buf, (char *) t->args->data, sizeof(buf)-1);
e = get_ematch_kind(buf);
if (e == NULL) {
fprintf(stderr, "Unknown ematch \"%s\"\n",
......@@ -218,7 +219,7 @@ static int parse_tree(struct nlmsghdr *n, struct ematch *tree)
return -1;
}
tail->rta_len = (void*) NLMSG_TAIL(n) - (void*) tail;
tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
}
return 0;
......@@ -353,8 +354,8 @@ int parse_ematch(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
if (parse_tree(n, ematch_root) < 0)
return -1;
tail_list->rta_len = (void*) NLMSG_TAIL(n) - (void*) tail_list;
tail->rta_len = (void*) NLMSG_TAIL(n) - (void*) tail;
tail_list->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail_list;
tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
}
*argc_p = ematch_argc;
......@@ -492,7 +493,7 @@ int print_ematch(FILE *fd, const struct rtattr *rta)
return print_ematch_list(fd, hdr, tb[TCA_EMATCH_TREE_LIST]);
}
struct bstr * bstr_alloc(const char *text)
struct bstr *bstr_alloc(const char *text)
{
struct bstr *b = calloc(1, sizeof(*b));
......@@ -558,6 +559,7 @@ void print_ematch_tree(const struct ematch *tree)
printf(")");
} else {
struct bstr *b;
for (b = t->args; b; b = b->next)
printf("%s%s", b->data, b->next ? " " : "");
}
......
......@@ -38,7 +38,7 @@ int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est)
{
int argc = *p_argc;
char **argv = *p_argv;
unsigned A, time_const;
unsigned int A, time_const;
NEXT_ARG();
if (est->ewma_log)
......
......@@ -45,16 +45,16 @@ explain(void)
#ifdef CONFIG_GACT_PROB
fprintf(stderr, "Usage: ... gact <ACTION> [RAND] [INDEX]\n");
fprintf(stderr,
"Where: \tACTION := reclassify | drop | continue | pass \n"
"\tRAND := random <RANDTYPE> <ACTION> <VAL>\n"
"\tRANDTYPE := netrand | determ\n"
"Where: \tACTION := reclassify | drop | continue | pass\n"
"\tRAND := random <RANDTYPE> <ACTION> <VAL>\n"
"\tRANDTYPE := netrand | determ\n"
"\tVAL : = value not exceeding 10000\n"
"\tINDEX := index value used\n"
"\n");
#else
fprintf(stderr, "Usage: ... gact <ACTION> [INDEX]\n");
fprintf(stderr,
"Where: \tACTION := reclassify | drop | continue | pass \n"
"Where: \tACTION := reclassify | drop | continue | pass\n"
"\tINDEX := index value used\n"
"\n");
#endif
......@@ -84,7 +84,7 @@ get_act(char ***argv_p)
} else if (matches(*argv, "pass") == 0 || matches(*argv, "ok") == 0) {
return TC_ACT_OK;
} else {
fprintf(stderr,"bad action type %s\n",*argv);
fprintf(stderr, "bad action type %s\n", *argv);
return -10;
}
}
......@@ -104,7 +104,7 @@ parse_gact(struct action_util *a, int *argc_p, char ***argv_p,
#endif
struct rtattr *tail;
memset(&p, 0, sizeof (p));
memset(&p, 0, sizeof(p));
p.action = TC_POLICE_RECLASSIFY;
if (argc < 0)
......@@ -155,11 +155,11 @@ parse_gact(struct action_util *a, int *argc_p, char ***argv_p,
argc--;
argv++;
if (get_u16(&pp.pval, *argv, 10)) {
fprintf(stderr, "Illegal probability val 0x%x\n",pp.pval);
fprintf(stderr, "Illegal probability val 0x%x\n", pp.pval);
return -1;
}
if (pp.pval > 10000) {
fprintf(stderr, "Illegal probability val 0x%x\n",pp.pval);
fprintf(stderr, "Illegal probability val 0x%x\n", pp.pval);
return -1;
}
argc--;
......@@ -190,10 +190,10 @@ parse_gact(struct action_util *a, int *argc_p, char ***argv_p,
tail = NLMSG_TAIL(n);
addattr_l(n, MAX_MSG, tca_id, NULL, 0);
addattr_l(n, MAX_MSG, TCA_GACT_PARMS, &p, sizeof (p));
addattr_l(n, MAX_MSG, TCA_GACT_PARMS, &p, sizeof(p));
#ifdef CONFIG_GACT_PROB
if (rd) {
addattr_l(n, MAX_MSG, TCA_GACT_PROB, &pp, sizeof (pp));
addattr_l(n, MAX_MSG, TCA_GACT_PROB, &pp, sizeof(pp));
}
#endif
tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
......@@ -204,7 +204,7 @@ parse_gact(struct action_util *a, int *argc_p, char ***argv_p,
}
static int
print_gact(struct action_util *au,FILE * f, struct rtattr *arg)
print_gact(struct action_util *au, FILE * f, struct rtattr *arg)
{
SPRINT_BUF(b1);
#ifdef CONFIG_GACT_PROB
......@@ -226,22 +226,23 @@ print_gact(struct action_util *au,FILE * f, struct rtattr *arg)
}
p = RTA_DATA(tb[TCA_GACT_PARMS]);
fprintf(f, "gact action %s", action_n2a(p->action, b1, sizeof (b1)));
fprintf(f, "gact action %s", action_n2a(p->action, b1, sizeof(b1)));
#ifdef CONFIG_GACT_PROB
if (NULL != tb[TCA_GACT_PROB]) {
if (tb[TCA_GACT_PROB] != NULL) {
pp = RTA_DATA(tb[TCA_GACT_PROB]);
} else {
/* need to keep consistent output */
memset(&pp_dummy, 0, sizeof (pp_dummy));
memset(&pp_dummy, 0, sizeof(pp_dummy));
pp = &pp_dummy;
}
fprintf(f, "\n\t random type %s %s val %d",prob_n2a(pp->ptype), action_n2a(pp->paction, b2, sizeof (b2)), pp->pval);
fprintf(f, "\n\t random type %s %s val %d", prob_n2a(pp->ptype), action_n2a(pp->paction, b2, sizeof (b2)), pp->pval);
#endif
fprintf(f, "\n\t index %d ref %d bind %d",p->index, p->refcnt, p->bindcnt);
fprintf(f, "\n\t index %d ref %d bind %d", p->index, p->refcnt, p->bindcnt);
if (show_stats) {
if (tb[TCA_GACT_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_GACT_TM]);
print_tm(f,tm);
print_tm(f, tm);
}
}
fprintf(f, "\n ");
......
......@@ -51,9 +51,9 @@ static struct option original_opts[] = {
{0, 0, 0, 0}
};
static struct iptables_target *t_list = NULL;
static struct iptables_target *t_list;
static struct option *opts = original_opts;
static unsigned int global_option_offset = 0;
static unsigned int global_option_offset;
#define OPTION_OFFSET 256
char *lib_dir;
......@@ -61,7 +61,7 @@ char *lib_dir;
void
register_target(struct iptables_target *me)
{
/* fprintf(stderr, "\nDummy register_target %s \n", me->name);
/* fprintf(stderr, "\nDummy register_target %s\n", me->name);
*/
me->next = t_list;
t_list = me;
......@@ -177,18 +177,18 @@ merge_options(struct option *oldopts, const struct option *newopts,
struct option *merge;
unsigned int num_old, num_new, i;
for (num_old = 0; oldopts[num_old].name; num_old++) ;
for (num_new = 0; newopts[num_new].name; num_new++) ;
for (num_old = 0; oldopts[num_old].name; num_old++);
for (num_new = 0; newopts[num_new].name; num_new++);
*option_offset = global_option_offset + OPTION_OFFSET;
merge = malloc(sizeof (struct option) * (num_new + num_old + 1));
memcpy(merge, oldopts, num_old * sizeof (struct option));
merge = malloc(sizeof(struct option) * (num_new + num_old + 1));
memcpy(merge, oldopts, num_old * sizeof(struct option));
for (i = 0; i < num_new; i++) {
merge[num_old + i] = newopts[i];
merge[num_old + i].val += *option_offset;
}
memset(merge + num_old + num_new, 0, sizeof (struct option));
memset(merge + num_old + num_new, 0, sizeof(struct option));
return merge;
}
......@@ -209,6 +209,7 @@ static struct iptables_target *
find_t(char *name)
{
struct iptables_target *m;
for (m = t_list; m; m = m->next) {
if (strcmp(m->name, name) == 0)
return m;
......@@ -224,7 +225,7 @@ get_target_name(const char *name)
char *error;
char *new_name, *lname;
struct iptables_target *m;
char path[strlen(lib_dir) + sizeof ("/libipt_.so") + strlen(name)];
char path[strlen(lib_dir) + sizeof("/libipt_.so") + strlen(name)];
#ifdef NO_SHARED_LIBS
return NULL;
......@@ -247,6 +248,7 @@ get_target_name(const char *name)
if (isupper(lname[0])) {
int i;
for (i = 0; i < strlen(name); i++) {
lname[i] = tolower(lname[i]);
}
......@@ -254,6 +256,7 @@ get_target_name(const char *name)
if (islower(new_name[0])) {
int i;
for (i = 0; i < strlen(new_name); i++) {
new_name[i] = toupper(new_name[i]);
}
......@@ -268,12 +271,12 @@ get_target_name(const char *name)
handle = dlopen(path, RTLD_LAZY);
if (!handle) {
sprintf(path, "%s/libxt_%s.so", lib_dir , lname);
sprintf(path, "%s/libxt_%s.so", lib_dir, lname);
handle = dlopen(path, RTLD_LAZY);
}
if (!handle) {
sprintf(path, "%s/libipt_%s.so", lib_dir , lname);
sprintf(path, "%s/libipt_%s.so", lib_dir, lname);
handle = dlopen(path, RTLD_LAZY);
}
/* ok, lets give up .. */
......@@ -291,9 +294,9 @@ get_target_name(const char *name)
m = (struct iptables_target *) dlsym(handle, lname);
if ((error = dlerror()) != NULL) {
m = find_t(new_name);
if (NULL == m) {
if (m == NULL) {
m = find_t(lname);
if (NULL == m) {
if (m == NULL) {
fputs(error, stderr);
fprintf(stderr, "\n");
dlclose(handle);
......@@ -321,7 +324,7 @@ struct in_addr *dotted_to_addr(const char *dotted)
char buf[20];
/* copy dotted string, because we need to modify it */
strncpy(buf, dotted, sizeof (buf) - 1);
strncpy(buf, dotted, sizeof(buf) - 1);
addrp = (unsigned char *) &(addr.s_addr);
p = buf;
......@@ -366,9 +369,9 @@ build_st(struct iptables_target *target, struct ipt_entry_target *t)
size_t size;
size =
IPT_ALIGN(sizeof (struct ipt_entry_target)) + target->size;
IPT_ALIGN(sizeof(struct ipt_entry_target)) + target->size;
if (NULL == t) {
if (t == NULL) {
target->t = fw_calloc(1, size);
target->t->u.target_size = size;
......@@ -385,7 +388,7 @@ build_st(struct iptables_target *target, struct ipt_entry_target *t)
return -1;
}
static int parse_ipt(struct action_util *a,int *argc_p,
static int parse_ipt(struct action_util *a, int *argc_p,
char ***argv_p, int tca_id, struct nlmsghdr *n)
{
struct iptables_target *m = NULL;
......@@ -406,6 +409,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
{
int i;
for (i = 0; i < rargc; i++) {
if (NULL == argv[i] || 0 == strcmp(argv[i], "action")) {
break;
......@@ -415,7 +419,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
}
if (argc <= 2) {
fprintf(stderr,"bad arguments to ipt %d vs %d \n", argc, rargc);
fprintf(stderr, "bad arguments to ipt %d vs %d\n", argc, rargc);
return -1;
}
......@@ -426,29 +430,29 @@ static int parse_ipt(struct action_util *a,int *argc_p,
switch (c) {
case 'j':
m = get_target_name(optarg);
if (NULL != m) {
if (m != NULL) {
if (0 > build_st(m, NULL)) {
printf(" %s error \n", m->name);
if (build_st(m, NULL) < 0) {
printf(" %s error\n", m->name);
return -1;
}
opts =
merge_options(opts, m->extra_opts,
&m->option_offset);
} else {
fprintf(stderr," failed to find target %s\n\n", optarg);
fprintf(stderr, " failed to find target %s\n\n", optarg);
return -1;
}
ok++;
break;
default:
memset(&fw, 0, sizeof (fw));
memset(&fw, 0, sizeof(fw));
if (m) {
m->parse(c - m->option_offset, argv, 0,
&m->tflags, NULL, &m->t);
} else {
fprintf(stderr," failed to find target %s\n\n", optarg);
fprintf(stderr, " failed to find target %s\n\n", optarg);
return -1;
}
......@@ -472,7 +476,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
}
if (!ok && !iok) {
fprintf(stderr," ipt Parser BAD!! (%s)\n", *argv);
fprintf(stderr, " ipt Parser BAD!! (%s)\n", *argv);
return -1;
}
......@@ -482,6 +486,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
{
struct tcmsg *t = NLMSG_DATA(n);
if (t->tcm_parent != TC_H_ROOT
&& t->tcm_parent == TC_H_MAJ(TC_H_INGRESS)) {
hook = NF_IP_PRE_ROUTING;
......@@ -522,11 +527,11 @@ static int parse_ipt(struct action_util *a,int *argc_p,
optind = 0;
free_opts(opts);
/* Clear flags if target will be used again */
m->tflags=0;
m->used=0;
m->tflags = 0;
m->used = 0;
/* Free allocated memory */
if (m->t)
free(m->t);
if (m->t)
free(m->t);
return 0;
......@@ -534,7 +539,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
}
static int
print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
print_ipt(struct action_util *au, FILE * f, struct rtattr *arg)
{
struct rtattr *tb[TCA_IPT_MAX + 1];
struct ipt_entry_target *t = NULL;
......@@ -560,20 +565,22 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
return -1;
} else {
__u32 hook;
hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
fprintf(f, " hook: %s \n", ipthooks[hook]);
fprintf(f, " hook: %s\n", ipthooks[hook]);
}
if (tb[TCA_IPT_TARG] == NULL) {
fprintf(f, "\t[NULL ipt target parameters ] \n");
fprintf(f, "\t[NULL ipt target parameters ]\n");
return -1;
} else {
struct iptables_target *m = NULL;
t = RTA_DATA(tb[TCA_IPT_TARG]);
m = get_target_name(t->u.user.name);
if (NULL != m) {
if (0 > build_st(m, t)) {
fprintf(stderr, " %s error \n", m->name);
if (m != NULL) {
if (build_st(m, t) < 0) {
fprintf(stderr, " %s error\n", m->name);
return -1;
}
......@@ -591,21 +598,24 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
fprintf(f, " [NULL ipt target index ]\n");
} else {
__u32 index;
index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
fprintf(f, " \n\tindex %d", index);
fprintf(f, "\n\tindex %d", index);
}
if (tb[TCA_IPT_CNT]) {
struct tc_cnt *c = RTA_DATA(tb[TCA_IPT_CNT]);;
struct tc_cnt *c = RTA_DATA(tb[TCA_IPT_CNT]);
fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
}
if (show_stats) {
if (tb[TCA_IPT_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);
print_tm(f,tm);
print_tm(f, tm);
}
}
fprintf(f, " \n");
fprintf(f, "\n");
}
free_opts(opts);
......@@ -614,7 +624,7 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
}
struct action_util ipt_action_util = {
.id = "ipt",
.parse_aopt = parse_ipt,
.print_aopt = print_ipt,
.id = "ipt",
.parse_aopt = parse_ipt,
.print_aopt = print_ipt,
};
......@@ -29,12 +29,12 @@
static void
explain(void)
{
fprintf(stderr, "Usage: mirred <DIRECTION> <ACTION> [index INDEX] <dev DEVICENAME> \n");
fprintf(stderr, "where: \n");
fprintf(stderr, "Usage: mirred <DIRECTION> <ACTION> [index INDEX] <dev DEVICENAME>\n");
fprintf(stderr, "where:\n");
fprintf(stderr, "\tDIRECTION := <ingress | egress>\n");
fprintf(stderr, "\tACTION := <mirror | redirect>\n");
fprintf(stderr, "\tINDEX is the specific policy instance id\n");
fprintf(stderr, "\tDEVICENAME is the devicename \n");
fprintf(stderr, "\tDEVICENAME is the devicename\n");
}
......@@ -68,13 +68,13 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p,
int argc = *argc_p;
char **argv = *argv_p;
int ok = 0, iok = 0, mirror=0,redir=0;
int ok = 0, iok = 0, mirror = 0, redir = 0;
struct tc_mirred p;
struct rtattr *tail;
char d[16];
memset(d,0,sizeof(d)-1);
memset(&p,0,sizeof(struct tc_mirred));
memset(d, 0, sizeof(d)-1);
memset(&p, 0, sizeof(struct tc_mirred));
while (argc > 0) {
......@@ -98,12 +98,12 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p,
argv++;
break;
}
} else if(!ok) {
} else if (!ok) {
fprintf(stderr, "was expecting egress (%s)\n", *argv);
break;
} else if (!mirror && matches(*argv, "mirror") == 0) {
mirror=1;
mirror = 1;
if (redir) {
fprintf(stderr, "Can't have both mirror and redir\n");
return -1;
......@@ -112,7 +112,7 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p,
p.action = TC_ACT_PIPE;
ok++;
} else if (!redir && matches(*argv, "redirect") == 0) {
redir=1;
redir = 1;
if (mirror) {
fprintf(stderr, "Can't have both mirror and redir\n");
return -1;
......@@ -145,6 +145,7 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p,
if (d[0]) {
int idx;
ll_init_map(&rth);
if ((idx = ll_name_to_index(d)) == 0) {
......@@ -197,7 +198,7 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p,
tail = NLMSG_TAIL(n);
addattr_l(n, MAX_MSG, tca_id, NULL, 0);
addattr_l(n, MAX_MSG, TCA_MIRRED_PARMS, &p, sizeof (p));
addattr_l(n, MAX_MSG, TCA_MIRRED_PARMS, &p, sizeof(p));
tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
*argc_p = argc;
......@@ -215,20 +216,21 @@ parse_mirred(struct action_util *a, int *argc_p, char ***argv_p,
char **argv = *argv_p;
if (argc < 0) {
fprintf(stderr,"mirred bad argument count %d\n", argc);
fprintf(stderr, "mirred bad argument count %d\n", argc);
return -1;
}
if (matches(*argv, "mirred") == 0) {
NEXT_ARG();
} else {
fprintf(stderr,"mirred bad argument %s\n", *argv);
fprintf(stderr, "mirred bad argument %s\n", *argv);
return -1;
}
if (matches(*argv, "egress") == 0 || matches(*argv, "index") == 0) {
int ret = parse_egress(a, &argc, &argv, tca_id, n);
if (ret == 0) {
*argc_p = argc;
*argv_p = argv;
......@@ -236,11 +238,11 @@ parse_mirred(struct action_util *a, int *argc_p, char ***argv_p,
}
} else if (matches(*argv, "ingress") == 0) {
fprintf(stderr,"mirred ingress not supported at the moment\n");
fprintf(stderr, "mirred ingress not supported at the moment\n");
} else if (matches(*argv, "help") == 0) {
usage();
} else {
fprintf(stderr,"mirred option not supported %s\n", *argv);
fprintf(stderr, "mirred option not supported %s\n", *argv);
}
return -1;
......@@ -248,11 +250,12 @@ parse_mirred(struct action_util *a, int *argc_p, char ***argv_p,
}
static int
print_mirred(struct action_util *au,FILE * f, struct rtattr *arg)
print_mirred(struct action_util *au, FILE * f, struct rtattr *arg)
{
struct tc_mirred *p;
struct rtattr *tb[TCA_MIRRED_MAX + 1];
const char *dev;
SPRINT_BUF(b1);
if (arg == NULL)
......@@ -276,15 +279,16 @@ print_mirred(struct action_util *au,FILE * f, struct rtattr *arg)
return -1;
}
fprintf(f, "mirred (%s to device %s) %s", mirred_n2a(p->eaction), dev,action_n2a(p->action, b1, sizeof (b1)));
fprintf(f, "mirred (%s to device %s) %s", mirred_n2a(p->eaction), dev, action_n2a(p->action, b1, sizeof (b1)));
fprintf(f, "\n ");
fprintf(f, "\tindex %d ref %d bind %d",p->index,p->refcnt,p->bindcnt);
fprintf(f, "\tindex %d ref %d bind %d", p->index, p->refcnt, p->bindcnt);
if (show_stats) {
if (tb[TCA_MIRRED_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_MIRRED_TM]);
print_tm(f,tm);
print_tm(f, tm);
}
}
fprintf(f, "\n ");
......
......@@ -41,7 +41,7 @@ usage(void)
}
static int
parse_nat_args(int *argc_p, char ***argv_p,struct tc_nat *sel)
parse_nat_args(int *argc_p, char ***argv_p, struct tc_nat *sel)
{
int argc = *argc_p;
char **argv = *argv_p;
......@@ -97,7 +97,7 @@ parse_nat(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct
if (matches(*argv, "nat") == 0) {
NEXT_ARG();
if (parse_nat_args(&argc, &argv, &sel)) {
fprintf(stderr, "Illegal nat construct (%s) \n",
fprintf(stderr, "Illegal nat construct (%s)\n",
*argv);
explain();
return -1;
......@@ -165,12 +165,13 @@ parse_nat(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct
}
static int
print_nat(struct action_util *au,FILE * f, struct rtattr *arg)
print_nat(struct action_util *au, FILE * f, struct rtattr *arg)
{
struct tc_nat *sel;
struct rtattr *tb[TCA_NAT_MAX + 1];
char buf1[256];
char buf2[256];
SPRINT_BUF(buf3);
int len;
......@@ -193,12 +194,13 @@ print_nat(struct action_util *au,FILE * f, struct rtattr *arg)
format_host(AF_INET, 4, &sel->old_addr, buf1, sizeof(buf1)),
len,
format_host(AF_INET, 4, &sel->new_addr, buf2, sizeof(buf2)),
action_n2a(sel->action, buf3, sizeof (buf3)));
action_n2a(sel->action, buf3, sizeof(buf3)));
if (show_stats) {
if (tb[TCA_NAT_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_NAT_TM]);
print_tm(f,tm);
print_tm(f, tm);
}
}
......
This diff is collapsed.
......@@ -38,9 +38,9 @@ static void usage(void)
fprintf(stderr, " [ peakrate BPS ] [ avrate BPS ] [ overhead BYTES ]\n");
fprintf(stderr, " [ linklayer TYPE ] [ ACTIONTERM ]\n");
fprintf(stderr, "New Syntax ACTIONTERM := conform-exceed <EXCEEDACT>[/NOTEXCEEDACT] \n");
fprintf(stderr, "Where: *EXCEEDACT := pipe | ok | reclassify | drop | continue \n");
fprintf(stderr, "Where: pipe is only valid for new syntax \n");
fprintf(stderr, "New Syntax ACTIONTERM := conform-exceed <EXCEEDACT>[/NOTEXCEEDACT]\n");
fprintf(stderr, "Where: *EXCEEDACT := pipe | ok | reclassify | drop | continue\n");
fprintf(stderr, "Where: pipe is only valid for new syntax\n");
exit(-1);
}
......@@ -91,6 +91,7 @@ static int police_action_a2n(const char *arg, int *result)
res = TC_POLICE_PIPE;
else {
char dummy;
if (sscanf(arg, "%d%c", &res, &dummy) != 1)
return -1;
}
......@@ -121,21 +122,21 @@ static int get_police_result(int *action, int *result, char *arg)
}
int act_parse_police(struct action_util *a,int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
int act_parse_police(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
{
int argc = *argc_p;
char **argv = *argv_p;
int res = -1;
int ok=0;
int ok = 0;
struct tc_police p;
__u32 rtab[256];
__u32 ptab[256];
__u32 avrate = 0;
int presult = 0;
unsigned buffer=0, mtu=0, mpu=0;
unsigned short overhead=0;
unsigned buffer = 0, mtu = 0, mpu = 0;
unsigned short overhead = 0;
unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */
int Rcell_log=-1, Pcell_log = -1;
int Rcell_log = -1, Pcell_log = -1;
struct rtattr *tail;
memset(&p, 0, sizeof(p));
......@@ -297,7 +298,7 @@ int act_parse_police(struct action_util *a,int *argc_p, char ***argv_p, int tca_
if (p.rate.rate)
addattr_l(n, MAX_MSG, TCA_POLICE_RATE, rtab, 1024);
if (p.peakrate.rate)
addattr_l(n, MAX_MSG, TCA_POLICE_PEAKRATE, ptab, 1024);
addattr_l(n, MAX_MSG, TCA_POLICE_PEAKRATE, ptab, 1024);
if (avrate)
addattr32(n, MAX_MSG, TCA_POLICE_AVRATE, avrate);
if (presult)
......@@ -313,7 +314,7 @@ int act_parse_police(struct action_util *a,int *argc_p, char ***argv_p, int tca_
int parse_police(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
{
return act_parse_police(NULL,argc_p,argv_p,tca_id,n);
return act_parse_police(NULL, argc_p, argv_p, tca_id, n);
}
int
......@@ -323,7 +324,7 @@ print_police(struct action_util *a, FILE *f, struct rtattr *arg)
SPRINT_BUF(b2);
struct tc_police *p;
struct rtattr *tb[TCA_POLICE_MAX+1];
unsigned buffer;
unsigned int buffer;
unsigned int linklayer;
if (arg == NULL)
......@@ -356,19 +357,19 @@ print_police(struct action_util *a, FILE *f, struct rtattr *arg)
fprintf(f, "avrate %s ", sprint_rate(rta_getattr_u32(tb[TCA_POLICE_AVRATE]), b1));
fprintf(f, "action %s", police_action_n2a(p->action, b1, sizeof(b1)));
if (tb[TCA_POLICE_RESULT]) {
fprintf(f, "/%s ", police_action_n2a(*(int*)RTA_DATA(tb[TCA_POLICE_RESULT]), b1, sizeof(b1)));
fprintf(f, "/%s ", police_action_n2a(*(int *)RTA_DATA(tb[TCA_POLICE_RESULT]), b1, sizeof(b1)));
} else
fprintf(f, " ");
fprintf(f, "overhead %ub ", p->rate.overhead);
linklayer = (p->rate.linklayer & TC_LINKLAYER_MASK);
if (linklayer > TC_LINKLAYER_ETHERNET || show_details)
fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b2));
fprintf(f, "\nref %d bind %d\n",p->refcnt, p->bindcnt);
fprintf(f, "\nref %d bind %d\n", p->refcnt, p->bindcnt);
return 0;
}
int
tc_print_police(FILE *f, struct rtattr *arg) {
return print_police(&police_action_util,f,arg);
return print_police(&police_action_util, f, arg);
}
......@@ -138,7 +138,7 @@ parse_simple(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
}
if (strlen(simpdata) > (SIMP_MAX_DATA - 1)) {
fprintf(stderr, "simple: Illegal string len %zu <%s> \n",
fprintf(stderr, "simple: Illegal string len %zu <%s>\n",
strlen(simpdata), simpdata);
return -1;
}
......@@ -156,7 +156,7 @@ parse_simple(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
return 0;
}
static int print_simple(struct action_util *au, FILE * f, struct rtattr *arg)
static int print_simple(struct action_util *au, FILE *f, struct rtattr *arg)
{
struct tc_defact *sel;
struct rtattr *tb[TCA_DEF_MAX + 1];
......@@ -187,6 +187,7 @@ static int print_simple(struct action_util *au, FILE * f, struct rtattr *arg)
if (show_stats) {
if (tb[TCA_DEF_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_DEF_TM]);
print_tm(f, tm);
}
}
......
......@@ -32,8 +32,8 @@ explain(void)
{
fprintf(stderr, "Usage: ... skbedit <[QM] [PM] [MM]>\n"
"QM = queue_mapping QUEUE_MAPPING\n"
"PM = priority PRIORITY \n"
"MM = mark MARK \n"
"PM = priority PRIORITY\n"
"MM = mark MARK\n"
"QUEUE_MAPPING = device transmit queue to use\n"
"PRIORITY = classID to assign to priority field\n"
"MARK = firewall mark to set\n");
......@@ -161,6 +161,7 @@ parse_skbedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
{
struct rtattr *tb[TCA_SKBEDIT_MAX + 1];
SPRINT_BUF(b1);
__u32 *priority;
__u32 *mark;
......@@ -198,6 +199,7 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
if (show_stats) {
if (tb[TCA_SKBEDIT_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_SKBEDIT_TM]);
print_tm(f, tm);
}
}
......
......@@ -186,7 +186,7 @@ static int print_vlan(struct action_util *au, FILE *f, struct rtattr *arg)
fprintf(f, " vlan");
switch(parm->v_action) {
switch (parm->v_action) {
case TCA_VLAN_ACT_POP:
fprintf(f, " pop");
break;
......@@ -203,7 +203,7 @@ static int print_vlan(struct action_util *au, FILE *f, struct rtattr *arg)
}
break;
}
fprintf(f, " %s", action_n2a(parm->action, b1, sizeof (b1)));
fprintf(f, " %s", action_n2a(parm->action, b1, sizeof(b1)));
fprintf(f, "\n\t index %d ref %d bind %d", parm->index, parm->refcnt,
parm->bindcnt);
......@@ -211,6 +211,7 @@ static int print_vlan(struct action_util *au, FILE *f, struct rtattr *arg)
if (show_stats) {
if (tb[TCA_VLAN_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_VLAN_TM]);
print_tm(f, tm);
}
}
......
......@@ -44,7 +44,7 @@
#endif
#ifndef ALIGN
#define ALIGN(x,a) __ALIGN_KERNEL((x), (a))
#define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
#endif
static const char *tname = "mangle";
......@@ -85,9 +85,9 @@ build_st(struct xtables_target *target, struct xt_entry_target *t)
{
size_t size =
XT_ALIGN(sizeof (struct xt_entry_target)) + target->size;
XT_ALIGN(sizeof(struct xt_entry_target)) + target->size;
if (NULL == t) {
if (t == NULL) {
target->t = xtables_calloc(1, size);
target->t->u.target_size = size;
strcpy(target->t->u.user.name, target->name);
......@@ -109,14 +109,14 @@ static void set_lib_dir(void)
if (!lib_dir) {
lib_dir = getenv("IPTABLES_LIB_DIR");
if (lib_dir)
fprintf(stderr, "using deprecated IPTABLES_LIB_DIR \n");
fprintf(stderr, "using deprecated IPTABLES_LIB_DIR\n");
}
if (lib_dir == NULL)
lib_dir = XT_LIB_DIR;
}
static int parse_ipt(struct action_util *a,int *argc_p,
static int parse_ipt(struct action_util *a, int *argc_p,
char ***argv_p, int tca_id, struct nlmsghdr *n)
{
struct xtables_target *m = NULL;
......@@ -138,6 +138,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
{
int i;
for (i = 0; i < rargc; i++) {
if (NULL == argv[i] || 0 == strcmp(argv[i], "action")) {
break;
......@@ -147,7 +148,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
}
if (argc <= 2) {
fprintf(stderr,"bad arguments to ipt %d vs %d \n", argc, rargc);
fprintf(stderr, "bad arguments to ipt %d vs %d\n", argc, rargc);
return -1;
}
......@@ -158,10 +159,10 @@ static int parse_ipt(struct action_util *a,int *argc_p,
switch (c) {
case 'j':
m = xtables_find_target(optarg, XTF_TRY_LOAD);
if (NULL != m) {
if (m != NULL) {
if (0 > build_st(m, NULL)) {
printf(" %s error \n", m->name);
if (build_st(m, NULL) < 0) {
printf(" %s error\n", m->name);
return -1;
}
#if (XTABLES_VERSION_CODE >= 6)
......@@ -180,24 +181,24 @@ static int parse_ipt(struct action_util *a,int *argc_p,
} else
tcipt_globals.opts = opts;
} else {
fprintf(stderr," failed to find target %s\n\n", optarg);
fprintf(stderr, " failed to find target %s\n\n", optarg);
return -1;
}
ok++;
break;
default:
memset(&fw, 0, sizeof (fw));
memset(&fw, 0, sizeof(fw));
#if (XTABLES_VERSION_CODE >= 6)
if (m != NULL && m->x6_parse != NULL ) {
xtables_option_tpcall(c, argv, 0 , m, NULL);
if (m != NULL && m->x6_parse != NULL) {
xtables_option_tpcall(c, argv, 0, m, NULL);
#else
if (m != NULL && m->parse != NULL ) {
if (m != NULL && m->parse != NULL) {
m->parse(c - m->option_offset, argv, 0, &m->tflags,
NULL, &m->t);
#endif
} else {
fprintf(stderr,"failed to find target %s\n\n", optarg);
fprintf(stderr, "failed to find target %s\n\n", optarg);
return -1;
}
......@@ -220,7 +221,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
}
if (!ok && !iok) {
fprintf(stderr," ipt Parser BAD!! (%s)\n", *argv);
fprintf(stderr, " ipt Parser BAD!! (%s)\n", *argv);
return -1;
}
......@@ -235,6 +236,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
{
struct tcmsg *t = NLMSG_DATA(n);
if (t->tcm_parent != TC_H_ROOT
&& t->tcm_parent == TC_H_MAJ(TC_H_INGRESS)) {
hook = NF_IP_PRE_ROUTING;
......@@ -289,7 +291,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
}
static int
print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
print_ipt(struct action_util *au, FILE * f, struct rtattr *arg)
{
struct rtattr *tb[TCA_IPT_MAX + 1];
struct xt_entry_target *t = NULL;
......@@ -318,20 +320,22 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
return -1;
} else {
__u32 hook;
hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
fprintf(f, " hook: %s \n", ipthooks[hook]);
fprintf(f, " hook: %s\n", ipthooks[hook]);
}
if (tb[TCA_IPT_TARG] == NULL) {
fprintf(f, "\t[NULL ipt target parameters ] \n");
fprintf(f, "\t[NULL ipt target parameters ]\n");
return -1;
} else {
struct xtables_target *m = NULL;
t = RTA_DATA(tb[TCA_IPT_TARG]);
m = xtables_find_target(t->u.user.name, XTF_TRY_LOAD);
if (NULL != m) {
if (0 > build_st(m, t)) {
fprintf(stderr, " %s error \n", m->name);
if (m != NULL) {
if (build_st(m, t) < 0) {
fprintf(stderr, " %s error\n", m->name);
return -1;
}
......@@ -361,21 +365,24 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
fprintf(f, " [NULL ipt target index ]\n");
} else {
__u32 index;
index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
fprintf(f, " \n\tindex %d", index);
fprintf(f, "\n\tindex %d", index);
}
if (tb[TCA_IPT_CNT]) {
struct tc_cnt *c = RTA_DATA(tb[TCA_IPT_CNT]);;
struct tc_cnt *c = RTA_DATA(tb[TCA_IPT_CNT]);
fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
}
if (show_stats) {
if (tb[TCA_IPT_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);
print_tm(f,tm);
print_tm(f, tm);
}
}
fprintf(f, " \n");
fprintf(f, "\n");
}
xtables_free_opts(1);
......@@ -384,7 +391,7 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
}
struct action_util xt_action_util = {
.id = "xt",
.parse_aopt = parse_ipt,
.print_aopt = print_ipt,
.id = "xt",
.parse_aopt = parse_ipt,
.print_aopt = print_ipt,
};
......@@ -41,8 +41,8 @@
#endif
#ifndef ALIGN
#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
#endif
static const char *pname = "tc-ipt";
......@@ -63,7 +63,7 @@ static struct option original_opts[] = {
};
static struct option *opts = original_opts;
static unsigned int global_option_offset = 0;
static unsigned int global_option_offset;
char *lib_dir;
const char *program_version = XTABLES_VERSION;
const char *program_name = "tc-ipt";
......@@ -96,18 +96,18 @@ merge_options(struct option *oldopts, const struct option *newopts,
struct option *merge;
unsigned int num_old, num_new, i;
for (num_old = 0; oldopts[num_old].name; num_old++) ;
for (num_new = 0; newopts[num_new].name; num_new++) ;
for (num_old = 0; oldopts[num_old].name; num_old++);
for (num_new = 0; newopts[num_new].name; num_new++);
*option_offset = global_option_offset + OPTION_OFFSET;
merge = malloc(sizeof (struct option) * (num_new + num_old + 1));
memcpy(merge, oldopts, num_old * sizeof (struct option));
merge = malloc(sizeof(struct option) * (num_new + num_old + 1));
memcpy(merge, oldopts, num_old * sizeof(struct option));
for (i = 0; i < num_new; i++) {
merge[num_old + i] = newopts[i];
merge[num_old + i].val += *option_offset;
}
memset(merge + num_old + num_new, 0, sizeof (struct option));
memset(merge + num_old + num_new, 0, sizeof(struct option));
return merge;
}
......@@ -125,35 +125,35 @@ merge_options(struct option *oldopts, const struct option *newopts,
int
check_inverse(const char option[], int *invert, int *my_optind, int argc)
{
if (option && strcmp(option, "!") == 0) {
if (*invert)
exit_error(PARAMETER_PROBLEM,
"Multiple `!' flags not allowed");
*invert = TRUE;
if (my_optind != NULL) {
++*my_optind;
if (argc && *my_optind > argc)
exit_error(PARAMETER_PROBLEM,
"no argument following `!'");
}
return TRUE;
}
return FALSE;
if (option && strcmp(option, "!") == 0) {
if (*invert)
exit_error(PARAMETER_PROBLEM,
"Multiple `!' flags not allowed");
*invert = TRUE;
if (my_optind != NULL) {
++*my_optind;
if (argc && *my_optind > argc)
exit_error(PARAMETER_PROBLEM,
"no argument following `!'");
}
return TRUE;
}
return FALSE;
}
/*XXX: TC_CONFIG_XT_H */
void exit_error(enum exittype status, const char *msg, ...)
{
va_list args;
va_start(args, msg);
fprintf(stderr, "%s v%s: ", pname, pversion);
vfprintf(stderr, msg, args);
va_end(args);
fprintf(stderr, "\n");
/* On error paths, make sure that we don't leak memory */
exit(status);
va_list args;
va_start(args, msg);
fprintf(stderr, "%s v%s: ", pname, pversion);
vfprintf(stderr, msg, args);
va_end(args);
fprintf(stderr, "\n");
/* On error paths, make sure that we don't leak memory */
exit(status);
}
/*XXX: TC_CONFIG_XT_H */
......@@ -173,9 +173,9 @@ build_st(struct xtables_target *target, struct xt_entry_target *t)
{
size_t size =
XT_ALIGN(sizeof (struct xt_entry_target)) + target->size;
XT_ALIGN(sizeof(struct xt_entry_target)) + target->size;
if (NULL == t) {
if (t == NULL) {
target->t = fw_calloc(1, size);
target->t->u.target_size = size;
strcpy(target->t->u.user.name, target->name);
......@@ -197,14 +197,14 @@ inline void set_lib_dir(void)
if (!lib_dir) {
lib_dir = getenv("IPTABLES_LIB_DIR");
if (lib_dir)
fprintf(stderr, "using deprecated IPTABLES_LIB_DIR \n");
fprintf(stderr, "using deprecated IPTABLES_LIB_DIR\n");
}
if (lib_dir == NULL)
lib_dir = XT_LIB_DIR;
}
static int parse_ipt(struct action_util *a,int *argc_p,
static int parse_ipt(struct action_util *a, int *argc_p,
char ***argv_p, int tca_id, struct nlmsghdr *n)
{
struct xtables_target *m = NULL;
......@@ -223,6 +223,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
{
int i;
for (i = 0; i < rargc; i++) {
if (NULL == argv[i] || 0 == strcmp(argv[i], "action")) {
break;
......@@ -232,7 +233,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
}
if (argc <= 2) {
fprintf(stderr,"bad arguments to ipt %d vs %d \n", argc, rargc);
fprintf(stderr, "bad arguments to ipt %d vs %d\n", argc, rargc);
return -1;
}
......@@ -243,29 +244,29 @@ static int parse_ipt(struct action_util *a,int *argc_p,
switch (c) {
case 'j':
m = find_target(optarg, TRY_LOAD);
if (NULL != m) {
if (m != NULL) {
if (0 > build_st(m, NULL)) {
printf(" %s error \n", m->name);
if (build_st(m, NULL) < 0) {
printf(" %s error\n", m->name);
return -1;
}
opts =
merge_options(opts, m->extra_opts,
&m->option_offset);
} else {
fprintf(stderr," failed to find target %s\n\n", optarg);
fprintf(stderr, " failed to find target %s\n\n", optarg);
return -1;
}
ok++;
break;
default:
memset(&fw, 0, sizeof (fw));
memset(&fw, 0, sizeof(fw));
if (m) {
m->parse(c - m->option_offset, argv, 0,
&m->tflags, NULL, &m->t);
} else {
fprintf(stderr," failed to find target %s\n\n", optarg);
fprintf(stderr, " failed to find target %s\n\n", optarg);
return -1;
}
......@@ -289,7 +290,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
}
if (!ok && !iok) {
fprintf(stderr," ipt Parser BAD!! (%s)\n", *argv);
fprintf(stderr, " ipt Parser BAD!! (%s)\n", *argv);
return -1;
}
......@@ -299,6 +300,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
{
struct tcmsg *t = NLMSG_DATA(n);
if (t->tcm_parent != TC_H_ROOT
&& t->tcm_parent == TC_H_MAJ(TC_H_INGRESS)) {
hook = NF_IP_PRE_ROUTING;
......@@ -339,11 +341,11 @@ static int parse_ipt(struct action_util *a,int *argc_p,
optind = 0;
free_opts(opts);
/* Clear flags if target will be used again */
m->tflags=0;
m->used=0;
m->tflags = 0;
m->used = 0;
/* Free allocated memory */
if (m->t)
free(m->t);
if (m->t)
free(m->t);
return 0;
......@@ -351,7 +353,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
}
static int
print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
print_ipt(struct action_util *au, FILE * f, struct rtattr *arg)
{
struct rtattr *tb[TCA_IPT_MAX + 1];
struct xt_entry_target *t = NULL;
......@@ -375,20 +377,22 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
return -1;
} else {
__u32 hook;
hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
fprintf(f, " hook: %s \n", ipthooks[hook]);
fprintf(f, " hook: %s\n", ipthooks[hook]);
}
if (tb[TCA_IPT_TARG] == NULL) {
fprintf(f, "\t[NULL ipt target parameters ] \n");
fprintf(f, "\t[NULL ipt target parameters ]\n");
return -1;
} else {
struct xtables_target *m = NULL;
t = RTA_DATA(tb[TCA_IPT_TARG]);
m = find_target(t->u.user.name, TRY_LOAD);
if (NULL != m) {
if (0 > build_st(m, t)) {
fprintf(stderr, " %s error \n", m->name);
if (m != NULL) {
if (build_st(m, t) < 0) {
fprintf(stderr, " %s error\n", m->name);
return -1;
}
......@@ -406,21 +410,24 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
fprintf(f, " [NULL ipt target index ]\n");
} else {
__u32 index;
index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
fprintf(f, " \n\tindex %d", index);
fprintf(f, "\n\tindex %d", index);
}
if (tb[TCA_IPT_CNT]) {
struct tc_cnt *c = RTA_DATA(tb[TCA_IPT_CNT]);;
struct tc_cnt *c = RTA_DATA(tb[TCA_IPT_CNT]);
fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
}
if (show_stats) {
if (tb[TCA_IPT_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);
print_tm(f,tm);
print_tm(f, tm);
}
}
fprintf(f, " \n");
fprintf(f, "\n");
}
free_opts(opts);
......@@ -429,7 +436,7 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
}
struct action_util ipt_action_util = {
.id = "ipt",
.parse_aopt = parse_ipt,
.print_aopt = print_ipt,
.id = "ipt",
.parse_aopt = parse_ipt,
.print_aopt = print_ipt,
};
......@@ -25,7 +25,7 @@
static int
parse_icmp(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
parse_icmp(int *argc_p, char ***argv_p, struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
{
int res = -1;
#if 0
......@@ -47,7 +47,7 @@ parse_icmp(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_
}
return -1;
done:
done:
*argc_p = argc;
*argv_p = argv;
#endif
......
......@@ -24,7 +24,7 @@
#include "m_pedit.h"
static int
parse_ip(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
parse_ip(int *argc_p, char ***argv_p, struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
{
int res = -1;
int argc = *argc_p;
......@@ -36,13 +36,13 @@ parse_ip(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_ke
if (strcmp(*argv, "src") == 0) {
NEXT_ARG();
tkey->off = 12;
res = parse_cmd(&argc, &argv, 4, TIPV4,RU32,sel,tkey);
res = parse_cmd(&argc, &argv, 4, TIPV4, RU32, sel, tkey);
goto done;
}
if (strcmp(*argv, "dst") == 0) {
NEXT_ARG();
tkey->off = 16;
res = parse_cmd(&argc, &argv, 4, TIPV4,RU32,sel,tkey);
res = parse_cmd(&argc, &argv, 4, TIPV4, RU32, sel, tkey);
goto done;
}
/* jamal - look at these and make them either old or new
......@@ -52,94 +52,94 @@ parse_ip(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_ke
if (strcmp(*argv, "tos") == 0 || matches(*argv, "dsfield") == 0) {
NEXT_ARG();
tkey->off = 1;
res = parse_cmd(&argc, &argv, 1, TU32,RU8,sel,tkey);
res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
goto done;
}
if (strcmp(*argv, "ihl") == 0) {
NEXT_ARG();
tkey->off = 0;
res = parse_cmd(&argc, &argv, 1, TU32,0x0f,sel,tkey);
res = parse_cmd(&argc, &argv, 1, TU32, 0x0f, sel, tkey);
goto done;
}
if (strcmp(*argv, "protocol") == 0) {
NEXT_ARG();
tkey->off = 9;
res = parse_cmd(&argc, &argv, 1, TU32,RU8,sel,tkey);
res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
goto done;
}
/* jamal - fix this */
if (matches(*argv, "precedence") == 0) {
NEXT_ARG();
tkey->off = 1;
res = parse_cmd(&argc, &argv, 1, TU32,RU8,sel,tkey);
res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
goto done;
}
/* jamal - validate this at some point */
if (strcmp(*argv, "nofrag") == 0) {
NEXT_ARG();
tkey->off = 6;
res = parse_cmd(&argc, &argv, 1, TU32,0x3F,sel,tkey);
res = parse_cmd(&argc, &argv, 1, TU32, 0x3F, sel, tkey);
goto done;
}
/* jamal - validate this at some point */
if (strcmp(*argv, "firstfrag") == 0) {
NEXT_ARG();
tkey->off = 6;
res = parse_cmd(&argc, &argv, 1, TU32,0x1F,sel,tkey);
res = parse_cmd(&argc, &argv, 1, TU32, 0x1F, sel, tkey);
goto done;
}
if (strcmp(*argv, "ce") == 0) {
NEXT_ARG();
tkey->off = 6;
res = parse_cmd(&argc, &argv, 1, TU32,0x80,sel,tkey);
res = parse_cmd(&argc, &argv, 1, TU32, 0x80, sel, tkey);
goto done;
}
if (strcmp(*argv, "df") == 0) {
NEXT_ARG();
tkey->off = 6;
res = parse_cmd(&argc, &argv, 1, TU32,0x40,sel,tkey);
res = parse_cmd(&argc, &argv, 1, TU32, 0x40, sel, tkey);
goto done;
}
if (strcmp(*argv, "mf") == 0) {
NEXT_ARG();
tkey->off = 6;
res = parse_cmd(&argc, &argv, 1, TU32,0x20,sel,tkey);
res = parse_cmd(&argc, &argv, 1, TU32, 0x20, sel, tkey);
goto done;
}
if (strcmp(*argv, "dport") == 0) {
NEXT_ARG();
tkey->off = 22;
res = parse_cmd(&argc, &argv, 2, TU32,RU16,sel,tkey);
res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
goto done;
}
if (strcmp(*argv, "sport") == 0) {
NEXT_ARG();
tkey->off = 20;
res = parse_cmd(&argc, &argv, 2, TU32,RU16,sel,tkey);
res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
goto done;
}
if (strcmp(*argv, "icmp_type") == 0) {
NEXT_ARG();
tkey->off = 20;
res = parse_cmd(&argc, &argv, 1, TU32,RU8,sel,tkey);
res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
goto done;
}
if (strcmp(*argv, "icmp_code") == 0) {
NEXT_ARG();
tkey->off = 20;
res = parse_cmd(&argc, &argv, 1, TU32,RU8,sel,tkey);
res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
goto done;
}
return -1;
done:
done:
*argc_p = argc;
*argv_p = argv;
return res;
}
static int
parse_ip6(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
parse_ip6(int *argc_p, char ***argv_p, struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
{
int res = -1;
return res;
......
......@@ -24,7 +24,7 @@
#include "m_pedit.h"
static int
parse_tcp(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
parse_tcp(int *argc_p, char ***argv_p, struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
{
int res = -1;
return res;
......
......@@ -24,7 +24,7 @@
#include "m_pedit.h"
static int
parse_udp(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
parse_udp(int *argc_p, char ***argv_p, struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
{
int res = -1;
return res;
......
......@@ -30,7 +30,7 @@
static int atm_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{
if (argc) {
fprintf(stderr,"Usage: atm\n");
fprintf(stderr, "Usage: atm\n");
return -1;
}
return 0;
......@@ -39,10 +39,8 @@ static int atm_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
static void explain(void)
{
fprintf(stderr, "Usage: ... atm ( pvc ADDR | svc ADDR [ sap SAP ] ) "
"[ qos QOS ] [ sndbuf BYTES ]\n");
fprintf(stderr, " [ hdr HEX... ] [ excess ( CLASSID | clp ) ] "
"[ clip ]\n");
fprintf(stderr, "Usage: ... atm ( pvc ADDR | svc ADDR [ sap SAP ] ) [ qos QOS ] [ sndbuf BYTES ]\n");
fprintf(stderr, " [ hdr HEX... ] [ excess ( CLASSID | clp ) ] [ clip ]\n");
}
......@@ -60,52 +58,47 @@ static int atm_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
int set_clip = 0;
int s;
memset(&addr,0,sizeof(addr));
(void) text2qos("aal5,ubr:sdu=9180,rx:none",&qos,0);
(void) text2sap("blli:l2=iso8802",&sap,0);
memset(&addr, 0, sizeof(addr));
(void) text2qos("aal5,ubr:sdu=9180,rx:none", &qos, 0);
(void) text2sap("blli:l2=iso8802", &sap, 0);
while (argc > 0) {
if (!strcmp(*argv,"pvc")) {
if (!strcmp(*argv, "pvc")) {
NEXT_ARG();
if (text2atm(*argv,(struct sockaddr *) &addr,
sizeof(addr),T2A_PVC | T2A_NAME) < 0) {
if (text2atm(*argv, (struct sockaddr *) &addr,
sizeof(addr), T2A_PVC | T2A_NAME) < 0) {
explain();
return -1;
}
}
else if (!strcmp(*argv,"svc")) {
} else if (!strcmp(*argv,"svc")) {
NEXT_ARG();
if (text2atm(*argv,(struct sockaddr *) &addr,
sizeof(addr),T2A_SVC | T2A_NAME) < 0) {
if (text2atm(*argv, (struct sockaddr *) &addr,
sizeof(addr), T2A_SVC | T2A_NAME) < 0) {
explain();
return -1;
}
}
else if (!strcmp(*argv,"qos")) {
} else if (!strcmp(*argv,"qos")) {
NEXT_ARG();
if (text2qos(*argv,&qos,0) < 0) {
if (text2qos(*argv, &qos, 0) < 0) {
explain();
return -1;
}
}
else if (!strcmp(*argv,"sndbuf")) {
} else if (!strcmp(*argv,"sndbuf")) {
char *end;
NEXT_ARG();
sndbuf = strtol(*argv,&end,0);
sndbuf = strtol(*argv, &end, 0);
if (*end) {
explain();
return -1;
}
}
else if (!strcmp(*argv,"sap")) {
} else if (!strcmp(*argv,"sap")) {
NEXT_ARG();
if (addr.sas_family != AF_ATMSVC ||
text2sap(*argv,&sap,T2A_NAME) < 0) {
text2sap(*argv, &sap, T2A_NAME) < 0) {
explain();
return -1;
}
}
else if (!strcmp(*argv,"hdr")) {
} else if (!strcmp(*argv,"hdr")) {
unsigned char *ptr;
char *walk;
......@@ -115,7 +108,7 @@ static int atm_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
int tmp;
if (ptr == hdr+MAX_HDR_LEN) {
fprintf(stderr,"header is too long\n");
fprintf(stderr, "header is too long\n");
return -1;
}
if (*walk == '.') continue;
......@@ -124,64 +117,61 @@ static int atm_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
explain();
return -1;
}
sscanf(walk,"%2x",&tmp);
sscanf(walk, "%2x", &tmp);
*ptr++ = tmp;
walk++;
}
hdr_len = ptr-hdr;
}
else if (!strcmp(*argv,"excess")) {
} else if (!strcmp(*argv,"excess")) {
NEXT_ARG();
if (!strcmp(*argv,"clp")) excess = 0;
else if (get_tc_classid(&excess,*argv)) {
if (!strcmp(*argv, "clp")) excess = 0;
else if (get_tc_classid(&excess, *argv)) {
explain();
return -1;
}
}
else if (!strcmp(*argv,"clip")) {
} else if (!strcmp(*argv,"clip")) {
set_clip = 1;
}
else {
} else {
explain();
return 1;
}
argc--;
argv++;
}
s = socket(addr.sas_family,SOCK_DGRAM,0);
s = socket(addr.sas_family, SOCK_DGRAM, 0);
if (s < 0) {
perror("socket");
return -1;
}
if (setsockopt(s,SOL_ATM,SO_ATMQOS,&qos,sizeof(qos)) < 0) {
if (setsockopt(s, SOL_ATM, SO_ATMQOS, &qos, sizeof(qos)) < 0) {
perror("SO_ATMQOS");
return -1;
}
if (sndbuf)
if (setsockopt(s,SOL_SOCKET,SO_SNDBUF,&sndbuf,sizeof(sndbuf)) < 0) {
if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf)) < 0) {
perror("SO_SNDBUF");
return -1;
}
if (addr.sas_family == AF_ATMSVC && setsockopt(s,SOL_ATM,SO_ATMSAP,
&sap,sizeof(sap)) < 0) {
if (addr.sas_family == AF_ATMSVC && setsockopt(s, SOL_ATM, SO_ATMSAP,
&sap, sizeof(sap)) < 0) {
perror("SO_ATMSAP");
return -1;
}
if (connect(s,(struct sockaddr *) &addr,addr.sas_family == AF_ATMPVC ?
if (connect(s, (struct sockaddr *) &addr, addr.sas_family == AF_ATMPVC ?
sizeof(struct sockaddr_atmpvc) : sizeof(addr)) < 0) {
perror("connect");
return -1;
}
if (set_clip)
if (ioctl(s,ATMARP_MKIP,0) < 0) {
if (ioctl(s, ATMARP_MKIP, 0) < 0) {
perror("ioctl ATMARP_MKIP");
return -1;
}
tail = NLMSG_TAIL(n);
addattr_l(n,1024,TCA_OPTIONS,NULL,0);
addattr_l(n,1024,TCA_ATM_FD,&s,sizeof(s));
if (excess) addattr_l(n,1024,TCA_ATM_EXCESS,&excess,sizeof(excess));
if (hdr_len != -1) addattr_l(n,1024,TCA_ATM_HDR,hdr,hdr_len);
addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
addattr_l(n, 1024, TCA_ATM_FD, &s, sizeof(s));
if (excess) addattr_l(n, 1024, TCA_ATM_EXCESS, &excess, sizeof(excess));
if (hdr_len != -1) addattr_l(n, 1024, TCA_ATM_HDR, hdr, hdr_len);
tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
return 0;
}
......@@ -200,37 +190,37 @@ static int atm_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
if (tb[TCA_ATM_ADDR]) {
if (RTA_PAYLOAD(tb[TCA_ATM_ADDR]) <
sizeof(struct sockaddr_atmpvc))
fprintf(stderr,"ATM: address too short\n");
fprintf(stderr, "ATM: address too short\n");
else {
if (atm2text(buffer,MAX_ATM_ADDR_LEN,
RTA_DATA(tb[TCA_ATM_ADDR]),A2T_PRETTY | A2T_NAME) <
0) fprintf(stderr,"atm2text error\n");
fprintf(f,"pvc %s ",buffer);
if (atm2text(buffer, MAX_ATM_ADDR_LEN,
RTA_DATA(tb[TCA_ATM_ADDR]), A2T_PRETTY | A2T_NAME) <
0) fprintf(stderr, "atm2text error\n");
fprintf(f, "pvc %s ", buffer);
}
}
if (tb[TCA_ATM_HDR]) {
int i;
const __u8 *hdr = RTA_DATA(tb[TCA_ATM_HDR]);
fprintf(f,"hdr");
fprintf(f, "hdr");
for (i = 0; i < RTA_PAYLOAD(tb[TCA_ATM_HDR]); i++)
fprintf(f,"%c%02x", i ? '.' : ' ', hdr[i]);
if (!i) fprintf(f," .");
fprintf(f," ");
fprintf(f, "%c%02x", i ? '.' : ' ', hdr[i]);
if (!i) fprintf(f, " .");
fprintf(f, " ");
}
if (tb[TCA_ATM_EXCESS]) {
__u32 excess;
if (RTA_PAYLOAD(tb[TCA_ATM_EXCESS]) < sizeof(excess))
fprintf(stderr,"ATM: excess class ID too short\n");
fprintf(stderr, "ATM: excess class ID too short\n");
else {
excess = rta_getattr_u32(tb[TCA_ATM_EXCESS]);
if (!excess) fprintf(f,"excess clp ");
if (!excess) fprintf(f, "excess clp ");
else {
char buf[64];
print_tc_classid(buf,sizeof(buf),excess);
fprintf(f,"excess %s ",buf);
print_tc_classid(buf, sizeof(buf), excess);
fprintf(f, "excess %s ", buf);
}
}
}
......@@ -239,10 +229,10 @@ static int atm_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
int state;
if (RTA_PAYLOAD(tb[TCA_ATM_STATE]) < sizeof(state))
fprintf(stderr,"ATM: state field too short\n");
fprintf(stderr, "ATM: state field too short\n");
else {
state = *(int *) RTA_DATA(tb[TCA_ATM_STATE]);
fprintf(f,"%s ",map[state]);
fprintf(f, "%s ", map[state]);
}
}
return 0;
......@@ -250,7 +240,7 @@ static int atm_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
struct qdisc_util atm_qdisc_util = {
.id = "atm",
.id = "atm",
.parse_qopt = atm_parse_opt,
.print_qopt = atm_print_opt,
.parse_copt = atm_parse_class_opt,
......
......@@ -52,11 +52,11 @@ static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
struct tc_ratespec r;
struct tc_cbq_lssopt lss;
__u32 rtab[256];
unsigned mpu=0, avpkt=0, allot=0;
unsigned short overhead=0;
unsigned mpu = 0, avpkt = 0, allot = 0;
unsigned short overhead = 0;
unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */
int cell_log=-1;
int ewma_log=-1;
int cell_log = -1;
int ewma_log = -1;
struct rtattr *tail;
memset(&lss, 0, sizeof(lss));
......@@ -81,17 +81,18 @@ static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
return -1;
}
} else if (matches(*argv, "cell") == 0) {
unsigned cell;
unsigned int cell;
int i;
NEXT_ARG();
if (get_size(&cell, *argv)) {
explain1("cell");
return -1;
}
for (i=0; i<32; i++)
for (i = 0; i < 32; i++)
if ((1<<i) == cell)
break;
if (i>=32) {
if (i >= 32) {
fprintf(stderr, "cell must be 2^n\n");
return -1;
}
......@@ -170,7 +171,8 @@ static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
addattr_l(n, 3024, TCA_CBQ_RTAB, rtab, 1024);
if (show_raw) {
int i;
for (i=0; i<256; i++)
for (i = 0; i < 256; i++)
printf("%u ", rtab[i]);
printf("\n");
}
......@@ -180,19 +182,19 @@ static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{
int wrr_ok=0, fopt_ok=0;
int wrr_ok = 0, fopt_ok = 0;
struct tc_ratespec r;
struct tc_cbq_lssopt lss;
struct tc_cbq_wrropt wrr;
struct tc_cbq_fopt fopt;
struct tc_cbq_ovl ovl;
__u32 rtab[256];
unsigned mpu=0;
int cell_log=-1;
int ewma_log=-1;
unsigned bndw = 0;
unsigned minburst=0, maxburst=0;
unsigned short overhead=0;
unsigned mpu = 0;
int cell_log = -1;
int ewma_log = -1;
unsigned int bndw = 0;
unsigned minburst = 0, maxburst = 0;
unsigned short overhead = 0;
unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */
struct rtattr *tail;
......@@ -260,23 +262,25 @@ static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, str
}
lss.change |= TCF_CBQ_LSS_EWMA;
} else if (matches(*argv, "cell") == 0) {
unsigned cell;
unsigned int cell;
int i;
NEXT_ARG();
if (get_size(&cell, *argv)) {
explain1("cell");
return -1;
}
for (i=0; i<32; i++)
for (i = 0; i < 32; i++)
if ((1<<i) == cell)
break;
if (i>=32) {
if (i >= 32) {
fprintf(stderr, "cell must be 2^n\n");
return -1;
}
cell_log = i;
} else if (matches(*argv, "prio") == 0) {
unsigned prio;
unsigned int prio;
NEXT_ARG();
if (get_u32(&prio, *argv, 0)) {
explain1("prio");
......@@ -323,6 +327,7 @@ static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, str
fopt_ok++;
} else if (matches(*argv, "defmap") == 0) {
int err;
NEXT_ARG();
err = sscanf(*argv, "%08x/%08x", &fopt.defmap, &fopt.defchange);
if (err < 1) {
......@@ -357,7 +362,8 @@ static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, str
/* 1. Prepare link sharing scheduler parameters */
if (r.rate) {
unsigned pktsize = wrr.allot;
unsigned int pktsize = wrr.allot;
if (wrr.allot < (lss.avpkt*3)/2)
wrr.allot = (lss.avpkt*3)/2;
r.mpu = mpu;
......@@ -375,7 +381,7 @@ static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, str
fprintf(stderr, "CBQ: avpkt is required for max/minburst.\n");
return -1;
}
if (bndw==0 || r.rate == 0) {
if (bndw == 0 || r.rate == 0) {
fprintf(stderr, "CBQ: bandwidth&rate are required for max/minburst.\n");
return -1;
}
......@@ -424,7 +430,8 @@ static int cbq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, str
addattr_l(n, 3024, TCA_CBQ_RTAB, rtab, 1024);
if (show_raw) {
int i;
for (i=0; i<256; i++)
for (i = 0; i < 256; i++)
printf("%u ", rtab[i]);
printf("\n");
}
......@@ -443,6 +450,7 @@ static int cbq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
struct tc_cbq_fopt *fopt = NULL;
struct tc_cbq_ovl *ovl = NULL;
unsigned int linklayer;
SPRINT_BUF(b1);
SPRINT_BUF(b2);
......@@ -478,14 +486,15 @@ static int cbq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
if (tb[TCA_CBQ_OVL_STRATEGY]) {
if (RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY]) < sizeof(*ovl))
fprintf(stderr, "CBQ: too short overlimit strategy %u/%u\n",
(unsigned) RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY]),
(unsigned) sizeof(*ovl));
(unsigned int) RTA_PAYLOAD(tb[TCA_CBQ_OVL_STRATEGY]),
(unsigned int) sizeof(*ovl));
else
ovl = RTA_DATA(tb[TCA_CBQ_OVL_STRATEGY]);
}
if (r) {
char buf[64];
print_rate(buf, sizeof(buf), r->rate);
fprintf(f, "rate %s ", buf);
linklayer = (r->linklayer & TC_LINKLAYER_MASK);
......@@ -500,11 +509,12 @@ static int cbq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
}
}
if (lss && lss->flags) {
int comma=0;
int comma = 0;
fprintf(f, "(");
if (lss->flags&TCF_CBQ_LSS_BOUNDED) {
fprintf(f, "bounded");
comma=1;
comma = 1;
}
if (lss->flags&TCF_CBQ_LSS_ISOLATED) {
if (comma)
......@@ -520,6 +530,7 @@ static int cbq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
fprintf(f, "prio no-transmit");
if (show_details) {
char buf[64];
fprintf(f, "/%u ", wrr->cpriority);
if (wrr->weight != 1) {
print_rate(buf, sizeof(buf), wrr->weight);
......@@ -536,7 +547,7 @@ static int cbq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
if (show_raw)
fprintf(f, "[%08x] ", lss->maxidle);
}
if (lss->minidle!=0x7fffffff) {
if (lss->minidle != 0x7fffffff) {
fprintf(f, "minidle %s ", sprint_ticks(lss->minidle>>lss->ewma_log, b1));
if (show_raw)
fprintf(f, "[%08x] ", lss->minidle);
......@@ -549,6 +560,7 @@ static int cbq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
}
if (fopt && show_details) {
char buf[64];
print_tc_classid(buf, sizeof(buf), fopt->split);
fprintf(f, "\nsplit %s ", buf);
if (fopt->defmap) {
......
......@@ -35,10 +35,10 @@ static int choke_parse_opt(struct qdisc_util *qu, int argc, char **argv,
struct nlmsghdr *n)
{
struct tc_red_qopt opt;
unsigned burst = 0;
unsigned avpkt = 1000;
unsigned int burst = 0;
unsigned int avpkt = 1000;
double probability = 0.02;
unsigned rate = 0;
unsigned int rate = 0;
int ecn_ok = 0;
int wlog;
__u8 sbuf[256];
......
......@@ -61,10 +61,10 @@ static void explain(void)
static int codel_parse_opt(struct qdisc_util *qu, int argc, char **argv,
struct nlmsghdr *n)
{
unsigned limit = 0;
unsigned target = 0;
unsigned interval = 0;
unsigned ce_threshold = ~0U;
unsigned int limit = 0;
unsigned int target = 0;
unsigned int interval = 0;
unsigned int ce_threshold = ~0U;
int ecn = -1;
struct rtattr *tail;
......@@ -129,11 +129,12 @@ static int codel_parse_opt(struct qdisc_util *qu, int argc, char **argv,
static int codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
struct rtattr *tb[TCA_CODEL_MAX + 1];
unsigned limit;
unsigned interval;
unsigned target;
unsigned ecn;
unsigned ce_threshold;
unsigned int limit;
unsigned int interval;
unsigned int target;
unsigned int ecn;
unsigned int ce_threshold;
SPRINT_BUF(b1);
if (opt == NULL)
......@@ -175,6 +176,7 @@ static int codel_print_xstats(struct qdisc_util *qu, FILE *f,
struct rtattr *xstats)
{
struct tc_codel_xstats _st, *st;
SPRINT_BUF(b1);
if (xstats == NULL)
......
......@@ -84,6 +84,7 @@ static int drr_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
static int drr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
struct rtattr *tb[TCA_DRR_MAX + 1];
SPRINT_BUF(b1);
if (opt == NULL)
......@@ -100,6 +101,7 @@ static int drr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
static int drr_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
{
struct tc_drr_stats *x;
SPRINT_BUF(b1);
if (xstats == NULL)
......
......@@ -21,8 +21,7 @@
static void explain(void)
{
fprintf(stderr,"Usage: dsmark indices INDICES [ default_index "
"DEFAULT_INDEX ] [ set_tc_index ]\n");
fprintf(stderr,"Usage: dsmark indices INDICES [ default_index DEFAULT_INDEX ] [ set_tc_index ]\n");
}
......@@ -32,32 +31,29 @@ static int dsmark_parse_opt(struct qdisc_util *qu, int argc, char **argv,
struct rtattr *tail;
__u16 ind;
char *end;
int dflt,set_tc_index;
int dflt, set_tc_index;
ind = set_tc_index = 0;
dflt = -1;
while (argc > 0) {
if (!strcmp(*argv,"indices")) {
if (!strcmp(*argv, "indices")) {
NEXT_ARG();
ind = strtoul(*argv,&end,0);
ind = strtoul(*argv, &end, 0);
if (*end) {
explain();
return -1;
}
}
else if (!strcmp(*argv,"default_index") || !strcmp(*argv,
} else if (!strcmp(*argv,"default_index") || !strcmp(*argv,
"default")) {
NEXT_ARG();
dflt = strtoul(*argv,&end,0);
dflt = strtoul(*argv, &end, 0);
if (*end) {
explain();
return -1;
}
}
else if (!strcmp(*argv,"set_tc_index")) {
} else if (!strcmp(*argv,"set_tc_index")) {
set_tc_index = 1;
}
else {
} else {
explain();
return -1;
}
......@@ -69,14 +65,14 @@ static int dsmark_parse_opt(struct qdisc_util *qu, int argc, char **argv,
return -1;
}
tail = NLMSG_TAIL(n);
addattr_l(n,1024,TCA_OPTIONS,NULL,0);
addattr_l(n,1024,TCA_DSMARK_INDICES,&ind,sizeof(ind));
addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
addattr_l(n, 1024, TCA_DSMARK_INDICES, &ind, sizeof(ind));
if (dflt != -1) {
__u16 tmp = dflt;
addattr_l(n,1024,TCA_DSMARK_DEFAULT_INDEX,&tmp,sizeof(tmp));
addattr_l(n, 1024, TCA_DSMARK_DEFAULT_INDEX, &tmp, sizeof(tmp));
}
if (set_tc_index) addattr_l(n,1024,TCA_DSMARK_SET_TC_INDEX,NULL,0);
if (set_tc_index) addattr_l(n, 1024, TCA_DSMARK_SET_TC_INDEX, NULL, 0);
tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
return 0;
}
......@@ -96,27 +92,25 @@ static int dsmark_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
char *end;
tail = NLMSG_TAIL(n);
addattr_l(n,1024,TCA_OPTIONS,NULL,0);
addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
while (argc > 0) {
if (!strcmp(*argv,"mask")) {
if (!strcmp(*argv, "mask")) {
NEXT_ARG();
tmp = strtoul(*argv,&end,0);
tmp = strtoul(*argv, &end, 0);
if (*end) {
explain_class();
return -1;
}
addattr_l(n,1024,TCA_DSMARK_MASK,&tmp,1);
}
else if (!strcmp(*argv,"value")) {
addattr_l(n, 1024, TCA_DSMARK_MASK, &tmp, 1);
} else if (!strcmp(*argv,"value")) {
NEXT_ARG();
tmp = strtoul(*argv,&end,0);
tmp = strtoul(*argv, &end, 0);
if (*end) {
explain_class();
return -1;
}
addattr_l(n,1024,TCA_DSMARK_VALUE,&tmp,1);
}
else {
addattr_l(n, 1024, TCA_DSMARK_VALUE, &tmp, 1);
} else {
explain_class();
return -1;
}
......@@ -138,29 +132,29 @@ static int dsmark_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
parse_rtattr(tb, TCA_DSMARK_MAX, RTA_DATA(opt), RTA_PAYLOAD(opt));
if (tb[TCA_DSMARK_MASK]) {
if (!RTA_PAYLOAD(tb[TCA_DSMARK_MASK]))
fprintf(stderr,"dsmark: empty mask\n");
else fprintf(f,"mask 0x%02x ",
fprintf(stderr, "dsmark: empty mask\n");
else fprintf(f, "mask 0x%02x ",
rta_getattr_u8(tb[TCA_DSMARK_MASK]));
}
if (tb[TCA_DSMARK_VALUE]) {
if (!RTA_PAYLOAD(tb[TCA_DSMARK_VALUE]))
fprintf(stderr,"dsmark: empty value\n");
else fprintf(f,"value 0x%02x ",
fprintf(stderr, "dsmark: empty value\n");
else fprintf(f, "value 0x%02x ",
rta_getattr_u8(tb[TCA_DSMARK_VALUE]));
}
if (tb[TCA_DSMARK_INDICES]) {
if (RTA_PAYLOAD(tb[TCA_DSMARK_INDICES]) < sizeof(__u16))
fprintf(stderr,"dsmark: indices too short\n");
else fprintf(f,"indices 0x%04x ",
fprintf(stderr, "dsmark: indices too short\n");
else fprintf(f, "indices 0x%04x ",
rta_getattr_u16(tb[TCA_DSMARK_INDICES]));
}
if (tb[TCA_DSMARK_DEFAULT_INDEX]) {
if (RTA_PAYLOAD(tb[TCA_DSMARK_DEFAULT_INDEX]) < sizeof(__u16))
fprintf(stderr,"dsmark: default_index too short\n");
else fprintf(f,"default_index 0x%04x ",
fprintf(stderr, "dsmark: default_index too short\n");
else fprintf(f, "default_index 0x%04x ",
rta_getattr_u16(tb[TCA_DSMARK_DEFAULT_INDEX]));
}
if (tb[TCA_DSMARK_SET_TC_INDEX]) fprintf(f,"set_tc_index ");
if (tb[TCA_DSMARK_SET_TC_INDEX]) fprintf(f, "set_tc_index ");
return 0;
}
......
......@@ -30,8 +30,9 @@ static void explain(void)
static int fifo_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{
int ok=0;
int ok = 0;
struct tc_fifo_qopt opt;
memset(&opt, 0, sizeof(opt));
while (argc > 0) {
......
......@@ -218,6 +218,7 @@ static int fq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
unsigned int rate, quantum;
unsigned int refill_delay;
unsigned int orphan_mask;
SPRINT_BUF(b1);
if (opt == NULL)
......
......@@ -59,12 +59,12 @@ static void explain(void)
static int fq_codel_parse_opt(struct qdisc_util *qu, int argc, char **argv,
struct nlmsghdr *n)
{
unsigned limit = 0;
unsigned flows = 0;
unsigned target = 0;
unsigned interval = 0;
unsigned quantum = 0;
unsigned ce_threshold = ~0U;
unsigned int limit = 0;
unsigned int flows = 0;
unsigned int target = 0;
unsigned int interval = 0;
unsigned int quantum = 0;
unsigned int ce_threshold = ~0U;
int ecn = -1;
struct rtattr *tail;
......@@ -144,13 +144,14 @@ static int fq_codel_parse_opt(struct qdisc_util *qu, int argc, char **argv,
static int fq_codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
struct rtattr *tb[TCA_FQ_CODEL_MAX + 1];
unsigned limit;
unsigned flows;
unsigned interval;
unsigned target;
unsigned ecn;
unsigned quantum;
unsigned ce_threshold;
unsigned int limit;
unsigned int flows;
unsigned int interval;
unsigned int target;
unsigned int ecn;
unsigned int quantum;
unsigned int ce_threshold;
SPRINT_BUF(b1);
if (opt == NULL)
......@@ -202,6 +203,7 @@ static int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f,
struct rtattr *xstats)
{
struct tc_fq_codel_xstats _st, *st;
SPRINT_BUF(b1);
if (xstats == NULL)
......
......@@ -30,9 +30,9 @@
#if 0
#define DPRINTF(format,args...) fprintf(stderr,format,##args)
#define DPRINTF(format, args...) fprintf(stderr, format, ##args)
#else
#define DPRINTF(format,args...)
#define DPRINTF(format, args...)
#endif
static void explain(void)
......@@ -55,7 +55,7 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv,
opt.def_DP = MAX_DPs;
while (argc > 0) {
DPRINTF(stderr,"init_gred: invoked with %s\n",*argv);
DPRINTF(stderr, "init_gred: invoked with %s\n", *argv);
if (strcmp(*argv, "vqs") == 0 ||
strcmp(*argv, "DPs") == 0) {
NEXT_ARG();
......@@ -63,14 +63,13 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv,
fprintf(stderr, "Illegal \"vqs\"\n");
return -1;
} else if (opt.DPs > MAX_DPs) {
fprintf(stderr, "GRED: only %u VQs are "
"currently supported\n", MAX_DPs);
fprintf(stderr, "GRED: only %u VQs are currently supported\n",
MAX_DPs);
return -1;
}
} else if (strcmp(*argv, "default") == 0) {
if (opt.DPs == 0) {
fprintf(stderr, "\"default\" must be defined "
"after \"vqs\"\n");
fprintf(stderr, "\"default\" must be defined after \"vqs\"\n");
return -1;
}
NEXT_ARG();
......@@ -78,8 +77,7 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv,
fprintf(stderr, "Illegal \"default\"\n");
return -1;
} else if (opt.def_DP >= opt.DPs) {
fprintf(stderr, "\"default\" must be less than "
"\"vqs\"\n");
fprintf(stderr, "\"default\" must be less than \"vqs\"\n");
return -1;
}
} else if (strcmp(*argv, "grio") == 0) {
......@@ -102,12 +100,12 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv,
}
if (!opt.DPs || opt.def_DP == MAX_DPs) {
fprintf(stderr, "Illegal gred setup parameters \n");
fprintf(stderr, "Illegal gred setup parameters\n");
return -1;
}
DPRINTF("TC_GRED: sending DPs=%u def_DP=%u\n",opt.DPs,opt.def_DP);
n->nlmsg_flags|=NLM_F_CREATE;
DPRINTF("TC_GRED: sending DPs=%u def_DP=%u\n", opt.DPs, opt.def_DP);
n->nlmsg_flags |= NLM_F_CREATE;
tail = NLMSG_TAIL(n);
addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
addattr_l(n, 1024, TCA_GRED_DPS, &opt, sizeof(struct tc_gred_sopt));
......@@ -121,12 +119,12 @@ static int init_gred(struct qdisc_util *qu, int argc, char **argv,
*/
static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{
int ok=0;
int ok = 0;
struct tc_gred_qopt opt = { 0 };
unsigned burst = 0;
unsigned avpkt = 0;
unsigned int burst = 0;
unsigned int avpkt = 0;
double probability = 0.02;
unsigned rate = 0;
unsigned int rate = 0;
int parm;
__u8 sbuf[256];
struct rtattr *tail;
......@@ -169,8 +167,8 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
fprintf(stderr, "Illegal \"vq\"\n");
return -1;
} else if (opt.DP >= MAX_DPs) {
fprintf(stderr, "GRED: only %u VQs are "
"currently supported\n", MAX_DPs);
fprintf(stderr, "GRED: only %u VQs are currently supported\n",
MAX_DPs);
return -1;
} /* need a better error check */
ok++;
......@@ -197,7 +195,7 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
ok++;
} else if (strcmp(*argv, "prio") == 0) {
NEXT_ARG();
opt.prio=strtol(*argv, (char **)NULL, 10);
opt.prio = strtol(*argv, (char **)NULL, 10);
/* some error check here */
ok++;
} else if (strcmp(*argv, "bandwidth") == 0) {
......@@ -224,8 +222,7 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
}
if (opt.DP == MAX_DPs || !opt.limit || !opt.qth_min || !opt.qth_max ||
!avpkt) {
fprintf(stderr, "Required parameter (vq, limit, min, max, "
"avpkt) is missing\n");
fprintf(stderr, "Required parameter (vq, limit, min, max, avpkt) is missing\n");
return -1;
}
if (!burst) {
......@@ -241,8 +238,8 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
return -1;
}
if (parm >= 10)
fprintf(stderr, "GRED: WARNING. Burst %u seems to be too "
"large.\n", burst);
fprintf(stderr, "GRED: WARNING. Burst %u seems to be too large.\n",
burst);
opt.Wlog = parm;
if ((parm = tc_red_eval_P(opt.qth_min, opt.qth_max, probability)) < 0) {
fprintf(stderr, "GRED: failed to calculate probability.\n");
......@@ -251,8 +248,7 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
opt.Plog = parm;
if ((parm = tc_red_eval_idle_damping(opt.Wlog, avpkt, rate, sbuf)) < 0)
{
fprintf(stderr, "GRED: failed to calculate idle damping "
"table.\n");
fprintf(stderr, "GRED: failed to calculate idle damping table.\n");
return -1;
}
opt.Scell_log = parm;
......@@ -274,7 +270,8 @@ static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
struct tc_gred_qopt *qopt;
__u32 *max_p = NULL;
__u32 *limit = NULL;
unsigned i;
unsigned int i;
SPRINT_BUF(b1);
SPRINT_BUF(b2);
SPRINT_BUF(b3);
......@@ -299,7 +296,7 @@ static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
qopt = RTA_DATA(tb[TCA_GRED_PARMS]);
if (RTA_PAYLOAD(tb[TCA_GRED_DPS]) < sizeof(*sopt) ||
RTA_PAYLOAD(tb[TCA_GRED_PARMS]) < sizeof(*qopt)*MAX_DPs) {
fprintf(f,"\n GRED received message smaller than expected\n");
fprintf(f, "\n GRED received message smaller than expected\n");
return -1;
}
......@@ -314,7 +311,7 @@ static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
fprintf(f, "limit %s ",
sprint_size(*limit, b1));
for (i=0;i<MAX_DPs;i++, qopt++) {
for (i = 0; i < MAX_DPs; i++, qopt++) {
if (qopt->DP >= MAX_DPs) continue;
fprintf(f, "\n vq %u prio %hhu limit %s min %s max %s ",
qopt->DP,
......
......@@ -144,7 +144,7 @@ hfsc_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
static int
hfsc_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
struct nlmsghdr *n)
struct nlmsghdr *n)
{
struct tc_service_curve rsc, fsc, usc;
int rsc_ok, fsc_ok, usc_ok;
......@@ -203,8 +203,7 @@ hfsc_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
return -1;
}
if (usc_ok && !fsc_ok) {
fprintf(stderr, "HFSC: Upper-limit Service Curve without "
"Link-Share Service Curve\n");
fprintf(stderr, "HFSC: Upper-limit Service Curve without Link-Share Service Curve\n");
explain_class();
return -1;
}
......
......@@ -28,13 +28,13 @@ static void explain(void)
static int hhf_parse_opt(struct qdisc_util *qu, int argc, char **argv,
struct nlmsghdr *n)
{
unsigned limit = 0;
unsigned quantum = 0;
unsigned hh_limit = 0;
unsigned reset_timeout = 0;
unsigned admit_bytes = 0;
unsigned evict_timeout = 0;
unsigned non_hh_weight = 0;
unsigned int limit = 0;
unsigned int quantum = 0;
unsigned int hh_limit = 0;
unsigned int reset_timeout = 0;
unsigned int admit_bytes = 0;
unsigned int evict_timeout = 0;
unsigned int non_hh_weight = 0;
struct rtattr *tail;
while (argc > 0) {
......@@ -120,13 +120,14 @@ static int hhf_parse_opt(struct qdisc_util *qu, int argc, char **argv,
static int hhf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
struct rtattr *tb[TCA_HHF_MAX + 1];
unsigned limit;
unsigned quantum;
unsigned hh_limit;
unsigned reset_timeout;
unsigned admit_bytes;
unsigned evict_timeout;
unsigned non_hh_weight;
unsigned int limit;
unsigned int quantum;
unsigned int hh_limit;
unsigned int reset_timeout;
unsigned int admit_bytes;
unsigned int evict_timeout;
unsigned int non_hh_weight;
SPRINT_BUF(b1);
if (opt == NULL)
......
......@@ -49,7 +49,7 @@ static void explain(void)
" mtu max packet size we create rate map for {1600}\n"
" prio priority of leaf; lower are served first {0}\n"
" quantum how much bytes to serve from leaf at once {use r2q}\n"
"\nTC HTB version %d.%d\n",HTB_TC_VER>>16,HTB_TC_VER&0xffff
"\nTC HTB version %d.%d\n", HTB_TC_VER>>16, HTB_TC_VER&0xffff
);
}
......@@ -65,8 +65,9 @@ static int htb_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
unsigned int direct_qlen = ~0U;
struct tc_htb_glob opt;
struct rtattr *tail;
unsigned i; char *p;
memset(&opt,0,sizeof(opt));
unsigned int i; char *p;
memset(&opt, 0, sizeof(opt));
opt.rate2quantum = 10;
opt.version = 3;
......@@ -83,8 +84,8 @@ static int htb_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
}
} else if (matches(*argv, "debug") == 0) {
NEXT_ARG(); p = *argv;
for (i=0; i<16; i++,p++) {
if (*p<'0' || *p>'3') break;
for (i = 0; i < 16; i++, p++) {
if (*p < '0' || *p > '3') break;
opt.debug |= (*p-'0')<<(2*i);
}
} else if (matches(*argv, "direct_qlen") == 0) {
......@@ -111,12 +112,12 @@ static int htb_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
static int htb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{
int ok=0;
int ok = 0;
struct tc_htb_opt opt;
__u32 rtab[256],ctab[256];
unsigned buffer=0,cbuffer=0;
int cell_log=-1,ccell_log = -1;
unsigned mtu;
__u32 rtab[256], ctab[256];
unsigned buffer = 0, cbuffer = 0;
int cell_log = -1, ccell_log = -1;
unsigned int mtu;
unsigned short mpu = 0;
unsigned short overhead = 0;
unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */
......@@ -268,9 +269,10 @@ static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
struct rtattr *tb[TCA_HTB_MAX + 1];
struct tc_htb_opt *hopt;
struct tc_htb_glob *gopt;
double buffer,cbuffer;
double buffer, cbuffer;
unsigned int linklayer;
__u64 rate64, ceil64;
SPRINT_BUF(b1);
SPRINT_BUF(b2);
SPRINT_BUF(b3);
......@@ -327,16 +329,16 @@ static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
}
if (show_raw)
fprintf(f, "buffer [%08x] cbuffer [%08x] ",
hopt->buffer,hopt->cbuffer);
hopt->buffer, hopt->cbuffer);
}
if (tb[TCA_HTB_INIT]) {
gopt = RTA_DATA(tb[TCA_HTB_INIT]);
if (RTA_PAYLOAD(tb[TCA_HTB_INIT]) < sizeof(*gopt)) return -1;
fprintf(f, "r2q %d default %x direct_packets_stat %u",
gopt->rate2quantum,gopt->defcls,gopt->direct_pkts);
gopt->rate2quantum, gopt->defcls, gopt->direct_pkts);
if (show_details)
fprintf(f," ver %d.%d",gopt->version >> 16,gopt->version & 0xffff);
fprintf(f, " ver %d.%d", gopt->version >> 16, gopt->version & 0xffff);
}
if (tb[TCA_HTB_DIRECT_QLEN] &&
RTA_PAYLOAD(tb[TCA_HTB_DIRECT_QLEN]) >= sizeof(__u32)) {
......@@ -350,6 +352,7 @@ static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
static int htb_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
{
struct tc_htb_xstats *st;
if (xstats == NULL)
return 0;
......@@ -358,16 +361,16 @@ static int htb_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstat
st = RTA_DATA(xstats);
fprintf(f, " lended: %u borrowed: %u giants: %u\n",
st->lends,st->borrows,st->giants);
fprintf(f, " tokens: %d ctokens: %d\n", st->tokens,st->ctokens);
st->lends, st->borrows, st->giants);
fprintf(f, " tokens: %d ctokens: %d\n", st->tokens, st->ctokens);
return 0;
}
struct qdisc_util htb_qdisc_util = {
.id = "htb",
.id = "htb",
.parse_qopt = htb_parse_opt,
.print_qopt = htb_print_opt,
.print_xstats = htb_print_xstats,
.print_xstats = htb_print_xstats,
.parse_copt = htb_parse_class_opt,
.print_copt = htb_print_opt,
};
......@@ -77,7 +77,7 @@ static int multiq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
}
struct qdisc_util multiq_qdisc_util = {
.id = "multiq",
.id = "multiq",
.parse_qopt = multiq_parse_opt,
.print_qopt = multiq_print_opt,
};
......@@ -30,10 +30,10 @@
static void explain(void)
{
fprintf(stderr,
"Usage: ... netem [ limit PACKETS ] \n" \
"Usage: ... netem [ limit PACKETS ]\n" \
" [ delay TIME [ JITTER [CORRELATION]]]\n" \
" [ distribution {uniform|normal|pareto|paretonormal} ]\n" \
" [ corrupt PERCENT [CORRELATION]] \n" \
" [ corrupt PERCENT [CORRELATION]]\n" \
" [ duplicate PERCENT [CORRELATION]]\n" \
" [ loss random PERCENT [CORRELATION]]\n" \
" [ loss state P13 [P31 [P32 [P23 P14]]]\n" \
......@@ -58,7 +58,7 @@ static const double max_percent_value = 0xffffffff;
/* scaled value used to percent of maximum. */
static void set_percent(__u32 *percent, double per)
{
*percent = (unsigned) rint(per * max_percent_value);
*percent = (unsigned int) rint(per * max_percent_value);
}
......@@ -70,7 +70,7 @@ static int parse_percent(double *val, const char *str)
char *p;
*val = strtod(str, &p) / 100.;
if (*p && strcmp(p, "%") )
if (*p && strcmp(p, "%"))
return -1;
return 0;
......@@ -92,7 +92,7 @@ static void print_percent(char *buf, int len, __u32 per)
snprintf(buf, len, "%g%%", 100. * (double) per / max_percent_value);
}
static char * sprint_percent(__u32 per, char *buf)
static char *sprint_percent(__u32 per, char *buf)
{
print_percent(buf, SPRINT_BSIZE-1, per);
return buf;
......@@ -123,6 +123,7 @@ static int get_distribution(const char *type, __s16 *data, int maxdata)
n = 0;
while (getline(&line, &len, f) != -1) {
char *p, *endp;
if (*line == '\n' || *line == '#')
continue;
......@@ -154,9 +155,9 @@ static int get_distribution(const char *type, __s16 *data, int maxdata)
(based on kernel PSCHED_CLOCK configuration */
static int get_ticks(__u32 *ticks, const char *str)
{
unsigned t;
unsigned int t;
if(get_time(&t, str))
if (get_time(&t, str))
return -1;
if (tc_core_time2big(t)) {
......@@ -191,7 +192,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
memset(&rate, 0, sizeof(rate));
memset(present, 0, sizeof(present));
for( ; argc > 0; --argc, ++argv) {
for ( ; argc > 0; --argc, ++argv) {
if (matches(*argv, "limit") == 0) {
NEXT_ARG();
if (get_size(&opt.limit, *argv)) {
......@@ -236,7 +237,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
if (!strcmp(*argv, "random")) {
NEXT_ARG();
random_loss_model:
random_loss_model:
if (get_percent(&opt.loss, *argv)) {
explain1("loss percent");
return -1;
......@@ -545,6 +546,7 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
const struct tc_netem_rate *rate = NULL;
int len = RTA_PAYLOAD(opt) - sizeof(qopt);
__u64 rate64 = 0;
SPRINT_BUF(b1);
if (opt == NULL)
......@@ -558,6 +560,7 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
if (len > 0) {
struct rtattr *tb[TCA_NETEM_MAX+1];
parse_rtattr(tb, TCA_NETEM_MAX, RTA_DATA(opt) + sizeof(qopt),
len);
......@@ -684,7 +687,7 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
}
struct qdisc_util netem_qdisc_util = {
.id = "netem",
.id = "netem",
.parse_qopt = netem_parse_opt,
.print_qopt = netem_print_opt,
};
......@@ -136,8 +136,9 @@ static int pie_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
unsigned int target;
unsigned int alpha;
unsigned int beta;
unsigned ecn;
unsigned bytemode;
unsigned int ecn;
unsigned int bytemode;
SPRINT_BUF(b1);
if (opt == NULL)
......
......@@ -32,7 +32,7 @@ static int prio_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
{
int pmap_mode = 0;
int idx = 0;
struct tc_prio_qopt opt={3,{ 1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 }};
struct tc_prio_qopt opt = {3, { 1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 } };
struct rtattr *nest;
unsigned char mq = 0;
......@@ -57,7 +57,8 @@ static int prio_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
explain();
return -1;
} else {
unsigned band;
unsigned int band;
if (!pmap_mode) {
fprintf(stderr, "What is \"%s\"?\n", *argv);
explain();
......@@ -104,10 +105,10 @@ int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
if (parse_rtattr_nested_compat(tb, TCA_PRIO_MAX, opt, qopt,
sizeof(*qopt)))
return -1;
return -1;
fprintf(f, "bands %u priomap ", qopt->bands);
for (i=0; i<=TC_PRIO_MAX; i++)
for (i = 0; i <= TC_PRIO_MAX; i++)
fprintf(f, " %d", qopt->priomap[i]);
if (tb[TCA_PRIO_MQ])
......@@ -118,7 +119,7 @@ int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
}
struct qdisc_util prio_qdisc_util = {
.id = "prio",
.id = "prio",
.parse_qopt = prio_parse_opt,
.print_qopt = prio_print_opt,
};
......@@ -36,10 +36,10 @@ static void explain(void)
static int red_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{
struct tc_red_qopt opt;
unsigned burst = 0;
unsigned avpkt = 0;
unsigned int burst = 0;
unsigned int avpkt = 0;
double probability = 0.02;
unsigned rate = 0;
unsigned int rate = 0;
int parm;
__u8 sbuf[256];
__u32 max_P;
......@@ -160,6 +160,7 @@ static int red_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
struct rtattr *tb[TCA_RED_MAX + 1];
struct tc_red_qopt *qopt;
__u32 max_P = 0;
SPRINT_BUF(b1);
SPRINT_BUF(b2);
SPRINT_BUF(b3);
......
......@@ -33,7 +33,7 @@ static int rr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlm
{
int pmap_mode = 0;
int idx = 0;
struct tc_prio_qopt opt={3,{ 1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 }};
struct tc_prio_qopt opt = {3, { 1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 } };
struct rtattr *nest;
unsigned char mq = 0;
......@@ -58,7 +58,8 @@ static int rr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlm
} else if (strcmp(*argv, "multiqueue") == 0) {
mq = 1;
} else {
unsigned band;
unsigned int band;
if (!pmap_mode) {
fprintf(stderr, "What is \"%s\"?\n", *argv);
explain();
......@@ -102,7 +103,7 @@ static int rr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
return -1;
fprintf(f, "bands %u priomap ", qopt->bands);
for (i=0; i <= TC_PRIO_MAX; i++)
for (i = 0; i <= TC_PRIO_MAX; i++)
fprintf(f, " %d", qopt->priomap[i]);
if (tb[TCA_PRIO_MQ])
......@@ -113,7 +114,7 @@ static int rr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
}
struct qdisc_util rr_qdisc_util = {
.id = "rr",
.id = "rr",
.parse_qopt = rr_parse_opt,
.print_qopt = rr_print_opt,
};
......@@ -158,8 +158,7 @@ static int sfb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
fprintf(f,
"limit %d max %d target %d\n"
" increment %.5f decrement %.5f penalty rate %d burst %d "
"(%ums %ums)",
" increment %.5f decrement %.5f penalty rate %d burst %d (%ums %ums)",
qopt->limit, qopt->max, qopt->bin_size,
(double)qopt->increment / SFB_MAX_PROB,
(double)qopt->decrement / SFB_MAX_PROB,
......
......@@ -207,6 +207,7 @@ static int sfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
struct tc_sfq_qopt *qopt;
struct tc_sfq_qopt_v1 *qopt_ext = NULL;
SPRINT_BUF(b1);
SPRINT_BUF(b2);
SPRINT_BUF(b3);
......
......@@ -38,13 +38,13 @@ static void explain1(const char *arg, const char *val)
static int tbf_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{
int ok=0;
int ok = 0;
struct tc_tbf_qopt opt;
__u32 rtab[256];
__u32 ptab[256];
unsigned buffer=0, mtu=0, mpu=0, latency=0;
int Rcell_log=-1, Pcell_log = -1;
unsigned short overhead=0;
unsigned buffer = 0, mtu = 0, mpu = 0, latency = 0;
int Rcell_log = -1, Pcell_log = -1;
unsigned short overhead = 0;
unsigned int linklayer = LINKLAYER_ETHERNET; /* Assume ethernet */
struct rtattr *tail;
__u64 rate64 = 0, prate64 = 0;
......@@ -86,6 +86,7 @@ static int tbf_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
strcmp(*argv, "buffer") == 0 ||
strcmp(*argv, "maxburst") == 0) {
const char *parm_name = *argv;
NEXT_ARG();
if (buffer) {
fprintf(stderr, "tbf: duplicate \"buffer/burst/maxburst\" specification\n");
......@@ -99,6 +100,7 @@ static int tbf_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
} else if (strcmp(*argv, "mtu") == 0 ||
strcmp(*argv, "minburst") == 0) {
const char *parm_name = *argv;
NEXT_ARG();
if (mtu) {
fprintf(stderr, "tbf: duplicate \"mtu/minburst\" specification\n");
......@@ -167,12 +169,12 @@ static int tbf_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
argc--; argv++;
}
int verdict = 0;
int verdict = 0;
/* Be nice to the user: try to emit all error messages in
* one go rather than reveal one more problem when a
* previous one has been fixed.
*/
/* Be nice to the user: try to emit all error messages in
* one go rather than reveal one more problem when a
* previous one has been fixed.
*/
if (rate64 == 0) {
fprintf(stderr, "tbf: the \"rate\" parameter is mandatory.\n");
verdict = -1;
......@@ -193,18 +195,20 @@ static int tbf_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
verdict = -1;
}
if (verdict != 0) {
explain();
return verdict;
}
if (verdict != 0) {
explain();
return verdict;
}
opt.rate.rate = (rate64 >= (1ULL << 32)) ? ~0U : rate64;
opt.peakrate.rate = (prate64 >= (1ULL << 32)) ? ~0U : prate64;
if (opt.limit == 0) {
double lim = rate64*(double)latency/TIME_UNITS_PER_SEC + buffer;
if (prate64) {
double lim2 = prate64*(double)latency/TIME_UNITS_PER_SEC + mtu;
if (lim2 < lim)
lim = lim2;
}
......@@ -254,6 +258,7 @@ static int tbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
double buffer, mtu;
double latency;
__u64 rate64 = 0, prate64 = 0;
SPRINT_BUF(b1);
SPRINT_BUF(b2);
SPRINT_BUF(b3);
......@@ -305,6 +310,7 @@ static int tbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
latency = TIME_UNITS_PER_SEC*(qopt->limit/(double)rate64) - tc_core_tick2time(qopt->buffer);
if (prate64) {
double lat2 = TIME_UNITS_PER_SEC*(qopt->limit/(double)prate64) - tc_core_tick2time(qopt->mtu);
if (lat2 > latency)
latency = lat2;
}
......
......@@ -31,33 +31,33 @@
#include "tc_common.h"
#include "namespace.h"
int show_stats = 0;
int show_details = 0;
int show_raw = 0;
int show_pretty = 0;
int show_graph = 0;
int show_stats;
int show_details;
int show_raw;
int show_pretty;
int show_graph;
int timestamp;
int batch_mode = 0;
int resolve_hosts = 0;
int use_iec = 0;
int force = 0;
bool use_names = false;
int batch_mode;
int resolve_hosts;
int use_iec;
int force;
bool use_names;
static char *conf_file;
struct rtnl_handle rth;
static void *BODY = NULL; /* cached handle dlopen(NULL) */
static struct qdisc_util * qdisc_list;
static struct filter_util * filter_list;
static void *BODY; /* cached handle dlopen(NULL) */
static struct qdisc_util *qdisc_list;
static struct filter_util *filter_list;
static int print_noqopt(struct qdisc_util *qu, FILE *f,
struct rtattr *opt)
{
if (opt && RTA_PAYLOAD(opt))
fprintf(f, "[Unknown qdisc, optlen=%u] ",
(unsigned) RTA_PAYLOAD(opt));
(unsigned int) RTA_PAYLOAD(opt));
return 0;
}
......@@ -74,7 +74,7 @@ static int print_nofopt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u
{
if (opt && RTA_PAYLOAD(opt))
fprintf(f, "fh %08x [Unknown filter, optlen=%u] ",
fhandle, (unsigned) RTA_PAYLOAD(opt));
fhandle, (unsigned int) RTA_PAYLOAD(opt));
else if (fhandle)
fprintf(f, "fh %08x ", fhandle);
return 0;
......@@ -90,6 +90,7 @@ static int parse_nofopt(struct filter_util *qu, char *fhandle, int argc, char **
}
if (fhandle) {
struct tcmsg *t = NLMSG_DATA(n);
if (get_u32(&handle, fhandle, 16)) {
fprintf(stderr, "Unparsable filter ID \"%s\"\n", fhandle);
return -1;
......@@ -191,9 +192,8 @@ static void usage(void)
{
fprintf(stderr, "Usage: tc [ OPTIONS ] OBJECT { COMMAND | help }\n"
" tc [-force] -batch filename\n"
"where OBJECT := { qdisc | class | filter | action | monitor | exec }\n"
" OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] | "
"-n[etns] name |\n"
"where OBJECT := { qdisc | class | filter | action | monitor | exec }\n"
" OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] | -n[etns] name |\n"
" -nm | -nam[es] | { -cf | -conf } path }\n");
}
......
......@@ -167,8 +167,7 @@ static int bpf_ops_parse(int argc, char **argv, struct sock_filter *bpf_ops,
token = bpf_string;
while ((token = strchr(token, separator)) && (++token)[0]) {
if (i >= bpf_len) {
fprintf(stderr, "Real program length exceeds encoded "
"length parameter!\n");
fprintf(stderr, "Real program length exceeds encoded length parameter!\n");
ret = -EINVAL;
goto out;
}
......@@ -185,8 +184,7 @@ static int bpf_ops_parse(int argc, char **argv, struct sock_filter *bpf_ops,
}
if (i != bpf_len) {
fprintf(stderr, "Parsed program length is less than encoded"
"length parameter!\n");
fprintf(stderr, "Parsed program length is less than encodedlength parameter!\n");
ret = -EINVAL;
goto out;
}
......@@ -385,7 +383,7 @@ int bpf_trace_pipe(void)
static const char *bpf_get_tc_dir(void)
{
static bool bpf_mnt_cached = false;
static bool bpf_mnt_cached;
static char bpf_tc_dir[PATH_MAX];
static const char *mnt;
static const char * const bpf_known_mnts[] = {
......@@ -648,8 +646,7 @@ int bpf_graft_map(const char *map_path, uint32_t *key, int argc, char **argv)
} else {
ret = sscanf(section, "%*i/%i", &map_key);
if (ret != 1) {
fprintf(stderr, "Couldn\'t infer map key from section "
"name! Please provide \'key\' argument!\n");
fprintf(stderr, "Couldn\'t infer map key from section name! Please provide \'key\' argument!\n");
ret = -EINVAL;
goto out_prog;
}
......@@ -855,7 +852,7 @@ static int bpf_obj_hash(const char *object, uint8_t *out, size_t len)
goto out_ofd;
}
ret = fstat(ffd, &stbuff);
ret = fstat(ffd, &stbuff);
if (ret < 0) {
fprintf(stderr, "Error doing fstat: %s\n",
strerror(errno));
......@@ -889,7 +886,7 @@ out_cfd:
static const char *bpf_get_obj_uid(const char *pathname)
{
static bool bpf_uid_cached = false;
static bool bpf_uid_cached;
static char bpf_uid[64];
uint8_t tmp[20];
int ret;
......@@ -920,8 +917,7 @@ static int bpf_init_env(const char *pathname)
setrlimit(RLIMIT_MEMLOCK, &limit);
if (!bpf_get_tc_dir()) {
fprintf(stderr, "Continuing without mounted eBPF fs. "
"Too old kernel?\n");
fprintf(stderr, "Continuing without mounted eBPF fs. Too old kernel?\n");
return 0;
}
......@@ -1091,8 +1087,7 @@ retry:
if (tries++ < 6 && !bpf_log_realloc(ctx))
goto retry;
fprintf(stderr, "Log buffer too small to dump "
"verifier log %zu bytes (%d tries)!\n",
fprintf(stderr, "Log buffer too small to dump verifier log %zu bytes (%d tries)!\n",
ctx->log_size, tries);
return fd;
}
......@@ -1311,8 +1306,8 @@ static int bpf_fetch_ancillary(struct bpf_elf_ctx *ctx)
!strcmp(data.sec_name, ".strtab"))
ret = bpf_fetch_strtab(ctx, i, &data);
if (ret < 0) {
fprintf(stderr, "Error parsing section %d! Perhaps"
"check with readelf -a?\n", i);
fprintf(stderr, "Error parsing section %d! Perhapscheck with readelf -a?\n",
i);
break;
}
}
......@@ -1383,21 +1378,18 @@ static int bpf_apply_relo_data(struct bpf_elf_ctx *ctx,
ioff = relo.r_offset / sizeof(struct bpf_insn);
if (ioff >= num_insns ||
insns[ioff].code != (BPF_LD | BPF_IMM | BPF_DW)) {
fprintf(stderr, "ELF contains relo data for non ld64 "
"instruction at offset %u! Compiler bug?!\n",
fprintf(stderr, "ELF contains relo data for non ld64 instruction at offset %u! Compiler bug?!\n",
ioff);
if (ioff < num_insns &&
insns[ioff].code == (BPF_JMP | BPF_CALL))
fprintf(stderr, " - Try to annotate functions "
"with always_inline attribute!\n");
fprintf(stderr, " - Try to annotate functions with always_inline attribute!\n");
return -EINVAL;
}
if (gelf_getsym(ctx->sym_tab, GELF_R_SYM(relo.r_info), &sym) != &sym)
return -EIO;
if (sym.st_shndx != ctx->sec_maps) {
fprintf(stderr, "ELF contains non-map related relo data in "
"entry %u pointing to section %u! Compiler bug?!\n",
fprintf(stderr, "ELF contains non-map related relo data in entry %u pointing to section %u! Compiler bug?!\n",
relo_ent, sym.st_shndx);
return -EIO;
}
......@@ -1409,8 +1401,7 @@ static int bpf_apply_relo_data(struct bpf_elf_ctx *ctx,
return -EINVAL;
if (ctx->verbose)
fprintf(stderr, "Map \'%s\' (%d) injected into prog "
"section \'%s\' at offset %u!\n",
fprintf(stderr, "Map \'%s\' (%d) injected into prog section \'%s\' at offset %u!\n",
bpf_str_tab_name(ctx, &sym), ctx->map_fds[rmap],
data_insn->sec_name, ioff);
......@@ -1599,8 +1590,8 @@ static void bpf_hash_init(struct bpf_elf_ctx *ctx, const char *db_file)
}
if (bpf_pinning_reserved(pinning)) {
fprintf(stderr, "Database %s, id %u is reserved - "
"ignoring!\n", db_file, pinning);
fprintf(stderr, "Database %s, id %u is reserved - ignoring!\n",
db_file, pinning);
continue;
}
......
......@@ -24,8 +24,8 @@
#include "tc_core.h"
#include "tc_cbq.h"
unsigned tc_cbq_calc_maxidle(unsigned bndw, unsigned rate, unsigned avpkt,
int ewma_log, unsigned maxburst)
unsigned int tc_cbq_calc_maxidle(unsigned int bndw, unsigned int rate, unsigned int avpkt,
int ewma_log, unsigned int maxburst)
{
double maxidle;
double g = 1.0 - 1.0/(1<<ewma_log);
......@@ -34,6 +34,7 @@ unsigned tc_cbq_calc_maxidle(unsigned bndw, unsigned rate, unsigned avpkt,
maxidle = xmt*(1-g);
if (bndw != rate && maxburst) {
double vxmt = (double)avpkt/rate - xmt;
vxmt *= (pow(g, -(double)maxburst) - 1);
if (vxmt > maxidle)
maxidle = vxmt;
......@@ -41,8 +42,8 @@ unsigned tc_cbq_calc_maxidle(unsigned bndw, unsigned rate, unsigned avpkt,
return tc_core_time2tick(maxidle*(1<<ewma_log)*TIME_UNITS_PER_SEC);
}
unsigned tc_cbq_calc_offtime(unsigned bndw, unsigned rate, unsigned avpkt,
int ewma_log, unsigned minburst)
unsigned int tc_cbq_calc_offtime(unsigned int bndw, unsigned int rate, unsigned int avpkt,
int ewma_log, unsigned int minburst)
{
double g = 1.0 - 1.0/(1<<ewma_log);
double offtime = (double)avpkt/rate - (double)avpkt/bndw;
......
......@@ -55,12 +55,12 @@ static void usage(void)
return;
}
static int tc_class_modify(int cmd, unsigned flags, int argc, char **argv)
static int tc_class_modify(int cmd, unsigned int flags, int argc, char **argv)
{
struct {
struct nlmsghdr n;
struct tcmsg t;
char buf[4096];
struct nlmsghdr n;
struct tcmsg t;
char buf[4096];
} req;
struct qdisc_util *q = NULL;
struct tc_estimator est;
......@@ -85,6 +85,7 @@ static int tc_class_modify(int cmd, unsigned flags, int argc, char **argv)
strncpy(d, *argv, sizeof(d)-1);
} else if (strcmp(*argv, "classid") == 0) {
__u32 handle;
NEXT_ARG();
if (req.t.tcm_handle)
duparg("classid", *argv);
......@@ -102,6 +103,7 @@ static int tc_class_modify(int cmd, unsigned flags, int argc, char **argv)
req.t.tcm_parent = TC_H_ROOT;
} else if (strcmp(*argv, "parent") == 0) {
__u32 handle;
NEXT_ARG();
if (req.t.tcm_parent)
duparg("parent", *argv);
......@@ -305,7 +307,7 @@ static void graph_cls_show(FILE *fp, char *buf, struct hlist_head *root_list,
int print_class(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg)
{
FILE *fp = (FILE*)arg;
FILE *fp = (FILE *)arg;
struct tcmsg *t = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr *tb[TCA_MAX + 1] = {};
......@@ -430,6 +432,7 @@ static int tc_class_list(int argc, char **argv)
t.tcm_parent = TC_H_ROOT;
} else if (strcmp(*argv, "parent") == 0) {
__u32 handle;
if (t.tcm_parent)
duparg("parent", *argv);
NEXT_ARG();
......
......@@ -27,7 +27,7 @@
static double tick_in_usec = 1;
static double clock_factor = 1;
int tc_core_time2big(unsigned time)
int tc_core_time2big(unsigned int time)
{
__u64 t = time;
......@@ -36,32 +36,32 @@ int tc_core_time2big(unsigned time)
}
unsigned tc_core_time2tick(unsigned time)
unsigned int tc_core_time2tick(unsigned int time)
{
return time*tick_in_usec;
}
unsigned tc_core_tick2time(unsigned tick)
unsigned int tc_core_tick2time(unsigned int tick)
{
return tick/tick_in_usec;
}
unsigned tc_core_time2ktime(unsigned time)
unsigned int tc_core_time2ktime(unsigned int time)
{
return time * clock_factor;
}
unsigned tc_core_ktime2time(unsigned ktime)
unsigned int tc_core_ktime2time(unsigned int ktime)
{
return ktime / clock_factor;
}
unsigned tc_calc_xmittime(__u64 rate, unsigned size)
unsigned int tc_calc_xmittime(__u64 rate, unsigned int size)
{
return tc_core_time2tick(TIME_UNITS_PER_SEC*((double)size/(double)rate));
}
unsigned tc_calc_xmitsize(__u64 rate, unsigned ticks)
unsigned int tc_calc_xmitsize(__u64 rate, unsigned int ticks)
{
return ((double)rate*tc_core_tick2time(ticks))/TIME_UNITS_PER_SEC;
}
......@@ -76,9 +76,10 @@ unsigned tc_calc_xmitsize(__u64 rate, unsigned ticks)
* (as the table will always be aligned for 48 bytes).
* --Hawk, d.7/11-2004. <hawk@diku.dk>
*/
static unsigned tc_align_to_atm(unsigned size)
static unsigned int tc_align_to_atm(unsigned int size)
{
int linksize, cells;
cells = size / ATM_CELL_PAYLOAD;
if ((size % ATM_CELL_PAYLOAD) > 0)
cells++;
......@@ -87,7 +88,7 @@ static unsigned tc_align_to_atm(unsigned size)
return linksize;
}
static unsigned tc_adjust_size(unsigned sz, unsigned mpu, enum link_layer linklayer)
static unsigned int tc_adjust_size(unsigned int sz, unsigned int mpu, enum link_layer linklayer)
{
if (sz < mpu)
sz = mpu;
......@@ -97,7 +98,7 @@ static unsigned tc_adjust_size(unsigned sz, unsigned mpu, enum link_layer linkla
return tc_align_to_atm(sz);
case LINKLAYER_ETHERNET:
default:
// No size adjustments on Ethernet
/* No size adjustments on Ethernet */
return sz;
}
}
......@@ -122,13 +123,13 @@ static unsigned tc_adjust_size(unsigned sz, unsigned mpu, enum link_layer linkla
*/
int tc_calc_rtable(struct tc_ratespec *r, __u32 *rtab,
int cell_log, unsigned mtu,
int cell_log, unsigned int mtu,
enum link_layer linklayer)
{
int i;
unsigned sz;
unsigned bps = r->rate;
unsigned mpu = r->mpu;
unsigned int sz;
unsigned int bps = r->rate;
unsigned int mpu = r->mpu;
if (mtu == 0)
mtu = 2047;
......@@ -139,13 +140,13 @@ int tc_calc_rtable(struct tc_ratespec *r, __u32 *rtab,
cell_log++;
}
for (i=0; i<256; i++) {
for (i = 0; i < 256; i++) {
sz = tc_adjust_size((i + 1) << cell_log, mpu, linklayer);
rtab[i] = tc_calc_xmittime(bps, sz);
}
r->cell_align=-1; // Due to the sz calc
r->cell_log=cell_log;
r->cell_align = -1;
r->cell_log = cell_log;
r->linklayer = (linklayer & TC_LINKLAYER_MASK);
return cell_log;
}
......@@ -193,7 +194,7 @@ again:
(*stab)[i] = sz >> s->size_log;
}
s->cell_align = -1; // Due to the sz calc
s->cell_align = -1; /* Due to the sz calc */
return 0;
}
......
......@@ -23,22 +23,23 @@
#include "tc_core.h"
int tc_setup_estimator(unsigned A, unsigned time_const, struct tc_estimator *est)
int tc_setup_estimator(unsigned int A, unsigned int time_const, struct tc_estimator *est)
{
for (est->interval=0; est->interval<=5; est->interval++) {
for (est->interval = 0; est->interval <= 5; est->interval++) {
if (A <= (1<<est->interval)*(TIME_UNITS_PER_SEC/4))
break;
}
if (est->interval > 5)
return -1;
est->interval -= 2;
for (est->ewma_log=1; est->ewma_log<32; est->ewma_log++) {
for (est->ewma_log = 1; est->ewma_log < 32; est->ewma_log++) {
double w = 1.0 - 1.0/(1<<est->ewma_log);
if (A/(-log(w)) > time_const)
break;
}
est->ewma_log--;
if (est->ewma_log==0 || est->ewma_log >= 31)
if (est->ewma_log == 0 || est->ewma_log >= 31)
return -1;
return 0;
}
......@@ -19,7 +19,7 @@
#include "tc_common.h"
static struct exec_util *exec_list;
static void *BODY = NULL;
static void *BODY;
static void usage(void)
{
......@@ -32,8 +32,8 @@ static void usage(void)
static int parse_noeopt(struct exec_util *eu, int argc, char **argv)
{
if (argc) {
fprintf(stderr, "Unknown exec \"%s\", hence option \"%s\" "
"is unparsable\n", eu->id, *argv);
fprintf(stderr, "Unknown exec \"%s\", hence option \"%s\" is unparsable\n",
eu->id, *argv);
return -1;
}
......
......@@ -41,12 +41,12 @@ static void usage(void)
fprintf(stderr, "OPTIONS := ... try tc filter add <desired FILTER_KIND> help\n");
}
static int tc_filter_modify(int cmd, unsigned flags, int argc, char **argv)
static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv)
{
struct {
struct nlmsghdr n;
struct tcmsg t;
char buf[MAX_MSG];
struct nlmsghdr n;
struct tcmsg t;
char buf[MAX_MSG];
} req;
struct filter_util *q = NULL;
__u32 prio = 0;
......@@ -99,6 +99,7 @@ static int tc_filter_modify(int cmd, unsigned flags, int argc, char **argv)
TC_H_MIN_EGRESS);
} else if (strcmp(*argv, "parent") == 0) {
__u32 handle;
NEXT_ARG();
if (req.t.tcm_parent)
duparg("parent", *argv);
......@@ -119,6 +120,7 @@ static int tc_filter_modify(int cmd, unsigned flags, int argc, char **argv)
invarg("invalid priority value", *argv);
} else if (matches(*argv, "protocol") == 0) {
__u16 id;
NEXT_ARG();
if (protocol_set)
duparg("protocol", *argv);
......@@ -153,8 +155,7 @@ static int tc_filter_modify(int cmd, unsigned flags, int argc, char **argv)
return 1;
} else {
if (fhandle) {
fprintf(stderr, "Must specify filter type when using "
"\"handle\"\n");
fprintf(stderr, "Must specify filter type when using \"handle\"\n");
return -1;
}
if (argc) {
......@@ -189,16 +190,16 @@ static __u32 filter_parent;
static int filter_ifindex;
static __u32 filter_prio;
static __u32 filter_protocol;
__u16 f_proto = 0;
__u16 f_proto;
int print_filter(const struct sockaddr_nl *who,
struct nlmsghdr *n,
void *arg)
{
FILE *fp = (FILE*)arg;
FILE *fp = (FILE *)arg;
struct tcmsg *t = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr * tb[TCA_MAX+1];
struct rtattr *tb[TCA_MAX+1];
struct filter_util *q;
char abuf[256];
......@@ -243,6 +244,7 @@ int print_filter(const struct sockaddr_nl *who,
if (t->tcm_info) {
f_proto = TC_H_MIN(t->tcm_info);
__u32 prio = TC_H_MAJ(t->tcm_info)>>16;
if (!filter_protocol || filter_protocol != f_proto) {
if (f_proto) {
SPRINT_BUF(b1);
......@@ -316,6 +318,7 @@ static int tc_filter_list(int argc, char **argv)
t.tcm_parent = filter_parent;
} else if (strcmp(*argv, "parent") == 0) {
__u32 handle;
NEXT_ARG();
if (t.tcm_parent)
duparg("parent", *argv);
......@@ -337,6 +340,7 @@ static int tc_filter_list(int argc, char **argv)
filter_prio = prio;
} else if (matches(*argv, "protocol") == 0) {
__u16 res;
NEXT_ARG();
if (protocol)
duparg("protocol", *argv);
......@@ -401,7 +405,7 @@ int do_filter(int argc, char **argv)
if (matches(*argv, "help") == 0) {
usage();
return 0;
}
}
fprintf(stderr, "Command \"%s\" is unknown, try \"tc filter help\".\n", *argv);
return -1;
}
......@@ -39,7 +39,7 @@ static int accept_tcmsg(const struct sockaddr_nl *who,
struct rtnl_ctrl_data *ctrl,
struct nlmsghdr *n, void *arg)
{
FILE *fp = (FILE*)arg;
FILE *fp = (FILE *)arg;
if (timestamp)
print_timestamp(fp);
......@@ -73,7 +73,7 @@ int do_tcmonitor(int argc, char **argv)
{
struct rtnl_handle rth;
char *file = NULL;
unsigned groups = nl_mgrp(RTNLGRP_TC);
unsigned int groups = nl_mgrp(RTNLGRP_TC);
while (argc > 0) {
if (matches(*argv, "file") == 0) {
......@@ -109,7 +109,7 @@ int do_tcmonitor(int argc, char **argv)
ll_init_map(&rth);
if (rtnl_listen(&rth, accept_tcmsg, (void*)stdout) < 0) {
if (rtnl_listen(&rth, accept_tcmsg, (void *)stdout) < 0) {
rtnl_close(&rth);
exit(2);
}
......
......@@ -42,7 +42,7 @@ static int usage(void)
return -1;
}
static int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)
{
struct qdisc_util *q = NULL;
struct tc_estimator est;
......@@ -53,9 +53,9 @@ static int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
char d[16];
char k[16];
struct {
struct nlmsghdr n;
struct tcmsg t;
char buf[TCA_BUF_MAX];
struct nlmsghdr n;
struct tcmsg t;
char buf[TCA_BUF_MAX];
} req;
memset(&req, 0, sizeof(req));
......@@ -77,6 +77,7 @@ static int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
strncpy(d, *argv, sizeof(d)-1);
} else if (strcmp(*argv, "handle") == 0) {
__u32 handle;
if (req.t.tcm_handle)
duparg("handle", *argv);
NEXT_ARG();
......@@ -113,6 +114,7 @@ static int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
break;
} else if (strcmp(*argv, "parent") == 0) {
__u32 handle;
NEXT_ARG();
if (req.t.tcm_parent)
duparg("parent", *argv);
......@@ -205,10 +207,10 @@ int print_qdisc(const struct sockaddr_nl *who,
struct nlmsghdr *n,
void *arg)
{
FILE *fp = (FILE*)arg;
FILE *fp = (FILE *)arg;
struct tcmsg *t = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr * tb[TCA_MAX+1];
struct rtattr *tb[TCA_MAX+1];
struct qdisc_util *q;
char abuf[256];
......@@ -296,13 +298,13 @@ static int tc_qdisc_list(int argc, char **argv)
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
strncpy(d, *argv, sizeof(d)-1);
} else if (strcmp(*argv, "ingress") == 0 ||
} else if (strcmp(*argv, "ingress") == 0 ||
strcmp(*argv, "clsact") == 0) {
if (t.tcm_parent) {
fprintf(stderr, "Duplicate parent ID\n");
usage();
}
t.tcm_parent = TC_H_INGRESS;
if (t.tcm_parent) {
fprintf(stderr, "Duplicate parent ID\n");
usage();
}
t.tcm_parent = TC_H_INGRESS;
} else if (matches(*argv, "help") == 0) {
usage();
} else {
......@@ -360,7 +362,7 @@ int do_qdisc(int argc, char **argv)
if (matches(*argv, "help") == 0) {
usage();
return 0;
}
}
fprintf(stderr, "Command \"%s\" is unknown, try \"tc qdisc help\".\n", *argv);
return -1;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment