2 * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1988, 1991, 1993
30 * The Regents of the University of California. All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)rtsock.c 8.5 (Berkeley) 11/2/94
64 #include <sys/param.h>
65 #include <sys/systm.h>
66 #include <sys/kernel.h>
67 #include <sys/sysctl.h>
69 #include <sys/malloc.h>
71 #include <sys/socket.h>
72 #include <sys/socketvar.h>
73 #include <sys/domain.h>
74 #include <sys/protosw.h>
75 #include <sys/syslog.h>
76 #include <kern/lock.h>
79 #include <net/route.h>
80 #include <net/raw_cb.h>
81 #include <netinet/in.h>
83 #include <machine/spl.h>
85 extern struct rtstat rtstat
;
86 extern int check_routeselfref
;
88 MALLOC_DEFINE(M_RTABLE
, "routetbl", "routing tables");
90 static struct sockaddr route_dst
= { 2, PF_ROUTE
, { 0, } };
91 static struct sockaddr route_src
= { 2, PF_ROUTE
, { 0, } };
92 static struct sockaddr sa_zero
= { sizeof(sa_zero
), AF_INET
, { 0, } };
93 static struct sockproto route_proto
= { PF_ROUTE
, 0 };
99 struct sysctl_req
*w_req
;
102 static struct mbuf
*rt_msg1(int, struct rt_addrinfo
*);
103 static int rt_msg2(int, struct rt_addrinfo
*, caddr_t
, struct walkarg
*);
104 static int rt_xaddrs(caddr_t
, caddr_t
, struct rt_addrinfo
*);
105 static int sysctl_dumpentry(struct radix_node
*rn
, void *vw
);
106 static int sysctl_iflist(int af
, struct walkarg
*w
);
107 static int sysctl_iflist2(int af
, struct walkarg
*w
);
108 static int route_output(struct mbuf
*, struct socket
*);
109 static void rt_setmetrics(u_int32_t
, struct rt_metrics
*, struct rt_metrics
*);
110 static void rt_setif(struct rtentry
*, struct sockaddr
*, struct sockaddr
*,
111 struct sockaddr
*, unsigned int);
113 #define SIN(sa) ((struct sockaddr_in *)(size_t)(sa))
115 /* Sleazy use of local variables throughout file, warning!!!! */
116 #define dst info.rti_info[RTAX_DST]
117 #define gate info.rti_info[RTAX_GATEWAY]
118 #define netmask info.rti_info[RTAX_NETMASK]
119 #define genmask info.rti_info[RTAX_GENMASK]
120 #define ifpaddr info.rti_info[RTAX_IFP]
121 #define ifaaddr info.rti_info[RTAX_IFA]
122 #define brdaddr info.rti_info[RTAX_BRD]
125 * It really doesn't make any sense at all for this code to share much
126 * with raw_usrreq.c, since its functionality is so restricted. XXX
129 rts_abort(struct socket
*so
)
133 error
= raw_usrreqs
.pru_abort(so
);
137 /* pru_accept is EOPNOTSUPP */
140 rts_attach(struct socket
*so
, int proto
, __unused
struct proc
*p
)
145 if (sotorawcb(so
) != 0)
146 return EISCONN
; /* XXX panic? */
147 MALLOC(rp
, struct rawcb
*, sizeof *rp
, M_PCB
, M_WAITOK
); /* XXX */
150 bzero(rp
, sizeof *rp
);
153 * The splnet() is necessary to block protocols from sending
154 * error notifications (like RTM_REDIRECT or RTM_LOSING) while
155 * this PCB is extant but incompletely initialized.
156 * Probably we should try to do more of this work beforehand and
159 so
->so_pcb
= (caddr_t
)rp
;
160 error
= raw_attach(so
, proto
); /* don't use raw_usrreqs.pru_attach, it checks for SS_PRIV */
165 so
->so_flags
|= SOF_PCBCLEARING
;
169 switch(rp
->rcb_proto
.sp_protocol
) {
170 //####LD route_cb needs looking
175 route_cb
.ip6_count
++;
178 route_cb
.ipx_count
++;
184 rp
->rcb_faddr
= &route_src
;
185 route_cb
.any_count
++;
186 /* the socket is already locked when we enter rts_attach */
188 so
->so_options
|= SO_USELOOPBACK
;
193 rts_bind(struct socket
*so
, struct sockaddr
*nam
, struct proc
*p
)
196 error
= raw_usrreqs
.pru_bind(so
, nam
, p
); /* xxx just EINVAL */
201 rts_connect(struct socket
*so
, struct sockaddr
*nam
, struct proc
*p
)
204 error
= raw_usrreqs
.pru_connect(so
, nam
, p
); /* XXX just EINVAL */
208 /* pru_connect2 is EOPNOTSUPP */
209 /* pru_control is EOPNOTSUPP */
212 rts_detach(struct socket
*so
)
214 struct rawcb
*rp
= sotorawcb(so
);
218 switch(rp
->rcb_proto
.sp_protocol
) {
223 route_cb
.ip6_count
--;
226 route_cb
.ipx_count
--;
232 route_cb
.any_count
--;
234 error
= raw_usrreqs
.pru_detach(so
);
239 rts_disconnect(struct socket
*so
)
242 error
= raw_usrreqs
.pru_disconnect(so
);
246 /* pru_listen is EOPNOTSUPP */
249 rts_peeraddr(struct socket
*so
, struct sockaddr
**nam
)
252 error
= raw_usrreqs
.pru_peeraddr(so
, nam
);
256 /* pru_rcvd is EOPNOTSUPP */
257 /* pru_rcvoob is EOPNOTSUPP */
260 rts_send(struct socket
*so
, int flags
, struct mbuf
*m
, struct sockaddr
*nam
,
261 struct mbuf
*control
, struct proc
*p
)
264 error
= raw_usrreqs
.pru_send(so
, flags
, m
, nam
, control
, p
);
268 /* pru_sense is null */
271 rts_shutdown(struct socket
*so
)
274 error
= raw_usrreqs
.pru_shutdown(so
);
279 rts_sockaddr(struct socket
*so
, struct sockaddr
**nam
)
282 error
= raw_usrreqs
.pru_sockaddr(so
, nam
);
286 static struct pr_usrreqs route_usrreqs
= {
287 rts_abort
, pru_accept_notsupp
, rts_attach
, rts_bind
,
288 rts_connect
, pru_connect2_notsupp
, pru_control_notsupp
,
289 rts_detach
, rts_disconnect
, pru_listen_notsupp
, rts_peeraddr
,
290 pru_rcvd_notsupp
, pru_rcvoob_notsupp
, rts_send
, pru_sense_null
,
291 rts_shutdown
, rts_sockaddr
, sosend
, soreceive
, pru_sopoll_notsupp
296 route_output(struct mbuf
*m
, struct socket
*so
)
298 struct rt_msghdr
*rtm
= NULL
;
299 struct rtentry
*rt
= NULL
;
300 struct rtentry
*saved_nrt
= NULL
;
301 struct radix_node_head
*rnh
;
302 struct rt_addrinfo info
;
304 struct ifnet
*ifp
= NULL
;
306 struct proc
*curproc
= current_proc();
308 struct sockaddr_in dst_in
, gate_in
;
309 int sendonlytoself
= 0;
310 unsigned int ifscope
= IFSCOPE_NONE
;
312 #define senderr(e) { error = e; goto flush;}
314 ((m
->m_len
< sizeof(intptr_t)) && (m
= m_pullup(m
, sizeof(intptr_t))) == 0))
316 if ((m
->m_flags
& M_PKTHDR
) == 0)
317 panic("route_output");
319 /* unlock the socket (but keep a reference) it won't be accessed until raw_input appends to it. */
320 socket_unlock(so
, 0);
321 lck_mtx_lock(rnh_lock
);
323 len
= m
->m_pkthdr
.len
;
324 if (len
< sizeof(*rtm
) ||
325 len
!= mtod(m
, struct rt_msghdr
*)->rtm_msglen
) {
329 R_Malloc(rtm
, struct rt_msghdr
*, len
);
334 m_copydata(m
, 0, len
, (caddr_t
)rtm
);
335 if (rtm
->rtm_version
!= RTM_VERSION
) {
337 senderr(EPROTONOSUPPORT
);
341 * Silent version of RTM_GET for Reachabiltiy APIs. We may change
342 * all RTM_GETs to be silent in the future, so this is private for now.
344 if (rtm
->rtm_type
== RTM_GET_SILENT
) {
345 if ((so
->so_options
& SO_USELOOPBACK
) == 0)
348 rtm
->rtm_type
= RTM_GET
;
352 * Perform permission checking, only privileged sockets
353 * may perform operations other than RTM_GET
355 if (rtm
->rtm_type
!= RTM_GET
&& (so
->so_state
& SS_PRIV
) == 0) {
360 rtm
->rtm_pid
= proc_selfpid();
361 info
.rti_addrs
= rtm
->rtm_addrs
;
362 if (rt_xaddrs((caddr_t
)(rtm
+ 1), len
+ (caddr_t
)rtm
, &info
)) {
366 if (dst
== NULL
|| (dst
->sa_family
>= AF_MAX
) ||
367 (gate
!= NULL
&& (gate
->sa_family
>= AF_MAX
))) {
371 if (dst
->sa_family
== AF_INET
&& dst
->sa_len
!= sizeof (dst_in
)) {
372 /* At minimum, we need up to sin_addr */
373 if (dst
->sa_len
< offsetof(struct sockaddr_in
, sin_zero
))
375 bzero(&dst_in
, sizeof (dst_in
));
376 dst_in
.sin_len
= sizeof (dst_in
);
377 dst_in
.sin_family
= AF_INET
;
378 dst_in
.sin_port
= SIN(dst
)->sin_port
;
379 dst_in
.sin_addr
= SIN(dst
)->sin_addr
;
380 dst
= (struct sockaddr
*)&dst_in
;
384 gate
->sa_family
== AF_INET
&& gate
->sa_len
!= sizeof (gate_in
)) {
385 /* At minimum, we need up to sin_addr */
386 if (gate
->sa_len
< offsetof(struct sockaddr_in
, sin_zero
))
388 bzero(&gate_in
, sizeof (gate_in
));
389 gate_in
.sin_len
= sizeof (gate_in
);
390 gate_in
.sin_family
= AF_INET
;
391 gate_in
.sin_port
= SIN(gate
)->sin_port
;
392 gate_in
.sin_addr
= SIN(gate
)->sin_addr
;
393 gate
= (struct sockaddr
*)&gate_in
;
397 struct radix_node
*t
;
398 t
= rn_addmask((caddr_t
)genmask
, 0, 1);
399 if (t
&& Bcmp(genmask
, t
->rn_key
, *(u_char
*)genmask
) == 0)
400 genmask
= (struct sockaddr
*)(t
->rn_key
);
406 * If RTF_IFSCOPE flag is set, then rtm_index specifies the scope.
408 if (rtm
->rtm_flags
& RTF_IFSCOPE
) {
409 /* Scoped routing is for AF_INET only */
410 if (dst
->sa_family
!= AF_INET
)
412 ifscope
= rtm
->rtm_index
;
415 switch (rtm
->rtm_type
) {
422 /* XXX LD11JUL02 Special case for AOL 5.1.2 connectivity issue to AirPort BS (Radar 2969954)
423 * AOL is adding a circular route ("10.0.1.1/32 10.0.1.1") when establishing its ppp tunnel
424 * to the AP BaseStation by removing the default gateway and replacing it with their tunnel entry point.
425 * There is no apparent reason to add this route as there is a valid 10.0.1.1/24 route to the BS.
426 * That circular route was ignored on previous version of MacOS X because of a routing bug
427 * corrected with the merge to FreeBSD4.4 (a route generated from an RTF_CLONING route had the RTF_WASCLONED
428 * flag set but did not have a reference to the parent route) and that entry was left in the RT. This workaround is
429 * made in order to provide binary compatibility with AOL.
430 * If we catch a process adding a circular route with a /32 from the routing socket, we error it out instead of
431 * confusing the routing table with a wrong route to the previous default gateway
434 #define satosinaddr(sa) (((struct sockaddr_in *)sa)->sin_addr.s_addr)
436 if (check_routeselfref
&& (dst
&& dst
->sa_family
== AF_INET
) &&
437 (netmask
&& satosinaddr(netmask
) == INADDR_BROADCAST
) &&
438 (gate
&& satosinaddr(dst
) == satosinaddr(gate
))) {
439 log(LOG_WARNING
, "route_output: circular route %ld.%ld.%ld.%ld/32 ignored\n",
440 (ntohl(satosinaddr(gate
)>>24))&0xff,
441 (ntohl(satosinaddr(gate
)>>16))&0xff,
442 (ntohl(satosinaddr(gate
)>>8))&0xff,
443 (ntohl(satosinaddr(gate
)))&0xff);
449 error
= rtrequest_scoped_locked(RTM_ADD
, dst
, gate
,
450 netmask
, rtm
->rtm_flags
, &saved_nrt
, ifscope
);
451 if (error
== 0 && saved_nrt
) {
455 * If the route request specified an interface with
456 * IFA and/or IFP, we set the requested interface on
457 * the route with rt_setif. It would be much better
458 * to do this inside rtrequest, but that would
459 * require passing the desired interface, in some
460 * form, to rtrequest. Since rtrequest is called in
461 * so many places (roughly 40 in our source), adding
462 * a parameter is to much for us to swallow; this is
463 * something for the FreeBSD developers to tackle.
464 * Instead, we let rtrequest compute whatever
465 * interface it wants, then come in behind it and
466 * stick in the interface that we really want. This
467 * works reasonably well except when rtrequest can't
468 * figure out what interface to use (with
469 * ifa_withroute) and returns ENETUNREACH. Ideally
470 * it shouldn't matter if rtrequest can't figure out
471 * the interface if we're going to explicitly set it
472 * ourselves anyway. But practically we can't
473 * recover here because rtrequest will not do any of
474 * the work necessary to add the route if it can't
475 * find an interface. As long as there is a default
476 * route that leads to some interface, rtrequest will
477 * find an interface, so this problem should be
478 * rarely encountered.
482 rt_setif(saved_nrt
, ifpaddr
, ifaaddr
, gate
,
485 rt_setmetrics(rtm
->rtm_inits
,
486 &rtm
->rtm_rmx
, &saved_nrt
->rt_rmx
);
487 saved_nrt
->rt_rmx
.rmx_locks
&= ~(rtm
->rtm_inits
);
488 saved_nrt
->rt_rmx
.rmx_locks
|=
489 (rtm
->rtm_inits
& rtm
->rtm_rmx
.rmx_locks
);
490 saved_nrt
->rt_genmask
= genmask
;
491 RT_REMREF_LOCKED(saved_nrt
);
492 RT_UNLOCK(saved_nrt
);
497 error
= rtrequest_scoped_locked(RTM_DELETE
, dst
,
498 gate
, netmask
, rtm
->rtm_flags
, &saved_nrt
, ifscope
);
509 if ((rnh
= rt_tables
[dst
->sa_family
]) == NULL
)
510 senderr(EAFNOSUPPORT
);
513 * Lookup the best match based on the key-mask pair;
514 * callee adds a reference and checks for root node.
516 rt
= rt_lookup(TRUE
, dst
, netmask
, rnh
, ifscope
);
521 switch(rtm
->rtm_type
) {
527 RT_LOCK_ASSERT_HELD(rt
);
529 gate
= rt
->rt_gateway
;
530 netmask
= rt_mask(rt
);
531 genmask
= rt
->rt_genmask
;
532 if (rtm
->rtm_addrs
& (RTA_IFP
| RTA_IFA
)) {
535 ifnet_lock_shared(ifp
);
536 ifa2
= ifp
->if_addrhead
.tqh_first
;
537 ifpaddr
= ifa2
->ifa_addr
;
539 ifnet_lock_done(ifp
);
540 ifaaddr
= rt
->rt_ifa
->ifa_addr
;
541 rtm
->rtm_index
= ifp
->if_index
;
547 len
= rt_msg2(rtm
->rtm_type
, &info
, (caddr_t
)0,
548 (struct walkarg
*)0);
549 if (len
> rtm
->rtm_msglen
) {
550 struct rt_msghdr
*new_rtm
;
551 R_Malloc(new_rtm
, struct rt_msghdr
*, len
);
558 Bcopy(rtm
, new_rtm
, rtm
->rtm_msglen
);
559 R_Free(rtm
); rtm
= new_rtm
;
561 (void)rt_msg2(rtm
->rtm_type
, &info
, (caddr_t
)rtm
,
562 (struct walkarg
*)0);
563 rtm
->rtm_flags
= rt
->rt_flags
;
564 rtm
->rtm_rmx
= rt
->rt_rmx
;
565 rtm
->rtm_addrs
= info
.rti_addrs
;
572 if (gate
&& (error
= rt_setgate(rt
,
573 rt_key(rt
), gate
))) {
578 * If they tried to change things but didn't specify
579 * the required gateway, then just use the old one.
580 * This can happen if the user tries to change the
581 * flags on the default route without changing the
582 * default gateway. Changing flags still doesn't work.
584 if ((rt
->rt_flags
& RTF_GATEWAY
) && !gate
)
585 gate
= rt
->rt_gateway
;
589 * On Darwin, we call rt_setif which contains the
590 * equivalent to the code found at this very spot
593 rt_setif(rt
, ifpaddr
, ifaaddr
, gate
,
597 rt_setmetrics(rtm
->rtm_inits
, &rtm
->rtm_rmx
,
600 /* rt_setif, called above does this for us on darwin */
601 if (rt
->rt_ifa
&& rt
->rt_ifa
->ifa_rtrequest
)
602 rt
->rt_ifa
->ifa_rtrequest(RTM_ADD
, rt
, gate
);
605 rt
->rt_genmask
= genmask
;
610 rt
->rt_rmx
.rmx_locks
&= ~(rtm
->rtm_inits
);
611 rt
->rt_rmx
.rmx_locks
|=
612 (rtm
->rtm_inits
& rtm
->rtm_rmx
.rmx_locks
);
624 rtm
->rtm_errno
= error
;
626 rtm
->rtm_flags
|= RTF_DONE
;
629 RT_LOCK_ASSERT_NOTHELD(rt
);
632 lck_mtx_unlock(rnh_lock
);
633 socket_lock(so
, 0); /* relock the socket now */
635 struct rawcb
*rp
= 0;
637 * Check to see if we don't want our own messages.
639 if ((so
->so_options
& SO_USELOOPBACK
) == 0) {
640 if (route_cb
.any_count
<= 1) {
646 /* There is another listener, so construct message */
650 m_copyback(m
, 0, rtm
->rtm_msglen
, (caddr_t
)rtm
);
651 if (m
->m_pkthdr
.len
< rtm
->rtm_msglen
) {
654 } else if (m
->m_pkthdr
.len
> rtm
->rtm_msglen
)
655 m_adj(m
, rtm
->rtm_msglen
- m
->m_pkthdr
.len
);
658 if (sendonlytoself
&& m
) {
660 if (sbappendaddr(&so
->so_rcv
, &route_src
, m
, (struct mbuf
*)0, &error
) != 0) {
667 rp
->rcb_proto
.sp_family
= 0; /* Avoid us */
669 route_proto
.sp_protocol
= dst
->sa_family
;
671 socket_unlock(so
, 0);
672 raw_input(m
, &route_proto
, &route_src
, &route_dst
);
676 rp
->rcb_proto
.sp_family
= PF_ROUTE
;
683 rt_setmetrics(u_int32_t which
, struct rt_metrics
*in
, struct rt_metrics
*out
)
685 #define metric(f, e) if (which & (f)) out->e = in->e;
686 metric(RTV_RPIPE
, rmx_recvpipe
);
687 metric(RTV_SPIPE
, rmx_sendpipe
);
688 metric(RTV_SSTHRESH
, rmx_ssthresh
);
689 metric(RTV_RTT
, rmx_rtt
);
690 metric(RTV_RTTVAR
, rmx_rttvar
);
691 metric(RTV_HOPCOUNT
, rmx_hopcount
);
692 metric(RTV_MTU
, rmx_mtu
);
693 metric(RTV_EXPIRE
, rmx_expire
);
698 * Set route's interface given ifpaddr, ifaaddr, and gateway.
701 rt_setif(struct rtentry
*rt
, struct sockaddr
*Ifpaddr
, struct sockaddr
*Ifaaddr
,
702 struct sockaddr
*Gate
, unsigned int ifscope
)
704 struct ifaddr
*ifa
= 0;
705 struct ifnet
*ifp
= 0;
707 lck_mtx_assert(rnh_lock
, LCK_MTX_ASSERT_OWNED
);
709 RT_LOCK_ASSERT_HELD(rt
);
711 /* trigger route cache reevaluation */
715 /* Don't update a defunct route */
716 if (rt
->rt_flags
& RTF_CONDEMNED
)
719 /* Add an extra ref for ourselves */
720 RT_ADDREF_LOCKED(rt
);
723 * New gateway could require new ifaddr, ifp; flags may also
724 * be different; ifp may be specified by ll sockaddr when
725 * protocol address is ambiguous.
727 if (Ifpaddr
&& (ifa
= ifa_ifwithnet_scoped(Ifpaddr
, ifscope
)) &&
728 (ifp
= ifa
->ifa_ifp
) && (Ifaaddr
|| Gate
)) {
730 ifa
= ifaof_ifpforaddr(Ifaaddr
? Ifaaddr
: Gate
, ifp
);
736 if (Ifpaddr
&& (ifp
= if_withname(Ifpaddr
)) ) {
738 ifa
= ifaof_ifpforaddr(Gate
, ifp
);
740 ifnet_lock_shared(ifp
);
741 ifa
= TAILQ_FIRST(&ifp
->if_addrhead
);
744 ifnet_lock_done(ifp
);
746 } else if (Ifaaddr
&&
747 (ifa
= ifa_ifwithaddr_scoped(Ifaaddr
, ifscope
))) {
749 } else if (Gate
!= NULL
) {
751 * Safe to drop rt_lock and use rt_key, since holding
752 * rnh_lock here prevents another thread from calling
753 * rt_setgate() on this route. We cannot hold the
754 * lock across ifa_ifwithroute since the lookup done
755 * by that routine may point to the same route.
758 if ((ifa
= ifa_ifwithroute_scoped_locked(rt
->rt_flags
,
759 rt_key(rt
), Gate
, ifscope
)) != NULL
)
762 /* Don't update a defunct route */
763 if (rt
->rt_flags
& RTF_CONDEMNED
) {
766 /* Release extra ref */
767 RT_REMREF_LOCKED(rt
);
773 struct ifaddr
*oifa
= rt
->rt_ifa
;
775 if (oifa
&& oifa
->ifa_rtrequest
)
776 oifa
->ifa_rtrequest(RTM_DELETE
, rt
, Gate
);
780 * If this is the (non-scoped) default route, record
781 * the interface index used for the primary ifscope.
783 if (rt_inet_default(rt
, rt_key(rt
)))
784 set_primary_ifscope(rt
->rt_ifp
->if_index
);
785 rt
->rt_rmx
.rmx_mtu
= ifp
->if_mtu
;
786 if (rt
->rt_ifa
&& rt
->rt_ifa
->ifa_rtrequest
)
787 rt
->rt_ifa
->ifa_rtrequest(RTM_ADD
, rt
, Gate
);
789 /* Release extra ref */
790 RT_REMREF_LOCKED(rt
);
796 /* XXX: to reset gateway to correct value, at RTM_CHANGE */
797 if (rt
->rt_ifa
&& rt
->rt_ifa
->ifa_rtrequest
)
798 rt
->rt_ifa
->ifa_rtrequest(RTM_ADD
, rt
, Gate
);
800 /* Release extra ref */
801 RT_REMREF_LOCKED(rt
);
804 #define ROUNDUP32(a) \
805 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(uint32_t) - 1))) : sizeof(uint32_t))
806 #define ADVANCE32(x, n) (x += ROUNDUP32((n)->sa_len))
810 * Extract the addresses of the passed sockaddrs.
811 * Do a little sanity checking so as to avoid bad memory references.
812 * This data is derived straight from userland.
815 rt_xaddrs(caddr_t cp
, caddr_t cplim
, struct rt_addrinfo
*rtinfo
)
820 bzero(rtinfo
->rti_info
, sizeof(rtinfo
->rti_info
));
821 for (i
= 0; (i
< RTAX_MAX
) && (cp
< cplim
); i
++) {
822 if ((rtinfo
->rti_addrs
& (1 << i
)) == 0)
824 sa
= (struct sockaddr
*)cp
;
828 if ( (cp
+ sa
->sa_len
) > cplim
) {
833 * there are no more.. quit now
834 * If there are more bits, they are in error.
835 * I've seen this. route(1) can evidently generate these.
836 * This causes kernel to core dump.
837 * for compatibility, If we see this, point to a safe address.
839 if (sa
->sa_len
== 0) {
840 rtinfo
->rti_info
[i
] = &sa_zero
;
841 return (0); /* should be EINVAL but for compat */
845 rtinfo
->rti_info
[i
] = sa
;
852 rt_msg1(int type
, struct rt_addrinfo
*rtinfo
)
854 struct rt_msghdr
*rtm
;
863 len
= sizeof(struct ifa_msghdr
);
868 len
= sizeof(struct ifma_msghdr
);
872 len
= sizeof(struct if_msghdr
);
876 len
= sizeof(struct rt_msghdr
);
880 m
= m_gethdr(M_DONTWAIT
, MT_DATA
);
881 if (m
&& len
> MHLEN
) {
882 MCLGET(m
, M_DONTWAIT
);
883 if ((m
->m_flags
& M_EXT
) == 0) {
890 m
->m_pkthdr
.len
= m
->m_len
= len
;
891 m
->m_pkthdr
.rcvif
= 0;
892 rtm
= mtod(m
, struct rt_msghdr
*);
893 bzero((caddr_t
)rtm
, len
);
894 for (i
= 0; i
< RTAX_MAX
; i
++) {
895 struct sockaddr
*sa
, *hint
;
896 struct sockaddr_storage ss
;
898 if ((sa
= rtinfo
->rti_info
[i
]) == NULL
)
904 if ((hint
= rtinfo
->rti_info
[RTAX_DST
]) == NULL
)
905 hint
= rtinfo
->rti_info
[RTAX_IFA
];
907 /* Scrub away any trace of embedded interface scope */
908 sa
= rtm_scrub_ifscope(i
, hint
, sa
, &ss
);
915 rtinfo
->rti_addrs
|= (1 << i
);
916 dlen
= ROUNDUP32(sa
->sa_len
);
917 m_copyback(m
, len
, dlen
, (caddr_t
)sa
);
920 if (m
->m_pkthdr
.len
!= len
) {
924 rtm
->rtm_msglen
= len
;
925 rtm
->rtm_version
= RTM_VERSION
;
926 rtm
->rtm_type
= type
;
931 rt_msg2(int type
, struct rt_addrinfo
*rtinfo
, caddr_t cp
, struct walkarg
*w
)
934 int len
, dlen
, second_time
= 0;
937 rtinfo
->rti_addrs
= 0;
943 len
= sizeof(struct ifa_msghdr
);
948 len
= sizeof(struct ifma_msghdr
);
952 len
= sizeof(struct if_msghdr
);
956 len
= sizeof(struct if_msghdr2
);
960 len
= sizeof(struct ifma_msghdr2
);
964 len
= sizeof(struct rt_msghdr2
);
968 len
= sizeof(struct rt_msghdr
);
973 for (i
= 0; i
< RTAX_MAX
; i
++) {
974 struct sockaddr
*sa
, *hint
;
975 struct sockaddr_storage ss
;
977 if ((sa
= rtinfo
->rti_info
[i
]) == 0)
983 if ((hint
= rtinfo
->rti_info
[RTAX_DST
]) == NULL
)
984 hint
= rtinfo
->rti_info
[RTAX_IFA
];
986 /* Scrub away any trace of embedded interface scope */
987 sa
= rtm_scrub_ifscope(i
, hint
, sa
, &ss
);
994 rtinfo
->rti_addrs
|= (1 << i
);
995 dlen
= ROUNDUP32(sa
->sa_len
);
997 bcopy((caddr_t
)sa
, cp
, (unsigned)dlen
);
1002 if (cp
== 0 && w
!= NULL
&& !second_time
) {
1003 struct walkarg
*rw
= w
;
1006 if (rw
->w_tmemsize
< len
) {
1008 FREE(rw
->w_tmem
, M_RTABLE
);
1009 rw
->w_tmem
= (caddr_t
)
1010 _MALLOC(len
, M_RTABLE
, M_WAITOK
); /*###LD0412 was NOWAIT */
1012 rw
->w_tmemsize
= len
;
1022 struct rt_msghdr
*rtm
= (struct rt_msghdr
*)cp0
;
1024 rtm
->rtm_version
= RTM_VERSION
;
1025 rtm
->rtm_type
= type
;
1026 rtm
->rtm_msglen
= len
;
1032 * This routine is called to generate a message from the routing
1033 * socket indicating that a redirect has occurred, a routing lookup
1034 * has failed, or that a protocol has detected timeouts to a particular
1038 rt_missmsg(int type
, struct rt_addrinfo
*rtinfo
, int flags
, int error
)
1040 struct rt_msghdr
*rtm
;
1042 struct sockaddr
*sa
= rtinfo
->rti_info
[RTAX_DST
];
1044 if (route_cb
.any_count
== 0)
1046 m
= rt_msg1(type
, rtinfo
);
1049 rtm
= mtod(m
, struct rt_msghdr
*);
1050 rtm
->rtm_flags
= RTF_DONE
| flags
;
1051 rtm
->rtm_errno
= error
;
1052 rtm
->rtm_addrs
= rtinfo
->rti_addrs
;
1053 route_proto
.sp_protocol
= sa
? sa
->sa_family
: 0;
1054 raw_input(m
, &route_proto
, &route_src
, &route_dst
);
1058 * This routine is called to generate a message from the routing
1059 * socket indicating that the status of a network interface has changed.
1065 struct if_msghdr
*ifm
;
1067 struct rt_addrinfo info
;
1069 if (route_cb
.any_count
== 0)
1071 bzero((caddr_t
)&info
, sizeof(info
));
1072 m
= rt_msg1(RTM_IFINFO
, &info
);
1075 ifm
= mtod(m
, struct if_msghdr
*);
1076 ifm
->ifm_index
= ifp
->if_index
;
1077 ifm
->ifm_flags
= (u_short
)ifp
->if_flags
;
1078 if_data_internal_to_if_data(ifp
, &ifp
->if_data
, &ifm
->ifm_data
);
1080 route_proto
.sp_protocol
= 0;
1081 raw_input(m
, &route_proto
, &route_src
, &route_dst
);
1085 * This is called to generate messages from the routing socket
1086 * indicating a network interface has had addresses associated with it.
1087 * if we ever reverse the logic and replace messages TO the routing
1088 * socket indicate a request to configure interfaces, then it will
1089 * be unnecessary as the routing socket will automatically generate
1092 * Since this is coming from the interface, it is expected that the
1093 * interface will be locked. Caller must hold rt_lock.
1096 rt_newaddrmsg(int cmd
, struct ifaddr
*ifa
, int error
, struct rtentry
*rt
)
1098 struct rt_addrinfo info
;
1099 struct sockaddr
*sa
= 0;
1102 struct ifnet
*ifp
= ifa
->ifa_ifp
;
1104 RT_LOCK_ASSERT_HELD(rt
);
1106 if (route_cb
.any_count
== 0)
1108 for (pass
= 1; pass
< 3; pass
++) {
1109 bzero((caddr_t
)&info
, sizeof(info
));
1110 if ((cmd
== RTM_ADD
&& pass
== 1) ||
1111 (cmd
== RTM_DELETE
&& pass
== 2)) {
1112 struct ifa_msghdr
*ifam
;
1113 int ncmd
= cmd
== RTM_ADD
? RTM_NEWADDR
: RTM_DELADDR
;
1115 /* Lock ifp for if_addrhead */
1116 ifnet_lock_shared(ifp
);
1117 ifaaddr
= sa
= ifa
->ifa_addr
;
1118 ifpaddr
= ifp
->if_addrhead
.tqh_first
->ifa_addr
;
1119 netmask
= ifa
->ifa_netmask
;
1120 brdaddr
= ifa
->ifa_dstaddr
;
1121 if ((m
= rt_msg1(ncmd
, &info
)) == NULL
) {
1122 ifnet_lock_done(ifp
);
1125 ifnet_lock_done(ifp
);
1126 ifam
= mtod(m
, struct ifa_msghdr
*);
1127 ifam
->ifam_index
= ifp
->if_index
;
1128 ifam
->ifam_metric
= ifa
->ifa_metric
;
1129 ifam
->ifam_flags
= ifa
->ifa_flags
;
1130 ifam
->ifam_addrs
= info
.rti_addrs
;
1132 if ((cmd
== RTM_ADD
&& pass
== 2) ||
1133 (cmd
== RTM_DELETE
&& pass
== 1)) {
1134 struct rt_msghdr
*rtm
;
1138 netmask
= rt_mask(rt
);
1139 dst
= sa
= rt_key(rt
);
1140 gate
= rt
->rt_gateway
;
1141 if ((m
= rt_msg1(cmd
, &info
)) == NULL
)
1143 rtm
= mtod(m
, struct rt_msghdr
*);
1144 rtm
->rtm_index
= ifp
->if_index
;
1145 rtm
->rtm_flags
|= rt
->rt_flags
;
1146 rtm
->rtm_errno
= error
;
1147 rtm
->rtm_addrs
= info
.rti_addrs
;
1149 route_proto
.sp_protocol
= sa
? sa
->sa_family
: 0;
1150 raw_input(m
, &route_proto
, &route_src
, &route_dst
);
1155 * This is the analogue to the rt_newaddrmsg which performs the same
1156 * function but for multicast group memberhips. This is easier since
1157 * there is no route state to worry about.
1160 rt_newmaddrmsg(int cmd
, struct ifmultiaddr
*ifma
)
1162 struct rt_addrinfo info
;
1164 struct ifnet
*ifp
= ifma
->ifma_ifp
;
1165 struct ifma_msghdr
*ifmam
;
1167 if (route_cb
.any_count
== 0)
1170 bzero((caddr_t
)&info
, sizeof(info
));
1171 ifaaddr
= ifma
->ifma_addr
;
1172 /* Lock ifp for if_addrhead */
1174 ifnet_lock_shared(ifp
);
1175 if (ifp
&& ifp
->if_addrhead
.tqh_first
)
1176 ifpaddr
= ifp
->if_addrhead
.tqh_first
->ifa_addr
;
1180 * If a link-layer address is present, present it as a ``gateway''
1181 * (similarly to how ARP entries, e.g., are presented).
1183 gate
= ifma
->ifma_ll
->ifma_addr
;
1184 if ((m
= rt_msg1(cmd
, &info
)) == NULL
) {
1186 ifnet_lock_done(ifp
);
1190 ifnet_lock_done(ifp
);
1191 ifmam
= mtod(m
, struct ifma_msghdr
*);
1192 ifmam
->ifmam_index
= ifp
? ifp
->if_index
: 0;
1193 ifmam
->ifmam_addrs
= info
.rti_addrs
;
1194 route_proto
.sp_protocol
= ifma
->ifma_addr
->sa_family
;
1195 raw_input(m
, &route_proto
, &route_src
, &route_dst
);
1199 * This is used in dumping the kernel table via sysctl().
1202 sysctl_dumpentry(struct radix_node
*rn
, void *vw
)
1204 struct walkarg
*w
= vw
;
1205 struct rtentry
*rt
= (struct rtentry
*)rn
;
1206 int error
= 0, size
;
1207 struct rt_addrinfo info
;
1210 if (w
->w_op
== NET_RT_FLAGS
&& !(rt
->rt_flags
& w
->w_arg
)) {
1214 bzero((caddr_t
)&info
, sizeof(info
));
1216 gate
= rt
->rt_gateway
;
1217 netmask
= rt_mask(rt
);
1218 genmask
= rt
->rt_genmask
;
1219 if (w
->w_op
!= NET_RT_DUMP2
) {
1220 size
= rt_msg2(RTM_GET
, &info
, 0, w
);
1221 if (w
->w_req
&& w
->w_tmem
) {
1222 struct rt_msghdr
*rtm
= (struct rt_msghdr
*)w
->w_tmem
;
1224 rtm
->rtm_flags
= rt
->rt_flags
;
1225 rtm
->rtm_use
= rt
->rt_use
;
1226 rtm
->rtm_rmx
= rt
->rt_rmx
;
1227 rtm
->rtm_index
= rt
->rt_ifp
->if_index
;
1231 rtm
->rtm_addrs
= info
.rti_addrs
;
1232 error
= SYSCTL_OUT(w
->w_req
, (caddr_t
)rtm
, size
);
1237 size
= rt_msg2(RTM_GET2
, &info
, 0, w
);
1238 if (w
->w_req
&& w
->w_tmem
) {
1239 struct rt_msghdr2
*rtm
= (struct rt_msghdr2
*)w
->w_tmem
;
1241 rtm
->rtm_flags
= rt
->rt_flags
;
1242 rtm
->rtm_use
= rt
->rt_use
;
1243 rtm
->rtm_rmx
= rt
->rt_rmx
;
1244 rtm
->rtm_index
= rt
->rt_ifp
->if_index
;
1245 rtm
->rtm_refcnt
= rt
->rt_refcnt
;
1247 rtm
->rtm_parentflags
= rt
->rt_parent
->rt_flags
;
1249 rtm
->rtm_parentflags
= 0;
1250 rtm
->rtm_reserved
= 0;
1251 rtm
->rtm_addrs
= info
.rti_addrs
;
1252 error
= SYSCTL_OUT(w
->w_req
, (caddr_t
)rtm
, size
);
1269 struct rt_addrinfo info
;
1272 bzero((caddr_t
)&info
, sizeof(info
));
1273 ifnet_head_lock_shared();
1274 TAILQ_FOREACH(ifp
, &ifnet_head
, if_link
) {
1277 if (w
->w_arg
&& w
->w_arg
!= ifp
->if_index
)
1279 ifnet_lock_shared(ifp
);
1280 ifa
= ifp
->if_addrhead
.tqh_first
;
1281 ifpaddr
= ifa
->ifa_addr
;
1282 len
= rt_msg2(RTM_IFINFO
, &info
, (caddr_t
)0, w
);
1284 if (w
->w_req
&& w
->w_tmem
) {
1285 struct if_msghdr
*ifm
;
1287 ifm
= (struct if_msghdr
*)w
->w_tmem
;
1288 ifm
->ifm_index
= ifp
->if_index
;
1289 ifm
->ifm_flags
= (u_short
)ifp
->if_flags
;
1290 if_data_internal_to_if_data(ifp
, &ifp
->if_data
, &ifm
->ifm_data
);
1291 ifm
->ifm_addrs
= info
.rti_addrs
;
1292 error
= SYSCTL_OUT(w
->w_req
,(caddr_t
)ifm
, len
);
1294 ifnet_lock_done(ifp
);
1298 while ((ifa
= ifa
->ifa_link
.tqe_next
) != 0) {
1299 if (af
&& af
!= ifa
->ifa_addr
->sa_family
)
1301 ifaaddr
= ifa
->ifa_addr
;
1302 netmask
= ifa
->ifa_netmask
;
1303 brdaddr
= ifa
->ifa_dstaddr
;
1304 len
= rt_msg2(RTM_NEWADDR
, &info
, 0, w
);
1305 if (w
->w_req
&& w
->w_tmem
) {
1306 struct ifa_msghdr
*ifam
;
1308 ifam
= (struct ifa_msghdr
*)w
->w_tmem
;
1309 ifam
->ifam_index
= ifa
->ifa_ifp
->if_index
;
1310 ifam
->ifam_flags
= ifa
->ifa_flags
;
1311 ifam
->ifam_metric
= ifa
->ifa_metric
;
1312 ifam
->ifam_addrs
= info
.rti_addrs
;
1313 error
= SYSCTL_OUT(w
->w_req
, w
->w_tmem
, len
);
1318 ifnet_lock_done(ifp
);
1319 ifaaddr
= netmask
= brdaddr
= 0;
1332 struct rt_addrinfo info
;
1335 bzero((caddr_t
)&info
, sizeof(info
));
1336 ifnet_head_lock_shared();
1337 TAILQ_FOREACH(ifp
, &ifnet_head
, if_link
) {
1340 if (w
->w_arg
&& w
->w_arg
!= ifp
->if_index
)
1342 ifnet_lock_shared(ifp
);
1343 ifa
= ifp
->if_addrhead
.tqh_first
;
1344 ifpaddr
= ifa
->ifa_addr
;
1345 len
= rt_msg2(RTM_IFINFO2
, &info
, (caddr_t
)0, w
);
1347 if (w
->w_req
&& w
->w_tmem
) {
1348 struct if_msghdr2
*ifm
;
1350 ifm
= (struct if_msghdr2
*)w
->w_tmem
;
1351 ifm
->ifm_addrs
= info
.rti_addrs
;
1352 ifm
->ifm_flags
= (u_short
)ifp
->if_flags
;
1353 ifm
->ifm_index
= ifp
->if_index
;
1354 ifm
->ifm_snd_len
= ifp
->if_snd
.ifq_len
;
1355 ifm
->ifm_snd_maxlen
= ifp
->if_snd
.ifq_maxlen
;
1356 ifm
->ifm_snd_drops
= ifp
->if_snd
.ifq_drops
;
1357 ifm
->ifm_timer
= ifp
->if_timer
;
1358 if_data_internal_to_if_data64(ifp
, &ifp
->if_data
, &ifm
->ifm_data
);
1359 error
= SYSCTL_OUT(w
->w_req
, w
->w_tmem
, len
);
1361 ifnet_lock_done(ifp
);
1365 while ((ifa
= ifa
->ifa_link
.tqe_next
) != 0) {
1366 if (af
&& af
!= ifa
->ifa_addr
->sa_family
)
1368 ifaaddr
= ifa
->ifa_addr
;
1369 netmask
= ifa
->ifa_netmask
;
1370 brdaddr
= ifa
->ifa_dstaddr
;
1371 len
= rt_msg2(RTM_NEWADDR
, &info
, 0, w
);
1372 if (w
->w_req
&& w
->w_tmem
) {
1373 struct ifa_msghdr
*ifam
;
1375 ifam
= (struct ifa_msghdr
*)w
->w_tmem
;
1376 ifam
->ifam_index
= ifa
->ifa_ifp
->if_index
;
1377 ifam
->ifam_flags
= ifa
->ifa_flags
;
1378 ifam
->ifam_metric
= ifa
->ifa_metric
;
1379 ifam
->ifam_addrs
= info
.rti_addrs
;
1380 error
= SYSCTL_OUT(w
->w_req
, w
->w_tmem
, len
);
1386 ifnet_lock_done(ifp
);
1390 struct ifmultiaddr
*ifma
;
1392 for (ifma
= ifp
->if_multiaddrs
.lh_first
; ifma
;
1393 ifma
= ifma
->ifma_link
.le_next
) {
1394 if (af
&& af
!= ifma
->ifma_addr
->sa_family
)
1396 bzero((caddr_t
)&info
, sizeof(info
));
1397 ifaaddr
= ifma
->ifma_addr
;
1398 if (ifp
->if_addrhead
.tqh_first
)
1399 ifpaddr
= ifp
->if_addrhead
.tqh_first
->ifa_addr
;
1401 gate
= ifma
->ifma_ll
->ifma_addr
;
1402 len
= rt_msg2(RTM_NEWMADDR2
, &info
, 0, w
);
1403 if (w
->w_req
&& w
->w_tmem
) {
1404 struct ifma_msghdr2
*ifmam
;
1406 ifmam
= (struct ifma_msghdr2
*)w
->w_tmem
;
1407 ifmam
->ifmam_addrs
= info
.rti_addrs
;
1408 ifmam
->ifmam_flags
= 0;
1409 ifmam
->ifmam_index
= ifma
->ifma_ifp
->if_index
;
1410 ifmam
->ifmam_refcount
= ifma
->ifma_refcount
;
1411 error
= SYSCTL_OUT(w
->w_req
, w
->w_tmem
, len
);
1417 ifnet_lock_done(ifp
);
1418 ifaaddr
= netmask
= brdaddr
= 0;
1426 sysctl_rtstat(struct sysctl_req
*req
)
1430 error
= SYSCTL_OUT(req
, &rtstat
, sizeof(struct rtstat
));
1438 sysctl_rttrash(struct sysctl_req
*req
)
1442 error
= SYSCTL_OUT(req
, &rttrash
, sizeof(rttrash
));
1451 sysctl_rtsock SYSCTL_HANDLER_ARGS
1453 #pragma unused(oidp)
1454 int *name
= (int *)arg1
;
1455 u_int namelen
= arg2
;
1456 struct radix_node_head
*rnh
;
1457 int i
, error
= EINVAL
;
1468 Bzero(&w
, sizeof(w
));
1478 lck_mtx_lock(rnh_lock
);
1479 for (i
= 1; i
<= AF_MAX
; i
++)
1480 if ((rnh
= rt_tables
[i
]) && (af
== 0 || af
== i
) &&
1481 (error
= rnh
->rnh_walktree(rnh
,
1482 sysctl_dumpentry
, &w
)))
1484 lck_mtx_unlock(rnh_lock
);
1487 error
= sysctl_iflist(af
, &w
);
1489 case NET_RT_IFLIST2
:
1490 error
= sysctl_iflist2(af
, &w
);
1493 error
= sysctl_rtstat(req
);
1496 error
= sysctl_rttrash(req
);
1500 FREE(w
.w_tmem
, M_RTABLE
);
1504 SYSCTL_NODE(_net
, PF_ROUTE
, routetable
, CTLFLAG_RD
, sysctl_rtsock
, "");
1507 * Definitions of protocols supported in the ROUTE domain.
1510 extern struct domain routedomain
; /* or at least forward */
1512 static struct protosw routesw
[] = {
1513 { SOCK_RAW
, &routedomain
, 0, PR_ATOMIC
|PR_ADDR
,
1514 0, route_output
, raw_ctlinput
, 0,
1524 struct domain routedomain
=
1525 { PF_ROUTE
, "route", route_init
, 0, 0,
1527 NULL
, NULL
, 0, 0, 0, 0, NULL
, 0,