]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netinet6/natpt_log.c
1 /* $KAME: natpt_log.c,v 1.6 2000/03/25 07:23:55 sumikawa Exp $ */
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
33 #include <sys/errno.h>
34 #include <sys/param.h>
35 #include <sys/malloc.h>
37 #include <sys/socket.h>
38 #include <sys/types.h>
39 #include <sys/systm.h>
42 #include <netinet/in.h>
43 #include <netinet/in_systm.h>
44 #include <netinet/ip.h>
46 #include <netinet/ip6.h>
48 #include <netinet6/natpt_defs.h>
49 #include <netinet6/natpt_log.h>
50 #include <netinet6/natpt_var.h>
57 static struct sockaddr _natpt_dst
= {2, PF_INET
};
58 static struct sockaddr _natpt_src
= {2, PF_INET
};
61 struct mbuf
*natpt_lbuf
__P((int type
, int priorities
, size_t size
));
69 natpt_logMsg(int priorities
, void *item
, size_t size
)
71 natpt_log(LOG_MSG
, priorities
, item
, size
);
76 natpt_logMBuf(int priorities
, struct mbuf
*m
, char *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
));
85 natpt_logIp4(int priorities
, struct ip
*ip4
)
87 natpt_log(LOG_IP4
, priorities
, (void *)ip4
, sizeof(struct ip
)+8);
92 natpt_logIp6(int priorities
, struct ip6_hdr
*ip6
)
94 natpt_log(LOG_IP6
, priorities
, (void *)ip6
, sizeof(struct ip6_hdr
)+8);
99 natpt_log(int type
, int priorities
, void *item
, size_t size
)
101 struct sockproto proto
;
105 if ((m
= natpt_lbuf(type
, priorities
, size
)) == NULL
)
108 p
= (struct lbuf
*)m
->m_data
;
109 m_copyback(m
, sizeof(struct l_hdr
), p
->l_hdr
.lh_size
, (caddr_t
)item
);
111 proto
.sp_family
= AF_INET
;
112 proto
.sp_protocol
= IPPROTO_AHIP
;
113 natpt_input(m
, &proto
, &_natpt_src
, &_natpt_dst
);
120 natpt_logIN6addr(int priorities
, char *msg
, struct in6_addr
*sin6addr
)
126 msgsz
= strlen(msg
)+1;
127 size
= sizeof(struct l_hdr
) + IN6ADDRSZ
+ msgsz
;
129 m
= natpt_lbuf(LOG_IN6ADDR
, priorities
, size
);
134 struct sockproto proto
;
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';
141 proto
.sp_family
= AF_INET
;
142 proto
.sp_protocol
= IPPROTO_AHIP
;
143 natpt_input(m
, &proto
, &_natpt_src
, &_natpt_dst
);
151 natpt_lbuf(int type
, int priorities
, size_t size
)
156 MGETHDR(m
, M_NOWAIT
, MT_DATA
);
160 m
->m_pkthdr
.len
= m
->m_len
= MHLEN
;
161 m
->m_pkthdr
.rcvif
= NULL
;
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
);