From 0545c7c5e14bdc166962f419da77e65fa8d72b8e Mon Sep 17 00:00:00 2001 From: Daniel Hartmeier Date: Sun, 9 Jun 2002 20:20:59 +0000 Subject: Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it includes ports and operator. --- sys/net/pf.c | 36 +++++++++++++++++++++--------------- sys/net/pf_ioctl.c | 34 +++++++++++++++++----------------- sys/net/pfvar.h | 12 ++++-------- 3 files changed, 42 insertions(+), 40 deletions(-) (limited to 'sys/net') diff --git a/sys/net/pf.c b/sys/net/pf.c index 7b4d7705905..bc40a89c46d 100644 --- a/sys/net/pf.c +++ b/sys/net/pf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf.c,v 1.227 2002/06/09 10:55:59 pb Exp $ */ +/* $OpenBSD: pf.c,v 1.228 2002/06/09 20:20:58 dhartmei Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -404,18 +404,22 @@ pf_compare_nats(struct pf_nat *a, struct pf_nat *b) { if (a->proto != b->proto || a->af != b->af || - a->snot != b->snot || - a->dnot != b->dnot || a->ifnot != b->ifnot || a->no != b->no) return (1); - if (PF_ANEQ(&a->saddr.addr, &b->saddr.addr, a->af)) - return (1); - if (PF_ANEQ(&a->smask, &b->smask, a->af)) - return (1); - if (PF_ANEQ(&a->daddr.addr, &b->daddr.addr, a->af)) + if (PF_ANEQ(&a->src.addr.addr, &b->src.addr.addr, a->af) || + PF_ANEQ(&a->src.mask, &b->src.mask, a->af) || + a->src.port[0] != b->src.port[0] || + a->src.port[1] != b->src.port[1] || + a->src.not != b->src.not || + a->src.port_op != b->src.port_op) return (1); - if (PF_ANEQ(&a->dmask, &b->dmask, a->af)) + if (PF_ANEQ(&a->dst.addr.addr, &b->dst.addr.addr, a->af) || + PF_ANEQ(&a->dst.mask, &b->dst.mask, a->af) || + a->dst.port[0] != b->dst.port[0] || + a->dst.port[1] != b->dst.port[1] || + a->dst.not != b->dst.not || + a->dst.port_op != b->dst.port_op) return (1); if (PF_ANEQ(&a->raddr.addr, &b->raddr.addr, a->af)) return (1); @@ -1429,12 +1433,14 @@ pf_get_nat(struct ifnet *ifp, u_int8_t proto, struct pf_addr *saddr, (n->ifp != ifp && n->ifnot)) && (!n->proto || n->proto == proto) && (!n->af || n->af == af) && - (n->saddr.addr_dyn == NULL || - !n->saddr.addr_dyn->undefined) && - PF_MATCHA(n->snot, &n->saddr.addr, &n->smask, saddr, af) && - (n->daddr.addr_dyn == NULL || - !n->daddr.addr_dyn->undefined) && - PF_MATCHA(n->dnot, &n->daddr.addr, &n->dmask, daddr, af)) + (n->src.addr.addr_dyn == NULL || + !n->src.addr.addr_dyn->undefined) && + PF_MATCHA(n->src.not, &n->src.addr.addr, &n->src.mask, + saddr, af) && + (n->dst.addr.addr_dyn == NULL || + !n->dst.addr.addr_dyn->undefined) && + PF_MATCHA(n->dst.not, &n->dst.addr.addr, &n->dst.mask, + daddr, af)) nm = n; else n = TAILQ_NEXT(n, entries); diff --git a/sys/net/pf_ioctl.c b/sys/net/pf_ioctl.c index ba8591dd64c..49017187261 100644 --- a/sys/net/pf_ioctl.c +++ b/sys/net/pf_ioctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf_ioctl.c,v 1.1 2002/06/09 03:57:18 pb Exp $ */ +/* $OpenBSD: pf_ioctl.c,v 1.2 2002/06/09 20:20:58 dhartmei Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -480,8 +480,8 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p) struct pf_nat *nat; while ((nat = TAILQ_FIRST(pf_nats_inactive)) != NULL) { - pf_dynaddr_remove(&nat->saddr); - pf_dynaddr_remove(&nat->daddr); + pf_dynaddr_remove(&nat->src.addr); + pf_dynaddr_remove(&nat->dst.addr); pf_dynaddr_remove(&nat->raddr); TAILQ_REMOVE(pf_nats_inactive, nat, entries); pool_put(&pf_nat_pl, nat); @@ -527,11 +527,11 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p) } } else nat->ifp = NULL; - if (pf_dynaddr_setup(&nat->saddr, nat->af) || - pf_dynaddr_setup(&nat->daddr, nat->af) || + if (pf_dynaddr_setup(&nat->src.addr, nat->af) || + pf_dynaddr_setup(&nat->dst.addr, nat->af) || pf_dynaddr_setup(&nat->raddr, nat->af)) { - pf_dynaddr_remove(&nat->saddr); - pf_dynaddr_remove(&nat->daddr); + pf_dynaddr_remove(&nat->src.addr); + pf_dynaddr_remove(&nat->dst.addr); pf_dynaddr_remove(&nat->raddr); pool_put(&pf_nat_pl, nat); error = EINVAL; @@ -561,8 +561,8 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p) /* Purge the old nat list */ while ((nat = TAILQ_FIRST(old_nats)) != NULL) { - pf_dynaddr_remove(&nat->saddr); - pf_dynaddr_remove(&nat->daddr); + pf_dynaddr_remove(&nat->src.addr); + pf_dynaddr_remove(&nat->dst.addr); pf_dynaddr_remove(&nat->raddr); TAILQ_REMOVE(old_nats, nat, entries); pool_put(&pf_nat_pl, nat); @@ -605,8 +605,8 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p) break; } bcopy(nat, &pn->nat, sizeof(struct pf_nat)); - pf_dynaddr_copyout(&pn->nat.saddr); - pf_dynaddr_copyout(&pn->nat.daddr); + pf_dynaddr_copyout(&pn->nat.src.addr); + pf_dynaddr_copyout(&pn->nat.dst.addr); pf_dynaddr_copyout(&pn->nat.raddr); splx(s); break; @@ -652,11 +652,11 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p) } } else newnat->ifp = NULL; - if (pf_dynaddr_setup(&newnat->saddr, newnat->af) || - pf_dynaddr_setup(&newnat->daddr, newnat->af) || + if (pf_dynaddr_setup(&newnat->src.addr, newnat->af) || + pf_dynaddr_setup(&newnat->dst.addr, newnat->af) || pf_dynaddr_setup(&newnat->raddr, newnat->af)) { - pf_dynaddr_remove(&newnat->saddr); - pf_dynaddr_remove(&newnat->daddr); + pf_dynaddr_remove(&newnat->src.addr); + pf_dynaddr_remove(&newnat->dst.addr); pf_dynaddr_remove(&newnat->raddr); pool_put(&pf_nat_pl, newnat); error = EINVAL; @@ -683,8 +683,8 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p) } if (pcn->action == PF_CHANGE_REMOVE) { - pf_dynaddr_remove(&oldnat->saddr); - pf_dynaddr_remove(&oldnat->daddr); + pf_dynaddr_remove(&oldnat->src.addr); + pf_dynaddr_remove(&oldnat->dst.addr); pf_dynaddr_remove(&oldnat->raddr); TAILQ_REMOVE(pf_nats_active, oldnat, entries); pool_put(&pf_nat_pl, oldnat); diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 0741f8f4ac0..39abee4967c 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pfvar.h,v 1.81 2002/06/09 08:53:08 pb Exp $ */ +/* $OpenBSD: pfvar.h,v 1.82 2002/06/09 20:20:58 dhartmei Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -328,18 +328,14 @@ struct pf_tree_node { struct pf_nat { + struct pf_rule_addr src; + struct pf_rule_addr dst; + struct pf_addr_wrap raddr; char ifname[IFNAMSIZ]; struct ifnet *ifp; TAILQ_ENTRY(pf_nat) entries; - struct pf_addr_wrap saddr; - struct pf_addr_wrap daddr; - struct pf_addr_wrap raddr; - struct pf_addr smask; - struct pf_addr dmask; u_int8_t af; u_int8_t proto; - u_int8_t snot; - u_int8_t dnot; u_int8_t ifnot; u_int8_t no; }; -- cgit v1.2.3