From c90e7dcc542051a01f90b10cd7a2fe56922204d3 Mon Sep 17 00:00:00 2001 From: bluhm Date: Tue, 25 May 2021 22:45:09 +0000 Subject: [PATCH] As network features are not added dynamically, the domain structures are constant. Having more const makes MP review easier. More pointers are mapped read-only in the kernel image. OK deraadt@ mvs@ --- sys/kern/uipc_domain.c | 31 +++++++++++----------------- sys/kern/uipc_proto.c | 6 ++---- sys/kern/uipc_socket.c | 8 +++++--- sys/kern/uipc_usrreq.c | 4 +--- sys/net/if.c | 6 +++--- sys/net/pfkeyv2.c | 6 +++--- sys/net/route.c | 4 ++-- sys/net/rtable.c | 44 ++++++++++++++++++++-------------------- sys/net/rtsock.c | 6 ++---- sys/netinet/in_proto.c | 4 ++-- sys/netinet6/in6_proto.c | 4 ++-- sys/netmpls/mpls.h | 4 +--- sys/netmpls/mpls_proto.c | 4 ++-- sys/sys/domain.h | 18 ++++++++-------- sys/sys/protosw.h | 4 ++-- 15 files changed, 70 insertions(+), 83 deletions(-) diff --git a/sys/kern/uipc_domain.c b/sys/kern/uipc_domain.c index 6dbbe01921c..6f31217e26c 100644 --- a/sys/kern/uipc_domain.c +++ b/sys/kern/uipc_domain.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_domain.c,v 1.58 2021/05/17 17:06:51 claudio Exp $ */ +/* $OpenBSD: uipc_domain.c,v 1.59 2021/05/25 22:45:09 bluhm Exp $ */ /* $NetBSD: uipc_domain.c,v 1.14 1996/02/09 19:00:44 christos Exp $ */ /* @@ -45,14 +45,7 @@ #include "bpfilter.h" #include "pflow.h" -extern struct domain mplsdomain; -extern struct domain pfkeydomain; -extern struct domain inet6domain; -extern struct domain inetdomain; -extern struct domain unixdomain; -extern struct domain routedomain; - -struct domain *domains[] = { +const struct domain *const domains[] = { #ifdef MPLS &mplsdomain, #endif @@ -70,12 +63,12 @@ struct domain *domains[] = { void pffasttimo(void *); void pfslowtimo(void *); -struct domain * pffinddomain(int); +const struct domain * pffinddomain(int); void domaininit(void) { - struct domain *dp; + const struct domain *dp; const struct protosw *pr; static struct timeout pffast_timeout; static struct timeout pfslow_timeout; @@ -105,10 +98,10 @@ domaininit(void) timeout_add(&pfslow_timeout, 1); } -struct domain * +const struct domain * pffinddomain(int family) { - struct domain *dp; + const struct domain *dp; int i; for (i = 0; (dp = domains[i]) != NULL; i++) { @@ -121,7 +114,7 @@ pffinddomain(int family) const struct protosw * pffindtype(int family, int type) { - struct domain *dp; + const struct domain *dp; const struct protosw *pr; dp = pffinddomain(family); @@ -137,7 +130,7 @@ pffindtype(int family, int type) const struct protosw * pffindproto(int family, int protocol, int type) { - struct domain *dp; + const struct domain *dp; const struct protosw *pr; const struct protosw *maybe = NULL; @@ -194,7 +187,7 @@ int net_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen, struct proc *p) { - struct domain *dp; + const struct domain *dp; const struct protosw *pr; int error, family, protocol; @@ -254,7 +247,7 @@ net_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, void pfctlinput(int cmd, struct sockaddr *sa) { - struct domain *dp; + const struct domain *dp; const struct protosw *pr; int i; @@ -271,7 +264,7 @@ void pfslowtimo(void *arg) { struct timeout *to = (struct timeout *)arg; - struct domain *dp; + const struct domain *dp; const struct protosw *pr; int i; @@ -287,7 +280,7 @@ void pffasttimo(void *arg) { struct timeout *to = (struct timeout *)arg; - struct domain *dp; + const struct domain *dp; const struct protosw *pr; int i; diff --git a/sys/kern/uipc_proto.c b/sys/kern/uipc_proto.c index d57340cd9c3..2c29eb37e5e 100644 --- a/sys/kern/uipc_proto.c +++ b/sys/kern/uipc_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_proto.c,v 1.18 2019/07/15 12:28:06 bluhm Exp $ */ +/* $OpenBSD: uipc_proto.c,v 1.19 2021/05/25 22:45:09 bluhm Exp $ */ /* $NetBSD: uipc_proto.c,v 1.8 1996/02/13 21:10:47 christos Exp $ */ /*- @@ -44,8 +44,6 @@ * Definitions of protocols supported in the UNIX domain. */ -extern struct domain unixdomain; /* or at least forward */ - struct protosw unixsw[] = { { .pr_type = SOCK_STREAM, @@ -76,7 +74,7 @@ struct protosw unixsw[] = { } }; -struct domain unixdomain = { +const struct domain unixdomain = { .dom_family = AF_UNIX, .dom_name = "unix", .dom_init = unp_init, diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 341b9ae053a..f194fae1707 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.261 2021/05/13 19:43:11 mvs Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.262 2021/05/25 22:45:09 bluhm Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -1821,7 +1821,8 @@ sosetopt(struct socket *so, int level, int optname, struct mbuf *m) if (so->so_proto->pr_domain && so->so_proto->pr_domain->dom_protosw && so->so_proto->pr_ctloutput) { - struct domain *dom = so->so_proto->pr_domain; + const struct domain *dom = + so->so_proto->pr_domain; level = dom->dom_protosw->pr_protocol; error = (*so->so_proto->pr_ctloutput) @@ -1961,7 +1962,8 @@ sogetopt(struct socket *so, int level, int optname, struct mbuf *m) if (so->so_proto->pr_domain && so->so_proto->pr_domain->dom_protosw && so->so_proto->pr_ctloutput) { - struct domain *dom = so->so_proto->pr_domain; + const struct domain *dom = + so->so_proto->pr_domain; level = dom->dom_protosw->pr_protocol; error = (*so->so_proto->pr_ctloutput) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 2dd6d89a252..83e62bad6c1 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.147 2021/05/18 11:15:14 mvs Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.148 2021/05/25 22:45:09 bluhm Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -792,8 +792,6 @@ unp_drain(void) } #endif -extern struct domain unixdomain; - static struct unpcb * fptounp(struct file *fp) { diff --git a/sys/net/if.c b/sys/net/if.c index c11710b75fc..e375f5211db 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.640 2021/03/26 22:41:06 mvs Exp $ */ +/* $OpenBSD: if.c,v 1.641 2021/05/25 22:45:09 bluhm Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -501,7 +501,7 @@ if_free_sadl(struct ifnet *ifp) void if_attachdomain(struct ifnet *ifp) { - struct domain *dp; + const struct domain *dp; int i, s; s = splnet(); @@ -1010,7 +1010,7 @@ if_detach(struct ifnet *ifp) { struct ifaddr *ifa; struct ifg_list *ifg; - struct domain *dp; + const struct domain *dp; int i, s; /* Undo pseudo-driver changes. */ diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c index 23f4d00a3b0..fa6917352b5 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.212 2021/05/25 09:55:22 bluhm Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.213 2021/05/25 22:45:09 bluhm Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -125,7 +125,7 @@ static const struct sadb_alg calgs[] = { struct pool pkpcb_pool; #define PFKEY_MSG_MAXSZ 4096 const struct sockaddr pfkey_addr = { 2, PF_KEY, }; -struct domain pfkeydomain; +const struct domain pfkeydomain; /* * pfkey PCB @@ -214,7 +214,7 @@ static struct protosw pfkeysw[] = { } }; -struct domain pfkeydomain = { +const struct domain pfkeydomain = { .dom_family = PF_KEY, .dom_name = "PF_KEY", .dom_init = pfkey_init, diff --git a/sys/net/route.c b/sys/net/route.c index 3e3c32617df..73bd6f53639 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.398 2021/03/10 10:21:48 jsg Exp $ */ +/* $OpenBSD: route.c,v 1.399 2021/05/25 22:45:09 bluhm Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -1061,7 +1061,7 @@ rt_copysa(struct sockaddr *src, struct sockaddr *mask, struct sockaddr **dst) static const u_char maskarray[] = { 0x0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe }; struct sockaddr *ndst; - struct domain *dp; + const struct domain *dp; u_char *csrc, *cdst; int i, plen; diff --git a/sys/net/rtable.c b/sys/net/rtable.c index 4d00cd101f7..4cdd303200a 100644 --- a/sys/net/rtable.c +++ b/sys/net/rtable.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtable.c,v 1.74 2021/03/26 22:41:06 mvs Exp $ */ +/* $OpenBSD: rtable.c,v 1.75 2021/05/25 22:45:09 bluhm Exp $ */ /* * Copyright (c) 2014-2016 Martin Pieuchot @@ -90,8 +90,8 @@ void *rtable_get(unsigned int, sa_family_t); void rtmap_init(void) { - struct domain *dp; - int i; + const struct domain *dp; + int i; /* Start with a single table for every domain that requires it. */ for (i = 0; (dp = domains[i]) != NULL; i++) { @@ -152,8 +152,8 @@ rtmap_dtor(void *null, void *xmap) void rtable_init(void) { - struct domain *dp; - int i; + const struct domain *dp; + int i; KASSERT(sizeof(struct rtmap) == sizeof(struct dommp)); @@ -189,13 +189,13 @@ rtable_init(void) int rtable_add(unsigned int id) { - struct domain *dp; - void *tbl; - struct rtmap *map; - struct dommp *dmm; - sa_family_t af; - unsigned int off, alen; - int i, error = 0; + const struct domain *dp; + void *tbl; + struct rtmap *map; + struct dommp *dmm; + sa_family_t af; + unsigned int off, alen; + int i, error = 0; if (id > RT_TABLEID_MAX) return (EINVAL); @@ -262,9 +262,9 @@ rtable_get(unsigned int rtableid, sa_family_t af) int rtable_exists(unsigned int rtableid) { - struct domain *dp; - void *tbl; - int i; + const struct domain *dp; + void *tbl; + int i; for (i = 0; (dp = domains[i]) != NULL; i++) { if (dp->dom_rtoffset == 0) @@ -281,9 +281,9 @@ rtable_exists(unsigned int rtableid) int rtable_empty(unsigned int rtableid) { - struct domain *dp; - int i; - struct art_root *tbl; + const struct domain *dp; + int i; + struct art_root *tbl; for (i = 0; (dp = domains[i]) != NULL; i++) { if (dp->dom_rtoffset == 0) @@ -902,10 +902,10 @@ satoaddr(struct art_root *at, struct sockaddr *sa) int rtable_satoplen(sa_family_t af, struct sockaddr *mask) { - struct domain *dp; - uint8_t *ap, *ep; - int mlen, plen = 0; - int i; + const struct domain *dp; + uint8_t *ap, *ep; + int mlen, plen = 0; + int i; for (i = 0; (dp = domains[i]) != NULL; i++) { if (dp->dom_rtoffset == 0) diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 36c52549528..cd7c3490964 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.315 2021/05/17 17:58:35 claudio Exp $ */ +/* $OpenBSD: rtsock.c,v 1.316 2021/05/25 22:45:09 bluhm Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -2356,8 +2356,6 @@ rt_setsource(unsigned int rtableid, struct sockaddr *src) * Definitions of protocols supported in the ROUTE domain. */ -struct domain routedomain; - struct protosw routesw[] = { { .pr_type = SOCK_RAW, @@ -2373,7 +2371,7 @@ struct protosw routesw[] = { } }; -struct domain routedomain = { +const struct domain routedomain = { .dom_family = PF_ROUTE, .dom_name = "route", .dom_init = route_init, diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c index f474f0ca901..071f0b04b71 100644 --- a/sys/netinet/in_proto.c +++ b/sys/netinet/in_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_proto.c,v 1.94 2019/11/04 23:52:28 dlg Exp $ */ +/* $OpenBSD: in_proto.c,v 1.95 2021/05/25 22:45:09 bluhm Exp $ */ /* $NetBSD: in_proto.c,v 1.14 1996/02/18 18:58:32 christos Exp $ */ /* @@ -419,7 +419,7 @@ const struct protosw inetsw[] = { } }; -struct domain inetdomain = { +const struct domain inetdomain = { .dom_family = AF_INET, .dom_name = "internet", .dom_init = in_init, diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c index 11b63efa566..5331dc5a4ca 100644 --- a/sys/netinet6/in6_proto.c +++ b/sys/netinet6/in6_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_proto.c,v 1.104 2019/06/13 08:12:11 claudio Exp $ */ +/* $OpenBSD: in6_proto.c,v 1.105 2021/05/25 22:45:10 bluhm Exp $ */ /* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */ /* @@ -361,7 +361,7 @@ const struct protosw inet6sw[] = { } }; -struct domain inet6domain = { +const struct domain inet6domain = { .dom_family = AF_INET6, .dom_name = "internet6", .dom_protosw = inet6sw, diff --git a/sys/netmpls/mpls.h b/sys/netmpls/mpls.h index a1d4fee78d3..702aa90c584 100644 --- a/sys/netmpls/mpls.h +++ b/sys/netmpls/mpls.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls.h,v 1.45 2021/03/10 10:21:49 jsg Exp $ */ +/* $OpenBSD: mpls.h,v 1.46 2021/05/25 22:45:10 bluhm Exp $ */ /* * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. @@ -145,8 +145,6 @@ struct ifmpwreq { #define MPLS_LABEL2SHIM(_l) (htonl((_l) << MPLS_LABEL_OFFSET)) #define MPLS_SHIM2LABEL(_s) (ntohl((_s)) >> MPLS_LABEL_OFFSET) -extern struct domain mplsdomain; - extern int mpls_defttl; extern int mpls_mapttl_ip; extern int mpls_mapttl_ip6; diff --git a/sys/netmpls/mpls_proto.c b/sys/netmpls/mpls_proto.c index 8be741a0c43..0124488be24 100644 --- a/sys/netmpls/mpls_proto.c +++ b/sys/netmpls/mpls_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls_proto.c,v 1.18 2019/06/13 08:12:11 claudio Exp $ */ +/* $OpenBSD: mpls_proto.c,v 1.19 2021/05/25 22:45:10 bluhm Exp $ */ /* * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. @@ -45,7 +45,7 @@ /* * MPLS address family: needed for the routing table */ -struct domain mplsdomain = { +const struct domain mplsdomain = { .dom_family = AF_MPLS, .dom_name = "mpls", .dom_sasize = sizeof(struct sockaddr_mpls), diff --git a/sys/sys/domain.h b/sys/sys/domain.h index 86eab567c61..d8758fb8b9c 100644 --- a/sys/sys/domain.h +++ b/sys/sys/domain.h @@ -1,4 +1,4 @@ -/* $OpenBSD: domain.h,v 1.21 2021/03/10 10:21:47 jsg Exp $ */ +/* $OpenBSD: domain.h,v 1.22 2021/05/25 22:45:10 bluhm Exp $ */ /* $NetBSD: domain.h,v 1.10 1996/02/09 18:25:07 christos Exp $ */ /* @@ -47,7 +47,7 @@ typedef __socklen_t socklen_t; /* length type for network syscalls */ struct mbuf; struct ifnet; -struct domain { +struct domain { int dom_family; /* AF_xxx */ char *dom_name; void (*dom_init)(void); /* initialize domain data structures */ @@ -66,13 +66,13 @@ struct domain { }; #ifdef _KERNEL -extern struct domain *domains[]; void domaininit(void); -extern struct domain inetdomain; - -#ifdef INET6 -extern struct domain inet6domain; -#endif - +extern const struct domain *const domains[]; +extern const struct domain inet6domain; +extern const struct domain inetdomain; +extern const struct domain mplsdomain; +extern const struct domain pfkeydomain; +extern const struct domain routedomain; +extern const struct domain unixdomain; #endif /* _KERNEL */ diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index 995a038a47d..f8acb7d941c 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.31 2018/01/23 20:49:58 bluhm Exp $ */ +/* $OpenBSD: protosw.h,v 1.32 2021/05/25 22:45:10 bluhm Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -61,7 +61,7 @@ struct proc; struct protosw { short pr_type; /* socket type used for */ - struct domain *pr_domain; /* domain protocol a member of */ + const struct domain *pr_domain; /* domain protocol a member of */ short pr_protocol; /* protocol number */ short pr_flags; /* see below */ -- 2.20.1