diff options
-rw-r--r-- | sys/net/if.c | 17 | ||||
-rw-r--r-- | sys/net/route.c | 30 | ||||
-rw-r--r-- | sys/net/route.h | 3 | ||||
-rw-r--r-- | sys/net/rtsock.c | 6 |
4 files changed, 24 insertions, 32 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index bb06caf9f1d..156b9e94992 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.223 2010/08/25 13:57:07 claudio Exp $ */ +/* $OpenBSD: if.c,v 1.224 2010/08/25 14:07:24 claudio Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -1488,6 +1488,17 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) ifr->ifr_rdomainid > RT_TABLEID_MAX) return (EINVAL); + /* make sure that the routing table exists */ + if (!rtable_exists(ifr->ifr_rdomainid)) { + if ((error = rtable_add(ifr->ifr_rdomainid)) != 0) + return (error); + rtable_l2set(ifr->ifr_rdomainid, ifr->ifr_rdomainid); + } + + /* make sure that the routing table is a real rdomain */ + if (ifr->ifr_rdomainid != rtable_l2(ifr->ifr_rdomainid)) + return (EINVAL); + /* remove all routing entries when switching domains */ /* XXX hell this is ugly */ if (ifr->ifr_rdomainid != ifp->if_rdomain) { @@ -1525,13 +1536,13 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) splx(s); } - /* Let devices like enc(4) enforce the rdomain */ + /* Let devices like enc(4) or mpe(4) know about the change */ if ((error = (*ifp->if_ioctl)(ifp, cmd, data)) != ENOTTY) return (error); error = 0; /* Add interface to the specified rdomain */ - rtable_addif(ifp, ifr->ifr_rdomainid); + ifp->if_rdomain = ifr->ifr_rdomainid; break; case SIOCAIFGROUP: diff --git a/sys/net/route.c b/sys/net/route.c index 23a34d699d2..e2e53bd2e45 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.126 2010/08/24 15:50:16 claudio Exp $ */ +/* $OpenBSD: route.c,v 1.127 2010/08/25 14:07:24 claudio Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -185,7 +185,7 @@ rtable_init(struct radix_node_head ***table, u_int id) if ((p = malloc(sizeof(void *) * (rtafidx_max + 1), M_RTABLE, M_NOWAIT|M_ZERO)) == NULL) - return (-1); + return (ENOMEM); /* 2nd pass: attach */ for (dom = domains; dom != NULL; dom = dom->dom_next) @@ -220,7 +220,7 @@ route_init(void) if (dom->dom_rtattach) af2rtafidx[dom->dom_family] = rtafidx_max++; - if (rtable_add(0) == -1) + if (rtable_add(0) != 0) panic("route_init rtable_add"); } @@ -230,17 +230,17 @@ rtable_add(u_int id) /* must be called at splsoftnet */ void *p, *q; if (id > RT_TABLEID_MAX) - return (-1); + return (EINVAL); if (id == 0 || id > rtbl_id_max) { size_t newlen = sizeof(void *) * (id+1); size_t newlen2 = sizeof(u_int) * (id+1); if ((p = malloc(newlen, M_RTABLE, M_NOWAIT|M_ZERO)) == NULL) - return (-1); + return (ENOMEM); if ((q = malloc(newlen2, M_RTABLE, M_NOWAIT|M_ZERO)) == NULL) { free(p, M_RTABLE); - return (-1); + return (ENOMEM); } if (rt_tables) { bcopy(rt_tables, p, sizeof(void *) * (rtbl_id_max+1)); @@ -254,28 +254,12 @@ rtable_add(u_int id) /* must be called at splsoftnet */ } if (rt_tables[id] != NULL) /* already exists */ - return (-1); + return (EEXIST); rt_tab2dom[id] = 0; /* use main table/domain by default */ return (rtable_init(&rt_tables[id], id)); } -void -rtable_addif(struct ifnet *ifp, u_int id) -{ - /* make sure that the routing table exists */ - if (!rtable_exists(id)) { - if (rtable_add(id) == -1) - panic("rtable_addif: rtable_add"); - } - if (id != rtable_l2(id)) { - /* XXX we should probably flush the table */ - rtable_l2set(id, id); - } - - ifp->if_rdomain = id; -} - u_int rtable_l2(u_int id) { diff --git a/sys/net/route.h b/sys/net/route.h index 08ee0b05350..8ab5284bc3e 100644 --- a/sys/net/route.h +++ b/sys/net/route.h @@ -1,4 +1,4 @@ -/* $OpenBSD: route.h,v 1.72 2010/07/14 00:42:57 dlg Exp $ */ +/* $OpenBSD: route.h,v 1.73 2010/08/25 14:07:24 claudio Exp $ */ /* $NetBSD: route.h,v 1.9 1996/02/13 22:00:49 christos Exp $ */ /* @@ -355,7 +355,6 @@ extern const struct sockaddr_rtin rt_defmask4; struct socket; void route_init(void); int rtable_add(u_int); -void rtable_addif(struct ifnet *, u_int); u_int rtable_l2(u_int); void rtable_l2set(u_int, u_int); int rtable_exists(u_int); diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 9a424137104..66ae5a7d0d6 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.106 2010/08/24 12:45:08 claudio Exp $ */ +/* $OpenBSD: rtsock.c,v 1.107 2010/08/25 14:07:24 claudio Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -459,10 +459,8 @@ route_output(struct mbuf *m, ...) tableid = rtm->rtm_tableid; if (!rtable_exists(tableid)) { if (rtm->rtm_type == RTM_ADD) { - if (rtable_add(tableid)) { - error = EINVAL; + if ((error = rtable_add(tableid)) != NULL) goto flush; - } } else { error = EINVAL; goto flush; |