1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 #ifndef _NETINET_IN_PCB_H_
65 #define _NETINET_IN_PCB_H_
66
67 #include <sys/queue.h>
68 #include <netinet/ip6.h>
69 #include <netinet6/ip6_var.h>
70 #include <netinet/icmp6.h>
71 #include <netinet/ip_ipsp.h>
72
73 union inpaddru {
74 struct in6_addr iau_addr6;
75 struct {
76 uint8_t pad[12];
77 struct in_addr inaddr;
78 } iau_a4u;
79 };
80
81
82
83
84
85
86
87
88 struct inpcb {
89 LIST_ENTRY(inpcb) inp_hash;
90 LIST_ENTRY(inpcb) inp_lhash;
91 CIRCLEQ_ENTRY(inpcb) inp_queue;
92 struct inpcbtable *inp_table;
93 union inpaddru inp_faddru;
94 union inpaddru inp_laddru;
95 #define inp_faddr inp_faddru.iau_a4u.inaddr
96 #define inp_faddr6 inp_faddru.iau_addr6
97 #define inp_laddr inp_laddru.iau_a4u.inaddr
98 #define inp_laddr6 inp_laddru.iau_addr6
99 u_int16_t inp_fport;
100 u_int16_t inp_lport;
101 struct socket *inp_socket;
102 caddr_t inp_ppcb;
103 union {
104 struct route ru_route;
105 struct route_in6 ru_route6;
106 } inp_ru;
107 #define inp_route inp_ru.ru_route
108 #define inp_route6 inp_ru.ru_route6
109 int inp_flags;
110 union {
111 struct ip hu_ip;
112 struct ip6_hdr hu_ipv6;
113 } inp_hu;
114 #define inp_ip inp_hu.hu_ip
115 #define inp_ipv6 inp_hu.hu_ipv6
116 struct mbuf *inp_options;
117 struct ip6_pktopts *inp_outputopts6;
118 int inp_hops;
119 union {
120 struct ip_moptions *mou_mo;
121 struct ip6_moptions *mou_mo6;
122 } inp_mou;
123 #define inp_moptions inp_mou.mou_mo
124 #define inp_moptions6 inp_mou.mou_mo6
125 u_char inp_seclevel[4];
126 #define SL_AUTH 0
127 #define SL_ESP_TRANS 1
128 #define SL_ESP_NETWORK 2
129 #define SL_IPCOMP 3
130 u_int inp_secrequire:4,
131 inp_secresult:4;
132 #define SR_FAILED 1
133 #define SR_SUCCESS 2
134 #define SR_WAIT 3
135 u_char inp_ip_minttl;
136 TAILQ_ENTRY(inpcb) inp_tdb_in_next, inp_tdb_out_next;
137 struct tdb *inp_tdb_in, *inp_tdb_out;
138 struct ipsec_policy *inp_ipo;
139 struct ipsec_ref *inp_ipsec_remotecred;
140 struct ipsec_ref *inp_ipsec_remoteauth;
141 #define inp_flowinfo inp_hu.hu_ipv6.ip6_flow
142
143 int in6p_cksum;
144 #ifndef _KERNEL
145 #define inp_csumoffset in6p_cksum
146 #endif
147 struct icmp6_filter *inp_icmp6filt;
148 };
149
150 struct inpcbtable {
151 CIRCLEQ_HEAD(, inpcb) inpt_queue;
152 LIST_HEAD(inpcbhead, inpcb) *inpt_hashtbl, *inpt_lhashtbl;
153 u_long inpt_hash, inpt_lhash;
154 u_int16_t inpt_lastport;
155 };
156
157
158 #define INP_RECVOPTS 0x001
159 #define INP_RECVRETOPTS 0x002
160 #define INP_RECVDSTADDR 0x004
161
162 #define INP_RXDSTOPTS INP_RECVOPTS
163 #define INP_RXHOPOPTS INP_RECVRETOPTS
164 #define INP_RXINFO INP_RECVDSTADDR
165 #define INP_RXSRCRT 0x010
166 #define INP_HOPLIMIT 0x020
167
168 #define INP_HDRINCL 0x008
169 #define INP_HIGHPORT 0x010
170 #define INP_LOWPORT 0x020
171 #define INP_RECVIF 0x080
172 #define INP_RECVTTL 0x040
173
174 #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR| \
175 INP_RXSRCRT|INP_HOPLIMIT|INP_RECVIF|INP_RECVTTL)
176
177
178
179
180
181 #define INP_IPV6 0x100
182
183 #if 1
184
185
186
187
188
189
190 #define IN6P_HIGHPORT INP_HIGHPORT
191 #define IN6P_LOWPORT INP_LOWPORT
192 #define IN6P_PKTINFO 0x010000
193 #define IN6P_HOPLIMIT 0x020000
194 #define IN6P_HOPOPTS 0x040000
195 #define IN6P_DSTOPTS 0x080000
196 #define IN6P_RTHDR 0x100000
197 #define IN6P_RTHDRDSTOPTS 0x200000
198 #define IN6P_TCLASS 0x400000
199 #define IN6P_AUTOFLOWLABEL 0x800000
200
201 #define IN6P_ANONPORT 0x4000000
202 #define IN6P_FAITH 0x8000000
203 #define IN6P_RFC2292 0x40000000
204 #define IN6P_MTU 0x80000000
205
206 #define IN6P_MINMTU 0x20000000
207
208 #define IN6P_CONTROLOPTS (IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
209 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
210 IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\
211 IN6P_MTU)
212 #endif
213
214 #define INPLOOKUP_WILDCARD 1
215 #define INPLOOKUP_SETLOCAL 2
216 #define INPLOOKUP_IPV6 4
217
218 #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
219
220
221 #define DP_MAPBITS (sizeof(u_int32_t) * NBBY)
222 #define DP_MAPSIZE (howmany(IPPORT_RESERVED/2, DP_MAPBITS))
223 #define DP_SET(m, p) ((m)[((p) - IPPORT_RESERVED/2) / DP_MAPBITS] |= (1 << ((p) % DP_MAPBITS)))
224 #define DP_CLR(m, p) ((m)[((p) - IPPORT_RESERVED/2) / DP_MAPBITS] &= ~(1 << ((p) % DP_MAPBITS)))
225 #define DP_ISSET(m, p) ((m)[((p) - IPPORT_RESERVED/2) / DP_MAPBITS] & (1 << ((p) % DP_MAPBITS)))
226
227
228 #define DEFBADDYNAMICPORTS_TCP { 587, 749, 750, 751, 871, 0 }
229 #define DEFBADDYNAMICPORTS_UDP { 623, 664, 749, 750, 751, 0 }
230
231 struct baddynamicports {
232 u_int32_t tcp[DP_MAPSIZE];
233 u_int32_t udp[DP_MAPSIZE];
234 };
235
236 #ifdef _KERNEL
237
238 #define sotopf(so) (so->so_proto->pr_domain->dom_family)
239
240 void in_losing(struct inpcb *);
241 int in_pcballoc(struct socket *, void *);
242 int in_pcbbind(void *, struct mbuf *);
243 int in_pcbconnect(void *, struct mbuf *);
244 void in_pcbdetach(void *);
245 void in_pcbdisconnect(void *);
246 struct inpcb *
247 in_pcbhashlookup(struct inpcbtable *, struct in_addr,
248 u_int, struct in_addr, u_int);
249 struct inpcb *
250 in_pcblookup_listen(struct inpcbtable *, struct in_addr, u_int, int);
251 #ifdef INET6
252 struct inpcb *
253 in6_pcbhashlookup(struct inpcbtable *, struct in6_addr *,
254 u_int, struct in6_addr *, u_int);
255 struct inpcb *
256 in6_pcblookup_listen(struct inpcbtable *,
257 struct in6_addr *, u_int, int);
258 int in6_pcbbind(struct inpcb *, struct mbuf *);
259 int in6_pcbconnect(struct inpcb *, struct mbuf *);
260 int in6_setsockaddr(struct inpcb *, struct mbuf *);
261 int in6_setpeeraddr(struct inpcb *, struct mbuf *);
262 #endif
263 void in_pcbinit(struct inpcbtable *, int);
264 struct inpcb *
265 in_pcblookup(struct inpcbtable *, void *, u_int, void *,
266 u_int, int);
267 void in_pcbnotifyall(struct inpcbtable *, struct sockaddr *,
268 int, void (*)(struct inpcb *, int));
269 void in_pcbrehash(struct inpcb *);
270 void in_rtchange(struct inpcb *, int);
271 void in_setpeeraddr(struct inpcb *, struct mbuf *);
272 void in_setsockaddr(struct inpcb *, struct mbuf *);
273 int in_baddynamic(u_int16_t, u_int16_t);
274 extern struct sockaddr_in *in_selectsrc(struct sockaddr_in *,
275 struct route *, int, struct ip_moptions *, int *);
276 struct rtentry *
277 in_pcbrtentry(struct inpcb *);
278
279
280 int in6_pcbnotify(struct inpcbtable *, struct sockaddr *,
281 u_int, struct sockaddr *, u_int, int, void *,
282 void (*)(struct inpcb *, int));
283 int in6_selecthlim(struct inpcb *, struct ifnet *);
284 int in6_pcbsetport(struct in6_addr *, struct inpcb *, struct proc *);
285 #endif
286 #endif