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> 12#include <xtables.h> 13#include <linux/netfilter/xt_CHECKSUM.h> 14 15enum { 16 O_CHECKSUM_FILL = 0, 17}; 18 19static void CHECKSUM_help(void) 20{ 21 printf( 22"CHECKSUM target options\n" 23" --checksum-fill Fill in packet checksum.\n"); 24} 25 26static 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, 30}; 31 32static void CHECKSUM_parse(struct xt_option_call *cb) 33{ 34 struct xt_CHECKSUM_info *einfo = cb->data; 35 36 xtables_option_parse(cb); 37 einfo->operation = XT_CHECKSUM_OP_FILL; 38} 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 46 printf(" CHECKSUM"); 47 48 if (einfo->operation & XT_CHECKSUM_OP_FILL) 49 printf(" fill"); 50} 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) 58 printf(" --checksum-fill"); 59} 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, 68 .print = CHECKSUM_print, 69 .save = CHECKSUM_save, 70 .x6_parse = CHECKSUM_parse, 71 .x6_options = CHECKSUM_opts, 72}; 73 74void _init(void) 75{ 76 xtables_register_target(&checksum_tg_reg); 77} 78