On Wed, Nov 22, 2017 at 12:19:49PM +0100, Martin Pieuchot wrote:
> On 22/11/17(Wed) 11:05, Martin Pieuchot wrote:
> > ip_deliver() dispatches incoming packets to their corresponding protocol
> > input function.  It doesn't need the KERNEL_LOCK(), so remove the assert
> > and mark the dispatch tables as 'const' all over the kernel.
> > 
> > ok?

OK bluhm@

> I missed netinet6/ bits in the previous diff.
> 
> Index: kern/uipc_domain.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/uipc_domain.c,v
> retrieving revision 1.54
> diff -u -p -r1.54 uipc_domain.c
> --- kern/uipc_domain.c        29 Oct 2017 14:56:36 -0000      1.54
> +++ kern/uipc_domain.c        22 Nov 2017 09:57:06 -0000
> @@ -76,7 +76,7 @@ void
>  domaininit(void)
>  {
>       struct domain *dp;
> -     struct protosw *pr;
> +     const struct protosw *pr;
>       static struct timeout pffast_timeout;
>       static struct timeout pfslow_timeout;
>       int i;
> @@ -118,11 +118,11 @@ pffinddomain(int family)
>       return (NULL);
>  }
>  
> -struct protosw *
> +const struct protosw *
>  pffindtype(int family, int type)
>  {
>       struct domain *dp;
> -     struct protosw *pr;
> +     const struct protosw *pr;
>  
>       dp = pffinddomain(family);
>       if (dp == NULL)
> @@ -134,12 +134,12 @@ pffindtype(int family, int type)
>       return (NULL);
>  }
>  
> -struct protosw *
> +const struct protosw *
>  pffindproto(int family, int protocol, int type)
>  {
>       struct domain *dp;
> -     struct protosw *pr;
> -     struct protosw *maybe = NULL;
> +     const struct protosw *pr;
> +     const struct protosw *maybe = NULL;
>  
>       if (family == 0)
>               return (NULL);
> @@ -164,7 +164,7 @@ net_sysctl(int *name, u_int namelen, voi
>      size_t newlen, struct proc *p)
>  {
>       struct domain *dp;
> -     struct protosw *pr;
> +     const struct protosw *pr;
>       int error, family, protocol;
>  
>       /*
> @@ -218,7 +218,7 @@ void
>  pfctlinput(int cmd, struct sockaddr *sa)
>  {
>       struct domain *dp;
> -     struct protosw *pr;
> +     const struct protosw *pr;
>       int i;
>  
>       NET_ASSERT_LOCKED();
> @@ -235,7 +235,7 @@ pfslowtimo(void *arg)
>  {
>       struct timeout *to = (struct timeout *)arg;
>       struct domain *dp;
> -     struct protosw *pr;
> +     const struct protosw *pr;
>       int i;
>  
>       for (i = 0; (dp = domains[i]) != NULL; i++) {
> @@ -251,7 +251,7 @@ pffasttimo(void *arg)
>  {
>       struct timeout *to = (struct timeout *)arg;
>       struct domain *dp;
> -     struct protosw *pr;
> +     const struct protosw *pr;
>       int i;
>  
>       for (i = 0; (dp = domains[i]) != NULL; i++) {
> Index: kern/uipc_socket.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/uipc_socket.c,v
> retrieving revision 1.207
> diff -u -p -r1.207 uipc_socket.c
> --- kern/uipc_socket.c        4 Nov 2017 14:13:53 -0000       1.207
> +++ kern/uipc_socket.c        22 Nov 2017 09:59:21 -0000
> @@ -111,7 +111,7 @@ int
>  socreate(int dom, struct socket **aso, int type, int proto)
>  {
>       struct proc *p = curproc;               /* XXX */
> -     struct protosw *prp;
> +     const struct protosw *prp;
>       struct socket *so;
>       int error, s;
>  
> @@ -633,7 +633,7 @@ soreceive(struct socket *so, struct mbuf
>       struct mbuf *cm;
>       u_long len, offset, moff;
>       int flags, error, s, type, uio_error = 0;
> -     struct protosw *pr = so->so_proto;
> +     const struct protosw *pr = so->so_proto;
>       struct mbuf *nextrecord;
>       size_t resid, orig_resid = uio->uio_resid;
>  
> @@ -1012,7 +1012,7 @@ release:
>  int
>  soshutdown(struct socket *so, int how)
>  {
> -     struct protosw *pr = so->so_proto;
> +     const struct protosw *pr = so->so_proto;
>       int s, error = 0;
>  
>       s = solock(so);
> @@ -1040,7 +1040,7 @@ void
>  sorflush(struct socket *so)
>  {
>       struct sockbuf *sb = &so->so_rcv;
> -     struct protosw *pr = so->so_proto;
> +     const struct protosw *pr = so->so_proto;
>       struct socket aso;
>       int error;
>  
> Index: netinet/in_proto.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/in_proto.c,v
> retrieving revision 1.87
> diff -u -p -r1.87 in_proto.c
> --- netinet/in_proto.c        17 Nov 2017 18:22:52 -0000      1.87
> +++ netinet/in_proto.c        22 Nov 2017 09:53:08 -0000
> @@ -174,7 +174,7 @@
>  
>  u_char ip_protox[IPPROTO_MAX];
>  
> -struct protosw inetsw[] = {
> +const struct protosw inetsw[] = {
>  {
>    .pr_domain = &inetdomain,
>    .pr_init   = ip_init,
> Index: netinet/ip_input.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_input.c,v
> retrieving revision 1.333
> diff -u -p -r1.333 ip_input.c
> --- netinet/ip_input.c        20 Nov 2017 10:35:24 -0000      1.333
> +++ netinet/ip_input.c        22 Nov 2017 09:55:39 -0000
> @@ -151,7 +151,7 @@ void save_rte(struct mbuf *, u_char *, s
>  void
>  ip_init(void)
>  {
> -     struct protosw *pr;
> +     const struct protosw *pr;
>       int i;
>       const u_int16_t defbaddynamicports_tcp[] = DEFBADDYNAMICPORTS_TCP;
>       const u_int16_t defbaddynamicports_udp[] = DEFBADDYNAMICPORTS_UDP;
> @@ -613,13 +613,11 @@ ip_local(struct mbuf **mp, int *offp, in
>  int
>  ip_deliver(struct mbuf **mp, int *offp, int nxt, int af)
>  {
> -     struct protosw *psw;
> +     const struct protosw *psw;
>       int naf = af;
>  #ifdef INET6
>       int nest = 0;
>  #endif /* INET6 */
> -
> -     KERNEL_ASSERT_LOCKED();
>  
>       /* pf might have modified stuff, might have to chksum */
>       switch (af) {
> Index: sys/domain.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/domain.h,v
> retrieving revision 1.17
> diff -u -p -r1.17 domain.h
> --- sys/domain.h      3 Dec 2015 23:12:13 -0000       1.17
> +++ sys/domain.h      22 Nov 2017 09:55:04 -0000
> @@ -55,7 +55,7 @@ struct      domain {
>       int     (*dom_externalize)(struct mbuf *, socklen_t, int);
>                                       /* dispose of internalized rights */
>       void    (*dom_dispose)(struct mbuf *);
> -     struct  protosw *dom_protosw, *dom_protoswNPROTOSW;
> +     const struct    protosw *dom_protosw, *dom_protoswNPROTOSW;
>                                       /* initialize routing table */
>       unsigned int    dom_rtkeylen;   /* maximum size of the key */
>       unsigned int    dom_rtoffset;   /* offset of the key, in bytes */
> Index: sys/protosw.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/protosw.h,v
> retrieving revision 1.27
> diff -u -p -r1.27 protosw.h
> --- sys/protosw.h     5 Nov 2017 13:19:59 -0000       1.27
> +++ sys/protosw.h     22 Nov 2017 09:57:32 -0000
> @@ -226,10 +226,10 @@ char    *prcorequests[] = {
>  
>  #ifdef _KERNEL
>  struct sockaddr;
> -struct protosw *pffindproto(int, int, int);
> -struct protosw *pffindtype(int, int);
> +const struct protosw *pffindproto(int, int, int);
> +const struct protosw *pffindtype(int, int);
>  void pfctlinput(int, struct sockaddr *);
>  
>  extern u_char ip_protox[];
> -extern struct protosw inetsw[];
> +extern const struct protosw inetsw[];
>  #endif
> Index: sys/socketvar.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/socketvar.h,v
> retrieving revision 1.77
> diff -u -p -r1.77 socketvar.h
> --- sys/socketvar.h   4 Nov 2017 14:13:53 -0000       1.77
> +++ sys/socketvar.h   22 Nov 2017 09:58:56 -0000
> @@ -56,7 +56,7 @@ struct socket {
>       short   so_linger;              /* time to linger while closing */
>       short   so_state;               /* internal state flags SS_*, below */
>       void    *so_pcb;                /* protocol control block */
> -     struct  protosw *so_proto;      /* protocol handle */
> +     const struct protosw *so_proto; /* protocol handle */
>  /*
>   * Variables for connection queueing.
>   * Socket where accepts occur is so_head in all subsidiary sockets.
> Index: netinet6/in6_proto.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/in6_proto.c,v
> retrieving revision 1.99
> diff -u -p -r1.99 in6_proto.c
> --- netinet6/in6_proto.c      17 Nov 2017 14:51:13 -0000      1.99
> +++ netinet6/in6_proto.c      22 Nov 2017 10:02:12 -0000
> @@ -121,7 +121,7 @@
>   */
>  u_char ip6_protox[IPPROTO_MAX];
>  
> -struct protosw inet6sw[] = {
> +const struct protosw inet6sw[] = {
>  {
>    .pr_domain = &inet6domain,
>    .pr_protocol       = IPPROTO_IPV6,
> Index: netinet6/ip6_input.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/ip6_input.c,v
> retrieving revision 1.209
> diff -u -p -r1.209 ip6_input.c
> --- netinet6/ip6_input.c      20 Nov 2017 10:35:24 -0000      1.209
> +++ netinet6/ip6_input.c      22 Nov 2017 09:55:25 -0000
> @@ -138,7 +138,7 @@ static struct task ip6send_task =
>  void
>  ip6_init(void)
>  {
> -     struct protosw *pr;
> +     const struct protosw *pr;
>       int i;
>  
>       pr = pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
> Index: netinet6/ip6protosw.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/ip6protosw.h,v
> retrieving revision 1.12
> diff -u -p -r1.12 ip6protosw.h
> --- netinet6/ip6protosw.h     29 Jan 2017 19:58:47 -0000      1.12
> +++ netinet6/ip6protosw.h     22 Nov 2017 10:02:23 -0000
> @@ -111,7 +111,7 @@ struct ip6ctlparam {
>  
>  #ifdef _KERNEL
>  extern u_char ip6_protox[];
> -extern struct protosw inet6sw[];
> +extern const struct protosw inet6sw[];
>  #endif
>  
>  #endif /* !_NETINET6_IP6PROTOSW_H_ */

Reply via email to