Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/pgoyette-compat]: src/sys Split sys/net/rtsock.c into two pieces, one of...



details:   https://anonhg.NetBSD.org/src/rev/56c014d681e8
branches:  pgoyette-compat
changeset: 447531:56c014d681e8
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Tue Jan 15 03:40:35 2019 +0000

description:
Split sys/net/rtsock.c into two pieces, one of which is applicable only
to -current and one which is shared between -current and COMPAT_50.

diffstat:

 sys/compat/common/rtsock_50.c |    19 +-
 sys/net/rtsock.c              |  1618 +----------------------------------------
 sys/net/rtsock_shared.c       |    25 +-
 3 files changed, 25 insertions(+), 1637 deletions(-)

diffs (truncated from 1882 to 300 lines):

diff -r 1df35a1aaecf -r 56c014d681e8 sys/compat/common/rtsock_50.c
--- a/sys/compat/common/rtsock_50.c     Tue Jan 15 01:16:42 2019 +0000
+++ b/sys/compat/common/rtsock_50.c     Tue Jan 15 03:40:35 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtsock_50.c,v 1.6.2.4 2019/01/14 13:34:27 pgoyette Exp $       */
+/*     $NetBSD: rtsock_50.c,v 1.6.2.5 2019/01/15 03:40:35 pgoyette Exp $       */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,23 +61,18 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock_50.c,v 1.6.2.4 2019/01/14 13:34:27 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock_50.c,v 1.6.2.5 2019/01/15 03:40:35 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
 #endif
 
-/*
- * COMPAT_50 and COMPAT_RTSOCK must be defined for rtsock.c regardless of
- * the currently enabled options.
- */
-#ifndef COMPAT_50
-#define COMPAT_50
-#endif
+#define        COMPAT_RTSOCK   /* Use the COMPATNAME/COMPATCALL macros and the
+                        * various other compat definitions - see
+                        * sys/net/rtsock_shared.c for details
+                        */
 
-#define        COMPAT_RTSOCK
-
-#include <net/rtsock.c>
+#include <net/rtsock_shared.c>
 #include <compat/net/route_50.h>
 
 void
diff -r 1df35a1aaecf -r 56c014d681e8 sys/net/rtsock.c
--- a/sys/net/rtsock.c  Tue Jan 15 01:16:42 2019 +0000
+++ b/sys/net/rtsock.c  Tue Jan 15 03:40:35 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtsock.c,v 1.238.2.19 2019/01/14 13:34:28 pgoyette Exp $       */
+/*     $NetBSD: rtsock.c,v 1.238.2.20 2019/01/15 03:40:35 pgoyette Exp $       */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.238.2.19 2019/01/14 13:34:28 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.238.2.20 2019/01/15 03:40:35 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -105,91 +105,14 @@
 #include <compat/net/route.h>
 
 #ifdef COMPAT_RTSOCK
-#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"
-CTASSERT(sizeof(struct ifa_xmsghdr) == 20);
-DOMAIN_DEFINE(compat_50_routedomain); /* forward declare and add to link set */
-#else /* COMPAT_RTSOCK */
-#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"
-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)
+#undef COMPAT_RTSOCK
 #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 int if_addrflags(struct ifaddr *);
+static void sysctl_net_route_setup(struct sysctllog **);
 
-#ifndef COMPAT_RTSOCK
-static void sysctl_net_route_setup(struct sysctllog **);
-#endif
-
-static const struct protosw COMPATNAME(route_protosw)[];
+#include <net/rtsock_shared.c>
 
-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
-
-#ifndef COMPAT_RTSOCK
 /*
  * Compat linkage
  */
@@ -198,868 +121,7 @@
 
        return 0;
 }
-#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)
-{
-       struct rawcb *rp = sotorawcb(so);
-       int s;
-
-       KASSERT(rp != NULL);
-       KASSERT(solocked(so));
-
-       s = splsoftnet();
-       rt_adjustcount(rp->rcb_proto.sp_protocol, -1);
-       raw_detach(so);
-       splx(s);
-}
-
-static int
-COMPATNAME(route_accept)(struct socket *so, struct sockaddr *nam)
-{
-       KASSERT(solocked(so));
-
-       panic("route_accept");
-
-       return EOPNOTSUPP;
-}
-
-static int
-COMPATNAME(route_bind)(struct socket *so, struct sockaddr *nam, struct lwp *l)
-{
-       KASSERT(solocked(so));
-
-       return EOPNOTSUPP;
-}
-
-static int
-COMPATNAME(route_listen)(struct socket *so, struct lwp *l)
-{



Home | Main Index | Thread Index | Old Index