summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2005-05-23 22:30:22 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2005-05-23 22:30:22 +0000
commit7f4309c14cafdbcf2c6baed1c5f294d6990408f3 (patch)
tree7b6bbe6556c0c930cc3b91dfe50f41b52ba07c25
parenta3d5c9d34c3b6e23d37073fd3bec7cd84017d8ba (diff)
further cleanup: don't mimic ifnet and add hooks and the dohooks() stuff to
pf's interface abstraction, just attahc a linked list of the dynaddrs to the respective kifs. makes things way easier and will be needed for the next step, ryan jajajaja
-rw-r--r--sys/net/pf_if.c52
-rw-r--r--sys/net/pfvar.h29
2 files changed, 37 insertions, 44 deletions
diff --git a/sys/net/pf_if.c b/sys/net/pf_if.c
index dfddc47579f..8d9ba2b3871 100644
--- a/sys/net/pf_if.c
+++ b/sys/net/pf_if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_if.c,v 1.29 2005/05/23 20:40:13 henning Exp $ */
+/* $OpenBSD: pf_if.c,v 1.30 2005/05/23 22:30:21 henning Exp $ */
/*
* Copyright 2005 Henning Brauer <henning@openbsd.org>
@@ -67,7 +67,7 @@ struct pfr_addr *pfi_buffer;
int pfi_buffer_cnt;
int pfi_buffer_max;
-void pfi_dynaddr_update(void *);
+void pfi_dynaddr_update(struct pfi_dynaddr *dyn);
void pfi_table_update(struct pfr_ktable *, struct pfi_kif *,
int, int);
void pfi_kifaddr_update(void *);
@@ -117,15 +117,7 @@ pfi_kif_get(char *kif_name)
bzero(kif, sizeof(*kif));
strlcpy(kif->pfik_name, kif_name, sizeof(kif->pfik_name));
kif->pfik_tzero = time_second;
-
- if ((kif->pfik_ah_head = malloc(sizeof(*kif->pfik_ah_head), PFI_MTYPE,
- M_DONTWAIT)) == NULL) {
- free(kif, PFI_MTYPE);
- return (NULL);
- }
-
- bzero(kif->pfik_ah_head, sizeof(*kif->pfik_ah_head));
- TAILQ_INIT(kif->pfik_ah_head);
+ TAILQ_INIT(&kif->pfik_dynaddrs);
RB_INSERT(pfi_ifhead, &pfi_ifs, kif);
@@ -183,7 +175,6 @@ pfi_kif_unref(struct pfi_kif *kif, enum pfi_kif_refs what)
return;
RB_REMOVE(pfi_ifhead, &pfi_ifs, kif);
- free(kif->pfik_ah_head, PFI_MTYPE);
free(kif, PFI_MTYPE);
}
@@ -206,8 +197,9 @@ pfi_kif_match(struct pfi_kif *rule_kif, struct pfi_kif *packet_kif)
void
pfi_attach_ifnet(struct ifnet *ifp)
{
- struct pfi_kif *kif;
- int s;
+ struct pfi_kif *kif;
+ struct pfi_dynaddr *dyn;
+ int s;
pfi_initialize();
s = splsoftnet();
@@ -222,7 +214,9 @@ pfi_attach_ifnet(struct ifnet *ifp)
pfi_kifaddr_update, kif)) == NULL)
panic("pfi_attach_ifnet: cannot allocate '%s' address hook",
ifp->if_xname);
- dohooks(kif->pfik_ah_head, 0);
+
+ TAILQ_FOREACH(dyn, &kif->pfik_dynaddrs, entry)
+ pfi_dynaddr_update(dyn);
splx(s);
}
@@ -230,8 +224,9 @@ pfi_attach_ifnet(struct ifnet *ifp)
void
pfi_detach_ifnet(struct ifnet *ifp)
{
- int s;
- struct pfi_kif *kif;
+ int s;
+ struct pfi_kif *kif;
+ struct pfi_dynaddr *dyn;
if ((kif = (struct pfi_kif *)ifp->if_pf_kif) == NULL)
return;
@@ -239,7 +234,8 @@ pfi_detach_ifnet(struct ifnet *ifp)
s = splsoftnet();
pfi_update++;
hook_disestablish(ifp->if_addrhooks, kif->pfik_ah_cookie);
- dohooks(kif->pfik_ah_head, 0);
+ TAILQ_FOREACH(dyn, &kif->pfik_dynaddrs, entry)
+ pfi_dynaddr_update(dyn);
pfi_kif_unref(kif, PFI_KIF_REF_NONE);
kif->pfik_ifp = NULL;
@@ -371,13 +367,8 @@ pfi_dynaddr_setup(struct pf_addr_wrap *aw, sa_family_t af)
dyn->pfid_kt->pfrkt_flags |= PFR_TFLAG_ACTIVE;
dyn->pfid_iflags = aw->iflags;
dyn->pfid_af = af;
- dyn->pfid_hook_cookie = hook_establish(dyn->pfid_kif->pfik_ah_head, 1,
- pfi_dynaddr_update, dyn);
- if (dyn->pfid_hook_cookie == NULL) {
- rv = 1;
- goto _bad;
- }
+ TAILQ_INSERT_TAIL(&dyn->pfid_kif->pfik_dynaddrs, dyn, entry);
aw->p.dyn = dyn;
pfi_dynaddr_update(aw->p.dyn);
splx(s);
@@ -396,9 +387,8 @@ _bad:
}
void
-pfi_dynaddr_update(void *p)
+pfi_dynaddr_update(struct pfi_dynaddr *dyn)
{
- struct pfi_dynaddr *dyn = (struct pfi_dynaddr *)p;
struct pfi_kif *kif;
struct pfr_ktable *kt;
@@ -559,8 +549,7 @@ pfi_dynaddr_remove(struct pf_addr_wrap *aw)
return;
s = splsoftnet();
- hook_disestablish(aw->p.dyn->pfid_kif->pfik_ah_head,
- aw->p.dyn->pfid_hook_cookie);
+ TAILQ_REMOVE(&aw->p.dyn->pfid_kif->pfik_dynaddrs, aw->p.dyn, entry);
pfi_kif_unref(aw->p.dyn->pfid_kif, PFI_KIF_REF_RULE);
aw->p.dyn->pfid_kif = NULL;
pfr_detach_table(aw->p.dyn->pfid_kt);
@@ -582,11 +571,14 @@ pfi_dynaddr_copyout(struct pf_addr_wrap *aw)
void
pfi_kifaddr_update(void *v)
{
- int s;
+ int s;
+ struct pfi_kif *kif = (struct pfi_kif *)v;
+ struct pfi_dynaddr *dyn;
s = splsoftnet();
pfi_update++;
- dohooks(((struct pfi_kif *)v)->pfik_ah_head, 0);
+ TAILQ_FOREACH(dyn, &kif->pfik_dynaddrs, entry)
+ pfi_dynaddr_update(dyn);
splx(s);
}
diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h
index 71a85ecf7ab..bde89c0863e 100644
--- a/sys/net/pfvar.h
+++ b/sys/net/pfvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfvar.h,v 1.215 2005/05/22 18:23:04 henning Exp $ */
+/* $OpenBSD: pfvar.h,v 1.216 2005/05/23 22:30:21 henning Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -152,18 +152,19 @@ struct pf_addr_wrap {
#ifdef _KERNEL
struct pfi_dynaddr {
- struct pf_addr pfid_addr4;
- struct pf_addr pfid_mask4;
- struct pf_addr pfid_addr6;
- struct pf_addr pfid_mask6;
- struct pfr_ktable *pfid_kt;
- struct pfi_kif *pfid_kif;
- void *pfid_hook_cookie;
- int pfid_net; /* optional mask, or 128 */
- int pfid_acnt4; /* address count, IPv4 */
- int pfid_acnt6; /* address count, IPv6 */
- sa_family_t pfid_af; /* rule address family */
- u_int8_t pfid_iflags; /* PFI_AFLAG_* */
+ TAILQ_ENTRY(pfi_dynaddr) entry;
+ struct pf_addr pfid_addr4;
+ struct pf_addr pfid_mask4;
+ struct pf_addr pfid_addr6;
+ struct pf_addr pfid_mask6;
+ struct pfr_ktable *pfid_kt;
+ struct pfi_kif *pfid_kif;
+ void *pfid_hook_cookie;
+ int pfid_net; /* mask or 128 */
+ int pfid_acnt4; /* address count IPv4 */
+ int pfid_acnt6; /* address count IPv6 */
+ sa_family_t pfid_af; /* rule af */
+ u_int8_t pfid_iflags; /* PFI_AFLAG_* */
};
/*
@@ -858,12 +859,12 @@ struct pfi_kif {
struct pf_state_tree_lan_ext pfik_lan_ext;
struct pf_state_tree_ext_gwy pfik_ext_gwy;
TAILQ_ENTRY(pfi_kif) pfik_w_states;
- struct hook_desc_head *pfik_ah_head;
void *pfik_ah_cookie;
struct ifnet *pfik_ifp;
struct ifg_group *pfik_group;
int pfik_states;
int pfik_rules;
+ TAILQ_HEAD(, pfi_dynaddr) pfik_dynaddrs;
};
enum pfi_kif_refs {