2 * m_connmark.c Connection tracking marking import
4 * Copyright (c) 2011 Felix Fietkau <nbd@openwrt.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, see <http://www.gnu.org/licenses>.
25 #include <linux/tc_act/tc_connmark.h>
30 fprintf(stderr
, "Usage: ... connmark [zone ZONE] [CONTROL] [index <INDEX>]\n");
31 fprintf(stderr
, "where :\n"
32 "\tZONE is the conntrack zone\n"
33 "\tCONTROL := reclassify|pipe|drop|continue|ok\n");
44 parse_connmark(struct action_util
*a
, int *argc_p
, char ***argv_p
, int tca_id
,
47 struct tc_connmark sel
= {};
48 char **argv
= *argv_p
;
54 if (matches(*argv
, "connmark") == 0) {
58 } else if (matches(*argv
, "help") == 0) {
72 if (matches(*argv
, "zone") == 0) {
74 if (get_u16(&sel
.zone
, *argv
, 10)) {
75 fprintf(stderr
, "simple: Illegal \"index\"\n");
83 sel
.action
= TC_ACT_PIPE
;
84 if (argc
&& !action_a2n(*argv
, &sel
.action
, false))
88 if (matches(*argv
, "index") == 0) {
90 if (get_u32(&sel
.index
, *argv
, 10)) {
91 fprintf(stderr
, "simple: Illegal \"index\"\n");
100 addattr_l(n
, MAX_MSG
, tca_id
, NULL
, 0);
101 addattr_l(n
, MAX_MSG
, TCA_CONNMARK_PARMS
, &sel
, sizeof(sel
));
102 tail
->rta_len
= (char *)NLMSG_TAIL(n
) - (char *)tail
;
109 static int print_connmark(struct action_util
*au
, FILE *f
, struct rtattr
*arg
)
111 struct rtattr
*tb
[TCA_CONNMARK_MAX
+ 1];
112 struct tc_connmark
*ci
;
117 parse_rtattr_nested(tb
, TCA_CONNMARK_MAX
, arg
);
118 if (tb
[TCA_CONNMARK_PARMS
] == NULL
) {
119 fprintf(f
, "[NULL connmark parameters]");
123 ci
= RTA_DATA(tb
[TCA_CONNMARK_PARMS
]);
125 fprintf(f
, " connmark zone %d\n", ci
->zone
);
126 fprintf(f
, "\t index %u ref %d bind %d", ci
->index
,
127 ci
->refcnt
, ci
->bindcnt
);
130 if (tb
[TCA_CONNMARK_TM
]) {
131 struct tcf_t
*tm
= RTA_DATA(tb
[TCA_CONNMARK_TM
]);
141 struct action_util connmark_action_util
= {
143 .parse_aopt
= parse_connmark
,
144 .print_aopt
= print_connmark
,