Use NLMSG_TAIL

(Logical change 1.127)
This commit is contained in:
8!tgraf 2005-01-18 01:24:18 +00:00
parent 1b52a7622e
commit 4a86fe19bc
3 changed files with 21 additions and 34 deletions

View File

@ -794,7 +794,7 @@ static int u32_parse_opt(struct filter_util *qu, char *handle, int argc, char **
if (argc == 0) if (argc == 0)
return 0; return 0;
tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len)); tail = NLMSG_TAIL(n);
addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0); addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
while (argc > 0) { while (argc > 0) {
@ -943,7 +943,7 @@ static int u32_parse_opt(struct filter_util *qu, char *handle, int argc, char **
addattr_l(n, MAX_MSG, TCA_U32_HASH, &htid, 4); addattr_l(n, MAX_MSG, TCA_U32_HASH, &htid, 4);
if (sel_ok) if (sel_ok)
addattr_l(n, MAX_MSG, TCA_U32_SEL, &sel, sizeof(sel.sel)+sel.sel.nkeys*sizeof(struct tc_u32_key)); addattr_l(n, MAX_MSG, TCA_U32_SEL, &sel, sizeof(sel.sel)+sel.sel.nkeys*sizeof(struct tc_u32_key));
tail->rta_len = (((void*)n)+n->nlmsg_len) - (void*)tail; tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
return 0; return 0;
} }

View File

@ -144,8 +144,7 @@ parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
if (argc <= 0) if (argc <= 0)
return -1; return -1;
tail = tail2 = tail = tail2 = NLMSG_TAIL(n);
(struct rtattr *) (((void *) n) + NLMSG_ALIGN(n->nlmsg_len));
addattr_l(n, MAX_MSG, tca_id, NULL, 0); addattr_l(n, MAX_MSG, tca_id, NULL, 0);
@ -185,9 +184,7 @@ done0:
goto bad_val; goto bad_val;
} }
tail = tail = NLMSG_TAIL(n);
(struct rtattr *) (((void *) n) +
NLMSG_ALIGN(n->nlmsg_len));
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);
@ -197,9 +194,7 @@ done0:
fprintf(stderr,"bad action parsing\n"); fprintf(stderr,"bad action parsing\n");
goto bad_val; goto bad_val;
} }
tail->rta_len = tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
(((void *) n) + NLMSG_ALIGN(n->nlmsg_len)) -
(void *) tail;
ok++; ok++;
} }
@ -210,8 +205,7 @@ done0:
goto bad_val; goto bad_val;
} }
tail2->rta_len = tail2->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail2;
(((void *) n) + NLMSG_ALIGN(n->nlmsg_len)) - (void *) tail2;
done: done:
*argc_p = argc; *argc_p = argc;
@ -376,8 +370,7 @@ int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p)
argv +=1; argv +=1;
tail = (struct rtattr*)(((void*)&req.n)+NLMSG_ALIGN(req.n.nlmsg_len)); 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) {
@ -425,17 +418,15 @@ int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p)
goto bad_val; goto bad_val;
} }
tail2 = tail2 = NLMSG_TAIL(&req.n);
(struct rtattr *) (((void *) &req.n) + NLMSG_ALIGN(req.n.nlmsg_len)); 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); addattr32(&req.n, MAX_MSG, TCA_ACT_INDEX, i);
addattr32(&req.n, MAX_MSG, TCA_ACT_INDEX, i); tail2->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail2;
tail2->rta_len =
(((void *) &req.n) + NLMSG_ALIGN(req.n.nlmsg_len)) - (void *) tail2;
} }
tail->rta_len = (((void*)&req.n)+ NLMSG_ALIGN(req.n.nlmsg_len)) - (void*)tail; tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail;
if (rtnl_open(&rth, 0) < 0) { if (rtnl_open(&rth, 0) < 0) {
fprintf(stderr, "Cannot open rtnetlink\n"); fprintf(stderr, "Cannot open rtnetlink\n");
@ -485,14 +476,14 @@ int tc_action_modify(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;
tail = (struct rtattr*)(((void*)&req.n)+NLMSG_ALIGN(req.n.nlmsg_len)); 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;
} }
tail->rta_len = (((void*)&req.n)+req.n.nlmsg_len) - (void*)tail; tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail;
if (rtnl_open(&rth, 0) < 0) { if (rtnl_open(&rth, 0) < 0) {
fprintf(stderr, "Cannot open rtnetlink\n"); fprintf(stderr, "Cannot open rtnetlink\n");
@ -530,11 +521,9 @@ int tc_act_list_or_flush(int argc, char **argv, int event)
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg));
tail = (struct rtattr*)(((void*)&req.n)+NLMSG_ALIGN(req.n.nlmsg_len)); 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);
tail2 = tail2 = NLMSG_TAIL(&req.n);
(struct rtattr *) (((void *) &req.n) + NLMSG_ALIGN(req.n.nlmsg_len));
strncpy(k, *argv, sizeof (k) - 1); strncpy(k, *argv, sizeof (k) - 1);
#ifdef CONFIG_GACT #ifdef CONFIG_GACT
@ -555,10 +544,8 @@ int tc_act_list_or_flush(int argc, char **argv, int event)
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);
tail2->rta_len = tail2->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail2;
(((void *) &req.n) + NLMSG_ALIGN(req.n.nlmsg_len)) - (void *) tail2; tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail;
tail->rta_len = (((void*)&req.n)+NLMSG_ALIGN(req.n.nlmsg_len)) - (void*)tail;
if (rtnl_open(&rth, 0) < 0) { if (rtnl_open(&rth, 0) < 0) {
fprintf(stderr, "Cannot open rtnetlink\n"); fprintf(stderr, "Cannot open rtnetlink\n");

View File

@ -205,7 +205,7 @@ hfsc_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
return -1; return -1;
} }
tail = (struct rtattr*)(((void*)n) + NLMSG_ALIGN(n->nlmsg_len)); tail = NLMSG_TAIL(n);
addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
if (rsc_ok) if (rsc_ok)
@ -215,7 +215,7 @@ hfsc_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
if (usc_ok) if (usc_ok)
addattr_l(n, 1024, TCA_HFSC_USC, &usc, sizeof(usc)); addattr_l(n, 1024, TCA_HFSC_USC, &usc, sizeof(usc));
tail->rta_len = (((void*)n) + NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail; tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
return 0; return 0;
} }