1/*-
2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3 * Copyright (c) 2010-2011 Juniper Networks, Inc.
4 * All rights reserved.
5 *
6 * Portions of this software were developed by Robert N. M. Watson under
7 * contract to Juniper Networks, Inc.
8 *
--- 51 unchanged lines hidden (view full) ---
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * SUCH DAMAGE.
63 *
64 * @(#)in_pcb.c 8.2 (Berkeley) 1/4/94
65 */
66
67#include <sys/cdefs.h>
68__FBSDID("$FreeBSD: head/sys/netinet6/in6_pcb.c 222488 2011-05-30 09:43:55Z rwatson $");
69
70#include "opt_inet.h"
71#include "opt_inet6.h"
72#include "opt_ipsec.h"
73
74#include <sys/param.h>
75#include <sys/systm.h>
76#include <sys/malloc.h>
--- 282 unchanged lines hidden (view full) ---
359/*
360 * Outer subroutine:
361 * Connect from a socket to a specified address.
362 * Both address and port must be specified in argument sin.
363 * If don't have a local address for this socket yet,
364 * then pick one.
365 */
366int
367in6_pcbconnect(register struct inpcb *inp, struct sockaddr *nam,
368 struct ucred *cred)
369{
370 struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
371 register struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam;
372 struct in6_addr addr6;
373 int error;
374
375 INP_WLOCK_ASSERT(inp);
376 INP_HASH_WLOCK_ASSERT(pcbinfo);
--- 23 unchanged lines hidden (view full) ---
400 inp->in6p_faddr = sin6->sin6_addr;
401 inp->inp_fport = sin6->sin6_port;
402 /* update flowinfo - draft-itojun-ipv6-flowlabel-api-00 */
403 inp->inp_flow &= ~IPV6_FLOWLABEL_MASK;
404 if (inp->inp_flags & IN6P_AUTOFLOWLABEL)
405 inp->inp_flow |=
406 (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK);
407
408 in_pcbrehash(inp);
409
410 return (0);
411}
412
413void
414in6_pcbdisconnect(struct inpcb *inp)
415{
416
417 INP_WLOCK_ASSERT(inp);
418 INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo);
419
420 bzero((caddr_t)&inp->in6p_faddr, sizeof(inp->in6p_faddr));
--- 548 unchanged lines hidden (view full) ---
969 } else
970 panic("%s: locking bug", __func__);
971 } else
972 INP_HASH_RUNLOCK(pcbinfo);
973 return (inp);
974}
975
976/*
977 * Public inpcb lookup routines, accepting a 4-tuple.
978 */
979struct inpcb *
980in6_pcblookup(struct inpcbinfo *pcbinfo, struct in6_addr *faddr, u_int fport,
981 struct in6_addr *laddr, u_int lport, int lookupflags, struct ifnet *ifp)
982{
983
984 KASSERT((lookupflags & ~INPLOOKUP_MASK) == 0,
985 ("%s: invalid lookup flags %d", __func__, lookupflags));
986 KASSERT((lookupflags & (INPLOOKUP_RLOCKPCB | INPLOOKUP_WLOCKPCB)) != 0,
987 ("%s: LOCKPCB not set", __func__));
988
989 return (in6_pcblookup_hash(pcbinfo, faddr, fport, laddr, lport,
990 lookupflags, ifp));
991}
--- 16 unchanged lines hidden ---
2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3 * Copyright (c) 2010-2011 Juniper Networks, Inc.
4 * All rights reserved.
5 *
6 * Portions of this software were developed by Robert N. M. Watson under
7 * contract to Juniper Networks, Inc.
8 *
--- 51 unchanged lines hidden (view full) ---
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * SUCH DAMAGE.
63 *
64 * @(#)in_pcb.c 8.2 (Berkeley) 1/4/94
65 */
66
67#include <sys/cdefs.h>
68__FBSDID("$FreeBSD: head/sys/netinet6/in6_pcb.c 222488 2011-05-30 09:43:55Z rwatson $");
69
70#include "opt_inet.h"
71#include "opt_inet6.h"
72#include "opt_ipsec.h"
73
74#include <sys/param.h>
75#include <sys/systm.h>
76#include <sys/malloc.h>
--- 282 unchanged lines hidden (view full) ---
359/*
360 * Outer subroutine:
361 * Connect from a socket to a specified address.
362 * Both address and port must be specified in argument sin.
363 * If don't have a local address for this socket yet,
364 * then pick one.
365 */
366int
367in6_pcbconnect(register struct inpcb *inp, struct sockaddr *nam,
368 struct ucred *cred)
369{
370 struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
371 register struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam;
372 struct in6_addr addr6;
373 int error;
374
375 INP_WLOCK_ASSERT(inp);
376 INP_HASH_WLOCK_ASSERT(pcbinfo);
--- 23 unchanged lines hidden (view full) ---
400 inp->in6p_faddr = sin6->sin6_addr;
401 inp->inp_fport = sin6->sin6_port;
402 /* update flowinfo - draft-itojun-ipv6-flowlabel-api-00 */
403 inp->inp_flow &= ~IPV6_FLOWLABEL_MASK;
404 if (inp->inp_flags & IN6P_AUTOFLOWLABEL)
405 inp->inp_flow |=
406 (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK);
407
408 in_pcbrehash(inp);
409
410 return (0);
411}
412
413void
414in6_pcbdisconnect(struct inpcb *inp)
415{
416
417 INP_WLOCK_ASSERT(inp);
418 INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo);
419
420 bzero((caddr_t)&inp->in6p_faddr, sizeof(inp->in6p_faddr));
--- 548 unchanged lines hidden (view full) ---
969 } else
970 panic("%s: locking bug", __func__);
971 } else
972 INP_HASH_RUNLOCK(pcbinfo);
973 return (inp);
974}
975
976/*
977 * Public inpcb lookup routines, accepting a 4-tuple.
978 */
979struct inpcb *
980in6_pcblookup(struct inpcbinfo *pcbinfo, struct in6_addr *faddr, u_int fport,
981 struct in6_addr *laddr, u_int lport, int lookupflags, struct ifnet *ifp)
982{
983
984 KASSERT((lookupflags & ~INPLOOKUP_MASK) == 0,
985 ("%s: invalid lookup flags %d", __func__, lookupflags));
986 KASSERT((lookupflags & (INPLOOKUP_RLOCKPCB | INPLOOKUP_WLOCKPCB)) != 0,
987 ("%s: LOCKPCB not set", __func__));
988
989 return (in6_pcblookup_hash(pcbinfo, faddr, fport, laddr, lport,
990 lookupflags, ifp));
991}
--- 16 unchanged lines hidden ---