|
Packit |
7b22a4 |
/* Shared library add-on to iptables to add comment match support.
|
|
Packit |
7b22a4 |
*
|
|
Packit |
7b22a4 |
* ChangeLog
|
|
Packit |
7b22a4 |
* 2003-05-13: Brad Fisher <brad@info-link.net>
|
|
Packit |
7b22a4 |
* Initial comment match
|
|
Packit |
7b22a4 |
* 2004-05-12: Brad Fisher <brad@info-link.net>
|
|
Packit |
7b22a4 |
* Port to patch-o-matic-ng
|
|
Packit |
7b22a4 |
*/
|
|
Packit |
7b22a4 |
#include <stdio.h>
|
|
Packit |
7b22a4 |
#include <xtables.h>
|
|
Packit |
7b22a4 |
#include <linux/netfilter/xt_comment.h>
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
enum {
|
|
Packit |
7b22a4 |
O_COMMENT = 0,
|
|
Packit |
7b22a4 |
};
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
static void comment_help(void)
|
|
Packit |
7b22a4 |
{
|
|
Packit |
7b22a4 |
printf(
|
|
Packit |
7b22a4 |
"comment match options:\n"
|
|
Packit |
7b22a4 |
"--comment COMMENT Attach a comment to a rule\n");
|
|
Packit |
7b22a4 |
}
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
static const struct xt_option_entry comment_opts[] = {
|
|
Packit |
7b22a4 |
{.name = "comment", .id = O_COMMENT, .type = XTTYPE_STRING,
|
|
Packit |
7b22a4 |
.flags = XTOPT_MAND | XTOPT_PUT,
|
|
Packit |
7b22a4 |
XTOPT_POINTER(struct xt_comment_info, comment)},
|
|
Packit |
7b22a4 |
XTOPT_TABLEEND,
|
|
Packit |
7b22a4 |
};
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
static void
|
|
Packit |
7b22a4 |
comment_print(const void *ip, const struct xt_entry_match *match, int numeric)
|
|
Packit |
7b22a4 |
{
|
|
Packit |
7b22a4 |
struct xt_comment_info *commentinfo = (void *)match->data;
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
commentinfo->comment[XT_MAX_COMMENT_LEN-1] = '\0';
|
|
Packit |
7b22a4 |
printf(" /* %s */", commentinfo->comment);
|
|
Packit |
7b22a4 |
}
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
/* Saves the union ipt_matchinfo in parsable form to stdout. */
|
|
Packit |
7b22a4 |
static void
|
|
Packit |
7b22a4 |
comment_save(const void *ip, const struct xt_entry_match *match)
|
|
Packit |
7b22a4 |
{
|
|
Packit |
7b22a4 |
struct xt_comment_info *commentinfo = (void *)match->data;
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
commentinfo->comment[XT_MAX_COMMENT_LEN-1] = '\0';
|
|
Packit |
7b22a4 |
printf(" --comment");
|
|
Packit |
7b22a4 |
xtables_save_string(commentinfo->comment);
|
|
Packit |
7b22a4 |
}
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
static int comment_xlate(struct xt_xlate *xl,
|
|
Packit |
7b22a4 |
const struct xt_xlate_mt_params *params)
|
|
Packit |
7b22a4 |
{
|
|
Packit |
7b22a4 |
struct xt_comment_info *commentinfo = (void *)params->match->data;
|
|
Packit |
7b22a4 |
char comment[XT_MAX_COMMENT_LEN + sizeof("\\\"\\\"")];
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
commentinfo->comment[XT_MAX_COMMENT_LEN - 1] = '\0';
|
|
Packit |
7b22a4 |
if (params->escape_quotes)
|
|
Packit |
7b22a4 |
snprintf(comment, sizeof(comment), "\\\"%s\\\"",
|
|
Packit |
7b22a4 |
commentinfo->comment);
|
|
Packit |
7b22a4 |
else
|
|
Packit |
7b22a4 |
snprintf(comment, sizeof(comment), "\"%s\"",
|
|
Packit |
7b22a4 |
commentinfo->comment);
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
xt_xlate_add_comment(xl, comment);
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
return 1;
|
|
Packit |
7b22a4 |
}
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
static struct xtables_match comment_match = {
|
|
Packit |
7b22a4 |
.family = NFPROTO_UNSPEC,
|
|
Packit |
7b22a4 |
.name = "comment",
|
|
Packit |
7b22a4 |
.version = XTABLES_VERSION,
|
|
Packit |
7b22a4 |
.size = XT_ALIGN(sizeof(struct xt_comment_info)),
|
|
Packit |
7b22a4 |
.userspacesize = XT_ALIGN(sizeof(struct xt_comment_info)),
|
|
Packit |
7b22a4 |
.help = comment_help,
|
|
Packit |
7b22a4 |
.print = comment_print,
|
|
Packit |
7b22a4 |
.save = comment_save,
|
|
Packit |
7b22a4 |
.x6_parse = xtables_option_parse,
|
|
Packit |
7b22a4 |
.x6_options = comment_opts,
|
|
Packit |
7b22a4 |
.xlate = comment_xlate,
|
|
Packit |
7b22a4 |
};
|
|
Packit |
7b22a4 |
|
|
Packit |
7b22a4 |
void _init(void)
|
|
Packit |
7b22a4 |
{
|
|
Packit |
7b22a4 |
xtables_register_match(&comment_match);
|
|
Packit |
7b22a4 |
}
|