-/* $OpenBSD: pf_lb.c,v 1.42 2015/03/14 03:38:51 jsg Exp $ */
+/* $OpenBSD: pf_lb.c,v 1.43 2015/06/03 11:57:37 yasuoka Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
case PF_POOL_RANDOM:
if (rpool->addr.type == PF_ADDR_TABLE) {
cnt = rpool->addr.p.tbl->pfrkt_cnt;
- rpool->tblidx = (int)arc4random_uniform(cnt);
+ if (cnt == 0)
+ rpool->tblidx = 0;
+ else
+ rpool->tblidx = (int)arc4random_uniform(cnt);
memset(&rpool->counter, 0, sizeof(rpool->counter));
if (pfr_pool_get(rpool, &raddr, &rmask, af))
return (1);
PF_ACPY(naddr, &rpool->counter, af);
} else if (rpool->addr.type == PF_ADDR_DYNIFTL) {
cnt = rpool->addr.p.dyn->pfid_kt->pfrkt_cnt;
- rpool->tblidx = (int)arc4random_uniform(cnt);
+ if (cnt == 0)
+ rpool->tblidx = 0;
+ else
+ rpool->tblidx = (int)arc4random_uniform(cnt);
memset(&rpool->counter, 0, sizeof(rpool->counter));
if (pfr_pool_get(rpool, &raddr, &rmask, af))
return (1);
pf_hash(saddr, (struct pf_addr *)&hash, &rpool->key, af);
if (rpool->addr.type == PF_ADDR_TABLE) {
cnt = rpool->addr.p.tbl->pfrkt_cnt;
- rpool->tblidx = (int)(hashidx % cnt);
+ if (cnt == 0)
+ rpool->tblidx = 0;
+ else
+ rpool->tblidx = (int)(hashidx % cnt);
memset(&rpool->counter, 0, sizeof(rpool->counter));
if (pfr_pool_get(rpool, &raddr, &rmask, af))
return (1);
PF_ACPY(naddr, &rpool->counter, af);
} else if (rpool->addr.type == PF_ADDR_DYNIFTL) {
cnt = rpool->addr.p.dyn->pfid_kt->pfrkt_cnt;
- rpool->tblidx = (int)(hashidx % cnt);
+ if (cnt == 0)
+ rpool->tblidx = 0;
+ else
+ rpool->tblidx = (int)(hashidx % cnt);
memset(&rpool->counter, 0, sizeof(rpool->counter));
if (pfr_pool_get(rpool, &raddr, &rmask, af))
return (1);