]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* $KAME: natpt_log.c,v 1.6 2000/03/25 07:23:55 sumikawa Exp $ */ |
2 | ||
3 | /* | |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
5 | * All rights reserved. | |
6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3. Neither the name of the project nor the names of its contributors | |
16 | * may be used to endorse or promote products derived from this software | |
17 | * without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | |
30 | * | |
31 | */ | |
32 | ||
33 | #include <sys/errno.h> | |
34 | #include <sys/param.h> | |
35 | #include <sys/malloc.h> | |
36 | #include <sys/mbuf.h> | |
37 | #include <sys/socket.h> | |
38 | #include <sys/types.h> | |
39 | #include <sys/systm.h> | |
40 | ||
41 | #include <net/if.h> | |
42 | #include <netinet/in.h> | |
43 | #include <netinet/in_systm.h> | |
44 | #include <netinet/ip.h> | |
45 | ||
46 | #include <netinet/ip6.h> | |
47 | ||
48 | #include <netinet6/natpt_defs.h> | |
49 | #include <netinet6/natpt_log.h> | |
50 | #include <netinet6/natpt_var.h> | |
51 | ||
52 | ||
53 | /* | |
54 | * | |
55 | */ | |
56 | ||
57 | static struct sockaddr _natpt_dst = {2, PF_INET}; | |
58 | static struct sockaddr _natpt_src = {2, PF_INET}; | |
59 | ||
60 | ||
61 | struct mbuf *natpt_lbuf __P((int type, int priorities, size_t size)); | |
62 | ||
63 | ||
64 | /* | |
65 | * | |
66 | */ | |
67 | ||
68 | void | |
69 | natpt_logMsg(int priorities, void *item, size_t size) | |
70 | { | |
71 | natpt_log(LOG_MSG, priorities, item, size); | |
72 | } | |
73 | ||
74 | ||
75 | void | |
76 | natpt_logMBuf(int priorities, struct mbuf *m, char *msg) | |
77 | { | |
78 | if (msg) | |
79 | natpt_log(LOG_MSG, priorities, (void *)msg, strlen(msg)+1); | |
80 | natpt_log(LOG_MBUF, priorities, (void *)m->m_data, min(m->m_len, LBFSZ)); | |
81 | } | |
82 | ||
83 | ||
84 | void | |
85 | natpt_logIp4(int priorities, struct ip *ip4) | |
86 | { | |
87 | natpt_log(LOG_IP4, priorities, (void *)ip4, sizeof(struct ip)+8); | |
88 | } | |
89 | ||
90 | ||
91 | void | |
92 | natpt_logIp6(int priorities, struct ip6_hdr *ip6) | |
93 | { | |
94 | natpt_log(LOG_IP6, priorities, (void *)ip6, sizeof(struct ip6_hdr)+8); | |
95 | } | |
96 | ||
97 | ||
98 | int | |
99 | natpt_log(int type, int priorities, void *item, size_t size) | |
100 | { | |
101 | struct sockproto proto; | |
102 | struct mbuf *m; | |
103 | struct lbuf *p; | |
104 | ||
105 | if ((m = natpt_lbuf(type, priorities, size)) == NULL) | |
106 | return (ENOBUFS); | |
107 | ||
108 | p = (struct lbuf *)m->m_data; | |
109 | m_copyback(m, sizeof(struct l_hdr), p->l_hdr.lh_size, (caddr_t)item); | |
110 | ||
111 | proto.sp_family = AF_INET; | |
112 | proto.sp_protocol = IPPROTO_AHIP; | |
113 | natpt_input(m, &proto, &_natpt_src, &_natpt_dst); | |
114 | ||
115 | return (0); | |
116 | } | |
117 | ||
118 | ||
119 | int | |
120 | natpt_logIN6addr(int priorities, char *msg, struct in6_addr *sin6addr) | |
121 | { | |
122 | int size, msgsz; | |
123 | struct mbuf *m; | |
124 | struct lbuf *p; | |
125 | ||
126 | msgsz = strlen(msg)+1; | |
127 | size = sizeof(struct l_hdr) + IN6ADDRSZ + msgsz; | |
128 | ||
129 | m = natpt_lbuf(LOG_IN6ADDR, priorities, size); | |
130 | if (m == NULL) | |
131 | return (ENOBUFS); | |
132 | ||
133 | { | |
134 | struct sockproto proto; | |
135 | ||
136 | p = (struct lbuf *)m->m_pktdat; | |
137 | bcopy(sin6addr, p->l_addr.in6addr, sizeof(struct in6_addr)); | |
138 | strncpy(p->l_msg, msg, min(msgsz, MSGSZ-1)); | |
139 | p->l_msg[MSGSZ-1] = '\0'; | |
140 | ||
141 | proto.sp_family = AF_INET; | |
142 | proto.sp_protocol = IPPROTO_AHIP; | |
143 | natpt_input(m, &proto, &_natpt_src, &_natpt_dst); | |
144 | } | |
145 | ||
146 | return (0); | |
147 | } | |
148 | ||
149 | ||
150 | struct mbuf * | |
151 | natpt_lbuf(int type, int priorities, size_t size) | |
152 | { | |
153 | struct mbuf *m; | |
154 | struct lbuf *p; | |
155 | ||
156 | MGETHDR(m, M_NOWAIT, MT_DATA); | |
157 | if (m == NULL) | |
158 | return (NULL); | |
159 | ||
160 | m->m_pkthdr.len = m->m_len = MHLEN; | |
161 | m->m_pkthdr.rcvif = NULL; | |
162 | ||
163 | p = (struct lbuf *)m->m_data; | |
164 | p->l_hdr.lh_type = type; | |
165 | p->l_hdr.lh_pri = priorities; | |
166 | p->l_hdr.lh_size = size; | |
167 | microtime((struct timeval *)&p->l_hdr.lh_sec); | |
168 | ||
169 | return (m); | |
170 | } |