IPMARK: rebuild parameter structure (fixed-size types)

Rebuild the parameter structure to have fixed-size members only.
This commit is contained in:
Jan Engelhardt
2008-04-08 19:23:07 +02:00
parent d432d8041a
commit e037035bd4
3 changed files with 36 additions and 39 deletions

View File

@@ -40,12 +40,9 @@ static struct option opts[] = {
static void
init(struct xt_entry_target *t)
{
struct ipt_ipmark_target_info *ipmarkinfo =
(struct ipt_ipmark_target_info *)t->data;
ipmarkinfo->andmask=0xffffffff;
ipmarkinfo->ormask=0;
struct xt_ipmark_tginfo *info = (void *)t->data;
info->andmask = ~0U;
}
/* Function which parses command options; returns true if it
@@ -54,14 +51,13 @@ static int
parse(int c, char **argv, int invert, unsigned int *flags,
const void *entry, struct xt_entry_target **target)
{
struct ipt_ipmark_target_info *ipmarkinfo
= (struct ipt_ipmark_target_info *)(*target)->data;
struct xt_ipmark_tginfo *info = (void *)(*target)->data;
switch (c) {
char *end;
case '1':
if(!strcmp(optarg, "src")) ipmarkinfo->addr=IPT_IPMARK_SRC;
else if(!strcmp(optarg, "dst")) ipmarkinfo->addr=IPT_IPMARK_DST;
if(!strcmp(optarg, "src")) info->selector=XT_IPMARK_SRC;
else if(!strcmp(optarg, "dst")) info->selector=XT_IPMARK_DST;
else exit_error(PARAMETER_PROBLEM, "Bad addr value `%s' - should be `src' or `dst'", optarg);
if (*flags & IPT_ADDR_USED)
exit_error(PARAMETER_PROBLEM,
@@ -70,7 +66,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
break;
case '2':
ipmarkinfo->andmask = strtoul(optarg, &end, 0);
info->andmask = strtoul(optarg, &end, 0);
if (*end != '\0' || end == optarg)
exit_error(PARAMETER_PROBLEM, "Bad and-mask value `%s'", optarg);
if (*flags & IPT_AND_MASK_USED)
@@ -79,7 +75,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
*flags |= IPT_AND_MASK_USED;
break;
case '3':
ipmarkinfo->ormask = strtoul(optarg, &end, 0);
info->ormask = strtoul(optarg, &end, 0);
if (*end != '\0' || end == optarg)
exit_error(PARAMETER_PROBLEM, "Bad or-mask value `%s'", optarg);
if (*flags & IPT_OR_MASK_USED)
@@ -111,39 +107,38 @@ static void
print(const void *entry, const struct xt_entry_target *target,
int numeric)
{
const struct ipt_ipmark_target_info *ipmarkinfo =
(const struct ipt_ipmark_target_info *)target->data;
const struct xt_ipmark_tginfo *info = (const void *)target->data;
if(ipmarkinfo->addr == IPT_IPMARK_SRC)
if (info->selector == XT_IPMARK_SRC)
printf("IPMARK src");
else
printf("IPMARK dst");
printf(" ip and 0x%lx or 0x%lx", ipmarkinfo->andmask, ipmarkinfo->ormask);
printf(" ip and 0x%x or 0x%x",
(unsigned int)info->andmask, (unsigned int)info->ormask);
}
/* Saves the union ipt_targinfo in parsable form to stdout. */
static void
save(const void *entry, const struct xt_entry_target *target)
{
const struct ipt_ipmark_target_info *ipmarkinfo =
(const struct ipt_ipmark_target_info *)target->data;
const struct xt_ipmark_tginfo *info = (const void *)target->data;
if(ipmarkinfo->addr == IPT_IPMARK_SRC)
if (info->selector == XT_IPMARK_SRC)
printf("--addr=src ");
else
printf("--addr=dst ");
if(ipmarkinfo->andmask != 0xffffffff)
printf("--and-mask 0x%lx ", ipmarkinfo->andmask);
if(ipmarkinfo->ormask != 0)
printf("--or-mask 0x%lx ", ipmarkinfo->ormask);
if (info->andmask != ~0U)
printf("--and-mask 0x%x ", (unsigned int)info->andmask);
if (info->ormask != 0)
printf("--or-mask 0x%x ", (unsigned int)info->ormask);
}
static struct xtables_target ipmark = {
.next = NULL,
.name = "IPMARK",
.version = XTABLES_VERSION,
.size = XT_ALIGN(sizeof(struct ipt_ipmark_target_info)),
.userspacesize = XT_ALIGN(sizeof(struct ipt_ipmark_target_info)),
.size = XT_ALIGN(sizeof(struct xt_ipmark_tginfo)),
.userspacesize = XT_ALIGN(sizeof(struct xt_ipmark_tginfo)),
.help = &help,
.init = &init,
.parse = &parse,

View File

@@ -20,14 +20,14 @@ ipmark_tg(struct sk_buff *skb,
const struct xt_target *target,
const void *targinfo)
{
const struct ipt_ipmark_target_info *ipmarkinfo = targinfo;
const struct xt_ipmark_tginfo *ipmarkinfo = targinfo;
struct iphdr *iph = ip_hdr(skb);
unsigned long mark;
__u32 mark;
if (ipmarkinfo->addr == IPT_IPMARK_SRC)
mark = (unsigned long) ntohl(iph->saddr);
if (ipmarkinfo->selector == XT_IPMARK_SRC)
mark = ntohl(iph->saddr);
else
mark = (unsigned long) ntohl(iph->daddr);
mark = ntohl(iph->daddr);
mark &= ipmarkinfo->andmask;
mark |= ipmarkinfo->ormask;
@@ -41,7 +41,7 @@ static struct xt_target ipt_ipmark_reg = {
.family = AF_INET,
.table = "mangle",
.target = ipmark_tg,
.targetsize = sizeof(struct ipt_ipmark_target_info),
.targetsize = sizeof(struct xt_ipmark_tginfo),
.me = THIS_MODULE
};

View File

@@ -1,13 +1,15 @@
#ifndef _IPT_IPMARK_H_target
#define _IPT_IPMARK_H_target
#ifndef _LINUX_NETFILTER_XT_IPMARK_H
#define _LINUX_NETFILTER_XT_IPMARK_H 1
struct ipt_ipmark_target_info {
unsigned long andmask;
unsigned long ormask;
unsigned char addr;
enum {
XT_IPMARK_SRC,
XT_IPMARK_DST,
};
#define IPT_IPMARK_SRC 0
#define IPT_IPMARK_DST 1
struct xt_ipmark_tginfo {
__u32 andmask;
__u32 ormask;
__u8 selector;
};
#endif /*_IPT_IPMARK_H_target*/
#endif /* _LINUX_NETFILTER_XT_IPMARK_H */