mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-09 06:04:56 +02:00
IPMARK: style cleanup
This commit is contained in:
@@ -12,11 +12,10 @@
|
|||||||
#include <xtables.h>
|
#include <xtables.h>
|
||||||
#include "xt_IPMARK.h"
|
#include "xt_IPMARK.h"
|
||||||
|
|
||||||
#define IPT_ADDR_USED 1
|
|
||||||
#define IPT_AND_MASK_USED 2
|
|
||||||
#define IPT_OR_MASK_USED 4
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
FL_ADDR_USED = 1 << 0,
|
||||||
|
FL_AND_MASK_USED = 1 << 1,
|
||||||
|
FL_OR_MASK_USED = 1 << 2,
|
||||||
FL_SHIFT = 1 << 3,
|
FL_SHIFT = 1 << 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -25,7 +24,7 @@ static void ipmark_tg_help(void)
|
|||||||
{
|
{
|
||||||
printf(
|
printf(
|
||||||
"IPMARK target options:\n"
|
"IPMARK target options:\n"
|
||||||
" --addr src/dst use source or destination ip address\n"
|
" --addr {src|dst} use source or destination ip address\n"
|
||||||
" --and-mask value logical AND ip address with this value becomes MARK\n"
|
" --and-mask value logical AND ip address with this value becomes MARK\n"
|
||||||
" --or-mask value logical OR ip address with this value becomes MARK\n"
|
" --or-mask value logical OR ip address with this value becomes MARK\n"
|
||||||
" --shift value shift address right by value before copying to mark\n"
|
" --shift value shift address right by value before copying to mark\n"
|
||||||
@@ -33,9 +32,9 @@ static void ipmark_tg_help(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct option ipmark_tg_opts[] = {
|
static const struct option ipmark_tg_opts[] = {
|
||||||
{ "addr", 1, 0, '1' },
|
{.name = "addr", .has_arg = true, .val = '1'},
|
||||||
{ "and-mask", 1, 0, '2' },
|
{.name = "and-mask", .has_arg = true, .val = '2'},
|
||||||
{ "or-mask", 1, 0, '3' },
|
{.name = "or-mask", .has_arg = true, .val = '3'},
|
||||||
{.name = "shift", .has_arg = true, .val = '4'},
|
{.name = "shift", .has_arg = true, .val = '4'},
|
||||||
{NULL},
|
{NULL},
|
||||||
};
|
};
|
||||||
@@ -53,36 +52,39 @@ static int ipmark_tg_parse(int c, char **argv, int invert, unsigned int *flags,
|
|||||||
{
|
{
|
||||||
struct xt_ipmark_tginfo *info = (void *)(*target)->data;
|
struct xt_ipmark_tginfo *info = (void *)(*target)->data;
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
|
char *end;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
char *end;
|
|
||||||
case '1':
|
case '1':
|
||||||
if(!strcmp(optarg, "src")) info->selector=XT_IPMARK_SRC;
|
if (strcmp(optarg, "src") == 0)
|
||||||
else if(!strcmp(optarg, "dst")) info->selector=XT_IPMARK_DST;
|
info->selector = XT_IPMARK_SRC;
|
||||||
else exit_error(PARAMETER_PROBLEM, "Bad addr value `%s' - should be `src' or `dst'", optarg);
|
else if (strcmp(optarg, "dst") == 0)
|
||||||
if (*flags & IPT_ADDR_USED)
|
info->selector = XT_IPMARK_DST;
|
||||||
|
else
|
||||||
|
exit_error(PARAMETER_PROBLEM, "Bad addr value `%s' - should be `src' or `dst'", optarg);
|
||||||
|
if (*flags & FL_ADDR_USED)
|
||||||
exit_error(PARAMETER_PROBLEM,
|
exit_error(PARAMETER_PROBLEM,
|
||||||
"IPMARK target: Can't specify --addr twice");
|
"IPMARK target: Can't specify --addr twice");
|
||||||
*flags |= IPT_ADDR_USED;
|
*flags |= FL_ADDR_USED;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '2':
|
case '2':
|
||||||
info->andmask = strtoul(optarg, &end, 0);
|
info->andmask = strtoul(optarg, &end, 0);
|
||||||
if (*end != '\0' || end == optarg)
|
if (*end != '\0' || end == optarg)
|
||||||
exit_error(PARAMETER_PROBLEM, "Bad and-mask value `%s'", optarg);
|
exit_error(PARAMETER_PROBLEM, "Bad and-mask value `%s'", optarg);
|
||||||
if (*flags & IPT_AND_MASK_USED)
|
if (*flags & FL_AND_MASK_USED)
|
||||||
exit_error(PARAMETER_PROBLEM,
|
exit_error(PARAMETER_PROBLEM,
|
||||||
"IPMARK target: Can't specify --and-mask twice");
|
"IPMARK target: Can't specify --and-mask twice");
|
||||||
*flags |= IPT_AND_MASK_USED;
|
*flags |= FL_AND_MASK_USED;
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '3':
|
||||||
info->ormask = strtoul(optarg, &end, 0);
|
info->ormask = strtoul(optarg, &end, 0);
|
||||||
if (*end != '\0' || end == optarg)
|
if (*end != '\0' || end == optarg)
|
||||||
exit_error(PARAMETER_PROBLEM, "Bad or-mask value `%s'", optarg);
|
exit_error(PARAMETER_PROBLEM, "Bad or-mask value `%s'", optarg);
|
||||||
if (*flags & IPT_OR_MASK_USED)
|
if (*flags & FL_OR_MASK_USED)
|
||||||
exit_error(PARAMETER_PROBLEM,
|
exit_error(PARAMETER_PROBLEM,
|
||||||
"IPMARK target: Can't specify --or-mask twice");
|
"IPMARK target: Can't specify --or-mask twice");
|
||||||
*flags |= IPT_OR_MASK_USED;
|
*flags |= FL_OR_MASK_USED;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '4':
|
case '4':
|
||||||
@@ -106,7 +108,7 @@ static int ipmark_tg_parse(int c, char **argv, int invert, unsigned int *flags,
|
|||||||
|
|
||||||
static void ipmark_tg_check(unsigned int flags)
|
static void ipmark_tg_check(unsigned int flags)
|
||||||
{
|
{
|
||||||
if (!(flags & IPT_ADDR_USED))
|
if (!(flags & FL_ADDR_USED))
|
||||||
exit_error(PARAMETER_PROBLEM,
|
exit_error(PARAMETER_PROBLEM,
|
||||||
"IPMARK target: Parameter --addr is required");
|
"IPMARK target: Parameter --addr is required");
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
#include "compat_xtables.h"
|
#include "compat_xtables.h"
|
||||||
|
|
||||||
MODULE_AUTHOR("Grzegorz Janoszka <Grzegorz@Janoszka.pl>");
|
MODULE_AUTHOR("Grzegorz Janoszka <Grzegorz@Janoszka.pl>");
|
||||||
MODULE_DESCRIPTION("IP tables IPMARK: mark based on ip address");
|
MODULE_DESCRIPTION("Xtables: mark based on IP address");
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
MODULE_ALIAS("ipt_IPMARK");
|
MODULE_ALIAS("ipt_IPMARK");
|
||||||
MODULE_ALIAS("ip6t_IPMARK");
|
MODULE_ALIAS("ip6t_IPMARK");
|
||||||
|
Reference in New Issue
Block a user