Constify sockaddr argument to ether_multiaddr(). Change struct

ifreq * arguments to ether_addmulti() and ether_delmulti() to const
struct sockaddr *, since ether_{add,del}multi() only ever read the
sockaddr ifreq member, ifr_addr.  Update uses in carp(4) and in
vlan(4).
This commit is contained in:
dyoung 2007-09-19 05:25:33 +00:00
parent 4c9b6756a5
commit 43390716bc
4 changed files with 41 additions and 39 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_ether.h,v 1.45 2007/03/04 06:03:15 christos Exp $ */
/* $NetBSD: if_ether.h,v 1.46 2007/09/19 05:25:33 dyoung Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
@ -174,10 +174,9 @@ extern const uint8_t ether_ipmulticast_min[ETHER_ADDR_LEN];
extern const uint8_t ether_ipmulticast_max[ETHER_ADDR_LEN];
int ether_ioctl(struct ifnet *, u_long, void *);
int ether_addmulti (struct ifreq *, struct ethercom *);
int ether_delmulti (struct ifreq *, struct ethercom *);
int ether_changeaddr (struct ifreq *, struct ethercom *);
int ether_multiaddr(struct sockaddr *, u_int8_t[], u_int8_t[]);
int ether_addmulti(const struct sockaddr *, struct ethercom *);
int ether_delmulti(const struct sockaddr *, struct ethercom *);
int ether_multiaddr(const struct sockaddr *, u_int8_t[], u_int8_t[]);
#endif /* _KERNEL */
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_ethersubr.c,v 1.154 2007/08/30 02:17:35 dyoung Exp $ */
/* $NetBSD: if_ethersubr.c,v 1.155 2007/09/19 05:25:33 dyoung Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.154 2007/08/30 02:17:35 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.155 2007/09/19 05:25:33 dyoung Exp $");
#include "opt_inet.h"
#include "opt_atalk.h"
@ -1266,14 +1266,14 @@ ether_nonstatic_aton(u_char *dest, char *str)
* addresses.
*/
int
ether_multiaddr(struct sockaddr *sa, u_int8_t addrlo[ETHER_ADDR_LEN],
ether_multiaddr(const struct sockaddr *sa, u_int8_t addrlo[ETHER_ADDR_LEN],
u_int8_t addrhi[ETHER_ADDR_LEN])
{
#ifdef INET
struct sockaddr_in *sin;
const struct sockaddr_in *sin;
#endif /* INET */
#ifdef INET6
struct sockaddr_in6 *sin6;
const struct sockaddr_in6 *sin6;
#endif /* INET6 */
switch (sa->sa_family) {
@ -1285,7 +1285,7 @@ ether_multiaddr(struct sockaddr *sa, u_int8_t addrlo[ETHER_ADDR_LEN],
#ifdef INET
case AF_INET:
sin = satosin(sa);
sin = satocsin(sa);
if (sin->sin_addr.s_addr == INADDR_ANY) {
/*
* An IP address of INADDR_ANY means listen to
@ -1304,7 +1304,7 @@ ether_multiaddr(struct sockaddr *sa, u_int8_t addrlo[ETHER_ADDR_LEN],
#endif
#ifdef INET6
case AF_INET6:
sin6 = satosin6(sa);
sin6 = satocsin6(sa);
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
/*
* An IP6 address of 0 means listen to or stop
@ -1332,15 +1332,14 @@ ether_multiaddr(struct sockaddr *sa, u_int8_t addrlo[ETHER_ADDR_LEN],
* given interface.
*/
int
ether_addmulti(struct ifreq *ifr, struct ethercom *ec)
ether_addmulti(const struct sockaddr *sa, struct ethercom *ec)
{
struct ether_multi *enm;
u_char addrlo[ETHER_ADDR_LEN];
u_char addrhi[ETHER_ADDR_LEN];
int s = splnet(), error;
error = ether_multiaddr(&ifr->ifr_addr, addrlo,
addrhi);
error = ether_multiaddr(sa, addrlo, addrhi);
if (error != 0) {
splx(s);
return error;
@ -1391,15 +1390,14 @@ ether_addmulti(struct ifreq *ifr, struct ethercom *ec)
* Delete a multicast address record.
*/
int
ether_delmulti(struct ifreq *ifr, struct ethercom *ec)
ether_delmulti(const struct sockaddr *sa, struct ethercom *ec)
{
struct ether_multi *enm;
u_char addrlo[ETHER_ADDR_LEN];
u_char addrhi[ETHER_ADDR_LEN];
int s = splnet(), error;
error = ether_multiaddr(&ifr->ifr_addr, addrlo,
addrhi);
error = ether_multiaddr(sa, addrlo, addrhi);
if (error != 0) {
splx(s);
return (error);
@ -1532,11 +1530,11 @@ ether_ioctl(struct ifnet *ifp, u_long cmd, void *data)
break;
case SIOCADDMULTI:
error = ether_addmulti(ifr, ec);
error = ether_addmulti(ifreq_getaddr(cmd, ifr), ec);
break;
case SIOCDELMULTI:
error = ether_delmulti(ifr, ec);
error = ether_delmulti(ifreq_getaddr(cmd, ifr), ec);
break;
default:

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_vlan.c,v 1.54 2007/08/26 22:59:09 dyoung Exp $ */
/* $NetBSD: if_vlan.c,v 1.55 2007/09/19 05:25:33 dyoung Exp $ */
/*-
* Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@ -85,7 +85,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.54 2007/08/26 22:59:09 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.55 2007/09/19 05:25:33 dyoung Exp $");
#include "opt_inet.h"
#include "bpfilter.h"
@ -584,14 +584,15 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, void *data)
static int
vlan_ether_addmulti(struct ifvlan *ifv, struct ifreq *ifr)
{
const struct sockaddr *sa = ifreq_getaddr(SIOCADDMULTI, ifr);
struct vlan_mc_entry *mc;
u_int8_t addrlo[ETHER_ADDR_LEN], addrhi[ETHER_ADDR_LEN];
int error;
if (ifr->ifr_addr.sa_len > sizeof(struct sockaddr_storage))
if (sa->sa_len > sizeof(struct sockaddr_storage))
return (EINVAL);
error = ether_addmulti(ifr, &ifv->ifv_ec);
error = ether_addmulti(sa, &ifv->ifv_ec);
if (error != ENETRESET)
return (error);
@ -611,9 +612,9 @@ vlan_ether_addmulti(struct ifvlan *ifv, struct ifreq *ifr)
* As ether_addmulti() returns ENETRESET, following two
* statement shouldn't fail.
*/
(void)ether_multiaddr(&ifr->ifr_addr, addrlo, addrhi);
(void)ether_multiaddr(sa, addrlo, addrhi);
ETHER_LOOKUP_MULTI(addrlo, addrhi, &ifv->ifv_ec, mc->mc_enm);
memcpy(&mc->mc_addr, &ifr->ifr_addr, ifr->ifr_addr.sa_len);
memcpy(&mc->mc_addr, sa, sa->sa_len);
LIST_INSERT_HEAD(&ifv->ifv_mc_listhead, mc, mc_entries);
error = (*ifv->ifv_p->if_ioctl)(ifv->ifv_p, SIOCADDMULTI,
@ -626,13 +627,14 @@ vlan_ether_addmulti(struct ifvlan *ifv, struct ifreq *ifr)
LIST_REMOVE(mc, mc_entries);
FREE(mc, M_DEVBUF);
alloc_failed:
(void)ether_delmulti(ifr, &ifv->ifv_ec);
(void)ether_delmulti(sa, &ifv->ifv_ec);
return (error);
}
static int
vlan_ether_delmulti(struct ifvlan *ifv, struct ifreq *ifr)
{
const struct sockaddr *sa = ifreq_getaddr(SIOCDELMULTI, ifr);
struct ether_multi *enm;
struct vlan_mc_entry *mc;
u_int8_t addrlo[ETHER_ADDR_LEN], addrhi[ETHER_ADDR_LEN];
@ -642,11 +644,11 @@ vlan_ether_delmulti(struct ifvlan *ifv, struct ifreq *ifr)
* Find a key to lookup vlan_mc_entry. We have to do this
* before calling ether_delmulti for obvious reason.
*/
if ((error = ether_multiaddr(&ifr->ifr_addr, addrlo, addrhi)) != 0)
if ((error = ether_multiaddr(sa, addrlo, addrhi)) != 0)
return (error);
ETHER_LOOKUP_MULTI(addrlo, addrhi, &ifv->ifv_ec, enm);
error = ether_delmulti(ifr, &ifv->ifv_ec);
error = ether_delmulti(sa, &ifv->ifv_ec);
if (error != ENETRESET)
return (error);
@ -665,7 +667,7 @@ vlan_ether_delmulti(struct ifvlan *ifv, struct ifreq *ifr)
}
KASSERT(mc != NULL);
} else
(void)ether_addmulti(ifr, &ifv->ifv_ec);
(void)ether_addmulti(sa, &ifv->ifv_ec);
return (error);
}
@ -689,7 +691,8 @@ vlan_ether_purgemulti(struct ifvlan *ifv)
memcpy(ifr->ifr_name, ifp->if_xname, IFNAMSIZ);
while ((mc = LIST_FIRST(&ifv->ifv_mc_listhead)) != NULL) {
memcpy(&ifr->ifr_addr, &mc->mc_addr, mc->mc_addr.ss_len);
ifreq_setaddr(SIOCDELMULTI, ifr,
(const struct sockaddr *)&mc->mc_addr);
(void)(*ifp->if_ioctl)(ifp, SIOCDELMULTI, (void *)ifr);
LIST_REMOVE(mc, mc_entries);
FREE(mc, M_DEVBUF);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_carp.c,v 1.16 2007/08/30 02:17:37 dyoung Exp $ */
/* $NetBSD: ip_carp.c,v 1.17 2007/09/19 05:25:33 dyoung Exp $ */
/* $OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $ */
/*
@ -2098,6 +2098,7 @@ carp_carpdev_state(void *v)
int
carp_ether_addmulti(struct carp_softc *sc, struct ifreq *ifr)
{
const struct sockaddr *sa = ifreq_getaddr(SIOCADDMULTI, ifr);
struct ifnet *ifp;
struct carp_mc_entry *mc;
u_int8_t addrlo[ETHER_ADDR_LEN], addrhi[ETHER_ADDR_LEN];
@ -2107,7 +2108,7 @@ carp_ether_addmulti(struct carp_softc *sc, struct ifreq *ifr)
if (ifp == NULL)
return (EINVAL);
error = ether_addmulti(ifr, &sc->sc_ac);
error = ether_addmulti(sa, &sc->sc_ac);
if (error != ENETRESET)
return (error);
@ -2127,9 +2128,9 @@ carp_ether_addmulti(struct carp_softc *sc, struct ifreq *ifr)
* As ether_addmulti() returns ENETRESET, following two
* statement shouldn't fail.
*/
(void)ether_multiaddr(&ifr->ifr_addr, addrlo, addrhi);
(void)ether_multiaddr(sa, addrlo, addrhi);
ETHER_LOOKUP_MULTI(addrlo, addrhi, &sc->sc_ac, mc->mc_enm);
memcpy(&mc->mc_addr, &ifr->ifr_addr, ifr->ifr_addr.sa_len);
memcpy(&mc->mc_addr, sa, sa->sa_len);
LIST_INSERT_HEAD(&sc->carp_mc_listhead, mc, mc_entries);
error = (*ifp->if_ioctl)(ifp, SIOCADDMULTI, (void *)ifr);
@ -2142,7 +2143,7 @@ carp_ether_addmulti(struct carp_softc *sc, struct ifreq *ifr)
LIST_REMOVE(mc, mc_entries);
FREE(mc, M_DEVBUF);
alloc_failed:
(void)ether_delmulti(ifr, &sc->sc_ac);
(void)ether_delmulti(sa, &sc->sc_ac);
return (error);
}
@ -2150,6 +2151,7 @@ carp_ether_addmulti(struct carp_softc *sc, struct ifreq *ifr)
int
carp_ether_delmulti(struct carp_softc *sc, struct ifreq *ifr)
{
const struct sockaddr *sa = ifreq_getaddr(SIOCDELMULTI, ifr);
struct ifnet *ifp;
struct ether_multi *enm;
struct carp_mc_entry *mc;
@ -2164,7 +2166,7 @@ carp_ether_delmulti(struct carp_softc *sc, struct ifreq *ifr)
* Find a key to lookup carp_mc_entry. We have to do this
* before calling ether_delmulti for obvious reason.
*/
if ((error = ether_multiaddr(&ifr->ifr_addr, addrlo, addrhi)) != 0)
if ((error = ether_multiaddr(sa, addrlo, addrhi)) != 0)
return (error);
ETHER_LOOKUP_MULTI(addrlo, addrhi, &sc->sc_ac, enm);
if (enm == NULL)
@ -2178,7 +2180,7 @@ carp_ether_delmulti(struct carp_softc *sc, struct ifreq *ifr)
if (mc == NULL)
return (EINVAL);
error = ether_delmulti(ifr, &sc->sc_ac);
error = ether_delmulti(sa, &sc->sc_ac);
if (error != ENETRESET)
return (error);
@ -2189,7 +2191,7 @@ carp_ether_delmulti(struct carp_softc *sc, struct ifreq *ifr)
LIST_REMOVE(mc, mc_entries);
FREE(mc, M_DEVBUF);
} else
(void)ether_addmulti(ifr, &sc->sc_ac);
(void)ether_addmulti(sa, &sc->sc_ac);
return (error);
}