예제 #1
0
파일: ebt_among.c 프로젝트: ebichu/dd-wrt
static int compare(const struct ebt_entry_match *m1,
		   const struct ebt_entry_match *m2)
{
	struct ebt_among_info *a = (struct ebt_among_info *) m1->data;
	struct ebt_among_info *b = (struct ebt_among_info *) m2->data;

	if (!compare_wh(ebt_among_wh_dst(a), ebt_among_wh_dst(b)))
		return 0;
	if (!compare_wh(ebt_among_wh_src(a), ebt_among_wh_src(b)))
		return 0;
	if (a->bitmask != b->bitmask)
		return 0;
	return 1;
}
예제 #2
0
static int ebt_among_mt_check(const struct xt_mtchk_param *par) {
  const struct ebt_among_info *info = par->matchinfo;
  const struct ebt_entry_match *em =
    container_of(par->matchinfo, const struct ebt_entry_match, data);
  int expected_length = sizeof(struct ebt_among_info);
  const struct ebt_mac_wormhash *wh_dst, *wh_src;
  int err;

  wh_dst = ebt_among_wh_dst(info);
  wh_src = ebt_among_wh_src(info);
  expected_length += ebt_mac_wormhash_size(wh_dst);
  expected_length += ebt_mac_wormhash_size(wh_src);

  if (em->match_size != EBT_ALIGN(expected_length)) {
    pr_info("wrong size: %d against expected %d, rounded to %Zd\n",
            em->match_size, expected_length,
            EBT_ALIGN(expected_length));
    return -EINVAL;
  }
  if (wh_dst && (err = ebt_mac_wormhash_check_integrity(wh_dst))) {
    pr_info("dst integrity fail: %x\n", -err);
    return -EINVAL;
  }
  if (wh_src && (err = ebt_mac_wormhash_check_integrity(wh_src))) {
    pr_info("src integrity fail: %x\n", -err);
    return -EINVAL;
  }
  return 0;
}
예제 #3
0
static bool ebt_among_mt_check(const struct xt_mtchk_param *par)
{
	const struct ebt_among_info *info = par->matchinfo;
	const struct ebt_entry_match *em =
		container_of(par->matchinfo, const struct ebt_entry_match, data);
	int expected_length = sizeof(struct ebt_among_info);
	const struct ebt_mac_wormhash *wh_dst, *wh_src;
	int err;

	wh_dst = ebt_among_wh_dst(info);
	wh_src = ebt_among_wh_src(info);
	expected_length += ebt_mac_wormhash_size(wh_dst);
	expected_length += ebt_mac_wormhash_size(wh_src);

	if (em->match_size != EBT_ALIGN(expected_length)) {
		printk(KERN_WARNING
		       "ebtables: among: wrong size: %d "
		       "against expected %d, rounded to %Zd\n",
		       em->match_size, expected_length,
		       EBT_ALIGN(expected_length));
		return false;
	}
	if (wh_dst && (err = ebt_mac_wormhash_check_integrity(wh_dst))) {
		printk(KERN_WARNING
		       "ebtables: among: dst integrity fail: %x\n", -err);
		return false;
	}
	if (wh_src && (err = ebt_mac_wormhash_check_integrity(wh_src))) {
		printk(KERN_WARNING
		       "ebtables: among: src integrity fail: %x\n", -err);
		return false;
	}
	return true;
}
예제 #4
0
static int ebt_among_check(const char *tablename, unsigned int hookmask,
			   const struct ebt_entry *e, void *data,
			   unsigned int datalen)
{
	const struct ebt_among_info *info = data;
	int expected_length = sizeof(struct ebt_among_info);
	const struct ebt_mac_wormhash *wh_dst, *wh_src;
	int err;

	wh_dst = ebt_among_wh_dst(info);
	wh_src = ebt_among_wh_src(info);
	expected_length += ebt_mac_wormhash_size(wh_dst);
	expected_length += ebt_mac_wormhash_size(wh_src);

	if (datalen != EBT_ALIGN(expected_length)) {
		printk(KERN_WARNING
		       "ebtables: among: wrong size: %d "
		       "against expected %d, rounded to %Zd\n",
		       datalen, expected_length,
		       EBT_ALIGN(expected_length));
		return -EINVAL;
	}
	if (wh_dst && (err = ebt_mac_wormhash_check_integrity(wh_dst))) {
		printk(KERN_WARNING
		       "ebtables: among: dst integrity fail: %x\n", -err);
		return -EINVAL;
	}
	if (wh_src && (err = ebt_mac_wormhash_check_integrity(wh_src))) {
		printk(KERN_WARNING
		       "ebtables: among: src integrity fail: %x\n", -err);
		return -EINVAL;
	}
	return 0;
}
예제 #5
0
static bool
ebt_among_mt(const struct sk_buff *skb, struct xt_action_param *par) {
  const struct ebt_among_info *info = par->matchinfo;
  const char *dmac, *smac;
  const struct ebt_mac_wormhash *wh_dst, *wh_src;
  __be32 dip = 0, sip = 0;

  wh_dst = ebt_among_wh_dst(info);
  wh_src = ebt_among_wh_src(info);

  if (wh_src) {
    smac = eth_hdr(skb)->h_source;
    if (get_ip_src(skb, &sip)) {
      return false;
    }
    if (!(info->bitmask & EBT_AMONG_SRC_NEG)) {
      /* we match only if it contains */
      if (!ebt_mac_wormhash_contains(wh_src, smac, sip)) {
        return false;
      }
    } else {
      /* we match only if it DOES NOT contain */
      if (ebt_mac_wormhash_contains(wh_src, smac, sip)) {
        return false;
      }
    }
  }

  if (wh_dst) {
    dmac = eth_hdr(skb)->h_dest;
    if (get_ip_dst(skb, &dip)) {
      return false;
    }
    if (!(info->bitmask & EBT_AMONG_DST_NEG)) {
      /* we match only if it contains */
      if (!ebt_mac_wormhash_contains(wh_dst, dmac, dip)) {
        return false;
      }
    } else {
      /* we match only if it DOES NOT contain */
      if (ebt_mac_wormhash_contains(wh_dst, dmac, dip)) {
        return false;
      }
    }
  }

  return true;
}
예제 #6
0
static int ebt_filter_among(const struct sk_buff *skb,
			    const struct net_device *in,
			    const struct net_device *out, const void *data,
			    unsigned int datalen)
{
	const struct ebt_among_info *info = data;
	const char *dmac, *smac;
	const struct ebt_mac_wormhash *wh_dst, *wh_src;
	__be32 dip = 0, sip = 0;

	wh_dst = ebt_among_wh_dst(info);
	wh_src = ebt_among_wh_src(info);

	if (wh_src) {
		smac = eth_hdr(skb)->h_source;
		if (get_ip_src(skb, &sip))
			return EBT_NOMATCH;
		if (!(info->bitmask & EBT_AMONG_SRC_NEG)) {
			/* we match only if it contains */
			if (!ebt_mac_wormhash_contains(wh_src, smac, sip))
				return EBT_NOMATCH;
		} else {
			/* we match only if it DOES NOT contain */
			if (ebt_mac_wormhash_contains(wh_src, smac, sip))
				return EBT_NOMATCH;
		}
	}

	if (wh_dst) {
		dmac = eth_hdr(skb)->h_dest;
		if (get_ip_dst(skb, &dip))
			return EBT_NOMATCH;
		if (!(info->bitmask & EBT_AMONG_DST_NEG)) {
			/* we match only if it contains */
			if (!ebt_mac_wormhash_contains(wh_dst, dmac, dip))
				return EBT_NOMATCH;
		} else {
			/* we match only if it DOES NOT contain */
			if (ebt_mac_wormhash_contains(wh_dst, dmac, dip))
				return EBT_NOMATCH;
		}
	}

	return EBT_MATCH;
}
예제 #7
0
파일: ebt_among.c 프로젝트: ebichu/dd-wrt
static void print(const struct ebt_u_entry *entry,
		  const struct ebt_entry_match *match)
{
	struct ebt_among_info *info = (struct ebt_among_info *)match->data;

	if (info->wh_dst_ofs) {
		printf("--among-dst ");
		if (info->bitmask && EBT_AMONG_DST_NEG) {
			printf("! ");
		}
		wormhash_printout(ebt_among_wh_dst(info));
	}
	if (info->wh_src_ofs) {
		printf("--among-src ");
		if (info->bitmask && EBT_AMONG_SRC_NEG) {
			printf("! ");
		}
		wormhash_printout(ebt_among_wh_src(info));
	}
}