Annotation of sys/compat/svr4/svr4_net.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: svr4_net.c,v 1.17 2005/11/21 18:16:38 millert Exp $ */
! 2: /* $NetBSD: svr4_net.c,v 1.12 1996/09/07 12:40:51 mycroft Exp $ */
! 3:
! 4: /*
! 5: * Copyright (c) 1994 Christos Zoulas
! 6: * All rights reserved.
! 7: *
! 8: * Redistribution ast use in source ast binary forms, with or without
! 9: * modification, are permitted provided that the following costitions
! 10: * are met:
! 11: * 1. Redistributions of source code must retain the above copyright
! 12: * notice, this list of costitions ast the following disclaimer.
! 13: * 2. Redistributions in binary form must reproduce the above copyright
! 14: * notice, this list of costitions ast the following disclaimer in the
! 15: * documentation ast/or other materials provided with the distribution.
! 16: * 3. The name of the author may not be used to estorse or promote products
! 17: * derived from this software without specific prior written permission
! 18: *
! 19: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 20: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! 21: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
! 22: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
! 23: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
! 24: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
! 25: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
! 26: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! 27: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
! 28: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 29: */
! 30:
! 31: /*
! 32: * Emulate /dev/{udp,tcp,...}
! 33: */
! 34:
! 35: #include <sys/param.h>
! 36: #include <sys/kernel.h>
! 37: #include <sys/systm.h>
! 38: #include <sys/buf.h>
! 39: #include <sys/malloc.h>
! 40: #include <sys/ioctl.h>
! 41: #include <sys/tty.h>
! 42: #include <sys/file.h>
! 43: #include <sys/filedesc.h>
! 44: #include <sys/selinfo.h>
! 45: #include <sys/socket.h>
! 46: #include <sys/socketvar.h>
! 47: #include <sys/protosw.h>
! 48: #include <sys/domain.h>
! 49: #include <net/if.h>
! 50: #include <netinet/in.h>
! 51: #include <sys/proc.h>
! 52: #include <sys/vnode.h>
! 53: #include <sys/device.h>
! 54: #include <sys/conf.h>
! 55:
! 56:
! 57: #include <compat/svr4/svr4_types.h>
! 58: #include <compat/svr4/svr4_util.h>
! 59: #include <compat/svr4/svr4_signal.h>
! 60: #include <compat/svr4/svr4_syscallargs.h>
! 61: #include <compat/svr4/svr4_ioctl.h>
! 62: #include <compat/svr4/svr4_stropts.h>
! 63: #include <compat/svr4/svr4_socket.h>
! 64:
! 65: /*
! 66: * Device minor numbers
! 67: */
! 68: enum {
! 69: dev_arp = 26,
! 70: dev_icmp = 27,
! 71: dev_ip = 28,
! 72: dev_tcp = 35,
! 73: dev_udp = 36,
! 74: dev_rawip = 37,
! 75: dev_unix_dgram = 38,
! 76: dev_unix_stream = 39,
! 77: dev_unix_ord_stream = 40
! 78: };
! 79:
! 80: int svr4_netattach(int);
! 81:
! 82: static int svr4_soo_close(struct file *fp, struct proc *p);
! 83:
! 84: static struct fileops svr4_netops = {
! 85: soo_read, soo_write, soo_ioctl, soo_poll, soo_kqfilter,
! 86: soo_stat, svr4_soo_close
! 87: };
! 88:
! 89:
! 90: /*
! 91: * Used by new config, but we don't need it.
! 92: */
! 93: int
! 94: svr4_netattach(n)
! 95: int n;
! 96: {
! 97: return 0;
! 98: }
! 99:
! 100:
! 101: int
! 102: svr4_netopen(dev, flag, mode, p)
! 103: dev_t dev;
! 104: int flag;
! 105: int mode;
! 106: struct proc *p;
! 107: {
! 108: int type, protocol;
! 109: int fd;
! 110: struct file *fp;
! 111: struct socket *so;
! 112: int error;
! 113: int family;
! 114:
! 115: DPRINTF(("netopen("));
! 116:
! 117: if (p->p_dupfd >= 0)
! 118: return ENODEV;
! 119:
! 120: switch (minor(dev)) {
! 121: case dev_udp:
! 122: family = AF_INET;
! 123: type = SOCK_DGRAM;
! 124: protocol = IPPROTO_UDP;
! 125: DPRINTF(("udp, "));
! 126: break;
! 127:
! 128: case dev_tcp:
! 129: family = AF_INET;
! 130: type = SOCK_STREAM;
! 131: protocol = IPPROTO_TCP;
! 132: DPRINTF(("tcp, "));
! 133: break;
! 134:
! 135: case dev_ip:
! 136: case dev_rawip:
! 137: family = AF_INET;
! 138: type = SOCK_RAW;
! 139: protocol = IPPROTO_IP;
! 140: DPRINTF(("ip, "));
! 141: break;
! 142:
! 143: case dev_icmp:
! 144: family = AF_INET;
! 145: type = SOCK_RAW;
! 146: protocol = IPPROTO_ICMP;
! 147: DPRINTF(("icmp, "));
! 148: break;
! 149:
! 150: case dev_unix_dgram:
! 151: family = AF_UNIX;
! 152: type = SOCK_DGRAM;
! 153: protocol = 0;
! 154: DPRINTF(("unix-dgram, "));
! 155: break;
! 156:
! 157: case dev_unix_stream:
! 158: case dev_unix_ord_stream:
! 159: family = AF_UNIX;
! 160: type = SOCK_STREAM;
! 161: protocol = 0;
! 162: DPRINTF(("unix-stream, "));
! 163: break;
! 164:
! 165: default:
! 166: DPRINTF(("%d);\n", minor(dev)));
! 167: return EOPNOTSUPP;
! 168: }
! 169:
! 170: if ((error = falloc(p, &fp, &fd)) != 0)
! 171: return (error);
! 172:
! 173: if ((error = socreate(family, &so, type, protocol)) != 0) {
! 174: DPRINTF(("socreate error %d\n", error));
! 175: fdremove(p->p_fd, fd);
! 176: closef(fp, p);
! 177: return error;
! 178: }
! 179:
! 180: fp->f_flag = FREAD|FWRITE;
! 181: fp->f_type = DTYPE_SOCKET;
! 182: fp->f_ops = &svr4_netops;
! 183:
! 184: fp->f_data = (caddr_t)so;
! 185: (void) svr4_stream_get(fp);
! 186:
! 187: DPRINTF(("ok);\n"));
! 188:
! 189: p->p_dupfd = fd;
! 190: FILE_SET_MATURE(fp);
! 191: return ENXIO;
! 192: }
! 193:
! 194: static int
! 195: svr4_soo_close(fp, p)
! 196: struct file *fp;
! 197: struct proc *p;
! 198: {
! 199: struct socket *so = (struct socket *) fp->f_data;
! 200: svr4_delete_socket(p, fp);
! 201: free(so->so_internal, M_NETADDR);
! 202: return soo_close(fp, p);
! 203: }
! 204:
! 205: struct svr4_strm *
! 206: svr4_stream_get(fp)
! 207: struct file *fp;
! 208: {
! 209: struct socket *so;
! 210: struct svr4_strm *st;
! 211:
! 212: if (fp == NULL || fp->f_type != DTYPE_SOCKET)
! 213: return NULL;
! 214:
! 215: so = (struct socket *) fp->f_data;
! 216:
! 217: if (so->so_internal)
! 218: return so->so_internal;
! 219:
! 220: /* Allocate a new one. */
! 221: fp->f_ops = &svr4_netops;
! 222: st = malloc(sizeof(struct svr4_strm), M_NETADDR, M_WAITOK);
! 223: st->s_family = so->so_proto->pr_domain->dom_family;
! 224: st->s_cmd = ~0;
! 225: st->s_afd = -1;
! 226: so->so_internal = st;
! 227:
! 228: return st;
! 229: }
CVSweb