Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/pgoyette-compat]: src/sys/net First pass at extracting the "shared" comp...
details: https://anonhg.NetBSD.org/src/rev/1df35a1aaecf
branches: pgoyette-compat
changeset: 447525:1df35a1aaecf
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Tue Jan 15 01:16:42 2019 +0000
description:
First pass at extracting the "shared" compat code into its own source
file, rather than burying it in sys/net/rtsock.c and conditionalizing
various pieces.
XXX Not yet used - it will eventually be #include-d by sys/net/rtsock.c
XXX and compat/common/rtsock_50.c
diffstat:
sys/net/rtsock_shared.c | 1727 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 1727 insertions(+), 0 deletions(-)
diffs (truncated from 1731 to 300 lines):
diff -r 5f0c45b9c063 -r 1df35a1aaecf sys/net/rtsock_shared.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/net/rtsock_shared.c Tue Jan 15 01:16:42 2019 +0000
@@ -0,0 +1,1727 @@
+/* $NetBSD: rtsock_shared.c,v 1.1.2.1 2019/01/15 01:16:42 pgoyette Exp $ */
+
+/*
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1988, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)rtsock.c 8.7 (Berkeley) 10/12/95
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: rtsock_shared.c,v 1.1.2.1 2019/01/15 01:16:42 pgoyette Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_inet.h"
+#include "opt_mpls.h"
+#include "opt_compat_netbsd.h"
+#include "opt_sctp.h"
+#include "opt_net_mpsafe.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/domain.h>
+#include <sys/protosw.h>
+#include <sys/sysctl.h>
+#include <sys/kauth.h>
+#include <sys/kmem.h>
+#include <sys/intr.h>
+#include <sys/condvar.h>
+#include <sys/compat_stub.h>
+
+#include <net/if.h>
+#include <net/if_llatbl.h>
+#include <net/if_types.h>
+#include <net/route.h>
+#include <net/raw_cb.h>
+
+#include <netinet/in_var.h>
+#include <netinet/if_inarp.h>
+
+#include <netmpls/mpls.h>
+
+#ifdef SCTP
+extern void sctp_add_ip_address(struct ifaddr *);
+extern void sctp_delete_ip_address(struct ifaddr *);
+#endif
+
+#include <compat/net/if.h>
+#include <compat/net/route.h>
+
+#ifdef COMPAT_RTSOCK /* These belong in compat/common/rtsock_50.c */
+#define RTM_XVERSION RTM_OVERSION
+#define RTM_XNEWADDR RTM_ONEWADDR
+#define RTM_XDELADDR RTM_ODELADDR
+#define RTM_XCHGADDR RTM_OCHGADDR
+#define RT_XADVANCE(a,b) RT_OADVANCE(a,b)
+#define RT_XROUNDUP(n) RT_OROUNDUP(n)
+#define PF_XROUTE PF_OROUTE
+#define rt_xmsghdr rt_msghdr50
+#define if_xmsghdr if_msghdr /* if_msghdr50 is for RTM_OIFINFO */
+#define ifa_xmsghdr ifa_msghdr50
+#define if_xannouncemsghdr if_announcemsghdr50
+#define COMPATNAME(x) compat_50_ ## x
+#define DOMAINNAME "oroute"
+#define RTS_CTASSERT(x) __nothing
+CTASSERT(sizeof(struct ifa_xmsghdr) == 20);
+DOMAIN_DEFINE(compat_50_routedomain); /* forward declare and add to link set */
+#else /* COMPAT_RTSOCK */ /* These belong in net/rtsock.c */
+#define RTM_XVERSION RTM_VERSION
+#define RTM_XNEWADDR RTM_NEWADDR
+#define RTM_XDELADDR RTM_DELADDR
+#define RTM_XCHGADDR RTM_CHGADDR
+#define RT_XADVANCE(a,b) RT_ADVANCE(a,b)
+#define RT_XROUNDUP(n) RT_ROUNDUP(n)
+#define PF_XROUTE PF_ROUTE
+#define rt_xmsghdr rt_msghdr
+#define if_xmsghdr if_msghdr
+#define ifa_xmsghdr ifa_msghdr
+#define if_xannouncemsghdr if_announcemsghdr
+#define COMPATNAME(x) x
+#define DOMAINNAME "route"
+#define RTS_CTASSERT(x) CTASSERT(x)
+CTASSERT(sizeof(struct ifa_xmsghdr) == 32);
+#ifdef COMPAT_50
+#define COMPATCALL(name, args) rtsock_50_ ## name ## _hook_call args
+#endif
+DOMAIN_DEFINE(routedomain); /* forward declare and add to link set */
+#undef COMPAT_50
+#endif /* COMPAT_RTSOCK */
+
+#ifndef COMPATCALL
+#define COMPATCALL(name, args) do { } while (/*CONSTCOND*/ 0)
+#endif
+
+#ifdef RTSOCK_DEBUG
+#define RT_IN_PRINT(info, b, a) (in_print((b), sizeof(b), \
+ &((const struct sockaddr_in *)(info)->rti_info[(a)])->sin_addr), (b))
+#endif /* RTSOCK_DEBUG */
+
+struct route_info COMPATNAME(route_info) = {
+ .ri_dst = { .sa_len = 2, .sa_family = PF_XROUTE, },
+ .ri_src = { .sa_len = 2, .sa_family = PF_XROUTE, },
+ .ri_maxqlen = IFQ_MAXLEN,
+};
+
+static void COMPATNAME(route_init)(void);
+static int COMPATNAME(route_output)(struct mbuf *, struct socket *);
+
+static int rt_xaddrs(u_char, const char *, const char *, struct rt_addrinfo *);
+static struct mbuf *rt_makeifannouncemsg(struct ifnet *, int, int,
+ struct rt_addrinfo *);
+static int rt_msg2(int, struct rt_addrinfo *, void *, struct rt_walkarg *, int *);
+static void _rt_setmetrics(int, const struct rt_xmsghdr *, struct rtentry *);
+static void rtm_setmetrics(const struct rtentry *, struct rt_xmsghdr *);
+static void rt_adjustcount(int, int);
+
+static const struct protosw COMPATNAME(route_protosw)[];
+
+struct routecb {
+ struct rawcb rocb_rcb;
+ unsigned int rocb_msgfilter;
+#define RTMSGFILTER(m) (1U << (m))
+};
+#define sotoroutecb(so) ((struct routecb *)(so)->so_pcb)
+
+static struct rawcbhead rt_rawcb;
+#ifdef NET_MPSAFE
+static kmutex_t *rt_so_mtx;
+
+static bool rt_updating = false;
+static kcondvar_t rt_update_cv;
+#endif
+
+static void
+rt_adjustcount(int af, int cnt)
+{
+ struct route_cb * const cb = &COMPATNAME(route_info).ri_cb;
+
+ cb->any_count += cnt;
+
+ switch (af) {
+ case AF_INET:
+ cb->ip_count += cnt;
+ return;
+#ifdef INET6
+ case AF_INET6:
+ cb->ip6_count += cnt;
+ return;
+#endif
+ case AF_MPLS:
+ cb->mpls_count += cnt;
+ return;
+ }
+}
+
+static int
+COMPATNAME(route_filter)(struct mbuf *m, struct sockproto *proto,
+ struct rawcb *rp)
+{
+ struct routecb *rop = (struct routecb *)rp;
+ struct rt_xmsghdr *rtm;
+
+ KASSERT(m != NULL);
+ KASSERT(proto != NULL);
+ KASSERT(rp != NULL);
+
+ /* Wrong family for this socket. */
+ if (proto->sp_family != PF_ROUTE)
+ return ENOPROTOOPT;
+
+ /* If no filter set, just return. */
+ if (rop->rocb_msgfilter == 0)
+ return 0;
+
+ /* Ensure we can access rtm_type */
+ if (m->m_len <
+ offsetof(struct rt_xmsghdr, rtm_type) + sizeof(rtm->rtm_type))
+ return EINVAL;
+
+ rtm = mtod(m, struct rt_xmsghdr *);
+ /* If the rtm type is filtered out, return a positive. */
+ if (!(rop->rocb_msgfilter & RTMSGFILTER(rtm->rtm_type)))
+ return EEXIST;
+
+ /* Passed the filter. */
+ return 0;
+}
+
+static void
+rt_pr_init(void)
+{
+
+ LIST_INIT(&rt_rawcb);
+}
+
+static int
+COMPATNAME(route_attach)(struct socket *so, int proto)
+{
+ struct rawcb *rp;
+ struct routecb *rop;
+ int s, error;
+
+ KASSERT(sotorawcb(so) == NULL);
+ rop = kmem_zalloc(sizeof(*rop), KM_SLEEP);
+ rp = &rop->rocb_rcb;
+ rp->rcb_len = sizeof(*rop);
+ so->so_pcb = rp;
+
+ s = splsoftnet();
+
+#ifdef NET_MPSAFE
+ KASSERT(so->so_lock == NULL);
+ mutex_obj_hold(rt_so_mtx);
+ so->so_lock = rt_so_mtx;
+ solock(so);
+#endif
+
+ if ((error = raw_attach(so, proto, &rt_rawcb)) == 0) {
+ rt_adjustcount(rp->rcb_proto.sp_protocol, 1);
+ rp->rcb_laddr = &COMPATNAME(route_info).ri_src;
+ rp->rcb_faddr = &COMPATNAME(route_info).ri_dst;
+ rp->rcb_filter = COMPATNAME(route_filter);
+ }
+ splx(s);
+
+ if (error) {
+ kmem_free(rop, sizeof(*rop));
+ so->so_pcb = NULL;
+ return error;
+ }
+
+ soisconnected(so);
+ so->so_options |= SO_USELOOPBACK;
+ KASSERT(solocked(so));
+
+ return error;
+}
+
+static void
+COMPATNAME(route_detach)(struct socket *so)
Home |
Main Index |
Thread Index |
Old Index