1 /* SPDX-License-Identifier: GPL-2.0 */
3 * m_connmark.c Connection tracking marking import
5 * Copyright (c) 2011 Felix Fietkau <nbd@openwrt.org>
14 #include <linux/tc_act/tc_connmark.h>
20 "Usage: ... connmark [zone ZONE] [CONTROL] [index <INDEX>]\n"
22 "\tZONE is the conntrack zone\n"
23 "\tCONTROL := reclassify | pipe | drop | continue | ok |\n"
24 "\t goto chain <CHAIN_INDEX>\n");
35 parse_connmark(const struct action_util
*a
, int *argc_p
, char ***argv_p
, int tca_id
,
38 struct tc_connmark sel
= {};
39 char **argv
= *argv_p
;
45 if (matches(*argv
, "connmark") == 0) {
49 } else if (matches(*argv
, "help") == 0) {
63 if (matches(*argv
, "zone") == 0) {
65 if (get_u16(&sel
.zone
, *argv
, 10)) {
66 fprintf(stderr
, "connmark: Illegal \"zone\"\n");
74 parse_action_control_dflt(&argc
, &argv
, &sel
.action
, false, TC_ACT_PIPE
);
77 if (matches(*argv
, "index") == 0) {
79 if (get_u32(&sel
.index
, *argv
, 10)) {
80 fprintf(stderr
, "connmark: Illegal \"index\"\n");
88 tail
= addattr_nest(n
, MAX_MSG
, tca_id
);
89 addattr_l(n
, MAX_MSG
, TCA_CONNMARK_PARMS
, &sel
, sizeof(sel
));
90 addattr_nest_end(n
, tail
);
97 static int print_connmark(const struct action_util
*au
, FILE *f
, struct rtattr
*arg
)
99 struct rtattr
*tb
[TCA_CONNMARK_MAX
+ 1];
100 struct tc_connmark
*ci
;
102 print_string(PRINT_ANY
, "kind", "%s ", "connmark");
106 parse_rtattr_nested(tb
, TCA_CONNMARK_MAX
, arg
);
107 if (tb
[TCA_CONNMARK_PARMS
] == NULL
) {
108 fprintf(stderr
, "Missing connmark parameters\n");
112 ci
= RTA_DATA(tb
[TCA_CONNMARK_PARMS
]);
114 print_uint(PRINT_ANY
, "zone", "zone %u", ci
->zone
);
115 print_action_control(f
, " ", ci
->action
, "");
118 print_uint(PRINT_ANY
, "index", "\t index %u", ci
->index
);
119 print_int(PRINT_ANY
, "ref", " ref %d", ci
->refcnt
);
120 print_int(PRINT_ANY
, "bind", " bind %d", ci
->bindcnt
);
123 if (tb
[TCA_CONNMARK_TM
]) {
124 struct tcf_t
*tm
= RTA_DATA(tb
[TCA_CONNMARK_TM
]);
134 struct action_util connmark_action_util
= {
136 .parse_aopt
= parse_connmark
,
137 .print_aopt
= print_connmark
,