aboutsummaryrefslogtreecommitdiffstats
path: root/extensions/libip6t_LOG.c
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/libip6t_LOG.c')
-rw-r--r--extensions/libip6t_LOG.c140
1 files changed, 56 insertions, 84 deletions
diff --git a/extensions/libip6t_LOG.c b/extensions/libip6t_LOG.c
index 5043b44..423d988 100644
--- a/extensions/libip6t_LOG.c
+++ b/extensions/libip6t_LOG.c
@@ -1,12 +1,11 @@
-/* Shared library add-on to iptables to add LOG support. */
+/* Shared library add-on to ip6tables to add LOG support. */
#include <stdio.h>
#include <netdb.h>
#include <string.h>
#include <stdlib.h>
#include <syslog.h>
#include <getopt.h>
-#include <ip6tables.h>
-#include <linux/netfilter_ipv6/ip6_tables.h>
+#include <xtables.h>
#include <linux/netfilter_ipv6/ip6t_LOG.h>
#ifndef IP6T_LOG_UID /* Old kernel */
@@ -17,34 +16,29 @@
#define LOG_DEFAULT_LEVEL LOG_WARNING
-/* Function which prints out usage message. */
-static void
-help(void)
+static void LOG_help(void)
{
printf(
-"LOG v%s options:\n"
+"LOG target options:\n"
" --log-level level Level of logging (numeric or see syslog.conf)\n"
-" --log-prefix prefix Prefix log messages with this prefix.\n\n"
-" --log-tcp-sequence Log TCP sequence numbers.\n\n"
-" --log-tcp-options Log TCP options.\n\n"
-" --log-ip-options Log IP options.\n\n"
-" --log-uid Log UID owning the local socket.\n\n",
-IPTABLES_VERSION);
+" --log-prefix prefix Prefix log messages with this prefix.\n"
+" --log-tcp-sequence Log TCP sequence numbers.\n"
+" --log-tcp-options Log TCP options.\n"
+" --log-ip-options Log IP options.\n"
+" --log-uid Log UID owning the local socket.\n");
}
-static struct option opts[] = {
- { .name = "log-level", .has_arg = 1, .flag = 0, .val = '!' },
- { .name = "log-prefix", .has_arg = 1, .flag = 0, .val = '#' },
- { .name = "log-tcp-sequence", .has_arg = 0, .flag = 0, .val = '1' },
- { .name = "log-tcp-options", .has_arg = 0, .flag = 0, .val = '2' },
- { .name = "log-ip-options", .has_arg = 0, .flag = 0, .val = '3' },
- { .name = "log-uid", .has_arg = 0, .flag = 0, .val = '4' },
- { .name = 0 }
+static const struct option LOG_opts[] = {
+ { .name = "log-level", .has_arg = 1, .val = '!' },
+ { .name = "log-prefix", .has_arg = 1, .val = '#' },
+ { .name = "log-tcp-sequence", .has_arg = 0, .val = '1' },
+ { .name = "log-tcp-options", .has_arg = 0, .val = '2' },
+ { .name = "log-ip-options", .has_arg = 0, .val = '3' },
+ { .name = "log-uid", .has_arg = 0, .val = '4' },
+ { .name = NULL }
};
-/* Initialize the target. */
-static void
-init(struct ip6t_entry_target *t, unsigned int *nfcache)
+static void LOG_init(struct xt_entry_target *t)
{
struct ip6t_log_info *loginfo = (struct ip6t_log_info *)t->data;
@@ -57,7 +51,7 @@ struct ip6t_log_names {
unsigned int level;
};
-static struct ip6t_log_names ip6t_log_names[]
+static const struct ip6t_log_names ip6t_log_names[]
= { { .name = "alert", .level = LOG_ALERT },
{ .name = "crit", .level = LOG_CRIT },
{ .name = "debug", .level = LOG_DEBUG },
@@ -75,28 +69,25 @@ parse_level(const char *level)
unsigned int lev = -1;
unsigned int set = 0;
- if (string_to_number(level, 0, 7, &lev) == -1) {
+ if (!xtables_strtoui(level, NULL, &lev, 0, 7)) {
unsigned int i = 0;
- for (i = 0;
- i < sizeof(ip6t_log_names) / sizeof(struct ip6t_log_names);
- i++) {
+ for (i = 0; i < ARRAY_SIZE(ip6t_log_names); ++i)
if (strncasecmp(level, ip6t_log_names[i].name,
strlen(level)) == 0) {
if (set++)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"log-level `%s' ambiguous",
level);
lev = ip6t_log_names[i].level;
}
- }
if (!set)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"log-level `%s' unknown", level);
}
- return (u_int8_t)lev;
+ return lev;
}
#define IP6T_LOG_OPT_LEVEL 0x01
@@ -106,23 +97,19 @@ parse_level(const char *level)
#define IP6T_LOG_OPT_IPOPT 0x10
#define IP6T_LOG_OPT_UID 0x20
-/* Function which parses command options; returns true if it
- ate an option */
-static int
-parse(int c, char **argv, int invert, unsigned int *flags,
- const struct ip6t_entry *entry,
- struct ip6t_entry_target **target)
+static int LOG_parse(int c, char **argv, int invert, unsigned int *flags,
+ const void *entry, struct xt_entry_target **target)
{
struct ip6t_log_info *loginfo = (struct ip6t_log_info *)(*target)->data;
switch (c) {
case '!':
if (*flags & IP6T_LOG_OPT_LEVEL)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"Can't specify --log-level twice");
- if (check_inverse(optarg, &invert, NULL, 0))
- exit_error(PARAMETER_PROBLEM,
+ if (xtables_check_inverse(optarg, &invert, NULL, 0, argv))
+ xtables_error(PARAMETER_PROBLEM,
"Unexpected `!' after --log-level");
loginfo->level = parse_level(optarg);
@@ -131,24 +118,24 @@ parse(int c, char **argv, int invert, unsigned int *flags,
case '#':
if (*flags & IP6T_LOG_OPT_PREFIX)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"Can't specify --log-prefix twice");
- if (check_inverse(optarg, &invert, NULL, 0))
- exit_error(PARAMETER_PROBLEM,
+ if (xtables_check_inverse(optarg, &invert, NULL, 0, argv))
+ xtables_error(PARAMETER_PROBLEM,
"Unexpected `!' after --log-prefix");
if (strlen(optarg) > sizeof(loginfo->prefix) - 1)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"Maximum prefix length %u for --log-prefix",
(unsigned int)sizeof(loginfo->prefix) - 1);
if (strlen(optarg) == 0)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"No prefix specified for --log-prefix");
if (strlen(optarg) != strlen(strtok(optarg, "\n")))
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"Newlines not allowed in --log-prefix");
strcpy(loginfo->prefix, optarg);
@@ -157,7 +144,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
case '1':
if (*flags & IP6T_LOG_OPT_TCPSEQ)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"Can't specify --log-tcp-sequence "
"twice");
@@ -167,7 +154,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
case '2':
if (*flags & IP6T_LOG_OPT_TCPOPT)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"Can't specify --log-tcp-options twice");
loginfo->logflags |= IP6T_LOG_TCPOPT;
@@ -176,7 +163,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
case '3':
if (*flags & IP6T_LOG_OPT_IPOPT)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"Can't specify --log-ip-options twice");
loginfo->logflags |= IP6T_LOG_IPOPT;
@@ -185,7 +172,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
case '4':
if (*flags & IP6T_LOG_OPT_UID)
- exit_error(PARAMETER_PROBLEM,
+ xtables_error(PARAMETER_PROBLEM,
"Can't specify --log-uid twice");
loginfo->logflags |= IP6T_LOG_UID;
@@ -199,16 +186,8 @@ parse(int c, char **argv, int invert, unsigned int *flags,
return 1;
}
-/* Final check; nothing. */
-static void final_check(unsigned int flags)
-{
-}
-
-/* Prints out the targinfo. */
-static void
-print(const struct ip6t_ip6 *ip,
- const struct ip6t_entry_target *target,
- int numeric)
+static void LOG_print(const void *ip, const struct xt_entry_target *target,
+ int numeric)
{
const struct ip6t_log_info *loginfo
= (const struct ip6t_log_info *)target->data;
@@ -219,15 +198,12 @@ print(const struct ip6t_ip6 *ip,
printf("flags %u level %u ",
loginfo->logflags, loginfo->level);
else {
- for (i = 0;
- i < sizeof(ip6t_log_names) / sizeof(struct ip6t_log_names);
- i++) {
+ for (i = 0; i < ARRAY_SIZE(ip6t_log_names); ++i)
if (loginfo->level == ip6t_log_names[i].level) {
printf("level %s ", ip6t_log_names[i].name);
break;
}
- }
- if (i == sizeof(ip6t_log_names) / sizeof(struct ip6t_log_names))
+ if (i == ARRAY_SIZE(ip6t_log_names))
printf("UNKNOWN level %u ", loginfo->level);
if (loginfo->logflags & IP6T_LOG_TCPSEQ)
printf("tcp-sequence ");
@@ -245,9 +221,7 @@ print(const struct ip6t_ip6 *ip,
printf("prefix `%s' ", loginfo->prefix);
}
-/* Saves the union ip6t_targinfo in parsable form to stdout. */
-static void
-save(const struct ip6t_ip6 *ip, const struct ip6t_entry_target *target)
+static void LOG_save(const void *ip, const struct xt_entry_target *target)
{
const struct ip6t_log_info *loginfo
= (const struct ip6t_log_info *)target->data;
@@ -268,23 +242,21 @@ save(const struct ip6t_ip6 *ip, const struct ip6t_entry_target *target)
printf("--log-uid ");
}
-static
-struct ip6tables_target log
-= {
+static struct xtables_target log_tg6_reg = {
.name = "LOG",
- .version = IPTABLES_VERSION,
- .size = IP6T_ALIGN(sizeof(struct ip6t_log_info)),
- .userspacesize = IP6T_ALIGN(sizeof(struct ip6t_log_info)),
- .help = &help,
- .init = &init,
- .parse = &parse,
- .final_check = &final_check,
- .print = &print,
- .save = &save,
- .extra_opts = opts
+ .version = XTABLES_VERSION,
+ .family = NFPROTO_IPV6,
+ .size = XT_ALIGN(sizeof(struct ip6t_log_info)),
+ .userspacesize = XT_ALIGN(sizeof(struct ip6t_log_info)),
+ .help = LOG_help,
+ .init = LOG_init,
+ .parse = LOG_parse,
+ .print = LOG_print,
+ .save = LOG_save,
+ .extra_opts = LOG_opts,
};
void _init(void)
{
- register_target6(&log);
+ xtables_register_target(&log_tg6_reg);
}