Commit | Line | Data |
---|---|---|
cb1c44c2 | 1 | /* |
1810611d | 2 | * Copyright (c) 1980, 1986 Regents of the University of California. |
5b519e94 | 3 | * All rights reserved. |
cb1c44c2 | 4 | * |
dbf0c423 | 5 | * %sccs.include.redist.c% |
5b519e94 | 6 | * |
2e5eb990 | 7 | * @(#)raw_cb.c 7.13 (Berkeley) %G% |
cb1c44c2 | 8 | */ |
785d93ac | 9 | |
20666ad3 JB |
10 | #include "param.h" |
11 | #include "systm.h" | |
12 | #include "mbuf.h" | |
13 | #include "socket.h" | |
14 | #include "socketvar.h" | |
829f867e MK |
15 | #include "domain.h" |
16 | #include "protosw.h" | |
20666ad3 | 17 | #include "errno.h" |
f4d55810 | 18 | |
20666ad3 JB |
19 | #include "if.h" |
20 | #include "route.h" | |
21 | #include "raw_cb.h" | |
9e9695c7 | 22 | #include "../netinet/in.h" |
f4d55810 | 23 | |
785d93ac BJ |
24 | /* |
25 | * Routines to manage the raw protocol control blocks. | |
26 | * | |
27 | * TODO: | |
28 | * hash lookups by protocol family/protocol + address family | |
ee787340 | 29 | * take care of unique address problems per AF? |
1e25d807 | 30 | * redo address binding to allow wildcards |
785d93ac BJ |
31 | */ |
32 | ||
73379934 MK |
33 | u_long raw_sendspace = RAWSNDQ; |
34 | u_long raw_recvspace = RAWRCVQ; | |
35 | ||
785d93ac BJ |
36 | /* |
37 | * Allocate a control block and a nominal amount | |
38 | * of buffer space for the socket. | |
39 | */ | |
829f867e | 40 | raw_attach(so, proto) |
785d93ac | 41 | register struct socket *so; |
829f867e | 42 | int proto; |
785d93ac | 43 | { |
b72a6efb | 44 | register struct rawcb *rp = sotorawcb(so); |
22d9d71b | 45 | int error; |
785d93ac | 46 | |
b72a6efb KS |
47 | /* |
48 | * It is assumed that raw_attach is called | |
49 | * after space has been allocated for the | |
50 | * rawcb. | |
51 | */ | |
52 | if (rp == 0) | |
785d93ac | 53 | return (ENOBUFS); |
22d9d71b MK |
54 | if (error = soreserve(so, raw_sendspace, raw_recvspace)) |
55 | return (error); | |
785d93ac | 56 | rp->rcb_socket = so; |
829f867e MK |
57 | rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family; |
58 | rp->rcb_proto.sp_protocol = proto; | |
59 | insque(rp, &rawcb); | |
785d93ac | 60 | return (0); |
785d93ac BJ |
61 | } |
62 | ||
63 | /* | |
64 | * Detach the raw connection block and discard | |
65 | * socket resources. | |
66 | */ | |
67 | raw_detach(rp) | |
68 | register struct rawcb *rp; | |
69 | { | |
70 | struct socket *so = rp->rcb_socket; | |
71 | ||
785d93ac BJ |
72 | so->so_pcb = 0; |
73 | sofree(so); | |
74 | remque(rp); | |
b72a6efb KS |
75 | #ifdef notdef |
76 | if (rp->rcb_laddr) | |
77 | m_freem(dtom(rp->rcb_laddr)); | |
78 | rp->rcb_laddr = 0; | |
79 | #endif | |
80 | free((caddr_t)(rp), M_PCB); | |
785d93ac BJ |
81 | } |
82 | ||
83 | /* | |
84 | * Disconnect and possibly release resources. | |
85 | */ | |
86 | raw_disconnect(rp) | |
87 | struct rawcb *rp; | |
88 | { | |
4053be18 | 89 | |
b72a6efb KS |
90 | #ifdef notdef |
91 | if (rp->rcb_faddr) | |
92 | m_freem(dtom(rp->rcb_faddr)); | |
93 | rp->rcb_faddr = 0; | |
94 | #endif | |
f832270b | 95 | if (rp->rcb_socket->so_state & SS_NOFDREF) |
785d93ac BJ |
96 | raw_detach(rp); |
97 | } | |
98 | ||
b72a6efb | 99 | #ifdef notdef |
14fa60f2 BJ |
100 | raw_bind(so, nam) |
101 | register struct socket *so; | |
102 | struct mbuf *nam; | |
103 | { | |
104 | struct sockaddr *addr = mtod(nam, struct sockaddr *); | |
14fa60f2 BJ |
105 | register struct rawcb *rp; |
106 | ||
107 | if (ifnet == 0) | |
108 | return (EADDRNOTAVAIL); | |
af0b24db | 109 | rp = sotorawcb(so); |
b72a6efb KS |
110 | nam = m_copym(nam, 0, M_COPYALL, M_WAITOK); |
111 | rp->rcb_laddr = mtod(nam, struct sockaddr *); | |
14fa60f2 BJ |
112 | return (0); |
113 | } | |
b72a6efb | 114 | #endif |