The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/netncp/ncp_subr.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 1999, 2000, 2001 Boris Popov
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. All advertising materials mentioning features or use of this software
   14  *    must display the following acknowledgement:
   15  *    This product includes software developed by Boris Popov.
   16  * 4. Neither the name of the author nor the names of any co-contributors
   17  *    may be used to endorse or promote products derived from this software
   18  *    without specific prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   30  * SUCH DAMAGE.
   31  *
   32  * $FreeBSD: releng/5.1/sys/netncp/ncp_subr.c 112564 2003-03-24 21:15:35Z jhb $
   33  */
   34 #include <sys/param.h>
   35 #include <sys/systm.h>
   36 #include <sys/errno.h>
   37 #include <sys/eventhandler.h>
   38 #include <sys/kernel.h>
   39 #include <sys/lock.h>
   40 #include <sys/malloc.h>
   41 #include <sys/proc.h>
   42 #include <sys/sysctl.h>
   43 #include <sys/time.h>
   44 
   45 #include <netncp/ncp.h>
   46 #include <netncp/ncp_conn.h>
   47 #include <netncp/ncp_sock.h>
   48 #include <netncp/ncp_subr.h>
   49 #include <netncp/ncp_rq.h>
   50 #include <netncp/ncp_ncp.h>
   51 #include <netncp/nwerror.h>
   52 
   53 int ncp_debuglevel = 0;
   54 
   55 struct callout_handle ncp_timer_handle;
   56 static eventhandler_tag ncp_exit_tag;
   57 
   58 static void ncp_at_exit(void *arg, struct proc *p);
   59 static void ncp_timer(void *arg);
   60 
   61 /*
   62  * duplicate string from user space. It should be very-very slow.
   63  */
   64 char *
   65 ncp_str_dup(char *s) {
   66         char *p, bt;
   67         int len = 0;
   68 
   69         for (p = s;;p++) {
   70                 if (copyin(p, &bt, 1)) return NULL;
   71                 len++;
   72                 if (bt == 0) break;
   73         }
   74         MALLOC(p, char*, len, M_NCPDATA, M_WAITOK);
   75         copyin(s, p, len);
   76         return p;
   77 }
   78 
   79 
   80 void
   81 ncp_at_exit(void *arg, struct proc *p)
   82 {
   83         struct ncp_conn *ncp, *nncp;
   84         struct thread *td;
   85 
   86         FOREACH_THREAD_IN_PROC(p, td) {
   87                 if (ncp_conn_putprochandles(td) == 0)
   88                         continue;
   89 
   90                 ncp_conn_locklist(LK_EXCLUSIVE, td);
   91                 for (ncp = SLIST_FIRST(&conn_list); ncp; ncp = nncp) {
   92                         nncp = SLIST_NEXT(ncp, nc_next);
   93                         if (ncp_conn_lock(ncp, td, td->td_ucred,
   94                                           NCPM_READ | NCPM_EXECUTE | NCPM_WRITE))
   95                                 continue;
   96                         if (ncp_conn_free(ncp) != 0)
   97                                 ncp_conn_unlock(ncp, td);
   98                 }
   99                 ncp_conn_unlocklist(td);
  100         }
  101 }
  102 
  103 int
  104 ncp_init(void)
  105 {
  106         ncp_conn_init();
  107         ncp_exit_tag = EVENTHANDLER_REGISTER(process_exit, ncp_at_exit, NULL,
  108             EVENTHANDLER_PRI_ANY);
  109         ncp_timer_handle = timeout(ncp_timer, NULL, NCP_TIMER_TICK);
  110         return 0;
  111 }
  112 
  113 int
  114 ncp_done(void)
  115 {
  116         int error;
  117 
  118         error = ncp_conn_destroy();
  119         if (error)
  120                 return error;
  121         untimeout(ncp_timer, NULL, ncp_timer_handle);
  122         EVENTHANDLER_DEREGISTER(process_exit, ncp_exit_tag);
  123         return 0;
  124 }
  125 
  126 
  127 /* tick every second and check for watch dog packets and lost connections */
  128 static void
  129 ncp_timer(void *arg)
  130 {
  131         struct ncp_conn *conn;
  132 
  133         if(ncp_conn_locklist(LK_SHARED | LK_NOWAIT, NULL) == 0) {
  134                 SLIST_FOREACH(conn, &conn_list, nc_next)
  135                         ncp_check_conn(conn);
  136                 ncp_conn_unlocklist(NULL);
  137         }
  138         ncp_timer_handle = timeout(ncp_timer, NULL, NCP_TIMER_TICK);
  139 }

Cache object: 43b6e520b53ac30f30e254a1792a02c3


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.