Michael S. Tsirkin | 9d1b111 | 2010-07-15 17:23:24 +0200 | [diff] [blame] | 1 | /* 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. Tsirkin | 9d1b111 | 2010-07-15 17:23:24 +0200 | [diff] [blame] | 12 | #include <xtables.h> |
| 13 | #include <linux/netfilter/xt_CHECKSUM.h> |
| 14 | |
Jan Engelhardt | f92bca9 | 2011-02-27 16:54:27 +0100 | [diff] [blame] | 15 | enum { |
| 16 | O_CHECKSUM_FILL = 0, |
| 17 | }; |
| 18 | |
Michael S. Tsirkin | 9d1b111 | 2010-07-15 17:23:24 +0200 | [diff] [blame] | 19 | static void CHECKSUM_help(void) |
| 20 | { |
| 21 | printf( |
| 22 | "CHECKSUM target options\n" |
| 23 | " --checksum-fill Fill in packet checksum.\n"); |
| 24 | } |
| 25 | |
Jan Engelhardt | f92bca9 | 2011-02-27 16:54:27 +0100 | [diff] [blame] | 26 | static 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. Tsirkin | 9d1b111 | 2010-07-15 17:23:24 +0200 | [diff] [blame] | 30 | }; |
| 31 | |
Jan Engelhardt | f92bca9 | 2011-02-27 16:54:27 +0100 | [diff] [blame] | 32 | static void CHECKSUM_parse(struct xt_option_call *cb) |
Michael S. Tsirkin | 9d1b111 | 2010-07-15 17:23:24 +0200 | [diff] [blame] | 33 | { |
Jan Engelhardt | f92bca9 | 2011-02-27 16:54:27 +0100 | [diff] [blame] | 34 | struct xt_CHECKSUM_info *einfo = cb->data; |
Michael S. Tsirkin | 9d1b111 | 2010-07-15 17:23:24 +0200 | [diff] [blame] | 35 | |
Jan Engelhardt | f92bca9 | 2011-02-27 16:54:27 +0100 | [diff] [blame] | 36 | xtables_option_parse(cb); |
| 37 | einfo->operation = XT_CHECKSUM_OP_FILL; |
Michael S. Tsirkin | 9d1b111 | 2010-07-15 17:23:24 +0200 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static 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 Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 46 | printf(" CHECKSUM"); |
Michael S. Tsirkin | 9d1b111 | 2010-07-15 17:23:24 +0200 | [diff] [blame] | 47 | |
| 48 | if (einfo->operation & XT_CHECKSUM_OP_FILL) |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 49 | printf(" fill"); |
Michael S. Tsirkin | 9d1b111 | 2010-07-15 17:23:24 +0200 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | static 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 Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 58 | printf(" --checksum-fill"); |
Michael S. Tsirkin | 9d1b111 | 2010-07-15 17:23:24 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static 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. Tsirkin | 9d1b111 | 2010-07-15 17:23:24 +0200 | [diff] [blame] | 68 | .print = CHECKSUM_print, |
| 69 | .save = CHECKSUM_save, |
Jan Engelhardt | f92bca9 | 2011-02-27 16:54:27 +0100 | [diff] [blame] | 70 | .x6_parse = CHECKSUM_parse, |
| 71 | .x6_options = CHECKSUM_opts, |
Michael S. Tsirkin | 9d1b111 | 2010-07-15 17:23:24 +0200 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | void _init(void) |
| 75 | { |
| 76 | xtables_register_target(&checksum_tg_reg); |
| 77 | } |