2 * m_csum.c checksum updating action
4 * This program is free software; you can distribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Gregoire Baron <baronchon@n7mm.org>
17 #include <linux/tc_act/tc_csum.h>
25 fprintf(stderr
, "Usage: ... csum <UPDATE>\n"
26 "Where: UPDATE := <TARGET> [<UPDATE>]\n"
27 " TARGET := { ip4h | icmp | igmp |"
28 " tcp | udp | udplite | <SWEETS> }\n"
29 " SWEETS := { and | or | \'+\' }\n");
40 parse_csum_args(int *argc_p
, char ***argv_p
, struct tc_csum
*sel
)
43 char **argv
= *argv_p
;
49 if ((matches(*argv
, "iph") == 0) ||
50 (matches(*argv
, "ip4h") == 0) ||
51 (matches(*argv
, "ipv4h") == 0))
52 sel
->update_flags
|= TCA_CSUM_UPDATE_FLAG_IPV4HDR
;
54 else if (matches(*argv
, "icmp") == 0)
55 sel
->update_flags
|= TCA_CSUM_UPDATE_FLAG_ICMP
;
57 else if (matches(*argv
, "igmp") == 0)
58 sel
->update_flags
|= TCA_CSUM_UPDATE_FLAG_IGMP
;
60 else if (matches(*argv
, "tcp") == 0)
61 sel
->update_flags
|= TCA_CSUM_UPDATE_FLAG_TCP
;
63 else if (matches(*argv
, "udp") == 0)
64 sel
->update_flags
|= TCA_CSUM_UPDATE_FLAG_UDP
;
66 else if (matches(*argv
, "udplite") == 0)
67 sel
->update_flags
|= TCA_CSUM_UPDATE_FLAG_UDPLITE
;
69 else if ((matches(*argv
, "and") == 0) ||
70 (matches(*argv
, "or") == 0) ||
71 (matches(*argv
, "+") == 0))
72 ; /* just ignore: ... csum iph and tcp or udp */
86 parse_csum(struct action_util
*a
, int *argc_p
,
87 char ***argv_p
, int tca_id
, struct nlmsghdr
*n
)
92 char **argv
= *argv_p
;
96 memset(&sel
, 0, sizeof(sel
));
99 if (matches(*argv
, "csum") == 0) {
101 if (parse_csum_args(&argc
, &argv
, &sel
)) {
102 fprintf(stderr
, "Illegal csum construct (%s)\n",
109 } else if (matches(*argv
, "help") == 0) {
122 if (sel
.update_flags
== 0) {
123 fprintf(stderr
, "Illegal csum construct, empty <UPDATE> list\n");
128 if (matches(*argv
, "reclassify") == 0) {
129 sel
.action
= TC_ACT_RECLASSIFY
;
132 } else if (matches(*argv
, "pipe") == 0) {
133 sel
.action
= TC_ACT_PIPE
;
136 } else if (matches(*argv
, "drop") == 0 ||
137 matches(*argv
, "shot") == 0) {
138 sel
.action
= TC_ACT_SHOT
;
141 } else if (matches(*argv
, "continue") == 0) {
142 sel
.action
= TC_ACT_UNSPEC
;
145 } else if (matches(*argv
, "pass") == 0) {
146 sel
.action
= TC_ACT_OK
;
153 if (matches(*argv
, "index") == 0) {
155 if (get_u32(&sel
.index
, *argv
, 10)) {
156 fprintf(stderr
, "Illegal \"index\" (%s) <csum>\n",
165 tail
= NLMSG_TAIL(n
);
166 addattr_l(n
, MAX_MSG
, tca_id
, NULL
, 0);
167 addattr_l(n
, MAX_MSG
, TCA_CSUM_PARMS
, &sel
, sizeof(sel
));
168 tail
->rta_len
= (char *)NLMSG_TAIL(n
) - (char *)tail
;
177 print_csum(struct action_util
*au
, FILE * f
, struct rtattr
*arg
)
181 struct rtattr
*tb
[TCA_CSUM_MAX
+ 1];
189 SPRINT_BUF(action_buf
);
196 parse_rtattr_nested(tb
, TCA_CSUM_MAX
, arg
);
198 if (tb
[TCA_CSUM_PARMS
] == NULL
) {
199 fprintf(f
, "[NULL csum parameters]");
202 sel
= RTA_DATA(tb
[TCA_CSUM_PARMS
]);
204 if (sel
->update_flags
& TCA_CSUM_UPDATE_FLAG_IPV4HDR
) {
208 #define CSUM_UFLAG_BUFFER(flag_buffer, flag_value, flag_string) \
210 if (sel->update_flags & flag_value) { \
211 flag_buffer = uflag_count > 0 ? \
212 ", " flag_string : flag_string; \
216 CSUM_UFLAG_BUFFER(uflag_2
, TCA_CSUM_UPDATE_FLAG_ICMP
, "icmp");
217 CSUM_UFLAG_BUFFER(uflag_3
, TCA_CSUM_UPDATE_FLAG_IGMP
, "igmp");
218 CSUM_UFLAG_BUFFER(uflag_4
, TCA_CSUM_UPDATE_FLAG_TCP
, "tcp");
219 CSUM_UFLAG_BUFFER(uflag_5
, TCA_CSUM_UPDATE_FLAG_UDP
, "udp");
220 CSUM_UFLAG_BUFFER(uflag_6
, TCA_CSUM_UPDATE_FLAG_UDPLITE
, "udplite");
225 fprintf(f
, "csum (%s%s%s%s%s%s) action %s\n",
226 uflag_1
, uflag_2
, uflag_3
,
227 uflag_4
, uflag_5
, uflag_6
,
228 action_n2a(sel
->action
, action_buf
, sizeof(action_buf
)));
229 fprintf(f
, "\tindex %d ref %d bind %d", sel
->index
, sel
->refcnt
, sel
->bindcnt
);
232 if (tb
[TCA_CSUM_TM
]) {
233 struct tcf_t
*tm
= RTA_DATA(tb
[TCA_CSUM_TM
]);
242 struct action_util csum_action_util
= {
244 .parse_aopt
= parse_csum
,
245 .print_aopt
= print_csum
,