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 | tcp | udp | udplite | sctp | <SWEETS> }\n"
28 " SWEETS := { and | or | \'+\' }\n");
39 parse_csum_args(int *argc_p
, char ***argv_p
, struct tc_csum
*sel
)
42 char **argv
= *argv_p
;
48 if ((matches(*argv
, "iph") == 0) ||
49 (matches(*argv
, "ip4h") == 0) ||
50 (matches(*argv
, "ipv4h") == 0))
51 sel
->update_flags
|= TCA_CSUM_UPDATE_FLAG_IPV4HDR
;
53 else if (matches(*argv
, "icmp") == 0)
54 sel
->update_flags
|= TCA_CSUM_UPDATE_FLAG_ICMP
;
56 else if (matches(*argv
, "igmp") == 0)
57 sel
->update_flags
|= TCA_CSUM_UPDATE_FLAG_IGMP
;
59 else if (matches(*argv
, "tcp") == 0)
60 sel
->update_flags
|= TCA_CSUM_UPDATE_FLAG_TCP
;
62 else if (matches(*argv
, "udp") == 0)
63 sel
->update_flags
|= TCA_CSUM_UPDATE_FLAG_UDP
;
65 else if (matches(*argv
, "udplite") == 0)
66 sel
->update_flags
|= TCA_CSUM_UPDATE_FLAG_UDPLITE
;
68 else if (matches(*argv
, "sctp") == 0)
69 sel
->update_flags
|= TCA_CSUM_UPDATE_FLAG_SCTP
;
71 else if ((matches(*argv
, "and") == 0) ||
72 (matches(*argv
, "or") == 0) ||
73 (matches(*argv
, "+") == 0))
74 ; /* just ignore: ... csum iph and tcp or udp */
88 parse_csum(struct action_util
*a
, int *argc_p
,
89 char ***argv_p
, int tca_id
, struct nlmsghdr
*n
)
91 struct tc_csum sel
= {};
94 char **argv
= *argv_p
;
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) {
121 if (sel
.update_flags
== 0) {
122 fprintf(stderr
, "Illegal csum construct, empty <UPDATE> list\n");
126 if (argc
&& !action_a2n(*argv
, &sel
.action
, false))
130 if (matches(*argv
, "index") == 0) {
132 if (get_u32(&sel
.index
, *argv
, 10)) {
133 fprintf(stderr
, "Illegal \"index\" (%s) <csum>\n",
142 tail
= NLMSG_TAIL(n
);
143 addattr_l(n
, MAX_MSG
, tca_id
, NULL
, 0);
144 addattr_l(n
, MAX_MSG
, TCA_CSUM_PARMS
, &sel
, sizeof(sel
));
145 tail
->rta_len
= (char *)NLMSG_TAIL(n
) - (char *)tail
;
154 print_csum(struct action_util
*au
, FILE *f
, struct rtattr
*arg
)
158 struct rtattr
*tb
[TCA_CSUM_MAX
+ 1];
173 parse_rtattr_nested(tb
, TCA_CSUM_MAX
, arg
);
175 if (tb
[TCA_CSUM_PARMS
] == NULL
) {
176 fprintf(f
, "[NULL csum parameters]");
179 sel
= RTA_DATA(tb
[TCA_CSUM_PARMS
]);
181 if (sel
->update_flags
& TCA_CSUM_UPDATE_FLAG_IPV4HDR
) {
185 #define CSUM_UFLAG_BUFFER(flag_buffer, flag_value, flag_string) \
187 if (sel->update_flags & flag_value) { \
188 flag_buffer = uflag_count > 0 ? \
189 ", " flag_string : flag_string; \
193 CSUM_UFLAG_BUFFER(uflag_2
, TCA_CSUM_UPDATE_FLAG_ICMP
, "icmp");
194 CSUM_UFLAG_BUFFER(uflag_3
, TCA_CSUM_UPDATE_FLAG_IGMP
, "igmp");
195 CSUM_UFLAG_BUFFER(uflag_4
, TCA_CSUM_UPDATE_FLAG_TCP
, "tcp");
196 CSUM_UFLAG_BUFFER(uflag_5
, TCA_CSUM_UPDATE_FLAG_UDP
, "udp");
197 CSUM_UFLAG_BUFFER(uflag_6
, TCA_CSUM_UPDATE_FLAG_UDPLITE
, "udplite");
198 CSUM_UFLAG_BUFFER(uflag_7
, TCA_CSUM_UPDATE_FLAG_SCTP
, "sctp");
203 fprintf(f
, "csum (%s%s%s%s%s%s%s) action %s\n",
204 uflag_1
, uflag_2
, uflag_3
,
205 uflag_4
, uflag_5
, uflag_6
, uflag_7
,
206 action_n2a(sel
->action
));
207 fprintf(f
, "\tindex %u ref %d bind %d", sel
->index
, sel
->refcnt
,
211 if (tb
[TCA_CSUM_TM
]) {
212 struct tcf_t
*tm
= RTA_DATA(tb
[TCA_CSUM_TM
]);
222 struct action_util csum_action_util
= {
224 .parse_aopt
= parse_csum
,
225 .print_aopt
= print_csum
,