]>
Commit | Line | Data |
---|---|---|
b8d5c9a7 FF |
1 | /* |
2 | * m_connmark.c Connection tracking marking import | |
3 | * | |
4 | * Copyright (c) 2011 Felix Fietkau <nbd@openwrt.org> | |
5 | * | |
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. | |
9 | * | |
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 | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along with | |
5c32fa1d | 16 | * this program; if not, see <http://www.gnu.org/licenses>. |
b8d5c9a7 FF |
17 | */ |
18 | ||
19 | #include <stdio.h> | |
20 | #include <stdlib.h> | |
21 | #include <unistd.h> | |
22 | #include <string.h> | |
23 | #include "utils.h" | |
24 | #include "tc_util.h" | |
25 | #include <linux/tc_act/tc_connmark.h> | |
26 | ||
27 | static void | |
28 | explain(void) | |
29 | { | |
1672f421 | 30 | fprintf(stderr, "Usage: ... connmark [zone ZONE] [CONTROL] [index <INDEX>]\n"); |
b8d5c9a7 FF |
31 | fprintf(stderr, "where :\n" |
32 | "\tZONE is the conntrack zone\n" | |
d19f72f7 JP |
33 | "\tCONTROL := reclassify | pipe | drop | continue | ok |\n" |
34 | "\t goto chain <CHAIN_INDEX>\n"); | |
b8d5c9a7 FF |
35 | } |
36 | ||
37 | static void | |
38 | usage(void) | |
39 | { | |
40 | explain(); | |
41 | exit(-1); | |
42 | } | |
43 | ||
44 | static int | |
45 | parse_connmark(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, | |
46 | struct nlmsghdr *n) | |
47 | { | |
48 | struct tc_connmark sel = {}; | |
49 | char **argv = *argv_p; | |
50 | int argc = *argc_p; | |
51 | int ok = 0; | |
52 | struct rtattr *tail; | |
53 | ||
54 | while (argc > 0) { | |
55 | if (matches(*argv, "connmark") == 0) { | |
56 | ok = 1; | |
57 | argc--; | |
58 | argv++; | |
59 | } else if (matches(*argv, "help") == 0) { | |
60 | usage(); | |
61 | } else { | |
62 | break; | |
63 | } | |
64 | ||
65 | } | |
66 | ||
67 | if (!ok) { | |
68 | explain(); | |
69 | return -1; | |
70 | } | |
71 | ||
72 | if (argc) { | |
73 | if (matches(*argv, "zone") == 0) { | |
74 | NEXT_ARG(); | |
75 | if (get_u16(&sel.zone, *argv, 10)) { | |
76 | fprintf(stderr, "simple: Illegal \"index\"\n"); | |
77 | return -1; | |
78 | } | |
79 | argc--; | |
80 | argv++; | |
81 | } | |
82 | } | |
83 | ||
e67aba55 | 84 | parse_action_control_dflt(&argc, &argv, &sel.action, false, TC_ACT_PIPE); |
b8d5c9a7 FF |
85 | |
86 | if (argc) { | |
87 | if (matches(*argv, "index") == 0) { | |
88 | NEXT_ARG(); | |
89 | if (get_u32(&sel.index, *argv, 10)) { | |
90 | fprintf(stderr, "simple: Illegal \"index\"\n"); | |
91 | return -1; | |
92 | } | |
93 | argc--; | |
94 | argv++; | |
95 | } | |
96 | } | |
97 | ||
98 | tail = NLMSG_TAIL(n); | |
99 | addattr_l(n, MAX_MSG, tca_id, NULL, 0); | |
100 | addattr_l(n, MAX_MSG, TCA_CONNMARK_PARMS, &sel, sizeof(sel)); | |
101 | tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail; | |
102 | ||
103 | *argc_p = argc; | |
104 | *argv_p = argv; | |
105 | return 0; | |
106 | } | |
107 | ||
108 | static int print_connmark(struct action_util *au, FILE *f, struct rtattr *arg) | |
109 | { | |
110 | struct rtattr *tb[TCA_CONNMARK_MAX + 1]; | |
111 | struct tc_connmark *ci; | |
112 | ||
113 | if (arg == NULL) | |
114 | return -1; | |
115 | ||
116 | parse_rtattr_nested(tb, TCA_CONNMARK_MAX, arg); | |
117 | if (tb[TCA_CONNMARK_PARMS] == NULL) { | |
118 | fprintf(f, "[NULL connmark parameters]"); | |
119 | return -1; | |
120 | } | |
121 | ||
122 | ci = RTA_DATA(tb[TCA_CONNMARK_PARMS]); | |
123 | ||
990b1d90 RM |
124 | fprintf(f, " connmark zone %d", ci->zone); |
125 | print_action_control(f, " ", ci->action, "\n"); | |
53075318 | 126 | fprintf(f, "\t index %u ref %d bind %d", ci->index, |
b8d5c9a7 FF |
127 | ci->refcnt, ci->bindcnt); |
128 | ||
129 | if (show_stats) { | |
130 | if (tb[TCA_CONNMARK_TM]) { | |
131 | struct tcf_t *tm = RTA_DATA(tb[TCA_CONNMARK_TM]); | |
32a121cb | 132 | |
b8d5c9a7 FF |
133 | print_tm(f, tm); |
134 | } | |
135 | } | |
136 | fprintf(f, "\n"); | |
137 | ||
138 | return 0; | |
139 | } | |
140 | ||
141 | struct action_util connmark_action_util = { | |
142 | .id = "connmark", | |
143 | .parse_aopt = parse_connmark, | |
144 | .print_aopt = print_connmark, | |
145 | }; |