action pedit: stylistic changes
More modern layout. Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
This commit is contained in:
parent
8e45e44b79
commit
d8694a30a4
96
tc/m_pedit.c
96
tc/m_pedit.c
|
|
@ -32,8 +32,7 @@
|
|||
static struct m_pedit_util *pedit_list;
|
||||
static int pedit_debug;
|
||||
|
||||
static void
|
||||
explain(void)
|
||||
static void explain(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: ... pedit munge <MUNGE> [CONTROL]\n");
|
||||
fprintf(stderr,
|
||||
|
|
@ -48,21 +47,23 @@ explain(void)
|
|||
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
static void usage(void)
|
||||
{
|
||||
explain();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
static int
|
||||
pedit_parse_nopopt (int *argc_p, char ***argv_p, struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
|
||||
static int pedit_parse_nopopt(int *argc_p, char ***argv_p,
|
||||
struct tc_pedit_sel *sel,
|
||||
struct tc_pedit_key *tkey)
|
||||
{
|
||||
int argc = *argc_p;
|
||||
char **argv = *argv_p;
|
||||
|
||||
if (argc) {
|
||||
fprintf(stderr, "Unknown action hence option \"%s\" is unparsable\n", *argv);
|
||||
fprintf(stderr,
|
||||
"Unknown action hence option \"%s\" is unparsable\n",
|
||||
*argv);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -114,8 +115,7 @@ noexist:
|
|||
return p;
|
||||
}
|
||||
|
||||
int
|
||||
pack_key(struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
|
||||
int pack_key(struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
|
||||
{
|
||||
int hwm = sel->nkeys;
|
||||
|
||||
|
|
@ -137,9 +137,8 @@ pack_key(struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
pack_key32(__u32 retain, struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
|
||||
int pack_key32(__u32 retain, struct tc_pedit_sel *sel,
|
||||
struct tc_pedit_key *tkey)
|
||||
{
|
||||
if (tkey->off > (tkey->off & ~3)) {
|
||||
fprintf(stderr,
|
||||
|
|
@ -152,8 +151,8 @@ pack_key32(__u32 retain, struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
|
|||
return pack_key(sel, tkey);
|
||||
}
|
||||
|
||||
int
|
||||
pack_key16(__u32 retain, struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
|
||||
int pack_key16(__u32 retain, struct tc_pedit_sel *sel,
|
||||
struct tc_pedit_key *tkey)
|
||||
{
|
||||
int ind, stride;
|
||||
__u32 m[4] = { 0x0000FFFF, 0xFF0000FF, 0xFFFF0000 };
|
||||
|
|
@ -177,19 +176,20 @@ pack_key16(__u32 retain, struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
|
|||
tkey->off &= ~3;
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
pack_key8(__u32 retain, struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
|
||||
int pack_key8(__u32 retain, struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
|
||||
{
|
||||
int ind, stride;
|
||||
__u32 m[4] = { 0x00FFFFFF, 0xFF00FFFF, 0xFFFF00FF, 0xFFFFFF00 };
|
||||
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -202,12 +202,12 @@ pack_key8(__u32 retain, struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
|
|||
tkey->off &= ~3;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int
|
||||
parse_val(int *argc_p, char ***argv_p, __u32 *val, int type)
|
||||
int parse_val(int *argc_p, char ***argv_p, __u32 * val, int type)
|
||||
{
|
||||
int argc = *argc_p;
|
||||
char **argv = *argv_p;
|
||||
|
|
@ -238,8 +238,8 @@ parse_val(int *argc_p, char ***argv_p, __u32 *val, int type)
|
|||
return -1;
|
||||
}
|
||||
|
||||
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)
|
||||
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)
|
||||
{
|
||||
__u32 mask = 0, val = 0;
|
||||
__u32 o = 0xFF;
|
||||
|
|
@ -251,7 +251,8 @@ parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type, __u32 retain, struct
|
|||
return -1;
|
||||
|
||||
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)
|
||||
o = 0xFFFF;
|
||||
|
|
@ -271,13 +272,15 @@ parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type, __u32 retain, struct
|
|||
return -1;
|
||||
}
|
||||
|
||||
argc--; argv++;
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if (argc && matches(*argv, "retain") == 0) {
|
||||
NEXT_ARG();
|
||||
if (parse_val(&argc, &argv, &retain, TU32))
|
||||
return -1;
|
||||
argc--; argv++;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
tkey->val = val;
|
||||
|
|
@ -302,15 +305,16 @@ parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type, __u32 retain, struct
|
|||
return -1;
|
||||
done:
|
||||
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;
|
||||
*argv_p = argv;
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
parse_offset(int *argc_p, char ***argv_p, struct tc_pedit_sel *sel, struct tc_pedit_key *tkey)
|
||||
int parse_offset(int *argc_p, char ***argv_p, struct tc_pedit_sel *sel,
|
||||
struct tc_pedit_key *tkey)
|
||||
{
|
||||
int off;
|
||||
__u32 len, retain;
|
||||
|
|
@ -331,7 +335,6 @@ parse_offset(int *argc_p, char ***argv_p, struct tc_pedit_sel *sel, struct tc_pe
|
|||
if (argc <= 0)
|
||||
return -1;
|
||||
|
||||
|
||||
if (matches(*argv, "u32") == 0) {
|
||||
len = 4;
|
||||
retain = 0xFFFFFFFF;
|
||||
|
|
@ -386,8 +389,7 @@ done:
|
|||
return res;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_munge(int *argc_p, char ***argv_p, struct tc_pedit_sel *sel)
|
||||
static int parse_munge(int *argc_p, char ***argv_p, struct tc_pedit_sel *sel)
|
||||
{
|
||||
struct tc_pedit_key tkey;
|
||||
int argc = *argc_p;
|
||||
|
|
@ -433,8 +435,8 @@ done:
|
|||
return res;
|
||||
}
|
||||
|
||||
int
|
||||
parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
|
||||
int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
|
||||
struct nlmsghdr *n)
|
||||
{
|
||||
struct {
|
||||
struct tc_pedit_sel sel;
|
||||
|
|
@ -459,13 +461,15 @@ parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, stru
|
|||
usage();
|
||||
} else if (matches(*argv, "munge") == 0) {
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Illegal pedit construct (%s)\n", *argv);
|
||||
fprintf(stderr, "Bad pedit construct (%s)\n",
|
||||
*argv);
|
||||
explain();
|
||||
return -1;
|
||||
}
|
||||
NEXT_ARG();
|
||||
if (parse_munge(&argc, &argv, &sel.sel)) {
|
||||
fprintf(stderr, "Illegal pedit construct (%s)\n", *argv);
|
||||
fprintf(stderr, "Bad pedit construct (%s)\n",
|
||||
*argv);
|
||||
explain();
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -517,7 +521,9 @@ parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, stru
|
|||
|
||||
tail = NLMSG_TAIL(n);
|
||||
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;
|
||||
|
||||
*argc_p = argc;
|
||||
|
|
@ -525,8 +531,7 @@ parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, stru
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
print_pedit(struct action_util *au, FILE * f, struct rtattr *arg)
|
||||
int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
|
||||
{
|
||||
struct tc_pedit_sel *sel;
|
||||
struct rtattr *tb[TCA_PEDIT_MAX + 1];
|
||||
|
|
@ -544,8 +549,10 @@ print_pedit(struct action_util *au, FILE * f, struct rtattr *arg)
|
|||
}
|
||||
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, "\t index %d ref %d bind %d", sel->index, sel->refcnt, sel->bindcnt);
|
||||
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);
|
||||
|
||||
if (show_stats) {
|
||||
if (tb[TCA_PEDIT_TM]) {
|
||||
|
|
@ -566,16 +573,15 @@ print_pedit(struct action_util *au, FILE * f, struct rtattr *arg)
|
|||
(unsigned int)ntohl(key->mask));
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
|
||||
|
||||
fprintf(f, "\n ");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pedit_print_xstats(struct action_util *au, FILE *f, struct rtattr *xstats)
|
||||
int pedit_print_xstats(struct action_util *au, FILE *f, struct rtattr *xstats)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue