mirror_iproute2/tc/m_skbedit.c
Jamal Hadi Salim 43726b750a tc: don't ignore ok as an action branch
This is what used to happen before:

tc filter add dev tap1 parent ffff: protocol 0xfefe prio 10 \
     u32 match u32 0 0 flowid 1:16 \
     action ife decode allow mark ok

tc -s filter ls dev tap1 parent ffff:
filter protocol [65278] pref 10 u32
filter protocol [65278] pref 10 u32 fh 800: ht divisor 1
filter protocol [65278] pref 10 u32 fh 800::800 order 2048 key ht 800
bkt 0 flowid 1:16
  match 00000000/00000000 at 0
        action order 1: ife decode action pipe
         index 2 ref 1 bind 1 installed 4 sec used 4 sec
         type: 0x0
         Metadata: allow mark
        Action statistics:
        Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
        backlog 0b 0p requeues 0

        action order 2: gact action pass
         random type none pass val 0
         index 1 ref 1 bind 1 installed 4 sec used 4 sec
        Action statistics:
        Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
        backlog 0b 0p requeues 0

Note the extra action added at the end..

Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
2016-05-16 11:13:58 -07:00

218 lines
5.0 KiB
C

/*
* m_skbedit.c SKB Editing module
*
* Copyright (c) 2008, Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses>.
*
* Authors: Alexander Duyck <alexander.h.duyck@intel.com>
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "utils.h"
#include "tc_util.h"
#include <linux/tc_act/tc_skbedit.h>
static void
explain(void)
{
fprintf(stderr, "Usage: ... skbedit <[QM] [PM] [MM]>\n"
"QM = queue_mapping QUEUE_MAPPING\n"
"PM = priority PRIORITY\n"
"MM = mark MARK\n"
"QUEUE_MAPPING = device transmit queue to use\n"
"PRIORITY = classID to assign to priority field\n"
"MARK = firewall mark to set\n");
}
static void
usage(void)
{
explain();
exit(-1);
}
static int
parse_skbedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
struct nlmsghdr *n)
{
int argc = *argc_p;
char **argv = *argv_p;
int ok = 0;
struct rtattr *tail;
unsigned int tmp;
__u16 queue_mapping;
__u32 flags = 0, priority, mark;
struct tc_skbedit sel = { 0 };
if (matches(*argv, "skbedit") != 0)
return -1;
NEXT_ARG();
while (argc > 0) {
if (matches(*argv, "queue_mapping") == 0) {
flags |= SKBEDIT_F_QUEUE_MAPPING;
NEXT_ARG();
if (get_unsigned(&tmp, *argv, 10) || tmp > 65535) {
fprintf(stderr, "Illegal queue_mapping\n");
return -1;
}
queue_mapping = tmp;
ok++;
} else if (matches(*argv, "priority") == 0) {
flags |= SKBEDIT_F_PRIORITY;
NEXT_ARG();
if (get_tc_classid(&priority, *argv)) {
fprintf(stderr, "Illegal priority\n");
return -1;
}
ok++;
} else if (matches(*argv, "mark") == 0) {
flags |= SKBEDIT_F_MARK;
NEXT_ARG();
if (get_u32(&mark, *argv, 0)) {
fprintf(stderr, "Illegal mark\n");
return -1;
}
ok++;
} else if (matches(*argv, "help") == 0) {
usage();
} else {
break;
}
argc--;
argv++;
}
sel.action = TC_ACT_PIPE;
if (argc) {
if (matches(*argv, "reclassify") == 0) {
sel.action = TC_ACT_RECLASSIFY;
NEXT_ARG();
} else if (matches(*argv, "pipe") == 0) {
sel.action = TC_ACT_PIPE;
NEXT_ARG();
} else if (matches(*argv, "drop") == 0 ||
matches(*argv, "shot") == 0) {
sel.action = TC_ACT_SHOT;
NEXT_ARG();
} else if (matches(*argv, "continue") == 0) {
sel.action = TC_ACT_UNSPEC;
NEXT_ARG();
} else if (matches(*argv, "pass") == 0 ||
matches(*argv, "ok") == 0) {
sel.action = TC_ACT_OK;
NEXT_ARG();
}
}
if (argc) {
if (matches(*argv, "index") == 0) {
NEXT_ARG();
if (get_u32(&sel.index, *argv, 10)) {
fprintf(stderr, "Pedit: Illegal \"index\"\n");
return -1;
}
argc--;
argv++;
ok++;
}
}
if (!ok) {
explain();
return -1;
}
tail = NLMSG_TAIL(n);
addattr_l(n, MAX_MSG, tca_id, NULL, 0);
addattr_l(n, MAX_MSG, TCA_SKBEDIT_PARMS, &sel, sizeof(sel));
if (flags & SKBEDIT_F_QUEUE_MAPPING)
addattr_l(n, MAX_MSG, TCA_SKBEDIT_QUEUE_MAPPING,
&queue_mapping, sizeof(queue_mapping));
if (flags & SKBEDIT_F_PRIORITY)
addattr_l(n, MAX_MSG, TCA_SKBEDIT_PRIORITY,
&priority, sizeof(priority));
if (flags & SKBEDIT_F_MARK)
addattr_l(n, MAX_MSG, TCA_SKBEDIT_MARK,
&mark, sizeof(mark));
tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail;
*argc_p = argc;
*argv_p = argv;
return 0;
}
static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
{
struct rtattr *tb[TCA_SKBEDIT_MAX + 1];
SPRINT_BUF(b1);
__u32 *priority;
__u32 *mark;
__u16 *queue_mapping;
struct tc_skbedit *p = NULL;
if (arg == NULL)
return -1;
parse_rtattr_nested(tb, TCA_SKBEDIT_MAX, arg);
if (tb[TCA_SKBEDIT_PARMS] == NULL) {
fprintf(f, "[NULL skbedit parameters]");
return -1;
}
p = RTA_DATA(tb[TCA_SKBEDIT_PARMS]);
fprintf(f, " skbedit");
if (tb[TCA_SKBEDIT_QUEUE_MAPPING] != NULL) {
queue_mapping = RTA_DATA(tb[TCA_SKBEDIT_QUEUE_MAPPING]);
fprintf(f, " queue_mapping %u", *queue_mapping);
}
if (tb[TCA_SKBEDIT_PRIORITY] != NULL) {
priority = RTA_DATA(tb[TCA_SKBEDIT_PRIORITY]);
fprintf(f, " priority %s", sprint_tc_classid(*priority, b1));
}
if (tb[TCA_SKBEDIT_MARK] != NULL) {
mark = RTA_DATA(tb[TCA_SKBEDIT_MARK]);
fprintf(f, " mark %d", *mark);
}
fprintf(f, "\n\t index %d ref %d bind %d", p->index, p->refcnt, p->bindcnt);
if (show_stats) {
if (tb[TCA_SKBEDIT_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_SKBEDIT_TM]);
print_tm(f, tm);
}
}
fprintf(f, "\n ");
return 0;
}
struct action_util skbedit_action_util = {
.id = "skbedit",
.parse_aopt = parse_skbedit,
.print_aopt = print_skbedit,
};