kernel - Replace zalloc zones with kmalloc for PCBs
[dragonfly.git] / sys / netinet / raw_ip.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1982, 1986, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)raw_ip.c 8.7 (Berkeley) 5/15/95
f1f552f6 34 * $FreeBSD: src/sys/netinet/raw_ip.c,v 1.64.2.16 2003/08/24 08:24:38 hsu Exp $
47d96de7 35 * $DragonFly: src/sys/netinet/raw_ip.c,v 1.33 2008/10/28 03:07:28 sephe Exp $
984263bc
MD
36 */
37
38#include "opt_inet6.h"
39#include "opt_ipsec.h"
984263bc
MD
40
41#include <sys/param.h>
42#include <sys/systm.h>
43#include <sys/kernel.h>
7b09fb68 44#include <sys/jail.h>
984263bc
MD
45#include <sys/malloc.h>
46#include <sys/mbuf.h>
47#include <sys/proc.h>
895c1f85 48#include <sys/priv.h>
984263bc
MD
49#include <sys/protosw.h>
50#include <sys/socket.h>
51#include <sys/socketvar.h>
52#include <sys/sysctl.h>
1cae611f 53#include <sys/thread2.h>
984263bc 54
deffea2e
JS
55#include <machine/stdarg.h>
56
984263bc
MD
57#include <net/if.h>
58#include <net/route.h>
59
60#define _IP_VHL
61#include <netinet/in.h>
62#include <netinet/in_systm.h>
63#include <netinet/ip.h>
64#include <netinet/in_pcb.h>
65#include <netinet/in_var.h>
66#include <netinet/ip_var.h>
984263bc 67
1f2de5d4
MD
68#include <net/ip_mroute/ip_mroute.h>
69#include <net/ipfw/ip_fw.h>
70#include <net/dummynet/ip_dummynet.h>
984263bc
MD
71
72#ifdef FAST_IPSEC
bf844ffa 73#include <netproto/ipsec/ipsec.h>
984263bc
MD
74#endif /*FAST_IPSEC*/
75
76#ifdef IPSEC
77#include <netinet6/ipsec.h>
78#endif /*IPSEC*/
79
984263bc
MD
80struct inpcbinfo ripcbinfo;
81
82/* control hooks for ipfw and dummynet */
83ip_fw_ctl_t *ip_fw_ctl_ptr;
84ip_dn_ctl_t *ip_dn_ctl_ptr;
85
86/*
87 * hooks for multicast routing. They all default to NULL,
88 * so leave them not initialized and rely on BSS being set to 0.
89 */
90
91/* The socket used to communicate with the multicast routing daemon. */
92struct socket *ip_mrouter;
93
94/* The various mrouter and rsvp functions */
95int (*ip_mrouter_set)(struct socket *, struct sockopt *);
96int (*ip_mrouter_get)(struct socket *, struct sockopt *);
97int (*ip_mrouter_done)(void);
98int (*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *,
99 struct ip_moptions *);
100int (*mrt_ioctl)(int, caddr_t);
101int (*legal_vif_num)(int);
102u_long (*ip_mcast_src)(int);
103
a00138cb 104void (*rsvp_input_p)(struct mbuf *m, ...);
984263bc
MD
105int (*ip_rsvp_vif)(struct socket *, struct sockopt *);
106void (*ip_rsvp_force_done)(struct socket *);
107
108/*
109 * Nominal space allocated to a raw ip socket.
110 */
111#define RIPSNDQ 8192
112#define RIPRCVQ 8192
113
114/*
115 * Raw interface to IP protocol.
116 */
117
118/*
119 * Initialize raw connection block queue.
120 */
121void
122rip_init(void)
123{
d2e9e54c 124 in_pcbinfo_init(&ripcbinfo);
984263bc
MD
125 /*
126 * XXX We don't use the hash list for raw IP, but it's easier
127 * to allocate a one entry hash list than it is to check all
128 * over the place for hashbase == NULL.
129 */
130 ripcbinfo.hashbase = hashinit(1, M_PCB, &ripcbinfo.hashmask);
131 ripcbinfo.porthashbase = hashinit(1, M_PCB, &ripcbinfo.porthashmask);
2322f6ca
JH
132 ripcbinfo.wildcardhashbase = hashinit(1, M_PCB,
133 &ripcbinfo.wildcardhashmask);
9f42c129 134 ripcbinfo.ipi_size = sizeof(struct inpcb);
984263bc
MD
135}
136
984263bc
MD
137/*
138 * Setup generic address and protocol structures
139 * for raw_input routine, then pass them along with
140 * mbuf chain.
141 */
142void
a00138cb 143rip_input(struct mbuf *m, ...)
984263bc 144{
668488bd 145 struct sockaddr_in ripsrc = { sizeof ripsrc, AF_INET };
984263bc
MD
146 struct ip *ip = mtod(m, struct ip *);
147 struct inpcb *inp;
148 struct inpcb *last = NULL;
149 struct mbuf *opts = NULL;
a00138cb
JS
150 int off, proto;
151 __va_list ap;
152
153 __va_start(ap, m);
154 off = __va_arg(ap, int);
155 proto = __va_arg(ap, int);
156 __va_end(ap);
984263bc
MD
157
158 ripsrc.sin_addr = ip->ip_src;
d2e9e54c
MD
159 LIST_FOREACH(inp, &ripcbinfo.pcblisthead, inp_list) {
160 if (inp->inp_flags & INP_PLACEMARKER)
161 continue;
984263bc
MD
162#ifdef INET6
163 if ((inp->inp_vflag & INP_IPV4) == 0)
164 continue;
165#endif
166 if (inp->inp_ip_p && inp->inp_ip_p != proto)
167 continue;
168 if (inp->inp_laddr.s_addr != INADDR_ANY &&
169 inp->inp_laddr.s_addr != ip->ip_dst.s_addr)
170 continue;
171 if (inp->inp_faddr.s_addr != INADDR_ANY &&
172 inp->inp_faddr.s_addr != ip->ip_src.s_addr)
173 continue;
174 if (last) {
74f1caca 175 struct mbuf *n = m_copypacket(m, MB_DONTWAIT);
984263bc
MD
176
177#ifdef IPSEC
178 /* check AH/ESP integrity. */
179 if (n && ipsec4_in_reject_so(n, last->inp_socket)) {
180 m_freem(n);
181 ipsecstat.in_polvio++;
182 /* do not inject data to pcb */
183 } else
184#endif /*IPSEC*/
185#ifdef FAST_IPSEC
186 /* check AH/ESP integrity. */
187 if (ipsec4_in_reject(n, last)) {
188 m_freem(n);
189 /* do not inject data to pcb */
190 } else
191#endif /*FAST_IPSEC*/
192 if (n) {
193 if (last->inp_flags & INP_CONTROLOPTS ||
194 last->inp_socket->so_options & SO_TIMESTAMP)
195 ip_savecontrol(last, &opts, ip, n);
6d49aa6f 196 if (ssb_appendaddr(&last->inp_socket->so_rcv,
984263bc
MD
197 (struct sockaddr *)&ripsrc, n,
198 opts) == 0) {
199 /* should notify about lost packet */
200 m_freem(n);
201 if (opts)
202 m_freem(opts);
203 } else
204 sorwakeup(last->inp_socket);
205 opts = 0;
206 }
207 }
208 last = inp;
209 }
210#ifdef IPSEC
211 /* check AH/ESP integrity. */
212 if (last && ipsec4_in_reject_so(m, last->inp_socket)) {
213 m_freem(m);
214 ipsecstat.in_polvio++;
215 ipstat.ips_delivered--;
216 /* do not inject data to pcb */
217 } else
218#endif /*IPSEC*/
219#ifdef FAST_IPSEC
220 /* check AH/ESP integrity. */
221 if (last && ipsec4_in_reject(m, last)) {
222 m_freem(m);
223 ipstat.ips_delivered--;
224 /* do not inject data to pcb */
225 } else
226#endif /*FAST_IPSEC*/
95926362
MD
227 /* Check the minimum TTL for socket. */
228 if (last && ip->ip_ttl < last->inp_ip_minttl) {
229 m_freem(opts);
230 ipstat.ips_delivered--;
231 } else if (last) {
984263bc
MD
232 if (last->inp_flags & INP_CONTROLOPTS ||
233 last->inp_socket->so_options & SO_TIMESTAMP)
234 ip_savecontrol(last, &opts, ip, m);
6d49aa6f 235 if (ssb_appendaddr(&last->inp_socket->so_rcv,
984263bc
MD
236 (struct sockaddr *)&ripsrc, m, opts) == 0) {
237 m_freem(m);
238 if (opts)
239 m_freem(opts);
240 } else
241 sorwakeup(last->inp_socket);
242 } else {
243 m_freem(m);
244 ipstat.ips_noproto++;
245 ipstat.ips_delivered--;
246 }
247}
248
249/*
250 * Generate IP header and pass packet to ip_output.
251 * Tack on options user may have setup with control call.
252 */
253int
deffea2e 254rip_output(struct mbuf *m, struct socket *so, ...)
984263bc
MD
255{
256 struct ip *ip;
ed894f8c 257 struct inpcb *inp = so->so_pcb;
deffea2e 258 __va_list ap;
984263bc 259 int flags = (so->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST;
deffea2e
JS
260 u_long dst;
261
262 __va_start(ap, so);
263 dst = __va_arg(ap, u_long);
264 __va_end(ap);
984263bc
MD
265
266 /*
267 * If the user handed us a complete IP packet, use it.
268 * Otherwise, allocate an mbuf for a header and fill it in.
269 */
270 if ((inp->inp_flags & INP_HDRINCL) == 0) {
271 if (m->m_pkthdr.len + sizeof(struct ip) > IP_MAXPACKET) {
272 m_freem(m);
273 return(EMSGSIZE);
274 }
74f1caca 275 M_PREPEND(m, sizeof(struct ip), MB_WAIT);
0cc6c79e
HP
276 if (m == NULL)
277 return(ENOBUFS);
984263bc
MD
278 ip = mtod(m, struct ip *);
279 ip->ip_tos = inp->inp_ip_tos;
280 ip->ip_off = 0;
281 ip->ip_p = inp->inp_ip_p;
282 ip->ip_len = m->m_pkthdr.len;
283 ip->ip_src = inp->inp_laddr;
284 ip->ip_dst.s_addr = dst;
285 ip->ip_ttl = inp->inp_ip_ttl;
286 } else {
47d96de7
SZ
287 int hlen;
288
984263bc
MD
289 if (m->m_pkthdr.len > IP_MAXPACKET) {
290 m_freem(m);
291 return(EMSGSIZE);
292 }
47d96de7
SZ
293 if (m->m_len < sizeof(struct ip)) {
294 m = m_pullup(m, sizeof(struct ip));
295 if (m == NULL)
296 return ENOBUFS;
297 }
984263bc 298 ip = mtod(m, struct ip *);
47d96de7
SZ
299 hlen = IP_VHL_HL(ip->ip_vhl) << 2;
300
301 /* Don't allow header length less than the minimum. */
302 if (hlen < sizeof(struct ip)) {
303 m_freem(m);
304 return EINVAL;
305 }
306
307 /*
308 * Don't allow both user specified and setsockopt options.
309 * Don't allow packet length sizes that will crash.
310 */
311 if ((hlen != sizeof(struct ip) && inp->inp_options) ||
312 ip->ip_len > m->m_pkthdr.len || ip->ip_len < hlen) {
984263bc
MD
313 m_freem(m);
314 return EINVAL;
315 }
316 if (ip->ip_id == 0)
6277137d 317 ip->ip_id = ip_newid();
47d96de7
SZ
318
319 /* Prevent ip_output from overwriting header fields */
984263bc
MD
320 flags |= IP_RAWOUTPUT;
321 ipstat.ips_rawout++;
322 }
323
47d96de7
SZ
324 return ip_output(m, inp->inp_options, &inp->inp_route, flags,
325 inp->inp_moptions, inp);
984263bc
MD
326}
327
328/*
329 * Raw IP socket option processing.
330 */
331int
332rip_ctloutput(struct socket *so, struct sockopt *sopt)
333{
ed894f8c 334 struct inpcb *inp = so->so_pcb;
984263bc
MD
335 int error, optval;
336
337 if (sopt->sopt_level != IPPROTO_IP)
338 return (EINVAL);
339
340 error = 0;
341
342 switch (sopt->sopt_dir) {
343 case SOPT_GET:
344 switch (sopt->sopt_name) {
345 case IP_HDRINCL:
346 optval = inp->inp_flags & INP_HDRINCL;
0d9bd372 347 soopt_from_kbuf(sopt, &optval, sizeof optval);
984263bc
MD
348 break;
349
350 case IP_FW_ADD: /* ADD actually returns the body... */
351 case IP_FW_GET:
352 if (IPFW_LOADED)
aed810cb 353 error = ip_fw_sockopt(sopt);
984263bc
MD
354 else
355 error = ENOPROTOOPT;
356 break;
357
358 case IP_DUMMYNET_GET:
879652a3 359 error = ip_dn_sockopt(sopt);
984263bc
MD
360 break ;
361
362 case MRT_INIT:
363 case MRT_DONE:
364 case MRT_ADD_VIF:
365 case MRT_DEL_VIF:
366 case MRT_ADD_MFC:
367 case MRT_DEL_MFC:
368 case MRT_VERSION:
369 case MRT_ASSERT:
f1f552f6
JH
370 case MRT_API_SUPPORT:
371 case MRT_API_CONFIG:
372 case MRT_ADD_BW_UPCALL:
373 case MRT_DEL_BW_UPCALL:
984263bc
MD
374 error = ip_mrouter_get ? ip_mrouter_get(so, sopt) :
375 EOPNOTSUPP;
376 break;
377
378 default:
379 error = ip_ctloutput(so, sopt);
380 break;
381 }
382 break;
383
384 case SOPT_SET:
385 switch (sopt->sopt_name) {
386 case IP_HDRINCL:
0d9bd372
HT
387 error = soopt_to_kbuf(sopt, &optval, sizeof optval,
388 sizeof optval);
984263bc
MD
389 if (error)
390 break;
391 if (optval)
392 inp->inp_flags |= INP_HDRINCL;
393 else
394 inp->inp_flags &= ~INP_HDRINCL;
395 break;
396
397 case IP_FW_ADD:
398 case IP_FW_DEL:
399 case IP_FW_FLUSH:
400 case IP_FW_ZERO:
401 case IP_FW_RESETLOG:
402 if (IPFW_LOADED)
403 error = ip_fw_ctl_ptr(sopt);
404 else
405 error = ENOPROTOOPT;
406 break;
407
408 case IP_DUMMYNET_CONFIGURE:
409 case IP_DUMMYNET_DEL:
410 case IP_DUMMYNET_FLUSH:
879652a3 411 error = ip_dn_sockopt(sopt);
984263bc
MD
412 break ;
413
414 case IP_RSVP_ON:
415 error = ip_rsvp_init(so);
416 break;
417
418 case IP_RSVP_OFF:
419 error = ip_rsvp_done();
420 break;
421
422 case IP_RSVP_VIF_ON:
423 case IP_RSVP_VIF_OFF:
424 error = ip_rsvp_vif ?
425 ip_rsvp_vif(so, sopt) : EINVAL;
426 break;
427
428 case MRT_INIT:
429 case MRT_DONE:
430 case MRT_ADD_VIF:
431 case MRT_DEL_VIF:
432 case MRT_ADD_MFC:
433 case MRT_DEL_MFC:
434 case MRT_VERSION:
435 case MRT_ASSERT:
f1f552f6
JH
436 case MRT_API_SUPPORT:
437 case MRT_API_CONFIG:
438 case MRT_ADD_BW_UPCALL:
439 case MRT_DEL_BW_UPCALL:
984263bc
MD
440 error = ip_mrouter_set ? ip_mrouter_set(so, sopt) :
441 EOPNOTSUPP;
442 break;
443
444 default:
445 error = ip_ctloutput(so, sopt);
446 break;
447 }
448 break;
449 }
450
451 return (error);
452}
453
454/*
455 * This function exists solely to receive the PRC_IFDOWN messages which
456 * are sent by if_down(). It looks for an ifaddr whose ifa_addr is sa,
457 * and calls in_ifadown() to remove all routes corresponding to that address.
458 * It also receives the PRC_IFUP messages from if_up() and reinstalls the
459 * interface routes.
460 */
461void
462rip_ctlinput(int cmd, struct sockaddr *sa, void *vip)
463{
464 struct in_ifaddr *ia;
1b562c24 465 struct in_ifaddr_container *iac;
984263bc
MD
466 struct ifnet *ifp;
467 int err;
468 int flags;
469
470 switch (cmd) {
471 case PRC_IFDOWN:
1b562c24
SZ
472 TAILQ_FOREACH(iac, &in_ifaddrheads[mycpuid], ia_link) {
473 ia = iac->ia;
474
be23faf1
JH
475 if (ia->ia_ifa.ifa_addr == sa &&
476 (ia->ia_flags & IFA_ROUTE)) {
984263bc
MD
477 /*
478 * in_ifscrub kills the interface route.
479 */
480 in_ifscrub(ia->ia_ifp, ia);
481 /*
482 * in_ifadown gets rid of all the rest of
483 * the routes. This is not quite the right
484 * thing to do, but at least if we are running
485 * a routing process they will come back.
486 */
487 in_ifadown(&ia->ia_ifa, 0);
488 break;
489 }
490 }
491 break;
492
493 case PRC_IFUP:
1b562c24
SZ
494 ia = NULL;
495 TAILQ_FOREACH(iac, &in_ifaddrheads[mycpuid], ia_link) {
496 if (iac->ia->ia_ifa.ifa_addr == sa) {
497 ia = iac->ia;
984263bc 498 break;
1b562c24 499 }
984263bc 500 }
1b562c24 501 if (ia == NULL || (ia->ia_flags & IFA_ROUTE))
984263bc
MD
502 return;
503 flags = RTF_UP;
504 ifp = ia->ia_ifa.ifa_ifp;
505
be23faf1
JH
506 if ((ifp->if_flags & IFF_LOOPBACK) ||
507 (ifp->if_flags & IFF_POINTOPOINT))
984263bc
MD
508 flags |= RTF_HOST;
509
510 err = rtinit(&ia->ia_ifa, RTM_ADD, flags);
511 if (err == 0)
512 ia->ia_flags |= IFA_ROUTE;
513 break;
514 }
515}
516
517u_long rip_sendspace = RIPSNDQ;
518u_long rip_recvspace = RIPRCVQ;
519
520SYSCTL_INT(_net_inet_raw, OID_AUTO, maxdgram, CTLFLAG_RW,
521 &rip_sendspace, 0, "Maximum outgoing raw IP datagram size");
522SYSCTL_INT(_net_inet_raw, OID_AUTO, recvspace, CTLFLAG_RW,
523 &rip_recvspace, 0, "Maximum incoming raw IP datagram size");
524
525static int
e4700d00 526rip_attach(struct socket *so, int proto, struct pru_attach_info *ai)
984263bc
MD
527{
528 struct inpcb *inp;
1cae611f 529 int error;
984263bc 530
ed894f8c 531 inp = so->so_pcb;
984263bc
MD
532 if (inp)
533 panic("rip_attach");
8d911978
MN
534 error = priv_check_cred(ai->p_ucred, PRIV_NETINET_RAW, NULL_CRED_OKAY);
535 if (error)
984263bc
MD
536 return error;
537
e4700d00 538 error = soreserve(so, rip_sendspace, rip_recvspace, ai->sb_rlimit);
984263bc
MD
539 if (error)
540 return error;
1cae611f 541 crit_enter();
e4700d00 542 error = in_pcballoc(so, &ripcbinfo);
1cae611f 543 crit_exit();
984263bc
MD
544 if (error)
545 return error;
546 inp = (struct inpcb *)so->so_pcb;
547 inp->inp_vflag |= INP_IPV4;
548 inp->inp_ip_p = proto;
549 inp->inp_ip_ttl = ip_defttl;
550 return 0;
551}
552
553static int
554rip_detach(struct socket *so)
555{
556 struct inpcb *inp;
557
ed894f8c 558 inp = so->so_pcb;
984263bc
MD
559 if (inp == 0)
560 panic("rip_detach");
561 if (so == ip_mrouter && ip_mrouter_done)
562 ip_mrouter_done();
563 if (ip_rsvp_force_done)
564 ip_rsvp_force_done(so);
565 if (so == ip_rsvpd)
566 ip_rsvp_done();
567 in_pcbdetach(inp);
568 return 0;
569}
570
571static int
572rip_abort(struct socket *so)
573{
574 soisdisconnected(so);
575 if (so->so_state & SS_NOFDREF)
576 return rip_detach(so);
577 return 0;
578}
579
580static int
581rip_disconnect(struct socket *so)
582{
583 if ((so->so_state & SS_ISCONNECTED) == 0)
584 return ENOTCONN;
585 return rip_abort(so);
586}
587
588static int
dadab5e9 589rip_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
984263bc 590{
ed894f8c 591 struct inpcb *inp = so->so_pcb;
984263bc
MD
592 struct sockaddr_in *addr = (struct sockaddr_in *)nam;
593
594 if (nam->sa_len != sizeof(*addr))
595 return EINVAL;
596
597 if (TAILQ_EMPTY(&ifnet) || ((addr->sin_family != AF_INET) &&
598 (addr->sin_family != AF_IMPLINK)) ||
599 (addr->sin_addr.s_addr != INADDR_ANY &&
600 ifa_ifwithaddr((struct sockaddr *)addr) == 0))
601 return EADDRNOTAVAIL;
602 inp->inp_laddr = addr->sin_addr;
603 return 0;
604}
605
606static int
dadab5e9 607rip_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
984263bc 608{
ed894f8c 609 struct inpcb *inp = so->so_pcb;
984263bc
MD
610 struct sockaddr_in *addr = (struct sockaddr_in *)nam;
611
612 if (nam->sa_len != sizeof(*addr))
613 return EINVAL;
614 if (TAILQ_EMPTY(&ifnet))
615 return EADDRNOTAVAIL;
616 if ((addr->sin_family != AF_INET) &&
617 (addr->sin_family != AF_IMPLINK))
618 return EAFNOSUPPORT;
619 inp->inp_faddr = addr->sin_addr;
620 soisconnected(so);
621 return 0;
622}
623
624static int
625rip_shutdown(struct socket *so)
626{
627 socantsendmore(so);
628 return 0;
629}
630
631static int
632rip_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
dadab5e9 633 struct mbuf *control, struct thread *td)
984263bc 634{
ed894f8c 635 struct inpcb *inp = so->so_pcb;
984263bc
MD
636 u_long dst;
637
638 if (so->so_state & SS_ISCONNECTED) {
639 if (nam) {
640 m_freem(m);
641 return EISCONN;
642 }
643 dst = inp->inp_faddr.s_addr;
644 } else {
645 if (nam == NULL) {
646 m_freem(m);
647 return ENOTCONN;
648 }
649 dst = ((struct sockaddr_in *)nam)->sin_addr.s_addr;
650 }
651 return rip_output(m, so, dst);
652}
653
48a2763f
JS
654SYSCTL_PROC(_net_inet_raw, OID_AUTO/*XXX*/, pcblist, CTLFLAG_RD, &ripcbinfo, 0,
655 in_pcblist_global, "S,xinpcb", "List of active raw IP sockets");
984263bc
MD
656
657struct pr_usrreqs rip_usrreqs = {
fa5e758c
MD
658 .pru_abort = rip_abort,
659 .pru_accept = pru_accept_notsupp,
660 .pru_attach = rip_attach,
661 .pru_bind = rip_bind,
662 .pru_connect = rip_connect,
663 .pru_connect2 = pru_connect2_notsupp,
664 .pru_control = in_control,
665 .pru_detach = rip_detach,
666 .pru_disconnect = rip_disconnect,
667 .pru_listen = pru_listen_notsupp,
668 .pru_peeraddr = in_setpeeraddr,
669 .pru_rcvd = pru_rcvd_notsupp,
670 .pru_rcvoob = pru_rcvoob_notsupp,
671 .pru_send = rip_send,
672 .pru_sense = pru_sense_null,
673 .pru_shutdown = rip_shutdown,
674 .pru_sockaddr = in_setsockaddr,
675 .pru_sosend = sosend,
676 .pru_soreceive = soreceive,
677 .pru_sopoll = sopoll
984263bc 678};