1*79b06451Sthorpej /* $NetBSD: rtsock_14.c,v 1.10 2020/01/29 05:47:12 thorpej Exp $ */
2461a86f9Schristos
3461a86f9Schristos /*
4461a86f9Schristos * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5461a86f9Schristos * All rights reserved.
6461a86f9Schristos *
7461a86f9Schristos * Redistribution and use in source and binary forms, with or without
8461a86f9Schristos * modification, are permitted provided that the following conditions
9461a86f9Schristos * are met:
10461a86f9Schristos * 1. Redistributions of source code must retain the above copyright
11461a86f9Schristos * notice, this list of conditions and the following disclaimer.
12461a86f9Schristos * 2. Redistributions in binary form must reproduce the above copyright
13461a86f9Schristos * notice, this list of conditions and the following disclaimer in the
14461a86f9Schristos * documentation and/or other materials provided with the distribution.
15461a86f9Schristos * 3. Neither the name of the project nor the names of its contributors
16461a86f9Schristos * may be used to endorse or promote products derived from this software
17461a86f9Schristos * without specific prior written permission.
18461a86f9Schristos *
19461a86f9Schristos * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20461a86f9Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21461a86f9Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22461a86f9Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23461a86f9Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24461a86f9Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25461a86f9Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26461a86f9Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27461a86f9Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28461a86f9Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29461a86f9Schristos * SUCH DAMAGE.
30461a86f9Schristos */
31461a86f9Schristos
32461a86f9Schristos /*
33461a86f9Schristos * Copyright (c) 1988, 1991, 1993
34461a86f9Schristos * The Regents of the University of California. All rights reserved.
35461a86f9Schristos *
36461a86f9Schristos * Redistribution and use in source and binary forms, with or without
37461a86f9Schristos * modification, are permitted provided that the following conditions
38461a86f9Schristos * are met:
39461a86f9Schristos * 1. Redistributions of source code must retain the above copyright
40461a86f9Schristos * notice, this list of conditions and the following disclaimer.
41461a86f9Schristos * 2. Redistributions in binary form must reproduce the above copyright
42461a86f9Schristos * notice, this list of conditions and the following disclaimer in the
43461a86f9Schristos * documentation and/or other materials provided with the distribution.
44461a86f9Schristos * 3. Neither the name of the University nor the names of its contributors
45461a86f9Schristos * may be used to endorse or promote products derived from this software
46461a86f9Schristos * without specific prior written permission.
47461a86f9Schristos *
48461a86f9Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49461a86f9Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50461a86f9Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51461a86f9Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52461a86f9Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53461a86f9Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54461a86f9Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55461a86f9Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56461a86f9Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57461a86f9Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58461a86f9Schristos * SUCH DAMAGE.
59461a86f9Schristos *
60461a86f9Schristos * @(#)rtsock.c 8.7 (Berkeley) 10/12/95
61461a86f9Schristos */
62461a86f9Schristos
63461a86f9Schristos #include <sys/cdefs.h>
64*79b06451Sthorpej __KERNEL_RCSID(0, "$NetBSD: rtsock_14.c,v 1.10 2020/01/29 05:47:12 thorpej Exp $");
65d91f98a8Spgoyette
66d91f98a8Spgoyette #if defined(_KERNEL_OPT)
67d91f98a8Spgoyette #include "opt_compat_netbsd.h"
68d91f98a8Spgoyette #endif
69461a86f9Schristos
7000d7b5f1Sriastradh #ifdef _KERNEL_OPT
71461a86f9Schristos #include "opt_inet.h"
7200d7b5f1Sriastradh #endif
73461a86f9Schristos
74461a86f9Schristos #include <sys/param.h>
75461a86f9Schristos #include <sys/systm.h>
76461a86f9Schristos #include <sys/proc.h>
77461a86f9Schristos #include <sys/mbuf.h>
78461a86f9Schristos #include <sys/socket.h>
79461a86f9Schristos #include <sys/socketvar.h>
80461a86f9Schristos #include <sys/domain.h>
81461a86f9Schristos #include <sys/protosw.h>
82461a86f9Schristos #include <sys/sysctl.h>
83461a86f9Schristos #include <sys/kauth.h>
84d91f98a8Spgoyette #include <sys/compat_stub.h>
85461a86f9Schristos #ifdef RTSOCK_DEBUG
86461a86f9Schristos #include <netinet/in.h>
87461a86f9Schristos #endif /* RTSOCK_DEBUG */
88461a86f9Schristos
89461a86f9Schristos #include <net/if.h>
90461a86f9Schristos #include <net/route.h>
91461a86f9Schristos #include <net/raw_cb.h>
92461a86f9Schristos
93461a86f9Schristos #include <compat/net/if.h>
944d5d6d9aSmatt #include <compat/net/route.h>
95461a86f9Schristos
96d91f98a8Spgoyette #include <compat/common/compat_mod.h>
97d91f98a8Spgoyette
98461a86f9Schristos void
compat_14_rt_oifmsg(struct ifnet * ifp)994d5d6d9aSmatt compat_14_rt_oifmsg(struct ifnet *ifp)
100461a86f9Schristos {
101461a86f9Schristos struct if_msghdr14 oifm;
102*79b06451Sthorpej struct if_data ifi;
103461a86f9Schristos struct mbuf *m;
104461a86f9Schristos struct rt_addrinfo info;
105461a86f9Schristos struct timeval tv;
106461a86f9Schristos
1074d5d6d9aSmatt if (compat_50_route_info.ri_cb.any_count == 0)
108461a86f9Schristos return;
109461a86f9Schristos (void)memset(&info, 0, sizeof(info));
110461a86f9Schristos (void)memset(&oifm, 0, sizeof(oifm));
111*79b06451Sthorpej if_export_if_data(ifp, &ifi, false);
112461a86f9Schristos oifm.ifm_index = ifp->if_index;
113461a86f9Schristos oifm.ifm_flags = ifp->if_flags;
114*79b06451Sthorpej oifm.ifm_data.ifi_type = ifi.ifi_type;
115*79b06451Sthorpej oifm.ifm_data.ifi_addrlen = ifi.ifi_addrlen;
116*79b06451Sthorpej oifm.ifm_data.ifi_hdrlen = ifi.ifi_hdrlen;
117*79b06451Sthorpej oifm.ifm_data.ifi_mtu = ifi.ifi_mtu;
118*79b06451Sthorpej oifm.ifm_data.ifi_metric = ifi.ifi_metric;
119*79b06451Sthorpej oifm.ifm_data.ifi_baudrate = ifi.ifi_baudrate;
120*79b06451Sthorpej oifm.ifm_data.ifi_ipackets = ifi.ifi_ipackets;
121*79b06451Sthorpej oifm.ifm_data.ifi_ierrors = ifi.ifi_ierrors;
122*79b06451Sthorpej oifm.ifm_data.ifi_opackets = ifi.ifi_opackets;
123*79b06451Sthorpej oifm.ifm_data.ifi_oerrors = ifi.ifi_oerrors;
124*79b06451Sthorpej oifm.ifm_data.ifi_collisions = ifi.ifi_collisions;
125*79b06451Sthorpej oifm.ifm_data.ifi_ibytes = ifi.ifi_ibytes;
126*79b06451Sthorpej oifm.ifm_data.ifi_obytes = ifi.ifi_obytes;
127*79b06451Sthorpej oifm.ifm_data.ifi_imcasts = ifi.ifi_imcasts;
128*79b06451Sthorpej oifm.ifm_data.ifi_omcasts = ifi.ifi_omcasts;
129*79b06451Sthorpej oifm.ifm_data.ifi_iqdrops = ifi.ifi_iqdrops;
130*79b06451Sthorpej oifm.ifm_data.ifi_noproto = ifi.ifi_noproto;
131*79b06451Sthorpej TIMESPEC_TO_TIMEVAL(&tv, &ifi.ifi_lastchange);
132461a86f9Schristos timeval_to_timeval50(&tv, &oifm.ifm_data.ifi_lastchange);
133461a86f9Schristos oifm.ifm_addrs = 0;
1344d5d6d9aSmatt m = compat_50_rt_msg1(RTM_OOIFINFO, &info, (void *)&oifm, sizeof(oifm));
135461a86f9Schristos if (m == NULL)
136461a86f9Schristos return;
1374d5d6d9aSmatt compat_50_route_enqueue(m, 0);
138461a86f9Schristos }
139461a86f9Schristos
140461a86f9Schristos int
compat_14_iflist(struct ifnet * ifp,struct rt_walkarg * w,struct rt_addrinfo * info,size_t len)141461a86f9Schristos compat_14_iflist(struct ifnet *ifp, struct rt_walkarg *w,
142461a86f9Schristos struct rt_addrinfo *info, size_t len)
143461a86f9Schristos {
144461a86f9Schristos struct if_msghdr14 *ifm;
145*79b06451Sthorpej struct if_data ifi;
146461a86f9Schristos struct timeval tv;
147461a86f9Schristos int error;
148461a86f9Schristos
149461a86f9Schristos ifm = (struct if_msghdr14 *)w->w_tmem;
150*79b06451Sthorpej if_export_if_data(ifp, &ifi, false);
151461a86f9Schristos ifm->ifm_index = ifp->if_index;
152461a86f9Schristos ifm->ifm_flags = ifp->if_flags;
153*79b06451Sthorpej ifm->ifm_data.ifi_type = ifi.ifi_type;
154*79b06451Sthorpej ifm->ifm_data.ifi_addrlen = ifi.ifi_addrlen;
155*79b06451Sthorpej ifm->ifm_data.ifi_hdrlen = ifi.ifi_hdrlen;
156*79b06451Sthorpej ifm->ifm_data.ifi_mtu = ifi.ifi_mtu;
157*79b06451Sthorpej ifm->ifm_data.ifi_metric = ifi.ifi_metric;
158*79b06451Sthorpej ifm->ifm_data.ifi_baudrate = ifi.ifi_baudrate;
159*79b06451Sthorpej ifm->ifm_data.ifi_ipackets = ifi.ifi_ipackets;
160*79b06451Sthorpej ifm->ifm_data.ifi_ierrors = ifi.ifi_ierrors;
161*79b06451Sthorpej ifm->ifm_data.ifi_opackets = ifi.ifi_opackets;
162*79b06451Sthorpej ifm->ifm_data.ifi_oerrors = ifi.ifi_oerrors;
163*79b06451Sthorpej ifm->ifm_data.ifi_collisions = ifi.ifi_collisions;
164*79b06451Sthorpej ifm->ifm_data.ifi_ibytes = ifi.ifi_ibytes;
165*79b06451Sthorpej ifm->ifm_data.ifi_obytes = ifi.ifi_obytes;
166*79b06451Sthorpej ifm->ifm_data.ifi_imcasts = ifi.ifi_imcasts;
167*79b06451Sthorpej ifm->ifm_data.ifi_omcasts = ifi.ifi_omcasts;
168*79b06451Sthorpej ifm->ifm_data.ifi_iqdrops = ifi.ifi_iqdrops;
169*79b06451Sthorpej ifm->ifm_data.ifi_noproto = ifi.ifi_noproto;
170*79b06451Sthorpej TIMESPEC_TO_TIMEVAL(&tv, &ifi.ifi_lastchange);
171461a86f9Schristos timeval_to_timeval50(&tv, &ifm->ifm_data.ifi_lastchange);
172461a86f9Schristos ifm->ifm_addrs = info->rti_addrs;
173461a86f9Schristos error = copyout(ifm, w->w_where, len);
174461a86f9Schristos if (error)
175461a86f9Schristos return error;
176461a86f9Schristos w->w_where = (char *)w->w_where + len;
177461a86f9Schristos return 0;
178461a86f9Schristos }
179d91f98a8Spgoyette
180d91f98a8Spgoyette void
rtsock_14_init(void)181d91f98a8Spgoyette rtsock_14_init(void)
182d91f98a8Spgoyette {
183d91f98a8Spgoyette
1848a031a1dSpgoyette MODULE_HOOK_SET(rtsock_oifmsg_14_hook, compat_14_rt_oifmsg);
1858a031a1dSpgoyette MODULE_HOOK_SET(rtsock_iflist_14_hook, compat_14_iflist);
186d91f98a8Spgoyette }
187d91f98a8Spgoyette
188d91f98a8Spgoyette void
rtsock_14_fini(void)189d91f98a8Spgoyette rtsock_14_fini(void)
190d91f98a8Spgoyette {
191d91f98a8Spgoyette
1928c2f80f1Spgoyette MODULE_HOOK_UNSET(rtsock_oifmsg_14_hook);
1938c2f80f1Spgoyette MODULE_HOOK_UNSET(rtsock_iflist_14_hook);
194d91f98a8Spgoyette }
195