in_pcb.c (4049a042532f6ed2ac22101bce0cb84f34e23f06) in_pcb.c (3d4d47f39858441d8b8625898e74563f7b60e2b5)
1/*
2 * Copyright (c) 1982, 1986, 1991, 1993, 1995
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

--- 17 unchanged lines hidden (view full) ---

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 * @(#)in_pcb.c 8.4 (Berkeley) 5/24/95
1/*
2 * Copyright (c) 1982, 1986, 1991, 1993, 1995
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

--- 17 unchanged lines hidden (view full) ---

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 * @(#)in_pcb.c 8.4 (Berkeley) 5/24/95
34 * $Id: in_pcb.c,v 1.38 1998/01/27 09:15:03 davidg Exp $
34 * $Id: in_pcb.c,v 1.39 1998/03/01 19:39:26 guido Exp $
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/malloc.h>
40#include <sys/mbuf.h>
41#include <sys/protosw.h>
42#include <sys/socket.h>
43#include <sys/socketvar.h>
44#include <sys/proc.h>
45#include <sys/kernel.h>
46#include <sys/sysctl.h>
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/malloc.h>
40#include <sys/mbuf.h>
41#include <sys/protosw.h>
42#include <sys/socket.h>
43#include <sys/socketvar.h>
44#include <sys/proc.h>
45#include <sys/kernel.h>
46#include <sys/sysctl.h>
47#include <vm/vm_zone.h> /* for zalloci, zfreei prototypes */
47
48#include <net/if.h>
49#include <net/route.h>
50
51#include <netinet/in.h>
52#include <netinet/in_pcb.h>
53#include <netinet/in_var.h>
54#include <netinet/ip_var.h>

--- 65 unchanged lines hidden (view full) ---

120int
121in_pcballoc(so, pcbinfo, p)
122 struct socket *so;
123 struct inpcbinfo *pcbinfo;
124 struct proc *p;
125{
126 register struct inpcb *inp;
127
48
49#include <net/if.h>
50#include <net/route.h>
51
52#include <netinet/in.h>
53#include <netinet/in_pcb.h>
54#include <netinet/in_var.h>
55#include <netinet/ip_var.h>

--- 65 unchanged lines hidden (view full) ---

121int
122in_pcballoc(so, pcbinfo, p)
123 struct socket *so;
124 struct inpcbinfo *pcbinfo;
125 struct proc *p;
126{
127 register struct inpcb *inp;
128
128 MALLOC(inp, struct inpcb *, sizeof(*inp), M_PCB,
129 p ? M_WAITOK : M_NOWAIT);
129 inp = zalloci(pcbinfo->ipi_zone);
130 if (inp == NULL)
131 return (ENOBUFS);
132 bzero((caddr_t)inp, sizeof(*inp));
130 if (inp == NULL)
131 return (ENOBUFS);
132 bzero((caddr_t)inp, sizeof(*inp));
133 inp->inp_gencnt = ++pcbinfo->ipi_gencnt;
133 inp->inp_pcbinfo = pcbinfo;
134 inp->inp_socket = so;
135 LIST_INSERT_HEAD(pcbinfo->listhead, inp, inp_list);
134 inp->inp_pcbinfo = pcbinfo;
135 inp->inp_socket = so;
136 LIST_INSERT_HEAD(pcbinfo->listhead, inp, inp_list);
137 pcbinfo->ipi_count++;
136 so->so_pcb = (caddr_t)inp;
137 return (0);
138}
139
140int
141in_pcbbind(inp, nam, p)
142 register struct inpcb *inp;
143 struct sockaddr *nam;

--- 315 unchanged lines hidden (view full) ---

459 in_pcbdetach(inp);
460}
461
462void
463in_pcbdetach(inp)
464 struct inpcb *inp;
465{
466 struct socket *so = inp->inp_socket;
138 so->so_pcb = (caddr_t)inp;
139 return (0);
140}
141
142int
143in_pcbbind(inp, nam, p)
144 register struct inpcb *inp;
145 struct sockaddr *nam;

--- 315 unchanged lines hidden (view full) ---

461 in_pcbdetach(inp);
462}
463
464void
465in_pcbdetach(inp)
466 struct inpcb *inp;
467{
468 struct socket *so = inp->inp_socket;
469 struct inpcbinfo *ipi = inp->inp_pcbinfo;
467
470
471 inp->inp_gencnt = ++ipi->ipi_gencnt;
468 in_pcbremlists(inp);
469 so->so_pcb = 0;
470 sofree(so);
471 if (inp->inp_options)
472 (void)m_free(inp->inp_options);
473 if (inp->inp_route.ro_rt)
474 rtfree(inp->inp_route.ro_rt);
475 ip_freemoptions(inp->inp_moptions);
472 in_pcbremlists(inp);
473 so->so_pcb = 0;
474 sofree(so);
475 if (inp->inp_options)
476 (void)m_free(inp->inp_options);
477 if (inp->inp_route.ro_rt)
478 rtfree(inp->inp_route.ro_rt);
479 ip_freemoptions(inp->inp_moptions);
476 FREE(inp, M_PCB);
480 zfreei(ipi->ipi_zone, inp);
477}
478
479/*
480 * The calling convention of in_setsockaddr() and in_setpeeraddr() was
481 * modified to match the pru_sockaddr() and pru_peeraddr() entry points
482 * in struct pr_usrreqs, so that protocols can just reference then directly
483 * without the need for a wrapper function. The socket must have a valid
484 * (i.e., non-nil) PCB, but it should be impossible to get an invalid one

--- 389 unchanged lines hidden (view full) ---

874 LIST_REMOVE(inp, inp_hash);
875 LIST_REMOVE(inp, inp_portlist);
876 if (phd->phd_pcblist.lh_first == NULL) {
877 LIST_REMOVE(phd, phd_hash);
878 free(phd, M_PCB);
879 }
880 }
881 LIST_REMOVE(inp, inp_list);
481}
482
483/*
484 * The calling convention of in_setsockaddr() and in_setpeeraddr() was
485 * modified to match the pru_sockaddr() and pru_peeraddr() entry points
486 * in struct pr_usrreqs, so that protocols can just reference then directly
487 * without the need for a wrapper function. The socket must have a valid
488 * (i.e., non-nil) PCB, but it should be impossible to get an invalid one

--- 389 unchanged lines hidden (view full) ---

878 LIST_REMOVE(inp, inp_hash);
879 LIST_REMOVE(inp, inp_portlist);
880 if (phd->phd_pcblist.lh_first == NULL) {
881 LIST_REMOVE(phd, phd_hash);
882 free(phd, M_PCB);
883 }
884 }
885 LIST_REMOVE(inp, inp_list);
886 inp->inp_pcbinfo->ipi_count--;
882}
887}