pf: add pf_find_state_all_exists
Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate")
This commit is contained in:
parent
1e67e3109d
commit
19d6e29b87
@ -1591,6 +1591,8 @@ pf_release_staten(struct pf_kstate *s, u_int n)
|
|||||||
extern struct pf_kstate *pf_find_state_byid(uint64_t, uint32_t);
|
extern struct pf_kstate *pf_find_state_byid(uint64_t, uint32_t);
|
||||||
extern struct pf_kstate *pf_find_state_all(struct pf_state_key_cmp *,
|
extern struct pf_kstate *pf_find_state_all(struct pf_state_key_cmp *,
|
||||||
u_int, int *);
|
u_int, int *);
|
||||||
|
extern bool pf_find_state_all_exists(struct pf_state_key_cmp *,
|
||||||
|
u_int);
|
||||||
extern struct pf_ksrc_node *pf_find_src_node(struct pf_addr *,
|
extern struct pf_ksrc_node *pf_find_src_node(struct pf_addr *,
|
||||||
struct pf_krule *, sa_family_t, int);
|
struct pf_krule *, sa_family_t, int);
|
||||||
extern void pf_unlink_src_node(struct pf_ksrc_node *);
|
extern void pf_unlink_src_node(struct pf_ksrc_node *);
|
||||||
|
@ -1453,6 +1453,15 @@ pf_find_state_all(struct pf_state_key_cmp *key, u_int dir, int *more)
|
|||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
pf_find_state_all_exists(struct pf_state_key_cmp *key, u_int dir)
|
||||||
|
{
|
||||||
|
struct pf_kstate *s;
|
||||||
|
|
||||||
|
s = pf_find_state_all(key, dir, NULL);
|
||||||
|
return (s != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* END state table stuff */
|
/* END state table stuff */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -244,13 +244,13 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_krule *r,
|
|||||||
* (traceroute -I through nat)
|
* (traceroute -I through nat)
|
||||||
*/
|
*/
|
||||||
key.port[1] = sport;
|
key.port[1] = sport;
|
||||||
if (pf_find_state_all(&key, PF_IN, NULL) == NULL) {
|
if (!pf_find_state_all_exists(&key, PF_IN)) {
|
||||||
*nport = sport;
|
*nport = sport;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
} else if (low == high) {
|
} else if (low == high) {
|
||||||
key.port[1] = htons(low);
|
key.port[1] = htons(low);
|
||||||
if (pf_find_state_all(&key, PF_IN, NULL) == NULL) {
|
if (!pf_find_state_all_exists(&key, PF_IN)) {
|
||||||
*nport = htons(low);
|
*nport = htons(low);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -268,8 +268,7 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_krule *r,
|
|||||||
/* low <= cut <= high */
|
/* low <= cut <= high */
|
||||||
for (tmp = cut; tmp <= high && tmp <= 0xffff; ++tmp) {
|
for (tmp = cut; tmp <= high && tmp <= 0xffff; ++tmp) {
|
||||||
key.port[1] = htons(tmp);
|
key.port[1] = htons(tmp);
|
||||||
if (pf_find_state_all(&key, PF_IN, NULL) ==
|
if (!pf_find_state_all_exists(&key, PF_IN)) {
|
||||||
NULL) {
|
|
||||||
*nport = htons(tmp);
|
*nport = htons(tmp);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -277,8 +276,7 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_krule *r,
|
|||||||
tmp = cut;
|
tmp = cut;
|
||||||
for (tmp -= 1; tmp >= low && tmp <= 0xffff; --tmp) {
|
for (tmp -= 1; tmp >= low && tmp <= 0xffff; --tmp) {
|
||||||
key.port[1] = htons(tmp);
|
key.port[1] = htons(tmp);
|
||||||
if (pf_find_state_all(&key, PF_IN, NULL) ==
|
if (!pf_find_state_all_exists(&key, PF_IN)) {
|
||||||
NULL) {
|
|
||||||
*nport = htons(tmp);
|
*nport = htons(tmp);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user