blob: df9f9b3c4358d6262293c3a64c460e7027d1526e [file] [log] [blame]
Michael S. Tsirkin9d1b1112010-07-15 17:23:24 +02001/* Shared library add-on to xtables for CHECKSUM
2 *
3 * (C) 2002 by Harald Welte <laforge@gnumonks.org>
4 * (C) 2010 by Red Hat, Inc
5 * Author: Michael S. Tsirkin <mst@redhat.com>
6 *
7 * This program is distributed under the terms of GNU GPL v2, 1991
8 *
9 * libxt_CHECKSUM.c borrowed some bits from libipt_ECN.c
10 */
11#include <stdio.h>
Michael S. Tsirkin9d1b1112010-07-15 17:23:24 +020012#include <xtables.h>
13#include <linux/netfilter/xt_CHECKSUM.h>
14
Jan Engelhardtf92bca92011-02-27 16:54:27 +010015enum {
16 O_CHECKSUM_FILL = 0,
17};
18
Michael S. Tsirkin9d1b1112010-07-15 17:23:24 +020019static void CHECKSUM_help(void)
20{
21 printf(
22"CHECKSUM target options\n"
23" --checksum-fill Fill in packet checksum.\n");
24}
25
Jan Engelhardtf92bca92011-02-27 16:54:27 +010026static const struct xt_option_entry CHECKSUM_opts[] = {
27 {.name = "checksum-fill", .id = O_CHECKSUM_FILL,
28 .flags = XTOPT_MAND, .type = XTTYPE_NONE},
29 XTOPT_TABLEEND,
Michael S. Tsirkin9d1b1112010-07-15 17:23:24 +020030};
31
Jan Engelhardtf92bca92011-02-27 16:54:27 +010032static void CHECKSUM_parse(struct xt_option_call *cb)
Michael S. Tsirkin9d1b1112010-07-15 17:23:24 +020033{
Jan Engelhardtf92bca92011-02-27 16:54:27 +010034 struct xt_CHECKSUM_info *einfo = cb->data;
Michael S. Tsirkin9d1b1112010-07-15 17:23:24 +020035
Jan Engelhardtf92bca92011-02-27 16:54:27 +010036 xtables_option_parse(cb);
37 einfo->operation = XT_CHECKSUM_OP_FILL;
Michael S. Tsirkin9d1b1112010-07-15 17:23:24 +020038}
39
40static void CHECKSUM_print(const void *ip, const struct xt_entry_target *target,
41 int numeric)
42{
43 const struct xt_CHECKSUM_info *einfo =
44 (const struct xt_CHECKSUM_info *)target->data;
45
Jan Engelhardt73866352010-12-18 02:04:59 +010046 printf(" CHECKSUM");
Michael S. Tsirkin9d1b1112010-07-15 17:23:24 +020047
48 if (einfo->operation & XT_CHECKSUM_OP_FILL)
Jan Engelhardt73866352010-12-18 02:04:59 +010049 printf(" fill");
Michael S. Tsirkin9d1b1112010-07-15 17:23:24 +020050}
51
52static void CHECKSUM_save(const void *ip, const struct xt_entry_target *target)
53{
54 const struct xt_CHECKSUM_info *einfo =
55 (const struct xt_CHECKSUM_info *)target->data;
56
57 if (einfo->operation & XT_CHECKSUM_OP_FILL)
Jan Engelhardt73866352010-12-18 02:04:59 +010058 printf(" --checksum-fill");
Michael S. Tsirkin9d1b1112010-07-15 17:23:24 +020059}
60
61static struct xtables_target checksum_tg_reg = {
62 .name = "CHECKSUM",
63 .version = XTABLES_VERSION,
64 .family = NFPROTO_UNSPEC,
65 .size = XT_ALIGN(sizeof(struct xt_CHECKSUM_info)),
66 .userspacesize = XT_ALIGN(sizeof(struct xt_CHECKSUM_info)),
67 .help = CHECKSUM_help,
Michael S. Tsirkin9d1b1112010-07-15 17:23:24 +020068 .print = CHECKSUM_print,
69 .save = CHECKSUM_save,
Jan Engelhardtf92bca92011-02-27 16:54:27 +010070 .x6_parse = CHECKSUM_parse,
71 .x6_options = CHECKSUM_opts,
Michael S. Tsirkin9d1b1112010-07-15 17:23:24 +020072};
73
74void _init(void)
75{
76 xtables_register_target(&checksum_tg_reg);
77}