Use if_addr_init() and if_mcast_op() instead of ifp->if_ioctl().

This commit is contained in:
dyoung 2011-10-19 01:52:22 +00:00
parent 0438231d62
commit 386d3978d1
8 changed files with 52 additions and 69 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: in.c,v 1.138 2010/05/15 05:02:46 oki Exp $ */
/* $NetBSD: in.c,v 1.139 2011/10/19 01:52:22 dyoung Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -91,7 +91,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.138 2010/05/15 05:02:46 oki Exp $");
__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.139 2011/10/19 01:52:22 dyoung Exp $");
#include "opt_inet.h"
#include "opt_inet_conf.h"
@ -454,7 +454,7 @@ in_control(struct socket *so, u_long cmd, void *data, struct ifnet *ifp,
return (EINVAL);
oldaddr = ia->ia_dstaddr;
ia->ia_dstaddr = *satocsin(ifreq_getdstaddr(cmd, ifr));
if ((error = (*ifp->if_ioctl)(ifp, SIOCSIFDSTADDR, ia)) != 0) {
if ((error = if_addr_init(ifp, &ia->ia_ifa, false)) != 0) {
ia->ia_dstaddr = oldaddr;
return error;
}
@ -813,7 +813,7 @@ in_ifinit(struct ifnet *ifp, struct in_ifaddr *ia,
* if this is its first address,
* and to validate the address if necessary.
*/
if ((error = (*ifp->if_ioctl)(ifp, SIOCINITIFADDR, ia)) != 0)
if ((error = if_addr_init(ifp, &ia->ia_ifa, true)) != 0)
goto bad;
splx(s);
if (scrub) {
@ -1045,7 +1045,6 @@ in_addmulti(struct in_addr *ap, struct ifnet *ifp)
{
struct sockaddr_in sin;
struct in_multi *inm;
struct ifreq ifr;
int s = splsoftnet();
/*
@ -1078,8 +1077,7 @@ in_addmulti(struct in_addr *ap, struct ifnet *ifp)
* filter appropriately for the new address.
*/
sockaddr_in_init(&sin, ap, 0);
ifreq_setaddr(SIOCADDMULTI, &ifr, sintosa(&sin));
if ((*ifp->if_ioctl)(ifp, SIOCADDMULTI, &ifr) != 0) {
if (if_mcast_op(ifp, SIOCADDMULTI, sintosa(&sin)) != 0) {
LIST_REMOVE(inm, inm_list);
pool_put(&inmulti_pool, inm);
splx(s);
@ -1107,7 +1105,6 @@ void
in_delmulti(struct in_multi *inm)
{
struct sockaddr_in sin;
struct ifreq ifr;
int s = splsoftnet();
if (--inm->inm_refcount == 0) {
@ -1126,8 +1123,7 @@ in_delmulti(struct in_multi *inm)
* filter.
*/
sockaddr_in_init(&sin, &inm->inm_addr, 0);
ifreq_setaddr(SIOCDELMULTI, &ifr, sintosa(&sin));
(*inm->inm_ifp->if_ioctl)(inm->inm_ifp, SIOCDELMULTI, &ifr);
if_mcast_op(inm->inm_ifp, SIOCDELMULTI, sintosa(&sin));
pool_put(&inmulti_pool, inm);
}
splx(s);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_carp.c,v 1.45 2011/07/17 20:54:53 joerg Exp $ */
/* $NetBSD: ip_carp.c,v 1.46 2011/10/19 01:52:22 dyoung Exp $ */
/* $OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $ */
/*
@ -30,7 +30,7 @@
#include "opt_inet.h"
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.45 2011/07/17 20:54:53 joerg Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.46 2011/10/19 01:52:22 dyoung Exp $");
/*
* TODO:
@ -2151,7 +2151,7 @@ carp_ether_addmulti(struct carp_softc *sc, struct ifreq *ifr)
memcpy(&mc->mc_addr, sa, sa->sa_len);
LIST_INSERT_HEAD(&sc->carp_mc_listhead, mc, mc_entries);
error = (*ifp->if_ioctl)(ifp, SIOCADDMULTI, ifr);
error = if_mcast_op(ifp, SIOCADDMULTI, sa);
if (error != 0)
goto ioctl_failed;
@ -2203,7 +2203,7 @@ carp_ether_delmulti(struct carp_softc *sc, struct ifreq *ifr)
return (error);
/* We no longer use this multicast address. Tell parent so. */
error = (*ifp->if_ioctl)(ifp, SIOCDELMULTI, ifr);
error = if_mcast_op(ifp, SIOCDELMULTI, sa);
if (error == 0) {
/* And forget about this address. */
LIST_REMOVE(mc, mc_entries);
@ -2222,22 +2222,12 @@ carp_ether_purgemulti(struct carp_softc *sc)
{
struct ifnet *ifp = sc->sc_carpdev; /* Parent. */
struct carp_mc_entry *mc;
union {
struct ifreq ifreq;
struct {
char ifr_name[IFNAMSIZ];
struct sockaddr_storage ifr_ss;
} ifreq_storage;
} u;
struct ifreq *ifr = &u.ifreq;
if (ifp == NULL)
return;
memcpy(ifr->ifr_name, ifp->if_xname, IFNAMSIZ);
while ((mc = LIST_FIRST(&sc->carp_mc_listhead)) != NULL) {
memcpy(&ifr->ifr_addr, &mc->mc_addr, mc->mc_addr.ss_len);
(void)(*ifp->if_ioctl)(ifp, SIOCDELMULTI, ifr);
(void)if_mcast_op(ifp, SIOCDELMULTI, sstosa(&mc->mc_addr));
LIST_REMOVE(mc, mc_entries);
free(mc, M_DEVBUF);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_mroute.c,v 1.120 2011/08/31 18:31:03 plunky Exp $ */
/* $NetBSD: ip_mroute.c,v 1.121 2011/10/19 01:52:22 dyoung Exp $ */
/*
* Copyright (c) 1992, 1993
@ -93,7 +93,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.120 2011/08/31 18:31:03 plunky Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.121 2011/10/19 01:52:22 dyoung Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@ -787,7 +787,6 @@ add_vif(struct vifctl *vifcp)
struct vif *vifp;
struct ifaddr *ifa;
struct ifnet *ifp;
struct ifreq ifr;
int error, s;
struct sockaddr_in sin;
@ -867,8 +866,7 @@ add_vif(struct vifctl *vifcp)
/* Enable promiscuous reception of all IP multicasts. */
sockaddr_in_init(&sin, &zeroin_addr, 0);
ifreq_setaddr(SIOCADDMULTI, &ifr, sintosa(&sin));
error = (*ifp->if_ioctl)(ifp, SIOCADDMULTI, &ifr);
error = if_mcast_op(ifp, SIOCADDMULTI, sintosa(&sin));
if (error)
return (error);
}
@ -926,7 +924,6 @@ reset_vif(struct vif *vifp)
{
struct mbuf *m, *n;
struct ifnet *ifp;
struct ifreq ifr;
struct sockaddr_in sin;
callout_stop(&vifp->v_repq_ch);
@ -951,9 +948,8 @@ reset_vif(struct vif *vifp)
#endif
} else {
sockaddr_in_init(&sin, &zeroin_addr, 0);
ifreq_setaddr(SIOCDELMULTI, &ifr, sintosa(&sin));
ifp = vifp->v_ifp;
(*ifp->if_ioctl)(ifp, SIOCDELMULTI, &ifr);
if_mcast_op(ifp, SIOCDELMULTI, sintosa(&sin));
}
memset((void *)vifp, 0, sizeof(*vifp));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: in6.c,v 1.157 2011/02/06 19:12:55 dyoung Exp $ */
/* $NetBSD: in6.c,v 1.158 2011/10/19 01:53:07 dyoung Exp $ */
/* $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $ */
/*
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.157 2011/02/06 19:12:55 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.158 2011/10/19 01:53:07 dyoung Exp $");
#include "opt_inet.h"
#include "opt_pfil_hooks.h"
@ -1753,8 +1753,8 @@ in6_ifinit(struct ifnet *ifp, struct in6_ifaddr *ia,
ia->ia_addr = *sin6;
if (ifacount <= 1 &&
(error = (*ifp->if_ioctl)(ifp, SIOCINITIFADDR, ia)) != 0) {
if (ifacount <= 1 &&
(error = if_addr_init(ifp, &ia->ia_ifa, true)) != 0) {
splx(s);
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip6_mroute.c,v 1.101 2011/08/31 18:31:03 plunky Exp $ */
/* $NetBSD: ip6_mroute.c,v 1.102 2011/10/19 01:53:07 dyoung Exp $ */
/* $KAME: ip6_mroute.c,v 1.49 2001/07/25 09:21:18 jinmei Exp $ */
/*
@ -117,7 +117,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.101 2011/08/31 18:31:03 plunky Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.102 2011/10/19 01:53:07 dyoung Exp $");
#include "opt_inet.h"
#include "opt_mrouting.h"
@ -512,7 +512,7 @@ ip6_mrouter_done(void)
mifi_t mifi;
int i;
struct ifnet *ifp;
struct in6_ifreq ifr;
struct sockaddr_in6 sin6;
struct mf6c *rt;
struct rtdetq *rte;
int s;
@ -538,10 +538,11 @@ ip6_mrouter_done(void)
for (mifi = 0; mifi < nummifs; mifi++) {
if (mif6table[mifi].m6_ifp &&
!(mif6table[mifi].m6_flags & MIFF_REGISTER)) {
ifr.ifr_addr.sin6_family = AF_INET6;
ifr.ifr_addr.sin6_addr= in6addr_any;
sin6.sin6_family = AF_INET6;
sin6.sin6_addr = in6addr_any;
ifp = mif6table[mifi].m6_ifp;
(*ifp->if_ioctl)(ifp, SIOCDELMULTI, &ifr);
if_mcast_op(ifp, SIOCDELMULTI,
sin6tocsa(&sin6));
}
}
}
@ -643,7 +644,7 @@ add_m6if(struct mif6ctl *mifcp)
{
struct mif6 *mifp;
struct ifnet *ifp;
struct in6_ifreq ifr;
struct sockaddr_in6 sin6;
int error, s;
#ifdef notyet
struct tbf *m_tbf = tbftable + mifcp->mif6c_mifi;
@ -686,9 +687,9 @@ add_m6if(struct mif6ctl *mifcp)
* Enable promiscuous reception of all IPv6 multicasts
* from the interface.
*/
ifr.ifr_addr.sin6_family = AF_INET6;
ifr.ifr_addr.sin6_addr = in6addr_any;
error = (*ifp->if_ioctl)(ifp, SIOCADDMULTI, &ifr);
sin6.sin6_family = AF_INET6;
sin6.sin6_addr = in6addr_any;
error = if_mcast_op(ifp, SIOCADDMULTI, sin6tosa(&sin6));
splx(s);
if (error)
return error;
@ -731,7 +732,7 @@ del_m6if(mifi_t *mifip)
struct mif6 *mifp = mif6table + *mifip;
mifi_t mifi;
struct ifnet *ifp;
struct in6_ifreq ifr;
struct sockaddr_in6 sin6;
int s;
if (*mifip >= nummifs)
@ -748,9 +749,9 @@ del_m6if(mifi_t *mifip)
*/
ifp = mifp->m6_ifp;
ifr.ifr_addr.sin6_family = AF_INET6;
ifr.ifr_addr.sin6_addr = in6addr_any;
(*ifp->if_ioctl)(ifp, SIOCDELMULTI, &ifr);
sin6.sin6_family = AF_INET6;
sin6.sin6_addr = in6addr_any;
if_mcast_op(ifp, SIOCDELMULTI, sin6tosa(&sin6));
} else {
if (reg_mif_num != (mifi_t)-1) {
if_detach(&multicast_register_if6);

View File

@ -1,4 +1,4 @@
/* $NetBSD: mld6.c,v 1.53 2011/08/31 18:31:03 plunky Exp $ */
/* $NetBSD: mld6.c,v 1.54 2011/10/19 01:53:07 dyoung Exp $ */
/* $KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $ */
/*
@ -102,7 +102,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.53 2011/08/31 18:31:03 plunky Exp $");
__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.54 2011/10/19 01:53:07 dyoung Exp $");
#include "opt_inet.h"
@ -616,7 +616,7 @@ in6_addmulti(struct in6_addr *maddr6, struct ifnet *ifp,
int *errorp, int timer)
{
struct in6_ifaddr *ia;
struct in6_ifreq ifr;
struct sockaddr_in6 sin6;
struct in6_multi *in6m;
int s = splsoftnet();
@ -663,8 +663,8 @@ in6_addmulti(struct in6_addr *maddr6, struct ifnet *ifp,
* Ask the network driver to update its multicast reception
* filter appropriately for the new address.
*/
sockaddr_in6_init(&ifr.ifr_addr, maddr6, 0, 0, 0);
*errorp = (*ifp->if_ioctl)(ifp, SIOCADDMULTI, &ifr);
sockaddr_in6_init(&sin6, maddr6, 0, 0, 0);
*errorp = if_mcast_op(ifp, SIOCADDMULTI, sin6tosa(&sin6));
if (*errorp) {
LIST_REMOVE(in6m, in6m_entry);
free(in6m, M_IPMADDR);
@ -700,7 +700,7 @@ in6_addmulti(struct in6_addr *maddr6, struct ifnet *ifp,
void
in6_delmulti(struct in6_multi *in6m)
{
struct in6_ifreq ifr;
struct sockaddr_in6 sin6;
struct in6_ifaddr *ia;
int s = splsoftnet();
@ -738,8 +738,8 @@ in6_delmulti(struct in6_multi *in6m)
* Notify the network driver to update its multicast
* reception filter.
*/
sockaddr_in6_init(&ifr.ifr_addr, &in6m->in6m_addr, 0, 0, 0);
(*in6m->in6m_ifp->if_ioctl)(in6m->in6m_ifp, SIOCDELMULTI, &ifr);
sockaddr_in6_init(&sin6, &in6m->in6m_addr, 0, 0, 0);
if_mcast_op(in6m->in6m_ifp, SIOCDELMULTI, sin6tosa(&sin6));
callout_destroy(&in6m->in6m_timer_ch);
free(in6m, M_IPMADDR);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: iso.c,v 1.57 2009/08/07 14:04:34 wiz Exp $ */
/* $NetBSD: iso.c,v 1.58 2011/10/19 01:53:35 dyoung Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -88,7 +88,7 @@ SOFTWARE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: iso.c,v 1.57 2009/08/07 14:04:34 wiz Exp $");
__KERNEL_RCSID(0, "$NetBSD: iso.c,v 1.58 2011/10/19 01:53:35 dyoung Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -649,7 +649,7 @@ iso_ifinit(struct ifnet *ifp, struct iso_ifaddr *ia, struct sockaddr_iso *siso,
* if this is its first address,
* and to validate the address if necessary.
*/
if ((error = (*ifp->if_ioctl)(ifp, SIOCINITIFADDR, ia)) != 0) {
if ((error = if_addr_init(ifp, &ia->ia_ifa, true)) != 0) {
splx(s);
ia->ia_addr = oldaddr;
return (error);

View File

@ -1,4 +1,4 @@
/* $NetBSD: iso_snpac.c,v 1.53 2009/04/16 21:37:17 elad Exp $ */
/* $NetBSD: iso_snpac.c,v 1.54 2011/10/19 01:53:35 dyoung Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -59,7 +59,7 @@ SOFTWARE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: iso_snpac.c,v 1.53 2009/04/16 21:37:17 elad Exp $");
__KERNEL_RCSID(0, "$NetBSD: iso_snpac.c,v 1.54 2011/10/19 01:53:35 dyoung Exp $");
#include "opt_iso.h"
#ifdef ISO
@ -275,18 +275,18 @@ iso_setmcasts(struct ifnet *ifp, int req)
{
static const char * const addrlist[] =
{all_es_snpa, all_is_snpa, all_l1is_snpa, all_l2is_snpa, 0};
struct ifreq ifr;
struct sockaddr sa;
const char *const *cpp;
(void)memset(&ifr, 0, sizeof(ifr));
(void)memset(&sa, 0, sizeof(sa));
for (cpp = addrlist; *cpp; cpp++) {
(void)memcpy(ifr.ifr_addr.sa_data, *cpp, 6);
(void)memcpy(sa.sa_data, *cpp, 6);
if (req == RTM_ADD &&
(*ifp->if_ioctl)(ifp, SIOCADDMULTI, &ifr) != 0)
if_mcast_op(ifp, SIOCADDMULTI, &sa) != 0)
printf("iso_setmcasts: %s unable to add mcast\n",
ifp->if_xname);
else if (req == RTM_DELETE &&
(*ifp->if_ioctl)(ifp, SIOCDELMULTI, &ifr) != 0)
if_mcast_op(ifp, SIOCDELMULTI, &sa) != 0)
printf("iso_setmcasts: %s unable to delete mcast\n",
ifp->if_xname);
}