rtsock_70.c revision 1.2 1 /* $NetBSD: rtsock_70.c,v 1.2 2017/12/16 09:10:30 maxv 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.2 2017/12/16 09:10:30 maxv 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 void
47 compat_70_rt_newaddrmsg1(int cmd, struct ifaddr *ifa)
48 {
49 struct rt_addrinfo info;
50 const struct sockaddr *sa;
51 struct mbuf *m;
52 struct ifnet *ifp;
53 struct ifa_msghdr70 ifam;
54 int ncmd;
55
56 KASSERT(ifa != NULL);
57 ifp = ifa->ifa_ifp;
58
59 switch (cmd) {
60 case RTM_NEWADDR:
61 ncmd = RTM_ONEWADDR;
62 break;
63 case RTM_DELADDR:
64 ncmd = RTM_ODELADDR;
65 break;
66 case RTM_CHGADDR:
67 ncmd = RTM_OCHGADDR;
68 break;
69 default:
70 panic("%s: called with wrong command", __func__);
71 }
72
73 memset(&info, 0, sizeof(info));
74 info.rti_info[RTAX_IFA] = sa = ifa->ifa_addr;
75 KASSERT(ifp->if_dl != NULL);
76 info.rti_info[RTAX_IFP] = ifp->if_dl->ifa_addr;
77 info.rti_info[RTAX_NETMASK] = ifa->ifa_netmask;
78 info.rti_info[RTAX_BRD] = ifa->ifa_dstaddr;
79
80 memset(&ifam, 0, sizeof(ifam));
81 ifam.ifam_index = ifp->if_index;
82 ifam.ifam_metric = ifa->ifa_metric;
83 ifam.ifam_flags = ifa->ifa_flags;
84
85 m = rt_msg1(ncmd, &info, &ifam, sizeof(ifam));
86 if (m == NULL)
87 return;
88
89 mtod(m, struct ifa_msghdr70 *)->ifam_addrs = info.rti_addrs;
90 route_enqueue(m, sa ? sa->sa_family : 0);
91 }
92
93 int
94 compat_70_iflist_addr(struct rt_walkarg *w, struct ifaddr *ifa,
95 struct rt_addrinfo *info)
96 {
97 int len, error;
98
99 if ((error = rt_msg3(RTM_ONEWADDR, info, 0, w, &len)))
100 return error;
101 if (w->w_where && w->w_tmem && w->w_needed <= 0) {
102 struct ifa_msghdr70 *ifam;
103
104 ifam = (struct ifa_msghdr70 *)w->w_tmem;
105 ifam->ifam_index = ifa->ifa_ifp->if_index;
106 ifam->ifam_flags = ifa->ifa_flags;
107 ifam->ifam_metric = ifa->ifa_metric;
108 ifam->ifam_addrs = info->rti_addrs;
109 if ((error = copyout(w->w_tmem, w->w_where, len)) == 0)
110 w->w_where = (char *)w->w_where + len;
111 }
112 return error;
113 }
114