|
|
1.1 root 1: /*
2: * Copyright (c) University of British Columbia, 1984
3: * Copyright (c) 1990 The Regents of the University of California.
4: * All rights reserved.
5: *
6: * This code is derived from software contributed to Berkeley by
7: * the Laboratory for Computation Vision and the Computer Science Department
8: * of the University of British Columbia.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * 3. All advertising materials mentioning features or use of this software
19: * must display the following acknowledgement:
20: * This product includes software developed by the University of
21: * California, Berkeley and its contributors.
22: * 4. Neither the name of the University nor the names of its contributors
23: * may be used to endorse or promote products derived from this software
24: * without specific prior written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36: * SUCH DAMAGE.
37: *
1.1.1.2 ! root 38: * from: @(#)pk_acct.c 7.6 (Berkeley) 6/26/91
! 39: * pk_acct.c,v 1.2 1993/05/20 04:12:15 cgd Exp
1.1 root 40: */
41:
42: #include "param.h"
43: #include "systm.h"
44: #include "namei.h"
45: #include "proc.h"
46: #include "vnode.h"
47: #include "kernel.h"
48: #include "file.h"
49: #include "socket.h"
50: #include "socketvar.h"
51:
52: #include "../net/if.h"
53:
54: #include "x25.h"
55: #include "pk.h"
56: #include "pk_var.h"
57: #include "x25acct.h"
58:
59:
60: struct vnode *pkacctp;
61: /*
62: * Turn on packet accounting
63: */
64:
65: pk_accton (path)
66: char *path;
67: {
68: register struct vnode *vp = NULL;
69: struct nameidata nd;
70: struct vnode *oacctp = pkacctp;
71: struct proc *p = curproc;
72: int error;
73:
74: if (path == 0)
75: goto close;
76: nd.ni_segflg = UIO_USERSPACE;
77: nd.ni_dirp = path;
78: if (error = vn_open (&nd, p, FWRITE, 0644))
79: return (error);
80: vp = nd.ni_vp;
81: VOP_UNLOCK(vp);
82: if (vp -> v_type != VREG) {
83: vrele (vp);
84: return (EACCES);
85: }
86: pkacctp = vp;
87: if (oacctp) {
88: close:
89: error = vn_close (oacctp, FWRITE, p -> p_ucred, p);
90: }
91: return (error);
92: }
93:
94: /*
95: * Write a record on the accounting file.
96: */
97:
98: pk_acct (lcp)
99: register struct pklcd *lcp;
100: {
101: register struct vnode *vp;
102: register struct sockaddr_x25 *sa;
103: register char *src, *dst;
104: register int len;
105: register long etime;
106: static struct x25acct acbuf;
107:
108: if ((vp = pkacctp) == 0)
109: return;
110: bzero ((caddr_t)&acbuf, sizeof (acbuf));
111: if (lcp -> lcd_ceaddr != 0)
112: sa = lcp -> lcd_ceaddr;
113: else if (lcp -> lcd_craddr != 0) {
114: sa = lcp -> lcd_craddr;
115: acbuf.x25acct_callin = 1;
116: } else
117: return;
118:
119: if (sa -> x25_opts.op_flags & X25_REVERSE_CHARGE)
120: acbuf.x25acct_revcharge = 1;
121: acbuf.x25acct_stime = lcp -> lcd_stime;
122: acbuf.x25acct_etime = time.tv_sec - acbuf.x25acct_stime;
123: acbuf.x25acct_uid = curproc -> p_cred -> p_ruid;
124: acbuf.x25acct_psize = sa -> x25_opts.op_psize;
125: acbuf.x25acct_net = sa -> x25_net;
126: /*
127: * Convert address to bcd
128: */
129: src = sa -> x25_addr;
130: dst = acbuf.x25acct_addr;
131: for (len = 0; *src; len++)
132: if (len & 01)
133: *dst++ |= *src++ & 0xf;
134: else
135: *dst = *src++ << 4;
136: acbuf.x25acct_addrlen = len;
137:
138: bcopy (sa -> x25_udata, acbuf.x25acct_udata,
139: sizeof (acbuf.x25acct_udata));
140: acbuf.x25acct_txcnt = lcp -> lcd_txcnt;
141: acbuf.x25acct_rxcnt = lcp -> lcd_rxcnt;
142:
143: (void) vn_rdwr(UIO_WRITE, vp, (caddr_t)&acbuf, sizeof (acbuf),
144: (off_t)0, UIO_SYSSPACE, IO_UNIT|IO_APPEND,
145: curproc -> p_ucred, (int *)0,
146: (struct proc *)0);
147: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.