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