Lines Matching refs:cb

29 #define XTOPT_MKPTR(cb) \
30 ((void *)((char *)(cb)->data + (cb)->entry->ptroff))
172 static void xtopt_parse_int(struct xt_option_call *cb)
174 const struct xt_option_entry *entry = cb->entry;
178 if (cb->entry->min != 0)
179 lmin = cb->entry->min;
180 if (cb->entry->max != 0)
181 lmax = cb->entry->max;
183 if (!xtables_strtoul(cb->arg, NULL, &value, lmin, lmax))
187 cb->ext_name, entry->name, lmin, lmax);
190 cb->val.u8 = value;
192 *(uint8_t *)XTOPT_MKPTR(cb) = cb->val.u8;
194 cb->val.u16 = value;
196 *(uint16_t *)XTOPT_MKPTR(cb) = cb->val.u16;
198 cb->val.u32 = value;
200 *(uint32_t *)XTOPT_MKPTR(cb) = cb->val.u32;
202 cb->val.u64 = value;
204 *(uint64_t *)XTOPT_MKPTR(cb) = cb->val.u64;
211 static void xtopt_parse_float(struct xt_option_call *cb)
213 const struct xt_option_entry *entry = cb->entry;
217 value = strtod(cb->arg, &end);
218 if (end == cb->arg || *end != '\0' ||
224 cb->ext_name, entry->name, entry->min, entry->max);
226 cb->val.dbl = value;
228 *(double *)XTOPT_MKPTR(cb) = cb->val.dbl;
232 * Copy the parsed value to the appropriate entry in cb->val.
234 static void xtopt_mint_value_to_cb(struct xt_option_call *cb, uintmax_t value)
236 const struct xt_option_entry *entry = cb->entry;
238 if (cb->nvals >= ARRAY_SIZE(cb->val.u32_range))
241 cb->val.u8_range[cb->nvals] = value;
243 cb->val.u16_range[cb->nvals] = value;
245 cb->val.u32_range[cb->nvals] = value;
247 cb->val.u64_range[cb->nvals] = value;
253 static void xtopt_mint_value_to_ptr(struct xt_option_call *cb, void **datap,
256 const struct xt_option_entry *entry = cb->entry;
277 * two values from the string will be put into @cb however (and as such,
278 * @cb->val.uXX_range is just that large) to cater for the few extensions that
282 static void xtopt_parse_mint(struct xt_option_call *cb)
284 const struct xt_option_entry *entry = cb->entry;
285 const char *arg = cb->arg;
288 void *put = XTOPT_MKPTR(cb);
296 maxiter = ARRAY_SIZE(cb->val.u32_range);
301 cb->nvals = 0;
302 for (arg = cb->arg, end = (char *)arg; ; arg = end + 1) {
303 if (cb->nvals == maxiter)
306 cb->ext_name, entry->name, maxiter);
310 value = (cb->nvals == 1) ? lmax : 0;
316 cb->ext_name, entry->name, arg, lmax);
321 cb->ext_name, entry->name, end);
323 xtopt_mint_value_to_cb(cb, value);
324 ++cb->nvals;
325 xtopt_mint_value_to_ptr(cb, &put, value);
331 static void xtopt_parse_string(struct xt_option_call *cb)
333 const struct xt_option_entry *entry = cb->entry;
334 size_t z = strlen(cb->arg);
349 p = XTOPT_MKPTR(cb);
350 strncpy(p, cb->arg, z);
373 static bool tos_parse_numeric(const char *str, struct xt_option_call *cb,
380 cb->val.tos_value = value;
381 cb->val.tos_mask = max;
389 cb->val.tos_mask = value;
402 static void xtopt_parse_tosmask(struct xt_option_call *cb)
407 if (xtables_strtoui(cb->arg, &tmp, NULL, 0, UINT8_MAX)) {
408 tos_parse_numeric(cb->arg, cb, UINT8_MAX);
415 cb->val.tos_mask = cb->entry->max;
417 if (strcasecmp(cb->arg, symbol->name) == 0) {
418 cb->val.tos_value = symbol->value;
423 cb->arg);
429 static void xtopt_parse_markmask(struct xt_option_call *cb)
434 if (!xtables_strtoui(cb->arg, &end, &mark, 0, UINT32_MAX))
438 cb->ext_name, cb->entry->name);
444 cb->ext_name, cb->entry->name);
449 cb->ext_name, cb->entry->name);
450 cb->val.mark = mark;
451 cb->val.mask = mask;
462 static void xtopt_parse_sysloglevel(struct xt_option_call *cb)
478 if (!xtables_strtoui(cb->arg, NULL, &num, 0, 7)) {
479 e = bsearch(cb->arg, log_names, ARRAY_SIZE(log_names),
483 "log level \"%s\" unknown\n", cb->arg);
486 cb->val.syslog_level = num;
487 if (cb->entry->flags & XTOPT_PUT)
488 *(uint8_t *)XTOPT_MKPTR(cb) = num;
511 * result is stored in @cb->val.haddr. Additionally, @cb->val.hmask and
512 * @cb->val.hlen are set for completeness to the appropriate values.
514 static void xtopt_parse_host(struct xt_option_call *cb)
521 ret = getaddrinfo(cb->arg, NULL, &hints, &res);
526 memset(&cb->val.hmask, 0xFF, sizeof(cb->val.hmask));
527 cb->val.hlen = (afinfo->family == NFPROTO_IPV4) ? 32 : 128;
531 memset(&cb->val.haddr, 0, sizeof(cb->val.haddr));
532 memcpy(&cb->val.haddr,
538 if (memcmp(&cb->val.haddr,
543 cb->arg);
547 if (cb->entry->flags & XTOPT_PUT)
549 memcpy(XTOPT_MKPTR(cb), &cb->val.haddr,
550 sizeof(cb->val.haddr));
585 * /etc/protocols and put the result into @cb->val.protocol.
587 static void xtopt_parse_protocol(struct xt_option_call *cb)
589 cb->val.protocol = xtables_parse_protocol(cb->arg);
590 if (cb->entry->flags & XTOPT_PUT)
591 *(uint8_t *)XTOPT_MKPTR(cb) = cb->val.protocol;
596 * @cb->val.port.
598 static void xtopt_parse_port(struct xt_option_call *cb)
600 const struct xt_option_entry *entry = cb->entry;
603 ret = xtables_getportbyname(cb->arg);
607 cb->arg);
610 cb->val.port = ret;
612 *(uint16_t *)XTOPT_MKPTR(cb) = cb->val.port;
615 static void xtopt_parse_mport(struct xt_option_call *cb)
618 const struct xt_option_entry *entry = cb->entry;
623 wp_arg = lo_arg = strdup(cb->arg);
629 maxiter = 2; /* ARRAY_SIZE(cb->val.port_range) */
634 cb->val.port_range[0] = 0;
635 cb->val.port_range[1] = UINT16_MAX;
636 cb->nvals = 0;
639 if (cb->nvals == maxiter)
642 cb->ext_name, entry->name, maxiter);
644 ++cb->nvals;
655 if (cb->nvals < ARRAY_SIZE(cb->val.port_range))
656 cb->val.port_range[cb->nvals] = value;
657 ++cb->nvals;
660 if (cb->nvals == 1) {
661 cb->val.port_range[1] = cb->val.port_range[0];
662 ++cb->nvals;
665 memcpy(XTOPT_MKPTR(cb), cb->val.port_range, sizeof(uint16_t) *
666 (cb->nvals <= maxiter ? cb->nvals : maxiter));
670 static int xtopt_parse_mask(struct xt_option_call *cb)
677 ret = getaddrinfo(cb->arg, NULL, &hints, &res);
681 memcpy(&cb->val.hmask, xtables_sa_host(res->ai_addr, res->ai_family),
686 cb->val.hlen = xtables_ipmask_to_cidr(&cb->val.hmask.in);
689 cb->val.hlen = xtables_ip6mask_to_cidr(&cb->val.hmask.in6);
699 * limits. The result is stored in @cb->val.hlen.
701 static void xtopt_parse_plen(struct xt_option_call *cb)
703 const struct xt_option_entry *entry = cb->entry;
706 cb->val.hlen = (afinfo->family == NFPROTO_IPV4) ? 32 : 128;
707 if (!xtables_strtoui(cb->arg, NULL, &prefix_len, 0, cb->val.hlen)) {
709 if (xtopt_parse_mask(cb))
716 cb->ext_name, entry->name, 0, cb->val.hlen);
718 cb->val.hlen = prefix_len;
723 * a bitmask, and make it available through @cb->val.hmask (hlen remains
726 static void xtopt_parse_plenmask(struct xt_option_call *cb)
728 const struct xt_option_entry *entry = cb->entry;
729 uint32_t *mask = cb->val.hmask.all;
731 xtopt_parse_plen(cb);
735 if (cb->val.hlen == 0) {
737 } else if (cb->val.hlen <= 32) {
738 mask[0] <<= 32 - cb->val.hlen;
740 } else if (cb->val.hlen <= 64) {
741 mask[1] <<= 32 - (cb->val.hlen - 32);
743 } else if (cb->val.hlen <= 96) {
744 mask[2] <<= 32 - (cb->val.hlen - 64);
746 } else if (cb->val.hlen <= 128) {
747 mask[3] <<= 32 - (cb->val.hlen - 96);
754 memcpy(XTOPT_MKPTR(cb), mask, sizeof(union nf_inet_addr));
757 static void xtopt_parse_hostmask(struct xt_option_call *cb)
759 const char *orig_arg = cb->arg;
762 if (strchr(cb->arg, '/') == NULL) {
763 xtopt_parse_host(cb);
777 cb->arg = work;
778 xtopt_parse_host(cb);
779 cb->arg = p;
780 xtopt_parse_plenmask(cb);
781 cb->arg = orig_arg;
784 static void xtopt_parse_ethermac(struct xt_option_call *cb)
786 const char *arg = cb->arg;
790 for (i = 0; i < ARRAY_SIZE(cb->val.ethermac) - 1; ++i) {
791 cb->val.ethermac[i] = strtoul(arg, &end, 16);
796 i = ARRAY_SIZE(cb->val.ethermac) - 1;
797 cb->val.ethermac[i] = strtoul(arg, &end, 16);
800 if (cb->entry->flags & XTOPT_PUT)
801 memcpy(XTOPT_MKPTR(cb), cb->val.ethermac,
802 sizeof(cb->val.ethermac));
837 void xtables_option_parse(struct xt_option_call *cb)
839 const struct xt_option_entry *entry = cb->entry;
840 unsigned int eflag = 1 << cb->entry->id;
849 cb->xflags & eflag)
852 cb->ext_name, cb->entry->name);
853 if (cb->invert && !(entry->flags & XTOPT_INVERT))
856 cb->ext_name, entry->name);
860 cb->ext_name, entry->name);
866 cb->nvals = 1;
869 xtopt_subparse[entry->type](cb);
871 cb->xflags |= 1 << entry->id;
934 struct xt_option_call cb;
944 cb.entry = xtables_option_lookup(t->x6_options, c);
945 if (cb.entry == NULL)
948 cb.arg = optarg;
949 cb.invert = invert;
950 cb.ext_name = t->name;
951 cb.data = t->t->data;
952 cb.xflags = t->tflags;
953 cb.target = &t->t;
954 cb.xt_entry = fw;
955 cb.udata = t->udata;
956 t->x6_parse(&cb);
957 t->tflags = cb.xflags;
970 struct xt_option_call cb;
980 cb.entry = xtables_option_lookup(m->x6_options, c);
981 if (cb.entry == NULL)
984 cb.arg = optarg;
985 cb.invert = invert;
986 cb.ext_name = m->name;
987 cb.data = m->m->data;
988 cb.xflags = m->mflags;
989 cb.match = &m->m;
990 cb.xt_entry = fw;
991 cb.udata = m->udata;
992 m->x6_parse(&cb);
993 m->mflags = cb.xflags;
1072 struct xt_fcheck_call cb;
1074 cb.ext_name = t->name;
1075 cb.data = t->t->data;
1076 cb.xflags = t->tflags;
1077 cb.udata = t->udata;
1078 t->x6_fcheck(&cb);
1093 struct xt_fcheck_call cb;
1095 cb.ext_name = m->name;
1096 cb.data = m->m->data;
1097 cb.xflags = m->mflags;
1098 cb.udata = m->udata;
1099 m->x6_fcheck(&cb);