1: /*
   2:  * Copyright (c) 1988 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  *
   6:  *	sys_kern.c 1.2 (2.11BSD) 1997/1/30
   7:  */
   8: 
   9: #include "param.h"
  10: #include "../machine/seg.h"
  11: 
  12: #include "user.h"
  13: #include "file.h"
  14: #include "socketvar.h"
  15: #include "inode.h"
  16: #include "proc.h"
  17: #include "namei.h"
  18: #include "mbuf.h"
  19: #include "map.h"
  20: 
  21: int knetisr;
  22: 
  23: netcrash()
  24: {
  25:     panic("Network crashed");
  26: }
  27: 
  28: /*
  29:  * These next entry points exist to allow the network kernel to
  30:  * access components of structures that exist in kernel data space.
  31:  */
  32: netpsignal(p, sig)      /* XXX? sosend, sohasoutofband, sowakeup */
  33:     struct proc *p;     /* if necessary, wrap psignal in save/restor */
  34:     int sig;
  35: {
  36:     mapinfo map;
  37: 
  38:     savemap(map);
  39:     psignal(p, sig);
  40:     restormap(map);
  41: }
  42: 
  43: struct proc *
  44: netpfind(pid)
  45:     int pid;
  46: {
  47:     register struct proc *p;
  48:     mapinfo map;
  49: 
  50:     savemap(map);
  51:     p = pfind(pid);
  52:     restormap(map);
  53:     return(p);
  54: }
  55: 
  56: void
  57: fpflags(fp, set, clear)
  58:     struct file *fp;
  59:     int set, clear;
  60: {
  61:     fp->f_flag |= set;
  62:     fp->f_flag &= ~clear;
  63: }
  64: 
  65: void
  66: fadjust(fp, msg, cnt)
  67:     struct file *fp;
  68:     int msg, cnt;
  69: {
  70:     fp->f_msgcount += msg;
  71:     fp->f_count += cnt;
  72: }
  73: 
  74: fpfetch(fp, fpp)
  75:     struct file *fp, *fpp;
  76: {
  77:     *fpp = *fp;
  78:     return(fp->f_count);
  79: }
  80: 
  81: void
  82: unpdet(ip)
  83:     struct inode *ip;
  84: {
  85:     ip->i_socket = 0;
  86:     irele(ip);
  87: }
  88: 
  89: unpbind(path, len, ipp, unpsock)
  90:     char *path;
  91:     int len;
  92:     struct inode **ipp;
  93:     struct socket *unpsock;
  94: {
  95:     /*
  96: 	 * As far as I could find out, the 'path' is in the _u area because
  97: 	 * a fake mbuf was MBZAP'd in bind().  The inode pointer is in the
  98: 	 * kernel stack so we can modify it.  SMS
  99: 	 */
 100:     register struct inode *ip;
 101:     char pth[MLEN];
 102:     int error;
 103:     struct  nameidata nd;
 104:     register struct nameidata *ndp = &nd;
 105: 
 106:     bcopy(path, pth, len);
 107:     NDINIT(ndp, CREATE, FOLLOW, UIO_SYSSPACE, pth);
 108:     ndp->ni_dirp[len - 2] = 0;
 109:     *ipp = 0;
 110:     ip = namei(ndp);
 111:     if (ip) {
 112:         iput(ip);
 113:         return(EADDRINUSE);
 114:     }
 115:     if (u.u_error || !(ip = maknode(IFSOCK | 0777, ndp))) {
 116:         error = u.u_error;
 117:         u.u_error = 0;
 118:         return(error);
 119:     }
 120:     *ipp = ip;
 121:     ip->i_socket = unpsock;
 122:     iunlock(ip);
 123:     return(0);
 124: }
 125: 
 126: unpconn(path, len, so2, ipp)
 127:     char *path;
 128:     int len;
 129:     struct socket **so2;
 130:     struct inode **ipp;
 131: {
 132:     register struct inode *ip;
 133:     char pth[MLEN];
 134:     int error;
 135:     struct  nameidata nd;
 136:     register struct nameidata *ndp = &nd;
 137: 
 138:     bcopy(path, pth, len);
 139:     if (!len)
 140:         return(EINVAL);     /* paranoia */
 141:     NDINIT(ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, pth);
 142:     ndp->ni_dirp[len - 2] = 0;
 143:     ip = namei(ndp);
 144:     *ipp = ip;
 145:     if (!ip || access(ip, IWRITE)) {
 146:         error = u.u_error;
 147:         u.u_error = 0;
 148:         return(error);
 149:     }
 150:     if ((ip->i_mode & IFMT) != IFSOCK)
 151:         return(ENOTSOCK);
 152:     *so2 = ip->i_socket;
 153:     if (*so2 == 0)
 154:         return(ECONNREFUSED);
 155:     return(0);
 156: }
 157: 
 158: unpgc1(beginf, endf)
 159:     struct file **beginf, **endf;
 160: {
 161:     register struct file *fp;
 162: 
 163:     for (*beginf = fp = file; fp < fileNFILE; fp++)
 164:         fp->f_flag &= ~(FMARK|FDEFER);
 165:     *endf = fileNFILE;
 166: }
 167: 
 168: unpdisc(fp)
 169:     struct file *fp;
 170: {
 171:     --fp->f_msgcount;
 172:     return(closef(fp));
 173: }

Defined functions

fadjust defined in line 65; used 3 times
fpfetch defined in line 74; used 2 times
fpflags defined in line 56; used 2 times
netcrash defined in line 23; used 2 times
netpfind defined in line 43; used 2 times
netpsignal defined in line 32; used 2 times
unpbind defined in line 89; used 2 times
unpconn defined in line 126; used 2 times
unpdet defined in line 81; used 2 times
unpdisc defined in line 168; used 2 times
unpgc1 defined in line 158; used 2 times

Defined variables

knetisr defined in line 21; used 2 times
Last modified: 1997-01-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 120
Valid CSS Valid XHTML 1.0 Strict