1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #pragma ident "@(#)ip.d.in 1.2 07/07/02 SMI"
27
28 #pragma D depends_on module ip
29 #pragma D depends_on provider ip
30
31 inline int AF_INET = @AF_INET@;
32 #pragma D binding "1.0" AF_INET
33 inline int AF_INET6 = @AF_INET6@;
34 #pragma D binding "1.0" AF_INET6
35
36 #pragma D binding "1.0" IPPROTO_IP
37 inline int IPPROTO_IP = @IPPROTO_IP@;
38 #pragma D binding "1.0" IPPROTO_HOPOPTS
39 inline int IPPROTO_HOPOPTS = @IPPROTO_HOPOPTS@;
40 #pragma D binding "1.0" IPPROTO_ICMP
41 inline int IPPROTO_ICMP = @IPPROTO_ICMP@;
42 #pragma D binding "1.0" IPPROTO_IGMP
43 inline int IPPROTO_IGMP = @IPPROTO_IGMP@;
44 #pragma D binding "1.0" IPPROTO_GGP
45 inline int IPPROTO_GGP = @IPPROTO_GGP@;
46 #pragma D binding "1.0" IPPROTO_ENCAP
47 inline int IPPROTO_ENCAP = @IPPROTO_ENCAP@;
48 #pragma D binding "1.0" IPPROTO_TCP
49 inline int IPPROTO_TCP = @IPPROTO_TCP@;
50 #pragma D binding "1.0" IPPROTO_EGP
51 inline int IPPROTO_EGP = @IPPROTO_EGP@;
52 #pragma D binding "1.0" IPPROTO_PUP
53 inline int IPPROTO_PUP = @IPPROTO_PUP@;
54 #pragma D binding "1.0" IPPROTO_UDP
55 inline int IPPROTO_UDP = @IPPROTO_UDP@;
56 #pragma D binding "1.0" IPPROTO_IDP
57 inline int IPPROTO_IDP = @IPPROTO_IDP@;
58 #pragma D binding "1.0" IPPROTO_IPV6
59 inline int IPPROTO_IPV6 = @IPPROTO_IPV6@;
60 #pragma D binding "1.0" IPPROTO_ROUTING
61 inline int IPPROTO_ROUTING = @IPPROTO_ROUTING@;
62 #pragma D binding "1.0" IPPROTO_FRAGMENT
63 inline int IPPROTO_FRAGMENT = @IPPROTO_FRAGMENT@;
64 #pragma D binding "1.0" IPPROTO_RSVP
65 inline int IPPROTO_RSVP = @IPPROTO_RSVP@;
66 #pragma D binding "1.0" IPPROTO_ESP
67 inline int IPPROTO_ESP = @IPPROTO_ESP@;
68 #pragma D binding "1.0" IPPROTO_AH
69 inline int IPPROTO_AH = @IPPROTO_AH@;
70 #pragma D binding "1.0" IPPROTO_ICMPV6
71 inline int IPPROTO_ICMPV6 = @IPPROTO_ICMPV6@;
72 #pragma D binding "1.0" IPPROTO_NONE
73 inline int IPPROTO_NONE = @IPPROTO_NONE@;
74 #pragma D binding "1.0" IPPROTO_DSTOPTS
75 inline int IPPROTO_DSTOPTS = @IPPROTO_DSTOPTS@;
76 #pragma D binding "1.0" IPPROTO_HELLO
77 inline int IPPROTO_HELLO = @IPPROTO_HELLO@;
78 #pragma D binding "1.0" IPPROTO_ND
79 inline int IPPROTO_ND = @IPPROTO_ND@;
80 #pragma D binding "1.0" IPPROTO_EON
81 inline int IPPROTO_EON = @IPPROTO_EON@;
82 #pragma D binding "1.0" IPPROTO_OSPF
83 inline int IPPROTO_OSPF = @IPPROTO_OSPF@;
84 #pragma D binding "1.0" IPPROTO_PIM
85 inline int IPPROTO_PIM = @IPPROTO_PIM@;
86 #pragma D binding "1.0" IPPROTO_SCTP
87 inline int IPPROTO_SCTP = @IPPROTO_SCTP@;
88 #pragma D binding "1.0" IPPROTO_RAW
89 inline int IPPROTO_RAW = @IPPROTO_RAW@;
90 #pragma D binding "1.0" IPPROTO_MAX
91 inline int IPPROTO_MAX = @IPPROTO_MAX@;
92
93 inline int IP_FORWARD_PROG = @IP_FORWARD_PROG@;
94 #pragma D binding "1.0" IP_FORWARD_PROG
95
96 /*
97 * ipinfo contains common IP info for both IPv4 and IPv6.
98 */
99 typedef struct ipinfo {
100 uint8_t ip_ver; /* IP version (4, 6) */
101 uint16_t ip_plength; /* payload length */
102 string ip_saddr; /* source address */
103 string ip_daddr; /* destination address */
104 } ipinfo_t;
105
106 /*
107 * ipv4info is a translated version of the IPv4 header (with raw pointer).
108 */
109 typedef struct ipv4info {
110 uint8_t ipv4_ver;
111 uint8_t ipv4_ihl;
112 uint8_t ipv4_tos;
113 uint16_t ipv4_length;
114 uint16_t ipv4_ident;
115 uint8_t ipv4_flags;
116 uint16_t ipv4_offset;
117 uint8_t ipv4_ttl;
118 uint8_t ipv4_protocol;
119 uint16_t ipv4_checksum;
120 ipaddr_t ipv4_src;
121 ipaddr_t ipv4_dst;
122 string ipv4_saddr;
123 string ipv4_daddr;
124 ipha_t *ipv4_hdr;
125 } ipv4info_t;
126
127 /*
128 * ipv6info is a translated version of the IPv6 header (with raw pointer).
129 */
130 typedef struct ipv6info {
131 uint8_t ipv6_ver;
132 uint8_t ipv6_tclass;
133 uint32_t ipv6_flow;
134 uint16_t ipv6_plen;
135 uint8_t ipv6_next;
136 uint8_t ipv6_hlim;
137 in6_addr_t *ipv6_src;
138 in6_addr_t *ipv6_dst;
139 string ipv6_saddr;
140 string ipv6_daddr;
141 ip6_t *ipv6_hdr;
142 } ipv6info_t;
143
144 /*
145 * illinfo contains IP Lower Layer info.
146 */
147 typedef struct illinfo {
148 string ill_name;
149 netstackid_t ill_ipstack;
150 uintptr_t ill_addr;
151 } illinfo_t;
152
153 /*
154 * void_ip_t is a void pointer to either an IPv4 or IPv6 header. It has
155 * it's own type name so that a translator can be determined.
156 */
157 typedef uintptr_t void_ip_t;
158
159 #pragma D binding "1.0" translator
160 translator ipinfo_t < ipha_t *I > {
161 ip_ver = I->ipha_version_and_hdr_length >> 4;
162 ip_plength = ntohs(I->ipha_length) -
163 ((I->ipha_version_and_hdr_length & 0xf) << 2);
164 ip_saddr = inet_ntoa(&I->ipha_src);
165 ip_daddr = inet_ntoa(&I->ipha_dst);
166 };
167
168 #pragma D binding "1.0" translator
169 translator ipinfo_t < ip6_t *I > {
170 ip_ver = (*(uint8_t *)I & ~IP_FORWARD_PROG) >> 4;
171 ip_plength = ntohs(I->ip6_ctlun.ip6_un1.ip6_un1_plen);
172 ip_saddr = inet_ntoa6(&I->ip6_src);
173 ip_daddr = inet_ntoa6(&I->ip6_dst);
174 };
175
176 #pragma D binding "1.0" translator
177 translator ipinfo_t < void_ip_t *I > {
178 ip_ver = I != NULL ? (*(uint8_t *)I & ~IP_FORWARD_PROG) >> 4 : 0;
179 ip_plength = I != NULL ? ((*(uint8_t *)I & ~IP_FORWARD_PROG) >> 4 == 4
180 ? ntohs(((ipha_t *)I)->ipha_length) -
181 ((((ipha_t *)I)->ipha_version_and_hdr_length & 0xf) << 2) :
182 (*(uint8_t *)I & ~IP_FORWARD_PROG) >> 4 == 6 ?
183 ntohs(((ip6_t *)I)->ip6_ctlun.ip6_un1.ip6_un1_plen) : 0) : 0;
184 ip_saddr = I != NULL ? ((*(uint8_t *)I & ~IP_FORWARD_PROG) >> 4 == 4 ?
185 inet_ntoa(&((ipha_t *)I)->ipha_src) :
186 (*(uint8_t *)I & ~IP_FORWARD_PROG) >> 4 == 6 ?
187 inet_ntoa6(&((ip6_t *)I)->ip6_src) : "<unknown>") : "<unknown>";
188 ip_daddr = I != NULL ? ((*(uint8_t *)I & ~IP_FORWARD_PROG) >> 4 == 4 ?
189 inet_ntoa(&((ipha_t *)I)->ipha_dst) :
190 (*(uint8_t *)I & ~IP_FORWARD_PROG) >> 4 == 6 ?
191 inet_ntoa6(&((ip6_t *)I)->ip6_dst) : "<unknown>") : "<unknown>";
192 };
193
194 #pragma D binding "1.0" translator
195 translator ipv4info_t < ipha_t *I > {
196 ipv4_ver = I != NULL ? I->ipha_version_and_hdr_length >> 4 : 0;
197 ipv4_ihl = I != NULL ? I->ipha_version_and_hdr_length & 0xf : 0;
198 ipv4_tos = I != NULL ? I->ipha_type_of_service : 0;
199 ipv4_length = I != NULL ? ntohs(I->ipha_length) : 0;
200 ipv4_ident = I != NULL ? ntohs(I->ipha_ident) : 0;
201 ipv4_flags = I != NULL ? ntohs(I->ipha_fragment_offset_and_flags) >>
202 12 : 0;
203 ipv4_offset = I != NULL ? ntohs(I->ipha_fragment_offset_and_flags) &
204 0x0fff : 0;
205 ipv4_ttl = I != NULL ? I->ipha_ttl : 0;
206 ipv4_protocol = I != NULL ? I->ipha_protocol : 0;
207 ipv4_checksum = I != NULL ? ntohs(I->ipha_hdr_checksum) : 0;
208 ipv4_src = I != NULL ? I->ipha_src : 0;
209 ipv4_dst = I != NULL ? I->ipha_dst : 0;
210 ipv4_saddr = I != NULL ? inet_ntoa(&I->ipha_src) : "<null>";
211 ipv4_daddr = I != NULL ? inet_ntoa(&I->ipha_dst) : "<null>";
212 ipv4_hdr = I;
213 };
214
215 #pragma D binding "1.0" translator
216 translator ipv6info_t < ip6_t *I > {
217 ipv6_ver = I != NULL ? I->ip6_ctlun.ip6_un2_vfc >> 4 : 0;
218 ipv6_tclass = I != NULL ? ((I->ip6_ctlun.ip6_un1.ip6_un1_flow &&
219 0x0fffffff) >> 20) : 0;
220 ipv6_flow = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_flow &&
221 0x000fffff : 0;
222 ipv6_plen = I != NULL ? ntohs(I->ip6_ctlun.ip6_un1.ip6_un1_plen) : 0;
223 ipv6_next = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_nxt : 0;
224 ipv6_hlim = I != NULL ? I->ip6_ctlun.ip6_un1.ip6_un1_hlim : 0;
225 ipv6_src = I != NULL ? &I->ip6_src : 0;
226 ipv6_dst = I != NULL ? &I->ip6_dst : 0;
227 ipv6_saddr = I != NULL ? inet_ntoa6(&I->ip6_src) : "<null>";
228 ipv6_daddr = I != NULL ? inet_ntoa6(&I->ip6_dst) : "<null>";
229 ipv6_hdr = I;
230 };
231
232 #pragma D binding "1.0" translator
233 translator illinfo_t < ill_t *I > {
234 ill_name = I != NULL ? stringof(I->ill_name) : "<null>";
235 ill_ipstack = I != NULL ? I->ill_ipst->ips_netstack->netstack_stackid
236 : 0;
237 ill_addr = (uintptr_t)I;
238 };