summaryrefslogtreecommitdiff
path: root/sys/net
diff options
context:
space:
mode:
authormvs <mvs@cvs.openbsd.org>2020-07-24 18:17:16 +0000
committermvs <mvs@cvs.openbsd.org>2020-07-24 18:17:16 +0000
commit4d197a94287f7314327ee06ffb48d36fdf9b74b2 (patch)
tree17903fcf8ca2d1b8856ee6e38ba4e3778dd56f83 /sys/net
parentf17d71dd0ed4d38d10059f6942259e3de2764ca0 (diff)
Use interface index instead of pointer to `ifnet' in carp(4).
ok sashan@
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/if.c7
-rw-r--r--sys/net/if_var.h7
-rw-r--r--sys/net/pf.c24
3 files changed, 23 insertions, 15 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 51ec987c37d..a38bd144869 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.615 2020/07/22 02:16:01 dlg Exp $ */
+/* $OpenBSD: if.c,v 1.616 2020/07/24 18:17:14 mvs Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -1125,8 +1125,9 @@ if_isconnected(const struct ifnet *ifp0, unsigned int ifidx)
connected = 1;
#endif
#if NCARP > 0
- if ((ifp0->if_type == IFT_CARP && ifp0->if_carpdev == ifp) ||
- (ifp->if_type == IFT_CARP && ifp->if_carpdev == ifp0))
+ if ((ifp0->if_type == IFT_CARP &&
+ ifp0->if_carpdevidx == ifp->if_index) ||
+ (ifp->if_type == IFT_CARP && ifp->if_carpdevidx == ifp0->if_index))
connected = 1;
#endif
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index a132b1a3801..64ad80a313c 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_var.h,v 1.110 2020/07/22 02:16:02 dlg Exp $ */
+/* $OpenBSD: if_var.h,v 1.111 2020/07/24 18:17:15 mvs Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
@@ -139,10 +139,11 @@ struct ifnet { /* and the entries */
caddr_t if_pf_kif; /* pf interface abstraction */
union {
struct srpl carp_s; /* carp if list (used by !carp ifs) */
- struct ifnet *carp_d; /* ptr to carpdev (used by carp ifs) */
+ int carp_idx; /* index of carpdev (used by carp
+ ifs) */
} if_carp_ptr;
#define if_carp if_carp_ptr.carp_s
-#define if_carpdev if_carp_ptr.carp_d
+#define if_carpdevidx if_carp_ptr.carp_idx
unsigned int if_index; /* [I] unique index for this if */
short if_timer; /* time 'til if_watchdog called */
unsigned short if_flags; /* [N] up/down, broadcast, etc. */
diff --git a/sys/net/pf.c b/sys/net/pf.c
index 034c138e234..823fdc22133 100644
--- a/sys/net/pf.c
+++ b/sys/net/pf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf.c,v 1.1093 2020/06/24 22:03:42 cheloha Exp $ */
+/* $OpenBSD: pf.c,v 1.1094 2020/07/24 18:17:15 mvs Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -3081,7 +3081,7 @@ pf_match_tag(struct mbuf *m, struct pf_rule *r, int *tag)
int
pf_match_rcvif(struct mbuf *m, struct pf_rule *r)
{
- struct ifnet *ifp;
+ struct ifnet *ifp, *ifp0;
struct pfi_kif *kif;
ifp = if_get(m->m_pkthdr.ph_ifidx);
@@ -3089,9 +3089,11 @@ pf_match_rcvif(struct mbuf *m, struct pf_rule *r)
return (0);
#if NCARP > 0
- if (ifp->if_type == IFT_CARP && ifp->if_carpdev)
- kif = (struct pfi_kif *)ifp->if_carpdev->if_pf_kif;
- else
+ if (ifp->if_type == IFT_CARP &&
+ (ifp0 = if_get(ifp->if_carpdevidx)) != NULL) {
+ kif = (struct pfi_kif *)ifp0->if_pf_kif;
+ if_put(ifp0);
+ } else
#endif /* NCARP */
kif = (struct pfi_kif *)ifp->if_pf_kif;
@@ -5926,7 +5928,8 @@ pf_routable(struct pf_addr *addr, sa_family_t af, struct pfi_kif *kif,
ifp = if_get(rt->rt_ifidx);
if (ifp != NULL && ifp->if_type == IFT_CARP &&
- ifp->if_carpdev == kif->pfik_ifp)
+ ifp->if_carpdevidx ==
+ kif->pfik_ifp->if_index)
ret = 1;
if_put(ifp);
#endif /* NCARP */
@@ -6852,6 +6855,7 @@ pf_counters_inc(int action, struct pf_pdesc *pd, struct pf_state *s,
int
pf_test(sa_family_t af, int fwdir, struct ifnet *ifp, struct mbuf **m0)
{
+ struct ifnet *ifp0;
struct pfi_kif *kif;
u_short action, reason = 0;
struct pf_rule *a = NULL, *r = &pf_default_rule;
@@ -6866,9 +6870,11 @@ pf_test(sa_family_t af, int fwdir, struct ifnet *ifp, struct mbuf **m0)
return (PF_PASS);
#if NCARP > 0
- if (ifp->if_type == IFT_CARP && ifp->if_carpdev)
- kif = (struct pfi_kif *)ifp->if_carpdev->if_pf_kif;
- else
+ if (ifp->if_type == IFT_CARP &&
+ (ifp0 = if_get(ifp->if_carpdevidx)) != NULL) {
+ kif = (struct pfi_kif *)ifp0->if_pf_kif;
+ if_put(ifp0);
+ } else
#endif /* NCARP */
kif = (struct pfi_kif *)ifp->if_pf_kif;