static int brip_parse(int c, char **argv, int invert, unsigned int *flags, const void *entry, struct xt_entry_match **match) { struct ebt_ip_info *info = (struct ebt_ip_info *)(*match)->data; switch (c) { case IP_SOURCE: if (invert) info->invflags |= EBT_IP_SOURCE; ebt_parse_ip_address(optarg, &info->saddr, &info->smsk); info->bitmask |= EBT_IP_SOURCE; break; case IP_DEST: if (invert) info->invflags |= EBT_IP_DEST; ebt_parse_ip_address(optarg, &info->daddr, &info->dmsk); info->bitmask |= EBT_IP_DEST; break; case IP_SPORT: if (invert) info->invflags |= EBT_IP_SPORT; parse_port_range(NULL, optarg, info->sport); info->bitmask |= EBT_IP_SPORT; break; case IP_DPORT: if (invert) info->invflags |= EBT_IP_DPORT; parse_port_range(NULL, optarg, info->dport); info->bitmask |= EBT_IP_DPORT; break; case IP_EBT_TOS: if (invert) info->invflags |= EBT_IP_TOS; if (!xtables_strtoul(optarg, NULL, (uintmax_t *)&info->tos, 0, 255)) xtables_error(PARAMETER_PROBLEM, "Problem with specified IP tos"); info->bitmask |= EBT_IP_TOS; break; case IP_PROTO: if (invert) info->invflags |= EBT_IP_PROTO; info->protocol = xtables_parse_protocol(optarg); if (info->protocol == -1) xtables_error(PARAMETER_PROBLEM, "Unknown specified IP protocol - %s", optarg); info->bitmask |= EBT_IP_PROTO; break; default: return 0; } *flags |= info->bitmask; return 1; }
static int parse(int c, char **argv, int argc, const struct ebt_u_entry *entry, unsigned int *flags, struct ebt_entry_match **match) { struct ebt_ip6_info *ipinfo = (struct ebt_ip6_info *)(*match)->data; char *end; long int i; switch (c) { case IP_SOURCE: ebt_check_option2(flags, OPT_SOURCE); ipinfo->bitmask |= EBT_IP6_SOURCE; if (ebt_check_inverse2(optarg)) { ipinfo->invflags |= EBT_IP6_SOURCE; } ebt_parse_ip6_address(optarg, &ipinfo->saddr, &ipinfo->smsk); break; case IP_DEST: ebt_check_option2(flags, OPT_DEST); ipinfo->bitmask |= EBT_IP6_DEST; if (ebt_check_inverse2(optarg)) { ipinfo->invflags |= EBT_IP6_DEST; } ebt_parse_ip6_address(optarg, &ipinfo->daddr, &ipinfo->dmsk); break; case IP_SPORT: case IP_DPORT: if (c == IP_SPORT) { ebt_check_option2(flags, OPT_SPORT); ipinfo->bitmask |= EBT_IP6_SPORT; if (ebt_check_inverse2(optarg)) ipinfo->invflags |= EBT_IP6_SPORT; } else { ebt_check_option2(flags, OPT_DPORT); ipinfo->bitmask |= EBT_IP6_DPORT; if (ebt_check_inverse2(optarg)) ipinfo->invflags |= EBT_IP6_DPORT; } if (c == IP_SPORT) parse_port_range(NULL, optarg, ipinfo->sport); else parse_port_range(NULL, optarg, ipinfo->dport); break; case IP_TCLASS: ebt_check_option2(flags, OPT_TCLASS); if (ebt_check_inverse2(optarg)) ipinfo->invflags |= EBT_IP6_TCLASS; i = strtol(optarg, &end, 16); if (i < 0 || i > 255 || *end != '\0') ebt_print_error2("Problem with specified IPv6 traffic class"); ipinfo->tclass = i; ipinfo->bitmask |= EBT_IP6_TCLASS; break; case IP_PROTO: ebt_check_option2(flags, OPT_PROTO); if (ebt_check_inverse2(optarg)) ipinfo->invflags |= EBT_IP6_PROTO; i = strtoul(optarg, &end, 10); if (*end != '\0') { struct protoent *pe; pe = getprotobyname(optarg); if (pe == NULL) ebt_print_error("Unknown specified IP protocol - %s", argv[optind - 1]); ipinfo->protocol = pe->p_proto; } else { ipinfo->protocol = (unsigned char) i; } ipinfo->bitmask |= EBT_IP6_PROTO; break; default: return 0; } return 1; }
static int parse(int c, char **argv, int argc, const struct ebt_u_entry *entry, unsigned int *flags, struct ebt_entry_match **match) { struct ebt_ip_info *ipinfo = (struct ebt_ip_info *)(*match)->data; char *end; long int i; switch (c) { case IP_SOURCE: check_option(flags, OPT_SOURCE); ipinfo->bitmask |= EBT_IP_SOURCE; case IP_DEST: if (c == IP_DEST) { check_option(flags, OPT_DEST); ipinfo->bitmask |= EBT_IP_DEST; } if (check_inverse(optarg)) { if (c == IP_SOURCE) ipinfo->invflags |= EBT_IP_SOURCE; else ipinfo->invflags |= EBT_IP_DEST; } if (optind > argc) print_error("Missing IP address argument"); if (c == IP_SOURCE) parse_ip_address(argv[optind - 1], &ipinfo->saddr, &ipinfo->smsk); else parse_ip_address(argv[optind - 1], &ipinfo->daddr, &ipinfo->dmsk); break; case IP_SPORT: case IP_DPORT: if (c == IP_SPORT) { check_option(flags, OPT_SPORT); ipinfo->bitmask |= EBT_IP_SPORT; if (check_inverse(optarg)) ipinfo->invflags |= EBT_IP_SPORT; } else { check_option(flags, OPT_DPORT); ipinfo->bitmask |= EBT_IP_DPORT; if (check_inverse(optarg)) ipinfo->invflags |= EBT_IP_DPORT; } if (optind > argc) print_error("Missing port argument"); if (c == IP_SPORT) parse_port_range(NULL, argv[optind - 1], ipinfo->sport); else parse_port_range(NULL, argv[optind - 1], ipinfo->dport); break; case IP_myTOS: check_option(flags, OPT_TOS); if (check_inverse(optarg)) ipinfo->invflags |= EBT_IP_TOS; if (optind > argc) print_error("Missing IP tos argument"); i = strtol(argv[optind - 1], &end, 16); if (i < 0 || i > 255 || *end != '\0') print_error("Problem with specified IP tos"); ipinfo->tos = i; ipinfo->bitmask |= EBT_IP_TOS; break; case IP_myDSCP: /* brcm */ check_option(flags, OPT_DSCP); if (check_inverse(optarg)) ipinfo->invflags |= EBT_IP_DSCP; if (optind > argc) print_error("Missing IP dscp argument"); i = strtol(argv[optind - 1], &end, 16); if (i < 0 || i > 255 || (i & 0x3) || *end != '\0') print_error("Problem with specified IP dscp"); ipinfo->dscp = i; ipinfo->bitmask |= EBT_IP_DSCP; break; case IP_PROTO: check_option(flags, OPT_PROTO); if (check_inverse(optarg)) ipinfo->invflags |= EBT_IP_PROTO; if (optind > argc) print_error("Missing IP protocol argument"); i = strtoul(argv[optind - 1], &end, 10); if (*end != '\0') { struct protoent *pe; pe = getprotobyname(argv[optind - 1]); if (pe == NULL) print_error ("Unknown specified IP protocol - %s", argv[optind - 1]); ipinfo->protocol = pe->p_proto; } else { ipinfo->protocol = (unsigned char) i; } ipinfo->bitmask |= EBT_IP_PROTO; break; default: return 0; } return 1; }