diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2018-05-21 15:52:23 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2018-05-21 15:52:23 +0000 |
commit | fd2efbb43bbf7605aaab6ed706f20ee85b72be38 (patch) | |
tree | 6265a79e358b97c76678c904ee22605554b642dc /sys | |
parent | 8a6684e984808fcaa2f734eb4f48d9304a3f6094 (diff) |
All places that call carp_lsdrop() use the interface pointer already.
It does not make sense to call if_get() again, just pass ifp as
parameter. Move the IFT_CARP check into the function instead of
doing it everywhere. Replace the inverted match variable logic
with simple returns.
OK mpi@ friehm@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/netinet/ip_carp.c | 27 | ||||
-rw-r--r-- | sys/netinet/ip_carp.h | 6 | ||||
-rw-r--r-- | sys/netinet/ip_icmp.c | 11 | ||||
-rw-r--r-- | sys/netinet/ip_input.c | 12 | ||||
-rw-r--r-- | sys/netinet6/icmp6.c | 7 | ||||
-rw-r--r-- | sys/netinet6/ip6_input.c | 9 |
6 files changed, 30 insertions, 42 deletions
diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 71661626a72..06b2bccd716 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_carp.c,v 1.331 2018/03/21 15:01:10 bluhm Exp $ */ +/* $OpenBSD: ip_carp.c,v 1.332 2018/05/21 15:52:22 bluhm Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -1468,21 +1468,18 @@ out: } int -carp_lsdrop(struct mbuf *m, sa_family_t af, u_int32_t *src, u_int32_t *dst, - int drop) +carp_lsdrop(struct ifnet *ifp, struct mbuf *m, sa_family_t af, u_int32_t *src, + u_int32_t *dst, int drop) { - struct ifnet *ifp; struct carp_softc *sc; - int match = 1; u_int32_t fold; struct m_tag *mtag; - ifp = if_get(m->m_pkthdr.ph_ifidx); - KASSERT(ifp != NULL); - + if (ifp->if_type != IFT_CARP) + return 0; sc = ifp->if_softc; if (sc->sc_balancing == CARP_BAL_NONE) - goto done; + return 0; /* * Remove M_MCAST flag from mbuf of balancing ip traffic, since the fact @@ -1500,14 +1497,14 @@ carp_lsdrop(struct mbuf *m, sa_family_t af, u_int32_t *src, u_int32_t *dst, * M_MCAST flag and do nothing else. */ if (!drop) - goto done; + return 0; /* * Never drop carp advertisements. * XXX Bad idea to pass all broadcast / multicast traffic? */ if (m->m_flags & (M_BCAST|M_MCAST)) - goto done; + return 0; fold = src[0] ^ dst[0]; #ifdef INET6 @@ -1518,13 +1515,9 @@ carp_lsdrop(struct mbuf *m, sa_family_t af, u_int32_t *src, u_int32_t *dst, } #endif if (sc->sc_lscount == 0) /* just to be safe */ - match = 0; - else - match = (1 << (ntohl(fold) % sc->sc_lscount)) & sc->sc_lsmask; + return 1; -done: - if_put(ifp); - return (!match); + return ((1 << (ntohl(fold) % sc->sc_lscount)) & sc->sc_lsmask) == 0; } void diff --git a/sys/netinet/ip_carp.h b/sys/netinet/ip_carp.h index 0b78c8cd528..8911e9170e2 100644 --- a/sys/netinet/ip_carp.h +++ b/sys/netinet/ip_carp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_carp.h,v 1.46 2018/01/12 23:47:24 dlg Exp $ */ +/* $OpenBSD: ip_carp.h,v 1.47 2018/05/21 15:52:22 bluhm Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -202,7 +202,7 @@ int carp_ourether(struct ifnet *, u_int8_t *); int carp_output(struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *); int carp_sysctl(int *, u_int, void *, size_t *, void *, size_t); -int carp_lsdrop(struct mbuf *, sa_family_t, u_int32_t *, - u_int32_t *, int); +int carp_lsdrop(struct ifnet *, struct mbuf *, sa_family_t, + u_int32_t *, u_int32_t *, int); #endif /* _KERNEL */ #endif /* _NETINET_IP_CARP_H_ */ diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index b71e8738da2..0527c54b3a7 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_icmp.c,v 1.174 2017/12/14 14:26:50 bluhm Exp $ */ +/* $OpenBSD: ip_icmp.c,v 1.175 2018/05/21 15:52:22 bluhm Exp $ */ /* $NetBSD: ip_icmp.c,v 1.19 1996/02/13 23:42:22 christos Exp $ */ /* @@ -497,8 +497,7 @@ icmp_input_if(struct ifnet *ifp, struct mbuf **mp, int *offp, int proto, int af) sin.sin_len = sizeof(struct sockaddr_in); sin.sin_addr = icp->icmp_ip.ip_dst; #if NCARP > 0 - if (ifp->if_type == IFT_CARP && - carp_lsdrop(m, AF_INET, &sin.sin_addr.s_addr, + if (carp_lsdrop(ifp, m, AF_INET, &sin.sin_addr.s_addr, &ip->ip_dst.s_addr, 1)) goto freeit; #endif @@ -581,8 +580,7 @@ icmp_input_if(struct ifnet *ifp, struct mbuf **mp, int *offp, int proto, int af) } reflect: #if NCARP > 0 - if (ifp->if_type == IFT_CARP && - carp_lsdrop(m, AF_INET, &ip->ip_src.s_addr, + if (carp_lsdrop(ifp, m, AF_INET, &ip->ip_src.s_addr, &ip->ip_dst.s_addr, 1)) goto freeit; #endif @@ -642,8 +640,7 @@ reflect: #endif #if NCARP > 0 - if (ifp->if_type == IFT_CARP && - carp_lsdrop(m, AF_INET, &sdst.sin_addr.s_addr, + if (carp_lsdrop(ifp, m, AF_INET, &sdst.sin_addr.s_addr, &ip->ip_dst.s_addr, 1)) goto freeit; #endif diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index b3aa0318c8f..d02d5bed158 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_input.c,v 1.336 2017/12/29 17:05:25 bluhm Exp $ */ +/* $OpenBSD: ip_input.c,v 1.337 2018/05/21 15:52:22 bluhm Exp $ */ /* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */ /* @@ -341,9 +341,8 @@ ip_input_if(struct mbuf **mp, int *offp, int nxt, int af, struct ifnet *ifp) } #if NCARP > 0 - if (ifp->if_type == IFT_CARP && - carp_lsdrop(m, AF_INET, &ip->ip_src.s_addr, &ip->ip_dst.s_addr, - (ip->ip_p == IPPROTO_ICMP ? 0 : 1))) + if (carp_lsdrop(ifp, m, AF_INET, &ip->ip_src.s_addr, + &ip->ip_dst.s_addr, (ip->ip_p == IPPROTO_ICMP ? 0 : 1))) goto bad; #endif @@ -451,8 +450,9 @@ ip_input_if(struct mbuf **mp, int *offp, int nxt, int af, struct ifnet *ifp) } #if NCARP > 0 - if (ifp->if_type == IFT_CARP && ip->ip_p == IPPROTO_ICMP && - carp_lsdrop(m, AF_INET, &ip->ip_src.s_addr, &ip->ip_dst.s_addr, 1)) + if (ip->ip_p == IPPROTO_ICMP && + carp_lsdrop(ifp, m, AF_INET, &ip->ip_src.s_addr, + &ip->ip_dst.s_addr, 1)) goto bad; #endif /* diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index e98ddeb0800..4255ecadda5 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: icmp6.c,v 1.222 2018/03/27 15:03:52 dhill Exp $ */ +/* $OpenBSD: icmp6.c,v 1.223 2018/05/21 15:52:22 bluhm Exp $ */ /* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */ /* @@ -448,9 +448,8 @@ icmp6_input(struct mbuf **mp, int *offp, int proto, int af) if (ifp == NULL) goto freeit; - if (ifp->if_type == IFT_CARP && - icmp6->icmp6_type == ICMP6_ECHO_REQUEST && - carp_lsdrop(m, AF_INET6, ip6->ip6_src.s6_addr32, + if (icmp6->icmp6_type == ICMP6_ECHO_REQUEST && + carp_lsdrop(ifp, m, AF_INET6, ip6->ip6_src.s6_addr32, ip6->ip6_dst.s6_addr32, 1)) { if_put(ifp); goto freeit; diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index c4911a9f3a7..527a8f70298 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_input.c,v 1.214 2018/02/19 08:59:53 mpi Exp $ */ +/* $OpenBSD: ip6_input.c,v 1.215 2018/05/21 15:52:22 bluhm Exp $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -245,8 +245,7 @@ ip6_input_if(struct mbuf **mp, int *offp, int nxt, int af, struct ifnet *ifp) } #if NCARP > 0 - if (ifp->if_type == IFT_CARP && - carp_lsdrop(m, AF_INET6, ip6->ip6_src.s6_addr32, + if (carp_lsdrop(ifp, m, AF_INET6, ip6->ip6_src.s6_addr32, ip6->ip6_dst.s6_addr32, (ip6->ip6_nxt == IPPROTO_ICMPV6 ? 0 : 1))) goto bad; #endif @@ -495,8 +494,8 @@ ip6_input_if(struct mbuf **mp, int *offp, int nxt, int af, struct ifnet *ifp) } #if NCARP > 0 - if (ifp->if_type == IFT_CARP && ip6->ip6_nxt == IPPROTO_ICMPV6 && - carp_lsdrop(m, AF_INET6, ip6->ip6_src.s6_addr32, + if (ip6->ip6_nxt == IPPROTO_ICMPV6 && + carp_lsdrop(ifp, m, AF_INET6, ip6->ip6_src.s6_addr32, ip6->ip6_dst.s6_addr32, 1)) goto bad; #endif |