summaryrefslogtreecommitdiff
path: root/sys/netinet
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2016-01-21 11:23:49 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2016-01-21 11:23:49 +0000
commit77e6310e00ab597c99ff48c7b868dfb82c4e9dc2 (patch)
tree3ba2c287e84d611ce7d5a369212b3aa320425257 /sys/netinet
parent55cb5be27292c957525f7cbf39b8972ee2e579f1 (diff)
Introduce in{,6}_hasmulti(), two functions to check in the hot path if
an interface joined a specific multicast group. ok phessler@, visa@, dlg@
Diffstat (limited to 'sys/netinet')
-rw-r--r--sys/netinet/in.c17
-rw-r--r--sys/netinet/in_var.h3
-rw-r--r--sys/netinet/ip_carp.c8
-rw-r--r--sys/netinet/ip_input.c7
-rw-r--r--sys/netinet/ip_output.c8
5 files changed, 25 insertions, 18 deletions
diff --git a/sys/netinet/in.c b/sys/netinet/in.c
index 4450832b380..40f21d279e4 100644
--- a/sys/netinet/in.c
+++ b/sys/netinet/in.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in.c,v 1.125 2015/12/03 21:57:59 mpi Exp $ */
+/* $OpenBSD: in.c,v 1.126 2016/01/21 11:23:48 mpi Exp $ */
/* $NetBSD: in.c,v 1.26 1996/02/13 23:41:39 christos Exp $ */
/*
@@ -880,6 +880,21 @@ in_delmulti(struct in_multi *inm)
}
}
+/*
+ * Return 1 if the multicast group represented by ``ap'' has been
+ * joined by interface ``ifp'', 0 otherwise.
+ */
+int
+in_hasmulti(struct in_addr *ap, struct ifnet *ifp)
+{
+ struct in_multi *inm;
+ int joined;
+
+ IN_LOOKUP_MULTI(*ap, ifp, inm);
+ joined = (inm != NULL);
+
+ return (joined);
+}
void
in_ifdetach(struct ifnet *ifp)
diff --git a/sys/netinet/in_var.h b/sys/netinet/in_var.h
index 2bee960430c..14a3a5938a8 100644
--- a/sys/netinet/in_var.h
+++ b/sys/netinet/in_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: in_var.h,v 1.37 2015/12/03 21:57:59 mpi Exp $ */
+/* $OpenBSD: in_var.h,v 1.38 2016/01/21 11:23:48 mpi Exp $ */
/* $NetBSD: in_var.h,v 1.16 1996/02/13 23:42:15 christos Exp $ */
/*
@@ -154,6 +154,7 @@ int in_ifinit(struct ifnet *,
struct in_ifaddr *, struct sockaddr_in *, int);
struct in_multi *in_addmulti(struct in_addr *, struct ifnet *);
void in_delmulti(struct in_multi *);
+int in_hasmulti(struct in_addr *, struct ifnet *);
void in_ifscrub(struct ifnet *, struct in_ifaddr *);
int in_control(struct socket *, u_long, caddr_t, struct ifnet *);
void in_prefixlen2mask(struct in_addr *, int);
diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c
index b4abb0185cf..e0220d74ca3 100644
--- a/sys/netinet/ip_carp.c
+++ b/sys/netinet/ip_carp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_carp.c,v 1.285 2016/01/12 09:22:01 mpi Exp $ */
+/* $OpenBSD: ip_carp.c,v 1.286 2016/01/21 11:23:48 mpi Exp $ */
/*
* Copyright (c) 2002 Michael Shalayeff. All rights reserved.
@@ -1809,17 +1809,13 @@ carp_addr_updated(void *v)
/* We received address changes from if_addrhooks callback */
if (new_naddrs != sc->sc_naddrs || new_naddrs6 != sc->sc_naddrs6) {
- struct in_addr mc_addr;
- struct in_multi *inm;
sc->sc_naddrs = new_naddrs;
sc->sc_naddrs6 = new_naddrs6;
/* Re-establish multicast membership removed by in_control */
if (IN_MULTICAST(sc->sc_peer.s_addr)) {
- mc_addr.s_addr = sc->sc_peer.s_addr;
- IN_LOOKUP_MULTI(mc_addr, &sc->sc_if, inm);
- if (inm == NULL) {
+ if (!in_hasmulti(&sc->sc_peer, &sc->sc_if)) {
struct in_multi **imm =
sc->sc_imo.imo_membership;
u_int16_t maxmem =
diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c
index 885e6fc4ed8..4ceb3de01cd 100644
--- a/sys/netinet/ip_input.c
+++ b/sys/netinet/ip_input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_input.c,v 1.265 2015/12/03 21:11:53 sashan Exp $ */
+/* $OpenBSD: ip_input.c,v 1.266 2016/01/21 11:23:48 mpi Exp $ */
/* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */
/*
@@ -346,8 +346,6 @@ ipv4_input(struct mbuf *m)
}
if (IN_MULTICAST(ip->ip_dst.s_addr)) {
- struct in_multi *inm;
-
/*
* Make sure M_MCAST is set. It should theoretically
* already be there, but let's play safe because upper
@@ -402,8 +400,7 @@ ipv4_input(struct mbuf *m)
* See if we belong to the destination multicast group on the
* arrival interface.
*/
- IN_LOOKUP_MULTI(ip->ip_dst, ifp, inm);
- if (inm == NULL) {
+ if (!in_hasmulti(&ip->ip_dst, ifp)) {
ipstat.ips_notmember++;
if (!IN_LOCAL_GROUP(ip->ip_dst.s_addr))
ipstat.ips_cantforward++;
diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c
index 070a56b6bd1..385f908aa9b 100644
--- a/sys/netinet/ip_output.c
+++ b/sys/netinet/ip_output.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_output.c,v 1.316 2016/01/13 09:38:36 mpi Exp $ */
+/* $OpenBSD: ip_output.c,v 1.317 2016/01/21 11:23:48 mpi Exp $ */
/* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */
/*
@@ -241,7 +241,6 @@ reroute:
if (IN_MULTICAST(ip->ip_dst.s_addr) ||
(ip->ip_dst.s_addr == INADDR_BROADCAST)) {
- struct in_multi *inm;
m->m_flags |= (ip->ip_dst.s_addr == INADDR_BROADCAST) ?
M_BCAST : M_MCAST;
@@ -295,9 +294,8 @@ reroute:
ip->ip_src = ia->ia_addr.sin_addr;
}
- IN_LOOKUP_MULTI(ip->ip_dst, ifp, inm);
- if (inm != NULL &&
- (imo == NULL || imo->imo_loop)) {
+ if ((imo == NULL || imo->imo_loop) &&
+ in_hasmulti(&ip->ip_dst, ifp)) {
/*
* If we belong to the destination multicast group
* on the outgoing interface, and the caller did not