主要代码:
用户空间;
static int parse(int c, char **argv, int invert,unsigned int *flags,
const struct ipt_entry *entry,unsigned int *nfcache,
struct ipt_entry_match **match)
{
struct ipt_vlan_info *vlaninfo = (struct ipt_vlan_info *) (*match)->data;
char *end;
struct ipt_vlan_info local;
switch (c) {
case VLAN_ID:
if(*flags & OPT_VLAN_ID)
exit_error(PARAMETER_PROBLEM,
"Can't specify --vlan-id twice");
check_inverse(optarg, &invert, &optind, 0);
if(invert){
vlaninfo->invflags |= EBT_VLAN_ID;
}
local.id = strtoul(optarg, &end, 10);
if (local.id > 4094 || *end != '\0')
exit_error(PARAMETER_PROBLEM,
"Invalid --vlan-id range ('%s')", optarg);
vlaninfo->id = local.id;
vlaninfo->bitmask |= EBT_VLAN_ID;
break;
case VLAN_PRIO:
if(*flags & OPT_VLAN_PRIO)
exit_error(PARAMETER_PROBLEM,
"Can't specify --vlan-prio twice");
check_inverse(optarg, &invert, &optind, 0);
if(invert){
vlaninfo->invflags |= EBT_VLAN_PRIO;
}
local.prio = strtoul(optarg, &end, 10);
if (local.prio >= 8 || *end != '\0')
exit_error(PARAMETER_PROBLEM,
"Invalid --vlan-prio range ('%s')", optarg);
vlaninfo->prio = local.prio;
vlaninfo->bitmask |= EBT_VLAN_PRIO;
break;
case VLAN_ENCAP:
if(*flags & OPT_VLAN_ENCAP)
exit_error(PARAMETER_PROBLEM,
"Can't specify --vlan-encap twice");
check_inverse(optarg, &invert, &optind, 0);
if(invert){
vlaninfo->invflags |= EBT_VLAN_ENCAP;
}
local.encap = strtoul(optarg, &end, 16);
if (local.encap < ETH_ZLEN)
exit_error(PARAMETER_PROBLEM,
"Invalid --vlan-encap range ('%s')", optarg);
vlaninfo->encap = htons(local.encap);
vlaninfo->bitmask |= EBT_VLAN_ENCAP;
break;
default:
return 0;
}
return 1;
}
/* Final check; we don't care. */
static void final_check(unsigned int flags)
{
/* Nothing to do */
}
static void print(const struct ipt_ip *ip,
const struct ipt_entry_match *match,
int numeric)
{
struct ipt_vlan_info *vlaninfo = (struct ipt_vlan_info *) match->data;
if (vlaninfo->bitmask & EBT_VLAN_ID) {
printf("--vlan-id %s %d ", (vlaninfo->invflags & EBT_VLAN_ID) ? "! " : "", vlaninfo->id);
}
if (vlaninfo->bitmask & EBT_VLAN_PRIO) {
printf("--vlan-prio %s %d ", (vlaninfo->invflags & EBT_VLAN_PRIO) ? "! " : "", vlaninfo->prio);
}
if (vlaninfo->bitmask & EBT_VLAN_ENCAP) {
printf("--vlan-encap %s ", (vlaninfo->invflags & EBT_VLAN_ENCAP) ? "! " : "");
printf("%4.4X ", ntohs(vlaninfo->encap));
}
}