1 | /* $NetBSD: rtsock_70.c,v 1.1 2016/09/21 10:50:23 roy Exp $ */ |
2 | |
3 | /* |
4 | * Copyright (c) 2016 The NetBSD Foundation, Inc. |
5 | * All rights reserved. |
6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Roy Marples. |
9 | * |
10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions |
12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. |
18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ |
31 | |
32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: rtsock_70.c,v 1.1 2016/09/21 10:50:23 roy Exp $" ); |
34 | |
35 | #ifdef _KERNEL_OPT |
36 | #include "opt_compat_netbsd.h" |
37 | #endif |
38 | |
39 | #include <sys/mbuf.h> |
40 | #include <net/if.h> |
41 | #include <net/route.h> |
42 | |
43 | #include <compat/net/if.h> |
44 | #include <compat/net/route.h> |
45 | |
46 | #if defined(COMPAT_70) |
47 | void |
48 | compat_70_rt_newaddrmsg1(int cmd, struct ifaddr *ifa) |
49 | { |
50 | struct rt_addrinfo info; |
51 | const struct sockaddr *sa; |
52 | struct mbuf *m; |
53 | struct ifnet *ifp; |
54 | struct ifa_msghdr70 ifam; |
55 | int ncmd; |
56 | |
57 | KASSERT(ifa != NULL); |
58 | ifp = ifa->ifa_ifp; |
59 | |
60 | switch (cmd) { |
61 | case RTM_NEWADDR: |
62 | ncmd = RTM_ONEWADDR; |
63 | break; |
64 | case RTM_DELADDR: |
65 | ncmd = RTM_ODELADDR; |
66 | break; |
67 | case RTM_CHGADDR: |
68 | ncmd = RTM_OCHGADDR; |
69 | break; |
70 | default: |
71 | panic("%s: called with wrong command" , __func__); |
72 | } |
73 | |
74 | memset(&info, 0, sizeof(info)); |
75 | info.rti_info[RTAX_IFA] = sa = ifa->ifa_addr; |
76 | KASSERT(ifp->if_dl != NULL); |
77 | info.rti_info[RTAX_IFP] = ifp->if_dl->ifa_addr; |
78 | info.rti_info[RTAX_NETMASK] = ifa->ifa_netmask; |
79 | info.rti_info[RTAX_BRD] = ifa->ifa_dstaddr; |
80 | |
81 | memset(&ifam, 0, sizeof(ifam)); |
82 | ifam.ifam_index = ifp->if_index; |
83 | ifam.ifam_metric = ifa->ifa_metric; |
84 | ifam.ifam_flags = ifa->ifa_flags; |
85 | |
86 | m = rt_msg1(ncmd, &info, &ifam, sizeof(ifam)); |
87 | if (m == NULL) |
88 | return; |
89 | |
90 | mtod(m, struct ifa_msghdr70 *)->ifam_addrs = info.rti_addrs; |
91 | route_enqueue(m, sa ? sa->sa_family : 0); |
92 | } |
93 | |
94 | int |
95 | compat_70_iflist_addr(struct rt_walkarg *w, struct ifaddr *ifa, |
96 | struct rt_addrinfo *info) |
97 | { |
98 | int len, error; |
99 | |
100 | if ((error = rt_msg3(RTM_ONEWADDR, info, 0, w, &len))) |
101 | return error; |
102 | if (w->w_where && w->w_tmem && w->w_needed <= 0) { |
103 | struct ifa_msghdr70 *ifam; |
104 | |
105 | ifam = (struct ifa_msghdr70 *)w->w_tmem; |
106 | ifam->ifam_index = ifa->ifa_ifp->if_index; |
107 | ifam->ifam_flags = ifa->ifa_flags; |
108 | ifam->ifam_metric = ifa->ifa_metric; |
109 | ifam->ifam_addrs = info->rti_addrs; |
110 | if ((error = copyout(w->w_tmem, w->w_where, len)) == 0) |
111 | w->w_where = (char *)w->w_where + len; |
112 | } |
113 | return error; |
114 | } |
115 | #endif /* COMPAT_70 */ |
116 | |