mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-08 13:44:56 +02:00
IPMARK: misc cleanups
- order #include lists - const annotations, removal of casts - add ipt_IPMARK alias - make symbol names distinct
This commit is contained in:
@@ -5,11 +5,10 @@
|
|||||||
*
|
*
|
||||||
* This program is distributed under the terms of GNU GPL
|
* This program is distributed under the terms of GNU GPL
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <xtables.h>
|
#include <xtables.h>
|
||||||
#include "xt_IPMARK.h"
|
#include "xt_IPMARK.h"
|
||||||
|
|
||||||
@@ -18,8 +17,7 @@
|
|||||||
#define IPT_OR_MASK_USED 4
|
#define IPT_OR_MASK_USED 4
|
||||||
|
|
||||||
/* Function which prints out usage message. */
|
/* Function which prints out usage message. */
|
||||||
static void
|
static void ipmark_tg_help(void)
|
||||||
help(void)
|
|
||||||
{
|
{
|
||||||
printf(
|
printf(
|
||||||
"IPMARK target options:\n"
|
"IPMARK target options:\n"
|
||||||
@@ -29,27 +27,23 @@ help(void)
|
|||||||
"\n");
|
"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct option opts[] = {
|
static const struct option ipmark_tg_opts[] = {
|
||||||
{ "addr", 1, 0, '1' },
|
{ "addr", 1, 0, '1' },
|
||||||
{ "and-mask", 1, 0, '2' },
|
{ "and-mask", 1, 0, '2' },
|
||||||
{ "or-mask", 1, 0, '3' },
|
{ "or-mask", 1, 0, '3' },
|
||||||
{ 0 }
|
{NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Initialize the target. */
|
/* Initialize the target. */
|
||||||
static void
|
static void ipmark_tg_init(struct xt_entry_target *t)
|
||||||
init(struct xt_entry_target *t)
|
|
||||||
{
|
{
|
||||||
struct xt_ipmark_tginfo *info = (void *)t->data;
|
struct xt_ipmark_tginfo *info = (void *)t->data;
|
||||||
|
|
||||||
info->andmask = ~0U;
|
info->andmask = ~0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Function which parses command options; returns true if it
|
static int ipmark_tg_parse(int c, char **argv, int invert, unsigned int *flags,
|
||||||
ate an option */
|
const void *entry, struct xt_entry_target **target)
|
||||||
static int
|
|
||||||
parse(int c, char **argv, int invert, unsigned int *flags,
|
|
||||||
const void *entry, struct xt_entry_target **target)
|
|
||||||
{
|
{
|
||||||
struct xt_ipmark_tginfo *info = (void *)(*target)->data;
|
struct xt_ipmark_tginfo *info = (void *)(*target)->data;
|
||||||
|
|
||||||
@@ -91,8 +85,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void ipmark_tg_check(unsigned int flags)
|
||||||
final_check(unsigned int flags)
|
|
||||||
{
|
{
|
||||||
if (!(flags & IPT_ADDR_USED))
|
if (!(flags & IPT_ADDR_USED))
|
||||||
exit_error(PARAMETER_PROBLEM,
|
exit_error(PARAMETER_PROBLEM,
|
||||||
@@ -102,10 +95,9 @@ final_check(unsigned int flags)
|
|||||||
"IPMARK target: Parameter --and-mask or --or-mask is required");
|
"IPMARK target: Parameter --and-mask or --or-mask is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prints out the targinfo. */
|
|
||||||
static void
|
static void
|
||||||
print(const void *entry, const struct xt_entry_target *target,
|
ipmark_tg_print(const void *entry, const struct xt_entry_target *target,
|
||||||
int numeric)
|
int numeric)
|
||||||
{
|
{
|
||||||
const struct xt_ipmark_tginfo *info = (const void *)target->data;
|
const struct xt_ipmark_tginfo *info = (const void *)target->data;
|
||||||
|
|
||||||
@@ -117,9 +109,8 @@ print(const void *entry, const struct xt_entry_target *target,
|
|||||||
(unsigned int)info->andmask, (unsigned int)info->ormask);
|
(unsigned int)info->andmask, (unsigned int)info->ormask);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Saves the union ipt_targinfo in parsable form to stdout. */
|
|
||||||
static void
|
static void
|
||||||
save(const void *entry, const struct xt_entry_target *target)
|
ipmark_tg_save(const void *entry, const struct xt_entry_target *target)
|
||||||
{
|
{
|
||||||
const struct xt_ipmark_tginfo *info = (const void *)target->data;
|
const struct xt_ipmark_tginfo *info = (const void *)target->data;
|
||||||
|
|
||||||
@@ -133,22 +124,23 @@ save(const void *entry, const struct xt_entry_target *target)
|
|||||||
printf("--or-mask 0x%x ", (unsigned int)info->ormask);
|
printf("--or-mask 0x%x ", (unsigned int)info->ormask);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct xtables_target ipmark = {
|
static struct xtables_target ipmark_tg4_reg = {
|
||||||
.next = NULL,
|
|
||||||
.name = "IPMARK",
|
|
||||||
.version = XTABLES_VERSION,
|
.version = XTABLES_VERSION,
|
||||||
|
.name = "IPMARK",
|
||||||
|
.family = PF_INET,
|
||||||
|
.revision = 0,
|
||||||
.size = XT_ALIGN(sizeof(struct xt_ipmark_tginfo)),
|
.size = XT_ALIGN(sizeof(struct xt_ipmark_tginfo)),
|
||||||
.userspacesize = XT_ALIGN(sizeof(struct xt_ipmark_tginfo)),
|
.userspacesize = XT_ALIGN(sizeof(struct xt_ipmark_tginfo)),
|
||||||
.help = &help,
|
.help = ipmark_tg_help,
|
||||||
.init = &init,
|
.init = ipmark_tg_init,
|
||||||
.parse = &parse,
|
.parse = ipmark_tg_parse,
|
||||||
.final_check = &final_check,
|
.final_check = ipmark_tg_check,
|
||||||
.print = &print,
|
.print = ipmark_tg_print,
|
||||||
.save = &save,
|
.save = ipmark_tg_save,
|
||||||
.extra_opts = opts
|
.extra_opts = ipmark_tg_opts,
|
||||||
};
|
};
|
||||||
|
|
||||||
void _init(void)
|
static void _init(void)
|
||||||
{
|
{
|
||||||
xtables_register_target(&ipmark);
|
xtables_register_target(&ipmark_tg4_reg);
|
||||||
}
|
}
|
||||||
|
@@ -1,16 +1,16 @@
|
|||||||
|
#include <linux/ip.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/skbuff.h>
|
#include <linux/skbuff.h>
|
||||||
#include <linux/version.h>
|
#include <linux/version.h>
|
||||||
#include <linux/ip.h>
|
|
||||||
#include <net/checksum.h>
|
|
||||||
|
|
||||||
#include <linux/netfilter/x_tables.h>
|
#include <linux/netfilter/x_tables.h>
|
||||||
|
#include <net/checksum.h>
|
||||||
#include "xt_IPMARK.h"
|
#include "xt_IPMARK.h"
|
||||||
#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("IP tables IPMARK: mark based on ip address");
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
|
MODULE_ALIAS("ipt_IPMARK");
|
||||||
|
|
||||||
static unsigned int
|
static unsigned int
|
||||||
ipmark_tg(struct sk_buff *skb,
|
ipmark_tg(struct sk_buff *skb,
|
||||||
@@ -21,7 +21,7 @@ ipmark_tg(struct sk_buff *skb,
|
|||||||
const void *targinfo)
|
const void *targinfo)
|
||||||
{
|
{
|
||||||
const struct xt_ipmark_tginfo *ipmarkinfo = targinfo;
|
const struct xt_ipmark_tginfo *ipmarkinfo = targinfo;
|
||||||
struct iphdr *iph = ip_hdr(skb);
|
const struct iphdr *iph = ip_hdr(skb);
|
||||||
__u32 mark;
|
__u32 mark;
|
||||||
|
|
||||||
if (ipmarkinfo->selector == XT_IPMARK_SRC)
|
if (ipmarkinfo->selector == XT_IPMARK_SRC)
|
||||||
|
Reference in New Issue
Block a user