2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
1994-05-24 10:09:53 +00:00
|
|
|
* Copyright (c) 1988, 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
2001-10-17 11:23:59 +00:00
|
|
|
* @(#)rtsock.c 8.7 (Berkeley) 10/12/95
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
2006-11-03 15:23:16 +00:00
|
|
|
#include "opt_sctp.h"
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/param.h>
|
2002-04-30 01:54:54 +00:00
|
|
|
#include <sys/domain.h>
|
1995-05-11 00:13:26 +00:00
|
|
|
#include <sys/kernel.h>
|
2002-04-30 01:54:54 +00:00
|
|
|
#include <sys/jail.h>
|
1997-09-02 01:19:47 +00:00
|
|
|
#include <sys/malloc.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/mbuf.h>
|
2006-11-06 13:42:10 +00:00
|
|
|
#include <sys/priv.h>
|
2002-04-30 01:54:54 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/signalvar.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
2002-04-30 01:54:54 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/systm.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
Introduce a netisr to deliver kernel-generated routing, avoiding
recursive entering of the socket code from the routing code:
- Modify rt_dispatch() to bundle up the sockaddr family, if any,
associated with a pending mbuf to dispatch to routing sockets, in
an m_tag on the mbuf.
- Allocate NETISR_ROUTE for use by routing sockets.
- Introduce rtsintrq, an ifqueue to be used by the netisr, and
introduce rts_input(), a function to unbundle the tagged sockaddr
and inject the mbuf and address into raw_input(), which previously
occurred in rt_dispatch().
- Introduce rts_init() to initialize rtsintrq, its mutex, and
register the netisr. Perform this at the same point in system
initialization as setup of the domains.
This change introduces asynchrony between the generation of a
pending routing socket message and delivery to sockets for use
by userspace. It avoids socket->routing->rtsock->socket use and
helps to avoid lock order reversals between the routing code and
socket code (in particular, raw socket control blocks), as route
locks are held over calls to rt_dispatch().
Reviewed by: "George V.Neville-Neil" <gnn@neville-neil.com>
Conceptual head nod by: sam
2004-06-09 02:48:23 +00:00
|
|
|
#include <net/netisr.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <net/raw_cb.h>
|
2002-04-30 01:54:54 +00:00
|
|
|
#include <net/route.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2004-04-26 19:46:52 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP
|
|
|
|
extern void sctp_addr_change(struct ifaddr *ifa, int cmd);
|
|
|
|
#endif /* SCTP */
|
|
|
|
|
1997-10-12 20:26:33 +00:00
|
|
|
MALLOC_DEFINE(M_RTABLE, "routetbl", "routing tables");
|
|
|
|
|
2003-10-03 18:15:54 +00:00
|
|
|
/* NB: these are not modified */
|
1995-11-16 19:00:27 +00:00
|
|
|
static struct sockaddr route_dst = { 2, PF_ROUTE, };
|
|
|
|
static struct sockaddr route_src = { 2, PF_ROUTE, };
|
1997-07-18 11:44:24 +00:00
|
|
|
static struct sockaddr sa_zero = { sizeof(sa_zero), AF_INET, };
|
2003-10-03 18:15:54 +00:00
|
|
|
|
|
|
|
static struct {
|
2004-08-24 08:47:15 +00:00
|
|
|
int ip_count; /* attached w/ AF_INET */
|
2003-10-03 18:15:54 +00:00
|
|
|
int ip6_count; /* attached w/ AF_INET6 */
|
|
|
|
int ipx_count; /* attached w/ AF_IPX */
|
|
|
|
int any_count; /* total attached */
|
|
|
|
} route_cb;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2003-10-03 18:27:02 +00:00
|
|
|
struct mtx rtsock_mtx;
|
|
|
|
MTX_SYSINIT(rtsock, &rtsock_mtx, "rtsock route_cb lock", MTX_DEF);
|
|
|
|
|
|
|
|
#define RTSOCK_LOCK() mtx_lock(&rtsock_mtx)
|
|
|
|
#define RTSOCK_UNLOCK() mtx_unlock(&rtsock_mtx)
|
|
|
|
#define RTSOCK_LOCK_ASSERT() mtx_assert(&rtsock_mtx, MA_OWNED)
|
|
|
|
|
Introduce a netisr to deliver kernel-generated routing, avoiding
recursive entering of the socket code from the routing code:
- Modify rt_dispatch() to bundle up the sockaddr family, if any,
associated with a pending mbuf to dispatch to routing sockets, in
an m_tag on the mbuf.
- Allocate NETISR_ROUTE for use by routing sockets.
- Introduce rtsintrq, an ifqueue to be used by the netisr, and
introduce rts_input(), a function to unbundle the tagged sockaddr
and inject the mbuf and address into raw_input(), which previously
occurred in rt_dispatch().
- Introduce rts_init() to initialize rtsintrq, its mutex, and
register the netisr. Perform this at the same point in system
initialization as setup of the domains.
This change introduces asynchrony between the generation of a
pending routing socket message and delivery to sockets for use
by userspace. It avoids socket->routing->rtsock->socket use and
helps to avoid lock order reversals between the routing code and
socket code (in particular, raw socket control blocks), as route
locks are held over calls to rt_dispatch().
Reviewed by: "George V.Neville-Neil" <gnn@neville-neil.com>
Conceptual head nod by: sam
2004-06-09 02:48:23 +00:00
|
|
|
static struct ifqueue rtsintrq;
|
|
|
|
|
2004-08-21 21:20:06 +00:00
|
|
|
SYSCTL_NODE(_net, OID_AUTO, route, CTLFLAG_RD, 0, "");
|
|
|
|
SYSCTL_INT(_net_route, OID_AUTO, netisr_maxqlen, CTLFLAG_RW,
|
|
|
|
&rtsintrq.ifq_maxlen, 0, "maximum routing socket dispatch queue length");
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
struct walkarg {
|
1995-11-16 19:00:27 +00:00
|
|
|
int w_tmemsize;
|
|
|
|
int w_op, w_arg;
|
|
|
|
caddr_t w_tmem;
|
|
|
|
struct sysctl_req *w_req;
|
1994-05-24 10:09:53 +00:00
|
|
|
};
|
|
|
|
|
Introduce a netisr to deliver kernel-generated routing, avoiding
recursive entering of the socket code from the routing code:
- Modify rt_dispatch() to bundle up the sockaddr family, if any,
associated with a pending mbuf to dispatch to routing sockets, in
an m_tag on the mbuf.
- Allocate NETISR_ROUTE for use by routing sockets.
- Introduce rtsintrq, an ifqueue to be used by the netisr, and
introduce rts_input(), a function to unbundle the tagged sockaddr
and inject the mbuf and address into raw_input(), which previously
occurred in rt_dispatch().
- Introduce rts_init() to initialize rtsintrq, its mutex, and
register the netisr. Perform this at the same point in system
initialization as setup of the domains.
This change introduces asynchrony between the generation of a
pending routing socket message and delivery to sockets for use
by userspace. It avoids socket->routing->rtsock->socket use and
helps to avoid lock order reversals between the routing code and
socket code (in particular, raw socket control blocks), as route
locks are held over calls to rt_dispatch().
Reviewed by: "George V.Neville-Neil" <gnn@neville-neil.com>
Conceptual head nod by: sam
2004-06-09 02:48:23 +00:00
|
|
|
static void rts_input(struct mbuf *m);
|
2004-04-18 00:56:44 +00:00
|
|
|
static struct mbuf *rt_msg1(int type, struct rt_addrinfo *rtinfo);
|
|
|
|
static int rt_msg2(int type, struct rt_addrinfo *rtinfo,
|
|
|
|
caddr_t cp, struct walkarg *w);
|
|
|
|
static int rt_xaddrs(caddr_t cp, caddr_t cplim,
|
|
|
|
struct rt_addrinfo *rtinfo);
|
2002-03-19 21:54:18 +00:00
|
|
|
static int sysctl_dumpentry(struct radix_node *rn, void *vw);
|
|
|
|
static int sysctl_iflist(int af, struct walkarg *w);
|
2003-11-14 18:48:15 +00:00
|
|
|
static int sysctl_ifmalist(int af, struct walkarg *w);
|
2004-04-18 00:56:44 +00:00
|
|
|
static int route_output(struct mbuf *m, struct socket *so);
|
|
|
|
static void rt_setmetrics(u_long which, const struct rt_metrics *in,
|
|
|
|
struct rt_metrics_lite *out);
|
|
|
|
static void rt_getmetrics(const struct rt_metrics_lite *in,
|
|
|
|
struct rt_metrics *out);
|
|
|
|
static void rt_dispatch(struct mbuf *, const struct sockaddr *);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
Introduce a netisr to deliver kernel-generated routing, avoiding
recursive entering of the socket code from the routing code:
- Modify rt_dispatch() to bundle up the sockaddr family, if any,
associated with a pending mbuf to dispatch to routing sockets, in
an m_tag on the mbuf.
- Allocate NETISR_ROUTE for use by routing sockets.
- Introduce rtsintrq, an ifqueue to be used by the netisr, and
introduce rts_input(), a function to unbundle the tagged sockaddr
and inject the mbuf and address into raw_input(), which previously
occurred in rt_dispatch().
- Introduce rts_init() to initialize rtsintrq, its mutex, and
register the netisr. Perform this at the same point in system
initialization as setup of the domains.
This change introduces asynchrony between the generation of a
pending routing socket message and delivery to sockets for use
by userspace. It avoids socket->routing->rtsock->socket use and
helps to avoid lock order reversals between the routing code and
socket code (in particular, raw socket control blocks), as route
locks are held over calls to rt_dispatch().
Reviewed by: "George V.Neville-Neil" <gnn@neville-neil.com>
Conceptual head nod by: sam
2004-06-09 02:48:23 +00:00
|
|
|
static void
|
|
|
|
rts_init(void)
|
|
|
|
{
|
2004-08-21 21:45:40 +00:00
|
|
|
int tmp;
|
Introduce a netisr to deliver kernel-generated routing, avoiding
recursive entering of the socket code from the routing code:
- Modify rt_dispatch() to bundle up the sockaddr family, if any,
associated with a pending mbuf to dispatch to routing sockets, in
an m_tag on the mbuf.
- Allocate NETISR_ROUTE for use by routing sockets.
- Introduce rtsintrq, an ifqueue to be used by the netisr, and
introduce rts_input(), a function to unbundle the tagged sockaddr
and inject the mbuf and address into raw_input(), which previously
occurred in rt_dispatch().
- Introduce rts_init() to initialize rtsintrq, its mutex, and
register the netisr. Perform this at the same point in system
initialization as setup of the domains.
This change introduces asynchrony between the generation of a
pending routing socket message and delivery to sockets for use
by userspace. It avoids socket->routing->rtsock->socket use and
helps to avoid lock order reversals between the routing code and
socket code (in particular, raw socket control blocks), as route
locks are held over calls to rt_dispatch().
Reviewed by: "George V.Neville-Neil" <gnn@neville-neil.com>
Conceptual head nod by: sam
2004-06-09 02:48:23 +00:00
|
|
|
|
2004-08-21 21:20:06 +00:00
|
|
|
rtsintrq.ifq_maxlen = 256;
|
2004-08-21 21:45:40 +00:00
|
|
|
if (TUNABLE_INT_FETCH("net.route.netisr_maxqlen", &tmp))
|
|
|
|
rtsintrq.ifq_maxlen = tmp;
|
Introduce a netisr to deliver kernel-generated routing, avoiding
recursive entering of the socket code from the routing code:
- Modify rt_dispatch() to bundle up the sockaddr family, if any,
associated with a pending mbuf to dispatch to routing sockets, in
an m_tag on the mbuf.
- Allocate NETISR_ROUTE for use by routing sockets.
- Introduce rtsintrq, an ifqueue to be used by the netisr, and
introduce rts_input(), a function to unbundle the tagged sockaddr
and inject the mbuf and address into raw_input(), which previously
occurred in rt_dispatch().
- Introduce rts_init() to initialize rtsintrq, its mutex, and
register the netisr. Perform this at the same point in system
initialization as setup of the domains.
This change introduces asynchrony between the generation of a
pending routing socket message and delivery to sockets for use
by userspace. It avoids socket->routing->rtsock->socket use and
helps to avoid lock order reversals between the routing code and
socket code (in particular, raw socket control blocks), as route
locks are held over calls to rt_dispatch().
Reviewed by: "George V.Neville-Neil" <gnn@neville-neil.com>
Conceptual head nod by: sam
2004-06-09 02:48:23 +00:00
|
|
|
mtx_init(&rtsintrq.ifq_mtx, "rts_inq", NULL, MTX_DEF);
|
|
|
|
netisr_register(NETISR_ROUTE, rts_input, &rtsintrq, NETISR_MPSAFE);
|
|
|
|
}
|
2008-03-16 10:58:09 +00:00
|
|
|
SYSINIT(rtsock, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, rts_init, 0);
|
Introduce a netisr to deliver kernel-generated routing, avoiding
recursive entering of the socket code from the routing code:
- Modify rt_dispatch() to bundle up the sockaddr family, if any,
associated with a pending mbuf to dispatch to routing sockets, in
an m_tag on the mbuf.
- Allocate NETISR_ROUTE for use by routing sockets.
- Introduce rtsintrq, an ifqueue to be used by the netisr, and
introduce rts_input(), a function to unbundle the tagged sockaddr
and inject the mbuf and address into raw_input(), which previously
occurred in rt_dispatch().
- Introduce rts_init() to initialize rtsintrq, its mutex, and
register the netisr. Perform this at the same point in system
initialization as setup of the domains.
This change introduces asynchrony between the generation of a
pending routing socket message and delivery to sockets for use
by userspace. It avoids socket->routing->rtsock->socket use and
helps to avoid lock order reversals between the routing code and
socket code (in particular, raw socket control blocks), as route
locks are held over calls to rt_dispatch().
Reviewed by: "George V.Neville-Neil" <gnn@neville-neil.com>
Conceptual head nod by: sam
2004-06-09 02:48:23 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
rts_input(struct mbuf *m)
|
|
|
|
{
|
|
|
|
struct sockproto route_proto;
|
|
|
|
unsigned short *family;
|
|
|
|
struct m_tag *tag;
|
|
|
|
|
|
|
|
route_proto.sp_family = PF_ROUTE;
|
|
|
|
tag = m_tag_find(m, PACKET_TAG_RTSOCKFAM, NULL);
|
|
|
|
if (tag != NULL) {
|
|
|
|
family = (unsigned short *)(tag + 1);
|
|
|
|
route_proto.sp_protocol = *family;
|
|
|
|
m_tag_delete(m, tag);
|
|
|
|
} else
|
|
|
|
route_proto.sp_protocol = 0;
|
|
|
|
|
|
|
|
raw_input(m, &route_proto, &route_src, &route_dst);
|
|
|
|
}
|
|
|
|
|
1997-04-27 20:01:29 +00:00
|
|
|
/*
|
|
|
|
* It really doesn't make any sense at all for this code to share much
|
|
|
|
* with raw_usrreq.c, since its functionality is so restricted. XXX
|
|
|
|
*/
|
2006-04-01 15:15:05 +00:00
|
|
|
static void
|
1997-04-27 20:01:29 +00:00
|
|
|
rts_abort(struct socket *so)
|
|
|
|
{
|
2005-08-25 13:30:04 +00:00
|
|
|
|
2006-04-01 15:15:05 +00:00
|
|
|
raw_usrreqs.pru_abort(so);
|
1997-04-27 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
2006-07-21 17:11:15 +00:00
|
|
|
static void
|
|
|
|
rts_close(struct socket *so)
|
|
|
|
{
|
|
|
|
|
|
|
|
raw_usrreqs.pru_close(so);
|
|
|
|
}
|
|
|
|
|
1997-04-27 20:01:29 +00:00
|
|
|
/* pru_accept is EOPNOTSUPP */
|
|
|
|
|
1995-11-16 19:00:27 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
rts_attach(struct socket *so, int proto, struct thread *td)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
1997-04-27 20:01:29 +00:00
|
|
|
struct rawcb *rp;
|
|
|
|
int s, error;
|
|
|
|
|
Chance protocol switch method pru_detach() so that it returns void
rather than an error. Detaches do not "fail", they other occur or
the protocol flags SS_PROTOREF to take ownership of the socket.
soclose() no longer looks at so_pcb to see if it's NULL, relying
entirely on the protocol to decide whether it's time to free the
socket or not using SS_PROTOREF. so_pcb is now entirely owned and
managed by the protocol code. Likewise, no longer test so_pcb in
other socket functions, such as soreceive(), which have no business
digging into protocol internals.
Protocol detach routines no longer try to free the socket on detach,
this is performed in the socket code if the protocol permits it.
In rts_detach(), no longer test for rp != NULL in detach, and
likewise in other protocols that don't permit a NULL so_pcb, reduce
the incidence of testing for it during detach.
netinet and netinet6 are not fully updated to this change, which
will be in an upcoming commit. In their current state they may leak
memory or panic.
MFC after: 3 months
2006-04-01 15:42:02 +00:00
|
|
|
KASSERT(so->so_pcb == NULL, ("rts_attach: so_pcb != NULL"));
|
|
|
|
|
2000-12-08 21:51:06 +00:00
|
|
|
/* XXX */
|
2003-02-19 05:47:46 +00:00
|
|
|
MALLOC(rp, struct rawcb *, sizeof *rp, M_PCB, M_WAITOK | M_ZERO);
|
2004-04-18 00:56:44 +00:00
|
|
|
if (rp == NULL)
|
1997-04-27 20:01:29 +00:00
|
|
|
return ENOBUFS;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The splnet() is necessary to block protocols from sending
|
|
|
|
* error notifications (like RTM_REDIRECT or RTM_LOSING) while
|
|
|
|
* this PCB is extant but incompletely initialized.
|
|
|
|
* Probably we should try to do more of this work beforehand and
|
|
|
|
* eliminate the spl.
|
|
|
|
*/
|
|
|
|
s = splnet();
|
|
|
|
so->so_pcb = (caddr_t)rp;
|
2001-08-31 12:31:09 +00:00
|
|
|
error = raw_attach(so, proto);
|
1997-04-27 20:01:29 +00:00
|
|
|
rp = sotorawcb(so);
|
|
|
|
if (error) {
|
|
|
|
splx(s);
|
2001-08-02 19:56:29 +00:00
|
|
|
so->so_pcb = NULL;
|
1997-04-27 20:01:29 +00:00
|
|
|
free(rp, M_PCB);
|
|
|
|
return error;
|
|
|
|
}
|
2003-10-03 18:27:02 +00:00
|
|
|
RTSOCK_LOCK();
|
1997-04-27 20:01:29 +00:00
|
|
|
switch(rp->rcb_proto.sp_protocol) {
|
|
|
|
case AF_INET:
|
|
|
|
route_cb.ip_count++;
|
|
|
|
break;
|
2000-01-28 20:10:51 +00:00
|
|
|
case AF_INET6:
|
|
|
|
route_cb.ip6_count++;
|
|
|
|
break;
|
1997-04-27 20:01:29 +00:00
|
|
|
case AF_IPX:
|
|
|
|
route_cb.ipx_count++;
|
|
|
|
break;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
1997-04-27 20:01:29 +00:00
|
|
|
rp->rcb_faddr = &route_src;
|
|
|
|
route_cb.any_count++;
|
2003-10-03 18:27:02 +00:00
|
|
|
RTSOCK_UNLOCK();
|
2002-06-18 07:42:02 +00:00
|
|
|
soisconnected(so);
|
1997-04-27 20:01:29 +00:00
|
|
|
so->so_options |= SO_USELOOPBACK;
|
|
|
|
splx(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
rts_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
|
1997-04-27 20:01:29 +00:00
|
|
|
{
|
2005-08-25 13:30:04 +00:00
|
|
|
|
|
|
|
return (raw_usrreqs.pru_bind(so, nam, td)); /* xxx just EINVAL */
|
1997-04-27 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
rts_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
|
1997-04-27 20:01:29 +00:00
|
|
|
{
|
2005-08-25 13:30:04 +00:00
|
|
|
|
|
|
|
return (raw_usrreqs.pru_connect(so, nam, td)); /* XXX just EINVAL */
|
1997-04-27 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* pru_connect2 is EOPNOTSUPP */
|
|
|
|
/* pru_control is EOPNOTSUPP */
|
|
|
|
|
Chance protocol switch method pru_detach() so that it returns void
rather than an error. Detaches do not "fail", they other occur or
the protocol flags SS_PROTOREF to take ownership of the socket.
soclose() no longer looks at so_pcb to see if it's NULL, relying
entirely on the protocol to decide whether it's time to free the
socket or not using SS_PROTOREF. so_pcb is now entirely owned and
managed by the protocol code. Likewise, no longer test so_pcb in
other socket functions, such as soreceive(), which have no business
digging into protocol internals.
Protocol detach routines no longer try to free the socket on detach,
this is performed in the socket code if the protocol permits it.
In rts_detach(), no longer test for rp != NULL in detach, and
likewise in other protocols that don't permit a NULL so_pcb, reduce
the incidence of testing for it during detach.
netinet and netinet6 are not fully updated to this change, which
will be in an upcoming commit. In their current state they may leak
memory or panic.
MFC after: 3 months
2006-04-01 15:42:02 +00:00
|
|
|
static void
|
1997-04-27 20:01:29 +00:00
|
|
|
rts_detach(struct socket *so)
|
|
|
|
{
|
|
|
|
struct rawcb *rp = sotorawcb(so);
|
|
|
|
|
Chance protocol switch method pru_detach() so that it returns void
rather than an error. Detaches do not "fail", they other occur or
the protocol flags SS_PROTOREF to take ownership of the socket.
soclose() no longer looks at so_pcb to see if it's NULL, relying
entirely on the protocol to decide whether it's time to free the
socket or not using SS_PROTOREF. so_pcb is now entirely owned and
managed by the protocol code. Likewise, no longer test so_pcb in
other socket functions, such as soreceive(), which have no business
digging into protocol internals.
Protocol detach routines no longer try to free the socket on detach,
this is performed in the socket code if the protocol permits it.
In rts_detach(), no longer test for rp != NULL in detach, and
likewise in other protocols that don't permit a NULL so_pcb, reduce
the incidence of testing for it during detach.
netinet and netinet6 are not fully updated to this change, which
will be in an upcoming commit. In their current state they may leak
memory or panic.
MFC after: 3 months
2006-04-01 15:42:02 +00:00
|
|
|
KASSERT(rp != NULL, ("rts_detach: rp == NULL"));
|
|
|
|
|
|
|
|
RTSOCK_LOCK();
|
|
|
|
switch(rp->rcb_proto.sp_protocol) {
|
|
|
|
case AF_INET:
|
|
|
|
route_cb.ip_count--;
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
route_cb.ip6_count--;
|
|
|
|
break;
|
|
|
|
case AF_IPX:
|
|
|
|
route_cb.ipx_count--;
|
|
|
|
break;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
Chance protocol switch method pru_detach() so that it returns void
rather than an error. Detaches do not "fail", they other occur or
the protocol flags SS_PROTOREF to take ownership of the socket.
soclose() no longer looks at so_pcb to see if it's NULL, relying
entirely on the protocol to decide whether it's time to free the
socket or not using SS_PROTOREF. so_pcb is now entirely owned and
managed by the protocol code. Likewise, no longer test so_pcb in
other socket functions, such as soreceive(), which have no business
digging into protocol internals.
Protocol detach routines no longer try to free the socket on detach,
this is performed in the socket code if the protocol permits it.
In rts_detach(), no longer test for rp != NULL in detach, and
likewise in other protocols that don't permit a NULL so_pcb, reduce
the incidence of testing for it during detach.
netinet and netinet6 are not fully updated to this change, which
will be in an upcoming commit. In their current state they may leak
memory or panic.
MFC after: 3 months
2006-04-01 15:42:02 +00:00
|
|
|
route_cb.any_count--;
|
|
|
|
RTSOCK_UNLOCK();
|
|
|
|
raw_usrreqs.pru_detach(so);
|
1997-04-27 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rts_disconnect(struct socket *so)
|
|
|
|
{
|
2005-08-25 13:30:04 +00:00
|
|
|
|
|
|
|
return (raw_usrreqs.pru_disconnect(so));
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1997-04-27 20:01:29 +00:00
|
|
|
/* pru_listen is EOPNOTSUPP */
|
|
|
|
|
|
|
|
static int
|
1997-08-16 19:16:27 +00:00
|
|
|
rts_peeraddr(struct socket *so, struct sockaddr **nam)
|
1997-04-27 20:01:29 +00:00
|
|
|
{
|
2005-08-25 13:30:04 +00:00
|
|
|
|
|
|
|
return (raw_usrreqs.pru_peeraddr(so, nam));
|
1997-04-27 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* pru_rcvd is EOPNOTSUPP */
|
|
|
|
/* pru_rcvoob is EOPNOTSUPP */
|
|
|
|
|
|
|
|
static int
|
1997-08-16 19:16:27 +00:00
|
|
|
rts_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct mbuf *control, struct thread *td)
|
1997-04-27 20:01:29 +00:00
|
|
|
{
|
2005-08-25 13:30:04 +00:00
|
|
|
|
|
|
|
return (raw_usrreqs.pru_send(so, flags, m, nam, control, td));
|
1997-04-27 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* pru_sense is null */
|
|
|
|
|
|
|
|
static int
|
|
|
|
rts_shutdown(struct socket *so)
|
|
|
|
{
|
2005-08-25 13:30:04 +00:00
|
|
|
|
|
|
|
return (raw_usrreqs.pru_shutdown(so));
|
1997-04-27 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-08-16 19:16:27 +00:00
|
|
|
rts_sockaddr(struct socket *so, struct sockaddr **nam)
|
1997-04-27 20:01:29 +00:00
|
|
|
{
|
2005-08-25 13:30:04 +00:00
|
|
|
|
|
|
|
return (raw_usrreqs.pru_sockaddr(so, nam));
|
1997-04-27 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pr_usrreqs route_usrreqs = {
|
2004-11-08 14:44:54 +00:00
|
|
|
.pru_abort = rts_abort,
|
|
|
|
.pru_attach = rts_attach,
|
|
|
|
.pru_bind = rts_bind,
|
|
|
|
.pru_connect = rts_connect,
|
|
|
|
.pru_detach = rts_detach,
|
|
|
|
.pru_disconnect = rts_disconnect,
|
|
|
|
.pru_peeraddr = rts_peeraddr,
|
|
|
|
.pru_send = rts_send,
|
|
|
|
.pru_shutdown = rts_shutdown,
|
|
|
|
.pru_sockaddr = rts_sockaddr,
|
2006-07-21 17:11:15 +00:00
|
|
|
.pru_close = rts_close,
|
1997-04-27 20:01:29 +00:00
|
|
|
};
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*ARGSUSED*/
|
1995-11-16 19:00:27 +00:00
|
|
|
static int
|
2004-04-18 00:56:44 +00:00
|
|
|
route_output(struct mbuf *m, struct socket *so)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2003-10-03 18:15:54 +00:00
|
|
|
#define sa_equal(a1, a2) (bcmp((a1), (a2), (a1)->sa_len) == 0)
|
2004-04-18 00:56:44 +00:00
|
|
|
struct rt_msghdr *rtm = NULL;
|
|
|
|
struct rtentry *rt = NULL;
|
1995-05-10 16:48:52 +00:00
|
|
|
struct radix_node_head *rnh;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct rt_addrinfo info;
|
|
|
|
int len, error = 0;
|
2004-04-18 00:56:44 +00:00
|
|
|
struct ifnet *ifp = NULL;
|
2004-04-26 19:46:52 +00:00
|
|
|
struct sockaddr_in jail;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
#define senderr(e) { error = e; goto flush;}
|
2004-04-18 00:56:44 +00:00
|
|
|
if (m == NULL || ((m->m_len < sizeof(long)) &&
|
|
|
|
(m = m_pullup(m, sizeof(long))) == NULL))
|
1994-05-24 10:09:53 +00:00
|
|
|
return (ENOBUFS);
|
|
|
|
if ((m->m_flags & M_PKTHDR) == 0)
|
|
|
|
panic("route_output");
|
|
|
|
len = m->m_pkthdr.len;
|
|
|
|
if (len < sizeof(*rtm) ||
|
|
|
|
len != mtod(m, struct rt_msghdr *)->rtm_msglen) {
|
2004-04-18 00:56:44 +00:00
|
|
|
info.rti_info[RTAX_DST] = NULL;
|
1994-05-24 10:09:53 +00:00
|
|
|
senderr(EINVAL);
|
|
|
|
}
|
|
|
|
R_Malloc(rtm, struct rt_msghdr *, len);
|
2004-04-18 00:56:44 +00:00
|
|
|
if (rtm == NULL) {
|
|
|
|
info.rti_info[RTAX_DST] = NULL;
|
1994-05-24 10:09:53 +00:00
|
|
|
senderr(ENOBUFS);
|
|
|
|
}
|
|
|
|
m_copydata(m, 0, len, (caddr_t)rtm);
|
|
|
|
if (rtm->rtm_version != RTM_VERSION) {
|
2004-04-18 00:56:44 +00:00
|
|
|
info.rti_info[RTAX_DST] = NULL;
|
1994-05-24 10:09:53 +00:00
|
|
|
senderr(EPROTONOSUPPORT);
|
|
|
|
}
|
|
|
|
rtm->rtm_pid = curproc->p_pid;
|
2001-10-17 18:07:05 +00:00
|
|
|
bzero(&info, sizeof(info));
|
1994-05-24 10:09:53 +00:00
|
|
|
info.rti_addrs = rtm->rtm_addrs;
|
1997-07-18 11:44:24 +00:00
|
|
|
if (rt_xaddrs((caddr_t)(rtm + 1), len + (caddr_t)rtm, &info)) {
|
2004-04-18 00:56:44 +00:00
|
|
|
info.rti_info[RTAX_DST] = NULL;
|
1997-07-18 11:44:24 +00:00
|
|
|
senderr(EINVAL);
|
|
|
|
}
|
2001-10-17 18:07:05 +00:00
|
|
|
info.rti_flags = rtm->rtm_flags;
|
2004-04-18 00:56:44 +00:00
|
|
|
if (info.rti_info[RTAX_DST] == NULL ||
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_DST]->sa_family >= AF_MAX ||
|
2004-04-18 00:56:44 +00:00
|
|
|
(info.rti_info[RTAX_GATEWAY] != NULL &&
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_GATEWAY]->sa_family >= AF_MAX))
|
1994-05-24 10:09:53 +00:00
|
|
|
senderr(EINVAL);
|
2003-10-03 18:15:54 +00:00
|
|
|
if (info.rti_info[RTAX_GENMASK]) {
|
1994-05-24 10:09:53 +00:00
|
|
|
struct radix_node *t;
|
2003-10-03 18:15:54 +00:00
|
|
|
t = rn_addmask((caddr_t) info.rti_info[RTAX_GENMASK], 0, 1);
|
2004-04-18 19:38:20 +00:00
|
|
|
if (t != NULL &&
|
2004-04-19 07:20:32 +00:00
|
|
|
bcmp((char *)(void *)info.rti_info[RTAX_GENMASK] + 1,
|
|
|
|
(char *)(void *)t->rn_key + 1,
|
|
|
|
((struct sockaddr *)t->rn_key)->sa_len - 1) == 0)
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_GENMASK] =
|
2004-04-19 07:20:32 +00:00
|
|
|
(struct sockaddr *)t->rn_key;
|
1994-05-24 10:09:53 +00:00
|
|
|
else
|
|
|
|
senderr(ENOBUFS);
|
|
|
|
}
|
2001-08-31 12:31:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify that the caller has the appropriate privilege; RTM_GET
|
|
|
|
* is the only operation the non-superuser is allowed.
|
|
|
|
*/
|
2006-11-06 13:42:10 +00:00
|
|
|
if (rtm->rtm_type != RTM_GET) {
|
|
|
|
error = priv_check(curthread, PRIV_NET_ROUTE);
|
|
|
|
if (error)
|
|
|
|
senderr(error);
|
|
|
|
}
|
2001-08-31 12:31:09 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
switch (rtm->rtm_type) {
|
2003-10-03 18:15:54 +00:00
|
|
|
struct rtentry *saved_nrt;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
case RTM_ADD:
|
2004-04-18 00:56:44 +00:00
|
|
|
if (info.rti_info[RTAX_GATEWAY] == NULL)
|
1994-05-24 10:09:53 +00:00
|
|
|
senderr(EINVAL);
|
2004-04-18 00:56:44 +00:00
|
|
|
saved_nrt = NULL;
|
2001-10-17 18:07:05 +00:00
|
|
|
error = rtrequest1(RTM_ADD, &info, &saved_nrt);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (error == 0 && saved_nrt) {
|
2003-10-04 03:44:50 +00:00
|
|
|
RT_LOCK(saved_nrt);
|
1994-05-24 10:09:53 +00:00
|
|
|
rt_setmetrics(rtm->rtm_inits,
|
|
|
|
&rtm->rtm_rmx, &saved_nrt->rt_rmx);
|
2006-03-15 19:39:09 +00:00
|
|
|
rtm->rtm_index = saved_nrt->rt_ifp->if_index;
|
2003-11-08 23:36:32 +00:00
|
|
|
RT_REMREF(saved_nrt);
|
2003-10-03 18:15:54 +00:00
|
|
|
saved_nrt->rt_genmask = info.rti_info[RTAX_GENMASK];
|
2003-10-04 03:44:50 +00:00
|
|
|
RT_UNLOCK(saved_nrt);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTM_DELETE:
|
2004-04-18 00:56:44 +00:00
|
|
|
saved_nrt = NULL;
|
2001-10-17 18:07:05 +00:00
|
|
|
error = rtrequest1(RTM_DELETE, &info, &saved_nrt);
|
1995-05-10 16:48:52 +00:00
|
|
|
if (error == 0) {
|
2003-10-04 03:44:50 +00:00
|
|
|
RT_LOCK(saved_nrt);
|
2002-12-25 10:21:02 +00:00
|
|
|
rt = saved_nrt;
|
1995-05-10 16:48:52 +00:00
|
|
|
goto report;
|
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RTM_GET:
|
|
|
|
case RTM_CHANGE:
|
|
|
|
case RTM_LOCK:
|
2003-10-03 18:15:54 +00:00
|
|
|
rnh = rt_tables[info.rti_info[RTAX_DST]->sa_family];
|
2004-04-18 00:56:44 +00:00
|
|
|
if (rnh == NULL)
|
1995-05-10 16:48:52 +00:00
|
|
|
senderr(EAFNOSUPPORT);
|
2002-12-24 03:03:39 +00:00
|
|
|
RADIX_NODE_HEAD_LOCK(rnh);
|
2003-10-03 18:15:54 +00:00
|
|
|
rt = (struct rtentry *) rnh->rnh_lookup(info.rti_info[RTAX_DST],
|
|
|
|
info.rti_info[RTAX_NETMASK], rnh);
|
2005-08-11 08:26:31 +00:00
|
|
|
if (rt == NULL) { /* XXX looks bogus */
|
|
|
|
RADIX_NODE_HEAD_UNLOCK(rnh);
|
1994-05-24 10:09:53 +00:00
|
|
|
senderr(ESRCH);
|
2005-08-11 08:26:31 +00:00
|
|
|
}
|
2003-10-04 03:44:50 +00:00
|
|
|
RT_LOCK(rt);
|
2003-11-08 23:36:32 +00:00
|
|
|
RT_ADDREF(rt);
|
2005-08-11 08:26:31 +00:00
|
|
|
RADIX_NODE_HEAD_UNLOCK(rnh);
|
2002-12-24 03:03:39 +00:00
|
|
|
|
2005-07-15 09:18:34 +00:00
|
|
|
/*
|
|
|
|
* Fix for PR: 82974
|
|
|
|
*
|
|
|
|
* RTM_CHANGE/LOCK need a perfect match, rn_lookup()
|
|
|
|
* returns a perfect match in case a netmask is
|
|
|
|
* specified. For host routes only a longest prefix
|
|
|
|
* match is returned so it is necessary to compare the
|
|
|
|
* existence of the netmask. If both have a netmask
|
|
|
|
* rnh_lookup() did a perfect match and if none of them
|
|
|
|
* have a netmask both are host routes which is also a
|
|
|
|
* perfect match.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (rtm->rtm_type != RTM_GET &&
|
|
|
|
(!rt_mask(rt) != !info.rti_info[RTAX_NETMASK])) {
|
|
|
|
RT_UNLOCK(rt);
|
|
|
|
senderr(ESRCH);
|
|
|
|
}
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
switch(rtm->rtm_type) {
|
|
|
|
|
|
|
|
case RTM_GET:
|
1995-05-10 16:48:52 +00:00
|
|
|
report:
|
2003-10-04 03:44:50 +00:00
|
|
|
RT_LOCK_ASSERT(rt);
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_DST] = rt_key(rt);
|
|
|
|
info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
|
|
|
|
info.rti_info[RTAX_NETMASK] = rt_mask(rt);
|
|
|
|
info.rti_info[RTAX_GENMASK] = rt->rt_genmask;
|
1994-05-24 10:09:53 +00:00
|
|
|
if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA)) {
|
1994-10-08 22:38:27 +00:00
|
|
|
ifp = rt->rt_ifp;
|
|
|
|
if (ifp) {
|
2004-04-16 08:14:34 +00:00
|
|
|
info.rti_info[RTAX_IFP] =
|
2005-11-11 16:04:59 +00:00
|
|
|
ifp->if_addr->ifa_addr;
|
2004-04-26 19:46:52 +00:00
|
|
|
if (jailed(so->so_cred)) {
|
2004-07-06 03:29:41 +00:00
|
|
|
bzero(&jail, sizeof(jail));
|
2004-04-26 19:46:52 +00:00
|
|
|
jail.sin_family = PF_INET;
|
|
|
|
jail.sin_len = sizeof(jail);
|
|
|
|
jail.sin_addr.s_addr =
|
|
|
|
htonl(prison_getip(so->so_cred));
|
|
|
|
info.rti_info[RTAX_IFA] =
|
2004-05-03 17:15:34 +00:00
|
|
|
(struct sockaddr *)&jail;
|
2004-04-26 19:46:52 +00:00
|
|
|
} else
|
|
|
|
info.rti_info[RTAX_IFA] =
|
2004-05-03 17:15:34 +00:00
|
|
|
rt->rt_ifa->ifa_addr;
|
2001-10-17 11:23:59 +00:00
|
|
|
if (ifp->if_flags & IFF_POINTOPOINT)
|
2004-05-03 17:15:34 +00:00
|
|
|
info.rti_info[RTAX_BRD] =
|
|
|
|
rt->rt_ifa->ifa_dstaddr;
|
1994-05-24 10:09:53 +00:00
|
|
|
rtm->rtm_index = ifp->if_index;
|
|
|
|
} else {
|
2004-04-18 00:56:44 +00:00
|
|
|
info.rti_info[RTAX_IFP] = NULL;
|
|
|
|
info.rti_info[RTAX_IFA] = NULL;
|
2002-10-01 15:48:31 +00:00
|
|
|
}
|
2005-06-09 12:20:50 +00:00
|
|
|
} else if ((ifp = rt->rt_ifp) != NULL) {
|
|
|
|
rtm->rtm_index = ifp->if_index;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2004-04-17 15:09:36 +00:00
|
|
|
len = rt_msg2(rtm->rtm_type, &info, NULL, NULL);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (len > rtm->rtm_msglen) {
|
|
|
|
struct rt_msghdr *new_rtm;
|
|
|
|
R_Malloc(new_rtm, struct rt_msghdr *, len);
|
2004-04-18 00:56:44 +00:00
|
|
|
if (new_rtm == NULL) {
|
2003-10-04 03:44:50 +00:00
|
|
|
RT_UNLOCK(rt);
|
1994-05-24 10:09:53 +00:00
|
|
|
senderr(ENOBUFS);
|
2003-10-03 18:15:54 +00:00
|
|
|
}
|
2004-04-18 11:47:04 +00:00
|
|
|
bcopy(rtm, new_rtm, rtm->rtm_msglen);
|
1994-05-24 10:09:53 +00:00
|
|
|
Free(rtm); rtm = new_rtm;
|
|
|
|
}
|
2004-04-17 15:09:36 +00:00
|
|
|
(void)rt_msg2(rtm->rtm_type, &info, (caddr_t)rtm, NULL);
|
1994-05-24 10:09:53 +00:00
|
|
|
rtm->rtm_flags = rt->rt_flags;
|
2006-03-15 19:39:09 +00:00
|
|
|
rtm->rtm_use = 0;
|
2003-11-20 20:07:39 +00:00
|
|
|
rt_getmetrics(&rt->rt_rmx, &rtm->rtm_rmx);
|
1994-05-24 10:09:53 +00:00
|
|
|
rtm->rtm_addrs = info.rti_addrs;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTM_CHANGE:
|
2003-10-03 18:15:54 +00:00
|
|
|
/*
|
|
|
|
* New gateway could require new ifaddr, ifp;
|
|
|
|
* flags may also be different; ifp may be specified
|
|
|
|
* by ll sockaddr when protocol address is ambiguous
|
|
|
|
*/
|
|
|
|
if (((rt->rt_flags & RTF_GATEWAY) &&
|
|
|
|
info.rti_info[RTAX_GATEWAY] != NULL) ||
|
|
|
|
info.rti_info[RTAX_IFP] != NULL ||
|
|
|
|
(info.rti_info[RTAX_IFA] != NULL &&
|
|
|
|
!sa_equal(info.rti_info[RTAX_IFA],
|
|
|
|
rt->rt_ifa->ifa_addr))) {
|
2005-09-19 16:27:22 +00:00
|
|
|
RT_UNLOCK(rt);
|
|
|
|
if ((error = rt_getifa(&info)) != 0)
|
2001-12-19 16:03:27 +00:00
|
|
|
senderr(error);
|
2005-09-19 16:27:22 +00:00
|
|
|
RT_LOCK(rt);
|
2001-12-19 16:03:27 +00:00
|
|
|
}
|
2007-03-27 19:36:12 +00:00
|
|
|
if (info.rti_ifa != NULL &&
|
|
|
|
info.rti_ifa != rt->rt_ifa &&
|
|
|
|
rt->rt_ifa != NULL &&
|
2007-03-22 10:51:03 +00:00
|
|
|
rt->rt_ifa->ifa_rtrequest != NULL) {
|
|
|
|
rt->rt_ifa->ifa_rtrequest(RTM_DELETE, rt,
|
|
|
|
&info);
|
|
|
|
IFAFREE(rt->rt_ifa);
|
|
|
|
}
|
|
|
|
if (info.rti_info[RTAX_GATEWAY] != NULL) {
|
|
|
|
if ((error = rt_setgate(rt, rt_key(rt),
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_GATEWAY])) != 0) {
|
2007-03-22 10:51:03 +00:00
|
|
|
RT_UNLOCK(rt);
|
|
|
|
senderr(error);
|
|
|
|
}
|
2007-09-08 19:28:45 +00:00
|
|
|
if (!(rt->rt_flags & RTF_LLINFO))
|
|
|
|
rt->rt_flags |= RTF_GATEWAY;
|
2003-10-03 18:15:54 +00:00
|
|
|
}
|
2007-03-27 19:36:12 +00:00
|
|
|
if (info.rti_ifa != NULL &&
|
|
|
|
info.rti_ifa != rt->rt_ifa) {
|
|
|
|
IFAREF(info.rti_ifa);
|
2007-03-22 10:51:03 +00:00
|
|
|
rt->rt_ifa = info.rti_ifa;
|
2007-03-27 19:36:12 +00:00
|
|
|
rt->rt_ifp = info.rti_ifp;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2006-03-15 19:39:09 +00:00
|
|
|
/* Allow some flags to be toggled on change. */
|
|
|
|
if (rtm->rtm_fmask & RTF_FMASK)
|
|
|
|
rt->rt_flags = (rt->rt_flags &
|
|
|
|
~rtm->rtm_fmask) |
|
|
|
|
(rtm->rtm_flags & rtm->rtm_fmask);
|
1994-05-24 10:09:53 +00:00
|
|
|
rt_setmetrics(rtm->rtm_inits, &rtm->rtm_rmx,
|
|
|
|
&rt->rt_rmx);
|
2006-03-15 19:39:09 +00:00
|
|
|
rtm->rtm_index = rt->rt_ifp->if_index;
|
1994-05-24 10:09:53 +00:00
|
|
|
if (rt->rt_ifa && rt->rt_ifa->ifa_rtrequest)
|
2001-10-17 18:07:05 +00:00
|
|
|
rt->rt_ifa->ifa_rtrequest(RTM_ADD, rt, &info);
|
2003-10-03 18:15:54 +00:00
|
|
|
if (info.rti_info[RTAX_GENMASK])
|
|
|
|
rt->rt_genmask = info.rti_info[RTAX_GENMASK];
|
2002-08-25 13:23:09 +00:00
|
|
|
/* FALLTHROUGH */
|
1994-05-24 10:09:53 +00:00
|
|
|
case RTM_LOCK:
|
2003-11-20 20:07:39 +00:00
|
|
|
/* We don't support locks anymore */
|
1994-05-24 10:09:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-10-04 03:44:50 +00:00
|
|
|
RT_UNLOCK(rt);
|
1994-05-24 10:09:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
senderr(EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
flush:
|
|
|
|
if (rtm) {
|
|
|
|
if (error)
|
|
|
|
rtm->rtm_errno = error;
|
1995-05-30 08:16:23 +00:00
|
|
|
else
|
1994-05-24 10:09:53 +00:00
|
|
|
rtm->rtm_flags |= RTF_DONE;
|
|
|
|
}
|
2003-10-03 18:15:54 +00:00
|
|
|
if (rt) /* XXX can this be true? */
|
|
|
|
RTFREE(rt);
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2004-04-18 00:56:44 +00:00
|
|
|
struct rawcb *rp = NULL;
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Check to see if we don't want our own messages.
|
|
|
|
*/
|
|
|
|
if ((so->so_options & SO_USELOOPBACK) == 0) {
|
|
|
|
if (route_cb.any_count <= 1) {
|
|
|
|
if (rtm)
|
|
|
|
Free(rtm);
|
|
|
|
m_freem(m);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
/* There is another listener, so construct message */
|
|
|
|
rp = sotorawcb(so);
|
2002-05-31 11:52:35 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
if (rtm) {
|
|
|
|
m_copyback(m, 0, rtm->rtm_msglen, (caddr_t)rtm);
|
2001-07-04 11:29:55 +00:00
|
|
|
if (m->m_pkthdr.len < rtm->rtm_msglen) {
|
|
|
|
m_freem(m);
|
|
|
|
m = NULL;
|
|
|
|
} else if (m->m_pkthdr.len > rtm->rtm_msglen)
|
|
|
|
m_adj(m, rtm->rtm_msglen - m->m_pkthdr.len);
|
1994-05-24 10:09:53 +00:00
|
|
|
Free(rtm);
|
|
|
|
}
|
2003-10-03 18:15:54 +00:00
|
|
|
if (m) {
|
|
|
|
if (rp) {
|
|
|
|
/*
|
|
|
|
* XXX insure we don't get a copy by
|
|
|
|
* invalidating our protocol
|
|
|
|
*/
|
|
|
|
unsigned short family = rp->rcb_proto.sp_family;
|
|
|
|
rp->rcb_proto.sp_family = 0;
|
|
|
|
rt_dispatch(m, info.rti_info[RTAX_DST]);
|
|
|
|
rp->rcb_proto.sp_family = family;
|
|
|
|
} else
|
|
|
|
rt_dispatch(m, info.rti_info[RTAX_DST]);
|
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
return (error);
|
2003-10-03 18:15:54 +00:00
|
|
|
#undef sa_equal
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1995-11-16 19:00:27 +00:00
|
|
|
static void
|
2004-04-18 00:56:44 +00:00
|
|
|
rt_setmetrics(u_long which, const struct rt_metrics *in,
|
|
|
|
struct rt_metrics_lite *out)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
#define metric(f, e) if (which & (f)) out->e = in->e;
|
2003-11-20 20:07:39 +00:00
|
|
|
/*
|
|
|
|
* Only these are stored in the routing entry since introduction
|
|
|
|
* of tcp hostcache. The rest is ignored.
|
|
|
|
*/
|
1994-05-24 10:09:53 +00:00
|
|
|
metric(RTV_MTU, rmx_mtu);
|
2006-07-06 00:24:36 +00:00
|
|
|
/* Userland -> kernel timebase conversion. */
|
|
|
|
if (which & RTV_EXPIRE)
|
|
|
|
out->rmx_expire = in->rmx_expire ?
|
|
|
|
in->rmx_expire - time_second + time_uptime : 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
#undef metric
|
|
|
|
}
|
|
|
|
|
2003-11-20 20:07:39 +00:00
|
|
|
static void
|
2004-04-18 00:56:44 +00:00
|
|
|
rt_getmetrics(const struct rt_metrics_lite *in, struct rt_metrics *out)
|
2003-11-20 20:07:39 +00:00
|
|
|
{
|
|
|
|
#define metric(e) out->e = in->e;
|
|
|
|
bzero(out, sizeof(*out));
|
|
|
|
metric(rmx_mtu);
|
2006-07-06 00:24:36 +00:00
|
|
|
/* Kernel -> userland timebase conversion. */
|
|
|
|
out->rmx_expire = in->rmx_expire ?
|
|
|
|
in->rmx_expire - time_uptime + time_second : 0;
|
2003-11-20 20:07:39 +00:00
|
|
|
#undef metric
|
|
|
|
}
|
|
|
|
|
1997-07-15 23:25:32 +00:00
|
|
|
/*
|
|
|
|
* Extract the addresses of the passed sockaddrs.
|
|
|
|
* Do a little sanity checking so as to avoid bad memory references.
|
1997-07-18 11:44:24 +00:00
|
|
|
* This data is derived straight from userland.
|
1997-07-15 23:25:32 +00:00
|
|
|
*/
|
1997-07-18 11:44:24 +00:00
|
|
|
static int
|
2003-10-03 18:15:54 +00:00
|
|
|
rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo *rtinfo)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2004-04-13 11:22:22 +00:00
|
|
|
struct sockaddr *sa;
|
|
|
|
int i;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2003-10-03 18:15:54 +00:00
|
|
|
for (i = 0; i < RTAX_MAX && cp < cplim; i++) {
|
1994-05-24 10:09:53 +00:00
|
|
|
if ((rtinfo->rti_addrs & (1 << i)) == 0)
|
|
|
|
continue;
|
1997-07-16 14:55:14 +00:00
|
|
|
sa = (struct sockaddr *)cp;
|
1997-07-15 23:25:32 +00:00
|
|
|
/*
|
1997-07-18 11:44:24 +00:00
|
|
|
* It won't fit.
|
1997-07-15 23:25:32 +00:00
|
|
|
*/
|
2003-10-03 18:15:54 +00:00
|
|
|
if (cp + sa->sa_len > cplim)
|
1997-07-18 11:44:24 +00:00
|
|
|
return (EINVAL);
|
1997-07-15 23:25:32 +00:00
|
|
|
/*
|
|
|
|
* there are no more.. quit now
|
|
|
|
* If there are more bits, they are in error.
|
|
|
|
* I've seen this. route(1) can evidently generate these.
|
|
|
|
* This causes kernel to core dump.
|
1997-07-18 11:44:24 +00:00
|
|
|
* for compatibility, If we see this, point to a safe address.
|
1997-07-15 23:25:32 +00:00
|
|
|
*/
|
1997-07-18 11:44:24 +00:00
|
|
|
if (sa->sa_len == 0) {
|
|
|
|
rtinfo->rti_info[i] = &sa_zero;
|
|
|
|
return (0); /* should be EINVAL but for compat */
|
|
|
|
}
|
|
|
|
/* accept it */
|
|
|
|
rtinfo->rti_info[i] = sa;
|
2004-04-13 11:22:22 +00:00
|
|
|
cp += SA_SIZE(sa);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
1997-07-18 11:44:24 +00:00
|
|
|
return (0);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct mbuf *
|
2003-10-03 18:15:54 +00:00
|
|
|
rt_msg1(int type, struct rt_addrinfo *rtinfo)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2004-04-18 00:56:44 +00:00
|
|
|
struct rt_msghdr *rtm;
|
|
|
|
struct mbuf *m;
|
|
|
|
int i;
|
|
|
|
struct sockaddr *sa;
|
1994-05-24 10:09:53 +00:00
|
|
|
int len, dlen;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
|
|
case RTM_DELADDR:
|
|
|
|
case RTM_NEWADDR:
|
|
|
|
len = sizeof(struct ifa_msghdr);
|
|
|
|
break;
|
|
|
|
|
1997-01-13 21:26:53 +00:00
|
|
|
case RTM_DELMADDR:
|
|
|
|
case RTM_NEWMADDR:
|
|
|
|
len = sizeof(struct ifma_msghdr);
|
|
|
|
break;
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
case RTM_IFINFO:
|
|
|
|
len = sizeof(struct if_msghdr);
|
|
|
|
break;
|
|
|
|
|
2002-01-18 14:33:04 +00:00
|
|
|
case RTM_IFANNOUNCE:
|
2004-10-05 19:48:33 +00:00
|
|
|
case RTM_IEEE80211:
|
2002-01-18 14:33:04 +00:00
|
|
|
len = sizeof(struct if_announcemsghdr);
|
|
|
|
break;
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
default:
|
|
|
|
len = sizeof(struct rt_msghdr);
|
|
|
|
}
|
2001-06-11 12:39:29 +00:00
|
|
|
if (len > MCLBYTES)
|
1994-05-24 10:09:53 +00:00
|
|
|
panic("rt_msg1");
|
2003-02-19 05:47:46 +00:00
|
|
|
m = m_gethdr(M_DONTWAIT, MT_DATA);
|
2001-06-11 12:39:29 +00:00
|
|
|
if (m && len > MHLEN) {
|
2003-02-19 05:47:46 +00:00
|
|
|
MCLGET(m, M_DONTWAIT);
|
2001-06-11 12:39:29 +00:00
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
m_free(m);
|
|
|
|
m = NULL;
|
|
|
|
}
|
|
|
|
}
|
2004-04-18 00:56:44 +00:00
|
|
|
if (m == NULL)
|
2001-06-11 12:39:29 +00:00
|
|
|
return (m);
|
1994-05-24 10:09:53 +00:00
|
|
|
m->m_pkthdr.len = m->m_len = len;
|
2004-04-18 00:56:44 +00:00
|
|
|
m->m_pkthdr.rcvif = NULL;
|
1994-05-24 10:09:53 +00:00
|
|
|
rtm = mtod(m, struct rt_msghdr *);
|
|
|
|
bzero((caddr_t)rtm, len);
|
|
|
|
for (i = 0; i < RTAX_MAX; i++) {
|
|
|
|
if ((sa = rtinfo->rti_info[i]) == NULL)
|
|
|
|
continue;
|
|
|
|
rtinfo->rti_addrs |= (1 << i);
|
2004-04-13 11:22:22 +00:00
|
|
|
dlen = SA_SIZE(sa);
|
1994-05-24 10:09:53 +00:00
|
|
|
m_copyback(m, len, dlen, (caddr_t)sa);
|
|
|
|
len += dlen;
|
|
|
|
}
|
|
|
|
if (m->m_pkthdr.len != len) {
|
|
|
|
m_freem(m);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
rtm->rtm_msglen = len;
|
|
|
|
rtm->rtm_version = RTM_VERSION;
|
|
|
|
rtm->rtm_type = type;
|
|
|
|
return (m);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-10-03 18:15:54 +00:00
|
|
|
rt_msg2(int type, struct rt_addrinfo *rtinfo, caddr_t cp, struct walkarg *w)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2004-04-18 00:56:44 +00:00
|
|
|
int i;
|
1994-05-24 10:09:53 +00:00
|
|
|
int len, dlen, second_time = 0;
|
|
|
|
caddr_t cp0;
|
|
|
|
|
|
|
|
rtinfo->rti_addrs = 0;
|
|
|
|
again:
|
|
|
|
switch (type) {
|
|
|
|
|
|
|
|
case RTM_DELADDR:
|
|
|
|
case RTM_NEWADDR:
|
|
|
|
len = sizeof(struct ifa_msghdr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTM_IFINFO:
|
|
|
|
len = sizeof(struct if_msghdr);
|
|
|
|
break;
|
|
|
|
|
2003-11-14 18:48:15 +00:00
|
|
|
case RTM_NEWMADDR:
|
|
|
|
len = sizeof(struct ifma_msghdr);
|
|
|
|
break;
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
default:
|
|
|
|
len = sizeof(struct rt_msghdr);
|
|
|
|
}
|
1994-10-08 22:38:27 +00:00
|
|
|
cp0 = cp;
|
|
|
|
if (cp0)
|
1994-05-24 10:09:53 +00:00
|
|
|
cp += len;
|
|
|
|
for (i = 0; i < RTAX_MAX; i++) {
|
2004-04-18 00:56:44 +00:00
|
|
|
struct sockaddr *sa;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2004-04-18 00:56:44 +00:00
|
|
|
if ((sa = rtinfo->rti_info[i]) == NULL)
|
1994-05-24 10:09:53 +00:00
|
|
|
continue;
|
|
|
|
rtinfo->rti_addrs |= (1 << i);
|
2004-04-13 11:22:22 +00:00
|
|
|
dlen = SA_SIZE(sa);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (cp) {
|
|
|
|
bcopy((caddr_t)sa, cp, (unsigned)dlen);
|
|
|
|
cp += dlen;
|
|
|
|
}
|
|
|
|
len += dlen;
|
|
|
|
}
|
2002-01-27 20:39:01 +00:00
|
|
|
len = ALIGN(len);
|
2004-04-18 00:56:44 +00:00
|
|
|
if (cp == NULL && w != NULL && !second_time) {
|
|
|
|
struct walkarg *rw = w;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1995-11-16 19:00:27 +00:00
|
|
|
if (rw->w_req) {
|
1994-05-24 10:09:53 +00:00
|
|
|
if (rw->w_tmemsize < len) {
|
|
|
|
if (rw->w_tmem)
|
|
|
|
free(rw->w_tmem, M_RTABLE);
|
1994-10-08 22:38:27 +00:00
|
|
|
rw->w_tmem = (caddr_t)
|
|
|
|
malloc(len, M_RTABLE, M_NOWAIT);
|
|
|
|
if (rw->w_tmem)
|
1994-05-24 10:09:53 +00:00
|
|
|
rw->w_tmemsize = len;
|
|
|
|
}
|
|
|
|
if (rw->w_tmem) {
|
|
|
|
cp = rw->w_tmem;
|
|
|
|
second_time = 1;
|
|
|
|
goto again;
|
1995-11-16 19:00:27 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cp) {
|
2004-04-18 00:56:44 +00:00
|
|
|
struct rt_msghdr *rtm = (struct rt_msghdr *)cp0;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
rtm->rtm_version = RTM_VERSION;
|
|
|
|
rtm->rtm_type = type;
|
|
|
|
rtm->rtm_msglen = len;
|
|
|
|
}
|
|
|
|
return (len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine is called to generate a message from the routing
|
|
|
|
* socket indicating that a redirect has occured, a routing lookup
|
|
|
|
* has failed, or that a protocol has detected timeouts to a particular
|
|
|
|
* destination.
|
|
|
|
*/
|
|
|
|
void
|
2003-10-03 18:15:54 +00:00
|
|
|
rt_missmsg(int type, struct rt_addrinfo *rtinfo, int flags, int error)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2003-10-03 18:15:54 +00:00
|
|
|
struct rt_msghdr *rtm;
|
|
|
|
struct mbuf *m;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct sockaddr *sa = rtinfo->rti_info[RTAX_DST];
|
|
|
|
|
|
|
|
if (route_cb.any_count == 0)
|
|
|
|
return;
|
|
|
|
m = rt_msg1(type, rtinfo);
|
2004-04-18 00:56:44 +00:00
|
|
|
if (m == NULL)
|
1994-05-24 10:09:53 +00:00
|
|
|
return;
|
|
|
|
rtm = mtod(m, struct rt_msghdr *);
|
|
|
|
rtm->rtm_flags = RTF_DONE | flags;
|
|
|
|
rtm->rtm_errno = error;
|
|
|
|
rtm->rtm_addrs = rtinfo->rti_addrs;
|
2003-10-03 18:15:54 +00:00
|
|
|
rt_dispatch(m, sa);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine is called to generate a message from the routing
|
|
|
|
* socket indicating that the status of a network interface has changed.
|
|
|
|
*/
|
|
|
|
void
|
2003-10-03 18:15:54 +00:00
|
|
|
rt_ifmsg(struct ifnet *ifp)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2003-10-03 18:15:54 +00:00
|
|
|
struct if_msghdr *ifm;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
struct rt_addrinfo info;
|
|
|
|
|
|
|
|
if (route_cb.any_count == 0)
|
|
|
|
return;
|
|
|
|
bzero((caddr_t)&info, sizeof(info));
|
|
|
|
m = rt_msg1(RTM_IFINFO, &info);
|
2004-04-18 00:56:44 +00:00
|
|
|
if (m == NULL)
|
1994-05-24 10:09:53 +00:00
|
|
|
return;
|
|
|
|
ifm = mtod(m, struct if_msghdr *);
|
|
|
|
ifm->ifm_index = ifp->if_index;
|
Rename IFF_RUNNING to IFF_DRV_RUNNING, IFF_OACTIVE to IFF_DRV_OACTIVE,
and move both flags from ifnet.if_flags to ifnet.if_drv_flags, making
and documenting the locking of these flags the responsibility of the
device driver, not the network stack. The flags for these two fields
will be mutually exclusive so that they can be exposed to user space as
though they were stored in the same variable.
Provide #defines to provide the old names #ifndef _KERNEL, so that user
applications (such as ifconfig) can use the old flag names. Using the
old names in a device driver will result in a compile error in order to
help device driver writers adopt the new model.
When exposing the interface flags to user space, via interface ioctls
or routing sockets, or the two fields together. Since the driver flags
cannot currently be set for user space, no new logic is currently
required to handle this case.
Add some assertions that general purpose network stack routines, such
as if_setflags(), are not improperly used on driver-owned flags.
With this change, a large number of very minor network stack races are
closed, subject to correct device driver locking. Most were likely
never triggered.
Driver sweep to follow; many thanks to pjd and bz for the line-by-line
review they gave this patch.
Reviewed by: pjd, bz
MFC after: 7 days
2005-08-09 10:16:17 +00:00
|
|
|
ifm->ifm_flags = ifp->if_flags | ifp->if_drv_flags;
|
1994-05-24 10:09:53 +00:00
|
|
|
ifm->ifm_data = ifp->if_data;
|
|
|
|
ifm->ifm_addrs = 0;
|
2003-10-03 18:15:54 +00:00
|
|
|
rt_dispatch(m, NULL);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called to generate messages from the routing socket
|
|
|
|
* indicating a network interface has had addresses associated with it.
|
|
|
|
* if we ever reverse the logic and replace messages TO the routing
|
|
|
|
* socket indicate a request to configure interfaces, then it will
|
|
|
|
* be unnecessary as the routing socket will automatically generate
|
|
|
|
* copies of it.
|
|
|
|
*/
|
|
|
|
void
|
2003-10-03 18:15:54 +00:00
|
|
|
rt_newaddrmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
struct rt_addrinfo info;
|
2004-04-18 00:56:44 +00:00
|
|
|
struct sockaddr *sa = NULL;
|
1994-05-24 10:09:53 +00:00
|
|
|
int pass;
|
2004-04-18 00:56:44 +00:00
|
|
|
struct mbuf *m = NULL;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct ifnet *ifp = ifa->ifa_ifp;
|
|
|
|
|
2005-03-26 21:49:43 +00:00
|
|
|
KASSERT(cmd == RTM_ADD || cmd == RTM_DELETE,
|
|
|
|
("unexpected cmd %u", cmd));
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP
|
|
|
|
/*
|
|
|
|
* notify the SCTP stack
|
|
|
|
* this will only get called when an address is added/deleted
|
|
|
|
* XXX pass the ifaddr struct instead if ifa->ifa_addr...
|
|
|
|
*/
|
|
|
|
sctp_addr_change(ifa, cmd);
|
|
|
|
#endif /* SCTP */
|
1994-05-24 10:09:53 +00:00
|
|
|
if (route_cb.any_count == 0)
|
|
|
|
return;
|
|
|
|
for (pass = 1; pass < 3; pass++) {
|
|
|
|
bzero((caddr_t)&info, sizeof(info));
|
|
|
|
if ((cmd == RTM_ADD && pass == 1) ||
|
|
|
|
(cmd == RTM_DELETE && pass == 2)) {
|
2004-04-18 00:56:44 +00:00
|
|
|
struct ifa_msghdr *ifam;
|
1994-05-24 10:09:53 +00:00
|
|
|
int ncmd = cmd == RTM_ADD ? RTM_NEWADDR : RTM_DELADDR;
|
|
|
|
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_IFA] = sa = ifa->ifa_addr;
|
2005-11-11 16:04:59 +00:00
|
|
|
info.rti_info[RTAX_IFP] = ifp->if_addr->ifa_addr;
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_NETMASK] = ifa->ifa_netmask;
|
|
|
|
info.rti_info[RTAX_BRD] = ifa->ifa_dstaddr;
|
1994-05-24 10:09:53 +00:00
|
|
|
if ((m = rt_msg1(ncmd, &info)) == NULL)
|
|
|
|
continue;
|
|
|
|
ifam = mtod(m, struct ifa_msghdr *);
|
|
|
|
ifam->ifam_index = ifp->if_index;
|
|
|
|
ifam->ifam_metric = ifa->ifa_metric;
|
|
|
|
ifam->ifam_flags = ifa->ifa_flags;
|
|
|
|
ifam->ifam_addrs = info.rti_addrs;
|
|
|
|
}
|
|
|
|
if ((cmd == RTM_ADD && pass == 2) ||
|
|
|
|
(cmd == RTM_DELETE && pass == 1)) {
|
2004-04-18 00:56:44 +00:00
|
|
|
struct rt_msghdr *rtm;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
2004-04-18 00:56:44 +00:00
|
|
|
if (rt == NULL)
|
1994-05-24 10:09:53 +00:00
|
|
|
continue;
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_NETMASK] = rt_mask(rt);
|
|
|
|
info.rti_info[RTAX_DST] = sa = rt_key(rt);
|
|
|
|
info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
|
1994-05-24 10:09:53 +00:00
|
|
|
if ((m = rt_msg1(cmd, &info)) == NULL)
|
|
|
|
continue;
|
|
|
|
rtm = mtod(m, struct rt_msghdr *);
|
|
|
|
rtm->rtm_index = ifp->if_index;
|
|
|
|
rtm->rtm_flags |= rt->rt_flags;
|
|
|
|
rtm->rtm_errno = error;
|
|
|
|
rtm->rtm_addrs = info.rti_addrs;
|
|
|
|
}
|
2003-10-03 18:15:54 +00:00
|
|
|
rt_dispatch(m, sa);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-01-13 21:26:53 +00:00
|
|
|
/*
|
|
|
|
* This is the analogue to the rt_newaddrmsg which performs the same
|
|
|
|
* function but for multicast group memberhips. This is easier since
|
|
|
|
* there is no route state to worry about.
|
|
|
|
*/
|
|
|
|
void
|
2003-10-03 18:15:54 +00:00
|
|
|
rt_newmaddrmsg(int cmd, struct ifmultiaddr *ifma)
|
1997-01-13 21:26:53 +00:00
|
|
|
{
|
|
|
|
struct rt_addrinfo info;
|
2004-04-18 00:56:44 +00:00
|
|
|
struct mbuf *m = NULL;
|
1997-01-13 21:26:53 +00:00
|
|
|
struct ifnet *ifp = ifma->ifma_ifp;
|
|
|
|
struct ifma_msghdr *ifmam;
|
|
|
|
|
|
|
|
if (route_cb.any_count == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bzero((caddr_t)&info, sizeof(info));
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_IFA] = ifma->ifma_addr;
|
2005-11-11 16:04:59 +00:00
|
|
|
info.rti_info[RTAX_IFP] = ifp ? ifp->if_addr->ifa_addr : NULL;
|
1997-01-13 21:26:53 +00:00
|
|
|
/*
|
|
|
|
* If a link-layer address is present, present it as a ``gateway''
|
|
|
|
* (similarly to how ARP entries, e.g., are presented).
|
|
|
|
*/
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_GATEWAY] = ifma->ifma_lladdr;
|
|
|
|
m = rt_msg1(cmd, &info);
|
|
|
|
if (m == NULL)
|
1997-01-13 21:26:53 +00:00
|
|
|
return;
|
|
|
|
ifmam = mtod(m, struct ifma_msghdr *);
|
2007-03-27 16:11:28 +00:00
|
|
|
KASSERT(ifp != NULL, ("%s: link-layer multicast address w/o ifp\n",
|
|
|
|
__func__));
|
1997-01-13 21:26:53 +00:00
|
|
|
ifmam->ifmam_index = ifp->if_index;
|
|
|
|
ifmam->ifmam_addrs = info.rti_addrs;
|
2003-10-03 18:15:54 +00:00
|
|
|
rt_dispatch(m, ifma->ifma_addr);
|
1997-01-13 21:26:53 +00:00
|
|
|
}
|
1995-11-16 19:00:27 +00:00
|
|
|
|
2004-10-05 19:48:33 +00:00
|
|
|
static struct mbuf *
|
|
|
|
rt_makeifannouncemsg(struct ifnet *ifp, int type, int what,
|
|
|
|
struct rt_addrinfo *info)
|
|
|
|
{
|
|
|
|
struct if_announcemsghdr *ifan;
|
|
|
|
struct mbuf *m;
|
|
|
|
|
|
|
|
if (route_cb.any_count == 0)
|
|
|
|
return NULL;
|
|
|
|
bzero((caddr_t)info, sizeof(*info));
|
|
|
|
m = rt_msg1(type, info);
|
|
|
|
if (m != NULL) {
|
|
|
|
ifan = mtod(m, struct if_announcemsghdr *);
|
|
|
|
ifan->ifan_index = ifp->if_index;
|
|
|
|
strlcpy(ifan->ifan_name, ifp->if_xname,
|
|
|
|
sizeof(ifan->ifan_name));
|
|
|
|
ifan->ifan_what = what;
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called to generate routing socket messages indicating
|
|
|
|
* IEEE80211 wireless events.
|
|
|
|
* XXX we piggyback on the RTM_IFANNOUNCE msg format in a clumsy way.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
rt_ieee80211msg(struct ifnet *ifp, int what, void *data, size_t data_len)
|
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
struct rt_addrinfo info;
|
|
|
|
|
|
|
|
m = rt_makeifannouncemsg(ifp, RTM_IEEE80211, what, &info);
|
|
|
|
if (m != NULL) {
|
|
|
|
/*
|
|
|
|
* Append the ieee80211 data. Try to stick it in the
|
|
|
|
* mbuf containing the ifannounce msg; otherwise allocate
|
|
|
|
* a new mbuf and append.
|
|
|
|
*
|
|
|
|
* NB: we assume m is a single mbuf.
|
|
|
|
*/
|
|
|
|
if (data_len > M_TRAILINGSPACE(m)) {
|
|
|
|
struct mbuf *n = m_get(M_NOWAIT, MT_DATA);
|
|
|
|
if (n == NULL) {
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bcopy(data, mtod(n, void *), data_len);
|
|
|
|
n->m_len = data_len;
|
|
|
|
m->m_next = n;
|
|
|
|
} else if (data_len > 0) {
|
|
|
|
bcopy(data, mtod(m, u_int8_t *) + m->m_len, data_len);
|
|
|
|
m->m_len += data_len;
|
|
|
|
}
|
|
|
|
if (m->m_flags & M_PKTHDR)
|
|
|
|
m->m_pkthdr.len += data_len;
|
|
|
|
mtod(m, struct if_announcemsghdr *)->ifan_msglen += data_len;
|
|
|
|
rt_dispatch(m, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-18 14:33:04 +00:00
|
|
|
/*
|
|
|
|
* This is called to generate routing socket messages indicating
|
|
|
|
* network interface arrival and departure.
|
|
|
|
*/
|
|
|
|
void
|
2003-10-03 18:15:54 +00:00
|
|
|
rt_ifannouncemsg(struct ifnet *ifp, int what)
|
2002-01-18 14:33:04 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
struct rt_addrinfo info;
|
|
|
|
|
2004-10-05 19:48:33 +00:00
|
|
|
m = rt_makeifannouncemsg(ifp, RTM_IFANNOUNCE, what, &info);
|
|
|
|
if (m != NULL)
|
|
|
|
rt_dispatch(m, NULL);
|
|
|
|
}
|
2002-01-18 14:33:04 +00:00
|
|
|
|
2003-10-03 18:15:54 +00:00
|
|
|
static void
|
2004-04-18 00:56:44 +00:00
|
|
|
rt_dispatch(struct mbuf *m, const struct sockaddr *sa)
|
2003-10-03 18:15:54 +00:00
|
|
|
{
|
Introduce a netisr to deliver kernel-generated routing, avoiding
recursive entering of the socket code from the routing code:
- Modify rt_dispatch() to bundle up the sockaddr family, if any,
associated with a pending mbuf to dispatch to routing sockets, in
an m_tag on the mbuf.
- Allocate NETISR_ROUTE for use by routing sockets.
- Introduce rtsintrq, an ifqueue to be used by the netisr, and
introduce rts_input(), a function to unbundle the tagged sockaddr
and inject the mbuf and address into raw_input(), which previously
occurred in rt_dispatch().
- Introduce rts_init() to initialize rtsintrq, its mutex, and
register the netisr. Perform this at the same point in system
initialization as setup of the domains.
This change introduces asynchrony between the generation of a
pending routing socket message and delivery to sockets for use
by userspace. It avoids socket->routing->rtsock->socket use and
helps to avoid lock order reversals between the routing code and
socket code (in particular, raw socket control blocks), as route
locks are held over calls to rt_dispatch().
Reviewed by: "George V.Neville-Neil" <gnn@neville-neil.com>
Conceptual head nod by: sam
2004-06-09 02:48:23 +00:00
|
|
|
struct m_tag *tag;
|
2003-10-03 18:15:54 +00:00
|
|
|
|
Introduce a netisr to deliver kernel-generated routing, avoiding
recursive entering of the socket code from the routing code:
- Modify rt_dispatch() to bundle up the sockaddr family, if any,
associated with a pending mbuf to dispatch to routing sockets, in
an m_tag on the mbuf.
- Allocate NETISR_ROUTE for use by routing sockets.
- Introduce rtsintrq, an ifqueue to be used by the netisr, and
introduce rts_input(), a function to unbundle the tagged sockaddr
and inject the mbuf and address into raw_input(), which previously
occurred in rt_dispatch().
- Introduce rts_init() to initialize rtsintrq, its mutex, and
register the netisr. Perform this at the same point in system
initialization as setup of the domains.
This change introduces asynchrony between the generation of a
pending routing socket message and delivery to sockets for use
by userspace. It avoids socket->routing->rtsock->socket use and
helps to avoid lock order reversals between the routing code and
socket code (in particular, raw socket control blocks), as route
locks are held over calls to rt_dispatch().
Reviewed by: "George V.Neville-Neil" <gnn@neville-neil.com>
Conceptual head nod by: sam
2004-06-09 02:48:23 +00:00
|
|
|
/*
|
|
|
|
* Preserve the family from the sockaddr, if any, in an m_tag for
|
|
|
|
* use when injecting the mbuf into the routing socket buffer from
|
|
|
|
* the netisr.
|
|
|
|
*/
|
|
|
|
if (sa != NULL) {
|
|
|
|
tag = m_tag_get(PACKET_TAG_RTSOCKFAM, sizeof(unsigned short),
|
|
|
|
M_NOWAIT);
|
|
|
|
if (tag == NULL) {
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
2005-02-23 22:50:19 +00:00
|
|
|
*(unsigned short *)(tag + 1) = sa->sa_family;
|
Introduce a netisr to deliver kernel-generated routing, avoiding
recursive entering of the socket code from the routing code:
- Modify rt_dispatch() to bundle up the sockaddr family, if any,
associated with a pending mbuf to dispatch to routing sockets, in
an m_tag on the mbuf.
- Allocate NETISR_ROUTE for use by routing sockets.
- Introduce rtsintrq, an ifqueue to be used by the netisr, and
introduce rts_input(), a function to unbundle the tagged sockaddr
and inject the mbuf and address into raw_input(), which previously
occurred in rt_dispatch().
- Introduce rts_init() to initialize rtsintrq, its mutex, and
register the netisr. Perform this at the same point in system
initialization as setup of the domains.
This change introduces asynchrony between the generation of a
pending routing socket message and delivery to sockets for use
by userspace. It avoids socket->routing->rtsock->socket use and
helps to avoid lock order reversals between the routing code and
socket code (in particular, raw socket control blocks), as route
locks are held over calls to rt_dispatch().
Reviewed by: "George V.Neville-Neil" <gnn@neville-neil.com>
Conceptual head nod by: sam
2004-06-09 02:48:23 +00:00
|
|
|
m_tag_prepend(m, tag);
|
|
|
|
}
|
2004-08-27 18:33:08 +00:00
|
|
|
netisr_queue(NETISR_ROUTE, m); /* mbuf is free'd on failure. */
|
2003-10-03 18:15:54 +00:00
|
|
|
}
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* This is used in dumping the kernel table via sysctl().
|
|
|
|
*/
|
2002-09-28 17:15:38 +00:00
|
|
|
static int
|
2003-10-03 18:15:54 +00:00
|
|
|
sysctl_dumpentry(struct radix_node *rn, void *vw)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2003-10-03 18:15:54 +00:00
|
|
|
struct walkarg *w = vw;
|
|
|
|
struct rtentry *rt = (struct rtentry *)rn;
|
1994-05-24 10:09:53 +00:00
|
|
|
int error = 0, size;
|
|
|
|
struct rt_addrinfo info;
|
|
|
|
|
|
|
|
if (w->w_op == NET_RT_FLAGS && !(rt->rt_flags & w->w_arg))
|
|
|
|
return 0;
|
|
|
|
bzero((caddr_t)&info, sizeof(info));
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_DST] = rt_key(rt);
|
|
|
|
info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
|
|
|
|
info.rti_info[RTAX_NETMASK] = rt_mask(rt);
|
|
|
|
info.rti_info[RTAX_GENMASK] = rt->rt_genmask;
|
2001-10-17 11:23:59 +00:00
|
|
|
if (rt->rt_ifp) {
|
2005-11-11 16:04:59 +00:00
|
|
|
info.rti_info[RTAX_IFP] = rt->rt_ifp->if_addr->ifa_addr;
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr;
|
2001-10-17 11:23:59 +00:00
|
|
|
if (rt->rt_ifp->if_flags & IFF_POINTOPOINT)
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_BRD] = rt->rt_ifa->ifa_dstaddr;
|
2001-10-17 11:23:59 +00:00
|
|
|
}
|
2004-04-17 15:09:36 +00:00
|
|
|
size = rt_msg2(RTM_GET, &info, NULL, w);
|
1995-11-16 19:00:27 +00:00
|
|
|
if (w->w_req && w->w_tmem) {
|
2003-10-03 18:15:54 +00:00
|
|
|
struct rt_msghdr *rtm = (struct rt_msghdr *)w->w_tmem;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
rtm->rtm_flags = rt->rt_flags;
|
2003-11-20 20:07:39 +00:00
|
|
|
rtm->rtm_use = rt->rt_rmx.rmx_pksent;
|
|
|
|
rt_getmetrics(&rt->rt_rmx, &rtm->rtm_rmx);
|
1994-05-24 10:09:53 +00:00
|
|
|
rtm->rtm_index = rt->rt_ifp->if_index;
|
|
|
|
rtm->rtm_errno = rtm->rtm_pid = rtm->rtm_seq = 0;
|
|
|
|
rtm->rtm_addrs = info.rti_addrs;
|
1995-11-16 19:00:27 +00:00
|
|
|
error = SYSCTL_OUT(w->w_req, (caddr_t)rtm, size);
|
|
|
|
return (error);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-09-28 17:15:38 +00:00
|
|
|
static int
|
2003-10-03 18:15:54 +00:00
|
|
|
sysctl_iflist(int af, struct walkarg *w)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2003-10-03 18:15:54 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
struct rt_addrinfo info;
|
|
|
|
int len, error = 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
bzero((caddr_t)&info, sizeof(info));
|
2005-09-10 15:12:24 +00:00
|
|
|
IFNET_RLOCK();
|
2001-02-04 13:13:25 +00:00
|
|
|
TAILQ_FOREACH(ifp, &ifnet, if_link) {
|
1994-05-24 10:09:53 +00:00
|
|
|
if (w->w_arg && w->w_arg != ifp->if_index)
|
|
|
|
continue;
|
2005-11-11 16:04:59 +00:00
|
|
|
ifa = ifp->if_addr;
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_IFP] = ifa->ifa_addr;
|
2004-04-17 15:09:36 +00:00
|
|
|
len = rt_msg2(RTM_IFINFO, &info, NULL, w);
|
2004-04-18 00:56:44 +00:00
|
|
|
info.rti_info[RTAX_IFP] = NULL;
|
1995-11-16 19:00:27 +00:00
|
|
|
if (w->w_req && w->w_tmem) {
|
2003-10-03 18:15:54 +00:00
|
|
|
struct if_msghdr *ifm;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
ifm = (struct if_msghdr *)w->w_tmem;
|
|
|
|
ifm->ifm_index = ifp->if_index;
|
Rename IFF_RUNNING to IFF_DRV_RUNNING, IFF_OACTIVE to IFF_DRV_OACTIVE,
and move both flags from ifnet.if_flags to ifnet.if_drv_flags, making
and documenting the locking of these flags the responsibility of the
device driver, not the network stack. The flags for these two fields
will be mutually exclusive so that they can be exposed to user space as
though they were stored in the same variable.
Provide #defines to provide the old names #ifndef _KERNEL, so that user
applications (such as ifconfig) can use the old flag names. Using the
old names in a device driver will result in a compile error in order to
help device driver writers adopt the new model.
When exposing the interface flags to user space, via interface ioctls
or routing sockets, or the two fields together. Since the driver flags
cannot currently be set for user space, no new logic is currently
required to handle this case.
Add some assertions that general purpose network stack routines, such
as if_setflags(), are not improperly used on driver-owned flags.
With this change, a large number of very minor network stack races are
closed, subject to correct device driver locking. Most were likely
never triggered.
Driver sweep to follow; many thanks to pjd and bz for the line-by-line
review they gave this patch.
Reviewed by: pjd, bz
MFC after: 7 days
2005-08-09 10:16:17 +00:00
|
|
|
ifm->ifm_flags = ifp->if_flags | ifp->if_drv_flags;
|
1994-05-24 10:09:53 +00:00
|
|
|
ifm->ifm_data = ifp->if_data;
|
|
|
|
ifm->ifm_addrs = info.rti_addrs;
|
1995-11-16 19:00:27 +00:00
|
|
|
error = SYSCTL_OUT(w->w_req,(caddr_t)ifm, len);
|
1994-10-08 22:38:27 +00:00
|
|
|
if (error)
|
2001-09-29 05:08:04 +00:00
|
|
|
goto done;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2004-04-18 00:56:44 +00:00
|
|
|
while ((ifa = TAILQ_NEXT(ifa, ifa_link)) != NULL) {
|
1994-05-24 10:09:53 +00:00
|
|
|
if (af && af != ifa->ifa_addr->sa_family)
|
|
|
|
continue;
|
2002-02-27 18:32:23 +00:00
|
|
|
if (jailed(curthread->td_ucred) &&
|
|
|
|
prison_if(curthread->td_ucred, ifa->ifa_addr))
|
This Implements the mumbled about "Jail" feature.
This is a seriously beefed up chroot kind of thing. The process
is jailed along the same lines as a chroot does it, but with
additional tough restrictions imposed on what the superuser can do.
For all I know, it is safe to hand over the root bit inside a
prison to the customer living in that prison, this is what
it was developed for in fact: "real virtual servers".
Each prison has an ip number associated with it, which all IP
communications will be coerced to use and each prison has its own
hostname.
Needless to say, you need more RAM this way, but the advantage is
that each customer can run their own particular version of apache
and not stomp on the toes of their neighbors.
It generally does what one would expect, but setting up a jail
still takes a little knowledge.
A few notes:
I have no scripts for setting up a jail, don't ask me for them.
The IP number should be an alias on one of the interfaces.
mount a /proc in each jail, it will make ps more useable.
/proc/<pid>/status tells the hostname of the prison for
jailed processes.
Quotas are only sensible if you have a mountpoint per prison.
There are no privisions for stopping resource-hogging.
Some "#ifdef INET" and similar may be missing (send patches!)
If somebody wants to take it from here and develop it into
more of a "virtual machine" they should be most welcome!
Tools, comments, patches & documentation most welcome.
Have fun...
Sponsored by: http://www.rndassociates.com/
Run for almost a year by: http://www.servetheweb.com/
1999-04-28 11:38:52 +00:00
|
|
|
continue;
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_IFA] = ifa->ifa_addr;
|
|
|
|
info.rti_info[RTAX_NETMASK] = ifa->ifa_netmask;
|
|
|
|
info.rti_info[RTAX_BRD] = ifa->ifa_dstaddr;
|
2004-04-17 15:09:36 +00:00
|
|
|
len = rt_msg2(RTM_NEWADDR, &info, NULL, w);
|
1995-11-16 19:00:27 +00:00
|
|
|
if (w->w_req && w->w_tmem) {
|
2003-10-03 18:15:54 +00:00
|
|
|
struct ifa_msghdr *ifam;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
ifam = (struct ifa_msghdr *)w->w_tmem;
|
|
|
|
ifam->ifam_index = ifa->ifa_ifp->if_index;
|
|
|
|
ifam->ifam_flags = ifa->ifa_flags;
|
|
|
|
ifam->ifam_metric = ifa->ifa_metric;
|
|
|
|
ifam->ifam_addrs = info.rti_addrs;
|
1995-11-16 19:00:27 +00:00
|
|
|
error = SYSCTL_OUT(w->w_req, w->w_tmem, len);
|
1994-10-08 22:38:27 +00:00
|
|
|
if (error)
|
2001-09-29 05:08:04 +00:00
|
|
|
goto done;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-03 18:15:54 +00:00
|
|
|
info.rti_info[RTAX_IFA] = info.rti_info[RTAX_NETMASK] =
|
2004-04-18 00:56:44 +00:00
|
|
|
info.rti_info[RTAX_BRD] = NULL;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2001-09-29 05:08:04 +00:00
|
|
|
done:
|
2005-09-10 15:12:24 +00:00
|
|
|
IFNET_RUNLOCK();
|
2001-09-29 05:08:04 +00:00
|
|
|
return (error);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
2003-11-14 18:48:15 +00:00
|
|
|
int
|
2004-04-16 08:14:34 +00:00
|
|
|
sysctl_ifmalist(int af, struct walkarg *w)
|
2003-11-14 18:48:15 +00:00
|
|
|
{
|
2004-04-16 08:14:34 +00:00
|
|
|
struct ifnet *ifp;
|
2003-11-14 18:48:15 +00:00
|
|
|
struct ifmultiaddr *ifma;
|
|
|
|
struct rt_addrinfo info;
|
|
|
|
int len, error = 0;
|
2004-04-16 08:14:34 +00:00
|
|
|
struct ifaddr *ifa;
|
2003-11-14 18:48:15 +00:00
|
|
|
|
|
|
|
bzero((caddr_t)&info, sizeof(info));
|
2005-09-10 15:12:24 +00:00
|
|
|
IFNET_RLOCK();
|
2003-11-14 18:48:15 +00:00
|
|
|
TAILQ_FOREACH(ifp, &ifnet, if_link) {
|
|
|
|
if (w->w_arg && w->w_arg != ifp->if_index)
|
|
|
|
continue;
|
2005-11-11 16:04:59 +00:00
|
|
|
ifa = ifp->if_addr;
|
2004-04-17 15:09:36 +00:00
|
|
|
info.rti_info[RTAX_IFP] = ifa ? ifa->ifa_addr : NULL;
|
2005-09-10 15:12:24 +00:00
|
|
|
IF_ADDR_LOCK(ifp);
|
2003-11-14 18:48:15 +00:00
|
|
|
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
|
|
|
if (af && af != ifma->ifma_addr->sa_family)
|
|
|
|
continue;
|
|
|
|
if (jailed(curproc->p_ucred) &&
|
|
|
|
prison_if(curproc->p_ucred, ifma->ifma_addr))
|
|
|
|
continue;
|
|
|
|
info.rti_info[RTAX_IFA] = ifma->ifma_addr;
|
2004-04-17 15:09:36 +00:00
|
|
|
info.rti_info[RTAX_GATEWAY] =
|
|
|
|
(ifma->ifma_addr->sa_family != AF_LINK) ?
|
|
|
|
ifma->ifma_lladdr : NULL;
|
|
|
|
len = rt_msg2(RTM_NEWMADDR, &info, NULL, w);
|
2003-11-14 18:48:15 +00:00
|
|
|
if (w->w_req && w->w_tmem) {
|
2004-04-16 08:14:34 +00:00
|
|
|
struct ifma_msghdr *ifmam;
|
2003-11-14 18:48:15 +00:00
|
|
|
|
|
|
|
ifmam = (struct ifma_msghdr *)w->w_tmem;
|
|
|
|
ifmam->ifmam_index = ifma->ifma_ifp->if_index;
|
|
|
|
ifmam->ifmam_flags = 0;
|
|
|
|
ifmam->ifmam_addrs = info.rti_addrs;
|
|
|
|
error = SYSCTL_OUT(w->w_req, w->w_tmem, len);
|
2005-09-10 15:12:24 +00:00
|
|
|
if (error) {
|
|
|
|
IF_ADDR_UNLOCK(ifp);
|
2003-11-14 18:48:15 +00:00
|
|
|
goto done;
|
2005-09-10 15:12:24 +00:00
|
|
|
}
|
2003-11-14 18:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
2005-09-10 15:12:24 +00:00
|
|
|
IF_ADDR_UNLOCK(ifp);
|
2003-11-14 18:48:15 +00:00
|
|
|
}
|
|
|
|
done:
|
2005-09-10 15:12:24 +00:00
|
|
|
IFNET_RUNLOCK();
|
2003-11-14 18:48:15 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1995-11-16 19:00:27 +00:00
|
|
|
static int
|
2000-07-04 11:25:35 +00:00
|
|
|
sysctl_rtsock(SYSCTL_HANDLER_ARGS)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
1995-11-16 19:00:27 +00:00
|
|
|
int *name = (int *)arg1;
|
|
|
|
u_int namelen = arg2;
|
2003-10-03 18:15:54 +00:00
|
|
|
struct radix_node_head *rnh;
|
2005-09-10 15:12:24 +00:00
|
|
|
int i, lim, error = EINVAL;
|
2004-04-12 20:26:01 +00:00
|
|
|
u_char af;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct walkarg w;
|
|
|
|
|
1995-11-16 19:00:27 +00:00
|
|
|
name ++;
|
|
|
|
namelen--;
|
|
|
|
if (req->newptr)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (EPERM);
|
|
|
|
if (namelen != 3)
|
2002-01-25 00:50:49 +00:00
|
|
|
return ((namelen < 3) ? EISDIR : ENOTDIR);
|
1994-05-24 10:09:53 +00:00
|
|
|
af = name[0];
|
2002-12-25 10:51:20 +00:00
|
|
|
if (af > AF_MAX)
|
|
|
|
return (EINVAL);
|
2004-04-18 11:47:04 +00:00
|
|
|
bzero(&w, sizeof(w));
|
1994-05-24 10:09:53 +00:00
|
|
|
w.w_op = name[1];
|
|
|
|
w.w_arg = name[2];
|
1995-11-16 19:00:27 +00:00
|
|
|
w.w_req = req;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2005-09-10 15:12:24 +00:00
|
|
|
error = sysctl_wire_old_buffer(req, 0);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
1994-05-24 10:09:53 +00:00
|
|
|
switch (w.w_op) {
|
|
|
|
|
|
|
|
case NET_RT_DUMP:
|
|
|
|
case NET_RT_FLAGS:
|
2004-04-12 20:26:01 +00:00
|
|
|
if (af == 0) { /* dump all tables */
|
|
|
|
i = 1;
|
|
|
|
lim = AF_MAX;
|
|
|
|
} else /* dump only one table */
|
|
|
|
i = lim = af;
|
|
|
|
for (error = 0; error == 0 && i <= lim; i++)
|
|
|
|
if ((rnh = rt_tables[i]) != NULL) {
|
2005-09-10 15:12:24 +00:00
|
|
|
RADIX_NODE_HEAD_LOCK(rnh);
|
2002-12-24 03:03:39 +00:00
|
|
|
error = rnh->rnh_walktree(rnh,
|
2005-09-10 15:12:24 +00:00
|
|
|
sysctl_dumpentry, &w);
|
|
|
|
RADIX_NODE_HEAD_UNLOCK(rnh);
|
2004-04-12 20:26:01 +00:00
|
|
|
} else if (af != 0)
|
2002-12-24 03:03:39 +00:00
|
|
|
error = EAFNOSUPPORT;
|
1994-05-24 10:09:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_RT_IFLIST:
|
|
|
|
error = sysctl_iflist(af, &w);
|
2003-11-14 18:48:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_RT_IFMALIST:
|
|
|
|
error = sysctl_ifmalist(af, &w);
|
|
|
|
break;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
if (w.w_tmem)
|
|
|
|
free(w.w_tmem, M_RTABLE);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1997-04-27 20:01:29 +00:00
|
|
|
SYSCTL_NODE(_net, PF_ROUTE, routetable, CTLFLAG_RD, sysctl_rtsock, "");
|
1995-11-16 19:00:27 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Definitions of protocols supported in the ROUTE domain.
|
|
|
|
*/
|
|
|
|
|
2005-09-07 10:06:14 +00:00
|
|
|
static struct domain routedomain; /* or at least forward */
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1995-11-16 19:00:27 +00:00
|
|
|
static struct protosw routesw[] = {
|
2005-11-09 13:29:16 +00:00
|
|
|
{
|
|
|
|
.pr_type = SOCK_RAW,
|
|
|
|
.pr_domain = &routedomain,
|
|
|
|
.pr_flags = PR_ATOMIC|PR_ADDR,
|
|
|
|
.pr_output = route_output,
|
|
|
|
.pr_ctlinput = raw_ctlinput,
|
|
|
|
.pr_init = raw_init,
|
|
|
|
.pr_usrreqs = &route_usrreqs
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2005-11-09 13:29:16 +00:00
|
|
|
static struct domain routedomain = {
|
|
|
|
.dom_family = PF_ROUTE,
|
|
|
|
.dom_name = "route",
|
|
|
|
.dom_protosw = routesw,
|
|
|
|
.dom_protoswNPROTOSW = &routesw[sizeof(routesw)/sizeof(routesw[0])]
|
|
|
|
};
|
1995-05-10 16:48:52 +00:00
|
|
|
|
1995-05-11 00:13:26 +00:00
|
|
|
DOMAIN_SET(route);
|