libxt_helper.c revision d09b6d591ca7d7d7575cb6aa20384c9830f777ab
1/* Shared library add-on to iptables to add related packet matching support. */ 2#include <stdbool.h> 3#include <stdio.h> 4#include <netdb.h> 5#include <string.h> 6#include <stdlib.h> 7#include <getopt.h> 8 9#include <xtables.h> 10#include <linux/netfilter/xt_helper.h> 11 12static void helper_help(void) 13{ 14 printf( 15"helper match options:\n" 16"[!] --helper string Match helper identified by string\n"); 17} 18 19static const struct option helper_opts[] = { 20 {.name = "helper", .has_arg = true, .val = '1'}, 21 XT_GETOPT_TABLEEND, 22}; 23 24static int 25helper_parse(int c, char **argv, int invert, unsigned int *flags, 26 const void *entry, struct xt_entry_match **match) 27{ 28 struct xt_helper_info *info = (struct xt_helper_info *)(*match)->data; 29 30 switch (c) { 31 case '1': 32 if (*flags) 33 xtables_error(PARAMETER_PROBLEM, 34 "helper match: Only use --helper ONCE!"); 35 xtables_check_inverse(optarg, &invert, &optind, 0, argv); 36 strncpy(info->name, optarg, 29); 37 info->name[29] = '\0'; 38 if (invert) 39 info->invert = 1; 40 *flags = 1; 41 break; 42 } 43 return 1; 44} 45 46static void helper_check(unsigned int flags) 47{ 48 if (!flags) 49 xtables_error(PARAMETER_PROBLEM, 50 "helper match: You must specify `--helper'"); 51} 52 53static void 54helper_print(const void *ip, const struct xt_entry_match *match, int numeric) 55{ 56 const struct xt_helper_info *info = (const void *)match->data; 57 58 printf("helper match %s\"%s\" ", info->invert ? "! " : "", info->name); 59} 60 61static void helper_save(const void *ip, const struct xt_entry_match *match) 62{ 63 const struct xt_helper_info *info = (const void *)match->data; 64 65 printf("%s--helper ",info->invert ? "! " : ""); 66 xtables_save_string(info->name); 67} 68 69static struct xtables_match helper_match = { 70 .family = NFPROTO_UNSPEC, 71 .name = "helper", 72 .version = XTABLES_VERSION, 73 .size = XT_ALIGN(sizeof(struct xt_helper_info)), 74 .help = helper_help, 75 .parse = helper_parse, 76 .final_check = helper_check, 77 .print = helper_print, 78 .save = helper_save, 79 .extra_opts = helper_opts, 80}; 81 82void _init(void) 83{ 84 xtables_register_match(&helper_match); 85} 86