-/* $OpenBSD: if.c,v 1.286 2014/04/22 12:35:00 mpi Exp $ */
+/* $OpenBSD: if.c,v 1.287 2014/05/05 11:44:33 mpi Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
}
}
+/*
+ * Default action when installing a local route on a point-to-point
+ * interface.
+ */
+void
+p2p_rtrequest(int req, struct rtentry *rt)
+{
+ struct ifnet *ifp = rt->rt_ifp;
+ struct ifaddr *ifa, *lo0ifa;
+
+ switch (req) {
+ case RTM_ADD:
+ /*
+ * XXX Here we abuse RTF_LLINFO to add a route to
+ * loopback. We do that to always have a route
+ * pointing to our address.
+ */
+ if ((rt->rt_flags & RTF_LLINFO) == 0)
+ break;
+
+ TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
+ if (memcmp(rt_key(rt), ifa->ifa_addr,
+ rt_key(rt)->sa_len) == 0)
+ break;
+ }
+
+ if (ifa == NULL)
+ break;
+
+ /*
+ * XXX Since lo0 is in the default rdomain we should not
+ * (ab)use it for any route related to an interface of a
+ * different rdomain.
+ */
+ TAILQ_FOREACH(lo0ifa, &lo0ifp->if_addrlist, ifa_list)
+ if (lo0ifa->ifa_addr->sa_family ==
+ ifa->ifa_addr->sa_family)
+ break;
+
+ if (lo0ifa == NULL)
+ break;
+
+ rt_setgate(rt, rt_key(rt), lo0ifa->ifa_addr, ifp->if_rdomain);
+ rt->rt_ifp = lo0ifp;
+ rt->rt_flags &= ~RTF_LLINFO;
+
+ /*
+ * make sure to set rt->rt_ifa to the interface
+ * address we are using, otherwise we will have trouble
+ * with source address selection.
+ */
+ if (ifa != rt->rt_ifa) {
+ ifafree(rt->rt_ifa);
+ ifa->ifa_refcnt++;
+ rt->rt_ifa = ifa;
+ }
+ break;
+ case RTM_DELETE:
+ case RTM_RESOLVE:
+ default:
+ break;
+ }
+}
+
+
/*
* Bring down all interfaces
*/
-/* $OpenBSD: if_gif.c,v 1.66 2014/04/21 12:22:25 henning Exp $ */
+/* $OpenBSD: if_gif.c,v 1.67 2014/05/05 11:44:33 mpi Exp $ */
/* $KAME: if_gif.c,v 1.43 2001/02/20 08:51:07 itojun Exp $ */
/*
gif_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
{
struct gif_softc *sc = (struct gif_softc*)ifp;
- struct ifreq *ifr = (struct ifreq*)data;
+ struct ifreq *ifr = (struct ifreq *)data;
+ struct ifaddr *ifa = (struct ifaddr *)data;
int error = 0, size;
struct sockaddr *dst, *src;
struct sockaddr *sa;
switch (cmd) {
case SIOCSIFADDR:
+ ifa->ifa_rtrequest = p2p_rtrequest;
break;
case SIOCSIFDSTADDR:
-/* $OpenBSD: if_gre.c,v 1.67 2014/04/21 12:22:25 henning Exp $ */
+/* $OpenBSD: if_gre.c,v 1.68 2014/05/05 11:44:33 mpi Exp $ */
/* $NetBSD: if_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */
/*
gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
{
- struct ifreq *ifr = (struct ifreq *) data;
+ struct ifreq *ifr = (struct ifreq *)data;
+ struct ifaddr *ifa = (struct ifaddr *)data;
struct if_laddrreq *lifr = (struct if_laddrreq *)data;
struct ifkalivereq *ikar = (struct ifkalivereq *)data;
struct gre_softc *sc = ifp->if_softc;
switch(cmd) {
case SIOCSIFADDR:
ifp->if_flags |= IFF_UP;
+ ifa->ifa_rtrequest = p2p_rtrequest;
break;
case SIOCSIFDSTADDR:
break;
-/* $OpenBSD: if_ppp.c,v 1.73 2014/04/19 12:08:10 henning Exp $ */
+/* $OpenBSD: if_ppp.c,v 1.74 2014/05/05 11:44:33 mpi Exp $ */
/* $NetBSD: if_ppp.c,v 1.39 1997/05/17 21:11:59 christos Exp $ */
/*
case SIOCSIFADDR:
if (ifa->ifa_addr->sa_family != AF_INET)
error = EAFNOSUPPORT;
+ ifa->ifa_rtrequest = p2p_rtrequest;
break;
case SIOCSIFDSTADDR:
-/* $OpenBSD: if_pppx.c,v 1.29 2014/04/08 04:26:53 miod Exp $ */
+/* $OpenBSD: if_pppx.c,v 1.30 2014/05/05 11:44:33 mpi Exp $ */
/*
* Copyright (c) 2010 Claudio Jeker <claudio@openbsd.org>
{
struct pppx_if *pxi = (struct pppx_if *)ifp->if_softc;
struct ifreq *ifr = (struct ifreq *)addr;
+ struct ifaddr *ifa = (struct ifaddr *)addr;
int error = 0;
switch (cmd) {
case SIOCSIFADDR:
+ ifa->ifa_rtrequest = p2p_rtrequest;
+ break;
+
case SIOCSIFFLAGS:
break;
-/* $OpenBSD: if_spppsubr.c,v 1.122 2014/05/02 10:40:26 jca Exp $ */
+/* $OpenBSD: if_spppsubr.c,v 1.123 2014/05/05 11:44:33 mpi Exp $ */
/*
* Synchronous PPP/Cisco link level subroutines.
* Keepalive protocol implemented in both Cisco and PPP modes.
int
sppp_ioctl(struct ifnet *ifp, u_long cmd, void *data)
{
- struct ifreq *ifr = (struct ifreq*) data;
+ struct ifreq *ifr = data;
+ struct ifaddr *ifa = data;
struct sppp *sp = (struct sppp*) ifp;
int s, rv, going_up, going_down, newmode;
case SIOCSIFADDR:
if_up(ifp);
+ ifa->ifa_rtrequest = p2p_rtrequest;
/* FALLTHROUGH */
case SIOCSIFFLAGS:
-/* $OpenBSD: if_tun.c,v 1.124 2014/04/22 14:41:03 mpi Exp $ */
+/* $OpenBSD: if_tun.c,v 1.125 2014/05/05 11:44:33 mpi Exp $ */
/* $NetBSD: if_tun.c,v 1.24 1996/05/07 02:40:48 thorpej Exp $ */
/*
{
struct tun_softc *tp = (struct tun_softc *)(ifp->if_softc);
struct ifreq *ifr = (struct ifreq *)data;
+ struct ifaddr *ifa = (struct ifaddr *)data;
int error = 0, s;
s = splnet();
case SIOCSIFADDR:
tuninit(tp);
TUNDEBUG(("%s: address set\n", ifp->if_xname));
- if (tp->tun_flags & TUN_LAYER2)
- switch (((struct ifaddr *)data)->ifa_addr->sa_family) {
+ if (tp->tun_flags & TUN_LAYER2) {
+ switch (ifa->ifa_addr->sa_family) {
#ifdef INET
case AF_INET:
- arp_ifinit(&tp->arpcom, (struct ifaddr *)data);
+ arp_ifinit(&tp->arpcom, ifa);
break;
#endif
default:
break;
}
+ } else {
+ ifa->ifa_rtrequest = p2p_rtrequest;
+ }
break;
case SIOCSIFDSTADDR:
tuninit(tp);
-/* $OpenBSD: if_var.h,v 1.9 2014/04/23 09:30:57 mpi Exp $ */
+/* $OpenBSD: if_var.h,v 1.10 2014/05/05 11:44:33 mpi Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *);
void ifafree(struct ifaddr *);
void link_rtrequest(int, struct rtentry *);
+void p2p_rtrequest(int, struct rtentry *);
void if_clone_attach(struct if_clone *);
void if_clone_detach(struct if_clone *);
-/* $OpenBSD: if_ether.c,v 1.125 2014/04/14 09:06:42 mpi Exp $ */
+/* $OpenBSD: if_ether.c,v 1.126 2014/05/05 11:44:33 mpi Exp $ */
/* $NetBSD: if_ether.c,v 1.31 1996/05/11 12:59:58 mycroft Exp $ */
/*
SDL(gate)->sdl_alen = ETHER_ADDR_LEN;
memcpy(LLADDR(SDL(gate)),
((struct arpcom *)ifp)->ac_enaddr, ETHER_ADDR_LEN);
+
+ /*
+ * XXX Since lo0 is in the default rdomain we
+ * should not (ab)use it for any route related
+ * to an interface of a different rdomain.
+ */
if (useloopback)
rt->rt_ifp = lo0ifp;
/*
-/* $OpenBSD: in6.c,v 1.135 2014/04/10 13:47:21 mpi Exp $ */
+/* $OpenBSD: in6.c,v 1.136 2014/05/05 11:44:33 mpi Exp $ */
/* $KAME: in6.c,v 1.372 2004/06/14 08:14:21 itojun Exp $ */
/*
ifacount++;
}
- if ((ifacount <= 1 || ifp->if_type == IFT_CARP) && ifp->if_ioctl &&
+ if ((ifacount <= 1 || ifp->if_type == IFT_CARP ||
+ (ifp->if_flags & IFF_POINTOPOINT)) && ifp->if_ioctl &&
(error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia6))) {
splx(s);
return (error);
/* Add ownaddr as loopback rtentry, if necessary (ex. on p2p link). */
if (newhost) {
/* set the rtrequest function to create llinfo */
- ia6->ia_ifa.ifa_rtrequest = nd6_rtrequest;
+ if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
+ ia6->ia_ifa.ifa_rtrequest = nd6_rtrequest;
+
rt_ifa_addloop(&(ia6->ia_ifa));
}
-/* $OpenBSD: nd6.c,v 1.114 2014/04/14 09:06:42 mpi Exp $ */
+/* $OpenBSD: nd6.c,v 1.115 2014/05/05 11:44:33 mpi Exp $ */
/* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */
/*
memcpy(LLADDR(SDL(gate)), macp, ifp->if_addrlen);
SDL(gate)->sdl_alen = ifp->if_addrlen;
}
+
+ /*
+ * XXX Since lo0 is in the default rdomain we
+ * should not (ab)use it for any route related
+ * to an interface of a different rdomain.
+ */
if (nd6_useloopback) {
- rt->rt_ifp = lo0ifp; /*XXX*/
+ rt->rt_ifp = lo0ifp;
/*
* Make sure rt_ifa be equal to the ifaddr
* corresponding to the address.