1*79b06451Sthorpej /* $NetBSD: rtsock_50.c,v 1.16 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_50.c,v 1.16 2020/01/29 05:47:12 thorpej Exp $");
65461a86f9Schristos
66d91f98a8Spgoyette #define COMPAT_RTSOCK /* Use the COMPATNAME/COMPATCALL macros and the
67d91f98a8Spgoyette * various other compat definitions - see
68d91f98a8Spgoyette * sys/net/rtsock_shared.c for details
69cd4e50d8Smaxv */
70cd4e50d8Smaxv
71d91f98a8Spgoyette #include <net/rtsock_shared.c>
72d91f98a8Spgoyette #include <compat/net/route_50.h>
73461a86f9Schristos
7462266216Smsaitoh static struct sysctllog *clog;
75c166c1c6Spgoyette
76461a86f9Schristos void
compat_50_rt_oifmsg(struct ifnet * ifp)774d5d6d9aSmatt compat_50_rt_oifmsg(struct ifnet *ifp)
78461a86f9Schristos {
79461a86f9Schristos struct if_msghdr50 oifm;
80*79b06451Sthorpej struct if_data ifi;
81461a86f9Schristos struct mbuf *m;
82461a86f9Schristos struct rt_addrinfo info;
83461a86f9Schristos
844d5d6d9aSmatt if (COMPATNAME(route_info).ri_cb.any_count == 0)
85461a86f9Schristos return;
86461a86f9Schristos (void)memset(&info, 0, sizeof(info));
87461a86f9Schristos (void)memset(&oifm, 0, sizeof(oifm));
88*79b06451Sthorpej if_export_if_data(ifp, &ifi, false);
89461a86f9Schristos oifm.ifm_index = ifp->if_index;
90461a86f9Schristos oifm.ifm_flags = ifp->if_flags;
91*79b06451Sthorpej oifm.ifm_data.ifi_type = ifi.ifi_type;
92*79b06451Sthorpej oifm.ifm_data.ifi_addrlen = ifi.ifi_addrlen;
93*79b06451Sthorpej oifm.ifm_data.ifi_hdrlen = ifi.ifi_hdrlen;
94*79b06451Sthorpej oifm.ifm_data.ifi_link_state = ifi.ifi_link_state;
95*79b06451Sthorpej oifm.ifm_data.ifi_mtu = ifi.ifi_mtu;
96*79b06451Sthorpej oifm.ifm_data.ifi_metric = ifi.ifi_metric;
97*79b06451Sthorpej oifm.ifm_data.ifi_baudrate = ifi.ifi_baudrate;
98*79b06451Sthorpej oifm.ifm_data.ifi_ipackets = ifi.ifi_ipackets;
99*79b06451Sthorpej oifm.ifm_data.ifi_ierrors = ifi.ifi_ierrors;
100*79b06451Sthorpej oifm.ifm_data.ifi_opackets = ifi.ifi_opackets;
101*79b06451Sthorpej oifm.ifm_data.ifi_oerrors = ifi.ifi_oerrors;
102*79b06451Sthorpej oifm.ifm_data.ifi_collisions = ifi.ifi_collisions;
103*79b06451Sthorpej oifm.ifm_data.ifi_ibytes = ifi.ifi_ibytes;
104*79b06451Sthorpej oifm.ifm_data.ifi_obytes = ifi.ifi_obytes;
105*79b06451Sthorpej oifm.ifm_data.ifi_imcasts = ifi.ifi_imcasts;
106*79b06451Sthorpej oifm.ifm_data.ifi_omcasts = ifi.ifi_omcasts;
107*79b06451Sthorpej oifm.ifm_data.ifi_iqdrops = ifi.ifi_iqdrops;
108*79b06451Sthorpej oifm.ifm_data.ifi_noproto = ifi.ifi_noproto;
109461a86f9Schristos TIMESPEC_TO_TIMEVAL(&oifm.ifm_data.ifi_lastchange,
110*79b06451Sthorpej &ifi.ifi_lastchange);
111461a86f9Schristos oifm.ifm_addrs = 0;
1124d5d6d9aSmatt m = COMPATNAME(rt_msg1)(RTM_OIFINFO, &info, (void *)&oifm, sizeof(oifm));
113461a86f9Schristos if (m == NULL)
114461a86f9Schristos return;
1154d5d6d9aSmatt COMPATNAME(route_enqueue)(m, 0);
116461a86f9Schristos }
117461a86f9Schristos
118461a86f9Schristos int
compat_50_iflist(struct ifnet * ifp,struct rt_walkarg * w,struct rt_addrinfo * info,size_t len)119461a86f9Schristos compat_50_iflist(struct ifnet *ifp, struct rt_walkarg *w,
120461a86f9Schristos struct rt_addrinfo *info, size_t len)
121461a86f9Schristos {
122461a86f9Schristos struct if_msghdr50 *ifm;
123*79b06451Sthorpej struct if_data ifi;
124461a86f9Schristos int error;
125461a86f9Schristos
126461a86f9Schristos ifm = (struct if_msghdr50 *)w->w_tmem;
127*79b06451Sthorpej if_export_if_data(ifp, &ifi, false);
128461a86f9Schristos ifm->ifm_index = ifp->if_index;
129461a86f9Schristos ifm->ifm_flags = ifp->if_flags;
130*79b06451Sthorpej ifm->ifm_data.ifi_type = ifi.ifi_type;
131*79b06451Sthorpej ifm->ifm_data.ifi_addrlen = ifi.ifi_addrlen;
132*79b06451Sthorpej ifm->ifm_data.ifi_hdrlen = ifi.ifi_hdrlen;
133*79b06451Sthorpej ifm->ifm_data.ifi_link_state = ifi.ifi_link_state;
134*79b06451Sthorpej ifm->ifm_data.ifi_mtu = ifi.ifi_mtu;
135*79b06451Sthorpej ifm->ifm_data.ifi_metric = ifi.ifi_metric;
136*79b06451Sthorpej ifm->ifm_data.ifi_baudrate = ifi.ifi_baudrate;
137*79b06451Sthorpej ifm->ifm_data.ifi_ipackets = ifi.ifi_ipackets;
138*79b06451Sthorpej ifm->ifm_data.ifi_ierrors = ifi.ifi_ierrors;
139*79b06451Sthorpej ifm->ifm_data.ifi_opackets = ifi.ifi_opackets;
140*79b06451Sthorpej ifm->ifm_data.ifi_oerrors = ifi.ifi_oerrors;
141*79b06451Sthorpej ifm->ifm_data.ifi_collisions = ifi.ifi_collisions;
142*79b06451Sthorpej ifm->ifm_data.ifi_ibytes = ifi.ifi_ibytes;
143*79b06451Sthorpej ifm->ifm_data.ifi_obytes = ifi.ifi_obytes;
144*79b06451Sthorpej ifm->ifm_data.ifi_imcasts = ifi.ifi_imcasts;
145*79b06451Sthorpej ifm->ifm_data.ifi_omcasts = ifi.ifi_omcasts;
146*79b06451Sthorpej ifm->ifm_data.ifi_iqdrops = ifi.ifi_iqdrops;
147*79b06451Sthorpej ifm->ifm_data.ifi_noproto = ifi.ifi_noproto;
148461a86f9Schristos TIMESPEC_TO_TIMEVAL(&ifm->ifm_data.ifi_lastchange,
149*79b06451Sthorpej &ifi.ifi_lastchange);
150461a86f9Schristos ifm->ifm_addrs = info->rti_addrs;
151461a86f9Schristos error = copyout(ifm, w->w_where, len);
152461a86f9Schristos if (error)
153461a86f9Schristos return error;
154461a86f9Schristos w->w_where = (char *)w->w_where + len;
155461a86f9Schristos return 0;
156461a86f9Schristos }
157d91f98a8Spgoyette
158d91f98a8Spgoyette void
rtsock_50_init(void)159d91f98a8Spgoyette rtsock_50_init(void)
160d91f98a8Spgoyette {
161d91f98a8Spgoyette
1628a031a1dSpgoyette MODULE_HOOK_SET(rtsock_iflist_50_hook, compat_50_iflist);
1638a031a1dSpgoyette MODULE_HOOK_SET(rtsock_oifmsg_50_hook, compat_50_rt_oifmsg);
1648a031a1dSpgoyette MODULE_HOOK_SET(rtsock_rt_missmsg_50_hook, compat_50_rt_missmsg);
1658a031a1dSpgoyette MODULE_HOOK_SET(rtsock_rt_ifmsg_50_hook, compat_50_rt_ifmsg);
1668a031a1dSpgoyette MODULE_HOOK_SET(rtsock_rt_addrmsg_rt_50_hook, compat_50_rt_addrmsg_rt);
1678a031a1dSpgoyette MODULE_HOOK_SET(rtsock_rt_addrmsg_src_50_hook,
1682e9156b7Sroy compat_50_rt_addrmsg_src);
1698a031a1dSpgoyette MODULE_HOOK_SET(rtsock_rt_addrmsg_50_hook, compat_50_rt_addrmsg);
1708a031a1dSpgoyette MODULE_HOOK_SET(rtsock_rt_ifannouncemsg_50_hook,
171d91f98a8Spgoyette compat_50_rt_ifannouncemsg);
1728a031a1dSpgoyette MODULE_HOOK_SET(rtsock_rt_ieee80211msg_50_hook,
173d91f98a8Spgoyette compat_50_rt_ieee80211msg);
174c166c1c6Spgoyette sysctl_net_route_setup(&clog, PF_OROUTE, "ortable");
175d91f98a8Spgoyette }
176d91f98a8Spgoyette
177d91f98a8Spgoyette void
rtsock_50_fini(void)178d91f98a8Spgoyette rtsock_50_fini(void)
179d91f98a8Spgoyette {
180d91f98a8Spgoyette
181c166c1c6Spgoyette sysctl_teardown(&clog);
1828c2f80f1Spgoyette MODULE_HOOK_UNSET(rtsock_iflist_50_hook);
1838c2f80f1Spgoyette MODULE_HOOK_UNSET(rtsock_oifmsg_50_hook);
1848c2f80f1Spgoyette MODULE_HOOK_UNSET(rtsock_rt_missmsg_50_hook);
1858c2f80f1Spgoyette MODULE_HOOK_UNSET(rtsock_rt_ifmsg_50_hook);
1864af7afb8Sroy MODULE_HOOK_UNSET(rtsock_rt_addrmsg_rt_50_hook);
1872e9156b7Sroy MODULE_HOOK_UNSET(rtsock_rt_addrmsg_src_50_hook);
1884af7afb8Sroy MODULE_HOOK_UNSET(rtsock_rt_addrmsg_50_hook);
1898c2f80f1Spgoyette MODULE_HOOK_UNSET(rtsock_rt_ifannouncemsg_50_hook);
1908c2f80f1Spgoyette MODULE_HOOK_UNSET(rtsock_rt_ieee80211msg_50_hook);
191d91f98a8Spgoyette }
192