1 /* $KAME: rtsock.c,v 1.3 2000/10/10 08:46:45 itojun Exp $ */
2 /* $FreeBSD: src/usr.sbin/rtsold/rtsock.c,v 1.1.2.1 2001/07/03 11:02:16 ume Exp $ */
3 /* $DragonFly: src/usr.sbin/rtsold/rtsock.c,v 1.6 2005/12/05 00:56:37 swildner Exp $ */
6 * Copyright (C) 2000 WIDE Project.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/param.h>
35 #include <sys/socket.h>
38 #include <sys/queue.h>
41 #include <net/route.h>
42 #include <net/if_dl.h>
44 #include <netinet/in.h>
45 #include <netinet/ip6.h>
46 #include <netinet/icmp6.h>
59 #ifdef RTM_IFANNOUNCE /*NetBSD 1.5 or later*/
60 static int rtsock_input_ifannounce(int, struct rt_msghdr
*, char *);
66 int (*func
)(int, struct rt_msghdr
*, char *);
67 } rtsock_dispatch
[] = {
68 #ifdef RTM_IFANNOUNCE /*NetBSD 1.5 or later*/
69 { RTM_IFANNOUNCE
, sizeof(struct if_announcemsghdr
),
70 rtsock_input_ifannounce
},
79 return socket(PF_ROUTE
, SOCK_RAW
, 0);
88 struct rt_msghdr
*rtm
;
92 const ssize_t lenlim
=
93 offsetof(struct rt_msghdr
, rtm_msglen
) + sizeof(rtm
->rtm_msglen
);
95 n
= read(s
, msg
, sizeof(msg
));
98 for (next
= msg
; next
< lim
; next
+= len
) {
99 rtm
= (struct rt_msghdr
*)next
;
100 if (lim
- next
< lenlim
)
102 len
= rtm
->rtm_msglen
;
107 warnmsg(LOG_INFO
, __func__
,
108 "rtmsg type %d, len=%lu", rtm
->rtm_type
,
112 for (idx
= 0; rtsock_dispatch
[idx
].func
; idx
++) {
113 if (rtm
->rtm_type
!= rtsock_dispatch
[idx
].type
)
115 if (rtm
->rtm_msglen
< rtsock_dispatch
[idx
].minlen
) {
116 warnmsg(LOG_INFO
, __func__
,
117 "rtmsg type %d too short!", rtm
->rtm_type
);
121 ret
= (*rtsock_dispatch
[idx
].func
)(s
, rtm
, lim
);
129 #ifdef RTM_IFANNOUNCE /*NetBSD 1.5 or later*/
131 rtsock_input_ifannounce(int s __unused
, struct rt_msghdr
*rtm
, char *lim
)
133 struct if_announcemsghdr
*ifan
;
134 struct ifinfo
*ifinfo
;
136 ifan
= (struct if_announcemsghdr
*)rtm
;
137 if ((char *)(ifan
+ 1) > lim
)
140 switch (ifan
->ifan_what
) {
143 * XXX for NetBSD 1.5, interface index will monotonically be
144 * increased as new pcmcia card gets inserted.
145 * we may be able to do a name-based interface match,
146 * and call ifreconfig() to enable the interface again.
148 warnmsg(LOG_INFO
, __func__
,
149 "interface %s inserted", ifan
->ifan_name
);
152 warnmsg(LOG_WARNING
, __func__
,
153 "interface %s removed", ifan
->ifan_name
);
154 ifinfo
= find_ifinfo(ifan
->ifan_index
);
157 warnmsg(LOG_INFO
, __func__
,
158 "bring interface %s to DOWN state",
161 ifinfo
->state
= IFS_DOWN
;