tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

stop ifnet ioctl (ab)use in the kernel, step 1



The network protocols and some drivers use ioctls to manipulate
ifnet flags, to add/delete multicast addresses, and to initialize
ifaddrs.  I'd like to stop that before I tackle some problems with
ioctl synchronization.  The first step is to replace calls to
ifp->if_ioctl(SIOCINITIFADDR|SIOCSIFFLAGS|SIOCADDMULTI|SIOSDELMULTI)
with calls to some new routines, if_flags_set(), if_mcast_op(), and
if_addr_init().  The new routines either call driver-provided routines
or fall back to if_ioctl.  See the attached patch.

This patch isn't ready to commit, but please let me know if you have
any objections to the general approach before I continue.

Notice that I have provisionally deleted SIOCSIFDSTADDR cases from a lot
of drivers, because we can ordinarily rely on SIOCINITIFADDR to do the
same checks that SIOCSIFDSTADDR will do.

Dave

-- 
David Young             OJC Technologies
dyoung%ojctech.com@localhost      Urbana, IL * (217) 344-0444 x24
Index: net/if.c
===================================================================
RCS file: /cvsroot/src/sys/net/if.c,v
retrieving revision 1.250
diff -u -p -r1.250 if.c
--- net/if.c    18 Jan 2011 20:33:45 -0000      1.250
+++ net/if.c    9 Mar 2011 21:47:46 -0000
@@ -1398,7 +1420,6 @@ ifpromisc(struct ifnet *ifp, int pswitch
 {
        int pcount, ret;
        short flags;
-       struct ifreq ifr;
 
        pcount = ifp->if_pcount;
        flags = ifp->if_flags;
@@ -1426,9 +1447,7 @@ ifpromisc(struct ifnet *ifp, int pswitch
                if ((ifp->if_flags & IFF_UP) == 0)
                        return 0;
        }
-       memset(&ifr, 0, sizeof(ifr));
-       ifr.ifr_flags = ifp->if_flags;
-       ret = (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, &ifr);
+       ret = if_flags_set(ifp, ifp->if_flags);
        /* Restore interface state if not successful. */
        if (ret != 0) {
                ifp->if_pcount = pcount;
@@ -2006,6 +2025,51 @@ ifq_enqueue2(struct ifnet *ifp, struct i
        return 0;
 }
 
+int
+if_addr_init(ifnet_t *ifp, struct ifaddr *ifa, const bool up)
+{
+       int rc;
+
+       if (ifp->if_initaddr != NULL)
+               rc = (*ifp->if_initaddr)(ifp, ifa, up);
+       else
+               rc = (*ifp->if_ioctl) (ifp, SIOCINITIFADDR, ifa);
+
+       return rc;
+}
+
+int
+if_flags_set(ifnet_t *ifp, const short flags)
+{
+       int rc;
+       struct ifreq ifr;
+
+       if (ifp->if_setflags != NULL)
+               rc = (*ifp->if_setflags)(ifp, flags);
+       else {
+               memset(&ifr, 0, sizeof(ifr));
+               ifr.ifr_flags = flags;
+               rc = (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, &ifr);
+       }
+
+       return rc;
+}
+
+int
+if_mcast_op(ifnet_t *ifp, const unsigned long cmd, const struct sockaddr *sa)
+{
+       int rc;
+       struct ifreq ifr;
+
+       if (ifp->if_mcastop != NULL)
+               rc = (*ifp->if_mcastop)(ifp, cmd, sa);
+       else {
+               ifreq_setaddr(cmd, &ifr, sa);
+               rc = (*ifp->if_ioctl)(ifp, cmd, &ifr);
+       }
+
+       return rc;
+}
 
 static void
 sysctl_sndq_setup(struct sysctllog **clog, const char *ifname,
Index: net/if.h
===================================================================
RCS file: /cvsroot/src/sys/net/if.h,v
retrieving revision 1.150
diff -u -p -r1.150 if.h
--- net/if.h    1 Feb 2011 01:39:20 -0000       1.150
+++ net/if.h    9 Mar 2011 21:47:46 -0000
@@ -63,6 +63,10 @@
 #ifndef _NET_IF_H_
 #define _NET_IF_H_
 
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include <stdbool.h>
+#endif
+
 #include <sys/featuretest.h>
 
 /*
@@ -296,6 +300,10 @@ typedef struct ifnet {
                                         * same, they are the same ifnet.
                                         */
        struct sysctllog        *if_sysctl_log;
+       int (*if_initaddr)(struct ifnet *, struct ifaddr *, bool);
+       int (*if_mcastop)(struct ifnet *, const unsigned long,
+           const struct sockaddr *);
+       int (*if_setflags)(struct ifnet *, const short);
 } ifnet_t;
 
 #define        if_mtu          if_data.ifi_mtu
@@ -849,10 +857,13 @@ int       ifioctl(struct socket *, u_long, voi
 int    ifioctl_common(struct ifnet *, u_long, void *);
 int    ifpromisc(struct ifnet *, int);
 struct ifnet *ifunit(const char *);
+int    if_addr_init(ifnet_t *, struct ifaddr *, bool);
+int    if_mcast_op(ifnet_t *, const unsigned long, const struct sockaddr *);
+int    if_flags_set(struct ifnet *, const short);
 
 void ifa_insert(struct ifnet *, struct ifaddr *);
 void ifa_remove(struct ifnet *, struct ifaddr *);
 
 struct ifaddr *ifa_ifwithaddr(const struct sockaddr *);
 struct ifaddr *ifa_ifwithaf(int);
 struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *);
Index: net/if_gif.c
===================================================================
RCS file: /cvsroot/src/sys/net/if_gif.c,v
retrieving revision 1.78
diff -u -p -r1.78 if_gif.c
--- net/if_gif.c        5 Apr 2010 07:22:23 -0000       1.78
+++ net/if_gif.c        9 Mar 2011 21:47:46 -0000
@@ -493,9 +493,6 @@ gif_ioctl(struct ifnet *ifp, u_long cmd,
                ifp->if_flags |= IFF_UP;
                break;
 
-       case SIOCSIFDSTADDR:
-               break;
-
        case SIOCADDMULTI:
        case SIOCDELMULTI:
                switch (ifr->ifr_addr.sa_family) {
Index: net/if_gre.c
===================================================================
RCS file: /cvsroot/src/sys/net/if_gre.c,v
retrieving revision 1.144
diff -u -p -r1.144 if_gre.c
--- net/if_gre.c        26 Jun 2010 14:24:28 -0000      1.144
+++ net/if_gre.c        9 Mar 2011 21:47:46 -0000
@@ -1328,8 +1265,6 @@ gre_ioctl(struct ifnet *ifp, const u_lon
                gre_clearconf(sp, false);
                ifp->if_flags |= IFF_UP;
                goto mksocket;
-       case SIOCSIFDSTADDR:
-               break;
        case SIOCSIFFLAGS:
                if ((error = ifioctl_common(ifp, cmd, data)) != 0)
                        break;
Index: net/if_ppp.c
===================================================================
RCS file: /cvsroot/src/sys/net/if_ppp.c,v
retrieving revision 1.132
diff -u -p -r1.132 if_ppp.c
--- net/if_ppp.c        21 Aug 2010 13:19:40 -0000      1.132
+++ net/if_ppp.c        9 Mar 2011 21:47:47 -0000
@@ -769,22 +769,6 @@ pppsioctl(struct ifnet *ifp, u_long cmd,
        }
        break;
 
-    case SIOCSIFDSTADDR:
-       switch (ifa->ifa_addr->sa_family) {
-#ifdef INET
-       case AF_INET:
-           break;
-#endif
-#ifdef INET6
-       case AF_INET6:
-           break;
-#endif
-       default:
-           error = EAFNOSUPPORT;
-           break;
-       }
-       break;
-
     case SIOCADDMULTI:
     case SIOCDELMULTI:
        if (ifr == NULL) {
Index: net/if_sl.c
===================================================================
RCS file: /cvsroot/src/sys/net/if_sl.c,v
retrieving revision 1.117
diff -u -p -r1.117 if_sl.c
--- net/if_sl.c 5 Apr 2010 07:22:23 -0000       1.117
+++ net/if_sl.c 9 Mar 2011 21:47:47 -0000
@@ -972,11 +972,6 @@ slioctl(struct ifnet *ifp, u_long cmd, v
                        error = EAFNOSUPPORT;
                break;
 
-       case SIOCSIFDSTADDR:
-               if (ifa->ifa_addr->sa_family != AF_INET)
-                       error = EAFNOSUPPORT;
-               break;
-
        case SIOCSIFMTU:
                if ((ifr->ifr_mtu < 3) || (ifr->ifr_mtu > SLMAX)) {
                    error = EINVAL;
Index: net/if_spppsubr.c
===================================================================
RCS file: /cvsroot/src/sys/net/if_spppsubr.c,v
retrieving revision 1.120
diff -u -p -r1.120 if_spppsubr.c
--- net/if_spppsubr.c   20 Apr 2010 14:32:03 -0000      1.120
+++ net/if_spppsubr.c   9 Mar 2011 21:47:47 -0000
@@ -1047,7 +1047,6 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd
 
        s = splnet();
        switch (cmd) {
-       case SIOCSIFDSTADDR:
        case SIOCINITIFADDR:
                break;
 
Index: net/if_srt.c
===================================================================
RCS file: /cvsroot/src/sys/net/if_srt.c,v
retrieving revision 1.15
diff -u -p -r1.15 if_srt.c
--- net/if_srt.c        9 Sep 2010 03:24:57 -0000       1.15
+++ net/if_srt.c        9 Mar 2011 21:47:47 -0000
@@ -151,7 +151,6 @@ srt_if_ioctl(struct ifnet *ifp, u_long c
        s = splnet();
        switch (cmd) {
        case SIOCINITIFADDR:
-       case SIOCSIFDSTADDR:
                ifa = (void *) data;
                switch (ifa->ifa_addr->sa_family) {
 #ifdef INET
@@ -166,8 +165,9 @@ srt_if_ioctl(struct ifnet *ifp, u_long c
                        err = EAFNOSUPPORT;
                        break;
                }
-               /* XXX do we need to do more here for either of these? */
-               break;
+               if (cmd == SIOCINITIFADDR || err != 0)
+                       break;
+               /*FALLTHROUGH*/
        default:
                if ((err = ifioctl_common(ifp, cmd, data)) == ENETRESET)
                        err = 0;
Index: net/if_strip.c
===================================================================
RCS file: /cvsroot/src/sys/net/if_strip.c,v
retrieving revision 1.95
diff -u -p -r1.95 if_strip.c
--- net/if_strip.c      5 Apr 2010 07:22:24 -0000       1.95
+++ net/if_strip.c      9 Mar 2011 21:47:47 -0000
@@ -1266,11 +1266,6 @@ stripioctl(struct ifnet *ifp, u_long cmd
                        error = EAFNOSUPPORT;
                break;
 
-       case SIOCSIFDSTADDR:
-               if (ifa->ifa_addr->sa_family != AF_INET)
-                       error = EAFNOSUPPORT;
-               break;
-
        case SIOCADDMULTI:
        case SIOCDELMULTI:
                ifr = (struct ifreq *)data;
Index: net/if_tun.c
===================================================================
RCS file: /cvsroot/src/sys/net/if_tun.c,v
retrieving revision 1.113
diff -u -p -r1.113 if_tun.c
--- net/if_tun.c        5 Apr 2010 07:22:24 -0000       1.113
+++ net/if_tun.c        9 Mar 2011 21:47:47 -0000
@@ -442,10 +442,6 @@ tun_ioctl(struct ifnet *ifp, u_long cmd,
                tuninit(tp);
                TUNDEBUG("%s: address set\n", ifp->if_xname);
                break;
-       case SIOCSIFDSTADDR:
-               tuninit(tp);
-               TUNDEBUG("%s: destination address set\n", ifp->if_xname);
-               break;
        case SIOCSIFBRDADDR:
                TUNDEBUG("%s: broadcast address set\n", ifp->if_xname);
                break;
Index: net/if_vlan.c
===================================================================
RCS file: /cvsroot/src/sys/net/if_vlan.c,v
retrieving revision 1.66
diff -u -p -r1.66 if_vlan.c
--- net/if_vlan.c       5 Apr 2010 07:22:24 -0000       1.66
+++ net/if_vlan.c       9 Mar 2011 21:47:48 -0000
@@ -286,11 +286,7 @@ vlan_config(struct ifvlan *ifv, struct i
                         */
                        ec->ec_capenable |= ETHERCAP_VLAN_MTU;
                        if (p->if_flags & IFF_UP) {
-                               struct ifreq ifr;
-
-                               ifr.ifr_flags = p->if_flags;
-                               error = (*p->if_ioctl)(p, SIOCSIFFLAGS,
-                                   (void *) &ifr);
+                               error = if_flags_set(p, p->if_flags);
                                if (error) {
                                        if (ec->ec_nvlans-- == 1)
                                                ec->ec_capenable &=
@@ -381,11 +377,8 @@ vlan_unconfig(struct ifnet *ifp)
                         */
                        ec->ec_capenable &= ~ETHERCAP_VLAN_MTU;
                        if (ifv->ifv_p->if_flags & IFF_UP) {
-                               struct ifreq ifr;
-
-                               ifr.ifr_flags = ifv->ifv_p->if_flags;
-                               (void) (*ifv->ifv_p->if_ioctl)(ifv->ifv_p,
-                                   SIOCSIFFLAGS, (void *) &ifr);
+                               (void)if_flags_set(ifv->ifv_p,
+                                   ifv->ifv_p->if_flags);
                        }
                }
 
@@ -612,8 +605,7 @@ vlan_ether_addmulti(struct ifvlan *ifv, 
        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,
-           (void *)ifr);
+       error = if_mcast_op(ifv->ifv_p, SIOCADDMULTI, sa);
        if (error != 0)
                goto ioctl_failed;
        return (error);
@@ -648,8 +640,7 @@ vlan_ether_delmulti(struct ifvlan *ifv, 
                return (error);
 
        /* We no longer use this multicast address.  Tell parent so. */
-       error = (*ifv->ifv_p->if_ioctl)(ifv->ifv_p, SIOCDELMULTI,
-           (void *)ifr);
+       error = if_mcast_op(ifv->ifv_p, SIOCDELMULTI, sa);
        if (error == 0) {
                /* And forget about this address. */
                for (mc = LIST_FIRST(&ifv->ifv_mc_listhead); mc != NULL;
@@ -675,20 +666,10 @@ vlan_ether_purgemulti(struct ifvlan *ifv
 {
        struct ifnet *ifp = ifv->ifv_p;         /* Parent. */
        struct vlan_mc_entry *mc;
-       union {
-               struct ifreq ifreq;
-               struct {
-                       char ifr_name[IFNAMSIZ];
-                       struct sockaddr_storage ifr_ss;
-               } ifreq_storage;
-       } ifreq;
-       struct ifreq *ifr = &ifreq.ifreq;
 
-       memcpy(ifr->ifr_name, ifp->if_xname, IFNAMSIZ);
        while ((mc = LIST_FIRST(&ifv->ifv_mc_listhead)) != NULL) {
-               ifreq_setaddr(SIOCDELMULTI, ifr,
+               (void)if_mcast_op(ifp, SIOCDELMULTI,
                    (const struct sockaddr *)&mc->mc_addr);
-               (void)(*ifp->if_ioctl)(ifp, SIOCDELMULTI, (void *)ifr);
                LIST_REMOVE(mc, mc_entries);
                free(mc, M_DEVBUF);
        }
Index: net/agr/if_agr.c
===================================================================
RCS file: /cvsroot/src/sys/net/agr/if_agr.c,v
retrieving revision 1.29
diff -u -p -r1.29 if_agr.c
--- net/agr/if_agr.c    11 Aug 2010 11:47:29 -0000      1.29
+++ net/agr/if_agr.c    9 Mar 2011 21:47:48 -0000
@@ -235,7 +235,6 @@ agr_vlan_add(struct agr_port *port, void
 {
        struct ifnet *ifp = port->port_ifp;
        struct ethercom *ec_port = (void *)ifp;
-       struct ifreq ifr;
        int error=0;
 
        if (ec_port->ec_nvlans++ == 0 &&
@@ -246,9 +245,7 @@ agr_vlan_add(struct agr_port *port, void
                 */
                ec_port->ec_capenable |= ETHERCAP_VLAN_MTU;
                if (p->if_flags & IFF_UP) {
-                       ifr.ifr_flags = p->if_flags;
-                       error = (*p->if_ioctl)(p, SIOCSIFFLAGS,
-                           (void *) &ifr);
+                       error = if_flags_set(p, p->if_flags);
                        if (error) {
                                if (ec_port->ec_nvlans-- == 1)
                                        ec_port->ec_capenable &=
@@ -268,7 +265,6 @@ static int
 agr_vlan_del(struct agr_port *port, void *arg)
 {
        struct ethercom *ec_port = (void *)port->port_ifp;
-       struct ifreq ifr;
 
        /* Disable vlan support */
        if (ec_port->ec_nvlans-- == 1) {
@@ -277,9 +273,8 @@ agr_vlan_del(struct agr_port *port, void
                 */
                ec_port->ec_capenable &= ~ETHERCAP_VLAN_MTU;
                if (port->port_ifp->if_flags & IFF_UP) {
-                       ifr.ifr_flags = port->port_ifp->if_flags;
-                       (void) (*port->port_ifp->if_ioctl)(port->port_ifp,
-                           SIOCSIFFLAGS, (void *) &ifr);
+                       (void)if_flags_set(port->port_ifp,
+                           port->port_ifp->if_flags);
                }
        }
 
@@ -641,7 +636,7 @@ agr_addport(struct ifnet *ifp, struct if
         * of each port to that of the first port. No need for arps 
         * since there are no inet addresses assigned to the ports.
         */
-       error = (*ifp_port->if_ioctl)(ifp_port, SIOCINITIFADDR, ifp->if_dl);
+       error = if_addr_init(ifp_port, ifp->if_dl, false);
 
        if (error) {
                printf("%s: SIOCINITIFADDR error %d\n", __func__, error);
Index: net/agr/if_agrether.c
===================================================================
RCS file: /cvsroot/src/sys/net/agr/if_agrether.c,v
retrieving revision 1.8
diff -u -p -r1.8 if_agrether.c
--- net/agr/if_agrether.c       9 Jun 2009 22:26:49 -0000       1.8
+++ net/agr/if_agrether.c       9 Mar 2011 21:47:48 -0000
@@ -175,9 +175,7 @@ agrether_portinit(struct agr_softc *sc, 
                 */
                ec_port->ec_capenable |= ETHERCAP_VLAN_MTU;
                if (p->if_flags & IFF_UP) {
-                       ifr.ifr_flags = p->if_flags;
-                       error = (*p->if_ioctl)(p, SIOCSIFFLAGS,
-                           (void *) &ifr);
+                       error = if_flags_set(p, p->if_flags);
                        if (error) {
                                if (ec_port->ec_nvlans-- == 1)
                                        ec_port->ec_capenable &=
@@ -234,9 +232,8 @@ agrether_portfini(struct agr_softc *sc, 
                 */
                ec_port->ec_capenable &= ~ETHERCAP_VLAN_MTU;
                if (port->port_ifp->if_flags & IFF_UP) {
-                       ifr.ifr_flags = port->port_ifp->if_flags;
-                       (void) (*port->port_ifp->if_ioctl)(port->port_ifp,
-                           SIOCSIFFLAGS, (void *) &ifr);
+                       (void)if_flags_set(port->port_ifp,
+                           port->port_ifp->if_flags);
                }
        }
 
Index: netatalk/at_control.c
===================================================================
RCS file: /cvsroot/src/sys/netatalk/at_control.c,v
retrieving revision 1.33
diff -u -p -r1.33 at_control.c
--- netatalk/at_control.c       30 Jan 2010 21:48:30 -0000      1.33
+++ netatalk/at_control.c       9 Mar 2011 21:47:48 -0000
@@ -575,7 +575,7 @@ at_ifinit(struct ifnet *ifp, struct at_i
         * Now that we have selected an address, we need to tell the
         * interface about it, just in case it needs to adjust something.
         */
-       if ((error = (*ifp->if_ioctl)(ifp, SIOCINITIFADDR, aa)) != 0) {
+       if ((error = if_addr_init(ifp, &aa->aa_ifa, true)) != 0) {
                /*
                 * of course this could mean that it objects violently
                 * so if it does, we back out again..
Index: netinet/in.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/in.c,v
retrieving revision 1.138
diff -u -p -r1.138 in.c
--- netinet/in.c        15 May 2010 05:02:46 -0000      1.138
+++ netinet/in.c        9 Mar 2011 21:47:48 -0000
@@ -454,7 +454,7 @@ in_control(struct socket *so, u_long cmd
                        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_i
         * 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 i
 {
        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 i
                 * 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);
Index: netinet/ip_carp.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/ip_carp.c,v
retrieving revision 1.44
diff -u -p -r1.44 ip_carp.c
--- netinet/ip_carp.c   11 Aug 2010 11:06:42 -0000      1.44
+++ netinet/ip_carp.c   9 Mar 2011 21:47:48 -0000
@@ -2153,7 +2153,7 @@ carp_ether_addmulti(struct carp_softc *s
        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;
 
@@ -2205,7 +2205,7 @@ carp_ether_delmulti(struct carp_softc *s
                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);
@@ -2224,22 +2224,12 @@ carp_ether_purgemulti(struct carp_softc 
 {
        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);
        }
Index: netinet/ip_mroute.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/ip_mroute.c,v
retrieving revision 1.118
diff -u -p -r1.118 ip_mroute.c
--- netinet/ip_mroute.c 18 Mar 2009 16:00:22 -0000      1.118
+++ netinet/ip_mroute.c 9 Mar 2011 21:47:49 -0000
@@ -789,7 +789,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;
 
@@ -869,8 +868,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);
        }
@@ -928,7 +926,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);
@@ -953,9 +950,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));
 }
Index: netinet6/in6.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/in6.c,v
retrieving revision 1.157
diff -u -p -r1.157 in6.c
--- netinet6/in6.c      6 Feb 2011 19:12:55 -0000       1.157
+++ netinet6/in6.c      9 Mar 2011 21:47:49 -0000
@@ -1753,8 +1753,8 @@ in6_ifinit(struct ifnet *ifp, struct in6
 
        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;
        }
Index: netinet6/ip6_mroute.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/ip6_mroute.c,v
retrieving revision 1.100
diff -u -p -r1.100 ip6_mroute.c
--- netinet6/ip6_mroute.c       14 Oct 2010 03:34:42 -0000      1.100
+++ netinet6/ip6_mroute.c       9 Mar 2011 21:47:49 -0000
@@ -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);
Index: netinet6/mld6.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/mld6.c,v
retrieving revision 1.51
diff -u -p -r1.51 mld6.c
--- netinet6/mld6.c     4 Aug 2009 22:04:23 -0000       1.51
+++ netinet6/mld6.c     9 Mar 2011 21:47:49 -0000
@@ -616,7 +616,7 @@ in6_addmulti(struct in6_addr *maddr6, st
        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, st
                 * 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, st
 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);
        }
Index: netisdn/i4b_ipr.c
===================================================================
RCS file: /cvsroot/src/sys/netisdn/i4b_ipr.c,v
retrieving revision 1.35
diff -u -p -r1.35 i4b_ipr.c
--- netisdn/i4b_ipr.c   5 Apr 2010 07:22:50 -0000       1.35
+++ netisdn/i4b_ipr.c   9 Mar 2011 21:47:49 -0000
@@ -576,7 +576,6 @@ iripioctl(struct ifnet *ifp, u_long cmd,
        {
                case SIOCAIFADDR:       /* add interface address */
                case SIOCINITIFADDR:    /* set interface address */
-               case SIOCSIFDSTADDR:    /* set interface destination address */
                        if(ifa->ifa_addr->sa_family != AF_INET)
                                error = EAFNOSUPPORT;
                        else
Index: netiso/iso.c
===================================================================
RCS file: /cvsroot/src/sys/netiso/iso.c,v
retrieving revision 1.57
diff -u -p -r1.57 iso.c
--- netiso/iso.c        7 Aug 2009 14:04:34 -0000       1.57
+++ netiso/iso.c        9 Mar 2011 21:47:50 -0000
@@ -649,7 +649,7 @@ iso_ifinit(struct ifnet *ifp, struct iso
         * 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);
Index: netiso/iso_snpac.c
===================================================================
RCS file: /cvsroot/src/sys/netiso/iso_snpac.c,v
retrieving revision 1.53
diff -u -p -r1.53 iso_snpac.c
--- netiso/iso_snpac.c  16 Apr 2009 21:37:17 -0000      1.53
+++ netiso/iso_snpac.c  9 Mar 2011 21:47:50 -0000
@@ -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);
        }


Home | Main Index | Thread Index | Old Index